Update ooo320-m1
[ooovba.git] / binfilter / inc / bf_svtools / undo.hxx
blobd1ccddad7ad4a0ffb25292f1e9ea22c31b1ce20f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: undo.hxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _UNDO_HXX
31 #define _UNDO_HXX
33 #ifndef INCLUDED_SVTDLLAPI_H
34 #include "bf_svtools/svtdllapi.h"
35 #endif
37 #ifndef _RTTI_HXX
38 #include <tools/rtti.hxx>
39 #endif
41 #ifndef _STRING_HXX
42 #include <tools/string.hxx>
43 #endif
45 #ifndef _SVARRAY_HXX
46 #include <bf_svtools/svarray.hxx>
47 #endif
49 namespace binfilter
52 //====================================================================
54 class SfxRepeatTarget
56 public:
57 TYPEINFO();
58 virtual ~SfxRepeatTarget() = 0;
61 //====================================================================
63 class SfxUndoAction
65 BOOL bLinked;
66 public:
67 TYPEINFO();
68 SfxUndoAction();
69 virtual ~SfxUndoAction();
71 virtual BOOL IsLinked();
72 virtual void SetLinked( BOOL bIsLinked = TRUE );
73 virtual void Undo();
74 virtual void Redo();
75 virtual void Repeat(SfxRepeatTarget&);
76 virtual BOOL CanRepeat(SfxRepeatTarget&) const;
78 virtual BOOL Merge( SfxUndoAction *pNextAction );
80 virtual UniString GetComment() const;
81 virtual UniString GetRepeatComment(SfxRepeatTarget&) const;
82 virtual USHORT GetId() const;
84 private:
85 SfxUndoAction& operator=( const SfxUndoAction& ); // n.i.!!
88 //========================================================================
90 SV_DECL_PTRARR( SfxUndoActions, SfxUndoAction*, 20, 8 )
92 //====================================================================
94 /** do not make use of this implementation details, unless you
95 really really have to! */
96 struct SfxUndoArray
98 SfxUndoActions aUndoActions;
99 USHORT nMaxUndoActions;
100 USHORT nCurUndoAction;
101 SfxUndoArray *pFatherUndoArray;
102 SfxUndoArray(USHORT nMax=0):
103 nMaxUndoActions(nMax), nCurUndoAction(0),
104 pFatherUndoArray(0) {}
105 ~SfxUndoArray();
108 //=========================================================================
110 /** do not make use of this implementation details, unless you
111 really really have to! */
112 class SfxListUndoAction : public SfxUndoAction, public SfxUndoArray
114 /* [Beschreibung]
116 UndoAction zur Klammerung mehrerer Undos in einer UndoAction.
117 Diese Actions werden vom SfxUndoManager verwendet. Dort
118 wird mit < SfxUndoManager::EnterListAction > eine Klammerebene
119 geoeffnet und mit <SfxUndoManager::LeaveListAction > wieder
120 geschlossen. Redo und Undo auf SfxListUndoActions wirken
121 Elementweise.
125 public:
126 TYPEINFO();
128 SfxListUndoAction( const UniString &rComment,
129 const UniString rRepeatComment, USHORT Id, SfxUndoArray *pFather);
130 virtual void Undo();
131 virtual void Redo();
132 virtual void Repeat(SfxRepeatTarget&);
133 virtual BOOL CanRepeat(SfxRepeatTarget&) const;
135 virtual BOOL Merge( SfxUndoAction *pNextAction );
137 virtual UniString GetComment() const;
138 virtual UniString GetRepeatComment(SfxRepeatTarget&) const;
139 virtual USHORT GetId() const;
141 void SetComment( const UniString& rComment );
143 private:
145 USHORT nId;
146 UniString aComment, aRepeatComment;
150 //=========================================================================
152 class SfxUndoManager
154 friend class SfxLinkUndoAction;
156 SfxUndoArray *pUndoArray;
157 SfxUndoArray *pActUndoArray;
158 SfxUndoArray *pFatherUndoArray;
160 public:
161 SfxUndoManager( USHORT nMaxUndoActionCount = 20 );
162 virtual ~SfxUndoManager();
164 virtual void SetMaxUndoActionCount( USHORT nMaxUndoActionCount );
165 virtual USHORT GetMaxUndoActionCount() const;
166 virtual void Clear();
168 virtual void AddUndoAction( SfxUndoAction *pAction, BOOL bTryMerg=FALSE );
170 virtual USHORT GetUndoActionCount() const;
171 virtual USHORT GetUndoActionId(USHORT nNo=0) const;
172 virtual UniString GetUndoActionComment( USHORT nNo=0 ) const;
174 virtual BOOL Undo( USHORT nCount=1 );
175 virtual void Undo( SfxUndoAction &rAction );
177 virtual USHORT GetRedoActionCount() const;
178 virtual USHORT GetRedoActionId(USHORT nNo=0) const;
179 virtual UniString GetRedoActionComment( USHORT nNo=0 ) const;
181 virtual BOOL Redo( USHORT nCount=1 );
182 virtual void Redo( SfxUndoAction &rAction );
183 virtual void ClearRedo();
185 virtual USHORT GetRepeatActionCount() const;
186 virtual UniString GetRepeatActionComment( SfxRepeatTarget &rTarget, USHORT nNo = 0) const;
187 virtual BOOL Repeat( SfxRepeatTarget &rTarget, USHORT nFrom=0, USHORT nCount=1 );
188 virtual void Repeat( SfxRepeatTarget &rTarget, SfxUndoAction &rAction );
189 virtual BOOL CanRepeat( SfxRepeatTarget &rTarget, USHORT nNo = 0 ) const;
190 virtual BOOL CanRepeat( SfxRepeatTarget &rTarget, SfxUndoAction &rAction ) const;
192 virtual void EnterListAction(const UniString &rComment, const UniString& rRepeatComment, USHORT nId=0);
193 virtual void LeaveListAction();
196 //=========================================================================
198 class SfxLinkUndoAction : public SfxUndoAction
200 /* [Beschreibung]
202 Die SfxLinkUndoAction dient zur Verbindung zweier SfxUndoManager. Die
203 im ersten SfxUndoManager eingefuegten SfxUndoAction leiten ihr Undo und Redo
204 an den zweiten weiter, so dass ein Undo und Redo am ersten
205 SfxUndoManager wie eine am zweiten wirkt.
207 Die SfxLinkUndoAction ist nach dem Einfuegen der SfxUndoAction am
208 zweiten SfxUndoManager einzufuegen. Waehrend der zweite SfxUndoManager
209 vom ersten ferngesteuert wird, duerfen an ihm weder Actions eingefuegt werden,
210 noch darf Undo/Redo aufgerufen werden.
215 public:
216 TYPEINFO();
217 ~SfxLinkUndoAction();
219 virtual void Undo();
220 virtual void Redo();
221 virtual BOOL CanRepeat(SfxRepeatTarget& r) const;
223 virtual void Repeat(SfxRepeatTarget&r);
225 virtual UniString GetComment() const;
226 virtual UniString GetRepeatComment(SfxRepeatTarget&r) const;
227 virtual USHORT GetId() const;
229 SfxUndoAction* GetAction() const { return pAction; }
231 protected:
232 SfxUndoManager *pUndoManager;
233 SfxUndoAction *pAction;
239 #endif