os/textandloc/textrendering/textformatting/undo/EditorCommands.cpp
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
#include "EditorCommands.h"
sl@0
    20
#include "AssertFileAndLine.h"
sl@0
    21
#include <txtetext.h>
sl@0
    22
#include <s32ucmp.h>
sl@0
    23
sl@0
    24
using namespace UndoSystem;
sl@0
    25
sl@0
    26
inline TBool IsSurrogate(TText a) { return 0xD800 == (a & 0xF800); }
sl@0
    27
inline TBool IsHighSurrogate(TText a) { return 0xD800 == (a & 0xFC00); }
sl@0
    28
inline TBool IsLowSurrogate(TText a) { return 0xDC00 == (a & 0xFC00); }
sl@0
    29
inline TChar JoinSurrogates(TText aHigh, TText aLow)
sl@0
    30
	{
sl@0
    31
	return ((aHigh - 0xd7f7) << 10) + aLow;
sl@0
    32
	}
sl@0
    33
sl@0
    34
// These roughly mirror the prototype commands, but rather than
sl@0
    35
// referencing externally-owned (and therefore temporary) objects,
sl@0
    36
// they own objects. Typically these are unique instances.
sl@0
    37
sl@0
    38
/**
sl@0
    39
 * Command for setting the base character and paragraph formats.
sl@0
    40
 *
sl@0
    41
 * @internalComponent
sl@0
    42
 * @since App-frameworks6.1
sl@0
    43
 */
sl@0
    44
NONSHARABLE_CLASS(CEditorCommandSetBaseFormat) : public CEditorCommand
sl@0
    45
	{
sl@0
    46
	MUnifiedEditor&						iTarget;
sl@0
    47
	RUniqueInstance<TTmCharFormat>	iChar;
sl@0
    48
	RUniqueInstance<RTmParFormat>	iPar;
sl@0
    49
sl@0
    50
	const TRepositories& iRepositories;
sl@0
    51
sl@0
    52
	CEditorCommandSetBaseFormat(const TRepositories& aReps, MUnifiedEditor& aTarget);
sl@0
    53
public:
sl@0
    54
	~CEditorCommandSetBaseFormat();
sl@0
    55
	static CEditorCommandSetBaseFormat* NewL(const TRepositories& aReps,
sl@0
    56
		const TTmCharFormat& aCharFormat, const RTmParFormat& aParFormat,
sl@0
    57
		MUnifiedEditor& aTarget);
sl@0
    58
	static CEditorCommandSetBaseFormat* NewL(const TRepositories& aReps,
sl@0
    59
		MUnifiedEditor& aTarget);
sl@0
    60
sl@0
    61
	UndoSystem::CCommand* CreateInverseL() const;
sl@0
    62
	TInt ExecuteL() const;
sl@0
    63
	};
sl@0
    64
sl@0
    65
/**
sl@0
    66
 * Command for renaming a style.
sl@0
    67
 *
sl@0
    68
 * @internalComponent
sl@0
    69
 * @since App-frameworks6.1
sl@0
    70
 */
sl@0
    71
NONSHARABLE_CLASS(CEditorCommandRenameStyle) : public CEditorCommand
sl@0
    72
	{
sl@0
    73
	MUnifiedEditor&				iTarget;
sl@0
    74
	RUniqueInstance<TDes>	iOldName;
sl@0
    75
	RUniqueInstance<TDes>	iNewName;
sl@0
    76
sl@0
    77
	const TRepositories& iRepositories;
sl@0
    78
sl@0
    79
	CEditorCommandRenameStyle(const TRepositories& aReps, MUnifiedEditor& aTarget)
sl@0
    80
		: iTarget(aTarget), iOldName(*aReps.iDes), iNewName(*aReps.iDes),
sl@0
    81
		iRepositories(aReps) {}
sl@0
    82
public:
sl@0
    83
	~CEditorCommandRenameStyle();
sl@0
    84
	static CEditorCommandRenameStyle* NewL(const TRepositories& aReps,
sl@0
    85
		const TDesC& aOldName, const TDesC& aNewName, MUnifiedEditor& aTarget);
sl@0
    86
sl@0
    87
	CCommand* CreateInverseL() const;
sl@0
    88
	TInt ExecuteL() const;
sl@0
    89
	};
sl@0
    90
sl@0
    91
/**
sl@0
    92
 * Command for inserting a picture into the text.
sl@0
    93
 *
sl@0
    94
 * @internalComponent
sl@0
    95
 * @since App-frameworks6.1
sl@0
    96
 */
sl@0
    97
NONSHARABLE_CLASS(CEditorCommandInsertPicture) : public CEditorCommand
sl@0
    98
	{
sl@0
    99
	MUnifiedEditor&				iTarget;
sl@0
   100
	TInt					iPos;
sl@0
   101
	mutable TPictureHeader	iPicture;
sl@0
   102
	MPictureOwner*			iPictureOwner;
sl@0
   103
	const TRepositories&	iRepositories;
sl@0
   104
sl@0
   105
	CEditorCommandInsertPicture(const TRepositories& aReps, MUnifiedEditor& aTarget)
sl@0
   106
		: iTarget(aTarget), iRepositories(aReps) {}
sl@0
   107
public:
sl@0
   108
	~CEditorCommandInsertPicture();
sl@0
   109
	static CEditorCommandInsertPicture* NewL(const TRepositories& aReps,
sl@0
   110
		TInt aPos, MPictureOwner& aPictureOwner, MUnifiedEditor& aTarget);
sl@0
   111
	void TakePictureOwnership(TPictureHeader&);
sl@0
   112
	void ForgetOwner(MPictureOwner*);
sl@0
   113
sl@0
   114
	CCommand* CreateInverseL() const;
sl@0
   115
	TInt ExecuteL() const;
sl@0
   116
	};
sl@0
   117
sl@0
   118
/**
sl@0
   119
 * Command for creating a new style.
sl@0
   120
 *
sl@0
   121
 * @internalComponent
sl@0
   122
 * @since App-frameworks6.1
sl@0
   123
 */
sl@0
   124
NONSHARABLE_CLASS(CEditorCommandCreateStyle) : public CEditorCommand
sl@0
   125
	{
sl@0
   126
	MUnifiedEditor&					iTarget;
sl@0
   127
	RUniqueInstance<TDes>			iName;
sl@0
   128
	RUniqueInstance<TDes>			iNext;
sl@0
   129
	RUniqueInstance<TTmCharFormat>	iChar;
sl@0
   130
	TTmCharFormatMask				iCharMask;
sl@0
   131
	RUniqueInstance<RTmParFormat>	iPar;
sl@0
   132
	TTmParFormatMask				iParMask;
sl@0
   133
	TInt							iLevel;
sl@0
   134
sl@0
   135
	const TRepositories& iRepositories;
sl@0
   136
sl@0
   137
	CEditorCommandCreateStyle(const TRepositories& aReps, MUnifiedEditor& aTarget)
sl@0
   138
		: iTarget(aTarget), iName(*aReps.iDes), iNext(*aReps.iDes),
sl@0
   139
		iChar(*aReps.iChar),
sl@0
   140
		iPar(*aReps.iPar), iRepositories(aReps) {}
sl@0
   141
public:
sl@0
   142
	~CEditorCommandCreateStyle();
sl@0
   143
	static CEditorCommandCreateStyle* NewL(const TRepositories& aReps,
sl@0
   144
		const TDesC& aName, const TDesC& aNext,
sl@0
   145
		TTmCharFormat& aChar, TTmCharFormatMask aCharMask,
sl@0
   146
		RTmParFormat& aPar, TTmParFormatMask aParMask,
sl@0
   147
		TInt aLevel, MUnifiedEditor& aTarget);
sl@0
   148
	static CEditorCommandCreateStyle* NewL(const TRepositories& aReps,
sl@0
   149
		const TDesC& aName, MUnifiedEditor& aTarget);
sl@0
   150
	static CCommand* NewBatchL(const TRepositories& aReps,
sl@0
   151
		const TDesC& aName, MUnifiedEditor& aTarget);
sl@0
   152
sl@0
   153
	CCommand* CreateInverseL() const;
sl@0
   154
	TInt ExecuteL() const;
sl@0
   155
	};
sl@0
   156
sl@0
   157
/**
sl@0
   158
 * Command for deleting a style, removing it from anywhere that it is applied.
sl@0
   159
 *
sl@0
   160
 * @internalComponent
sl@0
   161
 * @since App-frameworks6.1
sl@0
   162
 */
sl@0
   163
NONSHARABLE_CLASS(CEditorCommandDeleteStyle) : public CEditorCommand
sl@0
   164
	{
sl@0
   165
	MUnifiedEditor&						iTarget;
sl@0
   166
	RUniqueInstance<TDes>				iName;
sl@0
   167
	const TRepositories& iRepositories;
sl@0
   168
sl@0
   169
	CEditorCommandDeleteStyle(const TRepositories& aReps, MUnifiedEditor& aTarget)
sl@0
   170
		: iTarget(aTarget), iName(*aReps.iDes), iRepositories(aReps) {}
sl@0
   171
public:
sl@0
   172
	~CEditorCommandDeleteStyle();
sl@0
   173
	static CEditorCommandDeleteStyle* NewL(const TRepositories& aReps,
sl@0
   174
		const TDesC& aName, MUnifiedEditor& aTarget);
sl@0
   175
sl@0
   176
	CCommand* CreateInverseL() const;
sl@0
   177
	TInt ExecuteL() const;
sl@0
   178
	};
sl@0
   179
sl@0
   180
/**
sl@0
   181
 * Command for altering the attributes of a style.
sl@0
   182
 *
sl@0
   183
 * @internalComponent
sl@0
   184
 * @since App-frameworks6.1
sl@0
   185
 */
sl@0
   186
NONSHARABLE_CLASS(CEditorCommandAlterStyle) : public CEditorCommand
sl@0
   187
	{
sl@0
   188
	MUnifiedEditor&					iTarget;
sl@0
   189
	RUniqueInstance<TDes>			iName;
sl@0
   190
	RUniqueInstance<TDes>			iNext;
sl@0
   191
	RUniqueInstance<TTmCharFormat>	iChar;
sl@0
   192
	TTmCharFormatMask				iCharMask;
sl@0
   193
	RUniqueInstance<RTmParFormat>	iPar;
sl@0
   194
	TTmParFormatMask				iParMask;
sl@0
   195
	TInt							iLevel;
sl@0
   196
sl@0
   197
	const TRepositories& iRepositories;
sl@0
   198
sl@0
   199
	CEditorCommandAlterStyle(const TRepositories& aReps, MUnifiedEditor& aTarget)
sl@0
   200
		: iTarget(aTarget), iName(*aReps.iDes), iNext(*aReps.iDes),
sl@0
   201
		iChar(*aReps.iChar), iPar(*aReps.iPar), iRepositories(aReps) {}
sl@0
   202
public:
sl@0
   203
	~CEditorCommandAlterStyle();
sl@0
   204
	static CEditorCommandAlterStyle* NewL(const TRepositories& aReps,
sl@0
   205
		const TDesC& aName, const TDesC& aNext,
sl@0
   206
		TTmCharFormat& aChar, TTmCharFormatMask& aCharMask,
sl@0
   207
		RTmParFormat& aPar, TTmParFormatMask& aParMask,
sl@0
   208
		TInt aLevel, MUnifiedEditor& aTarget);
sl@0
   209
	static CEditorCommandAlterStyle* NewL(const TRepositories& aReps,
sl@0
   210
		const TDesC& aName, MUnifiedEditor& aTarget);
sl@0
   211
sl@0
   212
	CCommand* CreateInverseL() const;
sl@0
   213
	TInt ExecuteL() const;
sl@0
   214
	};
sl@0
   215
sl@0
   216
/**
sl@0
   217
 * Command for applying an existing style to text.
sl@0
   218
 *
sl@0
   219
 * @internalComponent
sl@0
   220
 * @since App-frameworks6.1
sl@0
   221
 */
sl@0
   222
NONSHARABLE_CLASS(CEditorCommandSetStyle) : public CEditorCommand
sl@0
   223
	{
sl@0
   224
	MUnifiedEditor&			iTarget;
sl@0
   225
	RUniqueInstance<TDes>	iName;
sl@0
   226
	TInt					iPos;
sl@0
   227
	TInt					iRunLength;
sl@0
   228
sl@0
   229
	const TRepositories& iRepositories;
sl@0
   230
sl@0
   231
	CEditorCommandSetStyle(const TRepositories& aReps, MUnifiedEditor& aTarget)
sl@0
   232
		: iTarget(aTarget), iName(*aReps.iDes), iRepositories(aReps) {}
sl@0
   233
public:
sl@0
   234
	~CEditorCommandSetStyle();
sl@0
   235
	static CEditorCommandSetStyle* NewL(const TRepositories& aReps,
sl@0
   236
		const TDesC& aName, TInt aPos, TInt aRunLength,
sl@0
   237
		MUnifiedEditor& aTarget);
sl@0
   238
	static CCommand* NewL(const TRepositories& aReps,
sl@0
   239
		TInt aPos, TInt aRunLength,
sl@0
   240
		MUnifiedEditor& aTarget);
sl@0
   241
sl@0
   242
	CCommand* CreateInverseL() const;
sl@0
   243
	TInt ExecuteL() const;
sl@0
   244
	};
sl@0
   245
sl@0
   246
/**
sl@0
   247
 * Command for deleting text without pictures in it.
sl@0
   248
 *
sl@0
   249
 * @internalComponent
sl@0
   250
 * @since App-frameworks6.1
sl@0
   251
 */
sl@0
   252
NONSHARABLE_CLASS(CEditorCommandDeleteText) : public CEditorCommand
sl@0
   253
	{
sl@0
   254
	TEditorDeletePlainTextImpl iImpl;
sl@0
   255
	const TRepositories& iRepositories;		// only used in creating the inverse
sl@0
   256
sl@0
   257
	CEditorCommandDeleteText*
sl@0
   258
		CastToCEditorCommandDeleteText() { return this; }
sl@0
   259
sl@0
   260
	CEditorCommandDeleteText(const TRepositories& aReps, MUnifiedEditor& aTarget,
sl@0
   261
		TInt aPos, TInt aLength)
sl@0
   262
		: iImpl(aTarget, aPos, aLength), iRepositories(aReps) {}
sl@0
   263
public:
sl@0
   264
	~CEditorCommandDeleteText();
sl@0
   265
	static CEditorCommandDeleteText* NewL(const TRepositories& aReps,
sl@0
   266
		TInt aPos, TInt aLength, MUnifiedEditor& aTarget);
sl@0
   267
sl@0
   268
	CCommand* CreateInverseL() const;
sl@0
   269
	TInt ExecuteL() const;
sl@0
   270
sl@0
   271
	// This command can be coalesced with others of the same type
sl@0
   272
	TBool CanAdd(TInt aPos, TInt aLength, MUnifiedEditor& aTarget) const;
sl@0
   273
	void Add(TInt aLength);
sl@0
   274
	};
