os/textandloc/textrendering/textformatting/undo/EditorPlainTextCommands.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #ifndef EDITORPLAINTEXTCOMMANDS_H_
    20 #define EDITORPLAINTEXTCOMMANDS_H_
    21 
    22 #include "unified_editor.h"
    23 #include "UniqueInstance.h"
    24 #include "UndoSystem.h"
    25 
    26 namespace LocalInFile
    27 {
    28 /**
    29 @internalComponent
    30 */
    31 const TInt KMaxCharsInSingleCommand = 20;
    32 const TInt KUndoDllUid = 0x1000902D;
    33 }
    34 
    35 using namespace LocalInFile;
    36 
    37 namespace UndoSystem
    38 {
    39 /**
    40  * Takes two commands and returns one, which when executed will
    41  * achieve the result of executing first aRight, then aLeft.
    42  * Either argument may be null, indicating no effect of execution.
    43  * In the event of a leave, aRight will be destroyed, however
    44  * aLeft must be protected by the calling function.
    45  * Ownership of aLeft is passed into the function if it exits
    46  * cleanly, and ownership of the return value is passed back
    47  * to the calling function.
    48  */
    49 CCommand* CoalesceL(CCommand* aLeft, CCommand* aRight);
    50 }
    51 
    52 // all the combinable commands:
    53 class CEditorCommandInsertTextAndFormat;
    54 class CEditorCommandDeleteText;
    55 class CEditorCommandInsertPlainText;
    56 class CEditorCommandDeletePlainText;
    57 class CEditorCommandDeleteCharFormat;
    58 class CEditorCommandDeleteParFormat;
    59 
    60 /**
    61  * Editor command is the base class for all the MUnifiedEditor commands.
    62  *
    63  * @internalComponent
    64  * @since App-frameworks6.1
    65  */
    66 NONSHARABLE_CLASS(CEditorCommand) : public UndoSystem::CSingleCommand
    67 	{
    68 public:
    69 	TUid FamilyUid() const;
    70 
    71 	// downcast to combinable internal commands
    72 	virtual CEditorCommandInsertTextAndFormat*
    73 		CastToCEditorCommandInsertTextAndFormat();
    74 	virtual CEditorCommandDeleteText*
    75 		CastToCEditorCommandDeleteText();
    76 	virtual CEditorCommandInsertPlainText*
    77 		CastToCEditorCommandInsertPlainText();
    78 	virtual CEditorCommandDeletePlainText*
    79 		CastToCEditorCommandDeletePlainText();
    80 	virtual CEditorCommandDeleteCharFormat*
    81 		CastToCEditorCommandDeleteCharFormat();
    82 	virtual CEditorCommandDeleteParFormat*
    83 		CastToCEditorCommandDeleteParFormat();
    84 	};
    85 
    86 //
    87 // command prototypes
    88 //
    89 
    90 /**
    91  * Prototype command for inserting text with specified character and paragraph
    92  * format.
    93  *
    94  * @internalComponent
    95  * @since App-frameworks6.1
    96  */
    97 NONSHARABLE_CLASS(CEditorCommandInsertPlainTextProto) : public CEditorCommand
    98 	{
    99 	MUnifiedEditor&							iTarget;
   100 	TInt								iPos;
   101 	const TDesC*						iText;
   102 
   103 public:
   104 	CEditorCommandInsertPlainTextProto(MUnifiedEditor& aTarget)
   105 		: iTarget(aTarget) {}
   106 	void Set(TInt aPos, const TDesC& aText);
   107 
   108 	UndoSystem::CCommand* CreateInverseL() const;
   109 	TInt ExecuteL() const;
   110 
   111 	TBool PrepareToAddInverseToLastL(UndoSystem::CSingleCommand& aLastCommand) const;
   112 	void AddInverseToLast(UndoSystem::CSingleCommand& aLastCommand) const;
   113 	};
   114 
   115 /**
   116  * Prototype command for deleting text.
   117  *
   118  * @internalComponent
   119  * @since App-frameworks6.1
   120  */
   121 NONSHARABLE_CLASS(CEditorCommandDeletePlainTextProto) : public CEditorCommand
   122 	{
   123 	enum { KMaxCombinableReinsertCharacters = 20 };
   124 
   125 	MUnifiedEditor&	iTarget;
   126 	TInt		iPos;
   127 	TInt		iLength;
   128 	// For adding inverse to last command
   129 	mutable TBuf<KMaxCombinableReinsertCharacters>	iDeletedText;
   130 
   131 public:
   132 	CEditorCommandDeletePlainTextProto(MUnifiedEditor& aTarget)
   133 		: iTarget(aTarget) {}
   134 	void Set(TInt aPos, TInt aLength);
   135 
   136 	UndoSystem::CCommand* CreateInverseL() const;
   137 	TInt ExecuteL() const;
   138 
   139 	TBool PrepareToAddInverseToLastL(UndoSystem::CSingleCommand& aLastCommand) const;
   140 	void AddInverseToLast(UndoSystem::CSingleCommand& aLastCommand) const;
   141 	};
   142 
   143 /**
   144  * Implementation of plain text insertion for use by plain & rich text
   145  * insertion commands.
   146  *
   147  * @internalComponent
   148  * @since App-frameworks6.1
   149  */
   150 class TEditorInsertPlainTextImpl
   151 	{
   152 	MUnifiedEditor&						iTarget;
   153 	TInt							iPos;
   154 	TBuf<KMaxCharsInSingleCommand>	iText;
   155 public:
   156 	TEditorInsertPlainTextImpl(MUnifiedEditor& aTarget, TInt aPos, const TDesC& aText)
   157 		: iTarget(aTarget), iPos(aPos), iText(aText) {}
   158 	MUnifiedEditor& Target() const	{ return iTarget; }
   159 	const TDesC& Text() const	{ return iText; }
   160 	TInt Pos() const			{ return iPos; }
   161 	TInt ExecuteL(const TDesC* aStyle, const TTmCharFormatLayer* aChar,
   162 		const RTmParFormatLayer* aPar) const;
   163 	TInt ExecuteL() const;
   164 	TInt CanAdd(TInt aPos, const TDesC& aText, MUnifiedEditor& aTarget) const;
   165 	void Add(TInt aPos, const TDesC& aText);
   166 	};
   167 
   168 /**
   169  * Implementation of plain text deletion for use by plain & rich text
   170  * deletion commands.
   171  * Used only in the implementation of command objects.
   172  *
   173  * @internalComponent
   174  * @since App-frameworks6.1
   175  */
   176 class TEditorDeletePlainTextImpl
   177 	{
   178 	MUnifiedEditor&	iTarget;
   179 	TInt		iPos;
   180 	TInt		iLength;
   181 
   182 public:
   183 	TEditorDeletePlainTextImpl(MUnifiedEditor& aTarget, TInt aPos,
   184 		TInt aLength) : iTarget(aTarget), iPos(aPos), iLength(aLength) {}
   185 	MUnifiedEditor& Target() const	{ return iTarget; }
   186 	TInt Pos() const			{ return iPos; }
   187 	TInt Length() const			{ return iLength; }
   188 	TInt ExecuteL() const;
   189 	TBool CanAdd(TInt aPos, TInt aLength, MUnifiedEditor& aTarget) const;
   190 	void Add(TInt aLength);
   191 	};
   192 
   193 /**
   194  * Implementation class for pasting text
   195  *
   196  * @internalComponent
   197  * @since App-frameworks6.1
   198  */
   199 class TEditorPasteProtoImpl
   200 	{
   201 	MUnifiedEditor&					iTarget;
   202 	const CStreamStore*			iStore;
   203 	const CStreamDictionary*	iStreamDictionary;
   204 	TInt						iPos;
   205 public:
   206 	TEditorPasteProtoImpl(MUnifiedEditor& aTarget) : iTarget(aTarget) {}
   207 	void Set(const CStreamStore&, const CStreamDictionary&, TInt aPos);
   208 	TInt						Pos() const					{ return iPos; }
   209 	const CStreamStore&			Store() const				{ return *iStore; }
   210 	const CStreamDictionary&	StreamDictionary() const	{ return *iStreamDictionary; }
   211 	MUnifiedEditor&					Target() const				{ return iTarget; }
   212 
   213 	void						OpenPlainTextStreamLC(RStoreReadStream& aStream) const;
   214 	// returns length of text in plain text stream. Leaves with KErrNotSupported
   215 	// if there is no such stream.
   216 	TInt						LengthL() const;
   217 	TInt						ExecuteL() const;
   218 	};
   219 
   220 /**
   221  * Prototype command for pasting plain text.
   222  *
   223  * @internalComponent
   224  * @since App-frameworks6.1
   225  */
   226 NONSHARABLE_CLASS(CEditorCommandPastePlainTextProto) : public CEditorCommand
   227 	{
   228 	TEditorPasteProtoImpl iImpl;
   229 
   230 public:
   231 	CEditorCommandPastePlainTextProto(MUnifiedEditor& aTarget)
   232 		: iImpl(aTarget) {}
   233 	void Set(const CStreamStore& aStore,
   234 		const CStreamDictionary& aStreamDictionary,
   235 		TInt aPos);
   236 
   237 	UndoSystem::CCommand* CreateInverseL() const;
   238 	TInt ExecuteL() const;
   239 	};
   240 
   241 
   242 #endif	// EDITORPLAINTEXTCOMMANDS_H_