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     if (mpPanel != NULL)
105     {
106         Image aImage (mpPanel->IsExpanded()
107             ? Theme::GetImage(Theme::Image_Collapse)
108             : Theme::GetImage(Theme::Image_Expand));
109         const Point aTopLeft (
110             gaLeftIconPadding,
111             (GetSizePixel().Height()-aImage.GetSizePixel().Height())/2);
112         DrawImage(aTopLeft, aImage);
113     }
114 }
115 
116 
117 
118 
119 Paint PanelTitleBar::GetBackgroundPaint (void)
120 {
121     return Theme::GetPaint(Theme::Paint_PanelTitleBarBackground);
122 }
123 
124 
125 
126 
127 Color PanelTitleBar::GetTextColor (void)
128 {
129     return Theme::GetColor(Theme::Color_PanelTitleFont);
130 }
131 
132 
133 
134 
135 void PanelTitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex)
136 {
137     if (nItemIndex == mnMenuItemIndex)
138         if (maMenuAction)
139             maMenuAction();
140 }
141 
142 
143 
144 
145 void PanelTitleBar::MouseButtonDown (const MouseEvent& rMouseEvent)
146 {
147     if (rMouseEvent.IsLeft())
148     {
149         mbIsLeftButtonDown = true;
150         CaptureMouse();
151     }
152 }
153 
154 
155 
156 
157 void PanelTitleBar::MouseButtonUp (const MouseEvent& rMouseEvent)
158 {
159     if (IsMouseCaptured())
160         ReleaseMouse();
161 
162     if (rMouseEvent.IsLeft())
163     {
164         if (mbIsLeftButtonDown)
165         {
166             if (mpPanel != NULL)
167             {
168                 mpPanel->SetExpanded( ! mpPanel->IsExpanded());
169                 Invalidate();
170             }
171         }
172     }
173     if (mbIsLeftButtonDown)
174         mbIsLeftButtonDown = false;
175 }
176 
177 
178 
179 
180 void PanelTitleBar::DataChanged (const DataChangedEvent& rEvent)
181 {
182     maToolBox.SetItemImage(
183         mnMenuItemIndex,
184         Theme::GetImage(Theme::Image_PanelMenu));
185 }
186 
187 } } // end of namespace sfx2::sidebar
188