LCOV - code coverage report
Current view: top level - chart2/source/controller/main - CommandDispatchContainer.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 81 92 88.0 %
Date: 2015-06-13 12:38:46 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          18 : CommandDispatchContainer::CommandDispatchContainer(
      42             :     const Reference< uno::XComponentContext > & xContext, ChartController* pController )
      43             :         :m_xContext( xContext )
      44             :         ,m_pChartController( pController )
      45             :         ,m_pDrawCommandDispatch( NULL )
      46          18 :         ,m_pShapeController( NULL )
      47             : {
      48          18 :     m_aContainerDocumentCommands =
      49             :         ::comphelper::MakeSet< OUString >
      50          36 :         ("AddDirect")    ("NewDoc")             ("Open")
      51          54 :         ("Save")         ("SaveAs")             ("SendMail")
      52          54 :         ("EditDoc")      ("ExportDirectToPDF")  ("PrintDefault")
      53          18 :         ;
      54          18 : }
      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 >& rChartDispatch,
      68             :     const ::std::set< OUString > & rChartCommands )
      69             : {
      70             :     OSL_ENSURE(rChartDispatch.is(),"Invalid fall back dispatcher!");
      71          17 :     m_xChartDispatcher.set( rChartDispatch );
      72          17 :     m_aChartCommands = rChartCommands;
      73          17 :     m_aToBeDisposedDispatches.push_back( m_xChartDispatcher );
      74          17 : }
      75             : 
      76         701 : Reference< frame::XDispatch > CommandDispatchContainer::getDispatchForURL(
      77             :     const util::URL & rURL )
      78             : {
      79         701 :     Reference< frame::XDispatch > xResult;
      80         701 :     tDispatchMap::const_iterator aIt( m_aCachedDispatches.find( rURL.Complete ));
      81         701 :     if( aIt != m_aCachedDispatches.end())
      82             :     {
      83          55 :         xResult.set( (*aIt).second );
      84             :     }
      85             :     else
      86             :     {
      87         646 :         uno::Reference< frame::XModel > xModel( m_xModel );
      88             : 
      89         646 :         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         629 :         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        3060 :         else if( xModel.is() &&
     109        3060 :                  (m_aContainerDocumentCommands.find( rURL.Path ) != m_aContainerDocumentCommands.end()) )
     110             :         {
     111         119 :             xResult.set( getContainerDispatchForURL( xModel->getCurrentController(), rURL ));
     112             :             // ToDo: can those dispatches be cached?
     113         119 :             m_aCachedDispatches[ rURL.Complete ].set( xResult );
     114             :         }
     115        2465 :         else if( m_xChartDispatcher.is() &&
     116        2465 :                  (m_aChartCommands.find( rURL.Path ) != m_aChartCommands.end()) )
     117             :         {
     118         374 :             xResult.set( m_xChartDispatcher );
     119         374 :             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         119 :         else if ( m_pDrawCommandDispatch && m_pDrawCommandDispatch->isFeatureSupported( rURL.Complete ) )
     126             :         {
     127           0 :             xResult.set( m_pDrawCommandDispatch );
     128           0 :             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         646 :         }
     135             :     }
     136             : 
     137         701 :     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           1 : void CommandDispatchContainer::DisposeAndClear()
     155             : {
     156           1 :     m_aCachedDispatches.clear();
     157           1 :     DisposeHelper::DisposeAllElements( m_aToBeDisposedDispatches );
     158           1 :     m_aToBeDisposedDispatches.clear();
     159           1 :     m_xChartDispatcher.clear();
     160           1 :     m_aChartCommands.clear();
     161           1 :     m_pChartController = NULL;
     162           1 :     m_pDrawCommandDispatch = NULL;
     163           1 :     m_pShapeController = NULL;
     164           1 : }
     165             : 
     166         119 : Reference< frame::XDispatch > CommandDispatchContainer::getContainerDispatchForURL(
     167             :     const Reference< frame::XController > & xChartController,
     168             :     const util::URL & rURL )
     169             : {
     170         119 :     Reference< frame::XDispatch > xResult;
     171         119 :     if( xChartController.is())
     172             :     {
     173         119 :         Reference< frame::XFrame > xFrame( xChartController->getFrame());
     174         119 :         if( xFrame.is())
     175             :         {
     176         102 :             Reference< frame::XDispatchProvider > xDispProv( xFrame->getCreator(), uno::UNO_QUERY );
     177         102 :             if( xDispProv.is())
     178         102 :                 xResult.set( xDispProv->queryDispatch( rURL, "_self", 0 ));
     179         119 :         }
     180             :     }
     181         119 :     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          57 : } //  namespace chart
     197             : 
     198             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11