textrendering/texthandling/stext/TXTINDEX.H
changeset 0 1fb32624e06b
equal deleted inserted replaced
-1:000000000000 0:1fb32624e06b
       
     1 /*
       
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __TXTINDEX_H__
       
    20 #define __TXTINDEX_H__
       
    21 
       
    22 #include <e32std.h>
       
    23 #include <e32base.h>
       
    24 #include <txtmrtsr.h>
       
    25 #include <txtrich.h>
       
    26 #include "TXTSTD.H"
       
    27 
       
    28 // forward declarations
       
    29 class CParaAttribs;
       
    30 class CPicturePhrase;
       
    31 class RReadStream;
       
    32 class RWriteStream;
       
    33 class CStoreMap;
       
    34 class CStreamStore;
       
    35 class CPicture;
       
    36 class CCharFormatLayer;
       
    37 class CParaFormatLayer;
       
    38 class CRichText;
       
    39 class MPictureFactory;
       
    40 
       
    41 /**
       
    42 @internalComponent
       
    43 */
       
    44 enum TRichTextStylePasteMode
       
    45 	{
       
    46 	EAddNewStyles,
       
    47 	EConvertNewStyles,
       
    48 	EIgnoreNewStyles
       
    49 	};
       
    50 
       
    51 class TTextFragment
       
    52 /**
       
    53 Describes a fragment of text that does not conform to the ERA text model.
       
    54 @internalComponent
       
    55 */
       
    56 	{
       
    57 public:
       
    58 	TTextFragment();
       
    59 public:
       
    60 	TInt iLength;  // Number of characters in text fragment
       
    61 	TInt iPhraseCount;  // Number of distinct phrases in text fragment.
       
    62 	};
       
    63 
       
    64 
       
    65 class RPhraseAttribsEntry
       
    66 /**
       
    67 Provides a full description of a phrase.
       
    68 A phrase consists of a specified number of contiguous characters [the phrase length]
       
    69 of identical character format.
       
    70 Where a picture is included as text content, it is described by its own phrase.
       
    71 @internalComponent
       
    72 */
       
    73 	{
       
    74 public:
       
    75 	enum {EPictureIndicator = -1};
       
    76 	enum {EPicturePhraseLength = 1};
       
    77 public:
       
    78 	RPhraseAttribsEntry();
       
    79 	RPhraseAttribsEntry(CCharFormatLayer* aCharFormat, TInt aLength = 0); // Sets iLen to zero - empty text phrase
       
    80 	RPhraseAttribsEntry(CPicturePhrase* aPicturePhrase);  // Sets iLen to EPictureIndicator
       
    81 	inline RPhraseAttribsEntry(const RPhraseAttribsEntry& aPhrase);
       
    82 	void Discard();
       
    83 	inline RPhraseAttribsEntry& operator=(const RPhraseAttribsEntry& aPhrase);
       
    84 	//
       
    85 	// Persist
       
    86 	void ExternalizeL(RWriteStream& aStream) const;
       
    87 	//
       
    88 	// General enquiry
       
    89 	inline TBool IsPicturePhrase() const;
       
    90 	TBool IsIdentical(const RPhraseAttribsEntry& aPhrase) const;
       
    91 	//
       
    92 	// Getters
       
    93 	inline TInt Length() const;
       
    94 	CCharFormatLayer* CharFormat() const;
       
    95 	CCharFormatLayer* ReleaseCharFormatLayerOwnership();
       
    96 	TInt GetPictureSizeInTwips(TSize& aSize) const;
       
    97 	TPictureHeader* PictureHeaderPtr() const;
       
    98 	TPictureHeader PictureHeader() const;
       
    99 	const CPicture* PictureHandleL(const MPictureFactory* aFactory,
       
   100 								   const MRichTextStoreResolver* aResolver,
       
   101 								   TInt aPos,
       
   102 								   MLayDoc::TForcePictureLoad aForceLoad) const;
       
   103 	//
       
   104 	// Setters
       
   105 	void AdjustLength(TInt aIncrement);
       
   106  	void SetLength(TInt aLength);
       
   107 private:
       
   108 	void AssignAndRelease(const RPhraseAttribsEntry& aPhrase);
       
   109 private:
       
   110 	TInt iLength;  // No. of characters covered by this phrase
       
   111 	union
       
   112 		{
       
   113 		CCharFormatLayer* iCharFormat;  // *OWNED* format of this text phrase
       
   114 		CPicturePhrase* iPicturePhrase;  // *OWNED* pointer to picture phrase information
       
   115 		};
       
   116 	__DECLARE_TEST;
       
   117 	};
       
   118 
       
   119 
       
   120 NONSHARABLE_CLASS(CPicturePhrase) : public CBase
       
   121 /**
       
   122 A low-level class providing a pointer to the character format layer for this picture phrase,
       
   123 and a pointer to a picture itself.  (Which may be expressed in its persistent form).
       
   124 @internalComponent
       
   125 */
       
   126 	{
       
   127 public:
       
   128 	static CPicturePhrase* NewL(const TPictureHeader& aPicHdr,
       
   129 	                            TCharFormatX& aFormat,
       
   130 	                            TCharFormatXMask& aMask,
       
   131 	                            CCharFormatLayer* aCharBase,
       
   132 	                            TBool& aPictureOwnershipTaken);
       
   133 
       
   134 	static CPicturePhrase* NewL(const TPictureHeader& aPicHdr,
       
   135 	                            CCharFormatLayer* aCharLayer,
       
   136 	                            TBool& aPictureOwnershipTaken);
       
   137 	~CPicturePhrase();
       
   138 protected:
       
   139 	CPicturePhrase(const TPictureHeader& aPicHdr,TBool& aPictureOwnershipTaken);
       
   140 	CPicturePhrase(const TPictureHeader& aPicHdr, CCharFormatLayer* aCharLayer,TBool& aPictureOwnershipTaken);
       
   141 	void ConstructL(TCharFormatX& aFormat, TCharFormatXMask& aMask, CCharFormatLayer* aCharBase);
       
   142 public:
       
   143 	CCharFormatLayer* iCharFormat;
       
   144 	TPictureHeader iPicHdr;
       
   145 	};
       
   146 
       
   147 
       
   148 class TParaAttribsEntry
       
   149 /**
       
   150 Records the length of a paragraph (no. of characters).
       
   151 and references a CParaAttributes.
       
   152 @internalComponent
       
   153 */
       
   154 	{
       
   155 public:
       
   156 	TParaAttribsEntry();
       
   157 	TParaAttribsEntry(TInt aLength, CParaAttribs* aParaAttribs);
       
   158 public:
       
   159 	TInt iLength;  // Number of characters in the paragraph (paragraph delimiter inclusive).
       
   160 	CParaAttribs* iParaAttribs;  // Only references this, does not own it.
       
   161 	};
       
   162 
       
   163 
       
   164 class TCurrentIndexRecords
       
   165 /**
       
   166 Packages current phrase & para records.
       
   167 @internalComponent
       
   168 */
       
   169 	{
       
   170 public:
       
   171 	TCurrentIndexRecords();
       
   172 public:
       
   173 	TParaAttribsEntry* iParaEntry;
       
   174 	CParaAttribs* iParaAttribs;
       
   175 	RPhraseAttribsEntry* iPhrase;  // May be NULL.
       
   176 	};
       
   177 
       
   178 
       
   179 
       
   180 class TLogicalPosition
       
   181 /**
       
   182 Locates the current cursor position within all aspects of the index.
       
   183 @internalComponent
       
   184 */
       
   185 	{
       
   186 public:
       
   187 	TLogicalPosition();
       
   188 	void Clear();
       
   189 public:
       
   190 	TInt iDocPos;					// Absolute document position.
       
   191 	TInt iParaElement;				// paragraph index
       
   192 	TInt iParaElementOffset;		// position from start of paragraph
       
   193 	TInt iParaBasePhraseElement;	// index of the first phrase in the paragraph
       
   194 	TInt iPhraseElement;
       
   195 	TInt iPhraseElementOffset;
       
   196 	};
       
   197 
       
   198 
       
   199 
       
   200 NONSHARABLE_CLASS(CParaAttribs) : public CBase
       
   201 /**
       
   202 Describes the attributes that apply to the paragraph.
       
   203 *owns* an iParaFormat(Layer), and *owns* an iPhraseAttribsIndex
       
   204 or charFormatLayer.
       
   205 @internalComponent
       
   206 */
       
   207 	{
       
   208 public:
       
   209 	enum TParaRefCount {EPrimeNonSharedCount, EPrimeSharedCount};
       
   210 	enum {EPhraseIxGranularity = 1};
       
   211 public:
       
   212 	// Create a CParaAttribs with constant character formatting.
       
   213 	static CParaAttribs* NewL(const CParaFormatLayer* aParaLayer, const CCharFormatLayer* aCharLayer);
       
   214 	// Create a CParaAttribs with specific character formatting.
       
   215 	static CParaAttribs* NewL(const CParaFormatLayer* aParaLayer);
       
   216 	static CParaAttribs* NewL(const CParaAttribs* aParaAttribs);
       
   217 	void Release();
       
   218 	void Release(TInt aCount);
       
   219 	//
       
   220 	// Utility functions
       
   221 	inline TBool IsShared() const;
       
   222 	TInt PhraseCount() const;
       
   223 protected:
       
   224 	CParaAttribs();
       
   225 	~CParaAttribs();
       
   226 	CParaAttribs* CopyParaFormatL();
       
   227 private:
       
   228 public:
       
   229 	TDblQueLink link;
       
   230 	TInt iRefCount;  // Indicates re-use of this.
       
   231 	CParaFormatLayer* iParaFormat;
       
   232 	union
       
   233 		{
       
   234 		CCharFormatLayer* iCharFormat;	// iRefCount>0 - a single shared phrase - constant char format.
       
   235 		TInt iPhraseCount;	// iRefCount==0 - the number of phrases in this para.
       
   236 		};
       
   237 	};
       
   238 
       
   239 
       
   240 //
       
   241 
       
   242 class TRtPasteContext
       
   243 /**
       
   244 Provides the context for pasting of pictures from a clipboard.
       
   245 @internalComponent
       
   246 */
       
   247 	{
       
   248 public:
       
   249 	TRtPasteContext(const CStreamStore* aStore, const CParaFormatLayer* aGlobalParaLayer, const CCharFormatLayer* aGlobalCharLayer, const CStyleList* aStyleList);
       
   250 public:
       
   251 	const CStreamStore* iStore;  // the clipboard store
       
   252 	const CParaFormatLayer* iGlobalParaLayer;  // the global para layer of the target text document
       
   253 	const CCharFormatLayer* iGlobalCharLayer;  // the global char layer of the target text document
       
   254 	const CStyleList* iStyleList;  // style list is present
       
   255 	TBool iParagraphStylesFlag;  // ETrue indicates presence of inline style references in index data
       
   256 	TBool iIncompleteParaFlag;  // ETrue indicates the pasted text fragment has no final para delimiter
       
   257 	TBool iApplyFormatToLastFlag;  // ETrue indicates that para format should be applied to last text fragment
       
   258 	TLogicalPosition iPastePos;  // the character position at which the text is to be pasted
       
   259 	TInt iParasPasted;  // the number of paragraphs successfully pasted
       
   260 	TInt iStylePasteMode;
       
   261 	};
       
   262 
       
   263 
       
   264 
       
   265 class TIndexDeleteInfo
       
   266 /**
       
   267 Contains information pertaining to an index delete operation.
       
   268 Carries between a SetForDeleteL and a DeleteNow method call.
       
   269 @internalComponent
       
   270 */
       
   271 	{
       
   272 public:
       
   273 	enum TDeleteType
       
   274 		{
       
   275 		EDeleteFromParagraph,
       
   276 		EDeleteParagraph,
       
   277 		ENonspecificDelete
       
   278 		};
       
   279 public:
       
   280 	TInt iStartPara;
       
   281 	TInt iEndPara;
       
   282 	TLogicalPosition iDeletePos;
       
   283 	TInt iDeleteLength;
       
   284 	TDeleteType iDeleteType;
       
   285 	};
       
   286 
       
   287 
       
   288 class TRichTextMapEntry
       
   289 /**
       
   290 A utility class for patching references to persisted shared objects
       
   291 of the specified type.
       
   292 Code at the bottom of the header
       
   293 @internalComponent
       
   294 */
       
   295 	{
       
   296 public:
       
   297 	TRichTextMapEntry(TInt aRefNumber, TAny* aItem);
       
   298 	TRichTextMapEntry(TAny* aS, TAny* aT);
       
   299 public:
       
   300 	union
       
   301 		{// The source item - a reference to a persistent one, or the in-memory original.
       
   302 		TInt iRefNumber;
       
   303 		TAny* iS;  // only used in appending one rich text to another
       
   304 		};
       
   305 	TAny* iT;  // the newly created/restored item - the target
       
   306 	};
       
   307 
       
   308 
       
   309 template <class T>
       
   310 class CRichTextStoreMap : public CBase
       
   311 /**
       
   312 //
       
   313 A utility class for patching references to persisted shared objects
       
   314 of the specified type.
       
   315 Code at the bottom of the header
       
   316 Used for clipboarding to i) patch references to paragraph styles
       
   317 ii) patch references to shared paragraph formats
       
   318 and also used in the appending of one rich text to another.
       
   319 @internalComponent
       
   320 */
       
   321 	{
       
   322 public:
       
   323 	static CRichTextStoreMap* NewLC(TInt aMaximumCapacity);
       
   324 	~CRichTextStoreMap();
       
   325 	//
       
   326 	void Bind(TInt aRefNumber, T* aItem);
       
   327 	void Bind(T* aS, T* aT);
       
   328 	//
       
   329 	T* Item(TInt aRefNo)const;
       
   330 	T* Item(const T* aS)const;
       
   331 	inline const TRichTextMapEntry& At(TInt aIndex)const;
       
   332 	//
       
   333 	inline TInt Count()const;
       
   334 	//
       
   335 	void __DbgTestInvariant()const;
       
   336 private:
       
   337 	void ConstructL(TInt aMaximumCapacity);
       
   338 private:
       
   339 	CArrayFixFlat<TRichTextMapEntry>* iMap;
       
   340 public:
       
   341 	TInt iCapacity;
       
   342 	};
       
   343 
       
   344 
       
   345 class TGlobalLayerInfoAppend
       
   346 /**
       
   347 @internalComponent
       
   348 */
       
   349 	{
       
   350 public:
       
   351 	TGlobalLayerInfoAppend();
       
   352 	TGlobalLayerInfoAppend(const CParaFormatLayer* aAggParaFormatLayer, const CCharFormatLayer* aAggCharFormatLayer,
       
   353 						   const CParaFormatLayer* aComParaFormatLayer, const CCharFormatLayer* aComCharFormatLayer);
       
   354 public:
       
   355 	const CParaFormatLayer* iAggParaFormatLayer;
       
   356 	const CCharFormatLayer* iAggCharFormatLayer;
       
   357 	const CParaFormatLayer* iComParaFormatLayer;
       
   358 	const CCharFormatLayer* iComCharFormatLayer;
       
   359 	};
       
   360 
       
   361 const TInt KSingleParaGranularity = 1;
       
   362 const TInt KMultiParaGranularity = 16;
       
   363 const TInt KSmallPhraseGranularity = 5;
       
   364 const TInt KLargePhraseGranularity = 16;
       
   365 const TUint32 KPhraseSplit = 0x01;
       
   366 const TUint32 KSpecificMarkupInternalized = 0x04;
       
   367 
       
   368 /**
       
   369 @internalComponent
       
   370 */
       
   371 typedef CRichTextStoreMap<CParagraphStyle> CStyleMap;
       
   372 typedef CRichTextStoreMap<CParaAttribs> CParaAttribsMap;
       
   373 
       
   374 /** Stores the paragraph and character formatting information for CRichText.
       
   375 
       
   376 iParaIx stores the paragraph formatting, one entry per paragraph. Paragraphs
       
   377 are pieces of text delimited by the Unicode Paragraph Delimiter character
       
   378 U+2029.
       
   379 
       
   380 iPhraseIx stores the character formatting.
       
   381 
       
   382 Paragraph formatting information can be shared or not shared between
       
   383 paragraphs. Sharing is only permitted for paragraphs that do not have any
       
   384 character formatting applied to their text.
       
   385 
       
   386 A phrase is a run of consistently formatted characters. A phrase may only
       
   387 contain a paragraph delimiter in its last character. In other words, phrases
       
   388 are not permitted to span paragraph boundaries.
       
   389 
       
   390 iPhraseIx only stores formatting for the non-shared paragraphs. Therefore
       
   391 adding up the lengths of all the phrases in iPhraseIx will yield the sum of the
       
   392 non-shared paragraphs stored in iParaIx.
       
   393 
       
   394 Note that the "nominal" paragraph delimiter at the end of the text which is not
       
   395 stored by CRichText is covered by both character and paragraph formatting. So
       
   396 the length of the final paragraph and final phrase (if appropriate) includes
       
   397 this character.
       
   398 
       
   399 @internalComponent
       
   400 */
       
   401 class CRichTextIndex : public CBase
       
   402 	{
       
   403 public:
       
   404 	static CRichTextIndex* NewL(const CParaFormatLayer* aGlobalParaLayer, const CCharFormatLayer* aGlobalCharLayer,
       
   405 								const CRichText& aText,
       
   406 								TInt aParaGran,TInt aPhraseGran);
       
   407 	static CRichTextIndex* NewL(const CStreamStore& aStore, TStreamId aId,
       
   408 								const CParaFormatLayer* aGlobalParaLayer,
       
   409 								const CCharFormatLayer* aGlobalCharLayer,
       
   410 								const CRichText& aText);
       
   411 	~CRichTextIndex();
       
   412 	//
       
   413 	// Store/Restore functions - Deferred loading of pictures
       
   414 	TStreamId StoreMarkupL(CStreamStore& aStore, const CStyleList* aStyleList) const;
       
   415 	//
       
   416 	void RestoreL(const CStreamStore& aStore, TStreamId aId,
       
   417 				  const CParaFormatLayer* aGlobalParaLayer, const CCharFormatLayer* aGlobalCharLayer,
       
   418 				  const CStyleList* aStyleList);
       
   419 	//
       
   420 	void StorePicturesL(CStreamStore& aStore, CStoreMap& aMap) const;
       
   421 	void StorePicturesL(CStreamStore& aStore, CStoreMap& aMap, TInt aPos, TInt aLength) const;
       
   422 	void DetachFromStoreL(CPicture::TDetach aDegree, TInt aPos, TInt aLength);
       
   423 	void ExternalizeL(RWriteStream& aStream) const;
       
   424 	void InternalizeL(RReadStream& aStream, const CParaFormatLayer* aGlobalParaLayer, const CCharFormatLayer* aGlobalCharLayer,
       
   425 					  const CStyleList* aStyleList);
       
   426 	//
       
   427 	// 3n Persist functions
       
   428 	TBool HasMarkupData(const CFormatLayer* aGlobalParaFormatLayer) const;
       
   429 	TPictureHeader PictureHeader(TInt aPos) const;
       
   430 	TPictureHeader* PictureHeaderPtr(TInt aPos);
       
   431 	//
       
   432 	// Undo/CutPaste
       
   433 	void CopyToStreamL(RWriteStream& aStream, TInt aPos, TInt aLength, TBool aCopyStyles) const;
       
   434 	void PasteFromStreamL(const CStreamStore& aStore, RReadStream& aStream, TInt aPos, CParagraphStyle::TStylePasteMode aStylePasteMode, const CParaFormatLayer* aGlobalParaLayer, const CCharFormatLayer* aGlobalCharLayer);
       
   435 	//
       
   436 	// Content modifier functions
       
   437 	void Reset(const CParaFormatLayer& aNormalParagraphStyle);
       
   438 	void InsertL(TInt aPos, const TDesC& aBuf, const CParaFormatLayer& aGlobalParaFormatLayer);
       
   439 	void InsertL(TInt aPos, const TPictureHeader& aPicHdr, TBool& aPictureOwnershipTaken);
       
   440 	void SetForDeleteL(TIndexDeleteInfo& aInfo, TInt aPos, TInt aLength);
       
   441 	TBool DeleteNow(TIndexDeleteInfo& aInfo);
       
   442 	void DeleteFromParagraph(TInt aPos, TInt aLength);
       
   443 	TBool DeleteParagraph(TInt aPos, TInt aLength);
       
   444 	void Normalize(TInt aPos);
       
   445 	//
       
   446 	// Insert a new paragraph at position aPos, based on the 'Normal' global defaults.
       
   447 	// Any explicit paragraph/character formatting is carried forward into this paragraph.
       
   448 	void InsertParagraphL(TInt aPos, const CParaFormatLayer& aGlobalParaFormatLayer);
       
   449 	//
       
   450 	// Special behaviour format modifier functions.
       
   451 	TBool InsertCharFormatIsActive();
       
   452 	void SetInsertCharFormatL(const TCharFormatX& aFormat, const TCharFormatXMask& aMask, TInt aPos);
       
   453 	void NewInsertCharFormatL(const TCharFormatX& aFormat,
       
   454 		const TCharFormatXMask& aMask, TInt aPos);
       
   455 	void UpdateInsertCharFormatL(const TCharFormatX& aFormat,
       
   456 		const TCharFormatXMask& aMask);
       
   457 	CCharFormatLayer* GetCurrentInsertCharFormat();
       
   458 	void CancelInsertCharFormat();
       
   459 	TBool DelSetInsertCharFormatL(TInt aPos, TInt aLength);
       
   460 	//
       
   461 	// Laydoc interface support
       
   462 	void GetParagraphFormatL(CParaFormat* aFormat,TInt aPos) const;
       
   463 	TInt GetChars(TCharFormatX& aFormat,TInt aPos) const;
       
   464 	TInt GetPictureSizeInTwips(TSize& aSize, TInt aPos) const;
       
   465 	CPicture* PictureHandleL(TInt aPos, MLayDoc::TForcePictureLoad aForceLoad) const;
       
   466 	//
       
   467 	// FormatText interface support
       
   468 	void GetParaFormatL(CParaFormat* aFormat, TParaFormatMask& aUndeterminedMask, TInt aPos, TInt aLength,
       
   469 						CParaFormat::TParaFormatGetMode aMode) const;
       
   470 	void ApplyParaFormatL(const CParaFormat* aFormat, const TParaFormatMask& aMask, TInt aPos, TInt aLength);
       
   471 	void GetCharFormat(TCharFormatX& aFormat, TCharFormatXMask& aMask,TInt aPos, TInt aLength) const;
       
   472 	void ApplyCharFormatL(const TCharFormatX& aFormat, const TCharFormatXMask& aMask, TInt aPos, TInt aLength, TBool aRemoveSpecific = EFalse);
       
   473 	void RemoveSpecificCharFormatL(TInt aPos, TInt aLength);
       
   474 	void RemoveSpecificParaFormatL(TInt aPos, TInt aLength);
       
   475 	//
       
   476 	//
       
   477 	void GetSpecificCharFormat(TCharFormatX& aFormat, TCharFormatXMask& aMask, TInt aPos) const;
       
   478 	void GetSpecificCharFormatDirection(TCharFormatX& aFormat, TCharFormatXMask& aMask,
       
   479 		TInt aPos, TBool aGetLeft) const;
       
   480 	//
       
   481 	// Paragraph style implementation
       
   482 	void ApplyParagraphStyleL(const CParagraphStyle& aStyle, TInt aPos, TInt aLength, const CCharFormatLayer* aCharStyleNormal, CParagraphStyle::TApplyParaStyleMode aMode);
       
   483 	void NotifyStyleChangedL(const CParagraphStyle* aTo, const CParagraphStyle* aFrom, const CParaFormatLayer& aGlobalParaFormatLayer, const CCharFormatLayer& aGlobalCharFormatLayer);
       
   484 	const CParaFormatLayer* ParagraphStyle(TBool& aStylesChangesOverRange, TInt aPos, TInt aLength) const;
       
   485 	//
       
   486 	// Utility functions
       
   487 	inline TInt ParagraphCount() const;
       
   488 	TInt CharPosOfParagraph(TInt& aLength, TInt aParaOffset) const;
       
   489 	TInt ParagraphNumberForPos(TInt& aPos) const;
       
   490 	inline void SetSpecificMarkupInternalized(TBool aBool);
       
   491 	inline TBool SpecificMarkupInternalized() const;
       
   492 	void DocumentChanged()const;
       
   493 	//
       
   494 	// Speciality functions
       
   495 	void AppendTakingSolePictureOwnershipL(const CRichTextIndex* aSource, const TGlobalLayerInfoAppend& aGlobalLayerInfo);
       
   496 	void AppendParagraphL(const CParaFormatLayer* aGlobalParaFormatLayer, const CCharFormatLayer* aGlobalCharFormatLayer,
       
   497 						  TInt aReplicas);
       
   498 	TInt SharedParaCount(const CRichTextIndex* aSource) const;
       
   499 	void GetSpecificParagraphFormatL(CParaFormat* aFormat,
       
   500 									 TParaFormatMask& aMask,
       
   501 									 TInt aPos) const;
       
   502 private:
       
   503 	enum TScanToPositionMode {EScanToPositionMatchLeft, EScanToPositionAbsolute};
       
   504 	enum {EInsertCharFormatReset = -1};
       
   505 	enum TPositionOrPhrase 	{EPositionOnly, EFollowingPhrase};
       
   506 private:
       
   507 	CRichTextIndex(const CRichText& aText);
       
   508 	void ConstructL(const CParaFormatLayer* aGlobalParaFormat, const CCharFormatLayer* aGlobalCharFormat, TInt aParaGran, TInt aPhraseGran);
       
   509 	//
       
   510 	// Persistence/Copy,Paste
       
   511 	void InternalizeRtiHeaderL(RReadStream& aStream, TRtPasteContext& aContext);
       
   512 	void ExternalizeRtiHeaderL(RWriteStream& aStream, const TLogicalPosition& aEnd, const CStyleList* aStyleList) const;
       
   513 	void ExternalizeReferencedStylesL(RWriteStream& aStream, const TLogicalPosition& aStart, const TLogicalPosition& aEnd) const;
       
   514 	void InternalizeSharedFormatsL(RReadStream& aStream, const TRtPasteContext& aContext);
       
   515 	void ExternalizeSharedFormatsL(RWriteStream& aStream, const TLogicalPosition& aStart, const TLogicalPosition& aEnd, const CStyleList* aStyleList) const;
       
   516 	void InternalizeParaIxL(RReadStream& aStream, const TRtPasteContext& aContext);
       
   517 	void ExternalizeParagraphFormatL(RWriteStream& aStream, const CParaFormatLayer& aSpecificParaFormatLayer, const CStyleList* aStyleList) const;
       
   518 	CParaFormatLayer* InternalizeParagraphFormatL(RReadStream& aStream, const TRtPasteContext& aContext);
       
   519 	CParaFormatLayer* PasteParagraphFormatL(RReadStream& aStream, const TRtPasteContext& aContext, CStyleMap* styleMap);
       
   520 	RPhraseAttribsEntry* ExternalizeParaIxL(RWriteStream& aStream, const TLogicalPosition& aStart,
       
   521 					const TLogicalPosition& aEnd, const CStyleList* aStyleList) const;
       
   522 	void InternalizePhraseIxL(RReadStream& aStream, const CCharFormatLayer* aGlobalCharFormat);
       
   523 	void ExternalizePhraseIxL(RWriteStream& aStream) const;
       
   524 	void ExternalizePhraseIxL(RWriteStream& aStream,
       
   525 							  const TLogicalPosition& aStartPos,
       
   526 							  TLogicalPosition& aEndPos,
       
   527 							  const RPhraseAttribsEntry* aVirtualTrailingText) const;
       
   528 	inline void ExternalizePhraseCountL(RWriteStream& aStream, TInt aPhraseCount) const;
       
   529 	void ExternalizePhrasesL(RWriteStream& aStream, TInt aStart, TInt aPhraseCount, const RPhraseAttribsEntry* aVirtualPhrase = NULL) const;
       
   530 	TInt MarkStyleRegister(TDes8& aBuf, TInt aStartPara, TInt aEndPara) const;
       
   531 	TInt MarkRegister(TDes8& aBuf, TInt aStartPara, TInt aEndPara) const;
       
   532 	void GenerateAllPhraseLinksL();
       
   533 	void GeneratePhraseLink(CCharFormatLayer* aPhraseCharFormatLayer, const CParaFormatLayer* aBase);
       
   534 	void ExternalizeItemsPresentInStyleRegisterL(RWriteStream& aStream, TInt aRefStyleCount, const TDes8& aBuf) const;
       
   535 	void ExternalizeItemsPresentInRegisterL(RWriteStream& aStream, TInt aParaCount, const TDes8& aBuf, const CStyleList* aStyleList) const;
       
   536 	CParaAttribs* SharedParaAttribs(TUint8 aOrdinal);
       
   537 	TUint8 RefNum(const CParaAttribs* aParaAttribs) const;
       
   538 	//
       
   539 	// Copy,Paste
       
   540 	void PasteStylesL(RReadStream& aStream, CStyleMap& aMap, const TRtPasteContext& aContext);
       
   541 	void PasteSharedFormatsL(RReadStream& aStream, CParaAttribsMap& aMap, const TRtPasteContext& aContext, CStyleMap* aStyleMap);
       
   542 	void ImposeCharacterStyleL(CCharFormatLayer** aCharLayer);
       
   543 	void PasteIxL(RReadStream& aStream, TRtPasteContext& aContext, const CParaAttribsMap& aMap, CStyleMap* aStyleMap/*,CParaAttribs* aSecondReserved*/);
       
   544 	TInt PasteParaIxL(RReadStream& aStream, TRtPasteContext& aContext, TInt aCompleteParaCount, const CParaAttribsMap& aMap, RPhraseAttribsEntry*& aFirstParaVirtualPhrase, CStyleMap* aStyleMap);
       
   545 	TParaAttribsEntry DoPasteIntoParaL(RReadStream& aStream, const CParaAttribsMap& aMap, const TRtPasteContext& aContext, CStyleMap* aStyleMap);
       
   546 	TParaAttribsEntry DoPasteFirstIntoParaL(RReadStream& aStream, const CParaAttribsMap& aMap, const TRtPasteContext& aContext, RPhraseAttribsEntry*& aFirstParaVirtualPhrase, CStyleMap* aStyleMap);
       
   547 	void DoPasteCleanup(TLogicalPosition& aNormalizePos, CParaAttribs* aReclaimed);
       
   548 	TTextFragment GetTextFragmentL(RReadStream& aStream);
       
   549 	void PastePhraseIxL(RReadStream& aStream, TRtPasteContext& aContext, const RPhraseAttribsEntry* aFirstParaVirtualPhrase);
       
   550 	void DoPastePhraseL(RReadStream& aStream, const TRtPasteContext& aContext, RPhraseAttribsEntry& aPhrase);
       
   551 	void RbPasteSharedFormatsL(TInt aRet);
       
   552 	void NormalizeSharedList();
       
   553 	void RbRemoveInsertedParaAttribsEntries(TInt aFirstParaInsertPos, TInt aInsertedParaCount);
       
   554 	void RbPasteParaIxL(const TLogicalPosition& aPastePos, TInt aParaCount, TInt aRet);
       
   555 	void RbPastePhraseIxL(const TLogicalPosition& aPos,TInt aPhraseCount, TInt aRet);
       
   556 	void RbRemoveInsertedPhraseAttribsEntries(TInt aFirstPhraseInsertPos, TInt aInsertedPhraseCount);
       
   557 	TUint8 ReadTUint8CountL(RReadStream& aStream) const;
       
   558 	//
       
   559 	// General utility
       
   560 	void DoSoloInsertL(TInt aPos, TInt aLength);
       
   561 	void ScanToPosition(TInt aCharPos, TScanToPositionMode aMode, TLogicalPosition* aLastUsed=NULL);  // Reset the logical position to the passed document position.
       
   562 	inline TInt PhraseCount() const;
       
   563 	TBool FirstPhraseOfParagraph() const;  // Interrogates current iPos record.
       
   564 	TInt CurrentPhraseLength() const;  // Encapsulates constant/specific character formatting.
       
   565 	TInt CurrentPhraseOffset() const;  // Encapsulates constant/specific character formatting.
       
   566 	void CheckForUndetermined(const TCharFormatX& aFormatA, const TCharFormatX& aFormatB, TCharFormatXMask& aVaries) const;
       
   567 	void GetCurrentRecords(TCurrentIndexRecords& aRecord) const;
       
   568 	void GetPhraseFormat(TCurrentIndexRecords& aCurrent, TCharFormatX& aFormat, TCharFormatXMask& aMask, CCharFormatLayer*& aCharBase) const;
       
   569 	TInt OwningParagraph(TInt aPos, TLogicalPosition* aLastUsed = NULL) const;
       
   570 	TBool MergePhrases(TInt aPos);
       
   571 	TBool MergePhrases(const TLogicalPosition& aPos);
       
   572 	TBool DeleteInsertCharFormat();
       
   573 	void ConsolidateAt(TInt aPosition, TPositionOrPhrase aPositionOrPhrase);
       
   574 	void RemoveFromPhraseIx(TInt aPos, TInt aCount = 1);
       
   575 	void SplitPhraseL(TInt aSplitPos);
       
   576 	void SplitPhraseL(TInt aPhraseElement, TInt aPhraseOffset, CParaAttribs* aParaAttribs);
       
   577 	void DoSplitPhraseL(RPhraseAttribsEntry& aCurrentPhrase, TInt aPhraseOffset, CParaAttribs* aParaAttribs);
       
   578 	TUint8 SharedParaAttribsEntryCountL() const;
       
   579 	void ModifySpecificFormatting(CParaFormatLayer& aPl, CCharFormatLayer& aCl, CParagraphStyle::TApplyParaStyleMode aMode);
       
   580 //
       
   581 // support for applycharformat
       
   582 	static void ApplyCharFormatCleanup(TAny* aPtr);
       
   583 	void ApplyCharFormatRollback();
       
   584 	TInt MergePhrases(TInt aPhrase, RPhraseAttribsEntry& aPhraseAttribs, CParaAttribs& aParaAttribs);
       
   585 	void SplitPhraseL(TInt aPhrase, TInt anOffset, RPhraseAttribsEntry& aPhraseAttribs, CParaAttribs& aParaAttribs);
       
   586 	void Share(TParaAttribsEntry& aParaEntry, TInt aPhrase);
       
   587 	//
       
   588 	// Specific rollback
       
   589 	void RbInsertPicture(CParaAttribs* aGoodParaAttribs);
       
   590 	//
       
   591 	// General implementation
       
   592 	void NormalizeNow(const TLogicalPosition& aNormalizePos);
       
   593 	TBool DeleteParagraphText(TInt& aLength);
       
   594 	TBool DoDeleteFromParagraph(const TIndexDeleteInfo& aInfo);
       
   595 	void TidyAfterDelete(const TIndexDeleteInfo& aInfo);
       
   596 	CParaAttribs* ReserveCellL();
       
   597 	CParaAttribs* ReserveCellLC();
       
   598 	void DoNewInsertCharFormatL(const TCharFormatX& aFormat,
       
   599 		const TCharFormatXMask& aMask, CCharFormatLayer* aBasedOn,
       
   600 		CParaAttribs* aParaAttribs);
       
   601 	TInt ParaLengthFromBuffer(TDesC& aBuf) const;
       
   602 	inline const CStreamStore* ResolvedStreamStore(TInt aPos) const;
       
   603 	//
       
   604 	// Agenda functions
       
   605 	void AppendSharedFormatsL(CParaAttribsMap& aMap, const CRichTextIndex* aSource, const TGlobalLayerInfoAppend& aGlobalLayerInfo);
       
   606 	void AppendParaIndexL(const CRichTextIndex* aSource, const TGlobalLayerInfoAppend& aGlobalLayerInfo);
       
   607 	void AppendPhraseIndexL(const CRichTextIndex* aSource, const TGlobalLayerInfoAppend& aGlobalLayerInfo);
       
   608 	//
       
   609 	// Shared list management utilities
       
   610 	CParaAttribs* RequestReclaimShareL(CParaAttribs* aParaAttribs, TParaAttribsEntry* aParaEntry);
       
   611 	CParaAttribs* RequestShareL(CParaAttribs* aParaAttribs, CCharFormatLayer* aCharFormat = NULL, CParaAttribs* aReservedCell = NULL);
       
   612 	CParaAttribs* GetParaAttribsL(const CParaFormatLayer* aParaFormat, const CCharFormatLayer* aCharFormat, CParaAttribs* aReservedCell = NULL);
       
   613 	CParaAttribs* RequestShare(const TLogicalPosition& aLogicalPosition);
       
   614 	CParaAttribs* GetParaAttribs(const TLogicalPosition& aLogicalPosition);
       
   615 	CParaAttribs* GetParaAttribs(CParaAttribs* aParaAttribs, CCharFormatLayer& aCharFormatLayer);
       
   616 	CParaAttribs* FindSharedParaAttribs(const CParaFormatLayer& aParaFormatLayer, const CCharFormatLayer& aCharFormatLayer);
       
   617 	void RebalanceIndex();
       
   618 	void SplitParagraphAtPastePosL(TLogicalPosition& aPastePos, TLogicalPosition& aNewPos,
       
   619 								   const CParaFormatLayer& aGlobalParaFormatLayer);
       
   620 	//
       
   621 	inline void SetPhraseSplit(TBool aBool);
       
   622 	inline TBool PhraseSplit() const;
       
   623 private:
       
   624 	const CRichText& iText;  // backward reference to owning rich text.
       
   625 	TUint32 iFlags;
       
   626 	TInt iPendingNewPhrasePos;  // When *INSERTSTATE* is active, this is used to place the zero-length phrase.
       
   627 	CParaAttribs* iRollbackParaAttribsHandle;
       
   628 	__MUTABLE TDblQue<CParaAttribs> iSharedParaQueHead;
       
   629 	__MUTABLE TLogicalPosition iLastUsed;
       
   630 	CCharFormatLayer* iLastCharacterStyle;
       
   631 public:
       
   632 	CArrayFixSeg<TParaAttribsEntry>* iParaIx;  // One entry per paragraph
       
   633 	CArrayFixSeg<RPhraseAttribsEntry>* iPhraseIx;  // One entry per phrase in the rich text
       
   634 	__MUTABLE TLogicalPosition iPos;
       
   635 	TInt iPictureCount;  // a count of the number of pictures contained by this text
       
   636 
       
   637 	__DECLARE_TEST;
       
   638 	};
       
   639 
       
   640 ////////////////////////////////////////
       
   641 
       
   642 template <class T>
       
   643 void CRichTextStoreMap<T>::__DbgTestInvariant() const
       
   644 // Provides class invariants.  Explanations below:
       
   645 //
       
   646 	{
       
   647 #ifdef _DEBUG
       
   648 	TInt count = Count();
       
   649 	for (TInt ii = 0; ii < count; ii++)
       
   650 		{
       
   651 		TInt ref = (*iMap)[ii].iRefNumber;
       
   652 		__ASSERT_DEBUG(ref > 0, User::Invariant());
       
   653 		}
       
   654 #endif
       
   655 	}
       
   656 
       
   657 
       
   658 template <class T>
       
   659 CRichTextStoreMap<T>* CRichTextStoreMap<T>::NewLC(TInt aMaximumCapacity)
       
   660 // Return a handle to a new instance of this class.
       
   661 //
       
   662 	{
       
   663 	CRichTextStoreMap* self = new(ELeave) CRichTextStoreMap();
       
   664 	CleanupStack::PushL(self);
       
   665 	self->ConstructL(aMaximumCapacity);
       
   666 	return self;
       
   667 	}
       
   668 
       
   669 
       
   670 
       
   671 template <class T>
       
   672 void CRichTextStoreMap<T>::ConstructL(TInt aMaximumCapacity)
       
   673 //
       
   674 //
       
   675 	{
       
   676 	if (aMaximumCapacity > 0)
       
   677 		{
       
   678 		iMap = new(ELeave) CArrayFixFlat<TRichTextMapEntry>(aMaximumCapacity);
       
   679 		iMap->SetReserveL(aMaximumCapacity);	// never need to allocate memory
       
   680 		}
       
   681 	iCapacity = aMaximumCapacity;
       
   682 	}
       
   683 
       
   684 
       
   685 template <class T>
       
   686 CRichTextStoreMap<T>::~CRichTextStoreMap()
       
   687 //
       
   688 //
       
   689 	{delete iMap;}
       
   690 
       
   691 
       
   692 template <class T>
       
   693 void CRichTextStoreMap<T>::Bind(TInt aRef, T* aT)
       
   694 //
       
   695 //
       
   696 	{
       
   697 	__TEST_INVARIANT;
       
   698 	__ASSERT_ALWAYS(Count() <= iCapacity, Panic(ESharedFormatsMapOverFlow));
       
   699 
       
   700 	TRichTextMapEntry entry(aRef, aT);
       
   701 	iMap->AppendL(entry);  // will not fail: we have reserved the space
       
   702 
       
   703 	__TEST_INVARIANT;
       
   704 	}
       
   705 
       
   706 
       
   707 
       
   708 template <class T>
       
   709 void CRichTextStoreMap<T>::Bind(T* aS, T* aT)
       
   710 //
       
   711 //
       
   712 	{
       
   713 	__TEST_INVARIANT;
       
   714 	__ASSERT_ALWAYS(Count() <= iCapacity, Panic(ESharedFormatsMapOverFlow));
       
   715 
       
   716 	TRichTextMapEntry entry(aS, aT);
       
   717 	iMap->AppendL(entry);  // will not fail: we have reserved the space
       
   718 
       
   719 	__TEST_INVARIANT;
       
   720 	}
       
   721 
       
   722 
       
   723 template <class T>
       
   724 T* CRichTextStoreMap<T>::Item(TInt aRef) const
       
   725 //
       
   726 //
       
   727 	{
       
   728 	TInt count = Count();
       
   729 	if (count > 0)
       
   730 		{
       
   731 		const TRichTextMapEntry* entry = &(*iMap)[0];
       
   732 		for (const TRichTextMapEntry* end = entry + count; entry < end; entry++)
       
   733 			{
       
   734 			if (entry->iRefNumber == aRef)
       
   735 				return (T*)entry->iT;
       
   736 			}
       
   737 		}
       
   738 	return NULL;
       
   739 	}
       
   740 
       
   741 
       
   742 template <class T>
       
   743 T* CRichTextStoreMap<T>::Item(const T* aS) const
       
   744 //
       
   745 //
       
   746 	{
       
   747 	TInt count = Count();
       
   748 	if (count > 0)
       
   749 		{
       
   750 		const TRichTextMapEntry* entry = &(*iMap)[0];
       
   751 		for (const TRichTextMapEntry* end = entry + count; entry < end; entry++)
       
   752 			{
       
   753 			if (entry->iS == (TAny*)aS)
       
   754 				return (T*)entry->iT;
       
   755 			}
       
   756 		}
       
   757 	return NULL;
       
   758 	}
       
   759 
       
   760 
       
   761 #include "TXTINDEX.INL"
       
   762 
       
   763 
       
   764 #endif