epoc32/include/txtrich.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
permissions -rw-r--r--
Final list of Symbian^2 public API header files
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #ifndef __TXTRICH_H__
    17 #define __TXTRICH_H__
    18 
    19 #include <e32std.h>
    20 #include <e32base.h>
    21 #include <txtglobl.h>
    22 #include <txtstyle.h>
    23 #include <mparser.h>
    24 #include <medobsrv.h>
    25 
    26 
    27 // forward references
    28 class CRichTextIndex;
    29 class CStreamStore;
    30 class CStoreMap;
    31 class MPictureFactory;
    32 class MRichTextStoreResolver;
    33 class TCharFormatX;
    34 class TCharFormatXMask;
    35 class CParserData;
    36 
    37 
    38 /**
    39 UIDs
    40 @internalComponent 
    41 */
    42 const TUid KRichTextStyleDataUid = { 268450335 };
    43 const TUid KClipboardUidTypeRichText = { 268450336 };
    44 const TUid KClipboardUidTypeRichTextWithStyles = { 268450337 };
    45 const TUid KRichTextMarkupDataUid = { 268435558 };
    46 
    47 
    48 class CRichText : public CGlobalText
    49 /** 
    50 Text with rich formatting.
    51 
    52 In rich text, each paragraph can have a different paragraph format, and each 
    53 character can have a different character format.
    54 
    55 All formatting in a rich text object is based on a global character and 
    56 paragraph format layer, and a chain of layers on which they may be based. In 
    57 case of conflict, upper layers override lower layers. These two format layers 
    58 are specified on construction, and are not owned by the text object. Additional 
    59 formatting may then be added to any portion of the text. This is called specific 
    60 formatting and in case of conflict, it overrides the formatting in the global 
    61 layers. Specific formatting is owned by the text object. So, the effective 
    62 formatting of a rich text object may be composed of specific formatting and 
    63 formatting specified in a chain of format layers.
    64 
    65 Rich text supports styles. A style is a named set of paragraph and character 
    66 format attributes. Styles are stored in a list which is passed to the rich 
    67 text object on construction, or which is assigned to the object after 
    68 construction. Styles can be appended to and removed from the list and existing 
    69 styles can be modified. Only paragraph styles are supported. This means that 
    70 styles are applied to entire paragraphs, although both character and paragraph 
    71 format attributes may be set in the style.
    72 
    73 Rich text also supports object embedding. Embedded objects are represented 
    74 in rich text by CPicture-derived objects. A rich text object which supports 
    75 the display of pictures needs to be supplied with a picture factory.
    76 
    77 @see CParagraphStyle 
    78 @publishedAll
    79 @released
    80 */
    81 	{
    82 public:
    83 	
    84 	/** Number of paragraphs in the object. */
    85 	enum TParaType 
    86 		{
    87 		/** The text object will contain a single paragraph. */
    88 		ESinglePara, 
    89 		/** The text object will contain multiple paragraphs. */
    90 		EMultiPara
    91 		};
    92 public:
    93 	// Create new rich text component whose sole content is an end-of-document character.	
    94 	IMPORT_C static CRichText* NewL(const CParaFormatLayer* aGlobalParaLayer, const CCharFormatLayer* aGlobalCharLayer,
    95 									TDocumentStorage aStorage = ESegmentedStorage,
    96 									TInt aDefaultTextGranularity = EDefaultTextGranularity,
    97 									TParaType aParaType = EMultiPara);
    98 	// Create new rich text component, supporting STYLES, whose sole content is an end-of-document character.
    99 	IMPORT_C static CRichText* NewL(const CParaFormatLayer* aGlobalParaLayer, const CCharFormatLayer* aGlobalCharLayer,
   100 									const CStyleList& aStyleList,
   101 									TDocumentStorage aStorage = ESegmentedStorage,
   102 									TInt aDefaultTextGranularity = EDefaultTextGranularity,
   103 									TParaType aParaType = EMultiPara);
   104 	// Restore into new rich text, using the specified global layers.
   105 	IMPORT_C static CRichText* NewL(const CStreamStore& aStore, TStreamId aStreamId,
   106 									const CParaFormatLayer* aGlobalParaLayer, const CCharFormatLayer* aGlobalCharLayer,
   107 									MTextFieldFactory* aFieldFactory = NULL,
   108 									TDocumentStorage aStorage = ESegmentedStorage);
   109 	// Restore into new rich text, using the specified layers, store & picture factory.
   110 	IMPORT_C static CRichText* NewL(const CStreamStore& aStore, TStreamId aStreamId,
   111 									const CParaFormatLayer* aGlobalParaLayer, const CCharFormatLayer * aGlobalCharLayer,
   112 									MPictureFactory* aPictureFactory, MRichTextStoreResolver* aStoreResolver,
   113 									MTextFieldFactory* aFieldFactory = NULL,
   114 									TDocumentStorage aStorage = ESegmentedStorage);
   115 	IMPORT_C virtual ~CRichText();
   116 	//
   117 	// Default persist functions - Deferred loading of pictures
   118 	IMPORT_C void RestoreWithStyleListL(const CStreamStore& aStore, TStreamId aStreamId, const CStyleList& aExternalStyleList);
   119 	//
   120 	IMPORT_C virtual void StoreComponentsL(CStreamStore& aStore, CStoreMap& aMap) const;
   121 	IMPORT_C virtual void RestoreComponentsL(const CStreamStore& aStore);
   122 	IMPORT_C virtual void ExternalizeL(RWriteStream& aStream) const;
   123 	IMPORT_C virtual void InternalizeL(RReadStream& aStream);
   124 	//
   125 	// Custom persist functions
   126 	IMPORT_C void ExternalizeStyleDataL(RWriteStream& aStream) const;
   127 	IMPORT_C void InternalizeStyleDataL(RReadStream& aStream);
   128 	//
   129 	IMPORT_C void StoreMarkupComponentsL(CStreamStore& aStore, CStoreMap& aMap) const;
   130 	IMPORT_C void ExternalizeMarkupDataL(RWriteStream& aStream) const;
   131 	IMPORT_C void InternalizeMarkupDataL(RReadStream& aStream);
   132 	//
   133 	// Utility persist functions
   134 	IMPORT_C void SetPictureFactory(MPictureFactory* aPictureFactory, MRichTextStoreResolver* aStoreResolver);
   135 	inline MPictureFactory* PictureFactory() const;
   136 	inline MRichTextStoreResolver* StoreResolver() const;
   137 	IMPORT_C TPictureHeader PictureHeader(TInt aPos) const;
   138 	IMPORT_C void DropPictureOwnership(TInt aPos);		// delete picture character. Forget but don't delete picture.
   139 	IMPORT_C void DetachFromStoreL(CPicture::TDetach aDegree);
   140 	IMPORT_C void DetachFromStoreL(CPicture::TDetach aDegree, TInt aPos, TInt aLength);
   141 	IMPORT_C TBool HasMarkupData() const;
   142 	//
   143 	// Copy/Paste
   144 	IMPORT_C virtual void CopyToStoreL(CStreamStore& aStore, CStreamDictionary& aDictionary, TInt aPos, TInt aLength) const;
   145 	IMPORT_C virtual TInt PasteFromStoreL(const CStreamStore& aStore, const CStreamDictionary& aDictionary, TInt aPos);
   146 	IMPORT_C TInt PasteFromStoreL(const CStreamStore& aStore, const CStreamDictionary& aDictionary, TInt aPos, CParagraphStyle::TStylePasteMode aStylePasteMode);
   147 	//
   148 	// Content modifier functions
   149 	IMPORT_C virtual void Reset();
   150 	IMPORT_C virtual void InsertL(TInt aPos, const TChar& aChar);  // Insert a single character.
   151 	IMPORT_C virtual void InsertL(TInt aPos, const TDesC& aBuf);
   152 	IMPORT_C void InsertL(TInt aPos, const TPictureHeader& aHeader);  // Insert a picture header.
   153 	//
   154 	// aPos is the position of the character being deleted, *not* the current cursor position!
   155 	IMPORT_C virtual TBool DeleteL(TInt aPos, TInt aLength);  // Call this for a delete-forward.
   156 	//
   157 	// Leave-safe delete for removing content from *within* a single paragraph only
   158 	IMPORT_C void DeleteFromParagraph(TInt aPos, TInt aLength);
   159 	//
   160 	// Leave-safe delete for removing *entire* paragraphs
   161 	IMPORT_C void DeleteParagraph(TInt aPos, TInt aLength);
   162 	//
   163 	// Special behaviour format modifier functions.
   164 	// Call this when applying a character format to a zero length selection, eg, turning bold on.
   165 	IMPORT_C void SetInsertCharFormatL(const TCharFormat& aFormat, const TCharFormatMask& aMask, TInt aPos);
   166 	//
   167 	// Call this on every cursor movement, page up/down etc...
   168 	IMPORT_C void CancelInsertCharFormat();
   169 	//
   170 	// Delete content, but preserve phrase format if aPos is at a phrase boundary.
   171 	// aPos is the position of the character being deleted, *not* the current cursor position!
   172 	IMPORT_C TBool DelSetInsertCharFormatL(TInt aPos, TInt aLength);
   173 	//
   174 	// MLaydoc implementation
   175 	IMPORT_C virtual void GetParagraphFormatL(CParaFormat* aFormat, TInt aPos) const;
   176 	IMPORT_C virtual void GetChars(TPtrC& aView, TCharFormat& aFormat, TInt aPos) const;
   177 	IMPORT_C virtual TInt GetPictureSizeInTwips(TSize& aSize, TInt aPos) const;
   178 	IMPORT_C virtual CPicture* PictureHandleL(TInt aPos, MLayDoc::TForcePictureLoad aForceLoad = MLayDoc::EForceLoadTrue) const;
   179 	//
   180 	// MFormatText implementation
   181 	// Used only by dialog writers, since they are not interested in the text, but require knowledge
   182 	// of attributes whose values change across the specified range.
   183 	IMPORT_C virtual void GetParaFormatL(CParaFormat* aFormat, TParaFormatMask& aVaries, TInt aPos, TInt aLength,
   184 										CParaFormat::TParaFormatGetMode aMode = CParaFormat::EAllAttributes) const;
   185 	IMPORT_C virtual void ApplyParaFormatL(const CParaFormat* aFormat, const TParaFormatMask& aMask, TInt aPos, TInt aLength);
   186 	IMPORT_C virtual void GetCharFormat(TCharFormat& aFormat, TCharFormatMask& aVaries, TInt aPos, TInt aLength) const;
   187 	IMPORT_C virtual void ApplyCharFormatL(const TCharFormat& aFormat, const TCharFormatMask& aMask, TInt aPos, TInt aLength);
   188 	//
   189 	//
   190 	IMPORT_C void GetSpecificCharFormat(TCharFormat& aFormat, TCharFormatMask& aMask, TInt aPos) const;
   191 	IMPORT_C void GetSpecificCharFormatRight(TCharFormat& aFormat, TCharFormatMask& aMask, TInt aPos) const;
   192 	IMPORT_C void GetSpecificParagraphFormatL(CParaFormat* aFormat, TParaFormatMask& aMask, TInt aPos) const;
   193 	//
   194 	// Paragraph style implementation
   195 	IMPORT_C void ApplyParagraphStyleL(const CParagraphStyle& aStyle, TInt aPos, TInt aLength, CParagraphStyle::TApplyParaStyleMode aMode);
   196 	inline void NotifyStyleDeletedL(const CParagraphStyle* aStyle);
   197 	IMPORT_C void NotifyStyleChangedL(const CParagraphStyle* aTo, const CParagraphStyle* aFrom);
   198 	IMPORT_C const CParaFormatLayer* ParagraphStyle(TBool& aStyleChangesOverRange, TInt aPos, TInt aLength) const;
   199 	//
   200 	// StyleList implementation
   201 	inline TBool StyleListPresent() const;
   202 	inline CStyleList* StyleList() const;
   203 	inline TInt StyleCount() const;
   204 
   205 	inline void SetStyleListExternallyOwned(TBool aExternallyOwned);
   206 	IMPORT_C void SetStyleListExternallyOwned(const CStyleList& aStyleList);
   207 	inline TBool StyleListExternallyOwned() const;
   208 	//
   209 	// Utility functions
   210 	IMPORT_C void RemoveSpecificParaFormatL(TInt aPos, TInt aLength);  
   211 	IMPORT_C void RemoveSpecificCharFormatL(TInt aPos, TInt aLength);
   212 	IMPORT_C TInt PictureCount() const;
   213 	IMPORT_C virtual TInt ParagraphCount() const;
   214 	IMPORT_C virtual TInt CharPosOfParagraph(TInt& aLength, TInt aParaOffset) const;
   215 	IMPORT_C virtual TInt ParagraphNumberForPos(TInt& aPos) const;
   216 	IMPORT_C virtual TEtextComponentInfo ComponentInfo() const;
   217 	//
   218 	// Text field implementation
   219 	IMPORT_C virtual void UpdateFieldL(TInt aPos);  // updates the field at aPos
   220 	// finds number of fields in range. Includes the field containing aPos, if applicable
   221 	// aInfo is set to the first field in the range (if any are found)
   222 	//
   223 	// Speciality functions
   224 	IMPORT_C void AppendTakingSolePictureOwnershipL(const CRichText& aSource);
   225 	IMPORT_C void AppendParagraphL(TInt aReplicas = 1);
   226 	IMPORT_C virtual void SetHasChanged(TBool aHasChanged);
   227 	
   228 	IMPORT_C void ExtendedInterface(TAny*& aInterface, TUid aInterfaceId); // from CEditableText
   229 	
   230 	// non-exported public functions
   231 	void ApplyExtendedCharFormatL(const TCharFormatX& aFormat, const TCharFormatXMask& aMask, TInt aPos, TInt aLength);
   232 	void GetExtendedCharFormat(TCharFormatX& aFormat, TCharFormatXMask& aVaries, TInt aPos, TInt aLength) const;
   233 	void GetTextAndExtendedFormat(TPtrC& aText, TCharFormatX& aFormat, TInt aPos) const;
   234 
   235 private:
   236 	CRichText(const CRichText& aRichText);
   237 	CRichText& operator=(const CRichText& aRichText);
   238 	void KillStyleList();
   239 	void KillIndex();
   240 	TBool CreateEmptyMarkupComponentL();
   241 	void CreateAndGenerateMarkupComponentL();
   242 	void GenerateMarkupL();
   243 	void CompletePastePlainTextL(TInt aPos,TInt aCharacterCount);
   244 	TInt DoPasteRtFromStoreL(const CStreamStore& aStore, const CStreamDictionary& aDictionary, TInt aPos, CParagraphStyle::TStylePasteMode aStylePasteMode);
   245 	TBool IndexPresent() const;
   246 	inline void SetParaTypeIsSingle(TBool aBool);
   247 	inline TBool ParaTypeIsSingle() const;
   248 	void SetExtendedInsertCharFormatL(const TCharFormatX& aFormat, const TCharFormatXMask& aMask, TInt aPos);
   249 	void GetSpecificCharFormatLeftRight(TCharFormat& aFormat,
   250 		TCharFormatMask& aMask, TInt aPos, TBool aLeft) const;
   251 	void DoApplyExtendedCharFormatL(const TCharFormatX& aFormat,const TCharFormatXMask& aMask,TInt aPos,TInt aLength);		
   252 
   253 protected:
   254 	IMPORT_C CRichText(const CParaFormatLayer* aGlobalParaLayer, const CCharFormatLayer* aGlobalCharLayer,
   255 					   CStyleList* aStyleList = NULL);
   256 	// New constructL's - to be merged post 057
   257 	IMPORT_C void ConstructL(TDocumentStorage aStorage, TInt aDefaultTextGranularity, TParaType aParaType);
   258 	IMPORT_C void ConstructL(const CStreamStore& aStore, TStreamId aStreamId, MPictureFactory* aFactory, MRichTextStoreResolver* aStoreResolver,
   259 							 MTextFieldFactory* aFieldFactory=NULL,
   260 							 TDocumentStorage aStorage = ESegmentedStorage);
   261 	//
   262 	void InternalizeL(RReadStream& aStream, const CStyleList* aExternalStyleList);
   263 	IMPORT_C void DoExternalizeStyleDataL(RWriteStream& aStream) const;
   264 	IMPORT_C void DoInternalizeStyleDataL(RReadStream& aStream);
   265 	void DoInternalizeStyleDataL(RReadStream& aStream, const CStyleList* aExternalStyleList);
   266 	IMPORT_C void DoExternalizeMarkupDataL(RWriteStream& aStream) const;
   267 	IMPORT_C void DoInternalizeMarkupDataL(RReadStream& aStream);
   268 	void StoreStylesL(CStreamStore& aStore,CStoreMap& aMap) const;
   269 	void RestoreStylesL(const CStreamStore& aStore, TStreamId aId, const CParaFormatLayer* aParaFormatLayer, const CCharFormatLayer* aCharFormatLayer);
   270 	void StoreMarkupL(CStreamStore& aStore,CStoreMap& aMap)const;
   271 	//
   272 	IMPORT_C void RtInsertL(TInt aPos,const TDesC& aBuf);
   273 	//
   274 	TStreamId DoCopyToStoreL(CStreamStore& aStore, TInt aPos, TInt aLength, TStreamId aGlobalTextId, TBool aCopyStyles) const;
   275 	IMPORT_C void CopyComponentsL(CStreamStore& aStore, CStoreMap& aMap, TInt aPos,TInt aLength, TStreamId aGlobalTextId) const;
   276 	IMPORT_C void CopyToStreamL(RWriteStream& aStream, TInt aPos, TInt aLength, TStreamId aGlobalTextId) const;
   277 	IMPORT_C void CopyToStreamL(RWriteStream& aStream, TInt aPos, TInt aLength) const;
   278 	void CopyToStreamL(RWriteStream& aStream, TInt aPos, TInt aLength, TStreamId aGlobalTextId, TBool aCopyStyles) const;
   279 	TInt PasteRichTextFromStoreL(const CStreamStore& aStore, const CStreamDictionary& aDictionary, TStreamId& anId, TInt aPos, CParagraphStyle::TStylePasteMode aStylePasteMode);
   280 	void CompletePasteRichTextFromStoreL(const CStreamStore& aStore, TStreamId& aRichTextStreamId, TInt aPos, CParagraphStyle::TStylePasteMode aStylePasteMode);
   281 	TInt PastePlainTextFromStoreL(const CStreamStore& aStore, TStreamId& anId, TInt aPos);
   282 	//
   283 	// Append
   284 	void PrepareAppendMarkupL(const CRichText& aSource);
   285 	void DoAppendTakingSolePictureOwnershipL(const CRichText& aSource);
   286 public:
   287 	IMPORT_C static void ActivateParserL(MParser* aParser);		// Switch on a particular parser
   288 	IMPORT_C static void DeactivateParser(MParser* aParser);	// Switch off a particular parser
   289 	IMPORT_C static void ActivateDefaultParserL(MParser* aParser);	// Switch on a default parser
   290 	IMPORT_C static void DeactivateParserDefaults();				// Switch off default set (if any)
   291 																// and delete EText TLS
   292 
   293 	IMPORT_C void SetEditObserver(MEditObserver* aEditObserver);
   294 	IMPORT_C TBool ParseText(TInt& aStartOfTags, TInt& aLength, TBool aForceScanAllText);
   295 	IMPORT_C TBool CursorOverTag(TInt aPos, MParser*& aParser, TInt& aTagStart, TInt& aLength) const;
   296 	// Next tag (forwards), any or specific parser
   297 	IMPORT_C TInt PositionOfNextTag(TInt aPos) const;
   298 	IMPORT_C TInt PositionOfNextTag(TInt aPos, const MParser* aParser) const;
   299 	// Prev tag (backwards), any or specific parser
   300 	IMPORT_C TInt PositionOfPrevTag(TInt aPos) const;
   301 	IMPORT_C TInt PositionOfPrevTag(TInt aPos, const MParser* aParser) const;
   302 
   303 private:
   304 	static void CreateParserETextTLSL();
   305 	TBool DoCursorOverTag(TInt aPos, MParser*& aParser, TInt& aTagStart, TInt& aLength) const;
   306 	void OverrideFormatForParsersIfApplicable(TPtrC& aText, TCharFormatX& aFormat, TInt aStartPos) const;
   307 	void CallEditObserver(TInt aStart, TInt aExtent) const;
   308 
   309 protected:
   310 	enum {EDelimiterCharacterLength = 1};
   311 private:
   312 	TSwizzle<CStyleList> iStyleList;
   313 	TSwizzle<CRichTextIndex> iIndex;
   314 	TUint32 iFlags;
   315 	MPictureFactory* iPictureFactory;
   316 	MRichTextStoreResolver* iStoreResolver;
   317 
   318 	CParserData* iParserData;
   319 
   320 	void* iReserved_3;
   321 
   322 	__DECLARE_TEST;  // Index consistency check with document length.
   323 	};
   324 
   325 
   326 #include <txtrich.inl>
   327 
   328 
   329 #endif