fep/aknfep/src/aknfepuiinputminiqwertysogoupinyinphraseplugin.cpp
branchRCL_3
changeset 50 5a1685599b76
equal deleted inserted replaced
46:bd83ceabce89 50:5a1685599b76
       
     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 TAknFepInputMiniQwertySogouPinyinPhrasePlugin definition.
       
    16  *
       
    17 */
       
    18 
       
    19 // System includes
       
    20 #include <e32cmn.h>
       
    21 #include <PtiEngine.h>
       
    22 #include <PtiDefs.h>
       
    23 #include <avkon.rsg>
       
    24 #include <aknfep.rsg>
       
    25 #include <PtiUserDicEntry.h>
       
    26 #include <aknnotewrappers.h> //CAknWarningNote 
       
    27 // User includes
       
    28 #include "AknFepUIManagerStateInterface.h"
       
    29 #include "AknFepUICtrlInputPane.h"
       
    30 #include "AknFepUICtrlPinyinPopup.h"        //Pinyin phrase
       
    31 #include "aknfepuictrleditpane.h"           //pinyin phrase creation
       
    32 #include "AknFepUICtrlCandidatePane.h"
       
    33 #include "AknFepManager.h"
       
    34 
       
    35 #include "aknfepuiinputminiqwertysogoupinyinphraseplugin.h"
       
    36 #include "AknFepUiInputStateCandidateQwertyBaseChinesePhrase.h"
       
    37 
       
    38 // Constant definition
       
    39 const TInt KMaxPhraseCreationCount = 10;
       
    40 const TInt KMaxKeystrokeCount = 31;
       
    41 const TInt KMaxShowKeystrokeCount = 255;
       
    42 const TInt KInvalidToneMark = -1;
       
    43 const TUint16 KAutoDLT = 0x002E;
       
    44 const TUint16 KManualDLT = 0x0027;
       
    45 const TUint16 KPYa = 0x0061;
       
    46 const TUint16 KPYb = 0x0062;
       
    47 const TUint16 KPYc = 0x0063;
       
    48 const TUint16 KPYd = 0x0064;
       
    49 const TUint16 KPYe = 0x0065;
       
    50 const TUint16 KPYf = 0x0066;
       
    51 const TUint16 KPYg = 0x0067;
       
    52 const TUint16 KPYh = 0x0068;
       
    53 const TUint16 KPYi = 0x0069;
       
    54 const TUint16 KPYj = 0x006A;
       
    55 const TUint16 KPYk = 0x006B;
       
    56 const TUint16 KPYl = 0x006C;
       
    57 const TUint16 KPYm = 0x006D;
       
    58 const TUint16 KPYn = 0x006E;
       
    59 const TUint16 KPYo = 0x006F;
       
    60 const TUint16 KPYp = 0x0070;
       
    61 const TUint16 KPYq = 0x0071;
       
    62 const TUint16 KPYr = 0x0072;
       
    63 const TUint16 KPYs = 0x0073;
       
    64 const TUint16 KPYt = 0x0074;
       
    65 const TUint16 KPYu = 0x0075;
       
    66 const TUint16 KPYv = 0x0076;
       
    67 const TUint16 KPYw = 0x0077;
       
    68 const TUint16 KPYx = 0x0078;
       
    69 const TUint16 KPYy = 0x0079;
       
    70 const TUint16 KPYz = 0x007A;
       
    71 
       
    72 const TMiniQwertyKeyMap StrokeMap[] =
       
    73     {
       
    74     {KPYa, EPtiKeyQwertyA},
       
    75     {KPYb, EPtiKeyQwertyB},
       
    76     {KPYc, EPtiKeyQwertyC},
       
    77     {KPYd, EPtiKeyQwertyD},
       
    78     {KPYe, EPtiKeyQwertyE},
       
    79     {KPYf, EPtiKeyQwertyF},
       
    80     {KPYg, EPtiKeyQwertyG},
       
    81     {KPYh, EPtiKeyQwertyH},
       
    82     {KPYi, EPtiKeyQwertyI},
       
    83     {KPYj, EPtiKeyQwertyJ},
       
    84     {KPYk, EPtiKeyQwertyK},
       
    85     {KPYl, EPtiKeyQwertyL},
       
    86     {KPYm, EPtiKeyQwertyM},
       
    87     {KPYn, EPtiKeyQwertyN},
       
    88     {KPYo, EPtiKeyQwertyO},
       
    89     {KPYp, EPtiKeyQwertyP},
       
    90     {KPYq, EPtiKeyQwertyQ},
       
    91     {KPYr, EPtiKeyQwertyR},
       
    92     {KPYs, EPtiKeyQwertyS},
       
    93     {KPYt, EPtiKeyQwertyT},
       
    94     {KPYu, EPtiKeyQwertyU},
       
    95     {KPYv, EPtiKeyQwertyV},
       
    96     {KPYw, EPtiKeyQwertyW},
       
    97     {KPYx, EPtiKeyQwertyX},
       
    98     {KPYy, EPtiKeyQwertyY},
       
    99     {KPYz, EPtiKeyQwertyZ},
       
   100     {KManualDLT, EPtiKeyQwertySpace}
       
   101     };
       
   102 
       
   103 const TMiniQwertyToneMap PinyinToneMap[] =
       
   104     {
       
   105     {0x02C9, 1},
       
   106     {0x02CA, 2},
       
   107     {0x02C7, 3},
       
   108     {0x02CB, 4},
       
   109     {0x02D9, 5}
       
   110     };
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // TAknFepInputMiniQwertySogouPinyinPhrasePlugin::TAknFepInputMiniQwertySogouPinyinPhrasePlugin
       
   114 // C++ default constructor
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 TAknFepInputMiniQwertySogouPinyinPhrasePlugin::TAknFepInputMiniQwertySogouPinyinPhrasePlugin(
       
   118     MAknFepUIManagerStateInterface* aOwner,
       
   119     MAknFepUICtrlContainerChinese* aUIContainer,
       
   120     TUIState aState )
       
   121     : iOwner( aOwner ),
       
   122       iUIContainer( aUIContainer ),
       
   123       iState( aState ),
       
   124       iValid( EFalse ),
       
   125       iNeedAddDLT( EFalse ),
       
   126       iCanConvertAll( ETrue ),
       
   127       iConvertCount( -1 )
       
   128     {
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // TAknFepInputMiniQwertySogouPinyinPhrasePlugin::operator=
       
   133 // 
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 void TAknFepInputMiniQwertySogouPinyinPhrasePlugin::operator=( const 
       
   137         TAknFepInputMiniQwertySogouPinyinPhrasePlugin& aPlugin )
       
   138     {
       
   139     Mem::Copy( this, &aPlugin, sizeof(TAknFepInputMiniQwertySogouPinyinPhrasePlugin));
       
   140     }
       
   141 
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // TAknFepInputMiniQwertySogouPinyinPhrasePlugin::AnalyseL
       
   145 // Analyse key storke.
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 void TAknFepInputMiniQwertySogouPinyinPhrasePlugin::AnalyseL()
       
   149     {
       
   150     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   151     MAknFepUICtrlEditPane* editPane = iUIContainer->EditPaneWindow();
       
   152     
       
   153     //user pressed keystroke sequence
       
   154     CDesCArrayFlat* keystroke = editPane->KeystrokeArray();
       
   155     
       
   156     //stroke to be shown
       
   157     CDesCArrayFlat* showKeystroke = editPane->ShowKeystrokeArray();
       
   158     TInt start = 0;
       
   159     TInt toneMarkCount = KInvalidToneMark;
       
   160 //    TInt delimiterPosition = 0;
       
   161     showKeystroke->Reset();
       
   162     TBuf<1> atuoDLT;
       
   163     TBuf<1> manualDLT;
       
   164     atuoDLT.Append( KAutoDLT );
       
   165     manualDLT.Append( KManualDLT );
       
   166     TBuf<KMaxKeystrokeCount> keyTmp;
       
   167 
       
   168     if ( keystroke->Count() == 0 )
       
   169         {
       
   170         return;
       
   171         }
       
   172     
       
   173     ClearPtiEngineKeystroke();
       
   174     
       
   175     TInt phraseCount = 0;
       
   176     CDesCArrayFlat* phrase = editPane->PhraseArray();
       
   177     for ( TInt j = 0;  j < phrase->Count(); j++ )
       
   178         {
       
   179         phraseCount += phrase->MdcaPoint(j).Length();;
       
   180         }
       
   181     
       
   182     // Analysis every keystroke
       
   183     TInt firstIsTonemark = EFalse;
       
   184     TBool lastOneIsTonemark = EFalse;
       
   185     for ( TInt i = start; i < keystroke->Count(); ++i )
       
   186         {
       
   187         // Detect which tonemark the keystroke is.
       
   188         toneMarkCount = ToneMark( keystroke->MdcaPoint( i ));
       
   189 
       
   190         // current keystroke is tonemark
       
   191         if ( KInvalidToneMark != toneMarkCount )
       
   192             {
       
   193             if ( i == 0 )
       
   194                 {
       
   195                 firstIsTonemark = ETrue;
       
   196                 }
       
   197             // Analysis and add the tonemark
       
   198             TBool checkTonemark = CheckSpellingAddToneMarkToPTIL( toneMarkCount );
       
   199             if ( !checkTonemark || lastOneIsTonemark )
       
   200                 {
       
   201                 if ( lastOneIsTonemark && checkTonemark )
       
   202                     {
       
   203                     ptiengine->IncrementToneMark( ETrue );
       
   204                     }
       
   205                 TPtrC ptr = getCurrentLeastDLTSpell();
       
   206                 TBuf<1> tonemark;
       
   207                 if ( ptr.Length() > 0 )
       
   208                     {
       
   209                     tonemark.Append( ptr[ ptr.Length() - 1 ] );
       
   210                     if ( lastOneIsTonemark )
       
   211                         {
       
   212                         keystroke->Delete( i - 1, 2 );
       
   213                         keystroke->InsertL( i - 1, tonemark );
       
   214                         i = i - 1;
       
   215                         }
       
   216                     else
       
   217                         {
       
   218                         keystroke->Delete( i );
       
   219                         keystroke->InsertL( i, tonemark );
       
   220                         }
       
   221                     }
       
   222                 else if ( lastOneIsTonemark )
       
   223                     {
       
   224                     toneMarkCount = ToneMark( keystroke->MdcaPoint( i )) + 
       
   225                             ToneMark( keystroke->MdcaPoint( i - 1 ));
       
   226                     toneMarkCount = toneMarkCount % 
       
   227                             ( sizeof(PinyinToneMap ) / ( sizeof(PinyinToneMap[0])));
       
   228                     if ( toneMarkCount == 0 )
       
   229                         {
       
   230                         toneMarkCount = 5;
       
   231                         }
       
   232                     tonemark.Append( PinyinToneMap[toneMarkCount - 1].iValue );
       
   233                     keystroke->Delete( i - 1, 2 );
       
   234                     keystroke->InsertL( i - 1, tonemark );
       
   235                     i = i - 1;
       
   236                     }
       
   237                     
       
   238                 }
       
   239             lastOneIsTonemark = ETrue;
       
   240             ptiengine->HandleCommandL( EPtiCommandResetToneMark );
       
   241             }
       
   242         else
       
   243             {
       
   244             if ( lastOneIsTonemark )
       
   245                 {
       
   246                 lastOneIsTonemark = EFalse;
       
   247                 }
       
   248             TInt keyCode = 0;
       
   249             GetKeystrokeCode( keyCode, keystroke->MdcaPoint( i ));
       
   250             ptiengine->AppendKeyPress(( TPtiKey )keyCode );
       
   251             }
       
   252         
       
   253         // If the last keystroke is appended, get the spell from core and
       
   254         // add it to show keystroke.
       
   255         if ( i == keystroke->Count() - 1 )
       
   256             {
       
   257             TPtrC spell = getCurrentLeastDLTSpell();
       
   258             TInt dltCount = 0;
       
   259             for ( TInt j = 0; j < spell.Length(); j++ )
       
   260                 {
       
   261                 showKeystroke->AppendL( spell.Mid( j, 1 ));
       
   262                 if ( KAutoDLT == spell[j] )
       
   263                     {
       
   264                     dltCount++;
       
   265                     }
       
   266                 }
       
   267             TInt tmp = 0;
       
   268             if ( firstIsTonemark )
       
   269                 {
       
   270                 tmp = 1;
       
   271                 }
       
   272             if ( spell.Length() - dltCount + start + tmp < keystroke->Count())
       
   273                 {
       
   274                 if ( spell.Length() != 0 )
       
   275                     {
       
   276                     showKeystroke->AppendL( atuoDLT );
       
   277                     }
       
   278                 for ( TInt k = spell.Length() - dltCount; k < keystroke->Count(); k++ )
       
   279                     {
       
   280                     showKeystroke->AppendL( keystroke->MdcaPoint( k ));
       
   281                     }
       
   282                 }
       
   283             else if ( spell.Length() - dltCount + start < keystroke->Count())
       
   284                 {
       
   285                 showKeystroke->InsertL( 0, keystroke->MdcaPoint( 0 ));
       
   286                 }
       
   287             
       
   288             ClearPtiEngineKeystroke();
       
   289             }
       
   290 
       
   291         if ( phraseCount + showKeystroke->Count() > KMaxKeystrokeCount )
       
   292             {
       
   293             showKeystroke->Delete( KMaxKeystrokeCount - phraseCount, 
       
   294                   phraseCount + showKeystroke->Count() - KMaxKeystrokeCount );
       
   295             if ( CheckSpellingDLT( showKeystroke->MdcaPoint( 
       
   296                                       KMaxKeystrokeCount - phraseCount - 1 )))
       
   297                 {
       
   298                 showKeystroke->Delete( KMaxKeystrokeCount - phraseCount - 1 );
       
   299                 }
       
   300             break;
       
   301             }
       
   302         }
       
   303     if ( iNeedAddDLT )
       
   304         {
       
   305         iNeedAddDLT = EFalse;
       
   306         }
       
   307     }
       
   308 
       
   309 // ---------------------------------------------------------
       
   310 // TAknFepInputMiniQwertySogouPinyinPhrasePlugin::ClearPtiEngineKeystroke
       
   311 // clear the ptiengine keystroke;
       
   312 // ---------------------------------------------------------
       
   313 //
       
   314 void TAknFepInputMiniQwertySogouPinyinPhrasePlugin::ClearPtiEngineKeystroke()
       
   315     {
       
   316     iOwner->PtiEngine()->ClearCurrentWord();
       
   317     }
       
   318 
       
   319 // ---------------------------------------------------------
       
   320 // TAknFepInputMiniQwertySogouPinyinPhrasePlugin::GetKeystrokeCode
       
   321 // get Code of the key stroke. 
       
   322 // ---------------------------------------------------------
       
   323 //
       
   324 void TAknFepInputMiniQwertySogouPinyinPhrasePlugin::GetKeystrokeCode( TInt& aKey,
       
   325     const TDesC& aKeystroke )
       
   326     {
       
   327     TInt count = sizeof(StrokeMap) / sizeof(StrokeMap[0]);
       
   328     for ( TInt i = 0; i < count; i++ )
       
   329         {
       
   330         TBuf<1> buf;
       
   331         buf.Append( StrokeMap[i].iValue );
       
   332         if ( 0 == aKeystroke.Compare( buf ))
       
   333             {
       
   334             aKey = StrokeMap[i].iKeyCode;
       
   335             break;
       
   336             }
       
   337         }
       
   338     }
       
   339 
       
   340 // ---------------------------------------------------------
       
   341 // TAknFepInputMiniQwertySogouPinyinPhrasePlugin::getCurrentLeastDLTSpell
       
   342 // get current spell which contains the least DLT.
       
   343 // ---------------------------------------------------------
       
   344 //
       
   345 TPtrC TAknFepInputMiniQwertySogouPinyinPhrasePlugin::getCurrentLeastDLTSpell()
       
   346     {
       
   347     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   348     CDesC16ArrayFlat* allSpell = new CDesC16ArrayFlat( 1 );
       
   349     TPtrC  currentSpell;
       
   350     TBuf<1> delimiter;
       
   351     TBuf<KMaxKeystrokeCount> preDltPosizeArr;
       
   352     TBuf<KMaxKeystrokeCount> curDltPosizeArr;
       
   353     preDltPosizeArr.FillZ( KMaxKeystrokeCount );
       
   354     preDltPosizeArr.SetLength( KMaxKeystrokeCount );
       
   355     curDltPosizeArr.FillZ( KMaxKeystrokeCount );
       
   356     curDltPosizeArr.SetLength( KMaxKeystrokeCount );
       
   357     
       
   358     TInt index = 1;
       
   359     delimiter.Append( KManualDLT );
       
   360     TRAP_IGNORE( ptiengine->GetPhoneticSpellingsL( *allSpell ));
       
   361     TInt allCount = ptiengine->PhoneticSpellingCount();
       
   362     
       
   363     
       
   364     for( TInt i = 0; i < allCount; i++ )
       
   365         {
       
   366         currentSpell.Set(allSpell->MdcaPoint( i ));
       
   367         TInt dltIndex = 0;
       
   368         curDltPosizeArr.FillZ(KMaxKeystrokeCount);
       
   369         curDltPosizeArr.SetLength(KMaxKeystrokeCount);
       
   370         TInt preIndex = 0;
       
   371         for ( TInt j = 0; j < currentSpell.Length(); j++ )
       
   372             {
       
   373             if ( currentSpell.Mid( j, 1 ).Compare( delimiter ) == 0 )
       
   374                 {   
       
   375                 curDltPosizeArr[dltIndex] = j - preIndex - 1;
       
   376                 preIndex = j;
       
   377                 dltIndex++;
       
   378                 }
       
   379             else if (( j + 1 ) == currentSpell.Length())
       
   380                 {
       
   381                 curDltPosizeArr[dltIndex] = j - preIndex;
       
   382                 }
       
   383             }
       
   384         
       
   385         for ( TInt k = 0; k < KMaxKeystrokeCount; k++ )
       
   386             {
       
   387             
       
   388             if ( preDltPosizeArr[k] < curDltPosizeArr[k] )
       
   389                 {
       
   390                 preDltPosizeArr.Copy( curDltPosizeArr );
       
   391                 index = i + 1;
       
   392                 break;
       
   393                 }
       
   394             else if ( preDltPosizeArr[k] > curDltPosizeArr[k] )
       
   395                 {
       
   396                 break;
       
   397                 }
       
   398             }
       
   399         }
       
   400     
       
   401     // Pop and destroy allSpell
       
   402     if ( allSpell )
       
   403         {
       
   404         delete allSpell;
       
   405         }
       
   406     
       
   407     ptiengine->SelectPhoneticSpelling( index );
       
   408     return ptiengine->GetPhoneticSpelling( index ); 
       
   409     }
       
   410 
       
   411 // ---------------------------------------------------------
       
   412 // TAknFepInputMiniQwertySogouPinyinPhrasePlugin::CheckSpellingDLT
       
   413 // Check the delimiter of spelling.
       
   414 // ---------------------------------------------------------
       
   415 //
       
   416 TBool TAknFepInputMiniQwertySogouPinyinPhrasePlugin::CheckSpellingDLT(
       
   417     const TDesC& aKeystroke )
       
   418     {
       
   419     if ( aKeystroke.Length() == 0 )
       
   420         {
       
   421         return EFalse;
       
   422         }
       
   423     
       
   424     if (( KAutoDLT == aKeystroke[0] ) || ( KManualDLT == aKeystroke[0] ))
       
   425         {
       
   426         return ETrue;
       
   427         }
       
   428     
       
   429     return EFalse;
       
   430     }
       
   431 
       
   432 // ---------------------------------------------------------
       
   433 // TAknFepInputMiniQwertySogouPinyinPhrasePlugin::ToneMark
       
   434 // Get pinyin tone mark.
       
   435 // ---------------------------------------------------------
       
   436 //
       
   437 TInt TAknFepInputMiniQwertySogouPinyinPhrasePlugin::ToneMark( 
       
   438         const TDesC& aKeystroke )
       
   439     {
       
   440     if ( aKeystroke.Length() == 0 )
       
   441         {
       
   442         return KInvalidToneMark;
       
   443         }
       
   444     TInt numOfToneMark = sizeof(PinyinToneMap) / sizeof(PinyinToneMap[0]);
       
   445     for ( TInt i = 0; i < numOfToneMark; i++ )
       
   446         {
       
   447         if ( PinyinToneMap[i].iValue == aKeystroke[0] )
       
   448             {
       
   449             return PinyinToneMap[i].iInputTone;
       
   450             }
       
   451         }
       
   452     return KInvalidToneMark;
       
   453     }
       
   454 
       
   455 // ---------------------------------------------------------
       
   456 // TAknFepInputMiniQwertySogouPinyinPhrasePlugin::CheckSpellingAddToneMarkToPTIL
       
   457 // Check spell after add the tonemark to ptiEngine.
       
   458 // ---------------------------------------------------------
       
   459 //
       
   460 TBool TAknFepInputMiniQwertySogouPinyinPhrasePlugin::CheckSpellingAddToneMarkToPTIL(
       
   461                                                         const TInt aToneMark )
       
   462     {
       
   463     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   464     MAknFepUICtrlEditPane* editPane = iUIContainer->EditPaneWindow();
       
   465     TBuf<1> toneMark;
       
   466     TBuf<1> delimiter;
       
   467     
       
   468     toneMark.Append( PinyinToneMap[aToneMark - 1].iValue );
       
   469     delimiter.Append( KManualDLT );
       
   470     
       
   471     for ( TInt i = 0; i < aToneMark; ++i )
       
   472         {
       
   473         ptiengine->IncrementToneMark( ETrue );
       
   474         TPtrC ptr = getCurrentLeastDLTSpell();
       
   475         
       
   476         // Some tonemarks are invalid for some pinyin stroke, so we need check
       
   477         // the tonemark.
       
   478         if ( ptr.Length() == 0 )
       
   479             {
       
   480             break;
       
   481             }
       
   482         TBuf<1> tonemarkResult;
       
   483         tonemarkResult.Append( ptr.Mid( ptr.Length() - 1, 1 ));
       
   484         if ( i != aToneMark - 1 )
       
   485             {
       
   486             CheckResultOfToneMark( tonemarkResult , i );
       
   487             }
       
   488 
       
   489         if (( 0 == ptr.Mid( ptr.Length() - 1, 1 ).Compare( toneMark )) &&
       
   490             ( KErrNotFound == ptr.Find( delimiter ))
       
   491             )
       
   492             {
       
   493             return ETrue;
       
   494             }
       
   495         }
       
   496     
       
   497     return EFalse;
       
   498     }
       
   499 
       
   500 // ---------------------------------------------------------
       
   501 // TAknFepInputMiniQwertySogouPinyinPhrasePlugin::CheckResultOfToneMark
       
   502 // Check the tonemark result.
       
   503 // ---------------------------------------------------------
       
   504 //
       
   505 void TAknFepInputMiniQwertySogouPinyinPhrasePlugin::CheckResultOfToneMark( 
       
   506                                             const TDesC16& aDes, TInt& aIndex )
       
   507     {
       
   508     TInt tonemarkIndex = 0;
       
   509     TInt num = sizeof(PinyinToneMap )/( sizeof(PinyinToneMap[0]));
       
   510     for ( tonemarkIndex = 0; tonemarkIndex < num; ++tonemarkIndex )
       
   511         {
       
   512         TBuf<1> toneMark;
       
   513         toneMark.Append( PinyinToneMap[tonemarkIndex].iValue );
       
   514         if ( aDes.Compare( toneMark ) == 0 )
       
   515             {
       
   516             break;
       
   517             }
       
   518         }
       
   519     aIndex = tonemarkIndex;
       
   520     }
       
   521 
       
   522 // ---------------------------------------------------------
       
   523 // TAknFepInputMiniQwertySogouPinyinPhrasePlugin::Enable
       
   524 // Enable or disable the plugin.
       
   525 // ---------------------------------------------------------
       
   526 //
       
   527 void TAknFepInputMiniQwertySogouPinyinPhrasePlugin::Enable( TBool aValid )
       
   528     {
       
   529     iValid = aValid;
       
   530     }
       
   531         
       
   532 // ---------------------------------------------------------
       
   533 // TAknFepInputMiniQwertySogouPinyinPhrasePlugin::IsEnable
       
   534 // Get the state of the plugin.
       
   535 // ---------------------------------------------------------
       
   536 //
       
   537 TBool TAknFepInputMiniQwertySogouPinyinPhrasePlugin::IsEnable()
       
   538     {
       
   539     return iValid;
       
   540     }
       
   541 
       
   542 // ---------------------------------------------------------------------------
       
   543 // TAknFepInputMiniQwertySogouPinyinPhrasePlugin::CommitInlineEEPL
       
   544 // Commint text to EEP or editor
       
   545 // ---------------------------------------------------------------------------
       
   546 //
       
   547 TBool TAknFepInputMiniQwertySogouPinyinPhrasePlugin::CommitInlineEEPL(
       
   548     const TDesC& aDes )
       
   549     {
       
   550     TInt charCount = aDes.Length();
       
   551     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   552     MAknFepUICtrlEditPane* editpane = iUIContainer->EditPaneWindow();
       
   553     CDesCArrayFlat* showkeyStoke = editpane->ShowKeystrokeArray();
       
   554     CDesCArrayFlat* keyStoke = editpane->KeystrokeArray();
       
   555     CDesCArrayFlat* phraseArray = editpane->PhraseArray();
       
   556     CDesCArrayFlat* phraseShowKeyStroke = editpane->PhraseShowKeyStrokeArray();
       
   557     TBuf<KMaxKeystrokeCount> buf;
       
   558     TBuf<1> autoDLT;
       
   559     autoDLT.Append( KAutoDLT );
       
   560 
       
   561     if (phraseArray->Count() == 0)
       
   562         {
       
   563         editpane->SetPhraseCreationFlag(EFalse);
       
   564         }
       
   565     phraseArray->AppendL( aDes );
       
   566 
       
   567     // Calculate the count of show keystroke which need to be deleted.   
       
   568     TInt delCount = 0;
       
   569     for ( TInt i = 0; i < showkeyStoke->Count() && charCount
       
   570             && keyStoke->Count() != 0; i++ )
       
   571         {
       
   572         TPtrC showptr = showkeyStoke->MdcaPoint(i);
       
   573         TPtrC ptr = keyStoke->MdcaPoint( 0);
       
   574         if ( CheckSpellingDLT( showptr ) || ( KInvalidToneMark
       
   575                 != ToneMark( showptr )))
       
   576             {
       
   577             // If the previous show key stroke is DLT or tonemark too, break.
       
   578             if ( i > 0 && 
       
   579                  ( CheckSpellingDLT( showkeyStoke->MdcaPoint( i - 1 )) || 
       
   580                  ( KInvalidToneMark != ToneMark( showkeyStoke->MdcaPoint( i - 1 )))))
       
   581                 {
       
   582                 break;
       
   583                 }
       
   584 
       
   585             charCount--;
       
   586             }
       
   587         if ( showptr.Compare( autoDLT ) != 0 )
       
   588             {
       
   589             buf.Append( ptr );
       
   590             keyStoke->Delete( 0 );
       
   591             }
       
   592         delCount++;
       
   593         }
       
   594     
       
   595     // Delete the show keystroke
       
   596     for (TInt j = 0; j < delCount; j++)
       
   597         {
       
   598         showkeyStoke->Delete( 0 );
       
   599         }
       
   600     
       
   601     // Record the keystrokes relative with the commit word
       
   602     phraseShowKeyStroke->AppendL( buf );
       
   603     
       
   604     // For Sogou core, maybe one element of PhraseArray() contains two or
       
   605     // more characters.
       
   606     TInt phraseCount = 0;
       
   607     for ( TInt l = 0; l < phraseArray->Count(); l++ )
       
   608         {
       
   609         phraseCount += phraseArray->MdcaPoint(l).Length();
       
   610         }
       
   611 
       
   612     // Tell sogou core which phrase is selected. It is used for phrase creation.
       
   613     TBuf<KMaxPhraseCreationCount> phraseSelected;
       
   614     phraseSelected.FillZ();
       
   615     if ( aDes.Length() <= KMaxPhraseCreationCount )
       
   616         {
       
   617         phraseSelected.Append( aDes );
       
   618         iOwner->PtiEngine()->HandleCommandL( EPtiCommandSelectElement, 
       
   619             ( TAny* )( &phraseSelected ));
       
   620         }
       
   621     
       
   622     // If there is no keystroke left or character count reach the limitation
       
   623     if ( keyStoke->Count() == 0 /*|| phraseCount == KMaxPhraseCreationCount */)
       
   624         {
       
   625         // Though maybe one element of PhraseArray() contains two or more characters,
       
   626         // here we do not need to get the characters count. Because we will handle
       
   627         // the phrase here, not character.
       
   628         HBufC* phraseCreated = HBufC::NewLC( phraseCount );
       
   629         TPtr keyPtr = phraseCreated->Des();
       
   630         phraseCount = phraseArray->Count();
       
   631         
       
   632         for ( TInt ii = 0; ii < phraseCount; ++ii )
       
   633             {
       
   634             TPtrC ptrZi = phraseArray->MdcaPoint( ii );
       
   635             keyPtr.Append( ptrZi );
       
   636             }
       
   637         fepMan->NewTextL( phraseCreated->Des());
       
   638         fepMan->CommitInlineEditL();
       
   639         
       
   640         // Tell sogou core the phrase pinyin
       
   641         AddPhrasePinyinToPti();
       
   642         iOwner->PtiEngine()->SetPredictiveChineseChar( phraseCreated->Des());
       
   643         CleanupStack::PopAndDestroy();
       
   644         return EFalse;
       
   645         }
       
   646 
       
   647     editpane->SetCursorIndexOfKeystroke( 0 );
       
   648     editpane->DisableCursor();
       
   649     editpane->SetPhraseCreationFlag( ETrue );
       
   650     return ETrue;
       
   651     }
       
   652 
       
   653 // ---------------------------------------------------------
       
   654 // TAknFepInputMiniQwertyPinyinPhraseBase::AddPhrasePinyinToPti
       
   655 // Add phrase to DB.
       
   656 // ---------------------------------------------------------
       
   657 //
       
   658 void TAknFepInputMiniQwertySogouPinyinPhrasePlugin::AddPhrasePinyinToPti()
       
   659     {
       
   660     MAknFepUICtrlEditPane* editpane = iUIContainer->EditPaneWindow();
       
   661     CDesCArrayFlat* phraseShowKeyStroke = editpane->PhraseShowKeyStrokeArray();
       
   662     TBuf<KMaxShowKeystrokeCount> phraseCreatedPinYin;
       
   663     phraseCreatedPinYin.FillZ();
       
   664     for ( TInt i = 0; i < phraseShowKeyStroke->Count(); i++ )
       
   665         {
       
   666         TPtrC ptrPinYin = phraseShowKeyStroke->MdcaPoint(i);
       
   667         phraseCreatedPinYin.Append(ptrPinYin);
       
   668         }
       
   669     //Add the phrase pinyin to the DB by PTI Engine
       
   670     TRAP_IGNORE( iOwner->PtiEngine()->HandleCommandL( 
       
   671             EPtiCommandSetPinyinForLearnWord, (TAny*)( &phraseCreatedPinYin )));
       
   672     }
       
   673 
       
   674 // ---------------------------------------------------------
       
   675 // TAknFepInputMiniQwertySogouPinyinPhrasePlugin::GetCandidateL
       
   676 // Get the candidate info.
       
   677 // ---------------------------------------------------------
       
   678 //
       
   679 void TAknFepInputMiniQwertySogouPinyinPhrasePlugin::GetCandidateL()
       
   680     {
       
   681     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   682     MAknFepUICtrlEditPane* editPane = iUIContainer->EditPaneWindow();
       
   683     CDesCArrayFlat* phraseCandidates = 
       
   684             iUIContainer->CandidatePane()->CandidateArray();
       
   685     CDesCArrayFlat* keystroke = editPane->KeystrokeArray();
       
   686     CDesCArrayFlat* showKeystroke = editPane->ShowKeystrokeArray();
       
   687     TInt phraseCount = editPane->PhraseArray()->Count();
       
   688     phraseCandidates->Reset();
       
   689     TBuf<KMaxKeystrokeCount> buf;
       
   690     TBuf<1> delimiter;
       
   691     delimiter.Append( KManualDLT );
       
   692     TInt keyCode;
       
   693     TInt count = KInvalidToneMark;
       
   694     ClearPtiEngineKeystroke();
       
   695     
       
   696     if ( showKeystroke->Count() == 0 )
       
   697         {
       
   698         return;
       
   699         }
       
   700     
       
   701     // If all strokes are valid
       
   702     if ( iCanConvertAll )
       
   703         {
       
   704         AnalyseL();
       
   705         ptiengine->GetChinesePhraseCandidatesL( *phraseCandidates ); 
       
   706         return;
       
   707         }
       
   708 
       
   709     // If some characters are invalid, we only need to get the candidates of 
       
   710     // the strokes before the invalid character.
       
   711     ClearPtiEngineKeystroke();
       
   712     TInt autoDLT = 0;
       
   713     for ( TInt j = 0; j < iConvertCount; j++ )
       
   714         {
       
   715         if ( showKeystroke->MdcaPoint( j )[0] == KAutoDLT )
       
   716             {
       
   717             autoDLT++;
       
   718             }
       
   719         }
       
   720     for ( TInt i = 0; i < iConvertCount - autoDLT/*showKeystroke->Count()*/; ++i )
       
   721         {
       
   722         count = ToneMark( keystroke->MdcaPoint( i ) );
       
   723         if ( KInvalidToneMark != count )
       
   724             {
       
   725             for ( TInt j = 0; j < count; ++j )
       
   726                 {
       
   727                 ptiengine->IncrementToneMark( ETrue );
       
   728                 }
       
   729             }
       
   730         else
       
   731             {
       
   732             GetKeystrokeCode( keyCode, keystroke->MdcaPoint( i ) );
       
   733             ptiengine->AppendKeyPress((TPtiKey)keyCode);
       
   734             }
       
   735         }
       
   736 
       
   737     getCurrentLeastDLTSpell();
       
   738     ptiengine->GetChinesePhraseCandidatesL( *phraseCandidates );
       
   739     }
       
   740 
       
   741 // ---------------------------------------------------------
       
   742 // TAknFepInputMiniQwertySogouPinyinPhrasePlugin::CanConvertAll
       
   743 // Set flag for convert all stroke.
       
   744 // ---------------------------------------------------------
       
   745 //
       
   746 void TAknFepInputMiniQwertySogouPinyinPhrasePlugin::CanConvertAll( TBool aEnable )
       
   747     {
       
   748     iCanConvertAll = aEnable;
       
   749     }
       
   750 
       
   751 // ---------------------------------------------------------
       
   752 // TAknFepInputMiniQwertySogouPinyinPhrasePlugin::ConvertCount
       
   753 // Set convert count.
       
   754 // ---------------------------------------------------------
       
   755 //           
       
   756 void TAknFepInputMiniQwertySogouPinyinPhrasePlugin::ConvertCount( TInt aCount )
       
   757     {
       
   758     iConvertCount = aCount;
       
   759     }
       
   760 
       
   761 // End of file