webengine/wmlengine/src/fbox/src/FBOXWmlFormatHandler.cpp
changeset 74 91031d3aab7d
parent 68 92a765b5b3e7
child 85 e358f2276d3f
equal deleted inserted replaced
68:92a765b5b3e7 74:91031d3aab7d
     1 /*
       
     2 * Copyright (c) 2000 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 the License "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 FILES
       
    20 #include <AknUtils.h>
       
    21 #include "nw_fbox_wmlformathandler.h"
       
    22 #include "NW_Unicode_LetterOther.h"
       
    23 #include "NW_Unicode_LetterChina.h"
       
    24 #include "NW_Unicode_LetterThai.h"
       
    25 
       
    26 
       
    27 // CONSTANTS
       
    28 
       
    29 static const TUint KWmlFormatNone = 0;
       
    30 static const TUint KWmlFormatA = 'A';
       
    31 static const TUint KWmlFormata = 'a';
       
    32 static const TUint KWmlFormatn = 'n';
       
    33 static const TUint KWmlFormatN = 'N';
       
    34 static const TUint KWmlFormatX = 'X';
       
    35 static const TUint KWmlFormatx = 'x';
       
    36 static const TUint KWmlFormatm = 'm';
       
    37 static const TUint KWmlFormatM = 'M';
       
    38 static const TUint KWmlFormatStatic = '\\';
       
    39 
       
    40 static const TUint KWmlFormatMultiplier = '*';
       
    41 
       
    42 // ================= MEMBER FUNCTIONS =======================
       
    43 
       
    44 // C++ default constructor can NOT contain any code, that
       
    45 // might leave.
       
    46 //
       
    47 TWmlFormatChar::TWmlFormatChar( TUint aChar, TUint aStatic )
       
    48 	: iChar( aChar )
       
    49 	{
       
    50 	iStatic = ( aChar == KWmlFormatStatic ) ? aStatic : 0;
       
    51 	}
       
    52 
       
    53 // ---------------------------------------------------------
       
    54 // TWmlFormatChar::ForcedCase
       
    55 // ---------------------------------------------------------
       
    56 //
       
    57 TWmlFormatChar::TWmlCase TWmlFormatChar::ForcedCase() const
       
    58 	{
       
    59 	TWmlCase result;
       
    60 	switch( iChar )
       
    61 		{
       
    62 		case KWmlFormatA :
       
    63 		case KWmlFormatX :
       
    64 			result = EWmlUpperCase;
       
    65 			break;
       
    66 
       
    67 		case KWmlFormata :
       
    68 		case KWmlFormatx :
       
    69 			result = EWmlLowerCase;
       
    70 			break;
       
    71 
       
    72 		case KWmlFormatn :
       
    73 		case KWmlFormatN :
       
    74 			result = EWmlNumericCase;
       
    75 			break;
       
    76 
       
    77 		default:
       
    78 			result = EWmlNone;
       
    79 			break;
       
    80 		}
       
    81 	return result;
       
    82 	}
       
    83 
       
    84 // ---------------------------------------------------------
       
    85 // TWmlFormatChar::SuggestedCase
       
    86 // ---------------------------------------------------------
       
    87 //
       
    88 TWmlFormatChar::TWmlCase TWmlFormatChar::SuggestedCase() const
       
    89 	{
       
    90 	TWmlCase result;
       
    91 	switch( iChar )
       
    92 		{
       
    93 		case KWmlFormatA :
       
    94 		case KWmlFormatX :
       
    95 		case KWmlFormatM :
       
    96 			result = EWmlUpperCase;
       
    97 			break;
       
    98 
       
    99 		case KWmlFormata :
       
   100 		case KWmlFormatx :
       
   101 		case KWmlFormatm :
       
   102 			result = EWmlLowerCase;
       
   103 			break;
       
   104 
       
   105 		case KWmlFormatn :
       
   106 		case KWmlFormatN :
       
   107 			result = EWmlNumericCase;
       
   108 			break;
       
   109 
       
   110 		default:
       
   111 			result = EWmlNone;
       
   112 			break;
       
   113 		}
       
   114 	return result;
       
   115 	}
       
   116 
       
   117 // ---------------------------------------------------------
       
   118 // TWmlFormatChar::AlphaAllowed
       
   119 // ---------------------------------------------------------
       
   120 //
       
   121 TBool TWmlFormatChar::AlphaAllowed() const
       
   122 	{
       
   123 	TBool result;
       
   124 	switch( iChar )
       
   125 		{
       
   126 		case KWmlFormatA :
       
   127 		case KWmlFormata :
       
   128 		case KWmlFormatX :
       
   129 		case KWmlFormatx :
       
   130 		case KWmlFormatM :
       
   131 		case KWmlFormatm :
       
   132 		case KWmlFormatStatic :
       
   133 			result = ETrue;
       
   134 			break;
       
   135 
       
   136 		default:
       
   137 			result = EFalse;
       
   138 			break;
       
   139 		}
       
   140 	return result;
       
   141 	}
       
   142 
       
   143 // ---------------------------------------------------------
       
   144 // TWmlFormatChar::NumericAllowed
       
   145 // ---------------------------------------------------------
       
   146 //
       
   147 TBool TWmlFormatChar::NumericAllowed() const
       
   148 	{
       
   149 	TBool result;
       
   150 	switch( iChar )
       
   151 		{
       
   152 		case KWmlFormatX :
       
   153 		case KWmlFormatx :
       
   154 		case KWmlFormatM :
       
   155 		case KWmlFormatm :
       
   156 		case KWmlFormatn :
       
   157 		case KWmlFormatN :
       
   158 		case KWmlFormatStatic :
       
   159 			result = ETrue;
       
   160 			break;
       
   161 
       
   162 		default:
       
   163 			result = EFalse;
       
   164 			break;
       
   165 		}
       
   166 	return result;
       
   167 	}
       
   168 
       
   169 // ---------------------------------------------------------
       
   170 // TWmlFormatChar::SpecialAllowed
       
   171 // ---------------------------------------------------------
       
   172 //
       
   173 TBool TWmlFormatChar::SpecialAllowed() const
       
   174 	{
       
   175 	TBool result;
       
   176 	switch( iChar )
       
   177 		{
       
   178 		case KWmlFormatA :
       
   179 		case KWmlFormata :
       
   180 		case KWmlFormatX :
       
   181 		case KWmlFormatx :
       
   182 		case KWmlFormatM :
       
   183 		case KWmlFormatm :
       
   184 		case KWmlFormatn :
       
   185 		case KWmlFormatStatic :
       
   186 			result = ETrue;
       
   187 			break;
       
   188 
       
   189 		default:
       
   190 			result = EFalse;
       
   191 			break;
       
   192 		}
       
   193 	return result;
       
   194 	}
       
   195 
       
   196 // ---------------------------------------------------------
       
   197 // TWmlFormatChar::Char
       
   198 // ---------------------------------------------------------
       
   199 //
       
   200 TUint TWmlFormatChar::Char() const
       
   201 	{
       
   202 	return iChar;
       
   203 	}
       
   204 
       
   205 // ---------------------------------------------------------
       
   206 // TWmlFormatChar::Static()
       
   207 // ---------------------------------------------------------
       
   208 //
       
   209 TUint TWmlFormatChar::Static() const
       
   210 	{
       
   211 	return iStatic;
       
   212 	}
       
   213 
       
   214 // ================= MEMBER FUNCTIONS =======================
       
   215 
       
   216 // C++ default constructor can NOT contain any code, that
       
   217 // might leave.
       
   218 //
       
   219 TKStaticChar::TKStaticChar( TUint aChar, TInt aPos )
       
   220 	: iChar( aChar )
       
   221 	, iPos( aPos )
       
   222 	{
       
   223 	}
       
   224 
       
   225 // ---------------------------------------------------------
       
   226 // TStaticChar::Char
       
   227 // ---------------------------------------------------------
       
   228 //
       
   229 TUint TKStaticChar::Char() const
       
   230 	{
       
   231 	return iChar;	
       
   232 	}
       
   233 
       
   234 // ---------------------------------------------------------
       
   235 // TStaticChar::Pos
       
   236 // ---------------------------------------------------------
       
   237 //
       
   238 TInt TKStaticChar::Pos() const
       
   239 	{
       
   240 	return iPos;	
       
   241 	}
       
   242 
       
   243 // ================= MEMBER FUNCTIONS =======================
       
   244 
       
   245 // C++ default constructor can NOT contain any code, that
       
   246 // might leave.
       
   247 //
       
   248 CWmlFormatHandler::CWmlFormatHandler()
       
   249 	: iPostFix( KWmlFormatNone )
       
   250     {
       
   251 	}
       
   252 
       
   253 // EPOC default constructor can leave.
       
   254 void CWmlFormatHandler::ConstructL
       
   255 	( const TDesC& aFormatString, TWapDocType aWapDocType )
       
   256     {
       
   257     if ( aWapDocType != EWmlDocType_Wml_1_0 &&
       
   258 		 aWapDocType != EWmlDocType_Wml_1_1 &&
       
   259 		 aWapDocType != EWmlDocType_Wml_1_2 )
       
   260 		{
       
   261 		// handle unknown types as WML1.3
       
   262 		aWapDocType = EWmlDocType_Wml_1_3;
       
   263 		}
       
   264 
       
   265 	CArrayFixFlat<TInt>* statics = new( ELeave )CArrayFixFlat<TInt>( 3 );
       
   266 	CleanupStack::PushL( statics );
       
   267 	
       
   268 	// collect the indexes of static characters
       
   269 	TBool mark = EFalse;
       
   270 	TInt length = aFormatString.Length();
       
   271 	for ( TInt i = 0; i < length; i++ )
       
   272 		{
       
   273 		if ( mark )	// was the previous character prefix?
       
   274 			{
       
   275 			mark = EFalse;
       
   276 			statics->AppendL( i );
       
   277 			}
       
   278 		else
       
   279 			{		// is it prefix?
       
   280 			mark = ( aFormatString[ i ] == KWmlFormatStatic );
       
   281 			}
       
   282 		}
       
   283 
       
   284 	TInt numberOfStatics = statics->Count();
       
   285 	iMinLength = length - numberOfStatics;
       
   286 	iMaxLength = iMinLength;
       
   287 
       
   288 	// *f and nf handling	
       
   289 	if ( length > 1 &&				// longer than one character
       
   290 		 ( !numberOfStatics ||		// there are no statics, or it isn't static
       
   291 		   statics->At( numberOfStatics - 1 ) != length - 2 ) )
       
   292 		{
       
   293 		if ( aFormatString[ length - 2 ] == KWmlFormatMultiplier )	// *f?
       
   294 			{
       
   295 			iPostFix = aFormatString[ ( --length )-- ];
       
   296 			iMinLength = length - numberOfStatics;
       
   297 			iMaxLength = KInfiniteLength;
       
   298 			}
       
   299 		else
       
   300 			{
       
   301 			TChar n( aFormatString[ length - 2 ] );
       
   302 			if ( n.IsDigit() && n != '0' )	// nf?
       
   303 				{
       
   304                                 TInt adjustLength = length;
       
   305 				iPostFix = aFormatString[ ( --adjustLength )-- ];
       
   306 				iMaxLength = adjustLength - numberOfStatics + n.GetNumericValue();
       
   307 				// WML1.0, WML1.1: entry of n characters
       
   308 				// WML1.2, WML1.3: entry of up to n characters
       
   309 				iMinLength = aWapDocType > EWmlDocType_Wml_1_1
       
   310 					? adjustLength - numberOfStatics + 1 : iMaxLength;
       
   311 				}
       
   312 			}
       
   313 		}
       
   314 
       
   315 	// allocate memory for members
       
   316 	iMask = HBufC::NewL( length);	
       
   317 	iStatic = new( ELeave )CArrayFixFlat<TKStaticChar>( 3 );
       
   318 
       
   319 	// copy aFormatString to iMask except static text
       
   320 	TInt nextStatic = 0;
       
   321 	for ( TInt j = 0; j < length; j++ )
       
   322 		{
       
   323 		if ( nextStatic < numberOfStatics &&
       
   324 			 j == statics->At( nextStatic ) )	// is it static?
       
   325 			{
       
   326 				nextStatic++;
       
   327 				iStatic->AppendL
       
   328 					( TKStaticChar( aFormatString[ j ], j - nextStatic ) );
       
   329 			}
       
   330 		else
       
   331 			{
       
   332 			iMask->Des().Append( aFormatString[ j ] );
       
   333 			}
       
   334 		}
       
   335 
       
   336 	iDynamic = HBufC::NewL( iMinLength );
       
   337 
       
   338 	CleanupStack::PopAndDestroy();	// statics
       
   339     }
       
   340 
       
   341 // Two-phased constructor.
       
   342 CWmlFormatHandler* CWmlFormatHandler::NewLC
       
   343 	( const TDesC& aFormatString, TWapDocType aWapDocType )
       
   344     {
       
   345 	CWmlFormatHandler* self = new( ELeave )CWmlFormatHandler;
       
   346 	CleanupStack::PushL( self );
       
   347     self->ConstructL( aFormatString, aWapDocType );
       
   348 	return self;
       
   349     }
       
   350 
       
   351 // Two-phased constructor.
       
   352 CWmlFormatHandler* CWmlFormatHandler::NewL
       
   353 	( const TDesC& aFormatString, TWapDocType aWapDocType )
       
   354     {
       
   355     CWmlFormatHandler* self = NewLC( aFormatString, aWapDocType );
       
   356     CleanupStack::Pop();
       
   357     return self;
       
   358     }
       
   359     
       
   360 // Destructor
       
   361 CWmlFormatHandler::~CWmlFormatHandler()
       
   362     {
       
   363 	delete iMask;
       
   364 	delete iStatic;
       
   365 	delete iDynamic;
       
   366     }
       
   367 
       
   368 // ---------------------------------------------------------
       
   369 // CWmlFormatHandler::GetTextOnly
       
   370 // ---------------------------------------------------------
       
   371 //
       
   372 HBufC* CWmlFormatHandler::GetTextOnlyL( )
       
   373     {
       
   374     HBufC* newText = HBufC::NewL( iDynamic->Length() );
       
   375     TPtr ptr = iDynamic->Des();
       
   376 
       
   377     newText->Des().Copy( ptr );
       
   378     return newText;
       
   379     }
       
   380 
       
   381 // ---------------------------------------------------------
       
   382 // CWmlFormatHandler::SetTextL
       
   383 // ---------------------------------------------------------
       
   384 //
       
   385 TBool CWmlFormatHandler::SetTextL( const TDesC& aText, TBool aNoValidation )
       
   386 	{
       
   387 	iDynamic->Des().SetLength( 0 );	// ignore previous text
       
   388 	
       
   389 	if(AknLayoutUtils::PenEnabled())
       
   390 	    {
       
   391 	    // ignore validation if VKB is in use
       
   392 	    // validation will be done on exit
       
   393 	    aNoValidation = ETrue; 
       
   394 	    }
       
   395 
       
   396 	// insert chars while they are valid
       
   397 	TInt j( 0 );
       
   398 	TInt textLength( aText.Length() );
       
   399 	for ( ;
       
   400 		  j < textLength &&
       
   401 		  ( aNoValidation || ValidateChar( aText[ j ], GetFormat( j ) ) );
       
   402 		  j++ )
       
   403 		{
       
   404 
       
   405 		if ( !GetFormat( j ).Static() )
       
   406 			{
       
   407 		    InsertL( j, aText[ j ] );	// insert non-static chars
       
   408 			}
       
   409 		}
       
   410 
       
   411 	return j == textLength;
       
   412 	}
       
   413 
       
   414 // ---------------------------------------------------------
       
   415 // CWmlFormatHandler::TextLC
       
   416 // ---------------------------------------------------------
       
   417 //
       
   418 HBufC* CWmlFormatHandler::TextLC( TBool aReadable ) const
       
   419 	{
       
   420 	HBufC* text = StaticTextLC();	// get static text
       
   421 	TInt staticLength = text->Length();
       
   422 	TInt dynamicLength = iDynamic->Length();
       
   423 	TInt dynamicPtr( 0 );
       
   424 	TInt staticPtr( 0 );
       
   425 	TInt staticCounter( 0 );
       
   426 	TInt numberOfStatics( iStatic->Count() );
       
   427 	// insert dynamic text into the static text as many as possible
       
   428 	for ( ; dynamicPtr < dynamicLength; ++dynamicPtr, ++staticPtr )
       
   429 		{
       
   430 		// find the next non-static position
       
   431 		while ( staticCounter < numberOfStatics &&
       
   432 				iStatic->At( staticCounter ).Pos() == staticPtr )
       
   433 			{
       
   434 			++staticCounter;
       
   435 			++staticPtr;
       
   436 			}
       
   437 
       
   438 		if ( staticPtr < staticLength )	// is there place for it?
       
   439 			{
       
   440             /*lint -e{111} Assignment to const object */
       
   441 			text->Des()[ staticPtr ] = aReadable ? ( *iDynamic )[ dynamicPtr ]
       
   442 												 : KObscuringChar()[ 0 ];
       
   443 			}
       
   444 		else
       
   445 			{
       
   446 			break;
       
   447 			}
       
   448 		}
       
   449 
       
   450 	if ( dynamicPtr < dynamicLength )	// append the remaining dynamic text
       
   451 		{
       
   452 		HBufC* newText = text->ReAllocL
       
   453 			( staticLength + dynamicLength - dynamicPtr + 1 );
       
   454 
       
   455 		CleanupStack::Pop();			// text
       
   456 		CleanupStack::PushL( newText );	// newText
       
   457 		text = newText;
       
   458 
       
   459 		if ( aReadable )
       
   460 			{
       
   461 			for ( ; dynamicPtr < dynamicLength; dynamicPtr++ )
       
   462 				{
       
   463 				text->Des().Append( ( *iDynamic )[ dynamicPtr ] );
       
   464 				}
       
   465 			}
       
   466 		else
       
   467 			{
       
   468 			for ( ; dynamicPtr < dynamicLength; dynamicPtr++ )
       
   469 				{
       
   470 				text->Des().Append( KObscuringChar );
       
   471 				}
       
   472 			}
       
   473 		}
       
   474 
       
   475 	text->Des().ZeroTerminate();
       
   476 	return text;
       
   477 	}
       
   478 
       
   479 // ---------------------------------------------------------
       
   480 // CWmlFormatHandler::InsertL
       
   481 // ---------------------------------------------------------
       
   482 //
       
   483 void CWmlFormatHandler::InsertL( TInt aPos, TChar aChar )
       
   484 	{
       
   485 	TBuf<1> buf;
       
   486 	buf.Append( aChar );
       
   487 	InsertL( aPos, buf );
       
   488 	}
       
   489 
       
   490 // ---------------------------------------------------------
       
   491 // CWmlFormatHandler::InsertL
       
   492 // ---------------------------------------------------------
       
   493 //
       
   494 void CWmlFormatHandler::InsertL( TInt aPos, const TDesC& aDes )
       
   495 	{
       
   496 	TInt newPos = PosExludingStatic( aPos );
       
   497 	if ( -1 < newPos && newPos <= iDynamic->Length() )
       
   498 		{
       
   499 		// make sure there's enough space
       
   500 		TInt newLength = iDynamic->Length() + aDes.Length();
       
   501 		if ( iDynamic->Des().MaxLength() < newLength )
       
   502 			{
       
   503 			iDynamic = iDynamic->ReAllocL( newLength );
       
   504 			}
       
   505 
       
   506 		iDynamic->Des().Insert( newPos, aDes );
       
   507 		}
       
   508 	}
       
   509 
       
   510 // ---------------------------------------------------------
       
   511 // CWmlFormatHandler::Delete
       
   512 // ---------------------------------------------------------
       
   513 //
       
   514 TBool CWmlFormatHandler::Delete( TInt aPos, TInt aLength )
       
   515     {
       
   516     TBool status = EFalse;
       
   517     TInt newPos = PosExludingStatic( aPos );
       
   518     if ( -1 < newPos && newPos <= iDynamic->Length() )
       
   519         {
       
   520         iDynamic->Des().Delete( newPos, aLength );
       
   521         status = ETrue;
       
   522         }
       
   523     return status;
       
   524     }
       
   525 
       
   526 // ---------------------------------------------------------
       
   527 // CWmlFormatHandler::StaticTextLC
       
   528 // ---------------------------------------------------------
       
   529 //
       
   530 HBufC* CWmlFormatHandler::StaticTextLC() const
       
   531 	{
       
   532 	TInt count = iStatic->Count();
       
   533 	TInt length = ( count ) ? iStatic->At( count - 1 ).Pos() + 1 : 0;
       
   534 	HBufC* empty = HBufC::NewLC( length + 1 );
       
   535 	empty->Des().Fill( ' ', length );
       
   536 	for ( TInt i = 0; i < count; i++ )
       
   537 		{
       
   538 		TKStaticChar staticChar = iStatic->At( i );
       
   539         /*lint -e{111} Assignment to const object */
       
   540 		empty->Des()[ staticChar.Pos() ] =
       
   541 			STATIC_CAST( TUint16, staticChar.Char() );
       
   542 		}
       
   543 
       
   544 	empty->Des().ZeroTerminate();
       
   545 	return empty;
       
   546 	}
       
   547 
       
   548 // ---------------------------------------------------------
       
   549 // CWmlFormatHandler::NumberOfStatic
       
   550 // ---------------------------------------------------------
       
   551 //
       
   552 TInt CWmlFormatHandler::NumberOfStatic() const
       
   553 	{
       
   554 	return iStatic->Count();
       
   555 	}
       
   556 
       
   557 // ---------------------------------------------------------
       
   558 // CWmlFormatHandler::GetFormat
       
   559 // ---------------------------------------------------------
       
   560 //
       
   561 TWmlFormatChar CWmlFormatHandler::GetFormat( TInt aIndex ) const
       
   562 	{
       
   563 	TUint code = KWmlFormatNone;
       
   564 	if ( -1 < aIndex )
       
   565 		{
       
   566 		if ( aIndex < iMask->Length() )		// is it in the mask?
       
   567 			{
       
   568 			code = ( *iMask )[ aIndex ];
       
   569                         TChar n( code );
       
   570 		        if ( n.IsDigit() || code == KWmlFormatMultiplier )	// nf? *f?
       
   571                          {
       
   572                           ++aIndex;
       
   573                           code = ( *iMask )[ aIndex ];
       
   574                          }
       
   575 			}
       
   576 		else
       
   577 			{
       
   578 			if ( aIndex < iMaxLength ||
       
   579 				 iMaxLength == KInfiniteLength )		// is it the postfix?
       
   580 				{
       
   581 				code = iPostFix;
       
   582 				}
       
   583 			}
       
   584 		}
       
   585 
       
   586 	TInt staticChar = 0;
       
   587 	if ( code == KWmlFormatStatic )			// is it static?
       
   588 		{
       
   589 		for ( TInt i = iStatic->Count() - 1; i > -1; i-- )
       
   590 			{
       
   591 			if ( iStatic->At( i ).Pos() == aIndex )
       
   592 				{
       
   593 				staticChar = iStatic->At( i ).Char();
       
   594 				break;
       
   595 				}
       
   596 			}
       
   597 		}
       
   598 
       
   599 	return TWmlFormatChar( code, staticChar );
       
   600 	}
       
   601 
       
   602 // ---------------------------------------------------------
       
   603 // CWmlFormatHandler::PostFix
       
   604 // ---------------------------------------------------------
       
   605 //
       
   606 TWmlFormatChar CWmlFormatHandler::PostFix() const
       
   607 	{
       
   608 	return iPostFix;
       
   609 	}
       
   610 
       
   611 // ---------------------------------------------------------
       
   612 // CWmlFormatHandler::MinLength
       
   613 // ---------------------------------------------------------
       
   614 //
       
   615 TInt CWmlFormatHandler::MinLength() const
       
   616 	{
       
   617 	return iMinLength;
       
   618 	}
       
   619 
       
   620 // ---------------------------------------------------------
       
   621 // CWmlFormatHandler::MaxLength
       
   622 // ---------------------------------------------------------
       
   623 //
       
   624 TInt CWmlFormatHandler::MaxLength() const
       
   625 	{
       
   626 	return iMaxLength;
       
   627 	}
       
   628 
       
   629 // ---------------------------------------------------------
       
   630 // CWmlFormatHandler::ValidateChar
       
   631 // ---------------------------------------------------------
       
   632 //
       
   633 TBool CWmlFormatHandler::ValidateChar
       
   634 	( TChar aChar, TWmlFormatChar aFormatChar ) const
       
   635 	{
       
   636     TBool match( EFalse );
       
   637 
       
   638 	if ( aFormatChar.Static() )		// is it static?
       
   639 		{
       
   640 		match = ( aChar == aFormatChar.Static() );
       
   641 		}
       
   642 	else
       
   643 		{
       
   644 		if ( aChar.IsDigit() )		// is it number?
       
   645 			{
       
   646 			match = aFormatChar.NumericAllowed();
       
   647 			}
       
   648 		else
       
   649 			{
       
   650 			if ( aChar.IsAlpha() )	// is it alphabetical?
       
   651 				{
       
   652 				TWmlFormatChar::TWmlCase forcedCase = aFormatChar.ForcedCase();
       
   653 				match = ( forcedCase == TWmlFormatChar::EWmlNone )
       
   654 					? ETrue
       
   655 					: ( aChar.IsUpper() &&
       
   656 						forcedCase == TWmlFormatChar::EWmlUpperCase ) ||
       
   657 					  ( aChar.IsLower() &&
       
   658 						forcedCase == TWmlFormatChar::EWmlLowerCase );
       
   659         // If non-western alpha then assume there is no upper and lower case
       
   660         // - so check for LetterOther or LetterChina/LetterThai (depending upon variant).
       
   661         // If invalid char for format, value of "match" is retained. 
       
   662         if ( !match && !aChar.IsUpper() && !aChar.IsLower() )
       
   663             {
       
   664             NW_Ucs4 uniCompare;
       
   665             EVariantFlag variant = AknLayoutUtils::Variant();
       
   666             uniCompare = (NW_Ucs4)aChar;
       
   667             if (variant == EApacVariant)
       
   668                 {
       
   669                 if ( NW_Unicode_IsLetterChina(uniCompare) )
       
   670                     {
       
   671                     match = ETrue;
       
   672                     }
       
   673                 if ( NW_Unicode_IsLetterThai(uniCompare) )
       
   674                     {
       
   675                     match = ETrue;
       
   676                     }
       
   677                 }
       
   678             else if ( NW_Unicode_IsLetterOther(uniCompare) )
       
   679                 {
       
   680                 match = ETrue;
       
   681                 }
       
   682             }
       
   683 				}
       
   684 			else
       
   685 				{					// it's punctuator or symbol
       
   686 				match = aFormatChar.SpecialAllowed();
       
   687 				}
       
   688 			}
       
   689 		}
       
   690 
       
   691 	return match;
       
   692 	}
       
   693 
       
   694 // ---------------------------------------------------------
       
   695 // CWmlFormatHandler::ValidateTextLC
       
   696 // ---------------------------------------------------------
       
   697 //
       
   698 CArrayFixFlat<TInt>* CWmlFormatHandler::ValidateTextLC() const
       
   699 	{
       
   700 	CArrayFixFlat<TInt>* errors =
       
   701 		new( ELeave )CArrayFixFlat<TInt>( 3 );
       
   702 	CleanupStack::PushL( errors );
       
   703 
       
   704 	HBufC* text = TextLC();
       
   705 	TInt length( text->Length() );
       
   706 	for ( TInt i = 0; i < length; i++ )
       
   707 		{
       
   708 		if ( !ValidateChar( ( *text )[ i ], GetFormat( i ) ) )
       
   709 			{
       
   710 			errors->AppendL( i );
       
   711 			}
       
   712 		}
       
   713 		
       
   714 	CleanupStack::PopAndDestroy();	// text
       
   715 	return errors;
       
   716 	}
       
   717 
       
   718 // ---------------------------------------------------------
       
   719 // CWmlFormatHandler::ValidateTextL
       
   720 // ---------------------------------------------------------
       
   721 //
       
   722 TBool CWmlFormatHandler::ValidateTextL() const
       
   723 	{
       
   724 	HBufC* text = TextLC();
       
   725 	TInt length( text->Length() );
       
   726 	TInt i;
       
   727 	for ( i = 0;
       
   728 		  i < length && ValidateChar( ( *text )[ i ], GetFormat( i ) );
       
   729 		  i++ )
       
   730 		{}
       
   731 		
       
   732 	CleanupStack::PopAndDestroy();	// text
       
   733 	return ( i == length );
       
   734 	}
       
   735 
       
   736 // ---------------------------------------------------------
       
   737 // CWmlFormatHandler::PosIncludingStatic
       
   738 // ---------------------------------------------------------
       
   739 //
       
   740 TInt CWmlFormatHandler::PosIncludingStatic( TInt aPosExludingStatic )
       
   741 	{
       
   742 	TInt i = 0;
       
   743 	TInt count = iStatic->Count();
       
   744 	for ( ; i < count; i++ )
       
   745 		{
       
   746 		if ( iStatic->At( i ).Pos() <= aPosExludingStatic )
       
   747 			{
       
   748 			aPosExludingStatic++;
       
   749 			}
       
   750 		}
       
   751 
       
   752 	return aPosExludingStatic;
       
   753 	}
       
   754 
       
   755 // ---------------------------------------------------------
       
   756 // CWmlFormatHandler::PosExludingStatic
       
   757 // ---------------------------------------------------------
       
   758 //
       
   759 TInt CWmlFormatHandler::PosExludingStatic( TInt aPosIncludingStatic )
       
   760 	{
       
   761 	// find the nearest static character before aPosIncludingStatic
       
   762 	TInt c = iStatic->Count();
       
   763 	TInt i (0);
       
   764 	for ( ;
       
   765 		  i < c && aPosIncludingStatic >= iStatic->At( i ).Pos();
       
   766 		  i++ )
       
   767 		{
       
   768 		}
       
   769 
       
   770 	return ( aPosIncludingStatic - i );
       
   771 	}
       
   772 
       
   773 // ---------------------------------------------------------
       
   774 // CWmlFormatHandler::PreviousNonStatic
       
   775 // ---------------------------------------------------------
       
   776 //
       
   777 TInt CWmlFormatHandler::PreviousNonStatic( TInt aPos )
       
   778 	{
       
   779 	TInt posExludingStatic = PosExludingStatic( aPos );
       
   780 
       
   781 	return ( -1 < posExludingStatic )
       
   782 		? PosIncludingStatic( posExludingStatic )
       
   783 		: KNotFound;
       
   784 	}
       
   785 
       
   786 // ---------------------------------------------------------
       
   787 // CWmlFormatHandler::NextNonStatic
       
   788 // ---------------------------------------------------------
       
   789 //
       
   790 TInt CWmlFormatHandler::NextNonStatic( TInt aPos )
       
   791 	{
       
   792 	TInt posExludingStatic = PosExludingStatic( aPos ) + 1;
       
   793 
       
   794 	return ( posExludingStatic < iDynamic->Length() )
       
   795 		? PosIncludingStatic( posExludingStatic )
       
   796 		: KNotFound;
       
   797 	}
       
   798 
       
   799 // ---------------------------------------------------------
       
   800 // CWmlFormatHandler::FirstEmpty
       
   801 // ---------------------------------------------------------
       
   802 //
       
   803 TInt CWmlFormatHandler::FirstEmpty()
       
   804 	{
       
   805 	return PosIncludingStatic( iDynamic->Length() );
       
   806 	}
       
   807 
       
   808 
       
   809 // ---------------------------------------------------------
       
   810 // CWmlFormatHandler::PreviousStatic
       
   811 // ---------------------------------------------------------
       
   812 //
       
   813 TInt CWmlFormatHandler::PreviousStatic( TInt aPos )
       
   814 	{
       
   815   TInt prevStaticPos = 0;
       
   816   TInt i = iStatic->Count() - 1;
       
   817   for ( ; i >= 0 &&  iStatic->At( i ).Pos() > aPos; i-- )
       
   818     {}
       
   819   if(i >= 0)
       
   820     {
       
   821     prevStaticPos  = iStatic->At( i ).Pos() ;
       
   822     }
       
   823   return prevStaticPos ;
       
   824 	}
       
   825 
       
   826 
       
   827 
       
   828 // ---------------------------------------------------------
       
   829 // CWmlFormatHandler::IsPosStatic
       
   830 // ---------------------------------------------------------
       
   831 //
       
   832 TBool CWmlFormatHandler::IsPosStatic( TInt aPos )
       
   833 	{
       
   834   TInt i = iStatic->Count() - 1;
       
   835   for ( ; i >= 0 &&  iStatic->At( i ).Pos() != aPos; i-- )
       
   836     {}
       
   837   if(i >= 0)
       
   838     {
       
   839     return ETrue;
       
   840     }
       
   841   return EFalse;
       
   842 	}
       
   843 
       
   844 //  End of File