LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/framework - undomanagerhelper.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 4 75.0 %
Date: 2012-08-25 Functions: 3 4 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       4                 :            :  *
       5                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       6                 :            :  *
       7                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       8                 :            :  *
       9                 :            :  * This file is part of OpenOffice.org.
      10                 :            :  *
      11                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      12                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      13                 :            :  * only, as published by the Free Software Foundation.
      14                 :            :  *
      15                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      16                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      17                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      18                 :            :  * GNU Lesser General Public License version 3 for more details
      19                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      20                 :            :  *
      21                 :            :  * You should have received a copy of the GNU Lesser General Public License
      22                 :            :  * version 3 along with OpenOffice.org.  If not, see
      23                 :            :  * <http://www.openoffice.org/license.html>
      24                 :            :  * for a copy of the LGPLv3 License.
      25                 :            :  *
      26                 :            :  ************************************************************************/
      27                 :            : 
      28                 :            : #ifndef FRAMEWORK_UNDOMANAGERHELPER_HXX
      29                 :            : #define FRAMEWORK_UNDOMANAGERHELPER_HXX
      30                 :            : 
      31                 :            : #include "framework/fwedllapi.h"
      32                 :            : #include "framework/iguard.hxx"
      33                 :            : #include "framework/imutex.hxx"
      34                 :            : 
      35                 :            : #include <com/sun/star/document/XUndoManager.hpp>
      36                 :            : #include <com/sun/star/util/XModifyListener.hpp>
      37                 :            : 
      38                 :            : #include <boost/scoped_ptr.hpp>
      39                 :            : 
      40                 :            : namespace svl
      41                 :            : {
      42                 :            :     class IUndoManager;
      43                 :            : }
      44                 :            : 
      45                 :            : //......................................................................................................................
      46                 :            : namespace framework
      47                 :            : {
      48                 :            : //......................................................................................................................
      49                 :            : 
      50                 :            :     //==================================================================================================================
      51                 :            :     //= IMutexGuard
      52                 :            :     //==================================================================================================================
      53                 :       3602 :     class SAL_NO_VTABLE IMutexGuard : public IGuard
      54                 :            :     {
      55                 :            :     public:
      56                 :            :         /** returns the mutex guarded by the instance.
      57                 :            : 
      58                 :            :             Even if the guard currently has not a lock on the mutex, this method must succeed.
      59                 :            :         */
      60                 :            :         virtual IMutex& getGuardedMutex() = 0;
      61                 :            : 
      62                 :            :     protected:
      63                 :       3602 :         ~IMutexGuard() {}
      64                 :            :     };
      65                 :            : 
      66                 :            :     //==================================================================================================================
      67                 :            :     //= IUndoManagerImplementation
      68                 :            :     //==================================================================================================================
      69                 :         55 :     class SAL_NO_VTABLE IUndoManagerImplementation
      70                 :            :     {
      71                 :            :     public:
      72                 :            :         /** returns the IUndoManager interface to the actual Undo stack
      73                 :            : 
      74                 :            :             @throws com::sun::star::lang::DisposedException
      75                 :            :                 when the instance is already disposed, and no IUndoManager can be provided
      76                 :            : 
      77                 :            :             @throws com::sun::star::lang::NotInitializedException
      78                 :            :                 when the instance is not initialized, yet, and no IUndoManager can be provided
      79                 :            :         */
      80                 :            :         virtual ::svl::IUndoManager&    getImplUndoManager() = 0;
      81                 :            : 
      82                 :            :         /** provides access to an UNO interface for the XUndoManager implementation. Used when throwing exceptions.
      83                 :            :         */
      84                 :            :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::document::XUndoManager >
      85                 :            :                                         getThis() = 0;
      86                 :            : 
      87                 :            :     protected:
      88                 :          0 :         ~IUndoManagerImplementation() {}
      89                 :            :     };
      90                 :            : 
      91                 :            :     //==================================================================================================================
      92                 :            :     //= UndoManagerHelper
      93                 :            :     //==================================================================================================================
      94                 :            :     class UndoManagerHelper_Impl;
      95                 :            :     /** helper class for implementing an XUndoManager
      96                 :            : 
      97                 :            :         Several of the methods of the class take an IMutexGuard instance. It is assumed that this guard has a lock on
      98                 :            :         its mutext at the moment the method is entered. The lock will be released before any notifications to the
      99                 :            :         registered XUndoManagerListeners happen.
     100                 :            : 
     101                 :            :         The following locking strategy is used for this mutex:
     102                 :            :         <ul><li>Any notifications to the registered XUndoManagerListeners are after the guard has been cleared. i.e.
     103                 :            :                 without the mutex being locked.</p>
     104                 :            :             <li>Any calls into the <code>IUndoManager</code> implementation is made without the mutex being locked.
     105                 :            :                 Note that this implies that the <code>IUndoManager</code> implementation must be thread-safe in itself
     106                 :            :                 (which is true for the default implementation, SfxUndoManager).</li>
     107                 :            :             <li>An exception to the previous item are the <member>IUndoManager::Undo</member> and
     108                 :            :                 <member>IUndoManager::Redo</member> methods: They're called with the given external mutex being
     109                 :            :                 locked.</li>
     110                 :            :         </ul>
     111                 :            : 
     112                 :            :         The reason for the exception for IUndoManager::Undo and IUndoManager::Redo is that those are expected to
     113                 :            :         modify the actual document which the UndoManager works for. And as long as our documents are not thread-safe,
     114                 :            :         and as long as we do not re-fit <strong>all</strong> existing SfxUndoImplementations to <em>not</em> expect
     115                 :            :         the dreaded SolarMutex being locked when they're called, the above behavior is a compromise between "how it should
     116                 :            :         be" and "how it can realistically be".
     117                 :            :     */
     118                 :            :     class FWE_DLLPUBLIC UndoManagerHelper
     119                 :            :     {
     120                 :            :     public:
     121                 :            :         UndoManagerHelper( IUndoManagerImplementation& i_undoManagerImpl );
     122                 :            :         ~UndoManagerHelper();
     123                 :            : 
     124                 :            :         // life time control
     125                 :            :         void disposing();
     126                 :            : 
     127                 :            :         // XUndoManager equivalents
     128                 :            :         void            enterUndoContext( const ::rtl::OUString& i_title, IMutexGuard& i_instanceLock );
     129                 :            :         void            enterHiddenUndoContext( IMutexGuard& i_instanceLock );
     130                 :            :         void            leaveUndoContext( IMutexGuard& i_instanceLock );
     131                 :            :         void            addUndoAction( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XUndoAction >& i_action, IMutexGuard& i_instanceLock );
     132                 :            :         void            undo( IMutexGuard& i_instanceLock );
     133                 :            :         void            redo( IMutexGuard& i_instanceLock );
     134                 :            :         ::sal_Bool      isUndoPossible() const;
     135                 :            :         ::sal_Bool      isRedoPossible() const;
     136                 :            :         ::rtl::OUString getCurrentUndoActionTitle() const;
     137                 :            :         ::rtl::OUString getCurrentRedoActionTitle() const;
     138                 :            :         ::com::sun::star::uno::Sequence< ::rtl::OUString >
     139                 :            :                         getAllUndoActionTitles() const;
     140                 :            :         ::com::sun::star::uno::Sequence< ::rtl::OUString >
     141                 :            :                         getAllRedoActionTitles() const;
     142                 :            :         void            clear( IMutexGuard& i_instanceLock );
     143                 :            :         void            clearRedo( IMutexGuard& i_instanceLock );
     144                 :            :         void            reset( IMutexGuard& i_instanceLock );
     145                 :            :         void            addUndoManagerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XUndoManagerListener >& i_listener );
     146                 :            :         void            removeUndoManagerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XUndoManagerListener >& i_listener );
     147                 :            : 
     148                 :            :         // XLockable, base of XUndoManager, equivalents
     149                 :            :         void            lock();
     150                 :            :         void            unlock();
     151                 :            :         ::sal_Bool      isLocked();
     152                 :            : 
     153                 :            :         // XModifyBroadcaster equivalents
     154                 :            :         void            addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& i_listener );
     155                 :            :         void            removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& i_listener );
     156                 :            : 
     157                 :            :     private:
     158                 :            :         ::boost::scoped_ptr< UndoManagerHelper_Impl >   m_pImpl;
     159                 :            :     };
     160                 :            : 
     161                 :            : //......................................................................................................................
     162                 :            : } // namespace framework
     163                 :            : //......................................................................................................................
     164                 :            : 
     165                 :            : #endif // FRAMEWORK_UNDOMANAGERHELPER_HXX
     166                 :            : 
     167                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10