fep/aknfep/src/aknfepinputstatepinyinphrasecreationbase.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 TAknFepInputStateEntryPinyinPhraseCreation methods.
       
    16  *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 
       
    30 #include <PtiEngine.h>                          //CPtiEngine
       
    31 #include <PtiUserDicEntry.h>
       
    32 #include <avkon.rsg>
       
    33 #include <aknfep.rsg>
       
    34 
       
    35 #include "aknfepinputstatepinyinphrasecreationbase.h"
       
    36 #include "AknFepPanic.h"
       
    37 #include "AknFepUIManagerStateInterface.h"      //MAknFepUIManagerStateInterface
       
    38 #include "AknFepManagerUIInterface.h"           //MAknFepManagerUIInterface
       
    39 #include "AknFepUiCtrlContainerChinese.h"
       
    40 #include "AknFepUICtrlPinyinPopup.h"    //Pinyin phrase
       
    41 #include "aknfepuictrleditpane.h" 
       
    42 #include "AknFepUICtrlCandidatePane.h"
       
    43 #include "AknFepUICtrlInputPane.h"
       
    44 
       
    45 const TUint16 KToneMarkLib[] = 
       
    46     {
       
    47     0x02C9, 0x02CA, 0x02C7, 0x02CB, 0x02D9
       
    48     };
       
    49 
       
    50 const TUint16 KDelimiter =0x0027; 
       
    51 const TInt KToneMarkMax = 5;
       
    52 const TInt KMaxKeystrokeCount = 31;
       
    53 const TInt KMaxPhraseCreationCount = 7;
       
    54 
       
    55 _LIT( KKey2, "2");
       
    56 _LIT( KKey3, "3");
       
    57 _LIT( KKey4, "4");
       
    58 _LIT( KKey5, "5");
       
    59 _LIT( KKey6, "6");
       
    60 _LIT( KKey7, "7");
       
    61 _LIT( KKey8, "8");
       
    62 _LIT( KKey9, "9");
       
    63 //KMaxPhraseNote means the max phrase is seven
       
    64 _LIT( KMaxPhraseNote,"\x8BCD\x7EC4\x6700\x957F\x4E3A\x4E03\x5B57" );
       
    65 
       
    66 // ---------------------------------------------------------
       
    67 // C++ constructor
       
    68 // ---------------------------------------------------------
       
    69 //
       
    70 TAknFepInputStatePinyinPhraseCreationBase::TAknFepInputStatePinyinPhraseCreationBase(
       
    71     MAknFepUIManagerStateInterface* aOwner,
       
    72     MAknFepUICtrlContainerChinese* aUIContainer ) :
       
    73     TAknFepInputStateCandidateBase( aOwner, aUIContainer )
       
    74     {    
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------
       
    78 // Add keystroke.
       
    79 // ---------------------------------------------------------
       
    80 //
       
    81 TBool TAknFepInputStatePinyinPhraseCreationBase::AddKeystroke( TInt aKey )
       
    82     {
       
    83     TBool result = ETrue;
       
    84     TRAPD( ret, result = AddKeystrokeL( aKey ) );
       
    85     if ( KErrNone != ret )
       
    86         {
       
    87         return EFalse;
       
    88         }
       
    89     return result;
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------
       
    93 // Add tone mark.
       
    94 // ---------------------------------------------------------
       
    95 //
       
    96 TBool TAknFepInputStatePinyinPhraseCreationBase::AddToneMark()
       
    97     {
       
    98     TBool result = ETrue;
       
    99     TRAPD( ret, result = AddToneMarkL() );
       
   100     if ( KErrNone != ret )
       
   101         {
       
   102         return EFalse;
       
   103         }
       
   104     return result;
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------
       
   108 // get the valid keystroke.
       
   109 // ---------------------------------------------------------
       
   110 //
       
   111 TBool TAknFepInputStatePinyinPhraseCreationBase::GetValidKeystroke()
       
   112     {
       
   113     TBool result = ETrue;
       
   114     TRAPD( ret, result = GetValidKeystrokeL() );
       
   115     if ( KErrNone != ret )
       
   116         {
       
   117         return EFalse;
       
   118         }
       
   119     return result;
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------
       
   123 // Delete current keystroke.
       
   124 // ---------------------------------------------------------
       
   125 //
       
   126 TBool TAknFepInputStatePinyinPhraseCreationBase::DeleteCurrentKeystroke()
       
   127     {
       
   128     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   129     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   130     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   131     CDesCArrayFlat* showKeystroke = popup->ShowKeystrokeArray();
       
   132     TInt index = editPane->GetCursorIndexOfKeystroke();
       
   133     
       
   134     if ( 0 == index )
       
   135         {
       
   136         return EFalse;
       
   137         }
       
   138     
       
   139     showKeystroke->Delete( index - 1 );
       
   140     editPane->SetCursorIndexOfKeystroke( index - 1 );
       
   141     
       
   142     return ETrue;
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------
       
   146 // Delete current keystroke.
       
   147 // ---------------------------------------------------------
       
   148 //
       
   149 TBool TAknFepInputStatePinyinPhraseCreationBase::ChineseRevertKeystroke()
       
   150     {
       
   151     TBool result = ETrue;
       
   152     TRAPD( ret, result = ChineseRevertKeystrokeL() );
       
   153     if ( KErrNone != ret )
       
   154         {
       
   155         return EFalse;
       
   156         }
       
   157     return result;
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------
       
   161 // show info to the eep ctrl.
       
   162 // ---------------------------------------------------------
       
   163 //
       
   164 void TAknFepInputStatePinyinPhraseCreationBase::ShowInfo()
       
   165     {
       
   166     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   167     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   168     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   169     CDesCArrayFlat* showKeystroke = popup->ShowKeystrokeArray();
       
   170     CDesCArrayFlat* chinese = popup->ChooseChineseCharacterArray();
       
   171     TInt index = editPane->GetCursorIndexOfKeystroke();
       
   172     
       
   173     TBuf<KMaxKeystrokeCount> buf;
       
   174     
       
   175     for ( TInt i = 0; i < chinese->Count(); ++i )
       
   176         {
       
   177         buf.Append( chinese->MdcaPoint( i ) );
       
   178         }
       
   179     
       
   180     for ( TInt i = 0; i < showKeystroke->Count(); ++i )
       
   181         {
       
   182         buf.Append( showKeystroke->MdcaPoint( i ) );
       
   183         }
       
   184     
       
   185     if ( showKeystroke->Count() == 0 )
       
   186         {
       
   187         editPane->SetCursorIndexOfKeystroke( 0 );
       
   188         index = 0;
       
   189         }
       
   190     
       
   191     editPane->SetText( buf, chinese->Count() + index );
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------
       
   195 // set the show info warning color.
       
   196 // ---------------------------------------------------------
       
   197 //
       
   198 void TAknFepInputStatePinyinPhraseCreationBase::SetWarningColor()
       
   199     {
       
   200     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   201     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   202     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   203     TInt showKeystrokeCount = popup->ShowKeystrokeArray()->Count();
       
   204     TInt chineseCount = popup->ChooseChineseCharacterArray()->Count();
       
   205     TInt validKeytrokeCount = popup->KeystrokeArray()->Count();
       
   206     if ( 0 == validKeytrokeCount )
       
   207         {
       
   208         editPane->SetHighlight( chineseCount, chineseCount + showKeystrokeCount );
       
   209         }
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------
       
   213 // Get the candidate info.
       
   214 // ---------------------------------------------------------
       
   215 //
       
   216 void TAknFepInputStatePinyinPhraseCreationBase::GetCandidate( TInt aSelection )
       
   217     {
       
   218     TRAP_IGNORE( GetCandidateL( aSelection ) );
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------
       
   222 // Change CBA
       
   223 // ---------------------------------------------------------
       
   224 //
       
   225 void TAknFepInputStatePinyinPhraseCreationBase::ChangeCba()
       
   226     {
       
   227     TRAP_IGNORE( ChangeCbaL() );
       
   228     }
       
   229 
       
   230 // ---------------------------------------------------------
       
   231 // Refresh UI
       
   232 // ---------------------------------------------------------
       
   233 //
       
   234 void TAknFepInputStatePinyinPhraseCreationBase::RefreshCandidate()
       
   235     {
       
   236     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   237     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   238     MAknFepUICtrlInputPane* inputPane = uiContainer->InputPane();
       
   239     CDesCArrayFlat* validKeystroke = popup->InEffectKeystrokeArray();
       
   240     CDesCArrayFlat* spelling = popup->PhoneticSpellingArray();
       
   241     CDesCArrayFlat* candidateArray = 
       
   242         uiContainer->CandidatePane()->CandidateArray();
       
   243     TInt chineseCount = popup->ChooseChineseCharacterArray()->Count();
       
   244     // have valid keystroke.
       
   245     if ( validKeystroke->Count() > 0 )
       
   246         {
       
   247         uiContainer->SetControlInVisible( ETrue );
       
   248         // set display page for delibrate selection
       
   249         ClearDeliberateSelection();
       
   250         GetCandidate( );
       
   251         uiContainer->CandidatePane()->SplitPhraseCandidatesIntoPages();
       
   252         uiContainer->CandidatePane()->SetCandidateBuffer();
       
   253         uiContainer->Enable( ETrue );
       
   254         uiContainer->ShowHorizontalScrollArrows( EFalse );
       
   255         uiContainer->ShowVerticalScrollArrows( ETrue );
       
   256         }
       
   257     else
       
   258         {
       
   259         candidateArray->Reset();
       
   260         if ( KMaxPhraseCreationCount == chineseCount )
       
   261             {
       
   262             uiContainer->SetControlInVisible( ETrue );
       
   263             TRAP_IGNORE( candidateArray->AppendL( KMaxPhraseNote ) );
       
   264             }
       
   265         else
       
   266             {
       
   267             uiContainer->SetControlInVisible( EFalse );
       
   268             }
       
   269         
       
   270         uiContainer->CandidatePane()->SplitPhraseCandidatesIntoPages();
       
   271         uiContainer->CandidatePane()->SetCandidateBuffer();
       
   272         uiContainer->Enable( ETrue );
       
   273         uiContainer->ShowHorizontalScrollArrows( EFalse );
       
   274         uiContainer->ShowVerticalScrollArrows( EFalse );
       
   275         }    
       
   276         
       
   277     if (  EKeySequenceEdit == iState )
       
   278         {
       
   279         //popup->SetNoneHighlighted();
       
   280         }
       
   281     uiContainer->Enable(ETrue);
       
   282     popup->Enable( validKeystroke->Count() > 0 );    
       
   283     UpdateIndicator();
       
   284     }
       
   285 
       
   286 // ---------------------------------------------------------
       
   287 // Refresh UI
       
   288 // ---------------------------------------------------------
       
   289 //
       
   290 void TAknFepInputStatePinyinPhraseCreationBase::RefreshUI(TInt aSelection)
       
   291     {
       
   292     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   293     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   294     MAknFepUICtrlInputPane* inputPane = uiContainer->InputPane();
       
   295     CDesCArrayFlat* validKeystroke = popup->InEffectKeystrokeArray();
       
   296     CDesCArrayFlat* spelling = popup->PhoneticSpellingArray();
       
   297     CDesCArrayFlat* candidateArray = 
       
   298         uiContainer->CandidatePane()->CandidateArray();
       
   299     TInt chineseCount = popup->ChooseChineseCharacterArray()->Count();
       
   300     // have valid keystroke.
       
   301     if ( validKeystroke->Count() > 0 )
       
   302         {
       
   303         uiContainer->SetControlInVisible( ETrue );
       
   304         popup->SplitPhraseSpellingIntoPages();
       
   305         inputPane->SetText( spelling->MdcaPoint( aSelection ) );
       
   306         // set display page for delibrate selection
       
   307         popup->SetDisplayPage(aSelection);
       
   308         popup->SetPhraseItemTexts();
       
   309         popup->PopupSizeChanged();
       
   310         GetCandidate( aSelection );
       
   311         uiContainer->CandidatePane()->SplitPhraseCandidatesIntoPages();
       
   312         uiContainer->CandidatePane()->SetCandidateBuffer();
       
   313         uiContainer->Enable( ETrue );
       
   314         uiContainer->ShowHorizontalScrollArrows( EFalse );
       
   315         uiContainer->ShowVerticalScrollArrows( ETrue );
       
   316         }
       
   317     else
       
   318         {
       
   319         candidateArray->Reset();
       
   320         if ( KMaxPhraseCreationCount == chineseCount )
       
   321             {
       
   322             uiContainer->SetControlInVisible( ETrue );
       
   323             TRAP_IGNORE( candidateArray->AppendL( KMaxPhraseNote ) );
       
   324             }
       
   325         else
       
   326             {
       
   327             uiContainer->SetControlInVisible( EFalse );
       
   328             }
       
   329         
       
   330         uiContainer->CandidatePane()->SplitPhraseCandidatesIntoPages();
       
   331         uiContainer->CandidatePane()->SetCandidateBuffer();
       
   332         uiContainer->Enable( ETrue );
       
   333         uiContainer->ShowHorizontalScrollArrows( EFalse );
       
   334         uiContainer->ShowVerticalScrollArrows( EFalse );
       
   335         }    
       
   336         
       
   337     if (  EKeySequenceEdit == iState )
       
   338         {
       
   339         popup->SetNoneHighlighted();
       
   340         }
       
   341     uiContainer->Enable(ETrue);
       
   342     popup->Enable( validKeystroke->Count() > 0 );    
       
   343     UpdateIndicator();
       
   344     }
       
   345 
       
   346 // ---------------------------------------------------------
       
   347 // clear selection.
       
   348 // ---------------------------------------------------------
       
   349 //
       
   350 void TAknFepInputStatePinyinPhraseCreationBase::ClearDeliberateSelection()
       
   351     {
       
   352     // we must have just deleted the last character, 
       
   353     // or we are starting a new pinyin session, so wipe the last deliberate selection
       
   354     TPtr oldDeliberateSelection = iOwner->GetLatestDeliberateSelection();
       
   355     oldDeliberateSelection = KNullDesC;
       
   356     }
       
   357 
       
   358 // ---------------------------------------------------------
       
   359 // clear the keystroke of PtiEngine.
       
   360 // ---------------------------------------------------------
       
   361 //
       
   362 void TAknFepInputStatePinyinPhraseCreationBase::ClearPtiEngineKeystroke()
       
   363     {
       
   364     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   365     for ( TInt i = 0; i < KMaxKeystrokeCount; ++i )
       
   366         {
       
   367         ptiengine->DeleteKeyPress();
       
   368         }
       
   369     }
       
   370 
       
   371 
       
   372 // ---------------------------------------------------------
       
   373 // Get the code of Keystroke in ITUT.
       
   374 // ---------------------------------------------------------
       
   375 //
       
   376 TInt TAknFepInputStatePinyinPhraseCreationBase::GetKeystrokeCode(
       
   377                                                        TPtiKey& aKey, 
       
   378                                                        const TDesC& aKeystroke )
       
   379     {    
       
   380     if ( aKeystroke.Length() < 1 )
       
   381         {
       
   382         return EKeyStrokeNull;
       
   383         }
       
   384     
       
   385     // the input key is delimiter the return -1.
       
   386     if ( KDelimiter == aKeystroke[0] )
       
   387         {
       
   388         aKey = EPtiKey1;
       
   389         return EKeyDelimiter;
       
   390         }
       
   391     // the input key is tone mark return tone mark.
       
   392     for ( TInt i = 0; i < KToneMarkMax; ++i )
       
   393         {
       
   394         if ( KToneMarkLib[i] == aKeystroke[0] )
       
   395             {
       
   396             return i + 1;
       
   397             }
       
   398         }
       
   399     // the keystroke is 2 - 9.
       
   400     if ( 0 == aKeystroke.Compare( KKey2 ) )
       
   401         {
       
   402         aKey = EPtiKey2;
       
   403         }
       
   404     else if ( 0 == aKeystroke.Compare( KKey3 ) )
       
   405         {
       
   406         aKey = EPtiKey3;
       
   407         }
       
   408     else if ( 0 == aKeystroke.Compare( KKey4 ) )
       
   409         {
       
   410         aKey = EPtiKey4;
       
   411         }
       
   412     else if ( 0 == aKeystroke.Compare( KKey5 ) )
       
   413         {
       
   414         aKey = EPtiKey5;
       
   415         }
       
   416     else if ( 0 == aKeystroke.Compare( KKey6 ) )
       
   417         {
       
   418         aKey = EPtiKey6;
       
   419         }
       
   420     else if ( 0 == aKeystroke.Compare( KKey7 ) )
       
   421         {
       
   422         aKey = EPtiKey7;
       
   423         }
       
   424     else if ( 0 == aKeystroke.Compare( KKey8 ) )
       
   425         {
       
   426         aKey = EPtiKey8;
       
   427         }
       
   428     else if ( 0 == aKeystroke.Compare( KKey9 ) )
       
   429         {
       
   430         aKey = EPtiKey9;
       
   431         }
       
   432     return EkeyNumber;
       
   433     }
       
   434 
       
   435 
       
   436 // ---------------------------------------------------------
       
   437 // Append the key to the ptiengine.
       
   438 // ---------------------------------------------------------
       
   439 //
       
   440 TBool TAknFepInputStatePinyinPhraseCreationBase::AppendKeyPressL( 
       
   441                                                  TPtiKey& aKey,
       
   442                                                  TBool aAddSpellingFlag
       
   443                                                  )
       
   444     {
       
   445     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   446     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   447     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   448     CDesCArrayFlat* tempSpelling = popup->TempSpelling();
       
   449     CDesCArrayFlat* spelling = popup->PhoneticSpellingArray();
       
   450     CDesCArrayFlat* afterCheck = popup->OptimizeSpelling();
       
   451     
       
   452     tempSpelling->Reset();
       
   453     afterCheck->Reset();
       
   454     TInt stringBeforeLength = ptiengine->GetPhoneticSpelling(1).Length();
       
   455     TInt stringAfterLength = ptiengine->AppendKeyPress(aKey).Length();
       
   456     // the pti can't append key.
       
   457     if ( stringBeforeLength == stringAfterLength )
       
   458         {
       
   459         return EFalse;
       
   460         }
       
   461     // get the spelling by pti.
       
   462     ptiengine->GetPhoneticSpellingsL( *tempSpelling );
       
   463     // delete the phrase spelling.
       
   464     CheckSpellingL( tempSpelling, afterCheck );
       
   465     if ( afterCheck->Count() > 0 )
       
   466         {
       
   467         if ( !aAddSpellingFlag )
       
   468             {
       
   469             for( TInt i = afterCheck->Count() - 1; i >= 0; --i )
       
   470                 {
       
   471                 spelling->InsertL( 0, afterCheck->MdcaPoint( i ) );
       
   472                 }
       
   473             }
       
   474         return ETrue;            
       
   475         }
       
   476     
       
   477     return EFalse;
       
   478     }
       
   479 
       
   480 // ---------------------------------------------------------
       
   481 // Append the tone mark to the ptiengine.
       
   482 // ---------------------------------------------------------
       
   483 //
       
   484 TBool TAknFepInputStatePinyinPhraseCreationBase::AppendToneMarkL( TInt& aToneMark )
       
   485     {
       
   486     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   487     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   488     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   489     CDesCArrayFlat* tempSpelling = popup->TempSpelling();
       
   490     CDesCArrayFlat* spelling = popup->PhoneticSpellingArray();    
       
   491     
       
   492     for ( TInt i = 0; i < aToneMark; ++i )
       
   493         {
       
   494         tempSpelling->Reset();
       
   495         ptiengine->IncrementToneMark( ETrue );
       
   496         // get the spelling by pti.
       
   497         ptiengine->GetPhoneticSpellingsL( *tempSpelling );
       
   498         if ( CheckToneMark( aToneMark ) )
       
   499             {
       
   500             break;
       
   501             }
       
   502         }
       
   503     
       
   504     if ( tempSpelling->Count() > 0 )
       
   505         {
       
   506         for ( TInt i = tempSpelling->Count() - 1; i >= 0; --i )
       
   507             {
       
   508             spelling->InsertL( 0, tempSpelling->MdcaPoint( i ) );
       
   509             }
       
   510         return ETrue;
       
   511         }
       
   512     
       
   513     return EFalse;
       
   514     }
       
   515 
       
   516 // ---------------------------------------------------------
       
   517 // check the spelling delete the phrase spelling.
       
   518 // ---------------------------------------------------------
       
   519 //
       
   520 void TAknFepInputStatePinyinPhraseCreationBase::CheckSpellingL(
       
   521                                                CDesCArrayFlat* aTempSpelling,
       
   522                                                CDesCArrayFlat* aAfterCheck
       
   523                                                )
       
   524     {
       
   525     TBuf<1> buf;
       
   526     buf.Append( KDelimiter );
       
   527     for (TInt i = 0; i < aTempSpelling->Count(); ++i )
       
   528         {
       
   529         if ( KErrNotFound == aTempSpelling->MdcaPoint(i).Find( buf ) )
       
   530             {
       
   531             aAfterCheck->AppendL( aTempSpelling->MdcaPoint(i) );
       
   532             }
       
   533         }
       
   534     }
       
   535 
       
   536 // ---------------------------------------------------------
       
   537 // check the tone mark and delete the phrase spelling.
       
   538 // ---------------------------------------------------------
       
   539 //
       
   540 TBool TAknFepInputStatePinyinPhraseCreationBase::CheckToneMark( TInt& aToneMark )
       
   541     {
       
   542     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   543     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   544     CDesCArrayFlat* tempSpelling = popup->TempSpelling();
       
   545     TBuf<1> delimiter;
       
   546     delimiter.Append( KDelimiter );
       
   547     
       
   548     for ( TInt i = tempSpelling->Count() - 1; i >= 0; --i )
       
   549         {
       
   550         if ( KErrNotFound != tempSpelling->MdcaPoint( i ).Find( delimiter ) )
       
   551             {
       
   552             tempSpelling->Delete( i );
       
   553             }
       
   554         else
       
   555             {
       
   556             if ( KToneMarkLib[ aToneMark - 1 ] != 
       
   557                 tempSpelling->MdcaPoint( i ).Right( 1 )[0] )
       
   558                 {
       
   559                 tempSpelling->Delete( i );
       
   560                 }
       
   561             }
       
   562         }
       
   563     tempSpelling->Compress();
       
   564     return tempSpelling->Count();
       
   565     }
       
   566 
       
   567 
       
   568 // ---------------------------------------------------------
       
   569 // Add keystroke.
       
   570 // ---------------------------------------------------------
       
   571 //
       
   572 TBool TAknFepInputStatePinyinPhraseCreationBase::AddKeystrokeL( TInt aKey )
       
   573     {
       
   574     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   575     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   576     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   577     CDesCArrayFlat* showKeystroke = popup->ShowKeystrokeArray();
       
   578     TInt index = editPane->GetCursorIndexOfKeystroke();
       
   579     TInt chineseCount = popup->ChooseChineseCharacterArray()->Count();
       
   580     TBuf<1> key;
       
   581     
       
   582     if ( showKeystroke->Count() + chineseCount >= KMaxKeystrokeCount )
       
   583         {
       
   584         return EFalse;
       
   585         }
       
   586     
       
   587     if ( KMaxPhraseCreationCount == chineseCount )
       
   588         {
       
   589         return EFalse;
       
   590         }
       
   591     
       
   592     switch( (TPtiKey)aKey )
       
   593         {
       
   594         case EPtiKey0:
       
   595             key.Append( KDelimiter );
       
   596             break;
       
   597         case EPtiKey1:
       
   598             key.Append( KDelimiter );
       
   599             break;
       
   600         case EPtiKey2:
       
   601             key.Append( EPtiKey2 );
       
   602             break;
       
   603         case EPtiKey3:
       
   604             key.Append( EPtiKey3 );
       
   605             break;
       
   606         case EPtiKey4:
       
   607             key.Append( EPtiKey4 );
       
   608             break;
       
   609         case EPtiKey5:
       
   610             key.Append( EPtiKey5 );
       
   611             break;
       
   612         case EPtiKey6:
       
   613             key.Append( EPtiKey6 );
       
   614             break;  
       
   615         case EPtiKey7:
       
   616             key.Append( EPtiKey7 );
       
   617             break;
       
   618         case EPtiKey8:
       
   619             key.Append( EPtiKey8 );
       
   620             break;
       
   621         case EPtiKey9:
       
   622             key.Append( EPtiKey9 );
       
   623             break;
       
   624         default:
       
   625             return EFalse;
       
   626         }
       
   627     
       
   628     if ( index > showKeystroke->Count() )
       
   629         {
       
   630         index = showKeystroke->Count();
       
   631         }
       
   632     
       
   633     showKeystroke->InsertL( index, key );
       
   634     editPane->SetCursorIndexOfKeystroke( index + 1 );
       
   635     return ETrue;
       
   636     }
       
   637 
       
   638 // ---------------------------------------------------------
       
   639 // Add tone mark.
       
   640 // ---------------------------------------------------------
       
   641 //
       
   642 TBool TAknFepInputStatePinyinPhraseCreationBase::AddToneMarkL()
       
   643     {
       
   644     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   645     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   646     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   647     CDesCArrayFlat* showKeystroke = popup->ShowKeystrokeArray();
       
   648     TInt index = editPane->GetCursorIndexOfKeystroke();
       
   649     TInt chineseCount = popup->ChooseChineseCharacterArray()->Count();
       
   650     TBuf<1> key;
       
   651     TInt toneMark( 0 );
       
   652     
       
   653     if ( KMaxPhraseCreationCount == chineseCount )
       
   654         {
       
   655         return EFalse;
       
   656         }
       
   657     
       
   658     if ( showKeystroke->Count() + chineseCount >= KMaxKeystrokeCount )
       
   659         {
       
   660         if ( 0 == index )
       
   661             {
       
   662             return EFalse;
       
   663             }
       
   664         for ( TInt i = 0; i < KToneMarkMax; ++i )
       
   665             {
       
   666             if ( KToneMarkLib[i] == showKeystroke->MdcaPoint( index - 1 )[0] )
       
   667                 {
       
   668                 toneMark = i + 1;
       
   669                 break;
       
   670                 }
       
   671             }
       
   672         if ( 0 == toneMark )
       
   673             {
       
   674             return EFalse;
       
   675             }
       
   676         }
       
   677     
       
   678     if ( 0 == index )
       
   679         {
       
   680         key.Append( KToneMarkLib[0] );
       
   681         showKeystroke->InsertL( 0, key );
       
   682         editPane->SetCursorIndexOfKeystroke( 1 );
       
   683         return ETrue;
       
   684         }
       
   685     
       
   686     for ( TInt i = 0; i < KToneMarkMax; ++i )
       
   687         {
       
   688         if ( KToneMarkLib[i] == showKeystroke->MdcaPoint( index - 1 )[0] )
       
   689             {
       
   690             toneMark = i + 1;
       
   691             break;
       
   692             }
       
   693         }
       
   694     
       
   695     if ( 0 == toneMark )
       
   696         {
       
   697         key.Append( KToneMarkLib[0] );
       
   698         showKeystroke->InsertL( index, key );
       
   699         editPane->SetCursorIndexOfKeystroke( index + 1 );
       
   700         }
       
   701     else if ( KToneMarkMax == toneMark )
       
   702         {
       
   703         key.Append( KToneMarkLib[0] );
       
   704         showKeystroke->Delete( index - 1 );
       
   705         showKeystroke->InsertL( index - 1, key );
       
   706         }
       
   707     else
       
   708         {
       
   709         key.Append( KToneMarkLib[toneMark] );
       
   710         showKeystroke->Delete( index - 1 );
       
   711         showKeystroke->InsertL( index - 1, key );
       
   712         }
       
   713     
       
   714     return ETrue;
       
   715     }
       
   716 
       
   717 // ---------------------------------------------------------
       
   718 //  check the keystroke.
       
   719 // ---------------------------------------------------------
       
   720 //
       
   721 TBool TAknFepInputStatePinyinPhraseCreationBase::IsToneMark( const TDesC& aInput )
       
   722     {
       
   723     for ( TInt i = 0; i < KToneMarkMax; ++i )
       
   724         {
       
   725         if ( KToneMarkLib[i] == aInput[0] )
       
   726             {
       
   727             return ETrue;
       
   728             }
       
   729         }
       
   730     return EFalse;
       
   731     }
       
   732 // ---------------------------------------------------------
       
   733 //  check the keystroke.
       
   734 // ---------------------------------------------------------
       
   735 //
       
   736 TBool TAknFepInputStatePinyinPhraseCreationBase::CheckKeystroke()
       
   737     {
       
   738     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   739     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   740     CDesCArrayFlat* showKeystroke = popup->ShowKeystrokeArray();
       
   741     TBuf<1> buf;
       
   742     buf.Append( KDelimiter );
       
   743     // if the keystroke is null then the keystroke is invalid.
       
   744     if ( 0 == showKeystroke->Count() )
       
   745         {
       
   746         return EFalse;
       
   747         }
       
   748     // if the first keystroke is delimiter then keytroke is invalid. 
       
   749     if ( KDelimiter == showKeystroke->MdcaPoint( 0 )[0] )
       
   750         {
       
   751         return EFalse;
       
   752         }
       
   753     // if the first keystroke is Tone mark then keytroke is invalid.
       
   754     for ( TInt i = 0; i < KToneMarkMax; ++i )
       
   755         {
       
   756         if ( KToneMarkLib[i] == showKeystroke->MdcaPoint( 0 )[0] )
       
   757             {
       
   758             return EFalse;
       
   759             }            
       
   760         }
       
   761     // the first keystroke is not delimiter and tone mark, if the number of keystroke
       
   762     // is not more than two then must the keytroke are all valid.
       
   763     if ( showKeystroke->Count() <= 2 )
       
   764         {
       
   765         return ETrue;
       
   766         }
       
   767     
       
   768     return ETrue;
       
   769     }
       
   770 
       
   771 // ---------------------------------------------------------
       
   772 // get the valid keystroke.
       
   773 // ---------------------------------------------------------
       
   774 //
       
   775 TBool TAknFepInputStatePinyinPhraseCreationBase::GetValidKeystrokeL()
       
   776     {
       
   777     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   778     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   779     CDesCArrayFlat* showKeystroke = popup->ShowKeystrokeArray();
       
   780     CDesCArrayFlat* spelling = popup->PhoneticSpellingArray();
       
   781     CDesCArrayFlat* allValidKeystroke = popup->KeystrokeArray();
       
   782     CDesCArrayFlat* validKeystroke = popup->InEffectKeystrokeArray();
       
   783     TInt allValidKeyLen = allValidKeystroke->Count();
       
   784     TPtiKey key;
       
   785     TInt retCode(0);
       
   786     TBool nextIsToneMark = EFalse;
       
   787     TBuf<1> delimiter;
       
   788     TBuf<KMaxKeystrokeCount> beforeBuf;
       
   789     TBuf<KMaxKeystrokeCount> afterBuf;
       
   790     
       
   791     delimiter.Append( KDelimiter );
       
   792     
       
   793     for ( TInt i = 0; i < allValidKeyLen; ++i )
       
   794         {
       
   795         if ( 0 == allValidKeystroke->MdcaPoint( i ).Compare( delimiter ) )
       
   796             {
       
   797             break;
       
   798             }
       
   799         beforeBuf.Append( allValidKeystroke->MdcaPoint( i ) );
       
   800         }
       
   801     
       
   802     spelling->Reset();
       
   803     validKeystroke->Reset();
       
   804     allValidKeystroke->Reset();
       
   805     
       
   806     ClearPtiEngineKeystroke();
       
   807     if ( !CheckKeystroke() )
       
   808         {
       
   809         if ( allValidKeyLen > 0 )
       
   810             {
       
   811             popup->SetValidKeystrokeChange( ETrue );
       
   812             }
       
   813         else
       
   814             {
       
   815             popup->SetValidKeystrokeChange( EFalse );
       
   816             }
       
   817         return EFalse;
       
   818         }
       
   819     
       
   820     // the firts keystroke is key 2 - 9.    
       
   821     for ( TInt i = 0; i < showKeystroke->Count(); ++i )
       
   822         {
       
   823         retCode = GetKeystrokeCode( key, showKeystroke->MdcaPoint( i ) );
       
   824         //the keystroke is delimiter.
       
   825         if ( -1 == retCode )
       
   826             {
       
   827             validKeystroke->AppendL( showKeystroke->MdcaPoint( i ) );
       
   828             allValidKeystroke->AppendL( showKeystroke->MdcaPoint( i ) );
       
   829             break;
       
   830             }
       
   831         //the keystroke is 2 - 9
       
   832         else if ( 0 == retCode )
       
   833             {
       
   834             //if the next keystroke is tone mark, then current keystroke and 
       
   835             //the next keystroke need to whole check. 
       
   836             if ( i < showKeystroke->Count() - 1 )
       
   837                 {
       
   838                 TPtiKey keyTmp;
       
   839                 if ( GetKeystrokeCode( keyTmp, 
       
   840                     showKeystroke->MdcaPoint( i  + 1) ) > 0 )
       
   841                     {
       
   842                     nextIsToneMark = ETrue;
       
   843                     }
       
   844                 }
       
   845             if ( AppendKeyPressL( key, nextIsToneMark ) )
       
   846                 {
       
   847                 //the next keystroke is not tone mark.
       
   848                 if ( !nextIsToneMark )
       
   849                     {
       
   850                     validKeystroke->AppendL( showKeystroke->MdcaPoint( i ) );
       
   851                     allValidKeystroke->AppendL( showKeystroke->MdcaPoint( i ) );
       
   852                     }
       
   853                 }
       
   854             else
       
   855                 {
       
   856                 break;
       
   857                 }
       
   858             }
       
   859         else
       
   860             {
       
   861             if ( AppendToneMarkL( retCode ) )
       
   862                 {
       
   863                 validKeystroke->AppendL( showKeystroke->MdcaPoint( i - 1 ) );
       
   864                 validKeystroke->AppendL( showKeystroke->MdcaPoint( i ) );
       
   865                 allValidKeystroke->AppendL( showKeystroke->MdcaPoint( i - 1 ) );
       
   866                 allValidKeystroke->AppendL( showKeystroke->MdcaPoint( i ) );
       
   867                 }
       
   868             break;
       
   869             }
       
   870         }
       
   871     for ( TInt i = 0; i < allValidKeystroke->Count(); ++i )
       
   872         {
       
   873         if ( 0 == allValidKeystroke->MdcaPoint( i ).Compare( delimiter ) )
       
   874             {
       
   875             break;
       
   876             }
       
   877         afterBuf.Append( allValidKeystroke->MdcaPoint( i ) );
       
   878         }
       
   879     
       
   880     if ( allValidKeystroke->Count() > 0 )
       
   881         {
       
   882         if ( ( 0 == allValidKeyLen ) ||  
       
   883             ( 0 != afterBuf.Compare( beforeBuf ) ) )
       
   884             {
       
   885             popup->SetValidKeystrokeChange( ETrue );
       
   886             }
       
   887         else
       
   888             {
       
   889             popup->SetValidKeystrokeChange( EFalse );
       
   890             }
       
   891         return ETrue;
       
   892         }
       
   893     
       
   894     return EFalse;
       
   895     }
       
   896 
       
   897 // ---------------------------------------------------------
       
   898 // Revert the current chinse to keystroke.
       
   899 // ---------------------------------------------------------
       
   900 //
       
   901 TBool TAknFepInputStatePinyinPhraseCreationBase::ChineseRevertKeystrokeL()
       
   902     {
       
   903     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   904     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   905     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   906     CDesCArrayFlat* showKeystroke = popup->ShowKeystrokeArray();
       
   907     CDesCArrayFlat* chinese = popup->ChooseChineseCharacterArray();
       
   908     CDesCArrayFlat* chineseKeystroke = 
       
   909         popup->ChooseChineseCharacterArrayKeystroke();
       
   910     TInt index = editPane->GetCursorIndexOfKeystroke();
       
   911     
       
   912     if ( ( 0 != index ) || ( 0 == chinese->Count() ) )
       
   913         {
       
   914         return EFalse;
       
   915         }
       
   916     
       
   917     if ( chineseKeystroke->MdcaPoint( chineseKeystroke->Count() - 1 ).Length() < 1 )
       
   918         {
       
   919         return EFalse;
       
   920         }
       
   921     
       
   922     for( TInt i = chineseKeystroke->MdcaPoint( chineseKeystroke->Count() - 1 ).
       
   923         Length() - 1; i >= 0 ; --i )
       
   924         {
       
   925         showKeystroke->InsertL( 0, chineseKeystroke->MdcaPoint( 
       
   926             chineseKeystroke->Count() - 1 ).Mid( i, 1 ) );
       
   927         }
       
   928     
       
   929     editPane->SetCursorIndexOfKeystroke( 
       
   930         chineseKeystroke->MdcaPoint( chineseKeystroke->Count() - 1 ).Length() );
       
   931     chinese->Delete( chinese->Count() - 1 );
       
   932     chineseKeystroke->Delete( chineseKeystroke->Count() - 1 );
       
   933     
       
   934     // if the show inof's length more than KMaxKeystrokeCount, delete more inof.   
       
   935     for ( TInt i = chinese->Count() + showKeystroke->Count() - KMaxKeystrokeCount; 
       
   936         i > 0; --i )
       
   937         {
       
   938         showKeystroke->Delete( showKeystroke->Count() - 1 );
       
   939         }
       
   940         
       
   941     showKeystroke->Compress();
       
   942     chinese->Compress();
       
   943     chineseKeystroke->Compress();
       
   944     return ETrue;
       
   945     }
       
   946 
       
   947 
       
   948 // ---------------------------------------------------------
       
   949 // Get the candidate info.
       
   950 // ---------------------------------------------------------
       
   951 //
       
   952 void TAknFepInputStatePinyinPhraseCreationBase::GetCandidateL( TInt aSelection )
       
   953     {
       
   954     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   955     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   956     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   957     CDesCArrayFlat* phraseCandidates = 
       
   958         uiContainer->CandidatePane()->CandidateArray();
       
   959     CDesCArrayFlat* spelling = popup->PhoneticSpellingArray();
       
   960     
       
   961     phraseCandidates->Reset();
       
   962     if ( ( aSelection > spelling->Count() ) || ( 0 == spelling->Count() ) )
       
   963         {
       
   964         return;
       
   965         }
       
   966     extern void CleanArray( TAny* aAny );
       
   967     RPointerArray<HBufC> list;
       
   968     TCleanupItem cleanitem( CleanArray, &list );
       
   969     CleanupStack::PushL( cleanitem );
       
   970     TPtrC curSpell = spelling->MdcaPoint( aSelection );
       
   971     HBufC* retString = ptiengine->GetCandidatesByInputString( 
       
   972                                               spelling->MdcaPoint( aSelection ), 
       
   973                                               list,
       
   974                                               EFalse );
       
   975     
       
   976     CleanupStack::PushL( retString );
       
   977     for (int index = 0; index < ptiengine->PhoneticSpellingCount(); index++)
       
   978         {
       
   979         TPtrC ptr = ptiengine->GetPhoneticSpelling(index + 1);               
       
   980         if (ptr.Length() == curSpell.Length())
       
   981             {
       
   982             ptiengine->SelectPhoneticSpelling(index + 1);
       
   983             ptiengine->GetChinesePhraseCandidatesL(*phraseCandidates);
       
   984             break;
       
   985             }
       
   986         }
       
   987     
       
   988     CleanupStack::PopAndDestroy( retString );
       
   989     CleanupStack::PopAndDestroy(); // cleanitem   
       
   990     }
       
   991 
       
   992 // ---------------------------------------------------------
       
   993 // Change CBA
       
   994 // ---------------------------------------------------------
       
   995 //
       
   996 void TAknFepInputStatePinyinPhraseCreationBase::ChangeCbaL()
       
   997     {
       
   998     MAknFepUICtrlPinyinPopup* popup = UIContainer()->PinyinPopupWindow();
       
   999     TInt keystrokeCount = popup->ShowKeystrokeArray()->Count();
       
  1000     TInt chineseCount = popup->ChooseChineseCharacterArray()->Count();
       
  1001     TInt validKeystrokeCount = popup->InEffectKeystrokeArray()->Count();
       
  1002     TInt lastRes = popup->GetLastResouce();
       
  1003 
       
  1004     if ( ( chineseCount == KMaxPhraseCreationCount ) ||
       
  1005         ( ( 0 == keystrokeCount ) && ( chineseCount > 1 ) ) )
       
  1006         {
       
  1007         if ( lastRes == R_AKNFEP_SOFTKEYS_DONE_CANCEL_DONE )
       
  1008             {
       
  1009             return;
       
  1010             }
       
  1011         //User cba done-done-cancel
       
  1012         iOwner->FepMan()->UpdateCbaL( R_AKNFEP_SOFTKEYS_DONE_CANCEL_DONE );
       
  1013         popup->SetLastResouce( R_AKNFEP_SOFTKEYS_DONE_CANCEL_DONE );
       
  1014         }
       
  1015     else if ( ( 0 != keystrokeCount ) && ( 0 != validKeystrokeCount ) )
       
  1016         {
       
  1017         if ( lastRes == R_AKNFEP_SOFTKEYS_PHRASE_CREATION_SELECT_CANCEL_SELECT )
       
  1018             {
       
  1019             return;
       
  1020             }
       
  1021         //User cba select-select-cancel
       
  1022         iOwner->FepMan()->UpdateCbaL( R_AKNFEP_SOFTKEYS_PHRASE_CREATION_SELECT_CANCEL_SELECT );
       
  1023         popup->SetLastResouce( R_AKNFEP_SOFTKEYS_PHRASE_CREATION_SELECT_CANCEL_SELECT );
       
  1024         }
       
  1025     else
       
  1026         {
       
  1027         if ( lastRes == R_AKNFEP_SOFTKEYS__PHRASE_CREATION_EMPTY_CANCEL_EMPTY )
       
  1028             {
       
  1029             return;
       
  1030             }
       
  1031         iOwner->FepMan()->UpdateCbaL( R_AKNFEP_SOFTKEYS__PHRASE_CREATION_EMPTY_CANCEL_EMPTY );
       
  1032         popup->SetLastResouce( R_AKNFEP_SOFTKEYS__PHRASE_CREATION_EMPTY_CANCEL_EMPTY );
       
  1033         }
       
  1034     }
       
  1035 
       
  1036 // ---------------------------------------------------------
       
  1037 // Update Indicator.
       
  1038 // ---------------------------------------------------------
       
  1039 //
       
  1040 void TAknFepInputStatePinyinPhraseCreationBase::UpdateIndicator()
       
  1041     {
       
  1042     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
  1043     MAknFepUICtrlCandidatePane* candidatePane = uiContainer->CandidatePane();
       
  1044 
       
  1045     if ( candidatePane->IsFirstPage() )
       
  1046         {
       
  1047         uiContainer->CandidatePane()->ShowUpScrollArrows( EFalse );
       
  1048         }
       
  1049     else
       
  1050         {
       
  1051         uiContainer->CandidatePane()->ShowUpScrollArrows( ETrue );
       
  1052         }
       
  1053 
       
  1054     if ( candidatePane->IsLastPage() )
       
  1055         {
       
  1056         uiContainer->CandidatePane()->ShowDownScrollArrows( EFalse );
       
  1057         }
       
  1058     else
       
  1059         {
       
  1060         uiContainer->CandidatePane()->ShowDownScrollArrows( ETrue );
       
  1061         }
       
  1062 
       
  1063     if ( candidatePane->SelectedIndex() == 0
       
  1064         && candidatePane->IsFirstPage() )
       
  1065         {
       
  1066         uiContainer->CandidatePane()->ShowLeftScrollArrows( EFalse );
       
  1067         }
       
  1068     else
       
  1069         {
       
  1070         uiContainer->CandidatePane()->ShowLeftScrollArrows( ETrue );
       
  1071         }
       
  1072 
       
  1073     if ( candidatePane->IsLastPage() && (candidatePane->SelectedIndex()
       
  1074         == candidatePane->VisibleCandidateCount() - 1 ) )
       
  1075         {
       
  1076         uiContainer->CandidatePane()->ShowRightScrollArrows( EFalse );
       
  1077         }
       
  1078     else
       
  1079         {
       
  1080         uiContainer->CandidatePane()->ShowRightScrollArrows( ETrue );
       
  1081         }
       
  1082     }
       
  1083 
       
  1084 // End of file