textrendering/textformatting/undo/EditorCommands.h
changeset 0 1fb32624e06b
equal deleted inserted replaced
-1:000000000000 0:1fb32624e06b
       
     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 EDITORCOMMANDS_H_
       
    20 #define EDITORCOMMANDS_H_
       
    21 
       
    22 #include "unified_editor.h"
       
    23 #include "UniqueInstance.h"
       
    24 #include "UndoSystem.h"
       
    25 #include "EditorPlainTextCommands.h"
       
    26 
       
    27 // all the combinable commands:
       
    28 class CEditorCommandInsertTextAndFormat;
       
    29 class CEditorCommandDeleteText;
       
    30 class CEditorCommandDeleteCharFormat;
       
    31 class CEditorCommandDeleteParFormat;
       
    32 
       
    33 /**
       
    34  * Pointers to the repositories used by the undo system.
       
    35  *
       
    36  * @internalComponent
       
    37  * @since App-frameworks6.1
       
    38  */
       
    39 struct TRepositories
       
    40 	{
       
    41 	CUniqueInstanceRepository<TTmCharFormat>*	iChar;
       
    42 	CUniqueInstanceRepository<RTmParFormat>*	iPar;
       
    43 	CUniqueInstanceRepository<TDes>*			iDes;
       
    44 	};
       
    45 
       
    46 //
       
    47 // command prototypes
       
    48 //
       
    49 /**
       
    50  * Base class for command prototypes. These prototypes are used to generate
       
    51  * inverses. They do not need any copying to be sent into the undo system,
       
    52  * executed, then recycled. Some also store a pointer to the last generated
       
    53  * inverse so that they can add to it if two similar commands come along
       
    54  * together.
       
    55  *
       
    56  * @internalComponent
       
    57  * @since App-frameworks6.1
       
    58  */
       
    59 class CEditorCommandProto : public CEditorCommand
       
    60 	{
       
    61 	const TRepositories& iReps;
       
    62 public:
       
    63 	CEditorCommandProto(const TRepositories& aReps)
       
    64 		: iReps(aReps) {}
       
    65 	const TRepositories& Repositories() const { return iReps; }
       
    66 	};
       
    67 
       
    68 /**
       
    69  * Prototype command for creating a style.
       
    70  *
       
    71  * @internalComponent
       
    72  * @since App-frameworks6.1
       
    73  */
       
    74 NONSHARABLE_CLASS(CEditorCommandCreateStyleProto) : public CEditorCommandProto
       
    75 	{
       
    76 	MUnifiedEditor&	iTarget;
       
    77 	const RTmStyle*	iStyle;
       
    78 
       
    79 public:
       
    80 	CEditorCommandCreateStyleProto(const TRepositories& aReps, MUnifiedEditor& aTarget)
       
    81 		: CEditorCommandProto(aReps), iTarget(aTarget) {}
       
    82 	void Set(const RTmStyle&);
       
    83 
       
    84 	UndoSystem::CCommand* CreateInverseL() const;
       
    85 	TInt ExecuteL() const;
       
    86 	};
       
    87 
       
    88 /**
       
    89  * Prototype command for setting the attributes of a style.
       
    90  *
       
    91  * @internalComponent
       
    92  * @since App-frameworks6.1
       
    93  */
       
    94 NONSHARABLE_CLASS(CEditorCommandChangeStyleProto) : public CEditorCommandProto
       
    95 	{
       
    96 	MUnifiedEditor&		iTarget;
       
    97 	const RTmStyle*	iStyle;
       
    98 
       
    99 public:
       
   100 	CEditorCommandChangeStyleProto(const TRepositories& aReps, MUnifiedEditor& aTarget)
       
   101 		: CEditorCommandProto(aReps), iTarget(aTarget) {}
       
   102 	void Set(const RTmStyle&);
       
   103 
       
   104 	UndoSystem::CCommand* CreateInverseL() const;
       
   105 	TInt ExecuteL() const;
       
   106 	};
       
   107 
       
   108 /**
       
   109  * Prototype command for applying a style to a run of text.
       
   110  *
       
   111  * @internalComponent
       
   112  * @since App-frameworks6.1
       
   113  */
       
   114 NONSHARABLE_CLASS(CEditorCommandSetStyleProto) : public CEditorCommandProto
       
   115 	{
       
   116 	MUnifiedEditor&			iTarget;
       
   117 	TInt					iPos;
       
   118 	TInt					iLength;
       
   119 	const TDesC*			iName;
       
   120 
       
   121 public:
       
   122 	CEditorCommandSetStyleProto(const TRepositories& aReps, MUnifiedEditor& aTarget)
       
   123 		: CEditorCommandProto(aReps), iTarget(aTarget) {}
       
   124 	void Set(TInt aPos, TInt aLength,
       
   125 		const TDesC& aName);
       
   126 
       
   127 	UndoSystem::CCommand* CreateInverseL() const;
       
   128 	TInt ExecuteL() const;
       
   129 	};
       
   130 
       
   131 /**
       
   132  * Prototype command for deleting a style.
       
   133  *
       
   134  * @internalComponent
       
   135  * @since App-frameworks6.1
       
   136  */
       
   137 NONSHARABLE_CLASS(CEditorCommandDeleteStyleProto) : public CEditorCommandProto
       
   138 	{
       
   139 	MUnifiedEditor&				iTarget;
       
   140 	const TDesC*			iName;
       
   141 
       
   142 public:
       
   143 	CEditorCommandDeleteStyleProto(const TRepositories& aReps, MUnifiedEditor& aTarget)
       
   144 		: CEditorCommandProto(aReps), iTarget(aTarget) {}
       
   145 	void Set(const TDesC& aName);
       
   146 
       
   147 	UndoSystem::CCommand* CreateInverseL() const;
       
   148 	TInt ExecuteL() const;
       
   149 	};
       
   150 
       
   151 /**
       
   152  * Prototype command for setting the character format of a run of text.
       
   153  *
       
   154  * @internalComponent
       
   155  * @since App-frameworks6.1
       
   156  */
       
   157 NONSHARABLE_CLASS(CEditorCommandSetCharFormatProto) : public CEditorCommandProto
       
   158 	{
       
   159 	MUnifiedEditor&				iTarget;
       
   160 	TInt						iPos;
       
   161 	TInt						iLength;
       
   162 	const TTmCharFormatLayer*	iFormat;
       
   163 
       
   164 public:
       
   165 	CEditorCommandSetCharFormatProto(const TRepositories& aReps, MUnifiedEditor& aTarget)
       
   166 		: CEditorCommandProto(aReps), iTarget(aTarget) {}
       
   167 	void Set(TInt aPos,
       
   168 		TInt aLength,
       
   169 		const TTmCharFormatLayer& aFormat);
       
   170 
       
   171 	UndoSystem::CCommand* CreateInverseL() const;
       
   172 	TInt ExecuteL() const;
       
   173 	};
       
   174 
       
   175 /**
       
   176  * Prototype command for setting the paragraph format of a run of text.
       
   177  *
       
   178  * @internalComponent
       
   179  * @since App-frameworks6.1
       
   180  */
       
   181 NONSHARABLE_CLASS(CEditorCommandSetParFormatProto) : public CEditorCommandProto
       
   182 	{
       
   183 	MUnifiedEditor&					iTarget;
       
   184 	TInt						iPos;
       
   185 	TInt						iLength;
       
   186 	const RTmParFormatLayer*	iFormat;
       
   187 
       
   188 public:
       
   189 	CEditorCommandSetParFormatProto(const TRepositories& aReps, MUnifiedEditor& aTarget)
       
   190 		: CEditorCommandProto(aReps), iTarget(aTarget) {}
       
   191 	void Set(TInt aPos,
       
   192 		TInt aLength,
       
   193 		const RTmParFormatLayer& aFormat);
       
   194 
       
   195 	UndoSystem::CCommand* CreateInverseL() const;
       
   196 	TInt ExecuteL() const;
       
   197 	};
       
   198 
       
   199 /**
       
   200  * Prototype command for inserting text with specified character and paragraph
       
   201  * format.
       
   202  *
       
   203  * @internalComponent
       
   204  * @since App-frameworks6.1
       
   205  */
       
   206 NONSHARABLE_CLASS(CEditorCommandInsertProto) : public CEditorCommandProto
       
   207 	{
       
   208 	MUnifiedEditor&						iTarget;
       
   209 	TInt								iPos;
       
   210 	const TDesC*						iText;
       
   211 	const TTmCharFormatLayer*			iCharFormat;
       
   212 	const RTmParFormatLayer*			iParFormat;
       
   213 	const TDesC*						iStyle;
       
   214 
       
   215 public:
       
   216 	CEditorCommandInsertProto(const TRepositories& aReps, MUnifiedEditor& aTarget)
       
   217 		: CEditorCommandProto(aReps), iTarget(aTarget) {}
       
   218 	void Set(TInt aPos,
       
   219 		const TDesC& aText,
       
   220 		const TDesC* aStyle,
       
   221 		const TTmCharFormatLayer* aCharFormat,
       
   222 		const RTmParFormatLayer* aParFormat);
       
   223 
       
   224 	UndoSystem::CCommand* CreateInverseL() const;
       
   225 	TInt ExecuteL() const;
       
   226 
       
   227 	TBool PrepareToAddInverseToLastL(UndoSystem::CSingleCommand& aLastCommand) const;
       
   228 	void AddInverseToLast(UndoSystem::CSingleCommand& aLastCommand) const;
       
   229 	};
       
   230 
       
   231 /**
       
   232  * Prototype command for deleting text.
       
   233  *
       
   234  * @internalComponent
       
   235  * @since App-frameworks6.1
       
   236  */
       
   237 NONSHARABLE_CLASS(CEditorCommandDeleteProto) : public CEditorCommandProto
       
   238 	{
       
   239 	enum { KMaxCombinableReinsertCharacters = 20 };
       
   240 
       
   241 	MUnifiedEditor&	iTarget;
       
   242 	TInt		iPos;
       
   243 	TInt		iLength;
       
   244 	// For adding inverse to last command
       
   245 	mutable TBuf<KMaxCombinableReinsertCharacters>	iDeletedText;
       
   246 
       
   247 public:
       
   248 	CEditorCommandDeleteProto(const TRepositories& aReps, MUnifiedEditor& aTarget)
       
   249 		: CEditorCommandProto(aReps), iTarget(aTarget) {}
       
   250 	void Set(TInt aPos, TInt aLength);
       
   251 
       
   252 	UndoSystem::CCommand* CreateInverseL() const;
       
   253 	TInt ExecuteL() const;
       
   254 
       
   255 	TBool PrepareToAddInverseToLastL(UndoSystem::CSingleCommand& aLastCommand) const;
       
   256 	void AddInverseToLast(UndoSystem::CSingleCommand& aLastCommand) const;
       
   257 	};
       
   258 
       
   259 /**
       
   260  * Prototype command for setting the base format.
       
   261  *
       
   262  * @internalComponent
       
   263  * @since App-frameworks6.1
       
   264  */
       
   265 NONSHARABLE_CLASS(CEditorCommandSetBaseFormatProto) : public CEditorCommandProto
       
   266 	{
       
   267 	MUnifiedEditor&			iTarget;
       
   268 	const TTmCharFormat*	iChar;
       
   269 	const RTmParFormat*		iPar;
       
   270 
       
   271 public:
       
   272 	CEditorCommandSetBaseFormatProto(const TRepositories& aReps, MUnifiedEditor& aTarget)
       
   273 		: CEditorCommandProto(aReps), iTarget(aTarget) {}
       
   274 	void Set(const TTmCharFormat* aCharFormat, const RTmParFormat* aParFormat);
       
   275 
       
   276 	UndoSystem::CCommand* CreateInverseL() const;
       
   277 	TInt ExecuteL() const;
       
   278 	};
       
   279 
       
   280 /**
       
   281  * Prototype command for deleting specific character formatting.
       
   282  *
       
   283  * @internalComponent
       
   284  * @since App-frameworks6.1
       
   285  */
       
   286 NONSHARABLE_CLASS(CEditorCommandDeleteCharFormatProto) : public CEditorCommandProto
       
   287 	{
       
   288 	MUnifiedEditor&	iTarget;
       
   289 	TInt		iPos;
       
   290 	TInt		iLength;
       
   291 
       
   292 public:
       
   293 	CEditorCommandDeleteCharFormatProto(const TRepositories& aReps, MUnifiedEditor& aTarget)
       
   294 		: CEditorCommandProto(aReps), iTarget(aTarget) {}
       
   295 	void Set(TInt aPos, TInt aLength);
       
   296 
       
   297 	UndoSystem::CCommand* CreateInverseL() const;
       
   298 	TInt ExecuteL() const;
       
   299 	};
       
   300 
       
   301 /**
       
   302  * Prototype command for deleting specific paragraph formatting.
       
   303  *
       
   304  * @internalComponent
       
   305  * @since App-frameworks6.1
       
   306  */
       
   307 NONSHARABLE_CLASS(CEditorCommandDeleteParFormatProto) : public CEditorCommandProto
       
   308 	{
       
   309 	MUnifiedEditor&	iTarget;
       
   310 	TInt		iPos;
       
   311 	TInt		iLength;
       
   312 
       
   313 public:
       
   314 	CEditorCommandDeleteParFormatProto(const TRepositories& aReps, MUnifiedEditor& aTarget)
       
   315 		: CEditorCommandProto(aReps), iTarget(aTarget) {}
       
   316 	void Set(TInt aPos, TInt aLength);
       
   317 
       
   318 	UndoSystem::CCommand* CreateInverseL() const;
       
   319 	TInt ExecuteL() const;
       
   320 	};
       
   321 
       
   322 /**
       
   323  * Prototype command for deleting a picture.
       
   324  *
       
   325  * @internalComponent
       
   326  * @since App-frameworks6.1
       
   327  */
       
   328 NONSHARABLE_CLASS(CEditorCommandDeletePictureProto) : public CEditorCommandProto
       
   329 	{
       
   330 	MUnifiedEditor&	iTarget;
       
   331 	TInt		iPos;
       
   332 
       
   333 public:
       
   334 	CEditorCommandDeletePictureProto(const TRepositories& aReps, MUnifiedEditor& aTarget)
       
   335 		: CEditorCommandProto(aReps), iTarget(aTarget) {}
       
   336 	void Set(TInt aPos);
       
   337 
       
   338 	TInt ExecuteL() const;
       
   339 	};
       
   340 
       
   341 /**
       
   342  * Prototype command for inserting a picture.
       
   343  *
       
   344  * @internalComponent
       
   345  * @since App-frameworks6.1
       
   346  */
       
   347 NONSHARABLE_CLASS(CEditorCommandInsertPictureProto) : public CEditorCommandProto
       
   348 	{
       
   349 	MUnifiedEditor&			iTarget;
       
   350 	TInt					iPos;
       
   351 	const TPictureHeader*	iPicture;
       
   352 
       
   353 public:
       
   354 	CEditorCommandInsertPictureProto(const TRepositories& aReps, MUnifiedEditor& aTarget)
       
   355 		: CEditorCommandProto(aReps), iTarget(aTarget) {}
       
   356 	void Set(TInt aPos, const TPictureHeader& picture);
       
   357 
       
   358 	UndoSystem::CCommand* CreateInverseL() const;
       
   359 	TInt ExecuteL() const;
       
   360 	};
       
   361 
       
   362 /**
       
   363  * Prototype command for renaming a style.
       
   364  *
       
   365  * @internalComponent
       
   366  * @since App-frameworks6.1
       
   367  */
       
   368 NONSHARABLE_CLASS(CEditorCommandRenameStyleProto) : public CEditorCommandProto
       
   369 	{
       
   370 	MUnifiedEditor&		iTarget;
       
   371 	const TDesC*	iOldName;
       
   372 	const TDesC*	iNewName;
       
   373 
       
   374 public:
       
   375 	CEditorCommandRenameStyleProto(const TRepositories& aReps, MUnifiedEditor& aTarget)
       
   376 		: CEditorCommandProto(aReps), iTarget(aTarget) {}
       
   377 	void Set(const TDesC& aOldName, const TDesC& aNewName);
       
   378 
       
   379 	UndoSystem::CCommand* CreateInverseL() const;
       
   380 	TInt ExecuteL() const;
       
   381 	};
       
   382 
       
   383 /**
       
   384  * Prototype command for pasting text.
       
   385  *
       
   386  * @internalComponent
       
   387  * @since App-frameworks6.1
       
   388  */
       
   389 NONSHARABLE_CLASS(CEditorCommandPasteProto) : public CEditorCommandProto
       
   390 	{
       
   391 	TEditorPasteProtoImpl iImpl;
       
   392 
       
   393 public:
       
   394 	CEditorCommandPasteProto(const TRepositories& aReps, MUnifiedEditor& aTarget)
       
   395 		: CEditorCommandProto(aReps), iImpl(aTarget) {}
       
   396 	void Set(const CStreamStore& aStore,
       
   397 		const CStreamDictionary& aStreamDictionary,
       
   398 		TInt aPos);
       
   399 
       
   400 	UndoSystem::CCommand* CreateInverseL() const;
       
   401 	TInt ExecuteL() const;
       
   402 	};
       
   403 
       
   404 /**
       
   405  * Owner of a picture which will eventually pass on ownership.
       
   406  *
       
   407  * @internalComponent
       
   408  * @since App-frameworks6.1
       
   409  */
       
   410 class MPictureOwner
       
   411 	{
       
   412 public:
       
   413 	/**
       
   414 	 * Forgets the delegate that has been made next in line for
       
   415 	 * the picture.
       
   416 	 */
       
   417 	virtual void ForgetDelegate() = 0;
       
   418 	};
       
   419 
       
   420 class CEditorCommandInsertPicture;
       
   421 
       
   422 /**
       
   423  * Prototype command for deleting a picture from the text without
       
   424  * returning ownership.
       
   425  *
       
   426  * @internalComponent
       
   427  * @since App-frameworks6.1
       
   428  */
       
   429 NONSHARABLE_CLASS(CEditorCommandDestroyPictureProto) : public CEditorCommandProto,
       
   430 	private MPictureOwner
       
   431 	{
       
   432 	MUnifiedEditor&								iTarget;
       
   433 	TInt									iPos;
       
   434 	/**
       
   435 	 * Will own picture after us.
       
   436 	 */
       
   437 	mutable CEditorCommandInsertPicture*	iPictureOwnerDelegate;
       
   438 
       
   439 	void ForgetDelegate();
       
   440 public:
       
   441 	CEditorCommandDestroyPictureProto(const TRepositories& aReps, MUnifiedEditor& aTarget)
       
   442 		: CEditorCommandProto(aReps), iTarget(aTarget) {}
       
   443 	~CEditorCommandDestroyPictureProto();
       
   444 	void Set(TInt aPos);
       
   445 
       
   446 	UndoSystem::CCommand* CreateInverseL() const;
       
   447 	TInt ExecuteL() const;
       
   448 	};
       
   449 
       
   450 namespace UndoSystem
       
   451 	{
       
   452 	/**
       
   453 	 * Finds the position of the first picture in the text. Returns
       
   454 	 * 'KNotFound' if there are none. This will not return any
       
   455 	 * picture characters that do not have attatched pictures.
       
   456 	 *
       
   457 	 * @internalComponent
       
   458 	 * @since App-frameworks6.1
       
   459 	 */
       
   460 	TInt FindPicture(const MUnifiedEditor& aTarget, TInt aPos, TInt aLength);
       
   461 	}
       
   462 
       
   463 #endif	// EDITORCOMMANDS_H_