sl@0: /* sl@0: * Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #ifndef EDITORCOMMANDS_H_ sl@0: #define EDITORCOMMANDS_H_ sl@0: sl@0: #include "unified_editor.h" sl@0: #include "UniqueInstance.h" sl@0: #include "UndoSystem.h" sl@0: #include "EditorPlainTextCommands.h" sl@0: sl@0: // all the combinable commands: sl@0: class CEditorCommandInsertTextAndFormat; sl@0: class CEditorCommandDeleteText; sl@0: class CEditorCommandDeleteCharFormat; sl@0: class CEditorCommandDeleteParFormat; sl@0: sl@0: /** sl@0: * Pointers to the repositories used by the undo system. sl@0: * sl@0: * @internalComponent sl@0: * @since App-frameworks6.1 sl@0: */ sl@0: struct TRepositories sl@0: { sl@0: CUniqueInstanceRepository* iChar; sl@0: CUniqueInstanceRepository* iPar; sl@0: CUniqueInstanceRepository* iDes; sl@0: }; sl@0: sl@0: // sl@0: // command prototypes sl@0: // sl@0: /** sl@0: * Base class for command prototypes. These prototypes are used to generate sl@0: * inverses. They do not need any copying to be sent into the undo system, sl@0: * executed, then recycled. Some also store a pointer to the last generated sl@0: * inverse so that they can add to it if two similar commands come along sl@0: * together. sl@0: * sl@0: * @internalComponent sl@0: * @since App-frameworks6.1 sl@0: */ sl@0: class CEditorCommandProto : public CEditorCommand sl@0: { sl@0: const TRepositories& iReps; sl@0: public: sl@0: CEditorCommandProto(const TRepositories& aReps) sl@0: : iReps(aReps) {} sl@0: const TRepositories& Repositories() const { return iReps; } sl@0: }; sl@0: sl@0: /** sl@0: * Prototype command for creating a style. sl@0: * sl@0: * @internalComponent sl@0: * @since App-frameworks6.1 sl@0: */ sl@0: NONSHARABLE_CLASS(CEditorCommandCreateStyleProto) : public CEditorCommandProto sl@0: { sl@0: MUnifiedEditor& iTarget; sl@0: const RTmStyle* iStyle; sl@0: sl@0: public: sl@0: CEditorCommandCreateStyleProto(const TRepositories& aReps, MUnifiedEditor& aTarget) sl@0: : CEditorCommandProto(aReps), iTarget(aTarget) {} sl@0: void Set(const RTmStyle&); sl@0: sl@0: UndoSystem::CCommand* CreateInverseL() const; sl@0: TInt ExecuteL() const; sl@0: }; sl@0: sl@0: /** sl@0: * Prototype command for setting the attributes of a style. sl@0: * sl@0: * @internalComponent sl@0: * @since App-frameworks6.1 sl@0: */ sl@0: NONSHARABLE_CLASS(CEditorCommandChangeStyleProto) : public CEditorCommandProto sl@0: { sl@0: MUnifiedEditor& iTarget; sl@0: const RTmStyle* iStyle; sl@0: sl@0: public: sl@0: CEditorCommandChangeStyleProto(const TRepositories& aReps, MUnifiedEditor& aTarget) sl@0: : CEditorCommandProto(aReps), iTarget(aTarget) {} sl@0: void Set(const RTmStyle&); sl@0: sl@0: UndoSystem::CCommand* CreateInverseL() const; sl@0: TInt ExecuteL() const; sl@0: }; sl@0: sl@0: /** sl@0: * Prototype command for applying a style to a run of text. sl@0: * sl@0: * @internalComponent sl@0: * @since App-frameworks6.1 sl@0: */ sl@0: NONSHARABLE_CLASS(CEditorCommandSetStyleProto) : public CEditorCommandProto sl@0: { sl@0: MUnifiedEditor& iTarget; sl@0: TInt iPos; sl@0: TInt iLength; sl@0: const TDesC* iName; sl@0: sl@0: public: sl@0: CEditorCommandSetStyleProto(const TRepositories& aReps, MUnifiedEditor& aTarget) sl@0: : CEditorCommandProto(aReps), iTarget(aTarget) {} sl@0: void Set(TInt aPos, TInt aLength, sl@0: const TDesC& aName); sl@0: sl@0: UndoSystem::CCommand* CreateInverseL() const; sl@0: TInt ExecuteL() const; sl@0: }; sl@0: sl@0: /** sl@0: * Prototype command for deleting a style. sl@0: * sl@0: * @internalComponent sl@0: * @since App-frameworks6.1 sl@0: */ sl@0: NONSHARABLE_CLASS(CEditorCommandDeleteStyleProto) : public CEditorCommandProto sl@0: { sl@0: MUnifiedEditor& iTarget; sl@0: const TDesC* iName; sl@0: sl@0: public: sl@0: CEditorCommandDeleteStyleProto(const TRepositories& aReps, MUnifiedEditor& aTarget) sl@0: : CEditorCommandProto(aReps), iTarget(aTarget) {} sl@0: void Set(const TDesC& aName); sl@0: sl@0: UndoSystem::CCommand* CreateInverseL() const; sl@0: TInt ExecuteL() const; sl@0: }; sl@0: sl@0: /** sl@0: * Prototype command for setting the character format of a run of text. sl@0: * sl@0: * @internalComponent sl@0: * @since App-frameworks6.1 sl@0: */ sl@0: NONSHARABLE_CLASS(CEditorCommandSetCharFormatProto) : public CEditorCommandProto sl@0: { sl@0: MUnifiedEditor& iTarget; sl@0: TInt iPos; sl@0: TInt iLength; sl@0: const TTmCharFormatLayer* iFormat; sl@0: sl@0: public: sl@0: CEditorCommandSetCharFormatProto(const TRepositories& aReps, MUnifiedEditor& aTarget) sl@0: : CEditorCommandProto(aReps), iTarget(aTarget) {} sl@0: void Set(TInt aPos, sl@0: TInt aLength, sl@0: const TTmCharFormatLayer& aFormat); sl@0: sl@0: UndoSystem::CCommand* CreateInverseL() const; sl@0: TInt ExecuteL() const; sl@0: }; sl@0: sl@0: /** sl@0: * Prototype command for setting the paragraph format of a run of text. sl@0: * sl@0: * @internalComponent sl@0: * @since App-frameworks6.1 sl@0: */ sl@0: NONSHARABLE_CLASS(CEditorCommandSetParFormatProto) : public CEditorCommandProto sl@0: { sl@0: MUnifiedEditor& iTarget; sl@0: TInt iPos; sl@0: TInt iLength; sl@0: const RTmParFormatLayer* iFormat; sl@0: sl@0: public: sl@0: CEditorCommandSetParFormatProto(const TRepositories& aReps, MUnifiedEditor& aTarget) sl@0: : CEditorCommandProto(aReps), iTarget(aTarget) {} sl@0: void Set(TInt aPos, sl@0: TInt aLength, sl@0: const RTmParFormatLayer& aFormat); sl@0: sl@0: UndoSystem::CCommand* CreateInverseL() const; sl@0: TInt ExecuteL() const; sl@0: }; sl@0: sl@0: /** sl@0: * Prototype command for inserting text with specified character and paragraph sl@0: * format. sl@0: * sl@0: * @internalComponent sl@0: * @since App-frameworks6.1 sl@0: */ sl@0: NONSHARABLE_CLASS(CEditorCommandInsertProto) : public CEditorCommandProto sl@0: { sl@0: MUnifiedEditor& iTarget; sl@0: TInt iPos; sl@0: const TDesC* iText; sl@0: const TTmCharFormatLayer* iCharFormat; sl@0: const RTmParFormatLayer* iParFormat; sl@0: const TDesC* iStyle; sl@0: sl@0: public: sl@0: CEditorCommandInsertProto(const TRepositories& aReps, MUnifiedEditor& aTarget) sl@0: : CEditorCommandProto(aReps), iTarget(aTarget) {} sl@0: void Set(TInt aPos, sl@0: const TDesC& aText, sl@0: const TDesC* aStyle, sl@0: const TTmCharFormatLayer* aCharFormat, sl@0: const RTmParFormatLayer* aParFormat); sl@0: sl@0: UndoSystem::CCommand* CreateInverseL() const; sl@0: TInt ExecuteL() const; sl@0: sl@0: TBool PrepareToAddInverseToLastL(UndoSystem::CSingleCommand& aLastCommand) const; sl@0: void AddInverseToLast(UndoSystem::CSingleCommand& aLastCommand) const; sl@0: }; sl@0: sl@0: /** sl@0: * Prototype command for deleting text. sl@0: * sl@0: * @internalComponent sl@0: * @since App-frameworks6.1 sl@0: */ sl@0: NONSHARABLE_CLASS(CEditorCommandDeleteProto) : public CEditorCommandProto sl@0: { sl@0: enum { KMaxCombinableReinsertCharacters = 20 }; sl@0: sl@0: MUnifiedEditor& iTarget; sl@0: TInt iPos; sl@0: TInt iLength; sl@0: // For adding inverse to last command sl@0: mutable TBuf iDeletedText; sl@0: sl@0: public: sl@0: CEditorCommandDeleteProto(const TRepositories& aReps, MUnifiedEditor& aTarget) sl@0: : CEditorCommandProto(aReps), iTarget(aTarget) {} sl@0: void Set(TInt aPos, TInt aLength); sl@0: sl@0: UndoSystem::CCommand* CreateInverseL() const; sl@0: TInt ExecuteL() const; sl@0: sl@0: TBool PrepareToAddInverseToLastL(UndoSystem::CSingleCommand& aLastCommand) const; sl@0: void AddInverseToLast(UndoSystem::CSingleCommand& aLastCommand) const; sl@0: }; sl@0: sl@0: /** sl@0: * Prototype command for setting the base format. sl@0: * sl@0: * @internalComponent sl@0: * @since App-frameworks6.1 sl@0: */ sl@0: NONSHARABLE_CLASS(CEditorCommandSetBaseFormatProto) : public CEditorCommandProto sl@0: { sl@0: MUnifiedEditor& iTarget; sl@0: const TTmCharFormat* iChar; sl@0: const RTmParFormat* iPar; sl@0: sl@0: public: sl@0: CEditorCommandSetBaseFormatProto(const TRepositories& aReps, MUnifiedEditor& aTarget) sl@0: : CEditorCommandProto(aReps), iTarget(aTarget) {} sl@0: void Set(const TTmCharFormat* aCharFormat, const RTmParFormat* aParFormat); sl@0: sl@0: UndoSystem::CCommand* CreateInverseL() const; sl@0: TInt ExecuteL() const; sl@0: }; sl@0: sl@0: /** sl@0: * Prototype command for deleting specific character formatting. sl@0: * sl@0: * @internalComponent sl@0: * @since App-frameworks6.1 sl@0: */ sl@0: NONSHARABLE_CLASS(CEditorCommandDeleteCharFormatProto) : public CEditorCommandProto sl@0: { sl@0: MUnifiedEditor& iTarget; sl@0: TInt iPos; sl@0: TInt iLength; sl@0: sl@0: public: sl@0: CEditorCommandDeleteCharFormatProto(const TRepositories& aReps, MUnifiedEditor& aTarget) sl@0: : CEditorCommandProto(aReps), iTarget(aTarget) {} sl@0: void Set(TInt aPos, TInt aLength); sl@0: sl@0: UndoSystem::CCommand* CreateInverseL() const; sl@0: TInt ExecuteL() const; sl@0: }; sl@0: sl@0: /** sl@0: * Prototype command for deleting specific paragraph formatting. sl@0: * sl@0: * @internalComponent sl@0: * @since App-frameworks6.1 sl@0: */ sl@0: NONSHARABLE_CLASS(CEditorCommandDeleteParFormatProto) : public CEditorCommandProto sl@0: { sl@0: MUnifiedEditor& iTarget; sl@0: TInt iPos; sl@0: TInt iLength; sl@0: sl@0: public: sl@0: CEditorCommandDeleteParFormatProto(const TRepositories& aReps, MUnifiedEditor& aTarget) sl@0: : CEditorCommandProto(aReps), iTarget(aTarget) {} sl@0: void Set(TInt aPos, TInt aLength); sl@0: sl@0: UndoSystem::CCommand* CreateInverseL() const; sl@0: TInt ExecuteL() const; sl@0: }; sl@0: sl@0: /** sl@0: * Prototype command for deleting a picture. sl@0: * sl@0: * @internalComponent sl@0: * @since App-frameworks6.1 sl@0: */ sl@0: NONSHARABLE_CLASS(CEditorCommandDeletePictureProto) : public CEditorCommandProto sl@0: { sl@0: MUnifiedEditor& iTarget; sl@0: TInt iPos; sl@0: sl@0: public: sl@0: CEditorCommandDeletePictureProto(const TRepositories& aReps, MUnifiedEditor& aTarget) sl@0: : CEditorCommandProto(aReps), iTarget(aTarget) {} sl@0: void Set(TInt aPos); sl@0: sl@0: TInt ExecuteL() const; sl@0: }; sl@0: sl@0: /** sl@0: * Prototype command for inserting a picture. sl@0: * sl@0: * @internalComponent sl@0: * @since App-frameworks6.1 sl@0: */ sl@0: NONSHARABLE_CLASS(CEditorCommandInsertPictureProto) : public CEditorCommandProto sl@0: { sl@0: MUnifiedEditor& iTarget; sl@0: TInt iPos; sl@0: const TPictureHeader* iPicture; sl@0: sl@0: public: sl@0: CEditorCommandInsertPictureProto(const TRepositories& aReps, MUnifiedEditor& aTarget) sl@0: : CEditorCommandProto(aReps), iTarget(aTarget) {} sl@0: void Set(TInt aPos, const TPictureHeader& picture); sl@0: sl@0: UndoSystem::CCommand* CreateInverseL() const; sl@0: TInt ExecuteL() const; sl@0: }; sl@0: sl@0: /** sl@0: * Prototype command for renaming a style. sl@0: * sl@0: * @internalComponent sl@0: * @since App-frameworks6.1 sl@0: */ sl@0: NONSHARABLE_CLASS(CEditorCommandRenameStyleProto) : public CEditorCommandProto sl@0: { sl@0: MUnifiedEditor& iTarget; sl@0: const TDesC* iOldName; sl@0: const TDesC* iNewName; sl@0: sl@0: public: sl@0: CEditorCommandRenameStyleProto(const TRepositories& aReps, MUnifiedEditor& aTarget) sl@0: : CEditorCommandProto(aReps), iTarget(aTarget) {} sl@0: void Set(const TDesC& aOldName, const TDesC& aNewName); sl@0: sl@0: UndoSystem::CCommand* CreateInverseL() const; sl@0: TInt ExecuteL() const; sl@0: }; sl@0: sl@0: /** sl@0: * Prototype command for pasting text. sl@0: * sl@0: * @internalComponent sl@0: * @since App-frameworks6.1 sl@0: */ sl@0: NONSHARABLE_CLASS(CEditorCommandPasteProto) : public CEditorCommandProto sl@0: { sl@0: TEditorPasteProtoImpl iImpl; sl@0: sl@0: public: sl@0: CEditorCommandPasteProto(const TRepositories& aReps, MUnifiedEditor& aTarget) sl@0: : CEditorCommandProto(aReps), iImpl(aTarget) {} sl@0: void Set(const CStreamStore& aStore, sl@0: const CStreamDictionary& aStreamDictionary, sl@0: TInt aPos); sl@0: sl@0: UndoSystem::CCommand* CreateInverseL() const; sl@0: TInt ExecuteL() const; sl@0: }; sl@0: sl@0: /** sl@0: * Owner of a picture which will eventually pass on ownership. sl@0: * sl@0: * @internalComponent sl@0: * @since App-frameworks6.1 sl@0: */ sl@0: class MPictureOwner sl@0: { sl@0: public: sl@0: /** sl@0: * Forgets the delegate that has been made next in line for sl@0: * the picture. sl@0: */ sl@0: virtual void ForgetDelegate() = 0; sl@0: }; sl@0: sl@0: class CEditorCommandInsertPicture; sl@0: sl@0: /** sl@0: * Prototype command for deleting a picture from the text without sl@0: * returning ownership. sl@0: * sl@0: * @internalComponent sl@0: * @since App-frameworks6.1 sl@0: */ sl@0: NONSHARABLE_CLASS(CEditorCommandDestroyPictureProto) : public CEditorCommandProto, sl@0: private MPictureOwner sl@0: { sl@0: MUnifiedEditor& iTarget; sl@0: TInt iPos; sl@0: /** sl@0: * Will own picture after us. sl@0: */ sl@0: mutable CEditorCommandInsertPicture* iPictureOwnerDelegate; sl@0: sl@0: void ForgetDelegate(); sl@0: public: sl@0: CEditorCommandDestroyPictureProto(const TRepositories& aReps, MUnifiedEditor& aTarget) sl@0: : CEditorCommandProto(aReps), iTarget(aTarget) {} sl@0: ~CEditorCommandDestroyPictureProto(); sl@0: void Set(TInt aPos); sl@0: sl@0: UndoSystem::CCommand* CreateInverseL() const; sl@0: TInt ExecuteL() const; sl@0: }; sl@0: sl@0: namespace UndoSystem sl@0: { sl@0: /** sl@0: * Finds the position of the first picture in the text. Returns sl@0: * 'KNotFound' if there are none. This will not return any sl@0: * picture characters that do not have attatched pictures. sl@0: * sl@0: * @internalComponent sl@0: * @since App-frameworks6.1 sl@0: */ sl@0: TInt FindPicture(const MUnifiedEditor& aTarget, TInt aPos, TInt aLength); sl@0: } sl@0: sl@0: #endif // EDITORCOMMANDS_H_