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