nss: upgrade to release 3.73
[LibreOffice.git] / sfx2 / source / sidebar / SidebarPanelBase.cxx
blob6865047df25280ab3e9884e541f853691940c4f5
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/Theme.hxx>
21 #include <sfx2/sidebar/ILayoutableWindow.hxx>
22 #include <sfx2/sidebar/IContextChangeReceiver.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 vcl::Window* pWindow,
39 const css::ui::LayoutSize& rLayoutSize)
41 Reference<ui::XUIElement> xUIElement (
42 new SidebarPanelBase(
43 rsResourceURL,
44 rxFrame,
45 pWindow,
46 rLayoutSize));
47 return xUIElement;
50 SidebarPanelBase::SidebarPanelBase (
51 const OUString& rsResourceURL,
52 const css::uno::Reference<css::frame::XFrame>& rxFrame,
53 vcl::Window* pWindow,
54 const css::ui::LayoutSize& rLayoutSize)
55 : SidebarPanelBaseInterfaceBase(m_aMutex),
56 mxFrame(rxFrame),
57 mpControl(pWindow),
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());
68 if (mpControl != nullptr)
70 mpControl->SetBackground(Theme::GetColor(Theme::Color_PanelBackground));
71 mpControl->Show();
75 SidebarPanelBase::~SidebarPanelBase()
79 void SAL_CALL SidebarPanelBase::disposing()
81 SolarMutexGuard aGuard;
83 mpControl.disposeAndClear();
85 if (mxFrame.is())
87 css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
88 css::ui::ContextChangeEventMultiplexer::get(
89 ::comphelper::getProcessComponentContext()));
90 xMultiplexer->removeAllContextChangeEventListeners(this);
91 mxFrame = nullptr;
95 // XContextChangeEventListener
96 void SAL_CALL SidebarPanelBase::notifyContextChangeEvent (
97 const ui::ContextChangeEventObject& rEvent)
99 SolarMutexGuard aGuard;
101 IContextChangeReceiver* pContextChangeReceiver
102 = dynamic_cast<IContextChangeReceiver*>(mpControl.get());
103 if (pContextChangeReceiver != nullptr)
105 const vcl::EnumContext aContext(
106 vcl::EnumContext::GetApplicationEnum(rEvent.ApplicationName),
107 vcl::EnumContext::GetContextEnum(rEvent.ContextName));
108 pContextChangeReceiver->HandleContextChange(aContext);
112 void SAL_CALL SidebarPanelBase::disposing (
113 const css::lang::EventObject&)
115 SolarMutexGuard aGuard;
117 mxFrame = nullptr;
118 mpControl = nullptr;
121 css::uno::Reference<css::frame::XFrame> SAL_CALL SidebarPanelBase::getFrame()
123 return mxFrame;
126 OUString SAL_CALL SidebarPanelBase::getResourceURL()
128 return msResourceURL;
131 sal_Int16 SAL_CALL SidebarPanelBase::getType()
133 return ui::UIElementType::TOOLPANEL;
136 Reference<XInterface> SAL_CALL SidebarPanelBase::getRealInterface()
138 return Reference<XInterface>(static_cast<XWeak*>(this));
141 Reference<accessibility::XAccessible> SAL_CALL SidebarPanelBase::createAccessible (
142 const Reference<accessibility::XAccessible>&)
144 // Not yet implemented.
145 return nullptr;
148 Reference<awt::XWindow> SAL_CALL SidebarPanelBase::getWindow()
150 SolarMutexGuard aGuard;
152 if (mpControl != nullptr)
153 return Reference<awt::XWindow>(
154 mpControl->GetComponentInterface(),
155 UNO_QUERY);
156 else
157 return nullptr;
160 ui::LayoutSize SAL_CALL SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth)
162 SolarMutexGuard aGuard;
164 if (maLayoutSize.Minimum >= 0)
165 return maLayoutSize;
166 else
168 ILayoutableWindow* pLayoutableWindow = dynamic_cast<ILayoutableWindow*>(mpControl.get());
169 if (pLayoutableWindow)
170 return pLayoutableWindow->GetHeightForWidth(nWidth);
171 else if (isLayoutEnabled(mpControl))
173 // widget layout-based sidebar
174 Size aSize(mpControl->get_preferred_size());
175 return ui::LayoutSize(aSize.Height(), aSize.Height(), aSize.Height());
177 else if (mpControl != nullptr)
179 const sal_Int32 nHeight (mpControl->GetSizePixel().Height());
180 return ui::LayoutSize(nHeight,nHeight,nHeight);
184 return ui::LayoutSize(0,0,0);
187 sal_Int32 SAL_CALL SidebarPanelBase::getMinimalWidth ()
189 SolarMutexGuard aGuard;
191 if (isLayoutEnabled(mpControl))
193 // widget layout-based sidebar
194 Size aSize(mpControl->get_preferred_size());
195 return aSize.Width();
197 return 0;
200 void SAL_CALL SidebarPanelBase::updateModel(const css::uno::Reference<css::frame::XModel>& xModel)
202 SolarMutexGuard aGuard;
204 SidebarModelUpdate* pModelUpdate = dynamic_cast<SidebarModelUpdate*>(mpControl.get());
205 if (!pModelUpdate)
206 return;
208 pModelUpdate->updateModel(xModel);
211 } // end of namespace sfx2::sidebar
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */