fep/aknfep/src/aknfepuiinputstateminiqwertyzhuyinphrase.cpp
changeset 0 eb1f2e154e89
child 3 f5a1e66df979
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2007 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  TAknFepInputStateEntryMiniQwertyZhuyinPhrase,
       
    16  *       TAknFepInputStateEditingMiniQwertyZhuyinPhrase,
       
    17  *       TAknFepUiInputStateCandidateMiniQwertyZhuyinPhrase methods.
       
    18  *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 
       
    30 
       
    31 
       
    32 // System includes
       
    33 #include <PtiEngine.h>  
       
    34 #include <PtiUserDicEntry.h>
       
    35 #include <aknnotewrappers.h> //CAknWarningNote
       
    36 #include <AknFep.rsg>  
       
    37 
       
    38 // User includes
       
    39 #include "AknFepUiCtrlContainerChinese.h"
       
    40 #include "AknFepUICtrlCandidatePane.h"
       
    41 #include "AknFepUICtrlInputPane.h"
       
    42 #include "aknfepuictrleditpane.h"           //phrase creation
       
    43 #include "AknFepUICtrlPinyinPopup.h"        //Pinyin phrase
       
    44 #include "AknFepUIManagerStateInterface.h"  
       
    45 #include "AknFepManager.h" 
       
    46 #include "aknfepuiinputstateminiqwertyzhuyinphrase.h"
       
    47 #include "aknfepinputstateminiqwertyzhuyinkeymap.h"
       
    48 
       
    49 const TInt KMaxKeystrokeCount = 31;
       
    50 const TInt KMaxKeystrokeSize = 130;
       
    51 const TInt KMaxPhraseLength = 7;
       
    52 const TInt KMinCandidateCount = 1;
       
    53 const TInt KKeystrokeMaxLength = 4;
       
    54 //const TInt KTonemarkCount = 5;
       
    55 
       
    56 const TUint16 KToneMark1 = 0x0020;
       
    57 const TUint16 KToneMark2 = 0x02CA;
       
    58 const TUint16 KToneMark3 = 0x02c7;
       
    59 const TUint16 KToneMark4 = 0x02CB;
       
    60 const TUint16 KToneMark5 = 0x02D9;
       
    61 
       
    62 _LIT(KLeftBracket, "(");
       
    63 _LIT(KRightBracket, ")");
       
    64 _LIT(KReplace, "");
       
    65 
       
    66 _LIT( KDelimiter, "'");
       
    67 struct TToneZhuYinMap
       
    68     {
       
    69     TUint16 iValue;
       
    70     TInt iInputTone;
       
    71     };
       
    72 const TToneZhuYinMap ZhuyinToneMap[] =
       
    73     {
       
    74         {KToneMark1, 1},
       
    75         {KToneMark2, 2},
       
    76         {KToneMark3, 3},
       
    77         {KToneMark4, 4},
       
    78         {KToneMark5, 5}
       
    79     };
       
    80 // ---------------------------------------------------------------------------
       
    81 // TAknFepInputStateEditingMiniQwertyZhuyinPhrase::TAknFepInputStateEditingMiniQwertyZhuyinPhrase
       
    82 // C++ default constructor
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 TAknFepInputStateEditingMiniQwertyZhuyinPhrase::TAknFepInputStateEditingMiniQwertyZhuyinPhrase(
       
    86     MAknFepUIManagerStateInterface* aOwner,
       
    87     MAknFepUICtrlContainerChinese* aUIContainer ) :
       
    88     TAknFepInputMiniQwertyZhuyinPhraseBase( aOwner, aUIContainer)
       
    89     {
       
    90     iState = EMiniQwertyEdit;
       
    91     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
    92     uiContainer->FocusCandidatePane( EFalse );
       
    93     uiContainer->CandidatePane()->ShowCandidateOrdinals( EFalse );
       
    94     uiContainer->SetLayout( MAknFepUICtrlContainerChinese::ELayoutPhraseCreation );
       
    95     uiContainer->CandidatePane()->SelectFirstPhrase();
       
    96     uiContainer->ShowVerticalScrollArrows( ETrue );
       
    97     uiContainer->ShowHorizontalScrollArrows( EFalse );
       
    98     uiContainer->InputPane()->SetOverrideFontId( 0 );
       
    99     // in the case that we are coming back to the input pane from the candidate pane, 
       
   100     // we need to ensure that the current selection is selected correctly
       
   101     ImplicityShowInfo( ETrue );
       
   102     // so that it could handle EKeyCBA1
       
   103     iOwner->FepMan()->EntryPhrase( ETrue );
       
   104     RefreshEditPane();
       
   105     uiContainer->PinyinPopupWindow()->SetNoneHighlighted();
       
   106     TRAP_IGNORE( ChangeCbaL() );
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // TAknFepInputStateEditingMiniQwertyZhuyinPhrase::HandleKeyL
       
   111 // Handle system key press event.
       
   112 // ---------------------------------------------------------------------------
       
   113 // 
       
   114 TBool TAknFepInputStateEditingMiniQwertyZhuyinPhrase::HandleKeyL( TInt aKey,
       
   115     TKeyPressLength aLength )
       
   116     {
       
   117     TBool ret = ETrue;
       
   118     TBool state = ETrue;
       
   119     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   120     MAknFepUICtrlCandidatePane* candidatePane = UIContainer()->CandidatePane();
       
   121     MAknFepUICtrlEditPane* editPane = UIContainer()->EditPaneWindow();
       
   122     CDesCArrayFlat* keystrokeArray = editPane->KeystrokeArray();
       
   123     CDesCArrayFlat* phraseArray = editPane->PhraseArray();
       
   124     
       
   125     if ( iOwner->FepMan()->GetComposChrFlag() && aKey == EStdKeyLeftFunc )
       
   126         {
       
   127         iOwner->FepMan()->SetComposChrFlag( EFalse );
       
   128         return ret;
       
   129         }
       
   130     
       
   131     switch ( aKey )
       
   132         {
       
   133         case EStdKeyLeftShift:
       
   134         case EStdKeyRightShift:
       
   135         case EStdKeyLeftCtrl:
       
   136         case EStdKeyRightCtrl:
       
   137         case EStdKeyRightFunc://fn 
       
   138         case EStdKeyLeftFunc: //chr key
       
   139         case EStdKeyUpArrow:
       
   140         case EKeyRightFunc:
       
   141         case EKeyLeftFunc:
       
   142             iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   143             break;
       
   144             //if the canidate is empty ,inactive;else candiniate selecting state
       
   145         case EStdKeyDownArrow:
       
   146             {
       
   147             if ( 0 != candidatePane->VisibleCandidateCount() && phraseArray->Count() < 7 )
       
   148                 {
       
   149                 uiContainer->EditPaneWindow()->SetChangeState( ETrue );
       
   150                 iOwner->ChangeState( EZhuyinSpelling );
       
   151                 }
       
   152             }
       
   153             break;
       
   154         case EStdKeyRightArrow:
       
   155             MoveCursorRight();
       
   156             break;
       
   157         case EStdKeyLeftArrow:
       
   158             MoveCursorLeft();
       
   159             break;
       
   160         case EStdKeyDevice1: //"cancle" key
       
   161             iOwner->FepMan()->TryCloseUiL();
       
   162             break;
       
   163         case EStdKeyEnter:
       
   164             CommitContentL( EFalse );
       
   165             break;
       
   166         case EStdKeyDevice0:
       
   167         case EStdKeyDevice3:
       
   168         	
       
   169             if ( editPane->IsChangeState() && aLength == ELongKeyPress )
       
   170                 {
       
   171                 state = EFalse;
       
   172                 }
       
   173             else
       
   174                 {
       
   175                 editPane->SetChangeState( EFalse );
       
   176                 }
       
   177             if ( state )
       
   178                 {
       
   179                 HandleCommitL();
       
   180                 }
       
   181             break;
       
   182         case EStdKeyBackspace:
       
   183             {
       
   184             if ( editPane->IsChangeState() && aLength == ELongKeyPress )
       
   185                 {
       
   186                 state = EFalse;
       
   187                 }
       
   188             else
       
   189                 {
       
   190                 editPane->SetChangeState( EFalse );
       
   191                 }
       
   192             if ( state )
       
   193                 {
       
   194                 HandleKeyBackspaceL( aLength );
       
   195                 }
       
   196             }
       
   197             break;
       
   198         default:
       
   199             {
       
   200             if ( aLength == EShortKeyPress && keystrokeArray->Count() < KMaxKeystrokeCount && 
       
   201                 !iOwner->FepMan()->IsFlagSet( CAknFepManager::EFlagQwertyChrKeyDepressed ) && 
       
   202                 phraseArray->Count() < KMaxPhraseLength &&
       
   203                 ( iOwner->IsValidChineseInputKeyQwerty( aKey ) || aKey == EStdKeySpace ) )
       
   204                 {
       
   205                 AddKeystrokeL( aKey );
       
   206                 RefreshUI();
       
   207                 ShowEEPInfo();
       
   208                 ChangeCbaL();
       
   209                 }
       
   210             else
       
   211                 {
       
   212                 iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   213                 }
       
   214             }
       
   215             break;
       
   216         }
       
   217     return ret;
       
   218     }
       
   219 
       
   220 // ---------------------------------------------------------------------------
       
   221 // TAknFepInputStateEditingMiniQwertyZhuyinPhrase::AddKeystrokeL
       
   222 // Add key stroke.
       
   223 // ---------------------------------------------------------------------------
       
   224 // 
       
   225 TBool TAknFepInputStateEditingMiniQwertyZhuyinPhrase::AddKeystrokeL( TInt aKey )
       
   226     {
       
   227     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   228     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   229     CDesCArrayFlat* keystrokeArray = editPane->KeystrokeArray();
       
   230     RArray<TInt>* keycodeArray = editPane->KeycodeArray();
       
   231     TInt phraseCount = editPane->PhraseArray()->Count();
       
   232     TInt showKeystrokeCount = editPane->ShowKeystrokeArray()->Count();
       
   233     TInt index = editPane->GetCursorIndexOfKeystroke();
       
   234 
       
   235     if ( phraseCount + showKeystrokeCount >= KMaxKeystrokeCount - 1 )
       
   236         {
       
   237         return EFalse;
       
   238         }
       
   239     TBuf<KKeystrokeMaxLength> keystroke;
       
   240     
       
   241     TAknFepInputStateMiniQwertyZhuyinKeyMap::GetKeyStroke(
       
   242             iOwner->PtiEngine(), aKey, keystroke );
       
   243     
       
   244     if ( index >= keystrokeArray->Count() )
       
   245         {
       
   246         keycodeArray->Append( aKey );
       
   247         keystrokeArray->AppendL( keystroke );
       
   248         editPane->SetCursorIndexOfKeystroke( keystrokeArray->Count() );
       
   249         }
       
   250     else
       
   251         {
       
   252         keycodeArray->Insert( aKey, index );
       
   253         keystrokeArray->InsertL( index, keystroke );
       
   254         editPane->SetCursorIndexOfKeystroke( index + 1 );
       
   255         }
       
   256     editPane->SetNeedClearDeliberateSelection( ETrue );
       
   257     return ETrue;
       
   258     }
       
   259 
       
   260 // ---------------------------------------------------------
       
   261 // TAknFepInputStateEditingMiniQwertyZhuyinPhrase::RevertPhraseToKeystrokeL
       
   262 // Revert the phrase to keystroke.
       
   263 // ---------------------------------------------------------
       
   264 //
       
   265 void TAknFepInputStateEditingMiniQwertyZhuyinPhrase::RevertPhraseToKeystrokeL()
       
   266     {
       
   267     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   268     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   269     CDesCArrayFlat* keystrokeArray = editPane->KeystrokeArray();
       
   270     CDesCArrayFlat* phrase = editPane->PhraseArray();
       
   271     RArray<TInt>* keycodeArray = editPane->KeycodeArray();
       
   272     RArray<TInt>* phraseKeycode = editPane->PhraseKeycodeArray();
       
   273     CDesCArrayFlat* phraseStroke = editPane->PhraseShowKeyStrokeArray();
       
   274     TBuf<KMaxKeystrokeCount> buf;
       
   275 
       
   276     if ( (phrase->Count() == 0 ) || (phraseStroke->Count() == 0 ) )
       
   277         {
       
   278         return;
       
   279         }
       
   280     
       
   281     buf.Append( phraseStroke->MdcaPoint( phraseStroke->Count() - 1 ) );
       
   282     
       
   283     TInt insertIndex = 0;
       
   284     while ( buf.Length() != 0 )
       
   285         {
       
   286         TBuf<KKeystrokeMaxLength> strokeBuf;
       
   287         TInt index = buf.Find( KRightBracket );
       
   288         if ( index != KErrNotFound )
       
   289             {
       
   290             strokeBuf.Copy( buf.Left( index + 1 ) );
       
   291             keystrokeArray->InsertL( insertIndex, strokeBuf );
       
   292             buf.Replace( 0, index + 1, KNullDesC );
       
   293             }
       
   294         else
       
   295             {
       
   296             keystrokeArray->InsertL( insertIndex, buf );
       
   297             insertIndex = insertIndex + 1;
       
   298             break;
       
   299             }
       
   300         insertIndex = insertIndex + 1;
       
   301         }
       
   302     phrase->Delete( phrase->Count() - 1 );
       
   303     phraseStroke->Delete( phraseStroke->Count() - 1 );
       
   304     
       
   305     if ( insertIndex > phraseKeycode->Count() )
       
   306         {
       
   307         insertIndex = keycodeArray->Count();
       
   308         }
       
   309     
       
   310     for ( TInt i = 0; i < insertIndex ; ++i )
       
   311         {
       
   312         keycodeArray->Insert( (*phraseKeycode)[phraseKeycode->Count() - 1 ],0 );
       
   313         phraseKeycode->Remove( phraseKeycode->Count() - 1 );
       
   314         }
       
   315     
       
   316     TInt keystrokeCount = keystrokeArray->Count();
       
   317     TInt lenth = phrase->Count() + keystrokeCount;
       
   318     TInt deleteCount = lenth - KMaxKeystrokeCount;
       
   319 
       
   320     for (TInt i = 0; i < deleteCount; ++i )
       
   321         {
       
   322         keycodeArray->Remove( keycodeArray->Count() - 1 );
       
   323         keystrokeArray->Delete( keystrokeArray->Count() - 1 );
       
   324         }
       
   325     editPane->SetCursorIndexOfKeystroke( insertIndex );
       
   326     keystrokeArray->Compress();
       
   327     phrase->Compress();
       
   328     phraseStroke->Compress();
       
   329     }
       
   330 
       
   331 // ---------------------------------------------------------
       
   332 // TAknFepInputStateEditingMiniQwertyZhuyinPhrase::AddPhraseToDB
       
   333 // Add phrase to DB.
       
   334 // ---------------------------------------------------------
       
   335 //
       
   336 void TAknFepInputStateEditingMiniQwertyZhuyinPhrase::AddPhraseToDB(
       
   337     const TDesC& aPhraseAdd )
       
   338     {
       
   339     TPtiUserDictionaryEntry addUdbEntry(aPhraseAdd);
       
   340     //Add the phrase to the DB by PTI Engine
       
   341     iOwner->PtiEngine()->AddUserDictionaryEntry( addUdbEntry );
       
   342     }
       
   343 
       
   344 // ---------------------------------------------------------
       
   345 // TAknFepInputStateEditingMiniQwertyZhuyinPhrase::MoveCursorLeft
       
   346 // Move the cursor to Left.
       
   347 // ---------------------------------------------------------
       
   348 //
       
   349 TBool TAknFepInputStateEditingMiniQwertyZhuyinPhrase::MoveCursorLeft()
       
   350     {
       
   351     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   352     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   353     CDesCArrayFlat* keyStrokeArray = editPane->KeystrokeArray();
       
   354     TInt keystrokeCount = keyStrokeArray->Count();
       
   355     TInt index = editPane->GetCursorIndexOfKeystroke();
       
   356     TInt phraseCount = editPane->PhraseArray()->Count();
       
   357 
       
   358     if ( EMiniQwertyEdit != iState )
       
   359         {
       
   360         return EFalse;
       
   361         }
       
   362     if ( 0 == keystrokeCount )
       
   363         {
       
   364         return EFalse;
       
   365         }
       
   366 
       
   367     if ( 0 == index )
       
   368         {
       
   369         editPane->SetCursorIndexOfKeystroke( keystrokeCount );
       
   370         ShowEEPInfo();
       
   371         }
       
   372     else if ( phraseCount > 0 && 1 == index )
       
   373         {
       
   374         editPane->SetCursorIndexOfKeystroke( 0 );
       
   375         ShowEEPInfo();
       
   376         }
       
   377     else
       
   378         {
       
   379         TInt stride = keyStrokeArray->MdcaPoint( index - 1 ).Length();
       
   380         editPane->MoveCursorLeft( stride );
       
   381         editPane->SetCursorIndexOfKeystroke( index - 1 );
       
   382         }
       
   383     return ETrue;
       
   384     }
       
   385 
       
   386 // ---------------------------------------------------------
       
   387 // TAknFepInputStateEditingMiniQwertyZhuyinPhrase::MoveCursorRight
       
   388 // Move the cursor to Right.
       
   389 // ---------------------------------------------------------
       
   390 //
       
   391 TBool TAknFepInputStateEditingMiniQwertyZhuyinPhrase::MoveCursorRight()
       
   392     {
       
   393     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   394     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   395     CDesCArrayFlat* keystroke = editPane->KeystrokeArray();
       
   396     TInt keystrokeCount = keystroke->Count();
       
   397     TInt index = editPane->GetCursorIndexOfKeystroke();
       
   398 
       
   399     if ( EMiniQwertyEdit != iState )
       
   400         {
       
   401         return EFalse;
       
   402         }
       
   403     if ( 0 == keystrokeCount )
       
   404         {
       
   405         return EFalse;
       
   406         }
       
   407     if ( index >= keystrokeCount )
       
   408         {
       
   409         editPane->SetCursorIndexOfKeystroke( 0 );
       
   410         ShowEEPInfo();
       
   411         }
       
   412     else
       
   413         {
       
   414         TInt stride = editPane->KeystrokeArray()->MdcaPoint( index ).Length();
       
   415         editPane->MoveCursorRight( stride );
       
   416         editPane->SetCursorIndexOfKeystroke( index + 1 );
       
   417         }
       
   418     return ETrue;
       
   419     }
       
   420 
       
   421 // ---------------------------------------------------------
       
   422 // TAknFepInputStateEditingMiniQwertyZhuyinPhrase::HandleKeyBackspace
       
   423 // Handle Key Backspace
       
   424 // ---------------------------------------------------------
       
   425 //
       
   426 void TAknFepInputStateEditingMiniQwertyZhuyinPhrase::HandleKeyBackspaceL( 
       
   427                                                      TKeyPressLength aLength )
       
   428     {
       
   429     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   430     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   431 
       
   432     CDesCArrayFlat* keyStrokeArray = editPane->KeystrokeArray();
       
   433     RArray<TInt>* keycodeArray = editPane->KeycodeArray();
       
   434     TInt keystrokeCount = keyStrokeArray->Count();
       
   435     TInt phraseCount = editPane->PhraseArray()->Count();
       
   436 
       
   437     TInt cursorOfkeystrokeIndex = editPane->GetCursorIndexOfKeystroke();
       
   438 
       
   439     if ( 1 == cursorOfkeystrokeIndex )
       
   440         {
       
   441         editPane->Reset();
       
   442         }
       
   443     
       
   444     if ( cursorOfkeystrokeIndex > 0 && 
       
   445         ( keystrokeCount > 1 || phraseCount > 0 ) )
       
   446         {
       
   447         keycodeArray->Remove( cursorOfkeystrokeIndex - 1 );
       
   448         keyStrokeArray->Delete( cursorOfkeystrokeIndex - 1 );
       
   449         editPane->SetCursorIndexOfKeystroke( cursorOfkeystrokeIndex - 1 );
       
   450         }
       
   451     else if ( phraseCount > 0 && 0 == cursorOfkeystrokeIndex )
       
   452         {
       
   453         RevertPhraseToKeystrokeL();
       
   454         }
       
   455     else if ( 1 == cursorOfkeystrokeIndex )
       
   456         {
       
   457         iOwner->FepMan()->TryCloseUiL();
       
   458         if ( aLength == ELongKeyPress )
       
   459             {
       
   460             iOwner->FepMan()->SetLongClearAfterCloseUI( ETrue );
       
   461             }
       
   462         return;
       
   463         }
       
   464     else
       
   465         {
       
   466         return;
       
   467         }
       
   468     editPane->SetNeedClearDeliberateSelection( ETrue );
       
   469     RefreshUI();
       
   470     ShowEEPInfo();
       
   471     ChangeCbaL();
       
   472     }
       
   473 
       
   474 // ---------------------------------------------------------
       
   475 // TAknFepInputStateEditingMiniQwertyZhuyinPhrase::CommitContentL
       
   476 // Commit content
       
   477 // ---------------------------------------------------------
       
   478 //
       
   479 void TAknFepInputStateEditingMiniQwertyZhuyinPhrase::CommitContentL(
       
   480     TBool aAddUDB )
       
   481     {
       
   482     TBuf<KMaxKeystrokeSize> currentText;
       
   483     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   484     MAknFepUICtrlEditPane* editpane = UIContainer()->EditPaneWindow();
       
   485     CDesCArrayFlat* phraseArray = editpane->PhraseArray();
       
   486     CDesCArrayFlat* keystrokeArray = editpane->KeystrokeArray();
       
   487     TInt phraseCount = phraseArray->Count();
       
   488     TInt keyStrokeCount = keystrokeArray->Count();
       
   489 
       
   490     for (TInt i = 0; i < phraseCount; i++ )
       
   491         {
       
   492         currentText.Append( phraseArray->MdcaPoint( i ) );
       
   493         }
       
   494     for (TInt i = 0; i < keyStrokeCount; i++ )
       
   495         {
       
   496         currentText.Append( keystrokeArray->MdcaPoint( i ) );
       
   497         }
       
   498 
       
   499     if ( currentText.Length() )
       
   500         {
       
   501         while (currentText.Find( KLeftBracket ) >= 0 )
       
   502             {
       
   503             currentText.Replace( currentText.Find( KLeftBracket ), 1,
       
   504                 KReplace );
       
   505             }
       
   506         while (currentText.Find( KRightBracket ) > 0 )
       
   507             {
       
   508             currentText.Replace( currentText.Find( KRightBracket ), 1,
       
   509                 KReplace );
       
   510             }
       
   511         fepMan->NewTextL( currentText );
       
   512         fepMan->CommitInlineEditL();
       
   513         }
       
   514     UIContainer()->EditPaneWindow()->ResetAllArray();
       
   515     UIContainer()->EditPaneWindow()->SetPhraseCreationFlag( EFalse );
       
   516     if ( fepMan->IsFlagSet( CAknFepManager::EFlagEditorFull ) )
       
   517         {
       
   518         fepMan->ClearFlag( CAknFepManager::EFlagEditorFull );
       
   519         }
       
   520     if ( aAddUDB )
       
   521         {
       
   522         AddPhraseToDB( currentText );
       
   523         }
       
   524     fepMan->TryCloseUiL();
       
   525     }
       
   526 
       
   527 // ---------------------------------------------------------
       
   528 // TAknFepInputStateEditingMiniQwertyZhuyinPhrase::HandleCommitL
       
   529 // Handle commit action
       
   530 // ---------------------------------------------------------
       
   531 //
       
   532 void TAknFepInputStateEditingMiniQwertyZhuyinPhrase::HandleCommitL()
       
   533     {
       
   534     TBuf<KMaxKeystrokeSize> currentText;
       
   535     MAknFepUICtrlEditPane* editpane = UIContainer()->EditPaneWindow();
       
   536     MAknFepUICtrlCandidatePane* candidatePane = UIContainer()->CandidatePane();
       
   537     CDesCArrayFlat* phraseArray = editpane->PhraseArray();
       
   538     CDesCArrayFlat* keystrokeArray = editpane->KeystrokeArray();
       
   539     TInt phraseCount = phraseArray->Count();
       
   540     TInt keyStrokeCount = keystrokeArray->Count();
       
   541 
       
   542     if ( 0 == candidatePane->VisibleCandidateCount() && ( 1 == phraseCount
       
   543         || keyStrokeCount > 0 ) )
       
   544         {
       
   545         return;
       
   546         }
       
   547     if ( 0 != candidatePane->VisibleCandidateCount() && phraseCount < KMaxPhraseLength )
       
   548         {
       
   549         UIContainer()->EditPaneWindow()->SetChangeState( ETrue );
       
   550         iOwner->ChangeState( EZhuyinSpelling );
       
   551         return;
       
   552         }
       
   553     CommitContentL( ETrue );
       
   554     }
       
   555 
       
   556 // ---------------------------------------------------------
       
   557 // TAknFepInputStateEditingMiniQwertyZhuyinPhrase::RefreshUI
       
   558 // Refresh UI if necessary
       
   559 // ---------------------------------------------------------
       
   560 //
       
   561 void TAknFepInputStateEditingMiniQwertyZhuyinPhrase::RefreshUI()
       
   562     {
       
   563     MAknFepUICtrlEditPane* editpane = UIContainer()->EditPaneWindow();
       
   564     MAknFepUICtrlPinyinPopup* popup = UIContainer()->PinyinPopupWindow();
       
   565     CDesCArrayFlat* showKeystroke = editpane->ShowKeystrokeArray();
       
   566     TBuf<KMaxKeystrokeCount> preValidKeystroke;
       
   567     TInt preValidKeystrokeCount = showKeystroke->Count();
       
   568     for (TInt i=0; i < preValidKeystrokeCount; i++ )
       
   569         {
       
   570         preValidKeystroke.Append( showKeystroke->MdcaPoint( i ) );
       
   571         }
       
   572     GetValidKeystroke();
       
   573     TBuf<KMaxKeystrokeCount> validKeystroke;
       
   574     TInt validKeystrokeCount = showKeystroke->Count();
       
   575     for (TInt i=0; i < validKeystrokeCount; i++ )
       
   576         {
       
   577         validKeystroke.Append( showKeystroke->MdcaPoint( i ) );
       
   578         }
       
   579     if ( preValidKeystroke.Compare( validKeystroke ) != 0 )
       
   580         {
       
   581         RefreshSpellingPane( ETrue );
       
   582         RefreshCandidatePane();
       
   583         }
       
   584     else if ( popup->CurrentSelection() != 0 )
       
   585         {
       
   586         RefreshCandidatePane();
       
   587         }
       
   588     UpdateIndicator();
       
   589     }
       
   590 
       
   591 // ---------------------------------------------------------
       
   592 // Init the show info
       
   593 // ---------------------------------------------------------
       
   594 //
       
   595 void TAknFepInputStateEditingMiniQwertyZhuyinPhrase::ImplicityShowInfo(
       
   596     TBool aGetScreenCoordinates )
       
   597     {
       
   598     TRAP_IGNORE( ImplicityShowInfoL( aGetScreenCoordinates ) );
       
   599     }
       
   600 
       
   601 // ---------------------------------------------------------
       
   602 // Init the show info
       
   603 // ---------------------------------------------------------
       
   604 //
       
   605 void TAknFepInputStateEditingMiniQwertyZhuyinPhrase::ImplicityShowInfoL(
       
   606     TBool aGetScreenCoordinates )
       
   607     {
       
   608     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   609     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   610     // get cursor position
       
   611     TPoint baseLine = TPoint( 0, 0 );
       
   612     TInt height = 0;
       
   613     TInt ascent = 0;
       
   614     if ( aGetScreenCoordinates )
       
   615         {
       
   616         iOwner->FepMan()->GetScreenCoordinatesL( baseLine, height, ascent );
       
   617         uiContainer->SetContainerPosition( baseLine, height );
       
   618         }
       
   619     editPane->ActiveCursor();
       
   620     }
       
   621 
       
   622 // ---------------------------------------------------------
       
   623 // Init the show info
       
   624 // ---------------------------------------------------------
       
   625 //
       
   626 void TAknFepInputStateEditingMiniQwertyZhuyinPhrase::ShowEEPInfo()
       
   627     {
       
   628     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   629     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   630     CDesCArrayFlat* keystroke = editPane->KeystrokeArray();
       
   631     CDesCArrayFlat* phrase = editPane->PhraseArray();
       
   632     TInt index = editPane->GetCursorIndexOfKeystroke();
       
   633     TInt cursorPosInKeystroke = 0;
       
   634 
       
   635     TBuf<KMaxKeystrokeSize> buf;
       
   636 
       
   637     for (TInt i = 0; i < phrase->Count(); ++i )
       
   638         {
       
   639         buf.Append( phrase->MdcaPoint( i ) );
       
   640         }
       
   641 
       
   642     for (TInt i = 0; i < keystroke->Count(); ++i )
       
   643         {
       
   644         buf.Append( keystroke->MdcaPoint( i ) );
       
   645         }
       
   646 
       
   647     for (TInt i = 0; i < index; ++i )
       
   648         {
       
   649         cursorPosInKeystroke = cursorPosInKeystroke + keystroke->MdcaPoint( i ).Length();
       
   650         }
       
   651 
       
   652     editPane->SetText( buf, phrase->Count() + cursorPosInKeystroke, ETrue );
       
   653     if ( editPane->GetEffictiveLength() == 0 )
       
   654         {
       
   655         editPane->SetHighlight( phrase->Count(), buf.Length() );
       
   656         }
       
   657     }
       
   658 
       
   659 // ---------------------------------------------------------------------------
       
   660 // TAknFepInputStateSpellingMiniQwertyZhuyin::TAknFepInputStateSpellingMiniQwertyZhuyin
       
   661 // C++ default constructor
       
   662 // ---------------------------------------------------------------------------
       
   663 //
       
   664 TAknFepInputStateSpellingMiniQwertyZhuyin::TAknFepInputStateSpellingMiniQwertyZhuyin(
       
   665     MAknFepUIManagerStateInterface* aOwner,
       
   666     MAknFepUICtrlContainerChinese* aUIContainer ) :
       
   667     TAknFepInputMiniQwertyZhuyinPhraseBase( aOwner, aUIContainer)
       
   668     {
       
   669     iState = EZhuyinSpelling;
       
   670 
       
   671     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   672     uiContainer->FocusCandidatePane( EFalse );
       
   673     uiContainer->CandidatePane()->ShowCandidateOrdinals( EFalse );
       
   674     uiContainer->CandidatePane()->SelectFirstPhrase();
       
   675     uiContainer->ShowVerticalScrollArrows( ETrue );
       
   676     uiContainer->ShowHorizontalScrollArrows( EFalse );
       
   677     uiContainer->InputPane()->SetOverrideFontId( 0 );
       
   678     uiContainer->SetLayout( MAknFepUICtrlContainerChinese::ELayoutPhraseCreation );
       
   679     uiContainer->EditPaneWindow()->DeactiveCursor();
       
   680     RefreshUI();
       
   681     // however we also need to clear the deliberate selection, in case we are not
       
   682     // coming back to the input pane from the candidate pane
       
   683     ClearDeliberateSelection();
       
   684     UpdateIndicator();
       
   685 
       
   686     iOwner->PtiEngine()->SetInputMode( EPtiEngineZhuyinPhraseQwerty );
       
   687     iOwner->PtiEngine()->SetCase( EPtiCaseLower );
       
   688     }
       
   689 
       
   690 // ---------------------------------------------------------------------------
       
   691 // TAknFepInputStateSpellingMiniQwertyZhuyin::HandleKeyL
       
   692 // Handle system key press event.
       
   693 // ---------------------------------------------------------------------------
       
   694 // 
       
   695 TBool TAknFepInputStateSpellingMiniQwertyZhuyin::HandleKeyL( TInt aKey,
       
   696     TKeyPressLength aLength )
       
   697     {
       
   698     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   699     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   700     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   701     TBool ret = ETrue;
       
   702 
       
   703     if ( CAknFepFnKeyManager::EFnKeyNext == iOwner->FepMan()->FnKeyState() || CAknFepFnKeyManager::EFnKeyLock
       
   704         == iOwner->FepMan()->FnKeyState() || CAknFepFnKeyManager::EFnKeyDown
       
   705         == iOwner->FepMan()->FnKeyState() )
       
   706         {
       
   707         iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   708         return ETrue;
       
   709         }
       
   710     else if ( iOwner->FepMan()->IsFlagSet( CAknFepManager::EFlagShiftKeyDepressed )
       
   711         || iOwner->FepMan()->IsFlagSet( CAknFepManager::EFlagQwertyChrKeyDepressed ) )
       
   712         {
       
   713         return ETrue;
       
   714         }
       
   715 
       
   716     switch ( aKey )
       
   717         {
       
   718         case EPtiKeyQwertyE:
       
   719         case EPtiKeyQwertyR:
       
   720         case EPtiKeyQwertyY:
       
   721         case EPtiKeyQwertyU:
       
   722         case EStdKeyLeftFunc:
       
   723             {
       
   724             if ( aLength == EShortKeyPress )
       
   725                 {
       
   726                 iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   727                 }
       
   728             }
       
   729             break;
       
   730         case EKeyRightFunc:
       
   731         case EKeyLeftShift:
       
   732         case EKeyLeftCtrl:
       
   733         case EKeyRightCtrl:
       
   734         case EStdKeyEnter:
       
   735             {
       
   736             iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   737             }
       
   738             break;
       
   739         case EStdKeyBackspace:
       
   740         case EStdKeyUpArrow:
       
   741             {
       
   742             TBool state = ETrue;
       
   743             if ( editPane->IsChangeState() && aLength == ELongKeyPress )
       
   744                 {
       
   745                 state = EFalse;
       
   746                 }
       
   747             else
       
   748                 {
       
   749                 editPane->SetChangeState( EFalse );
       
   750                 }
       
   751             if ( state )
       
   752                 {
       
   753                 editPane->SetChangeState( ETrue );
       
   754                 iOwner->ChangeState( EMiniQwertyEdit );
       
   755                 }
       
   756             }
       
   757             break;
       
   758         case EStdKeyDevice1:
       
   759             {
       
   760             iOwner->FepMan()->TryCloseUiL();
       
   761             }
       
   762             break;
       
   763         case EStdKeyRightArrow:
       
   764             {
       
   765             if ( popup->IsEnabled() )
       
   766                 {
       
   767                 if ( popup->SelectNextPhrase() )
       
   768                     {
       
   769                     RefreshVaildKeyStroke();
       
   770                     RefreshCandidatePane();
       
   771                     RefreshSpellingPane();
       
   772                     RefreshEditPane();
       
   773                     UpdateIndicator();
       
   774                     }
       
   775                 }
       
   776             }
       
   777             break;
       
   778         case EStdKeyLeftArrow:
       
   779             {
       
   780             if ( popup->IsEnabled() )
       
   781                 {
       
   782                 if ( popup->SelectPrevPhrase() )
       
   783                     {
       
   784                     RefreshVaildKeyStroke();
       
   785                     RefreshCandidatePane();
       
   786                     RefreshSpellingPane();
       
   787                     RefreshEditPane();
       
   788                     UpdateIndicator();
       
   789                     }
       
   790                 }
       
   791             }
       
   792             break;
       
   793         case EStdKeyDownArrow:
       
   794         case EStdKeyDevice3:
       
   795         case EStdKeyDevice0:
       
   796             {
       
   797             TBool state = ETrue;
       
   798             if ( editPane->IsChangeState() && aLength == ELongKeyPress )
       
   799                 {
       
   800                 state = EFalse;
       
   801                 }
       
   802             else
       
   803                 {
       
   804                 editPane->SetChangeState( EFalse );
       
   805                 }
       
   806             if ( state )
       
   807                 {
       
   808                 if ( popup->IsEnabled() )
       
   809                     {
       
   810                     popup->Enable( EFalse );
       
   811                     }
       
   812                 editPane->SetChangeState( ETrue );
       
   813                 iOwner->ChangeState( EZhuyinCandidate );
       
   814                 }
       
   815             }
       
   816             break;
       
   817         default:
       
   818             {
       
   819             iOwner->FepMan()->PlaySound( EAvkonSIDErrorTone );
       
   820             return TAknFepInputMiniQwertyZhuyinPhraseBase::HandleKeyL(
       
   821                 aKey, aLength );
       
   822             }
       
   823 //            break;
       
   824         }
       
   825     return ret;
       
   826     }
       
   827 
       
   828 // ---------------------------------------------------------
       
   829 // TAknFepInputStateSpellingMiniQwertyZhuyin::RefreshUI
       
   830 // Refresh UI if necessary
       
   831 // ---------------------------------------------------------
       
   832 //
       
   833 void TAknFepInputStateSpellingMiniQwertyZhuyin::RefreshUI()
       
   834     {
       
   835     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   836     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   837     // get cursor position
       
   838     TPoint baseLine = TPoint( 0, 0 );
       
   839     TInt height = 0;
       
   840     TInt ascent = 0;
       
   841 
       
   842     TRAPD(ret,iOwner->FepMan()->GetScreenCoordinatesL(baseLine,height,ascent));
       
   843     if ( ret == KErrNone )
       
   844         {
       
   845         uiContainer->SetContainerPosition( baseLine, height );
       
   846         }
       
   847     
       
   848     GetValidKeystroke( );
       
   849     TBool needClearDeliberateSelection = editPane->NeedClearDeliberateSelection();
       
   850     if ( needClearDeliberateSelection )
       
   851         {
       
   852         editPane->SetNeedClearDeliberateSelection( EFalse );
       
   853         }
       
   854     else
       
   855         {
       
   856         RefreshVaildKeyStroke();
       
   857         }
       
   858     RefreshEditPane();
       
   859     RefreshCandidatePane( needClearDeliberateSelection );
       
   860     RefreshSpellingPane( needClearDeliberateSelection );
       
   861     }
       
   862 
       
   863 // ---------------------------------------------------------
       
   864 // TAknFepInputStateSpellingMiniQwertyZhuyin::RefreshUI
       
   865 // Refresh vaild key stroke length
       
   866 // ---------------------------------------------------------
       
   867 //
       
   868 void TAknFepInputStateSpellingMiniQwertyZhuyin::RefreshVaildKeyStroke()
       
   869     {
       
   870     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   871     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   872     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   873     CDesCArrayFlat* spelling = popup->PhoneticSpellingArray();
       
   874     TInt currentSel = popup->CurrentSelection();
       
   875     if ( currentSel >= spelling->Count() )
       
   876         {
       
   877         currentSel = 0;
       
   878         }
       
   879     TPtrC ptr = spelling->MdcaPoint( currentSel );
       
   880     TInt currentLength = ptr.Length();
       
   881     editPane->SetEffictiveLength( currentLength );
       
   882     }
       
   883 // ---------------------------------------------------------------------------
       
   884 // TAknFepInputStateCanindateSelectingMiniQwertyZhuyin::TAknFepInputStateCanindateSelectingMiniQwertyZhuyin
       
   885 // C++ default constructor
       
   886 // ---------------------------------------------------------------------------
       
   887 //
       
   888 TAknFepInputStateCanindateSelectingMiniQwertyZhuyin::TAknFepInputStateCanindateSelectingMiniQwertyZhuyin(
       
   889     MAknFepUIManagerStateInterface* aOwner,
       
   890     MAknFepUICtrlContainerChinese* aUIContainer ) :
       
   891     TAknFepInputMiniQwertyZhuyinPhraseBase( aOwner, aUIContainer)
       
   892     {
       
   893     iState = EZhuyinCandidate;
       
   894     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   895 
       
   896     TBool multiplePages = !(uiContainer->CandidatePane()->IsLastPage() && uiContainer->CandidatePane()->IsFirstPage());
       
   897     TInt bufLength = iOwner->PtiEngine()->CandidatePage().Length();
       
   898     TBool showHorizontalScrollArrows = multiplePages || bufLength
       
   899         > KMinCandidateCount;
       
   900 
       
   901     uiContainer->ShowHorizontalScrollArrows( showHorizontalScrollArrows );
       
   902     uiContainer->ShowVerticalScrollArrows( multiplePages );
       
   903     uiContainer->FocusCandidatePane( ETrue );
       
   904     uiContainer->CandidatePane()->ShowCandidateOrdinals( ETrue );
       
   905     uiContainer->CandidatePane()->SelectFirstPhrase();
       
   906     UpdateIndicator();
       
   907     }
       
   908 // ---------------------------------------------------------------------------
       
   909 // TAknFepInputStateCanindateSelectingMiniQwertyZhuyin::HandleKeyL
       
   910 // Handle system key press event.
       
   911 // ---------------------------------------------------------------------------
       
   912 //
       
   913 TBool TAknFepInputStateCanindateSelectingMiniQwertyZhuyin::HandleKeyL(
       
   914     TInt aKey, TKeyPressLength aLength )
       
   915     {
       
   916     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   917     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   918     TInt selected = uiContainer->CandidatePane()->SelectedIndex();
       
   919     TInt numbertotal = uiContainer->CandidatePane()->VisibleCandidateCount();
       
   920     TBool ret = ETrue;
       
   921 
       
   922     if (iOwner->FepMan()->GetComposChrFlag() )
       
   923         {
       
   924         iOwner->FepMan()->SetComposChrFlag(EFalse);
       
   925         return ETrue;
       
   926         }
       
   927     switch ( aKey )
       
   928         {
       
   929         case EStdKeySpace:
       
   930         case EStdKeyEnter:
       
   931             {
       
   932             iOwner->FepMan()->PlaySound( EAvkonSIDDefaultSound );
       
   933             }
       
   934             break;
       
   935         case EStdKeyLeftArrow:
       
   936             {
       
   937             if ( selected == 0 )
       
   938                 {
       
   939                 UIContainer()->CandidatePane()->SelectIndex( numbertotal-1 );
       
   940                 }
       
   941             else
       
   942                 {
       
   943                 UIContainer()->CandidatePane()->SelectIndex( selected - 1 );
       
   944                 }
       
   945             }
       
   946             break;
       
   947         case EStdKeyRightArrow:
       
   948             {
       
   949             if ( selected == numbertotal-1 )
       
   950                 {
       
   951                 UIContainer()->CandidatePane()->SelectIndex( 0 );
       
   952                 }
       
   953             else
       
   954                 {
       
   955                 UIContainer()->CandidatePane()->SelectIndex( selected + 1 );
       
   956                 }
       
   957             break;
       
   958             }
       
   959         case EStdKeyDevice1: // cancel key
       
   960             {
       
   961             iOwner->FepMan()->TryCloseUiL();
       
   962             break;
       
   963             }
       
   964         case EStdKeyUpArrow:
       
   965             {
       
   966             if ( uiContainer->CandidatePane()->IsFirstPage() ) // same as the backspace
       
   967                 {
       
   968                 editPane->SetChangeState( ETrue );
       
   969                 iOwner->ChangeState( EZhuyinSpelling );
       
   970                 }
       
   971             else // just move to the last page 
       
   972                 {
       
   973                 uiContainer->CandidatePane()->PreviousCandidatePage();
       
   974                 uiContainer->CandidatePane()->SetCandidateBuffer();
       
   975                 uiContainer->CandidatePane()->SelectFirstPhrase();
       
   976                 UpdateIndicator();
       
   977                 }
       
   978             break;
       
   979             }
       
   980         case EStdKeyDownArrow:
       
   981             {
       
   982             ret = TAknFepInputStateCandidateQwertyBaseChinesePhrase::HandleKeyL( aKey, aLength );
       
   983             }
       
   984             break;
       
   985         case EStdKeyBackspace: // 
       
   986             {
       
   987             TBool state = ETrue;
       
   988             if ( editPane->IsChangeState() && aLength == ELongKeyPress )
       
   989                 {
       
   990                 state = EFalse;
       
   991                 }
       
   992             else
       
   993                 {
       
   994                 editPane->SetChangeState( EFalse );
       
   995                 }
       
   996             if ( state )
       
   997                 {
       
   998                 editPane->SetChangeState( ETrue );
       
   999                 iOwner->ChangeState( EZhuyinSpelling );
       
  1000                 }
       
  1001             }
       
  1002             break;
       
  1003         case EStdKeyDevice0: //commit to editor
       
  1004         case EStdKeyDevice3:
       
  1005             {
       
  1006             TBool state = ETrue;
       
  1007             if ( editPane->IsChangeState() && aLength == ELongKeyPress )
       
  1008                 {
       
  1009                 state = EFalse;
       
  1010                 }
       
  1011             else
       
  1012                 {
       
  1013                 editPane->SetChangeState( EFalse );
       
  1014                 }
       
  1015             if ( state )
       
  1016                 {
       
  1017                 editPane->SetNeedClearDeliberateSelection( ETrue );
       
  1018                 CommitCandidateL();
       
  1019                 }
       
  1020             }
       
  1021             break;
       
  1022         default:
       
  1023             if (iOwner->FepMan()->IsFlagSet(CAknFepManager::EFlagQwertyChrKeyDepressed))
       
  1024                 {
       
  1025                 iOwner->FepMan()->PlaySound(EAvkonSIDDefaultSound);
       
  1026                 break;
       
  1027                 }
       
  1028             if ( SelectCandidate( aKey ) ) // is 1-6 key 
       
  1029                 {
       
  1030                 editPane->SetNeedClearDeliberateSelection( ETrue );
       
  1031                 CommitCandidateL();
       
  1032                 }
       
  1033             else
       
  1034                 {
       
  1035                 return TAknFepInputMiniQwertyZhuyinPhraseBase::HandleKeyL(
       
  1036                     aKey, aLength );
       
  1037                 }
       
  1038             break;
       
  1039         }
       
  1040     return ret;
       
  1041     }
       
  1042 // ---------------------------------------------------------------------------
       
  1043 // TAknFepInputStateCanindateSelectingMiniQwertyZhuyin::CommitCandidate
       
  1044 // commint the charater to the editor pane 
       
  1045 // ---------------------------------------------------------------------------
       
  1046 
       
  1047 TInt TAknFepInputStateCanindateSelectingMiniQwertyZhuyin::GetIndexOfToneMark( const TDesC& aText)
       
  1048     {
       
  1049     TInt indexOfToneMark = -1;
       
  1050     TInt num = sizeof(ZhuyinToneMap )/( sizeof(ZhuyinToneMap[0]));
       
  1051     TInt len = aText.Length();
       
  1052     for( TInt j = 0; j< len ;j++ )
       
  1053         {
       
  1054         indexOfToneMark = j;
       
  1055         TBuf<1> keyStorkeBuf = aText.Mid( j ,1 );
       
  1056         for (TInt i = 0; i<num; i++ )
       
  1057             {
       
  1058             if (  keyStorkeBuf[0] == ZhuyinToneMap[i].iValue  )
       
  1059                 {
       
  1060                 return indexOfToneMark;
       
  1061                 }
       
  1062             }
       
  1063         }
       
  1064     return -1;
       
  1065     }
       
  1066 // ---------------------------------------------------------------------------
       
  1067 // TAknFepInputStateCanindateSelectingMiniQwertyZhuyin::CommitCandidate
       
  1068 // commint the charater to the editor pane 
       
  1069 // ---------------------------------------------------------------------------
       
  1070 //
       
  1071 void TAknFepInputStateCanindateSelectingMiniQwertyZhuyin::CommitCandidateL()
       
  1072     {
       
  1073     CDesCArrayFlat* keyStrokeArray = UIContainer()->EditPaneWindow()->KeystrokeArray();
       
  1074     CDesCArrayFlat* phraseKeyStrokeArray = UIContainer()->EditPaneWindow()->PhraseShowKeyStrokeArray();
       
  1075     CDesCArrayFlat* phraseArray = UIContainer()->EditPaneWindow()->PhraseArray();
       
  1076     TPtrC candidate = UIContainer()->CandidatePane()->CurrentPhraseCandidate();
       
  1077     
       
  1078     RArray<TInt>* keyCodeArray = UIContainer()->EditPaneWindow()->KeycodeArray();
       
  1079     RArray<TInt>* keyCodePhraseArray = UIContainer()->EditPaneWindow()->PhraseKeycodeArray();
       
  1080     TBuf<KMaxKeystrokeCount> spellingText;
       
  1081     UIContainer()->InputPane()->GetText( spellingText );
       
  1082     phraseArray->AppendL( candidate );
       
  1083     TBuf<KMaxKeystrokeCount> keyStoke;
       
  1084     TInt replaceCount = 0;
       
  1085     TInt delimiterIndex = spellingText.Find( KDelimiter );
       
  1086     if ( KErrNotFound ==delimiterIndex )
       
  1087         {
       
  1088         delimiterIndex = -1;
       
  1089         }
       
  1090     TInt indexOfToneMark = GetIndexOfToneMark( spellingText );
       
  1091     if ( delimiterIndex != KErrNotFound && indexOfToneMark >= 0 )
       
  1092         {
       
  1093         replaceCount = Min( delimiterIndex, indexOfToneMark );
       
  1094         if ( delimiterIndex > indexOfToneMark )
       
  1095             {
       
  1096             replaceCount++;
       
  1097             }
       
  1098         }
       
  1099     else if ( delimiterIndex != KErrNotFound && indexOfToneMark == -1 )
       
  1100         {
       
  1101         replaceCount = delimiterIndex;
       
  1102         }
       
  1103     else if ( delimiterIndex == KErrNotFound && indexOfToneMark != -1 )
       
  1104         {
       
  1105         replaceCount = indexOfToneMark + 1;
       
  1106         }
       
  1107     else
       
  1108         {
       
  1109         replaceCount = spellingText.Length();
       
  1110         } 
       
  1111     for (TInt i = 0; i < replaceCount; i++ )
       
  1112         {
       
  1113         TPtrC ptr = keyStrokeArray->MdcaPoint( 0 );
       
  1114         keyStoke.Append( ptr );
       
  1115         keyStrokeArray->Delete( 0 );
       
  1116         // added for the keycode
       
  1117         TInt keyCodeValue = ( *keyCodeArray )[0];
       
  1118         keyCodePhraseArray->AppendL( keyCodeValue );
       
  1119         keyCodeArray->Remove( 0 );
       
  1120         }
       
  1121     phraseKeyStrokeArray->AppendL( keyStoke );
       
  1122 
       
  1123     if ( GetValidKeystroke() )
       
  1124         {
       
  1125         iOwner->ChangeState( EZhuyinSpelling );
       
  1126         }
       
  1127     else
       
  1128         {
       
  1129         iOwner->ChangeState( EMiniQwertyEdit );
       
  1130         }
       
  1131     UIContainer()->EditPaneWindow()->SetChangeState(ETrue);
       
  1132     RefreshSpellingPane();
       
  1133     RefreshCandidatePane();
       
  1134     ChangeCbaL();
       
  1135     }
       
  1136 
       
  1137 // ---------------------------------------------------------------------------
       
  1138 // TAknFepInputStateCanindateSelectingMiniQwertyZhuyin::CommitCandidate
       
  1139 // to check the select number is valid or not 
       
  1140 // ---------------------------------------------------------------------------
       
  1141 //
       
  1142 TBool TAknFepInputStateCanindateSelectingMiniQwertyZhuyin::SelectCandidate(
       
  1143     TInt aKey )
       
  1144     {
       
  1145     TInt index = 0;
       
  1146     MPtiLanguage *lang= NULL;
       
  1147     RArray <TPtiNumericKeyBinding> keybinding;
       
  1148     TBool validnumkey = EFalse;
       
  1149     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
  1150     TPtiKeyboardType keyboardtype = iOwner->FepMan()->KeyboardLayout();
       
  1151     lang = ptiengine->CurrentLanguage();
       
  1152     if ( ptiengine && lang  )
       
  1153         {
       
  1154         TRAP_IGNORE(ptiengine->GetNumericModeKeysForQwertyL(lang->LanguageCode(), keybinding, keyboardtype));
       
  1155         TInt numericKeysCount = keybinding.Count();
       
  1156         while (numericKeysCount-- )
       
  1157             {
       
  1158             TPtiNumericKeyBinding numKeyBind = keybinding[numericKeysCount];
       
  1159             if ( (numKeyBind.iChar >= 0x31 && numKeyBind.iChar <= 0x36)
       
  1160                 &&(aKey == numKeyBind.iKey) )
       
  1161                 {
       
  1162                 index = numKeyBind.iChar - EPtiKey0 -1;
       
  1163                 if ( UIContainer()->CandidatePane()->SelectIndex( index, EFalse ) )
       
  1164                     {
       
  1165                     validnumkey = ETrue;
       
  1166                     }
       
  1167                 break;
       
  1168                 }
       
  1169             }
       
  1170         }
       
  1171     keybinding.Reset();
       
  1172     return validnumkey;
       
  1173     }
       
  1174 // ---------------------------------------------------------------------------
       
  1175 // TAknFepInputStateEditingMiniQwertyZhuyinPhrase::HandleCommandL
       
  1176 // Handling Command
       
  1177 // ---------------------------------------------------------------------------
       
  1178 //
       
  1179 void TAknFepInputStateEditingMiniQwertyZhuyinPhrase::HandleCommandL(
       
  1180     TInt aCommandId )
       
  1181     {
       
  1182     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
  1183     MAknFepUICtrlCandidatePane* candidatePane =
       
  1184         UIContainer()->CandidatePane();
       
  1185     MAknFepUICtrlEditPane* editPane = UIContainer()->EditPaneWindow();
       
  1186     TBool state = ETrue;
       
  1187     switch ( aCommandId )
       
  1188         {
       
  1189         // Handle the event frome command.
       
  1190         case EAknSoftkeySelect:
       
  1191             //case (TUint16)EAknSoftkeySelect: //the Selected in soft CBA
       
  1192             if ( editPane->IsChangeState() )
       
  1193                 {
       
  1194                 state = EFalse;
       
  1195                 }
       
  1196             else
       
  1197                 {
       
  1198                 editPane->SetChangeState( EFalse );
       
  1199                 }
       
  1200             if ( state )
       
  1201                 {
       
  1202                 HandleCommitL();
       
  1203                 }
       
  1204             break;
       
  1205         default:
       
  1206             TAknFepInputStateChineseBase::HandleCommandL( aCommandId );
       
  1207             break;
       
  1208         }
       
  1209     }
       
  1210 
       
  1211 // ---------------------------------------------------------------------------
       
  1212 // TAknFepInputStateSpellingMiniQwertyZhuyin::HandleCommandL
       
  1213 // Handling Command
       
  1214 // ---------------------------------------------------------------------------
       
  1215 //
       
  1216 void TAknFepInputStateSpellingMiniQwertyZhuyin::HandleCommandL(
       
  1217     TInt aCommandId )
       
  1218     {
       
  1219     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
  1220     MAknFepUICtrlCandidatePane* candidatePane =
       
  1221         UIContainer()->CandidatePane();
       
  1222     MAknFepUICtrlEditPane* editPane = UIContainer()->EditPaneWindow();
       
  1223     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
  1224     TBool state = ETrue;
       
  1225     switch ( aCommandId )
       
  1226         {
       
  1227         // Handle the event frome command.
       
  1228         case EAknSoftkeySelect:
       
  1229             //case (TUint16)EAknSoftkeySelect: //the Selected in soft CBA
       
  1230             if ( editPane->IsChangeState() )
       
  1231                 {
       
  1232                 state = EFalse;
       
  1233                 }
       
  1234             else
       
  1235                 {
       
  1236                 editPane->SetChangeState( EFalse );
       
  1237                 }
       
  1238             if ( state )
       
  1239                 {
       
  1240                 if ( popup->IsEnabled() )
       
  1241                     {
       
  1242                     popup->Enable( EFalse );
       
  1243                     }
       
  1244                 editPane->SetChangeState( ETrue );
       
  1245                 iOwner->ChangeState( EZhuyinCandidate );
       
  1246                 }
       
  1247             break;
       
  1248         default:
       
  1249             TAknFepInputStateChineseBase::HandleCommandL( aCommandId );
       
  1250             break;
       
  1251         }
       
  1252     }
       
  1253 
       
  1254 // ---------------------------------------------------------------------------
       
  1255 // TAknFepInputStateCanindateSelectingMiniQwertyZhuyin::HandleCommandL
       
  1256 // Handling Command
       
  1257 // ---------------------------------------------------------------------------
       
  1258 //
       
  1259 void TAknFepInputStateCanindateSelectingMiniQwertyZhuyin::HandleCommandL(
       
  1260     TInt aCommandId )
       
  1261     {
       
  1262     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
  1263     MAknFepUICtrlCandidatePane* candidatePane =
       
  1264         UIContainer()->CandidatePane();
       
  1265     MAknFepUICtrlEditPane* editPane = UIContainer()->EditPaneWindow();
       
  1266     TBool state = ETrue;
       
  1267     switch ( aCommandId )
       
  1268         {
       
  1269         // Handle the event frome command.
       
  1270         case EAknSoftkeySelect:
       
  1271             //case (TUint16)EAknSoftkeySelect: //the Selected in soft CBA
       
  1272             if ( editPane->IsChangeState() )
       
  1273                 {
       
  1274                 state = EFalse;
       
  1275                 }
       
  1276             else
       
  1277                 {
       
  1278                 editPane->SetChangeState( EFalse );
       
  1279                 }
       
  1280             if ( state )
       
  1281                 {
       
  1282                 editPane->SetNeedClearDeliberateSelection( ETrue );
       
  1283                 CommitCandidateL();
       
  1284                 }
       
  1285 
       
  1286             break;
       
  1287         default:
       
  1288             TAknFepInputStateChineseBase::HandleCommandL( aCommandId );
       
  1289             break;
       
  1290         }
       
  1291     }
       
  1292 //End of File