bump product version to 4.1.6.2
[LibreOffice.git] / sfx2 / source / sidebar / SidebarPanelBase.cxx
bloba4e037a8c4a1ac34f009779213fbafb34047197a
1 /*
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>
30 using namespace css;
31 using namespace cssu;
34 namespace sfx2 { namespace sidebar {
36 Reference<ui::XUIElement> SidebarPanelBase::Create (
37 const ::rtl::OUString& rsResourceURL,
38 const cssu::Reference<css::frame::XFrame>& rxFrame,
39 Window* pWindow,
40 const css::ui::LayoutSize& rLayoutSize)
42 Reference<ui::XUIElement> xUIElement (
43 new SidebarPanelBase(
44 rsResourceURL,
45 rxFrame,
46 pWindow,
47 rLayoutSize));
48 return xUIElement;
54 SidebarPanelBase::SidebarPanelBase (
55 const ::rtl::OUString& rsResourceURL,
56 const cssu::Reference<css::frame::XFrame>& rxFrame,
57 Window* pWindow,
58 const css::ui::LayoutSize& rLayoutSize)
59 : SidebarPanelBaseInterfaceBase(m_aMutex),
60 mxFrame(rxFrame),
61 mpControl(pWindow),
62 msResourceURL(rsResourceURL),
63 maLayoutSize(rLayoutSize)
65 if (mxFrame.is())
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));
76 mpControl->Show();
83 SidebarPanelBase::~SidebarPanelBase (void)
90 void SAL_CALL SidebarPanelBase::disposing (void)
91 throw (cssu::RuntimeException)
93 if (mpControl != NULL)
95 delete mpControl;
96 mpControl = NULL;
99 if (mxFrame.is())
101 cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
102 css::ui::ContextChangeEventMultiplexer::get(
103 ::comphelper::getProcessComponentContext()));
104 if (xMultiplexer.is())
105 xMultiplexer->removeAllContextChangeEventListeners(this);
106 mxFrame = NULL;
113 void SidebarPanelBase::SetControl (::Window* pControl)
115 mpControl = pControl;
121 ::Window* SidebarPanelBase::GetControl (void) const
123 return mpControl;
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)
152 (void)rEvent;
154 mxFrame = NULL;
155 mpControl = NULL;
161 cssu::Reference<css::frame::XFrame> SAL_CALL SidebarPanelBase::getFrame (void)
162 throw(cssu::RuntimeException)
164 return mxFrame;
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.
204 return NULL;
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(),
216 UNO_QUERY);
217 else
218 return NULL;
224 ui::LayoutSize SAL_CALL SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth)
225 throw(cssu::RuntimeException)
227 if (maLayoutSize.Minimum >= 0)
228 return maLayoutSize;
229 else
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();
259 return 0;
262 } } // end of namespace sfx2::sidebar