Branch libreoffice-5-0-4
[LibreOffice.git] / sfx2 / source / sidebar / SidebarPanelBase.cxx
bloba7ec830687dda1221c276da9155616b8c6d2372a
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/imagemgr.hxx>
24 #include <vcl/ctrl.hxx>
25 #include <vcl/layout.hxx>
26 #include <comphelper/processfactory.hxx>
28 #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
29 #include <com/sun/star/ui/UIElementType.hpp>
31 using namespace css;
32 using namespace css::uno;
34 namespace sfx2 { namespace sidebar {
36 Reference<ui::XUIElement> SidebarPanelBase::Create (
37 const ::rtl::OUString& rsResourceURL,
38 const css::uno::Reference<css::frame::XFrame>& rxFrame,
39 vcl::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;
51 SidebarPanelBase::SidebarPanelBase (
52 const ::rtl::OUString& rsResourceURL,
53 const css::uno::Reference<css::frame::XFrame>& rxFrame,
54 vcl::Window* pWindow,
55 const css::ui::LayoutSize& rLayoutSize)
56 : SidebarPanelBaseInterfaceBase(m_aMutex),
57 mxFrame(rxFrame),
58 mpControl(pWindow),
59 msResourceURL(rsResourceURL),
60 maLayoutSize(rLayoutSize)
62 if (mxFrame.is())
64 css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
65 css::ui::ContextChangeEventMultiplexer::get(
66 ::comphelper::getProcessComponentContext()));
67 if (xMultiplexer.is())
68 xMultiplexer->addContextChangeEventListener(this, mxFrame->getController());
70 if (mpControl != nullptr)
72 mpControl->SetBackground(Theme::GetWallpaper(Theme::Paint_PanelBackground));
73 mpControl->Show();
77 SidebarPanelBase::~SidebarPanelBase()
81 void SAL_CALL SidebarPanelBase::disposing()
82 throw (css::uno::RuntimeException)
84 mpControl.disposeAndClear();
86 if (mxFrame.is())
88 css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
89 css::ui::ContextChangeEventMultiplexer::get(
90 ::comphelper::getProcessComponentContext()));
91 if (xMultiplexer.is())
92 xMultiplexer->removeAllContextChangeEventListeners(this);
93 mxFrame = NULL;
97 // XContextChangeEventListener
98 void SAL_CALL SidebarPanelBase::notifyContextChangeEvent (
99 const ui::ContextChangeEventObject& rEvent)
100 throw (css::uno::RuntimeException, std::exception)
102 IContextChangeReceiver* pContextChangeReceiver
103 = dynamic_cast<IContextChangeReceiver*>(mpControl.get());
104 if (pContextChangeReceiver != NULL)
106 const EnumContext aContext(
107 EnumContext::GetApplicationEnum(rEvent.ApplicationName),
108 EnumContext::GetContextEnum(rEvent.ContextName));
109 pContextChangeReceiver->HandleContextChange(aContext);
113 void SAL_CALL SidebarPanelBase::disposing (
114 const css::lang::EventObject& rEvent)
115 throw (css::uno::RuntimeException, std::exception)
117 (void)rEvent;
119 mxFrame = NULL;
120 mpControl = NULL;
123 css::uno::Reference<css::frame::XFrame> SAL_CALL SidebarPanelBase::getFrame()
124 throw(css::uno::RuntimeException, std::exception)
126 return mxFrame;
129 ::rtl::OUString SAL_CALL SidebarPanelBase::getResourceURL()
130 throw(css::uno::RuntimeException, std::exception)
132 return msResourceURL;
135 sal_Int16 SAL_CALL SidebarPanelBase::getType()
136 throw(css::uno::RuntimeException, std::exception)
138 return ui::UIElementType::TOOLPANEL;
141 Reference<XInterface> SAL_CALL SidebarPanelBase::getRealInterface()
142 throw(css::uno::RuntimeException, std::exception)
144 return Reference<XInterface>(static_cast<XWeak*>(this));
147 Reference<accessibility::XAccessible> SAL_CALL SidebarPanelBase::createAccessible (
148 const Reference<accessibility::XAccessible>& rxParentAccessible)
149 throw(css::uno::RuntimeException, std::exception)
151 (void)rxParentAccessible;
153 // Not yet implemented.
154 return NULL;
157 Reference<awt::XWindow> SAL_CALL SidebarPanelBase::getWindow()
158 throw(css::uno::RuntimeException, std::exception)
160 if (mpControl != nullptr)
161 return Reference<awt::XWindow>(
162 mpControl->GetComponentInterface(),
163 UNO_QUERY);
164 else
165 return NULL;
168 ui::LayoutSize SAL_CALL SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth)
169 throw(css::uno::RuntimeException, std::exception)
171 if (maLayoutSize.Minimum >= 0)
172 return maLayoutSize;
173 else
175 ILayoutableWindow* pLayoutableWindow = dynamic_cast<ILayoutableWindow*>(mpControl.get());
177 if (isLayoutEnabled(mpControl))
179 // widget layout-based sidebar
180 Size aSize(mpControl->get_preferred_size());
181 return ui::LayoutSize(aSize.Height(), aSize.Height(), aSize.Height());
183 else if (pLayoutableWindow != NULL)
184 return pLayoutableWindow->GetHeightForWidth(nWidth);
185 else if (mpControl != nullptr)
187 const sal_Int32 nHeight (mpControl->GetSizePixel().Height());
188 return ui::LayoutSize(nHeight,nHeight,nHeight);
192 return ui::LayoutSize(0,0,0);
195 sal_Int32 SAL_CALL SidebarPanelBase::getMinimalWidth () throw(css::uno::RuntimeException, std::exception)
197 if (isLayoutEnabled(mpControl))
199 // widget layout-based sidebar
200 Size aSize(mpControl->get_preferred_size());
201 return aSize.Width();
203 return 0;
206 } } // end of namespace sfx2::sidebar
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */