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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
31 class MPictureFactory;
32 class MRichTextStoreResolver;
34 class TCharFormatXMask;
42 const TUid KRichTextStyleDataUid = { 268450335 };
43 const TUid KClipboardUidTypeRichText = { 268450336 };
44 const TUid KClipboardUidTypeRichTextWithStyles = { 268450337 };
45 const TUid KRichTextMarkupDataUid = { 268435558 };
48 class CRichText : public CGlobalText
50 Text with rich formatting.
52 In rich text, each paragraph can have a different paragraph format, and each
53 character can have a different character format.
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.
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.
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.
84 /** Number of paragraphs in the object. */
87 /** The text object will contain a single paragraph. */
89 /** The text object will contain multiple paragraphs. */
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();
117 // Default persist functions - Deferred loading of pictures
118 IMPORT_C void RestoreWithStyleListL(const CStreamStore& aStore, TStreamId aStreamId, const CStyleList& aExternalStyleList);
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);
125 // Custom persist functions
126 IMPORT_C void ExternalizeStyleDataL(RWriteStream& aStream) const;
127 IMPORT_C void InternalizeStyleDataL(RReadStream& aStream);
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);
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;
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);
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.
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.
157 // Leave-safe delete for removing content from *within* a single paragraph only
158 IMPORT_C void DeleteFromParagraph(TInt aPos, TInt aLength);
160 // Leave-safe delete for removing *entire* paragraphs
161 IMPORT_C void DeleteParagraph(TInt aPos, TInt aLength);
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);
167 // Call this on every cursor movement, page up/down etc...
168 IMPORT_C void CancelInsertCharFormat();
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);
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;
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);
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;
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;
200 // StyleList implementation
201 inline TBool StyleListPresent() const;
202 inline CStyleList* StyleList() const;
203 inline TInt StyleCount() const;
205 inline void SetStyleListExternallyOwned(TBool aExternallyOwned);
206 IMPORT_C void SetStyleListExternallyOwned(const CStyleList& aStyleList);
207 inline TBool StyleListExternallyOwned() const;
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;
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)
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);
228 IMPORT_C void ExtendedInterface(TAny*& aInterface, TUid aInterfaceId); // from CEditableText
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;
236 CRichText(const CRichText& aRichText);
237 CRichText& operator=(const CRichText& aRichText);
238 void KillStyleList();
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);
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);
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;
272 IMPORT_C void RtInsertL(TInt aPos,const TDesC& aBuf);
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);
284 void PrepareAppendMarkupL(const CRichText& aSource);
285 void DoAppendTakingSolePictureOwnershipL(const CRichText& aSource);
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
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;
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;
310 enum {EDelimiterCharacterLength = 1};
312 TSwizzle<CStyleList> iStyleList;
313 TSwizzle<CRichTextIndex> iIndex;
315 MPictureFactory* iPictureFactory;
316 MRichTextStoreResolver* iStoreResolver;
318 CParserData* iParserData;
322 __DECLARE_TEST; // Index consistency check with document length.
326 #include <txtrich.inl>