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