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