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

Generated by: LCOV version 1.10