epoc32/include/editorundo.h
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
equal deleted inserted replaced
3:e1b950c65cb4 4:837f303aceeb
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef EDITORUNDO_H_
       
    17 #define EDITORUNDO_H_
       
    18 
       
    19 #include "unified_editor.h"
       
    20 
       
    21 namespace UndoSystem
       
    22 /**
       
    23 @internalTechnology
       
    24 */
       
    25 {
       
    26 class CCommandManager;
       
    27 class MNotUndoableGatekeeper;
       
    28 }
       
    29 
       
    30 class CEditorCommandFactory;
       
    31 
       
    32 /**
       
    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.
       
    39 
       
    40 @since App-frameworks6.1
       
    41 @internalAll
       
    42 */
       
    43 class CEditorWithUndo : public CBase,
       
    44 	public MUnifiedEditor,
       
    45 	private MUnifiedEditor::MStyleSupport,
       
    46 	private MUnifiedEditor::MPictureSupport,
       
    47 	private MUnifiedEditor::MClipboardSupport
       
    48 
       
    49 	{
       
    50 public:
       
    51 	~CEditorWithUndo();
       
    52 
       
    53 	/**
       
    54 	 * Creates a CEditorWithUndo. It does not own the aEditor.
       
    55 	 */
       
    56 	IMPORT_C static CEditorWithUndo* NewL(MUnifiedEditor& aEditor);
       
    57 	/**
       
    58 	 * Creates a CEditorWithUndo, using the aSharedUndoSystem. This allows
       
    59 	 * many objects to stay in synchronization when each is accessed
       
    60 	 * seperately.
       
    61 	 * The aEditor is not owned.
       
    62 	 */
       
    63 	IMPORT_C static CEditorWithUndo* NewL(MUnifiedEditor& aEditor,
       
    64 		UndoSystem::CCommandManager* aSharedUndoSystem);
       
    65 	/**
       
    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
       
    72 	 * permitting).
       
    73 	 */
       
    74 	IMPORT_C void UndoL();
       
    75 	/**
       
    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
       
    82 	 * permitting).
       
    83 	 */
       
    84 	IMPORT_C void RedoL();
       
    85 	/**
       
    86 	 * Returns ETrue iff UndoL() would have an effect
       
    87 	 */
       
    88 	IMPORT_C TBool CanUndo() const;
       
    89 	/**
       
    90 	 * Returns ETrue iff RedoL() would have an effect
       
    91 	 */
       
    92 	IMPORT_C TBool CanRedo() const;
       
    93 	/**
       
    94 	 * Wipes all undo and redo operations
       
    95 	 */
       
    96 	IMPORT_C void ResetUndo();
       
    97 	/**
       
    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.
       
   101 	 */
       
   102 	IMPORT_C void SetMaxItems(TInt aMaxItems);
       
   103 	/**
       
   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.
       
   110 	 */
       
   111 	IMPORT_C UndoSystem::MNotUndoableGatekeeper*
       
   112 		SetGatekeeper(UndoSystem::MNotUndoableGatekeeper*);
       
   113 
       
   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;
       
   131 
       
   132 private:
       
   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;
       
   143 
       
   144 	// from MPictureSupport
       
   145 	void InsertPictureL(TInt aPos, const TPictureHeader&);
       
   146 	void DropPictureL(TInt aPos);
       
   147 	void Picture(TInt aPos, TPictureHeader&) const;
       
   148 
       
   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);
       
   154 
       
   155 	CEditorWithUndo();
       
   156 	void ConstructL(MUnifiedEditor& aEditorBasedOn,
       
   157 		UndoSystem::CCommandManager* aSharedUndoSystem);
       
   158 
       
   159 	CEditorCommandFactory*			iFactory;
       
   160 	MUnifiedEditor*						iBaseEditor;
       
   161 	UndoSystem::CCommandManager*	iCommandManager;
       
   162 	};
       
   163 
       
   164 #endif	// EDITORUNDO_H_