1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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 (
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
),
57 mxControl(std::move(xControl
)),
58 msResourceURL(rsResourceURL
),
59 maLayoutSize(rLayoutSize
)
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
)
78 mxControl
->SetPanel(pPanel
);
81 void SAL_CALL
SidebarPanelBase::disposing()
83 SolarMutexGuard aGuard
;
89 css::uno::Reference
<css::ui::XContextChangeEventMultiplexer
> xMultiplexer (
90 css::ui::ContextChangeEventMultiplexer::get(
91 ::comphelper::getProcessComponentContext()));
92 xMultiplexer
->removeAllContextChangeEventListeners(this);
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
;
123 css::uno::Reference
<css::frame::XFrame
> SAL_CALL
SidebarPanelBase::getFrame()
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
>&)
150 Reference
<awt::XWindow
> SAL_CALL
SidebarPanelBase::getWindow()
156 ui::LayoutSize SAL_CALL
SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth
)
158 SolarMutexGuard aGuard
;
160 if (maLayoutSize
.Minimum
>= 0)
163 ILayoutableWindow
* pLayoutableWindow
= dynamic_cast<ILayoutableWindow
*>(mxControl
.get());
164 if (pLayoutableWindow
)
165 return pLayoutableWindow
->GetHeightForWidth(nWidth
);
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());
192 pModelUpdate
->updateModel(xModel
);
195 } // end of namespace sfx2::sidebar
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */