fep/aknfep/src/aknfepuiinputstateentryhalfqwertyphrase.cpp
changeset 40 2cb9bae34d17
parent 31 f1bdd6b078d1
child 49 37f5d84451bd
equal deleted inserted replaced
31:f1bdd6b078d1 40:2cb9bae34d17
     1 /*
       
     2 * Copyright (c) 2008 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 *       Provides the  TAknFepInputStateEntryMiniQwertyPinyinPhrase methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 
       
    30 #include "AknFepUIManagerStateInterface.h"  //MAknFepUIManagerStateInterface
       
    31 #include "AknFepUiCtrlContainerChinese.h"
       
    32 #include "AknFepManagerUIInterface.h"       //MAknFepManagerUIInterface
       
    33 #include "AknFepUICtrlCandidatePane.h"
       
    34 #include "aknfepuiinputstateentryhalfqwertyphrase.h"
       
    35 
       
    36 #include "AknFepManager.h"                  //FepMan flag
       
    37 #include "AknFepUICtrlInputPane.h"
       
    38 #include "AknFepUICtrlPinyinPopup.h"        //Pinyin phrase
       
    39 #include "AknFepUiCtrlContainerChinese.h"
       
    40 #include <aknfep.rsg>
       
    41 #include <PtiEngine.h>      //CPtiEngine
       
    42 #include <e32keys.h>        //keys  
       
    43 #include <avkon.rsg>
       
    44 
       
    45 const TInt KFnMappedCharacters = 5;
       
    46 const TInt KInputPaneLength = 32;
       
    47 const TText KPinyinTone4Valid = 0x02D9;
       
    48 const TText KPinyinTone4Invalid = 0x0020;
       
    49 const TInt KMaxPhraseCount = 150;
       
    50 
       
    51 //For Pinyin
       
    52 // ---------------------------------------------------------------------------
       
    53 // TAknFepInputStateEntryHalfQwertyPinyinPhrase::TAknFepInputStateEntryHalfQwertyPinyinPhrase
       
    54 // the construt funtion 
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 TAknFepInputStateEntryHalfQwertyPinyinPhrase::TAknFepInputStateEntryHalfQwertyPinyinPhrase(
       
    58                                MAknFepUIManagerStateInterface* aOwner,
       
    59                                MAknFepUICtrlContainerChinese* aUIContainer)
       
    60     :TAknFepInputStateEntryQwertyBaseChinesePhrase(aOwner,aUIContainer)                           
       
    61     {
       
    62     iState = EEntry;
       
    63     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
    64     uiContainer->FocusCandidatePane(EFalse);
       
    65     uiContainer->CandidatePane()->ShowCandidateOrdinals(EFalse);
       
    66     uiContainer->SetLayout(MAknFepUICtrlContainerChinese::ELayoutInput);
       
    67     uiContainer->CandidatePane()->SelectFirstPhrase(); 
       
    68     uiContainer->ShowHorizontalScrollArrows(EFalse); 
       
    69     uiContainer->ShowVerticalScrollArrows(EFalse);
       
    70     uiContainer->InputPane()->SetOverrideFontId(0);
       
    71     // in the case that we are coming back to the input pane from the candidate pane, 
       
    72     // we need to ensure that the current selection is selected correctly
       
    73     ImplicitlyUpdateSelection();
       
    74     UpdateIndicator();
       
    75     ClearDeliberateSelection();
       
    76     iOwner->PtiEngine()->SetInputMode(EPtiEnginePinyinPhraseHalfQwerty);
       
    77     iOwner->PtiEngine()->SetCandidatePageLength(KMaxPhraseCount);
       
    78     iOwner->PtiEngine()->SetCase(EPtiCaseLower);
       
    79     }
       
    80                                
       
    81 // ---------------------------------------------------------------------------
       
    82 // TAknFepUiInputStateCandidateMiniQwertyZhuyinPhrase::HandleKeyL
       
    83 // handle key event
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 TBool TAknFepInputStateEntryHalfQwertyPinyinPhrase::HandleKeyL(TInt aKey, TKeyPressLength aLength)
       
    87     {
       
    88     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
    89     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
    90     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
    91     MAknFepUICtrlCandidatePane* candidatePane = uiContainer->CandidatePane();
       
    92     TBool state = ETrue;
       
    93     TPtrC text;
       
    94     TBool ret = ETrue;
       
    95     if ( aLength == EShortKeyPress )
       
    96     	{
       
    97     	switch (aKey)
       
    98 			{
       
    99 			case EPtiKeyQwerty1:
       
   100 				{
       
   101 				aKey = EPtiKeyQwertyE;
       
   102 				break;
       
   103 			}
       
   104 		case EPtiKeyQwerty2:
       
   105 			{
       
   106 			aKey = EPtiKeyQwertyT;
       
   107 			break;
       
   108 			}
       
   109 		case EPtiKeyQwerty3:
       
   110 			{
       
   111 			aKey = EPtiKeyQwertyU;
       
   112 			break;
       
   113 			}
       
   114 		case EPtiKeyQwerty4:
       
   115 			{
       
   116 			aKey = EPtiKeyQwertyD;
       
   117 			break;
       
   118 			}
       
   119 		case EPtiKeyQwerty5:
       
   120 			{
       
   121 			aKey = EPtiKeyQwertyG;
       
   122 			break;
       
   123 			}
       
   124 		case EPtiKeyQwerty6:
       
   125 			{
       
   126 			aKey = EPtiKeyQwertyJ;
       
   127 			break;
       
   128 			}
       
   129 		case EPtiKeyQwerty7:
       
   130 			{
       
   131 			aKey = EPtiKeyQwertyC;
       
   132 			break;
       
   133 			}
       
   134 		case EPtiKeyQwerty8:
       
   135 			{
       
   136 			aKey = EPtiKeyQwertyB;
       
   137 			break;
       
   138 			}
       
   139 		case EPtiKeyQwerty9:
       
   140 			{
       
   141 			aKey = EPtiKeyQwertyM;
       
   142 			break;
       
   143 			}
       
   144 			case EPtiKeyQwerty0:
       
   145 				{
       
   146 				aKey = EPtiKeyQwertySpace;
       
   147 				break;
       
   148 				}
       
   149 			}
       
   150     	}
       
   151 	
       
   152     if ( aKey != EStdKeyLeftFunc && 
       
   153         (iOwner->FepMan()->IsFlagSet(CAknFepManager::EFlagQwertyChrKeyDepressed) ||
       
   154         iOwner->FepMan()->IsFlagSet(CAknFepManager::EFlagShiftKeyDepressed)))
       
   155         {
       
   156         iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
   157         return ETrue;
       
   158         }
       
   159     if(( aKey == EStdKeyLeftFunc  || aKey == EStdKeyFullStop) && aLength == EShortKeyPress) //chr and punctuation key to tone mark   
       
   160         {
       
   161         if(ptiengine->IncrementToneMark(ETrue))
       
   162             {
       
   163             ImplicitlyUpdateSelection();
       
   164             }
       
   165         }
       
   166     else if( CAknFepFnKeyManager::EFnKeyNext == iOwner->FepMan()->FnKeyState() ||     //
       
   167         CAknFepFnKeyManager::EFnKeyLock == iOwner->FepMan()->FnKeyState() ||
       
   168         CAknFepFnKeyManager::EFnKeyDown == iOwner->FepMan()->FnKeyState())
       
   169         {
       
   170         popup->SetPreStateIsPredictive( EFalse );
       
   171         iOwner->FepMan()->TryCloseUiL();
       
   172         ret = EFalse;
       
   173         }                                                    
       
   174     else if(aKey == EStdKeyBackspace )
       
   175         {
       
   176         if ( popup->IsChangeStatet() && aLength == ELongKeyPress )
       
   177             {
       
   178             state = EFalse;
       
   179             }
       
   180         else
       
   181             {
       
   182             popup->SetChangeState( EFalse );
       
   183             }
       
   184         if ( state )
       
   185             {
       
   186             if (iOwner->PtiEngine()->DeleteKeyPress().Length())
       
   187                 {
       
   188                 ImplicitlyUpdateSelection();
       
   189                 }
       
   190             else
       
   191                 {
       
   192                 iOwner->FepMan()->TryCloseUiL(); //no more keys, close the UI.
       
   193                 popup->SetPreStateIsPredictive( EFalse );
       
   194                 if ( aLength == ELongKeyPress )
       
   195                     {
       
   196                     iOwner->FepMan()->SetLongClearAfterCloseUI(ETrue);
       
   197                     }
       
   198                 }
       
   199             }
       
   200         } 
       
   201     else if(aKey ==EStdKeyDevice1)//sk2
       
   202         {
       
   203         iOwner->FepMan()->TryCloseUiL();
       
   204         popup->SetPreStateIsPredictive( EFalse );
       
   205         }
       
   206     else if(aKey == EStdKeyRightArrow)
       
   207         {
       
   208         if(popup->IsEnabled())
       
   209             {
       
   210             if(popup->SelectNextPhrase())
       
   211                 {
       
   212                 DeliberatelyUpdateSelection();
       
   213                 }
       
   214             }
       
   215         }
       
   216     else if(aKey == EStdKeyLeftArrow)
       
   217         {
       
   218         if(popup->IsEnabled())
       
   219             {
       
   220             if(popup->SelectPrevPhrase())
       
   221                 {
       
   222                 DeliberatelyUpdateSelection();
       
   223                 }
       
   224             }
       
   225         } 
       
   226     else if (aKey == EStdKeyDownArrow
       
   227             || aKey == EStdKeyDevice3
       
   228             || aKey == EStdKeyDevice0
       
   229             ||aKey == EStdKeyEnter) //Downkey,sk1,selection,enter key
       
   230         {
       
   231         if(popup->IsEnabled())
       
   232             {
       
   233             popup->Enable(EFalse);
       
   234             }
       
   235         iOwner->ChangeState(ECandidate);
       
   236         popup->SetPreStateIsPredictive( EFalse );
       
   237         popup->SetChangeState( ETrue );
       
   238         }  
       
   239     else if ( aKey == EStdKeyUpArrow )
       
   240         {
       
   241         if ( !candidatePane->IsFirstPage() )
       
   242             {
       
   243             candidatePane->PreviousCandidatePage();
       
   244             candidatePane->SetCandidateBuffer();
       
   245             candidatePane->SelectFirst();
       
   246             UpdateIndicator();
       
   247             }
       
   248         }
       
   249     else if(aLength == EShortKeyPress) 
       
   250         {
       
   251         iOwner->FepMan()->SetCcpuFlag(CAknFepManager::ECcpuStateIgnoreStarUp);            
       
   252         
       
   253         if(iOwner->IsValidChineseInputKeyQwerty(aKey) || aKey ==EStdKeySpace ) //seperator
       
   254             {
       
   255             TInt stringBeforeLength(0);
       
   256             TInt stringAfterLength(0);
       
   257             stringBeforeLength = ptiengine->GetPhoneticSpelling(1).Length();
       
   258             stringAfterLength = ptiengine->AppendKeyPress((TPtiKey)aKey).Length();
       
   259             if (stringAfterLength==0 && aKey == EPtiKeyQwertyU )  //u,i should not as first character in pinyin
       
   260                {
       
   261                iOwner->FepMan()->TryCloseUiL();
       
   262                popup->SetPreStateIsPredictive( EFalse );
       
   263                iOwner->FepMan()->UpdateCbaL(NULL);
       
   264 //               iOwner->ChangeState(EQwerty);
       
   265                iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
   266                return ETrue;     
       
   267                }
       
   268             if (stringBeforeLength != stringAfterLength)
       
   269                 {
       
   270                 if (ptiengine->GetPhoneticSpelling(1).Length() == 1)
       
   271                     {
       
   272                     iOwner->FepMan()->UpdateCbaL(R_AKNFEP_SOFTKEYS_OK_SELECT_CANCEL);
       
   273                     }
       
   274                 ImplicitlyUpdateSelection();
       
   275                 }
       
   276             else
       
   277                 {
       
   278                 iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
   279                 }
       
   280             }
       
   281         else
       
   282             {
       
   283             iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
   284             }
       
   285         if ( popup->PhoneticSpellingArray()->Count() > 0 &&
       
   286             popup->PhoneticSpellingArray()->MdcaPoint( 0 ).Length() > 1 )
       
   287             {
       
   288             popup->SetPreStateIsPredictive( EFalse );
       
   289             }
       
   290         }
       
   291     else 
       
   292         {
       
   293         if ( popup->GetPreStateIsPredictive() && 
       
   294             popup->PhoneticSpellingArray()->Count() > 0 &&
       
   295         		popup->PhoneticSpellingArray()->MdcaPoint( 0 ).Length() == 1)    //long press fn mode character should inputted
       
   296             {
       
   297             iOwner->FepMan()->TryCloseUiL();
       
   298             popup->SetPreStateIsPredictive( EFalse );
       
   299             if (aKey == EStdKeyEnter)
       
   300                 {
       
   301                 // PtiEngine does not have mapping for the enter key.
       
   302                 const TText KAknFEPLineFeedSymbol = 0x21B2;
       
   303                 TBuf<1> lineFeed;
       
   304                 lineFeed.Zero();
       
   305                 lineFeed.Append(KAknFEPLineFeedSymbol);
       
   306                 text.Set(lineFeed);
       
   307                 }
       
   308             else
       
   309                 {
       
   310                 TBuf<KFnMappedCharacters> allFnMappedCharacters;
       
   311                 ptiengine->MappingDataForKey((TPtiKey)aKey, allFnMappedCharacters, EPtiCaseFnLower);
       
   312                 text.Set(allFnMappedCharacters);
       
   313                 }
       
   314             if (text.Length() > 0)
       
   315                 {
       
   316                 TBuf<1> chr;
       
   317                 chr.Append(text[0]);
       
   318                 iOwner->FepMan()->NewCharacterL(chr);
       
   319                 iOwner->FepMan()->CommitInlineEditL();
       
   320                 ptiengine->ClearCurrentWord();
       
   321                 ret = ETrue;
       
   322                 }
       
   323             }
       
   324         }
       
   325     return ret;
       
   326     }
       
   327 
       
   328 // ---------------------------------------------------------------------------
       
   329 // TAknFepInputStateEntryHalfQwertyPinyinPhrase::DeliberatelyUpdateSelection
       
   330 // DeliberatelyUpdateSelection
       
   331 // ---------------------------------------------------------------------------
       
   332 //
       
   333 void TAknFepInputStateEntryHalfQwertyPinyinPhrase::DeliberatelyUpdateSelection()
       
   334     {
       
   335     TPtr deliberateSelection = iOwner->GetLatestDeliberateSelection();
       
   336     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   337     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   338     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   339     TInt selected = popup->CurrentSelection();
       
   340     ptiengine->EnableToneMarks(EFalse);
       
   341     // our index is zero based, engine index is one based
       
   342     TPtrC spelling = ptiengine->GetPhoneticSpelling(selected + 1); 
       
   343     deliberateSelection = spelling.Left(MAknFepUICtrlInputPane::EMaxInputCharsPinyinPopupNotIncludingToneMark);
       
   344     ptiengine->EnableToneMarks(ETrue);
       
   345     UIContainer()->PinyinPopupWindow()->SetFlag(MAknFepUICtrlPinyinPopup::ESpellingNavigation);    
       
   346     RefreshUI(popup->CurrentVisibleSelection());
       
   347     }
       
   348 
       
   349 // ---------------------------------------------------------------------------
       
   350 // TAknFepInputStateEntryHalfQwertyPinyinPhrase::ImplicitlyUpdateSelection
       
   351 // update the selection
       
   352 // ---------------------------------------------------------------------------
       
   353 //
       
   354 void TAknFepInputStateEntryHalfQwertyPinyinPhrase::ImplicitlyUpdateSelection()
       
   355     {
       
   356     TPtr oldDeliberateSelection = iOwner->GetLatestDeliberateSelection();
       
   357     TInt oldDeliberateSelectionLength = oldDeliberateSelection.Length();
       
   358     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   359     // previously selected is compared in turn to each of the new candidates
       
   360     ptiengine->EnableToneMarks(EFalse);
       
   361     TInt pinyinCount = ptiengine->PhoneticSpellingCount();
       
   362     TInt newSelection = 0;
       
   363     for(TInt i = 0; i < pinyinCount; i++)
       
   364         {
       
   365         TPtrC spelling = ptiengine->GetPhoneticSpelling(i + 1);  // our index is zero based, engine index is one based
       
   366         TInt spellingLength = spelling.Length();
       
   367         // figure out how many characters we are comparing, this depends on the 
       
   368         // direction of the edit
       
   369         TInt compareLength = oldDeliberateSelectionLength <= spellingLength ? 
       
   370             oldDeliberateSelectionLength : spellingLength;
       
   371         if(oldDeliberateSelection.Left(compareLength) == spelling.Left(compareLength))
       
   372             {
       
   373             // as soon as a substring match is found, the 
       
   374             // highlight position is set to that candidate in the new list. 
       
   375             // note that in the case of the first character entered, the
       
   376             // oldBuf will be empty so it will always match... which is 
       
   377             // fine as we want to select the top one anyway, so we will
       
   378             // quit the loop early.
       
   379             newSelection = i;
       
   380             break;
       
   381             }
       
   382         }
       
   383     ptiengine->EnableToneMarks(ETrue);
       
   384     UIContainer()->PinyinPopupWindow()->SetFlag(MAknFepUICtrlPinyinPopup::ESpellingChanged);
       
   385     RefreshUI(newSelection);
       
   386     }
       
   387 
       
   388 // ---------------------------------------------------------------------------
       
   389 // TAknFepInputStateEntryHalfQwertyPinyinPhrase::ClearDeliberateSelection
       
   390 // clear the deliberate selection
       
   391 // ---------------------------------------------------------------------------
       
   392 //
       
   393 void TAknFepInputStateEntryHalfQwertyPinyinPhrase::ClearDeliberateSelection()
       
   394     {
       
   395     MAknFepUICtrlPinyinPopup* popup = UIContainer()->PinyinPopupWindow();
       
   396     TInt spellingCount = popup->PhoneticSpellingArray()->Count();
       
   397     // we must have just deleted the last character, 
       
   398     // or we are starting a new zhuyin session, so wipe the last deliberate selection
       
   399     if ( 0 == spellingCount )
       
   400         {
       
   401         TPtr oldDeliberateSelection = iOwner->GetLatestDeliberateSelection();
       
   402         oldDeliberateSelection = KNullDesC;
       
   403         }
       
   404     }
       
   405 
       
   406 // ---------------------------------------------------------------------------
       
   407 // TAknFepInputStateEntryHalfQwertyPinyinPhrase::RefreshUI
       
   408 // refresh ui 
       
   409 // ---------------------------------------------------------------------------
       
   410 //
       
   411 void TAknFepInputStateEntryHalfQwertyPinyinPhrase::RefreshUI(TInt aSelection)
       
   412     {
       
   413     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   414     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   415     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   416     MAknFepUICtrlInputPane* inputPane = uiContainer->InputPane();   
       
   417     // get cursor position
       
   418     TPoint baseLine = TPoint(0,0);
       
   419     TInt height = 0;
       
   420     TInt ascent = 0;
       
   421     TRAPD(ret,iOwner->FepMan()->GetScreenCoordinatesL(baseLine,height,ascent));
       
   422     if (ret == KErrNone)
       
   423         {
       
   424         uiContainer->SetContainerPosition(baseLine, height);    
       
   425         }
       
   426     TText toneMark;
       
   427     TBool toneMarkEntered = ptiengine->ToneMark(toneMark);
       
   428     TBuf<1> validToneMarkBuf;
       
   429     if(toneMarkEntered)
       
   430         {
       
   431         // override specific invalid tonemark character only, the others are the same character 
       
   432         // when both valid and invalid
       
   433         if(toneMark == KPinyinTone4Invalid)
       
   434             toneMark = KPinyinTone4Valid;
       
   435         validToneMarkBuf.Append(toneMark);
       
   436         }
       
   437     // to start with, disable the tone marks so we can get the list of all zhuyin matches
       
   438     // later we will figure out which ones are invalid
       
   439     ptiengine->EnableToneMarks(EFalse);
       
   440     TInt pinyinCountWithoutToneMarks = ptiengine->PhoneticSpellingCount();
       
   441     if(pinyinCountWithoutToneMarks > 0)
       
   442         {
       
   443         if(popup->IsFlagSet(MAknFepUICtrlPinyinPopup::ESpellingChanged))
       
   444             {
       
   445             CDesCArrayFlat* spelling = popup->PhoneticSpellingArray();
       
   446             TRAPD(ignore, ptiengine->GetPhoneticSpellingsL(*spelling));
       
   447             if (ignore != KErrNone)
       
   448                 {
       
   449                 return;
       
   450                 }
       
   451             popup->SplitPhraseSpellingIntoPages(); 
       
   452             }
       
   453         // set display page for delibrate selection
       
   454         popup->SetDisplayPage(aSelection);
       
   455         popup->SetPhraseItemTexts();
       
   456         // fill in input pane although it's invisible
       
   457         inputPane->SetText(ptiengine->GetPhoneticSpelling(popup->CurrentSelection() + 1));
       
   458         popup->PopupSizeChanged(); // phrase input
       
   459         }
       
   460     // turn tone marks back on so that we know where we are.
       
   461     ptiengine->EnableToneMarks(ETrue);
       
   462     // this is where we start to figure out whether the tonemarks are valid,
       
   463     // whether the selected tonemark is valid, and what is the index of the 
       
   464     // selected candidate in the list of candidates with tonemarks...
       
   465     TBool selectionToneMarkValid = EFalse;
       
   466     TInt selectionIndexAdjustedForToneMarkValidity = popup->CurrentSelection();
       
   467     // we only need to deal with tone marks if there is one
       
   468     if(toneMarkEntered)
       
   469         {
       
   470         if(pinyinCountWithoutToneMarks > 0)
       
   471             {
       
   472             for(TInt i = 0; i < pinyinCountWithoutToneMarks; i++)
       
   473                 {
       
   474                 TBool valid = EFalse;
       
   475                 
       
   476                 TBuf<MAknFepUICtrlInputPane::EMaxInputCharsPinyinPopupNotIncludingToneMark> nextCandidateWithoutToneMark;
       
   477                 nextCandidateWithoutToneMark.Copy(ptiengine->GetPhoneticSpelling
       
   478                     (i + 1).Left(MAknFepUICtrlInputPane::EMaxInputCharsPinyinPopupNotIncludingToneMark));
       
   479                 ptiengine->EnableToneMarks(EFalse); 
       
   480                 ptiengine->SelectPhoneticSpelling(i + 1);
       
   481                 valid = ptiengine->IsToneMarkValidForSpelling();
       
   482                 if(valid)
       
   483                     {
       
   484                     ptiengine->EnableToneMarks(ETrue); 
       
   485                     TInt pinyinCountWithToneMarks = ptiengine->PhoneticSpellingCount();
       
   486                     for(TInt j = 0; j < pinyinCountWithToneMarks; j++)
       
   487                         {
       
   488                         // use j here not i as we are looking at the list with tonemarks
       
   489                         TPtrC nextCandidateWithToneMark = ptiengine->GetPhoneticSpelling(j + 1);  
       
   490                         if(nextCandidateWithToneMark == nextCandidateWithoutToneMark)
       
   491                             {
       
   492                             if(i == aSelection)
       
   493                                 {
       
   494                                 selectionToneMarkValid = ETrue;
       
   495                                 
       
   496                                 // fill in input pane even if it can't be seen, for when we have to hide popup window
       
   497                                 inputPane->SetText(nextCandidateWithoutToneMark);
       
   498                                 }
       
   499                             break;
       
   500                             }
       
   501                         }
       
   502                     }
       
   503                 }
       
   504             }
       
   505         }
       
   506     ptiengine->EnableToneMarks(EFalse); 
       
   507     ptiengine->SelectPhoneticSpelling(popup->CurrentSelection() + 1); 
       
   508     // next two lines are for tonemark validity
       
   509     ptiengine->EnableToneMarks(selectionToneMarkValid); 
       
   510     ptiengine->SelectPhoneticSpelling(selectionIndexAdjustedForToneMarkValidity + 1); // our index is zero based, engine index is one based
       
   511     // update the candidate pane.
       
   512     if(popup->IsFlagSet(MAknFepUICtrlPinyinPopup::ESpellingChanged) 
       
   513         || popup->IsFlagSet(MAknFepUICtrlPinyinPopup::ESpellingNavigation))
       
   514         {
       
   515         TRAPD(ignore, ptiengine->GetChinesePhraseCandidatesL(*(uiContainer->CandidatePane()->CandidateArray())));
       
   516         if (ignore != KErrNone)
       
   517             {
       
   518             return;
       
   519             }
       
   520         uiContainer->CandidatePane()->SplitPhraseCandidatesIntoPages(); 
       
   521         popup->ClearFlag(MAknFepUICtrlPinyinPopup::ESpellingChanged 
       
   522                         | MAknFepUICtrlPinyinPopup::ESpellingNavigation);
       
   523         }
       
   524     uiContainer->CandidatePane()->SetCandidateBuffer();
       
   525     uiContainer->Enable(ETrue);
       
   526     // need to enable the pinyin popup after the container so that it is raised to the front
       
   527     popup->Enable(pinyinCountWithoutToneMarks > 0);
       
   528     UpdateIndicator();
       
   529     }
       
   530 
       
   531 // ---------------------------------------------------------------------------
       
   532 // TAknFepInputStateEntryHalfQwertyPinyinPhrase::InitializeStateL
       
   533 // updata the cba 
       
   534 // ---------------------------------------------------------------------------
       
   535 //
       
   536 void TAknFepInputStateEntryHalfQwertyPinyinPhrase::InitializeStateL(void)
       
   537     {
       
   538     iOwner->FepMan()->UpdateCbaL( R_AKNFEP_SOFTKEYS_OK_SELECT_CANCEL );
       
   539     }
       
   540 
       
   541 // ---------------------------------------------------------------------------
       
   542 // TAknFepInputStateEntryHalfQwertyPinyinPhrase::UpdateIndicator
       
   543 // updata the indicator
       
   544 // ---------------------------------------------------------------------------
       
   545 //
       
   546 void TAknFepInputStateEntryHalfQwertyPinyinPhrase::UpdateIndicator()
       
   547     {
       
   548     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();        
       
   549 
       
   550     uiContainer->CandidatePane()->ShowUpScrollArrows(EFalse);    
       
   551     uiContainer->CandidatePane()->ShowDownScrollArrows(EFalse);     
       
   552     uiContainer->CandidatePane()->ShowLeftScrollArrows(EFalse);
       
   553     uiContainer->CandidatePane()->ShowRightScrollArrows(EFalse);        
       
   554     }
       
   555 
       
   556 // ---------------------------------------------------------------------------
       
   557 // TAknFepInputStateEntryHalfQwertyPinyinPhrase::IsCharacterKey
       
   558 // to check whether the key is character or not
       
   559 // ---------------------------------------------------------------------------
       
   560 //
       
   561 TBool TAknFepInputStateEntryHalfQwertyPinyinPhrase::IsCharacterKey(
       
   562     const TInt aKey )
       
   563     {
       
   564     CPtiEngine* ptiengine = iOwner->PtiEngine( );
       
   565     // Max length doesn't matter because we'll need only the first character.    
       
   566     TBuf<KMaxName> lowerdata;
       
   567     ptiengine->MappingDataForKey( (TPtiKey)aKey, lowerdata, EPtiCaseLower );
       
   568     if ( lowerdata.Length( ) > 0 )
       
   569         {
       
   570         TChar lower = lowerdata[0];
       
   571         TUint upper = lower.GetUpperCase( );
       
   572         if ( TUint( lower ) != upper )
       
   573             {
       
   574             return ETrue;
       
   575             }
       
   576         }
       
   577     return EFalse;
       
   578     }
       
   579 
       
   580 //For stroke
       
   581 // ---------------------------------------------------------------------------
       
   582 // TAknFepInputStateEntryHalfQwertyStrokePhrase::TAknFepInputStateEntryHalfQwertyStrokePhrase
       
   583 // the construt funtion 
       
   584 // ---------------------------------------------------------------------------
       
   585 //
       
   586 TAknFepInputStateEntryHalfQwertyStrokePhrase::TAknFepInputStateEntryHalfQwertyStrokePhrase(
       
   587                                MAknFepUIManagerStateInterface* aOwner,
       
   588                                MAknFepUICtrlContainerChinese* aUIContainer)
       
   589     :TAknFepInputStateEntryQwertyBaseChinesePhrase(aOwner,aUIContainer)                           
       
   590     {
       
   591     iState = EEntry;
       
   592     iOwner->PtiEngine()->SetInputMode( EPtiEngineStrokePhraseHalfQwerty );
       
   593     iOwner->PtiEngine()->SetCase( EPtiCaseLower );
       
   594     iOwner->PtiEngine()->SetCandidatePageLength( KMaxPhraseCount );
       
   595     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   596     TBool multiplePages = !(uiContainer->CandidatePane()->IsLastPage() &&
       
   597                             uiContainer->CandidatePane()->IsFirstPage());
       
   598     uiContainer->ShowHorizontalScrollArrows(EFalse); 
       
   599     uiContainer->ShowVerticalScrollArrows(multiplePages);
       
   600     uiContainer->CandidatePane()->ShowCandidateOrdinals( EFalse );
       
   601     UpdateIndicator();
       
   602     }
       
   603                                
       
   604 //For stroke
       
   605 // ---------------------------------------------------------------------------
       
   606 // TAknFepInputStateEntryHalfQwertyStrokePhrase::HandleKeyL
       
   607 // handle the key event of stroke 
       
   608 // ---------------------------------------------------------------------------
       
   609 //
       
   610 TBool TAknFepInputStateEntryHalfQwertyStrokePhrase::HandleKeyL(TInt aKey,
       
   611         TKeyPressLength aLength )
       
   612     {
       
   613     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   614     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   615     MAknFepUICtrlInputPane* inputPane = uiContainer->InputPane();
       
   616     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   617     MAknFepUICtrlCandidatePane* candidatePane = uiContainer->CandidatePane();
       
   618     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   619     TBuf<KInputPaneLength> currentText;
       
   620     TPtrC text;
       
   621     TBool state = ETrue;
       
   622     TInt spellingLen = 0;
       
   623     TBool ret = ETrue;
       
   624     
       
   625     if ( aKey == EPtiKeyQwerty0 )
       
   626     	{
       
   627     	aKey = EPtiKeyQwertySpace;
       
   628     	}
       
   629    
       
   630     if ( aKey != EStdKeyLeftFunc && 
       
   631         (iOwner->FepMan()->IsFlagSet(CAknFepManager::EFlagQwertyChrKeyDepressed) ||
       
   632         iOwner->FepMan()->IsFlagSet(CAknFepManager::EFlagShiftKeyDepressed)))
       
   633         {
       
   634         iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
   635         return ETrue;
       
   636         }
       
   637     switch (aKey)
       
   638         {
       
   639         case EStdKeyBackspace:
       
   640             {
       
   641             if (popup->IsChangeStatet() && aLength == ELongKeyPress)
       
   642                 {
       
   643                 state = EFalse;
       
   644                 }
       
   645             else
       
   646                 {
       
   647                 popup->SetChangeState(EFalse);
       
   648                 }
       
   649             if (state)
       
   650                 {
       
   651                 if (iOwner->PtiEngine()->DeleteKeyPress().Length())
       
   652                     {
       
   653                     inputPane->SetFlag(MAknFepUICtrlInputPane::EPhoneticChanged);
       
   654                     RefreshUI();
       
   655                     }
       
   656                 else
       
   657                     {
       
   658                     iOwner->FepMan()->TryCloseUiL(); //no more keys, close the UI.
       
   659                     popup->SetPreStateIsPredictive( EFalse );
       
   660                     if (aLength == ELongKeyPress)
       
   661                         {
       
   662                         iOwner->FepMan()->SetLongClearAfterCloseUI(ETrue);
       
   663                         }
       
   664                     }
       
   665                 }
       
   666             break;
       
   667             }
       
   668         case EStdKeyDevice1://sk2
       
   669             {
       
   670             iOwner->FepMan()->TryCloseUiL();
       
   671             popup->SetPreStateIsPredictive( EFalse );
       
   672             break;
       
   673             }
       
   674         case EStdKeyUpArrow:
       
   675             {
       
   676             if ( !candidatePane->IsFirstPage() )
       
   677                 {
       
   678                 candidatePane->PreviousCandidatePage();
       
   679                 candidatePane->SetCandidateBuffer();
       
   680                 candidatePane->SelectFirst();
       
   681                 UpdateIndicator();
       
   682                 }
       
   683             break;
       
   684             }
       
   685         case EStdKeyRightArrow:
       
   686             {
       
   687             if (candidatePane->VisibleCandidateCount()!= 1)
       
   688                 {
       
   689                 iOwner->ChangeState(ECandidate);
       
   690                 popup->SetPreStateIsPredictive( EFalse );
       
   691                 candidatePane->SelectNext();
       
   692                 }
       
   693             break;
       
   694             }
       
   695         case EStdKeyLeftArrow:
       
   696             {
       
   697             if (candidatePane->VisibleCandidateCount()!= 1)
       
   698                 {
       
   699                 iOwner->ChangeState(ECandidate);
       
   700                 popup->SetPreStateIsPredictive( EFalse );
       
   701                 TInt numbertotal = UIContainer()->CandidatePane()->VisibleCandidateCount();
       
   702                 UIContainer()->CandidatePane()->SelectIndex(numbertotal-1);
       
   703                 }
       
   704             break;
       
   705             }
       
   706         case EStdKeyDownArrow:
       
   707             {
       
   708             if ( candidatePane->IsLastPage() )
       
   709                 {
       
   710                 return ETrue;
       
   711                 }
       
   712             if ( candidatePane->NeedGetNewCandidatePage( ) )
       
   713                 {
       
   714                 if ( !iOwner->PtiEngine()->NextCandidatePage( ) )
       
   715                     {
       
   716                     if ( candidatePane->IsLastPage() )
       
   717                         {
       
   718                         iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   719                         return ETrue;
       
   720                         }
       
   721                     }
       
   722                 else
       
   723                     {
       
   724                     CDesCArrayFlat* phraseCandidates =
       
   725                         candidatePane->CandidateArray( );
       
   726                     RPointerArray<HBufC> list;
       
   727                     GetNewCandidatesL( iOwner->PtiEngine()->CandidatePage( ), list );
       
   728                     for (TInt i = 0; i < list.Count( ); ++i )
       
   729                         {
       
   730                         phraseCandidates->AppendL( *(list[i]) );
       
   731                         }
       
   732                     list.ResetAndDestroy();
       
   733                     }
       
   734                 }
       
   735             candidatePane->NextCandidatePage();
       
   736             candidatePane->SetCandidateBuffer();
       
   737             candidatePane->SelectFirstPhrase();
       
   738             UpdateIndicator();
       
   739             break;
       
   740             }
       
   741         case EStdKeyDevice3://Select
       
   742         case EStdKeyDevice0://sk1
       
   743         case EStdKeyEnter:
       
   744             {
       
   745             uiContainer->PinyinPopupWindow()->Enable(EFalse);
       
   746             TPtrC currentPhraseText = UIContainer()->CandidatePane()->CurrentPhraseCandidate();
       
   747             if(currentPhraseText.Length())
       
   748                 {            
       
   749                 fepMan->NewTextL(currentPhraseText);
       
   750                 fepMan->CommitInlineEditL();
       
   751                 iOwner->PtiEngine()->SetPredictiveChineseChar(currentPhraseText);
       
   752                 if (fepMan->IsFlagSet(CAknFepManager::EFlagEditorFull))
       
   753                     {
       
   754                     fepMan->ClearFlag(CAknFepManager::EFlagEditorFull);
       
   755                     iOwner->FepMan()->TryCloseUiL();
       
   756                     popup->SetPreStateIsPredictive( EFalse );
       
   757                     }
       
   758                 else
       
   759                     {
       
   760                     iOwner->ChangeState(EPredictiveCandidate);
       
   761                     popup->SetPreStateIsPredictive( EFalse );
       
   762                     }
       
   763                 }
       
   764             break;
       
   765             }
       
   766         default:
       
   767             {
       
   768             if (aLength == EShortKeyPress)
       
   769                 {
       
   770                 iOwner->FepMan()->SetCcpuFlag(CAknFepManager::ECcpuStateIgnoreStarUp);
       
   771                 if (iOwner->IsValidChineseInputKeyQwerty(aKey) ||
       
   772                         aKey ==EStdKeySpace ||
       
   773                         aKey == EStdKeyFullStop ||
       
   774                         aKey == EStdKeyLeftFunc ) //seperator
       
   775                     {
       
   776                     TInt stringBeforeLength(0);
       
   777                     TInt stringAfterLength(0);
       
   778                     stringBeforeLength = ptiengine->GetPhoneticSpelling(1).Length();
       
   779                     stringAfterLength = ptiengine->AppendKeyPress((TPtiKey)aKey).Length();
       
   780                     if (stringBeforeLength != stringAfterLength)
       
   781                         {
       
   782                         if (ptiengine->GetPhoneticSpelling(1).Length() == 1)
       
   783                             {
       
   784                             iOwner->FepMan()->UpdateCbaL(R_AKNFEP_SOFTKEYS_OK_SELECT_CANCEL);
       
   785                             }
       
   786                         inputPane->SetFlag(MAknFepUICtrlInputPane::EPhoneticChanged);
       
   787                         RefreshUI();
       
   788                         }
       
   789                     else
       
   790                         {
       
   791                         iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
   792                         }
       
   793                     }
       
   794                 else
       
   795                     {
       
   796                     iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
   797                     }
       
   798                 inputPane->GetText(currentText);
       
   799                 spellingLen = currentText.Length();
       
   800                 if ( spellingLen > 1 )
       
   801                     {
       
   802                     popup->SetPreStateIsPredictive( EFalse );
       
   803                     }
       
   804                 }
       
   805             else if ( popup->GetPreStateIsPredictive() && 0 == spellingLen)  //long press fn mode character should inputted
       
   806                 {
       
   807                 iOwner->FepMan()->TryCloseUiL();
       
   808                 popup->SetPreStateIsPredictive( EFalse );
       
   809 
       
   810                 TBuf<KFnMappedCharacters> allFnMappedCharacters;
       
   811                 ptiengine->MappingDataForKey( (TPtiKey)aKey,
       
   812                     allFnMappedCharacters, EPtiCaseFnLower );
       
   813                 text.Set( allFnMappedCharacters );
       
   814                 if ( text.Length( ) > 0 )
       
   815                     {
       
   816                     TBuf<1> chr;
       
   817                     chr.Append( text[0] );
       
   818                     iOwner->FepMan()->NewCharacterL( chr );
       
   819                     iOwner->FepMan()->CommitInlineEditL();
       
   820                     ptiengine->ClearCurrentWord();
       
   821                     ret = ETrue;
       
   822                     }
       
   823                 }
       
   824             }
       
   825         }
       
   826     return ret;
       
   827     }
       
   828 
       
   829 // ---------------------------------------------------------------------------
       
   830 // TAknFepInputStateEntryHalfQwertyStrokePhrase::InitializeStateL
       
   831 // change the cba 
       
   832 // ---------------------------------------------------------------------------
       
   833 //
       
   834 void TAknFepInputStateEntryHalfQwertyStrokePhrase::InitializeStateL(void)
       
   835     {
       
   836     iOwner->FepMan()->UpdateCbaL(R_AKNFEP_SOFTKEYS_OK_SELECT_CANCEL);
       
   837     }
       
   838 
       
   839 // ---------------------------------------------------------------------------
       
   840 // TAknFepInputStateEntryHalfQwertyStrokePhrase::IsCharacterKey
       
   841 // to check whether the key is character or not
       
   842 // ---------------------------------------------------------------------------
       
   843 //
       
   844 TBool TAknFepInputStateEntryHalfQwertyStrokePhrase::IsCharacterKey(
       
   845     const TInt aKey )
       
   846     {
       
   847     CPtiEngine* ptiengine = iOwner->PtiEngine( );
       
   848     // Max length doesn't matter because we'll need only the first character.    
       
   849     TBuf<KMaxName> lowerdata;
       
   850     ptiengine->MappingDataForKey( (TPtiKey)aKey, lowerdata, EPtiCaseLower );
       
   851     if ( lowerdata.Length( ) > 0 )
       
   852         {
       
   853         TChar lower = lowerdata[0];
       
   854         TUint upper = lower.GetUpperCase( );
       
   855 
       
   856         if ( TUint( lower ) != upper )
       
   857             {
       
   858             return ETrue;
       
   859             }
       
   860         }
       
   861 
       
   862     return EFalse;
       
   863     }   
       
   864 
       
   865 // ---------------------------------------------------------------------------
       
   866 // TAknFepInputStateEntryHalfQwertyStrokePhrase::UpdateIndicator
       
   867 // updata the indicator
       
   868 // ---------------------------------------------------------------------------
       
   869 //
       
   870 void TAknFepInputStateEntryHalfQwertyStrokePhrase::UpdateIndicator()
       
   871     {
       
   872     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();        
       
   873     MAknFepUICtrlCandidatePane* candidatePane = uiContainer->CandidatePane();
       
   874     
       
   875     if (candidatePane->IsFirstPage())
       
   876         {
       
   877         uiContainer->CandidatePane()->ShowUpScrollArrows(EFalse);    
       
   878         }
       
   879     else
       
   880         {
       
   881         uiContainer->CandidatePane()->ShowUpScrollArrows(ETrue);    
       
   882         }
       
   883     if (candidatePane->IsLastPage())
       
   884         {
       
   885         uiContainer->CandidatePane()->ShowDownScrollArrows(EFalse);     
       
   886         }
       
   887     else
       
   888         {
       
   889         uiContainer->CandidatePane()->ShowDownScrollArrows(ETrue);      
       
   890         }
       
   891 
       
   892     uiContainer->CandidatePane()->ShowLeftScrollArrows(EFalse);
       
   893     uiContainer->CandidatePane()->ShowRightScrollArrows(EFalse);   
       
   894     }
       
   895 
       
   896 //for zhuyin
       
   897 // ---------------------------------------------------------------------------
       
   898 // TAknFepInputStateEntryHalfQwertyZhuyinPhrase::TAknFepInputStateEntryHalfQwertyZhuyinPhrase
       
   899 // c++ construct funtion
       
   900 // ---------------------------------------------------------------------------
       
   901 //
       
   902 TAknFepInputStateEntryHalfQwertyZhuyinPhrase::TAknFepInputStateEntryHalfQwertyZhuyinPhrase(
       
   903                                 MAknFepUIManagerStateInterface* aOwner,
       
   904                                 MAknFepUICtrlContainerChinese* aUIContainer)
       
   905     :TAknFepInputStateEntryQwertyBaseChinesePhrase(aOwner, aUIContainer)
       
   906     {
       
   907     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   908     uiContainer->SetLayout(MAknFepUICtrlContainerChinese::ELayoutInput);
       
   909     uiContainer->CandidatePane()->SelectFirstPhrase(); 
       
   910     uiContainer->InputPane()->SetOverrideFontId(0);
       
   911     uiContainer->CandidatePane()->ShowCandidateOrdinals( EFalse );
       
   912     TBool multiplePages = !(uiContainer->CandidatePane()->IsLastPage() &&
       
   913                             uiContainer->CandidatePane()->IsFirstPage());
       
   914     uiContainer->ShowHorizontalScrollArrows(EFalse); 
       
   915     uiContainer->ShowVerticalScrollArrows(multiplePages);
       
   916     iOwner->PtiEngine()->SetInputMode( EPtiEngineZhuyinPhraseHalfQwerty );
       
   917     iOwner->PtiEngine()->SetCase( EPtiCaseLower );
       
   918     UpdateIndicator();
       
   919     }
       
   920 
       
   921 // ---------------------------------------------------------------------------
       
   922 // TAknFepInputStateEntryHalfQwertyZhuyinPhrase::HandleKeyL
       
   923 // handle the key of zhuyin 
       
   924 // ---------------------------------------------------------------------------
       
   925 //
       
   926 TBool TAknFepInputStateEntryHalfQwertyZhuyinPhrase::HandleKeyL(TInt aKey, TKeyPressLength aLength)
       
   927     {
       
   928     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   929     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   930     MAknFepUICtrlInputPane* inputPane = uiContainer->InputPane();
       
   931     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   932     MAknFepUICtrlCandidatePane* candidatePane = uiContainer->CandidatePane();
       
   933     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   934     TInt originalKey = aKey;
       
   935     TPtrC text;
       
   936     TInt spellingLen = 0;
       
   937     TBool state = ETrue;
       
   938     TBool ret = ETrue;
       
   939     TBuf<KInputPaneLength> currentText;
       
   940     if ( aKey != EStdKeyLeftFunc && 
       
   941         (iOwner->FepMan()->IsFlagSet(CAknFepManager::EFlagQwertyChrKeyDepressed) ||
       
   942         iOwner->FepMan()->IsFlagSet(CAknFepManager::EFlagShiftKeyDepressed)))
       
   943         {
       
   944         iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
   945         return ETrue;
       
   946         }
       
   947     switch (aKey)
       
   948         {
       
   949         case EPtiKeyQwertyE:
       
   950             aKey = EPtiKey1;
       
   951             break;
       
   952         case EPtiKeyQwertyT:
       
   953             aKey = EPtiKey2;
       
   954             break;
       
   955         case EPtiKeyQwertyU:
       
   956             aKey = EPtiKey3;
       
   957             break;
       
   958         case EPtiKeyQwertyD:
       
   959             aKey = EPtiKey4;
       
   960             break;
       
   961         case EPtiKeyQwertyG:
       
   962             aKey = EPtiKey5;
       
   963             break;
       
   964         case EPtiKeyQwertyJ:
       
   965             aKey = EPtiKey6;
       
   966             break;
       
   967         case EPtiKeyQwertyC:
       
   968             aKey = EPtiKey7;
       
   969             break;
       
   970         case EPtiKeyQwertyB:
       
   971             aKey = EPtiKey8;
       
   972             break;
       
   973         case EPtiKeyQwertyM:
       
   974             aKey = EPtiKey9;
       
   975             break;
       
   976         case EPtiKeyQwertySpace:
       
   977             aKey = EPtiKey0;
       
   978             break;
       
   979         }
       
   980     if( (aKey == EStdKeyLeftFunc || aKey == EStdKeyFullStop )&& 
       
   981             aLength == EShortKeyPress )
       
   982         {
       
   983         if( ptiengine->IncrementToneMark( ETrue ) )
       
   984             {
       
   985             inputPane->SetFlag( MAknFepUICtrlInputPane::EPhoneticChanged );
       
   986             RefreshUI();
       
   987             return ETrue;
       
   988             }
       
   989         }
       
   990     switch (aKey)
       
   991         {
       
   992         case EStdKeyBackspace:
       
   993             {
       
   994             if (popup->IsChangeStatet() && aLength == ELongKeyPress)
       
   995                 {
       
   996                 state = EFalse;
       
   997                 }
       
   998             else
       
   999                 {
       
  1000                 popup->SetChangeState(EFalse);
       
  1001                 }
       
  1002             if (state)
       
  1003                 {
       
  1004                 if (iOwner->PtiEngine()->DeleteKeyPress().Length())
       
  1005                     {
       
  1006                     inputPane->SetFlag(MAknFepUICtrlInputPane::EPhoneticChanged);
       
  1007                     RefreshUI();
       
  1008                     }
       
  1009                 else
       
  1010                     {
       
  1011                     iOwner->FepMan()->TryCloseUiL(); //no more keys, close the UI.
       
  1012                     popup->SetPreStateIsPredictive( EFalse );
       
  1013                     if (aLength == ELongKeyPress)
       
  1014                         {
       
  1015                         iOwner->FepMan()->SetLongClearAfterCloseUI(ETrue);
       
  1016                         }
       
  1017                     }
       
  1018                 }
       
  1019             break;
       
  1020             }
       
  1021         case EStdKeyDevice1://sk2
       
  1022             {
       
  1023             iOwner->FepMan()->TryCloseUiL();
       
  1024             popup->SetPreStateIsPredictive( EFalse );
       
  1025             break;
       
  1026             }
       
  1027         case EStdKeyUpArrow:
       
  1028             {
       
  1029             if ( !candidatePane->IsFirstPage() )
       
  1030                 {
       
  1031                 candidatePane->PreviousCandidatePage();
       
  1032                 candidatePane->SetCandidateBuffer();
       
  1033                 candidatePane->SelectFirst();
       
  1034                 UpdateIndicator();
       
  1035                 }
       
  1036             break;
       
  1037             }
       
  1038         case EStdKeyRightArrow:
       
  1039             {
       
  1040             if (candidatePane->VisibleCandidateCount()!= 1)
       
  1041                 {
       
  1042                 iOwner->ChangeState(ECandidate);
       
  1043                 popup->SetPreStateIsPredictive( EFalse );
       
  1044                 candidatePane->SelectNext();
       
  1045                 }
       
  1046             break;
       
  1047             }
       
  1048         case EStdKeyLeftArrow:
       
  1049             {
       
  1050             if (candidatePane->VisibleCandidateCount()!= 1)
       
  1051                 {
       
  1052                 iOwner->ChangeState(ECandidate);
       
  1053                 popup->SetPreStateIsPredictive( EFalse );
       
  1054                 TInt numbertotal = UIContainer()->CandidatePane()->VisibleCandidateCount();
       
  1055                 UIContainer()->CandidatePane()->SelectIndex(numbertotal-1);
       
  1056                 }
       
  1057             break;
       
  1058             }
       
  1059         case EStdKeyDownArrow:
       
  1060             {
       
  1061             if ( candidatePane->IsLastPage() )
       
  1062                 {
       
  1063                 return ETrue;
       
  1064                 }
       
  1065             if ( candidatePane->NeedGetNewCandidatePage( ) )
       
  1066                 {
       
  1067                 if ( !iOwner->PtiEngine()->NextCandidatePage( ) )
       
  1068                     {
       
  1069                     if ( candidatePane->IsLastPage() )
       
  1070                         {
       
  1071                         iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
  1072                         return ETrue;
       
  1073                         }
       
  1074                     }
       
  1075                 else
       
  1076                     {
       
  1077                     CDesCArrayFlat* phraseCandidates =
       
  1078                         candidatePane->CandidateArray( );
       
  1079                     RPointerArray<HBufC> list;
       
  1080                     GetNewCandidatesL( iOwner->PtiEngine()->CandidatePage( ), list );
       
  1081                     for (TInt i = 0; i < list.Count( ); ++i )
       
  1082                         {
       
  1083                         phraseCandidates->AppendL( *(list[i]) );
       
  1084                         }
       
  1085                     list.ResetAndDestroy();
       
  1086                     }
       
  1087                 }
       
  1088             candidatePane->NextCandidatePage();
       
  1089             candidatePane->SetCandidateBuffer();
       
  1090             candidatePane->SelectFirstPhrase();
       
  1091             UpdateIndicator();
       
  1092             break;
       
  1093             }
       
  1094         case EStdKeyDevice3://Select
       
  1095         case EStdKeyDevice0://sk1
       
  1096         case EStdKeyEnter:
       
  1097             {
       
  1098             uiContainer->PinyinPopupWindow()->Enable(EFalse);
       
  1099             TPtrC phraseText = UIContainer()->CandidatePane()->CurrentPhraseCandidate();
       
  1100             if(phraseText.Length())
       
  1101                 {            
       
  1102                 fepMan->NewTextL(phraseText);
       
  1103                 fepMan->CommitInlineEditL();
       
  1104                 iOwner->PtiEngine()->SetPredictiveChineseChar(phraseText);
       
  1105                 if (fepMan->IsFlagSet(CAknFepManager::EFlagEditorFull))
       
  1106                     {
       
  1107                     fepMan->ClearFlag(CAknFepManager::EFlagEditorFull);
       
  1108                     iOwner->FepMan()->TryCloseUiL();
       
  1109                     popup->SetPreStateIsPredictive( EFalse );
       
  1110                     }
       
  1111                 else
       
  1112                     {
       
  1113                     iOwner->ChangeState(EPredictiveCandidate);
       
  1114                     popup->SetPreStateIsPredictive( EFalse );
       
  1115                     }
       
  1116                 }
       
  1117             break;
       
  1118             }
       
  1119         case EPtiKeyQwertyQ:
       
  1120         case EPtiKeyQwertyA:
       
  1121         case EPtiKeyQwertyO:
       
  1122         case EPtiKeyQwertyL:
       
  1123         case EPtiKeyQwertyZ:
       
  1124             {
       
  1125             ret = ETrue;
       
  1126             break;
       
  1127             }
       
  1128         default:
       
  1129             {
       
  1130             if (aLength == EShortKeyPress)
       
  1131                 {
       
  1132                 iOwner->FepMan()->SetCcpuFlag(CAknFepManager::ECcpuStateIgnoreStarUp);
       
  1133 
       
  1134                 if (iOwner->IsValidChineseInputKeyQwerty(aKey) || aKey
       
  1135                         ==EStdKeySpace) //seperator
       
  1136                     {
       
  1137                     ptiengine->AppendKeyPress((TPtiKey)aKey);
       
  1138                     SetInputPaneToneMark();
       
  1139                     if (ptiengine->GetPhoneticSpelling(1).Length() == 1)
       
  1140                         {
       
  1141                         iOwner->FepMan()->UpdateCbaL(R_AKNFEP_SOFTKEYS_OK_SELECT_CANCEL);
       
  1142                         }
       
  1143                     inputPane->SetFlag(MAknFepUICtrlInputPane::EPhoneticChanged);
       
  1144                     RefreshUI();
       
  1145                     }
       
  1146                 else
       
  1147                     {
       
  1148                     iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
  1149                     }
       
  1150                 inputPane->GetText(currentText);
       
  1151                 spellingLen = currentText.Length();
       
  1152                 if ( spellingLen > 1 )
       
  1153                     {
       
  1154                     popup->SetPreStateIsPredictive( EFalse );
       
  1155                     }
       
  1156                 }
       
  1157             else if ( popup->GetPreStateIsPredictive() && 0 == spellingLen)  //long press fn mode character should inputted
       
  1158                 {
       
  1159                 iOwner->FepMan()->TryCloseUiL();
       
  1160                 popup->SetPreStateIsPredictive( EFalse );
       
  1161 
       
  1162                 TBuf<KFnMappedCharacters> allFnMappedCharacters;
       
  1163                 ptiengine->MappingDataForKey( (TPtiKey)originalKey,
       
  1164                     allFnMappedCharacters, EPtiCaseFnLower );
       
  1165                 text.Set( allFnMappedCharacters );
       
  1166                 if ( text.Length( ) > 0 )
       
  1167                     {
       
  1168                     TBuf<1> chr;
       
  1169                     chr.Append( text[0] );
       
  1170                     iOwner->FepMan()->NewCharacterL( chr );
       
  1171                     iOwner->FepMan()->CommitInlineEditL();
       
  1172                     ptiengine->ClearCurrentWord();
       
  1173                     ret = ETrue;
       
  1174                     }
       
  1175                 }
       
  1176             }
       
  1177         }
       
  1178     return ret;
       
  1179     }
       
  1180 
       
  1181 // ---------------------------------------------------------------------------
       
  1182 // TAknFepInputStateEntryHalfQwertyZhuyinPhrase::KeyTimerExpired
       
  1183 // 
       
  1184 // ---------------------------------------------------------------------------
       
  1185 //
       
  1186 void TAknFepInputStateEntryHalfQwertyZhuyinPhrase::KeyTimerExpired()
       
  1187     {
       
  1188     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
  1189     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
  1190     MAknFepUICtrlInputPane* inputPane = uiContainer->InputPane();
       
  1191     
       
  1192     // set container's position
       
  1193     TPoint baseLine = TPoint(0,0);
       
  1194     TInt height = 0;
       
  1195     TInt ascent = 0;
       
  1196     TRAPD(ret,iOwner->FepMan()->GetScreenCoordinatesL(baseLine,height,ascent));
       
  1197     if (ret == KErrNone)
       
  1198         {
       
  1199         uiContainer->SetContainerPosition(baseLine, height);    
       
  1200         }
       
  1201     TPtrC ptr = ptiengine->GetPhoneticSpelling(1);
       
  1202     inputPane->SetText(ptr);
       
  1203     TBuf<KInputPaneLength> currentText;
       
  1204     inputPane->GetText(currentText);
       
  1205     if (ptr.Length() < currentText.Length())
       
  1206         {
       
  1207         iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
  1208         }
       
  1209     UpdateIndicator();
       
  1210     }
       
  1211 
       
  1212 // ---------------------------------------------------------------------------
       
  1213 // TAknFepInputStateEntryHalfQwertyZhuyinPhrase::UpdateIndicator
       
  1214 // updata the indicator
       
  1215 // ---------------------------------------------------------------------------
       
  1216 //
       
  1217 void TAknFepInputStateEntryHalfQwertyZhuyinPhrase::UpdateIndicator()
       
  1218     {
       
  1219     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();        
       
  1220     MAknFepUICtrlCandidatePane* candidatePane = uiContainer->CandidatePane();
       
  1221     
       
  1222     if (candidatePane->IsFirstPage())
       
  1223         {
       
  1224         uiContainer->CandidatePane()->ShowUpScrollArrows(EFalse);    
       
  1225         }
       
  1226     else
       
  1227         {
       
  1228         uiContainer->CandidatePane()->ShowUpScrollArrows(ETrue);    
       
  1229         }
       
  1230     if (candidatePane->IsLastPage())
       
  1231         {
       
  1232         uiContainer->CandidatePane()->ShowDownScrollArrows(EFalse);     
       
  1233         }
       
  1234     else
       
  1235         {
       
  1236         uiContainer->CandidatePane()->ShowDownScrollArrows(ETrue);      
       
  1237         }
       
  1238 
       
  1239     uiContainer->CandidatePane()->ShowLeftScrollArrows(EFalse);
       
  1240     uiContainer->CandidatePane()->ShowRightScrollArrows(EFalse);   
       
  1241     }
       
  1242 
       
  1243 //End Of File