LCOV - code coverage report
Current view: top level - sd/source/ui/framework/factories - BasicToolBarFactory.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 63 72 87.5 %
Date: 2014-11-03 Functions: 15 15 100.0 %
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 "BasicToolBarFactory.hxx"
      21             : 
      22             : #include "ViewTabBar.hxx"
      23             : #include "facreg.hxx"
      24             : #include "framework/FrameworkHelper.hxx"
      25             : #include <unotools/mediadescriptor.hxx>
      26             : 
      27             : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      28             : #include "DrawController.hxx"
      29             : 
      30             : using namespace ::com::sun::star;
      31             : using namespace ::com::sun::star::uno;
      32             : using namespace ::com::sun::star::lang;
      33             : using namespace ::com::sun::star::drawing::framework;
      34             : 
      35             : namespace sd { namespace framework {
      36             : 
      37          52 : Reference<XInterface> SAL_CALL BasicToolBarFactory_createInstance (
      38             :     const Reference<XComponentContext>& rxContext) throw (css::uno::Exception)
      39             : {
      40          52 :     return static_cast<XWeak*>(new BasicToolBarFactory(rxContext));
      41             : }
      42             : 
      43          46 : OUString BasicToolBarFactory_getImplementationName (void) throw(RuntimeException)
      44             : {
      45          46 :     return OUString("com.sun.star.comp.Draw.framework.BasicToolBarFactory");
      46             : }
      47             : 
      48          12 : Sequence<OUString> SAL_CALL BasicToolBarFactory_getSupportedServiceNames (void)
      49             :     throw (RuntimeException)
      50             : {
      51          12 :     const OUString sServiceName("com.sun.star.drawing.framework.BasicToolBarFactory");
      52          12 :     return Sequence<OUString>(&sServiceName, 1);
      53             : }
      54             : 
      55             : //===== BasicToolBarFactory ===================================================
      56             : 
      57          52 : BasicToolBarFactory::BasicToolBarFactory (
      58             :     const Reference<XComponentContext>& rxContext)
      59             :     : BasicToolBarFactoryInterfaceBase(m_aMutex),
      60             :       mxConfigurationController(),
      61             :       mxController(),
      62          52 :       mpViewShellBase(NULL)
      63             : {
      64             :     (void)rxContext;
      65          52 : }
      66             : 
      67         104 : BasicToolBarFactory::~BasicToolBarFactory (void)
      68             : {
      69         104 : }
      70             : 
      71          52 : void SAL_CALL BasicToolBarFactory::disposing (void)
      72             : {
      73          52 :     Shutdown();
      74          52 : }
      75             : 
      76          52 : void BasicToolBarFactory::Shutdown (void)
      77             : {
      78          52 :     mpViewShellBase = NULL;
      79          52 :     Reference<lang::XComponent> xComponent (mxConfigurationController, UNO_QUERY);
      80          52 :     if (xComponent.is())
      81           0 :         xComponent->removeEventListener(static_cast<lang::XEventListener*>(this));
      82          52 :     if (mxConfigurationController.is())
      83             :     {
      84           0 :         mxConfigurationController->removeResourceFactoryForReference(this);
      85           0 :         mxConfigurationController = NULL;
      86          52 :     }
      87          52 : }
      88             : 
      89             : //----- XInitialization -------------------------------------------------------
      90             : 
      91          52 : void SAL_CALL BasicToolBarFactory::initialize (const Sequence<Any>& aArguments)
      92             :     throw (Exception, RuntimeException, std::exception)
      93             : {
      94          52 :     if (aArguments.getLength() > 0)
      95             :     {
      96             :         try
      97             :         {
      98             :             // Get the XController from the first argument.
      99          52 :             mxController = Reference<frame::XController>(aArguments[0], UNO_QUERY_THROW);
     100             : 
     101             :             // Tunnel through the controller to obtain a ViewShellBase.
     102          52 :             Reference<lang::XUnoTunnel> xTunnel (mxController, UNO_QUERY_THROW);
     103             :             ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
     104          52 :                 xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
     105          52 :             if (pController != NULL)
     106          52 :                 mpViewShellBase = pController->GetViewShellBase();
     107             : 
     108         104 :             utl::MediaDescriptor aDescriptor (mxController->getModel()->getArgs());
     109         104 :             if ( ! aDescriptor.getUnpackedValueOrDefault(
     110          52 :                 utl::MediaDescriptor::PROP_PREVIEW(),
     111         156 :                 sal_False))
     112             :             {
     113             :                 // Register the factory for its supported tool bars.
     114          52 :                 Reference<XControllerManager> xControllerManager(mxController, UNO_QUERY_THROW);
     115          52 :                 mxConfigurationController = xControllerManager->getConfigurationController();
     116          52 :                 if (mxConfigurationController.is())
     117             :                 {
     118          52 :                     mxConfigurationController->addResourceFactory(
     119          52 :                         FrameworkHelper::msViewTabBarURL, this);
     120             :                 }
     121             : 
     122         104 :                 Reference<lang::XComponent> xComponent (mxConfigurationController, UNO_QUERY);
     123          52 :                 if (xComponent.is())
     124         104 :                     xComponent->addEventListener(static_cast<lang::XEventListener*>(this));
     125             :             }
     126             :             else
     127             :             {
     128             :                 // The view shell is in preview mode and thus does not need
     129             :                 // the view tab bar.
     130           0 :                 mxConfigurationController = NULL;
     131          52 :             }
     132             :         }
     133           0 :         catch (RuntimeException&)
     134             :         {
     135           0 :             Shutdown();
     136           0 :             throw;
     137             :         }
     138             :     }
     139          52 : }
     140             : 
     141             : //----- lang::XEventListener --------------------------------------------------
     142             : 
     143          52 : void SAL_CALL BasicToolBarFactory::disposing (
     144             :     const lang::EventObject& rEventObject)
     145             :     throw (RuntimeException, std::exception)
     146             : {
     147          52 :     if (rEventObject.Source == mxConfigurationController)
     148          52 :         mxConfigurationController = NULL;
     149          52 : }
     150             : 
     151             : //===== XPaneFactory ==========================================================
     152             : 
     153          52 : Reference<XResource> SAL_CALL BasicToolBarFactory::createResource (
     154             :     const Reference<XResourceId>& rxToolBarId)
     155             :     throw (RuntimeException, IllegalArgumentException, WrappedTargetException, std::exception)
     156             : {
     157          52 :     ThrowIfDisposed();
     158             : 
     159          52 :     Reference<XResource> xToolBar;
     160             : 
     161          52 :     if (rxToolBarId->getResourceURL().equals(FrameworkHelper::msViewTabBarURL))
     162             :     {
     163          52 :         xToolBar = new ViewTabBar(rxToolBarId, mxController);
     164             :     }
     165             :     else
     166           0 :         throw lang::IllegalArgumentException();
     167             : 
     168          52 :     return xToolBar;
     169             : }
     170             : 
     171          52 : void SAL_CALL BasicToolBarFactory::releaseResource (
     172             :     const Reference<XResource>& rxToolBar)
     173             :     throw (RuntimeException, std::exception)
     174             : {
     175          52 :     ThrowIfDisposed();
     176             : 
     177          52 :     Reference<XComponent> xComponent (rxToolBar, UNO_QUERY);
     178          52 :     if (xComponent.is())
     179          52 :         xComponent->dispose();
     180          52 : }
     181             : 
     182         104 : void BasicToolBarFactory::ThrowIfDisposed (void) const
     183             :     throw (lang::DisposedException)
     184             : {
     185         104 :     if (rBHelper.bDisposed || rBHelper.bInDispose)
     186             :     {
     187             :         throw lang::DisposedException ("BasicToolBarFactory object has already been disposed",
     188           0 :             const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
     189             :     }
     190         104 : }
     191             : 
     192         114 : } } // end of namespace sd::framework
     193             : 
     194             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10