xref: /AOO42X/main/sfx2/source/sidebar/PanelTitleBar.cxx (revision 055746153e5cd78346b485d23b1c8e3408d513f1)
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"
25abdd804dSAndre Fischer #include "sfx2/sfxresid.hxx"
26abdd804dSAndre Fischer #include "Sidebar.hrc"
27ff12d537SAndre Fischer 
28ff12d537SAndre Fischer #include "Paint.hxx"
29ff12d537SAndre Fischer #include "Panel.hxx"
30b9e67834SAndre Fischer #include "sfx2/sidebar/Theme.hxx"
318a1a651aSAndre Fischer #include "sfx2/sidebar/ControllerFactory.hxx"
3288f32a2cSAndre Fischer #include "sfx2/sidebar/Tools.hxx"
33ff12d537SAndre Fischer #include <tools/svborder.hxx>
34ff12d537SAndre Fischer #include <vcl/gradient.hxx>
3595a18594SAndre Fischer #include <vcl/image.hxx>
368a1a651aSAndre Fischer #include <toolkit/helper/vclunohelper.hxx>
3795a18594SAndre Fischer 
388a1a651aSAndre Fischer using namespace css;
398a1a651aSAndre Fischer using namespace cssu;
40ff12d537SAndre Fischer 
41ff12d537SAndre Fischer namespace sfx2 { namespace sidebar {
42ff12d537SAndre Fischer 
43ff12d537SAndre Fischer static const sal_Int32 gaLeftIconPadding (5);
44ff12d537SAndre Fischer static const sal_Int32 gaRightIconPadding (5);
45ff12d537SAndre Fischer 
PanelTitleBar(const::rtl::OUString & rsTitle,Window * pParentWindow,Panel * pPanel)46ff12d537SAndre Fischer PanelTitleBar::PanelTitleBar (
47ff12d537SAndre Fischer     const ::rtl::OUString& rsTitle,
48ff12d537SAndre Fischer     Window* pParentWindow,
49c545150fSOliver-Rainer Wittmann     Panel* pPanel)
507a32b0c8SAndre Fischer     : TitleBar(rsTitle, pParentWindow, GetBackgroundPaint()),
51ff12d537SAndre Fischer       mbIsLeftButtonDown(false),
527a32b0c8SAndre Fischer       mpPanel(pPanel),
537a32b0c8SAndre Fischer       mnMenuItemIndex(1),
548a1a651aSAndre Fischer       mxFrame(),
553b2c5b9dSAndre Fischer       msMoreOptionsCommand(),
563b2c5b9dSAndre Fischer       msAccessibleNamePrefix(String(SfxResId(SFX_STR_SIDEBAR_ACCESSIBILITY_PANEL_PREFIX)))
57ff12d537SAndre Fischer {
58ff12d537SAndre Fischer     OSL_ASSERT(mpPanel != NULL);
59a5516503SAndre Fischer 
607a32b0c8SAndre Fischer #ifdef DEBUG
617a32b0c8SAndre Fischer     SetText(A2S("PanelTitleBar"));
627a32b0c8SAndre Fischer #endif
63ff12d537SAndre Fischer }
64ff12d537SAndre Fischer 
~PanelTitleBar(void)65ff12d537SAndre Fischer PanelTitleBar::~PanelTitleBar (void)
66ff12d537SAndre Fischer {
67ff12d537SAndre Fischer }
68ff12d537SAndre Fischer 
SetMoreOptionsCommand(const::rtl::OUString & rsCommandName,const::cssu::Reference<css::frame::XFrame> & rxFrame)698a1a651aSAndre Fischer void PanelTitleBar::SetMoreOptionsCommand (
708a1a651aSAndre Fischer     const ::rtl::OUString& rsCommandName,
718a1a651aSAndre Fischer     const ::cssu::Reference<css::frame::XFrame>& rxFrame)
72c545150fSOliver-Rainer Wittmann {
738a1a651aSAndre Fischer     if ( ! rsCommandName.equals(msMoreOptionsCommand))
748a1a651aSAndre Fischer     {
758a1a651aSAndre Fischer         if (msMoreOptionsCommand.getLength() > 0)
768a1a651aSAndre Fischer             maToolBox.RemoveItem(maToolBox.GetItemPos(mnMenuItemIndex));
778a1a651aSAndre Fischer 
788a1a651aSAndre Fischer         msMoreOptionsCommand = rsCommandName;
798a1a651aSAndre Fischer         mxFrame = rxFrame;
808a1a651aSAndre Fischer 
818a1a651aSAndre Fischer         if (msMoreOptionsCommand.getLength() > 0)
82c545150fSOliver-Rainer Wittmann         {
83c545150fSOliver-Rainer Wittmann             maToolBox.InsertItem(
84c545150fSOliver-Rainer Wittmann                 mnMenuItemIndex,
85c545150fSOliver-Rainer Wittmann                 Theme::GetImage(Theme::Image_PanelMenu));
868a1a651aSAndre Fischer             Reference<frame::XToolbarController> xController (
878a1a651aSAndre Fischer                 ControllerFactory::CreateToolBoxController(
888a1a651aSAndre Fischer                     &maToolBox,
898a1a651aSAndre Fischer                     mnMenuItemIndex,
908a1a651aSAndre Fischer                     msMoreOptionsCommand,
918a1a651aSAndre Fischer                     rxFrame,
928a1a651aSAndre Fischer                     VCLUnoHelper::GetInterface(&maToolBox),
938a1a651aSAndre Fischer                     0));
948a1a651aSAndre Fischer             maToolBox.SetController(mnMenuItemIndex, xController, msMoreOptionsCommand);
95c545150fSOliver-Rainer Wittmann             maToolBox.SetOutStyle(TOOLBOX_STYLE_FLAT);
96abdd804dSAndre Fischer             maToolBox.SetQuickHelpText(
97abdd804dSAndre Fischer                 mnMenuItemIndex,
98abdd804dSAndre Fischer                 String(SfxResId(SFX_STR_SIDEBAR_MORE_OPTIONS)));
99c545150fSOliver-Rainer Wittmann         }
100c545150fSOliver-Rainer Wittmann     }
101c545150fSOliver-Rainer Wittmann }
102c545150fSOliver-Rainer Wittmann 
GetTitleArea(const Rectangle & rTitleBarBox)103ff12d537SAndre Fischer Rectangle PanelTitleBar::GetTitleArea (const Rectangle& rTitleBarBox)
104ff12d537SAndre Fischer {
105ff12d537SAndre Fischer     if (mpPanel != NULL)
106ff12d537SAndre Fischer     {
107ff12d537SAndre Fischer         Image aImage (mpPanel->IsExpanded()
108b9e67834SAndre Fischer             ? Theme::GetImage(Theme::Image_Expand)
109b9e67834SAndre Fischer             : Theme::GetImage(Theme::Image_Collapse));
110ff12d537SAndre Fischer         return Rectangle(
111ff12d537SAndre Fischer             aImage.GetSizePixel().Width() + gaLeftIconPadding + gaRightIconPadding,
112ff12d537SAndre Fischer             rTitleBarBox.Top(),
113ff12d537SAndre Fischer             rTitleBarBox.Right(),
114ff12d537SAndre Fischer             rTitleBarBox.Bottom());
115ff12d537SAndre Fischer     }
116ff12d537SAndre Fischer     else
117ff12d537SAndre Fischer         return rTitleBarBox;
118ff12d537SAndre Fischer }
119ff12d537SAndre Fischer 
PaintDecoration(const Rectangle & rTitleBarBox)120ff12d537SAndre Fischer void PanelTitleBar::PaintDecoration (const Rectangle& rTitleBarBox)
121ff12d537SAndre Fischer {
12202c50d82SAndre Fischer     (void)rTitleBarBox;
12302c50d82SAndre Fischer 
124ff12d537SAndre Fischer     if (mpPanel != NULL)
125ff12d537SAndre Fischer     {
126ff12d537SAndre Fischer         Image aImage (mpPanel->IsExpanded()
12795a18594SAndre Fischer             ? Theme::GetImage(Theme::Image_Collapse)
12895a18594SAndre Fischer             : Theme::GetImage(Theme::Image_Expand));
129ff12d537SAndre Fischer         const Point aTopLeft (
130ff12d537SAndre Fischer             gaLeftIconPadding,
131ff12d537SAndre Fischer             (GetSizePixel().Height()-aImage.GetSizePixel().Height())/2);
132ff12d537SAndre Fischer         DrawImage(aTopLeft, aImage);
133ff12d537SAndre Fischer     }
134ff12d537SAndre Fischer }
135ff12d537SAndre Fischer 
GetBackgroundPaint(void)136ff12d537SAndre Fischer Paint PanelTitleBar::GetBackgroundPaint (void)
137ff12d537SAndre Fischer {
138b9e67834SAndre Fischer     return Theme::GetPaint(Theme::Paint_PanelTitleBarBackground);
139ff12d537SAndre Fischer }
140ff12d537SAndre Fischer 
GetTextColor(void)141ff12d537SAndre Fischer Color PanelTitleBar::GetTextColor (void)
142ff12d537SAndre Fischer {
143b9e67834SAndre Fischer     return Theme::GetColor(Theme::Color_PanelTitleFont);
144ff12d537SAndre Fischer }
145ff12d537SAndre Fischer 
HandleToolBoxItemClick(const sal_uInt16 nItemIndex)1467a32b0c8SAndre Fischer void PanelTitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex)
1477a32b0c8SAndre Fischer {
1487a32b0c8SAndre Fischer     if (nItemIndex == mnMenuItemIndex)
1498a1a651aSAndre Fischer         if (msMoreOptionsCommand.getLength() > 0)
1508a1a651aSAndre Fischer         {
1518a1a651aSAndre Fischer             try
1528a1a651aSAndre Fischer             {
1538a1a651aSAndre Fischer                 const util::URL aURL (Tools::GetURL(msMoreOptionsCommand));
1548a1a651aSAndre Fischer                 Reference<frame::XDispatch> xDispatch (Tools::GetDispatch(mxFrame, aURL));
1558a1a651aSAndre Fischer                 if (xDispatch.is())
1568a1a651aSAndre Fischer                     xDispatch->dispatch(aURL, Sequence<beans::PropertyValue>());
1578a1a651aSAndre Fischer             }
1588a1a651aSAndre Fischer             catch(Exception& rException)
1598a1a651aSAndre Fischer             {
1608a1a651aSAndre Fischer                 OSL_TRACE("caught exception: %s",
1618a1a651aSAndre Fischer                     OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr());
1628a1a651aSAndre Fischer             }
1638a1a651aSAndre Fischer         }
1647a32b0c8SAndre Fischer }
1657a32b0c8SAndre Fischer 
CreateAccessible(void)1663b2c5b9dSAndre Fischer Reference<accessibility::XAccessible> PanelTitleBar::CreateAccessible (void)
1673b2c5b9dSAndre Fischer {
1683b2c5b9dSAndre Fischer     const ::rtl::OUString sAccessibleName(msAccessibleNamePrefix + msTitle);
1693b2c5b9dSAndre Fischer     SetAccessibleName(sAccessibleName);
1703b2c5b9dSAndre Fischer     SetAccessibleDescription(sAccessibleName);
1713b2c5b9dSAndre Fischer     return TitleBar::CreateAccessible();
1723b2c5b9dSAndre Fischer }
1733b2c5b9dSAndre Fischer 
MouseButtonDown(const MouseEvent & rMouseEvent)174ff12d537SAndre Fischer void PanelTitleBar::MouseButtonDown (const MouseEvent& rMouseEvent)
175ff12d537SAndre Fischer {
176ff12d537SAndre Fischer     if (rMouseEvent.IsLeft())
177ff12d537SAndre Fischer     {
178ff12d537SAndre Fischer         mbIsLeftButtonDown = true;
179ff12d537SAndre Fischer         CaptureMouse();
180ff12d537SAndre Fischer     }
181ff12d537SAndre Fischer }
182ff12d537SAndre Fischer 
MouseButtonUp(const MouseEvent & rMouseEvent)183ff12d537SAndre Fischer void PanelTitleBar::MouseButtonUp (const MouseEvent& rMouseEvent)
184ff12d537SAndre Fischer {
185ff12d537SAndre Fischer     if (IsMouseCaptured())
186ff12d537SAndre Fischer         ReleaseMouse();
187ff12d537SAndre Fischer 
188ff12d537SAndre Fischer     if (rMouseEvent.IsLeft())
189ff12d537SAndre Fischer     {
190ff12d537SAndre Fischer         if (mbIsLeftButtonDown)
191ff12d537SAndre Fischer         {
192ff12d537SAndre Fischer             if (mpPanel != NULL)
193ff12d537SAndre Fischer             {
194ff12d537SAndre Fischer                 mpPanel->SetExpanded( ! mpPanel->IsExpanded());
195ff12d537SAndre Fischer                 Invalidate();
196ff12d537SAndre Fischer             }
197ff12d537SAndre Fischer         }
198ff12d537SAndre Fischer     }
199ff12d537SAndre Fischer     if (mbIsLeftButtonDown)
200ff12d537SAndre Fischer         mbIsLeftButtonDown = false;
201ff12d537SAndre Fischer }
202ff12d537SAndre Fischer 
DataChanged(const DataChangedEvent & rEvent)2037a32b0c8SAndre Fischer void PanelTitleBar::DataChanged (const DataChangedEvent& rEvent)
2047a32b0c8SAndre Fischer {
2057a32b0c8SAndre Fischer     maToolBox.SetItemImage(
2067a32b0c8SAndre Fischer         mnMenuItemIndex,
2077a32b0c8SAndre Fischer         Theme::GetImage(Theme::Image_PanelMenu));
208580828edSAndre Fischer     TitleBar::DataChanged(rEvent);
2097a32b0c8SAndre Fischer }
2107a32b0c8SAndre Fischer 
211ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar
212*05574615Smseidel 
213*05574615Smseidel /* vim: set noet sw=4 ts=4: */
214