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 };
66
67
68
69
70 typedef ::cppu::WeakComponentImplHelper1 <XView> PresentationViewInterfaceBase;
71
72 /** The PresentationView is not an actual view, it is a marker whose
73 existence in a configuration indicates that a slideshow is running
74 (in another application window).
75 */
76 class PresentationView
77 : protected MutexOwner,
78 public PresentationViewInterfaceBase
79 {
80 public:
PresentationView(const Reference<XResourceId> & rxViewId)81 PresentationView (const Reference<XResourceId>& rxViewId)
82 : PresentationViewInterfaceBase(maMutex),mxResourceId(rxViewId) {};
~PresentationView(void)83 virtual ~PresentationView (void) {};
84
85 // XView
86
getResourceId(void)87 virtual Reference<XResourceId> SAL_CALL getResourceId (void)
88 { return mxResourceId; };
89
isAnchorOnly(void)90 virtual sal_Bool SAL_CALL isAnchorOnly (void)
91 { return false; }
92
93
94 private:
95 Reference<XResourceId> mxResourceId;
96 };
97
98 } // end of anonymous namespace.
99
100
101
102
103 //===== PresentationFactoryProvider service ===================================
104
PresentationFactoryProvider_createInstance(const Reference<XComponentContext> & rxContext)105 Reference<XInterface> SAL_CALL PresentationFactoryProvider_createInstance (
106 const Reference<XComponentContext>& rxContext)
107 {
108 return Reference<XInterface>(static_cast<XWeak*>(new PresentationFactoryProvider(rxContext)));
109 }
110
111
112
113
PresentationFactoryProvider_getImplementationName(void)114 ::rtl::OUString PresentationFactoryProvider_getImplementationName (void)
115 {
116 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
117 "com.sun.star.comp.Draw.framework.PresentationFactoryProvider"));
118 }
119
120
121
122
PresentationFactoryProvider_getSupportedServiceNames(void)123 Sequence<rtl::OUString> SAL_CALL PresentationFactoryProvider_getSupportedServiceNames (void)
124 {
125 static const ::rtl::OUString sServiceName(RTL_CONSTASCII_USTRINGPARAM(
126 "com.sun.star.drawing.framework.PresentationFactoryProvider"));
127 return Sequence<rtl::OUString>(&sServiceName, 1);
128 }
129
130
131
132
133 //===== PresentationFactory ===================================================
134
135 const ::rtl::OUString PresentationFactory::msPresentationViewURL(
136 OUString::createFromAscii("private:resource/view/Presentation"));
137
138
PresentationFactory(const Reference<frame::XController> & rxController)139 PresentationFactory::PresentationFactory (
140 const Reference<frame::XController>& rxController)
141 : PresentationFactoryInterfaceBase(MutexOwner::maMutex),
142 mxConfigurationController(),
143 mxController(rxController)
144 {
145 try
146 {
147 // Get the XController from the first argument.
148 Reference<XControllerManager> xControllerManager(rxController, UNO_QUERY_THROW);
149 mxConfigurationController = xControllerManager->getConfigurationController();
150 }
151 catch (RuntimeException&)
152 {
153 DBG_UNHANDLED_EXCEPTION();
154 }
155 }
156
157
158
159
160
~PresentationFactory(void)161 PresentationFactory::~PresentationFactory (void)
162 {
163 }
164
165
166
167
disposing(void)168 void SAL_CALL PresentationFactory::disposing (void)
169 {
170 }
171
172
173
174
175 //----- XViewFactory ----------------------------------------------------------
176
createResource(const Reference<XResourceId> & rxViewId)177 Reference<XResource> SAL_CALL PresentationFactory::createResource (
178 const Reference<XResourceId>& rxViewId)
179 {
180 ThrowIfDisposed();
181
182 if (rxViewId.is())
183 if ( ! rxViewId->hasAnchor() && rxViewId->getResourceURL().equals(msPresentationViewURL))
184 return new PresentationView(rxViewId);
185
186 return Reference<XResource>();
187 }
188
189
190
191
releaseResource(const Reference<XResource> & rxView)192 void SAL_CALL PresentationFactory::releaseResource (
193 const Reference<XResource>& rxView)
194 {
195 ThrowIfDisposed();
196 (void)rxView;
197
198 Reference<lang::XUnoTunnel> xTunnel (mxController, UNO_QUERY);
199 if (xTunnel.is())
200 {
201 ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
202 xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
203 if (pController != NULL)
204 {
205 ViewShellBase* pBase = pController->GetViewShellBase();
206 if (pBase != NULL)
207 SlideShow::Stop( *pBase );
208 }
209 }
210 }
211
212
213
214
215 //===== XConfigurationChangeListener ==========================================
216
notifyConfigurationChange(const ConfigurationChangeEvent & rEvent)217 void SAL_CALL PresentationFactory::notifyConfigurationChange (
218 const ConfigurationChangeEvent& rEvent)
219 {
220 (void)rEvent;
221 }
222
223
224
225
226 //===== lang::XEventListener ==================================================
227
disposing(const lang::EventObject & rEventObject)228 void SAL_CALL PresentationFactory::disposing (
229 const lang::EventObject& rEventObject)
230 {
231 (void)rEventObject;
232 }
233
234
235
236
237
238 //-----------------------------------------------------------------------------
239
ThrowIfDisposed(void) const240 void PresentationFactory::ThrowIfDisposed (void) const
241 {
242 if (rBHelper.bDisposed || rBHelper.bInDispose)
243 {
244 throw lang::DisposedException (
245 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
246 "PresentationFactory object has already been disposed")),
247 const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
248 }
249 }
250
251
252
253 namespace {
254
255 //===== PresentationFactoryProvider ===========================================
256
PresentationFactoryProvider(const Reference<XComponentContext> & rxContext)257 PresentationFactoryProvider::PresentationFactoryProvider (
258 const Reference<XComponentContext>& rxContext)
259 : PresentationFactoryProviderInterfaceBase(maMutex)
260 {
261 (void)rxContext;
262 }
263
264
265
266
~PresentationFactoryProvider(void)267 PresentationFactoryProvider::~PresentationFactoryProvider (void)
268 {
269 }
270
271
272
273
disposing(void)274 void PresentationFactoryProvider::disposing (void)
275 {
276 }
277
278
279
280
281 // XInitialization
282
initialize(const Sequence<Any> & aArguments)283 void SAL_CALL PresentationFactoryProvider::initialize(
284 const Sequence<Any>& aArguments)
285 {
286 if (aArguments.getLength() > 0)
287 {
288 try
289 {
290 // Get the XController from the first argument.
291 Reference<frame::XController> xController (aArguments[0], UNO_QUERY_THROW);
292 Reference<XControllerManager> xCM (xController, UNO_QUERY_THROW);
293 Reference<XConfigurationController> xCC (xCM->getConfigurationController());
294 if (xCC.is())
295 xCC->addResourceFactory(
296 PresentationFactory::msPresentationViewURL,
297 new PresentationFactory(xController));
298 }
299 catch (RuntimeException&)
300 {
301 DBG_UNHANDLED_EXCEPTION();
302 }
303 }
304 }
305
306
307
308 } // end of anonymous namespace.
309
310
311 } } // end of namespace sd::framework
312