sl@0
   275
sl@0
   276
/**
sl@0
   277
 * Command for inserting text in a specified style and format.
sl@0
   278
 *
sl@0
   279
 * @internalComponent
sl@0
   280
 * @since App-frameworks6.1
sl@0
   281
 */
sl@0
   282
NONSHARABLE_CLASS(CEditorCommandInsertTextAndFormat) : public CEditorCommand
sl@0
   283
	{
sl@0
   284
	TEditorInsertPlainTextImpl		iImpl;
sl@0
   285
	// layer
sl@0
   286
	RUniqueInstance<TTmCharFormat>	iChar;
sl@0
   287
	TTmCharFormatMask				iCharMask;
sl@0
   288
	RUniqueInstance<RTmParFormat>	iPar;
sl@0
   289
	TTmParFormatMask				iParMask;
sl@0
   290
	RUniqueInstance<TDes>			iStyle;
sl@0
   291
sl@0
   292
	const TRepositories& iRepositories;
sl@0
   293
sl@0
   294
	CEditorCommandInsertTextAndFormat*
sl@0
   295
		CastToCEditorCommandInsertTextAndFormat() { return this; }
sl@0
   296
	CEditorCommandInsertTextAndFormat(const TRepositories& aReps,
sl@0
   297
		MUnifiedEditor& aTarget, TInt aPos, TDesC& aText)
sl@0
   298
		: iImpl(aTarget, aPos, aText), iChar(*aReps.iChar), iPar(*aReps.iPar),
sl@0
   299
		iStyle(*aReps.iDes), iRepositories(aReps) {}
sl@0
   300
public:
sl@0
   301
	struct RTextAndFormatParameters
sl@0
   302
		{
sl@0
   303
		TInt				iPos;
sl@0
   304
		TPtrC				iText;
sl@0
   305
		TPtrC				iStyleName;
sl@0
   306
		TTmCharFormatLayer	iChar;
sl@0
   307
		RTmParFormatLayer	iPar;
sl@0
   308
sl@0
   309
		void Close();
sl@0
   310
		void SetL(TInt aPos, TInt aMaxLength, MUnifiedEditor& aTarget);
sl@0
   311
		};
sl@0
   312
	~CEditorCommandInsertTextAndFormat();
sl@0
   313
	static CEditorCommandInsertTextAndFormat* NewL(const TRepositories& aReps,
sl@0
   314
		RTextAndFormatParameters& aParams, MUnifiedEditor& aTarget);
sl@0
   315
sl@0
   316
	/**
sl@0
   317
	 * Gets as much of a run as possible.
sl@0
   318
	 */
sl@0
   319
	static CEditorCommandInsertTextAndFormat* NewL(const TRepositories& aReps,
sl@0
   320
		TInt aPos, TInt& aRemaining, TInt aOriginalPos, MUnifiedEditor& aTarget);
sl@0
   321
sl@0
   322
	/**
sl@0
   323
	 * Gets as many runs as necessary and returns a batch if necessary.
sl@0
   324
	 */
sl@0
   325
	static CCommand* NewBatchL(const TRepositories& aReps,
sl@0
   326
		TInt aPos, TInt aLength, MUnifiedEditor& aTarget);
sl@0
   327
sl@0
   328
	CCommand* CreateInverseL() const;
sl@0
   329
	TInt ExecuteL() const;
sl@0
   330
sl@0
   331
	// This command can be coalesced with others of the same type
sl@0
   332
	TBool CanAdd(const RTextAndFormatParameters&, MUnifiedEditor& aTarget) const;
sl@0
   333
	void Add(TInt aPos, const TDesC& aText);
sl@0
   334
	};
sl@0
   335
sl@0
   336
/**
sl@0
   337
 * Command for deleting the specific character format over a run of text.
sl@0
   338
 *
sl@0
   339
 * @internalComponent
sl@0
   340
 * @since App-frameworks6.1
sl@0
   341
 */
sl@0
   342
NONSHARABLE_CLASS(CEditorCommandDeleteCharFormat) : public CEditorCommand
sl@0
   343
	{
sl@0
   344
	MUnifiedEditor&	iTarget;
sl@0
   345
	TInt		iPos;
sl@0
   346
	TInt		iLength;
sl@0
   347
sl@0
   348
	const TRepositories& iRepositories;
sl@0
   349
sl@0
   350
	CEditorCommandDeleteCharFormat*
sl@0
   351
		CastToCEditorCommandDeleteCharFormat() { return this; }
sl@0
   352
sl@0
   353
	CEditorCommandDeleteCharFormat(const TRepositories& aReps, MUnifiedEditor& aTarget)
sl@0
   354
		: iTarget(aTarget), iRepositories(aReps) {}
sl@0
   355
public:
sl@0
   356
	~CEditorCommandDeleteCharFormat();
sl@0
   357
	static CEditorCommandDeleteCharFormat* NewL(const TRepositories& aReps,
sl@0
   358
		TInt aPos, TInt aLength,
sl@0
   359
		MUnifiedEditor& aTarget);
sl@0
   360
sl@0
   361
	CCommand* CreateInverseL() const;
sl@0
   362
	TInt ExecuteL() const;
sl@0
   363
sl@0
   364
	// This command can be coalesced with others of the same type
sl@0
   365
	TBool CanAdd(TInt aPos, TInt aLength, MUnifiedEditor& aTarget) const;
sl@0
   366
	void Add(TInt aPos, TInt aLength);
sl@0
   367
	};
sl@0
   368
sl@0
   369
/**
sl@0
   370
 * Command for deleting the specific paragraph format over a run of text.
sl@0
   371
 *
sl@0
   372
 * @internalComponent
sl@0
   373
 * @since App-frameworks6.1
sl@0
   374
 */
sl@0
   375
NONSHARABLE_CLASS(CEditorCommandDeleteParFormat) : public CEditorCommand
sl@0
   376
	{
sl@0
   377
	MUnifiedEditor&	iTarget;
sl@0
   378
	TInt		iPos;
sl@0
   379
	TInt		iLength;
sl@0
   380
sl@0
   381
	const TRepositories& iRepositories;
sl@0
   382
sl@0
   383
	CEditorCommandDeleteParFormat*
sl@0
   384
		CastToCEditorCommandDeleteParFormat() { return this; }
sl@0
   385
sl@0
   386
	CEditorCommandDeleteParFormat(const TRepositories& aReps, MUnifiedEditor& aTarget)
sl@0
   387
		: iTarget(aTarget), iRepositories(aReps) {}
sl@0
   388
public:
sl@0
   389
	~CEditorCommandDeleteParFormat();
sl@0
   390
	static CEditorCommandDeleteParFormat* NewL(const TRepositories& aReps,
sl@0
   391
		TInt aPos, TInt aLength,
sl@0
   392
		MUnifiedEditor& aTarget);
sl@0
   393
sl@0
   394
	CCommand* CreateInverseL() const;
sl@0
   395
	TInt ExecuteL() const;
sl@0
   396
sl@0
   397
	// This command can be coalesced with others of the same type
sl@0
   398
	TBool CanAdd(TInt aPos, TInt aLength, MUnifiedEditor& aTarget) const;
sl@0
   399
	void Add(TInt aPos, TInt aLength);
sl@0
   400
	};
sl@0
   401
sl@0
   402
/**
sl@0
   403
 * Command for applying a character format to a run of text that has no
sl@0
   404
 * existing specific character format.
sl@0
   405
 *
sl@0
   406
 * @internalComponent
sl@0
   407
 * @since App-frameworks6.1
sl@0
   408
 */
sl@0
   409
NONSHARABLE_CLASS(CEditorCommandSetCharFormat) : public CEditorCommand
sl@0
   410
	{
sl@0
   411
	MUnifiedEditor&						iTarget;
sl@0
   412
	TInt							iPos;
sl@0
   413
	TInt							iLength;
sl@0
   414
	// layer
sl@0
   415
	RUniqueInstance<TTmCharFormat>	iChar;
sl@0
   416
	TTmCharFormatMask				iCharMask;
sl@0
   417
sl@0
   418
	const TRepositories& iRepositories;
sl@0
   419
sl@0
   420
	CEditorCommandSetCharFormat(const TRepositories& aReps, MUnifiedEditor& aTarget)
sl@0
   421
		: iTarget(aTarget), iChar(*aReps.iChar), iRepositories(aReps) {}
sl@0
   422
public:
sl@0
   423
	~CEditorCommandSetCharFormat();
sl@0
   424
	static CEditorCommandSetCharFormat* NewL(const TRepositories& aReps,
sl@0
   425
		TInt aPos, TInt aLength,
sl@0
   426
		const TTmCharFormat* aChar, TTmCharFormatMask aCharMask,
sl@0
   427
		MUnifiedEditor& aTarget);
sl@0
   428
sl@0
   429
	// get as much of a run as possible.
sl@0
   430
	static CEditorCommandSetCharFormat* NewL(const TRepositories& aReps,
sl@0
   431
		TInt aPos, TInt& aRemaining, MUnifiedEditor& aTarget);
sl@0
   432
sl@0
   433
	// get as many runs as necessary and return a batch if necessary.
sl@0
   434
	static CCommand* NewBatchL(const TRepositories& aReps,
sl@0
   435
		TInt aPos, TInt aLength, MUnifiedEditor& aTarget);
sl@0
   436
sl@0
   437
	TBool PrepareToAddInverseToLastL(CSingleCommand& aLastCommand) const;
sl@0
   438
	void AddInverseToLast(CSingleCommand& aLastCommand) const;
sl@0
   439
	CCommand* CreateInverseL() const;
sl@0
   440
	TInt ExecuteL() const;
sl@0
   441
	};
sl@0
   442
sl@0
   443
/**
sl@0
   444
 * Command for applying a paragraph format to a run of text that has no
sl@0
   445
 * existing specific paragraph format.
sl@0
   446
 *
sl@0
   447
 * @internalComponent
sl@0
   448
 * @since App-frameworks6.1
sl@0
   449
 */
sl@0
   450
NONSHARABLE_CLASS(CEditorCommandSetParFormat) : public CEditorCommand
sl@0
   451
	{
sl@0
   452
	MUnifiedEditor&					iTarget;
sl@0
   453
	TInt							iPos;
sl@0
   454
	TInt							iLength;
sl@0
   455
	// layer
sl@0
   456
	RUniqueInstance<RTmParFormat>	iPar;
sl@0
   457
	TTmParFormatMask				iParMask;
sl@0
   458
sl@0
   459
	const TRepositories& iRepositories;
sl@0
   460
sl@0
   461
	CEditorCommandSetParFormat(const TRepositories& aReps, MUnifiedEditor& aTarget)
sl@0
   462
		: iTarget(aTarget), iPar(*aReps.iPar), iRepositories(aReps) {}
sl@0
   463
public:
sl@0
   464
	~CEditorCommandSetParFormat();
sl@0
   465
	static CEditorCommandSetParFormat* NewL(const TRepositories& aReps,
sl@0
   466
		TInt aPos, TInt aLength,
sl@0
   467
		const RTmParFormat* aFormat, TTmParFormatMask aMask,
sl@0
   468
		MUnifiedEditor& aTarget);
sl@0
   469
sl@0
   470
	// get as much of a run as possible.
sl@0
   471
	static CEditorCommandSetParFormat* NewL(const TRepositories& aReps,
sl@0
   472
		TInt aPos, TInt& aRemaining, MUnifiedEditor& aTarget);
sl@0
   473
sl@0
   474
	// get as many runs as necessary and return a batch if necessary.
sl@0
   475
	static CCommand* NewBatchL(const TRepositories& aReps,
sl@0
   476
		TInt aPos, TInt aLength, MUnifiedEditor& aTarget);
sl@0
   477
sl@0
   478
	TBool PrepareToAddInverseToLastL(CSingleCommand& aLastCommand) const;
sl@0
   479
	void AddInverseToLast(CSingleCommand& aLastCommand) const;
sl@0
   480
	CCommand* CreateInverseL() const;
sl@0
   481
	TInt ExecuteL() const;
sl@0
   482
	};
sl@0
   483
sl@0
   484
/**
sl@0
   485
 * Command for deleting a picture from the text. The picture is assumed
sl@0
   486
 * to be without significant formatting.
sl@0
   487
 *
sl@0
   488
 * @internalComponent
sl@0
   489
 * @since App-frameworks6.1
sl@0
   490
 */
sl@0
   491
NONSHARABLE_CLASS(CEditorCommandDeletePicture) : public CEditorCommand,
sl@0
   492
	private MPictureOwner
sl@0
   493
	{
sl@0
   494
	MUnifiedEditor&							iTarget;
sl@0
   495
	TInt									iPos;
sl@0
   496
	const TRepositories&					iRepositories;
sl@0
   497
	/**
sl@0
   498
	 * Will own picture after us.
sl@0
   499
	 */
sl@0
   500
	mutable CEditorCommandInsertPicture*	iPictureOwnerDelegate;
sl@0
   501
sl@0
   502
	void ForgetDelegate();
sl@0
   503
	CEditorCommandDeletePicture(const TRepositories& aReps, MUnifiedEditor& aTarget)
sl@0
   504
		: iTarget(aTarget), iRepositories(aReps) {}
sl@0
   505
public:
sl@0
   506
	~CEditorCommandDeletePicture();
sl@0
   507
	static CEditorCommandDeletePicture* NewL(const TRepositories& aReps,
sl@0
   508
		TInt aPos, MUnifiedEditor& aTarget);
sl@0
   509
sl@0
   510
	UndoSystem::CCommand* CreateInverseL() const;
sl@0
   511
	TInt ExecuteL() const;
sl@0
   512
	};
sl@0
   513
sl@0
   514
///////////////////////////////////
sl@0
   515
//								 //
sl@0
   516
//	CEditorCommandSetBaseFormat  //
sl@0
   517
//								 //
sl@0
   518
///////////////////////////////////
sl@0
   519
sl@0
   520
CEditorCommandSetBaseFormat::CEditorCommandSetBaseFormat(
sl@0
   521
	const TRepositories& aReps, MUnifiedEditor& aTarget)
sl@0
   522
	: iTarget(aTarget), iChar(*aReps.iChar), iPar(*aReps.iPar),
