LCOV - code coverage report
Current view: top level - dbaccess/source/ui/misc - dbaundomanager.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 28 131 21.4 %
Date: 2015-06-13 12:38:46 Functions: 12 44 27.3 %
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           3 :         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           3 :             ,aUndoHelper( *this )
      64             :         {
      65           3 :         }
      66             : 
      67           6 :         virtual ~UndoManager_Impl()
      68           3 :         {
      69           6 :         }
      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           6 :     ::svl::IUndoManager& UndoManager_Impl::getImplUndoManager()
      84             :     {
      85           6 :         return aUndoManager;
      86             :     }
      87             : 
      88           9 :     Reference< XUndoManager > UndoManager_Impl::getThis()
      89             :     {
      90           9 :         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           3 :     UndoManager::UndoManager( ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex )
     160           3 :         :m_xImpl( new UndoManager_Impl( *this, i_parent, i_mutex ) )
     161             :     {
     162           3 :     }
     163             : 
     164           6 :     UndoManager::~UndoManager()
     165             :     {
     166           6 :     }
     167             : 
     168           3 :     SfxUndoManager& UndoManager::GetSfxUndoManager() const
     169             :     {
     170           3 :         return m_xImpl->aUndoManager;
     171             :     }
     172             : 
     173          18 :     void SAL_CALL UndoManager::acquire(  ) throw ()
     174             :     {
     175          18 :         m_xImpl->rParent.acquire();
     176          18 :     }
     177             : 
     178          18 :     void SAL_CALL UndoManager::release(  ) throw ()
     179             :     {
     180          18 :         m_xImpl->rParent.release();
     181          18 :     }
     182             : 
     183           3 :     void UndoManager::disposing()
     184             :     {
     185             :         {
     186           3 :             ::osl::MutexGuard aGuard( m_xImpl->rMutex );
     187           3 :             m_xImpl->bDisposed = true;
     188             :         }
     189           3 :         m_xImpl->aUndoHelper.disposing();
     190           3 :     }
     191             : 
     192           0 :     void SAL_CALL UndoManager::enterUndoContext( const OUString& i_title ) throw (RuntimeException, std::exception)
     193             :     {
     194           0 :         UndoManagerMethodGuard aGuard( *m_xImpl );
     195           0 :         m_xImpl->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_xImpl );
     201           0 :         m_xImpl->aUndoHelper.enterHiddenUndoContext( aGuard );
     202           0 :     }
     203             : 
     204           0 :     void SAL_CALL UndoManager::leaveUndoContext(  ) throw (InvalidStateException, RuntimeException, std::exception)
     205             :     {
     206           0 :         UndoManagerMethodGuard aGuard( *m_xImpl );
     207           0 :         m_xImpl->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_xImpl );
     213           0 :         m_xImpl->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_xImpl );
     221           0 :         m_xImpl->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_xImpl );
     229           0 :         m_xImpl->aUndoHelper.redo( aGuard );
     230           0 :     }
     231             : 
     232           0 :     sal_Bool SAL_CALL UndoManager::isUndoPossible(  ) throw (RuntimeException, std::exception)
     233             :     {
     234           0 :         UndoManagerMethodGuard aGuard( *m_xImpl );
     235           0 :         return m_xImpl->aUndoHelper.isUndoPossible();
     236             :     }
     237             : 
     238           0 :     sal_Bool SAL_CALL UndoManager::isRedoPossible(  ) throw (RuntimeException, std::exception)
     239             :     {
     240           0 :         UndoManagerMethodGuard aGuard( *m_xImpl );
     241           0 :         return m_xImpl->aUndoHelper.isRedoPossible();
     242             :     }
     243             : 
     244           0 :     OUString SAL_CALL UndoManager::getCurrentUndoActionTitle(  ) throw (EmptyUndoStackException, RuntimeException, std::exception)
     245             :     {
     246           0 :         UndoManagerMethodGuard aGuard( *m_xImpl );
     247           0 :         return m_xImpl->aUndoHelper.getCurrentUndoActionTitle();
     248             :     }
     249             : 
     250           0 :     OUString SAL_CALL UndoManager::getCurrentRedoActionTitle(  ) throw (EmptyUndoStackException, RuntimeException, std::exception)
     251             :     {
     252           0 :         UndoManagerMethodGuard aGuard( *m_xImpl );
     253           0 :         return m_xImpl->aUndoHelper.getCurrentRedoActionTitle();
     254             :     }
     255             : 
     256           0 :     Sequence< OUString > SAL_CALL UndoManager::getAllUndoActionTitles(  ) throw (RuntimeException, std::exception)
     257             :     {
     258           0 :         UndoManagerMethodGuard aGuard( *m_xImpl );
     259           0 :         return m_xImpl->aUndoHelper.getAllUndoActionTitles();
     260             :     }
     261             : 
     262           0 :     Sequence< OUString > SAL_CALL UndoManager::getAllRedoActionTitles(  ) throw (RuntimeException, std::exception)
     263             :     {
     264           0 :         UndoManagerMethodGuard aGuard( *m_xImpl );
     265           0 :         return m_xImpl->aUndoHelper.getAllRedoActionTitles();
     266             :     }
     267             : 
     268           0 :     void SAL_CALL UndoManager::clear(  ) throw (UndoContextNotClosedException, RuntimeException, std::exception)
     269             :     {
     270           0 :         UndoManagerMethodGuard aGuard( *m_xImpl );
     271           0 :         m_xImpl->aUndoHelper.clear( aGuard );
     272           0 :     }
     273             : 
     274           0 :     void SAL_CALL UndoManager::clearRedo(  ) throw (UndoContextNotClosedException, RuntimeException, std::exception)
     275             :     {
     276           0 :         UndoManagerMethodGuard aGuard( *m_xImpl );
     277           0 :         m_xImpl->aUndoHelper.clearRedo( aGuard );
     278           0 :     }
     279             : 
     280           0 :     void SAL_CALL UndoManager::reset(  ) throw (RuntimeException, std::exception)
     281             :     {
     282           0 :         UndoManagerMethodGuard aGuard( *m_xImpl );
     283           0 :         m_xImpl->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_xImpl );
     289           0 :         m_xImpl->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_xImpl );
     295           0 :         m_xImpl->aUndoHelper.removeUndoManagerListener( i_listener );
     296           0 :     }
     297             : 
     298           0 :     void SAL_CALL UndoManager::lock(  ) throw (RuntimeException, std::exception)
     299             :     {
     300           0 :         UndoManagerMethodGuard aGuard( *m_xImpl );
     301           0 :         m_xImpl->aUndoHelper.lock();
     302           0 :     }
     303             : 
     304           0 :     void SAL_CALL UndoManager::unlock(  ) throw (NotLockedException, RuntimeException, std::exception)
     305             :     {
     306           0 :         UndoManagerMethodGuard aGuard( *m_xImpl );
     307           0 :         m_xImpl->aUndoHelper.unlock();
     308           0 :     }
     309             : 
     310           0 :     sal_Bool SAL_CALL UndoManager::isLocked(  ) throw (RuntimeException, std::exception)
     311             :     {
     312           0 :         UndoManagerMethodGuard aGuard( *m_xImpl );
     313           0 :         return m_xImpl->aUndoHelper.isLocked();
     314             :     }
     315             : 
     316           0 :     Reference< XInterface > SAL_CALL UndoManager::getParent(  ) throw (RuntimeException, std::exception)
     317             :     {
     318           0 :         UndoManagerMethodGuard aGuard( *m_xImpl );
     319           0 :         return *&m_xImpl->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_xImpl->getThis() );
     326             :     }
     327             : 
     328             : } // namespace dbaui
     329             : 
     330             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11