LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/controller/main - UndoCommandDispatch.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 47 0.0 %
Date: 2012-12-27 Functions: 0 8 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 "UndoCommandDispatch.hxx"
      22             : #include "ResId.hxx"
      23             : #include "macros.hxx"
      24             : 
      25             : #include <com/sun/star/util/XModifyBroadcaster.hpp>
      26             : #include <com/sun/star/document/XUndoManagerSupplier.hpp>
      27             : 
      28             : #include <osl/mutex.hxx>
      29             : #include <vcl/svapp.hxx>
      30             : #include <tools/diagnose_ex.h>
      31             : 
      32             : // for resource strings STR_UNDO and STR_REDO
      33             : #include <svtools/svtools.hrc>
      34             : #include <svtools/svtresid.hxx>
      35             : 
      36             : using namespace ::com::sun::star;
      37             : 
      38             : using ::com::sun::star::uno::Reference;
      39             : using ::com::sun::star::uno::Sequence;
      40             : using ::rtl::OUString;
      41             : 
      42             : namespace chart
      43             : {
      44             : 
      45           0 : UndoCommandDispatch::UndoCommandDispatch(
      46             :     const Reference< uno::XComponentContext > & xContext,
      47             :     const Reference< frame::XModel > & xModel ) :
      48             :         CommandDispatch( xContext ),
      49           0 :         m_xModel( xModel )
      50             : {
      51           0 :     uno::Reference< document::XUndoManagerSupplier > xSuppUndo( m_xModel, uno::UNO_QUERY_THROW );
      52           0 :     m_xUndoManager.set( xSuppUndo->getUndoManager(), uno::UNO_QUERY_THROW );
      53           0 : }
      54             : 
      55           0 : UndoCommandDispatch::~UndoCommandDispatch()
      56           0 : {}
      57             : 
      58           0 : void UndoCommandDispatch::initialize()
      59             : {
      60           0 :     Reference< util::XModifyBroadcaster > xBroadcaster( m_xUndoManager, uno::UNO_QUERY );
      61           0 :     ENSURE_OR_RETURN_VOID( xBroadcaster.is(), "UndoCommandDispatch::initialize: missing modification broadcaster interface!" );
      62           0 :     xBroadcaster->addModifyListener( this );
      63             : }
      64             : 
      65           0 : void UndoCommandDispatch::fireStatusEvent(
      66             :     const OUString & rURL,
      67             :     const Reference< frame::XStatusListener > & xSingleListener /* = 0 */ )
      68             : {
      69           0 :     if( m_xUndoManager.is() )
      70             :     {
      71           0 :         bool bFireAll = rURL.isEmpty();
      72           0 :         uno::Any aUndoState, aRedoState;
      73           0 :         if( m_xUndoManager->isUndoPossible())
      74             :         {
      75             :             // using assignment for broken gcc 3.3
      76           0 :             OUString aUndo = OUString( String( SvtResId( STR_UNDO )));
      77           0 :             aUndoState <<= ( aUndo + m_xUndoManager->getCurrentUndoActionTitle());
      78             :         }
      79           0 :         if( m_xUndoManager->isRedoPossible())
      80             :         {
      81             :             // using assignment for broken gcc 3.3
      82           0 :             OUString aRedo = OUString( String( SvtResId( STR_REDO )));
      83           0 :             aRedoState <<= ( aRedo + m_xUndoManager->getCurrentRedoActionTitle());
      84             :         }
      85             : 
      86           0 :         if( bFireAll || rURL == ".uno:Undo" )
      87           0 :             fireStatusEventForURL( C2U(".uno:Undo"), aUndoState, m_xUndoManager->isUndoPossible(), xSingleListener );
      88           0 :         if( bFireAll || rURL == ".uno:Redo" )
      89           0 :             fireStatusEventForURL( C2U(".uno:Redo"), aRedoState, m_xUndoManager->isRedoPossible(), xSingleListener );
      90             :     }
      91           0 : }
      92             : 
      93             : // ____ XDispatch ____
      94           0 : void SAL_CALL UndoCommandDispatch::dispatch(
      95             :     const util::URL& URL,
      96             :     const Sequence< beans::PropertyValue >& /* Arguments */ )
      97             :     throw (uno::RuntimeException)
      98             : {
      99           0 :     if( m_xUndoManager.is() )
     100             :     {
     101             :         // why is it necessary to lock the solar mutex here?
     102           0 :         SolarMutexGuard aSolarGuard;
     103             :         try
     104             :         {
     105           0 :             if ( URL.Path == "Undo" )
     106           0 :                 m_xUndoManager->undo();
     107             :             else
     108           0 :                 m_xUndoManager->redo();
     109             :         }
     110           0 :         catch( const document::UndoFailedException& )
     111             :         {
     112             :             // silently ignore
     113             :         }
     114           0 :         catch( const uno::Exception& )
     115             :         {
     116             :             DBG_UNHANDLED_EXCEPTION();
     117           0 :         }
     118             :         // \--
     119             :     }
     120           0 : }
     121             : 
     122             : // ____ WeakComponentImplHelperBase ____
     123             : /// is called when this is disposed
     124           0 : void SAL_CALL UndoCommandDispatch::disposing()
     125             : {
     126           0 :     Reference< util::XModifyBroadcaster > xBroadcaster( m_xUndoManager, uno::UNO_QUERY );
     127             :     OSL_ENSURE( xBroadcaster.is(), "UndoCommandDispatch::initialize: missing modification broadcaster interface!" );
     128           0 :     if( xBroadcaster.is() )
     129             :     {
     130           0 :         xBroadcaster->removeModifyListener( this );
     131             :     }
     132             : 
     133           0 :     m_xUndoManager.clear();
     134           0 :     m_xModel.clear();
     135           0 : }
     136             : 
     137             : // ____ XEventListener (base of XModifyListener) ____
     138           0 : void SAL_CALL UndoCommandDispatch::disposing( const lang::EventObject& /* Source */ )
     139             :     throw (uno::RuntimeException)
     140             : {
     141           0 :     m_xUndoManager.clear();
     142           0 :     m_xModel.clear();
     143           0 : }
     144             : 
     145             : } //  namespace chart
     146             : 
     147             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10