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