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 32 #include <tools/svborder.hxx> 33 #include <vcl/gradient.hxx> 34 #include <vcl/image.hxx> 35 36 #ifdef DEBUG 37 #include "sfx2/sidebar/Tools.hxx" 38 #endif 39 40 41 namespace sfx2 { namespace sidebar { 42 43 44 static const sal_Int32 gaLeftIconPadding (5); 45 static const sal_Int32 gaRightIconPadding (5); 46 47 48 PanelTitleBar::PanelTitleBar ( 49 const ::rtl::OUString& rsTitle, 50 Window* pParentWindow, 51 Panel* pPanel) 52 : TitleBar(rsTitle, pParentWindow, GetBackgroundPaint()), 53 mbIsLeftButtonDown(false), 54 mpPanel(pPanel), 55 mnMenuItemIndex(1), 56 maMenuAction() 57 { 58 OSL_ASSERT(mpPanel != NULL); 59 60 const ::rtl::OUString sAccessibleName( 61 String(SfxResId(SFX_STR_SIDEBAR_ACCESSIBILITY_PANEL_PREFIX)) 62 + rsTitle); 63 SetAccessibleName(sAccessibleName); 64 SetAccessibleDescription(sAccessibleName); 65 66 #ifdef DEBUG 67 SetText(A2S("PanelTitleBar")); 68 #endif 69 } 70 71 72 73 74 PanelTitleBar::~PanelTitleBar (void) 75 { 76 } 77 78 79 80 81 void PanelTitleBar::SetMenuAction ( const ::boost::function<void(void)>& rMenuAction ) 82 { 83 if ( !maMenuAction && rMenuAction ) 84 { 85 maToolBox.InsertItem( 86 mnMenuItemIndex, 87 Theme::GetImage(Theme::Image_PanelMenu)); 88 maToolBox.SetOutStyle(TOOLBOX_STYLE_FLAT); 89 maToolBox.SetQuickHelpText( 90 mnMenuItemIndex, 91 String(SfxResId(SFX_STR_SIDEBAR_MORE_OPTIONS))); 92 } 93 else if ( maMenuAction && !rMenuAction ) 94 { 95 maToolBox.RemoveItem( maToolBox.GetItemPos( mnMenuItemIndex ) ); 96 } 97 maMenuAction = rMenuAction; 98 } 99 100 101 102 103 Rectangle PanelTitleBar::GetTitleArea (const Rectangle& rTitleBarBox) 104 { 105 if (mpPanel != NULL) 106 { 107 Image aImage (mpPanel->IsExpanded() 108 ? Theme::GetImage(Theme::Image_Expand) 109 : Theme::GetImage(Theme::Image_Collapse)); 110 return Rectangle( 111 aImage.GetSizePixel().Width() + gaLeftIconPadding + gaRightIconPadding, 112 rTitleBarBox.Top(), 113 rTitleBarBox.Right(), 114 rTitleBarBox.Bottom()); 115 } 116 else 117 return rTitleBarBox; 118 } 119 120 121 122 123 void PanelTitleBar::PaintDecoration (const Rectangle& rTitleBarBox) 124 { 125 (void)rTitleBarBox; 126 127 if (mpPanel != NULL) 128 { 129 Image aImage (mpPanel->IsExpanded() 130 ? Theme::GetImage(Theme::Image_Collapse) 131 : Theme::GetImage(Theme::Image_Expand)); 132 const Point aTopLeft ( 133 gaLeftIconPadding, 134 (GetSizePixel().Height()-aImage.GetSizePixel().Height())/2); 135 DrawImage(aTopLeft, aImage); 136 } 137 } 138 139 140 141 142 Paint PanelTitleBar::GetBackgroundPaint (void) 143 { 144 return Theme::GetPaint(Theme::Paint_PanelTitleBarBackground); 145 } 146 147 148 149 150 Color PanelTitleBar::GetTextColor (void) 151 { 152 return Theme::GetColor(Theme::Color_PanelTitleFont); 153 } 154 155 156 157 158 void PanelTitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex) 159 { 160 if (nItemIndex == mnMenuItemIndex) 161 if (maMenuAction) 162 maMenuAction(); 163 } 164 165 166 167 168 void PanelTitleBar::MouseButtonDown (const MouseEvent& rMouseEvent) 169 { 170 if (rMouseEvent.IsLeft()) 171 { 172 mbIsLeftButtonDown = true; 173 CaptureMouse(); 174 } 175 } 176 177 178 179 180 void PanelTitleBar::MouseButtonUp (const MouseEvent& rMouseEvent) 181 { 182 if (IsMouseCaptured()) 183 ReleaseMouse(); 184 185 if (rMouseEvent.IsLeft()) 186 { 187 if (mbIsLeftButtonDown) 188 { 189 if (mpPanel != NULL) 190 { 191 mpPanel->SetExpanded( ! mpPanel->IsExpanded()); 192 Invalidate(); 193 } 194 } 195 } 196 if (mbIsLeftButtonDown) 197 mbIsLeftButtonDown = false; 198 } 199 200 201 202 203 void PanelTitleBar::DataChanged (const DataChangedEvent& rEvent) 204 { 205 maToolBox.SetItemImage( 206 mnMenuItemIndex, 207 Theme::GetImage(Theme::Image_PanelMenu)); 208 TitleBar::DataChanged(rEvent); 209 } 210 211 } } // end of namespace sfx2::sidebar 212