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