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

Generated by: LCOV version 1.10