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

Generated by: LCOV version 1.10