1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 #include "precompiled_sfx2.hxx" 23 24 #include "PanelTitleBar.hxx" 25 #include "sfx2/sfxresid.hxx" 26 #include "Sidebar.hrc" 27 28 #include "Paint.hxx" 29 #include "Panel.hxx" 30 #include "sfx2/sidebar/Theme.hxx" 31 #include "sfx2/sidebar/ControllerFactory.hxx" 32 #include <tools/svborder.hxx> 33 #include <vcl/gradient.hxx> 34 #include <vcl/image.hxx> 35 #include <toolkit/helper/vclunohelper.hxx> 36 37 #ifdef DEBUG 38 #include "sfx2/sidebar/Tools.hxx" 39 #endif 40 41 using namespace css; 42 using namespace cssu; 43 44 namespace sfx2 { namespace sidebar { 45 46 47 static const sal_Int32 gaLeftIconPadding (5); 48 static const sal_Int32 gaRightIconPadding (5); 49 50 51 PanelTitleBar::PanelTitleBar ( 52 const ::rtl::OUString& rsTitle, 53 Window* pParentWindow, 54 Panel* pPanel) 55 : TitleBar(rsTitle, pParentWindow, GetBackgroundPaint()), 56 mbIsLeftButtonDown(false), 57 mpPanel(pPanel), 58 mnMenuItemIndex(1), 59 mxFrame(), 60 msMoreOptionsCommand() 61 { 62 OSL_ASSERT(mpPanel != NULL); 63 64 const ::rtl::OUString sAccessibleName( 65 String(SfxResId(SFX_STR_SIDEBAR_ACCESSIBILITY_PANEL_PREFIX)) 66 + rsTitle); 67 SetAccessibleName(sAccessibleName); 68 SetAccessibleDescription(sAccessibleName); 69 70 #ifdef DEBUG 71 SetText(A2S("PanelTitleBar")); 72 #endif 73 } 74 75 76 77 78 PanelTitleBar::~PanelTitleBar (void) 79 { 80 } 81 82 83 84 85 void PanelTitleBar::SetMoreOptionsCommand ( 86 const ::rtl::OUString& rsCommandName, 87 const ::cssu::Reference<css::frame::XFrame>& rxFrame) 88 { 89 if ( ! rsCommandName.equals(msMoreOptionsCommand)) 90 { 91 if (msMoreOptionsCommand.getLength() > 0) 92 maToolBox.RemoveItem(maToolBox.GetItemPos(mnMenuItemIndex)); 93 94 msMoreOptionsCommand = rsCommandName; 95 mxFrame = rxFrame; 96 97 if (msMoreOptionsCommand.getLength() > 0) 98 { 99 maToolBox.InsertItem( 100 mnMenuItemIndex, 101 Theme::GetImage(Theme::Image_PanelMenu)); 102 Reference<frame::XToolbarController> xController ( 103 ControllerFactory::CreateToolBoxController( 104 &maToolBox, 105 mnMenuItemIndex, 106 msMoreOptionsCommand, 107 rxFrame, 108 VCLUnoHelper::GetInterface(&maToolBox), 109 0)); 110 maToolBox.SetController(mnMenuItemIndex, xController, msMoreOptionsCommand); 111 maToolBox.SetOutStyle(TOOLBOX_STYLE_FLAT); 112 maToolBox.SetQuickHelpText( 113 mnMenuItemIndex, 114 String(SfxResId(SFX_STR_SIDEBAR_MORE_OPTIONS))); 115 } 116 } 117 } 118 119 120 121 122 Rectangle PanelTitleBar::GetTitleArea (const Rectangle& rTitleBarBox) 123 { 124 if (mpPanel != NULL) 125 { 126 Image aImage (mpPanel->IsExpanded() 127 ? Theme::GetImage(Theme::Image_Expand) 128 : Theme::GetImage(Theme::Image_Collapse)); 129 return Rectangle( 130 aImage.GetSizePixel().Width() + gaLeftIconPadding + gaRightIconPadding, 131 rTitleBarBox.Top(), 132 rTitleBarBox.Right(), 133 rTitleBarBox.Bottom()); 134 } 135 else 136 return rTitleBarBox; 137 } 138 139 140 141 142 void PanelTitleBar::PaintDecoration (const Rectangle& rTitleBarBox) 143 { 144 (void)rTitleBarBox; 145 146 if (mpPanel != NULL) 147 { 148 Image aImage (mpPanel->IsExpanded() 149 ? Theme::GetImage(Theme::Image_Collapse) 150 : Theme::GetImage(Theme::Image_Expand)); 151 const Point aTopLeft ( 152 gaLeftIconPadding, 153 (GetSizePixel().Height()-aImage.GetSizePixel().Height())/2); 154 DrawImage(aTopLeft, aImage); 155 } 156 } 157 158 159 160 161 Paint PanelTitleBar::GetBackgroundPaint (void) 162 { 163 return Theme::GetPaint(Theme::Paint_PanelTitleBarBackground); 164 } 165 166 167 168 169 Color PanelTitleBar::GetTextColor (void) 170 { 171 return Theme::GetColor(Theme::Color_PanelTitleFont); 172 } 173 174 175 176 177 void PanelTitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex) 178 { 179 if (nItemIndex == mnMenuItemIndex) 180 if (msMoreOptionsCommand.getLength() > 0) 181 { 182 try 183 { 184 const util::URL aURL (Tools::GetURL(msMoreOptionsCommand)); 185 Reference<frame::XDispatch> xDispatch (Tools::GetDispatch(mxFrame, aURL)); 186 if (xDispatch.is()) 187 xDispatch->dispatch(aURL, Sequence<beans::PropertyValue>()); 188 } 189 catch(Exception& rException) 190 { 191 OSL_TRACE("caught exception: %s", 192 OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr()); 193 } 194 } 195 } 196 197 198 199 200 void PanelTitleBar::MouseButtonDown (const MouseEvent& rMouseEvent) 201 { 202 if (rMouseEvent.IsLeft()) 203 { 204 mbIsLeftButtonDown = true; 205 CaptureMouse(); 206 } 207 } 208 209 210 211 212 void PanelTitleBar::MouseButtonUp (const MouseEvent& rMouseEvent) 213 { 214 if (IsMouseCaptured()) 215 ReleaseMouse(); 216 217 if (rMouseEvent.IsLeft()) 218 { 219 if (mbIsLeftButtonDown) 220 { 221 if (mpPanel != NULL) 222 { 223 mpPanel->SetExpanded( ! mpPanel->IsExpanded()); 224 Invalidate(); 225 } 226 } 227 } 228 if (mbIsLeftButtonDown) 229 mbIsLeftButtonDown = false; 230 } 231 232 233 234 235 void PanelTitleBar::DataChanged (const DataChangedEvent& rEvent) 236 { 237 maToolBox.SetItemImage( 238 mnMenuItemIndex, 239 Theme::GetImage(Theme::Image_PanelMenu)); 240 TitleBar::DataChanged(rEvent); 241 } 242 243 } } // end of namespace sfx2::sidebar 244