2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 #include "sfx2/sidebar/SidebarPanelBase.hxx"
19 #include "sfx2/sidebar/Theme.hxx"
20 #include "sfx2/sidebar/ILayoutableWindow.hxx"
21 #include "sfx2/sidebar/IContextChangeReceiver.hxx"
22 #include "sfx2/imagemgr.hxx"
23 #include <vcl/ctrl.hxx>
24 #include <vcl/layout.hxx>
25 #include <comphelper/processfactory.hxx>
27 #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
28 #include <com/sun/star/ui/UIElementType.hpp>
34 namespace sfx2
{ namespace sidebar
{
36 Reference
<ui::XUIElement
> SidebarPanelBase::Create (
37 const ::rtl::OUString
& rsResourceURL
,
38 const cssu::Reference
<css::frame::XFrame
>& rxFrame
,
40 const css::ui::LayoutSize
& rLayoutSize
)
42 Reference
<ui::XUIElement
> xUIElement (
54 SidebarPanelBase::SidebarPanelBase (
55 const ::rtl::OUString
& rsResourceURL
,
56 const cssu::Reference
<css::frame::XFrame
>& rxFrame
,
58 const css::ui::LayoutSize
& rLayoutSize
)
59 : SidebarPanelBaseInterfaceBase(m_aMutex
),
62 msResourceURL(rsResourceURL
),
63 maLayoutSize(rLayoutSize
)
67 cssu::Reference
<css::ui::XContextChangeEventMultiplexer
> xMultiplexer (
68 css::ui::ContextChangeEventMultiplexer::get(
69 ::comphelper::getProcessComponentContext()));
70 if (xMultiplexer
.is())
71 xMultiplexer
->addContextChangeEventListener(this, mxFrame
->getController());
73 if (mpControl
!= NULL
)
75 mpControl
->SetBackground(Theme::GetWallpaper(Theme::Paint_PanelBackground
));
83 SidebarPanelBase::~SidebarPanelBase (void)
90 void SAL_CALL
SidebarPanelBase::disposing (void)
91 throw (cssu::RuntimeException
)
93 if (mpControl
!= NULL
)
101 cssu::Reference
<css::ui::XContextChangeEventMultiplexer
> xMultiplexer (
102 css::ui::ContextChangeEventMultiplexer::get(
103 ::comphelper::getProcessComponentContext()));
104 if (xMultiplexer
.is())
105 xMultiplexer
->removeAllContextChangeEventListeners(this);
113 void SidebarPanelBase::SetControl (::Window
* pControl
)
115 mpControl
= pControl
;
121 ::Window
* SidebarPanelBase::GetControl (void) const
129 // XContextChangeEventListener
130 void SAL_CALL
SidebarPanelBase::notifyContextChangeEvent (
131 const ui::ContextChangeEventObject
& rEvent
)
132 throw (cssu::RuntimeException
)
134 IContextChangeReceiver
* pContextChangeReceiver
135 = dynamic_cast<IContextChangeReceiver
*>(mpControl
);
136 if (pContextChangeReceiver
!= NULL
)
138 const EnumContext
aContext(
139 EnumContext::GetApplicationEnum(rEvent
.ApplicationName
),
140 EnumContext::GetContextEnum(rEvent
.ContextName
));
141 pContextChangeReceiver
->HandleContextChange(aContext
);
148 void SAL_CALL
SidebarPanelBase::disposing (
149 const css::lang::EventObject
& rEvent
)
150 throw (cssu::RuntimeException
)
161 cssu::Reference
<css::frame::XFrame
> SAL_CALL
SidebarPanelBase::getFrame (void)
162 throw(cssu::RuntimeException
)
170 ::rtl::OUString SAL_CALL
SidebarPanelBase::getResourceURL (void)
171 throw(cssu::RuntimeException
)
173 return msResourceURL
;
179 sal_Int16 SAL_CALL
SidebarPanelBase::getType (void)
180 throw(cssu::RuntimeException
)
182 return ui::UIElementType::TOOLPANEL
;
188 Reference
<XInterface
> SAL_CALL
SidebarPanelBase::getRealInterface (void)
189 throw(cssu::RuntimeException
)
191 return Reference
<XInterface
>(static_cast<XWeak
*>(this));
197 Reference
<accessibility::XAccessible
> SAL_CALL
SidebarPanelBase::createAccessible (
198 const Reference
<accessibility::XAccessible
>& rxParentAccessible
)
199 throw(cssu::RuntimeException
)
201 (void)rxParentAccessible
;
203 // Not yet implemented.
210 Reference
<awt::XWindow
> SAL_CALL
SidebarPanelBase::getWindow (void)
211 throw(cssu::RuntimeException
)
213 if (mpControl
!= NULL
)
214 return Reference
<awt::XWindow
>(
215 mpControl
->GetComponentInterface(),
224 ui::LayoutSize SAL_CALL
SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth
)
225 throw(cssu::RuntimeException
)
227 if (maLayoutSize
.Minimum
>= 0)
231 ILayoutableWindow
* pLayoutableWindow
= dynamic_cast<ILayoutableWindow
*>(mpControl
);
233 if (isLayoutEnabled(mpControl
))
235 // widget layout-based sidebar
236 Size
aSize(mpControl
->GetOptimalSize());
237 return ui::LayoutSize(aSize
.Height(), aSize
.Height(), aSize
.Height());
239 else if (pLayoutableWindow
!= NULL
)
240 return pLayoutableWindow
->GetHeightForWidth(nWidth
);
241 else if (mpControl
!= NULL
)
243 const sal_Int32
nHeight (mpControl
->GetSizePixel().Height());
244 return ui::LayoutSize(nHeight
,nHeight
,nHeight
);
248 return ui::LayoutSize(0,0,0);
251 sal_Int32 SAL_CALL
SidebarPanelBase::getMinimalWidth () throw(cssu::RuntimeException
)
253 if (isLayoutEnabled(mpControl
))
255 // widget layout-based sidebar
256 Size
aSize(mpControl
->GetOptimalSize());
257 return aSize
.Width();
262 } } // end of namespace sfx2::sidebar