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.
16 #ifndef __TXTSTYLE_H__
17 #define __TXTSTYLE_H__
24 // Classes declared in this file:
25 class CParagraphStyle;
28 // Classes referenced in this file:
33 The maximum number of characters in a paragraph style name.
36 const TInt KMaxParagraphStyleName=0x20;
40 The name of a paragraph style, with a maximum of 32 characters, to uniquely
44 typedef TBuf<KMaxParagraphStyleName> TParagraphStyleName;
49 const TUid KUserDefinedParagraphStyleUid={268435535};
53 // Defines a paragraph style, and the paragraph style to use next.
56 class RParagraphStyleInfo
60 This is a named set of paragraph and character format attributes, which can
61 only be applied to whole paragraphs. Paragraph styles may be used in rich
62 text. Global text does not support styles.
64 This class owns a pointer to an object of class CParagraphStyle, which stores
65 the style information for the current paragraph; it also references another
66 pointer which is optional, and stores the style information for the next paragraph.
67 After construction, the RParagraphStyleInfo object should be appended to a
68 style list (class CStyleList) which takes ownership of it.
74 inline RParagraphStyleInfo();
75 inline RParagraphStyleInfo(CParagraphStyle* aStyle,CParagraphStyle* aStyleForNextPara=NULL);
76 inline void Discard();
78 /** Pointer to the paragraph style information. Owned by the RParagraphStyleInfo
80 CParagraphStyle* iStyle; // owned
81 /** Pointer to the paragraph style information for the next paragraph. May be NULL. */
82 CParagraphStyle* iStyleForNextPara; // referenced, may be NULL
88 class CParagraphStyle : public CParaFormatLayer
89 // Defines a paragraph style as a named para format with richer attributes.
91 Defines a paragraph style.
93 A paragraph style is a named paragraph format layer which owns a set of character
94 format attributes, has an outline level and a type UID. The outline level
95 controls which headings should be shown when in document outline view. The
96 type UID is used to differentiate between a word processor's built-in styles,
97 which cannot be deleted, and user-defined styles, which can be deleted.
99 The style's paragraph format attributes can be set using the functions derived
100 from the base class CParaFormatLayer. Its character format attributes can
101 be set through the owned CCharFormatLayer*. The style's character and paragraph
102 format attributes are based on the global format layers specified on construction.
108 friend class CStyleList;
109 friend class CRichTextIndex;
113 /** Controls what happens to the styles when styled rich text is pasted into another
117 /** The pasted rich text retains all formatting and any new style definitions are
118 added to the style list of the rich text object into which it is pasted. */
120 /** The pasted rich text retains all formatting, including that specified in the
121 styles, but the new style definitions are not added to the style list of the
122 rich text object into which it is pasted. The formatting specified in the
123 styles becomes specific formatting. */
125 /** The pasted rich text loses all formatting specified in the styles. */
131 /** Retention of specific formatting */
132 enum TApplyParaStyleMode
134 /** Specific character and paragraph formatting which has been applied to the paragraph
135 is retained when a style is applied. If the style's formatting conflicts
136 with the specific formatting, the specific formatting overrides the style. */
137 ERetainAllSpecificFormats,
138 /** Specific character and paragraph formatting which has been applied to the paragraph
139 is removed when a style is applied, regardless of whether or not it conflicts
141 ERetainNoSpecificFormats,
142 /** Specific paragraph formatting which has been applied to the paragraph is retained
143 when a style is applied. If the style's formatting conflicts with the specific
144 paragraph formatting, the specific formatting overrides the style.
146 Specific character formatting which has been applied to the paragraph is removed,
147 regardless of whether or not it conflicts with the style. */
148 ERetainSpecificParaFormat,
149 /** Specific character formatting which has been applied to the paragraph is retained
150 when a style is applied. If the style's formatting conflicts with the specific
151 character formatting, the specific formatting overrides the style.
153 Specific paragraph formatting which has been applied to the paragraph is removed,
154 regardless of whether or not it conflicts with the style. */
155 ERetainSpecificCharFormat
158 // Creates style & bases it on the speicfied global layers - the 'Normal' style.
159 IMPORT_C static CParagraphStyle* NewL(const CParaFormatLayer& aGlobalParaFormatLayer,const CCharFormatLayer& aGlobalCharFormatLayer);
160 IMPORT_C ~CParagraphStyle();
163 inline CCharFormatLayer* CharFormatLayer()const;
164 inline TInt OutlineLevel()const;
165 inline void SetOutlineLevel(TInt aOutlineLevel);
168 IMPORT_C virtual TUid Type()const;
169 inline void SetType(TUid aType);
170 inline CParagraphStyle* CloneL()const;
173 void ConstructL(const CParaFormatLayer& aGlobalParaFormatLayer,
174 const CCharFormatLayer& aGlobalCharFormatLayer);
175 IMPORT_C virtual CFormatLayer* DoCloneL()const;
178 static CParagraphStyle* NewL(RReadStream& aStream,const CParaFormatLayer& aGlobalParaFormatLayer,const CCharFormatLayer& aGlobalCharFormatLayer);
179 virtual void InternalizeL(RReadStream& aStream,const CFormatLayer* aParaLayerBase,const CFormatLayer* aCharLayerBase);
180 virtual void ExternalizeL(RWriteStream& aStream)const;
184 CCharFormatLayer* iCharFormatLayer; // should never be NULL
186 /** Unique style name, with a maximum of 32 characters. */
187 TParagraphStyleName iName;
192 The number of entries by which a style list expands when its buffer is reallocated.
195 const TInt KMaxStyleListGranularity=0x04;
199 class CStyleList : public CBase
201 A container of paragraph styles.
203 It is implemented as a fixed length array of pointers to RParagraphStyleInfos.
204 The array's granularity is specified on construction. The list takes ownership
205 of all paragraph styles appended to it. When the list is deleted, all styles
206 it owns are also deleted.
208 After the style list has been set up, it should normally be passed to a CRichText
209 object, either in the rich text object's constructor, or by calling CRichText::SetStyleListExternallyOwned().
210 The rich text object takes ownership of the style list (unless SetStyleListExternallyOwned()
211 is used). Styles can be modified, added to and removed from the style list
212 after ownership of the list has been passed to the rich text object.
214 If CRichText::SetStyleListExternallyOwned() is used, the style list is not
215 owned by the rich text object, and it must be stored and restored separately
216 from the rich text object.
222 IMPORT_C static CStyleList* NewL(TInt aCapacity=KMaxStyleListGranularity);
223 IMPORT_C static CStyleList* NewL(RReadStream& aStream,
224 const CParaFormatLayer* aGlobalParaFormatLayer,
225 const CCharFormatLayer* aGlobalCharFormatLayer);
226 IMPORT_C ~CStyleList();
228 inline const RParagraphStyleInfo& operator[](TInt aIndex)const;
229 inline RParagraphStyleInfo& operator[](TInt aIndex);
230 IMPORT_C const RParagraphStyleInfo& At(TInt aIndex)const;
231 IMPORT_C RParagraphStyleInfo& At(TInt aIndex);
234 IMPORT_C TStreamId StoreL(CStreamStore& aStore)const;
235 IMPORT_C void ExternalizeL(RWriteStream& aStream)const;
236 IMPORT_C void InternalizeL(RReadStream& aStream,
237 const CParaFormatLayer* aGlobalParaFormatLayer,
238 const CCharFormatLayer* aGlobalCharFormatLayer);
241 IMPORT_C void Reset(); // Delete all styles from the style list.
242 IMPORT_C TInt AppendL(RParagraphStyleInfo* aStyleSet);
243 IMPORT_C void Remove(CParagraphStyle* aStyle);
244 IMPORT_C TInt SetStyleToFollow(const RParagraphStyleInfo& aStyleSet); // returns KErrNone or KErrNotFound
245 IMPORT_C CStyleList* DeepCloneL()const;
248 IMPORT_C RParagraphStyleInfo* PtrByName(const TParagraphStyleName& aName)const;
249 IMPORT_C RParagraphStyleInfo* PtrByType(const TUid aType)const;
250 IMPORT_C TInt IndexByPtr(const CParaFormatLayer* aPtr)const;
251 // Returns KErrNotFound if the specified style is not located in the style list.
253 IMPORT_C TInt IndexByName(const TDesC& aName)const;
254 // Returns KErrNotFound if the specified style name is not located in the style list.
257 inline TInt Count()const;
259 IMPORT_C CStyleList();
260 IMPORT_C void ConstructL(TInt aGranularity);
262 void KillStyleList();
264 CArrayFixFlat<RParagraphStyleInfo>* iList;
269 #include <txtstyle.inl>