sl@0
   523
	iRepositories(aReps)
sl@0
   524
	{
sl@0
   525
	}
sl@0
   526
sl@0
   527
CEditorCommandSetBaseFormat::~CEditorCommandSetBaseFormat()
sl@0
   528
	{
sl@0
   529
	iChar.Close();
sl@0
   530
	iPar.Close();
sl@0
   531
	}
sl@0
   532
sl@0
   533
CEditorCommandSetBaseFormat* CEditorCommandSetBaseFormat::NewL(
sl@0
   534
	const TRepositories& aReps,
sl@0
   535
	const TTmCharFormat& aCharFormat, const RTmParFormat& aParFormat,
sl@0
   536
	MUnifiedEditor& aTarget)
sl@0
   537
	{
sl@0
   538
	CEditorCommandSetBaseFormat* r
sl@0
   539
		= new(ELeave) CEditorCommandSetBaseFormat(aReps, aTarget);
sl@0
   540
	CleanupStack::PushL(r);
sl@0
   541
	r->iChar.TakeCopyL(&aCharFormat);
sl@0
   542
	r->iPar.TakeCopyL(&aParFormat);
sl@0
   543
	CleanupStack::Pop();
sl@0
   544
	return r;
sl@0
   545
	}
sl@0
   546
sl@0
   547
CEditorCommandSetBaseFormat* CEditorCommandSetBaseFormat::NewL(
sl@0
   548
	const TRepositories& aReps, MUnifiedEditor& aTarget)
sl@0
   549
	{
sl@0
   550
	TTmCharFormat c;
sl@0
   551
	RTmParFormat p;
sl@0
   552
	CleanupClosePushL(p);
sl@0
   553
	aTarget.GetBaseFormatL(c, p);
sl@0
   554
	CEditorCommandSetBaseFormat* r = NewL(aReps, c, p, aTarget);
sl@0
   555
	CleanupStack::PopAndDestroy();
sl@0
   556
	return r;
sl@0
   557
	}
sl@0
   558
sl@0
   559
CCommand* CEditorCommandSetBaseFormat::CreateInverseL() const
sl@0
   560
	{
sl@0
   561
	return NewL(iRepositories, iTarget);
sl@0
   562
	}
sl@0
   563
sl@0
   564
TInt CEditorCommandSetBaseFormat::ExecuteL() const
sl@0
   565
	{
sl@0
   566
	iTarget.SetBaseFormatL(*iChar.Peek(), *iPar.Peek());
sl@0
   567
	return KErrNone;
sl@0
   568
	}
sl@0
   569
sl@0
   570
/////////////////////////////////
sl@0
   571
//							   //
sl@0
   572
//	CEditorCommandRenameStyle  //
sl@0
   573
//							   //
sl@0
   574
/////////////////////////////////
sl@0
   575
sl@0
   576
CEditorCommandRenameStyle::~CEditorCommandRenameStyle()
sl@0
   577
	{
sl@0
   578
	iOldName.Close();
sl@0
   579
	iNewName.Close();
sl@0
   580
	}
sl@0
   581
sl@0
   582
CEditorCommandRenameStyle* CEditorCommandRenameStyle::NewL(
sl@0
   583
	const TRepositories& aReps,
sl@0
   584
	const TDesC& aOldName, const TDesC& aNewName, MUnifiedEditor& aTarget)
sl@0
   585
	{
sl@0
   586
	CEditorCommandRenameStyle* r =
sl@0
   587
		new(ELeave) CEditorCommandRenameStyle(aReps, aTarget);
sl@0
   588
	CleanupStack::PushL(r);
sl@0
   589
	r->iOldName.TakeCopyL(&aOldName);
sl@0
   590
	r->iNewName.TakeCopyL(&aNewName);
sl@0
   591
	CleanupStack::Pop(r);
sl@0
   592
	return r;
sl@0
   593
	}
sl@0
   594
sl@0
   595
CCommand* CEditorCommandRenameStyle::CreateInverseL() const
sl@0
   596
	{
sl@0
   597
	return NewL(iRepositories, *iNewName.Peek(), *iOldName.Peek(), iTarget);
sl@0
   598
	}
sl@0
   599
sl@0
   600
TInt CEditorCommandRenameStyle::ExecuteL() const
sl@0
   601
	{
sl@0
   602
	MUnifiedEditor::MStyleSupport* si = iTarget.StyleSupport();
sl@0
   603
	ASSERT(si);
sl@0
   604
	return si->RenameStyleL(*iOldName.Peek(), *iNewName.Peek());
sl@0
   605
	}
sl@0
   606
sl@0
   607
///////////////////////////////////
sl@0
   608
//								 //
sl@0
   609
//	CEditorCommandInsertPicture  //
sl@0
   610
//								 //
sl@0
   611
///////////////////////////////////
sl@0
   612
sl@0
   613
CEditorCommandInsertPicture::~CEditorCommandInsertPicture()
sl@0
   614
	{
sl@0
   615
	if (iPictureOwner)
sl@0
   616
		iPictureOwner->ForgetDelegate();
sl@0
   617
	iPicture.DeletePicture();
sl@0
   618
	}
sl@0
   619
sl@0
   620
CEditorCommandInsertPicture* CEditorCommandInsertPicture::NewL(
sl@0
   621
	const TRepositories& aReps,
sl@0
   622
	TInt aPos, MPictureOwner& aPictureOwner, MUnifiedEditor& aTarget)
sl@0
   623
	{
sl@0
   624
	CEditorCommandInsertPicture* r = new(ELeave)
sl@0
   625
		CEditorCommandInsertPicture(aReps, aTarget);
sl@0
   626
	r->iPictureOwner = &aPictureOwner;
sl@0
   627
	r->iPos = aPos;
sl@0
   628
	return r;
sl@0
   629
	}
sl@0
   630
sl@0
   631
void CEditorCommandInsertPicture::TakePictureOwnership(TPictureHeader& aPic)
sl@0
   632
	{
sl@0
   633
	iPicture = aPic;
sl@0
   634
	iPictureOwner = 0;
sl@0
   635
	}
sl@0
   636
sl@0
   637
void CEditorCommandInsertPicture::ForgetOwner(MPictureOwner*
sl@0
   638
#ifdef _DEBUG
sl@0
   639
	aOwner
sl@0
   640
#endif
sl@0
   641
	)
sl@0
   642
	{
sl@0
   643
	ASSERT(aOwner == iPictureOwner);
sl@0
   644
	iPictureOwner = 0;
sl@0
   645
	}
sl@0
   646
sl@0
   647
CCommand* CEditorCommandInsertPicture::CreateInverseL() const
sl@0
   648
	{
sl@0
   649
	return CEditorCommandDeletePicture::NewL(iRepositories, iPos, iTarget);
sl@0
   650
	}
sl@0
   651
sl@0
   652
TInt CEditorCommandInsertPicture::ExecuteL() const
sl@0
   653
	{
sl@0
   654
	ASSERT(iPictureOwner == 0);
sl@0
   655
	MUnifiedEditor::MPictureSupport* pi = iTarget.PictureSupport();
sl@0
   656
	ASSERT(pi);
sl@0
   657
	pi->InsertPictureL(iPos, iPicture);
sl@0
   658
	iPicture.iPicture = 0;
sl@0
   659
	iPicture.iPictureType = KNullUid;
sl@0
   660
	return KErrNone;
sl@0
   661
	}
sl@0
   662
sl@0
   663
sl@0
   664
///////////////////////////////////
sl@0
   665
//								 //
sl@0
   666
//	CEditorCommandDeletePicture  //
sl@0
   667
//								 //
sl@0
   668
///////////////////////////////////
sl@0
   669
sl@0
   670
CEditorCommandDeletePicture::~CEditorCommandDeletePicture()
sl@0
   671
	{
sl@0
   672
	if (iPictureOwnerDelegate)
sl@0
   673
		iPictureOwnerDelegate->ForgetOwner(this);
sl@0
   674
	}
sl@0
   675
sl@0
   676
void CEditorCommandDeletePicture::ForgetDelegate()
sl@0
   677
	{
sl@0
   678
	iPictureOwnerDelegate = 0;
sl@0
   679
	}
sl@0
   680
sl@0
   681
CEditorCommandDeletePicture* CEditorCommandDeletePicture::NewL(
sl@0
   682
	const TRepositories& aReps, TInt aPos, MUnifiedEditor& aTarget)
sl@0
   683
	{
sl@0
   684
	CEditorCommandDeletePicture* r =
sl@0
   685
		new(ELeave) CEditorCommandDeletePicture(aReps, aTarget);
sl@0
   686
	r->iPos = aPos;
sl@0
   687
	return r;
sl@0
   688
	}
sl@0
   689
sl@0
   690
CCommand* CEditorCommandDeletePicture::CreateInverseL() const
sl@0
   691
	{
sl@0
   692
	CEditorCommandDeletePicture* nonConstThis =
sl@0
   693
		const_cast<CEditorCommandDeletePicture*>(this);	//yuck
sl@0
   694
	CEditorCommandInsertPicture* inv =
sl@0
   695
		CEditorCommandInsertPicture::NewL(iRepositories, iPos,
sl@0
   696
		*nonConstThis, iTarget);
sl@0
   697
	CleanupStack::PushL(inv);
sl@0
   698
sl@0
   699
	if (iPictureOwnerDelegate)
sl@0
   700
		iPictureOwnerDelegate->ForgetOwner(nonConstThis);
sl@0
   701
sl@0
   702
	iPictureOwnerDelegate = inv;
sl@0
   703
	CleanupStack::Pop(inv);
sl@0
   704
sl@0
   705
	return inv;
sl@0
   706
	}
sl@0
   707
sl@0
   708
TInt CEditorCommandDeletePicture::ExecuteL() const
sl@0
   709
	{
sl@0
   710
	MUnifiedEditor::MPictureSupport* pi = iTarget.PictureSupport();
sl@0
   711
	ASSERT(pi);
sl@0
   712
	TPictureHeader pic;
sl@0
   713
	pi->Picture(iPos, pic);
sl@0
   714
	pi->DropPictureL(iPos);
sl@0
   715
	if (iPictureOwnerDelegate)
sl@0
   716
		{
sl@0
   717
		iPictureOwnerDelegate->TakePictureOwnership(pic);
sl@0
   718
		iPictureOwnerDelegate = 0;
sl@0
   719
		}
sl@0
   720
	else
sl@0
   721
		pic.DeletePicture();
sl@0
   722
	return KErrNone;
sl@0
   723
	}
sl@0
   724
sl@0
   725
/////////////////////////////////
sl@0
   726
//							   //
sl@0
   727
//	CEditorCommandCreateStyle  //
sl@0
   728
//							   //
sl@0
   729
/////////////////////////////////
sl@0
   730
sl@0
   731
CEditorCommandCreateStyle* CEditorCommandCreateStyle::NewL(const TRepositories& aReps,
sl@0
   732
 		const TDesC& aName, const TDesC& aNext,
sl@0
   733
		TTmCharFormat& aChar, TTmCharFormatMask aCharMask,
sl@0
   734
		RTmParFormat& aPar, TTmParFormatMask aParMask,
sl@0
   735
		TInt aLevel, MUnifiedEditor& aTarget)
sl@0
   736
	{
sl@0
   737
	CEditorCommandCreateStyle* p = new(ELeave) CEditorCommandCreateStyle(aReps, aTarget);
sl@0
   738
	CleanupStack::PushL(p);
sl@0
   739
	p->iName.TakeCopyL(&aName);
sl@0
   740
	p->iNext.TakeCopyL(&aNext);
sl@0
   741
	p->iChar.TakeCopyL(&aChar);
sl@0
   742
	p->iCharMask = aCharMask;
sl@0
   743
	p->iPar.TakeCopyL(&aPar);
sl@0
   744
	p->iParMask = aParMask;
sl@0
   745
	p->iLevel = aLevel;
sl@0
   746
	CleanupStack::Pop(p);
sl@0
   747
	return p;
sl@0
   748
	}
sl@0
   749
CEditorCommandCreateStyle* CEditorCommandCreateStyle::NewL(const TRepositories& aReps,
sl@0
   750
	const TDesC& aName, MUnifiedEditor& aTarget)
sl@0
   751
	{
sl@0
   752
	RTmStyle style;
sl@0
   753
	MUnifiedEditor::MStyleSupport* si = aTarget.StyleSupport();
sl@0
   754
	ASSERT(si);
sl@0
   755
	si->GetStyleByNameL(aName, style);
sl@0
   756
	CleanupClosePushL(style);
sl@0
   757
	CEditorCommandCreateStyle* p = NewL(aReps, aName, style.iNextStyleName,
sl@0
   758
		style.iCharFormat.iFormat, style.iCharFormat.iMask,
sl@0
   759
		style.iParFormat.iFormat, style.iParFormat.iMask,
sl@0
   760
		style.iOutlineLevel, aTarget);
sl@0
   761
	CleanupStack::PopAndDestroy();
sl@0
   762
	return p;
sl@0
   763
	}
sl@0
   764
sl@0
   765
CCommand* CEditorCommandCreateStyle::NewBatchL(const TRepositories& aReps,
sl@0
   766
											   const TDesC& aName,
sl@0
   767
											   MUnifiedEditor& aTarget)
sl@0
   768
	{
sl@0
   769
	CCommand* inverse = 0;
sl@0
   770
	MUnifiedEditor::MStyleSupport* si = aTarget.StyleSupport();
sl@0
   771
	ASSERT(si);
sl@0
   772
sl@0
   773
	TInt remainingLength = aTarget.DocumentLength();
sl@0
   774
	TInt currentPosition = 0;
sl@0
   775
	// got to be careful.. GetStyleL() can return KMaxTInt as the run length!
sl@0
   776
	// luckily, any nonnegative TInt - KMaxTInt gives a negative TInt
sl@0
   777
	while (0 < remainingLength)
sl@0
   778
		{
sl@0
   779
		TInt runLength;
sl@0
   780
		TPtrC name;
sl@0
   781
		si->GetStyle(currentPosition, name, runLength);
sl@0
   782
		if (name == aName)
sl@0
   783
			{
sl@0
   784
			CleanupStack::PushL(inverse);
sl@0
   785
	// coverity[double_free]
sl@0
   786
			inverse = CoalesceL(inverse,
sl@0
   787
				CEditorCommandSetStyle::NewL(aReps, aName,
sl@0
   788
					currentPosition, runLength, aTarget));
sl@0
   789
			CleanupStack::Pop();
sl@0
   790
			}
sl@0
   791
		currentPosition += runLength;
sl@0
   792
		remainingLength -= runLength;
sl@0
   793
		}
sl@0
   794
sl@0
   795
	CleanupStack::PushL(inverse);
sl@0
   796
	// coverity[double_free]
sl@0
   797
	inverse = CoalesceL(inverse,
sl@0
   798
		CEditorCommandCreateStyle::NewL(aReps, aName, aTarget));
sl@0
   799
	CleanupStack::Pop();
sl@0
   800
	return inverse;
sl@0
   801
	}
