LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sfx2 / source / sidebar / PanelTitleBar.cxx
blob6e0677252e4be754768caf3b939401bea01d165a
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 <vcl/event.hxx>
28 using namespace css;
29 using namespace css::uno;
31 namespace sfx2::sidebar {
33 PanelTitleBar::PanelTitleBar(const OUString& rsTitle,
34 weld::Builder& rBuilder,
35 Panel* pPanel)
36 : TitleBar(rBuilder, Theme::Color_PanelTitleBarBackground),
37 mxExpander(rBuilder.weld_expander("expander")),
38 mpPanel(pPanel),
39 msIdent("button")
41 mxExpander->set_label(rsTitle);
42 mxExpander->connect_expanded(LINK(this, PanelTitleBar, ExpandHdl));
44 // tdf#145801 lock the height to the size it needs with the "toolbar" button shown
45 // so all of the titlebars are the same height if the "toolbar" is hidden in some
46 // of them
47 mxToolBox->show();
48 mxTitlebar->set_size_request(-1, mxTitlebar->get_preferred_size().Height());
49 mxToolBox->hide();
51 assert(mpPanel);
53 UpdateExpandedState();
56 void PanelTitleBar::SetTitle(const OUString& rsTitle)
58 mxExpander->set_label(rsTitle);
61 OUString PanelTitleBar::GetTitle() const
63 return mxExpander->get_label();
66 void PanelTitleBar::UpdateExpandedState()
68 mxExpander->set_expanded(mpPanel->IsExpanded());
71 PanelTitleBar::~PanelTitleBar()
73 Reference<lang::XComponent> xComponent(mxController, UNO_QUERY);
74 if (xComponent.is())
75 xComponent->dispose();
76 mxController.clear();
77 mpPanel = nullptr;
78 mxExpander.reset();
81 void PanelTitleBar::SetMoreOptionsCommand(const OUString& rsCommandName,
82 const css::uno::Reference<css::frame::XFrame>& rxFrame,
83 const css::uno::Reference<css::frame::XController>& rxController)
85 if (rsCommandName == msMoreOptionsCommand)
86 return;
88 if (!msMoreOptionsCommand.isEmpty())
89 mxToolBox->hide();
91 msMoreOptionsCommand = rsCommandName;
93 if (msMoreOptionsCommand.isEmpty())
94 return;
96 msIdent = msMoreOptionsCommand.toUtf8();
97 mxToolBox->set_item_ident(0, msIdent);
99 Reference<lang::XComponent> xComponent(mxController, UNO_QUERY);
100 if (xComponent.is())
101 xComponent->dispose();
102 mxController =
103 ControllerFactory::CreateToolBoxController(
104 *mxToolBox, mrBuilder, msMoreOptionsCommand, rxFrame, rxController, true);
106 mxToolBox->show();
109 void PanelTitleBar::HandleToolBoxItemClick()
111 if (!mxController)
112 return;
113 mxController->click();
114 mxController->execute(0);
117 IMPL_LINK(PanelTitleBar, ExpandHdl, weld::Expander&, rExpander, void)
119 if (!mpPanel)
120 return;
121 mpPanel->SetExpanded(rExpander.get_expanded());
124 } // end of namespace sfx2::sidebar
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */