Update ooo320-m1
[ooovba.git] / sd / source / ui / framework / factories / PresentationFactory.cxx
bloba1714c719850496a4e46a7d6a4f74e81a40bd0c9
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: PresentationFactory.cxx,v $
11 * $Revision: 1.3 $
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 #include "precompiled_sd.hxx"
34 #include "framework/PresentationFactory.hxx"
36 #include "framework/FrameworkHelper.hxx"
37 #include "DrawController.hxx"
38 #include "ViewShellBase.hxx"
39 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
40 #include <cppuhelper/compbase1.hxx>
41 #include "slideshow.hxx"
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::drawing::framework;
47 using ::rtl::OUString;
48 using ::sd::framework::FrameworkHelper;
51 namespace sd { namespace framework {
53 namespace {
55 typedef ::cppu::WeakComponentImplHelper1 <lang::XInitialization> PresentationFactoryProviderInterfaceBase;
57 class PresentationFactoryProvider
58 : protected MutexOwner,
59 public PresentationFactoryProviderInterfaceBase
61 public:
62 PresentationFactoryProvider (const Reference<XComponentContext>& rxContext);
63 virtual ~PresentationFactoryProvider (void);
65 virtual void SAL_CALL disposing (void);
67 // XInitialization
69 virtual void SAL_CALL initialize(
70 const ::com::sun::star::uno::Sequence<com::sun::star::uno::Any>& aArguments)
71 throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
77 typedef ::cppu::WeakComponentImplHelper1 <XView> PresentationViewInterfaceBase;
79 /** The PresentationView is not an actual view, it is a marker whose
80 existence in a configuration indicates that a slideshow is running
81 (in another application window).
83 class PresentationView
84 : protected MutexOwner,
85 public PresentationViewInterfaceBase
87 public:
88 PresentationView (const Reference<XResourceId>& rxViewId)
89 : PresentationViewInterfaceBase(maMutex),mxResourceId(rxViewId) {};
90 virtual ~PresentationView (void) {};
92 // XView
94 virtual Reference<XResourceId> SAL_CALL getResourceId (void) throw (RuntimeException)
95 { return mxResourceId; };
97 virtual sal_Bool SAL_CALL isAnchorOnly (void) throw (RuntimeException)
98 { return false; }
101 private:
102 Reference<XResourceId> mxResourceId;
105 } // end of anonymous namespace.
110 //===== PresentationFactoryProvider service ===================================
112 Reference<XInterface> SAL_CALL PresentationFactoryProvider_createInstance (
113 const Reference<XComponentContext>& rxContext)
115 return Reference<XInterface>(static_cast<XWeak*>(new PresentationFactoryProvider(rxContext)));
121 ::rtl::OUString PresentationFactoryProvider_getImplementationName (void) throw(RuntimeException)
123 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
124 "com.sun.star.comp.Draw.framework.PresentationFactoryProvider"));
130 Sequence<rtl::OUString> SAL_CALL PresentationFactoryProvider_getSupportedServiceNames (void)
131 throw (RuntimeException)
133 static const ::rtl::OUString sServiceName(RTL_CONSTASCII_USTRINGPARAM(
134 "com.sun.star.drawing.framework.PresentationFactoryProvider"));
135 return Sequence<rtl::OUString>(&sServiceName, 1);
141 //===== PresentationFactory ===================================================
143 const ::rtl::OUString PresentationFactory::msPresentationViewURL(
144 OUString::createFromAscii("private:resource/view/Presentation"));
147 PresentationFactory::PresentationFactory (
148 const Reference<frame::XController>& rxController)
149 : PresentationFactoryInterfaceBase(MutexOwner::maMutex),
150 mxConfigurationController(),
151 mxController(rxController)
155 // Get the XController from the first argument.
156 Reference<XControllerManager> xControllerManager(rxController, UNO_QUERY_THROW);
157 mxConfigurationController = xControllerManager->getConfigurationController();
159 catch (RuntimeException&)
161 OSL_ASSERT(false);
169 PresentationFactory::~PresentationFactory (void)
176 void SAL_CALL PresentationFactory::disposing (void)
183 //----- XViewFactory ----------------------------------------------------------
185 Reference<XResource> SAL_CALL PresentationFactory::createResource (
186 const Reference<XResourceId>& rxViewId)
187 throw (RuntimeException)
189 ThrowIfDisposed();
191 if (rxViewId.is())
192 if ( ! rxViewId->hasAnchor() && rxViewId->getResourceURL().equals(msPresentationViewURL))
193 return new PresentationView(rxViewId);
195 return Reference<XResource>();
201 void SAL_CALL PresentationFactory::releaseResource (
202 const Reference<XResource>& rxView)
203 throw (RuntimeException)
205 ThrowIfDisposed();
206 (void)rxView;
208 Reference<lang::XUnoTunnel> xTunnel (mxController, UNO_QUERY);
209 if (xTunnel.is())
211 ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
212 xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
213 if (pController != NULL)
215 ViewShellBase* pBase = pController->GetViewShellBase();
216 if (pBase != NULL)
217 SlideShow::Stop( *pBase );
225 //===== XConfigurationChangeListener ==========================================
227 void SAL_CALL PresentationFactory::notifyConfigurationChange (
228 const ConfigurationChangeEvent& rEvent)
229 throw (RuntimeException)
231 (void)rEvent;
237 //===== lang::XEventListener ==================================================
239 void SAL_CALL PresentationFactory::disposing (
240 const lang::EventObject& rEventObject)
241 throw (RuntimeException)
243 (void)rEventObject;
250 //-----------------------------------------------------------------------------
252 void PresentationFactory::ThrowIfDisposed (void) const
253 throw (lang::DisposedException)
255 if (rBHelper.bDisposed || rBHelper.bInDispose)
257 throw lang::DisposedException (
258 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
259 "PresentationFactory object has already been disposed")),
260 const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
266 namespace {
268 //===== PresentationFactoryProvider ===========================================
270 PresentationFactoryProvider::PresentationFactoryProvider (
271 const Reference<XComponentContext>& rxContext)
272 : PresentationFactoryProviderInterfaceBase(maMutex)
274 (void)rxContext;
280 PresentationFactoryProvider::~PresentationFactoryProvider (void)
287 void PresentationFactoryProvider::disposing (void)
294 // XInitialization
296 void SAL_CALL PresentationFactoryProvider::initialize(
297 const Sequence<Any>& aArguments)
298 throw (Exception, RuntimeException)
300 if (aArguments.getLength() > 0)
304 // Get the XController from the first argument.
305 Reference<frame::XController> xController (aArguments[0], UNO_QUERY_THROW);
306 Reference<XControllerManager> xCM (xController, UNO_QUERY_THROW);
307 Reference<XConfigurationController> xCC (xCM->getConfigurationController());
308 if (xCC.is())
309 xCC->addResourceFactory(
310 PresentationFactory::msPresentationViewURL,
311 new PresentationFactory(xController));
313 catch (RuntimeException&)
315 OSL_ASSERT(false);
322 } // end of anonymous namespace.
325 } } // end of namespace sd::framework