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

Generated by: LCOV version 1.11