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"
25*abdd804dSAndre Fischer #include "sfx2/sfxresid.hxx"
26*abdd804dSAndre Fischer #include "Sidebar.hrc"
27ff12d537SAndre Fischer 
28ff12d537SAndre Fischer #include "Paint.hxx"
29ff12d537SAndre Fischer #include "Panel.hxx"
30b9e67834SAndre Fischer #include "sfx2/sidebar/Theme.hxx"
31ff12d537SAndre Fischer 
32ff12d537SAndre Fischer #include <tools/svborder.hxx>
33ff12d537SAndre Fischer #include <vcl/gradient.hxx>
3495a18594SAndre Fischer #include <vcl/image.hxx>
3595a18594SAndre Fischer 
367a32b0c8SAndre Fischer #ifdef DEBUG
37f35c6d02SAndre Fischer #include "sfx2/sidebar/Tools.hxx"
387a32b0c8SAndre Fischer #endif
397a32b0c8SAndre Fischer 
40ff12d537SAndre Fischer 
41ff12d537SAndre Fischer namespace sfx2 { namespace sidebar {
42ff12d537SAndre Fischer 
43ff12d537SAndre Fischer 
44ff12d537SAndre Fischer static const sal_Int32 gaLeftIconPadding (5);
45ff12d537SAndre Fischer static const sal_Int32 gaRightIconPadding (5);
46ff12d537SAndre Fischer 
47ff12d537SAndre Fischer 
48ff12d537SAndre Fischer PanelTitleBar::PanelTitleBar (
49ff12d537SAndre Fischer     const ::rtl::OUString& rsTitle,
50ff12d537SAndre Fischer     Window* pParentWindow,
51c545150fSOliver-Rainer Wittmann     Panel* pPanel )
527a32b0c8SAndre Fischer     : TitleBar(rsTitle, pParentWindow, GetBackgroundPaint()),
53ff12d537SAndre Fischer       mbIsLeftButtonDown(false),
547a32b0c8SAndre Fischer       mpPanel(pPanel),
557a32b0c8SAndre Fischer       mnMenuItemIndex(1),
56c545150fSOliver-Rainer Wittmann       maMenuAction()
57ff12d537SAndre Fischer {
58ff12d537SAndre Fischer     OSL_ASSERT(mpPanel != NULL);
597a32b0c8SAndre Fischer 
607a32b0c8SAndre Fischer #ifdef DEBUG
617a32b0c8SAndre Fischer     SetText(A2S("PanelTitleBar"));
627a32b0c8SAndre Fischer #endif
63ff12d537SAndre Fischer }
64ff12d537SAndre Fischer 
65ff12d537SAndre Fischer 
66ff12d537SAndre Fischer 
67ff12d537SAndre Fischer 
68ff12d537SAndre Fischer PanelTitleBar::~PanelTitleBar (void)
69ff12d537SAndre Fischer {
70ff12d537SAndre Fischer }
71ff12d537SAndre Fischer 
72ff12d537SAndre Fischer 
73ff12d537SAndre Fischer 
74ff12d537SAndre Fischer 
75c545150fSOliver-Rainer Wittmann void PanelTitleBar::SetMenuAction ( const ::boost::function<void(void)>& rMenuAction )
76c545150fSOliver-Rainer Wittmann {
77c545150fSOliver-Rainer Wittmann     if ( !maMenuAction && rMenuAction )
78c545150fSOliver-Rainer Wittmann     {
79c545150fSOliver-Rainer Wittmann         maToolBox.InsertItem(
80c545150fSOliver-Rainer Wittmann             mnMenuItemIndex,
81c545150fSOliver-Rainer Wittmann             Theme::GetImage(Theme::Image_PanelMenu));
82c545150fSOliver-Rainer Wittmann         maToolBox.SetOutStyle(TOOLBOX_STYLE_FLAT);
83*abdd804dSAndre Fischer         maToolBox.SetQuickHelpText(
84*abdd804dSAndre Fischer             mnMenuItemIndex,
85*abdd804dSAndre Fischer             String(SfxResId(SFX_STR_SIDEBAR_MORE_OPTIONS)));
86c545150fSOliver-Rainer Wittmann     }
87c545150fSOliver-Rainer Wittmann     else if ( maMenuAction && !rMenuAction )
88c545150fSOliver-Rainer Wittmann     {
89c545150fSOliver-Rainer Wittmann         maToolBox.RemoveItem( maToolBox.GetItemPos( mnMenuItemIndex ) );
90c545150fSOliver-Rainer Wittmann     }
91c545150fSOliver-Rainer Wittmann     maMenuAction = rMenuAction;
92c545150fSOliver-Rainer Wittmann }
93c545150fSOliver-Rainer Wittmann 
94c545150fSOliver-Rainer Wittmann 
95c545150fSOliver-Rainer Wittmann 
96c545150fSOliver-Rainer Wittmann 
97ff12d537SAndre Fischer Rectangle PanelTitleBar::GetTitleArea (const Rectangle& rTitleBarBox)
98ff12d537SAndre Fischer {
99ff12d537SAndre Fischer     if (mpPanel != NULL)
100ff12d537SAndre Fischer     {
101ff12d537SAndre Fischer         Image aImage (mpPanel->IsExpanded()
102b9e67834SAndre Fischer             ? Theme::GetImage(Theme::Image_Expand)
103b9e67834SAndre Fischer             : Theme::GetImage(Theme::Image_Collapse));
104ff12d537SAndre Fischer         return Rectangle(
105ff12d537SAndre Fischer             aImage.GetSizePixel().Width() + gaLeftIconPadding + gaRightIconPadding,
106ff12d537SAndre Fischer             rTitleBarBox.Top(),
107ff12d537SAndre Fischer             rTitleBarBox.Right(),
108ff12d537SAndre Fischer             rTitleBarBox.Bottom());
109ff12d537SAndre Fischer     }
110ff12d537SAndre Fischer     else
111ff12d537SAndre Fischer         return rTitleBarBox;
112ff12d537SAndre Fischer }
113ff12d537SAndre Fischer 
114ff12d537SAndre Fischer 
115ff12d537SAndre Fischer 
116ff12d537SAndre Fischer 
117ff12d537SAndre Fischer void PanelTitleBar::PaintDecoration (const Rectangle& rTitleBarBox)
118ff12d537SAndre Fischer {
11902c50d82SAndre Fischer     (void)rTitleBarBox;
12002c50d82SAndre Fischer 
121ff12d537SAndre Fischer     if (mpPanel != NULL)
122ff12d537SAndre Fischer     {
123ff12d537SAndre Fischer         Image aImage (mpPanel->IsExpanded()
12495a18594SAndre Fischer             ? Theme::GetImage(Theme::Image_Collapse)
12595a18594SAndre Fischer             : Theme::GetImage(Theme::Image_Expand));
126ff12d537SAndre Fischer         const Point aTopLeft (
127ff12d537SAndre Fischer             gaLeftIconPadding,
128ff12d537SAndre Fischer             (GetSizePixel().Height()-aImage.GetSizePixel().Height())/2);
129ff12d537SAndre Fischer         DrawImage(aTopLeft, aImage);
130ff12d537SAndre Fischer     }
131ff12d537SAndre Fischer }
132ff12d537SAndre Fischer 
133ff12d537SAndre Fischer 
134ff12d537SAndre Fischer 
135ff12d537SAndre Fischer 
136ff12d537SAndre Fischer Paint PanelTitleBar::GetBackgroundPaint (void)
137ff12d537SAndre Fischer {
138b9e67834SAndre Fischer     return Theme::GetPaint(Theme::Paint_PanelTitleBarBackground);
139ff12d537SAndre Fischer }
140ff12d537SAndre Fischer 
141ff12d537SAndre Fischer 
142ff12d537SAndre Fischer 
143ff12d537SAndre Fischer 
144ff12d537SAndre Fischer Color PanelTitleBar::GetTextColor (void)
145ff12d537SAndre Fischer {
146b9e67834SAndre Fischer     return Theme::GetColor(Theme::Color_PanelTitleFont);
147ff12d537SAndre Fischer }
148ff12d537SAndre Fischer 
149ff12d537SAndre Fischer 
150ff12d537SAndre Fischer 
151ff12d537SAndre Fischer 
1527a32b0c8SAndre Fischer void PanelTitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex)
1537a32b0c8SAndre Fischer {
1547a32b0c8SAndre Fischer     if (nItemIndex == mnMenuItemIndex)
1557a32b0c8SAndre Fischer         if (maMenuAction)
1567a32b0c8SAndre Fischer             maMenuAction();
1577a32b0c8SAndre Fischer }
1587a32b0c8SAndre Fischer 
1597a32b0c8SAndre Fischer 
1607a32b0c8SAndre Fischer 
1617a32b0c8SAndre Fischer 
162ff12d537SAndre Fischer void PanelTitleBar::MouseButtonDown (const MouseEvent& rMouseEvent)
163ff12d537SAndre Fischer {
164ff12d537SAndre Fischer     if (rMouseEvent.IsLeft())
165ff12d537SAndre Fischer     {
166ff12d537SAndre Fischer         mbIsLeftButtonDown = true;
167ff12d537SAndre Fischer         CaptureMouse();
168ff12d537SAndre Fischer     }
169ff12d537SAndre Fischer }
170ff12d537SAndre Fischer 
171ff12d537SAndre Fischer 
172ff12d537SAndre Fischer 
173ff12d537SAndre Fischer 
174ff12d537SAndre Fischer void PanelTitleBar::MouseButtonUp (const MouseEvent& rMouseEvent)
175ff12d537SAndre Fischer {
176ff12d537SAndre Fischer     if (IsMouseCaptured())
177ff12d537SAndre Fischer         ReleaseMouse();
178ff12d537SAndre Fischer 
179ff12d537SAndre Fischer     if (rMouseEvent.IsLeft())
180ff12d537SAndre Fischer     {
181ff12d537SAndre Fischer         if (mbIsLeftButtonDown)
182ff12d537SAndre Fischer         {
183ff12d537SAndre Fischer             if (mpPanel != NULL)
184ff12d537SAndre Fischer             {
185ff12d537SAndre Fischer                 mpPanel->SetExpanded( ! mpPanel->IsExpanded());
186ff12d537SAndre Fischer                 Invalidate();
187ff12d537SAndre Fischer             }
188ff12d537SAndre Fischer         }
189ff12d537SAndre Fischer     }
190ff12d537SAndre Fischer     if (mbIsLeftButtonDown)
191ff12d537SAndre Fischer         mbIsLeftButtonDown = false;
192ff12d537SAndre Fischer }
193ff12d537SAndre Fischer 
194ff12d537SAndre Fischer 
195ff12d537SAndre Fischer 
1967a32b0c8SAndre Fischer 
1977a32b0c8SAndre Fischer void PanelTitleBar::DataChanged (const DataChangedEvent& rEvent)
1987a32b0c8SAndre Fischer {
1997a32b0c8SAndre Fischer     maToolBox.SetItemImage(
2007a32b0c8SAndre Fischer         mnMenuItemIndex,
2017a32b0c8SAndre Fischer         Theme::GetImage(Theme::Image_PanelMenu));
202580828edSAndre Fischer     TitleBar::DataChanged(rEvent);
2037a32b0c8SAndre Fischer }
2047a32b0c8SAndre Fischer 
205ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar
206