xref: /AOO41X/main/sfx2/source/sidebar/PanelTitleBar.cxx (revision 02c50d825b93d3e4e3bd9073db30bd7615e748eb)
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 
347a32b0c8SAndre Fischer #ifdef DEBUG
357a32b0c8SAndre Fischer #include "Tools.hxx"
367a32b0c8SAndre Fischer #endif
377a32b0c8SAndre 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,
497a32b0c8SAndre Fischer     Panel* pPanel,
507a32b0c8SAndre Fischer     const ::boost::function<void(void)>& rMenuAction)
517a32b0c8SAndre Fischer     : TitleBar(rsTitle, pParentWindow, GetBackgroundPaint()),
52ff12d537SAndre Fischer       mbIsLeftButtonDown(false),
537a32b0c8SAndre Fischer       mpPanel(pPanel),
547a32b0c8SAndre Fischer       mnMenuItemIndex(1),
557a32b0c8SAndre Fischer       maMenuAction(rMenuAction)
56ff12d537SAndre Fischer {
57ff12d537SAndre Fischer     OSL_ASSERT(mpPanel != NULL);
587a32b0c8SAndre Fischer 
597a32b0c8SAndre Fischer     if (maMenuAction)
607a32b0c8SAndre Fischer     {
617a32b0c8SAndre Fischer         maToolBox.InsertItem(
627a32b0c8SAndre Fischer             mnMenuItemIndex,
637a32b0c8SAndre Fischer             Theme::GetImage(Theme::Image_PanelMenu));
647a32b0c8SAndre Fischer         maToolBox.SetOutStyle(TOOLBOX_STYLE_FLAT);
657a32b0c8SAndre Fischer     }
667a32b0c8SAndre Fischer 
677a32b0c8SAndre Fischer #ifdef DEBUG
687a32b0c8SAndre Fischer     SetText(A2S("PanelTitleBar"));
697a32b0c8SAndre 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 {
104*02c50d82SAndre Fischer     (void)rTitleBarBox;
105*02c50d82SAndre Fischer 
106ff12d537SAndre Fischer     if (mpPanel != NULL)
107ff12d537SAndre Fischer     {
108ff12d537SAndre Fischer         Image aImage (mpPanel->IsExpanded()
10995a18594SAndre Fischer             ? Theme::GetImage(Theme::Image_Collapse)
11095a18594SAndre Fischer             : Theme::GetImage(Theme::Image_Expand));
111ff12d537SAndre Fischer         const Point aTopLeft (
112ff12d537SAndre Fischer             gaLeftIconPadding,
113ff12d537SAndre Fischer             (GetSizePixel().Height()-aImage.GetSizePixel().Height())/2);
114ff12d537SAndre Fischer         DrawImage(aTopLeft, aImage);
115ff12d537SAndre Fischer     }
116ff12d537SAndre Fischer }
117ff12d537SAndre Fischer 
118ff12d537SAndre Fischer 
119ff12d537SAndre Fischer 
120ff12d537SAndre Fischer 
121ff12d537SAndre Fischer Paint PanelTitleBar::GetBackgroundPaint (void)
122ff12d537SAndre Fischer {
123b9e67834SAndre Fischer     return Theme::GetPaint(Theme::Paint_PanelTitleBarBackground);
124ff12d537SAndre Fischer }
125ff12d537SAndre Fischer 
126ff12d537SAndre Fischer 
127ff12d537SAndre Fischer 
128ff12d537SAndre Fischer 
129ff12d537SAndre Fischer Color PanelTitleBar::GetTextColor (void)
130ff12d537SAndre Fischer {
131b9e67834SAndre Fischer     return Theme::GetColor(Theme::Color_PanelTitleFont);
132ff12d537SAndre Fischer }
133ff12d537SAndre Fischer 
134ff12d537SAndre Fischer 
135ff12d537SAndre Fischer 
136ff12d537SAndre Fischer 
1377a32b0c8SAndre Fischer void PanelTitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex)
1387a32b0c8SAndre Fischer {
1397a32b0c8SAndre Fischer     if (nItemIndex == mnMenuItemIndex)
1407a32b0c8SAndre Fischer         if (maMenuAction)
1417a32b0c8SAndre Fischer             maMenuAction();
1427a32b0c8SAndre Fischer }
1437a32b0c8SAndre Fischer 
1447a32b0c8SAndre Fischer 
1457a32b0c8SAndre Fischer 
1467a32b0c8SAndre Fischer 
147ff12d537SAndre Fischer void PanelTitleBar::MouseButtonDown (const MouseEvent& rMouseEvent)
148ff12d537SAndre Fischer {
149ff12d537SAndre Fischer     if (rMouseEvent.IsLeft())
150ff12d537SAndre Fischer     {
151ff12d537SAndre Fischer         mbIsLeftButtonDown = true;
152ff12d537SAndre Fischer         CaptureMouse();
153ff12d537SAndre Fischer     }
154ff12d537SAndre Fischer }
155ff12d537SAndre Fischer 
156ff12d537SAndre Fischer 
157ff12d537SAndre Fischer 
158ff12d537SAndre Fischer 
159ff12d537SAndre Fischer void PanelTitleBar::MouseButtonUp (const MouseEvent& rMouseEvent)
160ff12d537SAndre Fischer {
161ff12d537SAndre Fischer     if (IsMouseCaptured())
162ff12d537SAndre Fischer         ReleaseMouse();
163ff12d537SAndre Fischer 
164ff12d537SAndre Fischer     if (rMouseEvent.IsLeft())
165ff12d537SAndre Fischer     {
166ff12d537SAndre Fischer         if (mbIsLeftButtonDown)
167ff12d537SAndre Fischer         {
168ff12d537SAndre Fischer             if (mpPanel != NULL)
169ff12d537SAndre Fischer             {
170ff12d537SAndre Fischer                 mpPanel->SetExpanded( ! mpPanel->IsExpanded());
171ff12d537SAndre Fischer                 Invalidate();
172ff12d537SAndre Fischer             }
173ff12d537SAndre Fischer         }
174ff12d537SAndre Fischer     }
175ff12d537SAndre Fischer     if (mbIsLeftButtonDown)
176ff12d537SAndre Fischer         mbIsLeftButtonDown = false;
177ff12d537SAndre Fischer }
178ff12d537SAndre Fischer 
179ff12d537SAndre Fischer 
180ff12d537SAndre Fischer 
1817a32b0c8SAndre Fischer 
1827a32b0c8SAndre Fischer void PanelTitleBar::DataChanged (const DataChangedEvent& rEvent)
1837a32b0c8SAndre Fischer {
1847a32b0c8SAndre Fischer     maToolBox.SetItemImage(
1857a32b0c8SAndre Fischer         mnMenuItemIndex,
1867a32b0c8SAndre Fischer         Theme::GetImage(Theme::Image_PanelMenu));
187580828edSAndre Fischer     TitleBar::DataChanged(rEvent);
1887a32b0c8SAndre Fischer }
1897a32b0c8SAndre Fischer 
190ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar
191