1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_sd.hxx"
25 
26 #include "framework/PresentationFactory.hxx"
27 
28 #include "framework/FrameworkHelper.hxx"
29 #include "DrawController.hxx"
30 #include "ViewShellBase.hxx"
31 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
32 #include <cppuhelper/compbase1.hxx>
33 #include <tools/diagnose_ex.h>
34 #include "slideshow.hxx"
35 
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::lang;
39 using namespace ::com::sun::star::drawing::framework;
40 
41 using ::rtl::OUString;
42 using ::sd::framework::FrameworkHelper;
43 
44 
45 namespace sd { namespace framework {
46 
47 namespace {
48 
49 typedef ::cppu::WeakComponentImplHelper1 <lang::XInitialization> PresentationFactoryProviderInterfaceBase;
50 
51 class PresentationFactoryProvider
52     : protected MutexOwner,
53       public PresentationFactoryProviderInterfaceBase
54 {
55 public:
56     PresentationFactoryProvider (const Reference<XComponentContext>& rxContext);
57     virtual ~PresentationFactoryProvider (void);
58 
59     virtual void SAL_CALL disposing (void);
60 
61     // XInitialization
62 
63     virtual void SAL_CALL initialize(
64         const ::com::sun::star::uno::Sequence<com::sun::star::uno::Any>& aArguments)
65         throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
66 };
67 
68 
69 
70 
71 typedef ::cppu::WeakComponentImplHelper1 <XView> PresentationViewInterfaceBase;
72 
73 /** The PresentationView is not an actual view, it is a marker whose
74     existence in a configuration indicates that a slideshow is running
75     (in another application window).
76 */
77 class PresentationView
78     : protected MutexOwner,
79       public PresentationViewInterfaceBase
80 {
81 public:
PresentationView(const Reference<XResourceId> & rxViewId)82     PresentationView (const Reference<XResourceId>& rxViewId)
83         : PresentationViewInterfaceBase(maMutex),mxResourceId(rxViewId) {};
~PresentationView(void)84     virtual ~PresentationView (void) {};
85 
86     // XView
87 
getResourceId(void)88     virtual Reference<XResourceId> SAL_CALL getResourceId (void) throw (RuntimeException)
89     { return mxResourceId; };
90 
isAnchorOnly(void)91     virtual sal_Bool SAL_CALL isAnchorOnly (void) throw (RuntimeException)
92     { return false; }
93 
94 
95 private:
96     Reference<XResourceId> mxResourceId;
97 };
98 
99 } // end of anonymous namespace.
100 
101 
102 
103 
104 //===== PresentationFactoryProvider service ===================================
105 
PresentationFactoryProvider_createInstance(const Reference<XComponentContext> & rxContext)106 Reference<XInterface> SAL_CALL PresentationFactoryProvider_createInstance (
107     const Reference<XComponentContext>& rxContext)
108 {
109     return Reference<XInterface>(static_cast<XWeak*>(new PresentationFactoryProvider(rxContext)));
110 }
111 
112 
113 
114 
PresentationFactoryProvider_getImplementationName(void)115 ::rtl::OUString PresentationFactoryProvider_getImplementationName (void) throw(RuntimeException)
116 {
117     return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
118         "com.sun.star.comp.Draw.framework.PresentationFactoryProvider"));
119 }
120 
121 
122 
123 
PresentationFactoryProvider_getSupportedServiceNames(void)124 Sequence<rtl::OUString> SAL_CALL PresentationFactoryProvider_getSupportedServiceNames (void)
125     throw (RuntimeException)
126 {
127 	static const ::rtl::OUString sServiceName(RTL_CONSTASCII_USTRINGPARAM(
128         "com.sun.star.drawing.framework.PresentationFactoryProvider"));
129 	return Sequence<rtl::OUString>(&sServiceName, 1);
130 }
131 
132 
133 
134 
135 //===== PresentationFactory ===================================================
136 
137 const ::rtl::OUString PresentationFactory::msPresentationViewURL(
138     OUString::createFromAscii("private:resource/view/Presentation"));
139 
140 
PresentationFactory(const Reference<frame::XController> & rxController)141 PresentationFactory::PresentationFactory (
142     const Reference<frame::XController>& rxController)
143     : PresentationFactoryInterfaceBase(MutexOwner::maMutex),
144       mxConfigurationController(),
145       mxController(rxController)
146 {
147     try
148     {
149         // Get the XController from the first argument.
150         Reference<XControllerManager> xControllerManager(rxController, UNO_QUERY_THROW);
151         mxConfigurationController = xControllerManager->getConfigurationController();
152     }
153     catch (RuntimeException&)
154     {
155         DBG_UNHANDLED_EXCEPTION();
156     }
157 }
158 
159 
160 
161 
162 
~PresentationFactory(void)163 PresentationFactory::~PresentationFactory (void)
164 {
165 }
166 
167 
168 
169 
disposing(void)170 void SAL_CALL PresentationFactory::disposing (void)
171 {
172 }
173 
174 
175 
176 
177 //----- XViewFactory ----------------------------------------------------------
178 
createResource(const Reference<XResourceId> & rxViewId)179 Reference<XResource> SAL_CALL PresentationFactory::createResource (
180     const Reference<XResourceId>& rxViewId)
181     throw (RuntimeException, IllegalArgumentException, WrappedTargetException)
182 {
183     ThrowIfDisposed();
184 
185     if (rxViewId.is())
186         if ( ! rxViewId->hasAnchor() && rxViewId->getResourceURL().equals(msPresentationViewURL))
187             return new PresentationView(rxViewId);
188 
189     return Reference<XResource>();
190 }
191 
192 
193 
194 
releaseResource(const Reference<XResource> & rxView)195 void SAL_CALL PresentationFactory::releaseResource (
196     const Reference<XResource>& rxView)
197     throw (RuntimeException)
198 {
199     ThrowIfDisposed();
200     (void)rxView;
201 
202     Reference<lang::XUnoTunnel> xTunnel (mxController, UNO_QUERY);
203     if (xTunnel.is())
204     {
205         ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
206             xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
207         if (pController != NULL)
208         {
209             ViewShellBase* pBase = pController->GetViewShellBase();
210             if (pBase != NULL)
211 				SlideShow::Stop( *pBase );
212         }
213     }
214 }
215 
216 
217 
218 
219 //===== XConfigurationChangeListener ==========================================
220 
notifyConfigurationChange(const ConfigurationChangeEvent & rEvent)221 void SAL_CALL PresentationFactory::notifyConfigurationChange (
222     const ConfigurationChangeEvent& rEvent)
223     throw (RuntimeException)
224 {
225     (void)rEvent;
226 }
227 
228 
229 
230 
231 //===== lang::XEventListener ==================================================
232 
disposing(const lang::EventObject & rEventObject)233 void SAL_CALL PresentationFactory::disposing (
234     const lang::EventObject& rEventObject)
235     throw (RuntimeException)
236 {
237     (void)rEventObject;
238 }
239 
240 
241 
242 
243 
244 //-----------------------------------------------------------------------------
245 
ThrowIfDisposed(void) const246 void PresentationFactory::ThrowIfDisposed (void) const
247     throw (lang::DisposedException)
248 {
249 	if (rBHelper.bDisposed || rBHelper.bInDispose)
250 	{
251         throw lang::DisposedException (
252             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
253                 "PresentationFactory object has already been disposed")),
254             const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
255     }
256 }
257 
258 
259 
260 namespace {
261 
262 //===== PresentationFactoryProvider ===========================================
263 
PresentationFactoryProvider(const Reference<XComponentContext> & rxContext)264 PresentationFactoryProvider::PresentationFactoryProvider (
265     const Reference<XComponentContext>& rxContext)
266     : PresentationFactoryProviderInterfaceBase(maMutex)
267 {
268     (void)rxContext;
269 }
270 
271 
272 
273 
~PresentationFactoryProvider(void)274 PresentationFactoryProvider::~PresentationFactoryProvider (void)
275 {
276 }
277 
278 
279 
280 
disposing(void)281 void PresentationFactoryProvider::disposing (void)
282 {
283 }
284 
285 
286 
287 
288 // XInitialization
289 
initialize(const Sequence<Any> & aArguments)290 void SAL_CALL PresentationFactoryProvider::initialize(
291     const Sequence<Any>& aArguments)
292     throw (Exception, RuntimeException)
293 {
294     if (aArguments.getLength() > 0)
295     {
296         try
297         {
298             // Get the XController from the first argument.
299             Reference<frame::XController> xController (aArguments[0], UNO_QUERY_THROW);
300             Reference<XControllerManager> xCM (xController, UNO_QUERY_THROW);
301             Reference<XConfigurationController> xCC (xCM->getConfigurationController());
302             if (xCC.is())
303                 xCC->addResourceFactory(
304                     PresentationFactory::msPresentationViewURL,
305                     new PresentationFactory(xController));
306         }
307         catch (RuntimeException&)
308         {
309             DBG_UNHANDLED_EXCEPTION();
310         }
311     }
312 }
313 
314 
315 
316 } // end of anonymous namespace.
317 
318 
319 } } // end of namespace sd::framework
320