LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/model/main - UndoManager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 145 0.0 %
Date: 2012-12-27 Functions: 0 50 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 "UndoManager.hxx"
      22             : #include "ChartViewHelper.hxx"
      23             : 
      24             : #include <com/sun/star/lang/DisposedException.hpp>
      25             : 
      26             : #include <framework/undomanagerhelper.hxx>
      27             : #include <officecfg/Office/Common.hxx>
      28             : #include <svl/undo.hxx>
      29             : 
      30             : //......................................................................................................................
      31             : namespace chart
      32             : {
      33             : //......................................................................................................................
      34             : 
      35             :     /** === begin UNO using === **/
      36             :     using ::com::sun::star::uno::Reference;
      37             :     using ::com::sun::star::uno::XInterface;
      38             :     using ::com::sun::star::uno::UNO_QUERY;
      39             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      40             :     using ::com::sun::star::uno::UNO_SET_THROW;
      41             :     using ::com::sun::star::uno::Exception;
      42             :     using ::com::sun::star::uno::RuntimeException;
      43             :     using ::com::sun::star::uno::Any;
      44             :     using ::com::sun::star::uno::makeAny;
      45             :     using ::com::sun::star::uno::Sequence;
      46             :     using ::com::sun::star::uno::Type;
      47             :     using ::com::sun::star::lang::DisposedException;
      48             :     using ::com::sun::star::document::XUndoManager;
      49             :     using ::com::sun::star::document::EmptyUndoStackException;
      50             :     using ::com::sun::star::document::UndoContextNotClosedException;
      51             :     using ::com::sun::star::document::UndoFailedException;
      52             :     using ::com::sun::star::util::InvalidStateException;
      53             :     using ::com::sun::star::document::XUndoAction;
      54             :     using ::com::sun::star::lang::IllegalArgumentException;
      55             :     using ::com::sun::star::document::XUndoManagerListener;
      56             :     using ::com::sun::star::util::NotLockedException;
      57             :     using ::com::sun::star::lang::NoSupportException;
      58             :     using ::com::sun::star::util::XModifyListener;
      59             :     using ::com::sun::star::frame::XModel;
      60             :     /** === end UNO using === **/
      61             : 
      62             :     namespace impl
      63             :     {
      64             :         //==============================================================================================================
      65             :         //= UndoManager_Impl
      66             :         //==============================================================================================================
      67             :         class UndoManager_Impl : public ::framework::IUndoManagerImplementation
      68             :         {
      69             :         public:
      70           0 :             UndoManager_Impl( UndoManager& i_antiImpl, ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex )
      71             :                 :m_rAntiImpl( i_antiImpl )
      72             :                 ,m_rParent( i_parent )
      73             :                 ,m_rMutex( i_mutex )
      74             :                 ,m_bDisposed( false )
      75             :                 ,m_aUndoManager()
      76           0 :                 ,m_aUndoHelper( *this )
      77             :             {
      78             :                 m_aUndoManager.SetMaxUndoActionCount(
      79           0 :                     officecfg::Office::Common::Undo::Steps::get());
      80           0 :             }
      81             : 
      82           0 :             virtual ~UndoManager_Impl()
      83           0 :             {
      84           0 :             }
      85             : 
      86             :             // .........................................................................................................
      87             :             // IUndoManagerImplementation
      88             :             virtual ::osl::Mutex&               getMutex();
      89             :             virtual ::svl::IUndoManager&        getImplUndoManager();
      90             :             virtual Reference< XUndoManager >   getThis();
      91             : 
      92             :             // .........................................................................................................
      93             :             // attribute access
      94           0 :             ::cppu::OWeakObject&                getParent() { return m_rParent; }
      95           0 :             ::framework::UndoManagerHelper&     getUndoHelper() { return m_aUndoHelper; }
      96             : 
      97             :             // .........................................................................................................
      98             :             // public interface
      99             : 
     100             :             /// is called when the owner of the UndoManager is being disposed
     101             :             void    disposing();
     102             : 
     103             :             /// checks whether we're already disposed, throws a DisposedException if so
     104             :             void    checkDisposed_lck();
     105             : 
     106             :         private:
     107             :             UndoManager&                        m_rAntiImpl;
     108             :             ::cppu::OWeakObject&                m_rParent;
     109             :             ::osl::Mutex&                       m_rMutex;
     110             :             bool                                m_bDisposed;
     111             : 
     112             :             SfxUndoManager                      m_aUndoManager;
     113             :             ::framework::UndoManagerHelper      m_aUndoHelper;
     114             :         };
     115             : 
     116             :         //--------------------------------------------------------------------------------------------------------------
     117           0 :         ::osl::Mutex& UndoManager_Impl::getMutex()
     118             :         {
     119           0 :             return m_rMutex;
     120             :         }
     121             : 
     122             :         //--------------------------------------------------------------------------------------------------------------
     123           0 :         ::svl::IUndoManager& UndoManager_Impl::getImplUndoManager()
     124             :         {
     125           0 :             return m_aUndoManager;
     126             :         }
     127             : 
     128             :         //--------------------------------------------------------------------------------------------------------------
     129           0 :         Reference< XUndoManager > UndoManager_Impl::getThis()
     130             :         {
     131           0 :             return &m_rAntiImpl;
     132             :         }
     133             : 
     134             :         //--------------------------------------------------------------------------------------------------------------
     135           0 :         void UndoManager_Impl::disposing()
     136             :         {
     137             :             {
     138           0 :                 ::osl::MutexGuard aGuard( m_rMutex );
     139           0 :                 m_bDisposed = true;
     140             :             }
     141           0 :             m_aUndoHelper.disposing();
     142           0 :         }
     143             : 
     144             :         //--------------------------------------------------------------------------------------------------------------
     145           0 :         void UndoManager_Impl::checkDisposed_lck()
     146             :         {
     147           0 :             if ( m_bDisposed )
     148           0 :                 throw DisposedException( ::rtl::OUString(), getThis() );
     149           0 :         }
     150             : 
     151             :         //==============================================================================================================
     152             :         //= UndoManagerMethodGuard
     153             :         //==============================================================================================================
     154             :         /** guard for public UNO methods of the UndoManager
     155             : 
     156             :             The only purpose of this guard is to check for the instance being disposed already. Everything else,
     157             :             in particular the IMutexGuard functionality required by the UndoManagerHelper class, is a dummy only,
     158             :             as all involved classes (means we ourselves, the UndoManagerHelper, the SfxUndoManager, and the Undo actions
     159             :             we create) are inherently thread-safe, thus need no external lock (in particular no SolarMutex!).
     160             :         */
     161             :         class UndoManagerMethodGuard : public ::framework::IMutexGuard
     162             :         {
     163             :         public:
     164           0 :             UndoManagerMethodGuard( UndoManager_Impl& i_impl )
     165           0 :             {
     166           0 :                 ::osl::MutexGuard aGuard( i_impl.getMutex() );
     167             :                 // throw if the instance is already disposed
     168           0 :                 i_impl.checkDisposed_lck();
     169           0 :             }
     170           0 :             virtual ~UndoManagerMethodGuard()
     171           0 :             {
     172           0 :             }
     173             : 
     174             :             // IMutexGuard
     175             :             virtual ::framework::IMutex& getGuardedMutex();
     176             : 
     177             :             // IGuard
     178             :             virtual void clear();
     179             :             virtual void reset();
     180             :         };
     181             : 
     182             :         class DummyMutex : public ::framework::IMutex
     183             :         {
     184             :         public:
     185           0 :             virtual ~DummyMutex() {}
     186           0 :             virtual void acquire() { }
     187           0 :             virtual void release() { }
     188             :         };
     189             : 
     190             :         //--------------------------------------------------------------------------------------------------------------
     191           0 :         ::framework::IMutex& UndoManagerMethodGuard::getGuardedMutex()
     192             :         {
     193           0 :             static DummyMutex s_aDummyMutex;
     194           0 :             return s_aDummyMutex;
     195             :         }
     196             : 
     197             :         //--------------------------------------------------------------------------------------------------------------
     198           0 :         void UndoManagerMethodGuard::clear()
     199             :         {
     200             :             // nothing to do. This interface implementation is a dummy.
     201           0 :         }
     202             : 
     203             :         //--------------------------------------------------------------------------------------------------------------
     204           0 :         void UndoManagerMethodGuard::reset()
     205             :         {
     206             :             // nothing to do. This interface implementation is a dummy.
     207           0 :         }
     208             :     }
     209             : 
     210             :     //==================================================================================================================
     211             :     //= UndoManager
     212             :     //==================================================================================================================
     213             :     using impl::UndoManagerMethodGuard;
     214             : 
     215             :     //------------------------------------------------------------------------------------------------------------------
     216           0 :     UndoManager::UndoManager( ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex )
     217           0 :         :m_pImpl( new impl::UndoManager_Impl( *this, i_parent, i_mutex ) )
     218             :     {
     219           0 :     }
     220             : 
     221             :     //------------------------------------------------------------------------------------------------------------------
     222           0 :     UndoManager::~UndoManager()
     223             :     {
     224           0 :     }
     225             : 
     226             :     //------------------------------------------------------------------------------------------------------------------
     227           0 :     void SAL_CALL UndoManager::acquire() throw ()
     228             :     {
     229           0 :         m_pImpl->getParent().acquire();
     230           0 :     }
     231             : 
     232             :     //------------------------------------------------------------------------------------------------------------------
     233           0 :     void SAL_CALL UndoManager::release() throw ()
     234             :     {
     235           0 :         m_pImpl->getParent().release();
     236           0 :     }
     237             : 
     238             :     //------------------------------------------------------------------------------------------------------------------
     239           0 :     void UndoManager::disposing()
     240             :     {
     241           0 :         m_pImpl->disposing();
     242           0 :     }
     243             : 
     244             :     //------------------------------------------------------------------------------------------------------------------
     245           0 :     void SAL_CALL UndoManager::enterUndoContext( const ::rtl::OUString& i_title ) throw (RuntimeException)
     246             :     {
     247           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     248           0 :         m_pImpl->getUndoHelper().enterUndoContext( i_title, aGuard );
     249           0 :     }
     250             : 
     251             :     //------------------------------------------------------------------------------------------------------------------
     252           0 :     void SAL_CALL UndoManager::enterHiddenUndoContext(  ) throw (EmptyUndoStackException, RuntimeException)
     253             :     {
     254           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     255           0 :         m_pImpl->getUndoHelper().enterHiddenUndoContext( aGuard );
     256           0 :     }
     257             : 
     258             :     //------------------------------------------------------------------------------------------------------------------
     259           0 :     void SAL_CALL UndoManager::leaveUndoContext(  ) throw (InvalidStateException, RuntimeException)
     260             :     {
     261           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     262           0 :         m_pImpl->getUndoHelper().leaveUndoContext( aGuard );
     263           0 :     }
     264             : 
     265             :     //------------------------------------------------------------------------------------------------------------------
     266           0 :     void SAL_CALL UndoManager::addUndoAction( const Reference< XUndoAction >& i_action ) throw (IllegalArgumentException, RuntimeException)
     267             :     {
     268           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     269           0 :         m_pImpl->getUndoHelper().addUndoAction( i_action, aGuard );
     270           0 :     }
     271             : 
     272             :     //------------------------------------------------------------------------------------------------------------------
     273           0 :     void SAL_CALL UndoManager::undo(  ) throw (EmptyUndoStackException, UndoContextNotClosedException, UndoFailedException, RuntimeException)
     274             :     {
     275           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     276           0 :         m_pImpl->getUndoHelper().undo( aGuard );
     277             : 
     278           0 :         ChartViewHelper::setViewToDirtyState( Reference< XModel >( getParent(), UNO_QUERY ) );
     279           0 :     }
     280             : 
     281             :     //------------------------------------------------------------------------------------------------------------------
     282           0 :     void SAL_CALL UndoManager::redo(  ) throw (EmptyUndoStackException, UndoContextNotClosedException, UndoFailedException, RuntimeException)
     283             :     {
     284           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     285           0 :         m_pImpl->getUndoHelper().redo( aGuard );
     286             : 
     287           0 :         ChartViewHelper::setViewToDirtyState( Reference< XModel >( getParent(), UNO_QUERY ) );
     288           0 :     }
     289             : 
     290             :     //------------------------------------------------------------------------------------------------------------------
     291           0 :     ::sal_Bool SAL_CALL UndoManager::isUndoPossible(  ) throw (RuntimeException)
     292             :     {
     293           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     294           0 :         return m_pImpl->getUndoHelper().isUndoPossible();
     295             :     }
     296             : 
     297             :     //------------------------------------------------------------------------------------------------------------------
     298           0 :     ::sal_Bool SAL_CALL UndoManager::isRedoPossible(  ) throw (RuntimeException)
     299             :     {
     300           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     301           0 :         return m_pImpl->getUndoHelper().isRedoPossible();
     302             :     }
     303             : 
     304             :     //------------------------------------------------------------------------------------------------------------------
     305           0 :     ::rtl::OUString SAL_CALL UndoManager::getCurrentUndoActionTitle(  ) throw (EmptyUndoStackException, RuntimeException)
     306             :     {
     307           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     308           0 :         return m_pImpl->getUndoHelper().getCurrentUndoActionTitle();
     309             :     }
     310             : 
     311             :     //------------------------------------------------------------------------------------------------------------------
     312           0 :     ::rtl::OUString SAL_CALL UndoManager::getCurrentRedoActionTitle(  ) throw (EmptyUndoStackException, RuntimeException)
     313             :     {
     314           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     315           0 :         return m_pImpl->getUndoHelper().getCurrentRedoActionTitle();
     316             :     }
     317             : 
     318             :     //------------------------------------------------------------------------------------------------------------------
     319           0 :     Sequence< ::rtl::OUString > SAL_CALL UndoManager::getAllUndoActionTitles(  ) throw (RuntimeException)
     320             :     {
     321           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     322           0 :         return m_pImpl->getUndoHelper().getAllUndoActionTitles();
     323             :     }
     324             : 
     325             :     //------------------------------------------------------------------------------------------------------------------
     326           0 :     Sequence< ::rtl::OUString > SAL_CALL UndoManager::getAllRedoActionTitles(  ) throw (RuntimeException)
     327             :     {
     328           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     329           0 :         return m_pImpl->getUndoHelper().getAllRedoActionTitles();
     330             :     }
     331             : 
     332             :     //------------------------------------------------------------------------------------------------------------------
     333           0 :     void SAL_CALL UndoManager::clear(  ) throw (UndoContextNotClosedException, RuntimeException)
     334             :     {
     335           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     336           0 :         m_pImpl->getUndoHelper().clear( aGuard );
     337           0 :     }
     338             : 
     339             :     //------------------------------------------------------------------------------------------------------------------
     340           0 :     void SAL_CALL UndoManager::clearRedo(  ) throw (UndoContextNotClosedException, RuntimeException)
     341             :     {
     342           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     343           0 :         m_pImpl->getUndoHelper().clearRedo( aGuard );
     344           0 :     }
     345             : 
     346             :     //------------------------------------------------------------------------------------------------------------------
     347           0 :     void SAL_CALL UndoManager::reset(  ) throw (RuntimeException)
     348             :     {
     349           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     350           0 :         m_pImpl->getUndoHelper().reset( aGuard );
     351           0 :     }
     352             : 
     353             :     //------------------------------------------------------------------------------------------------------------------
     354           0 :     void SAL_CALL UndoManager::addUndoManagerListener( const Reference< XUndoManagerListener >& i_listener ) throw (RuntimeException)
     355             :     {
     356           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     357           0 :         m_pImpl->getUndoHelper().addUndoManagerListener( i_listener );
     358           0 :     }
     359             : 
     360             :     //------------------------------------------------------------------------------------------------------------------
     361           0 :     void SAL_CALL UndoManager::removeUndoManagerListener( const Reference< XUndoManagerListener >& i_listener ) throw (RuntimeException)
     362             :     {
     363           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     364           0 :         m_pImpl->getUndoHelper().removeUndoManagerListener( i_listener );
     365           0 :     }
     366             : 
     367             :     //------------------------------------------------------------------------------------------------------------------
     368           0 :     void SAL_CALL UndoManager::lock(  ) throw (RuntimeException)
     369             :     {
     370           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     371           0 :         m_pImpl->getUndoHelper().lock();
     372           0 :     }
     373             : 
     374             :     //------------------------------------------------------------------------------------------------------------------
     375           0 :     void SAL_CALL UndoManager::unlock(  ) throw (NotLockedException, RuntimeException)
     376             :     {
     377           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     378           0 :         m_pImpl->getUndoHelper().unlock();
     379           0 :     }
     380             : 
     381             :     //------------------------------------------------------------------------------------------------------------------
     382           0 :     ::sal_Bool SAL_CALL UndoManager::isLocked(  ) throw (RuntimeException)
     383             :     {
     384           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     385           0 :         return m_pImpl->getUndoHelper().isLocked();
     386             :     }
     387             : 
     388             :     //------------------------------------------------------------------------------------------------------------------
     389           0 :     Reference< XInterface > SAL_CALL UndoManager::getParent(  ) throw (RuntimeException)
     390             :     {
     391           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     392           0 :         return *&m_pImpl->getParent();
     393             :     }
     394             : 
     395             :     //------------------------------------------------------------------------------------------------------------------
     396           0 :     void SAL_CALL UndoManager::setParent( const Reference< XInterface >& i_parent ) throw (NoSupportException, RuntimeException)
     397             :     {
     398           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     399             :         (void)i_parent;
     400           0 :         throw NoSupportException( ::rtl::OUString(), m_pImpl->getThis() );
     401             :     }
     402             : 
     403             :     //------------------------------------------------------------------------------------------------------------------
     404           0 :     void SAL_CALL UndoManager::addModifyListener( const Reference< XModifyListener >& i_listener ) throw (RuntimeException)
     405             :     {
     406           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     407           0 :         m_pImpl->getUndoHelper().addModifyListener( i_listener );
     408           0 :     }
     409             : 
     410             :     //------------------------------------------------------------------------------------------------------------------
     411           0 :     void SAL_CALL UndoManager::removeModifyListener( const Reference< XModifyListener >& i_listener ) throw (RuntimeException)
     412             :     {
     413           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     414           0 :         m_pImpl->getUndoHelper().removeModifyListener( i_listener );
     415           0 :     }
     416             : 
     417             : //......................................................................................................................
     418             : } // namespace chart
     419             : //......................................................................................................................
     420             : 
     421             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10