update dev300-m58
[ooovba.git] / sdext / source / presenter / PresenterPaneFactory.cxx
blob6004c6667c8ca52795feb726d1fc1c593995dad0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterPaneFactory.cxx,v $
11 * $Revision: 1.5 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "PresenterPaneFactory.hxx"
36 #include "PresenterController.hxx"
37 #include "PresenterPane.hxx"
38 #include "PresenterPaneBorderPainter.hxx"
39 #include "PresenterPaneContainer.hxx"
40 #include "PresenterSpritePane.hxx"
41 #include <com/sun/star/container/XChild.hpp>
42 #include <com/sun/star/drawing/framework/ResourceId.hpp>
43 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
44 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
45 #include <com/sun/star/frame/XController.hpp>
46 #include <com/sun/star/lang/XComponent.hpp>
47 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
48 #include <boost/bind.hpp>
50 using namespace ::com::sun::star;
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::drawing::framework;
53 using ::rtl::OUString;
55 namespace sdext { namespace presenter {
57 const ::rtl::OUString PresenterPaneFactory::msCurrentSlidePreviewPaneURL(
58 OUString::createFromAscii("private:resource/pane/Presenter/Pane1"));
59 const ::rtl::OUString PresenterPaneFactory::msNextSlidePreviewPaneURL(
60 OUString::createFromAscii("private:resource/pane/Presenter/Pane2"));
61 const ::rtl::OUString PresenterPaneFactory::msNotesPaneURL(
62 OUString::createFromAscii("private:resource/pane/Presenter/Pane3"));
63 const ::rtl::OUString PresenterPaneFactory::msToolBarPaneURL(
64 OUString::createFromAscii("private:resource/pane/Presenter/Pane4"));
65 const ::rtl::OUString PresenterPaneFactory::msSlideSorterPaneURL(
66 OUString::createFromAscii("private:resource/pane/Presenter/Pane5"));
67 const ::rtl::OUString PresenterPaneFactory::msHelpPaneURL(
68 OUString::createFromAscii("private:resource/pane/Presenter/Pane6"));
70 const ::rtl::OUString PresenterPaneFactory::msOverlayPaneURL(
71 OUString::createFromAscii("private:resource/pane/Presenter/Overlay"));
75 //===== PresenterPaneFactory ==================================================
77 Reference<drawing::framework::XResourceFactory> PresenterPaneFactory::Create (
78 const Reference<uno::XComponentContext>& rxContext,
79 const Reference<frame::XController>& rxController,
80 const ::rtl::Reference<PresenterController>& rpPresenterController)
82 rtl::Reference<PresenterPaneFactory> pFactory (
83 new PresenterPaneFactory(rxContext,rpPresenterController));
84 pFactory->Register(rxController);
85 return Reference<drawing::framework::XResourceFactory>(
86 static_cast<XWeak*>(pFactory.get()), UNO_QUERY);
92 PresenterPaneFactory::PresenterPaneFactory (
93 const Reference<uno::XComponentContext>& rxContext,
94 const ::rtl::Reference<PresenterController>& rpPresenterController)
95 : PresenterPaneFactoryInterfaceBase(m_aMutex),
96 mxComponentContextWeak(rxContext),
97 mxConfigurationControllerWeak(),
98 mpPresenterController(rpPresenterController),
99 mpResourceCache()
106 void PresenterPaneFactory::Register (const Reference<frame::XController>& rxController)
108 Reference<XConfigurationController> xCC;
111 // Get the configuration controller.
112 Reference<XControllerManager> xCM (rxController, UNO_QUERY_THROW);
113 xCC = Reference<XConfigurationController>(xCM->getConfigurationController());
114 mxConfigurationControllerWeak = xCC;
115 if ( ! xCC.is())
117 throw RuntimeException();
119 else
121 xCC->addResourceFactory(
122 OUString::createFromAscii("private:resource/pane/Presenter/*"),
123 this);
126 catch (RuntimeException&)
128 OSL_ASSERT(false);
129 if (xCC.is())
130 xCC->removeResourceFactoryForReference(this);
131 mxConfigurationControllerWeak = WeakReference<XConfigurationController>();
133 throw;
140 PresenterPaneFactory::~PresenterPaneFactory (void)
147 void SAL_CALL PresenterPaneFactory::disposing (void)
148 throw (RuntimeException)
150 Reference<XConfigurationController> xCC (mxConfigurationControllerWeak);
151 if (xCC.is())
152 xCC->removeResourceFactoryForReference(this);
153 mxConfigurationControllerWeak = WeakReference<XConfigurationController>();
155 // Dispose the panes in the cache.
156 if (mpResourceCache.get() != NULL)
158 ResourceContainer::const_iterator iPane (mpResourceCache->begin());
159 ResourceContainer::const_iterator iEnd (mpResourceCache->end());
160 for ( ; iPane!=iEnd; ++iPane)
162 Reference<lang::XComponent> xPaneComponent (iPane->second, UNO_QUERY);
163 if (xPaneComponent.is())
164 xPaneComponent->dispose();
166 mpResourceCache.reset();
173 //----- XPaneFactory ----------------------------------------------------------
175 Reference<XResource> SAL_CALL PresenterPaneFactory::createResource (
176 const Reference<XResourceId>& rxPaneId)
177 throw (RuntimeException)
179 ThrowIfDisposed();
181 if ( ! rxPaneId.is())
182 return NULL;
184 const OUString sPaneURL (rxPaneId->getResourceURL());
185 if (sPaneURL.getLength() == 0)
186 return NULL;
188 if (mpResourceCache.get() != NULL)
190 // Has the requested resource already been created?
191 ResourceContainer::const_iterator iResource (mpResourceCache->find(sPaneURL));
192 if (iResource != mpResourceCache->end())
194 // Yes. Mark it as active.
195 rtl::Reference<PresenterPaneContainer> pPaneContainer(
196 mpPresenterController->GetPaneContainer());
197 PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
198 pPaneContainer->FindPaneURL(sPaneURL));
199 if (pDescriptor.get() != NULL)
201 pDescriptor->SetActivationState(true);
202 if (pDescriptor->mxBorderWindow.is())
203 pDescriptor->mxBorderWindow->setVisible(sal_True);
204 pPaneContainer->StorePane(pDescriptor->mxPane);
207 return iResource->second;
211 // No. Create a new one.
212 Reference<XResource> xResource = CreatePane(rxPaneId, OUString());
213 return xResource;
219 void SAL_CALL PresenterPaneFactory::releaseResource (const Reference<XResource>& rxResource)
220 throw (RuntimeException)
222 ThrowIfDisposed();
224 if ( ! rxResource.is())
225 throw lang::IllegalArgumentException();
227 // Mark the pane as inactive.
228 rtl::Reference<PresenterPaneContainer> pPaneContainer(
229 mpPresenterController->GetPaneContainer());
230 const OUString sPaneURL (rxResource->getResourceId()->getResourceURL());
231 PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
232 pPaneContainer->FindPaneURL(sPaneURL));
233 if (pDescriptor.get() != NULL)
235 pDescriptor->SetActivationState(false);
236 if (pDescriptor->mxBorderWindow.is())
237 pDescriptor->mxBorderWindow->setVisible(sal_False);
239 if (mpResourceCache.get() != NULL)
241 // Store the pane in the cache.
242 (*mpResourceCache)[sPaneURL] = rxResource;
244 else
246 // Dispose the pane.
247 Reference<lang::XComponent> xPaneComponent (rxResource, UNO_QUERY);
248 if (xPaneComponent.is())
249 xPaneComponent->dispose();
257 //-----------------------------------------------------------------------------
259 Reference<XResource> PresenterPaneFactory::CreatePane (
260 const Reference<XResourceId>& rxPaneId,
261 const OUString& rsTitle)
263 (void)rsTitle;
265 if ( ! rxPaneId.is())
266 return NULL;
268 Reference<XConfigurationController> xCC (mxConfigurationControllerWeak);
269 if ( ! xCC.is())
270 return NULL;
272 Reference<XComponentContext> xContext (mxComponentContextWeak);
273 if ( ! xContext.is())
274 return NULL;
276 Reference<XPane> xParentPane (xCC->getResource(rxPaneId->getAnchor()), UNO_QUERY);
277 if ( ! xParentPane.is())
278 return NULL;
282 return CreatePane(
283 rxPaneId,
284 rsTitle,
285 xParentPane,
286 rxPaneId->getFullResourceURL().Arguments.compareToAscii("Sprite=1") == 0);
288 catch (Exception&)
290 OSL_ASSERT(false);
293 return NULL;
299 Reference<XResource> PresenterPaneFactory::CreatePane (
300 const Reference<XResourceId>& rxPaneId,
301 const OUString& rsTitle,
302 const Reference<drawing::framework::XPane>& rxParentPane,
303 const bool bIsSpritePane)
305 Reference<XComponentContext> xContext (mxComponentContextWeak);
306 Reference<lang::XMultiComponentFactory> xFactory (
307 xContext->getServiceManager(), UNO_QUERY_THROW);
309 // Create a border window and canvas and store it in the pane
310 // container.
312 // Create the pane.
313 ::rtl::Reference<PresenterPaneBase> xPane;
314 if (bIsSpritePane)
316 xPane = ::rtl::Reference<PresenterPaneBase>(
317 new PresenterSpritePane(xContext, mpPresenterController));
319 else
321 xPane = ::rtl::Reference<PresenterPaneBase>(
322 new PresenterPane(xContext, mpPresenterController));
325 // Supply arguments.
326 Sequence<Any> aArguments (6);
327 aArguments[0] <<= rxPaneId;
328 aArguments[1] <<= rxParentPane->getWindow();
329 aArguments[2] <<= rxParentPane->getCanvas();
330 aArguments[3] <<= rsTitle;
331 aArguments[4] <<= Reference<drawing::framework::XPaneBorderPainter>(
332 static_cast<XWeak*>(mpPresenterController->GetPaneBorderPainter().get()),
333 UNO_QUERY);
334 aArguments[5] <<= bIsSpritePane ? false : true;
335 xPane->initialize(aArguments);
337 // Store pane and canvases and windows in container.
338 ::rtl::Reference<PresenterPaneContainer> pContainer (
339 mpPresenterController->GetPaneContainer());
340 PresenterPaneContainer::SharedPaneDescriptor pDescriptor(
341 pContainer->StoreBorderWindow(rxPaneId, xPane->GetBorderWindow()));
342 pContainer->StorePane(xPane);
343 if (pDescriptor.get() != NULL)
345 if (bIsSpritePane)
347 pDescriptor->maSpriteProvider = ::boost::bind(
348 &PresenterSpritePane::GetSprite,
349 dynamic_cast<PresenterSpritePane*>(xPane.get()));
350 pDescriptor->mbIsSprite = true;
351 pDescriptor->mbNeedsClipping = false;
353 else
355 pDescriptor->mbIsSprite = false;
356 pDescriptor->mbNeedsClipping = true;
359 // Get the window of the frame and make that visible.
360 Reference<awt::XWindow> xWindow (pDescriptor->mxBorderWindow, UNO_QUERY_THROW);
361 xWindow->setVisible(sal_True);
364 return Reference<XResource>(static_cast<XWeak*>(xPane.get()), UNO_QUERY_THROW);
370 void PresenterPaneFactory::ThrowIfDisposed (void) const
371 throw (::com::sun::star::lang::DisposedException)
373 if (rBHelper.bDisposed || rBHelper.bInDispose)
375 throw lang::DisposedException (
376 OUString(RTL_CONSTASCII_USTRINGPARAM(
377 "PresenterPaneFactory object has already been disposed")),
378 const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
383 } } // end of namespace sdext::presenter