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

Generated by: LCOV version 1.10