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