textrendering/texthandling/stext/TXTSTYLE.CPP
changeset 0 1fb32624e06b
child 40 91ef7621b7fc
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 #include <e32std.h>
       
    20 #include <e32base.h>
       
    21 #include <s32strm.h>
       
    22 
       
    23 #include "TXTSTYLE.H"
       
    24 #include "TXTFRMAT.H"
       
    25 #include "TXTSTD.H"
       
    26 
       
    27 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    28 #include "TXTFMLYR_INTERNAL.H"
       
    29 #include "TXTSTYLE_INTERNAL.H"
       
    30 #endif
       
    31 
       
    32 // Return the handle of a new paragraph style
       
    33  
       
    34 
       
    35 EXPORT_C CParagraphStyle* CParagraphStyle::NewL(const CParaFormatLayer& aGlobalParaFormatLayer,
       
    36 												const CCharFormatLayer& aGlobalCharFormatLayer)
       
    37 /** Allocates and constructs a CParagraphStyle object whose formatting is based 
       
    38 on a global paragraph and character format layer. The type UID is initialised 
       
    39 to KUserDefinedParagraphStyleUid. The outline level is not initialised.
       
    40 
       
    41 @param aGlobalParaFormatLayer The paragraph format layer on which the style's 
       
    42 paragraph formatting is based. 
       
    43 @param aGlobalCharFormatLayer The character format layer on which the style's 
       
    44 character formatting is based. 
       
    45 @return Pointer to the new CParagraphStyle object. */
       
    46 	{
       
    47 	CParagraphStyle* self=new(ELeave) CParagraphStyle();
       
    48 	CleanupStack::PushL(self);
       
    49 	self->ConstructL(aGlobalParaFormatLayer,aGlobalCharFormatLayer);
       
    50 	CleanupStack::Pop();
       
    51 	return self;
       
    52 	}
       
    53 
       
    54 
       
    55 CParagraphStyle::CParagraphStyle():
       
    56 	iType(KUserDefinedParagraphStyleUid)
       
    57 	{
       
    58 	}
       
    59 
       
    60 
       
    61 // Create style and base it on the specified 'Normal' layers
       
    62 void CParagraphStyle::ConstructL(const CParaFormatLayer& aGlobalParaFormatLayer,
       
    63 										  const CCharFormatLayer& aGlobalCharFormatLayer)
       
    64 	{
       
    65 	SetBase(&aGlobalParaFormatLayer);
       
    66 	//
       
    67 	// Force para format layer storage allocation with empty layer
       
    68 	TParaFormatMask paraMask;
       
    69 	SetL((CParaFormat*)NULL,paraMask);
       
    70 	//
       
    71 	// Force char format layer storage allocation with empty layer;
       
    72 /*	TCharFormat format;
       
    73 	TCharFormatMask mask;
       
    74 	iCharFormatLayer=CCharFormatLayer::NewL(format,mask);
       
    75 */
       
    76 	iCharFormatLayer=CCharFormatLayer::NewL();
       
    77 	iCharFormatLayer->SetBase(&aGlobalCharFormatLayer);
       
    78 	}
       
    79  
       
    80 
       
    81 EXPORT_C CParagraphStyle::~CParagraphStyle()
       
    82 /** The destructor frees all resources owned by the object, prior to its destruction. */
       
    83 	{
       
    84 	delete iCharFormatLayer;
       
    85 	}
       
    86 
       
    87 
       
    88 EXPORT_C CFormatLayer* CParagraphStyle::DoCloneL()const
       
    89 	{
       
    90 	const CCharFormatLayer* charLayer=STATIC_CAST(const CCharFormatLayer*,iCharFormatLayer->SenseBase());
       
    91 	CParagraphStyle* clone=CParagraphStyle::NewL(STATIC_CAST(const CParaFormatLayer&,*SenseBase()),*charLayer);
       
    92 	CleanupStack::PushL(clone);
       
    93 	CloneLayerL(clone);  // clones the paragraph format layer
       
    94 	delete clone->iCharFormatLayer;
       
    95 	clone->iCharFormatLayer=NULL;  // necessary precaution if next instruction leaves
       
    96 	clone->iCharFormatLayer=iCharFormatLayer->CloneL();  // clones the character format layer
       
    97 	clone->iCharFormatLayer->SetBase(charLayer);  // restore the based on link
       
    98 	CleanupStack::Pop();  // clone
       
    99 	//
       
   100 	clone->SetType(Type());
       
   101 	clone->SetOutlineLevel(OutlineLevel());
       
   102 	clone->iName=iName;
       
   103 	//
       
   104 	return clone;
       
   105 	}
       
   106 
       
   107 
       
   108  
       
   109 
       
   110 EXPORT_C TUid CParagraphStyle::Type()const
       
   111 /** Gets the style's type UID.
       
   112 
       
   113 @return The style's type UID. */
       
   114 	{return iType;}
       
   115 
       
   116 
       
   117 CParagraphStyle* CParagraphStyle::NewL(RReadStream& aStream,
       
   118 										const CParaFormatLayer& aGlobalParaFormatLayer,
       
   119 										const CCharFormatLayer& aGlobalCharFormatLayer)
       
   120 	{
       
   121 	CParagraphStyle* self=new(ELeave) CParagraphStyle();
       
   122 	CleanupStack::PushL(self);
       
   123 	self->ConstructL(aGlobalParaFormatLayer,aGlobalCharFormatLayer);
       
   124 	self->InternalizeL(aStream,&aGlobalParaFormatLayer,&aGlobalCharFormatLayer);
       
   125 	CleanupStack::Pop();
       
   126 	return self;
       
   127 	}
       
   128 
       
   129 
       
   130 // Load into this style from the specified readStream.  Base this style on the layer aBase - Default NULL
       
   131 void CParagraphStyle::InternalizeL(RReadStream& aStream,const CFormatLayer* aParaLayerBase,const CFormatLayer* aCharLayerBase)
       
   132 	{
       
   133 	aStream>> iName;
       
   134 	aStream>> iType;
       
   135 	iOutlineLevel=aStream.ReadInt32L();
       
   136 	iCharFormatLayer->InternalizeL(aStream,aCharLayerBase);
       
   137 	//
       
   138 	CParaFormatLayer::InternalizeL(aStream,aParaLayerBase);
       
   139 	}
       
   140 
       
   141 
       
   142 // Save the style in the specified WriteStream. The based on link is *NOT* stored.
       
   143 void CParagraphStyle::ExternalizeL(RWriteStream& aStream)const
       
   144 	{
       
   145 	aStream<< iName;
       
   146 	aStream<< iType;
       
   147 	aStream.WriteInt32L(iOutlineLevel);
       
   148 	aStream<< *iCharFormatLayer;
       
   149 	//
       
   150 	CParaFormatLayer::ExternalizeL(aStream);
       
   151 	}
       
   152 
       
   153 
       
   154 DLLEXPORT_C void CStyleList::__DbgTestInvariant()const
       
   155 // Provides class invariants.  Explanations below:
       
   156 //
       
   157 	{
       
   158 #ifdef _DEBUG
       
   159 	TInt styleCount=Count();
       
   160 	for (TInt nn=0;nn<styleCount;nn++)
       
   161 		{
       
   162 		RParagraphStyleInfo info=iList->At(nn);
       
   163 		if (info.iStyleForNextPara)
       
   164 			{
       
   165 			TInt index=IndexByPtr(info.iStyleForNextPara);
       
   166 			// ASSERT: The style-to-follow is present in the list.
       
   167 			__ASSERT_DEBUG(
       
   168 				(info.iStyleForNextPara==NULL) ||
       
   169 				((info.iStyleForNextPara) && (index!=KErrNotFound && index>=0 && index<styleCount)),User::Invariant());
       
   170 			}
       
   171 		}
       
   172 #endif
       
   173 	}
       
   174 
       
   175 
       
   176  
       
   177 
       
   178 EXPORT_C CStyleList* CStyleList::NewL(TInt aCapacity /*=KMaxStyleListGranularity*/)
       
   179 /** Allocates and constructs an empty CStyleList object with an array granularity.
       
   180 
       
   181 @param aCapacity The number of entries by which the array of styles expands 
       
   182 when its buffer is reallocated. By default, KMaxStyleListGranularity (= 4). 
       
   183 Must be positive or a panic occurs. 
       
   184 @return Pointer to the new style list. */
       
   185 	{
       
   186 	CStyleList* self=new(ELeave) CStyleList();
       
   187 	CleanupStack::PushL(self);
       
   188 	self->ConstructL(aCapacity);
       
   189 	CleanupStack::Pop();
       
   190 	return self;
       
   191 	}
       
   192 
       
   193 
       
   194 EXPORT_C CStyleList* CStyleList::NewL(RReadStream& aStream,
       
   195 									  const CParaFormatLayer* aGlobalParaFormatLayer,
       
   196 									  const CCharFormatLayer* aGlobalCharFormatLayer)
       
   197 /** Allocates and constructs a CStyleList, restoring its contents from the specified 
       
   198 stream store. Each style in the list is set to be based on the global format 
       
   199 layers specified.
       
   200 
       
   201 @param aStream Stream store from which the style list is restored. 
       
   202 @param aGlobalParaFormatLayer Pointer to the global paragraph format layer 
       
   203 on which all styles in the list are based. 
       
   204 @param aGlobalCharFormatLayer Pointer to the global character format layer 
       
   205 on which all styles in the list are based. 
       
   206 @return Pointer to the new style list. */
       
   207 	{
       
   208 	CStyleList* self=new(ELeave) CStyleList();
       
   209 	CleanupStack::PushL(self);
       
   210 	self->InternalizeL(aStream,aGlobalParaFormatLayer,aGlobalCharFormatLayer);
       
   211 	CleanupStack::Pop();
       
   212 	return self;
       
   213 	}
       
   214 
       
   215 
       
   216 EXPORT_C CStyleList::CStyleList()
       
   217 	{
       
   218 	}
       
   219 
       
   220 
       
   221 EXPORT_C void CStyleList::ConstructL(TInt aCount)
       
   222 // Allocate the style list.
       
   223 //
       
   224 	{
       
   225 	iList=new(ELeave) CArrayFixFlat<RParagraphStyleInfo>(aCount);
       
   226 	}
       
   227 
       
   228 
       
   229  
       
   230 
       
   231 EXPORT_C CStyleList::~CStyleList()
       
   232 /** Deletes all the entries in the list and the list itself. */
       
   233 	{
       
   234 	KillStyleList();
       
   235 	}
       
   236 
       
   237 
       
   238  
       
   239 
       
   240 EXPORT_C const RParagraphStyleInfo& CStyleList::At(TInt aIndex)const
       
   241 /** Gets a style from the style list, from its index into the array. Two versions 
       
   242 are supplied. The compiler chooses the appropriate version based on the use 
       
   243 made of the returned reference. If it is used in an expression where that 
       
   244 reference can be modified, then the non-const version is chosen.
       
   245 
       
   246 @param aIndex The index of the style into the list. The first style is at 
       
   247 position zero. Must be within the bounds of the array, or a panic occurs. 
       
   248 @return A const reference to the style at position aIndex in the array. 
       
   249 @return A non-const reference to the style at position aIndex in the array. */
       
   250 	{
       
   251 	__ASSERT_ALWAYS(iList,Panic(EStyleIntegrityError));
       
   252 	__ASSERT_DEBUG(aIndex>=0 && aIndex<iList->Count(),Panic(EStyleIndexOutOfRange));
       
   253 	
       
   254 	return (*iList)[aIndex];
       
   255 	}
       
   256 
       
   257 
       
   258 EXPORT_C RParagraphStyleInfo& CStyleList::At(TInt aIndex)
       
   259 	{
       
   260 	__ASSERT_ALWAYS(iList,Panic(EStyleIntegrityError));
       
   261 	__ASSERT_DEBUG(aIndex>=0 && aIndex<iList->Count(),Panic(EStyleIndexOutOfRange));
       
   262 
       
   263 	return (*iList)[aIndex];
       
   264 	}
       
   265 
       
   266 
       
   267  
       
   268 EXPORT_C void CStyleList::Reset()
       
   269  /** Deletes the contents of the list. */
       
   270 	{
       
   271 	__TEST_INVARIANT;
       
   272 	
       
   273 	TInt styleCount=Count();
       
   274 	for (TInt nn=0;nn<styleCount;nn++)
       
   275 		delete (iList->At(nn)).iStyle;
       
   276 	if (iList)
       
   277 		iList->Reset();
       
   278 
       
   279 	__TEST_INVARIANT;
       
   280 	}
       
   281 
       
   282 
       
   283 void CStyleList::KillStyleList()
       
   284 	{
       
   285 	Reset();
       
   286 	delete iList;
       
   287 	}
       
   288 
       
   289 
       
   290 
       
   291 EXPORT_C TStreamId CStyleList::StoreL(CStreamStore& aStore)const
       
   292 /** Stores the style list to a stream store.
       
   293 
       
   294 @param aStore Stream store to which the style list is written. 
       
   295 @return The ID of the stream store. */
       
   296 	{
       
   297 	__TEST_INVARIANT;
       
   298 
       
   299 	RStoreWriteStream stream;
       
   300 	TStreamId id=stream.CreateLC(aStore);
       
   301 	//
       
   302 	stream<< *this;
       
   303 	//
       
   304 	stream.CommitL();
       
   305 	CleanupStack::PopAndDestroy();
       
   306 	return id;
       
   307 	}
       
   308 
       
   309 
       
   310 
       
   311 
       
   312 EXPORT_C void CStyleList::ExternalizeL(RWriteStream& aStream)const
       
   313 /** Externalises the style list to a write stream. The presence of this function 
       
   314 means that the standard templated operator<<() (defined in s32strm.h) is available 
       
   315 to externalise objects of this class. Does not externalise any styles' based-on 
       
   316 links.
       
   317 
       
   318 @param aStream Stream to which the object should be externalised. */
       
   319 	{
       
   320 	__TEST_INVARIANT;
       
   321 	
       
   322 	TInt count=Count();
       
   323 	aStream.WriteUint8L(count);
       
   324 	for (TInt mm=0;mm<count;mm++)
       
   325 		{
       
   326 		CParagraphStyle* style=(iList->At(mm)).iStyle;
       
   327 		style->ExternalizeL(aStream);
       
   328 		}
       
   329 	for (TInt nn=0;nn<count;nn++)
       
   330 		{
       
   331 		RParagraphStyleInfo set=iList->At(nn);
       
   332 		CParagraphStyle* style=set.iStyle;
       
   333 		TInt offset=(set.iStyleForNextPara!=NULL)
       
   334 			? IndexByPtr(style)
       
   335 			: -1;
       
   336 		__ASSERT_DEBUG(offset==-1 || (offset>=0 && offset<Count()),Panic(EStyleIntegrityError));
       
   337 		aStream.WriteInt8L(offset);
       
   338 		}
       
   339 	}
       
   340 
       
   341 
       
   342 
       
   343 EXPORT_C void CStyleList::InternalizeL(RReadStream& aStream,
       
   344 									   const CParaFormatLayer* aGlobalParaFormatLayer,
       
   345 									   const CCharFormatLayer* aGlobalCharFormatLayer)
       
   346 /** Internalises the style list from a read stream. The presence of this function 
       
   347 means that the standard templated operator>>() (defined in s32strm.h) is available 
       
   348 to internalise objects of this class. Any existing style list contents are 
       
   349 replaced.
       
   350 
       
   351 @param aStream Stream store from which the style list is internalised. 
       
   352 @param aGlobalParaFormatLayer Pointer to the global paragraph format layer 
       
   353 on which all styles in the list are based. 
       
   354 @param aGlobalCharFormatLayer Pointer to the global character format layer 
       
   355 on which all styles in the list are based. */
       
   356 	{
       
   357 	KillStyleList();
       
   358 	TInt styleCount=aStream.ReadUint8L();
       
   359 	ConstructL(Max(1,styleCount));  // panics if granularity==0
       
   360 	RParagraphStyleInfo holdingSet;
       
   361 	iList->AppendL(holdingSet,styleCount);
       
   362 	for (TInt mm=0;mm<styleCount;mm++)
       
   363 		{// restore the paragraph styles
       
   364 		CParagraphStyle* style=CParagraphStyle::NewL(aStream,*aGlobalParaFormatLayer,*aGlobalCharFormatLayer);
       
   365 		iList->At(mm).iStyle=style;
       
   366 		}
       
   367 	for (TInt nn=0;nn<styleCount;nn++)
       
   368 		{// restore the "style for next paragraph" for each paragraph
       
   369 		TInt offset=aStream.ReadInt8L();
       
   370 		iList->At(nn).iStyleForNextPara=(offset==-1)
       
   371 			? NULL
       
   372 			: iList->At(offset).iStyle;
       
   373 		}
       
   374 
       
   375 	__TEST_INVARIANT;
       
   376 	}
       
   377 
       
   378 
       
   379 
       
   380 EXPORT_C TInt CStyleList::AppendL(RParagraphStyleInfo* aStyleSet)
       
   381 /** Appends a style to the style list. The list takes ownership of the style.
       
   382 
       
   383 @param aStyleSet The style (and optional style for the following paragraph) 
       
   384 to append to the list. 
       
   385 @return KErrNone if successful, or KErrAlreadyExists if the style is already 
       
   386 present in the list. */
       
   387 	{
       
   388 	__TEST_INVARIANT;
       
   389 	
       
   390 	TInt count=Count();
       
   391 	for (TInt ii=0;ii<count;ii++)
       
   392 		{
       
   393 		if (aStyleSet->iStyle==iList->At(ii).iStyle)
       
   394 			return KErrAlreadyExists;  // we already own this style
       
   395 		}
       
   396 	CleanupStack::PushL(aStyleSet->iStyle);
       
   397 	iList->AppendL(*aStyleSet);  // if the append fails, we must take responsibility for the style
       
   398 	CleanupStack::Pop();  // aStyleSet.iStyle
       
   399 
       
   400 	__TEST_INVARIANT;
       
   401 	return KErrNone;
       
   402 	}
       
   403 
       
   404 
       
   405 EXPORT_C void CStyleList::Remove(CParagraphStyle* aStyle)
       
   406 /** Removes a style from the style list. If the style is owned by the list, it 
       
   407 is deleted. If the style is not owned by the list, but is referenced by a 
       
   408 style owned by the list, (i.e. a style in the list is based on it, or references 
       
   409 it as its iStyleForNextPara pointer) then the pointer to aStyle is set to 
       
   410 NULL.
       
   411 
       
   412 @param aStyle Pointer to the style to remove from the style list, or to set 
       
   413 to NULL. */
       
   414 	{
       
   415 	__TEST_INVARIANT;
       
   416 
       
   417 	TInt styles = Count();
       
   418 	TInt index = -1;
       
   419 	for (TInt i = 0; i < styles; i++)
       
   420 		{
       
   421 		RParagraphStyleInfo& cur_style = (*iList)[i];
       
   422 		if (cur_style.iStyleForNextPara == aStyle)
       
   423 			cur_style.iStyleForNextPara = NULL;
       
   424 		if (cur_style.iStyle->iBasedOn == aStyle)
       
   425 			cur_style.iStyle->iBasedOn = NULL;
       
   426 		if (cur_style.iStyle == aStyle)
       
   427 			{
       
   428 			// Assert that the style must occur only once in the style list.
       
   429 			__ASSERT_DEBUG(index == -1,Panic(EStyleIntegrityError));
       
   430 			index = i;
       
   431 			}
       
   432 		}
       
   433 
       
   434 	if (index != -1)
       
   435 		{
       
   436 		delete aStyle;
       
   437 		iList->Delete(index);
       
   438 		}
       
   439 	
       
   440 	__TEST_INVARIANT;
       
   441 	}
       
   442 
       
   443 
       
   444 
       
   445 EXPORT_C TInt CStyleList::SetStyleToFollow(const RParagraphStyleInfo& aStyleSet)
       
   446 /** Sets the style to use for the following paragraph for a style in the style 
       
   447 list. Both the style (aStyleSet.iStyle) and the style to set for the following 
       
   448 paragraph (aStyleSet.iStyleForNextPara) must exist in the style list.
       
   449 
       
   450 The function first locates the style (aStyleSet.iStyle) in the list, then 
       
   451 sets the style to use for the next paragraph to aStyleSet.iStyleForNextPara.
       
   452 
       
   453 If aStyleSet.iStyle does not exist in the style list, the function returns 
       
   454 with KErrNotFound. If aStyleSet.iStyleForNextPara does not exist in the style 
       
   455 list, a panic occurs.
       
   456 
       
   457 @param aStyleSet Identifies a style in the list, and a style to use for its 
       
   458 following paragraph. 
       
   459 @return KErrNone if successful, or KErrNotFound if the first style contained 
       
   460 in the argument (aStyleSet.iStyle) is not in the style list. */
       
   461 	{
       
   462 	__ASSERT_ALWAYS( IndexByPtr(aStyleSet.iStyleForNextPara) != KErrNotFound, Panic(EStyleIntegrityError) );
       
   463 	__TEST_INVARIANT;
       
   464 	
       
   465 	TInt index = IndexByPtr(aStyleSet.iStyle);
       
   466 	if (index == KErrNotFound)
       
   467 		return index;
       
   468 	
       
   469 	(*iList)[index].iStyleForNextPara = aStyleSet.iStyleForNextPara;
       
   470 	
       
   471 	__TEST_INVARIANT;
       
   472 	
       
   473 	return KErrNone;
       
   474 
       
   475 	}
       
   476 	
       
   477 
       
   478 
       
   479 
       
   480 EXPORT_C RParagraphStyleInfo* CStyleList::PtrByName(const TParagraphStyleName& aName) const
       
   481 /** Gets the style with the specified name from the style list.
       
   482 
       
   483 @param aName The name of the style to retrieve. 
       
   484 @return Pointer to the style with the name specified. NULL if there is no style 
       
   485 with this name in the list. */
       
   486 	{
       
   487 	// Return a pointer to the named style if it's in the list, or null if not.
       
   488 	__TEST_INVARIANT;
       
   489 	
       
   490 	int count = Count();
       
   491 	for (int i = 0; i < count; i++)
       
   492 		{
       
   493 		RParagraphStyleInfo& style_info = (*iList)[i];
       
   494 		if (style_info.iStyle != NULL && style_info.iStyle->iName == aName)
       
   495 			return &style_info;
       
   496 		}
       
   497 	return NULL;
       
   498 	}
       
   499 
       
   500 
       
   501 
       
   502 
       
   503 EXPORT_C RParagraphStyleInfo* CStyleList::PtrByType(const TUid aType) const
       
   504 /** Gets the style with the specified type UID from the style list.
       
   505 
       
   506 @param aType The UID of the style to retrieve. 
       
   507 @return Pointer to the style with the type UID specified. NULL if there is 
       
   508 no style with this type in the list. */
       
   509 	{
       
   510 	// Return a pointer to the first style with the specified type if any; or null if there are none with this type.
       
   511 	__TEST_INVARIANT;
       
   512 
       
   513 	int count = Count();
       
   514 	for (int i = 0; i < count; i++)
       
   515 		{
       
   516 		RParagraphStyleInfo& style_info = (*iList)[i];
       
   517 		if (style_info.iStyle != NULL && style_info.iStyle->Type() == aType)
       
   518 			return &style_info;
       
   519 		}
       
   520 	return NULL;
       
   521 	}
       
   522 
       
   523 
       
   524 
       
   525 
       
   526 EXPORT_C TInt CStyleList::IndexByPtr(const CParaFormatLayer* aPtr)const
       
   527 /** Gets the index into the style list of a specified paragraph style.
       
   528 
       
   529 @param aPtr Pointer to the style. 
       
   530 @return The style's index into the style list. KErrNotFound if the style is 
       
   531 not found in the style list, or if aPtr is a paragraph format layer rather 
       
   532 than a style. */
       
   533 	{
       
   534 	if (aPtr->Type()==KNormalParagraphStyleUid)
       
   535 		return KErrNotFound;
       
   536 	TInt count=Count();
       
   537 	if (count==0)
       
   538 		return KErrNotFound;  // ptr cannot be matched cos list is empty.
       
   539 	TInt index=0;
       
   540 	CParagraphStyle* style=NULL;
       
   541 	while (index<count)
       
   542 		{
       
   543 		style=(*iList)[index].iStyle;
       
   544 		if (style==aPtr)
       
   545 			break;
       
   546 		index++;
       
   547 		}
       
   548 	return (index<count)
       
   549 		? index
       
   550 		: KErrNotFound;
       
   551 	}
       
   552 
       
   553 
       
   554 
       
   555 
       
   556 EXPORT_C TInt CStyleList::IndexByName(const TDesC& aName)const
       
   557 /** Gets the index into the style list of a specified paragraph style, identified 
       
   558 by its name.
       
   559 
       
   560 @param aName The name of the style. 
       
   561 @return The style's index into the style list. KErrNotFound if the style name 
       
   562 is not found in the style list. */
       
   563 	{
       
   564 	TInt count=Count();
       
   565 	if (count==0)
       
   566 		return KErrNotFound;  // name cannot be in list cos its empty.
       
   567 	TInt index=0;
       
   568 	CParagraphStyle* style=NULL;
       
   569 	while (index<count)
       
   570 		{
       
   571 		style=(*iList)[index].iStyle;
       
   572 		if (style != NULL && style->iName == aName)
       
   573 			break;
       
   574 		index++;
       
   575 		}
       
   576 	return (index<count)
       
   577 		? index
       
   578 		: KErrNotFound;
       
   579 	}
       
   580 
       
   581 
       
   582 
       
   583 EXPORT_C CStyleList* CStyleList::DeepCloneL() const
       
   584 /** Creates and returns a style list which is a clone of the current style list.
       
   585 
       
   586 @return Pointer to a clone of the current style list. */
       
   587 	{
       
   588 	__TEST_INVARIANT;
       
   589 	
       
   590 	CStyleList* newList = CStyleList::NewL();
       
   591 	CleanupStack::PushL(newList);
       
   592 
       
   593 	TInt styleCount=Count();
       
   594 	for (TInt styleItem=0;styleItem<styleCount;styleItem++)
       
   595 		{
       
   596 		const RParagraphStyleInfo& source=iList->At(styleItem);
       
   597 		CParagraphStyle* style=source.iStyle->CloneL();
       
   598 		RParagraphStyleInfo info(style,source.iStyleForNextPara);
       
   599 		newList->AppendL(&info);
       
   600 		}
       
   601 
       
   602 	CleanupStack::Pop();
       
   603 	return newList;
       
   604 	}