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/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>
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
,
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
,
54 const css::ui::LayoutSize
& rLayoutSize
)
55 : SidebarPanelBaseInterfaceBase(m_aMutex
),
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());
68 if (mpControl
!= nullptr)
70 mpControl
->SetBackground(Theme::GetColor(Theme::Color_PanelBackground
));
75 SidebarPanelBase::~SidebarPanelBase()
79 void SAL_CALL
SidebarPanelBase::disposing()
81 SolarMutexGuard aGuard
;
83 mpControl
.disposeAndClear();
87 css::uno::Reference
<css::ui::XContextChangeEventMultiplexer
> xMultiplexer (
88 css::ui::ContextChangeEventMultiplexer::get(
89 ::comphelper::getProcessComponentContext()));
90 xMultiplexer
->removeAllContextChangeEventListeners(this);
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
;
121 css::uno::Reference
<css::frame::XFrame
> SAL_CALL
SidebarPanelBase::getFrame()
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.
148 Reference
<awt::XWindow
> SAL_CALL
SidebarPanelBase::getWindow()
150 SolarMutexGuard aGuard
;
152 if (mpControl
!= nullptr)
153 return Reference
<awt::XWindow
>(
154 mpControl
->GetComponentInterface(),
160 ui::LayoutSize SAL_CALL
SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth
)
162 SolarMutexGuard aGuard
;
164 if (maLayoutSize
.Minimum
>= 0)
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();
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());
208 pModelUpdate
->updateModel(xModel
);
211 } // end of namespace sfx2::sidebar
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */