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,
49*c545150fSOliver-Rainer Wittmann     Panel* pPanel )
507a32b0c8SAndre Fischer     : TitleBar(rsTitle, pParentWindow, GetBackgroundPaint()),
51ff12d537SAndre Fischer       mbIsLeftButtonDown(false),
527a32b0c8SAndre Fischer       mpPanel(pPanel),
537a32b0c8SAndre Fischer       mnMenuItemIndex(1),
54*c545150fSOliver-Rainer Wittmann       maMenuAction()
55ff12d537SAndre Fischer {
56ff12d537SAndre Fischer     OSL_ASSERT(mpPanel != NULL);
577a32b0c8SAndre Fischer 
587a32b0c8SAndre Fischer #ifdef DEBUG
597a32b0c8SAndre Fischer     SetText(A2S("PanelTitleBar"));
607a32b0c8SAndre Fischer #endif
61ff12d537SAndre Fischer }
62ff12d537SAndre Fischer 
63ff12d537SAndre Fischer 
64ff12d537SAndre Fischer 
65ff12d537SAndre Fischer 
66ff12d537SAndre Fischer PanelTitleBar::~PanelTitleBar (void)
67ff12d537SAndre Fischer {
68ff12d537SAndre Fischer }
69ff12d537SAndre Fischer 
70ff12d537SAndre Fischer 
71ff12d537SAndre Fischer 
72ff12d537SAndre Fischer 
73*c545150fSOliver-Rainer Wittmann void PanelTitleBar::SetMenuAction ( const ::boost::function<void(void)>& rMenuAction )
74*c545150fSOliver-Rainer Wittmann {
75*c545150fSOliver-Rainer Wittmann     if ( !maMenuAction && rMenuAction )
76*c545150fSOliver-Rainer Wittmann     {
77*c545150fSOliver-Rainer Wittmann         maToolBox.InsertItem(
78*c545150fSOliver-Rainer Wittmann             mnMenuItemIndex,
79*c545150fSOliver-Rainer Wittmann             Theme::GetImage(Theme::Image_PanelMenu));
80*c545150fSOliver-Rainer Wittmann         maToolBox.SetOutStyle(TOOLBOX_STYLE_FLAT);
81*c545150fSOliver-Rainer Wittmann     }
82*c545150fSOliver-Rainer Wittmann     else if ( maMenuAction && !rMenuAction )
83*c545150fSOliver-Rainer Wittmann     {
84*c545150fSOliver-Rainer Wittmann         maToolBox.RemoveItem( maToolBox.GetItemPos( mnMenuItemIndex ) );
85*c545150fSOliver-Rainer Wittmann     }
86*c545150fSOliver-Rainer Wittmann     maMenuAction = rMenuAction;
87*c545150fSOliver-Rainer Wittmann }
88*c545150fSOliver-Rainer Wittmann 
89*c545150fSOliver-Rainer Wittmann 
90*c545150fSOliver-Rainer Wittmann 
91*c545150fSOliver-Rainer Wittmann 
92ff12d537SAndre Fischer Rectangle PanelTitleBar::GetTitleArea (const Rectangle& rTitleBarBox)
93ff12d537SAndre Fischer {
94ff12d537SAndre Fischer     if (mpPanel != NULL)
95ff12d537SAndre Fischer     {
96ff12d537SAndre Fischer         Image aImage (mpPanel->IsExpanded()
97b9e67834SAndre Fischer             ? Theme::GetImage(Theme::Image_Expand)
98b9e67834SAndre Fischer             : Theme::GetImage(Theme::Image_Collapse));
99ff12d537SAndre Fischer         return Rectangle(
100ff12d537SAndre Fischer             aImage.GetSizePixel().Width() + gaLeftIconPadding + gaRightIconPadding,
101ff12d537SAndre Fischer             rTitleBarBox.Top(),
102ff12d537SAndre Fischer             rTitleBarBox.Right(),
103ff12d537SAndre Fischer             rTitleBarBox.Bottom());
104ff12d537SAndre Fischer     }
105ff12d537SAndre Fischer     else
106ff12d537SAndre Fischer         return rTitleBarBox;
107ff12d537SAndre Fischer }
108ff12d537SAndre Fischer 
109ff12d537SAndre Fischer 
110ff12d537SAndre Fischer 
111ff12d537SAndre Fischer 
112ff12d537SAndre Fischer void PanelTitleBar::PaintDecoration (const Rectangle& rTitleBarBox)
113ff12d537SAndre Fischer {
11402c50d82SAndre Fischer     (void)rTitleBarBox;
11502c50d82SAndre Fischer 
116ff12d537SAndre Fischer     if (mpPanel != NULL)
117ff12d537SAndre Fischer     {
118ff12d537SAndre Fischer         Image aImage (mpPanel->IsExpanded()
11995a18594SAndre Fischer             ? Theme::GetImage(Theme::Image_Collapse)
12095a18594SAndre Fischer             : Theme::GetImage(Theme::Image_Expand));
121ff12d537SAndre Fischer         const Point aTopLeft (
122ff12d537SAndre Fischer             gaLeftIconPadding,
123ff12d537SAndre Fischer             (GetSizePixel().Height()-aImage.GetSizePixel().Height())/2);
124ff12d537SAndre Fischer         DrawImage(aTopLeft, aImage);
125ff12d537SAndre Fischer     }
126ff12d537SAndre Fischer }
127ff12d537SAndre Fischer 
128ff12d537SAndre Fischer 
129ff12d537SAndre Fischer 
130ff12d537SAndre Fischer 
131ff12d537SAndre Fischer Paint PanelTitleBar::GetBackgroundPaint (void)
132ff12d537SAndre Fischer {
133b9e67834SAndre Fischer     return Theme::GetPaint(Theme::Paint_PanelTitleBarBackground);
134ff12d537SAndre Fischer }
135ff12d537SAndre Fischer 
136ff12d537SAndre Fischer 
137ff12d537SAndre Fischer 
138ff12d537SAndre Fischer 
139ff12d537SAndre Fischer Color PanelTitleBar::GetTextColor (void)
140ff12d537SAndre Fischer {
141b9e67834SAndre Fischer     return Theme::GetColor(Theme::Color_PanelTitleFont);
142ff12d537SAndre Fischer }
143ff12d537SAndre Fischer 
144ff12d537SAndre Fischer 
145ff12d537SAndre Fischer 
146ff12d537SAndre Fischer 
1477a32b0c8SAndre Fischer void PanelTitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex)
1487a32b0c8SAndre Fischer {
1497a32b0c8SAndre Fischer     if (nItemIndex == mnMenuItemIndex)
1507a32b0c8SAndre Fischer         if (maMenuAction)
1517a32b0c8SAndre Fischer             maMenuAction();
1527a32b0c8SAndre Fischer }
1537a32b0c8SAndre Fischer 
1547a32b0c8SAndre Fischer 
1557a32b0c8SAndre Fischer 
1567a32b0c8SAndre Fischer 
157ff12d537SAndre Fischer void PanelTitleBar::MouseButtonDown (const MouseEvent& rMouseEvent)
158ff12d537SAndre Fischer {
159ff12d537SAndre Fischer     if (rMouseEvent.IsLeft())
160ff12d537SAndre Fischer     {
161ff12d537SAndre Fischer         mbIsLeftButtonDown = true;
162ff12d537SAndre Fischer         CaptureMouse();
163ff12d537SAndre Fischer     }
164ff12d537SAndre Fischer }
165ff12d537SAndre Fischer 
166ff12d537SAndre Fischer 
167ff12d537SAndre Fischer 
168ff12d537SAndre Fischer 
169ff12d537SAndre Fischer void PanelTitleBar::MouseButtonUp (const MouseEvent& rMouseEvent)
170ff12d537SAndre Fischer {
171ff12d537SAndre Fischer     if (IsMouseCaptured())
172ff12d537SAndre Fischer         ReleaseMouse();
173ff12d537SAndre Fischer 
174ff12d537SAndre Fischer     if (rMouseEvent.IsLeft())
175ff12d537SAndre Fischer     {
176ff12d537SAndre Fischer         if (mbIsLeftButtonDown)
177ff12d537SAndre Fischer         {
178ff12d537SAndre Fischer             if (mpPanel != NULL)
179ff12d537SAndre Fischer             {
180ff12d537SAndre Fischer                 mpPanel->SetExpanded( ! mpPanel->IsExpanded());
181ff12d537SAndre Fischer                 Invalidate();
182ff12d537SAndre Fischer             }
183ff12d537SAndre Fischer         }
184ff12d537SAndre Fischer     }
185ff12d537SAndre Fischer     if (mbIsLeftButtonDown)
186ff12d537SAndre Fischer         mbIsLeftButtonDown = false;
187ff12d537SAndre Fischer }
188ff12d537SAndre Fischer 
189ff12d537SAndre Fischer 
190ff12d537SAndre Fischer 
1917a32b0c8SAndre Fischer 
1927a32b0c8SAndre Fischer void PanelTitleBar::DataChanged (const DataChangedEvent& rEvent)
1937a32b0c8SAndre Fischer {
1947a32b0c8SAndre Fischer     maToolBox.SetItemImage(
1957a32b0c8SAndre Fischer         mnMenuItemIndex,
1967a32b0c8SAndre Fischer         Theme::GetImage(Theme::Image_PanelMenu));
197580828edSAndre Fischer     TitleBar::DataChanged(rEvent);
1987a32b0c8SAndre Fischer }
1997a32b0c8SAndre Fischer 
200ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar
201