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

Generated by: LCOV version 1.10