sl@0
   802
sl@0
   803
CEditorCommandCreateStyle::~CEditorCommandCreateStyle()
sl@0
   804
	{
sl@0
   805
	iName.Close();
sl@0
   806
	iNext.Close();
sl@0
   807
	iChar.Close();
sl@0
   808
	iPar.Close();
sl@0
   809
	}
sl@0
   810
sl@0
   811
CCommand* CEditorCommandCreateStyle::CreateInverseL() const
sl@0
   812
	{
sl@0
   813
	return CEditorCommandDeleteStyle::NewL(iRepositories, *iName.Peek(), iTarget);
sl@0
   814
	}
sl@0
   815
sl@0
   816
TInt CEditorCommandCreateStyle::ExecuteL() const
sl@0
   817
	{
sl@0
   818
	RTmStyle style;
sl@0
   819
	CleanupClosePushL(style);
sl@0
   820
	style.iName = *iName.Peek();
sl@0
   821
	style.iNextStyleName = *iNext.Peek();
sl@0
   822
	style.iCharFormat.iFormat = *iChar.Peek();
sl@0
   823
	style.iCharFormat.iMask = iCharMask;
sl@0
   824
	style.iParFormat.iFormat.CopyL( *iPar.Peek() );
sl@0
   825
	style.iParFormat.iMask.iFlags = iParMask.iFlags;
sl@0
   826
	style.iOutlineLevel = iLevel;
sl@0
   827
	MUnifiedEditor::MStyleSupport* si = iTarget.StyleSupport();
sl@0
   828
	ASSERT(si);
sl@0
   829
	TInt err = si->CreateStyleL(style);
sl@0
   830
	CleanupStack::PopAndDestroy();
sl@0
   831
	return err;
sl@0
   832
	}
sl@0
   833
sl@0
   834
/////////////////////////////////
sl@0
   835
//							   //
sl@0
   836
//	CEditorCommandDeleteStyle  //
sl@0
   837
//							   //
sl@0
   838
/////////////////////////////////
sl@0
   839
sl@0
   840
CEditorCommandDeleteStyle* CEditorCommandDeleteStyle::NewL(const TRepositories& aReps,
sl@0
   841
 		const TDesC& aName, MUnifiedEditor& aTarget)
sl@0
   842
	{
sl@0
   843
	CEditorCommandDeleteStyle* p = new(ELeave) CEditorCommandDeleteStyle(aReps, aTarget);
sl@0
   844
	CleanupStack::PushL(p);
sl@0
   845
	p->iName.TakeCopyL(&aName);
sl@0
   846
	CleanupStack::Pop(p);
sl@0
   847
	return p;
sl@0
   848
	}
sl@0
   849
sl@0
   850
CEditorCommandDeleteStyle::~CEditorCommandDeleteStyle()
sl@0
   851
	{
sl@0
   852
	iName.Close();
sl@0
   853
	}
sl@0
   854
sl@0
   855
CCommand* CEditorCommandDeleteStyle::CreateInverseL() const
sl@0
   856
	{
sl@0
   857
	return CEditorCommandCreateStyle::NewBatchL(iRepositories, *iName.Peek(), iTarget);
sl@0
   858
	}
sl@0
   859
sl@0
   860
TInt CEditorCommandDeleteStyle::ExecuteL() const
sl@0
   861
	{
sl@0
   862
	MUnifiedEditor::MStyleSupport* si = iTarget.StyleSupport();
sl@0
   863
	ASSERT(si);
sl@0
   864
	return si->DeleteStyleL(*iName.Peek());
sl@0
   865
	}
sl@0
   866
sl@0
   867
////////////////////////////////
sl@0
   868
//							  //
sl@0
   869
//	CEditorCommandAlterStyle  //
sl@0
   870
//							  //
sl@0
   871
////////////////////////////////
sl@0
   872
sl@0
   873
CEditorCommandAlterStyle* CEditorCommandAlterStyle::NewL(const TRepositories& aReps,
sl@0
   874
 		const TDesC& aName, const TDesC& aNext,
sl@0
   875
		TTmCharFormat& aChar, TTmCharFormatMask& aCharMask,
sl@0
   876
		RTmParFormat& aPar, TTmParFormatMask& aParMask,
sl@0
   877
		TInt aLevel, MUnifiedEditor& aTarget)
sl@0
   878
	{
sl@0
   879
	CEditorCommandAlterStyle* p = new(ELeave) CEditorCommandAlterStyle(aReps, aTarget);
sl@0
   880
	CleanupStack::PushL(p);
sl@0
   881
	p->iName.TakeCopyL(&aName);
sl@0
   882
	p->iNext.TakeCopyL(&aNext);
sl@0
   883
	p->iChar.TakeCopyL(&aChar);
sl@0
   884
	p->iCharMask = aCharMask;
sl@0
   885
	p->iPar.TakeCopyL(&aPar);
sl@0
   886
	p->iParMask = aParMask;
sl@0
   887
	p->iLevel = aLevel;
sl@0
   888
	CleanupStack::Pop(p);
sl@0
   889
	return p;
sl@0
   890
	}
sl@0
   891
sl@0
   892
CEditorCommandAlterStyle* CEditorCommandAlterStyle::NewL(const TRepositories& aReps,
sl@0
   893
	const TDesC& aName, MUnifiedEditor& aTarget)
sl@0
   894
	{
sl@0
   895
	RTmStyle style;
sl@0
   896
	CleanupClosePushL(style);
sl@0
   897
	MUnifiedEditor::MStyleSupport* si = aTarget.StyleSupport();
sl@0
   898
	ASSERT(si);
sl@0
   899
	si->GetStyleByNameL(aName, style);
sl@0
   900
	CEditorCommandAlterStyle* p = NewL(aReps, aName, style.iNextStyleName,
sl@0
   901
		style.iCharFormat.iFormat, style.iCharFormat.iMask,
sl@0
   902
		style.iParFormat.iFormat, style.iParFormat.iMask,
sl@0
   903
		style.iOutlineLevel, aTarget);
sl@0
   904
	CleanupStack::PopAndDestroy();
sl@0
   905
	return p;
sl@0
   906
	}
sl@0
   907
sl@0
   908
CEditorCommandAlterStyle::~CEditorCommandAlterStyle()
sl@0
   909
	{
sl@0
   910
	iName.Close();
sl@0
   911
	iNext.Close();
sl@0
   912
	iChar.Close();
sl@0
   913
	iPar.Close();
sl@0
   914
	}
sl@0
   915
sl@0
   916
CCommand* CEditorCommandAlterStyle::CreateInverseL() const
sl@0
   917
	{
sl@0
   918
	return NewL(iRepositories, *iName.Peek(), iTarget);
sl@0
   919
	}
sl@0
   920
sl@0
   921
TInt CEditorCommandAlterStyle::ExecuteL() const
sl@0
   922
	{
sl@0
   923
	RTmStyle style;
sl@0
   924
	CleanupClosePushL(style);
sl@0
   925
	MUnifiedEditor::MStyleSupport* si = iTarget.StyleSupport();
sl@0
   926
	ASSERT(si);
sl@0
   927
	si->GetStyleByNameL(*iName.Peek(), style);
sl@0
   928
	style.iCharFormat.iFormat	= *iChar.Peek();
sl@0
   929
	style.iCharFormat.iMask		= iCharMask;
sl@0
   930
	style.iParFormat.iFormat.CopyL( *iPar.Peek() );
sl@0
   931
	style.iParFormat.iMask		= iParMask;
sl@0
   932
	style.iOutlineLevel			= iLevel;
sl@0
   933
	style.iName					= *iName.Peek();
sl@0
   934
	style.iNextStyleName		= *iNext.Peek();
sl@0
   935
	TInt err = si->ChangeStyleL(style);
sl@0
   936
	CleanupStack::PopAndDestroy();
sl@0
   937
	return err;
sl@0
   938
	}
sl@0
   939
sl@0
   940
//////////////////////////////
sl@0
   941
//							//
sl@0
   942
//	CEditorCommandSetStyle  //
sl@0
   943
//							//
sl@0
   944
//////////////////////////////
sl@0
   945
sl@0
   946
CEditorCommandSetStyle::~CEditorCommandSetStyle()
sl@0
   947
	{
sl@0
   948
	iName.Close();
sl@0
   949
	}
sl@0
   950
sl@0
   951
CEditorCommandSetStyle* CEditorCommandSetStyle::NewL(const TRepositories& aReps,
sl@0
   952
	const TDesC& aName, TInt aPos, TInt aRunLength, MUnifiedEditor& aTarget)
sl@0
   953
	{
sl@0
   954
	CEditorCommandSetStyle* r = new (ELeave) CEditorCommandSetStyle(aReps, aTarget);
sl@0
   955
	CleanupStack::PushL(r);
sl@0
   956
	r->iName.TakeCopyL(&aName);
sl@0
   957
	r->iPos = aPos;
sl@0
   958
	r->iRunLength = aRunLength;
sl@0
   959
	CleanupStack::Pop(r);
sl@0
   960
	return r;
sl@0
   961
	}
sl@0
   962
sl@0
   963
CCommand* CEditorCommandSetStyle::NewL(
sl@0
   964
	const TRepositories& aReps, TInt aPos, TInt aRunLength, MUnifiedEditor& aTarget)
sl@0
   965
	{
sl@0
   966
	CCommand* inverse = 0;
sl@0
   967
	MUnifiedEditor::MStyleSupport* si = aTarget.StyleSupport();
sl@0
   968
	ASSERT(si);
sl@0
   969
	while (0 < aRunLength)
sl@0
   970
		{
sl@0
   971
		TPtrC name;
sl@0
   972
		TInt runLength;
sl@0
   973
		si->GetStyle(aPos, name, runLength);
sl@0
   974
		if (aRunLength < runLength)
sl@0
   975
			runLength = aRunLength;
sl@0
   976
		CleanupStack::PushL(inverse);
sl@0
   977
		// coverity[double_free]
sl@0
   978
		inverse = CoalesceL(inverse, NewL(aReps, name, aPos, runLength, aTarget));
sl@0
   979
		CleanupStack::Pop();
sl@0
   980
		aPos += runLength;
sl@0
   981
		aRunLength -= runLength;
sl@0
   982
		}
sl@0
   983
	return inverse;
sl@0
   984
	}
sl@0
   985
sl@0
   986
CCommand* CEditorCommandSetStyle::CreateInverseL() const
sl@0
   987
	{
sl@0
   988
	return NewL(iRepositories, iPos, iRunLength, iTarget);
sl@0
   989
	}
sl@0
   990
sl@0
   991
TInt CEditorCommandSetStyle::ExecuteL() const
sl@0
   992
	{
sl@0
   993
	MUnifiedEditor::MStyleSupport* si = iTarget.StyleSupport();
sl@0
   994
	ASSERT(si);
sl@0
   995
	return si->SetStyleL(iPos, iRunLength, *iName.Peek());
sl@0
   996
	}
sl@0
   997
sl@0
   998
////////////////////////////////
sl@0
   999
//							  //
sl@0
  1000
//	CEditorCommandDeleteText  //
sl@0
  1001
//							  //
sl@0
  1002
////////////////////////////////
sl@0
  1003
sl@0
  1004
CEditorCommandDeleteText::~CEditorCommandDeleteText() {}
sl@0
  1005
sl@0
  1006
CEditorCommandDeleteText* CEditorCommandDeleteText::NewL(const TRepositories& aReps,
sl@0
  1007
	TInt aPos, TInt aLength, MUnifiedEditor& aTarget)
sl@0
  1008
	{
sl@0
  1009
	return new(ELeave) CEditorCommandDeleteText(aReps,
sl@0
  1010
		aTarget, aPos, aLength);
sl@0
  1011
	}
sl@0
  1012
sl@0
  1013
CCommand* CEditorCommandDeleteText::CreateInverseL() const
sl@0
  1014
	{
sl@0
  1015
	return CEditorCommandInsertTextAndFormat::NewBatchL(
sl@0
  1016
		iRepositories, iImpl.Pos(), iImpl.Length(), iImpl.Target());
sl@0
  1017
	}
sl@0
  1018
sl@0
  1019
TInt CEditorCommandDeleteText::ExecuteL() const
sl@0
  1020
	{
sl@0
  1021
	return iImpl.ExecuteL();
sl@0
  1022
	}
sl@0
  1023
sl@0
  1024
TBool CEditorCommandDeleteText::CanAdd(TInt aPos, TInt aLength, MUnifiedEditor& aTarget) const
sl@0
  1025
	{
sl@0
  1026
	return iImpl.CanAdd(aPos, aLength, aTarget);
sl@0
  1027
	}
sl@0
  1028
sl@0
  1029
void CEditorCommandDeleteText::Add(TInt aLength)
sl@0
  1030
	{
sl@0
  1031
	iImpl.Add(aLength);
sl@0
  1032
	}
sl@0
  1033
sl@0
  1034
/////////////////////////////////////////
sl@0
  1035
//									   //
sl@0
  1036
//	CEditorCommandInsertTextAndFormat  //
sl@0
  1037
//									   //
sl@0
  1038
/////////////////////////////////////////
sl@0
  1039
sl@0
  1040
CEditorCommandInsertTextAndFormat::~CEditorCommandInsertTextAndFormat()
sl@0
  1041
	{
sl@0
  1042
	iChar.Close();
sl@0
  1043
	iPar.Close();
sl@0
  1044
	iStyle.Close();
sl@0
  1045
	}
sl@0
  1046
sl@0
  1047
CEditorCommandInsertTextAndFormat* CEditorCommandInsertTextAndFormat::NewL(
sl@0
  1048
	const TRepositories& aReps,
sl@0
  1049
	CEditorCommandInsertTextAndFormat::RTextAndFormatParameters& aParams,
sl@0
  1050
	MUnifiedEditor& aTarget)
