extras/converter/Ui/Src/CCnvRatesForm.cpp
branchRCL_3
changeset 15 2d0f9ab0ba18
parent 12 ddecbce3dc1f
child 16 82ca176301de
equal deleted inserted replaced
12:ddecbce3dc1f 15:2d0f9ab0ba18
     1 /*
       
     2 * Copyright (c) 2002 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 *      This is the implementation of the class defined in CCnvRatesForm.h
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #include <eikcapc.h>
       
    22 #include <eikfpne.h>
       
    23 #include <AknQueryDialog.h>
       
    24 #include <aknnotewrappers.h>
       
    25 #include <akntitle.h>
       
    26 #include <StringLoader.h>
       
    27 #include <featmgr.h>
       
    28 #include <eikmenup.h>
       
    29 
       
    30 #include <TCnvCategory.h>
       
    31 #include "CCnvRatesForm.h"
       
    32 #include "CCnvApplication.h"
       
    33 
       
    34 #include <csxhelp/cnv.hlp.hrh>
       
    35 
       
    36 #include <Converter.rsg>
       
    37 #include "Converter.hrh"
       
    38 
       
    39 #include <e32math.h> //Header to be included for getting CEikEdwin Text to a number
       
    40 
       
    41 //CONSTANTS for Max Number of Added Currency
       
    42 const TInt KMaxNumberAddCurrency = 40;
       
    43 
       
    44 CCnvRatesForm::CCnvRatesForm( TBool* aWantsRelaunch, TBool* aShouldExit,
       
    45 							 TBool* aModelChanged, TCnvCategory& aCategory ) 
       
    46 							 : iWantsRelaunch( aWantsRelaunch ), iShouldExit( aShouldExit ),
       
    47 							 iModelChanged( aModelChanged ), iCategory( aCategory ),
       
    48 							 iLastUsedEditorId(-1)
       
    49 	{
       
    50 	}
       
    51 
       
    52 CCnvRatesForm::CCnvRatesForm()
       
    53 	{
       
    54 
       
    55 	//Member variable set to False in the Constructor
       
    56 	iEKeyOk = EFalse;
       
    57 	}
       
    58 
       
    59 CCnvRatesForm::~CCnvRatesForm()
       
    60 	{
       
    61 	iFormIdMapArray.Close();
       
    62 	iFormIdEdwinMapArray.Close();
       
    63 	SetDefaultTitle();
       
    64 	}
       
    65 
       
    66 void CCnvRatesForm::ConstructL()
       
    67 	{
       
    68 	// Use base class to construct menubar
       
    69 	CAknDialog::ConstructL( R_CNV_RATESFORM_MENUBAR );
       
    70     iCategory.CreateTempUnitArrayForRestore();
       
    71     iCategory.GetDefaultUnits( iSrcUnitIndexForRestore , iDesUnitIndexForRestore );	
       
    72      iHistoryBaseUnit = iCategory.BaseUnit();
       
    73 	}
       
    74 
       
    75 void CCnvRatesForm::GetHelpContext( TCoeHelpContext& aContext ) const
       
    76 	{
       
    77 	aContext.iMajor = KUidCnv;
       
    78 	aContext.iContext = KCNV_HLP_RATES;
       
    79 	}
       
    80 
       
    81 void CCnvRatesForm::ProcessCommandL( TInt aCommandId )
       
    82 	{
       
    83 	// Base class handles EAknFormCmdSave among the other things
       
    84 	CAknForm::ProcessCommandL( aCommandId );
       
    85 
       
    86 	switch ( aCommandId )
       
    87 		{
       
    88 		case ECmdAddCurrency:
       
    89 			{			
       
    90 			AddNewCurrencyL();
       
    91 			break;
       
    92 			} 
       
    93 		case ECmdDeleteCurrency:
       
    94 			{
       
    95 			DeleteCurrencyL();
       
    96 			break;
       
    97 			}
       
    98 		case ECmdChangeCurrencyName:
       
    99 			{
       
   100 			CmdChangeCurrencyNameL();
       
   101 			break;
       
   102 			}
       
   103 		case ECmdSetAsBaseCurrency:
       
   104 			{
       
   105 			CmdSetAsBaseCurrencyL();
       
   106 			break;
       
   107 			}
       
   108 		case EAknCmdHelp:
       
   109 			{
       
   110 			iEikonEnv->EikAppUi()->HandleCommandL( EAknCmdHelp );
       
   111 			break;
       
   112 			}
       
   113 		case EEikCmdExit:
       
   114 			{
       
   115 			*iShouldExit = ETrue;
       
   116 			TryExitL( EAknSoftkeyBack );
       
   117 			break;
       
   118 			}
       
   119 		default:
       
   120 			{
       
   121 			break;
       
   122 			}
       
   123 		}
       
   124 	}
       
   125 
       
   126 // Takes any action required when the current line is changed to aControlId.
       
   127 void CCnvRatesForm::LineChangedL( TInt aControlId )
       
   128 	{
       
   129 
       
   130 	CEikFloatingPointEditor* editor =
       
   131 		static_cast< CEikFloatingPointEditor* >( Control( aControlId ) );
       
   132 
       
   133 	//editor->ClearSelectionL();
       
   134     editor->SetCursorPosL( editor->Text()->DocumentLength(), ETrue );
       
   135 
       
   136     if ( iLastUsedEditorId > 0 )
       
   137         {
       
   138         editor =static_cast<CEikFloatingPointEditor*> ( Control( iLastUsedEditorId ) );  
       
   139         TBuf<KEditorTextMaxLength> editorText;
       
   140         editor->GetText( editorText );
       
   141         
       
   142         // Use local value for different area
       
   143         TBuf<1> localeZero;
       
   144         localeZero.AppendNum( 0 );
       
   145         AknTextUtils::LanguageSpecificNumberConversion( localeZero ); 
       
   146         if ( editorText.Length() > 1 && editorText[0] == localeZero[0] )
       
   147             {
       
   148             // remove all leading zeroes
       
   149             while ( editorText.Length() > 0 && editorText[0] == localeZero[0] )
       
   150                 {
       
   151                 editorText.Delete( 0, 1 );
       
   152                 }
       
   153             // if too many zeroes removed, insert one.
       
   154             TLocale locale;
       
   155             if ( editorText.Length() == 0 ||
       
   156                 TChar( editorText[0] ) == locale.DecimalSeparator() )
       
   157                 {
       
   158                 editorText.Insert( 0, localeZero );
       
   159                 }
       
   160             editor->SetTextL( &editorText );
       
   161             editor->DrawDeferred();
       
   162             }
       
   163         }
       
   164     iLastUsedEditorId = aControlId;
       
   165 	}
       
   166 
       
   167 void CCnvRatesForm::DoNotSaveFormDataL()
       
   168 	{
       
   169 	iCategory.RestoreUnitArray();
       
   170 	iCategory.SetDefaultUnits( iSrcUnitIndexForRestore , iDesUnitIndexForRestore );
       
   171 	iCategory.SetBaseUnit( iHistoryBaseUnit );
       
   172 	}
       
   173 
       
   174 // Saves values from form fields back to the model
       
   175 TBool CCnvRatesForm::SaveFormDataL()
       
   176 	{
       
   177 	SetEditableL( ETrue );
       
   178 
       
   179 	const MDesCArray* names = iCategory.MdcArray();
       
   180 	TInt len( names->MdcaCount() );
       
   181 	TInt formIdIndex = 0;
       
   182 	for( TInt i = 0; i < len; i ++ )
       
   183 		{
       
   184 
       
   185 		if( i != iCategory.BaseUnit() )
       
   186 			{
       
   187 			TInt formId = iFormIdMapArray[formIdIndex];
       
   188 			//A seperate formIdIndex is maintained for the form as iFormIdMapArray
       
   189 			//does not have an index for Base Unit
       
   190 			formIdIndex++;
       
   191 
       
   192 			TReal value = 0; //Contains the value of the editor
       
   193 
       
   194 			if(KErrNotFound != iFormIdEdwinMapArray.Find(formId))
       
   195 				{
       
   196 				TBuf<32> edText;
       
   197 				GetEdwinText( edText, formId );				
       
   198 				TInt64 power = 1;
       
   199 				TBool fraction = EFalse;
       
   200 				TChar ch;
       
   201 
       
   202 				for(TInt i = 0; i < edText.Length(); i++)
       
   203 					{
       
   204 					ch = edText[i];
       
   205 
       
   206 					if(ch == '+')
       
   207 						{
       
   208 						if( i != 0 )
       
   209 							{
       
   210 							value = 0;
       
   211 							break;
       
   212 							}
       
   213 						}
       
   214 
       
   215 					else if(ch == '.')
       
   216 						{
       
   217 						fraction = ETrue;
       
   218 						}
       
   219 					else if(IsDigit(ch))
       
   220 						{
       
   221 						value = value * 10 + ch.GetNumericValue();
       
   222 						if(fraction)
       
   223 							{
       
   224 							power = power * 10;
       
   225 							}
       
   226 						}
       
   227 					}
       
   228 				value = value / power;				
       
   229 
       
   230 				}
       
   231 			else
       
   232 				{
       
   233 				value = FloatEditorValue( formId  );
       
   234 				}
       
   235 			iCategory.SetUnitFactor( i, /*FloatEditorValue( formId  )*/value );
       
   236 			}		
       
   237 		}
       
   238 
       
   239 	*iModelChanged = ETrue;
       
   240 	return ETrue;
       
   241 	}
       
   242 
       
   243 // Sets the focus to the topmost line of the form when the dialog is activated
       
   244 void CCnvRatesForm::SetInitialCurrentLine()
       
   245 	{
       
   246 	CEikDialog::SetInitialCurrentLine();
       
   247 	TRAP_IGNORE(TryChangeFocusToL( IdOfFocusControl() ) );	
       
   248 	}
       
   249 
       
   250 void CCnvRatesForm::PreLayoutDynInitL()
       
   251 	{
       
   252 	SetTitleL( ETrue );
       
   253 
       
   254 	const MDesCArray* currencies = iCategory.MdcArray();
       
   255 	TInt len( currencies->MdcaCount() );
       
   256 
       
   257 	for( TInt i = 0; i < len; i++ )
       
   258 		{
       
   259 		if( i != iCategory.BaseUnit() )
       
   260 			{
       
   261 			// form controls don't like id = 0, so we need to do id += 1..
       
   262 			CCoeControl* control =
       
   263 				CreateLineByTypeL( currencies->MdcaPoint( i ),
       
   264 				ActivePageId(),
       
   265 				i + 1,
       
   266 				EEikCtFlPtEd,
       
   267 				NULL );
       
   268 			//Keep the id's of the form in an array so that deletion based on form ids is not a problem.
       
   269 			iFormIdMapArray.Append(i+1);
       
   270 			CEikFloatingPointEditor* editor =
       
   271 				static_cast< CEikFloatingPointEditor* >( control );
       
   272 			editor->ConstructL( 0, 9e99, 12 );	// 9e99 = max TReal
       
   273 			TReal value( iCategory.UnitFactor( i ) );
       
   274 			editor->SetValueL( &value );
       
   275 			}
       
   276 		}
       
   277 	}
       
   278 
       
   279 void CCnvRatesForm::CmdChangeCurrencyNameL()
       
   280 	{
       
   281 	// 16 is long enough, current edit window max length is 13
       
   282 	// (defined in R_CNV_UNITNAME_QUERY )
       
   283 	TBuf< 16 > newName;
       
   284 	TBool nameOk( EFalse );
       
   285 
       
   286 	TInt controlId = IdOfFocusControl();	
       
   287 	TInt index =  controlId - 1;
       
   288 
       
   289 	index = iFormIdMapArray.Find( controlId ); //get the index where the id i
       
   290 
       
   291 	TUint uintindex = index ;//To remove warnings
       
   292 
       
   293 	if( uintindex  >= iCategory.BaseUnit())
       
   294 		{
       
   295 		index++;
       
   296 		}
       
   297 	const MDesCArray* names = iCategory.MdcArray();
       
   298 	newName.Copy( names->MdcaPoint( index  ).Left( MAXCURRENCYNAMELENGTH ) );
       
   299 
       
   300 
       
   301 	TCurrencyType type = NewCurrencyNameDialogL( newName, nameOk );
       
   302 
       
   303 	if(nameOk)
       
   304 		{
       
   305 		iCategory.SetUnitName( index , newName , type);
       
   306 		Line( controlId )->SetCaptionL( newName );
       
   307 		Line( controlId )->DrawDeferred();
       
   308 		nameOk = ETrue;
       
   309 		*iModelChanged = ETrue;
       
   310 		}	
       
   311 	}
       
   312 
       
   313 
       
   314 void CCnvRatesForm::CmdSetAsBaseCurrencyL()
       
   315 	{
       
   316 	CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   317 
       
   318 	if( dlg->ExecuteLD( R_CNV_CONFIRMATION_QUERY ) )
       
   319 		{
       
   320 		// form controls don't like ID = 0, so IDs are unit id + 1;
       
   321 		TInt baseUnit;
       
   322 		TUint baseUnitIndex; //To remove warnings
       
   323 		//Get the current id of the form.
       
   324 		TInt currentFocusIndex = IdOfFocusControl();
       
   325 		//Find the id in the map array
       
   326 		baseUnit = iFormIdMapArray.Find(currentFocusIndex);
       
   327 		baseUnitIndex = baseUnit; //To remove warnings
       
   328 		//adjust the baseUnitIndxex to the index in the Currency Category array..
       
   329 		if( baseUnitIndex >= iCategory.BaseUnit())
       
   330 			{
       
   331 			baseUnit++;
       
   332 			}
       
   333 		iHistoryBaseUnit = baseUnit;
       
   334 		iCategory.SetBaseUnit( baseUnit );
       
   335 
       
   336 		// Reset all currency rates to 1
       
   337 		TInt len( iCategory.MdcArray()->MdcaCount() );
       
   338 		for( TInt i = 0; i < len; i++ )
       
   339 			{
       
   340 			iCategory.SetUnitFactor( i, 1.0 );
       
   341 			}
       
   342 
       
   343 		// Except the base unit factor is set to 1.0
       
   344 		iCategory.SetUnitFactor( baseUnit, 1.0 );
       
   345 
       
   346 		// We have to destroy and relaunch the form
       
   347 		*iWantsRelaunch = ETrue;
       
   348 		delete this;
       
   349 		}
       
   350 	}
       
   351 
       
   352 
       
   353 // Reset the title to default. Don't want a leave.
       
   354 // If it fails, it fails. For use in the destructor.
       
   355 void CCnvRatesForm::SetDefaultTitle()
       
   356 	{
       
   357 	 TRAP_IGNORE(SetTitleL( EFalse ) );
       
   358 	}
       
   359 
       
   360 void CCnvRatesForm::SetTitleL( TBool aNonDefault )
       
   361 	{
       
   362 	CAknTitlePane* title = static_cast< CAknTitlePane* >(
       
   363 		iEikonEnv->AppUiFactory()->StatusPane()->
       
   364 		ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   365 
       
   366 	if( aNonDefault )
       
   367 		{
       
   368 		TInt baseUnit = iCategory.BaseUnit();
       
   369 		const MDesCArray* currencies = iCategory.MdcArray();
       
   370 		TPtrC unitName = currencies->MdcaPoint( baseUnit );
       
   371 		// stuff it into the title text's placeholder
       
   372 		HBufC* titleText = StringLoader::LoadL( R_CNV_RATESFORM_TITLE,
       
   373 			unitName, iEikonEnv );
       
   374 		TPtr titleTextPtr = titleText->Des();
       
   375 		CleanupStack::PushL( titleText );
       
   376 		AknTextUtils::DisplayTextLanguageSpecificNumberConversion(titleTextPtr);
       
   377 		title->SetTextL( *titleText );
       
   378 		CleanupStack::PopAndDestroy( titleText ); // titleText
       
   379 		}
       
   380 	else
       
   381 		{
       
   382 		title->SetTextToDefaultL();
       
   383 		}
       
   384 	}	
       
   385 
       
   386 void CCnvRatesForm::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
       
   387 	{
       
   388 	//No delete option  for more than two currencies
       
   389 	const MDesCArray* names = iCategory.MdcArray();
       
   390 	TInt count = names->MdcaCount();
       
   391 
       
   392 	if (aResourceId == R_CNV_RATESFORM_MENUPANE)
       
   393 		{
       
   394 
       
   395 		if(count <= 2)
       
   396 			{
       
   397 			aMenuPane->SetItemDimmed(ECmdDeleteCurrency, ETrue);
       
   398 
       
   399 			}
       
   400 		else
       
   401 			{
       
   402 			aMenuPane->SetItemDimmed(ECmdDeleteCurrency, EFalse);
       
   403 			}
       
   404 		if(count >= KMaxNumberAddCurrency )
       
   405 			{
       
   406 			aMenuPane->SetItemDimmed(ECmdAddCurrency, ETrue);
       
   407 			}
       
   408 		else
       
   409 			{
       
   410 			aMenuPane->SetItemDimmed(ECmdAddCurrency, EFalse);
       
   411 			}
       
   412 		if (!FeatureManager::FeatureSupported(KFeatureIdHelp))
       
   413 			{
       
   414 			aMenuPane->SetItemDimmed(EAknCmdHelp, ETrue);
       
   415 			}
       
   416 		}
       
   417 	}
       
   418 //New methods which will imlement add and delete currency implementation
       
   419 void CCnvRatesForm::AddNewCurrencyL()
       
   420 	{	
       
   421 	//_LIT(KDefaultText,"Foreign");
       
   422 	//TBuf<16> newFieldPtr;
       
   423 	//newFieldPtr.Format(KDefaultText);
       
   424 	HBufC* foreignText = StringLoader::LoadLC( R_QTN_CNV_FOREIGN,iEikonEnv );
       
   425 	TBuf<16> newFieldPtr;
       
   426 	
       
   427 	newFieldPtr.Copy(foreignText->Left(MAXCURRENCYNAMELENGTH));
       
   428 	
       
   429 	TBool nameEntered(EFalse);
       
   430 	TCurrencyType type = 	NewCurrencyNameDialogL( newFieldPtr, nameEntered, ETrue );
       
   431 
       
   432 	TInt id = IdOfFocusControl(); //Get the focus controls id
       
   433 	TInt index = iFormIdMapArray.Find(id); //get the index where the id i
       
   434 	TInt indexOfCurrency = index;
       
   435 	TUint uintindex = indexOfCurrency;//To remove warnings
       
   436 
       
   437 	if( uintindex  >= iCategory.BaseUnit())
       
   438 		{
       
   439 		indexOfCurrency++;
       
   440 		}
       
   441 
       
   442 	if(nameEntered)//Dont add any field if the user cancels the dialog
       
   443 		{
       
   444 		TReal real = 1.0;
       
   445 
       
   446 		iCategory.AddNewCurrencyL( indexOfCurrency + 1, newFieldPtr, real, type);		
       
   447 
       
   448 		//TInt newItemId = 0;
       
   449 		TInt newItemId = iFormIdMapArray[0];
       
   450 
       
   451 		//Get the largest formId present now in the form...
       
   452 		for(TInt i = 0; i < iFormIdMapArray.Count() ; i++ )
       
   453 			{		
       
   454 			if( newItemId  < iFormIdMapArray[i])
       
   455 				newItemId = iFormIdMapArray[i];
       
   456 			}
       
   457 
       
   458 		newItemId++;
       
   459 
       
   460 		//Update the new FormId into the form id map array
       
   461 		if( index + 1 < iFormIdMapArray.Count() )
       
   462 			{
       
   463 			iFormIdMapArray.Insert(newItemId,index + 1 );
       
   464 			}
       
   465 		else
       
   466 			{
       
   467 			iFormIdMapArray.Append(newItemId);
       
   468 			}
       
   469 
       
   470 		//Update the arrray which holds the CEikEdwin ids...
       
   471 		iFormIdEdwinMapArray.Append(newItemId);
       
   472 
       
   473 
       
   474         CCoeControl* control = CreateLineByTypeL(newFieldPtr, ActivePageId(),
       
   475             newItemId , EEikCtFlPtEd, NULL ) ;
       
   476         CEikEdwin* edwin = STATIC_CAST( CEikEdwin*, control );
       
   477 
       
   478         CEikFloatingPointEditor* fpEditor = STATIC_CAST( 
       
   479         CEikFloatingPointEditor*, control );
       
   480         fpEditor->SetMinMax( 0, 9e99 );
       
   481         edwin->ConstructL( EEikEdwinNoHorizScrolling | EEikEdwinResizable, 10, 12, 10 );
       
   482         edwin->SetAknEditorNumericKeymap( EAknEditorConverterNumberModeKeymap );
       
   483 
       
   484         edwin->SetAknEditorAllowedInputModes( EAknEditorNumericInputMode );
       
   485 
       
   486         edwin->SetAknEditorInputMode( EAknEditorNumericInputMode );
       
   487         edwin->SetAknEditorSpecialCharacterTable( 0 );
       
   488 
       
   489         edwin->CreateTextViewL();
       
   490         Line( newItemId )->ActivateL();
       
   491 
       
   492         // Set the editor's value at last and use a number instead of the fixed character.
       
   493         SetFloatEditorValueL( IdOfFocusControl(), 1 );
       
   494 
       
   495 		*iModelChanged = ETrue;
       
   496 		}	
       
   497 		CleanupStack::PopAndDestroy(); // foreignText HBufC
       
   498 	}
       
   499 
       
   500 
       
   501 void CCnvRatesForm::DeleteCurrencyL()
       
   502 	{
       
   503 
       
   504 
       
   505 	TInt LineForDeletion = IdOfFocusControl();
       
   506 
       
   507 	TInt indexOfCurrency = iFormIdMapArray.Find(LineForDeletion);
       
   508 	TUint index = indexOfCurrency; //To remove warnings
       
   509 
       
   510 
       
   511 	if( index >= iCategory.BaseUnit())
       
   512 		{
       
   513 		indexOfCurrency++;
       
   514 		}
       
   515 
       
   516 	const MDesCArray* names = iCategory.MdcArray();
       
   517 
       
   518 		TBuf<16> currentName;
       
   519 	currentName.Copy( names->MdcaPoint( indexOfCurrency ).Left( MAXCURRENCYNAMELENGTH ) );
       
   520 
       
   521 	HBufC* confirmDelete = StringLoader::LoadLC(
       
   522 		R_QTN_CNV_CONFIRM_DELETE,currentName);
       
   523 
       
   524 	CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   525 	dlg->SetPromptL( *confirmDelete);
       
   526 
       
   527 	if( dlg->ExecuteLD( R_CNV_CONFIRMATION_QUERY ) )
       
   528 		{	
       
   529 		SetFormFlag( EDeleting, ETrue );
       
   530 
       
   531 		if (LineForDeletion)
       
   532 			{
       
   533 			iCategory.DeleteCurrencyL( indexOfCurrency );
       
   534 			DeleteLine(LineForDeletion);
       
   535 			//SetFormFlag( EUnsavedEdit, ETrue );
       
   536 			TInt index = iFormIdMapArray.Find(LineForDeletion);
       
   537 			iFormIdMapArray.Remove(index);
       
   538 
       
   539 			if( index  == iFormIdMapArray.Count())
       
   540 				{
       
   541 				iLastUsedEditorId = iFormIdMapArray[index - 1];
       
   542 				}
       
   543 			else
       
   544 				{
       
   545 				iLastUsedEditorId = iFormIdMapArray[index];
       
   546 				}
       
   547 			}
       
   548 
       
   549 		DrawNow();
       
   550 		SetFormFlag( EDeleting, EFalse );
       
   551 		*iModelChanged = ETrue;
       
   552 		}
       
   553 	CleanupStack::PopAndDestroy();	// confirmDelete;
       
   554 	}
       
   555 
       
   556 //This function launches a dialog to get the new currency name.
       
   557 //Note can also be used for Rename Currency, but will be made use, afte the  raised for that has been fixed
       
   558 TCurrencyType  CCnvRatesForm::NewCurrencyNameDialogL( TDes& aField, TBool& aNameEntered,  TBool aIsAddNewCurrency )
       
   559 	{	
       
   560 	TBool nameOk( EFalse );	
       
   561 	TCurrencyType type = ENameChanged;
       
   562   //TInt index = IdOfFocusControl() - 1;
       
   563   TInt controlId = IdOfFocusControl();
       
   564   TInt index = iFormIdMapArray.Find( controlId ); //get the index where the id i
       
   565   TUint uintindex = index ;                    //To remove warnings
       
   566     if ( uintindex  >= iCategory.BaseUnit() )     //get correct index
       
   567         {
       
   568         index++;
       
   569         }
       
   570 
       
   571 	const MDesCArray* names = iCategory.MdcArray();
       
   572 	do
       
   573 		{
       
   574 		CAknTextQueryDialog* dlg =
       
   575 			new( ELeave ) CAknTextQueryDialog( aField );
       
   576 		CleanupStack::PushL(dlg);
       
   577 
       
   578 				if( dlg->ExecuteLD( R_CNV_UNITNAME_QUERY ) != EAknSoftkeyOk )
       
   579 					{
       
   580 					aNameEntered = EFalse;
       
   581 					CleanupStack::Pop(dlg);	// dlg
       
   582 					return type;
       
   583 					}
       
   584 		CleanupStack::Pop(dlg);	// dlg
       
   585 
       
   586 		// Search through all the names to see if the new name already exists
       
   587 		TInt len( names->MdcaCount() );
       
   588 		TBool nameExists( EFalse );
       
   589         //Set the index larger than all when a new is added, make it compare with 
       
   590         //all of the item to judge if the name is already used
       
   591         if ( aIsAddNewCurrency )
       
   592             {
       
   593             index = len;
       
   594             }
       
   595 		
       
   596 		for( TInt i = 0; i < len; i ++ )
       
   597 			{
       
   598 			if( names->MdcaPoint( i ).Compare( aField ) == 0 )
       
   599 				{
       
   600                 if ( i != index )
       
   601                     {
       
   602 				    nameExists = ETrue;
       
   603 				    break;
       
   604 					}
       
   605 				}
       
   606 			}
       
   607 
       
   608 		if( nameExists )
       
   609 			{
       
   610 			// display error
       
   611 			HBufC* label = StringLoader::LoadLC(
       
   612 				R_QTN_FLDR_NAME_ALREADY_USED, aField );
       
   613 			CAknErrorNote* note = new( ELeave ) CAknErrorNote( ETrue );
       
   614 			note->ExecuteLD( *label );
       
   615 			CleanupStack::PopAndDestroy();	// label;
       
   616 			}
       
   617 		else
       
   618 			{
       
   619 			nameOk = ETrue;
       
   620 			}
       
   621 		}
       
   622 
       
   623 	while ( !nameOk );
       
   624 	
       
   625 	HBufC* homeText = StringLoader::LoadLC( R_QTN_CNV_HOME,iEikonEnv );	
       
   626 	HBufC* foreignText = StringLoader::LoadLC( R_QTN_CNV_FOREIGN,iEikonEnv );
       
   627 	TBuf<16> defaultTextPtr;
       
   628 	TBuf<16> homeTextPtr;
       
   629 	TInt equal;
       
   630 	
       
   631 	defaultTextPtr.Copy(foreignText->Left(MAXCURRENCYNAMELENGTH));
       
   632 	homeTextPtr.Copy(homeText->Left(MAXCURRENCYNAMELENGTH));
       
   633 	equal = defaultTextPtr.Compare(aField);
       
   634 	if(equal==0)
       
   635 		type = EForeign;
       
   636 	
       
   637 	equal = homeTextPtr.Compare(aField);
       
   638 	if(equal==0)
       
   639 		type = EHome;
       
   640 
       
   641 	aNameEntered = nameOk;
       
   642 	CleanupStack::PopAndDestroy(); // foreignText HBufC
       
   643 	CleanupStack::PopAndDestroy(); // HomeText HBufC		
       
   644 
       
   645 	return type;
       
   646 	}
       
   647 //
       
   648 //ShowInvalidValueNoteL(TInt aEditorId)
       
   649 //
       
   650 void CCnvRatesForm::ShowInvalidValueNoteL(TInt aEditorId, TBool aSetValue)
       
   651 	{
       
   652 	HBufC* label = iCoeEnv->AllocReadResourceLC(
       
   653 		R_CNV_MAINFORM_INVALIDVALUE );
       
   654 	CAknErrorNote* note = new( ELeave ) CAknErrorNote(ETrue);
       
   655 	note->ExecuteLD( *label );
       
   656 	CleanupStack::PopAndDestroy();	// label;
       
   657 	if ( aSetValue )
       
   658 		{
       
   659 		SetFloatEditorValueL( aEditorId, 0.0 ); 
       
   660 		}
       
   661 	}
       
   662 
       
   663 //
       
   664 //IsVaildNumberEntered(TInt aEditorId)
       
   665 //
       
   666 TBool CCnvRatesForm::IsVaildNumberEntered(TInt aEditorId)
       
   667 	{
       
   668 
       
   669 	CEikFloatingPointEditor* editor =
       
   670 		static_cast< CEikFloatingPointEditor* >( Control( aEditorId ) );
       
   671 
       
   672 	if( editor->TextLength() == 0 )
       
   673 		{
       
   674 		return EFalse;
       
   675 		}	
       
   676 
       
   677 	TReal real;
       
   678 	CAknNumericEdwin::TValidationStatus validationStatus = editor->GetValueAsReal(real);
       
   679 
       
   680   // The enter number is not valid if GetValueAsReal function's return value is not EValueValid 
       
   681 	if( validationStatus != CAknNumericEdwin::EValueValid /* && validationStatus != CAknNumericEdwin::EValueTooLarge */ )
       
   682 		{
       
   683 		return EFalse;
       
   684 		}
       
   685 	return ETrue;
       
   686 
       
   687 	}
       
   688 
       
   689 
       
   690 TBool CCnvRatesForm::OkToExitL(TInt aButtonId)
       
   691 	{
       
   692 	//Check for validity of the rates entered
       
   693 	TInt aControlId( IdOfFocusControl() );			
       
   694 	if(!IsVaildNumberEntered(aControlId))
       
   695 		{
       
   696 		ShowInvalidValueNoteL(aControlId, ETrue );
       
   697 		}
       
   698 	//Check which one of the two buttons'Options' or 'MSK' is pressed
       
   699 	if (aButtonId == EAknSoftkeyOptions && iEKeyOk)
       
   700 		{
       
   701 		//Make the variable False
       
   702 		iEKeyOk = EFalse;
       
   703 		return EFalse;
       
   704 		}
       
   705 	else
       
   706 		// Call the Base Class OkToExitL()
       
   707 		return CAknForm::OkToExitL(aButtonId);
       
   708 
       
   709 	}
       
   710 //
       
   711 //OfferKeyEventL
       
   712 //
       
   713 TKeyResponse CCnvRatesForm::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
       
   714 {
       
   715 	
       
   716 	// Make the variable 'iEKeyOk' to True if and only if MSK is pressed.
       
   717 	if(aKeyEvent.iScanCode == EStdKeyDevice3 && aType == EEventKeyDown)
       
   718 		{
       
   719 		iEKeyOk = ETrue;
       
   720 		}
       
   721 	if(aKeyEvent.iScanCode == EStdKeyDevice0 && aType == EEventKeyDown && iEKeyOk)
       
   722 		{
       
   723 		iEKeyOk = EFalse;
       
   724 		}
       
   725 
       
   726 	
       
   727 	TInt controlId1( IdOfFocusControl() );
       
   728 	if(aType == EEventKeyDown)
       
   729 	{		
       
   730 		if((aKeyEvent.iScanCode == EStdKeyDevice0)
       
   731 		 ||(aKeyEvent.iScanCode == EStdKeyDevice1)||(aKeyEvent.iScanCode == EStdKeyDevice3) )
       
   732 			{			
       
   733 			if(!IsVaildNumberEntered(controlId1))
       
   734 				{				
       
   735 				iError=ETrue;
       
   736 				return EKeyWasConsumed;
       
   737 				}
       
   738 		   	 }
       
   739 	 }	
       
   740 			
       
   741 	if(aType == EEventKeyUp && iError)	
       
   742 	{
       
   743 		if((aKeyEvent.iScanCode == EStdKeyDevice0)
       
   744 		 ||(aKeyEvent.iScanCode == EStdKeyDevice1)||(aKeyEvent.iScanCode == EStdKeyDevice3))
       
   745 			{
       
   746 			ShowInvalidValueNoteL(controlId1, ETrue); 
       
   747 			iError = EFalse;
       
   748 			return EKeyWasConsumed;
       
   749 			}
       
   750 	}
       
   751 
       
   752     // Return EKeyWasNotConsumed if OfferKeyEventL() does not handle any event.	
       
   753     if ( aType != EEventKey )
       
   754         {
       
   755         return EKeyWasNotConsumed;
       
   756         }
       
   757 
       
   758     if ( ( aKeyEvent.iScanCode == EStdKeyDownArrow ) || ( aKeyEvent.iScanCode == EStdKeyUpArrow ) )
       
   759         {			
       
   760         TInt controlId( IdOfFocusControl() );			
       
   761         if ( !IsVaildNumberEntered( controlId ) )
       
   762             {
       
   763             ShowInvalidValueNoteL( controlId, ETrue);
       
   764             return EKeyWasConsumed;
       
   765             }
       
   766         }	
       
   767     return CAknForm::OfferKeyEventL( aKeyEvent, aType );
       
   768 }
       
   769 
       
   770 // ----------------------------------------------------
       
   771 // CCnvRatesForm::IsDigit
       
   772 // Converts the digit from any digit mode (devangiri or arabic) 
       
   773 // to western digit and checks whether it is a valid digit or not.
       
   774 // ----------------------------------------------------
       
   775 //
       
   776 TBool CCnvRatesForm::IsDigit(TUint aChar)
       
   777 	{
       
   778 	TBuf<1> digit;
       
   779 	digit.Append(aChar);
       
   780 	
       
   781 	AknTextUtils::ConvertDigitsTo(digit , EDigitTypeWestern);
       
   782 	
       
   783 	TChar ch = digit[0];
       
   784 	return ch.IsDigit();
       
   785 	}
       
   786 
       
   787 
       
   788 // ----------------------------------------------------
       
   789 // CCnvRatesForm::PrepareForFocusTransitionL
       
   790 // Used for touch UI to display the invalid note if number 
       
   791 // is invalid
       
   792 // ----------------------------------------------------
       
   793 //
       
   794 void CCnvRatesForm::PrepareForFocusTransitionL()
       
   795     {
       
   796     // Check if touch is enabled or not
       
   797     if ( !AknLayoutUtils::PenEnabled() )
       
   798         {
       
   799         CAknForm::PrepareForFocusTransitionL();
       
   800         return;
       
   801         }
       
   802 
       
   803     // Get the focus of the current control line
       
   804     TInt controlId( IdOfFocusControl() );
       
   805     // Check for validity of the rate entered
       
   806     if (!IsVaildNumberEntered( controlId ) )
       
   807         {
       
   808          ShowInvalidValueNoteL(controlId, EFalse);
       
   809         }
       
   810 
       
   811     // Delete the radix point if it is excrescent
       
   812     else
       
   813         {
       
   814         CEikFloatingPointEditor* editor = 
       
   815            static_cast<CEikFloatingPointEditor*> ( Control( controlId ) );
       
   816         TBuf< KEditorTextMaxLength > editorText;
       
   817         editor->GetText( editorText );
       
   818         TInt editorTextLength = editorText.Length();
       
   819         TLocale local;
       
   820         if ( editorText[ editorTextLength - 1 ] == local.DecimalSeparator() )
       
   821             {
       
   822             editorText.Delete( editorTextLength - 1 , 1 );
       
   823             editor->SetTextL( &editorText );
       
   824             }
       
   825         }
       
   826     CAknForm::PrepareForFocusTransitionL();
       
   827     }
       
   828 
       
   829 
       
   830 // ----------------------------------------------------
       
   831 // CCnvRatesForm::ActivateL
       
   832 // Sets the control as ready to be drawn.
       
   833 // ----------------------------------------------------
       
   834 //    
       
   835 void CCnvRatesForm::ActivateL()
       
   836     {
       
   837     CAknForm::ActivateL();
       
   838     CEikFloatingPointEditor* editor =
       
   839         static_cast< CEikFloatingPointEditor* >( Control( IdOfFocusControl() ) );
       
   840     editor->SetCursorPosL( editor->Text()->DocumentLength(), ETrue );
       
   841     }
       
   842 //End of file
       
   843 
       
   844