1b9e67834SAndre Fischer /**************************************************************
2b9e67834SAndre Fischer *
3b9e67834SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one
4b9e67834SAndre Fischer * or more contributor license agreements. See the NOTICE file
5b9e67834SAndre Fischer * distributed with this work for additional information
6b9e67834SAndre Fischer * regarding copyright ownership. The ASF licenses this file
7b9e67834SAndre Fischer * to you under the Apache License, Version 2.0 (the
8b9e67834SAndre Fischer * "License"); you may not use this file except in compliance
9b9e67834SAndre Fischer * with the License. You may obtain a copy of the License at
10b9e67834SAndre Fischer *
11b9e67834SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0
12b9e67834SAndre Fischer *
13b9e67834SAndre Fischer * Unless required by applicable law or agreed to in writing,
14b9e67834SAndre Fischer * software distributed under the License is distributed on an
15b9e67834SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b9e67834SAndre Fischer * KIND, either express or implied. See the License for the
17b9e67834SAndre Fischer * specific language governing permissions and limitations
18b9e67834SAndre Fischer * under the License.
19b9e67834SAndre Fischer *
20b9e67834SAndre Fischer *************************************************************/
21b9e67834SAndre Fischer
22b9e67834SAndre Fischer #include "precompiled_sfx2.hxx"
23b9e67834SAndre Fischer
24b9e67834SAndre Fischer #include "sfx2/sidebar/SidebarPanelBase.hxx"
25b9e67834SAndre Fischer #include "sfx2/sidebar/Theme.hxx"
2602c50d82SAndre Fischer #include "sfx2/sidebar/ILayoutableWindow.hxx"
27f120fe41SAndre Fischer #include "sfx2/sidebar/IContextChangeReceiver.hxx"
28b9e67834SAndre Fischer #include "sfx2/imagemgr.hxx"
2995a18594SAndre Fischer #include <vcl/ctrl.hxx>
3095a18594SAndre Fischer #include <comphelper/processfactory.hxx>
3195a18594SAndre Fischer
32b9e67834SAndre Fischer #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
33b9e67834SAndre Fischer #include <com/sun/star/ui/UIElementType.hpp>
34b9e67834SAndre Fischer
35b9e67834SAndre Fischer using namespace css;
36b9e67834SAndre Fischer using namespace cssu;
37b9e67834SAndre Fischer
38b9e67834SAndre Fischer
39b9e67834SAndre Fischer namespace sfx2 { namespace sidebar {
40b9e67834SAndre Fischer
Create(const::rtl::OUString & rsResourceURL,const cssu::Reference<css::frame::XFrame> & rxFrame,Window * pWindow,const css::ui::LayoutSize & rLayoutSize)4195a18594SAndre Fischer Reference<ui::XUIElement> SidebarPanelBase::Create (
4295a18594SAndre Fischer const ::rtl::OUString& rsResourceURL,
4395a18594SAndre Fischer const cssu::Reference<css::frame::XFrame>& rxFrame,
447a32b0c8SAndre Fischer Window* pWindow,
4502c50d82SAndre Fischer const css::ui::LayoutSize& rLayoutSize)
4695a18594SAndre Fischer {
4795a18594SAndre Fischer Reference<ui::XUIElement> xUIElement (
4895a18594SAndre Fischer new SidebarPanelBase(
4995a18594SAndre Fischer rsResourceURL,
5095a18594SAndre Fischer rxFrame,
517a32b0c8SAndre Fischer pWindow,
5202c50d82SAndre Fischer rLayoutSize));
5395a18594SAndre Fischer return xUIElement;
5495a18594SAndre Fischer }
5595a18594SAndre Fischer
5695a18594SAndre Fischer
5795a18594SAndre Fischer
5895a18594SAndre Fischer
SidebarPanelBase(const::rtl::OUString & rsResourceURL,const cssu::Reference<css::frame::XFrame> & rxFrame,Window * pWindow,const css::ui::LayoutSize & rLayoutSize)59b9e67834SAndre Fischer SidebarPanelBase::SidebarPanelBase (
60b9e67834SAndre Fischer const ::rtl::OUString& rsResourceURL,
61b9e67834SAndre Fischer const cssu::Reference<css::frame::XFrame>& rxFrame,
627a32b0c8SAndre Fischer Window* pWindow,
6302c50d82SAndre Fischer const css::ui::LayoutSize& rLayoutSize)
64b9e67834SAndre Fischer : SidebarPanelBaseInterfaceBase(m_aMutex),
65b9e67834SAndre Fischer mxFrame(rxFrame),
667a32b0c8SAndre Fischer mpControl(pWindow),
677a32b0c8SAndre Fischer msResourceURL(rsResourceURL),
6802c50d82SAndre Fischer maLayoutSize(rLayoutSize)
69b9e67834SAndre Fischer {
707a32b0c8SAndre Fischer if (mxFrame.is())
717a32b0c8SAndre Fischer {
727a32b0c8SAndre Fischer cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
737a32b0c8SAndre Fischer css::ui::ContextChangeEventMultiplexer::get(
747a32b0c8SAndre Fischer ::comphelper::getProcessComponentContext()));
757a32b0c8SAndre Fischer if (xMultiplexer.is())
767a32b0c8SAndre Fischer xMultiplexer->addContextChangeEventListener(this, mxFrame->getController());
777a32b0c8SAndre Fischer }
787a32b0c8SAndre Fischer if (mpControl != NULL)
79*37fee4fdSAndre Fischer {
80*37fee4fdSAndre Fischer mpControl->SetBackground(Theme::GetWallpaper(Theme::Paint_PanelBackground));
817a32b0c8SAndre Fischer mpControl->Show();
82*37fee4fdSAndre Fischer }
83b9e67834SAndre Fischer }
84b9e67834SAndre Fischer
85b9e67834SAndre Fischer
86b9e67834SAndre Fischer
87b9e67834SAndre Fischer
~SidebarPanelBase(void)88b9e67834SAndre Fischer SidebarPanelBase::~SidebarPanelBase (void)
89b9e67834SAndre Fischer {
90b9e67834SAndre Fischer }
91b9e67834SAndre Fischer
92b9e67834SAndre Fischer
93b9e67834SAndre Fischer
94b9e67834SAndre Fischer
disposing(void)95b9e67834SAndre Fischer void SAL_CALL SidebarPanelBase::disposing (void)
96b9e67834SAndre Fischer throw (cssu::RuntimeException)
97b9e67834SAndre Fischer {
9802c50d82SAndre Fischer if (mpControl != NULL)
9902c50d82SAndre Fischer {
10002c50d82SAndre Fischer delete mpControl;
10102c50d82SAndre Fischer mpControl = NULL;
10202c50d82SAndre Fischer }
10395a18594SAndre Fischer
104b9e67834SAndre Fischer if (mxFrame.is())
105b9e67834SAndre Fischer {
106b9e67834SAndre Fischer cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
107b9e67834SAndre Fischer css::ui::ContextChangeEventMultiplexer::get(
108b9e67834SAndre Fischer ::comphelper::getProcessComponentContext()));
109b9e67834SAndre Fischer if (xMultiplexer.is())
110b9e67834SAndre Fischer xMultiplexer->removeAllContextChangeEventListeners(this);
111b9e67834SAndre Fischer mxFrame = NULL;
112b9e67834SAndre Fischer }
113b9e67834SAndre Fischer }
114b9e67834SAndre Fischer
115b9e67834SAndre Fischer
116b9e67834SAndre Fischer
117b9e67834SAndre Fischer
SetControl(::Window * pControl)1187a32b0c8SAndre Fischer void SidebarPanelBase::SetControl (::Window* pControl)
1197a32b0c8SAndre Fischer {
1207a32b0c8SAndre Fischer mpControl = pControl;
1217a32b0c8SAndre Fischer }
1227a32b0c8SAndre Fischer
1237a32b0c8SAndre Fischer
1247a32b0c8SAndre Fischer
1257a32b0c8SAndre Fischer
GetControl(void) const1267a32b0c8SAndre Fischer ::Window* SidebarPanelBase::GetControl (void) const
1277a32b0c8SAndre Fischer {
1287a32b0c8SAndre Fischer return mpControl;
1297a32b0c8SAndre Fischer }
1307a32b0c8SAndre Fischer
1317a32b0c8SAndre Fischer
1327a32b0c8SAndre Fischer
1337a32b0c8SAndre Fischer
134b9e67834SAndre Fischer // XContextChangeEventListener
notifyContextChangeEvent(const ui::ContextChangeEventObject & rEvent)135b9e67834SAndre Fischer void SAL_CALL SidebarPanelBase::notifyContextChangeEvent (
136b9e67834SAndre Fischer const ui::ContextChangeEventObject& rEvent)
13795a18594SAndre Fischer throw (cssu::RuntimeException)
138b9e67834SAndre Fischer {
139f120fe41SAndre Fischer IContextChangeReceiver* pContextChangeReceiver
140f120fe41SAndre Fischer = dynamic_cast<IContextChangeReceiver*>(mpControl);
1417a32b0c8SAndre Fischer if (pContextChangeReceiver != NULL)
14295a18594SAndre Fischer {
14395a18594SAndre Fischer const EnumContext aContext(
144b9e67834SAndre Fischer EnumContext::GetApplicationEnum(rEvent.ApplicationName),
14595a18594SAndre Fischer EnumContext::GetContextEnum(rEvent.ContextName));
1467a32b0c8SAndre Fischer pContextChangeReceiver->HandleContextChange(aContext);
14795a18594SAndre Fischer }
148b9e67834SAndre Fischer }
149b9e67834SAndre Fischer
150b9e67834SAndre Fischer
151b9e67834SAndre Fischer
152b9e67834SAndre Fischer
disposing(const css::lang::EventObject & rEvent)153b9e67834SAndre Fischer void SAL_CALL SidebarPanelBase::disposing (
154b9e67834SAndre Fischer const css::lang::EventObject& rEvent)
155b9e67834SAndre Fischer throw (cssu::RuntimeException)
156b9e67834SAndre Fischer {
15795a18594SAndre Fischer (void)rEvent;
15802c50d82SAndre Fischer
15995a18594SAndre Fischer mxFrame = NULL;
16095a18594SAndre Fischer mpControl = NULL;
161b9e67834SAndre Fischer }
162b9e67834SAndre Fischer
163b9e67834SAndre Fischer
164b9e67834SAndre Fischer
165b9e67834SAndre Fischer
getFrame(void)166b9e67834SAndre Fischer cssu::Reference<css::frame::XFrame> SAL_CALL SidebarPanelBase::getFrame (void)
167b9e67834SAndre Fischer throw(cssu::RuntimeException)
168b9e67834SAndre Fischer {
169b9e67834SAndre Fischer return mxFrame;
170b9e67834SAndre Fischer }
171b9e67834SAndre Fischer
172b9e67834SAndre Fischer
173b9e67834SAndre Fischer
174b9e67834SAndre Fischer
getResourceURL(void)175b9e67834SAndre Fischer ::rtl::OUString SAL_CALL SidebarPanelBase::getResourceURL (void)
176b9e67834SAndre Fischer throw(cssu::RuntimeException)
177b9e67834SAndre Fischer {
178b9e67834SAndre Fischer return msResourceURL;
179b9e67834SAndre Fischer }
180b9e67834SAndre Fischer
181b9e67834SAndre Fischer
182b9e67834SAndre Fischer
183b9e67834SAndre Fischer
getType(void)184b9e67834SAndre Fischer sal_Int16 SAL_CALL SidebarPanelBase::getType (void)
185b9e67834SAndre Fischer throw(cssu::RuntimeException)
186b9e67834SAndre Fischer {
187b9e67834SAndre Fischer return ui::UIElementType::TOOLPANEL;
188b9e67834SAndre Fischer }
189b9e67834SAndre Fischer
190b9e67834SAndre Fischer
191b9e67834SAndre Fischer
192b9e67834SAndre Fischer
getRealInterface(void)193b9e67834SAndre Fischer Reference<XInterface> SAL_CALL SidebarPanelBase::getRealInterface (void)
194b9e67834SAndre Fischer throw(cssu::RuntimeException)
195b9e67834SAndre Fischer {
196b9e67834SAndre Fischer return Reference<XInterface>(static_cast<XWeak*>(this));
197b9e67834SAndre Fischer }
198b9e67834SAndre Fischer
199b9e67834SAndre Fischer
200b9e67834SAndre Fischer
201b9e67834SAndre Fischer
createAccessible(const Reference<accessibility::XAccessible> & rxParentAccessible)202b9e67834SAndre Fischer Reference<accessibility::XAccessible> SAL_CALL SidebarPanelBase::createAccessible (
203b9e67834SAndre Fischer const Reference<accessibility::XAccessible>& rxParentAccessible)
204b9e67834SAndre Fischer throw(cssu::RuntimeException)
205b9e67834SAndre Fischer {
20695a18594SAndre Fischer (void)rxParentAccessible;
20795a18594SAndre Fischer
208b9e67834SAndre Fischer // Not yet implemented.
209b9e67834SAndre Fischer return NULL;
210b9e67834SAndre Fischer }
211b9e67834SAndre Fischer
212b9e67834SAndre Fischer
213b9e67834SAndre Fischer
214b9e67834SAndre Fischer
getWindow(void)215b9e67834SAndre Fischer Reference<awt::XWindow> SAL_CALL SidebarPanelBase::getWindow (void)
216b9e67834SAndre Fischer throw(cssu::RuntimeException)
217b9e67834SAndre Fischer {
21895a18594SAndre Fischer if (mpControl != NULL)
21995a18594SAndre Fischer return Reference<awt::XWindow>(
22095a18594SAndre Fischer mpControl->GetComponentInterface(),
22195a18594SAndre Fischer UNO_QUERY);
22295a18594SAndre Fischer else
22395a18594SAndre Fischer return NULL;
224b9e67834SAndre Fischer }
225b9e67834SAndre Fischer
226b9e67834SAndre Fischer
227b9e67834SAndre Fischer
228b9e67834SAndre Fischer
getHeightForWidth(const sal_Int32 nWidth)2297a32b0c8SAndre Fischer ui::LayoutSize SAL_CALL SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth)
23095a18594SAndre Fischer throw(cssu::RuntimeException)
231b9e67834SAndre Fischer {
23202c50d82SAndre Fischer if (maLayoutSize.Minimum >= 0)
23302c50d82SAndre Fischer return maLayoutSize;
23402c50d82SAndre Fischer else
2357a32b0c8SAndre Fischer {
23602c50d82SAndre Fischer ILayoutableWindow* pLayoutableWindow = dynamic_cast<ILayoutableWindow*>(mpControl);
23702c50d82SAndre Fischer if (pLayoutableWindow != NULL)
23802c50d82SAndre Fischer return pLayoutableWindow->GetHeightForWidth(nWidth);
23902c50d82SAndre Fischer else if (mpControl != NULL)
24002c50d82SAndre Fischer {
24102c50d82SAndre Fischer const sal_Int32 nHeight (mpControl->GetSizePixel().Height());
24202c50d82SAndre Fischer return ui::LayoutSize(nHeight,nHeight,nHeight);
24302c50d82SAndre Fischer }
2447a32b0c8SAndre Fischer }
24502c50d82SAndre Fischer
24602c50d82SAndre Fischer return ui::LayoutSize(0,0,0);
2477a32b0c8SAndre Fischer }
2487a32b0c8SAndre Fischer
2497a32b0c8SAndre Fischer
2507a32b0c8SAndre Fischer
2517a32b0c8SAndre Fischer
252b9e67834SAndre Fischer } } // end of namespace sfx2::sidebar
253