bump product version to 5.0.4.1
[LibreOffice.git] / sdext / source / presenter / PresenterPaneFactory.cxx
blob008f09ca12530923abe43ed88b904204d54005c8
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 .
20 #include "PresenterPaneFactory.hxx"
21 #include "PresenterController.hxx"
22 #include "PresenterPane.hxx"
23 #include "PresenterPaneBorderPainter.hxx"
24 #include "PresenterPaneContainer.hxx"
25 #include "PresenterSpritePane.hxx"
26 #include <com/sun/star/container/XChild.hpp>
27 #include <com/sun/star/drawing/framework/ResourceId.hpp>
28 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
29 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
30 #include <com/sun/star/frame/XController.hpp>
31 #include <com/sun/star/lang/XComponent.hpp>
32 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 #include <boost/bind.hpp>
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::lang;
38 using namespace ::com::sun::star::drawing::framework;
40 namespace sdext { namespace presenter {
42 const OUString PresenterPaneFactory::msCurrentSlidePreviewPaneURL(
43 "private:resource/pane/Presenter/Pane1");
44 const OUString PresenterPaneFactory::msNextSlidePreviewPaneURL(
45 "private:resource/pane/Presenter/Pane2");
46 const OUString PresenterPaneFactory::msNotesPaneURL(
47 "private:resource/pane/Presenter/Pane3");
48 const OUString PresenterPaneFactory::msToolBarPaneURL(
49 "private:resource/pane/Presenter/Pane4");
50 const OUString PresenterPaneFactory::msSlideSorterPaneURL(
51 "private:resource/pane/Presenter/Pane5");
52 const OUString PresenterPaneFactory::msHelpPaneURL(
53 "private:resource/pane/Presenter/Pane6");
55 const OUString PresenterPaneFactory::msOverlayPaneURL(
56 "private:resource/pane/Presenter/Overlay");
58 //===== PresenterPaneFactory ==================================================
60 Reference<drawing::framework::XResourceFactory> PresenterPaneFactory::Create (
61 const Reference<uno::XComponentContext>& rxContext,
62 const Reference<frame::XController>& rxController,
63 const ::rtl::Reference<PresenterController>& rpPresenterController)
65 rtl::Reference<PresenterPaneFactory> pFactory (
66 new PresenterPaneFactory(rxContext,rpPresenterController));
67 pFactory->Register(rxController);
68 return Reference<drawing::framework::XResourceFactory>(
69 static_cast<XWeak*>(pFactory.get()), UNO_QUERY);
72 PresenterPaneFactory::PresenterPaneFactory (
73 const Reference<uno::XComponentContext>& rxContext,
74 const ::rtl::Reference<PresenterController>& rpPresenterController)
75 : PresenterPaneFactoryInterfaceBase(m_aMutex),
76 mxComponentContextWeak(rxContext),
77 mxConfigurationControllerWeak(),
78 mpPresenterController(rpPresenterController),
79 mpResourceCache()
83 void PresenterPaneFactory::Register (const Reference<frame::XController>& rxController)
85 Reference<XConfigurationController> xCC;
86 try
88 // Get the configuration controller.
89 Reference<XControllerManager> xCM (rxController, UNO_QUERY_THROW);
90 xCC = Reference<XConfigurationController>(xCM->getConfigurationController());
91 mxConfigurationControllerWeak = xCC;
92 if ( ! xCC.is())
94 throw RuntimeException();
96 else
98 xCC->addResourceFactory(
99 OUString("private:resource/pane/Presenter/*"),
100 this);
103 catch (RuntimeException&)
105 OSL_ASSERT(false);
106 if (xCC.is())
107 xCC->removeResourceFactoryForReference(this);
108 mxConfigurationControllerWeak = WeakReference<XConfigurationController>();
110 throw;
114 PresenterPaneFactory::~PresenterPaneFactory()
118 void SAL_CALL PresenterPaneFactory::disposing()
119 throw (RuntimeException)
121 Reference<XConfigurationController> xCC (mxConfigurationControllerWeak);
122 if (xCC.is())
123 xCC->removeResourceFactoryForReference(this);
124 mxConfigurationControllerWeak = WeakReference<XConfigurationController>();
126 // Dispose the panes in the cache.
127 if (mpResourceCache.get() != NULL)
129 ResourceContainer::const_iterator iPane (mpResourceCache->begin());
130 ResourceContainer::const_iterator iEnd (mpResourceCache->end());
131 for ( ; iPane!=iEnd; ++iPane)
133 Reference<lang::XComponent> xPaneComponent (iPane->second, UNO_QUERY);
134 if (xPaneComponent.is())
135 xPaneComponent->dispose();
137 mpResourceCache.reset();
141 //----- XPaneFactory ----------------------------------------------------------
143 Reference<XResource> SAL_CALL PresenterPaneFactory::createResource (
144 const Reference<XResourceId>& rxPaneId)
145 throw (RuntimeException, IllegalArgumentException, WrappedTargetException, std::exception)
147 ThrowIfDisposed();
149 if ( ! rxPaneId.is())
150 return NULL;
152 const OUString sPaneURL (rxPaneId->getResourceURL());
153 if (sPaneURL.isEmpty())
154 return NULL;
156 if (mpResourceCache.get() != NULL)
158 // Has the requested resource already been created?
159 ResourceContainer::const_iterator iResource (mpResourceCache->find(sPaneURL));
160 if (iResource != mpResourceCache->end())
162 // Yes. Mark it as active.
163 rtl::Reference<PresenterPaneContainer> pPaneContainer(
164 mpPresenterController->GetPaneContainer());
165 PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
166 pPaneContainer->FindPaneURL(sPaneURL));
167 if (pDescriptor.get() != NULL)
169 pDescriptor->SetActivationState(true);
170 if (pDescriptor->mxBorderWindow.is())
171 pDescriptor->mxBorderWindow->setVisible(sal_True);
172 pPaneContainer->StorePane(pDescriptor->mxPane);
175 return iResource->second;
179 // No. Create a new one.
180 Reference<XResource> xResource = CreatePane(rxPaneId, OUString());
181 return xResource;
184 void SAL_CALL PresenterPaneFactory::releaseResource (const Reference<XResource>& rxResource)
185 throw (RuntimeException, std::exception)
187 ThrowIfDisposed();
189 if ( ! rxResource.is())
190 throw lang::IllegalArgumentException();
192 // Mark the pane as inactive.
193 rtl::Reference<PresenterPaneContainer> pPaneContainer(
194 mpPresenterController->GetPaneContainer());
195 const OUString sPaneURL (rxResource->getResourceId()->getResourceURL());
196 PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
197 pPaneContainer->FindPaneURL(sPaneURL));
198 if (pDescriptor.get() != NULL)
200 pDescriptor->SetActivationState(false);
201 if (pDescriptor->mxBorderWindow.is())
202 pDescriptor->mxBorderWindow->setVisible(sal_False);
204 if (mpResourceCache.get() != NULL)
206 // Store the pane in the cache.
207 (*mpResourceCache)[sPaneURL] = rxResource;
209 else
211 // Dispose the pane.
212 Reference<lang::XComponent> xPaneComponent (rxResource, UNO_QUERY);
213 if (xPaneComponent.is())
214 xPaneComponent->dispose();
221 Reference<XResource> PresenterPaneFactory::CreatePane (
222 const Reference<XResourceId>& rxPaneId,
223 const OUString& rsTitle)
225 if ( ! rxPaneId.is())
226 return NULL;
228 Reference<XConfigurationController> xCC (mxConfigurationControllerWeak);
229 if ( ! xCC.is())
230 return NULL;
232 Reference<XComponentContext> xContext (mxComponentContextWeak);
233 if ( ! xContext.is())
234 return NULL;
236 Reference<XPane> xParentPane (xCC->getResource(rxPaneId->getAnchor()), UNO_QUERY);
237 if ( ! xParentPane.is())
238 return NULL;
242 return CreatePane(
243 rxPaneId,
244 rsTitle,
245 xParentPane,
246 rxPaneId->getFullResourceURL().Arguments == "Sprite=1");
248 catch (Exception&)
250 OSL_ASSERT(false);
253 return NULL;
256 Reference<XResource> PresenterPaneFactory::CreatePane (
257 const Reference<XResourceId>& rxPaneId,
258 const OUString& rsTitle,
259 const Reference<drawing::framework::XPane>& rxParentPane,
260 const bool bIsSpritePane)
262 Reference<XComponentContext> xContext (mxComponentContextWeak);
263 Reference<lang::XMultiComponentFactory> xFactory (
264 xContext->getServiceManager(), UNO_QUERY_THROW);
266 // Create a border window and canvas and store it in the pane
267 // container.
269 // Create the pane.
270 ::rtl::Reference<PresenterPaneBase> xPane;
271 if (bIsSpritePane)
273 xPane = ::rtl::Reference<PresenterPaneBase>(
274 new PresenterSpritePane(xContext, mpPresenterController));
276 else
278 xPane = ::rtl::Reference<PresenterPaneBase>(
279 new PresenterPane(xContext, mpPresenterController));
282 // Supply arguments.
283 Sequence<Any> aArguments (6);
284 aArguments[0] <<= rxPaneId;
285 aArguments[1] <<= rxParentPane->getWindow();
286 aArguments[2] <<= rxParentPane->getCanvas();
287 aArguments[3] <<= rsTitle;
288 aArguments[4] <<= Reference<drawing::framework::XPaneBorderPainter>(
289 static_cast<XWeak*>(mpPresenterController->GetPaneBorderPainter().get()),
290 UNO_QUERY);
291 aArguments[5] <<= !bIsSpritePane;
292 xPane->initialize(aArguments);
294 // Store pane and canvases and windows in container.
295 ::rtl::Reference<PresenterPaneContainer> pContainer (
296 mpPresenterController->GetPaneContainer());
297 PresenterPaneContainer::SharedPaneDescriptor pDescriptor(
298 pContainer->StoreBorderWindow(rxPaneId, xPane->GetBorderWindow()));
299 pContainer->StorePane(xPane);
300 if (pDescriptor.get() != NULL)
302 if (bIsSpritePane)
304 pDescriptor->maSpriteProvider = ::boost::bind(
305 &PresenterSpritePane::GetSprite,
306 dynamic_cast<PresenterSpritePane*>(xPane.get()));
307 pDescriptor->mbIsSprite = true;
308 pDescriptor->mbNeedsClipping = false;
310 else
312 pDescriptor->mbIsSprite = false;
313 pDescriptor->mbNeedsClipping = true;
316 // Get the window of the frame and make that visible.
317 Reference<awt::XWindow> xWindow (pDescriptor->mxBorderWindow, UNO_QUERY_THROW);
318 xWindow->setVisible(sal_True);
321 return Reference<XResource>(static_cast<XWeak*>(xPane.get()), UNO_QUERY_THROW);
324 void PresenterPaneFactory::ThrowIfDisposed() const
325 throw (::com::sun::star::lang::DisposedException)
327 if (rBHelper.bDisposed || rBHelper.bInDispose)
329 throw lang::DisposedException (
330 OUString( "PresenterPaneFactory object has already been disposed"),
331 const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
335 } } // end of namespace sdext::presenter
337 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */