fep/aknfep/src/aknfepuiinputminiqwertypinyinphrasebase.cpp
branchRCL_3
changeset 50 5a1685599b76
parent 46 bd83ceabce89
child 56 8152b1f1763a
equal deleted inserted replaced
46:bd83ceabce89 50:5a1685599b76
   119     {0x02C7, 3},
   119     {0x02C7, 3},
   120     {0x02CB, 4},
   120     {0x02CB, 4},
   121     {0x02D9, 5}
   121     {0x02D9, 5}
   122     };
   122     };
   123 
   123 
       
   124 const TUid KPtiSogouCoreUid = { 0x20031DD6 };
       
   125 
   124 // ---------------------------------------------------------------------------
   126 // ---------------------------------------------------------------------------
   125 // TAknFepInputStateStrokePhraseCreationBase::TAknFepInputStateStrokePhraseCreationBase
   127 // TAknFepInputStateStrokePhraseCreationBase::TAknFepInputStateStrokePhraseCreationBase
   126 // C++ default constructor
   128 // C++ default constructor
   127 // ---------------------------------------------------------------------------
   129 // ---------------------------------------------------------------------------
   128 //
   130 //
   137         }
   139         }
   138     iOwner->PtiEngine()->SetCandidatePageLength(KMaxPhraseCount);
   140     iOwner->PtiEngine()->SetCandidatePageLength(KMaxPhraseCount);
   139     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
   141     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
   140     TBool multiplePages = !(uiContainer->CandidatePane()->IsLastPage() && uiContainer->CandidatePane()->IsFirstPage());
   142     TBool multiplePages = !(uiContainer->CandidatePane()->IsLastPage() && uiContainer->CandidatePane()->IsFirstPage());
   141     uiContainer->ShowVerticalScrollArrows(multiplePages);
   143     uiContainer->ShowVerticalScrollArrows(multiplePages);
       
   144     
       
   145     // If sogou core is in use, set plugin to the state
       
   146     // machine and enable the plugin.
       
   147     // Get current core id. It is used to judge whether sogou core is in use.
       
   148     TInt coreID = 0;
       
   149     TRAP_IGNORE( coreID = iOwner->PtiEngine()->HandleCommandL( EPtiCommandGetCoreID ));
       
   150     if ( TUid::Uid( coreID ) == KPtiSogouCoreUid )
       
   151         {
       
   152         TAknFepInputMiniQwertySogouPinyinPhrasePlugin plugin( aOwner, aUIContainer, iState );
       
   153         plugin.Enable( ETrue );
       
   154         SetPlugin( plugin );
       
   155         }
   142     }
   156     }
   143 
   157 
   144 // ---------------------------------------------------------------------------
   158 // ---------------------------------------------------------------------------
   145 // TAknFepInputMiniQwertyPinyinPhraseBase::HandleKeyL
   159 // TAknFepInputMiniQwertyPinyinPhraseBase::HandleKeyL
   146 // Handle system key press event.
   160 // Handle system key press event.
   384                 {
   398                 {
   385                 return EFalse;
   399                 return EFalse;
   386                 }
   400                 }
   387             }
   401             }
   388         GetKeystrokeCode(keyCode, showKeystroke->MdcaPoint(i) );
   402         GetKeystrokeCode(keyCode, showKeystroke->MdcaPoint(i) );
   389         stringBeforeLength = getCurrentLeastDLTSpell().Length();
   403         
       
   404         // dltBeforeCount is the dlt count before append the key.
       
   405         // dltAfterCount is the dlt count after append the key.
       
   406         // In sogou core, after appending a new key, the spell length
       
   407         // may be the same, but the dlt count will change.
       
   408         // In this situation, the appended key is valid.
       
   409         TInt dltBeforeCount = 0;
       
   410         TInt dltAfterCount = 0;
       
   411         TPtrC stringBefore = getCurrentLeastDLTSpell();
       
   412         stringBeforeLength = stringBefore.Length();
       
   413         for ( TInt k = 0; k < stringBefore.Length(); k++ )
       
   414             {
       
   415             if ( CheckSpellingDLT( stringBefore.Mid( k )))
       
   416                 {
       
   417                 dltBeforeCount++;
       
   418                 }
       
   419             }
       
   420         
       
   421         // Append the key.
   390         ptiengine->AppendKeyPress((TPtiKey)keyCode).Length();
   422         ptiengine->AppendKeyPress((TPtiKey)keyCode).Length();
   391         stringAfterLength = getCurrentLeastDLTSpell().Length();
   423         
   392         //the keystroke is invalid.
   424         // Get the dlt count after appending the key.
   393         if (stringBeforeLength == stringAfterLength)
   425         TPtrC stringAfter = getCurrentLeastDLTSpell();
       
   426         stringAfterLength = stringAfter.Length();
       
   427         for ( TInt l = 0; l < stringAfter.Length(); l++ )
       
   428             {
       
   429             if ( CheckSpellingDLT( stringAfter.Mid( l )))
       
   430                 {
       
   431                 dltAfterCount++;
       
   432                 }
       
   433             }
       
   434 
       
   435         // If the spell length is the same and the dlt count is 
       
   436         // the same, the keystroke is invalid
       
   437         if (( stringBeforeLength == stringAfterLength ) &&
       
   438             ( dltAfterCount == dltBeforeCount ))
   394             {
   439             {
   395             return EFalse;
   440             return EFalse;
   396             }
   441             }
   397         }
   442         }
   398     return ETrue;
   443     return ETrue;
   413     TInt index = editPane->GetCursorIndexOfKeystroke();
   458     TInt index = editPane->GetCursorIndexOfKeystroke();
   414     TInt pos = 0;
   459     TInt pos = 0;
   415     TInt count = 0;
   460     TInt count = 0;
   416     TBuf<1> autoDLT;
   461     TBuf<1> autoDLT;
   417     autoDLT.Append(KAutoDLT);
   462     autoDLT.Append(KAutoDLT);
   418 
   463     
       
   464     // If this method is called in construction of the state machine,
       
   465     // the plugin is not set. If sogou core is in use now, the phraseCount
       
   466     // should be the same as the phrase characters count.
       
   467     // For Sogou core, maybe one element of PhraseArray() contains two or more characters.
       
   468     TInt coreID = 0;
       
   469     TRAP_IGNORE( coreID = iOwner->PtiEngine()->HandleCommandL( EPtiCommandGetCoreID ));
       
   470     if ( TUid::Uid( coreID ) == KPtiSogouCoreUid )
       
   471         {
       
   472         CDesCArrayFlat* phraseArray = editPane->PhraseArray();
       
   473         phraseCount = 0;
       
   474         for ( TInt i = 0; i < phraseArray->Count(); i++ )
       
   475             {
       
   476             phraseCount += (*phraseArray)[i].Length();
       
   477             }
       
   478         }
       
   479     
   419     if ( 0 == index)
   480     if ( 0 == index)
   420         {
   481         {
   421         pos = phraseCount;
   482         pos = phraseCount;
   422         }
   483         }
   423     else
   484     else
   515     TBuf<1> manualDLT;
   576     TBuf<1> manualDLT;
   516     TBuf<1> autoDLT;
   577     TBuf<1> autoDLT;
   517     manualDLT.Append( KManualDLT );
   578     manualDLT.Append( KManualDLT );
   518     autoDLT.Append( KAutoDLT );
   579     autoDLT.Append( KAutoDLT );
   519     
   580     
       
   581     // Get the current core id
       
   582     TInt coreID = 0;
       
   583     TRAP_IGNORE( coreID = iOwner->PtiEngine()->HandleCommandL( EPtiCommandGetCoreID ));
       
   584     
       
   585     if ( TUid::Uid( coreID ) == KPtiSogouCoreUid )
       
   586         {
       
   587         CDesCArrayFlat* phrase = editPane->PhraseArray();
       
   588         phraseCount = 0;
       
   589         for ( TInt j = 0;  j < phrase->Count(); j++ )
       
   590             {
       
   591             phraseCount += phrase->MdcaPoint(j).Length();;
       
   592             }
       
   593         }
       
   594     
       
   595     if ( phraseCount + showKeystrokeCount >= KMaxKeystrokeCount )
       
   596         {
       
   597         iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
       
   598         return;
       
   599         }
       
   600     
   520     TBool firstGroup = CheckFirstGroupStroke();
   601     TBool firstGroup = CheckFirstGroupStroke();
   521 
   602 
   522     keystrokeArray->InsertL(index, manualDLT);
   603     keystrokeArray->InsertL(index, manualDLT);
   523     editPane->SetCursorIndexOfKeystroke(index + 1);
   604     editPane->SetCursorIndexOfKeystroke(index + 1);
   524     AnalyseL();
   605     AnalyseL();
   871 // Analyse key storke.
   952 // Analyse key storke.
   872 // ---------------------------------------------------------------------------
   953 // ---------------------------------------------------------------------------
   873 //
   954 //
   874 void TAknFepInputMiniQwertyPinyinPhraseBase::AnalyseL()
   955 void TAknFepInputMiniQwertyPinyinPhraseBase::AnalyseL()
   875     {
   956     {
       
   957     // If sogou core is actived, use the plugin.
       
   958     if ( iPlugin.IsEnable())
       
   959         {
       
   960         iPlugin.AnalyseL();
       
   961         return;
       
   962         }
   876     CPtiEngine* ptiengine = iOwner->PtiEngine();
   963     CPtiEngine* ptiengine = iOwner->PtiEngine();
   877     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
   964     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
   878     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
   965     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
   879     //user pressed keystroke sequence
   966     //user pressed keystroke sequence
   880     CDesCArrayFlat* keystroke = editPane->KeystrokeArray();
   967     CDesCArrayFlat* keystroke = editPane->KeystrokeArray();
   976     if (EMiniQwertyEdit == iState)
  1063     if (EMiniQwertyEdit == iState)
   977         {
  1064         {
   978         if ( ( showKeyCount > 0 ) && (cdtCount > 0 ) )
  1065         if ( ( showKeyCount > 0 ) && (cdtCount > 0 ) )
   979             {
  1066             {
   980             UIContainer()->EditPaneWindow()->SetChangeState(ETrue);
  1067             UIContainer()->EditPaneWindow()->SetChangeState(ETrue);
   981             iOwner->ChangeState(ECandidate);
  1068             iOwner->ChangeState(EEntry);
   982             return;
  1069             return;
   983             }
  1070             }
   984 
  1071 
   985         if ( keyCount > 0 )
  1072         if ( keyCount > 0 )
   986             {
  1073             {
  1047                 }
  1134                 }
  1048             else
  1135             else
  1049                 {
  1136                 {
  1050                 editPane->SetAutoChangeStateFlag(EAutoChangeStateFromCandidate);
  1137                 editPane->SetAutoChangeStateFlag(EAutoChangeStateFromCandidate);
  1051                 }
  1138                 }
       
  1139             //stroke to be shown
       
  1140             if ( iPlugin.IsEnable())
       
  1141                 {
       
  1142                 iPlugin.AnalyseL();
       
  1143                 }
  1052             iOwner->ChangeState(EMiniQwertyEdit);
  1144             iOwner->ChangeState(EMiniQwertyEdit);
  1053             return;
  1145             return;
  1054             }
  1146             }
  1055         else
  1147 
  1056             {
       
  1057             if ( iState == EEntry )
       
  1058                 {
       
  1059                 UIContainer()->EditPaneWindow()->SetChangeState( ETrue );
       
  1060                 iOwner->ChangeState( ECandidate );
       
  1061                 }
       
  1062             }
       
  1063         AnalyseL();
  1148         AnalyseL();
  1064         RefreshUI();
  1149         RefreshUI();
  1065         }
  1150         }
  1066     }
  1151     }
  1067 
  1152 
  1218     CDesCArrayFlat* showKeystroke = editPane->ShowKeystrokeArray();
  1303     CDesCArrayFlat* showKeystroke = editPane->ShowKeystrokeArray();
  1219     CDesCArrayFlat* keystrokeArray = editPane->KeystrokeArray();
  1304     CDesCArrayFlat* keystrokeArray = editPane->KeystrokeArray();
  1220     CDesCArrayFlat* phrase = editPane->PhraseArray();
  1305     CDesCArrayFlat* phrase = editPane->PhraseArray();
  1221     TBuf<KMaxKeystrokeCount> showInfo;
  1306     TBuf<KMaxKeystrokeCount> showInfo;
  1222     TBuf<KMaxKeystrokeCount> keyBuf;
  1307     TBuf<KMaxKeystrokeCount> keyBuf;
       
  1308     
       
  1309     // Get the current core id
       
  1310     TInt coreID = 0;
       
  1311     TRAP_IGNORE( coreID = iOwner->PtiEngine()->HandleCommandL( EPtiCommandGetCoreID ));
       
  1312     TInt phraseCount = 0;
       
  1313     
  1223     for (TInt i = 0; i < phrase->Count(); ++i)
  1314     for (TInt i = 0; i < phrase->Count(); ++i)
  1224         {
  1315         {
  1225         showInfo.Append(phrase->MdcaPoint(i) );
  1316         // If this method is called in construction of the state machine,
       
  1317         // the plugin is not set. If sogou core is in use now, we should append 
       
  1318         // each characters to showInfo.
       
  1319         // For Sogou core, maybe one element of PhraseArray() contains two or more characters.
       
  1320         if ( TUid::Uid( coreID ) == KPtiSogouCoreUid )
       
  1321             {
       
  1322             for ( TInt k = 0; k < phrase->MdcaPoint(i).Length(); k++ )
       
  1323                 {
       
  1324                 showInfo.Append( phrase->MdcaPoint(i)[k] );
       
  1325                 }
       
  1326             phraseCount += phrase->MdcaPoint(i).Length();
       
  1327             }
       
  1328         else
       
  1329             {
       
  1330             // If cpicore is in use, just append the element of phrase
       
  1331             showInfo.Append(phrase->MdcaPoint(i) );
       
  1332             }
  1226         }
  1333         }
  1227 
  1334 
  1228     for (TInt ii = 0; ii < showKeystroke->Count(); ++ii)
  1335     for (TInt ii = 0; ii < showKeystroke->Count(); ++ii)
  1229         {
  1336         {
  1230         showInfo.Append(showKeystroke->MdcaPoint(ii) );
  1337         showInfo.Append(showKeystroke->MdcaPoint(ii) );
  1232 
  1339 
  1233     for (TInt j = 0; j < keystrokeArray->Count(); ++j)
  1340     for (TInt j = 0; j < keystrokeArray->Count(); ++j)
  1234         {
  1341         {
  1235         keyBuf.Append(keystrokeArray->MdcaPoint(j) );
  1342         keyBuf.Append(keystrokeArray->MdcaPoint(j) );
  1236         }
  1343         }
  1237 
  1344     
  1238     editPane->SetTextForZhuyin(showInfo, GetCursorPos(), phrase->Count(),
  1345     // If this method is called in construction of the state machine,
       
  1346     // the plugin is not set. If sogou core is in use now, the phraseCount
       
  1347     // should be the same as the phrase characters count.
       
  1348     // For Sogou core, maybe one element of PhraseArray() contains two or more characters.
       
  1349     if ( TUid::Uid( coreID ) == KPtiSogouCoreUid )
       
  1350         {
       
  1351         editPane->SetTextForZhuyin(showInfo, GetCursorPos(), phraseCount,
       
  1352                         keyBuf, editPane->GetCursorIndexOfKeystroke() );
       
  1353         }
       
  1354     else
       
  1355         {
       
  1356         // If cpicore is in use, phraseCount is the same as phrase->Count()
       
  1357         editPane->SetTextForZhuyin(showInfo, GetCursorPos(), phrase->Count(),
  1239         keyBuf, editPane->GetCursorIndexOfKeystroke() );
  1358         keyBuf, editPane->GetCursorIndexOfKeystroke() );
       
  1359         }
  1240 
  1360 
  1241     if (iState == ECandidate)
  1361     if (iState == ECandidate)
  1242         {
  1362         {
  1243         editPane->DisableCursor();
  1363         editPane->DisableCursor();
  1244         }
  1364         }
  1534 // ---------------------------------------------------------
  1654 // ---------------------------------------------------------
  1535 //
  1655 //
  1536 void TAknFepInputMiniQwertyPinyinPhraseBase::AddPhraseToDB(
  1656 void TAknFepInputMiniQwertyPinyinPhraseBase::AddPhraseToDB(
  1537     const TDesC& aPhraseAdd)
  1657     const TDesC& aPhraseAdd)
  1538     {
  1658     {
       
  1659     if ( iPlugin.IsEnable())
       
  1660         {
       
  1661         iPlugin.AddPhrasePinyinToPti();
       
  1662         return;
       
  1663         }
  1539     TPtiUserDictionaryEntry addUdbEntry(aPhraseAdd);
  1664     TPtiUserDictionaryEntry addUdbEntry(aPhraseAdd);
  1540     //Add the phrase to the DB by PTI Engine
  1665     //Add the phrase to the DB by PTI Engine
  1541     iOwner->PtiEngine()->AddUserDictionaryEntry(addUdbEntry);
  1666     iOwner->PtiEngine()->AddUserDictionaryEntry(addUdbEntry);
  1542     }
  1667     }
  1543 
  1668 
  1586 // ---------------------------------------------------------------------------
  1711 // ---------------------------------------------------------------------------
  1587 //
  1712 //
  1588 TBool TAknFepInputMiniQwertyPinyinPhraseBase::CommitInlineEEPL(
  1713 TBool TAknFepInputMiniQwertyPinyinPhraseBase::CommitInlineEEPL(
  1589     const TDesC& aDes)
  1714     const TDesC& aDes)
  1590     {
  1715     {
       
  1716     // If sogou core is actived, use the plugin.
       
  1717     if ( iPlugin.IsEnable())
       
  1718         {
       
  1719         return iPlugin.CommitInlineEEPL( aDes );
       
  1720         }
       
  1721 
  1591     TInt charCount = aDes.Length();
  1722     TInt charCount = aDes.Length();
  1592     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
  1723     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
  1593     MAknFepUICtrlEditPane* editpane = UIContainer()->EditPaneWindow();
  1724     MAknFepUICtrlEditPane* editpane = UIContainer()->EditPaneWindow();
  1594     CDesCArrayFlat* showkeyStoke = editpane->ShowKeystrokeArray();
  1725     CDesCArrayFlat* showkeyStoke = editpane->ShowKeystrokeArray();
  1595     CDesCArrayFlat* keyStoke = editpane->KeystrokeArray();
  1726     CDesCArrayFlat* keyStoke = editpane->KeystrokeArray();
  1693     TInt phraseCount = editPane->PhraseArray()->Count();
  1824     TInt phraseCount = editPane->PhraseArray()->Count();
  1694     TInt showKeystrokeCount = editPane->ShowKeystrokeArray()->Count();
  1825     TInt showKeystrokeCount = editPane->ShowKeystrokeArray()->Count();
  1695     TInt index = editPane->GetCursorIndexOfKeystroke();
  1826     TInt index = editPane->GetCursorIndexOfKeystroke();
  1696     TBuf<1> keystroke;
  1827     TBuf<1> keystroke;
  1697     
  1828     
       
  1829     // Get the current core id
       
  1830     TInt coreID = 0;
       
  1831     TRAP_IGNORE( coreID = iOwner->PtiEngine()->HandleCommandL( EPtiCommandGetCoreID ));
       
  1832     
       
  1833     if ( TUid::Uid( coreID ) == KPtiSogouCoreUid )
       
  1834         {
       
  1835         CDesCArrayFlat* phrase = editPane->PhraseArray();
       
  1836         phraseCount = 0;
       
  1837         for ( TInt j = 0;  j < phrase->Count(); j++ )
       
  1838             {
       
  1839             phraseCount += phrase->MdcaPoint(j).Length();;
       
  1840             }
       
  1841         }
       
  1842     
  1698     if ( phraseCount + showKeystrokeCount >= KMaxKeystrokeCount )
  1843     if ( phraseCount + showKeystrokeCount >= KMaxKeystrokeCount )
  1699         {
  1844         {
  1700         return EFalse;
  1845         return EFalse;
  1701         }
  1846         }
  1702 
  1847 
  1705 	//Add this condition to avoid crash in case keystroke is empty.
  1850 	//Add this condition to avoid crash in case keystroke is empty.
  1706     if(keystroke.Length() == 0)
  1851     if(keystroke.Length() == 0)
  1707         {
  1852         {
  1708         return EFalse;
  1853         return EFalse;
  1709         }
  1854         }
       
  1855     
  1710     if ( index >= keystrokeArray->Count() )
  1856     if ( index >= keystrokeArray->Count() )
  1711         {
  1857         {
  1712         keystrokeArray->AppendL(keystroke);
  1858         keystrokeArray->AppendL(keystroke);
  1713         editPane->SetCursorIndexOfKeystroke(keystrokeArray->Count() );
  1859         editPane->SetCursorIndexOfKeystroke(keystrokeArray->Count() );
  1714         }
  1860         }
  1837 // Get the candidate info.
  1983 // Get the candidate info.
  1838 // ---------------------------------------------------------
  1984 // ---------------------------------------------------------
  1839 //
  1985 //
  1840 void TAknFepInputMiniQwertyPinyinPhraseBase::GetCandidateL()
  1986 void TAknFepInputMiniQwertyPinyinPhraseBase::GetCandidateL()
  1841     {
  1987     {
       
  1988     if ( iPlugin.IsEnable())
       
  1989         {
       
  1990         iPlugin.GetCandidateL();
       
  1991         return;
       
  1992         }
       
  1993     
  1842     CPtiEngine* ptiengine = iOwner->PtiEngine();
  1994     CPtiEngine* ptiengine = iOwner->PtiEngine();
  1843     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
  1995     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
  1844     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
  1996     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
  1845     CDesCArrayFlat* phraseCandidates = 
  1997     CDesCArrayFlat* phraseCandidates = 
  1846         uiContainer->CandidatePane()->CandidateArray();
  1998         uiContainer->CandidatePane()->CandidateArray();
  1858     if ( showKeystroke->Count() == 0 )
  2010     if ( showKeystroke->Count() == 0 )
  1859         {
  2011         {
  1860         return;
  2012         return;
  1861         }
  2013         }
  1862 
  2014 
  1863     if ( CheckAllGroupStroke() && ( phraseCount == 0 ) )
  2015     if (( phraseCount == 0 ) && CheckAllGroupStroke())
  1864         {
  2016         {
  1865         getCurrentLeastDLTSpell();
  2017         getCurrentLeastDLTSpell();
  1866         ptiengine->GetChinesePhraseCandidatesL( *phraseCandidates ); 
  2018         ptiengine->GetChinesePhraseCandidatesL( *phraseCandidates ); 
  1867         return;
  2019         return;
  1868         }
  2020         }
  1973 
  2125 
  1974     editPane->SetCursorIndexOfKeystroke(buf.Length() );
  2126     editPane->SetCursorIndexOfKeystroke(buf.Length() );
  1975     keystrokeArray->Compress();
  2127     keystrokeArray->Compress();
  1976     phrase->Compress();
  2128     phrase->Compress();
  1977     phraseStroke->Compress();
  2129     phraseStroke->Compress();
  1978 
  2130     
       
  2131     TInt coreID = iOwner->PtiEngine()->HandleCommandL( EPtiCommandGetCoreID );
       
  2132     if ( TUid::Uid( coreID ) == KPtiSogouCoreUid )
       
  2133         {
       
  2134         // Notify sogoucore that last phrase is cancelled
       
  2135         iOwner->PtiEngine()->HandleCommandL( EPtiCommandCancelSelectElement );
       
  2136         }
  1979     }
  2137     }
  1980 
  2138 
  1981 // ---------------------------------------------------------
  2139 // ---------------------------------------------------------
  1982 // TAknFepInputMiniQwertyPinyinPhraseBase::SetWarningColor
  2140 // TAknFepInputMiniQwertyPinyinPhraseBase::SetWarningColor
  1983 // Set warning color.
  2141 // Set warning color.
  1999             - 1) ) || (KInvalidToneMark
  2157             - 1) ) || (KInvalidToneMark
  2000             != ToneMark( aShowKeystroke->MdcaPoint( aI - 1 ) ) ))
  2158             != ToneMark( aShowKeystroke->MdcaPoint( aI - 1 ) ) ))
  2001         {
  2159         {
  2002         editPane->SetHighlight(aPhraseCount + aIndex, aPhraseCount
  2160         editPane->SetHighlight(aPhraseCount + aIndex, aPhraseCount
  2003                 + aIndex + aCount - 1 );
  2161                 + aIndex + aCount - 1 );
       
  2162         if ( iPlugin.IsEnable())
       
  2163             {
       
  2164             iPlugin.CanConvertAll( EFalse );
       
  2165             iPlugin.ConvertCount( aIndex );
       
  2166             }
  2004         }
  2167         }
  2005     else
  2168     else
  2006         {
  2169         {
  2007         TPtrC ptr1 = getCurrentLeastDLTSpell();
  2170         TPtrC ptr1 = getCurrentLeastDLTSpell();
  2008         for (TInt j = 0; j < aToneMark; ++j)
  2171         for (TInt j = 0; j < aToneMark; ++j)
  2023                 != ptr2.Mid( ptr2.Length() - 1, 1 ).
  2186                 != ptr2.Mid( ptr2.Length() - 1, 1 ).
  2024                 CompareC( aShowKeystroke->MdcaPoint( aI ) ) ))
  2187                 CompareC( aShowKeystroke->MdcaPoint( aI ) ) ))
  2025             {
  2188             {
  2026             editPane->SetHighlight( aPhraseCount + aIndex, aPhraseCount
  2189             editPane->SetHighlight( aPhraseCount + aIndex, aPhraseCount
  2027                     + aIndex + aCount - 1);
  2190                     + aIndex + aCount - 1);
       
  2191             if ( iPlugin.IsEnable())
       
  2192                 {
       
  2193                 iPlugin.CanConvertAll( EFalse );
       
  2194                 iPlugin.ConvertCount( aIndex );
       
  2195                 }
  2028             }
  2196             }
  2029         }
  2197         }
  2030     ClearPtiEngineKeystroke();
  2198     ClearPtiEngineKeystroke();
  2031     }
  2199     }
  2032 
  2200 
  2047     TInt stringBeforeLength = 0;
  2215     TInt stringBeforeLength = 0;
  2048     TInt stringAfterLength = 0;
  2216     TInt stringAfterLength = 0;
  2049     TInt start = 0;
  2217     TInt start = 0;
  2050     TInt keyCode = 0;
  2218     TInt keyCode = 0;
  2051     TInt toneMark = KInvalidToneMark;
  2219     TInt toneMark = KInvalidToneMark;
       
  2220     
       
  2221     if ( iPlugin.IsEnable())
       
  2222         {
       
  2223         iPlugin.CanConvertAll( ETrue );
       
  2224         }
       
  2225     // Get the current core id
       
  2226     TInt coreID = 0;
       
  2227     TRAP_IGNORE( coreID = iOwner->PtiEngine()->HandleCommandL( EPtiCommandGetCoreID ));
       
  2228     
       
  2229     if ( TUid::Uid( coreID ) == KPtiSogouCoreUid )
       
  2230         {
       
  2231         CDesCArrayFlat* phrase = editPane->PhraseArray();
       
  2232         phraseCount = 0;
       
  2233         for ( TInt j = 0;  j < phrase->Count(); j++ )
       
  2234             {
       
  2235             phraseCount += phrase->MdcaPoint(j).Length();;
       
  2236             }
       
  2237         }
  2052 
  2238 
  2053     if (showKeystroke->Count() == 0)
  2239     if (showKeystroke->Count() == 0)
  2054         {
  2240         {
  2055         return;
  2241         return;
  2056         }
  2242         }
  2057 
  2243 
  2058     if (CheckAllGroupStroke() )
  2244     if ( TUid::Uid( coreID ) != KPtiSogouCoreUid )
  2059         {
  2245         {
  2060         return;
  2246         if ( CheckAllGroupStroke())
  2061         }
  2247             {
       
  2248             return;
       
  2249             }
       
  2250         }
       
  2251 
  2062     ClearPtiEngineKeystroke();
  2252     ClearPtiEngineKeystroke();
  2063     if (CheckSpellingDLT(showKeystroke->MdcaPoint( 0) ) || (KInvalidToneMark
  2253     if (CheckSpellingDLT(showKeystroke->MdcaPoint( 0) ) || (KInvalidToneMark
  2064             != ToneMark(showKeystroke->MdcaPoint( 0) ) ))
  2254             != ToneMark(showKeystroke->MdcaPoint( 0) ) ))
  2065         {
  2255         {
  2066         start = 1;
  2256         start = 1;
  2067         editPane->SetHighlight(phraseCount, phraseCount);
  2257         editPane->SetHighlight(phraseCount, phraseCount);
       
  2258 
       
  2259         if ( iPlugin.IsEnable())
       
  2260             {
       
  2261             iPlugin.CanConvertAll( EFalse );
       
  2262             iPlugin.ConvertCount( index );
       
  2263             }
       
  2264         
  2068         index = 1;
  2265         index = 1;
  2069         }
  2266         }
  2070 
  2267     
  2071     for ( TInt i = start; i < showKeystroke->Count(); ++i )
  2268     TInt end = showKeystroke->Count();
       
  2269     if ( TUid::Uid( coreID ) == KPtiSogouCoreUid )
       
  2270         {
       
  2271         for ( TInt j = showKeystroke->Count() - 1; j >= 0; j-- )
       
  2272             {
       
  2273             if ( KAutoDLT == showKeystroke->MdcaPoint(j)[0] )
       
  2274                 {
       
  2275                 end = j + 1;
       
  2276                 break;
       
  2277                 }
       
  2278             }
       
  2279         }
       
  2280 
       
  2281     for ( TInt i = start; i < end; ++i )
  2072         {
  2282         {
  2073         count = count + 1;
  2283         count = count + 1;
  2074         // tone mark
  2284         // tone mark
  2075         toneMark = ToneMark(showKeystroke->MdcaPoint(i) );
  2285         toneMark = ToneMark(showKeystroke->MdcaPoint(i) );
  2076         if ( KInvalidToneMark != toneMark )
  2286         if ( KInvalidToneMark != toneMark )
  2094                         || (KInvalidToneMark
  2304                         || (KInvalidToneMark
  2095                                 != ToneMark(showKeystroke->MdcaPoint(i - 1) ) ))
  2305                                 != ToneMark(showKeystroke->MdcaPoint(i - 1) ) ))
  2096                     {
  2306                     {
  2097                     editPane->SetHighlight(phraseCount + index, phraseCount
  2307                     editPane->SetHighlight(phraseCount + index, phraseCount
  2098                             + index + count - 1);
  2308                             + index + count - 1);
       
  2309                     if ( iPlugin.IsEnable())
       
  2310                         {
       
  2311                         iPlugin.CanConvertAll( EFalse );
       
  2312                         iPlugin.ConvertCount( index );
       
  2313                         }
  2099                     }
  2314                     }
  2100                 ClearPtiEngineKeystroke();
  2315                 ClearPtiEngineKeystroke();
  2101                 index = i + 1;
  2316                 index = i + 1;
  2102                 count = 0;
  2317                 count = 0;
  2103                 valid = ETrue;
  2318                 valid = ETrue;
  2105             else
  2320             else
  2106                 {
  2321                 {
  2107                 if ( valid )
  2322                 if ( valid )
  2108                     {
  2323                     {
  2109                     GetKeystrokeCode(keyCode, showKeystroke->MdcaPoint(i) );
  2324                     GetKeystrokeCode(keyCode, showKeystroke->MdcaPoint(i) );
  2110                     stringBeforeLength = getCurrentLeastDLTSpell().Length();
  2325                     
  2111                     ptiengine->AppendKeyPress((TPtiKey)keyCode).Length();
  2326                     // dltBeforeCount is the dlt count before append the key.
  2112                     stringAfterLength = getCurrentLeastDLTSpell().Length();
  2327                     // dltAfterCount is the dlt count after append the key.
  2113                     if ( stringBeforeLength == stringAfterLength )//the keystroke is invalid
  2328                     // In sogou core, after appending a new key, the spell length
       
  2329                     // may be the same, but the dlt count will change.
       
  2330                     // In this situation, the appended key is valid.
       
  2331                     TInt dltBeforeCount = 0;
       
  2332                     TInt dltAfterCount = 0;
       
  2333                     TPtrC stringBefore = getCurrentLeastDLTSpell();
       
  2334                     stringBeforeLength = stringBefore.Length();
       
  2335                     for ( TInt j = 0; j < stringBefore.Length(); j++ )
       
  2336                         {
       
  2337                         if ( CheckSpellingDLT( stringBefore.Mid( j )))
       
  2338                             {
       
  2339                             dltBeforeCount++;
       
  2340                             }
       
  2341                         }
       
  2342                     
       
  2343                     // Append the key.
       
  2344                     ptiengine->AppendKeyPress(( TPtiKey )keyCode ).Length();
       
  2345                     
       
  2346                     // Get the dlt count after appending the key.
       
  2347                     TPtrC stringAfter = getCurrentLeastDLTSpell();
       
  2348                     stringAfterLength = stringAfter.Length();
       
  2349                     for ( TInt k = 0; k < stringAfter.Length(); k++ )
       
  2350                         {
       
  2351                         if ( CheckSpellingDLT( stringAfter.Mid( k )))
       
  2352                             {
       
  2353                             dltAfterCount++;
       
  2354                             }
       
  2355                         }
       
  2356                     
       
  2357                     // If the spell length is the same and the dlt count is 
       
  2358                     // the same, the keystroke is invalid
       
  2359                     if (( stringBeforeLength == stringAfterLength ) && 
       
  2360                         ( dltAfterCount == dltBeforeCount ))
  2114                         {
  2361                         {
  2115                         ClearPtiEngineKeystroke();
  2362                         ClearPtiEngineKeystroke();
  2116                         valid = EFalse;
  2363                         valid = EFalse;
  2117                         }
  2364                         }
  2118                     }
  2365                     }
  2121         if ( ( showKeystroke->Count() == i + 1 ) && ( !valid ) )
  2368         if ( ( showKeystroke->Count() == i + 1 ) && ( !valid ) )
  2122             {
  2369             {
  2123             editPane->SetHighlight(
  2370             editPane->SetHighlight(
  2124                                 phraseCount + index, 
  2371                                 phraseCount + index, 
  2125                                 phraseCount + index + count - 1 );
  2372                                 phraseCount + index + count - 1 );
       
  2373 
       
  2374             if ( iPlugin.IsEnable())
       
  2375                 {
       
  2376                 iPlugin.CanConvertAll( EFalse );
       
  2377                 iPlugin.ConvertCount( index );
       
  2378                 }
       
  2379 
  2126             ClearPtiEngineKeystroke();
  2380             ClearPtiEngineKeystroke();
  2127             }
  2381             }
  2128         }
  2382         }
  2129     }
  2383     }
  2130 
  2384 
  2176     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
  2430     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
  2177     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
  2431     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
  2178     CDesCArrayFlat* showKeyStoke = editPane->ShowKeystrokeArray();
  2432     CDesCArrayFlat* showKeyStoke = editPane->ShowKeystrokeArray();
  2179     TInt showKeyStokeCount = editPane->ShowKeystrokeArray()->Count();
  2433     TInt showKeyStokeCount = editPane->ShowKeystrokeArray()->Count();
  2180     TInt indexOfKeystroke = editPane->GetCursorIndexOfKeystroke();
  2434     TInt indexOfKeystroke = editPane->GetCursorIndexOfKeystroke();
  2181     TInt cursorPos = editPane->GetCursor() - editPane->PhraseArray()->Count();
  2435     
  2182 
  2436     TInt cursorPos = 0;
       
  2437     // Get the current core id
       
  2438     TInt coreID = 0;
       
  2439     TRAP_IGNORE( coreID = iOwner->PtiEngine()->HandleCommandL( EPtiCommandGetCoreID ));
       
  2440     TInt phraseCount = 0;
       
  2441     
       
  2442     // For Sogou core, maybe on element of PhraseArray() contains two or 
       
  2443     // more characters.
       
  2444     if ( TUid::Uid( coreID ) == KPtiSogouCoreUid )
       
  2445         {
       
  2446         for ( TInt l = 0; l < editPane->PhraseArray()->Count(); l++ )
       
  2447             {
       
  2448             phraseCount += editPane->PhraseArray()->MdcaPoint( l ).Length();
       
  2449             }
       
  2450         cursorPos = editPane->GetCursor() - phraseCount;
       
  2451         }
       
  2452     else
       
  2453         {
       
  2454         cursorPos = editPane->GetCursor() - editPane->PhraseArray()->Count();
       
  2455         }
       
  2456     
  2183     TBuf<1> autoDLT;
  2457     TBuf<1> autoDLT;
  2184     autoDLT.Append(KAutoDLT);
  2458     autoDLT.Append(KAutoDLT);
  2185     const TInt offset = 2;
  2459     const TInt offset = 2;
  2186     if (cursorPos <= 0)
  2460     if (cursorPos <= 0)
  2187         {
  2461         {
  2231     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
  2505     MAknFepUICtrlContainerChinese* uiContainer = UIContainer();
  2232     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
  2506     MAknFepUICtrlEditPane* editPane = uiContainer->EditPaneWindow();
  2233     CDesCArrayFlat* showKeyStoke = editPane->ShowKeystrokeArray();
  2507     CDesCArrayFlat* showKeyStoke = editPane->ShowKeystrokeArray();
  2234     TInt showKeyStokeCount = editPane->ShowKeystrokeArray()->Count();
  2508     TInt showKeyStokeCount = editPane->ShowKeystrokeArray()->Count();
  2235     TInt indexOfKeystroke = editPane->GetCursorIndexOfKeystroke();
  2509     TInt indexOfKeystroke = editPane->GetCursorIndexOfKeystroke();
  2236     TInt cursorPos = editPane->GetCursor() - editPane->PhraseArray()->Count();
  2510      
       
  2511     TInt cursorPos = 0;
       
  2512     // Get the current core id
       
  2513     TInt coreID = 0;
       
  2514     TRAP_IGNORE( coreID = iOwner->PtiEngine()->HandleCommandL( EPtiCommandGetCoreID ));
       
  2515     TInt phraseCount = 0;
       
  2516     
       
  2517     // For Sogou core, maybe on element of PhraseArray() contains two or 
       
  2518     // more characters.
       
  2519     if ( TUid::Uid( coreID ) == KPtiSogouCoreUid )
       
  2520         {
       
  2521         for ( TInt l = 0; l < editPane->PhraseArray()->Count(); l++ )
       
  2522             {
       
  2523             phraseCount += editPane->PhraseArray()->MdcaPoint( l ).Length();
       
  2524             }
       
  2525         cursorPos = editPane->GetCursor() - phraseCount;
       
  2526         }
       
  2527     else
       
  2528         {
       
  2529         cursorPos = editPane->GetCursor() - editPane->PhraseArray()->Count();
       
  2530         }
       
  2531     
  2237     TBuf<1> autoDLT;
  2532     TBuf<1> autoDLT;
  2238     autoDLT.Append(KAutoDLT);
  2533     autoDLT.Append(KAutoDLT);
  2239     const TInt offset = 2;
  2534     const TInt offset = 2;
  2240 
  2535 
  2241     if (cursorPos <= 0)
  2536     if (cursorPos <= 0)
  2482 // ---------------------------------------------------------
  2777 // ---------------------------------------------------------
  2483 //
  2778 //
  2484 void TAknFepInputMiniQwertyPinyinPhraseBase::HandleKeyFromCandidateL(
  2779 void TAknFepInputMiniQwertyPinyinPhraseBase::HandleKeyFromCandidateL(
  2485     TInt aKey, TKeyPressLength /*aLength*/)
  2780     TInt aKey, TKeyPressLength /*aLength*/)
  2486     {
  2781     {
  2487     TInt index = 0;
       
  2488 #ifdef RD_INTELLIGENT_TEXT_INPUT
  2782 #ifdef RD_INTELLIGENT_TEXT_INPUT
  2489     // it may be one of the 'valid' numbers..
  2783     // it may be one of the 'valid' numbers..
  2490     TPtiKeyboardType keyboardtype = iOwner->FepMan()->KeyboardLayout();
  2784     TPtiKeyboardType keyboardtype = iOwner->FepMan()->KeyboardLayout();
  2491     if (EPtiKeyboardQwerty4x10 == keyboardtype || EPtiKeyboardQwerty3x11
  2785     if (EPtiKeyboardQwerty4x10 == keyboardtype || EPtiKeyboardQwerty3x11
  2492             == keyboardtype || EPtiKeyboardHalfQwerty == keyboardtype
  2786             == keyboardtype || EPtiKeyboardHalfQwerty == keyboardtype
  2510                 TPtiNumericKeyBinding numKeyBind =
  2804                 TPtiNumericKeyBinding numKeyBind =
  2511                         keybinding[numericKeysCount];
  2805                         keybinding[numericKeysCount];
  2512                 if ( (numKeyBind.iChar >= 0x31 && numKeyBind.iChar <= 0x36)
  2806                 if ( (numKeyBind.iChar >= 0x31 && numKeyBind.iChar <= 0x36)
  2513                         &&(aKey == numKeyBind.iKey))
  2807                         &&(aKey == numKeyBind.iKey))
  2514                     {
  2808                     {
  2515                     index = numKeyBind.iChar - EPtiKey0 -1;
       
  2516                     validnumkey = ETrue;
  2809                     validnumkey = ETrue;
  2517                     break;
  2810                     break;
  2518                     }
  2811                     }
  2519                 }
  2812                 }
  2520             }
  2813             }
  2524             {
  2817             {
  2525             iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
  2818             iOwner->FepMan()->PlaySound(EAvkonSIDErrorTone);
  2526             return;
  2819             return;
  2527             }
  2820             }
  2528         }
  2821         }
  2529     else
       
  2530         {
       
  2531 #endif
       
  2532         index = MapKeyToIndex(aKey);
       
  2533 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
  2534         }
       
  2535 #endif
  2822 #endif
  2536     MAknFepUICtrlCandidatePane* candidatePane = UIContainer()->CandidatePane();
  2823     MAknFepUICtrlCandidatePane* candidatePane = UIContainer()->CandidatePane();
  2537 
  2824 
  2538     if (candidatePane->SelectIndex(index) || aKey == EStdKeyDevice3 || aKey
  2825     if ( aKey == EStdKeyDevice3 || aKey
  2539             == EStdKeyEnter)
  2826             == EStdKeyEnter)
  2540         {
  2827         {
  2541         TPtrC text = candidatePane->CurrentPhraseCandidate();
  2828         TPtrC text = candidatePane->CurrentPhraseCandidate();
  2542         if (text.Length() )
  2829         if (text.Length() )
  2543             {
  2830             {
  2630                     && (KInvalidToneMark != ToneMark(keystroke->MdcaPoint( i - 1 ) ) ) )
  2917                     && (KInvalidToneMark != ToneMark(keystroke->MdcaPoint( i - 1 ) ) ) )
  2631                 {
  2918                 {
  2632                 return EFalse;
  2919                 return EFalse;
  2633                 }
  2920                 }
  2634             GetKeystrokeCode(keyCode, keystroke->MdcaPoint(i) );
  2921             GetKeystrokeCode(keyCode, keystroke->MdcaPoint(i) );
  2635             stringBeforeLength = getCurrentLeastDLTSpell().Length();
  2922             
  2636             ptiengine->AppendKeyPress((TPtiKey)keyCode).Length();
  2923             // dltBeforeCount is the dlt count before append the key.
  2637             stringAfterLength = getCurrentLeastDLTSpell().Length();
  2924             // dltAfterCount is the dlt count after append the key.
  2638             if ( stringBeforeLength == stringAfterLength )
  2925             // In sogou core, after appending a new key, the spell length
       
  2926             // may be the same, but the dlt count will change.
       
  2927             // In this situation, the appended key is valid.
       
  2928             TInt dltBeforeCount = 0;
       
  2929             TInt dltAfterCount = 0;
       
  2930             TPtrC stringBefore = getCurrentLeastDLTSpell();
       
  2931             stringBeforeLength = stringBefore.Length();
       
  2932             for ( TInt k = 0; k < stringBefore.Length(); k++ )
       
  2933                 {
       
  2934                 if ( CheckSpellingDLT( stringBefore.Mid( k )))
       
  2935                     {
       
  2936                     dltBeforeCount++;
       
  2937                     }
       
  2938                 }
       
  2939 
       
  2940             // Append the key.
       
  2941             ptiengine->AppendKeyPress(( TPtiKey )keyCode );
       
  2942             
       
  2943             // Get the dlt count after appending the key.
       
  2944             TPtrC stringAfter = getCurrentLeastDLTSpell();
       
  2945             stringAfterLength = stringAfter.Length();
       
  2946             for ( TInt l = 0; l < stringAfter.Length(); l++ )
       
  2947                 {
       
  2948                 if ( CheckSpellingDLT( stringAfter.Mid( l )))
       
  2949                     {
       
  2950                     dltAfterCount++;
       
  2951                     }
       
  2952                 }
       
  2953             
       
  2954             // If the spell length is the same and the dlt count is 
       
  2955             // the same, the keystroke is invalid
       
  2956             if (( stringBeforeLength == stringAfterLength ) && 
       
  2957                 ( dltAfterCount == dltBeforeCount ))
  2639                 {
  2958                 {
  2640                 return EFalse;
  2959                 return EFalse;
  2641                 }
  2960                 }
  2642             }
  2961             }
  2643         }
  2962         }
  2688             errnote->SetTone(CAknNoteDialog::EWarningTone);
  3007             errnote->SetTone(CAknNoteDialog::EWarningTone);
  2689             errnote->ExecuteLD(KMaxPhraseNote);
  3008             errnote->ExecuteLD(KMaxPhraseNote);
  2690             }
  3009             }
  2691         else
  3010         else
  2692             {
  3011             {
       
  3012             // For sogou core, the predictive is not endless, so when there
       
  3013             // is no predictive candidates, we should call TryCloseUiL().
       
  3014             TBool noCandidates = EFalse;
       
  3015             
       
  3016             TInt coreID = iOwner->PtiEngine()->HandleCommandL( EPtiCommandGetCoreID );
       
  3017             if ( TUid::Uid( coreID ) == KPtiSogouCoreUid )
       
  3018                 {
       
  3019                 // Get the predictive candidates.
       
  3020                 CDesCArrayFlat* phraseCandidates = new(ELeave) CDesCArrayFlat( 1 );
       
  3021                 CleanupStack::PushL ( phraseCandidates );
       
  3022                 phraseCandidates->Reset();
       
  3023                 iOwner->PtiEngine()->GetChinesePhraseCandidatesL( *phraseCandidates );
       
  3024                 if ( phraseCandidates->Count() == 0 )
       
  3025                     {
       
  3026                     noCandidates = ETrue;
       
  3027                     }
       
  3028                 CleanupStack::PopAndDestroy( phraseCandidates );
       
  3029                 }
       
  3030         
  2693             UIContainer()->EditPaneWindow()->ResetAllArray();
  3031             UIContainer()->EditPaneWindow()->ResetAllArray();
  2694             if ( !UIContainer()->EditPaneWindow()->GetPhraseCreationFlag() )
  3032             if ( !UIContainer()->EditPaneWindow()->GetPhraseCreationFlag() && !noCandidates )
  2695                 {
  3033                 {
  2696                 UIContainer()->EditPaneWindow()->SetPhraseCreationFlag(EFalse);
  3034                 UIContainer()->EditPaneWindow()->SetPhraseCreationFlag(EFalse);
  2697                 UIContainer()->EditPaneWindow()->SetChangeState(ETrue);
  3035                 UIContainer()->EditPaneWindow()->SetChangeState(ETrue);
  2698                 iOwner->ChangeState(EPredictiveCandidate);
  3036                 iOwner->ChangeState(EPredictiveCandidate);
  2699                 }
  3037                 }