LCOV - code coverage report
Current view: top level - chart2/source/controller/main - CommandDispatchContainer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 81 90 90.0 %
Date: 2012-08-25 Functions: 8 9 88.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 120 244 49.2 %

           Branch data     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 "CommandDispatchContainer.hxx"
      22                 :            : #include "UndoCommandDispatch.hxx"
      23                 :            : #include "StatusBarCommandDispatch.hxx"
      24                 :            : #include "DisposeHelper.hxx"
      25                 :            : #include "macros.hxx"
      26                 :            : #include "ChartController.hxx"
      27                 :            : #include "DrawCommandDispatch.hxx"
      28                 :            : #include "ShapeController.hxx"
      29                 :            : 
      30                 :            : #include <comphelper/InlineContainer.hxx>
      31                 :            : 
      32                 :            : #include <com/sun/star/frame/XDispatchProvider.hpp>
      33                 :            : 
      34                 :            : using namespace ::com::sun::star;
      35                 :            : 
      36                 :            : using ::com::sun::star::uno::Reference;
      37                 :            : using ::com::sun::star::uno::Sequence;
      38                 :            : using ::rtl::OUString;
      39                 :            : 
      40                 :            : namespace chart
      41                 :            : {
      42                 :            : 
      43                 :         34 : CommandDispatchContainer::CommandDispatchContainer(
      44                 :            :     const Reference< uno::XComponentContext > & xContext, ChartController* pController )
      45                 :            :         :m_xContext( xContext )
      46                 :            :         ,m_pChartController( pController )
      47                 :            :         ,m_pDrawCommandDispatch( NULL )
      48 [ +  - ][ +  - ]:         34 :         ,m_pShapeController( NULL )
         [ +  - ][ +  - ]
      49                 :            : {
      50                 :            :     m_aContainerDocumentCommands =
      51                 :            :         ::comphelper::MakeSet< OUString >
      52 [ +  - ][ +  - ]:         68 :         ( C2U("AddDirect"))    ( C2U("NewDoc"))             ( C2U("Open"))
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      53 [ +  - ][ +  - ]:        102 :         ( C2U("Save"))         ( C2U("SaveAs"))             ( C2U("SendMail"))
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      54 [ +  - ][ +  - ]:        102 :         ( C2U("EditDoc"))      ( C2U("ExportDirectToPDF"))  ( C2U("PrintDefault"))
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      55         [ +  - ]:         34 :         ;
      56                 :         34 : }
      57                 :            : 
      58                 :         66 : void CommandDispatchContainer::setModel(
      59                 :            :     const Reference< frame::XModel > & xModel )
      60                 :            : {
      61                 :            :     // remove all existing dispatcher that base on the old model
      62                 :         66 :     m_aCachedDispatches.clear();
      63                 :         66 :     DisposeHelper::DisposeAllElements( m_aToBeDisposedDispatches );
      64                 :         66 :     m_aToBeDisposedDispatches.clear();
      65                 :         66 :     m_xModel = xModel;
      66                 :         66 : }
      67                 :            : 
      68                 :         34 : void CommandDispatchContainer::setChartDispatch(
      69                 :            :     const Reference< frame::XDispatch > xChartDispatch,
      70                 :            :     const ::std::set< OUString > & rChartCommands )
      71                 :            : {
      72                 :            :     OSL_ENSURE(xChartDispatch.is(),"Invalid fall back dispatcher!");
      73                 :         34 :     m_xChartDispatcher.set( xChartDispatch );
      74                 :         34 :     m_aChartCommands = rChartCommands;
      75                 :         34 :     m_aToBeDisposedDispatches.push_back( m_xChartDispatcher );
      76                 :         34 : }
      77                 :            : 
      78                 :       1504 : Reference< frame::XDispatch > CommandDispatchContainer::getDispatchForURL(
      79                 :            :     const util::URL & rURL )
      80                 :            : {
      81                 :       1504 :     Reference< frame::XDispatch > xResult;
      82         [ +  - ]:       1504 :     tDispatchMap::const_iterator aIt( m_aCachedDispatches.find( rURL.Complete ));
      83         [ +  + ]:       1504 :     if( aIt != m_aCachedDispatches.end())
      84                 :            :     {
      85         [ +  - ]:         76 :         xResult.set( (*aIt).second );
      86                 :            :     }
      87                 :            :     else
      88                 :            :     {
      89         [ +  - ]:       1428 :         uno::Reference< frame::XModel > xModel( m_xModel );
      90                 :            : 
      91 [ +  - ][ +  - ]:       1428 :         if( xModel.is() && ( rURL.Path == "Undo" || rURL.Path == "Redo" ) )
         [ +  + ][ +  + ]
      92                 :            :         {
      93         [ +  - ]:         34 :             CommandDispatch * pDispatch = new UndoCommandDispatch( m_xContext, xModel );
      94 [ +  - ][ +  - ]:         34 :             xResult.set( pDispatch );
      95         [ +  - ]:         34 :             pDispatch->initialize();
      96 [ +  - ][ +  - ]:         34 :             m_aCachedDispatches[ C2U(".uno:Undo") ].set( xResult );
                 [ +  - ]
      97 [ +  - ][ +  - ]:         34 :             m_aCachedDispatches[ C2U(".uno:Redo") ].set( xResult );
                 [ +  - ]
      98         [ +  - ]:         34 :             m_aToBeDisposedDispatches.push_back( xResult );
      99                 :            :         }
     100 [ +  - ][ +  + ]:       1394 :         else if( xModel.is() && ( rURL.Path == "Context" || rURL.Path == "ModifiedStatus" ) )
         [ -  + ][ +  + ]
     101                 :            :         {
     102 [ +  - ][ +  - ]:         34 :             Reference< view::XSelectionSupplier > xSelSupp( xModel->getCurrentController(), uno::UNO_QUERY );
                 [ +  - ]
     103         [ +  - ]:         34 :             CommandDispatch * pDispatch = new StatusBarCommandDispatch( m_xContext, xModel, xSelSupp );
     104 [ +  - ][ +  - ]:         34 :             xResult.set( pDispatch );
     105         [ +  - ]:         34 :             pDispatch->initialize();
     106 [ +  - ][ +  - ]:         34 :             m_aCachedDispatches[ C2U(".uno:Context") ].set( xResult );
                 [ +  - ]
     107 [ +  - ][ +  - ]:         34 :             m_aCachedDispatches[ C2U(".uno:ModifiedStatus") ].set( xResult );
                 [ +  - ]
     108         [ +  - ]:         34 :             m_aToBeDisposedDispatches.push_back( xResult );
     109                 :            :         }
     110   [ +  -  +  + ]:       4080 :         else if( xModel.is() &&
                 [ +  + ]
     111 [ +  - ][ +  - ]:       2720 :                  (m_aContainerDocumentCommands.find( rURL.Path ) != m_aContainerDocumentCommands.end()) )
                 [ +  - ]
           [ #  #  #  # ]
     112                 :            :         {
     113 [ +  - ][ +  - ]:        306 :             xResult.set( getContainerDispatchForURL( xModel->getCurrentController(), rURL ));
         [ +  - ][ +  - ]
     114                 :            :             // ToDo: can those dispatches be cached?
     115 [ +  - ][ +  - ]:        306 :             m_aCachedDispatches[ rURL.Complete ].set( xResult );
     116                 :            :         }
     117   [ +  -  +  + ]:       3162 :         else if( m_xChartDispatcher.is() &&
                 [ +  + ]
     118 [ +  - ][ +  - ]:       2108 :                  (m_aChartCommands.find( rURL.Path ) != m_aChartCommands.end()) )
                 [ +  - ]
           [ #  #  #  # ]
     119                 :            :         {
     120         [ +  - ]:        374 :             xResult.set( m_xChartDispatcher );
     121 [ +  - ][ +  - ]:        374 :             m_aCachedDispatches[ rURL.Complete ].set( xResult );
     122                 :            :         }
     123                 :            :         // #i12587# support for shapes in chart
     124                 :            :         // Note, that the chart dispatcher must be queried first, because
     125                 :            :         // the chart dispatcher is the default dispatcher for all context
     126                 :            :         // sensitive commands.
     127 [ +  - ][ +  - ]:        680 :         else if ( m_pDrawCommandDispatch && m_pDrawCommandDispatch->isFeatureSupported( rURL.Complete ) )
         [ +  + ][ +  + ]
     128                 :            :         {
     129 [ +  - ][ +  - ]:        476 :             xResult.set( m_pDrawCommandDispatch );
     130 [ +  - ][ +  - ]:        476 :             m_aCachedDispatches[ rURL.Complete ].set( xResult );
     131                 :            :         }
     132 [ +  - ][ +  - ]:        204 :         else if ( m_pShapeController && m_pShapeController->isFeatureSupported( rURL.Complete ) )
         [ -  + ][ -  + ]
     133                 :            :         {
     134 [ #  # ][ #  # ]:          0 :             xResult.set( m_pShapeController );
     135 [ #  # ][ #  # ]:          0 :             m_aCachedDispatches[ rURL.Complete ].set( xResult );
     136                 :       1504 :         }
     137                 :            :     }
     138                 :            : 
     139                 :       1504 :     return xResult;
     140                 :            : }
     141                 :            : 
     142                 :          0 : Sequence< Reference< frame::XDispatch > > CommandDispatchContainer::getDispatchesForURLs(
     143                 :            :     const Sequence< frame::DispatchDescriptor > & aDescriptors )
     144                 :            : {
     145                 :          0 :     sal_Int32 nCount = aDescriptors.getLength();
     146                 :          0 :     uno::Sequence< uno::Reference< frame::XDispatch > > aRet( nCount );
     147                 :            : 
     148         [ #  # ]:          0 :     for( sal_Int32 nPos = 0; nPos < nCount; ++nPos )
     149                 :            :     {
     150         [ #  # ]:          0 :         if ( aDescriptors[ nPos ].FrameName == "_self" )
     151 [ #  # ][ #  # ]:          0 :             aRet[ nPos ] = getDispatchForURL( aDescriptors[ nPos ].FeatureURL );
                 [ #  # ]
     152                 :            :     }
     153                 :          0 :     return aRet;
     154                 :            : }
     155                 :            : 
     156                 :         34 : void CommandDispatchContainer::DisposeAndClear()
     157                 :            : {
     158                 :         34 :     m_aCachedDispatches.clear();
     159                 :         34 :     DisposeHelper::DisposeAllElements( m_aToBeDisposedDispatches );
     160                 :         34 :     m_aToBeDisposedDispatches.clear();
     161                 :         34 :     m_xChartDispatcher.clear();
     162                 :         34 :     m_aChartCommands.clear();
     163                 :         34 :     m_pChartController = NULL;
     164                 :         34 :     m_pDrawCommandDispatch = NULL;
     165                 :         34 :     m_pShapeController = NULL;
     166                 :         34 : }
     167                 :            : 
     168                 :        306 : Reference< frame::XDispatch > CommandDispatchContainer::getContainerDispatchForURL(
     169                 :            :     const Reference< frame::XController > & xChartController,
     170                 :            :     const util::URL & rURL )
     171                 :            : {
     172                 :        306 :     Reference< frame::XDispatch > xResult;
     173         [ +  - ]:        306 :     if( xChartController.is())
     174                 :            :     {
     175 [ +  - ][ +  - ]:        306 :         Reference< frame::XFrame > xFrame( xChartController->getFrame());
     176         [ +  - ]:        306 :         if( xFrame.is())
     177                 :            :         {
     178 [ +  - ][ +  - ]:        306 :             Reference< frame::XDispatchProvider > xDispProv( xFrame->getCreator(), uno::UNO_QUERY );
                 [ +  - ]
     179         [ +  - ]:        306 :             if( xDispProv.is())
     180 [ +  - ][ +  - ]:        306 :                 xResult.set( xDispProv->queryDispatch( rURL, C2U("_self"), 0 ));
         [ +  - ][ +  - ]
     181                 :        306 :         }
     182                 :            :     }
     183                 :        306 :     return xResult;
     184                 :            : }
     185                 :            : 
     186                 :         34 : void CommandDispatchContainer::setDrawCommandDispatch( DrawCommandDispatch* pDispatch )
     187                 :            : {
     188                 :         34 :     m_pDrawCommandDispatch = pDispatch;
     189 [ +  - ][ +  - ]:         34 :     m_aToBeDisposedDispatches.push_back( Reference< frame::XDispatch >( pDispatch ) );
     190                 :         34 : }
     191                 :            : 
     192                 :         34 : void CommandDispatchContainer::setShapeController( ShapeController* pController )
     193                 :            : {
     194                 :         34 :     m_pShapeController = pController;
     195 [ +  - ][ +  - ]:         34 :     m_aToBeDisposedDispatches.push_back( Reference< frame::XDispatch >( pController ) );
     196                 :         34 : }
     197                 :            : 
     198                 :            : } //  namespace chart
     199                 :            : 
     200                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10