sl@0
  1051
	{
sl@0
  1052
	ASSERT(aParams.iText.Length() <= KMaxCharsInSingleCommand);
sl@0
  1053
	CEditorCommandInsertTextAndFormat* r = new(ELeave)
sl@0
  1054
		CEditorCommandInsertTextAndFormat(aReps, aTarget, aParams.iPos, aParams.iText);
sl@0
  1055
	CleanupStack::PushL(r);
sl@0
  1056
	r->iChar.TakeCopyL(&aParams.iChar.iFormat);
sl@0
  1057
	r->iCharMask = aParams.iChar.iMask;
sl@0
  1058
	r->iPar.TakeCopyL(&aParams.iPar.iFormat);
sl@0
  1059
	r->iParMask.iFlags = aParams.iPar.iMask.iFlags;
sl@0
  1060
	r->iStyle.TakeCopyL(&aParams.iStyleName);
sl@0
  1061
	CleanupStack::Pop(r);
sl@0
  1062
	return r;
sl@0
  1063
	}
sl@0
  1064
sl@0
  1065
void CEditorCommandInsertTextAndFormat::RTextAndFormatParameters::Close()
sl@0
  1066
	{
sl@0
  1067
	iPar.Close();
sl@0
  1068
	}
sl@0
  1069
sl@0
  1070
void CEditorCommandInsertTextAndFormat::RTextAndFormatParameters::SetL(
sl@0
  1071
	TInt aPos, TInt aMaxLength, MUnifiedEditor& aTarget)
sl@0
  1072
	{
sl@0
  1073
	iPos = aPos;
sl@0
  1074
	aTarget.GetText(aPos, iText);
sl@0
  1075
sl@0
  1076
	TInt length = iText.Length();
sl@0
  1077
sl@0
  1078
	TInt charLength;
sl@0
  1079
	aTarget.GetCharFormat(aPos, MUnifiedEditor::ESpecific, iChar, charLength);
sl@0
  1080
sl@0
  1081
	TInt parLength;
sl@0
  1082
	aTarget.GetParFormatL(aPos, MUnifiedEditor::ESpecific, iPar, parLength);
sl@0
  1083
sl@0
  1084
	TInt styleLength = length;
sl@0
  1085
	MUnifiedEditor::MStyleSupport* si = aTarget.StyleSupport();
sl@0
  1086
	if (si)
sl@0
  1087
		si->GetStyle(aPos, iStyleName, styleLength);
sl@0
  1088
	else
sl@0
  1089
		iStyleName.Set(TPtrC());
sl@0
  1090
sl@0
  1091
	if (charLength < length)
sl@0
  1092
		length = charLength;
sl@0
  1093
	if (parLength < length)
sl@0
  1094
		length = parLength;
sl@0
  1095
	if (styleLength < length)
sl@0
  1096
		length = styleLength;
sl@0
  1097
	if (aMaxLength < length)
sl@0
  1098
		length = aMaxLength;
sl@0
  1099
	if (KMaxCharsInSingleCommand < length)
sl@0
  1100
		length = KMaxCharsInSingleCommand;
sl@0
  1101
	iText.Set(iText.Ptr(), length);
sl@0
  1102
	}
sl@0
  1103
sl@0
  1104
CEditorCommandInsertTextAndFormat* CEditorCommandInsertTextAndFormat::NewL(
sl@0
  1105
	const TRepositories& aReps, TInt aPos, TInt& aRemaining,
sl@0
  1106
	TInt aOriginalPos, MUnifiedEditor& aTarget)
sl@0
  1107
	{
sl@0
  1108
	RTextAndFormatParameters params;
sl@0
  1109
	CleanupClosePushL(params);
sl@0
  1110
	params.SetL(aPos, aRemaining, aTarget);
sl@0
  1111
sl@0
  1112
	params.iPos = aOriginalPos;
sl@0
  1113
	CEditorCommandInsertTextAndFormat* p = NewL(aReps, params, aTarget);
sl@0
  1114
	aRemaining -= params.iText.Length();
sl@0
  1115
sl@0
  1116
	CleanupStack::PopAndDestroy();
sl@0
  1117
sl@0
  1118
	return p;
sl@0
  1119
	}
sl@0
  1120
sl@0
  1121
CCommand* CEditorCommandInsertTextAndFormat::NewBatchL(const TRepositories& aReps,
sl@0
  1122
	TInt aPos, TInt aLength, MUnifiedEditor& aTarget)
sl@0
  1123
	{
sl@0
  1124
	CCommand* command = 0;
sl@0
  1125
	TInt oldLength = aLength + 1;
sl@0
  1126
	TInt end = aPos + aLength;
sl@0
  1127
	// while there is still some length to go and there is still some
sl@0
  1128
	// text to be got
sl@0
  1129
	while (0 < aLength && aLength < oldLength)
sl@0
  1130
		{
sl@0
  1131
		oldLength = aLength;
sl@0
  1132
		CleanupStack::PushL(command);
sl@0
  1133
		// coverity[double_free]
sl@0
  1134
		command = CoalesceL(command,
sl@0
  1135
			NewL(aReps, end - aLength, aLength, aPos, aTarget));
sl@0
  1136
		CleanupStack::Pop();
sl@0
  1137
		}
sl@0
  1138
sl@0
  1139
	return command;
sl@0
  1140
	}
sl@0
  1141
sl@0
  1142
CCommand* CEditorCommandInsertTextAndFormat::CreateInverseL() const
sl@0
  1143
	{
sl@0
  1144
	return CEditorCommandDeleteText::NewL(iRepositories,
sl@0
  1145
		iImpl.Pos(), iImpl.Text().Length(), iImpl.Target());
sl@0
  1146
	}
sl@0
  1147
sl@0
  1148
TInt CEditorCommandInsertTextAndFormat::ExecuteL() const
sl@0
  1149
	{
sl@0
  1150
	TTmCharFormatLayer charLayer;
sl@0
  1151
	RTmParFormatLayer parLayer;
sl@0
  1152
sl@0
  1153
	TTmCharFormatLayer* pCharLayer = 0;
sl@0
  1154
	RTmParFormatLayer* pParLayer = 0;
sl@0
  1155
sl@0
  1156
	if (iChar.Peek())
sl@0
  1157
		{
sl@0
  1158
		charLayer.iFormat = *iChar.Peek();
sl@0
  1159
		charLayer.iMask = iCharMask;
sl@0
  1160
		pCharLayer = &charLayer;
sl@0
  1161
		}
sl@0
  1162
	if (iPar.Peek())
sl@0
  1163
		{
sl@0
  1164
		parLayer.iFormat.CopyL( *iPar.Peek() );
sl@0
  1165
		parLayer.iMask = iParMask;
sl@0
  1166
		pParLayer = &parLayer;
sl@0
  1167
		CleanupClosePushL(parLayer);
sl@0
  1168
		}
sl@0
  1169
	TInt result = iImpl.ExecuteL(iStyle.Peek(), pCharLayer, pParLayer);
sl@0
  1170
	if (pParLayer)
sl@0
  1171
		CleanupStack::PopAndDestroy();
sl@0
  1172
	return result;
sl@0
  1173
	}
sl@0
  1174
sl@0
  1175
TBool CEditorCommandInsertTextAndFormat::CanAdd(
sl@0
  1176
	const CEditorCommandInsertTextAndFormat::RTextAndFormatParameters& aParams,
sl@0
  1177
	MUnifiedEditor& aTarget) const
sl@0
  1178
	{
sl@0
  1179
	if (!iImpl.CanAdd(aParams.iPos, aParams.iText, aTarget))
sl@0
  1180
		return EFalse;
sl@0
  1181
	if (!iChar.Peek())
sl@0
  1182
		return EFalse;
sl@0
  1183
	if (!iPar.Peek())
sl@0
  1184
		return EFalse;
sl@0
  1185
	if (!iStyle.Peek())
sl@0
  1186
		return EFalse;
sl@0
  1187
	if (aParams.iStyleName != *iStyle.Peek())
sl@0
  1188
		return EFalse;
sl@0
  1189
	if (aParams.iPar.iMask.iFlags != iParMask.iFlags
sl@0
  1190
		|| aParams.iPar.iFormat != *iPar.Peek())
sl@0
  1191
		return EFalse;
sl@0
  1192
	if (iCharMask.iFlags != aParams.iChar.iMask.iFlags
sl@0
  1193
		|| aParams.iChar.iFormat != *iChar.Peek())
sl@0
  1194
		return EFalse;
sl@0
  1195
	// coalescence is not possible if the new text contains pictures.
sl@0
  1196
	if (0 <= UndoSystem::FindPicture(aTarget, aParams.iPos, aParams.iText.Length()))
sl@0
  1197
		return EFalse;
sl@0
  1198
	return ETrue;
sl@0
  1199
	}
sl@0
  1200
sl@0
  1201
void CEditorCommandInsertTextAndFormat::Add(TInt aPos, const TDesC& aText)
sl@0
  1202
	{
sl@0
  1203
	iImpl.Add(aPos, aText);
sl@0
  1204
	}
sl@0
  1205
sl@0
  1206
///////////////////////////////////
sl@0
  1207
//								 //
sl@0
  1208
//	CEditorCommandSetCharFormat  //
sl@0
  1209
//								 //
sl@0
  1210
///////////////////////////////////
sl@0
  1211
sl@0
  1212
CEditorCommandSetCharFormat::~CEditorCommandSetCharFormat()
sl@0
  1213
	{
sl@0
  1214
	iChar.Close();
sl@0
  1215
	}
sl@0
  1216
sl@0
  1217
CEditorCommandSetCharFormat* CEditorCommandSetCharFormat::NewL(
sl@0
  1218
	const TRepositories& aReps, TInt aPos, TInt aLength,
sl@0
  1219
	const TTmCharFormat* aChar, TTmCharFormatMask aCharMask,
sl@0
  1220
	MUnifiedEditor& aTarget)
sl@0
  1221
	{
sl@0
  1222
	CEditorCommandSetCharFormat* r = new(ELeave) CEditorCommandSetCharFormat(aReps, aTarget);
sl@0
  1223
	CleanupStack::PushL(r);
sl@0
  1224
	r->iPos		= aPos;
sl@0
  1225
	r->iLength	= aLength;
sl@0
  1226
	r->iChar.TakeCopyL(aChar);
sl@0
  1227
	r->iCharMask= aCharMask;
sl@0
  1228
	CleanupStack::Pop(r);
sl@0
  1229
	return r;
sl@0
  1230
	}
sl@0
  1231
sl@0
  1232
// get as much of a run as possible.
sl@0
  1233
CEditorCommandSetCharFormat* CEditorCommandSetCharFormat::NewL(const TRepositories& aReps,
sl@0
  1234
	TInt aPos, TInt& aRemaining, MUnifiedEditor& aTarget)
sl@0
  1235
	{
sl@0
  1236
	TTmCharFormatLayer format;
sl@0
  1237
	TInt length;
sl@0
  1238
	aTarget.GetCharFormat(aPos, MUnifiedEditor::ESpecific, format, length);
sl@0
  1239
	if (aRemaining < length)
sl@0
  1240
		length = aRemaining;
sl@0
  1241
	CEditorCommandSetCharFormat* r =
sl@0
  1242
		NewL(aReps, aPos, length, &format.iFormat, format.iMask, aTarget);
sl@0
  1243
	aRemaining -= length;
sl@0
  1244
	return r;
sl@0
  1245
	}
sl@0
  1246
sl@0
  1247
// get as many runs as necessary and return a batch if necessary.
sl@0
  1248
CCommand* CEditorCommandSetCharFormat::NewBatchL(const TRepositories& aReps,
sl@0
  1249
	TInt aPos, TInt aLength, MUnifiedEditor& aTarget)
sl@0
  1250
	{
sl@0
  1251
	CCommand* command = 0;
sl@0
  1252
	TInt oldLength = aLength + 1;
sl@0
  1253
	TInt end = aPos + aLength;
sl@0
  1254
	while (0 < aLength && aLength < oldLength)
sl@0
  1255
		{
sl@0
  1256
		oldLength = aLength;
sl@0
  1257
		CleanupStack::PushL(command);
sl@0
  1258
		// coverity[double_free]
sl@0
  1259
		command = CoalesceL(command, NewL(aReps, end - aLength, aLength, aTarget));
sl@0
  1260
		CleanupStack::Pop();		// command, as was before call to CoalesceL
sl@0
  1261
		}
sl@0
  1262
	return command;
sl@0
  1263
	}
sl@0
  1264
sl@0
  1265
CCommand* CEditorCommandSetCharFormat::CreateInverseL() const
sl@0
  1266
	{
sl@0
  1267
	return CEditorCommandDeleteCharFormat::NewL(iRepositories, iPos, iLength, iTarget);
sl@0
  1268
	}
sl@0
  1269
sl@0
  1270
TInt CEditorCommandSetCharFormat::ExecuteL() const
sl@0
  1271
	{
sl@0
  1272
	TTmCharFormatLayer layer;
sl@0
  1273
	layer.iFormat = *iChar.Peek();
sl@0
  1274
	layer.iMask = iCharMask;
sl@0
  1275
	iTarget.SetCharFormatL(iPos, iLength, layer);
sl@0
  1276
	return 0;
sl@0
  1277
	}
sl@0
  1278
sl@0
  1279
TBool CEditorCommandSetCharFormat::PrepareToAddInverseToLastL(CSingleCommand& aLastCommand) const
sl@0
  1280
	{
sl@0
  1281
	if (aLastCommand.FamilyUid() != TUid::Uid(KUndoDllUid))
sl@0
  1282
		return EFalse;
sl@0
  1283
	CEditorCommandDeleteCharFormat* last =
sl@0
  1284
		static_cast<CEditorCommand&>(aLastCommand).CastToCEditorCommandDeleteCharFormat();
sl@0
  1285
	if (!last)
sl@0
  1286
		return EFalse;
sl@0
  1287
	return last->CanAdd(iPos, iLength, iTarget);
sl@0
  1288
	}
sl@0
  1289
sl@0
  1290
void CEditorCommandSetCharFormat::AddInverseToLast(CSingleCommand& aLastCommand) const
sl@0
  1291
	{
sl@0
  1292
	ASSERT(aLastCommand.FamilyUid() == TUid::Uid(KUndoDllUid));
sl@0
  1293
	CEditorCommandDeleteCharFormat* last =
sl@0
  1294
		static_cast<CEditorCommand&>(aLastCommand).CastToCEditorCommandDeleteCharFormat();
sl@0
  1295
	ASSERT(last);
sl@0
  1296
	last->Add(iPos, iLength);
sl@0
  1297
	}
sl@0
  1298
sl@0
  1299
//////////////////////////////////
sl@0
  1300
//								//
sl@0
  1301
//	CEditorCommandSetParFormat  //
sl@0
  1302
//								//
sl@0
  1303
//////////////////////////////////
sl@0
  1304
sl@0
  1305
CEditorCommandSetParFormat::~CEditorCommandSetParFormat()
sl@0
  1306
	{
sl@0
  1307
	iPar.Close();
sl@0
  1308
	}
sl@0
  1309
sl@0
  1310
CEditorCommandSetParFormat* CEditorCommandSetParFormat::NewL(
sl@0
  1311
	const TRepositories& aReps, TInt aPos, TInt aLength,
sl@0
  1312
	const RTmParFormat* aFormat, TTmParFormatMask aMask,
sl@0
  1313
	MUnifiedEditor& aTarget)
sl@0
  1314
	{
sl@0
  1315
	CEditorCommandSetParFormat* r = new(ELeave) CEditorCommandSetParFormat(aReps, aTarget);
sl@0
  1316
	CleanupStack::PushL(r);
sl@0
  1317
	r->iPos		= aPos;
sl@0
  1318
	r->iLength	= aLength;
sl@0
  1319
	r->iPar.TakeCopyL(aFormat);
sl@0
  1320
	r->iParMask= aMask;
sl@0
  1321
	CleanupStack::Pop(r);
sl@0
  1322
	return r;
sl@0
  1323
	}
sl@0
  1324
sl@0
  1325
// get as much of a run as possible.
sl@0
  1326
CEditorCommandSetParFormat* CEditorCommandSetParFormat::NewL(const TRepositories& aReps,
sl@0
  1327
	TInt aPos, TInt& aRemaining, MUnifiedEditor& aTarget)
sl@0
  1328
	{
sl@0
  1329
	RTmParFormatLayer format;
sl@0
  1330
	TInt length;
sl@0
  1331
	CleanupClosePushL(format);
sl@0
  1332
	aTarget.GetParFormatL(aPos, MUnifiedEditor::ESpecific, format, length);
sl@0
  1333
	if (aRemaining < length)
sl@0
  1334
		length = aRemaining;
sl@0
  1335
	CEditorCommandSetParFormat* r =
sl@0
  1336
		NewL(aReps, aPos, length, &format.iFormat, format.iMask, aTarget);
sl@0
  1337
	aRemaining -= length;
sl@0
  1338
	CleanupStack::PopAndDestroy();	// format
sl@0
  1339
	return r;
sl@0
  1340
	}
sl@0
  1341
sl@0
  1342
// get as many runs as necessary and return a batch if necessary.
sl@0
  1343
CCommand* CEditorCommandSetParFormat::NewBatchL(const TRepositories& aReps,
sl@0
  1344
	TInt aPos, TInt aLength, MUnifiedEditor& aTarget)
sl@0
  1345
	{
sl@0
  1346
	CCommand* command = 0;
sl@0
  1347
	TInt oldLength = aLength + 1;
sl@0
  1348
	TInt end = aPos + aLength;
sl@0
  1349
	while (0 < aLength && aLength < oldLength)
sl@0
  1350
		{
sl@0
  1351
		oldLength = aLength;
sl@0
  1352
		CleanupStack::PushL(command);
sl@0
  1353
		// coverity[double_free]
sl@0
  1354
		command = CoalesceL(command, NewL(aReps, end - aLength, aLength, aTarget));
sl@0
  1355
		CleanupStack::Pop();		// command, as was before call to CoalesceL
sl@0
  1356
		}
sl@0
  1357
	return command;
sl@0
  1358
	}
sl@0
  1359
sl@0
  1360
CCommand* CEditorCommandSetParFormat::CreateInverseL() const
sl@0
  1361
	{
sl@0
  1362
	return CEditorCommandDeleteParFormat::NewL(iRepositories, iPos, iLength, iTarget);
sl@0
  1363
	}
sl@0
  1364
sl@0
  1365
TInt CEditorCommandSetParFormat::ExecuteL() const
sl@0
  1366
	{
sl@0
  1367
	RTmParFormatLayer layer;
sl@0
  1368
	CleanupClosePushL(layer);
sl@0
  1369
	layer.iFormat.CopyL(*iPar.Peek());
sl@0
  1370
	layer.iMask = iParMask;
sl@0
  1371
	iTarget.SetParFormatL(iPos, iLength, layer);
sl@0
  1372
	CleanupStack::PopAndDestroy();
sl@0
  1373
	return 0;
sl@0
  1374
	}
sl@0
  1375
sl@0
  1376
TBool CEditorCommandSetParFormat::PrepareToAddInverseToLastL(CSingleCommand& aLastCommand) const
sl@0
  1377
	{
sl@0
  1378
	if (aLastCommand.FamilyUid() != TUid::Uid(KUndoDllUid))
sl@0
  1379
		return EFalse;
sl@0
  1380
	CEditorCommandDeleteParFormat* last =
sl@0
  1381
		static_cast<CEditorCommand&>(aLastCommand).CastToCEditorCommandDeleteParFormat();
sl@0
  1382
	if (!last)
sl@0
  1383
		return EFalse;
sl@0
  1384
	return last->CanAdd(iPos, iLength, iTarget);
sl@0
  1385
	}
sl@0
  1386
sl@0
  1387
void CEditorCommandSetParFormat::AddInverseToLast(CSingleCommand& aLastCommand) const
sl@0
  1388
	{
sl@0
  1389
	ASSERT(aLastCommand.FamilyUid() == TUid::Uid(KUndoDllUid));
sl@0
  1390
	CEditorCommandDeleteParFormat* last =
sl@0
  1391
		static_cast<CEditorCommand&>(aLastCommand).CastToCEditorCommandDeleteParFormat();
sl@0
  1392
	ASSERT(last);
sl@0
  1393
	last->Add(iPos, iLength);
sl@0
  1394
	}
sl@0
  1395
sl@0
  1396
//////////////////////////////////////
sl@0
  1397
//									//
sl@0
  1398
//	CEditorCommandDeleteCharFormat  //
sl@0
  1399
//									//
sl@0
  1400
//////////////////////////////////////
sl@0
  1401
sl@0
  1402
CEditorCommandDeleteCharFormat::~CEditorCommandDeleteCharFormat() {}
sl@0
  1403
sl@0
  1404
CEditorCommandDeleteCharFormat* CEditorCommandDeleteCharFormat::NewL(
sl@0
  1405
	const TRepositories& aReps, TInt aPos, TInt aLength, MUnifiedEditor& aTarget)
sl@0
  1406
	{
sl@0
  1407
	CEditorCommandDeleteCharFormat* r =
sl@0
  1408
		new(ELeave) CEditorCommandDeleteCharFormat(aReps, aTarget);
sl@0
  1409
	r->iPos = aPos;
sl@0
  1410
	r->iLength = aLength;
sl@0
  1411
	return r;
sl@0
  1412
	}
sl@0
  1413
sl@0
  1414
CCommand* CEditorCommandDeleteCharFormat::CreateInverseL() const
sl@0
  1415
	{
sl@0
  1416
	return CEditorCommandSetCharFormat::NewBatchL(iRepositories, iPos, iLength, iTarget);
sl@0
  1417
	}
sl@0
  1418
sl@0
  1419
TInt CEditorCommandDeleteCharFormat::ExecuteL() const
sl@0
  1420
	{
sl@0
  1421
	iTarget.DeleteCharFormatL(iPos, iLength);
sl@0
  1422
	return KErrNone;
sl@0
  1423
	}
sl@0
  1424
sl@0
  1425
TBool CEditorCommandDeleteCharFormat::CanAdd(TInt aPos, TInt aLength, MUnifiedEditor &aTarget) const
sl@0
  1426
	{
sl@0
  1427
	return &aTarget == &iTarget
sl@0
  1428
		&& aPos <= iPos + iLength
sl@0
  1429
		&& iPos <= aPos + aLength? ETrue : EFalse;
sl@0
  1430
	}
sl@0
  1431
sl@0
  1432
void CEditorCommandDeleteCharFormat::Add(TInt aPos, TInt aLength)
sl@0
  1433
	{
sl@0
  1434
	TInt min = aPos < iPos? aPos : iPos;
sl@0
  1435
	TInt max = iPos + iLength;
sl@0
  1436
	TInt max2= aPos + aLength;
sl@0
  1437
	iPos = min;
sl@0
  1438
	iLength = (max < max2? max2 : max) - min;
sl@0
  1439
	}
sl@0
  1440
sl@0
  1441
/////////////////////////////////////
sl@0
  1442
//								   //
sl@0
  1443
//	CEditorCommandDeleteParFormat  //
sl@0
  1444
//								   //
sl@0
  1445
/////////////////////////////////////
sl@0
  1446
sl@0
  1447
CEditorCommandDeleteParFormat::~CEditorCommandDeleteParFormat() {}
sl@0
  1448
sl@0
  1449
CEditorCommandDeleteParFormat* CEditorCommandDeleteParFormat::NewL(
sl@0
  1450
	const TRepositories& aReps, TInt aPos, TInt aLength, MUnifiedEditor& aTarget)
sl@0
  1451
	{
sl@0
  1452
	CEditorCommandDeleteParFormat* r =
sl@0
  1453
		new(ELeave) CEditorCommandDeleteParFormat(aReps, aTarget);
sl@0
  1454
	r->iPos = aPos;
sl@0
  1455
	r->iLength = aLength;
sl@0
  1456
	return r;
sl@0
  1457
	}
sl@0
  1458
sl@0
  1459
CCommand* CEditorCommandDeleteParFormat::CreateInverseL() const
sl@0
  1460
	{
sl@0
  1461
	return CEditorCommandSetParFormat::NewBatchL(iRepositories, iPos, iLength, iTarget);
sl@0
  1462
	}
sl@0
  1463
sl@0
  1464
TInt CEditorCommandDeleteParFormat::ExecuteL() const
sl@0
  1465
	{
sl@0
  1466
	iTarget.DeleteParFormatL(iPos, iLength);
sl@0
  1467
	return KErrNone;
sl@0
  1468
	}
sl@0
  1469
sl@0
  1470
TBool CEditorCommandDeleteParFormat::CanAdd(TInt aPos, TInt aLength, MUnifiedEditor& aTarget) const
sl@0
  1471
	{
sl@0
  1472
	return &aTarget == &iTarget
sl@0
  1473
		&& aPos <= iPos + iLength
sl@0
  1474
		&& iPos <= aPos + aLength? ETrue : EFalse;
sl@0
  1475
	}
sl@0
  1476
sl@0
  1477
void CEditorCommandDeleteParFormat::Add(TInt aPos, TInt aLength)
sl@0
  1478
	{
sl@0
  1479
	TInt min = aPos < iPos? aPos : iPos;
sl@0
  1480
	TInt max = iPos + iLength;
sl@0
  1481
	TInt max2= aPos + aLength;
sl@0
  1482
	iPos = min;
sl@0
  1483
	iLength = (max < max2? max2 : max) - min;
sl@0
  1484
	}
sl@0
  1485
sl@0
  1486
//////////////////////////
sl@0
  1487
//						//
sl@0
  1488
//	Command prototypes  //
sl@0
  1489
//						//
sl@0
  1490
//////////////////////////
sl@0
  1491
sl@0
  1492
//
sl@0
  1493
// Attribute setters
sl@0
  1494
//
sl@0
  1495
void CEditorCommandCreateStyleProto::Set(const RTmStyle& aStyle)
sl@0
  1496
	{
sl@0
  1497
	iStyle = &aStyle;
sl@0
  1498
	}
sl@0
  1499
sl@0
  1500
void CEditorCommandChangeStyleProto::Set(const RTmStyle& aStyle)
sl@0
  1501
	{
sl@0
  1502
	iStyle = &aStyle;
sl@0
  1503
	}
sl@0
  1504
sl@0
  1505
void CEditorCommandSetStyleProto::Set(TInt aPos,
sl@0
  1506
	TInt aLength,
sl@0
  1507
	const TDesC& aName)
sl@0
  1508
	{
sl@0
  1509
	iPos	= aPos;
sl@0
  1510
	iLength	= aLength;
sl@0
  1511
	iName	= &aName;
sl@0
  1512
	}
sl@0
  1513
sl@0
  1514
void CEditorCommandDeleteStyleProto::Set(const TDesC& aName)
sl@0
  1515
	{
sl@0
  1516
	iName	= &aName;
sl@0
  1517
	}
sl@0
  1518
sl@0
  1519
void CEditorCommandSetCharFormatProto::Set(TInt aPos,
sl@0
  1520
	TInt aLength,
sl@0
  1521
	const TTmCharFormatLayer& aFormat)
sl@0
  1522
	{
sl@0
  1523
	iPos	= aPos;
sl@0
  1524
	iLength	= aLength;
sl@0
  1525
	iFormat	= &aFormat;
sl@0
  1526
	}
sl@0
  1527
sl@0
  1528
void CEditorCommandSetParFormatProto::Set(TInt aPos,
sl@0
  1529
	TInt aLength,
sl@0
  1530
	const RTmParFormatLayer& aFormat)
sl@0
  1531
	{
sl@0
  1532
	iPos	= aPos;
sl@0
  1533
	iLength	= aLength;
sl@0
  1534
	iFormat	= &aFormat;
sl@0
  1535
	}
sl@0
  1536
sl@0
  1537
void CEditorCommandInsertProto::Set(TInt aPos,
sl@0
  1538
	const TDesC& aText,
sl@0
  1539
	const TDesC* aStyle,
sl@0
  1540
	const TTmCharFormatLayer* aCharFormat,
sl@0
  1541
	const RTmParFormatLayer* aParFormat)
sl@0
  1542
	{
sl@0
  1543
	iPos		= aPos;
sl@0
  1544
	iText		= &aText;
sl@0
  1545
	iStyle		= aStyle;
sl@0
  1546
	iCharFormat	= aCharFormat;
sl@0
  1547
	iParFormat	= aParFormat;
sl@0
  1548
	}
sl@0
  1549
sl@0
  1550
void CEditorCommandDeleteProto::Set(TInt aPos, TInt aLength)
sl@0
  1551
	{
sl@0
  1552
	iPos	= aPos;
sl@0
  1553
	iLength	= aLength;
sl@0
  1554
sl@0
  1555
	// adjust 'iPos' and 'iLength' to be surrogate aligned, if possible
sl@0
  1556
	if (iPos >= 0 && iPos <= iTarget.DocumentLength())
sl@0
  1557
		{
sl@0
  1558
		// check the character at aPos
sl@0
  1559
		TBuf<2> dest;
sl@0
  1560
		iTarget.GetText(iPos, dest);
sl@0
  1561
		if (dest.Length() > 0 && IsLowSurrogate(dest[0]))
sl@0
  1562
			{
sl@0
  1563
			// try to decrease aPos by 1
sl@0
  1564
			if (iPos > 0)
sl@0
  1565
				{
sl@0
  1566
				iTarget.GetText(iPos-1, dest);
sl@0
  1567
				if (dest.Length() > 0 && IsHighSurrogate(dest[0]))
sl@0
  1568
					{
sl@0
  1569
					iPos--;
sl@0
  1570
					iLength++;
sl@0
  1571
					}
sl@0
  1572
				else
sl@0
  1573
					{
sl@0
  1574
					// do nothing, just delete the corrupt surrogate
sl@0
  1575
					}
sl@0
  1576
				}
sl@0
  1577
			else
sl@0
  1578
				{
sl@0
  1579
				// do nothing
sl@0
  1580
				}
sl@0
  1581
			}
sl@0
  1582
		}
sl@0
  1583
	
sl@0
  1584
	if (iLength > 0)
sl@0
  1585
		{
sl@0
  1586
		// check the character at aPos+aLength
sl@0
  1587
		TBuf<2> dest;
sl@0
  1588
		iTarget.GetText(iPos+iLength-1, dest);
sl@0
  1589
		if (dest.Length() > 0 && IsHighSurrogate(dest[0]))
sl@0
  1590
			{
sl@0
  1591
			if (iPos + (iLength - 1) <= iTarget.DocumentLength())
sl@0
  1592
				{
sl@0
  1593
				// try to increase aLength by 1
sl@0
  1594
				iTarget.GetText(iPos+iLength, dest);
sl@0
  1595
				if (dest.Length() > 0 && IsLowSurrogate(dest[0]))
sl@0
  1596
					{
sl@0
  1597
					iLength++;
sl@0
  1598
					}
sl@0
  1599
				else
sl@0
  1600
					{
sl@0
  1601
					// do nothing
sl@0
  1602
					}
sl@0
  1603
				}
sl@0
  1604
			else
sl@0
  1605
				{
sl@0
  1606
				// do nothing
sl@0
  1607
				}
sl@0
  1608
			}
sl@0
  1609
		}
sl@0
  1610
 	}
sl@0
  1611
sl@0
  1612
void CEditorCommandDeleteCharFormatProto::Set(TInt aPos, TInt aLength)
sl@0
  1613
	{
sl@0
  1614
	iPos	= aPos;
sl@0
  1615
	iLength	= aLength;
sl@0
  1616
	}
sl@0
  1617
sl@0
  1618
void CEditorCommandDeleteParFormatProto::Set(TInt aPos, TInt aLength)
sl@0
  1619
	{
sl@0
  1620
	iPos	= aPos;
sl@0
  1621
	iLength	= aLength;
sl@0
  1622
	}
sl@0
  1623
sl@0
  1624
void CEditorCommandDeletePictureProto::Set(TInt aPos)
sl@0
  1625
	{
sl@0
  1626
	iPos = aPos;
sl@0
  1627
	}
sl@0
  1628
sl@0
  1629
void CEditorCommandDestroyPictureProto::Set(TInt aPos)
sl@0
  1630
	{
sl@0
  1631
	if (iPictureOwnerDelegate)
sl@0
  1632
		{
sl@0
  1633
		iPictureOwnerDelegate->ForgetOwner(this);
sl@0
  1634
		iPictureOwnerDelegate = 0;
sl@0
  1635
		}
sl@0
  1636
	iPos = aPos;
sl@0
  1637
	}
sl@0
  1638
sl@0
  1639
void CEditorCommandInsertPictureProto::Set(TInt aPos, const TPictureHeader& aPicture)
sl@0
  1640
	{
sl@0
  1641
	iPos		= aPos;
sl@0
  1642
	iPicture	= &aPicture;
sl@0
  1643
	}
sl@0
  1644
sl@0
  1645
void CEditorCommandRenameStyleProto::Set(const TDesC& aOldName, const TDesC& aNewName)
sl@0
  1646
	{
sl@0
  1647
	iOldName	= &aOldName;
sl@0
  1648
	iNewName	= &aNewName;
sl@0
  1649
	}
sl@0
  1650
sl@0
  1651
void CEditorCommandSetBaseFormatProto::Set(
sl@0
  1652
	const TTmCharFormat* aCharFormat, const RTmParFormat* aParFormat)
sl@0
  1653
	{
sl@0
  1654
	iChar	= aCharFormat;
sl@0
  1655
	iPar	= aParFormat;
sl@0
  1656
	}
sl@0
  1657
sl@0
  1658
void CEditorCommandPasteProto::Set(const CStreamStore& aStore,
sl@0
  1659
	const CStreamDictionary& aStreamDictionary,	TInt aPos)
sl@0
  1660
	{
sl@0
  1661
	iImpl.Set(aStore, aStreamDictionary, aPos);
sl@0
  1662
	}
sl@0
  1663
sl@0
  1664
//
sl@0
  1665
// execution and inversion
sl@0
  1666
//
sl@0
  1667
sl@0
  1668
// CEditorCommandCreateStyleProto
sl@0
  1669
TInt CEditorCommandCreateStyleProto::ExecuteL() const
sl@0
  1670
	{
sl@0
  1671
	MUnifiedEditor::MStyleSupport* si = iTarget.StyleSupport();
sl@0
  1672
	ASSERT(si);
sl@0
  1673
	return si->CreateStyleL(*iStyle);
sl@0
  1674
	}
sl@0
  1675
sl@0
  1676
CCommand* CEditorCommandCreateStyleProto::CreateInverseL() const
sl@0
  1677
	{
sl@0
  1678
	return CEditorCommandDeleteStyle::NewL(Repositories(), iStyle->iName, iTarget);
sl@0
  1679
	}
sl@0
  1680
sl@0
  1681
sl@0
  1682
// CEditorCommandChangeStyleProto
sl@0
  1683
TInt CEditorCommandChangeStyleProto::ExecuteL() const
sl@0
  1684
	{
sl@0
  1685
	MUnifiedEditor::MStyleSupport* si = iTarget.StyleSupport();
sl@0
  1686
	ASSERT(si);
sl@0
  1687
	return si->ChangeStyleL(*iStyle);
sl@0
  1688
	}
sl@0
  1689
sl@0
  1690
CCommand* CEditorCommandChangeStyleProto::CreateInverseL() const
sl@0
  1691
	{
sl@0
  1692
	return CEditorCommandAlterStyle::NewL(Repositories(), iStyle->iName, iTarget);
sl@0
  1693
	}
sl@0
  1694
sl@0
  1695
// CEditorCommandSetStyleProto
sl@0
  1696
TInt CEditorCommandSetStyleProto::ExecuteL() const
sl@0
  1697
	{
sl@0
  1698
	MUnifiedEditor::MStyleSupport* si = iTarget.StyleSupport();
sl@0
  1699
	ASSERT(si);
sl@0
  1700
	return si->SetStyleL(iPos, iLength, *iName);
sl@0
  1701
	}
sl@0
  1702
sl@0
  1703
CCommand* CEditorCommandSetStyleProto::CreateInverseL() const
sl@0
  1704
	{
sl@0
  1705
	return CEditorCommandSetStyle::NewL(Repositories(), iPos, iLength, iTarget);
sl@0
  1706
	}
sl@0
  1707
sl@0
  1708
// CEditorCommandDeleteStyleProto
sl@0
  1709
TInt CEditorCommandDeleteStyleProto::ExecuteL() const
sl@0
  1710
	{
sl@0
  1711
	MUnifiedEditor::MStyleSupport* si = iTarget.StyleSupport();
sl@0
  1712
	ASSERT(si);
sl@0
  1713
	return si->DeleteStyleL(*iName);
sl@0
  1714
	}
sl@0
  1715
sl@0
  1716
CCommand* CEditorCommandDeleteStyleProto::CreateInverseL() const
sl@0
  1717
	{
sl@0
  1718
	return CEditorCommandCreateStyle::NewBatchL(Repositories(), *iName, iTarget);
sl@0
  1719
	}
sl@0
  1720
sl@0
  1721
// CEditorCommandSetCharFormatProto
sl@0
  1722
TInt CEditorCommandSetCharFormatProto::ExecuteL() const
sl@0
  1723
	{
sl@0
  1724
	iTarget.SetCharFormatL(iPos, iLength, *iFormat);
sl@0
  1725
	return KErrNone;
sl@0
  1726
	}
sl@0
  1727
sl@0
  1728
CCommand* CEditorCommandSetCharFormatProto::CreateInverseL() const
sl@0
  1729
	{
sl@0
  1730
	// inverse is to remove formatting and re-apply the old
sl@0
  1731
	CCommand* inverse =
sl@0
  1732
		CEditorCommandSetCharFormat::NewBatchL(Repositories(),
sl@0
  1733
			iPos, iLength, iTarget);
sl@0
  1734
	CleanupStack::PushL(inverse);
sl@0
  1735
	// coverity[double_free]
sl@0
  1736
	inverse = CoalesceL(inverse,
sl@0
  1737
		CEditorCommandDeleteCharFormat::NewL(Repositories(), iPos, iLength, iTarget));
sl@0
  1738
	CleanupStack::Pop();
sl@0
  1739
	return inverse;
sl@0
  1740
	}
sl@0
  1741
sl@0
  1742
// CEditorCommandSetParFormatProto
sl@0
  1743
TInt CEditorCommandSetParFormatProto::ExecuteL() const
sl@0
  1744
	{
sl@0
  1745
	iTarget.SetParFormatL(iPos, iLength, *iFormat);
sl@0
  1746
	return KErrNone;
sl@0
  1747
	}
sl@0
  1748
sl@0
  1749
CCommand* CEditorCommandSetParFormatProto::CreateInverseL() const
sl@0
  1750
	{
sl@0
  1751
	// inverse is to remove formatting and re-apply the old
sl@0
  1752
	CCommand* inverse =
sl@0
  1753
		CEditorCommandSetParFormat::NewBatchL(Repositories(), iPos, iLength, iTarget);
sl@0
  1754
	CleanupStack::PushL(inverse);
sl@0
  1755
	// coverity[double_free]
sl@0
  1756
	inverse = CoalesceL(inverse,
sl@0
  1757
		CEditorCommandDeleteParFormat::NewL(Repositories(), iPos, iLength, iTarget));
sl@0
  1758
	CleanupStack::Pop();
sl@0
  1759
	return inverse;
sl@0
  1760
	}
sl@0
  1761
sl@0
  1762
// CEditorCommandInsertProto
sl@0
  1763
TInt CEditorCommandInsertProto::ExecuteL() const
sl@0
  1764
	{
sl@0
  1765
	iTarget.InsertTextL(iPos, *iText, iStyle, iCharFormat, iParFormat);
sl@0
  1766
	return KErrNone;
sl@0
  1767
	}
sl@0
  1768
sl@0
  1769
CCommand* CEditorCommandInsertProto::CreateInverseL() const
sl@0
  1770
	{
sl@0
  1771
	return CEditorCommandDeleteText::NewL(Repositories(), iPos, iText->Length(), iTarget);
sl@0
  1772
	}
sl@0
  1773
sl@0
  1774
TBool CEditorCommandInsertProto::PrepareToAddInverseToLastL(CSingleCommand& aLastCommand) const
sl@0
  1775
	{
sl@0
  1776
	if (aLastCommand.FamilyUid() != TUid::Uid(KUndoDllUid))
sl@0
  1777
		return EFalse;
sl@0
  1778
	CEditorCommandDeleteText* last =
sl@0
  1779
		static_cast<CEditorCommand&>(aLastCommand).CastToCEditorCommandDeleteText();
sl@0
  1780
	if (!last)
sl@0
  1781
		return EFalse;
sl@0
  1782
	return last->CanAdd(iPos, iText->Length(), iTarget);
sl@0
  1783
	}
sl@0
  1784
sl@0
  1785
void CEditorCommandInsertProto::AddInverseToLast(CSingleCommand& aLastCommand) const
sl@0
  1786
	{
sl@0
  1787
	ASSERT(aLastCommand.FamilyUid() == TUid::Uid(KUndoDllUid));
sl@0
  1788
	CEditorCommandDeleteText* last =
sl@0
  1789
		static_cast<CEditorCommand&>(aLastCommand).CastToCEditorCommandDeleteText();
sl@0
  1790
	ASSERT(last);
sl@0
  1791
	last->Add(iText->Length());
sl@0
  1792
	}
sl@0
  1793
sl@0
  1794
// CEditorCommandDeleteProto
sl@0
  1795
TInt CEditorCommandDeleteProto::ExecuteL() const
sl@0
  1796
	{
sl@0
  1797
	iTarget.DeleteTextL(iPos, iLength);
sl@0
  1798
	return KErrNone;
sl@0
  1799
	}
sl@0
  1800
sl@0
  1801
CCommand* CEditorCommandDeleteProto::CreateInverseL() const
sl@0
  1802
	{
sl@0
  1803
	return CEditorCommandInsertTextAndFormat::NewBatchL(Repositories(),
sl@0
  1804
		iPos, iLength, iTarget);
sl@0
  1805
	}
sl@0
  1806
sl@0
  1807
TBool CEditorCommandDeleteProto::PrepareToAddInverseToLastL(CSingleCommand& aLastCommand) const
sl@0
  1808
	{
sl@0
  1809
	if (iDeletedText.MaxLength() < iLength)
sl@0
  1810
		return EFalse;
sl@0
  1811
	if (aLastCommand.FamilyUid() != TUid::Uid(KUndoDllUid))
sl@0
  1812
		return EFalse;
sl@0
  1813
	CEditorCommandInsertTextAndFormat* last =
sl@0
  1814
		static_cast<CEditorCommand&>(aLastCommand).CastToCEditorCommandInsertTextAndFormat();
sl@0
  1815
	if (!last)
sl@0
  1816
		return EFalse;
sl@0
  1817
	CEditorCommandInsertTextAndFormat::RTextAndFormatParameters params;
sl@0
  1818
	CleanupClosePushL(params);
sl@0
  1819
	params.SetL(iPos, iLength, iTarget);
sl@0
  1820
	TBool result = EFalse;
sl@0
  1821
	if (params.iText.Length() == iLength)
sl@0
  1822
		{
sl@0
  1823
		result = last->CanAdd(params, iTarget);
sl@0
  1824
		if (result)
sl@0
  1825
			iDeletedText = params.iText;
sl@0
  1826
		}
sl@0
  1827
	CleanupStack::PopAndDestroy();
sl@0
  1828
	return result;
sl@0
  1829
	}
sl@0
  1830
sl@0
  1831
