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