fep/aknfep/src/aknfepuiinputstatezhuyinphrasecreationbase.cpp
changeset 0 eb1f2e154e89
child 7 6defe5d1bd39
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     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 TAknFepInputStateEntryZhuyinPhraseCreation methods.
       
    16  *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 
       
    30 #include <PtiEngine.h>                          //CPtiEngine
       
    31 #include <avkon.rsg>
       
    32 #include <AknFep.rsg>
       
    33 
       
    34 #include "aknfepuiinputstatezhuyinphrasecreationbase.h"
       
    35 #include "AknFepUIManagerStateInterface.h"      //MAknFepUIManagerStateInterface
       
    36 #include "AknFepManagerUIInterface.h"           //MAknFepManagerUIInterface
       
    37 #include "AknFepUiCtrlContainerChinese.h"
       
    38 #include "AknFepUICtrlPinyinPopup.h"    //Pinyin phrase
       
    39 #include "aknfepuictrleditpane.h" 
       
    40 #include "AknFepUICtrlCandidatePane.h"
       
    41 #include "AknFepUICtrlInputPane.h"
       
    42 #include "aknfepzhuyinkeyhandlerinterface.h" //MZhuyinKeyHandler
       
    43 #include "AknFepZhuyinAnalyser.h"
       
    44 #include "aknfepzhuyinconvertion.h" //TZhuyinSymbolsMethods
       
    45 
       
    46 _LIT( KStrokeManualSeparator, "\x002E");
       
    47 _LIT( KToneMark1, "\x0020" );
       
    48 _LIT( KToneMark2, "\x02CA" );
       
    49 _LIT( KToneMark3, "\x02C7" );
       
    50 _LIT( KToneMark4, "\x02CB" );
       
    51 _LIT( KToneMark5, "\x02D9" );
       
    52 
       
    53 const TInt KMaxBufLen = 100;
       
    54 const TInt KMaxKeystrokeCount = 100;
       
    55 const TInt KMaxInputLength = 31;
       
    56 const TInt KMaxPhraseCreationCount = 7;
       
    57 
       
    58 // ---------------------------------------------------------
       
    59 // C++ constructor
       
    60 // ---------------------------------------------------------
       
    61 //
       
    62 TAknFepInputStateZhuyinPhraseCreationBase::TAknFepInputStateZhuyinPhraseCreationBase(
       
    63     MAknFepUIManagerStateInterface* aOwner,
       
    64     MAknFepUICtrlContainerChinese* aUIContainer ) :
       
    65     TAknFepInputStateCandidateBase( aOwner, aUIContainer )
       
    66     {    
       
    67     iState = EEntry;
       
    68 
       
    69     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
    70     MAknFepUICtrlCandidatePane* candidatePane = uiContainer->CandidatePane();
       
    71 
       
    72     uiContainer->FocusCandidatePane(EFalse);
       
    73     
       
    74     TBool multiplePages = !(uiContainer->CandidatePane()->IsLastPage() &&
       
    75                             uiContainer->CandidatePane()->IsFirstPage());
       
    76     TInt bufLength = iOwner->PtiEngine()->CandidatePage().Length();
       
    77     TBool showHorizontalScrollArrows = multiplePages || bufLength>1;
       
    78 
       
    79     uiContainer->ShowHorizontalScrollArrows(showHorizontalScrollArrows); 
       
    80     uiContainer->ShowVerticalScrollArrows(multiplePages);
       
    81     uiContainer->FocusCandidatePane(ETrue);
       
    82     candidatePane->SetHighlighted(ETrue);
       
    83     candidatePane->ShowCandidateOrdinals(EFalse);
       
    84     candidatePane->SelectFirstPhrase();
       
    85     }
       
    86     
       
    87 TBool TAknFepInputStateZhuyinPhraseCreationBase::AddKeystrokeL( TInt aKey )
       
    88     {
       
    89     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
    90     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
    91     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
    92     CDesCArrayFlat* zhuyinSymbol = popup->ZhuyinSymbols();
       
    93     TInt chineseCount = popup->ChineseCharsDisped()->Count();
       
    94     TInt currentIndex = editPane->GetCursorIndexOfKeystroke();
       
    95     TBuf<1> buf;
       
    96     TBuf<KMaxBufLen> showbuf;
       
    97     showbuf = uiContainer->PinyinPopupWindow()->GetEEPContent();
       
    98     
       
    99     TInt ret = iOwner->ZhuyinKeyHandler()->GetZhuyinSymbol( (TPtiKey)aKey, buf );  
       
   100     TInt showbufLen = showbuf.Length();
       
   101     
       
   102     if ( showbufLen >= KMaxInputLength )
       
   103         {
       
   104         if ( ( 0 == currentIndex ) || ( 1 == ret ) )
       
   105             {
       
   106             iOwner->ZhuyinKeyHandler()->Reset();
       
   107             return EFalse;
       
   108             }
       
   109         return ReplaceKeystrokeL( currentIndex,
       
   110                                  chineseCount,
       
   111                                  buf,
       
   112                                  zhuyinSymbol
       
   113                                  );
       
   114         }
       
   115     
       
   116     if ( showbufLen == KMaxInputLength - 1 )
       
   117         {
       
   118         if ( 0 == currentIndex )
       
   119             {
       
   120             iOwner->ZhuyinKeyHandler()->Reset();
       
   121             return EFalse;
       
   122             }
       
   123         else if ( 1 == ret )
       
   124             {
       
   125             zhuyinSymbol->InsertL( currentIndex, buf );
       
   126             if ( CheckKeystrokeCountL( chineseCount, zhuyinSymbol ) )
       
   127                 {
       
   128                 editPane->SetCursorIndexOfKeystroke( currentIndex + 1 );
       
   129                 return ETrue;
       
   130                 }
       
   131             else
       
   132                 {
       
   133                 iOwner->ZhuyinKeyHandler()->Reset();
       
   134                 zhuyinSymbol->Delete( currentIndex );
       
   135                 return EFalse;
       
   136                 }
       
   137             }
       
   138         else
       
   139             {
       
   140             return ReplaceKeystrokeL( currentIndex,
       
   141                                      chineseCount,
       
   142                                      buf,
       
   143                                      zhuyinSymbol
       
   144                                      );
       
   145             }
       
   146         }
       
   147     
       
   148     if ( ( 0 == currentIndex ) && 
       
   149         ( KMaxInputLength <= showbufLen ) )
       
   150         {
       
   151         return EFalse;
       
   152         }
       
   153     else if ( ( 0 != currentIndex ) &&
       
   154         ( KMaxInputLength <= showbufLen ) )
       
   155         {
       
   156         if ( 0 == ret )
       
   157             {
       
   158             zhuyinSymbol->Delete( currentIndex - 1 );
       
   159             zhuyinSymbol->InsertL( currentIndex - 1, buf );
       
   160             return ETrue;
       
   161             }
       
   162         else
       
   163             {
       
   164             iOwner->ZhuyinKeyHandler()->Reset();
       
   165             return EFalse;
       
   166             }
       
   167         }
       
   168     else if ( ( 0 == currentIndex ) && 
       
   169         ( KMaxInputLength > showbufLen ) ) 
       
   170         {
       
   171         zhuyinSymbol->InsertL( currentIndex, buf );
       
   172         editPane->SetCursorIndexOfKeystroke( currentIndex + 1 );
       
   173         return ETrue;
       
   174         }
       
   175     else if ( ( 0 != currentIndex ) && 
       
   176         ( KMaxInputLength > showbufLen ) ) 
       
   177         {
       
   178         if ( 0 == ret )
       
   179             {
       
   180             zhuyinSymbol->Delete( currentIndex - 1 );
       
   181             zhuyinSymbol->InsertL( currentIndex - 1, buf );
       
   182             return ETrue;
       
   183             }
       
   184         else if ( 1 == ret )
       
   185             {
       
   186             zhuyinSymbol->InsertL( currentIndex, buf );
       
   187             editPane->SetCursorIndexOfKeystroke( currentIndex + 1 );
       
   188             return ETrue;
       
   189             }
       
   190         }
       
   191     return ETrue;
       
   192     }
       
   193 
       
   194 TBool TAknFepInputStateZhuyinPhraseCreationBase::AddToneMarkL()
       
   195     {
       
   196     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   197     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   198     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   199     MZhuyinKeyHandler* zhuyinKeyHandler = iOwner->ZhuyinKeyHandler();
       
   200     CDesCArrayFlat* zhuyinSymbols = uiContainer->PinyinPopupWindow()->ZhuyinSymbols();
       
   201     
       
   202     TBuf<1> baseBuf;
       
   203     TBuf<1> buf;
       
   204     baseBuf.Zero();
       
   205     TInt strokePos = editPane->GetCursorIndexOfKeystroke();
       
   206     
       
   207     TBuf<KMaxBufLen> showbuf;
       
   208     showbuf = popup->GetEEPContent();
       
   209     
       
   210     if ( strokePos > 0 )
       
   211         {
       
   212         baseBuf.Append( zhuyinSymbols->MdcaPoint( strokePos - 1 ) );
       
   213         }
       
   214     TInt insert = zhuyinKeyHandler->GetToneMark( baseBuf, buf );
       
   215     if ( insert == 0 )
       
   216         {
       
   217         zhuyinSymbols->Delete ( strokePos - 1, 1 );
       
   218         zhuyinSymbols->InsertL(strokePos - 1, buf);
       
   219         }
       
   220     // for insert
       
   221     else if ( insert == 1)
       
   222         {
       
   223         if ( showbuf.Length() >= KMaxInputLength )
       
   224             {
       
   225             return EFalse;
       
   226             }
       
   227         zhuyinSymbols->InsertL(strokePos, buf);
       
   228         editPane->SetCursorIndexOfKeystroke(strokePos + 1);
       
   229         }
       
   230     return ETrue;
       
   231     }
       
   232 
       
   233 TBool TAknFepInputStateZhuyinPhraseCreationBase::DeleteZhuyinSymbolOrChinese()
       
   234     {
       
   235     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   236     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   237     MAknFepUICtrlPinyinPopup* popup = uiContainer->PinyinPopupWindow();
       
   238     CDesCArrayFlat* zhuyinSymbols = popup->ZhuyinSymbols();
       
   239     CDesCArrayFlat* chineseDisped = popup->ChineseCharsDisped();
       
   240     CDesCArrayFlat* zhuyinSymbolsForChinese = popup->ZhuyinSymbolsForChineseCharsDisped();
       
   241     TInt keyStrokePos = editPane->GetCursorIndexOfKeystroke();
       
   242     
       
   243     if ( 1 == keyStrokePos )
       
   244         {
       
   245         editPane->Reset();
       
   246         }
       
   247     
       
   248     if ( keyStrokePos != 0 )
       
   249         {
       
   250         TZhuyinSymbolsMethods::DeleteZhuyinSymbol(
       
   251             zhuyinSymbols,
       
   252             keyStrokePos);
       
   253             editPane->SetCursorIndexOfKeystroke(keyStrokePos-1);
       
   254         }
       
   255     else if ( chineseDisped->Count() )
       
   256         {
       
   257         TInt oldLen =  zhuyinSymbols->Count();
       
   258         TZhuyinSymbolsMethods::DeleteChineseChar(
       
   259             zhuyinSymbols,
       
   260             chineseDisped,
       
   261             zhuyinSymbolsForChinese
       
   262             );
       
   263         TInt newLen = zhuyinSymbols->Count();
       
   264         editPane->SetCursorIndexOfKeystroke(newLen - oldLen);
       
   265         }
       
   266     return ETrue;
       
   267     }
       
   268 
       
   269 TBool TAknFepInputStateZhuyinPhraseCreationBase::UpdateEEPContent()
       
   270     {
       
   271     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   272     CDesCArrayFlat* zhuyinSymbols = UIContainer()->PinyinPopupWindow()->ZhuyinSymbols();
       
   273     CDesCArrayFlat* chineseDisped = UIContainer()->PinyinPopupWindow()->ChineseCharsDisped();
       
   274     CAknFepZhuyinAnalyser* analyser = iOwner->ZhuyinAnalyser();
       
   275     CDesCArrayFlat* candidateList = UIContainer()->CandidatePane()->CandidateArray();
       
   276     TBuf<KMaxBufLen> buf;
       
   277     TBool isPhraseCreation = EFalse;
       
   278     TInt extLen = chineseDisped->Count() + zhuyinSymbols->Count() - KMaxInputLength;
       
   279     
       
   280     if ( extLen > 0 )
       
   281         {
       
   282         TInt keyStrokePos = UIContainer()->EditPaneWindow()->GetCursorIndexOfKeystroke();
       
   283         zhuyinSymbols->Delete ( zhuyinSymbols->Count() - extLen, extLen );
       
   284         if ( keyStrokePos > zhuyinSymbols->Count() )
       
   285             {
       
   286             UIContainer()->EditPaneWindow()->SetCursorIndexOfKeystroke( zhuyinSymbols->Count() );
       
   287             }
       
   288         }
       
   289 
       
   290     TBool valid = TZhuyinSymbolsMethods::UpdateEEPContent(
       
   291         ptiengine,
       
   292         analyser,
       
   293         zhuyinSymbols,
       
   294         chineseDisped,
       
   295         candidateList,
       
   296         buf,
       
   297         isPhraseCreation
       
   298         );
       
   299 
       
   300     if ( ( chineseDisped->Count() != 0 || zhuyinSymbols->Count() > 1 ) &&
       
   301         ( candidateList->Count() != 0 ) )
       
   302         {
       
   303         for ( TInt i = 0; i < candidateList->Count(); ++i )
       
   304             {
       
   305             if ( TZhuyinSymbolsMethods::IsZhuyinSymbol( candidateList->MdcaPoint( i ) ) )
       
   306                 {
       
   307                 candidateList->Delete( i, 1 );
       
   308                 break;
       
   309                 }
       
   310             }
       
   311         }
       
   312     UIContainer()->PinyinPopupWindow()->SetEEPContentValid(valid);
       
   313     UIContainer()->CandidatePane()->SplitPhraseCandidatesIntoPages();
       
   314     if ( !valid || candidateList->Count() == 0 )
       
   315         {
       
   316         DeleteSeparatorWhenInvaild( buf );
       
   317         valid = EFalse;
       
   318         }
       
   319     CheckShowInfo( buf, zhuyinSymbols );
       
   320     UIContainer()->PinyinPopupWindow()->SetEEPContent(buf);
       
   321     return valid;
       
   322     }
       
   323    
       
   324 void TAknFepInputStateZhuyinPhraseCreationBase::UpdateIndicator()
       
   325     {
       
   326     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   327     MAknFepUICtrlCandidatePane* candidatePane = uiContainer->CandidatePane();
       
   328     TInt candidateCount = candidatePane->CandidateArray()->Count();
       
   329 
       
   330     if ( candidatePane->IsFirstPage() || candidateCount== 0 )
       
   331         {
       
   332         uiContainer->CandidatePane()->ShowUpScrollArrows( EFalse );
       
   333         }
       
   334     else
       
   335         {
       
   336         uiContainer->CandidatePane()->ShowUpScrollArrows( ETrue );
       
   337         }
       
   338 
       
   339     if ( candidatePane->IsLastPage() || candidateCount== 0 )
       
   340         {
       
   341         uiContainer->CandidatePane()->ShowDownScrollArrows( EFalse );
       
   342         }
       
   343     else
       
   344         {
       
   345         uiContainer->CandidatePane()->ShowDownScrollArrows( ETrue );
       
   346         }
       
   347     }
       
   348 
       
   349 // ---------------------------------------------------------
       
   350 // Get high light begine position.
       
   351 // ---------------------------------------------------------
       
   352 //
       
   353 TInt TAknFepInputStateZhuyinPhraseCreationBase::BegPosOfMoreThanSeven()
       
   354     {
       
   355     TInt i = 0;
       
   356     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   357     TBuf<KMaxBufLen> buf;
       
   358     buf = uiContainer->PinyinPopupWindow()->GetEEPContent();
       
   359     TInt characterCount = uiContainer->PinyinPopupWindow()->ChineseCharsDisped()->Count();
       
   360     TInt allTextCount = characterCount;
       
   361 
       
   362     // calculate the total number of character according to stroke
       
   363     for (i = 0; i < buf.Length() && allTextCount < KMaxPhraseCreationCount; i++ )
       
   364         {
       
   365         if ( ( buf.Mid( i, 1 ) == KStrokeManualSeparator )|| 
       
   366             ( buf.Mid( i, 1 ) == KToneMark1 ) ||
       
   367             ( buf.Mid( i, 1 ) == KToneMark2 ) ||
       
   368             ( buf.Mid( i, 1 ) == KToneMark3 ) ||
       
   369             ( buf.Mid( i, 1 ) == KToneMark4 ) ||
       
   370             ( buf.Mid( i, 1 ) == KToneMark5 ) )
       
   371             {
       
   372             allTextCount++;
       
   373             }
       
   374         }
       
   375 
       
   376     allTextCount++;
       
   377     
       
   378     if ( allTextCount > KMaxPhraseCreationCount )
       
   379         {
       
   380         return i;
       
   381         }
       
   382     else
       
   383         {
       
   384         return 0;
       
   385         }
       
   386     }
       
   387 
       
   388 // ---------------------------------------------------------
       
   389 // Set high light.
       
   390 // ---------------------------------------------------------
       
   391 //
       
   392 void TAknFepInputStateZhuyinPhraseCreationBase::HighlightMoreThanSeven( TInt aBegPos )
       
   393     {
       
   394     MAknFepUICtrlEditPane* editPane = UIContainer()->EditPaneWindow();
       
   395     TBuf<KMaxBufLen> buf;
       
   396     buf = UIContainer()->PinyinPopupWindow()->GetEEPContent();
       
   397     TInt EndPos = buf.Length();
       
   398     editPane->SetHighlight( aBegPos, EndPos );
       
   399     }
       
   400 
       
   401 // ---------------------------------------------------------
       
   402 // replace the keystroke.
       
   403 // ---------------------------------------------------------
       
   404 //
       
   405 TBool TAknFepInputStateZhuyinPhraseCreationBase::ReplaceKeystrokeL(
       
   406                                                 TInt aIndex, 
       
   407                                                 TInt aChineseCount,
       
   408                                                 const TDesC& aSymbol, 
       
   409                                                 CDesCArrayFlat* aZhuyinSymbol )
       
   410     {
       
   411     TBuf<1> bufTmp;
       
   412     bufTmp.Append( aZhuyinSymbol->MdcaPoint( aIndex - 1 ) );
       
   413     aZhuyinSymbol->Delete( aIndex - 1 );
       
   414     aZhuyinSymbol->InsertL( aIndex - 1, aSymbol );
       
   415     if ( CheckKeystrokeCountL( aChineseCount, aZhuyinSymbol ) )
       
   416         {
       
   417         return ETrue;
       
   418         }
       
   419     else
       
   420         {
       
   421         aZhuyinSymbol->Delete( aIndex - 1 );
       
   422         aZhuyinSymbol->InsertL( aIndex - 1, bufTmp );
       
   423         return EFalse;
       
   424         }
       
   425     }
       
   426 
       
   427 void TAknFepInputStateZhuyinPhraseCreationBase::RefreshUI()
       
   428     {
       
   429     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
       
   430     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
       
   431     CDesCArrayFlat* zhuyinSymbols = uiContainer->PinyinPopupWindow()->ZhuyinSymbols();
       
   432     CDesCArrayFlat* chineseDisped = uiContainer->PinyinPopupWindow()->ChineseCharsDisped();
       
   433     
       
   434     CDesCArrayFlat* candidateList = uiContainer->CandidatePane()->CandidateArray();
       
   435     
       
   436     // get cursor position
       
   437     TPoint baseLine;
       
   438     TInt height(0);
       
   439     TInt ascent(0);
       
   440     TRAPD(ret,iOwner->FepMan()->
       
   441         GetScreenCoordinatesL(baseLine,height,ascent));
       
   442     if ( ret == KErrNone )
       
   443         {
       
   444         uiContainer->SetContainerPosition( baseLine, height );
       
   445         }
       
   446     TBuf<KMaxBufLen> seed;
       
   447     TBool valid = ETrue;
       
   448     TBuf<KMaxBufLen> buf;
       
   449     buf = uiContainer->PinyinPopupWindow()->GetEEPContent();
       
   450     valid = uiContainer->PinyinPopupWindow()->GetEEPContentValid();
       
   451 
       
   452     TBool isHighlight = EFalse;
       
   453     TInt zhuyinBegPos = chineseDisped->Count();
       
   454 
       
   455    TRAP_IGNORE( isHighlight = !iOwner->ZhuyinAnalyser()->AnalyzeL( buf.Mid( zhuyinBegPos ) ) );
       
   456    CheckShowInfo( buf, zhuyinSymbols );
       
   457    
       
   458     TInt keyStrokePos = editPane->GetCursorIndexOfKeystroke();
       
   459     if ( keyStrokePos > zhuyinSymbols->Count() + 1 )
       
   460     	{
       
   461     	keyStrokePos = zhuyinSymbols->Count();
       
   462     	editPane->SetCursorIndexOfKeystroke( keyStrokePos );
       
   463     	}
       
   464     TInt newCursorPos = TZhuyinSymbolsMethods::RefreshCursorPos(
       
   465         chineseDisped->Count(),buf,keyStrokePos);
       
   466     
       
   467     TZhuyinSymbolsMethods::Convert2Des(zhuyinSymbols,seed);
       
   468     editPane->SetTextForZhuyin(buf,newCursorPos,chineseDisped->Count(),seed,keyStrokePos,!valid);
       
   469     if ( !valid || isHighlight
       
   470         || candidateList->Count()== 0 || zhuyinSymbols->Count() == 0 )
       
   471         {
       
   472         uiContainer->CandidatePane()->SetInVisiable();
       
   473         editPane->SetHighlight(chineseDisped->Count(),buf.Length()-1);
       
   474         uiContainer->SetControlInVisible( EFalse );
       
   475         uiContainer->Enable( ETrue );
       
   476         uiContainer->ShowHorizontalScrollArrows( EFalse );
       
   477         uiContainer->ShowVerticalScrollArrows( EFalse );   
       
   478         }
       
   479     else
       
   480         {
       
   481         uiContainer->SetControlInVisible( ETrue );
       
   482         uiContainer->CandidatePane()->SetCandidateBuffer();
       
   483         uiContainer->CandidatePane()->SelectFirstPhrase();
       
   484         uiContainer->Enable( ETrue );
       
   485         uiContainer->ShowVerticalScrollArrows( ETrue );
       
   486         }
       
   487     TInt begPos = BegPosOfMoreThanSeven();
       
   488 
       
   489     if ( begPos )
       
   490         {
       
   491         HighlightMoreThanSeven( begPos );
       
   492         }
       
   493 
       
   494     UpdateIndicator();
       
   495     }
       
   496 
       
   497 // ---------------------------------------------------------
       
   498 // Check the keystroke count.
       
   499 // ---------------------------------------------------------
       
   500 //
       
   501 TBool TAknFepInputStateZhuyinPhraseCreationBase::CheckKeystrokeCountL(
       
   502                                               TInt aChineseCount,
       
   503                                               CDesCArrayFlat* aZhuyinSymbol )
       
   504     {
       
   505     TBuf<KMaxKeystrokeCount> inputBuf;
       
   506     
       
   507     for (TInt i = 0; i < aZhuyinSymbol->Count(); ++i )
       
   508         {
       
   509         inputBuf.Append( aZhuyinSymbol->MdcaPoint( i ) );
       
   510         }
       
   511     
       
   512     if ( !iOwner->ZhuyinAnalyser()->AnalyzeL( inputBuf ) )
       
   513         {
       
   514         return ETrue;
       
   515         }
       
   516     else
       
   517         {
       
   518         HBufC* showBuf = iOwner->ZhuyinAnalyser()->LastAnalysisResult();
       
   519         if ( showBuf->Length() > KMaxInputLength - aChineseCount )
       
   520             {
       
   521             return EFalse;
       
   522             }        
       
   523         }  
       
   524     return ETrue;
       
   525     }
       
   526 
       
   527 void TAknFepInputStateZhuyinPhraseCreationBase::HandleCommandL(TInt /*aCommandId*/)
       
   528     {   
       
   529     RefreshUI();    
       
   530     }
       
   531 
       
   532 void TAknFepInputStateZhuyinPhraseCreationBase::CheckShowInfo( TDes& aOutDes, 
       
   533                                             CDesCArrayFlat* aZhuyinSymbol )
       
   534     {
       
   535     if( aOutDes.Length() <= KMaxInputLength )
       
   536         {
       
   537         return;
       
   538         }
       
   539     TInt extLen = aOutDes.Length() - KMaxInputLength;
       
   540     TInt delCount = 0;
       
   541     TBuf<KMaxInputLength> delBuf;
       
   542     delBuf.Copy( aOutDes.Mid( KMaxInputLength ) );
       
   543     aOutDes.Delete( KMaxInputLength, extLen );
       
   544     if ( aOutDes.Mid( KMaxInputLength - 1, 1 ).
       
   545         Compare( KStrokeManualSeparator ) == 0 )
       
   546         {
       
   547         aOutDes.Delete( KMaxInputLength - 1, 1 );
       
   548         }
       
   549     
       
   550     for ( TInt i = 0; i < delBuf.Length(); i++ )
       
   551         {
       
   552         if ( delBuf.Mid( i, 1 ).Compare( KStrokeManualSeparator ) != 0 )
       
   553             {
       
   554             delCount++;
       
   555             }
       
   556         }
       
   557     
       
   558     for ( TInt i = 0; i < delCount; i++ )
       
   559         {
       
   560         aZhuyinSymbol->Delete( aZhuyinSymbol->Count() - 1 );
       
   561         }
       
   562     }
       
   563 
       
   564 // ---------------------------------------------------------
       
   565 // Change CBA
       
   566 // ---------------------------------------------------------
       
   567 //
       
   568 void TAknFepInputStateZhuyinPhraseCreationBase::ChangeCbaL()
       
   569     {
       
   570     MAknFepUICtrlPinyinPopup* popup = UIContainer()->PinyinPopupWindow();
       
   571     CDesCArrayFlat* zhuyinSymbol = popup->ZhuyinSymbols();
       
   572     CDesCArrayFlat* chineseArray = popup->ChineseCharsDisped( );
       
   573     CDesCArrayFlat* candidateArray = UIContainer()->CandidatePane()->CandidateArray( );
       
   574     TBool vaild = popup->GetEEPContentValid( );
       
   575     TInt lastRes = popup->GetLastResouce();
       
   576 
       
   577     if ( chineseArray->Count( ) == KMaxPhraseCreationCount )
       
   578         {
       
   579         if ( lastRes == R_AKNFEP_SOFTKEYS_DONE_CANCEL_DONE )
       
   580             {
       
   581             return;
       
   582             }
       
   583         //User cba done-done-cancel
       
   584         iOwner->FepMan()->UpdateCbaL( R_AKNFEP_SOFTKEYS_DONE_CANCEL_DONE );
       
   585         popup->SetLastResouce( R_AKNFEP_SOFTKEYS_DONE_CANCEL_DONE );
       
   586         }
       
   587     else if ( ( 0 != zhuyinSymbol->Count( ) ) && (candidateArray->Count( )
       
   588         != 0 ) && vaild )
       
   589         {
       
   590         if ( lastRes == R_AKNFEP_SOFTKEYS_PHRASE_CREATION_SELECT_CANCEL_SELECT )
       
   591             {
       
   592             return;
       
   593             }
       
   594         //User cba select-select-cancel
       
   595         iOwner->FepMan()->UpdateCbaL( R_AKNFEP_SOFTKEYS_PHRASE_CREATION_SELECT_CANCEL_SELECT );
       
   596         popup->SetLastResouce( R_AKNFEP_SOFTKEYS_PHRASE_CREATION_SELECT_CANCEL_SELECT );
       
   597         }
       
   598     else if ( (chineseArray->Count( ) > 1 )
       
   599         && ( 0 == zhuyinSymbol->Count( ) ) )
       
   600         {
       
   601         if ( lastRes == R_AKNFEP_SOFTKEYS_DONE_CANCEL_DONE )
       
   602             {
       
   603             return;
       
   604             }
       
   605         //User cba Done-Done-Cancel
       
   606         iOwner->FepMan()->UpdateCbaL( R_AKNFEP_SOFTKEYS_DONE_CANCEL_DONE );
       
   607         popup->SetLastResouce( R_AKNFEP_SOFTKEYS_DONE_CANCEL_DONE );
       
   608         }
       
   609     else
       
   610         {
       
   611         if ( lastRes == R_AKNFEP_SOFTKEYS__PHRASE_CREATION_EMPTY_CANCEL_EMPTY )
       
   612             {
       
   613             return;
       
   614             }
       
   615         iOwner->FepMan()->UpdateCbaL( R_AKNFEP_SOFTKEYS__PHRASE_CREATION_EMPTY_CANCEL_EMPTY );
       
   616         popup->SetLastResouce( R_AKNFEP_SOFTKEYS__PHRASE_CREATION_EMPTY_CANCEL_EMPTY );
       
   617         }
       
   618     }
       
   619 
       
   620 void TAknFepInputStateZhuyinPhraseCreationBase::DeleteSeparatorWhenInvaild( TDes& aDes )
       
   621     {
       
   622     TInt count = aDes.Length();
       
   623     for ( TInt i = count - 1; i > 0; i-- )
       
   624         {
       
   625         if ( aDes.Mid( i, 1 ).Compare( KStrokeManualSeparator ) == 0 )
       
   626             {
       
   627             aDes.Delete( i, 1 );
       
   628             }
       
   629         }
       
   630     }
       
   631 
       
   632 // End of file