LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sfx2 / source / sidebar / SidebarPanelBase.cxx
blobfd46b96b5c2ac0e05153880f5aa0478780ca782f
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 .
19 #include <sfx2/sidebar/SidebarPanelBase.hxx>
20 #include <sfx2/sidebar/ILayoutableWindow.hxx>
21 #include <sfx2/sidebar/IContextChangeReceiver.hxx>
22 #include <sfx2/sidebar/PanelLayout.hxx>
23 #include <sfx2/sidebar/SidebarModelUpdate.hxx>
24 #include <vcl/layout.hxx>
25 #include <comphelper/processfactory.hxx>
26 #include <com/sun/star/awt/XWindowPeer.hpp>
27 #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
28 #include <com/sun/star/ui/UIElementType.hpp>
30 using namespace css;
31 using namespace css::uno;
33 namespace sfx2::sidebar {
35 Reference<ui::XUIElement> SidebarPanelBase::Create (
36 const OUString& rsResourceURL,
37 const css::uno::Reference<css::frame::XFrame>& rxFrame,
38 std::unique_ptr<PanelLayout> xControl,
39 const css::ui::LayoutSize& rLayoutSize)
41 Reference<ui::XUIElement> xUIElement (
42 new SidebarPanelBase(
43 rsResourceURL,
44 rxFrame,
45 std::move(xControl),
46 rLayoutSize));
47 return xUIElement;
50 SidebarPanelBase::SidebarPanelBase (
51 const OUString& rsResourceURL,
52 const css::uno::Reference<css::frame::XFrame>& rxFrame,
53 std::unique_ptr<PanelLayout> xControl,
54 const css::ui::LayoutSize& rLayoutSize)
55 : SidebarPanelBaseInterfaceBase(m_aMutex),
56 mxFrame(rxFrame),
57 mxControl(std::move(xControl)),
58 msResourceURL(rsResourceURL),
59 maLayoutSize(rLayoutSize)
61 if (mxFrame.is())
63 css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
64 css::ui::ContextChangeEventMultiplexer::get(
65 ::comphelper::getProcessComponentContext()));
66 xMultiplexer->addContextChangeEventListener(this, mxFrame->getController());
70 SidebarPanelBase::~SidebarPanelBase()
74 void SidebarPanelBase::SetParentPanel(sfx2::sidebar::Panel* pPanel)
76 if (!mxControl)
77 return;
78 mxControl->SetPanel(pPanel);
81 void SAL_CALL SidebarPanelBase::disposing()
83 SolarMutexGuard aGuard;
85 mxControl.reset();
87 if (mxFrame.is())
89 css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
90 css::ui::ContextChangeEventMultiplexer::get(
91 ::comphelper::getProcessComponentContext()));
92 xMultiplexer->removeAllContextChangeEventListeners(this);
93 mxFrame = nullptr;
97 // XContextChangeEventListener
98 void SAL_CALL SidebarPanelBase::notifyContextChangeEvent (
99 const ui::ContextChangeEventObject& rEvent)
101 SolarMutexGuard aGuard;
103 IContextChangeReceiver* pContextChangeReceiver
104 = dynamic_cast<IContextChangeReceiver*>(mxControl.get());
105 if (pContextChangeReceiver != nullptr)
107 const vcl::EnumContext aContext(
108 vcl::EnumContext::GetApplicationEnum(rEvent.ApplicationName),
109 vcl::EnumContext::GetContextEnum(rEvent.ContextName));
110 pContextChangeReceiver->HandleContextChange(aContext);
114 void SAL_CALL SidebarPanelBase::disposing (
115 const css::lang::EventObject&)
117 SolarMutexGuard aGuard;
119 mxFrame = nullptr;
120 mxControl.reset();
123 css::uno::Reference<css::frame::XFrame> SAL_CALL SidebarPanelBase::getFrame()
125 return mxFrame;
128 OUString SAL_CALL SidebarPanelBase::getResourceURL()
130 return msResourceURL;
133 sal_Int16 SAL_CALL SidebarPanelBase::getType()
135 return ui::UIElementType::TOOLPANEL;
138 Reference<XInterface> SAL_CALL SidebarPanelBase::getRealInterface()
140 return Reference<XInterface>(static_cast<XWeak*>(this));
143 Reference<accessibility::XAccessible> SAL_CALL SidebarPanelBase::createAccessible (
144 const Reference<accessibility::XAccessible>&)
146 // Not implemented.
147 return nullptr;
150 Reference<awt::XWindow> SAL_CALL SidebarPanelBase::getWindow()
152 // Not implemented
153 return nullptr;
156 ui::LayoutSize SAL_CALL SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth)
158 SolarMutexGuard aGuard;
160 if (maLayoutSize.Minimum >= 0)
161 return maLayoutSize;
163 ILayoutableWindow* pLayoutableWindow = dynamic_cast<ILayoutableWindow*>(mxControl.get());
164 if (pLayoutableWindow)
165 return pLayoutableWindow->GetHeightForWidth(nWidth);
166 else
168 // widget layout-based sidebar
169 mxControl->queue_resize();
170 Size aSize(mxControl->get_preferred_size());
171 return ui::LayoutSize(aSize.Height(), aSize.Height(), aSize.Height());
175 sal_Int32 SAL_CALL SidebarPanelBase::getMinimalWidth ()
177 SolarMutexGuard aGuard;
179 // widget layout-based sidebar
180 Size aSize(mxControl->get_preferred_size());
181 return aSize.Width();
184 void SAL_CALL SidebarPanelBase::updateModel(const css::uno::Reference<css::frame::XModel>& xModel)
186 SolarMutexGuard aGuard;
188 SidebarModelUpdate* pModelUpdate = dynamic_cast<SidebarModelUpdate*>(mxControl.get());
189 if (!pModelUpdate)
190 return;
192 pModelUpdate->updateModel(xModel);
195 } // end of namespace sfx2::sidebar
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */