1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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>
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
,
45 : TitleBar(rsTitle
, pParentWindow
, GetBackgroundPaint()),
46 mbIsLeftButtonDown(false),
50 msMoreOptionsCommand()
52 OSL_ASSERT(mpPanel
!= nullptr);
55 SetText(OUString("PanelTitleBar"));
59 PanelTitleBar::~PanelTitleBar()
64 void PanelTitleBar::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
;
81 if (msMoreOptionsCommand
.getLength() > 0)
83 maToolBox
->InsertItem(
85 Theme::GetImage(Theme::Image_PanelMenu
));
86 Reference
<frame::XToolbarController
> xController (
87 ControllerFactory::CreateToolBoxController(
92 VCLUnoHelper::GetInterface(maToolBox
.get()),
94 maToolBox
->SetController(mnMenuItemIndex
, xController
, msMoreOptionsCommand
);
95 maToolBox
->SetOutStyle(TOOLBOX_STYLE_FLAT
);
96 maToolBox
->SetQuickHelpText(
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
));
111 aImage
.GetSizePixel().Width() + gaLeftIconPadding
+ gaRightIconPadding
,
113 rTitleBarBox
.Right(),
114 rTitleBarBox
.Bottom());
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
));
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;
179 void PanelTitleBar::MouseButtonUp (const MouseEvent
& rMouseEvent
)
181 if (IsMouseCaptured())
184 if (rMouseEvent
.IsLeft())
186 if (mbIsLeftButtonDown
)
188 if (mpPanel
!= nullptr)
190 mpPanel
->SetExpanded( ! mpPanel
->IsExpanded());
195 if (mbIsLeftButtonDown
)
196 mbIsLeftButtonDown
= false;
199 void PanelTitleBar::DataChanged (const DataChangedEvent
& rEvent
)
201 maToolBox
->SetItemImage(
203 Theme::GetImage(Theme::Image_PanelMenu
));
204 TitleBar::DataChanged(rEvent
);
207 } } // end of namespace sfx2::sidebar
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */