Branch libreoffice-5-0-4
[LibreOffice.git] / sfx2 / source / sidebar / PanelTitleBar.cxx
blobeda513bd9691891ab1da474a3b71152410746695
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "PanelTitleBar.hxx"
21 #include <sfx2/sfxresid.hxx>
22 #include "Sidebar.hrc"
24 #include "Paint.hxx"
25 #include "Panel.hxx"
26 #include <sfx2/sidebar/Theme.hxx>
27 #include <sfx2/sidebar/ControllerFactory.hxx>
28 #include <sfx2/sidebar/Tools.hxx>
29 #include <tools/svborder.hxx>
30 #include <vcl/gradient.hxx>
31 #include <vcl/image.hxx>
32 #include <toolkit/helper/vclunohelper.hxx>
34 using namespace css;
35 using namespace css::uno;
37 namespace sfx2 { namespace sidebar {
39 static const sal_Int32 gaLeftIconPadding (5);
40 static const sal_Int32 gaRightIconPadding (5);
42 PanelTitleBar::PanelTitleBar(const OUString& rsTitle,
43 vcl::Window* pParentWindow,
44 Panel* pPanel)
45 : TitleBar(rsTitle, pParentWindow, GetBackgroundPaint()),
46 mbIsLeftButtonDown(false),
47 mpPanel(pPanel),
48 mnMenuItemIndex(1),
49 mxFrame(),
50 msMoreOptionsCommand()
52 OSL_ASSERT(mpPanel != nullptr);
54 #ifdef DEBUG
55 SetText(OUString("PanelTitleBar"));
56 #endif
59 PanelTitleBar::~PanelTitleBar()
61 disposeOnce();
64 void PanelTitleBar::dispose()
66 mpPanel.clear();
67 TitleBar::dispose();
70 void PanelTitleBar::SetMoreOptionsCommand(const OUString& rsCommandName,
71 const css::uno::Reference<css::frame::XFrame>& rxFrame)
73 if (!rsCommandName.equals(msMoreOptionsCommand))
75 if (msMoreOptionsCommand.getLength() > 0)
76 maToolBox->RemoveItem(maToolBox->GetItemPos(mnMenuItemIndex));
78 msMoreOptionsCommand = rsCommandName;
79 mxFrame = rxFrame;
81 if (msMoreOptionsCommand.getLength() > 0)
83 maToolBox->InsertItem(
84 mnMenuItemIndex,
85 Theme::GetImage(Theme::Image_PanelMenu));
86 Reference<frame::XToolbarController> xController (
87 ControllerFactory::CreateToolBoxController(
88 maToolBox.get(),
89 mnMenuItemIndex,
90 msMoreOptionsCommand,
91 rxFrame,
92 VCLUnoHelper::GetInterface(maToolBox.get()),
93 0));
94 maToolBox->SetController(mnMenuItemIndex, xController, msMoreOptionsCommand);
95 maToolBox->SetOutStyle(TOOLBOX_STYLE_FLAT);
96 maToolBox->SetQuickHelpText(
97 mnMenuItemIndex,
98 SFX2_RESSTR(SFX_STR_SIDEBAR_MORE_OPTIONS));
103 Rectangle PanelTitleBar::GetTitleArea (const Rectangle& rTitleBarBox)
105 if (mpPanel != nullptr)
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());
116 else
117 return rTitleBarBox;
120 void PanelTitleBar::PaintDecoration (vcl::RenderContext& rRenderContext, const Rectangle& /*rTitleBarBox*/)
122 if (mpPanel != nullptr)
124 Image aImage (mpPanel->IsExpanded()
125 ? Theme::GetImage(Theme::Image_Collapse)
126 : Theme::GetImage(Theme::Image_Expand));
127 const Point aTopLeft(gaLeftIconPadding,
128 (GetSizePixel().Height() - aImage.GetSizePixel().Height()) / 2);
129 rRenderContext.DrawImage(aTopLeft, aImage);
133 Paint PanelTitleBar::GetBackgroundPaint()
135 return Theme::GetPaint(Theme::Paint_PanelTitleBarBackground);
138 Color PanelTitleBar::GetTextColor()
140 return Theme::GetColor(Theme::Color_PanelTitleFont);
143 void PanelTitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex)
145 if (nItemIndex == mnMenuItemIndex)
146 if (msMoreOptionsCommand.getLength() > 0)
150 const util::URL aURL (Tools::GetURL(msMoreOptionsCommand));
151 Reference<frame::XDispatch> xDispatch (Tools::GetDispatch(mxFrame, aURL));
152 if (xDispatch.is())
153 xDispatch->dispatch(aURL, Sequence<beans::PropertyValue>());
155 catch(Exception& rException)
157 OSL_TRACE("caught exception: %s",
158 OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr());
163 Reference<accessibility::XAccessible> PanelTitleBar::CreateAccessible()
165 SetAccessibleName(msTitle);
166 SetAccessibleDescription(msTitle);
167 return TitleBar::CreateAccessible();
170 void PanelTitleBar::MouseButtonDown (const MouseEvent& rMouseEvent)
172 if (rMouseEvent.IsLeft())
174 mbIsLeftButtonDown = true;
175 CaptureMouse();
179 void PanelTitleBar::MouseButtonUp (const MouseEvent& rMouseEvent)
181 if (IsMouseCaptured())
182 ReleaseMouse();
184 if (rMouseEvent.IsLeft())
186 if (mbIsLeftButtonDown)
188 if (mpPanel != nullptr)
190 mpPanel->SetExpanded( ! mpPanel->IsExpanded());
191 Invalidate();
195 if (mbIsLeftButtonDown)
196 mbIsLeftButtonDown = false;
199 void PanelTitleBar::DataChanged (const DataChangedEvent& rEvent)
201 maToolBox->SetItemImage(
202 mnMenuItemIndex,
203 Theme::GetImage(Theme::Image_PanelMenu));
204 TitleBar::DataChanged(rEvent);
207 } } // end of namespace sfx2::sidebar
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */