epoc32/include/txtetext.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 0 061f57f2323e
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
williamr@2
     1
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@2
     2
// All rights reserved.
williamr@2
     3
// This component and the accompanying materials are made available
williamr@2
     4
// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
williamr@2
     5
// which accompanies this distribution, and is available
williamr@2
     6
// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
williamr@2
     7
//
williamr@2
     8
// Initial Contributors:
williamr@2
     9
// Nokia Corporation - initial contribution.
williamr@2
    10
//
williamr@2
    11
// Contributors:
williamr@2
    12
//
williamr@2
    13
// Description:
williamr@2
    14
//
williamr@2
    15
williamr@2
    16
#ifndef __TXTETEXT_H__
williamr@2
    17
#define __TXTETEXT_H__
williamr@2
    18
williamr@2
    19
#include <e32std.h>
williamr@2
    20
#include <e32base.h>
williamr@2
    21
#include <fldset.h>
williamr@2
    22
#include <s32std.h>
williamr@2
    23
williamr@2
    24
williamr@2
    25
// Forward references
williamr@2
    26
class CParaFormatLayer;
williamr@2
    27
class CCharFormatLayer;
williamr@2
    28
class MTextFieldFactory;
williamr@2
    29
class CTextFieldSet;
williamr@2
    30
class CTextField;
williamr@2
    31
class TFindFieldInfo;
williamr@2
    32
class CInlineEditData;
williamr@2
    33
class MFepInlineTextFormatRetriever;
williamr@2
    34
class TCharFormat;
williamr@2
    35
class CEditableTextOptionalData;
williamr@2
    36
class RFs;
williamr@2
    37
williamr@2
    38
williamr@2
    39
/**
williamr@2
    40
UIDs
williamr@2
    41
@internalComponent
williamr@2
    42
*/
williamr@2
    43
const TUid KPlainTextFieldDataUid = {268435555};
williamr@2
    44
const TUid KEditableTextUid = {268450334};
williamr@2
    45
const TUid KPlainTextCharacterDataUid = {268450341};
williamr@2
    46
const TUid KClipboardUidTypePlainText = {268450333};
williamr@2
    47
const TUid KUidRichText = {271013233};
williamr@2
    48
williamr@2
    49
/**
williamr@2
    50
@internalComponent
williamr@2
    51
*/
williamr@2
    52
const TInt KMaxFieldBufferSize=0x14;
williamr@2
    53
williamr@2
    54
/** 
williamr@2
    55
An abstract base class which defines the behaviour common to all editable 
williamr@2
    56
text classes.
williamr@2
    57
williamr@2
    58
It provides no storage for text or text formatting, so it is not directly 
williamr@2
    59
usable. It defines protocols for editing the contents of a text object and 
williamr@2
    60
for extracting format data from a text object which supports formatting.
williamr@2
    61
williamr@2
    62
Note: when specifying a position in a text object (the document position), 
williamr@2
    63
zero is before the first character in the document. If the document contains 
williamr@2
    64
n characters, position n is after the last character. Valid document positions 
williamr@2
    65
are therefore between zero and the length of the document, inclusive. Many 
williamr@2
    66
editable text functions raise a panic if a specified document position is 
williamr@2
    67
invalid.
williamr@2
    68
williamr@2
    69
Note also that the functions which implement support for front-end-processor 
williamr@2
    70
inline editing are intended for internal use only by Symbian. 
williamr@2
    71
@publishedAll
williamr@2
    72
@released
williamr@2
    73
*/
williamr@2
    74
class CEditableText : public CBase
williamr@2
    75
	{
williamr@2
    76
public:
williamr@2
    77
	IMPORT_C ~CEditableText();
williamr@2
    78
	IMPORT_C TStreamId StoreL(CStreamStore& aStore) const;
williamr@2
    79
	IMPORT_C void RestoreL(const CStreamStore& aStore,TStreamId aStreamId);
williamr@2
    80
williamr@2
    81
	// virtual persistence functions
williamr@2
    82
	virtual void ExternalizeL(RWriteStream& aStream) const;
williamr@2
    83
	virtual void InternalizeL(RReadStream& aStream);
williamr@2
    84
	
williamr@2
    85
	/** Stores the text components, e.g. fields, pictures and formatting to the 
williamr@2
    86
	stream store specified. Does not store the text content.
williamr@2
    87
	
williamr@2
    88
	@param aStore Stream store to which the text components are written. 
williamr@2
    89
	@param aMap A store map. This binds the address of text components to the 
williamr@2
    90
	stream ID of aStore. This is needed to support deferred loading of 
williamr@2
    91
	pictures in rich text. */
williamr@2
    92
	virtual void StoreComponentsL(CStreamStore& aStore,CStoreMap& aMap) const = 0;
williamr@2
    93
	
williamr@2
    94
	/** Restores the text components, e.g. fields, pictures and formatting from 
williamr@2
    95
	the stream store. Does not restore the text content.
williamr@2
    96
	
williamr@2
    97
	@param aStore The stream store from which the text components are restored. */
williamr@2
    98
	virtual void RestoreComponentsL(const CStreamStore& aStore) = 0;
williamr@2
    99
williamr@2
   100
	// modifier functions
williamr@2
   101
	
williamr@2
   102
	/** Deletes the text content and components from the text object, leaving 
williamr@2
   103
	the single end-of-text paragraph delimiter. */
williamr@2
   104
	virtual void Reset() = 0;
williamr@2
   105
	
williamr@2
   106
	/**  Inserts a single character or a descriptor into the text object at a
williamr@2
   107
	specified document position.
williamr@2
   108
	
williamr@2
   109
	@param aInsertPos  A valid document position at which to insert the
williamr@2
   110
	            character or descriptor.
williamr@2
   111
	@param  aChar  The character to insert. */
williamr@2
   112
	virtual void InsertL(TInt aInsertPos,const TChar& aChar) = 0;
williamr@2
   113
williamr@2
   114
	/**  Inserts a single character or a descriptor into the text object at a
williamr@2
   115
	specified document position.
williamr@2
   116
	
williamr@2
   117
	@param aInsertPos  A valid document position at which to insert the
williamr@2
   118
	            character or descriptor.
williamr@2
   119
	@param  aBuf  The descriptor to insert.*/
williamr@2
   120
	virtual void InsertL(TInt aInsertPos,const TDesC& aBuf) = 0;
williamr@2
   121
	
williamr@2
   122
 	/** Deletes one or more characters beginning at (and including) the 
williamr@2
   123
 	character at the specified document position.
williamr@2
   124
	
williamr@2
   125
	@param aPos The document position from which to delete. 
williamr@2
   126
	@param aLength The number of characters to delete. 
williamr@2
   127
	@return Indicates whether or not two paragraphs have been merged as a 
williamr@2
   128
	result of the delete, so that the resulting paragraph needs to be 
williamr@2
   129
	reformatted. This value is only relevant to rich text, so for plain and 
williamr@2
   130
	global text implementations, the function always returns EFalse. */
williamr@2
   131
	virtual TBool DeleteL(TInt aPos,TInt aLength) = 0;
williamr@2
   132
williamr@2
   133
	// interrogation functions
williamr@2
   134
	
williamr@2
   135
	/**  Gets a read-only pointer descriptor to a portion of the text.
williamr@2
   136
	
williamr@2
   137
	@param aStartPos A valid document position from which to read.
williamr@2
   138
	@param aLength If specified, the number of characters to read,inclusive of 
williamr@2
   139
	the character at position aStartPos. If not specified, the read continues
williamr@2
   140
	to the end of the document, or the end of the segment if using segmented storage.
williamr@2
   141
	@return  Read-only pointer descriptor to a portion of the text. */ 
williamr@2
   142
 	virtual TPtrC Read(TInt aStartPos) const = 0;
williamr@2
   143
williamr@2
   144
	/** Gets a read-only pointer descriptor to a portion of the text.
williamr@2
   145
	
williamr@2
   146
	@param aStartPos A valid document position from which to read. 
williamr@2
   147
	@param aLength If specified, the number of characters to read, inclusive of 
williamr@2
   148
	the character at position aStartPos. If not specified, the read continues 
williamr@2
   149
	to the end of the document, or the end of the segment if using segmented 
williamr@2
   150
	storage. 
williamr@2
   151
	@return Read-only pointer descriptor to a portion of the text. */
williamr@2
   152
	virtual TPtrC Read(TInt aStartPos,TInt aLength) const = 0;
williamr@2
   153
	
williamr@2
   154
	/** Copies a portion of the text into a descriptor.
williamr@2
   155
	
williamr@2
   156
	Starts at the position specified and continues to the end of the document. 
williamr@2
   157
	A length may optionally be specified.
williamr@2
   158
	
williamr@2
   159
	@param aBuf Buffer which on return contains the extracted text.
williamr@2
   160
	@param aPos The document position from which to copy. Must be a valid 
williamr@2
   161
	position, or a panic occurs.
williamr@2
   162
	@param aLength If specified, the number of characters to copy. */ 
williamr@2
   163
 	virtual void Extract(TDes& aBuf,TInt aPos=0) const = 0;
williamr@2
   164
williamr@2
   165
	/** Copies a portion of the text into a descriptor. Starts at the position 
williamr@2
   166
	specified and continues to the end of the document. A length may optionally 
williamr@2
   167
	be specified.
williamr@2
   168
	
williamr@2
   169
	@param aBuf Buffer which on return contains the extracted text. 
williamr@2
   170
	@param aPos The document position from which to copy. Must be a valid 
williamr@2
   171
	position, or a panic occurs. 
williamr@2
   172
	@param aLength If specified, the number of characters to copy. */
williamr@2
   173
	virtual void Extract(TDes& aBuf,TInt aPos,TInt aLength) const = 0;
williamr@2
   174
williamr@2
   175
	// copy and paste
williamr@2
   176
	/** Copies a portion of the text to the clipboard.
williamr@2
   177
	
williamr@2
   178
	@param aStore The clipboard's store (see class CClipboard). 
williamr@2
   179
	@param aDictionary The clipboard's stream dictionary (see class CClipboard). 
williamr@2
   180
	@param aPos A valid document position from which to begin copying. 
williamr@2
   181
	@param aLength The number of characters to copy. */
williamr@2
   182
	virtual void CopyToStoreL(CStreamStore& aStore,CStreamDictionary& aDictionary,TInt aPos,TInt aLength) const = 0;
williamr@2
   183
	
williamr@2
   184
	/** Pastes the contents of the clipboard into the text object at the 
williamr@2
   185
	specified document position.
williamr@2
   186
	
williamr@2
   187
	@param aStore The clipboard's store (see class CClipboard). 
williamr@2
   188
	@param aDictionary The clipboard's stream dictionary (see class CClipboard). 
williamr@2
   189
	@param aPos A valid document position at which to paste the text. 
williamr@2
   190
	@return The number of characters pasted. */
williamr@2
   191
	virtual TInt PasteFromStoreL(const CStreamStore& aStore,const CStreamDictionary& aDictionary,TInt aPos) = 0;
williamr@2
   192
williamr@2
   193
	// utility functions
williamr@2
   194
	 
williamr@2
   195
	/** Returns a count of the number of words in the document.
williamr@2
   196
	
williamr@2
   197
	@return The number of words in the document */
williamr@2
   198
	virtual TInt WordCount() const = 0;
williamr@2
   199
	
williamr@2
   200
	/** Returns a count of the number of paragraphs in the document.
williamr@2
   201
	
williamr@2
   202
	@return The number of paragraphs in the document. Notes: The end-of-text 
williamr@2
   203
	paragraph delimiter at the end of every document means this function 
williamr@2
   204
	always returns a count of at least one. */
williamr@2
   205
	virtual TInt ParagraphCount() const = 0;
williamr@2
   206
	 
williamr@2
   207
	/** Returns a count of the number of characters in the document, 
williamr@2
   208
	excluding the end-of-text paragraph delimiter.
williamr@2
   209
	
williamr@2
   210
	@return The number of characters in the document. */
williamr@2
   211
	virtual TInt DocumentLength() const = 0;
williamr@2
   212
	
williamr@2
   213
	/** Updates a document position to the start of the paragraph.
williamr@2
   214
	
williamr@2
   215
	@param aPos Initially specifies a valid document position. On return, set 
williamr@2
   216
	to the document position of the first character in the paragraph. 
williamr@2
   217
	@return The number of characters skipped in scanning to the start of the 
williamr@2
   218
	paragraph. */
williamr@2
   219
	virtual TInt ToParagraphStart(TInt& aPos) const = 0;
williamr@2
   220
	inline TBool HasChanged() const;
williamr@2
   221
	
williamr@2
   222
	/** Returns the start position and length of the word that contains the 
williamr@2
   223
	specified document position.
williamr@2
   224
	
williamr@2
   225
	@param aCurrentPos A valid document position. 
williamr@2
   226
	@param aStartPos On return, the document position of the first character in 
williamr@2
   227
	the word containing document position aCurrentPos. 
williamr@2
   228
	@param aLength On return, the length of the word containing document 
williamr@2
   229
	position aCurrentPos. Does not include the trailing word delimiter 
williamr@2
   230
	character. 
williamr@2
   231
	@param aPictureIsDelimiter Specifies whether picture characters should be 
williamr@2
   232
	considered to be word delimiters. For example, this value might be EFalse 
williamr@2
   233
	when navigating a document, but ETrue when carrying out spell checking. 
williamr@2
   234
	@param aPunctuationIsDelimiter Specifies whether puncutation characters 
williamr@2
   235
	should be considered to be word delimiters. */
williamr@2
   236
	virtual void GetWordInfo(TInt aCurrentPos,TInt& aStartPos,TInt& aLength,
williamr@2
   237
							 TBool aPictureIsDelimiter,TBool aPunctuationIsDelimiter) const = 0;
williamr@2
   238
williamr@2
   239
	IMPORT_C virtual TInt ScanWords(TInt& aPos,TUint& aScanMask) const;
williamr@2
   240
	IMPORT_C virtual TInt ScanParas(TInt& aPos,TUint& aScanMask) const;
williamr@2
   241
	IMPORT_C virtual void SetHasChanged(TBool aHasChanged);
williamr@2
   242
williamr@2
   243
	// Internal to Symbian - support for front-end-processor inline editing
williamr@2
   244
	IMPORT_C void StartFepInlineEditL(TBool& aParagraphContainingStartPositionOfInlineTextHasChangedFormat,TInt& aNumberOfCharactersSuccessfullyDeleted,TInt& aNumberOfCharactersSuccessfullyInserted,TInt& aPositionOfInsertionPointInDocument,TInt aNewPositionOfInsertionPointInDocument,const TDesC& aInitialInlineText,TInt aPositionOfInlineTextInDocument,TInt aNumberOfCharactersToHide,MFepInlineTextFormatRetriever& aInlineTextFormatRetriever);
williamr@2
   245
	IMPORT_C void UpdateFepInlineTextL(TBool& aParagraphContainingStartPositionOfInlineTextHasChangedFormat,TInt& aNumberOfCharactersSuccessfullyDeleted,TInt& aNumberOfCharactersSuccessfullyInserted,TInt& aPositionOfInsertionPointInDocument,TInt aNewPositionOfInsertionPointInDocument,const TDesC& aNewInlineText);
williamr@2
   246
	IMPORT_C void CommitFepInlineEditL(TBool& aParagraphContainingStartPositionOfInlineTextHasChangedFormat,TInt& aNumberOfCharactersSuccessfullyDeleted,TInt& aNumberOfCharactersSuccessfullyInserted,TInt& aPositionOfInsertionPointInDocument,TInt aNewPositionOfInsertionPointInDocument);
williamr@2
   247
	IMPORT_C void CancelFepInlineEdit(TBool& aParagraphContainingStartPositionOfInlineTextHasChangedFormat,TInt& aNumberOfCharactersSuccessfullyDeleted,TInt& aNumberOfCharactersSuccessfullyInserted,TInt& aPositionOfInsertionPointInDocument,TInt aNewPositionOfInsertionPointInDocument);
williamr@2
   248
	
williamr@2
   249
	IMPORT_C virtual void ExtendedInterface(TAny*& aInterface, TUid aInterfaceId);
williamr@2
   250
williamr@2
   251
	IMPORT_C TInt GetPositionOfInlineTextInDocument() const;
williamr@2
   252
	IMPORT_C TInt GetLengthOfInlineText() const;
williamr@2
   253
williamr@2
   254
	/** Storage type */
williamr@2
   255
	enum TDocumentStorage
williamr@2
   256
		{
williamr@2
   257
		 /** Storage uses a flat buffer (CBufFlat). */
williamr@2
   258
		EFlatStorage, 
williamr@2
   259
		/** Storage uses a segmented buffer (CBufSeg). */
williamr@2
   260
		ESegmentedStorage
williamr@2
   261
		};
williamr@2
   262
		
williamr@2
   263
	/** Miscellaneous constants. */
williamr@2
   264
 	enum 
williamr@2
   265
		{
williamr@2
   266
		/** Granularity of the buffer, default 256 characters. */
williamr@2
   267
		EDefaultTextGranularity = 256
williamr@2
   268
		};
williamr@2
   269
williamr@2
   270
	/*
williamr@2
   271
	Useful Unicode character definitions.
williamr@2
   272
	ETEXT uses standard Unicode to store its text. In particular 0x2029 and 0x2028 are used
williamr@2
   273
	as paragraph separator and forced line break respectively.
williamr@2
   274
	*/
williamr@2
   275
	enum
williamr@2
   276
		{								// Unicode name, etc.
williamr@2
   277
		/** Tab stop. */
williamr@2
   278
		ETabCharacter = 0x0009,			// horizontal tabulation
williamr@2
   279
		/** New page. */
williamr@2
   280
		EPageBreak = 0x000C,			// form feed
williamr@2
   281
		/** Visible space character. */
williamr@2
   282
		ESpace = 0x0020,				// space
williamr@2
   283
		EApostrophe = 0x0027,			// apostrophe
williamr@2
   284
		EHyphenMinus = 0x002D,			// hyphen-minus; generally used for hyphen, but see 0x2010
williamr@2
   285
		/** A hard (non-breaking) space. */
williamr@2
   286
		ENonBreakingSpace = 0x00A0,		// no-break space
williamr@2
   287
		/** A soft hyphen (ensures that a hyphen followed by a new line will be
williamr@2
   288
		inserted at that point should a line break be required anywhere within
williamr@2
   289
		the word).
williamr@2
   290
		 */
williamr@2
   291
		EPotentialHyphen = 0x00AD,		// soft hyphen
williamr@2
   292
		EHyphen = 0x2010,				// hyphen; intended as an unambiguous hyphen codepoint
williamr@2
   293
		/** A hard (non-breaking) hyphen. */
williamr@2
   294
		ENonBreakingHyphen = 0x2011,	// non-breaking hyphen
williamr@2
   295
		ELeftSingleQuote = 0x2018,		// left single quotation mark
williamr@2
   296
		ERightSingleQuote = 0x2019,		// right single quotation mark
williamr@2
   297
		ELeftDoubleQuote = 0x201C,		// left double quotation mark
williamr@2
   298
		ERightDoubleQuote = 0x201D,		// right double quotation mark
williamr@2
   299
		EBullet = 0x2022,				// bullet
williamr@2
   300
		EEllipsis = 0x2026,				// horizontal ellipsis
williamr@2
   301
		/** Forced line break. */
williamr@2
   302
		ELineBreak = 0x2028,			// line separator
williamr@2
   303
		/** Paragraph delimiter. */
williamr@2
   304
		EParagraphDelimiter = 0x2029,	// paragraph separator
williamr@2
   305
		/** Represents a picture inserted into the text object. */
williamr@2
   306
		EPictureCharacter = 0xFFFC,		// object replacement character
williamr@2
   307
		EZeroWidthNoBreakSpace = 0xFEFF,// zero-width no-break space
williamr@2
   308
		EByteOrderMark = 0xFEFF,		// byte order mark; SAME AS zero-width no-break space
williamr@2
   309
		EReversedByteOrderMark = 0xFFFE	// not a character; evidence of endianness opposite to that of platform
williamr@2
   310
		};
williamr@2
   311
williamr@2
   312
protected:
williamr@2
   313
	// support for front-end-processor inline-editing
williamr@2
   314
	IMPORT_C void OverrideFormatOfInlineTextIfApplicable(TPtrC& aView,TCharFormat& aFormat,TInt aStartPos) const;
williamr@2
   315
williamr@2
   316
	TBool iHasChanged;
williamr@2
   317
williamr@2
   318
private:
williamr@2
   319
	void SetAndTransferOwnershipOfInlineEditDataL(CInlineEditData* aInlineEditData);
williamr@2
   320
	CInlineEditData* InlineEditData() const;
williamr@2
   321
	void DeleteInlineEditDataAndSetToNull();
williamr@2
   322
	TBool DeleteWithoutDestroyingFormatL(TInt aPos, TInt aLength);
williamr@2
   323
williamr@2
   324
	CEditableTextOptionalData* iOptionalData;
williamr@2
   325
	};
williamr@2
   326
williamr@2
   327
williamr@2
   328
// Information relating to the number of components owned by an editable text instance.
williamr@2
   329
williamr@2
   330
/** 
williamr@2
   331
Provides information about the number of components owned by an editable 
williamr@2
   332
text object. 
williamr@2
   333
williamr@2
   334
Components are fields and (rich text only), pictures and styles.
williamr@2
   335
williamr@2
   336
An instance of this class is returned by CPlainText::ComponentInfo() and by 
williamr@2
   337
CRichText::ComponentInfo(). 
williamr@2
   338
@publishedAll
williamr@2
   339
@released
williamr@2
   340
*/
williamr@2
   341
class TEtextComponentInfo
williamr@2
   342
	{
williamr@2
   343
public:
williamr@2
   344
	IMPORT_C TEtextComponentInfo();
williamr@2
   345
	IMPORT_C TEtextComponentInfo(TInt aFieldCount,TInt aPictureCount,TInt aStyleCount);
williamr@2
   346
public:
williamr@2
   347
	/** The number of fields in the text object. */
williamr@2
   348
	TInt iFieldCount;
williamr@2
   349
	/** The number of pictures in the text object (rich text only). */
williamr@2
   350
	TInt iPictureCount;
williamr@2
   351
	/** The number of styles owned or referenced by the text object (rich text only). */
williamr@2
   352
	TInt iStyleCount;
williamr@2
   353
	};
williamr@2
   354
williamr@2
   355
/** 
williamr@2
   356
Page table.
williamr@2
   357
williamr@2
   358
This is an array of integers; each integer represents the number or characters 
williamr@2
   359
on a page. 
williamr@2
   360
@publishedAll
williamr@2
   361
@released
williamr@2
   362
*/
williamr@2
   363
typedef CArrayFix<TInt> TPageTable;
williamr@2
   364
williamr@2
   365
/** 
williamr@2
   366
Stores and manipulates plain text. 
williamr@2
   367
williamr@2
   368
Plain text cannot be displayed, so this class provides no support for formatting. 
williamr@2
   369
It is purely an in-memory buffer for text, and provides services that act 
williamr@2
   370
upon it. These services include the following: import from and export to streams, 
williamr@2
   371
optionally translating between Unicode and other encodings; reading and writing 
williamr@2
   372
of field data; extraction of text; finding word and paragraph boundaries.
williamr@2
   373
williamr@2
   374
The type and size of in-memory buffer can be specified upon object construction. 
williamr@2
   375
However, if no specification is provided a buffer is provided with default 
williamr@2
   376
settings. There are two types of storage buffer: segmented buffers and flat 
williamr@2
   377
buffers. The default buffer for plain text is segmented (CBufSeg). This is 
williamr@2
   378
most efficient when a large quantity of text is to be stored, or will have 
williamr@2
   379
a large dynamic range. A flat buffer (CBufFlat) is most appropriate for storing 
williamr@2
   380
small quantities of text of bounded length. For most uses, however, a segmented 
williamr@2
   381
buffer is sufficient. 
williamr@2
   382
@publishedAll
williamr@2
   383
@released
williamr@2
   384
*/
williamr@2
   385
class CPlainText: public CEditableText
williamr@2
   386
	{
williamr@2
   387
public:
williamr@2
   388
	/** Line delimiter translation. */
williamr@2
   389
	enum TTextOrganisation
williamr@2
   390
		{
williamr@2
   391
		 
williamr@2
   392
		/** When importing text from a text file, all line feeds are 
williamr@2
   393
		converted into paragraph delimiters.
williamr@2
   394
		
williamr@2
   395
		When exporting text to a text file, lines do not wrap and paragraph 
williamr@2
   396
		delimiters are converted into CR/LF pairs. */
williamr@2
   397
		EOrganiseByParagraph,
williamr@2
   398
		/** When importing text from a text file, a single line feed or a 
williamr@2
   399
		line feed followed by a carriage return is converted into a space 
williamr@2
   400
		character. A line feed which is followed by another line feed is 
williamr@2
   401
		converted into a CEditableText::EParagraphDelimiter.
williamr@2
   402
		
williamr@2
   403
		When exporting text to a text file, lines wrap at the specified wrap 
williamr@2
   404
		width and paragraph delimiters are converted into CR/LFs pairs. */
williamr@2
   405
		EOrganiseByLine
williamr@2
   406
		};
williamr@2
   407
williamr@2
   408
	/**  Scan mask values. */ 
williamr@2
   409
	enum
williamr@2
   410
		{
williamr@2
   411
		/** Scan direction is backwards. The default is forwards. */
williamr@2
   412
		EScanBackwards = 0x01,
williamr@2
   413
		/** If the current document position is a word or paragraph boundary, no
williamr@2
   414
		scan occurs.*/
williamr@2
   415
		EScanStayIfBoundary = 0x02,
williamr@2
   416
		/** Scan to the first character in the word or paragraph. */
williamr@2
   417
		EScanToUnitStart = 0x04,
williamr@2
   418
		/** Scan to the last character in the word or paragraph. */
williamr@2
   419
		EScanToUnitEnd = 0x08,
williamr@2
   420
		/** Treat adjacent word or paragraph delimiters as a single delimiter.
williamr@2
   421
		Required when performing a word count, for example.
williamr@2
   422
		 */
williamr@2
   423
		EScanJoinDelimiters = 0x10,
williamr@2
   424
		/** Picture characters are considered to be word delimiters. */
williamr@2
   425
		EScanPictureIsDelimiter = 0x20,
williamr@2
   426
		/** Punctuation characters, except hyphens and apostrophes, are considered
williamr@2
   427
		to be word delimiters. */
williamr@2
   428
		EScanPunctuationIsDelimiter = 0x40
williamr@2
   429
		};
williamr@2
   430
williamr@2
   431
	
williamr@2
   432
	/** Used in text scanning functions to indicate the end of the document 
williamr@2
   433
	has been passed. */
williamr@2
   434
	enum TScanDataEnd
williamr@2
   435
		{
williamr@2
   436
		/** Indicates that a scan has passed the end of text paragraph delimiter. */
williamr@2
   437
		EScanEndOfData = -1
williamr@2
   438
		};
williamr@2
   439
williamr@2
   440
	class TImportExportParam
williamr@2
   441
	/** Parameters for importing or exporting text using 
williamr@2
   442
	CPlainText::ImportTextL() or CPlainText::ExportTextL(). */
williamr@2
   443
		{
williamr@2
   444
		public:
williamr@2
   445
		TImportExportParam():
williamr@2
   446
			iOrganisation(EOrganiseByParagraph),
williamr@2
   447
			iMaxOutputChars(KMaxTInt),
williamr@2
   448
			iMaxInputChars(KMaxTInt),
williamr@2
   449
			iMaxLineLength(KMaxTInt),
williamr@2
   450
			iOutputInternal(FALSE),
williamr@2
   451
			iInputInternal(FALSE),
williamr@2
   452
			iForeignEncoding(0),
williamr@2
   453
			iGuessForeignEncoding(FALSE),
williamr@2
   454
			iFileSession(NULL),
williamr@2
   455
			iReserved(0)
williamr@2
   456
		/** Default constructor. All member data is assigned default values. 
williamr@2
   457
		For details, see the member data. */
williamr@2
   458
			{
williamr@2
   459
			}
williamr@2
   460
williamr@2
   461
		/** Controls how line delimiters are translated. By default, 
williamr@2
   462
		EOrganiseByParagraph.
williamr@2
   463
		
williamr@2
   464
		@see CPlainText::TTextOrganisation */
williamr@2
   465
		TTextOrganisation iOrganisation;
williamr@2
   466
		/** The maximum number of characters to write to the stream (when 
williamr@2
   467
		exporting) or to write to the text object (when importing). By default, 
williamr@2
   468
		KMaxTInt. */
williamr@2
   469
		TInt iMaxOutputChars;
williamr@2
   470
		/** The maximum number of characters to read from the stream (when 
williamr@2
   471
		importing) or to read from the text object (when exporting). By 
williamr@2
   472
		default, KMaxTInt. */
williamr@2
   473
		TInt iMaxInputChars;
williamr@2
   474
		/** The wrap width as a number of characters. 
williamr@2
   475
		
williamr@2
   476
		Only relevant when exporting by line, (iOrganisation is 
williamr@2
   477
		CPlainText::EOrganiseByLine). Not used in CPlainText::ImportTextL(). 
williamr@2
   478
		By default, KMaxTInt. */
williamr@2
   479
		TInt iMaxLineLength;  // maximum line length when exporting text
williamr@2
   480
		/** If ETrue, output is in internal format, so is written according to 
williamr@2
   481
		native endianness. Used in CPlainText::ExportTextL(). By default, 
williamr@2
   482
		EFalse. */
williamr@2
   483
		TBool iOutputInternal; 
williamr@2
   484
		/** If ETrue, input is in internal format, so is read according to 
williamr@2
   485
		native endianness. Used in CPlainText::ImportTextL(). By default, 
williamr@2
   486
		EFalse. */
williamr@2
   487
		TBool iInputInternal;	
williamr@2
   488
		/** The identifier of the foreign character set encoding to be used 
williamr@2
   489
		to convert from or to. 
williamr@2
   490
williamr@2
   491
		Not used if iGuessForeignEncoding is true. If conversion to/from 
williamr@2
   492
		iForeignEncoding is not available on the phone, the function leaves 
williamr@2
   493
		with KErrNotSupported. By default, zero. */
williamr@2
   494
		TUint iForeignEncoding;			
williamr@2
   495
		/** If ETrue, an attempt is made to guess the encoding of the foreign 
williamr@2
   496
		text being imported before converting it into Unicode. Used in 
williamr@2
   497
		CPlainText::ImportTextL(). If EFalse, the value specified in 
williamr@2
   498
		iForeignEncoding (if any) is used. If none of the available character 
williamr@2
   499
		conversion plug-ins on the phone return a confidence level greater 
williamr@2
   500
		than 50%, CPlainText::ImportTextL() leaves with KErrNotSupported. 
williamr@2
   501
		By default, false. */
williamr@2
   502
		TBool iGuessForeignEncoding;		
williamr@2
   503
		/** If non-null, a connected file server session used to load character 
williamr@2
   504
		conversion data. Only relevant if the text needs to be converted to or 
williamr@2
   505
		from Unicode. By default, null. */
williamr@2
   506
		RFs* iFileSession;
williamr@2
   507
		TUint iReserved;
williamr@2
   508
		};
williamr@2
   509
williamr@2
   510
 	class TImportExportResult
williamr@2
   511
	/** Results of importing or exporting text using CPlainText::ImportTextL() 
williamr@2
   512
	or CPlainText::ExportTextL(). */
williamr@2
   513
		{
williamr@2
   514
		public:
williamr@2
   515
		TImportExportResult():
williamr@2
   516
			iOutputChars(0),
williamr@2
   517
			iInputChars(0),
williamr@2
   518
			iForeignEncoding(0),
williamr@2
   519
			iReserved(0)
williamr@2
   520
		/** Default constructor. All member data is initialised to zero. */
williamr@2
   521
			{
williamr@2
   522
			}
williamr@2
   523
williamr@2
   524
		/** The number of characters written to the stream (when exporting) or 
williamr@2
   525
		written to this text object (when importing). */
williamr@2
   526
		TInt iOutputChars;
williamr@2
   527
		/** The number of characters read from the stream (when importing) or 
williamr@2
   528
		read from this text object (when exporting). */
williamr@2
   529
		TInt iInputChars;
williamr@2
   530
		/** The identifier for the character set encoding selected when 
williamr@2
   531
		importing text whose encoding is guessed (iGuessForeignEncoding was 
williamr@2
   532
		true). */
williamr@2
   533
		TUint iForeignEncoding;				// foreign encoding actually used; useful if the encoding was guessed
williamr@2
   534
		TUint iReserved;		
williamr@2
   535
		};
williamr@2
   536
			   
williamr@2
   537
	IMPORT_C static CPlainText* NewL(TDocumentStorage aStorage = ESegmentedStorage,
williamr@2
   538
									 TInt aDefaultTextGranularity = EDefaultTextGranularity);
williamr@2
   539
	IMPORT_C static CPlainText* NewL(const CStreamStore& aStore,TStreamId aStreamId,
williamr@2
   540
									 MTextFieldFactory* aFieldFactory = NULL,
williamr@2
   541
									 TDocumentStorage aStorage = ESegmentedStorage);
williamr@2
   542
	IMPORT_C virtual ~CPlainText();
williamr@2
   543
williamr@2
   544
	// primary persistence functions
williamr@2
   545
	IMPORT_C virtual void StoreComponentsL(CStreamStore& aStore,CStoreMap& aMap) const;
williamr@2
   546
	IMPORT_C virtual void RestoreComponentsL(const CStreamStore& aStore);
williamr@2
   547
	IMPORT_C virtual void ExternalizeL(RWriteStream& aStream) const;
williamr@2
   548
	IMPORT_C virtual void InternalizeL(RReadStream& aStream);
williamr@2
   549
williamr@2
   550
	// secondary persistence functions
williamr@2
   551
	IMPORT_C void ExternalizePlainTextL(RWriteStream& aStream) const;
williamr@2
   552
	IMPORT_C void InternalizePlainTextL(RReadStream& aStream);
williamr@2
   553
	IMPORT_C void ExternalizePlainTextNoLengthCountL(RWriteStream& aStream) const; // Deprecated
williamr@2
   554
	IMPORT_C void InternalizePlainTextL(RReadStream& aStream,TInt aLength); // Deprecated
williamr@2
   555
williamr@2
   556
	// import and export text
williamr@2
   557
	IMPORT_C void ImportTextL(TInt aPos,RReadStream& aInput,TTextOrganisation aTextOrganisation,
williamr@2
   558
							  TInt aMaxOutputChars = KMaxTInt,TInt aMaxInputChars = KMaxTInt,
williamr@2
   559
							  TInt* aOutputChars = NULL,TInt* aInputChars = NULL);
williamr@2
   560
	IMPORT_C void ExportTextL(TInt aPos,RWriteStream& aOutput,TTextOrganisation aTextOrganisation,
williamr@2
   561
							  TInt aMaxOutputChars = KMaxTInt,TInt aMaxInputChars = KMaxTInt,
williamr@2
   562
							  TInt aMaxLineLength = KMaxTInt,
williamr@2
   563
							  TInt* aOutputChars = NULL,TInt* aInputChars = NULL) const;
williamr@2
   564
	IMPORT_C virtual TInt ImportTextFileL(TInt aPos,const TDes& aFileName,TTextOrganisation aTextOrganisation);
williamr@2
   565
	IMPORT_C virtual void ExportAsTextL(const TDes& aFileName,TTextOrganisation aTextOrganisation,
williamr@2
   566
										TInt aMaxLineLength) const;
williamr@2
   567
williamr@2
   568
	// import and export text AND optionally translate from or to a non-Unicode encoding
williamr@2
   569
	IMPORT_C void ImportTextL(TInt aPos,RReadStream& aInput,
williamr@2
   570
							  const TImportExportParam& aParam,TImportExportResult& aResult);
williamr@2
   571
	IMPORT_C void ExportTextL(TInt aPos,RWriteStream& aOutput,
williamr@2
   572
							  const TImportExportParam& aParam,TImportExportResult& aResult) const;
williamr@2
   573
williamr@2
   574
	// read and write field data
williamr@2
   575
	IMPORT_C void StoreFieldComponentsL(CStreamStore& aStore,CStoreMap& aMap) const;
williamr@2
   576
	IMPORT_C void RestoreFieldComponentsL(const CStreamStore& aStore);
williamr@2
   577
	IMPORT_C void ExternalizeFieldDataL(RWriteStream& aStream) const;
williamr@2
   578
	IMPORT_C void InternalizeFieldDataL(RReadStream& aStream);
williamr@2
   579
williamr@2
   580
	// modifier functions
williamr@2
   581
	IMPORT_C virtual void Reset();
williamr@2
   582
	IMPORT_C virtual void InsertL(TInt aPos,const TChar& aChar);
williamr@2
   583
	IMPORT_C virtual void InsertL(TInt aPos,const TDesC& aBuf);
williamr@2
   584
	IMPORT_C virtual TBool DeleteL(TInt aPos,TInt aLength);
williamr@2
   585
williamr@2
   586
	// interrogation functions
williamr@2
   587
	IMPORT_C virtual TPtrC Read(TInt aStartPos) const;
williamr@2
   588
	IMPORT_C virtual TPtrC Read(TInt aStartPos,TInt aLength) const;
williamr@2
   589
	IMPORT_C virtual void Extract(TDes& aBuf,TInt aPos=0) const;
williamr@2
   590
	IMPORT_C virtual void Extract(TDes& aBuf,TInt aPos,TInt aLength) const;
williamr@2
   591
williamr@2
   592
	// Flags for ExtractSelectively
williamr@2
   593
	enum
williamr@2
   594
		{
williamr@2
   595
		EExtractAll = 0,	// extract all characters
williamr@2
   596
		EExtractVisible = 1,	// discard control characters and soft hyphens; change par and line separators to spaces
williamr@2
   597
		EExcludeInlineEditedText = 2 // discard the inline text
williamr@2
   598
		};
williamr@2
   599
	IMPORT_C void ExtractSelectively(TDes& aBuf,TInt aPos,TInt aLength,TUint aFlags);
williamr@2
   600
williamr@2
   601
	// copy and paste
williamr@2
   602
	IMPORT_C virtual void CopyToStoreL(CStreamStore& aStore,CStreamDictionary& aDictionary,TInt aPos,TInt aLength) const;
williamr@2
   603
	IMPORT_C virtual TInt PasteFromStoreL(const CStreamStore& aStore,const CStreamDictionary& aDictionary,TInt aPos);
williamr@2
   604
williamr@2
   605
	// utility functions
williamr@2
   606
	IMPORT_C void SetPageTable(TPageTable* aPageTable);
williamr@2
   607
	IMPORT_C TInt PageContainingPos(TInt aPos) const;
williamr@2
   608
	IMPORT_C virtual TInt DocumentLength() const;
williamr@2
   609
 	IMPORT_C virtual TInt WordCount() const;
williamr@2
   610
	IMPORT_C virtual TInt ParagraphCount() const;
williamr@2
   611
	IMPORT_C virtual TInt ToParagraphStart(TInt& aPos) const;
williamr@2
   612
	IMPORT_C virtual TInt CharPosOfParagraph(TInt& aLength,TInt aParaOffset) const;
williamr@2
   613
	IMPORT_C virtual TInt ParagraphNumberForPos(TInt& aPos) const;
williamr@2
   614
	IMPORT_C virtual void GetWordInfo(TInt aCurrentPos,TInt& aStartPos,TInt& aLength,
williamr@2
   615
						TBool aPictureIsDelimiter,TBool aPunctuationIsDelimiter) const;
williamr@2
   616
	IMPORT_C virtual TInt ScanWords(TInt& aPos,TUint& aScanMask) const;
williamr@2
   617
	IMPORT_C virtual TInt ScanParas(TInt& aPos,TUint& aScanMask) const;
williamr@2
   618
	IMPORT_C virtual TEtextComponentInfo ComponentInfo() const;
williamr@2
   619
	//
williamr@2
   620
	// Field functions
williamr@2
   621
	IMPORT_C void SetFieldFactory(MTextFieldFactory* aFactory);
williamr@2
   622
	inline const MTextFieldFactory* FieldFactory() const;
williamr@2
   623
	IMPORT_C CTextField* NewTextFieldL(TUid aFieldType) const;
williamr@2
   624
	IMPORT_C void InsertFieldL(TInt aPos,CTextField* aField,TUid aFieldType); 
williamr@2
   625
	IMPORT_C virtual void UpdateFieldL(TInt aPos); 
williamr@2
   626
	IMPORT_C void UpdateAllFieldsL(); 
williamr@2
   627
	IMPORT_C TInt FieldCount() const;
williamr@2
   628
	IMPORT_C const CTextField* TextField(TInt aPos) const;
williamr@2
   629
	IMPORT_C TBool FindFields(TInt aPos) const; 
williamr@2
   630
	IMPORT_C TBool FindFields(TFindFieldInfo& aInfo,TInt aPos,TInt aRange=0) const;
williamr@2
   631
	IMPORT_C TBool RemoveField(TInt aPos);  
williamr@2
   632
	IMPORT_C TBool ConvertFieldToText(TInt aPos); 
williamr@2
   633
	IMPORT_C void ConvertAllFieldsToText();
williamr@2
   634
	
williamr@2
   635
	IMPORT_C void ExtendedInterface(TAny*& aInterface, TUid aInterfaceId); // from CEditableText
williamr@2
   636
williamr@2
   637
protected:
williamr@2
   638
	IMPORT_C CPlainText();
williamr@2
   639
	IMPORT_C void ConstructL(TDocumentStorage aStorage = ESegmentedStorage,
williamr@2
   640
							 TInt aDefaultTextGranularity = EDefaultTextGranularity);
williamr@2
   641
	IMPORT_C void ConstructL(const CStreamStore& aStore,TStreamId aStreamId,MTextFieldFactory* aFieldFactory,
williamr@2
   642
							 TDocumentStorage aStorage = ESegmentedStorage);
williamr@2
   643
	IMPORT_C void DoConstructL(TDocumentStorage aStorage,TInt aDefaultTextGranularity,
williamr@2
   644
							   MTextFieldFactory* aFieldFactory = NULL);
williamr@2
   645
	void DoExtract(TDes& aBuf,TInt aPos,TInt aLength,TUint aFlags = 0) const;
williamr@2
   646
	IMPORT_C void PtInsertL(TInt aInsertPos,const TDesC& aBuf);
williamr@2
   647
	IMPORT_C void DoPtInsertL(TInt aPos,const TDesC& aBuf);
williamr@2
   648
	IMPORT_C TBool DoPtDelete(TInt aPos,TInt aLength);
williamr@2
   649
	void InsertL(TInt aPos,const CPlainText* aText);
williamr@2
   650
	TBool Delete(TInt aPos,TInt aLength);
williamr@2
   651
williamr@2
   652
	// streaming
williamr@2
   653
	IMPORT_C void DoExternalizeFieldDataL(RWriteStream& aStream) const;
williamr@2
   654
	IMPORT_C void DoInternalizeFieldDataL(RReadStream& aStream);
williamr@2
   655
	IMPORT_C void DoExternalizePlainTextL(RWriteStream& aStream) const;
williamr@2
   656
	IMPORT_C void DoInternalizePlainTextL(RReadStream& aStream);
williamr@2
   657
	TStreamId DoCopyToStoreL(CStreamStore& aStore,CStreamDictionary& aDictionary,TInt aPos,TInt aLength) const;
williamr@2
   658
	TInt DoPasteFromStoreL(const CStreamStore& aStore,TStreamId aStreamId,TInt aPos);
williamr@2
   659
	void CopyComponentsL(CStreamStore& aStore,CStoreMap& aMap,TInt aPos,TInt aLength) const;
williamr@2
   660
	void PasteComponentsL(const CStreamStore& aStore,TInt aPos);
williamr@2
   661
	void CopyToStreamL(RWriteStream& aStream,TInt aPos,TInt aLength) const;
williamr@2
   662
williamr@2
   663
	// utility functions
williamr@2
   664
	inline static void ConsumeAdornmentL(RReadStream& aStream);
williamr@2
   665
	inline static TUid UidFromStreamL(RReadStream& aStream);
williamr@2
   666
protected:
williamr@2
   667
	enum
williamr@2
   668
		{
williamr@2
   669
		EImportBufSize = 512,
williamr@2
   670
		EBiggestCharacterPaste=0x100000
williamr@2
   671
		};
williamr@2
   672
williamr@2
   673
	enum TUnitOfText
williamr@2
   674
		{
williamr@2
   675
		EUnitIsWord,
williamr@2
   676
		EUnitIsParagraph
williamr@2
   677
		};
williamr@2
   678
williamr@2
   679
	struct SScanData
williamr@2
   680
		{
williamr@2
   681
		TInt pos;			// current character position
williamr@2
   682
		TInt oldPos;		// old character position
williamr@2
   683
		TText* buf;			// address of data (Unicode-aware)
williamr@2
   684
		TInt currentSegLen; // number of characters left in segment
williamr@2
   685
		TInt totalBufLen;	// number of unread characters
williamr@2
   686
		TInt delta;			// specifies current scan direction
williamr@2
   687
		TUint32 scanMask;	// bitmask containing the scan settings
williamr@2
   688
		enum
williamr@2
   689
			{
williamr@2
   690
			EInsideUnit = 0x10000000,
williamr@2
   691
			EStopEnd = 0x20000000,
williamr@2
   692
			EStopBegin = 0x40000000,
williamr@2
   693
			EIsDelimiter = 0x80000000
williamr@2
   694
			};
williamr@2
   695
		};
williamr@2
   696
williamr@2
   697
private:
williamr@2
   698
	CPlainText(const CPlainText& aPlainTextDoc);
williamr@2
   699
	CPlainText& operator=(const CPlainText& aPlainTextDoc);
williamr@2
   700
	TInt PasteFromStreamL(RReadStream& aStream,TInt aPos);
williamr@2
   701
	TInt DoPasteFromStreamL(RReadStream& aStream, TInt aPos);
williamr@2
   702
	void InsertEodL();
williamr@2
   703
	void InitScanControl(TInt& aPos,TUint& aScanMask,TUnitOfText aContext,SScanData& aScanData) const;
williamr@2
   704
	void InitScanData(TInt aPos,SScanData& aScanData) const;
williamr@2
   705
	void KillFieldSet();
williamr@2
   706
	TInt CountUnits(TUnitOfText aContext) const;
williamr@2
   707
	TInt ScanUnit(TInt& aPos,TUnitOfText aContext,SScanData& aScanData) const;
williamr@2
   708
	TBool TestForDelimiter(TUnitOfText aContext,SScanData& aScanData) const;
williamr@2
   709
	TBool GetChar(SScanData& aScanData,TChar& aChar) const;
williamr@2
   710
	void UpdatePageTable(TInt aPos,TInt aLength);
williamr@2
   711
	inline TBool FieldSetPresent() const;
williamr@2
   712
	void CreateFieldSetL(TInt aDocumentLength);
williamr@2
   713
williamr@2
   714
	IMPORT_C virtual void Reserved_2();	// new
williamr@2
   715
williamr@2
   716
	void* iReserved_1;
williamr@2
   717
williamr@2
   718
protected:
williamr@2
   719
	CBufBase* iByteStore;				// handle to document storage class.
williamr@2
   720
	TSwizzle<CTextFieldSet> iFieldSet;  // handle to field storage class
williamr@2
   721
	TPageTable* iPageTable;				// may be NULL
williamr@2
   722
	MTextFieldFactory* iFieldFactory;  // temporary handle to field factory during restoration
williamr@2
   723
williamr@2
   724
	__DECLARE_TEST;
williamr@2
   725
	};
williamr@2
   726
williamr@2
   727
williamr@2
   728
#include <txtetext.inl>
williamr@2
   729
williamr@2
   730
#endif // __TXTETEXT_H__