xref: /trunk/main/sfx2/source/sidebar/PanelTitleBar.cxx (revision 7a32b0c888def1bf84d1d657c48953bc10dc00c1)
1ff12d537SAndre Fischer /**************************************************************
2ff12d537SAndre Fischer  *
3ff12d537SAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
4ff12d537SAndre Fischer  * or more contributor license agreements.  See the NOTICE file
5ff12d537SAndre Fischer  * distributed with this work for additional information
6ff12d537SAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
7ff12d537SAndre Fischer  * to you under the Apache License, Version 2.0 (the
8ff12d537SAndre Fischer  * "License"); you may not use this file except in compliance
9ff12d537SAndre Fischer  * with the License.  You may obtain a copy of the License at
10ff12d537SAndre Fischer  *
11ff12d537SAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
12ff12d537SAndre Fischer  *
13ff12d537SAndre Fischer  * Unless required by applicable law or agreed to in writing,
14ff12d537SAndre Fischer  * software distributed under the License is distributed on an
15ff12d537SAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ff12d537SAndre Fischer  * KIND, either express or implied.  See the License for the
17ff12d537SAndre Fischer  * specific language governing permissions and limitations
18ff12d537SAndre Fischer  * under the License.
19ff12d537SAndre Fischer  *
20ff12d537SAndre Fischer  *************************************************************/
21ff12d537SAndre Fischer 
22ff12d537SAndre Fischer #include "precompiled_sfx2.hxx"
23ff12d537SAndre Fischer 
24ff12d537SAndre Fischer #include "PanelTitleBar.hxx"
25ff12d537SAndre Fischer 
26ff12d537SAndre Fischer #include "Paint.hxx"
27ff12d537SAndre Fischer #include "Panel.hxx"
28b9e67834SAndre Fischer #include "sfx2/sidebar/Theme.hxx"
29ff12d537SAndre Fischer 
30ff12d537SAndre Fischer #include <tools/svborder.hxx>
31ff12d537SAndre Fischer #include <vcl/gradient.hxx>
3295a18594SAndre Fischer #include <vcl/image.hxx>
3395a18594SAndre Fischer 
34*7a32b0c8SAndre Fischer #ifdef DEBUG
35*7a32b0c8SAndre Fischer #include "Tools.hxx"
36*7a32b0c8SAndre Fischer #endif
37*7a32b0c8SAndre Fischer 
38ff12d537SAndre Fischer 
39ff12d537SAndre Fischer namespace sfx2 { namespace sidebar {
40ff12d537SAndre Fischer 
41ff12d537SAndre Fischer 
42ff12d537SAndre Fischer static const sal_Int32 gaLeftIconPadding (5);
43ff12d537SAndre Fischer static const sal_Int32 gaRightIconPadding (5);
44ff12d537SAndre Fischer 
45ff12d537SAndre Fischer 
46ff12d537SAndre Fischer PanelTitleBar::PanelTitleBar (
47ff12d537SAndre Fischer     const ::rtl::OUString& rsTitle,
48ff12d537SAndre Fischer     Window* pParentWindow,
49*7a32b0c8SAndre Fischer     Panel* pPanel,
50*7a32b0c8SAndre Fischer     const ::boost::function<void(void)>& rMenuAction)
51*7a32b0c8SAndre Fischer     : TitleBar(rsTitle, pParentWindow, GetBackgroundPaint()),
52ff12d537SAndre Fischer       mbIsLeftButtonDown(false),
53*7a32b0c8SAndre Fischer       mpPanel(pPanel),
54*7a32b0c8SAndre Fischer       mnMenuItemIndex(1),
55*7a32b0c8SAndre Fischer       maMenuAction(rMenuAction)
56ff12d537SAndre Fischer {
57ff12d537SAndre Fischer     OSL_ASSERT(mpPanel != NULL);
58*7a32b0c8SAndre Fischer 
59*7a32b0c8SAndre Fischer     if (maMenuAction)
60*7a32b0c8SAndre Fischer     {
61*7a32b0c8SAndre Fischer         maToolBox.InsertItem(
62*7a32b0c8SAndre Fischer             mnMenuItemIndex,
63*7a32b0c8SAndre Fischer             Theme::GetImage(Theme::Image_PanelMenu));
64*7a32b0c8SAndre Fischer         maToolBox.SetOutStyle(TOOLBOX_STYLE_FLAT);
65*7a32b0c8SAndre Fischer     }
66*7a32b0c8SAndre Fischer 
67*7a32b0c8SAndre Fischer #ifdef DEBUG
68*7a32b0c8SAndre Fischer     SetText(A2S("PanelTitleBar"));
69*7a32b0c8SAndre Fischer #endif
70ff12d537SAndre Fischer }
71ff12d537SAndre Fischer 
72ff12d537SAndre Fischer 
73ff12d537SAndre Fischer 
74ff12d537SAndre Fischer 
75ff12d537SAndre Fischer PanelTitleBar::~PanelTitleBar (void)
76ff12d537SAndre Fischer {
77ff12d537SAndre Fischer }
78ff12d537SAndre Fischer 
79ff12d537SAndre Fischer 
80ff12d537SAndre Fischer 
81ff12d537SAndre Fischer 
82ff12d537SAndre Fischer Rectangle PanelTitleBar::GetTitleArea (const Rectangle& rTitleBarBox)
83ff12d537SAndre Fischer {
84ff12d537SAndre Fischer     if (mpPanel != NULL)
85ff12d537SAndre Fischer     {
86ff12d537SAndre Fischer         Image aImage (mpPanel->IsExpanded()
87b9e67834SAndre Fischer             ? Theme::GetImage(Theme::Image_Expand)
88b9e67834SAndre Fischer             : Theme::GetImage(Theme::Image_Collapse));
89ff12d537SAndre Fischer         return Rectangle(
90ff12d537SAndre Fischer             aImage.GetSizePixel().Width() + gaLeftIconPadding + gaRightIconPadding,
91ff12d537SAndre Fischer             rTitleBarBox.Top(),
92ff12d537SAndre Fischer             rTitleBarBox.Right(),
93ff12d537SAndre Fischer             rTitleBarBox.Bottom());
94ff12d537SAndre Fischer     }
95ff12d537SAndre Fischer     else
96ff12d537SAndre Fischer         return rTitleBarBox;
97ff12d537SAndre Fischer }
98ff12d537SAndre Fischer 
99ff12d537SAndre Fischer 
100ff12d537SAndre Fischer 
101ff12d537SAndre Fischer 
102ff12d537SAndre Fischer void PanelTitleBar::PaintDecoration (const Rectangle& rTitleBarBox)
103ff12d537SAndre Fischer {
104ff12d537SAndre Fischer     if (mpPanel != NULL)
105ff12d537SAndre Fischer     {
106ff12d537SAndre Fischer         Image aImage (mpPanel->IsExpanded()
10795a18594SAndre Fischer             ? Theme::GetImage(Theme::Image_Collapse)
10895a18594SAndre Fischer             : Theme::GetImage(Theme::Image_Expand));
109ff12d537SAndre Fischer         const Point aTopLeft (
110ff12d537SAndre Fischer             gaLeftIconPadding,
111ff12d537SAndre Fischer             (GetSizePixel().Height()-aImage.GetSizePixel().Height())/2);
112ff12d537SAndre Fischer         DrawImage(aTopLeft, aImage);
113ff12d537SAndre Fischer     }
114ff12d537SAndre Fischer }
115ff12d537SAndre Fischer 
116ff12d537SAndre Fischer 
117ff12d537SAndre Fischer 
118ff12d537SAndre Fischer 
119ff12d537SAndre Fischer Paint PanelTitleBar::GetBackgroundPaint (void)
120ff12d537SAndre Fischer {
121b9e67834SAndre Fischer     return Theme::GetPaint(Theme::Paint_PanelTitleBarBackground);
122ff12d537SAndre Fischer }
123ff12d537SAndre Fischer 
124ff12d537SAndre Fischer 
125ff12d537SAndre Fischer 
126ff12d537SAndre Fischer 
127ff12d537SAndre Fischer Color PanelTitleBar::GetTextColor (void)
128ff12d537SAndre Fischer {
129b9e67834SAndre Fischer     return Theme::GetColor(Theme::Color_PanelTitleFont);
130ff12d537SAndre Fischer }
131ff12d537SAndre Fischer 
132ff12d537SAndre Fischer 
133ff12d537SAndre Fischer 
134ff12d537SAndre Fischer 
135*7a32b0c8SAndre Fischer void PanelTitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex)
136*7a32b0c8SAndre Fischer {
137*7a32b0c8SAndre Fischer     if (nItemIndex == mnMenuItemIndex)
138*7a32b0c8SAndre Fischer         if (maMenuAction)
139*7a32b0c8SAndre Fischer             maMenuAction();
140*7a32b0c8SAndre Fischer }
141*7a32b0c8SAndre Fischer 
142*7a32b0c8SAndre Fischer 
143*7a32b0c8SAndre Fischer 
144*7a32b0c8SAndre Fischer 
145ff12d537SAndre Fischer void PanelTitleBar::MouseButtonDown (const MouseEvent& rMouseEvent)
146ff12d537SAndre Fischer {
147ff12d537SAndre Fischer     if (rMouseEvent.IsLeft())
148ff12d537SAndre Fischer     {
149ff12d537SAndre Fischer         mbIsLeftButtonDown = true;
150ff12d537SAndre Fischer         CaptureMouse();
151ff12d537SAndre Fischer     }
152ff12d537SAndre Fischer }
153ff12d537SAndre Fischer 
154ff12d537SAndre Fischer 
155ff12d537SAndre Fischer 
156ff12d537SAndre Fischer 
157ff12d537SAndre Fischer void PanelTitleBar::MouseButtonUp (const MouseEvent& rMouseEvent)
158ff12d537SAndre Fischer {
159ff12d537SAndre Fischer     if (IsMouseCaptured())
160ff12d537SAndre Fischer         ReleaseMouse();
161ff12d537SAndre Fischer 
162ff12d537SAndre Fischer     if (rMouseEvent.IsLeft())
163ff12d537SAndre Fischer     {
164ff12d537SAndre Fischer         if (mbIsLeftButtonDown)
165ff12d537SAndre Fischer         {
166ff12d537SAndre Fischer             if (mpPanel != NULL)
167ff12d537SAndre Fischer             {
168ff12d537SAndre Fischer                 mpPanel->SetExpanded( ! mpPanel->IsExpanded());
169ff12d537SAndre Fischer                 Invalidate();
170ff12d537SAndre Fischer             }
171ff12d537SAndre Fischer         }
172ff12d537SAndre Fischer     }
173ff12d537SAndre Fischer     if (mbIsLeftButtonDown)
174ff12d537SAndre Fischer         mbIsLeftButtonDown = false;
175ff12d537SAndre Fischer }
176ff12d537SAndre Fischer 
177ff12d537SAndre Fischer 
178ff12d537SAndre Fischer 
179*7a32b0c8SAndre Fischer 
180*7a32b0c8SAndre Fischer void PanelTitleBar::DataChanged (const DataChangedEvent& rEvent)
181*7a32b0c8SAndre Fischer {
182*7a32b0c8SAndre Fischer     maToolBox.SetItemImage(
183*7a32b0c8SAndre Fischer         mnMenuItemIndex,
184*7a32b0c8SAndre Fischer         Theme::GetImage(Theme::Image_PanelMenu));
185*7a32b0c8SAndre Fischer }
186*7a32b0c8SAndre Fischer 
187ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar
188