Get the style color and number just once
[LibreOffice.git] / sfx2 / source / sidebar / SidebarPanelBase.cxx
blob1bf3fe0fee8d486520aae96d4e094b610c652832
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 <utility>
25 #include <vcl/EnumContext.hxx>
26 #include <vcl/svapp.hxx>
27 #include <comphelper/processfactory.hxx>
28 #include <com/sun/star/awt/XWindowPeer.hpp>
29 #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
30 #include <com/sun/star/ui/UIElementType.hpp>
32 using namespace css;
33 using namespace css::uno;
35 namespace sfx2::sidebar {
37 Reference<ui::XUIElement> SidebarPanelBase::Create (
38 const OUString& rsResourceURL,
39 const css::uno::Reference<css::frame::XFrame>& rxFrame,
40 std::unique_ptr<PanelLayout> xControl,
41 const css::ui::LayoutSize& rLayoutSize)
43 Reference<ui::XUIElement> xUIElement (
44 new SidebarPanelBase(
45 rsResourceURL,
46 rxFrame,
47 std::move(xControl),
48 rLayoutSize));
49 return xUIElement;
52 SidebarPanelBase::SidebarPanelBase (
53 OUString sResourceURL,
54 css::uno::Reference<css::frame::XFrame> xFrame,
55 std::unique_ptr<PanelLayout> xControl,
56 const css::ui::LayoutSize& rLayoutSize)
57 : mxFrame(std::move(xFrame)),
58 mxControl(std::move(xControl)),
59 msResourceURL(std::move(sResourceURL)),
60 maLayoutSize(rLayoutSize)
62 if (mxFrame.is())
64 css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
65 css::ui::ContextChangeEventMultiplexer::get(
66 ::comphelper::getProcessComponentContext()));
67 xMultiplexer->addContextChangeEventListener(this, mxFrame->getController());
71 SidebarPanelBase::~SidebarPanelBase()
75 void SidebarPanelBase::SetParentPanel(sfx2::sidebar::Panel* pPanel)
77 if (!mxControl)
78 return;
79 mxControl->SetPanel(pPanel);
82 void SidebarPanelBase::disposing(std::unique_lock<std::mutex>&)
84 SolarMutexGuard aGuard;
86 mxControl.reset();
88 if (mxFrame.is())
90 css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
91 css::ui::ContextChangeEventMultiplexer::get(
92 ::comphelper::getProcessComponentContext()));
93 xMultiplexer->removeAllContextChangeEventListeners(this);
94 mxFrame = nullptr;
98 // XContextChangeEventListener
99 void SAL_CALL SidebarPanelBase::notifyContextChangeEvent (
100 const ui::ContextChangeEventObject& rEvent)
102 SolarMutexGuard aGuard;
104 IContextChangeReceiver* pContextChangeReceiver
105 = dynamic_cast<IContextChangeReceiver*>(mxControl.get());
106 if (pContextChangeReceiver != nullptr)
108 const vcl::EnumContext aContext(
109 vcl::EnumContext::GetApplicationEnum(rEvent.ApplicationName),
110 vcl::EnumContext::GetContextEnum(rEvent.ContextName));
111 pContextChangeReceiver->HandleContextChange(aContext);
115 void SAL_CALL SidebarPanelBase::disposing (
116 const css::lang::EventObject&)
118 SolarMutexGuard aGuard;
120 mxFrame = nullptr;
121 mxControl.reset();
124 css::uno::Reference<css::frame::XFrame> SAL_CALL SidebarPanelBase::getFrame()
126 return mxFrame;
129 OUString SAL_CALL SidebarPanelBase::getResourceURL()
131 return msResourceURL;
134 sal_Int16 SAL_CALL SidebarPanelBase::getType()
136 return ui::UIElementType::TOOLPANEL;
139 Reference<XInterface> SAL_CALL SidebarPanelBase::getRealInterface()
141 return getXWeak();
144 Reference<accessibility::XAccessible> SAL_CALL SidebarPanelBase::createAccessible (
145 const Reference<accessibility::XAccessible>&)
147 // Not implemented.
148 return nullptr;
151 Reference<awt::XWindow> SAL_CALL SidebarPanelBase::getWindow()
153 // Not implemented
154 return nullptr;
157 ui::LayoutSize SAL_CALL SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth)
159 SolarMutexGuard aGuard;
161 if (maLayoutSize.Minimum >= 0)
162 return maLayoutSize;
164 ILayoutableWindow* pLayoutableWindow = dynamic_cast<ILayoutableWindow*>(mxControl.get());
165 if (pLayoutableWindow)
166 return pLayoutableWindow->GetHeightForWidth(nWidth);
167 else
169 // widget layout-based sidebar
170 mxControl->queue_resize();
171 Size aSize(mxControl->get_preferred_size());
172 return ui::LayoutSize(aSize.Height(), aSize.Height(), aSize.Height());
176 sal_Int32 SAL_CALL SidebarPanelBase::getMinimalWidth ()
178 SolarMutexGuard aGuard;
180 // widget layout-based sidebar
181 Size aSize(mxControl->get_preferred_size());
182 return aSize.Width();
185 void SAL_CALL SidebarPanelBase::updateModel(const css::uno::Reference<css::frame::XModel>& xModel)
187 SolarMutexGuard aGuard;
189 SidebarModelUpdate* pModelUpdate = dynamic_cast<SidebarModelUpdate*>(mxControl.get());
190 if (!pModelUpdate)
191 return;
193 pModelUpdate->updateModel(xModel);
196 } // end of namespace sfx2::sidebar
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */