LCOV - code coverage report
Current view: top level - sd/source/ui/framework/factories - BasicToolBarFactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 62 71 87.3 %
Date: 2012-08-25 Functions: 13 13 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 53 132 40.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "BasicToolBarFactory.hxx"
      31                 :            : 
      32                 :            : #include "ViewTabBar.hxx"
      33                 :            : #include "framework/FrameworkHelper.hxx"
      34                 :            : #include <comphelper/mediadescriptor.hxx>
      35                 :            : 
      36                 :            : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      37                 :            : #include "DrawController.hxx"
      38                 :            : 
      39                 :            : using namespace ::com::sun::star;
      40                 :            : using namespace ::com::sun::star::uno;
      41                 :            : using namespace ::com::sun::star::lang;
      42                 :            : using namespace ::com::sun::star::drawing::framework;
      43                 :            : 
      44                 :            : namespace sd { namespace framework {
      45                 :            : 
      46                 :            : 
      47                 :         26 : Reference<XInterface> SAL_CALL BasicToolBarFactory_createInstance (
      48                 :            :     const Reference<XComponentContext>& rxContext)
      49                 :            : {
      50         [ +  - ]:         26 :     return static_cast<XWeak*>(new BasicToolBarFactory(rxContext));
      51                 :            : }
      52                 :            : 
      53                 :            : 
      54                 :            : 
      55                 :            : 
      56                 :         30 : ::rtl::OUString BasicToolBarFactory_getImplementationName (void) throw(RuntimeException)
      57                 :            : {
      58                 :         30 :     return ::rtl::OUString("com.sun.star.comp.Draw.framework.BasicToolBarFactory");
      59                 :            : }
      60                 :            : 
      61                 :            : 
      62                 :            : 
      63                 :            : 
      64                 :          8 : Sequence<rtl::OUString> SAL_CALL BasicToolBarFactory_getSupportedServiceNames (void)
      65                 :            :     throw (RuntimeException)
      66                 :            : {
      67                 :          8 :     const ::rtl::OUString sServiceName("com.sun.star.drawing.framework.BasicToolBarFactory");
      68         [ +  - ]:          8 :     return Sequence<rtl::OUString>(&sServiceName, 1);
      69                 :            : }
      70                 :            : 
      71                 :            : 
      72                 :            : 
      73                 :            : 
      74                 :            : 
      75                 :            : //===== BasicToolBarFactory ===================================================
      76                 :            : 
      77                 :         26 : BasicToolBarFactory::BasicToolBarFactory (
      78                 :            :     const Reference<XComponentContext>& rxContext)
      79                 :            :     : BasicToolBarFactoryInterfaceBase(m_aMutex),
      80                 :            :       mxConfigurationController(),
      81                 :            :       mxController(),
      82                 :         26 :       mpViewShellBase(NULL)
      83                 :            : {
      84                 :            :     (void)rxContext;
      85                 :         26 : }
      86                 :            : 
      87                 :            : 
      88                 :            : 
      89                 :            : 
      90         [ +  - ]:         26 : BasicToolBarFactory::~BasicToolBarFactory (void)
      91                 :            : {
      92         [ -  + ]:         52 : }
      93                 :            : 
      94                 :            : 
      95                 :            : 
      96                 :            : 
      97                 :         26 : void SAL_CALL BasicToolBarFactory::disposing (void)
      98                 :            : {
      99                 :         26 :     Shutdown();
     100                 :         26 : }
     101                 :            : 
     102                 :            : 
     103                 :            : 
     104                 :            : 
     105                 :         26 : void BasicToolBarFactory::Shutdown (void)
     106                 :            : {
     107                 :         26 :     mpViewShellBase = NULL;
     108         [ +  - ]:         26 :     Reference<lang::XComponent> xComponent (mxConfigurationController, UNO_QUERY);
     109         [ -  + ]:         26 :     if (xComponent.is())
     110 [ #  # ][ #  # ]:          0 :         xComponent->removeEventListener(static_cast<lang::XEventListener*>(this));
                 [ #  # ]
     111         [ -  + ]:         26 :     if (mxConfigurationController.is())
     112                 :            :     {
     113 [ #  # ][ #  # ]:          0 :         mxConfigurationController->removeResourceFactoryForReference(this);
                 [ #  # ]
     114         [ #  # ]:          0 :         mxConfigurationController = NULL;
     115                 :         26 :     }
     116                 :         26 : }
     117                 :            : 
     118                 :            : 
     119                 :            : 
     120                 :            : 
     121                 :            : //----- XInitialization -------------------------------------------------------
     122                 :            : 
     123                 :         26 : void SAL_CALL BasicToolBarFactory::initialize (const Sequence<Any>& aArguments)
     124                 :            :     throw (Exception, RuntimeException)
     125                 :            : {
     126         [ +  - ]:         26 :     if (aArguments.getLength() > 0)
     127                 :            :     {
     128                 :            :         try
     129                 :            :         {
     130                 :            :             // Get the XController from the first argument.
     131 [ +  - ][ +  - ]:         26 :             mxController = Reference<frame::XController>(aArguments[0], UNO_QUERY_THROW);
     132                 :            : 
     133                 :            :             // Tunnel through the controller to obtain a ViewShellBase.
     134         [ +  - ]:         26 :             Reference<lang::XUnoTunnel> xTunnel (mxController, UNO_QUERY_THROW);
     135                 :            :             ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
     136 [ +  - ][ +  - ]:         26 :                 xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
                 [ +  - ]
     137         [ +  - ]:         26 :             if (pController != NULL)
     138         [ +  - ]:         26 :                 mpViewShellBase = pController->GetViewShellBase();
     139                 :            : 
     140 [ +  - ][ +  - ]:         26 :             ::comphelper::MediaDescriptor aDescriptor (mxController->getModel()->getArgs());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     141         [ +  - ]:         26 :             if ( ! aDescriptor.getUnpackedValueOrDefault(
     142         [ +  - ]:         26 :                 ::comphelper::MediaDescriptor::PROP_PREVIEW(),
     143         [ +  - ]:         26 :                 sal_False))
     144                 :            :             {
     145                 :            :                 // Register the factory for its supported tool bars.
     146         [ +  - ]:         26 :                 Reference<XControllerManager> xControllerManager(mxController, UNO_QUERY_THROW);
     147 [ +  - ][ +  - ]:         26 :                 mxConfigurationController = xControllerManager->getConfigurationController();
                 [ +  - ]
     148         [ +  - ]:         26 :                 if (mxConfigurationController.is())
     149                 :            :                 {
     150         [ +  - ]:         26 :                     mxConfigurationController->addResourceFactory(
     151 [ +  - ][ +  - ]:         26 :                         FrameworkHelper::msViewTabBarURL, this);
     152                 :            :                 }
     153                 :            : 
     154         [ +  - ]:         26 :                 Reference<lang::XComponent> xComponent (mxConfigurationController, UNO_QUERY);
     155         [ +  - ]:         26 :                 if (xComponent.is())
     156 [ +  - ][ +  - ]:         26 :                     xComponent->addEventListener(static_cast<lang::XEventListener*>(this));
                 [ +  - ]
     157                 :            :             }
     158                 :            :             else
     159                 :            :             {
     160                 :            :                 // The view shell is in preview mode and thus does not need
     161                 :            :                 // the view tab bar.
     162         [ #  # ]:          0 :                 mxConfigurationController = NULL;
     163         [ +  - ]:         26 :             }
     164                 :            :         }
     165         [ #  # ]:          0 :         catch (RuntimeException&)
     166                 :            :         {
     167         [ #  # ]:          0 :             Shutdown();
     168                 :          0 :             throw;
     169                 :            :         }
     170                 :            :     }
     171                 :         26 : }
     172                 :            : 
     173                 :            : 
     174                 :            : 
     175                 :            : 
     176                 :            : //----- lang::XEventListener --------------------------------------------------
     177                 :            : 
     178                 :         26 : void SAL_CALL BasicToolBarFactory::disposing (
     179                 :            :     const lang::EventObject& rEventObject)
     180                 :            :     throw (RuntimeException)
     181                 :            : {
     182         [ +  - ]:         26 :     if (rEventObject.Source == mxConfigurationController)
     183                 :         26 :         mxConfigurationController = NULL;
     184                 :         26 : }
     185                 :            : 
     186                 :            : 
     187                 :            : 
     188                 :            : 
     189                 :            : //===== XPaneFactory ==========================================================
     190                 :            : 
     191                 :         26 : Reference<XResource> SAL_CALL BasicToolBarFactory::createResource (
     192                 :            :     const Reference<XResourceId>& rxToolBarId)
     193                 :            :     throw (RuntimeException, IllegalArgumentException, WrappedTargetException)
     194                 :            : {
     195                 :         26 :     ThrowIfDisposed();
     196                 :            : 
     197                 :         26 :     Reference<XResource> xToolBar;
     198                 :            : 
     199 [ +  - ][ +  - ]:         26 :     if (rxToolBarId->getResourceURL().equals(FrameworkHelper::msViewTabBarURL))
                 [ +  - ]
     200                 :            :     {
     201 [ +  - ][ +  - ]:         26 :         xToolBar = new ViewTabBar(rxToolBarId, mxController);
                 [ +  - ]
     202                 :            :     }
     203                 :            :     else
     204         [ #  # ]:          0 :         throw lang::IllegalArgumentException();
     205                 :            : 
     206                 :            : 
     207                 :         26 :     return xToolBar;
     208                 :            : }
     209                 :            : 
     210                 :            : 
     211                 :            : 
     212                 :            : 
     213                 :            : 
     214                 :         26 : void SAL_CALL BasicToolBarFactory::releaseResource (
     215                 :            :     const Reference<XResource>& rxToolBar)
     216                 :            :     throw (RuntimeException)
     217                 :            : {
     218         [ +  - ]:         26 :     ThrowIfDisposed();
     219                 :            : 
     220         [ +  - ]:         26 :     Reference<XComponent> xComponent (rxToolBar, UNO_QUERY);
     221         [ +  - ]:         26 :     if (xComponent.is())
     222 [ +  - ][ +  - ]:         26 :         xComponent->dispose();
     223                 :         26 : }
     224                 :            : 
     225                 :            : 
     226                 :            : 
     227                 :            : 
     228                 :         52 : void BasicToolBarFactory::ThrowIfDisposed (void) const
     229                 :            :     throw (lang::DisposedException)
     230                 :            : {
     231 [ +  - ][ -  + ]:         52 :     if (rBHelper.bDisposed || rBHelper.bInDispose)
     232                 :            :     {
     233                 :            :         throw lang::DisposedException ("BasicToolBarFactory object has already been disposed",
     234 [ #  # ][ #  # ]:          0 :             const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
     235                 :            :     }
     236                 :         52 : }
     237                 :            : 
     238                 :            : 
     239                 :            : 
     240                 :            : 
     241                 :            : } } // end of namespace sd::framework
     242                 :            : 
     243                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10