epoc32/include/txtstyle.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
permissions -rw-r--r--
Final list of Symbian^2 public API header files
     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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #ifndef __TXTSTYLE_H__
    17 #define __TXTSTYLE_H__
    18 
    19 #include <e32std.h>
    20 #include <e32base.h>
    21 #include <txtfmlyr.h>
    22 
    23 
    24 // Classes declared in this file:
    25 class CParagraphStyle;
    26 class CStyleTable;
    27 //
    28 // Classes referenced in this file:
    29 class RReadStream;
    30 class RWriteStream;
    31 
    32 /** 
    33 The maximum number of characters in a paragraph style name. 
    34 @internalAll 
    35 */
    36 const TInt KMaxParagraphStyleName=0x20;
    37 
    38 
    39 /** 
    40 The name of a paragraph style, with a maximum of 32 characters, to uniquely 
    41 identify the style. 
    42 @internalComponent 
    43 */
    44 typedef TBuf<KMaxParagraphStyleName> TParagraphStyleName;
    45 
    46 /**
    47 @internalComponent 
    48 */
    49 const TUid KUserDefinedParagraphStyleUid={268435535};
    50 
    51 
    52 //
    53 // Defines a paragraph style, and the paragraph style to use next.
    54 
    55 
    56 class RParagraphStyleInfo
    57 /** 
    58 A paragraph style.
    59 
    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.
    63 
    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. 
    69 @publishedAll
    70 @released
    71 */
    72 	{
    73 public:
    74 	inline RParagraphStyleInfo();
    75 	inline RParagraphStyleInfo(CParagraphStyle* aStyle,CParagraphStyle* aStyleForNextPara=NULL);
    76 	inline void Discard();
    77 public:
    78 	/** Pointer to the paragraph style information. Owned by the RParagraphStyleInfo 
    79 	object. */
    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
    83 	};
    84 
    85 
    86 
    87 
    88 class CParagraphStyle : public CParaFormatLayer
    89 // Defines a paragraph style as a named para format with richer attributes.
    90 /** 
    91 Defines a paragraph style. 
    92 
    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.
    98 
    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. 
   103 @publishedAll
   104 @released
   105 */
   106 	{
   107 public:
   108 	friend class CStyleList;
   109 	friend class CRichTextIndex;
   110 	
   111 
   112 
   113 /** Controls what happens to the styles when styled rich text is pasted into another 
   114 rich text object. */
   115 	enum TStylePasteMode
   116 		{
   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. */
   119 		EAddNewStyles,
   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. */
   124 		EConvertNewStyles,
   125 	/** The pasted rich text loses all formatting specified in the styles. */
   126 		EIgnoreNewStyles
   127 		};
   128 	
   129 
   130 
   131 /** Retention of specific formatting */
   132 	enum TApplyParaStyleMode
   133 		{
   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 
   140 	with the style. */
   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.
   145 	
   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.
   152 	
   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
   156 		};
   157 public:
   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();
   161 	//
   162 	// Getters/Setters
   163 	inline CCharFormatLayer* CharFormatLayer()const;
   164 	inline TInt OutlineLevel()const;
   165 	inline void SetOutlineLevel(TInt aOutlineLevel);
   166 	//
   167 	// Utilities
   168 	IMPORT_C virtual TUid Type()const;
   169 	inline void SetType(TUid aType);
   170 	inline CParagraphStyle* CloneL()const;
   171 private:
   172 	CParagraphStyle();	
   173 	void ConstructL(const CParaFormatLayer& aGlobalParaFormatLayer,
   174 							 const CCharFormatLayer& aGlobalCharFormatLayer);
   175 	IMPORT_C virtual CFormatLayer* DoCloneL()const;
   176 	//
   177 	// Save/Load
   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;
   181 private:
   182 	TUid iType;
   183 	TInt iOutlineLevel;
   184 	CCharFormatLayer* iCharFormatLayer;  // should never be NULL
   185 public:
   186 	/** Unique style name, with a maximum of 32 characters. */
   187 	TParagraphStyleName iName;
   188 	};
   189 
   190 
   191 /** 
   192 The number of entries by which a style list expands when its buffer is reallocated. 
   193 @internalComponent 
   194 */
   195 const TInt KMaxStyleListGranularity=0x04;
   196 
   197 
   198 
   199 class CStyleList : public CBase
   200 /** 
   201 A container of paragraph styles. 
   202 
   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.
   207 
   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.
   213 
   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. 
   217 @publishedAll
   218 @released
   219 */
   220 	{
   221 public:
   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();
   227 	//
   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);
   232 	//
   233 	// Persistence
   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);
   239 	//
   240 	// Table maintenance
   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;
   246 	//
   247 	// Getters
   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.
   252 	//
   253 	IMPORT_C TInt IndexByName(const TDesC& aName)const;
   254 	// Returns KErrNotFound if the specified style name is not located in the style list.
   255 	//
   256 	// General
   257 	inline TInt Count()const;
   258 protected:
   259 	IMPORT_C CStyleList();
   260 	IMPORT_C void ConstructL(TInt aGranularity);
   261 private:
   262 	void KillStyleList();
   263 private:
   264 	CArrayFixFlat<RParagraphStyleInfo>* iList;
   265 	__DECLARE_TEST;
   266 	};
   267 
   268 
   269 #include <txtstyle.inl>
   270 
   271 #endif