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 __TXTSTYLE_H__ williamr@2: #define __TXTSTYLE_H__ williamr@2: williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: williamr@2: // Classes declared in this file: williamr@2: class CParagraphStyle; williamr@2: class CStyleTable; williamr@2: // williamr@2: // Classes referenced in this file: williamr@2: class RReadStream; williamr@2: class RWriteStream; williamr@2: williamr@2: /** williamr@2: The maximum number of characters in a paragraph style name. williamr@2: @internalAll williamr@2: */ williamr@2: const TInt KMaxParagraphStyleName=0x20; williamr@2: williamr@2: williamr@2: /** williamr@2: The name of a paragraph style, with a maximum of 32 characters, to uniquely williamr@2: identify the style. williamr@2: @internalComponent williamr@2: */ williamr@2: typedef TBuf TParagraphStyleName; williamr@2: williamr@2: /** williamr@2: @internalComponent williamr@2: */ williamr@2: const TUid KUserDefinedParagraphStyleUid={268435535}; williamr@2: williamr@2: williamr@2: // williamr@2: // Defines a paragraph style, and the paragraph style to use next. williamr@2: williamr@2: williamr@2: class RParagraphStyleInfo williamr@2: /** williamr@2: A paragraph style. williamr@2: williamr@2: This is a named set of paragraph and character format attributes, which can williamr@2: only be applied to whole paragraphs. Paragraph styles may be used in rich williamr@2: text. Global text does not support styles. williamr@2: williamr@2: This class owns a pointer to an object of class CParagraphStyle, which stores williamr@2: the style information for the current paragraph; it also references another williamr@2: pointer which is optional, and stores the style information for the next paragraph. williamr@2: After construction, the RParagraphStyleInfo object should be appended to a williamr@2: style list (class CStyleList) which takes ownership of it. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: inline RParagraphStyleInfo(); williamr@2: inline RParagraphStyleInfo(CParagraphStyle* aStyle,CParagraphStyle* aStyleForNextPara=NULL); williamr@2: inline void Discard(); williamr@2: public: williamr@2: /** Pointer to the paragraph style information. Owned by the RParagraphStyleInfo williamr@2: object. */ williamr@2: CParagraphStyle* iStyle; // owned williamr@2: /** Pointer to the paragraph style information for the next paragraph. May be NULL. */ williamr@2: CParagraphStyle* iStyleForNextPara; // referenced, may be NULL williamr@2: }; williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: class CParagraphStyle : public CParaFormatLayer williamr@2: // Defines a paragraph style as a named para format with richer attributes. williamr@2: /** williamr@2: Defines a paragraph style. williamr@2: williamr@2: A paragraph style is a named paragraph format layer which owns a set of character williamr@2: format attributes, has an outline level and a type UID. The outline level williamr@2: controls which headings should be shown when in document outline view. The williamr@2: type UID is used to differentiate between a word processor's built-in styles, williamr@2: which cannot be deleted, and user-defined styles, which can be deleted. williamr@2: williamr@2: The style's paragraph format attributes can be set using the functions derived williamr@2: from the base class CParaFormatLayer. Its character format attributes can williamr@2: be set through the owned CCharFormatLayer*. The style's character and paragraph williamr@2: format attributes are based on the global format layers specified on construction. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: friend class CStyleList; williamr@2: friend class CRichTextIndex; williamr@2: williamr@2: williamr@2: williamr@2: /** Controls what happens to the styles when styled rich text is pasted into another williamr@2: rich text object. */ williamr@2: enum TStylePasteMode williamr@2: { williamr@2: /** The pasted rich text retains all formatting and any new style definitions are williamr@2: added to the style list of the rich text object into which it is pasted. */ williamr@2: EAddNewStyles, williamr@2: /** The pasted rich text retains all formatting, including that specified in the williamr@2: styles, but the new style definitions are not added to the style list of the williamr@2: rich text object into which it is pasted. The formatting specified in the williamr@2: styles becomes specific formatting. */ williamr@2: EConvertNewStyles, williamr@2: /** The pasted rich text loses all formatting specified in the styles. */ williamr@2: EIgnoreNewStyles williamr@2: }; williamr@2: williamr@2: williamr@2: williamr@2: /** Retention of specific formatting */ williamr@2: enum TApplyParaStyleMode williamr@2: { williamr@2: /** Specific character and paragraph formatting which has been applied to the paragraph williamr@2: is retained when a style is applied. If the style's formatting conflicts williamr@2: with the specific formatting, the specific formatting overrides the style. */ williamr@2: ERetainAllSpecificFormats, williamr@2: /** Specific character and paragraph formatting which has been applied to the paragraph williamr@2: is removed when a style is applied, regardless of whether or not it conflicts williamr@2: with the style. */ williamr@2: ERetainNoSpecificFormats, williamr@2: /** Specific paragraph formatting which has been applied to the paragraph is retained williamr@2: when a style is applied. If the style's formatting conflicts with the specific williamr@2: paragraph formatting, the specific formatting overrides the style. williamr@2: williamr@2: Specific character formatting which has been applied to the paragraph is removed, williamr@2: regardless of whether or not it conflicts with the style. */ williamr@2: ERetainSpecificParaFormat, williamr@2: /** Specific character formatting which has been applied to the paragraph is retained williamr@2: when a style is applied. If the style's formatting conflicts with the specific williamr@2: character formatting, the specific formatting overrides the style. williamr@2: williamr@2: Specific paragraph formatting which has been applied to the paragraph is removed, williamr@2: regardless of whether or not it conflicts with the style. */ williamr@2: ERetainSpecificCharFormat williamr@2: }; williamr@2: public: williamr@2: // Creates style & bases it on the speicfied global layers - the 'Normal' style. williamr@2: IMPORT_C static CParagraphStyle* NewL(const CParaFormatLayer& aGlobalParaFormatLayer,const CCharFormatLayer& aGlobalCharFormatLayer); williamr@2: IMPORT_C ~CParagraphStyle(); williamr@2: // williamr@2: // Getters/Setters williamr@2: inline CCharFormatLayer* CharFormatLayer()const; williamr@2: inline TInt OutlineLevel()const; williamr@2: inline void SetOutlineLevel(TInt aOutlineLevel); williamr@2: // williamr@2: // Utilities williamr@2: IMPORT_C virtual TUid Type()const; williamr@2: inline void SetType(TUid aType); williamr@2: inline CParagraphStyle* CloneL()const; williamr@2: private: williamr@2: CParagraphStyle(); williamr@2: void ConstructL(const CParaFormatLayer& aGlobalParaFormatLayer, williamr@2: const CCharFormatLayer& aGlobalCharFormatLayer); williamr@2: IMPORT_C virtual CFormatLayer* DoCloneL()const; williamr@2: // williamr@2: // Save/Load williamr@2: static CParagraphStyle* NewL(RReadStream& aStream,const CParaFormatLayer& aGlobalParaFormatLayer,const CCharFormatLayer& aGlobalCharFormatLayer); williamr@2: virtual void InternalizeL(RReadStream& aStream,const CFormatLayer* aParaLayerBase,const CFormatLayer* aCharLayerBase); williamr@2: virtual void ExternalizeL(RWriteStream& aStream)const; williamr@2: private: williamr@2: TUid iType; williamr@2: TInt iOutlineLevel; williamr@2: CCharFormatLayer* iCharFormatLayer; // should never be NULL williamr@2: public: williamr@2: /** Unique style name, with a maximum of 32 characters. */ williamr@2: TParagraphStyleName iName; williamr@2: }; williamr@2: williamr@2: williamr@2: /** williamr@2: The number of entries by which a style list expands when its buffer is reallocated. williamr@2: @internalComponent williamr@2: */ williamr@2: const TInt KMaxStyleListGranularity=0x04; williamr@2: williamr@2: williamr@2: williamr@2: class CStyleList : public CBase williamr@2: /** williamr@2: A container of paragraph styles. williamr@2: williamr@2: It is implemented as a fixed length array of pointers to RParagraphStyleInfos. williamr@2: The array's granularity is specified on construction. The list takes ownership williamr@2: of all paragraph styles appended to it. When the list is deleted, all styles williamr@2: it owns are also deleted. williamr@2: williamr@2: After the style list has been set up, it should normally be passed to a CRichText williamr@2: object, either in the rich text object's constructor, or by calling CRichText::SetStyleListExternallyOwned(). williamr@2: The rich text object takes ownership of the style list (unless SetStyleListExternallyOwned() williamr@2: is used). Styles can be modified, added to and removed from the style list williamr@2: after ownership of the list has been passed to the rich text object. williamr@2: williamr@2: If CRichText::SetStyleListExternallyOwned() is used, the style list is not williamr@2: owned by the rich text object, and it must be stored and restored separately williamr@2: from the rich text object. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C static CStyleList* NewL(TInt aCapacity=KMaxStyleListGranularity); williamr@2: IMPORT_C static CStyleList* NewL(RReadStream& aStream, williamr@2: const CParaFormatLayer* aGlobalParaFormatLayer, williamr@2: const CCharFormatLayer* aGlobalCharFormatLayer); williamr@2: IMPORT_C ~CStyleList(); williamr@2: // williamr@2: inline const RParagraphStyleInfo& operator[](TInt aIndex)const; williamr@2: inline RParagraphStyleInfo& operator[](TInt aIndex); williamr@2: IMPORT_C const RParagraphStyleInfo& At(TInt aIndex)const; williamr@2: IMPORT_C RParagraphStyleInfo& At(TInt aIndex); williamr@2: // williamr@2: // Persistence williamr@2: IMPORT_C TStreamId StoreL(CStreamStore& aStore)const; williamr@2: IMPORT_C void ExternalizeL(RWriteStream& aStream)const; williamr@2: IMPORT_C void InternalizeL(RReadStream& aStream, williamr@2: const CParaFormatLayer* aGlobalParaFormatLayer, williamr@2: const CCharFormatLayer* aGlobalCharFormatLayer); williamr@2: // williamr@2: // Table maintenance williamr@2: IMPORT_C void Reset(); // Delete all styles from the style list. williamr@2: IMPORT_C TInt AppendL(RParagraphStyleInfo* aStyleSet); williamr@2: IMPORT_C void Remove(CParagraphStyle* aStyle); williamr@2: IMPORT_C TInt SetStyleToFollow(const RParagraphStyleInfo& aStyleSet); // returns KErrNone or KErrNotFound williamr@2: IMPORT_C CStyleList* DeepCloneL()const; williamr@2: // williamr@2: // Getters williamr@2: IMPORT_C RParagraphStyleInfo* PtrByName(const TParagraphStyleName& aName)const; williamr@2: IMPORT_C RParagraphStyleInfo* PtrByType(const TUid aType)const; williamr@2: IMPORT_C TInt IndexByPtr(const CParaFormatLayer* aPtr)const; williamr@2: // Returns KErrNotFound if the specified style is not located in the style list. williamr@2: // williamr@2: IMPORT_C TInt IndexByName(const TDesC& aName)const; williamr@2: // Returns KErrNotFound if the specified style name is not located in the style list. williamr@2: // williamr@2: // General williamr@2: inline TInt Count()const; williamr@2: protected: williamr@2: IMPORT_C CStyleList(); williamr@2: IMPORT_C void ConstructL(TInt aGranularity); williamr@2: private: williamr@2: void KillStyleList(); williamr@2: private: williamr@2: CArrayFixFlat* iList; williamr@2: __DECLARE_TEST; williamr@2: }; williamr@2: williamr@2: williamr@2: #include williamr@2: williamr@2: #endif