sl@0: /*
sl@0: * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: * All rights reserved.
sl@0: * This component and the accompanying materials are made available
sl@0: * under the terms of "Eclipse Public License v1.0"
sl@0: * which accompanies this distribution, and is available
sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: *
sl@0: * Initial Contributors:
sl@0: * Nokia Corporation - initial contribution.
sl@0: *
sl@0: * Contributors:
sl@0: *
sl@0: * Description: 
sl@0: *
sl@0: */
sl@0: 
sl@0: 
sl@0: #ifndef __TXTETEXT_H__
sl@0: #define __TXTETEXT_H__
sl@0: 
sl@0: #include <e32std.h>
sl@0: #include <e32base.h>
sl@0: #include <s32std.h>
sl@0: 
sl@0: #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
sl@0: #include <fldset.h>
sl@0: #include <txtetext_internal.h>
sl@0: #include <txtclipboard.h>
sl@0: #endif
sl@0: 
sl@0: // Forward references
sl@0: class CParaFormatLayer;
sl@0: class CCharFormatLayer;
sl@0: class MTextFieldFactory;
sl@0: class CTextFieldSet;
sl@0: class CTextField;
sl@0: class TFindFieldInfo;
sl@0: class CInlineEditData;
sl@0: class MFepInlineTextFormatRetriever;
sl@0: class TCharFormat;
sl@0: class CEditableTextOptionalData;
sl@0: class RFs;
sl@0: 
sl@0: 
sl@0: /** 
sl@0: An abstract base class which defines the behaviour common to all editable 
sl@0: text classes.
sl@0: 
sl@0: It provides no storage for text or text formatting, so it is not directly 
sl@0: usable. It defines protocols for editing the contents of a text object and 
sl@0: for extracting format data from a text object which supports formatting.
sl@0: 
sl@0: Note: when specifying a position in a text object (the document position), 
sl@0: zero is before the first character in the document. If the document contains 
sl@0: n characters, position n is after the last character. Valid document positions 
sl@0: are therefore between zero and the length of the document, inclusive. Many 
sl@0: editable text functions raise a panic if a specified document position is 
sl@0: invalid.
sl@0: 
sl@0: Note also that the functions which implement support for front-end-processor 
sl@0: inline editing are intended for internal use only by Symbian. 
sl@0: @publishedAll
sl@0: @released
sl@0: */
sl@0: class CEditableText : public CBase
sl@0: 	{
sl@0: public:
sl@0: 	IMPORT_C ~CEditableText();
sl@0: 	IMPORT_C TStreamId StoreL(CStreamStore& aStore) const;
sl@0: 	IMPORT_C void RestoreL(const CStreamStore& aStore,TStreamId aStreamId);
sl@0: 
sl@0: 	// virtual persistence functions
sl@0: 	virtual void ExternalizeL(RWriteStream& aStream) const;
sl@0: 	virtual void InternalizeL(RReadStream& aStream);
sl@0: 	
sl@0: 	/** Stores the text components, e.g. fields, pictures and formatting to the 
sl@0: 	stream store specified. Does not store the text content.
sl@0: 	
sl@0: 	@param aStore Stream store to which the text components are written. 
sl@0: 	@param aMap A store map. This binds the address of text components to the 
sl@0: 	stream ID of aStore. This is needed to support deferred loading of 
sl@0: 	pictures in rich text. */
sl@0: 	virtual void StoreComponentsL(CStreamStore& aStore,CStoreMap& aMap) const = 0;
sl@0: 	
sl@0: 	/** Restores the text components, e.g. fields, pictures and formatting from 
sl@0: 	the stream store. Does not restore the text content.
sl@0: 	
sl@0: 	@param aStore The stream store from which the text components are restored. */
sl@0: 	virtual void RestoreComponentsL(const CStreamStore& aStore) = 0;
sl@0: 
sl@0: 	// modifier functions
sl@0: 	
sl@0: 	/** Deletes the text content and components from the text object, leaving 
sl@0: 	the single end-of-text paragraph delimiter. */
sl@0: 	virtual void Reset() = 0;
sl@0: 	
sl@0: 	/**  Inserts a single character or a descriptor into the text object at a
sl@0: 	specified document position.
sl@0: 	
sl@0: 	@param aInsertPos  A valid document position at which to insert the
sl@0: 	            character or descriptor.
sl@0: 	@param  aChar  The character to insert. */
sl@0: 	virtual void InsertL(TInt aInsertPos,const TChar& aChar) = 0;
sl@0: 
sl@0: 	/**  Inserts a single character or a descriptor into the text object at a
sl@0: 	specified document position.
sl@0: 	
sl@0: 	@param aInsertPos  A valid document position at which to insert the
sl@0: 	            character or descriptor.
sl@0: 	@param  aBuf  The descriptor to insert.*/
sl@0: 	virtual void InsertL(TInt aInsertPos,const TDesC& aBuf) = 0;
sl@0: 	
sl@0:  	/** Deletes one or more characters beginning at (and including) the 
sl@0:  	character at the specified document position.
sl@0: 	
sl@0: 	@param aPos The document position from which to delete. 
sl@0: 	@param aLength The number of characters to delete. 
sl@0: 	@return Indicates whether or not two paragraphs have been merged as a 
sl@0: 	result of the delete, so that the resulting paragraph needs to be 
sl@0: 	reformatted. This value is only relevant to rich text, so for plain and 
sl@0: 	global text implementations, the function always returns EFalse. */
sl@0: 	virtual TBool DeleteL(TInt aPos,TInt aLength) = 0;
sl@0: 
sl@0: 	// interrogation functions
sl@0: 	
sl@0: 	/**  Gets a read-only pointer descriptor to a portion of the text.
sl@0: 	
sl@0: 	@param aStartPos A valid document position from which to read.
sl@0: 	@param aLength If specified, the number of characters to read,inclusive of 
sl@0: 	the character at position aStartPos. If not specified, the read continues
sl@0: 	to the end of the document, or the end of the segment if using segmented storage.
sl@0: 	@return  Read-only pointer descriptor to a portion of the text. */ 
sl@0:  	virtual TPtrC Read(TInt aStartPos) const = 0;
sl@0: 
sl@0: 	/** Gets a read-only pointer descriptor to a portion of the text.
sl@0: 	
sl@0: 	@param aStartPos A valid document position from which to read. 
sl@0: 	@param aLength If specified, the number of characters to read, inclusive of 
sl@0: 	the character at position aStartPos. If not specified, the read continues 
sl@0: 	to the end of the document, or the end of the segment if using segmented 
sl@0: 	storage. 
sl@0: 	@return Read-only pointer descriptor to a portion of the text. */
sl@0: 	virtual TPtrC Read(TInt aStartPos,TInt aLength) const = 0;
sl@0: 	
sl@0: 	/** Copies a portion of the text into a descriptor.
sl@0: 	
sl@0: 	Starts at the position specified and continues to the end of the document. 
sl@0: 	A length may optionally be specified.
sl@0: 	
sl@0: 	@param aBuf Buffer which on return contains the extracted text.
sl@0: 	@param aPos The document position from which to copy. Must be a valid 
sl@0: 	position, or a panic occurs.
sl@0: 	@param aLength If specified, the number of characters to copy. */ 
sl@0:  	virtual void Extract(TDes& aBuf,TInt aPos=0) const = 0;
sl@0: 
sl@0: 	/** Copies a portion of the text into a descriptor. Starts at the position 
sl@0: 	specified and continues to the end of the document. A length may optionally 
sl@0: 	be specified.
sl@0: 	
sl@0: 	@param aBuf Buffer which on return contains the extracted text. 
sl@0: 	@param aPos The document position from which to copy. Must be a valid 
sl@0: 	position, or a panic occurs. 
sl@0: 	@param aLength If specified, the number of characters to copy. */
sl@0: 	virtual void Extract(TDes& aBuf,TInt aPos,TInt aLength) const = 0;
sl@0: 
sl@0: 	// copy and paste
sl@0: 	/** Copies a portion of the text to the clipboard.
sl@0: 	
sl@0: 	@param aStore The clipboard's store (see class CClipboard). 
sl@0: 	@param aDictionary The clipboard's stream dictionary (see class CClipboard). 
sl@0: 	@param aPos A valid document position from which to begin copying. 
sl@0: 	@param aLength The number of characters to copy. */
sl@0: 	virtual void CopyToStoreL(CStreamStore& aStore,CStreamDictionary& aDictionary,TInt aPos,TInt aLength) const = 0;
sl@0: 	
sl@0: 	/** Pastes the contents of the clipboard into the text object at the 
sl@0: 	specified document position.
sl@0: 	
sl@0: 	@param aStore The clipboard's store (see class CClipboard). 
sl@0: 	@param aDictionary The clipboard's stream dictionary (see class CClipboard). 
sl@0: 	@param aPos A valid document position at which to paste the text. 
sl@0: 	@return The number of characters pasted. */
sl@0: 	virtual TInt PasteFromStoreL(const CStreamStore& aStore,const CStreamDictionary& aDictionary,TInt aPos) = 0;
sl@0: 
sl@0: 	// utility functions
sl@0: 	 
sl@0: 	/** Returns a count of the number of words in the document.
sl@0: 	
sl@0: 	@return The number of words in the document */
sl@0: 	virtual TInt WordCount() const = 0;
sl@0: 	
sl@0: 	/** Returns a count of the number of paragraphs in the document.
sl@0: 	
sl@0: 	@return The number of paragraphs in the document. Notes: The end-of-text 
sl@0: 	paragraph delimiter at the end of every document means this function 
sl@0: 	always returns a count of at least one. */
sl@0: 	virtual TInt ParagraphCount() const = 0;
sl@0: 	 
sl@0: 	/** Returns a count of the number of characters in the document, 
sl@0: 	excluding the end-of-text paragraph delimiter.
sl@0: 	
sl@0: 	@return The number of characters in the document. */
sl@0: 	virtual TInt DocumentLength() const = 0;
sl@0: 	
sl@0: 	/** Updates a document position to the start of the paragraph.
sl@0: 	
sl@0: 	@param aPos Initially specifies a valid document position. On return, set 
sl@0: 	to the document position of the first character in the paragraph. 
sl@0: 	@return The number of characters skipped in scanning to the start of the 
sl@0: 	paragraph. */
sl@0: 	virtual TInt ToParagraphStart(TInt& aPos) const = 0;
sl@0: 	inline TBool HasChanged() const;
sl@0: 	
sl@0: 	/** Returns the start position and length of the word that contains the 
sl@0: 	specified document position.
sl@0: 	
sl@0: 	@param aCurrentPos A valid document position. 
sl@0: 	@param aStartPos On return, the document position of the first character in 
sl@0: 	the word containing document position aCurrentPos. 
sl@0: 	@param aLength On return, the length of the word containing document 
sl@0: 	position aCurrentPos. Does not include the trailing word delimiter 
sl@0: 	character. 
sl@0: 	@param aPictureIsDelimiter Specifies whether picture characters should be 
sl@0: 	considered to be word delimiters. For example, this value might be EFalse 
sl@0: 	when navigating a document, but ETrue when carrying out spell checking. 
sl@0: 	@param aPunctuationIsDelimiter Specifies whether puncutation characters 
sl@0: 	should be considered to be word delimiters. */
sl@0: 	virtual void GetWordInfo(TInt aCurrentPos,TInt& aStartPos,TInt& aLength,
sl@0: 							 TBool aPictureIsDelimiter,TBool aPunctuationIsDelimiter) const = 0;
sl@0: 
sl@0: 	IMPORT_C virtual TInt ScanWords(TInt& aPos,TUint& aScanMask) const;
sl@0: 	IMPORT_C virtual TInt ScanParas(TInt& aPos,TUint& aScanMask) const;
sl@0: 	IMPORT_C virtual void SetHasChanged(TBool aHasChanged);
sl@0: 
sl@0: 	// Internal to Symbian - support for front-end-processor inline editing
sl@0: 	IMPORT_C void StartFepInlineEditL(TBool& aParagraphContainingStartPositionOfInlineTextHasChangedFormat,TInt& aNumberOfCharactersSuccessfullyDeleted,TInt& aNumberOfCharactersSuccessfullyInserted,TInt& aPositionOfInsertionPointInDocument,TInt aNewPositionOfInsertionPointInDocument,const TDesC& aInitialInlineText,TInt aPositionOfInlineTextInDocument,TInt aNumberOfCharactersToHide,MFepInlineTextFormatRetriever& aInlineTextFormatRetriever);
sl@0: 	IMPORT_C void UpdateFepInlineTextL(TBool& aParagraphContainingStartPositionOfInlineTextHasChangedFormat,TInt& aNumberOfCharactersSuccessfullyDeleted,TInt& aNumberOfCharactersSuccessfullyInserted,TInt& aPositionOfInsertionPointInDocument,TInt aNewPositionOfInsertionPointInDocument,const TDesC& aNewInlineText);
sl@0: 	IMPORT_C void CommitFepInlineEditL(TBool& aParagraphContainingStartPositionOfInlineTextHasChangedFormat,TInt& aNumberOfCharactersSuccessfullyDeleted,TInt& aNumberOfCharactersSuccessfullyInserted,TInt& aPositionOfInsertionPointInDocument,TInt aNewPositionOfInsertionPointInDocument);
sl@0: 	IMPORT_C void CancelFepInlineEdit(TBool& aParagraphContainingStartPositionOfInlineTextHasChangedFormat,TInt& aNumberOfCharactersSuccessfullyDeleted,TInt& aNumberOfCharactersSuccessfullyInserted,TInt& aPositionOfInsertionPointInDocument,TInt aNewPositionOfInsertionPointInDocument);
sl@0: 	
sl@0: 	IMPORT_C virtual void ExtendedInterface(TAny*& aInterface, TUid aInterfaceId);
sl@0: 
sl@0: 	IMPORT_C TInt GetPositionOfInlineTextInDocument() const;
sl@0: 	IMPORT_C TInt GetLengthOfInlineText() const;
sl@0: 
sl@0: 	/** Storage type */
sl@0: 	enum TDocumentStorage
sl@0: 		{
sl@0: 		 /** Storage uses a flat buffer (CBufFlat). */
sl@0: 		EFlatStorage, 
sl@0: 		/** Storage uses a segmented buffer (CBufSeg). */
sl@0: 		ESegmentedStorage
sl@0: 		};
sl@0: 		
sl@0: 	/** Miscellaneous constants. */
sl@0:  	enum 
sl@0: 		{
sl@0: 		/** Granularity of the buffer, default 256 characters. */
sl@0: 		EDefaultTextGranularity = 256
sl@0: 		};
sl@0: 
sl@0: 	/*
sl@0: 	Useful Unicode character definitions.
sl@0: 	ETEXT uses standard Unicode to store its text. In particular 0x2029 and 0x2028 are used
sl@0: 	as paragraph separator and forced line break respectively.
sl@0: 	*/
sl@0: 	enum
sl@0: 		{								// Unicode name, etc.
sl@0: 		/** Tab stop. */
sl@0: 		ETabCharacter = 0x0009,			// horizontal tabulation
sl@0: 		/** New page. */
sl@0: 		EPageBreak = 0x000C,			// form feed
sl@0: 		/** Visible space character. */
sl@0: 		ESpace = 0x0020,				// space
sl@0: 		EApostrophe = 0x0027,			// apostrophe
sl@0: 		EHyphenMinus = 0x002D,			// hyphen-minus; generally used for hyphen, but see 0x2010
sl@0: 		/** A hard (non-breaking) space. */
sl@0: 		ENonBreakingSpace = 0x00A0,		// no-break space
sl@0: 		/** A soft hyphen (ensures that a hyphen followed by a new line will be
sl@0: 		inserted at that point should a line break be required anywhere within
sl@0: 		the word).
sl@0: 		 */
sl@0: 		EPotentialHyphen = 0x00AD,		// soft hyphen
sl@0: 		EHyphen = 0x2010,				// hyphen; intended as an unambiguous hyphen codepoint
sl@0: 		/** A hard (non-breaking) hyphen. */
sl@0: 		ENonBreakingHyphen = 0x2011,	// non-breaking hyphen
sl@0: 		ELeftSingleQuote = 0x2018,		// left single quotation mark
sl@0: 		ERightSingleQuote = 0x2019,		// right single quotation mark
sl@0: 		ELeftDoubleQuote = 0x201C,		// left double quotation mark
sl@0: 		ERightDoubleQuote = 0x201D,		// right double quotation mark
sl@0: 		EBullet = 0x2022,				// bullet
sl@0: 		EEllipsis = 0x2026,				// horizontal ellipsis
sl@0: 		/** Forced line break. */
sl@0: 		ELineBreak = 0x2028,			// line separator
sl@0: 		/** Paragraph delimiter. */
sl@0: 		EParagraphDelimiter = 0x2029,	// paragraph separator
sl@0: 		/** Represents a picture inserted into the text object. */
sl@0: 		EPictureCharacter = 0xFFFC,		// object replacement character
sl@0: 		EZeroWidthNoBreakSpace = 0xFEFF,// zero-width no-break space
sl@0: 		EByteOrderMark = 0xFEFF,		// byte order mark; SAME AS zero-width no-break space
sl@0: 		EReversedByteOrderMark = 0xFFFE	// not a character; evidence of endianness opposite to that of platform
sl@0: 		};
sl@0: 
sl@0: protected:
sl@0: 	// support for front-end-processor inline-editing
sl@0: 	IMPORT_C void OverrideFormatOfInlineTextIfApplicable(TPtrC& aView,TCharFormat& aFormat,TInt aStartPos) const;
sl@0: 
sl@0: 	TBool iHasChanged;
sl@0: 
sl@0: private:
sl@0: 	void SetAndTransferOwnershipOfInlineEditDataL(CInlineEditData* aInlineEditData);
sl@0: 	CInlineEditData* InlineEditData() const;
sl@0: 	void DeleteInlineEditDataAndSetToNull();
sl@0: 	TBool DeleteWithoutDestroyingFormatL(TInt aPos, TInt aLength);
sl@0: 
sl@0: 	CEditableTextOptionalData* iOptionalData;
sl@0: 	};
sl@0: 
sl@0: 
sl@0: // Information relating to the number of components owned by an editable text instance.
sl@0: 
sl@0: /** 
sl@0: Provides information about the number of components owned by an editable 
sl@0: text object. 
sl@0: 
sl@0: Components are fields and (rich text only), pictures and styles.
sl@0: 
sl@0: An instance of this class is returned by CPlainText::ComponentInfo() and by 
sl@0: CRichText::ComponentInfo(). 
sl@0: @publishedAll
sl@0: @released
sl@0: */
sl@0: class TEtextComponentInfo
sl@0: 	{
sl@0: public:
sl@0: 	IMPORT_C TEtextComponentInfo();
sl@0: 	IMPORT_C TEtextComponentInfo(TInt aFieldCount,TInt aPictureCount,TInt aStyleCount);
sl@0: public:
sl@0: 	/** The number of fields in the text object. */
sl@0: 	TInt iFieldCount;
sl@0: 	/** The number of pictures in the text object (rich text only). */
sl@0: 	TInt iPictureCount;
sl@0: 	/** The number of styles owned or referenced by the text object (rich text only). */
sl@0: 	TInt iStyleCount;
sl@0: 	};
sl@0: 
sl@0: /** 
sl@0: Page table.
sl@0: 
sl@0: This is an array of integers; each integer represents the number or characters 
sl@0: on a page. 
sl@0: @publishedAll
sl@0: @released
sl@0: */
sl@0: typedef CArrayFix<TInt> TPageTable;
sl@0: 
sl@0: /** 
sl@0: Stores and manipulates plain text. 
sl@0: 
sl@0: Plain text cannot be displayed, so this class provides no support for formatting. 
sl@0: It is purely an in-memory buffer for text, and provides services that act 
sl@0: upon it. These services include the following: import from and export to streams, 
sl@0: optionally translating between Unicode and other encodings; reading and writing 
sl@0: of field data; extraction of text; finding word and paragraph boundaries.
sl@0: 
sl@0: The type and size of in-memory buffer can be specified upon object construction. 
sl@0: However, if no specification is provided a buffer is provided with default 
sl@0: settings. There are two types of storage buffer: segmented buffers and flat 
sl@0: buffers. The default buffer for plain text is segmented (CBufSeg). This is 
sl@0: most efficient when a large quantity of text is to be stored, or will have 
sl@0: a large dynamic range. A flat buffer (CBufFlat) is most appropriate for storing 
sl@0: small quantities of text of bounded length. For most uses, however, a segmented 
sl@0: buffer is sufficient. 
sl@0: @publishedAll
sl@0: @released
sl@0: */
sl@0: class CPlainText: public CEditableText
sl@0: 	{
sl@0: public:
sl@0: 	/** Line delimiter translation. */
sl@0: 	enum TTextOrganisation
sl@0: 		{
sl@0: 		 
sl@0: 		/** When importing text from a text file, all line feeds are 
sl@0: 		converted into paragraph delimiters.
sl@0: 		
sl@0: 		When exporting text to a text file, lines do not wrap and paragraph 
sl@0: 		delimiters are converted into CR/LF pairs. */
sl@0: 		EOrganiseByParagraph,
sl@0: 		/** When importing text from a text file, a single line feed or a 
sl@0: 		line feed followed by a carriage return is converted into a space 
sl@0: 		character. A line feed which is followed by another line feed is 
sl@0: 		converted into a CEditableText::EParagraphDelimiter.
sl@0: 		
sl@0: 		When exporting text to a text file, lines wrap at the specified wrap 
sl@0: 		width and paragraph delimiters are converted into CR/LFs pairs. */
sl@0: 		EOrganiseByLine
sl@0: 		};
sl@0: 
sl@0: 	/**  Scan mask values. */ 
sl@0: 	enum
sl@0: 		{
sl@0: 		/** Scan direction is backwards. The default is forwards. */
sl@0: 		EScanBackwards = 0x01,
sl@0: 		/** If the current document position is a word or paragraph boundary, no
sl@0: 		scan occurs.*/
sl@0: 		EScanStayIfBoundary = 0x02,
sl@0: 		/** Scan to the first character in the word or paragraph. */
sl@0: 		EScanToUnitStart = 0x04,
sl@0: 		/** Scan to the last character in the word or paragraph. */
sl@0: 		EScanToUnitEnd = 0x08,
sl@0: 		/** Treat adjacent word or paragraph delimiters as a single delimiter.
sl@0: 		Required when performing a word count, for example.
sl@0: 		 */
sl@0: 		EScanJoinDelimiters = 0x10,
sl@0: 		/** Picture characters are considered to be word delimiters. */
sl@0: 		EScanPictureIsDelimiter = 0x20,
sl@0: 		/** Punctuation characters, except hyphens and apostrophes, are considered
sl@0: 		to be word delimiters. */
sl@0: 		EScanPunctuationIsDelimiter = 0x40
sl@0: 		};
sl@0: 
sl@0: 	
sl@0: 	/** Used in text scanning functions to indicate the end of the document 
sl@0: 	has been passed. */
sl@0: 	enum TScanDataEnd
sl@0: 		{
sl@0: 		/** Indicates that a scan has passed the end of text paragraph delimiter. */
sl@0: 		EScanEndOfData = -1
sl@0: 		};
sl@0: 
sl@0: 	class TImportExportParam
sl@0: 	/** Parameters for importing or exporting text using 
sl@0: 	CPlainText::ImportTextL() or CPlainText::ExportTextL(). */
sl@0: 		{
sl@0: 		public:
sl@0: 		TImportExportParam():
sl@0: 			iOrganisation(EOrganiseByParagraph),
sl@0: 			iMaxOutputChars(KMaxTInt),
sl@0: 			iMaxInputChars(KMaxTInt),
sl@0: 			iMaxLineLength(KMaxTInt),
sl@0: 			iOutputInternal(FALSE),
sl@0: 			iInputInternal(FALSE),
sl@0: 			iForeignEncoding(0),
sl@0: 			iGuessForeignEncoding(FALSE),
sl@0: 			iFileSession(NULL),
sl@0: 			iReserved(0)
sl@0: 		/** Default constructor. All member data is assigned default values. 
sl@0: 		For details, see the member data. */
sl@0: 			{
sl@0: 			}
sl@0: 
sl@0: 		/** Controls how line delimiters are translated. By default, 
sl@0: 		EOrganiseByParagraph.
sl@0: 		
sl@0: 		@see CPlainText::TTextOrganisation */
sl@0: 		TTextOrganisation iOrganisation;
sl@0: 		/** The maximum number of characters to write to the stream (when 
sl@0: 		exporting) or to write to the text object (when importing). By default, 
sl@0: 		KMaxTInt. */
sl@0: 		TInt iMaxOutputChars;
sl@0: 		/** The maximum number of characters to read from the stream (when 
sl@0: 		importing) or to read from the text object (when exporting). By 
sl@0: 		default, KMaxTInt. */
sl@0: 		TInt iMaxInputChars;
sl@0: 		/** The wrap width as a number of characters. 
sl@0: 		
sl@0: 		Only relevant when exporting by line, (iOrganisation is 
sl@0: 		CPlainText::EOrganiseByLine). Not used in CPlainText::ImportTextL(). 
sl@0: 		By default, KMaxTInt. */
sl@0: 		TInt iMaxLineLength;  // maximum line length when exporting text
sl@0: 		/** If ETrue, output is in internal format, so is written according to 
sl@0: 		native endianness. Used in CPlainText::ExportTextL(). By default, 
sl@0: 		EFalse. */
sl@0: 		TBool iOutputInternal; 
sl@0: 		/** If ETrue, input is in internal format, so is read according to 
sl@0: 		native endianness. Used in CPlainText::ImportTextL(). By default, 
sl@0: 		EFalse. */
sl@0: 		TBool iInputInternal;	
sl@0: 		/** The identifier of the foreign character set encoding to be used 
sl@0: 		to convert from or to. 
sl@0: 
sl@0: 		Not used if iGuessForeignEncoding is true. If conversion to/from 
sl@0: 		iForeignEncoding is not available on the phone, the function leaves 
sl@0: 		with KErrNotSupported. By default, zero. */
sl@0: 		TUint iForeignEncoding;			
sl@0: 		/** If ETrue, an attempt is made to guess the encoding of the foreign 
sl@0: 		text being imported before converting it into Unicode. Used in 
sl@0: 		CPlainText::ImportTextL(). If EFalse, the value specified in 
sl@0: 		iForeignEncoding (if any) is used. If none of the available character 
sl@0: 		conversion plug-ins on the phone return a confidence level greater 
sl@0: 		than 50%, CPlainText::ImportTextL() leaves with KErrNotSupported. 
sl@0: 		By default, false. */
sl@0: 		TBool iGuessForeignEncoding;		
sl@0: 		/** If non-null, a connected file server session used to load character 
sl@0: 		conversion data. Only relevant if the text needs to be converted to or 
sl@0: 		from Unicode. By default, null. */
sl@0: 		RFs* iFileSession;
sl@0: 		TUint iReserved;
sl@0: 		};
sl@0: 
sl@0:  	class TImportExportResult
sl@0: 	/** Results of importing or exporting text using CPlainText::ImportTextL() 
sl@0: 	or CPlainText::ExportTextL(). */
sl@0: 		{
sl@0: 		public:
sl@0: 		TImportExportResult():
sl@0: 			iOutputChars(0),
sl@0: 			iInputChars(0),
sl@0: 			iForeignEncoding(0),
sl@0: 			iReserved(0)
sl@0: 		/** Default constructor. All member data is initialised to zero. */
sl@0: 			{
sl@0: 			}
sl@0: 
sl@0: 		/** The number of characters written to the stream (when exporting) or 
sl@0: 		written to this text object (when importing). */
sl@0: 		TInt iOutputChars;
sl@0: 		/** The number of characters read from the stream (when importing) or 
sl@0: 		read from this text object (when exporting). */
sl@0: 		TInt iInputChars;
sl@0: 		/** The identifier for the character set encoding selected when 
sl@0: 		importing text whose encoding is guessed (iGuessForeignEncoding was 
sl@0: 		true). */
sl@0: 		TUint iForeignEncoding;				// foreign encoding actually used; useful if the encoding was guessed
sl@0: 		TUint iReserved;		
sl@0: 		};
sl@0: 			   
sl@0: 	IMPORT_C static CPlainText* NewL(TDocumentStorage aStorage = ESegmentedStorage,
sl@0: 									 TInt aDefaultTextGranularity = EDefaultTextGranularity);
sl@0: 	IMPORT_C static CPlainText* NewL(const CStreamStore& aStore,TStreamId aStreamId,
sl@0: 									 MTextFieldFactory* aFieldFactory = NULL,
sl@0: 									 TDocumentStorage aStorage = ESegmentedStorage);
sl@0: 	IMPORT_C virtual ~CPlainText();
sl@0: 
sl@0: 	// primary persistence functions
sl@0: 	IMPORT_C virtual void StoreComponentsL(CStreamStore& aStore,CStoreMap& aMap) const;
sl@0: 	IMPORT_C virtual void RestoreComponentsL(const CStreamStore& aStore);
sl@0: 	IMPORT_C virtual void ExternalizeL(RWriteStream& aStream) const;
sl@0: 	IMPORT_C virtual void InternalizeL(RReadStream& aStream);
sl@0: 
sl@0: 	// secondary persistence functions
sl@0: 	IMPORT_C void ExternalizePlainTextL(RWriteStream& aStream) const;
sl@0: 	IMPORT_C void InternalizePlainTextL(RReadStream& aStream);
sl@0: 	IMPORT_C void ExternalizePlainTextNoLengthCountL(RWriteStream& aStream) const; // Deprecated
sl@0: 	IMPORT_C void InternalizePlainTextL(RReadStream& aStream,TInt aLength); // Deprecated
sl@0: 
sl@0: 	// import and export text
sl@0: 	IMPORT_C void ImportTextL(TInt aPos,RReadStream& aInput,TTextOrganisation aTextOrganisation,
sl@0: 							  TInt aMaxOutputChars = KMaxTInt,TInt aMaxInputChars = KMaxTInt,
sl@0: 							  TInt* aOutputChars = NULL,TInt* aInputChars = NULL);
sl@0: 	IMPORT_C void ExportTextL(TInt aPos,RWriteStream& aOutput,TTextOrganisation aTextOrganisation,
sl@0: 							  TInt aMaxOutputChars = KMaxTInt,TInt aMaxInputChars = KMaxTInt,
sl@0: 							  TInt aMaxLineLength = KMaxTInt,
sl@0: 							  TInt* aOutputChars = NULL,TInt* aInputChars = NULL) const;
sl@0: 	IMPORT_C virtual TInt ImportTextFileL(TInt aPos,const TDes& aFileName,TTextOrganisation aTextOrganisation);
sl@0: 	IMPORT_C virtual void ExportAsTextL(const TDes& aFileName,TTextOrganisation aTextOrganisation,
sl@0: 										TInt aMaxLineLength) const;
sl@0: 
sl@0: 	// import and export text AND optionally translate from or to a non-Unicode encoding
sl@0: 	IMPORT_C void ImportTextL(TInt aPos,RReadStream& aInput,
sl@0: 							  const TImportExportParam& aParam,TImportExportResult& aResult);
sl@0: 	IMPORT_C void ExportTextL(TInt aPos,RWriteStream& aOutput,
sl@0: 							  const TImportExportParam& aParam,TImportExportResult& aResult) const;
sl@0: 
sl@0: 	// read and write field data
sl@0: 	IMPORT_C void StoreFieldComponentsL(CStreamStore& aStore,CStoreMap& aMap) const;
sl@0: 	IMPORT_C void RestoreFieldComponentsL(const CStreamStore& aStore);
sl@0: 	IMPORT_C void ExternalizeFieldDataL(RWriteStream& aStream) const;
sl@0: 	IMPORT_C void InternalizeFieldDataL(RReadStream& aStream);
sl@0: 
sl@0: 	// modifier functions
sl@0: 	IMPORT_C virtual void Reset();
sl@0: 	IMPORT_C virtual void InsertL(TInt aPos,const TChar& aChar);
sl@0: 	IMPORT_C virtual void InsertL(TInt aPos,const TDesC& aBuf);
sl@0: 	IMPORT_C virtual TBool DeleteL(TInt aPos,TInt aLength);
sl@0: 
sl@0: 	// interrogation functions
sl@0: 	IMPORT_C virtual TPtrC Read(TInt aStartPos) const;
sl@0: 	IMPORT_C virtual TPtrC Read(TInt aStartPos,TInt aLength) const;
sl@0: 	IMPORT_C virtual void Extract(TDes& aBuf,TInt aPos=0) const;
sl@0: 	IMPORT_C virtual void Extract(TDes& aBuf,TInt aPos,TInt aLength) const;
sl@0: 
sl@0: 	// Flags for ExtractSelectively
sl@0: 	enum
sl@0: 		{
sl@0: 		EExtractAll = 0,	// extract all characters
sl@0: 		EExtractVisible = 1,	// discard control characters and soft hyphens; change par and line separators to spaces
sl@0: 		EExcludeInlineEditedText = 2 // discard the inline text
sl@0: 		};
sl@0: 	IMPORT_C void ExtractSelectively(TDes& aBuf,TInt aPos,TInt aLength,TUint aFlags);
sl@0: 
sl@0: 	// copy and paste
sl@0: 	IMPORT_C virtual void CopyToStoreL(CStreamStore& aStore,CStreamDictionary& aDictionary,TInt aPos,TInt aLength) const;
sl@0: 	IMPORT_C virtual TInt PasteFromStoreL(const CStreamStore& aStore,const CStreamDictionary& aDictionary,TInt aPos);
sl@0: 
sl@0: 	// utility functions
sl@0: 	IMPORT_C void SetPageTable(TPageTable* aPageTable);
sl@0: 	IMPORT_C TInt PageContainingPos(TInt aPos) const;
sl@0: 	IMPORT_C virtual TInt DocumentLength() const;
sl@0:  	IMPORT_C virtual TInt WordCount() const;
sl@0: 	IMPORT_C virtual TInt ParagraphCount() const;
sl@0: 	IMPORT_C virtual TInt ToParagraphStart(TInt& aPos) const;
sl@0: 	IMPORT_C virtual TInt CharPosOfParagraph(TInt& aLength,TInt aParaOffset) const;
sl@0: 	IMPORT_C virtual TInt ParagraphNumberForPos(TInt& aPos) const;
sl@0: 	IMPORT_C virtual void GetWordInfo(TInt aCurrentPos,TInt& aStartPos,TInt& aLength,
sl@0: 						TBool aPictureIsDelimiter,TBool aPunctuationIsDelimiter) const;
sl@0: 	IMPORT_C virtual TInt ScanWords(TInt& aPos,TUint& aScanMask) const;
sl@0: 	IMPORT_C virtual TInt ScanParas(TInt& aPos,TUint& aScanMask) const;
sl@0: 	IMPORT_C virtual TEtextComponentInfo ComponentInfo() const;
sl@0: 	//
sl@0: 	// Field functions
sl@0: 	IMPORT_C void SetFieldFactory(MTextFieldFactory* aFactory);
sl@0: 	IMPORT_C const MTextFieldFactory* FieldFactory() const;
sl@0: 	IMPORT_C CTextField* NewTextFieldL(TUid aFieldType) const;
sl@0: 	IMPORT_C void InsertFieldL(TInt aPos,CTextField* aField,TUid aFieldType); 
sl@0: 	IMPORT_C virtual void UpdateFieldL(TInt aPos); 
sl@0: 	IMPORT_C void UpdateAllFieldsL(); 
sl@0: 	IMPORT_C TInt FieldCount() const;
sl@0: 	IMPORT_C const CTextField* TextField(TInt aPos) const;
sl@0: 	IMPORT_C TBool FindFields(TInt aPos) const; 
sl@0: 	IMPORT_C TBool FindFields(TFindFieldInfo& aInfo,TInt aPos,TInt aRange=0) const;
sl@0: 	IMPORT_C TBool RemoveField(TInt aPos);  
sl@0: 	IMPORT_C TBool ConvertFieldToText(TInt aPos); 
sl@0: 	IMPORT_C void ConvertAllFieldsToText();
sl@0: 	
sl@0: 	IMPORT_C void ExtendedInterface(TAny*& aInterface, TUid aInterfaceId); // from CEditableText
sl@0: 
sl@0: protected:
sl@0: 	IMPORT_C CPlainText();
sl@0: 	IMPORT_C void ConstructL(TDocumentStorage aStorage = ESegmentedStorage,
sl@0: 							 TInt aDefaultTextGranularity = EDefaultTextGranularity);
sl@0: 	IMPORT_C void ConstructL(const CStreamStore& aStore,TStreamId aStreamId,MTextFieldFactory* aFieldFactory,
sl@0: 							 TDocumentStorage aStorage = ESegmentedStorage);
sl@0: 	IMPORT_C void DoConstructL(TDocumentStorage aStorage,TInt aDefaultTextGranularity,
sl@0: 							   MTextFieldFactory* aFieldFactory = NULL);
sl@0: 	void DoExtract(TDes& aBuf,TInt aPos,TInt aLength,TUint aFlags = 0) const;
sl@0: 	IMPORT_C void PtInsertL(TInt aInsertPos,const TDesC& aBuf);
sl@0: 	IMPORT_C void DoPtInsertL(TInt aPos,const TDesC& aBuf);
sl@0: 	IMPORT_C TBool DoPtDelete(TInt aPos,TInt aLength);
sl@0: 	void InsertL(TInt aPos,const CPlainText* aText);
sl@0: 	TBool Delete(TInt aPos,TInt aLength);
sl@0: 
sl@0: 	// streaming
sl@0: 	IMPORT_C void DoExternalizeFieldDataL(RWriteStream& aStream) const;
sl@0: 	IMPORT_C void DoInternalizeFieldDataL(RReadStream& aStream);
sl@0: 	IMPORT_C void DoExternalizePlainTextL(RWriteStream& aStream) const;
sl@0: 	IMPORT_C void DoInternalizePlainTextL(RReadStream& aStream);
sl@0: 	TStreamId DoCopyToStoreL(CStreamStore& aStore,CStreamDictionary& aDictionary,TInt aPos,TInt aLength) const;
sl@0: 	TInt DoPasteFromStoreL(const CStreamStore& aStore,TStreamId aStreamId,TInt aPos);
sl@0: 	void CopyComponentsL(CStreamStore& aStore,CStoreMap& aMap,TInt aPos,TInt aLength) const;
sl@0: 	void PasteComponentsL(const CStreamStore& aStore,TInt aPos);
sl@0: 	void CopyToStreamL(RWriteStream& aStream,TInt aPos,TInt aLength) const;
sl@0: 
sl@0: 	// utility functions
sl@0: 	inline static void ConsumeAdornmentL(RReadStream& aStream);
sl@0: 	inline static TUid UidFromStreamL(RReadStream& aStream);
sl@0: protected:
sl@0: 	enum
sl@0: 		{
sl@0: 		EImportBufSize = 512,
sl@0: 		EBiggestCharacterPaste=0x100000
sl@0: 		};
sl@0: 
sl@0: 	enum TUnitOfText
sl@0: 		{
sl@0: 		EUnitIsWord,
sl@0: 		EUnitIsParagraph
sl@0: 		};
sl@0: 
sl@0: 	struct SScanData
sl@0: 		{
sl@0: 		TInt pos;			// current character position
sl@0: 		TInt oldPos;		// old character position
sl@0: 		TText* buf;			// address of data (Unicode-aware)
sl@0: 		TInt currentSegLen; // number of characters left in segment
sl@0: 		TInt totalBufLen;	// number of unread characters
sl@0: 		TInt delta;			// specifies current scan direction
sl@0: 		TUint32 scanMask;	// bitmask containing the scan settings
sl@0: 		enum
sl@0: 			{
sl@0: 			EInsideUnit = 0x10000000,
sl@0: 			EStopEnd = 0x20000000,
sl@0: 			EStopBegin = 0x40000000,
sl@0: 			EIsDelimiter = 0x80000000
sl@0: 			};
sl@0: 		};
sl@0: 
sl@0: private:
sl@0: 	CPlainText(const CPlainText& aPlainTextDoc);
sl@0: 	CPlainText& operator=(const CPlainText& aPlainTextDoc);
sl@0: 	TInt PasteFromStreamL(RReadStream& aStream,TInt aPos);
sl@0: 	TInt DoPasteFromStreamL(RReadStream& aStream, TInt aPos);
sl@0: 	void InsertEodL();
sl@0: 	void InitScanControl(TInt& aPos,TUint& aScanMask,TUnitOfText aContext,SScanData& aScanData) const;
sl@0: 	void InitScanData(TInt aPos,SScanData& aScanData) const;
sl@0: 	void KillFieldSet();
sl@0: 	TInt CountUnits(TUnitOfText aContext) const;
sl@0: 	TInt ScanUnit(TInt& aPos,TUnitOfText aContext,SScanData& aScanData) const;
sl@0: 	TBool TestForDelimiter(TUnitOfText aContext,SScanData& aScanData) const;
sl@0: 	TBool GetChar(SScanData& aScanData,TChar& aChar) const;
sl@0: 	void UpdatePageTable(TInt aPos,TInt aLength);
sl@0: 	inline TBool FieldSetPresent() const;
sl@0: 	void CreateFieldSetL(TInt aDocumentLength);
sl@0: 
sl@0: 	IMPORT_C virtual void Reserved_2();	// new
sl@0: 
sl@0: 	void* iReserved_1;
sl@0: 
sl@0: protected:
sl@0: 	CBufBase* iByteStore;				// handle to document storage class.
sl@0: 	TSwizzle<CTextFieldSet> iFieldSet;  // handle to field storage class
sl@0: 	TPageTable* iPageTable;				// may be NULL
sl@0: 	MTextFieldFactory* iFieldFactory;  // temporary handle to field factory during restoration
sl@0: 
sl@0: 	__DECLARE_TEST;
sl@0: 	};
sl@0: 
sl@0: 
sl@0: #include <txtetext.inl>
sl@0: 
sl@0: #endif // __TXTETEXT_H__