Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "framework/PresentationFactory.hxx"
21 :
22 : #include "framework/FrameworkHelper.hxx"
23 : #include "DrawController.hxx"
24 : #include "ViewShellBase.hxx"
25 : #include "facreg.hxx"
26 : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
27 : #include <cppuhelper/compbase1.hxx>
28 : #include <tools/diagnose_ex.h>
29 : #include "slideshow.hxx"
30 :
31 : using namespace ::com::sun::star;
32 : using namespace ::com::sun::star::uno;
33 : using namespace ::com::sun::star::lang;
34 : using namespace ::com::sun::star::drawing::framework;
35 :
36 : using ::sd::framework::FrameworkHelper;
37 :
38 : namespace sd { namespace framework {
39 :
40 : namespace {
41 :
42 : typedef ::cppu::WeakComponentImplHelper1 <lang::XInitialization> PresentationFactoryProviderInterfaceBase;
43 :
44 : class PresentationFactoryProvider
45 : : protected MutexOwner,
46 : public PresentationFactoryProviderInterfaceBase
47 : {
48 : public:
49 : PresentationFactoryProvider (const Reference<XComponentContext>& rxContext);
50 : virtual ~PresentationFactoryProvider();
51 :
52 : virtual void SAL_CALL disposing() SAL_OVERRIDE;
53 :
54 : // XInitialization
55 :
56 : virtual void SAL_CALL initialize(
57 : const ::com::sun::star::uno::Sequence<com::sun::star::uno::Any>& aArguments)
58 : throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
59 : };
60 :
61 : typedef ::cppu::WeakComponentImplHelper1 <XView> PresentationViewInterfaceBase;
62 :
63 : /** The PresentationView is not an actual view, it is a marker whose
64 : existence in a configuration indicates that a slideshow is running
65 : (in another application window).
66 : */
67 : class PresentationView
68 : : protected MutexOwner,
69 : public PresentationViewInterfaceBase
70 : {
71 : public:
72 0 : PresentationView (const Reference<XResourceId>& rxViewId)
73 0 : : PresentationViewInterfaceBase(maMutex),mxResourceId(rxViewId) {};
74 0 : virtual ~PresentationView() {};
75 :
76 : // XView
77 :
78 0 : virtual Reference<XResourceId> SAL_CALL getResourceId() throw (RuntimeException, std::exception) SAL_OVERRIDE
79 0 : { return mxResourceId; };
80 :
81 0 : virtual sal_Bool SAL_CALL isAnchorOnly() throw (RuntimeException, std::exception) SAL_OVERRIDE
82 0 : { return false; }
83 :
84 : private:
85 : Reference<XResourceId> mxResourceId;
86 : };
87 :
88 : } // end of anonymous namespace.
89 :
90 : //===== PresentationFactory ===================================================
91 :
92 22 : const OUString PresentationFactory::msPresentationViewURL("private:resource/view/Presentation");
93 :
94 127 : PresentationFactory::PresentationFactory (
95 : const Reference<frame::XController>& rxController)
96 : : PresentationFactoryInterfaceBase(MutexOwner::maMutex),
97 : mxConfigurationController(),
98 127 : mxController(rxController)
99 : {
100 : try
101 : {
102 : // Get the XController from the first argument.
103 127 : Reference<XControllerManager> xControllerManager(rxController, UNO_QUERY_THROW);
104 127 : mxConfigurationController = xControllerManager->getConfigurationController();
105 : }
106 0 : catch (RuntimeException&)
107 : {
108 : DBG_UNHANDLED_EXCEPTION();
109 : }
110 127 : }
111 :
112 254 : PresentationFactory::~PresentationFactory()
113 : {
114 254 : }
115 :
116 127 : void SAL_CALL PresentationFactory::disposing()
117 : {
118 127 : }
119 :
120 : //----- XViewFactory ----------------------------------------------------------
121 :
122 0 : Reference<XResource> SAL_CALL PresentationFactory::createResource (
123 : const Reference<XResourceId>& rxViewId)
124 : throw (RuntimeException, IllegalArgumentException, WrappedTargetException, std::exception)
125 : {
126 0 : ThrowIfDisposed();
127 :
128 0 : if (rxViewId.is())
129 0 : if ( ! rxViewId->hasAnchor() && rxViewId->getResourceURL().equals(msPresentationViewURL))
130 0 : return new PresentationView(rxViewId);
131 :
132 0 : return Reference<XResource>();
133 : }
134 :
135 0 : void SAL_CALL PresentationFactory::releaseResource (
136 : const Reference<XResource>& rxView)
137 : throw (RuntimeException, std::exception)
138 : {
139 0 : ThrowIfDisposed();
140 : (void)rxView;
141 :
142 0 : Reference<lang::XUnoTunnel> xTunnel (mxController, UNO_QUERY);
143 0 : if (xTunnel.is())
144 : {
145 : ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
146 0 : xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
147 0 : if (pController != NULL)
148 : {
149 0 : ViewShellBase* pBase = pController->GetViewShellBase();
150 0 : if (pBase != NULL)
151 0 : SlideShow::Stop( *pBase );
152 : }
153 0 : }
154 0 : }
155 :
156 : //===== XConfigurationChangeListener ==========================================
157 :
158 0 : void SAL_CALL PresentationFactory::notifyConfigurationChange (
159 : const ConfigurationChangeEvent& rEvent)
160 : throw (RuntimeException, std::exception)
161 : {
162 : (void)rEvent;
163 0 : }
164 :
165 : //===== lang::XEventListener ==================================================
166 :
167 0 : void SAL_CALL PresentationFactory::disposing (
168 : const lang::EventObject& rEventObject)
169 : throw (RuntimeException, std::exception)
170 : {
171 : (void)rEventObject;
172 0 : }
173 :
174 0 : void PresentationFactory::ThrowIfDisposed() const
175 : throw (lang::DisposedException)
176 : {
177 0 : if (rBHelper.bDisposed || rBHelper.bInDispose)
178 : {
179 : throw lang::DisposedException ("PresentationFactory object has already been disposed",
180 0 : const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
181 : }
182 0 : }
183 :
184 : namespace {
185 :
186 : //===== PresentationFactoryProvider ===========================================
187 :
188 127 : PresentationFactoryProvider::PresentationFactoryProvider (
189 : const Reference<XComponentContext>& rxContext)
190 127 : : PresentationFactoryProviderInterfaceBase(maMutex)
191 : {
192 : (void)rxContext;
193 127 : }
194 :
195 254 : PresentationFactoryProvider::~PresentationFactoryProvider()
196 : {
197 254 : }
198 :
199 127 : void PresentationFactoryProvider::disposing()
200 : {
201 127 : }
202 :
203 : // XInitialization
204 :
205 127 : void SAL_CALL PresentationFactoryProvider::initialize(
206 : const Sequence<Any>& aArguments)
207 : throw (Exception, RuntimeException, std::exception)
208 : {
209 127 : if (aArguments.getLength() > 0)
210 : {
211 : try
212 : {
213 : // Get the XController from the first argument.
214 127 : Reference<frame::XController> xController (aArguments[0], UNO_QUERY_THROW);
215 254 : Reference<XControllerManager> xCM (xController, UNO_QUERY_THROW);
216 254 : Reference<XConfigurationController> xCC (xCM->getConfigurationController());
217 127 : if (xCC.is())
218 127 : xCC->addResourceFactory(
219 : PresentationFactory::msPresentationViewURL,
220 254 : new PresentationFactory(xController));
221 : }
222 0 : catch (RuntimeException&)
223 : {
224 : DBG_UNHANDLED_EXCEPTION();
225 : }
226 : }
227 127 : }
228 :
229 : } // end of anonymous namespace.
230 :
231 : } } // end of namespace sd::framework
232 :
233 :
234 : extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
235 127 : com_sun_star_comp_Draw_framework_PresentationFactoryProvider_get_implementation(::com::sun::star::uno::XComponentContext* context,
236 : ::com::sun::star::uno::Sequence<css::uno::Any> const &)
237 : {
238 127 : return cppu::acquire(new sd::framework::PresentationFactoryProvider(context));
239 66 : }
240 :
241 :
242 :
243 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|