sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#ifndef UNDOSYSTEMIMPL_H_
|
sl@0
|
20 |
#define UNDOSYSTEMIMPL_H_
|
sl@0
|
21 |
|
sl@0
|
22 |
#include <e32base.h>
|
sl@0
|
23 |
#include "UndoSystem.h"
|
sl@0
|
24 |
|
sl@0
|
25 |
namespace UndoSystem
|
sl@0
|
26 |
{
|
sl@0
|
27 |
class CCommand;
|
sl@0
|
28 |
class CSingleCommand;
|
sl@0
|
29 |
class CBatchCommand;
|
sl@0
|
30 |
|
sl@0
|
31 |
/**
|
sl@0
|
32 |
* Undo panic codes
|
sl@0
|
33 |
*
|
sl@0
|
34 |
* @internalComponent
|
sl@0
|
35 |
*/
|
sl@0
|
36 |
enum TPanicCode
|
sl@0
|
37 |
{
|
sl@0
|
38 |
/**
|
sl@0
|
39 |
* CSingleCommand::PrepareToAddInverseToLast() overridden to return ETrue, but
|
sl@0
|
40 |
* CSingleCommand::AddInverseToLast() not overridden.
|
sl@0
|
41 |
*/
|
sl@0
|
42 |
KAddToLastOnlyHalfImplemented = 1,
|
sl@0
|
43 |
/**
|
sl@0
|
44 |
* CCommandStack or CSingleCommandStack::Pop() called on an empty stack
|
sl@0
|
45 |
*/
|
sl@0
|
46 |
KCommandStackUnderflow,
|
sl@0
|
47 |
/**
|
sl@0
|
48 |
* CCommandStack or CSingleCommandStack::Push() called without adequate
|
sl@0
|
49 |
* space being reserved via PrepareToPushL()
|
sl@0
|
50 |
*/
|
sl@0
|
51 |
KCommandStackPushNotPrepared,
|
sl@0
|
52 |
/**
|
sl@0
|
53 |
* No shared undo system passed when expected
|
sl@0
|
54 |
*/
|
sl@0
|
55 |
KEditorUndoNoCommandManager
|
sl@0
|
56 |
};
|
sl@0
|
57 |
|
sl@0
|
58 |
/**
|
sl@0
|
59 |
* Panic from Undo DLL
|
sl@0
|
60 |
*
|
sl@0
|
61 |
* @internalComponent
|
sl@0
|
62 |
*/
|
sl@0
|
63 |
void Panic(TPanicCode aCode);
|
sl@0
|
64 |
|
sl@0
|
65 |
/**
|
sl@0
|
66 |
* Stack of commands. A bookmark is maintianed so that we can tell if the stack
|
sl@0
|
67 |
* is in the same state it was at a previous time.
|
sl@0
|
68 |
*
|
sl@0
|
69 |
* @internalComponent
|
sl@0
|
70 |
* @since App-frameworks6.1
|
sl@0
|
71 |
*/
|
sl@0
|
72 |
NONSHARABLE_CLASS(CCommandStack) : public CBase
|
sl@0
|
73 |
{
|
sl@0
|
74 |
public:
|
sl@0
|
75 |
static CCommandStack* NewL();
|
sl@0
|
76 |
~CCommandStack();
|
sl@0
|
77 |
CCommandStack();
|
sl@0
|
78 |
void ConstructL();
|
sl@0
|
79 |
|
sl@0
|
80 |
CCommand* Top() const;
|
sl@0
|
81 |
CCommand* Pop();
|
sl@0
|
82 |
/**
|
sl@0
|
83 |
* Allows aNumberOfItems Push()s to be done before the next
|
sl@0
|
84 |
* call to another non-const member function apart from Push().
|
sl@0
|
85 |
* aNumberOfItems must be non-negative.
|
sl@0
|
86 |
*/
|
sl@0
|
87 |
void PrepareToPushL(TInt aNumberOfItems);
|
sl@0
|
88 |
void Push(CCommand* aCommand);
|
sl@0
|
89 |
void PruneTo(TInt aNumberOfItems);
|
sl@0
|
90 |
TInt Count() const;
|
sl@0
|
91 |
/**
|
sl@0
|
92 |
* Removes all elements from the stack and deletes the bookmark.
|
sl@0
|
93 |
*/
|
sl@0
|
94 |
void Reset();
|
sl@0
|
95 |
/**
|
sl@0
|
96 |
* Adds aStack to the top of this CCommandStack, emptying it completely.
|
sl@0
|
97 |
* Enough items must have been reserved with PrepareToPushL(TInt).
|
sl@0
|
98 |
*/
|
sl@0
|
99 |
void Concatenate(CCommandStack& aStack);
|
sl@0
|
100 |
/**
|
sl@0
|
101 |
* Sets the current position in the stack as the location of the bookmark.
|
sl@0
|
102 |
* The bookmark will be lost if the bookmarked object is removed from the
|
sl@0
|
103 |
* stack. Bookmark begins set at the zero position.
|
sl@0
|
104 |
*/
|
sl@0
|
105 |
void SetBookmark();
|
sl@0
|
106 |
/**
|
sl@0
|
107 |
* Returns true iff we are at the current bookmark position.
|
sl@0
|
108 |
*/
|
sl@0
|
109 |
TBool IsAtBookmark() const;
|
sl@0
|
110 |
|
sl@0
|
111 |
private:
|
sl@0
|
112 |
CArrayFix<CCommand*>* iStack;
|
sl@0
|
113 |
/**
|
sl@0
|
114 |
* One-past-top element in the array. Less than Count() after a call
|
sl@0
|
115 |
* to PrepareToPushL() with non-zero argument.
|
sl@0
|
116 |
*/
|
sl@0
|
117 |
TInt iEnd;
|
sl@0
|
118 |
/**
|
sl@0
|
119 |
* The bookmark into the stack. We are at the bookmark when iEnd ==
|
sl@0
|
120 |
* iBookmark. No bookmark is represented by iBookmark < 0.
|
sl@0
|
121 |
*/
|
sl@0
|
122 |
TInt iBookmark;
|
sl@0
|
123 |
};
|
sl@0
|
124 |
|
sl@0
|
125 |
/**
|
sl@0
|
126 |
* Stack of single commands
|
sl@0
|
127 |
*
|
sl@0
|
128 |
* @internalComponent
|
sl@0
|
129 |
* @since App-frameworks6.1
|
sl@0
|
130 |
*/
|
sl@0
|
131 |
class CSingleCommandStack : public CBase
|
sl@0
|
132 |
{
|
sl@0
|
133 |
public:
|
sl@0
|
134 |
static CSingleCommandStack* NewL();
|
sl@0
|
135 |
|
sl@0
|
136 |
inline CSingleCommand* Top() const;
|
sl@0
|
137 |
inline CSingleCommand* Pop();
|
sl@0
|
138 |
inline void PrepareToPushL(TInt aNumberOfItems);
|
sl@0
|
139 |
inline void Push(CSingleCommand* aCommand);
|
sl@0
|
140 |
inline void PruneTo(TInt aNumberOfItems);
|
sl@0
|
141 |
inline TInt Count() const;
|
sl@0
|
142 |
inline void Reset();
|
sl@0
|
143 |
inline void Concatenate(CSingleCommandStack& aStack);
|
sl@0
|
144 |
|
sl@0
|
145 |
private:
|
sl@0
|
146 |
CSingleCommandStack() {}
|
sl@0
|
147 |
|
sl@0
|
148 |
CCommandStack iStack;
|
sl@0
|
149 |
};
|
sl@0
|
150 |
|
sl@0
|
151 |
/**
|
sl@0
|
152 |
* A stack of commands supporting batching and a flag for whether a batch
|
sl@0
|
153 |
* has had its undo option waived. A bookmark is also supported, so that we can
|
sl@0
|
154 |
* tell whether the history is in the same state as it was at a previous time.
|
sl@0
|
155 |
*
|
sl@0
|
156 |
* @internalComponent
|
sl@0
|
157 |
* @since App-frameworks6.1
|
sl@0
|
158 |
*/
|
sl@0
|
159 |
NONSHARABLE_CLASS(CCommandHistory) : public CBase
|
sl@0
|
160 |
{
|
sl@0
|
161 |
public:
|
sl@0
|
162 |
~CCommandHistory();
|
sl@0
|
163 |
static CCommandHistory* NewL();
|
sl@0
|
164 |
|
sl@0
|
165 |
/**
|
sl@0
|
166 |
* Returns the command at the top of the stack.
|
sl@0
|
167 |
*/
|
sl@0
|
168 |
CCommand* Top() const;
|
sl@0
|
169 |
/**
|
sl@0
|
170 |
* Returns the single command at the top of the stack.
|
sl@0
|
171 |
*/
|
sl@0
|
172 |
CSingleCommand* TopSingleCommand() const;
|
sl@0
|
173 |
/**
|
sl@0
|
174 |
* Allocates enough resources for one call to AddCommand(CCommand* aCommand).
|
sl@0
|
175 |
*/
|
sl@0
|
176 |
void PrepareToAddCommandL(CCommand* aCommand);
|
sl@0
|
177 |
/**
|
sl@0
|
178 |
* Adds the command to the top of the stack. PrepareToAddCommandL() must
|
sl@0
|
179 |
* have been called successfully since the last call to AddCommand or NewL.
|
sl@0
|
180 |
*/
|
sl@0
|
181 |
void AddCommand(CCommand*);
|
sl@0
|
182 |
/**
|
sl@0
|
183 |
* Returns ETrue iff SetUndoWaived() has been called during this batch. If
|
sl@0
|
184 |
* there is no batch currently open, this function will always return
|
sl@0
|
185 |
* EFalse.
|
sl@0
|
186 |
*/
|
sl@0
|
187 |
TBool UndoHasBeenWaived() const;
|
sl@0
|
188 |
/**
|
sl@0
|
189 |
* Sets a flag to indicated that undo is not required for this current
|
sl@0
|
190 |
* batch. This function has no effect if there is no batch currently open.
|
sl@0
|
191 |
*
|
sl@0
|
192 |
* @see UndoHasBeenWaived
|
sl@0
|
193 |
*/
|
sl@0
|
194 |
void SetUndoWaived();
|
sl@0
|
195 |
/**
|
sl@0
|
196 |
* Sets the maximum height of the stack to aMaxItems. If it is exceeded,
|
sl@0
|
197 |
* the stack is truncated to aPrunedItems.
|
sl@0
|
198 |
*/
|
sl@0
|
199 |
void SetMaxItems(TInt aMaxItems);
|
sl@0
|
200 |
/**
|
sl@0
|
201 |
* Returns ETrue iff the stack has no elements.
|
sl@0
|
202 |
*/
|
sl@0
|
203 |
TBool IsEmpty() const { return Top()? EFalse : ETrue; }
|
sl@0
|
204 |
/**
|
sl@0
|
205 |
* Begins a new batch. All commands added subsequently will be exeuted all
|
sl@0
|
206 |
* at once. Close the batch with CleanupStack::PopAndDestroy();
|
sl@0
|
207 |
*/
|
sl@0
|
208 |
void BeginBatchLC();
|
sl@0
|
209 |
/**
|
sl@0
|
210 |
* Returns ETrue iff there is a batch currently open.
|
sl@0
|
211 |
*/
|
sl@0
|
212 |
TBool IsWithinBatch() const;
|
sl@0
|
213 |
/**
|
sl@0
|
214 |
* Removes and returns the top element. There must be no batch currently
|
sl@0
|
215 |
* open before a call to Pop().
|
sl@0
|
216 |
*/
|
sl@0
|
217 |
CCommand* Pop();
|
sl@0
|
218 |
/**
|
sl@0
|
219 |
* Removes all elements from the stack. If a batch is currently open, any
|
sl@0
|
220 |
* commands added subsequently will not be added to it. Deletes the
|
sl@0
|
221 |
* bookmark.
|
sl@0
|
222 |
*/
|
sl@0
|
223 |
void Reset();
|
sl@0
|
224 |
/**
|
sl@0
|
225 |
* Removes and destroys the top element iff it is an empty batch. Must not
|
sl@0
|
226 |
* be called if a batch is currently open.
|
sl@0
|
227 |
*/
|
sl@0
|
228 |
void Clean();
|
sl@0
|
229 |
/**
|
sl@0
|
230 |
* Sets the bookmark to the current position.
|
sl@0
|
231 |
*/
|
sl@0
|
232 |
void SetBookmark();
|
sl@0
|
233 |
/**
|
sl@0
|
234 |
* Returns true iff the bookmark is at the current position.
|
sl@0
|
235 |
*/
|
sl@0
|
236 |
TBool IsAtBookmark();
|
sl@0
|
237 |
|
sl@0
|
238 |
private:
|
sl@0
|
239 |
|
sl@0
|
240 |
CCommandHistory();
|
sl@0
|
241 |
void ConstructL();
|
sl@0
|
242 |
void Prune();
|
sl@0
|
243 |
|
sl@0
|
244 |
static void CloseBatch(void* aCCommandHistory);
|
sl@0
|
245 |
static void DownBatchLevel(void* aCCommandHistory);
|
sl@0
|
246 |
|
sl@0
|
247 |
CCommandStack* iStack;
|
sl@0
|
248 |
CBatchCommand* iCurrent; // either == 0 or points to the most
|
sl@0
|
249 |
// recent CBatchCommand within iStack
|
sl@0
|
250 |
|
sl@0
|
251 |
TInt iMaxItems;
|
sl@0
|
252 |
|
sl@0
|
253 |
TBool iBatchUndoHasBeenWaived;
|
sl@0
|
254 |
};
|
sl@0
|
255 |
|
sl@0
|
256 |
//
|
sl@0
|
257 |
// CSingleCommandStack inlines
|
sl@0
|
258 |
//
|
sl@0
|
259 |
CSingleCommand* CSingleCommandStack::Top() const
|
sl@0
|
260 |
{ return static_cast<CSingleCommand*>(iStack.Top()); }
|
sl@0
|
261 |
|
sl@0
|
262 |
CSingleCommand* CSingleCommandStack::Pop()
|
sl@0
|
263 |
{ return static_cast<CSingleCommand*>(iStack.Pop()); }
|
sl@0
|
264 |
|
sl@0
|
265 |
void CSingleCommandStack::PrepareToPushL(TInt aNumberOfItems)
|
sl@0
|
266 |
{ iStack.PrepareToPushL(aNumberOfItems); }
|
sl@0
|
267 |
|
sl@0
|
268 |
void CSingleCommandStack::Push(CSingleCommand* aCommand)
|
sl@0
|
269 |
{ iStack.Push(aCommand); }
|
sl@0
|
270 |
|
sl@0
|
271 |
void CSingleCommandStack::PruneTo(TInt aNumberOfItems)
|
sl@0
|
272 |
{ iStack.PruneTo(aNumberOfItems); }
|
sl@0
|
273 |
|
sl@0
|
274 |
TInt CSingleCommandStack::Count() const
|
sl@0
|
275 |
{ return iStack.Count(); }
|
sl@0
|
276 |
|
sl@0
|
277 |
void CSingleCommandStack::Reset()
|
sl@0
|
278 |
{ iStack.Reset(); }
|
sl@0
|
279 |
|
sl@0
|
280 |
void CSingleCommandStack::Concatenate(CSingleCommandStack& aStack)
|
sl@0
|
281 |
{ iStack.Concatenate(aStack.iStack); }
|
sl@0
|
282 |
|
sl@0
|
283 |
}
|
sl@0
|
284 |
|
sl@0
|
285 |
#endif
|
sl@0
|
286 |
|