LCOV - code coverage report
Current view: top level - libreoffice/dbaccess/source/ui/misc - dbaundomanager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 134 0.0 %
Date: 2012-12-27 Functions: 0 45 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 "dbaundomanager.hxx"
      22             : 
      23             : #include <com/sun/star/lang/DisposedException.hpp>
      24             : 
      25             : #include <svl/undo.hxx>
      26             : #include <vcl/svapp.hxx>
      27             : #include <framework/undomanagerhelper.hxx>
      28             : 
      29             : //......................................................................................................................
      30             : namespace dbaui
      31             : {
      32             : //......................................................................................................................
      33             : 
      34             :     /** === begin UNO using === **/
      35             :     using ::com::sun::star::uno::Reference;
      36             :     using ::com::sun::star::uno::XInterface;
      37             :     using ::com::sun::star::uno::UNO_QUERY;
      38             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      39             :     using ::com::sun::star::uno::UNO_SET_THROW;
      40             :     using ::com::sun::star::uno::Exception;
      41             :     using ::com::sun::star::uno::RuntimeException;
      42             :     using ::com::sun::star::uno::Any;
      43             :     using ::com::sun::star::uno::makeAny;
      44             :     using ::com::sun::star::uno::Sequence;
      45             :     using ::com::sun::star::uno::Type;
      46             :     using ::com::sun::star::document::XUndoManager;
      47             :     using ::com::sun::star::lang::DisposedException;
      48             :     using ::com::sun::star::document::UndoContextNotClosedException;
      49             :     using ::com::sun::star::document::UndoFailedException;
      50             :     using ::com::sun::star::document::EmptyUndoStackException;
      51             :     using ::com::sun::star::util::InvalidStateException;
      52             :     using ::com::sun::star::document::XUndoAction;
      53             :     using ::com::sun::star::lang::IllegalArgumentException;
      54             :     using ::com::sun::star::document::XUndoManagerListener;
      55             :     using ::com::sun::star::util::NotLockedException;
      56             :     using ::com::sun::star::lang::NoSupportException;
      57             :     /** === end UNO using === **/
      58             : 
      59             :     //==================================================================================================================
      60             :     //= UndoManager_Impl
      61             :     //==================================================================================================================
      62             :     struct UndoManager_Impl : public ::framework::IUndoManagerImplementation
      63             :     {
      64           0 :         UndoManager_Impl( UndoManager& i_antiImpl, ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex )
      65             :             :rAntiImpl( i_antiImpl )
      66             :             ,rParent( i_parent )
      67             :             ,rMutex( i_mutex )
      68             :             ,bDisposed( false )
      69             :             ,aUndoManager()
      70           0 :             ,aUndoHelper( *this )
      71             :         {
      72           0 :         }
      73             : 
      74           0 :         virtual ~UndoManager_Impl()
      75           0 :         {
      76           0 :         }
      77             : 
      78             :         UndoManager&                    rAntiImpl;
      79             :         ::cppu::OWeakObject&            rParent;
      80             :         ::osl::Mutex&                   rMutex;
      81             :         bool                            bDisposed;
      82             :         SfxUndoManager                  aUndoManager;
      83             :         ::framework::UndoManagerHelper  aUndoHelper;
      84             : 
      85             :         // IUndoManagerImplementation
      86             :         virtual ::svl::IUndoManager&        getImplUndoManager();
      87             :         virtual Reference< XUndoManager >   getThis();
      88             :     };
      89             : 
      90             :     //------------------------------------------------------------------------------------------------------------------
      91           0 :     ::svl::IUndoManager& UndoManager_Impl::getImplUndoManager()
      92             :     {
      93           0 :         return aUndoManager;
      94             :     }
      95             : 
      96             :     //------------------------------------------------------------------------------------------------------------------
      97           0 :     Reference< XUndoManager > UndoManager_Impl::getThis()
      98             :     {
      99           0 :         return static_cast< XUndoManager* >( &rAntiImpl );
     100             :     }
     101             : 
     102             :     //==============================================================================================================
     103             :     //= OslMutexFacade
     104             :     //==============================================================================================================
     105             :     class OslMutexFacade : public ::framework::IMutex
     106             :     {
     107             :     public:
     108           0 :         OslMutexFacade( ::osl::Mutex& i_mutex )
     109           0 :             :m_rMutex( i_mutex )
     110             :         {
     111           0 :         }
     112             : 
     113           0 :         virtual ~OslMutexFacade() {}
     114             : 
     115             :         virtual void acquire();
     116             :         virtual void release();
     117             : 
     118             :     private:
     119             :         ::osl::Mutex&   m_rMutex;
     120             :     };
     121             : 
     122             :     //--------------------------------------------------------------------------------------------------------------
     123           0 :     void OslMutexFacade::acquire()
     124             :     {
     125           0 :         m_rMutex.acquire();
     126           0 :     }
     127             : 
     128             :     //--------------------------------------------------------------------------------------------------------------
     129           0 :     void OslMutexFacade::release()
     130             :     {
     131           0 :         m_rMutex.release();
     132           0 :     }
     133             : 
     134             :     //==============================================================================================================
     135             :     //= UndoManagerMethodGuard
     136             :     //==============================================================================================================
     137             :     /** guard for public UNO methods of the UndoManager
     138             :     */
     139             :     class UndoManagerMethodGuard : public ::framework::IMutexGuard
     140             :     {
     141             :     public:
     142           0 :         UndoManagerMethodGuard( UndoManager_Impl& i_impl )
     143             :             :m_aGuard( i_impl.rMutex )
     144           0 :             ,m_aMutexFacade( i_impl.rMutex )
     145             :         {
     146             :             // throw if the instance is already disposed
     147           0 :             if ( i_impl.bDisposed )
     148           0 :                 throw DisposedException( ::rtl::OUString(), i_impl.getThis() );
     149           0 :         }
     150           0 :         virtual ~UndoManagerMethodGuard()
     151           0 :         {
     152           0 :         }
     153             : 
     154             :         // IMutexGuard
     155             :         virtual ::framework::IMutex& getGuardedMutex();
     156             : 
     157             :         // IGuard
     158             :         virtual void clear();
     159             :         virtual void reset();
     160             : 
     161             :     private:
     162             :         ::osl::ResettableMutexGuard m_aGuard;
     163             :         OslMutexFacade              m_aMutexFacade;
     164             :     };
     165             : 
     166             :     //--------------------------------------------------------------------------------------------------------------
     167           0 :     ::framework::IMutex& UndoManagerMethodGuard::getGuardedMutex()
     168             :     {
     169           0 :         return m_aMutexFacade;
     170             :     }
     171             : 
     172             :     //--------------------------------------------------------------------------------------------------------------
     173           0 :     void UndoManagerMethodGuard::clear()
     174             :     {
     175           0 :         m_aGuard.clear();
     176           0 :     }
     177             : 
     178             :     //--------------------------------------------------------------------------------------------------------------
     179           0 :     void UndoManagerMethodGuard::reset()
     180             :     {
     181           0 :         m_aGuard.reset();
     182           0 :     }
     183             : 
     184             :     //==================================================================================================================
     185             :     //= UndoManager
     186             :     //==================================================================================================================
     187             :     //------------------------------------------------------------------------------------------------------------------
     188           0 :     UndoManager::UndoManager( ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex )
     189           0 :         :m_pImpl( new UndoManager_Impl( *this, i_parent, i_mutex ) )
     190             :     {
     191           0 :     }
     192             : 
     193             :     //------------------------------------------------------------------------------------------------------------------
     194           0 :     UndoManager::~UndoManager()
     195             :     {
     196           0 :     }
     197             : 
     198             :     //------------------------------------------------------------------------------------------------------------------
     199           0 :     SfxUndoManager& UndoManager::GetSfxUndoManager() const
     200             :     {
     201           0 :         return m_pImpl->aUndoManager;
     202             :     }
     203             : 
     204             :     //------------------------------------------------------------------------------------------------------------------
     205           0 :     void SAL_CALL UndoManager::acquire(  ) throw ()
     206             :     {
     207           0 :         m_pImpl->rParent.acquire();
     208           0 :     }
     209             : 
     210             :     //------------------------------------------------------------------------------------------------------------------
     211           0 :     void SAL_CALL UndoManager::release(  ) throw ()
     212             :     {
     213           0 :         m_pImpl->rParent.release();
     214           0 :     }
     215             : 
     216             :     //------------------------------------------------------------------------------------------------------------------
     217           0 :     void UndoManager::disposing()
     218             :     {
     219             :         {
     220           0 :             ::osl::MutexGuard aGuard( m_pImpl->rMutex );
     221           0 :             m_pImpl->bDisposed = true;
     222             :         }
     223           0 :         m_pImpl->aUndoHelper.disposing();
     224           0 :     }
     225             : 
     226             :     //------------------------------------------------------------------------------------------------------------------
     227           0 :     void SAL_CALL UndoManager::enterUndoContext( const ::rtl::OUString& i_title ) throw (RuntimeException)
     228             :     {
     229           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     230           0 :         m_pImpl->aUndoHelper.enterUndoContext( i_title, aGuard );
     231           0 :     }
     232             : 
     233             :     //------------------------------------------------------------------------------------------------------------------
     234           0 :     void SAL_CALL UndoManager::enterHiddenUndoContext(  ) throw (EmptyUndoStackException, RuntimeException)
     235             :     {
     236           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     237           0 :         m_pImpl->aUndoHelper.enterHiddenUndoContext( aGuard );
     238           0 :     }
     239             : 
     240             :     //------------------------------------------------------------------------------------------------------------------
     241           0 :     void SAL_CALL UndoManager::leaveUndoContext(  ) throw (InvalidStateException, RuntimeException)
     242             :     {
     243           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     244           0 :         m_pImpl->aUndoHelper.leaveUndoContext( aGuard );
     245           0 :     }
     246             : 
     247             :     //------------------------------------------------------------------------------------------------------------------
     248           0 :     void SAL_CALL UndoManager::addUndoAction( const Reference< XUndoAction >& i_action ) throw (IllegalArgumentException, RuntimeException)
     249             :     {
     250           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     251           0 :         m_pImpl->aUndoHelper.addUndoAction( i_action, aGuard );
     252           0 :     }
     253             : 
     254             :     //------------------------------------------------------------------------------------------------------------------
     255           0 :     void SAL_CALL UndoManager::undo(  ) throw (EmptyUndoStackException, UndoContextNotClosedException, UndoFailedException, RuntimeException)
     256             :     {
     257           0 :         SolarMutexGuard aSolarGuard;
     258             :             // (all our UndoActions work directly on VCL code, usually, so ...)
     259           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     260           0 :         m_pImpl->aUndoHelper.undo( aGuard );
     261           0 :     }
     262             : 
     263             :     //------------------------------------------------------------------------------------------------------------------
     264           0 :     void SAL_CALL UndoManager::redo(  ) throw (EmptyUndoStackException, UndoContextNotClosedException, UndoFailedException, RuntimeException)
     265             :     {
     266           0 :         SolarMutexGuard aSolarGuard;
     267             :             // (all our UndoActions work directly on VCL code, usually, so ...)
     268           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     269           0 :         m_pImpl->aUndoHelper.redo( aGuard );
     270           0 :     }
     271             : 
     272             :     //------------------------------------------------------------------------------------------------------------------
     273           0 :     ::sal_Bool SAL_CALL UndoManager::isUndoPossible(  ) throw (RuntimeException)
     274             :     {
     275           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     276           0 :         return m_pImpl->aUndoHelper.isUndoPossible();
     277             :     }
     278             : 
     279             :     //------------------------------------------------------------------------------------------------------------------
     280           0 :     ::sal_Bool SAL_CALL UndoManager::isRedoPossible(  ) throw (RuntimeException)
     281             :     {
     282           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     283           0 :         return m_pImpl->aUndoHelper.isRedoPossible();
     284             :     }
     285             : 
     286             :     //------------------------------------------------------------------------------------------------------------------
     287           0 :     ::rtl::OUString SAL_CALL UndoManager::getCurrentUndoActionTitle(  ) throw (EmptyUndoStackException, RuntimeException)
     288             :     {
     289           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     290           0 :         return m_pImpl->aUndoHelper.getCurrentUndoActionTitle();
     291             :     }
     292             : 
     293             :     //------------------------------------------------------------------------------------------------------------------
     294           0 :     ::rtl::OUString SAL_CALL UndoManager::getCurrentRedoActionTitle(  ) throw (EmptyUndoStackException, RuntimeException)
     295             :     {
     296           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     297           0 :         return m_pImpl->aUndoHelper.getCurrentRedoActionTitle();
     298             :     }
     299             : 
     300             :     //------------------------------------------------------------------------------------------------------------------
     301           0 :     Sequence< ::rtl::OUString > SAL_CALL UndoManager::getAllUndoActionTitles(  ) throw (RuntimeException)
     302             :     {
     303           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     304           0 :         return m_pImpl->aUndoHelper.getAllUndoActionTitles();
     305             :     }
     306             : 
     307             :     //------------------------------------------------------------------------------------------------------------------
     308           0 :     Sequence< ::rtl::OUString > SAL_CALL UndoManager::getAllRedoActionTitles(  ) throw (RuntimeException)
     309             :     {
     310           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     311           0 :         return m_pImpl->aUndoHelper.getAllRedoActionTitles();
     312             :     }
     313             : 
     314             :     //------------------------------------------------------------------------------------------------------------------
     315           0 :     void SAL_CALL UndoManager::clear(  ) throw (UndoContextNotClosedException, RuntimeException)
     316             :     {
     317           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     318           0 :         m_pImpl->aUndoHelper.clear( aGuard );
     319           0 :     }
     320             : 
     321             :     //------------------------------------------------------------------------------------------------------------------
     322           0 :     void SAL_CALL UndoManager::clearRedo(  ) throw (UndoContextNotClosedException, RuntimeException)
     323             :     {
     324           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     325           0 :         m_pImpl->aUndoHelper.clearRedo( aGuard );
     326           0 :     }
     327             : 
     328             :     //------------------------------------------------------------------------------------------------------------------
     329           0 :     void SAL_CALL UndoManager::reset(  ) throw (RuntimeException)
     330             :     {
     331           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     332           0 :         m_pImpl->aUndoHelper.reset( aGuard );
     333           0 :     }
     334             : 
     335             :     //------------------------------------------------------------------------------------------------------------------
     336           0 :     void SAL_CALL UndoManager::addUndoManagerListener( const Reference< XUndoManagerListener >& i_listener ) throw (RuntimeException)
     337             :     {
     338           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     339           0 :         m_pImpl->aUndoHelper.addUndoManagerListener( i_listener );
     340           0 :     }
     341             : 
     342             :     //------------------------------------------------------------------------------------------------------------------
     343           0 :     void SAL_CALL UndoManager::removeUndoManagerListener( const Reference< XUndoManagerListener >& i_listener ) throw (RuntimeException)
     344             :     {
     345           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     346           0 :         m_pImpl->aUndoHelper.removeUndoManagerListener( i_listener );
     347           0 :     }
     348             : 
     349             :     //------------------------------------------------------------------------------------------------------------------
     350           0 :     void SAL_CALL UndoManager::lock(  ) throw (RuntimeException)
     351             :     {
     352           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     353           0 :         m_pImpl->aUndoHelper.lock();
     354           0 :     }
     355             : 
     356             :     //------------------------------------------------------------------------------------------------------------------
     357           0 :     void SAL_CALL UndoManager::unlock(  ) throw (NotLockedException, RuntimeException)
     358             :     {
     359           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     360           0 :         m_pImpl->aUndoHelper.unlock();
     361           0 :     }
     362             : 
     363             :     //------------------------------------------------------------------------------------------------------------------
     364           0 :     ::sal_Bool SAL_CALL UndoManager::isLocked(  ) throw (RuntimeException)
     365             :     {
     366           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     367           0 :         return m_pImpl->aUndoHelper.isLocked();
     368             :     }
     369             : 
     370             :     //------------------------------------------------------------------------------------------------------------------
     371           0 :     Reference< XInterface > SAL_CALL UndoManager::getParent(  ) throw (RuntimeException)
     372             :     {
     373           0 :         UndoManagerMethodGuard aGuard( *m_pImpl );
     374           0 :         return *&m_pImpl->rParent;
     375             :     }
     376             : 
     377             :     //------------------------------------------------------------------------------------------------------------------
     378           0 :     void SAL_CALL UndoManager::setParent( const Reference< XInterface >& i_parent ) throw (NoSupportException, RuntimeException)
     379             :     {
     380             :         (void)i_parent;
     381           0 :         throw NoSupportException( ::rtl::OUString(), m_pImpl->getThis() );
     382             :     }
     383             : 
     384             : //......................................................................................................................
     385             : } // namespace dbaui
     386             : //......................................................................................................................
     387             : 
     388             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10