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