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 35 namespace sfx2 { namespace sidebar { 36 37 38 static const sal_Int32 gaLeftIconPadding (5); 39 static const sal_Int32 gaRightIconPadding (5); 40 41 42 PanelTitleBar::PanelTitleBar ( 43 const ::rtl::OUString& rsTitle, 44 Window* pParentWindow, 45 Panel* pPanel) 46 : TitleBar(rsTitle, pParentWindow), 47 mbIsLeftButtonDown(false), 48 mpPanel(pPanel) 49 { 50 OSL_ASSERT(mpPanel != NULL); 51 } 52 53 54 55 56 PanelTitleBar::~PanelTitleBar (void) 57 { 58 } 59 60 61 62 63 Rectangle PanelTitleBar::GetTitleArea (const Rectangle& rTitleBarBox) 64 { 65 if (mpPanel != NULL) 66 { 67 Image aImage (mpPanel->IsExpanded() 68 ? Theme::GetImage(Theme::Image_Expand) 69 : Theme::GetImage(Theme::Image_Collapse)); 70 return Rectangle( 71 aImage.GetSizePixel().Width() + gaLeftIconPadding + gaRightIconPadding, 72 rTitleBarBox.Top(), 73 rTitleBarBox.Right(), 74 rTitleBarBox.Bottom()); 75 } 76 else 77 return rTitleBarBox; 78 } 79 80 81 82 83 void PanelTitleBar::PaintDecoration (const Rectangle& rTitleBarBox) 84 { 85 if (mpPanel != NULL) 86 { 87 Image aImage (mpPanel->IsExpanded() 88 ? Theme::GetImage(Theme::Image_Collapse) 89 : Theme::GetImage(Theme::Image_Expand)); 90 const Point aTopLeft ( 91 gaLeftIconPadding, 92 (GetSizePixel().Height()-aImage.GetSizePixel().Height())/2); 93 DrawImage(aTopLeft, aImage); 94 } 95 } 96 97 98 99 100 Paint PanelTitleBar::GetBackgroundPaint (void) 101 { 102 return Theme::GetPaint(Theme::Paint_PanelTitleBarBackground); 103 } 104 105 106 107 108 Color PanelTitleBar::GetTextColor (void) 109 { 110 return Theme::GetColor(Theme::Color_PanelTitleFont); 111 } 112 113 114 115 116 void PanelTitleBar::MouseButtonDown (const MouseEvent& rMouseEvent) 117 { 118 if (rMouseEvent.IsLeft()) 119 { 120 mbIsLeftButtonDown = true; 121 CaptureMouse(); 122 } 123 } 124 125 126 127 128 void PanelTitleBar::MouseButtonUp (const MouseEvent& rMouseEvent) 129 { 130 if (IsMouseCaptured()) 131 ReleaseMouse(); 132 133 if (rMouseEvent.IsLeft()) 134 { 135 if (mbIsLeftButtonDown) 136 { 137 if (mpPanel != NULL) 138 { 139 mpPanel->SetExpanded( ! mpPanel->IsExpanded()); 140 Invalidate(); 141 } 142 } 143 } 144 if (mbIsLeftButtonDown) 145 mbIsLeftButtonDown = false; 146 } 147 148 149 150 } } // end of namespace sfx2::sidebar 151