1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SFX2_SOURCE_INC_DOCUNDOMANAGER_HXX
21 #define INCLUDED_SFX2_SOURCE_INC_DOCUNDOMANAGER_HXX
23 #include <sfx2/sfxbasemodel.hxx>
25 #include <com/sun/star/document/XUndoManager.hpp>
27 #include <cppuhelper/implbase1.hxx>
29 #include <boost/scoped_ptr.hpp>
30 #include <boost/noncopyable.hpp>
32 /** base class for sub components of an SfxBaseModel, which share their ref count and lifetime with the SfxBaseModel
34 class SfxModelSubComponent
37 /** checks whether the instance is alive, i.e. properly initialized, and not yet disposed
39 void MethodEntryCheck()
41 m_rModel
.MethodEntryCheck( true );
44 // called when the SfxBaseModel which the component is superordinate of is being disposed
45 virtual void disposing();
48 SfxModelSubComponent( SfxBaseModel
& i_model
)
52 virtual ~SfxModelSubComponent();
54 void acquireModel() { m_rModel
.acquire(); }
55 void releaseModel() { m_rModel
.release(); }
57 bool isDisposed() const { return m_rModel
.IsDisposed(); }
60 const SfxBaseModel
& getBaseModel() const { return m_rModel
; }
61 SfxBaseModel
& getBaseModel() { return m_rModel
; }
63 ::osl::Mutex
& getMutex() { return m_rModel
.getMutex(); }
66 SfxBaseModel
& m_rModel
;
72 enum AllowedModelState
74 // not yet initialized
76 // fully alive, i.e. initialized, and not yet disposed
80 SfxModelGuard( SfxBaseModel
& i_rModel
, const AllowedModelState i_eState
= E_FULLY_ALIVE
)
83 i_rModel
.MethodEntryCheck( i_eState
!= E_INITIALIZING
);
85 SfxModelGuard( SfxModelSubComponent
& i_rSubComponent
)
88 i_rSubComponent
.MethodEntryCheck();
105 SolarMutexResettableGuard m_aGuard
;
110 //= DocumentUndoManager
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
118 friend struct DocumentUndoManager_Impl
;
121 DocumentUndoManager( SfxBaseModel
& i_document
);
122 virtual ~DocumentUndoManager();
124 // SfxModelSubComponent overridables
125 virtual void disposing() SAL_OVERRIDE
;
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.
131 bool isInContext() const;
134 virtual void SAL_CALL
acquire( ) throw () SAL_OVERRIDE
;
135 virtual void SAL_CALL
release( ) throw () SAL_OVERRIDE
;
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
;
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
;
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
;
166 ::boost::scoped_ptr
< DocumentUndoManager_Impl
> m_pImpl
;
173 #endif // INCLUDED_SFX2_SOURCE_INC_DOCUNDOMANAGER_HXX
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */