LCOV - code coverage report
Current view: top level - sd/source/ui/framework/factories - PresentationFactory.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 34 68 50.0 %
Date: 2014-04-11 Functions: 14 24 58.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10