LCOV - code coverage report
Current view: top level - sfx2/source/inc - docundomanager.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 23 23 100.0 %
Date: 2014-11-03 Functions: 9 9 100.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             : #ifndef INCLUDED_SFX2_SOURCE_INC_DOCUNDOMANAGER_HXX
      21             : #define INCLUDED_SFX2_SOURCE_INC_DOCUNDOMANAGER_HXX
      22             : 
      23             : #include <sfx2/sfxbasemodel.hxx>
      24             : 
      25             : #include <com/sun/star/document/XUndoManager.hpp>
      26             : 
      27             : #include <cppuhelper/implbase1.hxx>
      28             : 
      29             : #include <boost/scoped_ptr.hpp>
      30             : #include <boost/noncopyable.hpp>
      31             : 
      32             : /** base class for sub components of an SfxBaseModel, which share their ref count and lifetime with the SfxBaseModel
      33             : */
      34             : class SfxModelSubComponent
      35             : {
      36             : public:
      37             :     /** checks whether the instance is alive, i.e. properly initialized, and not yet disposed
      38             :     */
      39        3162 :     void    MethodEntryCheck()
      40             :     {
      41        3162 :         m_rModel.MethodEntryCheck( true );
      42        3162 :     }
      43             : 
      44             :     // called when the SfxBaseModel which the component is superordinate of is being disposed
      45             :     virtual void disposing();
      46             : 
      47             : protected:
      48         806 :     SfxModelSubComponent( SfxBaseModel& i_model )
      49         806 :         :m_rModel( i_model )
      50             :     {
      51         806 :     }
      52             :     virtual ~SfxModelSubComponent();
      53             : 
      54      276772 :     void acquireModel()  { m_rModel.acquire(); }
      55      276772 :     void releaseModel()  { m_rModel.release(); }
      56             : 
      57             :     bool isDisposed() const {   return m_rModel.IsDisposed();   }
      58             : 
      59             : protected:
      60             :     const SfxBaseModel& getBaseModel() const { return m_rModel; }
      61        1968 :           SfxBaseModel& getBaseModel()       { return m_rModel; }
      62             : 
      63             :           ::osl::Mutex&  getMutex()          { return m_rModel.getMutex(); }
      64             : 
      65             : private:
      66             :     SfxBaseModel&   m_rModel;
      67             : };
      68             : 
      69             : class SfxModelGuard
      70             : {
      71             : public:
      72             :     enum AllowedModelState
      73             :     {
      74             :         // not yet initialized
      75             :         E_INITIALIZING,
      76             :         // fully alive, i.e. initialized, and not yet disposed
      77             :         E_FULLY_ALIVE
      78             :     };
      79             : 
      80     1767101 :     SfxModelGuard( SfxBaseModel& i_rModel, const AllowedModelState i_eState = E_FULLY_ALIVE )
      81     1767905 :         : m_aGuard()
      82             :     {
      83     1767101 :         i_rModel.MethodEntryCheck( i_eState != E_INITIALIZING );
      84     1766297 :     }
      85        3162 :     SfxModelGuard( SfxModelSubComponent& i_rSubComponent )
      86        3162 :         :m_aGuard()
      87             :     {
      88        3162 :         i_rSubComponent.MethodEntryCheck();
      89        3162 :     }
      90     1769459 :     ~SfxModelGuard()
      91     1769459 :     {
      92     1769459 :     }
      93             : 
      94             :     void reset()
      95             :     {
      96             :         m_aGuard.reset();
      97             :     }
      98             : 
      99        1218 :     void clear()
     100             :     {
     101        1218 :         m_aGuard.clear();
     102        1218 :     }
     103             : 
     104             : private:
     105             :     SolarMutexResettableGuard  m_aGuard;
     106             : };
     107             : 
     108             : namespace sfx2
     109             : {
     110             :     //= DocumentUndoManager
     111             : 
     112             :     typedef ::cppu::WeakImplHelper1 <css::document::XUndoManager> DocumentUndoManager_Base;
     113             :     struct DocumentUndoManager_Impl;
     114             :     class DocumentUndoManager   :public DocumentUndoManager_Base
     115             :                                 ,public SfxModelSubComponent
     116             :                                 ,public ::boost::noncopyable
     117             :     {
     118             :         friend struct DocumentUndoManager_Impl;
     119             : 
     120             :     public:
     121             :         DocumentUndoManager( SfxBaseModel& i_document );
     122             :         virtual ~DocumentUndoManager();
     123             : 
     124             :         // SfxModelSubComponent overridables
     125             :         virtual void    disposing() SAL_OVERRIDE;
     126             : 
     127             :         // non-UNO API for our owner
     128             :         /** determines whether we have an open Undo context. No mutex locking within this method, no disposal check - this
     129             :             is the responsibility of the owner.
     130             :         */
     131             :         bool    isInContext() const;
     132             : 
     133             :         // XInterface
     134             :         virtual void SAL_CALL acquire(  ) throw () SAL_OVERRIDE;
     135             :         virtual void SAL_CALL release(  ) throw () SAL_OVERRIDE;
     136             : 
     137             :         // XUndoManager
     138             :         virtual void SAL_CALL enterUndoContext( const OUString& i_title ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     139             :         virtual void SAL_CALL enterHiddenUndoContext(  ) throw (::com::sun::star::document::EmptyUndoStackException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     140             :         virtual void SAL_CALL leaveUndoContext(  ) throw (::com::sun::star::util::InvalidStateException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     141             :         virtual void SAL_CALL addUndoAction( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XUndoAction >& i_action ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     142             :         virtual void SAL_CALL undo(  ) throw (::com::sun::star::document::EmptyUndoStackException, ::com::sun::star::document::UndoContextNotClosedException, ::com::sun::star::document::UndoFailedException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     143             :         virtual void SAL_CALL redo(  ) throw (::com::sun::star::document::EmptyUndoStackException, ::com::sun::star::document::UndoContextNotClosedException, ::com::sun::star::document::UndoFailedException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     144             :         virtual sal_Bool SAL_CALL isUndoPossible(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     145             :         virtual sal_Bool SAL_CALL isRedoPossible(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     146             :         virtual OUString SAL_CALL getCurrentUndoActionTitle(  ) throw (::com::sun::star::document::EmptyUndoStackException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     147             :         virtual OUString SAL_CALL getCurrentRedoActionTitle(  ) throw (::com::sun::star::document::EmptyUndoStackException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     148             :         virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getAllUndoActionTitles(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     149             :         virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getAllRedoActionTitles(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     150             :         virtual void SAL_CALL clear(  ) throw (::com::sun::star::document::UndoContextNotClosedException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     151             :         virtual void SAL_CALL clearRedo(  ) throw (::com::sun::star::document::UndoContextNotClosedException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     152             :         virtual void SAL_CALL reset(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     153             :         virtual void SAL_CALL addUndoManagerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XUndoManagerListener >& i_listener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     154             :         virtual void SAL_CALL removeUndoManagerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XUndoManagerListener >& i_listener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     155             : 
     156             :         // XLockable, base of XUndoManager
     157             :         virtual void SAL_CALL lock(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     158             :         virtual void SAL_CALL unlock(  ) throw (::com::sun::star::util::NotLockedException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     159             :         virtual sal_Bool SAL_CALL isLocked(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     160             : 
     161             :         // XChild, base of XUndoManager
     162             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getParent(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     163             :         virtual void SAL_CALL setParent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& Parent ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     164             : 
     165             :     private:
     166             :         ::boost::scoped_ptr< DocumentUndoManager_Impl > m_pImpl;
     167             :     };
     168             : 
     169             : 
     170             : } // namespace sfx2
     171             : 
     172             : 
     173             : #endif // INCLUDED_SFX2_SOURCE_INC_DOCUNDOMANAGER_HXX
     174             : 
     175             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10