LCOV - code coverage report
Current view: top level - sd/source/ui/framework/factories - PresentationFactory.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 34 68 50.0 %
Date: 2014-11-03 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             : #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 (void);
      51             : 
      52             :     virtual void SAL_CALL disposing (void) 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 (void) {};
      75             : 
      76             :     // XView
      77             : 
      78           0 :     virtual Reference<XResourceId> SAL_CALL getResourceId (void) throw (RuntimeException, std::exception) SAL_OVERRIDE
      79           0 :     { return mxResourceId; };
      80             : 
      81           0 :     virtual sal_Bool SAL_CALL isAnchorOnly (void) 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             : //===== PresentationFactoryProvider service ===================================
      91             : 
      92         212 : Reference<XInterface> SAL_CALL PresentationFactoryProvider_createInstance (
      93             :     const Reference<XComponentContext>& rxContext) throw (css::uno::Exception)
      94             : {
      95         212 :     return Reference<XInterface>(static_cast<XWeak*>(new PresentationFactoryProvider(rxContext)));
      96             : }
      97             : 
      98          56 : OUString PresentationFactoryProvider_getImplementationName (void) throw(RuntimeException)
      99             : {
     100          56 :     return OUString("com.sun.star.comp.Draw.framework.PresentationFactoryProvider");
     101             : }
     102             : 
     103          22 : Sequence<OUString> SAL_CALL PresentationFactoryProvider_getSupportedServiceNames (void)
     104             :     throw (RuntimeException)
     105             : {
     106          22 :     static const OUString sServiceName("com.sun.star.drawing.framework.PresentationFactoryProvider");
     107          22 :     return Sequence<OUString>(&sServiceName, 1);
     108             : }
     109             : 
     110             : //===== PresentationFactory ===================================================
     111             : 
     112          38 : const OUString PresentationFactory::msPresentationViewURL("private:resource/view/Presentation");
     113             : 
     114         212 : PresentationFactory::PresentationFactory (
     115             :     const Reference<frame::XController>& rxController)
     116             :     : PresentationFactoryInterfaceBase(MutexOwner::maMutex),
     117             :       mxConfigurationController(),
     118         212 :       mxController(rxController)
     119             : {
     120             :     try
     121             :     {
     122             :         // Get the XController from the first argument.
     123         212 :         Reference<XControllerManager> xControllerManager(rxController, UNO_QUERY_THROW);
     124         212 :         mxConfigurationController = xControllerManager->getConfigurationController();
     125             :     }
     126           0 :     catch (RuntimeException&)
     127             :     {
     128             :         DBG_UNHANDLED_EXCEPTION();
     129             :     }
     130         212 : }
     131             : 
     132         424 : PresentationFactory::~PresentationFactory (void)
     133             : {
     134         424 : }
     135             : 
     136         212 : void SAL_CALL PresentationFactory::disposing (void)
     137             : {
     138         212 : }
     139             : 
     140             : //----- XViewFactory ----------------------------------------------------------
     141             : 
     142           0 : Reference<XResource> SAL_CALL PresentationFactory::createResource (
     143             :     const Reference<XResourceId>& rxViewId)
     144             :     throw (RuntimeException, IllegalArgumentException, WrappedTargetException, std::exception)
     145             : {
     146           0 :     ThrowIfDisposed();
     147             : 
     148           0 :     if (rxViewId.is())
     149           0 :         if ( ! rxViewId->hasAnchor() && rxViewId->getResourceURL().equals(msPresentationViewURL))
     150           0 :             return new PresentationView(rxViewId);
     151             : 
     152           0 :     return Reference<XResource>();
     153             : }
     154             : 
     155           0 : void SAL_CALL PresentationFactory::releaseResource (
     156             :     const Reference<XResource>& rxView)
     157             :     throw (RuntimeException, std::exception)
     158             : {
     159           0 :     ThrowIfDisposed();
     160             :     (void)rxView;
     161             : 
     162           0 :     Reference<lang::XUnoTunnel> xTunnel (mxController, UNO_QUERY);
     163           0 :     if (xTunnel.is())
     164             :     {
     165             :         ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
     166           0 :             xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
     167           0 :         if (pController != NULL)
     168             :         {
     169           0 :             ViewShellBase* pBase = pController->GetViewShellBase();
     170           0 :             if (pBase != NULL)
     171           0 :                 SlideShow::Stop( *pBase );
     172             :         }
     173           0 :     }
     174           0 : }
     175             : 
     176             : //===== XConfigurationChangeListener ==========================================
     177             : 
     178           0 : void SAL_CALL PresentationFactory::notifyConfigurationChange (
     179             :     const ConfigurationChangeEvent& rEvent)
     180             :     throw (RuntimeException, std::exception)
     181             : {
     182             :     (void)rEvent;
     183           0 : }
     184             : 
     185             : //===== lang::XEventListener ==================================================
     186             : 
     187           0 : void SAL_CALL PresentationFactory::disposing (
     188             :     const lang::EventObject& rEventObject)
     189             :     throw (RuntimeException, std::exception)
     190             : {
     191             :     (void)rEventObject;
     192           0 : }
     193             : 
     194           0 : void PresentationFactory::ThrowIfDisposed (void) const
     195             :     throw (lang::DisposedException)
     196             : {
     197           0 :     if (rBHelper.bDisposed || rBHelper.bInDispose)
     198             :     {
     199             :         throw lang::DisposedException ("PresentationFactory object has already been disposed",
     200           0 :             const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
     201             :     }
     202           0 : }
     203             : 
     204             : namespace {
     205             : 
     206             : //===== PresentationFactoryProvider ===========================================
     207             : 
     208         212 : PresentationFactoryProvider::PresentationFactoryProvider (
     209             :     const Reference<XComponentContext>& rxContext)
     210         212 :     : PresentationFactoryProviderInterfaceBase(maMutex)
     211             : {
     212             :     (void)rxContext;
     213         212 : }
     214             : 
     215         424 : PresentationFactoryProvider::~PresentationFactoryProvider (void)
     216             : {
     217         424 : }
     218             : 
     219         212 : void PresentationFactoryProvider::disposing (void)
     220             : {
     221         212 : }
     222             : 
     223             : // XInitialization
     224             : 
     225         212 : void SAL_CALL PresentationFactoryProvider::initialize(
     226             :     const Sequence<Any>& aArguments)
     227             :     throw (Exception, RuntimeException, std::exception)
     228             : {
     229         212 :     if (aArguments.getLength() > 0)
     230             :     {
     231             :         try
     232             :         {
     233             :             // Get the XController from the first argument.
     234         212 :             Reference<frame::XController> xController (aArguments[0], UNO_QUERY_THROW);
     235         424 :             Reference<XControllerManager> xCM (xController, UNO_QUERY_THROW);
     236         424 :             Reference<XConfigurationController> xCC (xCM->getConfigurationController());
     237         212 :             if (xCC.is())
     238         212 :                 xCC->addResourceFactory(
     239             :                     PresentationFactory::msPresentationViewURL,
     240         424 :                     new PresentationFactory(xController));
     241             :         }
     242           0 :         catch (RuntimeException&)
     243             :         {
     244             :             DBG_UNHANDLED_EXCEPTION();
     245             :         }
     246             :     }
     247         212 : }
     248             : 
     249             : } // end of anonymous namespace.
     250             : 
     251         114 : } } // end of namespace sd::framework
     252             : 
     253             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10