First public contribution.
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #ifndef __TXTFMLYR_H__
20 #define __TXTFMLYR_H__
27 // forward declarations
33 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
34 #include <txtfmlyr_internal.h>
38 Abstract base class for the paragraph and character format layers.
40 A format layer is a set of character or paragraph format attributes which
41 may own a pointer to another format layer. This pointer is called a based-on
42 link. The effective formatting of a text object may be built up from a chain
43 of format layers - the final layer in the chain has a NULL based-on link.
44 In case of conflict, attribute values set in upper layers (layers furthest
45 from the layer with the NULL based-on link) override those set in lower layers.
46 In rich text, additional formatting may be applied on top of these format
49 The system of based-on links is implemented by the CFormatLayer class. It
50 also implements persistence for chains of format layers.
52 When setting or sensing the attributes of a CParaFormatLayer or CCharFormatLayer,
53 a format mask and container are specified as parameters. The container has
54 data members for every format attribute, which may be set independently. When
55 setting the layer, the mask indicates the attributes which will be taken from
56 the container. Any attributes not specified in the mask will be taken from
57 the system-provided default values.
59 When sensing a layer, on return, the mask indicates which attributes have
60 been explicitly set in the layer, (i.e. not taken from the default values).
61 In addition, a layer's effective format may be sensed. In this case, no
62 mask is used because the format container will, on return, contain a value
67 class CFormatLayer : public CBase
71 // Based-on link utilities
72 IMPORT_C void Reset(); // Remove all contents of this layer in a leave safe manner.
73 IMPORT_C void SetBase(const CFormatLayer* aBaseFormatLayer); // Set this layer to be based on the specified layer.
74 IMPORT_C const CFormatLayer* SenseBase()const;
75 IMPORT_C TInt ChainCount()const; // Returns the number of format layers in the chain, inclusive of itself.
80 /** Implementations of this function internalise the format layer but not its based-on
81 link from a read stream. The presence of this function means that the standard
82 templated operator>>() (defined in s32strm.h) is available to internalise
83 objects of the derived class. The internalised layer is set to be based on
86 @param aStream Stream from which the format layer should be internalised.
87 @param aBase The based-on link to assign to the layer. By default, NULL. */
88 virtual void InternalizeL(RReadStream& aStream,const CFormatLayer* aBase=NULL)=0;
91 /** Implementations of this function externalise the format layer but not its based-on
92 link to a write stream. The presence of this function means that the standard
93 templatedoperator<<() (defined in s32strm.h) is available to externalise objects
96 @param aStream Stream to which the format layer should be externalised. */
97 virtual void ExternalizeL(RWriteStream& aStream)const=0;
99 // Restore a format chain where the end of the chain is based on aBase (where aBase may be null).
100 IMPORT_C void InternalizeChainL(RReadStream& aStream,const CFormatLayer* aBase=NULL);
101 // Stores a format layer chain of length length-aExcludeCount (or by default the whole chain).
102 IMPORT_C void ExternalizeChainL(RWriteStream& aStream,TInt aExcludeCount=0)const;
103 /** Implementations of this function compare another format layer with the current
104 object. For the two layers to be equal, they must have the same contents and
105 (if the second parameter is ETrue), their based-on links must point to the
108 @param aLayer The layer to compare to this format layer.
109 @param aCheckBasedOnLink If ETrue, both layers' based-on links must point to
110 the same format layer. If EFalse, the based-on links are not used in the comparison.
112 @return ETrue if the two layers are identical, otherwise EFalse. */
113 virtual TBool IsIdentical(CFormatLayer* aLayer,TBool aCheckBasedOnLink=ETrue)const=0;
114 IMPORT_C TBool IsEmpty()const;
115 void Swap(CFormatLayer& aLayer);
117 CFormatLayer(const CFormatLayer& aFormatLayer);
118 CFormatLayer& operator=(const CFormatLayer& aFormatLayer);
119 virtual CFormatLayer* DoCloneL()const=0;
123 virtual CFormatLayer* RestoreNewL(RReadStream& aStream)=0;
124 void ExternalizeLayersRecurseL(RWriteStream& aStream,TInt aDescendantCount)const;
125 TBool IsIdentical(const TUint8* aPtr,TInt aSize)const;
126 const TUint8* Ptr(TInt& aSize)const;
127 void CloneLayerL(CFormatLayer* aClone)const;
129 RFormatStream iStore;
130 const CFormatLayer* iBasedOn; // If non-null used to inherit format attributes from the lower layer.
136 A paragraph format layer.
138 Has a pointer (stored in its base class CFormatLayer) to another paragraph
139 format layer which may be NULL. This pointer is referred to as the based-on
140 link. A paragraph format layer is owned by an instance of the CGlobalText
141 class and stores the object's global paragraph formatting. Implements persistence
142 and allows attributes to be set and sensed.
146 class CParaFormatLayer : public CFormatLayer
149 IMPORT_C static CParaFormatLayer* NewL();
150 IMPORT_C static CParaFormatLayer* NewL(const CParaFormat* aParaFormat,const TParaFormatMask& aMask);
151 IMPORT_C static CParaFormatLayer* NewL(RReadStream& aStream);
152 static CParaFormatLayer* NewL(const CParaFormatLayer* aLayer);
153 static CParaFormatLayer* NewCopyBaseL(const CParaFormatLayer* aLayer);
154 // Create a new instance, restoring it from the specified stream.
155 // The based on link is NULL. Restores only one layer.
158 IMPORT_C virtual void InternalizeL(RReadStream& aStream,const CFormatLayer* aBase=NULL);
159 IMPORT_C virtual void ExternalizeL(RWriteStream& aStream)const;
162 IMPORT_C void SetL(const CParaFormat* aDesiredEffectiveFormat,const TParaFormatMask& aMask);
163 IMPORT_C void SenseEffectiveL(CParaFormat* aParaFormat,CParaFormat::TParaFormatGetMode aMode=CParaFormat::EAllAttributes)const;
164 IMPORT_C void SenseL(CParaFormat* aParaFormat,TParaFormatMask& aMask,CParaFormat::TParaFormatGetMode aMode=CParaFormat::EAllAttributes)const;
167 inline CParaFormatLayer* CloneL()const;
168 IMPORT_C TBool IsIdenticalL(const CParaFormat* aParaFormat,const TParaFormatMask& aMask)const;
169 IMPORT_C virtual TBool IsIdentical(CFormatLayer* aLayer,TBool aCheckBasedOnLink=ETrue)const;
170 IMPORT_C virtual TUid Type()const;
171 IMPORT_C const TUint8* Ptr(TInt& aSize)const;
174 // No implementation provided
175 CParaFormatLayer(const CParaFormatLayer& aParaFormatLayer);
176 CParaFormatLayer& operator=(const CParaFormatLayer& aParaFormatLayer);
177 IMPORT_C virtual CFormatLayer* DoCloneL()const;
178 void FillParaFormatL(CParaFormat* aParaFormat,TParaFormatMask& aMask,CParaFormat::TParaFormatGetMode aMode)const;
179 void CleanupEffectiveFormat(CParaFormat* aParaFormat,TParaFormatMask aMask)const;
180 void CleanupBorders(CParaFormat* aParaFormat)const;
183 virtual CFormatLayer* RestoreNewL(RReadStream& aStream);
187 Character format layer.
189 Uses a pointer (stored in its base class CFormatLayer) to another character
190 format layer which may be NULL. This pointer is referred to as the based-on
191 link. A character format layer is owned by an instance of the CGlobalText
192 class and stores the object's global character formatting. Implements persistence
193 and allows attributes to be set and sensed.
197 class CCharFormatLayer : public CFormatLayer
200 IMPORT_C static CCharFormatLayer* NewL();
201 IMPORT_C static CCharFormatLayer* NewL(const TCharFormat& aFormat,const TCharFormatMask& aMask);
202 IMPORT_C static CCharFormatLayer* NewL(RReadStream& aStream);
203 IMPORT_C virtual void InternalizeL(RReadStream& aStream,const CFormatLayer* aBase=NULL);
204 IMPORT_C virtual void ExternalizeL(RWriteStream& aStream)const;
205 IMPORT_C void SetL(const TCharFormat& aCharFormat,const TCharFormatMask& aMask);
206 IMPORT_C void SenseEffective(TCharFormat& aCharFormat)const;
207 IMPORT_C void Sense(TCharFormat& aCharFormat,TCharFormatMask& aMask)const;
208 inline CCharFormatLayer* CloneL()const;
209 IMPORT_C virtual TBool IsIdentical(CFormatLayer* aLayer,TBool aCheckBasedOnLink=ETrue)const;
210 IMPORT_C TBool IsIdentical(const TCharFormat& aCharFormat,const TCharFormatMask& aMask)const;
211 IMPORT_C const TUint8* Ptr(TInt& aSize)const;
213 // non-exported public functions
214 static CCharFormatLayer* NewL(const CCharFormatLayer* aLayer);
215 static CCharFormatLayer* NewCopyBaseL(const CCharFormatLayer* aLayer);
216 static CCharFormatLayer* NewL(const TCharFormatX& aFormat,const TCharFormatXMask& aMask);
217 void SetL(const TCharFormatX& aCharFormat,const TCharFormatXMask& aMask);
218 void SenseEffective(TCharFormatX& aCharFormat)const;
219 void Sense(TCharFormatX& aCharFormat,TCharFormatXMask& aMask) const;
223 virtual CFormatLayer* RestoreNewL(RReadStream& aStream);
224 virtual void FillCharFormat(TCharFormatX& aCharFormat,TCharFormatXMask& aMask)const;
225 IMPORT_C virtual CFormatLayer* DoCloneL()const;
229 #include <txtfmlyr.inl>