Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / sfx2 / source / sidebar / PanelTitleBar.cxx
blob1de76008befd640b72795fa8d275106a4bfc886f
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 <sidebar/PanelTitleBar.hxx>
21 #include <sfx2/sfxresid.hxx>
22 #include <sfx2/strings.hrc>
23 #include <sfx2/sidebar/Panel.hxx>
24 #include <sfx2/sidebar/Theme.hxx>
25 #include <sidebar/ControllerFactory.hxx>
26 #include <sidebar/Tools.hxx>
27 #include <vcl/event.hxx>
28 #include <vcl/image.hxx>
29 #include <toolkit/helper/vclunohelper.hxx>
30 #include <tools/diagnose_ex.h>
32 #include <com/sun/star/frame/XDispatch.hpp>
34 using namespace css;
35 using namespace css::uno;
37 namespace sfx2::sidebar {
39 PanelTitleBar::PanelTitleBar(const OUString& rsTitle,
40 vcl::Window* pParentWindow,
41 Panel* pPanel)
42 : TitleBar(pParentWindow, "sfx/ui/paneltitlebar.ui", "PanelTitleBar",
43 Theme::Color_PanelTitleBarBackground),
44 mxExpander(m_xBuilder->weld_expander("expander")),
45 mpPanel(pPanel),
46 mxFrame(),
47 msIdent("button"),
48 msMoreOptionsCommand()
50 mxExpander->set_label(rsTitle);
51 mxExpander->connect_expanded(LINK(this, PanelTitleBar, ExpandHdl));
53 assert(mpPanel);
55 UpdateExpandedState();
57 #ifdef DEBUG
58 SetText(OUString("PanelTitleBar"));
59 #endif
62 void PanelTitleBar::SetTitle(const OUString& rsTitle)
64 mxExpander->set_label(rsTitle);
67 OUString PanelTitleBar::GetTitle() const
69 return mxExpander->get_label();
72 void PanelTitleBar::UpdateExpandedState()
74 mxExpander->set_expanded(mpPanel->IsExpanded());
77 PanelTitleBar::~PanelTitleBar()
79 disposeOnce();
82 void PanelTitleBar::dispose()
84 Reference<lang::XComponent> xComponent(mxController, UNO_QUERY);
85 if (xComponent.is())
86 xComponent->dispose();
87 mxController.clear();
88 mpPanel.clear();
89 mxExpander.reset();
90 TitleBar::dispose();
93 void PanelTitleBar::SetMoreOptionsCommand(const OUString& rsCommandName,
94 const css::uno::Reference<css::frame::XFrame>& rxFrame,
95 const css::uno::Reference<css::frame::XController>& rxController)
97 if (rsCommandName == msMoreOptionsCommand)
98 return;
100 if (!msMoreOptionsCommand.isEmpty())
101 mxToolBox->hide();
103 msMoreOptionsCommand = rsCommandName;
104 mxFrame = rxFrame;
106 if (msMoreOptionsCommand.isEmpty())
107 return;
109 msIdent = msMoreOptionsCommand.toUtf8();
110 mxToolBox->set_item_ident(0, msIdent);
112 Reference<lang::XComponent> xComponent(mxController, UNO_QUERY);
113 if (xComponent.is())
114 xComponent->dispose();
115 mxController =
116 ControllerFactory::CreateToolBoxController(
117 *mxToolBox, *m_xBuilder, msMoreOptionsCommand, rxFrame, rxController, true);
119 mxToolBox->show();
120 mxToolBox->set_item_icon_name(msIdent, "sfx2/res/symphony/morebutton.png");
121 mxToolBox->set_item_tooltip_text(msIdent, SfxResId(SFX_STR_SIDEBAR_MORE_OPTIONS));
124 void PanelTitleBar::HandleToolBoxItemClick()
126 if (!mxController)
127 return;
128 mxController->click();
129 mxController->execute(0);
132 IMPL_LINK(PanelTitleBar, ExpandHdl, weld::Expander&, rExpander, void)
134 if (!mpPanel)
135 return;
136 mpPanel->SetExpanded(rExpander.get_expanded());
139 void PanelTitleBar::DataChanged (const DataChangedEvent& rEvent)
141 mxToolBox->set_item_icon_name(msIdent, "sfx2/res/symphony/morebutton.png");
142 TitleBar::DataChanged(rEvent);
145 } // end of namespace sfx2::sidebar
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */