LCOV - code coverage report
Current view: top level - chart2/source/controller/main - CommandDispatchContainer.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 82 91 90.1 %
Date: 2014-04-11 Functions: 8 9 88.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          17 : CommandDispatchContainer::CommandDispatchContainer(
      42             :     const Reference< uno::XComponentContext > & xContext, ChartController* pController )
      43             :         :m_xContext( xContext )
      44             :         ,m_pChartController( pController )
      45             :         ,m_pDrawCommandDispatch( NULL )
      46          17 :         ,m_pShapeController( NULL )
      47             : {
      48          17 :     m_aContainerDocumentCommands =
      49             :         ::comphelper::MakeSet< OUString >
      50          34 :         ("AddDirect")    ("NewDoc")             ("Open")
      51          51 :         ("Save")         ("SaveAs")             ("SendMail")
      52          51 :         ("EditDoc")      ("ExportDirectToPDF")  ("PrintDefault")
      53          17 :         ;
      54          17 : }
      55             : 
      56          33 : void CommandDispatchContainer::setModel(
      57             :     const Reference< frame::XModel > & xModel )
      58             : {
      59             :     // remove all existing dispatcher that base on the old model
      60          33 :     m_aCachedDispatches.clear();
      61          33 :     DisposeHelper::DisposeAllElements( m_aToBeDisposedDispatches );
      62          33 :     m_aToBeDisposedDispatches.clear();
      63          33 :     m_xModel = xModel;
      64          33 : }
      65             : 
      66          17 : 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          17 :     m_xChartDispatcher.set( xChartDispatch );
      72          17 :     m_aChartCommands = rChartCommands;
      73          17 :     m_aToBeDisposedDispatches.push_back( m_xChartDispatcher );
      74          17 : }
      75             : 
      76         803 : Reference< frame::XDispatch > CommandDispatchContainer::getDispatchForURL(
      77             :     const util::URL & rURL )
      78             : {
      79         803 :     Reference< frame::XDispatch > xResult;
      80         803 :     tDispatchMap::const_iterator aIt( m_aCachedDispatches.find( rURL.Complete ));
      81         803 :     if( aIt != m_aCachedDispatches.end())
      82             :     {
      83          55 :         xResult.set( (*aIt).second );
      84             :     }
      85             :     else
      86             :     {
      87         748 :         uno::Reference< frame::XModel > xModel( m_xModel );
      88             : 
      89         748 :         if( xModel.is() && ( rURL.Path == "Undo" || rURL.Path == "Redo" ) )
      90             :         {
      91          17 :             CommandDispatch * pDispatch = new UndoCommandDispatch( m_xContext, xModel );
      92          17 :             xResult.set( pDispatch );
      93          17 :             pDispatch->initialize();
      94          17 :             m_aCachedDispatches[ ".uno:Undo" ].set( xResult );
      95          17 :             m_aCachedDispatches[ ".uno:Redo" ].set( xResult );
      96          17 :             m_aToBeDisposedDispatches.push_back( xResult );
      97             :         }
      98         731 :         else if( xModel.is() && ( rURL.Path == "Context" || rURL.Path == "ModifiedStatus" ) )
      99             :         {
     100          17 :             Reference< view::XSelectionSupplier > xSelSupp( xModel->getCurrentController(), uno::UNO_QUERY );
     101          17 :             CommandDispatch * pDispatch = new StatusBarCommandDispatch( m_xContext, xModel, xSelSupp );
     102          17 :             xResult.set( pDispatch );
     103          17 :             pDispatch->initialize();
     104          17 :             m_aCachedDispatches[ ".uno:Context" ].set( xResult );
     105          17 :             m_aCachedDispatches[ ".uno:ModifiedStatus" ].set( xResult );
     106          17 :             m_aToBeDisposedDispatches.push_back( xResult );
     107             :         }
     108        3570 :         else if( xModel.is() &&
     109        3570 :                  (m_aContainerDocumentCommands.find( rURL.Path ) != m_aContainerDocumentCommands.end()) )
     110             :         {
     111         153 :             xResult.set( getContainerDispatchForURL( xModel->getCurrentController(), rURL ));
     112             :             // ToDo: can those dispatches be cached?
     113         153 :             m_aCachedDispatches[ rURL.Complete ].set( xResult );
     114             :         }
     115        2805 :         else if( m_xChartDispatcher.is() &&
     116        2805 :                  (m_aChartCommands.find( rURL.Path ) != m_aChartCommands.end()) )
     117             :         {
     118         204 :             xResult.set( m_xChartDispatcher );
     119         204 :             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         357 :         else if ( m_pDrawCommandDispatch && m_pDrawCommandDispatch->isFeatureSupported( rURL.Complete ) )
     126             :         {
     127         238 :             xResult.set( m_pDrawCommandDispatch );
     128         238 :             m_aCachedDispatches[ rURL.Complete ].set( xResult );
     129             :         }
     130         119 :         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         748 :         }
     135             :     }
     136             : 
     137         803 :     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          17 : void CommandDispatchContainer::DisposeAndClear()
     155             : {
     156          17 :     m_aCachedDispatches.clear();
     157          17 :     DisposeHelper::DisposeAllElements( m_aToBeDisposedDispatches );
     158          17 :     m_aToBeDisposedDispatches.clear();
     159          17 :     m_xChartDispatcher.clear();
     160          17 :     m_aChartCommands.clear();
     161          17 :     m_pChartController = NULL;
     162          17 :     m_pDrawCommandDispatch = NULL;
     163          17 :     m_pShapeController = NULL;
     164          17 : }
     165             : 
     166         153 : Reference< frame::XDispatch > CommandDispatchContainer::getContainerDispatchForURL(
     167             :     const Reference< frame::XController > & xChartController,
     168             :     const util::URL & rURL )
     169             : {
     170         153 :     Reference< frame::XDispatch > xResult;
     171         153 :     if( xChartController.is())
     172             :     {
     173         153 :         Reference< frame::XFrame > xFrame( xChartController->getFrame());
     174         153 :         if( xFrame.is())
     175             :         {
     176         136 :             Reference< frame::XDispatchProvider > xDispProv( xFrame->getCreator(), uno::UNO_QUERY );
     177         136 :             if( xDispProv.is())
     178         136 :                 xResult.set( xDispProv->queryDispatch( rURL, "_self", 0 ));
     179         153 :         }
     180             :     }
     181         153 :     return xResult;
     182             : }
     183             : 
     184          17 : void CommandDispatchContainer::setDrawCommandDispatch( DrawCommandDispatch* pDispatch )
     185             : {
     186          17 :     m_pDrawCommandDispatch = pDispatch;
     187          17 :     m_aToBeDisposedDispatches.push_back( Reference< frame::XDispatch >( pDispatch ) );
     188          17 : }
     189             : 
     190          17 : void CommandDispatchContainer::setShapeController( ShapeController* pController )
     191             : {
     192          17 :     m_pShapeController = pController;
     193          17 :     m_aToBeDisposedDispatches.push_back( Reference< frame::XDispatch >( pController ) );
     194          17 : }
     195             : 
     196             : } //  namespace chart
     197             : 
     198             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10