xref: /trunk/main/sfx2/source/sidebar/PanelTitleBar.cxx (revision 549760eabef7046a021eb562805aa3542b2e9b62)
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 #include "sfx2/sfxresid.hxx"
26 #include "Sidebar.hrc"
27 
28 #include "Paint.hxx"
29 #include "Panel.hxx"
30 #include "sfx2/sidebar/Theme.hxx"
31 #include "sfx2/sidebar/ControllerFactory.hxx"
32 #include "sfx2/sidebar/Tools.hxx"
33 #include <tools/svborder.hxx>
34 #include <vcl/gradient.hxx>
35 #include <vcl/image.hxx>
36 #include <toolkit/helper/vclunohelper.hxx>
37 
38 using namespace css;
39 using namespace cssu;
40 
41 namespace sfx2 { namespace sidebar {
42 
43 static const sal_Int32 gaLeftIconPadding (5);
44 static const sal_Int32 gaRightIconPadding (5);
45 
PanelTitleBar(const::rtl::OUString & rsTitle,Window * pParentWindow,Panel * pPanel)46 PanelTitleBar::PanelTitleBar (
47     const ::rtl::OUString& rsTitle,
48     Window* pParentWindow,
49     Panel* pPanel)
50     : TitleBar(rsTitle, pParentWindow, GetBackgroundPaint()),
51       mbIsLeftButtonDown(false),
52       mpPanel(pPanel),
53       mnMenuItemIndex(1),
54       mxFrame(),
55       msMoreOptionsCommand(),
56       msAccessibleNamePrefix(String(SfxResId(SFX_STR_SIDEBAR_ACCESSIBILITY_PANEL_PREFIX)))
57 {
58     OSL_ASSERT(mpPanel != NULL);
59 
60 #ifdef DEBUG
61     SetText(A2S("PanelTitleBar"));
62 #endif
63 }
64 
~PanelTitleBar(void)65 PanelTitleBar::~PanelTitleBar (void)
66 {
67 }
68 
SetMoreOptionsCommand(const::rtl::OUString & rsCommandName,const::cssu::Reference<css::frame::XFrame> & rxFrame)69 void PanelTitleBar::SetMoreOptionsCommand (
70     const ::rtl::OUString& rsCommandName,
71     const ::cssu::Reference<css::frame::XFrame>& rxFrame)
72 {
73     if ( ! rsCommandName.equals(msMoreOptionsCommand))
74     {
75         if (msMoreOptionsCommand.getLength() > 0)
76             maToolBox.RemoveItem(maToolBox.GetItemPos(mnMenuItemIndex));
77 
78         msMoreOptionsCommand = rsCommandName;
79         mxFrame = rxFrame;
80 
81         if (msMoreOptionsCommand.getLength() > 0)
82         {
83             maToolBox.InsertItem(
84                 mnMenuItemIndex,
85                 Theme::GetImage(Theme::Image_PanelMenu));
86             Reference<frame::XToolbarController> xController (
87                 ControllerFactory::CreateToolBoxController(
88                     &maToolBox,
89                     mnMenuItemIndex,
90                     msMoreOptionsCommand,
91                     rxFrame,
92                     VCLUnoHelper::GetInterface(&maToolBox),
93                     0));
94             maToolBox.SetController(mnMenuItemIndex, xController, msMoreOptionsCommand);
95             maToolBox.SetOutStyle(TOOLBOX_STYLE_FLAT);
96             maToolBox.SetQuickHelpText(
97                 mnMenuItemIndex,
98                 String(SfxResId(SFX_STR_SIDEBAR_MORE_OPTIONS)));
99         }
100     }
101 }
102 
GetTitleArea(const Rectangle & rTitleBarBox)103 Rectangle PanelTitleBar::GetTitleArea (const Rectangle& rTitleBarBox)
104 {
105     if (mpPanel != NULL)
106     {
107         Image aImage (mpPanel->IsExpanded()
108             ? Theme::GetImage(Theme::Image_Expand)
109             : Theme::GetImage(Theme::Image_Collapse));
110         return Rectangle(
111             aImage.GetSizePixel().Width() + gaLeftIconPadding + gaRightIconPadding,
112             rTitleBarBox.Top(),
113             rTitleBarBox.Right(),
114             rTitleBarBox.Bottom());
115     }
116     else
117         return rTitleBarBox;
118 }
119 
PaintDecoration(const Rectangle & rTitleBarBox)120 void PanelTitleBar::PaintDecoration (const Rectangle& rTitleBarBox)
121 {
122     (void)rTitleBarBox;
123 
124     if (mpPanel != NULL)
125     {
126         Image aImage (mpPanel->IsExpanded()
127             ? Theme::GetImage(Theme::Image_Collapse)
128             : Theme::GetImage(Theme::Image_Expand));
129         const Point aTopLeft (
130             gaLeftIconPadding,
131             (GetSizePixel().Height()-aImage.GetSizePixel().Height())/2);
132         DrawImage(aTopLeft, aImage);
133     }
134 }
135 
GetBackgroundPaint(void)136 Paint PanelTitleBar::GetBackgroundPaint (void)
137 {
138     return Theme::GetPaint(Theme::Paint_PanelTitleBarBackground);
139 }
140 
GetTextColor(void)141 Color PanelTitleBar::GetTextColor (void)
142 {
143     return Theme::GetColor(Theme::Color_PanelTitleFont);
144 }
145 
HandleToolBoxItemClick(const sal_uInt16 nItemIndex)146 void PanelTitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex)
147 {
148     if (nItemIndex == mnMenuItemIndex)
149         if (msMoreOptionsCommand.getLength() > 0)
150         {
151             try
152             {
153                 const util::URL aURL (Tools::GetURL(msMoreOptionsCommand));
154                 Reference<frame::XDispatch> xDispatch (Tools::GetDispatch(mxFrame, aURL));
155                 if (xDispatch.is())
156                     xDispatch->dispatch(aURL, Sequence<beans::PropertyValue>());
157             }
158             catch(Exception& rException)
159             {
160                 OSL_TRACE("caught exception: %s",
161                     OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr());
162             }
163         }
164 }
165 
CreateAccessible(void)166 Reference<accessibility::XAccessible> PanelTitleBar::CreateAccessible (void)
167 {
168     const ::rtl::OUString sAccessibleName(msAccessibleNamePrefix + msTitle);
169     SetAccessibleName(sAccessibleName);
170     SetAccessibleDescription(sAccessibleName);
171     return TitleBar::CreateAccessible();
172 }
173 
MouseButtonDown(const MouseEvent & rMouseEvent)174 void PanelTitleBar::MouseButtonDown (const MouseEvent& rMouseEvent)
175 {
176     if (rMouseEvent.IsLeft())
177     {
178         mbIsLeftButtonDown = true;
179         CaptureMouse();
180     }
181 }
182 
MouseButtonUp(const MouseEvent & rMouseEvent)183 void PanelTitleBar::MouseButtonUp (const MouseEvent& rMouseEvent)
184 {
185     if (IsMouseCaptured())
186         ReleaseMouse();
187 
188     if (rMouseEvent.IsLeft())
189     {
190         if (mbIsLeftButtonDown)
191         {
192             if (mpPanel != NULL)
193             {
194                 mpPanel->SetExpanded( ! mpPanel->IsExpanded());
195                 Invalidate();
196             }
197         }
198     }
199     if (mbIsLeftButtonDown)
200         mbIsLeftButtonDown = false;
201 }
202 
DataChanged(const DataChangedEvent & rEvent)203 void PanelTitleBar::DataChanged (const DataChangedEvent& rEvent)
204 {
205     maToolBox.SetItemImage(
206         mnMenuItemIndex,
207         Theme::GetImage(Theme::Image_PanelMenu));
208     TitleBar::DataChanged(rEvent);
209 }
210 
211 } } // end of namespace sfx2::sidebar
212 
213 /* vim: set noet sw=4 ts=4: */
214