williamr@2: // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@2: // 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: // which accompanies this distribution, and is available williamr@2: // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // williamr@2: williamr@2: #ifndef EDITORUNDO_H_ williamr@2: #define EDITORUNDO_H_ williamr@2: williamr@2: #include "unified_editor.h" williamr@2: williamr@2: namespace UndoSystem williamr@2: /** williamr@2: @internalTechnology williamr@2: */ williamr@2: { williamr@2: class CCommandManager; williamr@2: class MNotUndoableGatekeeper; williamr@2: } williamr@2: williamr@2: class CEditorCommandFactory; williamr@2: williamr@2: /** williamr@2: MUnifiedEditor decorator that adds undo functionality. williamr@2: It passes commands transparently to the editor it is constructed upon, while williamr@2: storing the operations so that they can be undone and redone. Calling a williamr@2: non-const method of MUnifiedEditor wipes all 'Redo' operations. williamr@2: The undo and redo operations are only guaranteed to be accurate if the williamr@2: underlying editor satisfies certain conditions. williamr@2: williamr@2: @since App-frameworks6.1 williamr@2: @internalAll williamr@2: */ williamr@2: class CEditorWithUndo : public CBase, williamr@2: public MUnifiedEditor, williamr@2: private MUnifiedEditor::MStyleSupport, williamr@2: private MUnifiedEditor::MPictureSupport, williamr@2: private MUnifiedEditor::MClipboardSupport williamr@2: williamr@2: { williamr@2: public: williamr@2: ~CEditorWithUndo(); williamr@2: williamr@2: /** williamr@2: * Creates a CEditorWithUndo. It does not own the aEditor. williamr@2: */ williamr@2: IMPORT_C static CEditorWithUndo* NewL(MUnifiedEditor& aEditor); williamr@2: /** williamr@2: * Creates a CEditorWithUndo, using the aSharedUndoSystem. This allows williamr@2: * many objects to stay in synchronization when each is accessed williamr@2: * seperately. williamr@2: * The aEditor is not owned. williamr@2: */ williamr@2: IMPORT_C static CEditorWithUndo* NewL(MUnifiedEditor& aEditor, williamr@2: UndoSystem::CCommandManager* aSharedUndoSystem); williamr@2: /** williamr@2: * Undoes one operation or batch of operations. If one operation in the williamr@2: * middle of a batch leaves, this function will leave, but the underlying williamr@2: * editor will not necessarily be in the same state as it was in before williamr@2: * the call. However, all operations will still be stored, and so the williamr@2: * previous state is still recoverable with a call to RedoL() or a williamr@2: * further call to UndoL will complete the operation (resource acquisition williamr@2: * permitting). williamr@2: */ williamr@2: IMPORT_C void UndoL(); williamr@2: /** williamr@2: * Redoes one operation or batch of operations. If one operation in the williamr@2: * middle of a batch leaves, this function will leave, but the underlying williamr@2: * editor will not necessarily be in the same state as it was in before williamr@2: * the call. However, all operations will still be stored, and so the williamr@2: * previous state is still recoverable with a call to UndoL() or a williamr@2: * further call to RedoL will complete the operation (resource acquisition williamr@2: * permitting). williamr@2: */ williamr@2: IMPORT_C void RedoL(); williamr@2: /** williamr@2: * Returns ETrue iff UndoL() would have an effect williamr@2: */ williamr@2: IMPORT_C TBool CanUndo() const; williamr@2: /** williamr@2: * Returns ETrue iff RedoL() would have an effect williamr@2: */ williamr@2: IMPORT_C TBool CanRedo() const; williamr@2: /** williamr@2: * Wipes all undo and redo operations williamr@2: */ williamr@2: IMPORT_C void ResetUndo(); williamr@2: /** williamr@2: * Sets limits on the 'undo depth'. This is the numbet of times that williamr@2: * successive calls to UndoL() have an effect. When a depth of williamr@2: * aMaxItems is reached, the undo depth is reset to aMinItems. williamr@2: */ williamr@2: IMPORT_C void SetMaxItems(TInt aMaxItems); williamr@2: /** williamr@2: * Sets a gatekeper for the undo system. This will be called whenever an williamr@2: * operation is attempted that cannot be undone for any reason. williamr@2: * The gatekeeper therefore has an oportunity to suppress execution and williamr@2: * keep the current undo operations stored. williamr@2: * NULL may be passed to restore default behaviour. williamr@2: * Returns the old gatekeeper. williamr@2: */ williamr@2: IMPORT_C UndoSystem::MNotUndoableGatekeeper* williamr@2: SetGatekeeper(UndoSystem::MNotUndoableGatekeeper*); williamr@2: williamr@2: // From MUnifiedEditor williamr@2: MTmOptionalInterface* Interface(TUint aId); williamr@2: void InsertTextL(TInt aPos, const TDesC& aText, const TDesC* aStyle, williamr@2: const TTmCharFormatLayer*, const RTmParFormatLayer*); williamr@2: void DeleteTextL(TInt aPos,TInt aLength); williamr@2: void SetBaseFormatL(const TTmCharFormat&, const RTmParFormat&); williamr@2: void SetCharFormatL(TInt aPos, TInt aLength, const TTmCharFormatLayer&); williamr@2: void SetParFormatL(TInt aPos, TInt aLength, const RTmParFormatLayer&); williamr@2: void DeleteCharFormatL(TInt aPos, TInt aLength); williamr@2: void DeleteParFormatL(TInt aPos, TInt aLength); williamr@2: TInt DocumentLength() const; williamr@2: void GetText(TInt aPos, TPtrC& aText) const; williamr@2: void GetBaseFormatL(TTmCharFormat&, RTmParFormat&) const; williamr@2: void GetCharFormat(TInt aPos, TFormatLevel aLevel, williamr@2: TTmCharFormatLayer& aFormat,TInt& aRunLength) const; williamr@2: void GetParFormatL(TInt aPos, TFormatLevel aLevel, williamr@2: RTmParFormatLayer& aFormat, TInt& aRunLength) const; williamr@2: williamr@2: private: williamr@2: // from MStyleSupport williamr@2: TInt CreateStyleL(const RTmStyle&); williamr@2: TInt ChangeStyleL(const RTmStyle&); williamr@2: TInt SetStyleL(TInt aPos, TInt aLength, const TDesC&); williamr@2: TInt RenameStyleL(const TDesC& aOldName, const TDesC& aNewName); williamr@2: TInt DeleteStyleL(const TDesC& aName); williamr@2: TInt StyleCount() const; williamr@2: void GetStyle(TInt aPos, TPtrC& aName, TInt& aRunLength) const; williamr@2: TInt GetStyleByNameL(const TDesC& aName, RTmStyle&) const; williamr@2: TInt GetStyleByIndexL(TInt aIndex, RTmStyle&) const; williamr@2: williamr@2: // from MPictureSupport williamr@2: void InsertPictureL(TInt aPos, const TPictureHeader&); williamr@2: void DropPictureL(TInt aPos); williamr@2: void Picture(TInt aPos, TPictureHeader&) const; williamr@2: williamr@2: // from MClipboardSupport williamr@2: void CopyToStoreL(CStreamStore& aStore, CStreamDictionary& aDictionary, williamr@2: TInt aPos, TInt aLength) const; williamr@2: void PasteFromStoreL(const CStreamStore& aStore, williamr@2: const CStreamDictionary& aDictionary, TInt aPos); williamr@2: williamr@2: CEditorWithUndo(); williamr@2: void ConstructL(MUnifiedEditor& aEditorBasedOn, williamr@2: UndoSystem::CCommandManager* aSharedUndoSystem); williamr@2: williamr@2: CEditorCommandFactory* iFactory; williamr@2: MUnifiedEditor* iBaseEditor; williamr@2: UndoSystem::CCommandManager* iCommandManager; williamr@2: }; williamr@2: williamr@2: #endif // EDITORUNDO_H_