void CEditorCommandDeleteProto::AddInverseToLast(CSingleCommand& aLastCommand) const
sl@0
  1832
	{
sl@0
  1833
	ASSERT(aLastCommand.FamilyUid() == TUid::Uid(KUndoDllUid));
sl@0
  1834
	CEditorCommandInsertTextAndFormat* last =
sl@0
  1835
		static_cast<CEditorCommand&>(aLastCommand).CastToCEditorCommandInsertTextAndFormat();
sl@0
  1836
	ASSERT(last);
sl@0
  1837
	last->Add(iPos, iDeletedText);
sl@0
  1838
	}
sl@0
  1839
sl@0
  1840
// CEditorCommandDeleteCharFormatProto
sl@0
  1841
TInt CEditorCommandDeleteCharFormatProto::ExecuteL() const
sl@0
  1842
	{
sl@0
  1843
	iTarget.DeleteCharFormatL(iPos, iLength);
sl@0
  1844
	return KErrNone;
sl@0
  1845
	}
sl@0
  1846
sl@0
  1847
CCommand* CEditorCommandDeleteCharFormatProto::CreateInverseL() const
sl@0
  1848
	{
sl@0
  1849
	return CEditorCommandSetCharFormat::NewBatchL(Repositories(),
sl@0
  1850
		iPos, iLength, iTarget);
sl@0
  1851
	}
sl@0
  1852
sl@0
  1853
// CEditorCommandDeleteParFormatProto
sl@0
  1854
TInt CEditorCommandDeleteParFormatProto::ExecuteL() const
sl@0
  1855
	{
sl@0
  1856
	iTarget.DeleteParFormatL(iPos, iLength);
sl@0
  1857
	return KErrNone;
sl@0
  1858
	}
sl@0
  1859
sl@0
  1860
CCommand* CEditorCommandDeleteParFormatProto::CreateInverseL() const
sl@0
  1861
	{
sl@0
  1862
	return CEditorCommandSetParFormat::NewBatchL(Repositories(),
sl@0
  1863
		iPos, iLength, iTarget);
sl@0
  1864
	}
sl@0
  1865
sl@0
  1866
// CEditorCommandDeletePictureProto
sl@0
  1867
TInt CEditorCommandDeletePictureProto::ExecuteL() const
sl@0
  1868
	{
sl@0
  1869
	MUnifiedEditor::MPictureSupport* pi = iTarget.PictureSupport();
sl@0
  1870
	ASSERT(pi);
sl@0
  1871
	pi->DropPictureL(iPos);
sl@0
  1872
	return KErrNone;
sl@0
  1873
	}
sl@0
  1874
sl@0
  1875
// CEditorCommandInsertPictureProto
sl@0
  1876
TInt CEditorCommandInsertPictureProto::ExecuteL() const
sl@0
  1877
	{
sl@0
  1878
	MUnifiedEditor::MPictureSupport* pi = iTarget.PictureSupport();
sl@0
  1879
	ASSERT(pi);
sl@0
  1880
	pi->InsertPictureL(iPos, *iPicture);
sl@0
  1881
	return KErrNone;
sl@0
  1882
	}
sl@0
  1883
sl@0
  1884
CCommand* CEditorCommandInsertPictureProto::CreateInverseL() const
sl@0
  1885
	{
sl@0
  1886
	return CEditorCommandDeletePicture::NewL(Repositories(), iPos, iTarget);
sl@0
  1887
	}
sl@0
  1888
sl@0
  1889
// CEditorCommandDestroyPictureProto
sl@0
  1890
void CEditorCommandDestroyPictureProto::ForgetDelegate()
sl@0
  1891
	{
sl@0
  1892
	iPictureOwnerDelegate = 0;
sl@0
  1893
	}
sl@0
  1894
sl@0
  1895
CEditorCommandDestroyPictureProto::~CEditorCommandDestroyPictureProto()
sl@0
  1896
	{
sl@0
  1897
	if (iPictureOwnerDelegate)
sl@0
  1898
		iPictureOwnerDelegate->ForgetOwner(this);
sl@0
  1899
	}
sl@0
  1900
sl@0
  1901
CCommand* CEditorCommandDestroyPictureProto::CreateInverseL() const
sl@0
  1902
	{
sl@0
  1903
	CEditorCommandDestroyPictureProto* nonConstThis =
sl@0
  1904
		const_cast<CEditorCommandDestroyPictureProto*>(this);
sl@0
  1905
	if (iPictureOwnerDelegate)
sl@0
  1906
		{
sl@0
  1907
		iPictureOwnerDelegate->ForgetOwner(nonConstThis);
sl@0
  1908
		iPictureOwnerDelegate = 0;
sl@0
  1909
		}
sl@0
  1910
	CCommand* style =
sl@0
  1911
		CEditorCommandSetStyle::NewL(Repositories(), iPos, 1, iTarget);
sl@0
  1912
	CleanupStack::PushL(style);
sl@0
  1913
	CCommand* charFormat =
sl@0
  1914
		CEditorCommandSetCharFormat::NewBatchL(Repositories(), iPos, 1, iTarget);
sl@0
  1915
	CleanupStack::PushL(charFormat);
sl@0
  1916
	CCommand* parFormat =
sl@0
  1917
		CEditorCommandSetParFormat::NewBatchL(Repositories(), iPos, 1, iTarget);
sl@0
  1918
	CleanupStack::PushL(parFormat);
sl@0
  1919
	iPictureOwnerDelegate =
sl@0
  1920
		CEditorCommandInsertPicture::NewL(Repositories(), iPos,
sl@0
  1921
		*const_cast<CEditorCommandDestroyPictureProto*>(nonConstThis), iTarget);
sl@0
  1922
	// coverity[double_free]
sl@0
  1923
	CCommand* command = CoalesceL(parFormat, iPictureOwnerDelegate);
sl@0
  1924
	CleanupStack::Pop();	// parFormat, no longer owned
sl@0
  1925
	// coverity[double_free]
sl@0
  1926
	command = CoalesceL(charFormat, command);
sl@0
  1927
	CleanupStack::Pop();	// charFormat, no longer owned
sl@0
  1928
	// coverity[double_free]
sl@0
  1929
	command = CoalesceL(style, command);
sl@0
  1930
	CleanupStack::Pop();	// style, no longer owned
sl@0
  1931
sl@0
  1932
	return command;
sl@0
  1933
	}
sl@0
  1934
sl@0
  1935
TInt CEditorCommandDestroyPictureProto::ExecuteL() const
sl@0
  1936
	{
sl@0
  1937
	MUnifiedEditor::MPictureSupport* pi = iTarget.PictureSupport();
sl@0
  1938
	ASSERT(pi);
sl@0
  1939
	TPictureHeader pic;
sl@0
  1940
	pi->Picture(iPos, pic);
sl@0
  1941
	pi->DropPictureL(iPos);
sl@0
  1942
	if (iPictureOwnerDelegate)
sl@0
  1943
		{
sl@0
  1944
		iPictureOwnerDelegate->TakePictureOwnership(pic);
sl@0
  1945
		iPictureOwnerDelegate = 0;
sl@0
  1946
		}
sl@0
  1947
	else
sl@0
  1948
		pic.DeletePicture();
sl@0
  1949
	return KErrNone;
sl@0
  1950
	}
sl@0
  1951
sl@0
  1952
// CEditorCommandRenameStyleProto
sl@0
  1953
TInt CEditorCommandRenameStyleProto::ExecuteL() const
sl@0
  1954
	{
sl@0
  1955
	MUnifiedEditor::MStyleSupport* si = iTarget.StyleSupport();
sl@0
  1956
	ASSERT(si);
sl@0
  1957
	return si->RenameStyleL(*iOldName, *iNewName);
sl@0
  1958
	}
sl@0
  1959
sl@0
  1960
CCommand* CEditorCommandRenameStyleProto::CreateInverseL() const
sl@0
  1961
	{
sl@0
  1962
	return CEditorCommandRenameStyle::NewL(Repositories(),
sl@0
  1963
		*iNewName, *iOldName, iTarget);
sl@0
  1964
	}
sl@0
  1965
sl@0
  1966
// CEditorCommandPasteProto
sl@0
  1967
TInt CEditorCommandPasteProto::ExecuteL() const
sl@0
  1968
	{
sl@0
  1969
	return iImpl.ExecuteL();
sl@0
  1970
	}
sl@0
  1971
sl@0
  1972
UndoSystem::CCommand* CEditorCommandPasteProto::CreateInverseL() const
sl@0
  1973
	{
sl@0
  1974
	RStoreReadStream stream;
sl@0
  1975
	iImpl.OpenPlainTextStreamLC(stream);
sl@0
  1976
	TInt pos = iImpl.Pos();
sl@0
  1977
	TInt length = stream.ReadInt32L();
sl@0
  1978
	CCommand* command = 0;
sl@0
  1979
	CBufSeg* buf = CBufSeg::NewL(200);
sl@0
  1980
	CleanupStack::PushL(buf);
sl@0
  1981
	TPtrC current;
sl@0
  1982
sl@0
  1983
	if (length < 0)
sl@0
  1984
		User::Leave(KErrNotSupported);	// don't know how to undo
sl@0
  1985
sl@0
  1986
	RBufWriteStream bufferStream;
sl@0
  1987
	bufferStream.Open(*buf);
sl@0
  1988
	TMemoryStreamUnicodeSink sink(bufferStream);
sl@0
  1989
	TUnicodeExpander e;
sl@0
  1990
	e.ExpandL(sink, stream, length);
sl@0
  1991
	bufferStream.CommitL();
sl@0
  1992
	bufferStream.Close();
sl@0
  1993
sl@0
  1994
	TInt end = pos + length;
sl@0
  1995
	TInt bufferPos = 0;
sl@0
  1996
sl@0
  1997
	while (pos != end)
sl@0
  1998
		{
sl@0
  1999
		ASSERT(pos < end);
sl@0
  2000
		TInt lengthSearched = 0;
sl@0
  2001
		TInt pic = KErrNotFound;
sl@0
  2002
		while ((pic = current.Locate(CEditableText::EPictureCharacter)) < 0
sl@0
  2003
			&& pos + lengthSearched < end)
sl@0
  2004
			{
sl@0
  2005
			lengthSearched += current.Length();
sl@0
  2006
			TPtr8 seg(buf->Ptr(bufferPos));
sl@0
  2007
			bufferPos += seg.Length();
sl@0
  2008
			current.Set(reinterpret_cast<const TText*>(seg.Ptr()),
sl@0
  2009
				seg.Length() / sizeof(TText));
sl@0
  2010
			}
sl@0
  2011
		TInt currentSearched = 0 <= pic? pic : current.Length();
sl@0
  2012
		lengthSearched += currentSearched;
sl@0
  2013
sl@0
  2014
		if (lengthSearched)
sl@0
  2015
			{
sl@0
  2016
			// we have some text to delete
sl@0
  2017
			CleanupStack::PushL(command);
sl@0
  2018
			// coverity[double_free]
sl@0
  2019
			command = CoalesceL(command,
sl@0
  2020
				CEditorCommandDeleteText::NewL(Repositories(), pos, lengthSearched,
sl@0
  2021
					iImpl.Target()));
sl@0
  2022
			CleanupStack::Pop();
sl@0
  2023
			pos += lengthSearched;
sl@0
  2024
			}
sl@0
  2025
sl@0
  2026
		if (0 <= pic)
sl@0
  2027
			{
sl@0
  2028
			ASSERT(current.Length());
sl@0
  2029
			// we have a picture to delete
sl@0
  2030
			CleanupStack::PushL(command);
sl@0
  2031
			command = CoalesceL(command,
sl@0
  2032
				CEditorCommandDeletePicture::NewL(Repositories(), pos, iImpl.Target()));
sl@0
  2033
			CleanupStack::Pop();
sl@0
  2034
			currentSearched += 1;
sl@0
  2035
			pos += 1;
sl@0
  2036
			}
sl@0
  2037
sl@0
  2038
		current.Set(current.Mid(currentSearched));
sl@0
  2039
		}
sl@0
  2040
sl@0
  2041
	CleanupStack::PopAndDestroy(buf);
sl@0
  2042
	CleanupStack::PopAndDestroy();		// close stream
sl@0
  2043
sl@0
  2044
	return command;
sl@0
  2045
	}
sl@0
  2046
sl@0
  2047
// CEditorCommandSetBaseFormatProto
sl@0
  2048
TInt CEditorCommandSetBaseFormatProto::ExecuteL() const
sl@0
  2049
	{
sl@0
  2050
	iTarget.SetBaseFormatL(*iChar, *iPar);
sl@0
  2051
	return KErrNone;
sl@0
  2052
	}
sl@0
  2053
sl@0
  2054
CCommand* CEditorCommandSetBaseFormatProto::CreateInverseL() const
sl@0
  2055
	{
sl@0
  2056
	return CEditorCommandSetBaseFormat::NewL(Repositories(),
sl@0
  2057
		iTarget);
sl@0
  2058
	}
sl@0
  2059
sl@0
  2060
//////////////////////
sl@0
  2061
//					//
sl@0
  2062
//	free functions  //
sl@0
  2063
//					//
sl@0
  2064
//////////////////////
sl@0
  2065
sl@0
  2066
TInt UndoSystem::FindPicture(const MUnifiedEditor& aTarget, TInt aPos, TInt aLength)
sl@0
  2067
	{
sl@0
  2068
	const MUnifiedEditor::MPictureSupport* pi =
sl@0
  2069
		const_cast<MUnifiedEditor&>(aTarget).PictureSupport();
sl@0
  2070
	if (!pi)
sl@0
  2071
		return KErrNotFound;
sl@0
  2072
	while (0 < aLength)
sl@0
  2073
		{
sl@0
  2074
		TPtrC text;
sl@0
  2075
		aTarget.GetText(aPos, text);
sl@0
  2076
		if (aLength < text.Length())
sl@0
  2077
			text.Set(text.Ptr(), aLength);
sl@0
  2078
		TInt result;
sl@0
  2079
		while (0 <= (result = text.Locate(CEditableText::EPictureCharacter)))
sl@0
  2080
			{
sl@0
  2081
			TPictureHeader pic;
sl@0
  2082
			pi->Picture(aPos + result, pic);
sl@0
  2083
			if (pic.iPictureType != KNullUid)
sl@0
  2084
				return aPos + result;
sl@0
  2085
			++result;
sl@0
  2086
			aPos += result;
sl@0
  2087
			aLength -= result;
sl@0
  2088
			TPtrC temp = text.Mid(result);
sl@0
  2089
			text.Set(temp);
sl@0
  2090
			}
sl@0
  2091
		aPos += text.Length();
sl@0
  2092
		aLength -= text.Length();
sl@0
  2093
		}
sl@0
  2094
	return KErrNotFound;
sl@0
  2095
	}
sl@0
  2096