fep/aknfep/src/AknFepUiInputStateEntryWesternPredictive.cpp
changeset 40 2cb9bae34d17
parent 31 f1bdd6b078d1
child 49 37f5d84451bd
equal deleted inserted replaced
31:f1bdd6b078d1 40:2cb9bae34d17
     1 /*
       
     2 * Copyright (c) 2002-2004 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 TAknFepInputStateEntryWesternPredictive methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 
       
    30 #include "AknFepUiInputStateEntryWesternPredictive.h"
       
    31 #include "AknFepUIManagerStateInterface.h"      //MAknFepUIManagerStateInterface
       
    32 #include "AknFepManagerUIInterface.h"           //MAknFepManagerUIInterface
       
    33 #include "AknFepManager.h"
       
    34 #include "AknFepPanic.h"
       
    35 #include "AknFepCaseManager.h"
       
    36 #include "AknFepPluginManager.h"
       
    37 #include "AknFepManagerInterface.h" // MAknFepManagerInterface
       
    38 
       
    39 #include <aknedsts.h> 
       
    40 #include <PtiEngine.h>                             //CPtiEngine
       
    41 #include <PtiDefs.h>                            //keys
       
    42 #include <featmgr.h>                //FeatureManager
       
    43 #include <e32keys.h>
       
    44 #include <aknfep.rsg>
       
    45 #include <PtiUserDicEntry.h>
       
    46 
       
    47 // The Maximum world size
       
    48 const TInt KMaxWordSize = 63;
       
    49 TAknFepInputStateEntryWesternPredictive::
       
    50 TAknFepInputStateEntryWesternPredictive(MAknFepUIManagerStateInterface* aOwner)
       
    51     :TAknFepInputStateBase(aOwner)
       
    52     {
       
    53     //this class insists on the existence of a case manager
       
    54     __ASSERT_DEBUG(iOwner->CaseMan(), AknFepPanic(EAknFepPanicNoCaseManager));
       
    55     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
    56     iState = EEntry;
       
    57     iMatchState = EWordMatchNone;
       
    58     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
    59 
       
    60     TPtiTextCase caseMode = ptiengine->Case();
       
    61 	ptiengine->SetInputMode(EPtiEnginePredictive);  
       
    62 
       
    63 #ifdef RD_SCALABLE_UI_V2
       
    64 
       
    65     if (fepMan->PluginUIManager()->MatchCandidateList().Count() > 0)
       
    66         {
       
    67         fepMan->PluginUIManager()->ResetCandidateList();
       
    68         }
       
    69     
       
    70         iIsLastWord = EFalse;        
       
    71 /*
       
    72     if (fepMan->PluginUIManager()->GetSpellText())
       
    73         {
       
    74         TBuf<CAknFepManager::EMaximumFepWordLength> textToUncommit;
       
    75         textToUncommit.Zero();
       
    76         textToUncommit.Copy(*fepMan->PluginUIManager()->GetSpellText());
       
    77         ptiengine->SetCurrentWord(textToUncommit); 
       
    78         }
       
    79 */        
       
    80 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
    81     	ptiengine->SetInputMode(EPtiEnginePredictive);  
       
    82         TBool isUnlimitedEditor = EFalse;
       
    83         ptiengine->SetMaxLengthForAutoCompletedCandidates(
       
    84                           fepMan->EditorFreeSpaceForAutoWordCompletion(isUnlimitedEditor ));
       
    85         // To set the input mode
       
    86         if(fepMan->IsAutoCompleteOn())
       
    87         	{
       
    88         	TRAP_IGNORE(ptiengine->HandleCommandL(EPtiCommandEnableAutoCompletion));
       
    89         	}
       
    90         else
       
    91         	{
       
    92         	TRAP_IGNORE(ptiengine->HandleCommandL(EPtiCommandDisableAutoCompletion));
       
    93         	}
       
    94 
       
    95         TPtiKeyboardType keyboard = fepMan->KeyboardLayout();
       
    96     	ptiengine->SetKeyboardType(keyboard);
       
    97 
       
    98     	TBool isNumberCandidateShown = fepMan->IsAdvancedPredictiveNumberCandidateShown();
       
    99     	TRAP_IGNORE(ptiengine->HandleCommandL( EPtiCommandSetNumberCandidateStatus, 
       
   100                  &isNumberCandidateShown ));
       
   101 #endif
       
   102 
       
   103 #else
       
   104 
       
   105     ptiengine->ClearCurrentWord();
       
   106         
       
   107 #ifndef RD_INTELLIGENT_TEXT_INPUT
       
   108 
       
   109     // To set the input mode
       
   110     if(fepMan->IsAutoCompleteOn())
       
   111     	{
       
   112     	   ptiengine->SetInputMode(EPtiEngineWordCompletion);
       
   113     	}
       
   114 #endif // RD_PRED_AW_COMPLETION
       
   115 #endif //RD_SCALABLE_UI_V2
       
   116     ptiengine->SetCase(caseMode);
       
   117     }
       
   118 
       
   119 TBool TAknFepInputStateEntryWesternPredictive::HandleKeyL(TInt aKey, TKeyPressLength aLength)
       
   120     {
       
   121     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   122     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   123 
       
   124 #ifdef RD_SCALABLE_UI_V2
       
   125 
       
   126     if (fepMan->PluginUIManager()->GetSpellText())
       
   127         {
       
   128         fepMan->PluginUIManager()->SpellText(NULL);
       
   129         }    
       
   130 #endif //
       
   131 
       
   132     TBool response = ETrue;
       
   133 
       
   134     switch (aKey)
       
   135         {
       
   136     case EPtiKey1: //fall through
       
   137     case EPtiKey2:
       
   138     case EPtiKey3:
       
   139     case EPtiKey4:
       
   140     case EPtiKey5:
       
   141     case EPtiKey6:
       
   142     case EPtiKey7:
       
   143     case EPtiKey8:
       
   144     case EPtiKey9:
       
   145 #ifdef RD_SCALABLE_UI_V2
       
   146         fepMan->PluginUIManager()->SetFingerMatchSelectionState(EFalse);    
       
   147 #endif //RD_SCALABLE_UI_V2
       
   148         
       
   149         response = HandleStandardNumericKeysL(aKey, aLength);
       
   150         break;
       
   151     case EPtiKey0:
       
   152         if ( fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction) )
       
   153             {
       
   154             fepMan->TryRemoveNoMatchesIndicatorL();
       
   155 #ifndef RD_INTELLIGENT_TEXT_INPUT
       
   156  	    			// To rip off suggested word completion when user presses SPACE
       
   157 				if(fepMan->IsAutoCompleteOn())
       
   158 					{
       
   159 					fepMan->RemoveSuggestedCompletionL();
       
   160 					}
       
   161 #endif
       
   162             }
       
   163         fepMan->UpdateCbaL(NULL);
       
   164         if (fepMan->IsFlagSet(CAknFepManager::EFlagCompoundWord))
       
   165             { 
       
   166             if (fepMan->IsCursorAtEndOfWord())
       
   167                 {
       
   168                 fepMan->AddCompoundWordToUdbL();                
       
   169                 }
       
   170             fepMan->ClearFlag(CAknFepManager::EFlagCompoundWord);
       
   171             }		            
       
   172 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   173         if ( fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction) )
       
   174             {
       
   175             ptiengine->CommitCurrentWord();
       
   176 			fepMan->CommitInlineEditL();
       
   177             fepMan->TryCloseUiL();
       
   178             response = EFalse;
       
   179             }
       
   180         else
       
   181         	{
       
   182 #endif
       
   183 		fepMan->SetDelayedCommit(); // Delayed 'commit'. 				                                        	
       
   184 	    fepMan->TryCloseUiL();	                                
       
   185         response = EFalse;  //pass to initial state to handle key
       
   186 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   187         	}
       
   188 #endif        	
       
   189 #ifdef RD_SCALABLE_UI_V2
       
   190         fepMan->PluginUIManager()->SetFingerMatchSelectionState(EFalse);    
       
   191 #endif //RD_SCALABLE_UI_V2
       
   192         break;
       
   193     case EKeyLeftArrow: // fall through
       
   194     case EKeyRightArrow:
       
   195     case EKeyBackspace:
       
   196         response = HandleNaviKeysL(aKey, aLength);
       
   197 #ifdef RD_SCALABLE_UI_V2
       
   198         fepMan->PluginUIManager()->SetFingerMatchSelectionState(EFalse);    
       
   199 #endif //RD_SCALABLE_UI_V2
       
   200         break;
       
   201     case EPtiKeyStar:
       
   202             {
       
   203             response = HandleStarKeyL(aLength);    
       
   204             }
       
   205         break;
       
   206     case EKeyDownArrow: // Japanese input required
       
   207         if (fepMan->IsAbleScrollLatinPredictive())
       
   208             {
       
   209             if (fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction))
       
   210                 {
       
   211                 DoNextMatch();
       
   212                 }
       
   213             else
       
   214                 {
       
   215                 response = EFalse;
       
   216                 }
       
   217             }
       
   218         else
       
   219             {
       
   220             response = EFalse;
       
   221             }
       
   222         break;
       
   223     case EKeyUpArrow: // Japanese input required
       
   224         if (fepMan->IsAbleScrollLatinPredictive())
       
   225             {
       
   226             if (fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction))
       
   227                 {
       
   228                 DoPreviousMatchL();
       
   229                 }
       
   230             else
       
   231                 {
       
   232                 response = EFalse;
       
   233                 }
       
   234             }
       
   235         else
       
   236             {
       
   237             response = EFalse;
       
   238             }
       
   239         break;
       
   240     default:
       
   241         response = EFalse;
       
   242 #ifdef RD_SCALABLE_UI_V2
       
   243         fepMan->PluginUIManager()->SetFingerMatchSelectionState(EFalse);            
       
   244 #endif //RD_SCALABLE_UI_V2
       
   245         break;
       
   246         }
       
   247     return response;
       
   248     }
       
   249 
       
   250 void TAknFepInputStateEntryWesternPredictive::HandleCommandL(TInt aCommandId)
       
   251     {
       
   252     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();    
       
   253     if (aCommandId == EAknFepSoftkeyPrevious)
       
   254         {
       
   255         CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   256         
       
   257         __ASSERT_DEBUG(fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction), 
       
   258                        AknFepPanic(EAknFepPanicNotInsideInlineEdit));   
       
   259 
       
   260         if (iMatchState == EWordMatchLast || iMatchState == EWordMatchAfterLast)
       
   261             {
       
   262             fepMan->UpdateCbaL(R_AKNFEP_SOFTKEYS_EMPTY_PREVIOUS);
       
   263             }
       
   264         iMatchState = EWordMatchStd; 
       
   265         TPtrC prevText = ptiengine->PreviousCandidate();
       
   266         if(prevText.Length() == 1)
       
   267    			{
       
   268         	TDigitType digittype = fepMan->LocalDigit();
       
   269             TChar chchar(prevText[0]);
       
   270             if(!chchar.IsDigit() || (chchar.IsDigit() && !digittype))
       
   271             	{ 	
       
   272             	fepMan->UpdateInlineEditL(prevText, prevText.Length());    
       
   273             	}
       
   274             else 
       
   275             	{
       
   276             	TBuf<1> tempbuf;
       
   277 	            tempbuf.Append(prevText[0]);
       
   278             	ConvertDigitToDigittype(digittype,tempbuf);
       
   279                 fepMan->UpdateInlineEditL(tempbuf, tempbuf.Length());	
       
   280             	}
       
   281    			}
       
   282    		else 
       
   283    			{        
       
   284 			fepMan->UpdateInlineEditL(prevText, prevText.Length());
       
   285    			}
       
   286         }
       
   287     else if (aCommandId == ESignalSelectMatchSelectionText)
       
   288         {
       
   289         //fepMan->UpdateCbaL(R_AKNFEP_SOFTKEYS_FINGER);
       
   290 #ifdef RD_SCALABLE_UI_V2
       
   291         fepMan->PluginUIManager()->SetFingerMatchSelectionState(EFalse);
       
   292 #endif //RD_SCALABLE_UI_V2
       
   293         iOwner->ChangeState(EInitial);
       
   294         }
       
   295     else if (aCommandId == ESignalNaviLeftMatchSelectionText)
       
   296         {
       
   297         //fepMan->UpdateCbaL(R_AKNFEP_SOFTKEYS_FINGER);
       
   298 #ifdef RD_SCALABLE_UI_V2
       
   299         fepMan->PluginUIManager()->SetFingerMatchSelectionState(EFalse);
       
   300 #endif //RD_SCALABLE_UI_V2
       
   301         iOwner->ChangeState(EEntry);
       
   302 
       
   303         TRawEvent event;
       
   304         event.Set(TRawEvent::EKeyDown, EStdKeyLeftArrow);
       
   305         CCoeEnv::Static()->WsSession().SimulateRawEvent(event);
       
   306         
       
   307         event.Set(TRawEvent::EKeyUp, EStdKeyLeftArrow);
       
   308         CCoeEnv::Static()->WsSession().SimulateRawEvent(event);
       
   309         }
       
   310     else if (aCommandId == ESignalNaviRightMatchSelectionText)
       
   311         {
       
   312         //fepMan->UpdateCbaL(R_AKNFEP_SOFTKEYS_FINGER);
       
   313 #ifdef RD_SCALABLE_UI_V2
       
   314         fepMan->PluginUIManager()->SetFingerMatchSelectionState(EFalse);
       
   315 #endif //RD_SCALABLE_UI_V2
       
   316         iOwner->ChangeState(EEntry);
       
   317 
       
   318         TRawEvent event;
       
   319         event.Set(TRawEvent::EKeyDown, EStdKeyRightArrow);
       
   320         CCoeEnv::Static()->WsSession().SimulateRawEvent(event);
       
   321         
       
   322         event.Set(TRawEvent::EKeyUp, EStdKeyRightArrow);
       
   323         CCoeEnv::Static()->WsSession().SimulateRawEvent(event);
       
   324         }        
       
   325     }
       
   326 
       
   327 TBool TAknFepInputStateEntryWesternPredictive::HandleStandardNumericKeysL(TInt aKey, 
       
   328                                                                           TKeyPressLength aLength)
       
   329     {
       
   330     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   331     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   332 
       
   333     TBool response = ETrue;
       
   334 
       
   335     if (aLength == ELongKeyPress)
       
   336         {
       
   337         if (!fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction))
       
   338         	{
       
   339         	// No edit transaction going on, we have ended here because of long
       
   340         	// key press created editor on UI or some other similar non-standard situation.
       
   341         	// We can't handle key press, so just consume it.
       
   342         	return ETrue;	
       
   343         	}
       
   344                         
       
   345         // try and insert a digit
       
   346         if (!fepMan->TryRemoveNoMatchesIndicatorL())
       
   347             { 
       
   348             // remove last character
       
   349             TPtrC newText = ptiengine->DeleteKeyPress();
       
   350 #ifndef RD_INTELLIGENT_TEXT_INPUT
       
   351             if(ptiengine->InputMode() == EPtiEngineWordCompletion 
       
   352            && (newText.Length() > ptiengine->CurrentInputSequence().Length()))
       
   353             	{
       
   354             	    	fepMan->RemoveSuggestedCompletionL();
       
   355             	}
       
   356        		else
       
   357 #endif
       
   358 	       		{
       
   359             fepMan->UpdateInlineEditL(newText, newText.Length());
       
   360 	            }
       
   361             }
       
   362         //closing the UI will commit the current word and move to intial state
       
   363         fepMan->TryCloseUiL();
       
   364         //this flag to ensures that initial state does not send us back 
       
   365         //to this state as it would normally do for numeric keys
       
   366         fepMan->SetFlag(CAknFepManager::EFlagSuppressInputStateChange);
       
   367         response = EFalse;
       
   368         }
       
   369     else  // short keypress 
       
   370         {
       
   371         //To restrict up to 32 character..
       
   372         
       
   373         if(ptiengine->CurrentInputSequence().Length() >= KMaxWordSize)
       
   374         	{
       
   375             fepMan->SetFlag(CAknFepManager::EFlagNoMatches);
       
   376             
       
   377             // Enter word reach to max inline edit state
       
   378             // if we call upadte inline edit, it will insert '?' mark
       
   379             // which would be the 64th/33rd character
       
   380            
       
   381             // Not need to call appedkeypress/ updateinlineedit
       
   382             // ignore the current key press
       
   383             
       
   384             //fepMan->UpdateCbaL(R_AKNFEP_SOFTKEYS_SPELL_EMPTY);
       
   385             //TPtrC newText = ptiengine->CurrentWord();
       
   386 			//fepMan->UpdateInlineEditL(newText, newText.Length());
       
   387             }
       
   388         if (fepMan->IsFlagSet(CAknFepManager::EFlagNoMatches))
       
   389             {
       
   390             //no matches, so just play tone
       
   391             fepMan->PlaySound(EAvkonSIDConfirmationTone);
       
   392             }           
       
   393         else //insert a letter
       
   394             {
       
   395             fepMan->SetCcpuFlag(CAknFepManager::ECcpuStateIgnoreStarUp |
       
   396                                 CAknFepManager::ECcpuStateNewPredictiveWord);
       
   397             if (iMatchState == EWordMatchLast || iMatchState == EWordMatchAfterLast)
       
   398                 {
       
   399                 iMatchState = EWordMatchNone;
       
   400                 }
       
   401             if (!(fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction)))
       
   402                 { // 'new' inline edit
       
   403                 ptiengine->ClearCurrentWord();
       
   404                 fepMan->StartInlineEditL();
       
   405                 fepMan->TryStartCompoundWord();
       
   406                 }
       
   407 #ifndef RD_INTELLIGENT_TEXT_INPUT
       
   408   			TInt prevSeqLength = ptiengine->CurrentInputSequence().Length();
       
   409 #endif 
       
   410             TPtrC newText = ptiengine->AppendKeyPress((TPtiKey)aKey);
       
   411 
       
   412  			fepMan->ClearFlag(CAknFepManager::EFlagRemoveMatchesMenuItem);   
       
   413  			
       
   414 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   415  			if (ptiengine->NumberOfCandidates() > 0)
       
   416 #else
       
   417            if ((fepMan->IsMoreGoodWordsComing(newText.Length())
       
   418 #ifndef RD_INTELLIGENT_TEXT_INPUT
       
   419 				&& (ptiengine->InputMode() != EPtiEngineWordCompletion))
       
   420                 || fepMan->IsMoreGoodAutoCompleteWordsComing(ptiengine->InputMode(), 
       
   421                 										  prevSeqLength, ptiengine->CurrentInputSequence().Length()
       
   422 #endif
       
   423 		))
       
   424 #endif
       
   425                 {
       
   426                 // more good words coming in from predictive text engine so carry on
       
   427                 if(newText.Length() == 1)
       
   428            			{
       
   429 	            	TDigitType digittype = fepMan->LocalDigit();
       
   430 	                TChar chchar(newText[0]);
       
   431 	                if(!chchar.IsDigit() || (chchar.IsDigit() && !digittype))
       
   432 	                	{ 	
       
   433 	                	fepMan->UpdateInlineEditL(newText, newText.Length());    
       
   434     	            	}
       
   435 	                else 
       
   436 	                	{
       
   437 	                	TBuf<1> tempbuf;
       
   438 	                	tempbuf.Append(newText[0]);
       
   439 		            	ConvertDigitToDigittype(digittype,tempbuf);
       
   440 		                fepMan->UpdateInlineEditL(tempbuf, tempbuf.Length());				                	
       
   441 	                	}
       
   442            			}
       
   443            		else 
       
   444            			{
       
   445            			fepMan->UpdateInlineEditL(newText, newText.Length());	
       
   446            			}
       
   447            			
       
   448                 TBool lastEnteredDigitOne = (ptiengine->LastEnteredKey() == EPtiKey1);
       
   449                 if (!lastEnteredDigitOne)
       
   450                     {
       
   451                     iOwner->CaseMan()->UpdateCase(ENullNaviEvent);
       
   452                     }
       
   453                 fepMan->ClearFlag(CAknFepManager::EFlagRemoveMatchesMenuItem);
       
   454 				if (ptiengine->NumberOfCandidates() <= 1)                    
       
   455 					{
       
   456 	                fepMan->SetFlag(CAknFepManager::EFlagRemoveMatchesMenuItem);                					
       
   457 					}
       
   458                 }
       
   459             else 
       
   460                 {
       
   461                 // engine has run out of matches
       
   462                 fepMan->SetFlag(CAknFepManager::EFlagRemoveMatchesMenuItem);                
       
   463                 fepMan->SetFlag(CAknFepManager::EFlagNoMatches);
       
   464                 fepMan->UpdateCbaL(R_AKNFEP_SOFTKEYS_SPELL_EMPTY);
       
   465                 if(newText.Length() == 1)
       
   466            			{
       
   467 	            	TDigitType digittype = fepMan->LocalDigit();
       
   468 	                TChar chchar(newText[0]);
       
   469 	                if(!chchar.IsDigit() || (chchar.IsDigit() && !digittype))
       
   470 	                	{ 	
       
   471 	                	fepMan->UpdateInlineEditL(newText, newText.Length());    
       
   472     	            	}
       
   473 	                else 
       
   474 	                	{
       
   475 	                	TBuf<1> tempbuf;
       
   476 	                	tempbuf.Append(newText[0]);
       
   477 		            	ConvertDigitToDigittype(digittype,tempbuf);
       
   478 		                fepMan->UpdateInlineEditL(tempbuf, tempbuf.Length());					                	
       
   479 	                	}
       
   480            			}
       
   481            		else 
       
   482            			{
       
   483 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   484            			// Remove the autocompletion tail if present
       
   485                     if (fepMan->IsAutoCompleteOn())
       
   486                         {
       
   487                         TInt tailLength = 0;
       
   488                         ptiengine->HandleCommandL( EPtiCommandGetAutoCompletionTailLength, 
       
   489                                                   &tailLength );
       
   490                         if(tailLength > 0)
       
   491                             {
       
   492                             // To remove the autocompletion part, the below function is used. 
       
   493                             // DeleteKeyPress was used earlier. This is removed to fix the bug :
       
   494                             // enter characters to show autocompletion part. Now press a 
       
   495                             // character so that the no matches character is shown. Now press
       
   496                             // backspace key, last character is not deleted.
       
   497                             fepMan->RemoveSuggestedAdvanceCompletionL();
       
   498                             fepMan->PlaySound(EAvkonSIDConfirmationTone);
       
   499                             return response;
       
   500                             }
       
   501                         }
       
   502 #endif
       
   503            			fepMan->UpdateInlineEditL(newText, newText.Length());	
       
   504            			}
       
   505                 fepMan->PlaySound(EAvkonSIDConfirmationTone);
       
   506                 }
       
   507             }
       
   508         }
       
   509     return response;
       
   510     }
       
   511 
       
   512 TBool TAknFepInputStateEntryWesternPredictive::HandleNaviKeysL(TInt aKey, TKeyPressLength /*aLength*/)
       
   513     {
       
   514     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   515     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   516 
       
   517     if (!(fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction)))
       
   518         {
       
   519         TBuf<CAknFepManager::EMaximumFepWordLength> textToUncommit;
       
   520         TBool comsumeKey;
       
   521         if (!(fepMan->TryGetTextToUncommitL(textToUncommit, aKey, comsumeKey)))
       
   522             {
       
   523             // If T9 word length > 32, the navi key is consumed without action.
       
   524             // Maybe should navigate inside word.
       
   525             return comsumeKey;
       
   526             }
       
   527 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   528         ptiengine->ClearCurrentWord(); // Clear the buffer or setting input may fail
       
   529 #endif
       
   530         ptiengine->SetCurrentWord(textToUncommit);
       
   531         if( ptiengine->CurrentWord().Length() != textToUncommit.Length())
       
   532         	{
       
   533         	TPtiUserDictionaryEntry newUdbEntry(textToUncommit);
       
   534         	ptiengine->AddUserDictionaryEntry(newUdbEntry);
       
   535         	ptiengine->SetCurrentWord(textToUncommit);
       
   536         	}
       
   537 
       
   538 #ifdef   __ITI_VIRTUAL_TOUCH_FIRST_GENERATION_SUPPORT__ 
       
   539 		// First generation ITUT support loops through candidate list on star key press. When we bring
       
   540 		// a word in inline edit by navigating with arrow keys, we need to fetch the candidate list in order
       
   541 		// to navigate through the predictive list if any or get spell CBA.
       
   542         CDesCArrayFlat* matchesList=new(ELeave)CDesCArrayFlat(1);
       
   543         CleanupStack::PushL(matchesList);
       
   544         ptiengine->GetCandidateListL(*matchesList);
       
   545         CleanupStack::PopAndDestroy();//matchesList
       
   546 #endif        
       
   547         	
       
   548 		fepMan->ClearFlag(CAknFepManager::EFlagRemoveMatchesMenuItem);           
       
   549         if (ptiengine->NumberOfCandidates() <= 1)
       
   550         	{
       
   551 			fepMan->SetFlag(CAknFepManager::EFlagRemoveMatchesMenuItem);           	
       
   552         	}        
       
   553         if (ptiengine->NumberOfCandidates() < 1)
       
   554         	{
       
   555             fepMan->SetFlag(CAknFepManager::EFlagNoMatches);
       
   556             fepMan->UpdateCbaL(R_AKNFEP_SOFTKEYS_SPELL_EMPTY);           	
       
   557         	}
       
   558 			
       
   559         fepMan->StartInlineEditL(fepMan->UncommittedText(), textToUncommit, 
       
   560                                  textToUncommit.Length(), EFalse);
       
   561         }
       
   562     
       
   563     if (aKey == EKeyBackspace)
       
   564         {
       
   565         if (fepMan->IsFlagSet(CAknFepManager::EFlagNoMatches))
       
   566             {
       
   567             fepMan->TryRemoveNoMatchesIndicatorL();
       
   568             fepMan->UpdateCbaL(NULL);
       
   569 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   570             ptiengine->HandleCommandL(EPtiCommandSetFlagToUpdateCandidates);
       
   571 #endif //RD_INTELLIGENT_TEXT_INPUT
       
   572             // Need to return as DeleteKeyPress should not be passed to ptiengine.
       
   573             // This is because ptiengine does not maintain the input sequence
       
   574             // if the key press does not increase the word length. So when no matches
       
   575             // character is (?) is deleted, no need to pass to ptiengine. This is to done
       
   576             // to solve the bug :enter characters till the no matches character is shown. Now press
       
   577             // backspace, last character is not deleted.
       
   578             return ETrue;
       
   579             }
       
   580         else if (iMatchState != EWordMatchFirst)
       
   581             {
       
   582             //let FirstWordInSelectionList() reset the CBA
       
   583             iMatchState = EWordMatchNone;
       
   584             }
       
   585         
       
   586         TPtrC newText = ptiengine->DeleteKeyPress();
       
   587 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   588         TPtiEngineInputMode inputMode = ptiengine->InputMode();
       
   589         if((inputMode != EPtiEngineWordCompletion && inputMode != EPtiEnginePredictive )
       
   590         	&& newText.Length() != ptiengine->CurrentInputSequence().Length())
       
   591 #else
       
   592         if((ptiengine->InputMode() != EPtiEngineWordCompletion )
       
   593             	&& newText.Length() != ptiengine->CurrentInputSequence().Length())
       
   594 #endif
       
   595         {
       
   596         	TBuf<CAknFepManager::EMaximumFepWordLength> textToUncommit;
       
   597         	TBool comsumeKey;
       
   598         	fepMan->TryGetTextToUncommitL(textToUncommit, aKey, comsumeKey);
       
   599            	textToUncommit.SetLength(textToUncommit.Length() - 1);
       
   600            	ptiengine->SetCurrentWord(textToUncommit);
       
   601            	newText.Set(textToUncommit);
       
   602         }
       
   603         
       
   604 
       
   605 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   606         if (!fepMan->IsAutoCompleteOn())
       
   607             {
       
   608 			// rip-off the autocompletion part if any, do this before updating the editor content
       
   609 			// this is done to avoid any flickering
       
   610     	    TInt tailLength = 0;
       
   611         	ptiengine->HandleCommandL( EPtiCommandGetAutoCompletionTailLength, 
       
   612                                             &tailLength );
       
   613 	        if(tailLength > 0)
       
   614     	        {
       
   615         	    fepMan->RemoveSuggestedAdvanceCompletionL();
       
   616 				// text would have changed after ripping off the autocompletion part
       
   617 	            newText.Set(ptiengine->CurrentWord());
       
   618     	        }
       
   619             }
       
   620 #endif            
       
   621             
       
   622         fepMan->UpdateInlineEditL(newText, newText.Length());                    
       
   623 		fepMan->ClearFlag(CAknFepManager::EFlagRemoveMatchesMenuItem);           
       
   624         if (ptiengine->NumberOfCandidates() <= 1)
       
   625         	{
       
   626 			fepMan->SetFlag(CAknFepManager::EFlagRemoveMatchesMenuItem);           	
       
   627         	}
       
   628 
       
   629         iOwner->CaseMan()->UpdateCase(EBackspaceEvent);
       
   630         fepMan->CloseUiIfWordDeletedL();
       
   631         }
       
   632     return ETrue;
       
   633     }
       
   634 
       
   635 TBool TAknFepInputStateEntryWesternPredictive::HandleStarKeyL(TKeyPressLength aLength)
       
   636     {
       
   637     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   638     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   639 
       
   640     if (aLength == ELongKeyPress)
       
   641         { 
       
   642 // Fix for BSAN-7G5944. 
       
   643 // In non-ITI mode, during long star key press, initially it is treated as short key press 
       
   644 // and the next candidate word is shown. So before displaying the SCT, we revert to
       
   645 // the previous candidate. In ITI, long star key press does not result in showing the next
       
   646 // candidate, as short key press only launches the candidate list.
       
   647 // So reverting to the previous candidate is not needed in ITI mode.        
       
   648 #ifndef RD_INTELLIGENT_TEXT_INPUT        
       
   649         if (fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction))
       
   650             {
       
   651             // replace with previous match
       
   652             fepMan->TryRemoveNoMatchesIndicatorL();
       
   653             iMatchState = EWordMatchStd;
       
   654             TPtrC newText = ptiengine->PreviousCandidate();
       
   655             fepMan->UpdateInlineEditL(newText, newText.Length());
       
   656             }
       
   657 		// to rip off suggested completion when SCT is launched
       
   658 		if(fepMan->IsAutoCompleteOn()) 
       
   659 			{
       
   660 			fepMan->RemoveSuggestedCompletionL();	
       
   661 			}
       
   662 #endif
       
   663             
       
   664        	fepMan->LaunchSpecialCharacterTableL();
       
   665         }
       
   666     else 
       
   667         {
       
   668 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   669 #ifndef FF_ITI_VIRTUAL_TOUCH_FIRST_GENERATION_SUPPORT
       
   670         // Short key presses get filtered in AknFepKeyCatcher, so that short star
       
   671         // key press only gets through when the key is lifted. This means we can
       
   672         // launch the candidate popup without worrying about long keypress
       
   673         if (fepMan->WesternPredictive() && aLength == EShortKeyPress && !fepMan->IsQwerty()
       
   674         	&& fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction)
       
   675         	&& ptiengine->NumberOfCandidates() > 0 
       
   676         	&& fepMan->PluginUIManager()->PluginInputMode() == EPluginInputModeNone )
       
   677         	{
       
   678     		// With short * key press and candidates remaining, override normal behaviour
       
   679         	// and function like arrow down
       
   680         	TInt wordIndexToSelect = 0;
       
   681         	TInt lastCandidateIndex = ptiengine->NumberOfCandidates()-1;
       
   682     		ptiengine->HandleCommandL( EPtiCommandUserActionGetCurrentIndexOfCandidates, 
       
   683 					&wordIndexToSelect );
       
   684     		wordIndexToSelect < lastCandidateIndex ? wordIndexToSelect++ : wordIndexToSelect = 0;
       
   685     		fepMan->LaunchCandidatePopupListL( wordIndexToSelect );
       
   686     		return ETrue;
       
   687         	}
       
   688 #endif // FF_ITI_VIRTUAL_TOUCH_FIRST_GENERATION_SUPPORT  
       
   689 #endif // RD_INTELLIGENT_TEXT_INPUT          
       
   690         if (fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction))
       
   691             {
       
   692 #ifdef RD_SCALABLE_UI_V2
       
   693         	if ( (iIsLastWord || ptiengine->NumberOfCandidates() == 1) 
       
   694        	         && ( fepMan->PluginUIManager()->PluginInputMode() == EPluginInputModeItut ) )
       
   695         	    {
       
   696                 fepMan->PluginUIManager()->SetFingerMatchSelectionState(ETrue);
       
   697         	    fepMan->PluginUIManager()->ShowAllCandidates();
       
   698         	    iMatchState = EWordMatchNone;
       
   699         	    iIsLastWord = EFalse;
       
   700         	    return ETrue;
       
   701         	    }
       
   702             
       
   703 #endif //RD_SCALABLE_UI_V2
       
   704             
       
   705             if (fepMan->IsFlagSet(CAknFepManager::EFlagNoMatches))
       
   706                 {
       
   707                 CAknFepManager* fepMgr = static_cast<CAknFepManager*>(fepMan);
       
   708                 if(( fepMgr->EditorState()->Flags() & EAknEditorFlagEnablePartialScreen ) &&
       
   709                    ( fepMgr->PluginUIManager()->PluginInputMode() == EPluginInputModeItut ))
       
   710                     {
       
   711                     // launch full screen query for split itut
       
   712                     fepMgr->LaunchEditWordQueryL();
       
   713                     }
       
   714                 else
       
   715                     {
       
   716                     //no more matches
       
   717                     fepMan->PlaySound(EAvkonSIDWarningTone);
       
   718                     }
       
   719                 }
       
   720             else if (ptiengine->NumberOfCandidates() <= 1) //1
       
   721                 { 
       
   722                 // only one match
       
   723                 if (iMatchState == EWordMatchFirst || iMatchState == EWordMatchNone)
       
   724                     {
       
   725                     fepMan->UpdateCbaL(R_AKNFEP_SOFTKEYS_SPELL_EMPTY);
       
   726                     iMatchState = EWordMatchLast;
       
   727                     }
       
   728                 }
       
   729             else
       
   730                 {
       
   731                 if (iMatchState == EWordMatchLast && !(ptiengine->LastEnteredKey() == EPtiKey1))
       
   732                     {
       
   733                     fepMan->UpdateCbaL(R_AKNFEP_SOFTKEYS_SPELL_PREVIOUS);
       
   734                     }
       
   735                 else if (iMatchState == EWordMatchFirst || iMatchState == EWordMatchNone)
       
   736                     {
       
   737                     fepMan->UpdateCbaL(R_AKNFEP_SOFTKEYS_EMPTY_PREVIOUS);
       
   738                     iMatchState = EWordMatchStd;
       
   739                     }
       
   740                     
       
   741                 TPtrC newText = ptiengine->NextCandidate();
       
   742            		if(newText.Length() == 1)
       
   743            			{
       
   744 	            	TDigitType digittype = fepMan->LocalDigit();
       
   745 	                TChar chchar(newText[0]);
       
   746 	                if(!chchar.IsDigit() || (chchar.IsDigit() && !digittype))
       
   747 	                	{ 	
       
   748 	                	fepMan->UpdateInlineEditL(newText, newText.Length());    
       
   749     	            	}
       
   750 	                else 
       
   751 	                	{
       
   752 	                	TBuf<1> tempbuf;
       
   753 	                	tempbuf.Append(newText[0]);
       
   754 		            	ConvertDigitToDigittype(digittype,tempbuf);
       
   755 		                fepMan->UpdateInlineEditL(tempbuf, tempbuf.Length());	
       
   756 	                	}
       
   757            			}
       
   758            		else 
       
   759            			{
       
   760            			fepMan->UpdateInlineEditL(newText, newText.Length());	
       
   761            			}
       
   762                 }
       
   763             }
       
   764         else
       
   765             {
       
   766   			if (!fepMan->EditSubmenuInUse())
       
   767         		{
       
   768         		fepMan->LaunchSpecialCharacterTableL();
       
   769         		}
       
   770             }          
       
   771         }
       
   772     return ETrue;
       
   773     }
       
   774 
       
   775 void TAknFepInputStateEntryWesternPredictive::LastWordInSelectionList()
       
   776     {
       
   777     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   778     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   779     
       
   780     iIsLastWord = ETrue;
       
   781     
       
   782     if (iMatchState != EWordMatchAfterLast)
       
   783         {
       
   784         TInt newResource = R_AKNFEP_SOFTKEYS_SPELL_PREVIOUS;
       
   785         if (ptiengine->LastEnteredKey() == EPtiKey1)
       
   786             {
       
   787             newResource=R_AKNFEP_SOFTKEYS_SYMBOL_PREVIOUS;
       
   788             }
       
   789         TRAP_IGNORE(fepMan->UpdateCbaL(newResource));
       
   790         iMatchState = EWordMatchLast;
       
   791         }
       
   792     }
       
   793 
       
   794 void TAknFepInputStateEntryWesternPredictive::FirstWordInSelectionList()
       
   795     {   
       
   796     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   797 
       
   798     iIsLastWord = EFalse;
       
   799 
       
   800     if (iMatchState == EWordMatchLast)
       
   801         {
       
   802         //have cycled past the last word back to the beginning
       
   803         iMatchState = EWordMatchAfterLast;
       
   804         }
       
   805     else if (iMatchState == EWordMatchNone || iMatchState == EWordMatchStd) // called on every new keypress so checked to stop constant update
       
   806         {
       
   807         //have started/restarted a word or
       
   808         //have got back to the beginning using previous
       
   809         TRAP_IGNORE(fepMan->UpdateCbaL(NULL));
       
   810         iMatchState = EWordMatchFirst;
       
   811         }
       
   812     }
       
   813 
       
   814 void TAknFepInputStateEntryWesternPredictive::DoPreviousMatchL()
       
   815     {
       
   816     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   817     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   818     
       
   819     if (fepMan->IsFlagSet(CAknFepManager::EFlagNoMatches))
       
   820         {
       
   821         //no more matches
       
   822         fepMan->PlaySound(EAvkonSIDWarningTone);
       
   823         }
       
   824     else if (ptiengine->NumberOfCandidates()<=1)
       
   825         { 
       
   826         // only one match
       
   827         if (iMatchState == EWordMatchFirst || iMatchState == EWordMatchNone)
       
   828             {
       
   829             fepMan->UpdateCbaL(R_AKNFEP_SOFTKEYS_SPELL_EMPTY);
       
   830             iMatchState = EWordMatchLast;
       
   831             }
       
   832         }
       
   833     else
       
   834         { 
       
   835         // > 1 match
       
   836         if (iMatchState == EWordMatchLast || iMatchState == EWordMatchAfterLast)
       
   837             {
       
   838             fepMan->UpdateCbaL(R_AKNFEP_SOFTKEYS_EMPTY_PREVIOUS);
       
   839             }
       
   840         else if (iMatchState == EWordMatchFirst || iMatchState == EWordMatchNone)
       
   841             {
       
   842             fepMan->UpdateCbaL(R_AKNFEP_SOFTKEYS_EMPTY_PREVIOUS);
       
   843             }
       
   844         iMatchState = EWordMatchStd;
       
   845         TPtrC newText = ptiengine->PreviousCandidate();
       
   846         fepMan->UpdateInlineEditL(newText, newText.Length());
       
   847         }
       
   848     }
       
   849 
       
   850 void TAknFepInputStateEntryWesternPredictive::DoNextMatch()
       
   851     {
       
   852     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   853     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   854     
       
   855     if (fepMan->IsFlagSet(CAknFepManager::EFlagNoMatches))
       
   856         {
       
   857         //no more matches
       
   858         fepMan->PlaySound(EAvkonSIDWarningTone);
       
   859         }
       
   860     else if (ptiengine->NumberOfCandidates()<=1)
       
   861         { 
       
   862         // only one match
       
   863         if (iMatchState == EWordMatchFirst || iMatchState == EWordMatchNone)
       
   864             {
       
   865             TRAP_IGNORE(fepMan->UpdateCbaL(R_AKNFEP_SOFTKEYS_SPELL_EMPTY));
       
   866             iMatchState = EWordMatchLast;
       
   867             }
       
   868         }
       
   869     else
       
   870         { 
       
   871         // > 1 match
       
   872         if (iMatchState == EWordMatchLast && !(ptiengine->LastEnteredKey() == EPtiKey1))
       
   873             {
       
   874             TRAP_IGNORE(fepMan->UpdateCbaL(R_AKNFEP_SOFTKEYS_SPELL_PREVIOUS));
       
   875             }
       
   876         else if (iMatchState == EWordMatchFirst || iMatchState == EWordMatchNone)
       
   877             {
       
   878             TRAP_IGNORE(fepMan->UpdateCbaL(R_AKNFEP_SOFTKEYS_EMPTY_PREVIOUS));
       
   879             iMatchState = EWordMatchStd;
       
   880             }
       
   881         TPtrC newText = ptiengine->NextCandidate();
       
   882         TRAP_IGNORE(fepMan->UpdateInlineEditL(newText, newText.Length()));
       
   883         }
       
   884     }
       
   885 
       
   886 void TAknFepInputStateEntryWesternPredictive::ConvertDigitToDigittype(TDigitType& digittype,
       
   887                                                                       TDes& aConvertedNumeral)
       
   888 	{
       
   889 	TChar chchar(aConvertedNumeral[0]);
       
   890 	switch(digittype)
       
   891     	{
       
   892     	case EDigitTypeDevanagari:
       
   893         	{
       
   894         	chchar = (aConvertedNumeral[0] + KLatinToDevanagariDigitsDelta);
       
   895 	    	}
       
   896         	break;	
       
   897         case EDigitTypeArabicIndic:
       
   898             {
       
   899         	chchar = (aConvertedNumeral[0] + KLatinToArabicIndicDigitsDelta);
       
   900 	        }
       
   901             break;
       
   902     	case EDigitTypeEasternArabicIndic:
       
   903         	{
       
   904         	chchar = (aConvertedNumeral[0] + KLatinToEasternArabicIndicDigitsDelta);
       
   905         	}
       
   906     	}
       
   907     aConvertedNumeral.Zero();
       
   908     aConvertedNumeral.Append(chchar);
       
   909 	}
       
   910 
       
   911 TBool TAknFepInputStateEntryWesternPredictive::IsMoreCandidate()
       
   912     {
       
   913     TBool ret = ETrue;
       
   914     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   915     CPtiEngine* ptiengine = iOwner->PtiEngine();    
       
   916     
       
   917     if (fepMan->IsFlagSet(CAknFepManager::EFlagNoMatches))
       
   918         {
       
   919         ret = EFalse;
       
   920         }
       
   921 
       
   922     if (ptiengine->NumberOfCandidates() < 1)
       
   923         { 
       
   924         ret = EFalse;
       
   925         }
       
   926     else if (ptiengine->NextCandidate().Length() == 0)
       
   927         {
       
   928         ret = EFalse;
       
   929         }
       
   930     else
       
   931         {
       
   932         ptiengine->PreviousCandidate();    
       
   933         }    
       
   934     
       
   935     return ret;
       
   936     }
       
   937 
       
   938 // End of file