|
1 /* |
|
2 * Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef EDITORUNDO_H_ |
|
20 #define EDITORUNDO_H_ |
|
21 |
|
22 #include "unified_editor.h" |
|
23 |
|
24 namespace UndoSystem |
|
25 /** |
|
26 @internalTechnology |
|
27 */ |
|
28 { |
|
29 class CCommandManager; |
|
30 class MNotUndoableGatekeeper; |
|
31 } |
|
32 |
|
33 class CEditorCommandFactory; |
|
34 |
|
35 /** |
|
36 MUnifiedEditor decorator that adds undo functionality. |
|
37 It passes commands transparently to the editor it is constructed upon, while |
|
38 storing the operations so that they can be undone and redone. Calling a |
|
39 non-const method of MUnifiedEditor wipes all 'Redo' operations. |
|
40 The undo and redo operations are only guaranteed to be accurate if the |
|
41 underlying editor satisfies certain conditions. |
|
42 |
|
43 @since App-frameworks6.1 |
|
44 @internalAll |
|
45 */ |
|
46 class CEditorWithUndo : public CBase, |
|
47 public MUnifiedEditor, |
|
48 private MUnifiedEditor::MStyleSupport, |
|
49 private MUnifiedEditor::MPictureSupport, |
|
50 private MUnifiedEditor::MClipboardSupport |
|
51 |
|
52 { |
|
53 public: |
|
54 ~CEditorWithUndo(); |
|
55 |
|
56 /** |
|
57 * Creates a CEditorWithUndo. It does not own the aEditor. |
|
58 */ |
|
59 IMPORT_C static CEditorWithUndo* NewL(MUnifiedEditor& aEditor); |
|
60 /** |
|
61 * Creates a CEditorWithUndo, using the aSharedUndoSystem. This allows |
|
62 * many objects to stay in synchronization when each is accessed |
|
63 * seperately. |
|
64 * The aEditor is not owned. |
|
65 */ |
|
66 IMPORT_C static CEditorWithUndo* NewL(MUnifiedEditor& aEditor, |
|
67 UndoSystem::CCommandManager* aSharedUndoSystem); |
|
68 /** |
|
69 * Undoes one operation or batch of operations. If one operation in the |
|
70 * middle of a batch leaves, this function will leave, but the underlying |
|
71 * editor will not necessarily be in the same state as it was in before |
|
72 * the call. However, all operations will still be stored, and so the |
|
73 * previous state is still recoverable with a call to RedoL() or a |
|
74 * further call to UndoL will complete the operation (resource acquisition |
|
75 * permitting). |
|
76 */ |
|
77 IMPORT_C void UndoL(); |
|
78 /** |
|
79 * Redoes one operation or batch of operations. If one operation in the |
|
80 * middle of a batch leaves, this function will leave, but the underlying |
|
81 * editor will not necessarily be in the same state as it was in before |
|
82 * the call. However, all operations will still be stored, and so the |
|
83 * previous state is still recoverable with a call to UndoL() or a |
|
84 * further call to RedoL will complete the operation (resource acquisition |
|
85 * permitting). |
|
86 */ |
|
87 IMPORT_C void RedoL(); |
|
88 /** |
|
89 * Returns ETrue iff UndoL() would have an effect |
|
90 */ |
|
91 IMPORT_C TBool CanUndo() const; |
|
92 /** |
|
93 * Returns ETrue iff RedoL() would have an effect |
|
94 */ |
|
95 IMPORT_C TBool CanRedo() const; |
|
96 /** |
|
97 * Wipes all undo and redo operations |
|
98 */ |
|
99 IMPORT_C void ResetUndo(); |
|
100 /** |
|
101 * Sets limits on the 'undo depth'. This is the numbet of times that |
|
102 * successive calls to UndoL() have an effect. When a depth of |
|
103 * aMaxItems is reached, the undo depth is reset to aMinItems. |
|
104 */ |
|
105 IMPORT_C void SetMaxItems(TInt aMaxItems); |
|
106 /** |
|
107 * Sets a gatekeper for the undo system. This will be called whenever an |
|
108 * operation is attempted that cannot be undone for any reason. |
|
109 * The gatekeeper therefore has an oportunity to suppress execution and |
|
110 * keep the current undo operations stored. |
|
111 * NULL may be passed to restore default behaviour. |
|
112 * Returns the old gatekeeper. |
|
113 */ |
|
114 IMPORT_C UndoSystem::MNotUndoableGatekeeper* |
|
115 SetGatekeeper(UndoSystem::MNotUndoableGatekeeper*); |
|
116 |
|
117 // From MUnifiedEditor |
|
118 MTmOptionalInterface* Interface(TUint aId); |
|
119 void InsertTextL(TInt aPos, const TDesC& aText, const TDesC* aStyle, |
|
120 const TTmCharFormatLayer*, const RTmParFormatLayer*); |
|
121 void DeleteTextL(TInt aPos,TInt aLength); |
|
122 void SetBaseFormatL(const TTmCharFormat&, const RTmParFormat&); |
|
123 void SetCharFormatL(TInt aPos, TInt aLength, const TTmCharFormatLayer&); |
|
124 void SetParFormatL(TInt aPos, TInt aLength, const RTmParFormatLayer&); |
|
125 void DeleteCharFormatL(TInt aPos, TInt aLength); |
|
126 void DeleteParFormatL(TInt aPos, TInt aLength); |
|
127 TInt DocumentLength() const; |
|
128 void GetText(TInt aPos, TPtrC& aText) const; |
|
129 void GetBaseFormatL(TTmCharFormat&, RTmParFormat&) const; |
|
130 void GetCharFormat(TInt aPos, TFormatLevel aLevel, |
|
131 TTmCharFormatLayer& aFormat,TInt& aRunLength) const; |
|
132 void GetParFormatL(TInt aPos, TFormatLevel aLevel, |
|
133 RTmParFormatLayer& aFormat, TInt& aRunLength) const; |
|
134 |
|
135 private: |
|
136 // from MStyleSupport |
|
137 TInt CreateStyleL(const RTmStyle&); |
|
138 TInt ChangeStyleL(const RTmStyle&); |
|
139 TInt SetStyleL(TInt aPos, TInt aLength, const TDesC&); |
|
140 TInt RenameStyleL(const TDesC& aOldName, const TDesC& aNewName); |
|
141 TInt DeleteStyleL(const TDesC& aName); |
|
142 TInt StyleCount() const; |
|
143 void GetStyle(TInt aPos, TPtrC& aName, TInt& aRunLength) const; |
|
144 TInt GetStyleByNameL(const TDesC& aName, RTmStyle&) const; |
|
145 TInt GetStyleByIndexL(TInt aIndex, RTmStyle&) const; |
|
146 |
|
147 // from MPictureSupport |
|
148 void InsertPictureL(TInt aPos, const TPictureHeader&); |
|
149 void DropPictureL(TInt aPos); |
|
150 void Picture(TInt aPos, TPictureHeader&) const; |
|
151 |
|
152 // from MClipboardSupport |
|
153 void CopyToStoreL(CStreamStore& aStore, CStreamDictionary& aDictionary, |
|
154 TInt aPos, TInt aLength) const; |
|
155 void PasteFromStoreL(const CStreamStore& aStore, |
|
156 const CStreamDictionary& aDictionary, TInt aPos); |
|
157 |
|
158 CEditorWithUndo(); |
|
159 void ConstructL(MUnifiedEditor& aEditorBasedOn, |
|
160 UndoSystem::CCommandManager* aSharedUndoSystem); |
|
161 |
|
162 CEditorCommandFactory* iFactory; |
|
163 MUnifiedEditor* iBaseEditor; |
|
164 UndoSystem::CCommandManager* iCommandManager; |
|
165 }; |
|
166 |
|
167 #endif // EDITORUNDO_H_ |