williamr@2: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@2: // 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 williamr@2: // which accompanies this distribution, and is available williamr@2: // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // williamr@2: williamr@2: #ifndef __TXTFMLYR_H__ williamr@2: #define __TXTFMLYR_H__ williamr@2: williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: // forward declarations williamr@2: class CFormatStream; williamr@2: class RReadStream; williamr@2: class RWriteStream; williamr@2: class TCharFormatX; williamr@2: williamr@2: /** williamr@2: @internalTechnology williamr@2: */ williamr@2: const TUid KNormalParagraphStyleUid={268435531}; williamr@2: williamr@2: /** williamr@2: Abstract base class for the paragraph and character format layers. williamr@2: williamr@2: A format layer is a set of character or paragraph format attributes which williamr@2: may own a pointer to another format layer. This pointer is called a based-on williamr@2: link. The effective formatting of a text object may be built up from a chain williamr@2: of format layers - the final layer in the chain has a NULL based-on link. williamr@2: In case of conflict, attribute values set in upper layers (layers furthest williamr@2: from the layer with the NULL based-on link) override those set in lower layers. williamr@2: In rich text, additional formatting may be applied on top of these format williamr@2: layers. williamr@2: williamr@2: The system of based-on links is implemented by the CFormatLayer class. It williamr@2: also implements persistence for chains of format layers. williamr@2: williamr@2: When setting or sensing the attributes of a CParaFormatLayer or CCharFormatLayer, williamr@2: a format mask and container are specified as parameters. The container has williamr@2: data members for every format attribute, which may be set independently. When williamr@2: setting the layer, the mask indicates the attributes which will be taken from williamr@2: the container. Any attributes not specified in the mask will be taken from williamr@2: the system-provided default values. williamr@2: williamr@2: When sensing a layer, on return, the mask indicates which attributes have williamr@2: been explicitly set in the layer, (i.e. not taken from the default values). williamr@2: In addition, a layer's effective format may be sensed. In this case, no williamr@2: mask is used because the format container will, on return, contain a value williamr@2: for every attribute. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class CFormatLayer : public CBase williamr@2: { williamr@2: public: williamr@2: // williamr@2: // Based-on link utilities williamr@2: IMPORT_C void Reset(); // Remove all contents of this layer in a leave safe manner. williamr@2: IMPORT_C void SetBase(const CFormatLayer* aBaseFormatLayer); // Set this layer to be based on the specified layer. williamr@2: IMPORT_C const CFormatLayer* SenseBase()const; williamr@2: IMPORT_C TInt ChainCount()const; // Returns the number of format layers in the chain, inclusive of itself. williamr@2: // williamr@2: // Persistence williamr@2: williamr@2: williamr@2: /** Implementations of this function internalise the format layer but not its based-on williamr@2: link from a read stream. The presence of this function means that the standard williamr@2: templated operator>>() (defined in s32strm.h) is available to internalise williamr@2: objects of the derived class. The internalised layer is set to be based on williamr@2: the layer specified. williamr@2: williamr@2: @param aStream Stream from which the format layer should be internalised. williamr@2: @param aBase The based-on link to assign to the layer. By default, NULL. */ williamr@2: virtual void InternalizeL(RReadStream& aStream,const CFormatLayer* aBase=NULL)=0; williamr@2: williamr@2: williamr@2: /** Implementations of this function externalise the format layer but not its based-on williamr@2: link to a write stream. The presence of this function means that the standard williamr@2: templatedoperator<<() (defined in s32strm.h) is available to externalise objects williamr@2: of the derived class. williamr@2: williamr@2: @param aStream Stream to which the format layer should be externalised. */ williamr@2: virtual void ExternalizeL(RWriteStream& aStream)const=0; williamr@2: // williamr@2: // Restore a format chain where the end of the chain is based on aBase (where aBase may be null). williamr@2: IMPORT_C void InternalizeChainL(RReadStream& aStream,const CFormatLayer* aBase=NULL); williamr@2: // Stores a format layer chain of length length-aExcludeCount (or by default the whole chain). williamr@2: IMPORT_C void ExternalizeChainL(RWriteStream& aStream,TInt aExcludeCount=0)const; williamr@2: /** Implementations of this function compare another format layer with the current williamr@2: object. For the two layers to be equal, they must have the same contents and williamr@2: (if the second parameter is ETrue), their based-on links must point to the williamr@2: same format layer. williamr@2: williamr@2: @param aLayer The layer to compare to this format layer. williamr@2: @param aCheckBasedOnLink If ETrue, both layers' based-on links must point to williamr@2: the same format layer. If EFalse, the based-on links are not used in the comparison. williamr@2: By default, ETrue. williamr@2: @return ETrue if the two layers are identical, otherwise EFalse. */ williamr@2: virtual TBool IsIdentical(CFormatLayer* aLayer,TBool aCheckBasedOnLink=ETrue)const=0; williamr@2: IMPORT_C TBool IsEmpty()const; williamr@2: void Swap(CFormatLayer& aLayer); williamr@2: private: williamr@2: CFormatLayer(const CFormatLayer& aFormatLayer); williamr@2: CFormatLayer& operator=(const CFormatLayer& aFormatLayer); williamr@2: virtual CFormatLayer* DoCloneL()const=0; williamr@2: protected: williamr@2: CFormatLayer(); williamr@2: ~CFormatLayer(); williamr@2: virtual CFormatLayer* RestoreNewL(RReadStream& aStream)=0; williamr@2: void ExternalizeLayersRecurseL(RWriteStream& aStream,TInt aDescendantCount)const; williamr@2: TBool IsIdentical(const TUint8* aPtr,TInt aSize)const; williamr@2: const TUint8* Ptr(TInt& aSize)const; williamr@2: void CloneLayerL(CFormatLayer* aClone)const; williamr@2: protected: williamr@2: RFormatStream iStore; williamr@2: const CFormatLayer* iBasedOn; // If non-null used to inherit format attributes from the lower layer. williamr@2: __DECLARE_TEST; williamr@2: }; williamr@2: williamr@2: williamr@2: /** williamr@2: A paragraph format layer. williamr@2: williamr@2: Has a pointer (stored in its base class CFormatLayer) to another paragraph williamr@2: format layer which may be NULL. This pointer is referred to as the based-on williamr@2: link. A paragraph format layer is owned by an instance of the CGlobalText williamr@2: class and stores the object's global paragraph formatting. Implements persistence williamr@2: and allows attributes to be set and sensed. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class CParaFormatLayer : public CFormatLayer williamr@2: { williamr@2: public: williamr@2: IMPORT_C static CParaFormatLayer* NewL(); williamr@2: IMPORT_C static CParaFormatLayer* NewL(const CParaFormat* aParaFormat,const TParaFormatMask& aMask); williamr@2: IMPORT_C static CParaFormatLayer* NewL(RReadStream& aStream); williamr@2: static CParaFormatLayer* NewL(const CParaFormatLayer* aLayer); williamr@2: static CParaFormatLayer* NewCopyBaseL(const CParaFormatLayer* aLayer); williamr@2: // Create a new instance, restoring it from the specified stream. williamr@2: // The based on link is NULL. Restores only one layer. williamr@2: // williamr@2: // Persistence williamr@2: IMPORT_C virtual void InternalizeL(RReadStream& aStream,const CFormatLayer* aBase=NULL); williamr@2: IMPORT_C virtual void ExternalizeL(RWriteStream& aStream)const; williamr@2: // williamr@2: // Core methods williamr@2: IMPORT_C void SetL(const CParaFormat* aDesiredEffectiveFormat,const TParaFormatMask& aMask); williamr@2: IMPORT_C void SenseEffectiveL(CParaFormat* aParaFormat,CParaFormat::TParaFormatGetMode aMode=CParaFormat::EAllAttributes)const; williamr@2: IMPORT_C void SenseL(CParaFormat* aParaFormat,TParaFormatMask& aMask,CParaFormat::TParaFormatGetMode aMode=CParaFormat::EAllAttributes)const; williamr@2: // williamr@2: // Utilities williamr@2: inline CParaFormatLayer* CloneL()const; williamr@2: IMPORT_C TBool IsIdenticalL(const CParaFormat* aParaFormat,const TParaFormatMask& aMask)const; williamr@2: IMPORT_C virtual TBool IsIdentical(CFormatLayer* aLayer,TBool aCheckBasedOnLink=ETrue)const; williamr@2: IMPORT_C virtual TUid Type()const; williamr@2: IMPORT_C const TUint8* Ptr(TInt& aSize)const; williamr@2: private: williamr@2: // williamr@2: // No implementation provided williamr@2: CParaFormatLayer(const CParaFormatLayer& aParaFormatLayer); williamr@2: CParaFormatLayer& operator=(const CParaFormatLayer& aParaFormatLayer); williamr@2: IMPORT_C virtual CFormatLayer* DoCloneL()const; williamr@2: void FillParaFormatL(CParaFormat* aParaFormat,TParaFormatMask& aMask,CParaFormat::TParaFormatGetMode aMode)const; williamr@2: void CleanupEffectiveFormat(CParaFormat* aParaFormat,TParaFormatMask aMask)const; williamr@2: void CleanupBorders(CParaFormat* aParaFormat)const; williamr@2: protected: williamr@2: CParaFormatLayer(); williamr@2: virtual CFormatLayer* RestoreNewL(RReadStream& aStream); williamr@2: }; williamr@2: williamr@2: /** williamr@2: Character format layer. williamr@2: williamr@2: Uses a pointer (stored in its base class CFormatLayer) to another character williamr@2: format layer which may be NULL. This pointer is referred to as the based-on williamr@2: link. A character format layer is owned by an instance of the CGlobalText williamr@2: class and stores the object's global character formatting. Implements persistence williamr@2: and allows attributes to be set and sensed. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class CCharFormatLayer : public CFormatLayer williamr@2: { williamr@2: public: williamr@2: IMPORT_C static CCharFormatLayer* NewL(); williamr@2: IMPORT_C static CCharFormatLayer* NewL(const TCharFormat& aFormat,const TCharFormatMask& aMask); williamr@2: IMPORT_C static CCharFormatLayer* NewL(RReadStream& aStream); williamr@2: IMPORT_C virtual void InternalizeL(RReadStream& aStream,const CFormatLayer* aBase=NULL); williamr@2: IMPORT_C virtual void ExternalizeL(RWriteStream& aStream)const; williamr@2: IMPORT_C void SetL(const TCharFormat& aCharFormat,const TCharFormatMask& aMask); williamr@2: IMPORT_C void SenseEffective(TCharFormat& aCharFormat)const; williamr@2: IMPORT_C void Sense(TCharFormat& aCharFormat,TCharFormatMask& aMask)const; williamr@2: inline CCharFormatLayer* CloneL()const; williamr@2: IMPORT_C virtual TBool IsIdentical(CFormatLayer* aLayer,TBool aCheckBasedOnLink=ETrue)const; williamr@2: IMPORT_C TBool IsIdentical(const TCharFormat& aCharFormat,const TCharFormatMask& aMask)const; williamr@2: IMPORT_C const TUint8* Ptr(TInt& aSize)const; williamr@2: williamr@2: // non-exported public functions williamr@2: static CCharFormatLayer* NewL(const CCharFormatLayer* aLayer); williamr@2: static CCharFormatLayer* NewCopyBaseL(const CCharFormatLayer* aLayer); williamr@2: static CCharFormatLayer* NewL(const TCharFormatX& aFormat,const TCharFormatXMask& aMask); williamr@2: void SetL(const TCharFormatX& aCharFormat,const TCharFormatXMask& aMask); williamr@2: void SenseEffective(TCharFormatX& aCharFormat)const; williamr@2: void Sense(TCharFormatX& aCharFormat,TCharFormatXMask& aMask) const; williamr@2: williamr@2: private: williamr@2: CCharFormatLayer(); williamr@2: virtual CFormatLayer* RestoreNewL(RReadStream& aStream); williamr@2: virtual void FillCharFormat(TCharFormatX& aCharFormat,TCharFormatXMask& aMask)const; williamr@2: IMPORT_C virtual CFormatLayer* DoCloneL()const; williamr@2: }; williamr@2: williamr@2: williamr@2: #include williamr@2: williamr@2: williamr@2: #endif