fep/aknfep/src/AknFepUiInputStateEntryQwertyWesternPredictive.cpp
changeset 36 a7632c26d895
parent 35 0f326f2e628e
child 42 b3eaa440ab06
equal deleted inserted replaced
35:0f326f2e628e 36:a7632c26d895
     1 /*
       
     2 * Copyright (c) 2007 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 TAknFepInputStateEntryQwertyWesternPredictive methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 
       
    30 #include "AknFepUiInputStateEntryQwertyWesternPredictive.h"
       
    31 #include "AknFepUIManagerStateInterface.h"      //MAknFepUIManagerStateInterface
       
    32 #include "AknFepManagerUIInterface.h"           //MAknFepManagerUIInterface
       
    33 #include "AknFepUiManagerWestern.h"
       
    34 #include "AknFepManager.h"
       
    35 #include "AknFepPanic.h"
       
    36 #include "AknFepCaseManager.h"
       
    37 #include "AknFepPluginManager.h"
       
    38 
       
    39 #include <PtiEngine.h>              //CPtiEngine
       
    40 #include <PtiDefs.h>                //keys
       
    41 #include <PtiCompositionDataIF.h>   //MPtiEngineCompositionDataInterface
       
    42 #include <featmgr.h>                //FeatureManager
       
    43 #include <e32keys.h>
       
    44 #include <aknfep.rsg>
       
    45 
       
    46 
       
    47 static const TInt KKeyMappingsLength = 63;
       
    48 
       
    49 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
    50 //
       
    51 TAknFepInputStateEntryQwertyWesternPredictive::
       
    52 TAknFepInputStateEntryQwertyWesternPredictive(MAknFepUIManagerStateInterface* aOwner)
       
    53     :TAknFepInputStateBase(aOwner)
       
    54     {
       
    55     //this class insists on the existence of a case manager
       
    56     __ASSERT_DEBUG(iOwner->CaseMan(), AknFepPanic(EAknFepPanicNoCaseManager));
       
    57 
       
    58     iState = EEntry;
       
    59     iMatchState = EWordMatchNone;
       
    60     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
    61     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
    62 
       
    63     TPtiTextCase caseMode = ptiengine->Case();
       
    64 
       
    65     ptiengine->SetInputMode(EPtiEngineQwertyPredictive );    
       
    66     ptiengine->SetCase(caseMode);
       
    67     TBool isUnlimitedEditor = EFalse;
       
    68     ptiengine->SetMaxLengthForAutoCompletedCandidates(
       
    69               fepMan->EditorFreeSpaceForAutoWordCompletion(isUnlimitedEditor ));
       
    70     
       
    71 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
    72     if(fepMan->IsAutoCompleteOn())
       
    73     {
       
    74 	    TRAP_IGNORE(ptiengine->HandleCommandL( EPtiCommandEnableAutoCompletion ));
       
    75     }
       
    76     else
       
    77     {
       
    78 	    TRAP_IGNORE(ptiengine->HandleCommandL( EPtiCommandDisableAutoCompletion ));
       
    79     }
       
    80     TPtiErrorCorrectionLevel correctionLevel = 
       
    81                     (TPtiErrorCorrectionLevel)fepMan->AdvancedPredictiveTypingCorrectionLevel();
       
    82     TRAP_IGNORE(ptiengine->HandleCommandL( EPtiCommandSetCorrectionLevel, 
       
    83                                           &correctionLevel ));	
       
    84 	
       
    85     TPtiKeyboardType keyboard = fepMan->KeyboardLayout();
       
    86     ptiengine->SetKeyboardType(keyboard);
       
    87 	
       
    88     TBool isNumberCandidateShown = fepMan->IsAdvancedPredictiveNumberCandidateShown();
       
    89     TRAP_IGNORE(ptiengine->HandleCommandL( EPtiCommandSetNumberCandidateStatus, 
       
    90                                           &isNumberCandidateShown ));
       
    91 	
       
    92     TBool primaryCandidateState = fepMan->AdvancedPredictivePrimaryCandidate();
       
    93     TRAP_IGNORE(ptiengine->HandleCommandL( EPtiCommandSetProactiveCorrection, 
       
    94                                           &primaryCandidateState ));
       
    95 #endif //RD_INTELLIGENT_TEXT_INPUT
       
    96     }
       
    97 
       
    98 
       
    99 ///////////////////////////////////////////////////////////////////////////////////////////////////
       
   100 //
       
   101 TBool TAknFepInputStateEntryQwertyWesternPredictive::HandleKeyL(TInt aKey, TKeyPressLength aLength)
       
   102     {
       
   103     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   104     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   105     CAknFepFnKeyManager::TFnKeyState fnKeyState  = fepMan->FnKeyState();
       
   106 	if(fnKeyState  != CAknFepFnKeyManager::EFnKeyNone)
       
   107 		{
       
   108 		ptiengine->SetCase(EPtiCaseFnLower);
       
   109 		}
       
   110 
       
   111     // Handle the Chr cycling
       
   112     if ( fepMan->IsFlagSet(CAknFepManager::EFlagQwertyChrKeyDepressed) )
       
   113         {
       
   114         if ( iData && (iData != aKey) )
       
   115             {
       
   116             // Chr key is still pressed down but character key was changed from previous one
       
   117             // to new one. The previous character is committed and PtiEngine starts 
       
   118             // prosessing new key.
       
   119             ptiengine->CancelTimerActivity();
       
   120             
       
   121             if ( !fepMan->EditorHasFreeSpace() )
       
   122                 {
       
   123                 return EFalse;
       
   124                 }
       
   125             }
       
   126         fepMan->SetFlag( CAknFepManager::EFlagInsideMultitapInlineEditingTransaction );
       
   127         }
       
   128 
       
   129     TBool response = EFalse;
       
   130 
       
   131 
       
   132     // Handle dead keys with space or backspace. These keys are not mapped in PtiEngine, so they cannot
       
   133     // be handled there.
       
   134     if ( ptiengine->HandleCommandL(EPtiCommandDeadKeyWaiting) == 1 )
       
   135         {
       
   136         if ( aKey == EStdKeyBackspace )
       
   137             {
       
   138             // Pending dead key is removed with backspace. No other characters are removed.
       
   139             ptiengine->HandleCommandL(EPtiCommandGetAndClearDeadKeyRootChar);
       
   140             response = ETrue;
       
   141             }
       
   142         else if ( aKey == EStdKeySpace )
       
   143             {
       
   144             // Dead key followed by space enters the dead key root character
       
   145             TText deadRoot = ptiengine->HandleCommandL(EPtiCommandGetAndClearDeadKeyRootChar);
       
   146             ptiengine->HandleCommandL( EPtiCommandAppendCharacter, &deadRoot );
       
   147             
       
   148             TPtrC newText = ptiengine->CurrentWord();
       
   149             fepMan->UpdateInlineEditL( newText, newText.Length() );
       
   150             iOwner->CaseMan()->UpdateCase(ENullNaviEvent);
       
   151             
       
   152             response = ETrue;
       
   153             }
       
   154         }		    
       
   155 
       
   156     if (!response) // key not yet handled
       
   157         {
       
   158         switch (aKey)
       
   159             {
       
   160             case EStdKeySpace: //fall through
       
   161             case EStdKeyEnter:
       
   162             case EStdKeyTab:
       
   163             case EStdKeyLeftArrow:
       
   164             case EStdKeyRightArrow:
       
   165             case EStdKeyUpArrow:
       
   166             case EStdKeyDownArrow:
       
   167                 response = HandleWordBreakingKeysL(aKey);
       
   168                 break;
       
   169                 
       
   170             // Long press of shift key start copy event.     
       
   171             // Its should handle by framework.    
       
   172             case EStdKeyF21:
       
   173             case EKeyF21:
       
   174             // Soft key handle by framework
       
   175             // Selection key handle by AknFepManeger.
       
   176             case EStdKeyDevice0: // iCode:EKeyCBA1
       
   177             case EStdKeyDevice1: //	iCode:EKeyCBA2
       
   178             case EStdKeyDevice3: // iCode:EKeyOK
       
   179             case EKeyCBA1:
       
   180             case EKeyCBA2:
       
   181             case EKeyOK:
       
   182             	response = EFalse;
       
   183             	break;
       
   184 
       
   185             case EKeyUpArrow: 
       
   186                 if ( fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction) )
       
   187                     {
       
   188 #ifdef RD_INTELLIGENT_TEXT_INPUT                    
       
   189                     //fepMan->HideExactWordPopUp();
       
   190                     // Select the exact match with the up arrow and lock it.
       
   191                     // Another alternative could be to call function DoPreviousMatchL() from here
       
   192                     TBool primaryCandidateState = fepMan->AdvancedPredictivePrimaryCandidate(); 
       
   193                     TInt wordIndexToSelect = 0;
       
   194             		if (EFalse == primaryCandidateState)
       
   195             			{
       
   196             			ptiengine->HandleCommandL( EPtiCommandUserActionGetIndexOfSecondaryCandidate, 
       
   197         							&wordIndexToSelect );
       
   198             			}
       
   199             			
       
   200             			if (fepMan->IsExactWordPopUpShown())
       
   201             			{
       
   202             			    fepMan->HideExactWordPopUp();			
       
   203 				        	ptiengine->HandleCommandL( 
       
   204 	                               EPtiCommandUserActionSetCurrentIndexOfCandidates, 
       
   205 	                			   &wordIndexToSelect );
       
   206 	                    	ptiengine->HandleCommandL( EPtiCommandLockCurrentCandidate );
       
   207 	                    	TPtrC selectedWord = ptiengine->CurrentWord();
       
   208 	                    	fepMan->UpdateInlineEditL( selectedWord, selectedWord.Length() ); 
       
   209 	                    	response = ETrue;        							
       
   210 	            			break;	
       
   211             			}
       
   212 						else
       
   213 						{
       
   214 							fepMan->LaunchCandidatePopupListL( wordIndexToSelect );
       
   215 						    response = ETrue;        							
       
   216 	            			break;                 
       
   217 						}
       
   218 
       
   219 #endif // RD_INTELLIGENT_TEXT_INPUT            			
       
   220                     }
       
   221                     // fall through
       
   222             case EKeyDownArrow:
       
   223             case EKeyLeftArrow:
       
   224             case EKeyRightArrow:
       
   225             case EKeyBackspace:
       
   226                 response = HandleNaviKeysL(aKey, aLength);
       
   227                 break;
       
   228             
       
   229             
       
   230             default:
       
   231                 HandleShiftState(aKey);
       
   232                 response = HandleQwertyKeysL(aKey);
       
   233 #ifdef __ITI_LONGPRESS_NUM_SHIFT_COPYPASTE__
       
   234 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   235                 if ( aLength == ELongKeyPress )
       
   236                     {
       
   237                     // Expire multitap timer after long press. 
       
   238                     ptiengine->CancelTimerActivity();
       
   239                     }
       
   240 #endif // RD_INTELLIGENT_TEXT_INPUT
       
   241 #endif // __ITI_LONGPRESS_NUM_SHIFT_COPYPASTE__
       
   242                 break;
       
   243             }
       
   244         }
       
   245     
       
   246     iData = aKey; // store the pressed key for future reference
       
   247     return response;
       
   248     }
       
   249 
       
   250 
       
   251 //////////////////////////////////////////////////////////////////////////////////
       
   252 //
       
   253 void TAknFepInputStateEntryQwertyWesternPredictive::HandleShiftState( TInt aKey )
       
   254     {
       
   255     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   256     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   257     CAknFepCaseManager* caseMan = iOwner->CaseMan();
       
   258     CAknFepFnKeyManager::TFnKeyState fnKeyState  = fepMan->FnKeyState();
       
   259     TPtiTextCase shiftedCase;
       
   260     if(fnKeyState  != CAknFepFnKeyManager::EFnKeyNone)
       
   261 		{
       
   262 		shiftedCase = EPtiCaseFnLower;
       
   263 		}
       
   264 	else
       
   265  		{
       
   266  		shiftedCase= EPtiCaseLower;	
       
   267  		}
       
   268     
       
   269     // For addition of ITI features. 
       
   270     // When FSQ is opened wiht ITI features enabled,
       
   271     // after pressing keys, don't need to re-set current text case by editor's text or FN key state.
       
   272     // Because FSQ's case doesn't obey editor's case and there is no fn key on FSQ.
       
   273     if ( fepMan->PluginUIManager() 
       
   274          && fepMan->PluginUIManager()->PluginInputMode() == EPluginInputModeFSQ
       
   275          && fepMan->WesternPredictive() )
       
   276         {
       
   277         return;
       
   278         }
       
   279         
       
   280     // Find out if the key is alphabetic
       
   281     TBuf<KKeyMappingsLength> keyMappings; 
       
   282     ptiengine->MappingDataForKey( (TPtiKey)aKey, keyMappings, EPtiCaseUpper );   
       
   283     TBool isAlpha = ( keyMappings.Length() && TChar(keyMappings[0]).IsAlpha() );
       
   284     
       
   285     if (isAlpha && (fnKeyState  == CAknFepFnKeyManager::EFnKeyNone))
       
   286         {
       
   287         switch ( caseMan->CurrentCase() )
       
   288             {
       
   289             case EAknEditorTextCase:
       
   290                 {
       
   291                 // Alphabetic characters are always capitalized in "Abc" mode 
       
   292                 // unless the shift is pressed 
       
   293                 // Thai language should not go to automatic capitalization in text case
       
   294                 // mode and predictive input. This is because it would lead to the character 
       
   295                 // mapped to upper case being displayed instead of the intended character.
       
   296                 // So below is what is essentially a XNOR condition - 
       
   297                 // 1) no-shiftkey and language with case    => upper case
       
   298                 // 2) no-shiftkey and language without case => lower case
       
   299                 // 3) shiftkey and language with case       => lower case
       
   300                 // 4) shiftkey and language without case    => upper case
       
   301                 TInt inputLang = ptiengine->CurrentLanguage()->LanguageCode();
       
   302                 if ( ( fepMan->IsFlagSet(CAknFepManager::EFlagQwertyShiftMode) ||
       
   303                        fepMan->IsFlagSet(CAknFepManager::EFlagLongShiftKeyPress) )  
       
   304                       == ( inputLang == ELangThai ||
       
   305 					  	   inputLang == ELangArabic ||
       
   306                            inputLang == ELangFarsi ||
       
   307                            inputLang == ELangHebrew ||
       
   308                            inputLang == ELangUrdu ||
       
   309                            inputLang == ELangHindi ) )
       
   310                     {
       
   311                     shiftedCase = EPtiCaseUpper;
       
   312                     }          
       
   313                 }
       
   314             break;
       
   315             
       
   316             case EAknEditorLowerCase:
       
   317                 {
       
   318                 // Pressing shift enters uppercae letters in the "abc" mode
       
   319                 if ( fepMan->IsFlagSet(CAknFepManager::EFlagQwertyShiftMode) ||
       
   320                      fepMan->IsFlagSet(CAknFepManager::EFlagLongShiftKeyPress) )
       
   321                     {
       
   322                     shiftedCase = EPtiCaseUpper;
       
   323                     }                
       
   324                 }
       
   325             break;
       
   326             
       
   327             case EAknEditorUpperCase:
       
   328                 {
       
   329                 // In the "ABC" mode (capslock mode) the letters are uppercased
       
   330                 // unless the shift is pressed
       
   331                 if ( !(fepMan->IsFlagSet(CAknFepManager::EFlagQwertyShiftMode)||
       
   332                       fepMan->IsFlagSet(CAknFepManager::EFlagLongShiftKeyPress)) )
       
   333                     {
       
   334                     shiftedCase = EPtiCaseUpper;
       
   335                     }                
       
   336                 }
       
   337             break;
       
   338                 
       
   339             default:
       
   340             break;
       
   341             }
       
   342 
       
   343         
       
   344         }
       
   345     else
       
   346         {
       
   347         // non-alphabetic keys are shifted if and only if shift is pressed, no matter what is the input state
       
   348         if ( (fnKeyState  == CAknFepFnKeyManager::EFnKeyNone) &&
       
   349              ( fepMan->IsFlagSet(CAknFepManager::EFlagLongShiftKeyPress) ||
       
   350                fepMan->IsFlagSet(CAknFepManager::EFlagQwertyShiftMode) ) )
       
   351             {
       
   352             shiftedCase = EPtiCaseUpper;
       
   353             }
       
   354         else if( (fnKeyState  == CAknFepFnKeyManager::EFnKeyNext) &&
       
   355                  (caseMan->CurrentCase() == EAknEditorTextCase ||
       
   356                   caseMan->CurrentCase() == EAknEditorUpperCase ||
       
   357                   fepMan->IsFlagSet(CAknFepManager::EFlagLongShiftKeyPress) || 
       
   358                   fepMan->IsFlagSet(CAknFepManager::EFlagQwertyShiftMode)))
       
   359             {
       
   360             shiftedCase = EPtiCaseFnUpper;  
       
   361             }
       
   362         else if (( fepMan->IsFlagSet(CAknFepManager::EFlagLongShiftKeyPress) || 
       
   363         		  fepMan->IsFlagSet(CAknFepManager::EFlagQwertyShiftMode)) && 
       
   364         		  (fnKeyState  != CAknFepFnKeyManager::EFnKeyNone))
       
   365 	        {
       
   366 			shiftedCase = EPtiCaseFnUpper;
       
   367 	        }    
       
   368         }
       
   369 
       
   370     
       
   371     // Handle the Chr key state
       
   372     if ( fepMan->IsFlagSet(CAknFepManager::EFlagQwertyChrKeyDepressed) )
       
   373         {
       
   374         // Chr key is pressed down. Chr mode is used.
       
   375         if (shiftedCase == EPtiCaseLower)
       
   376             {
       
   377             shiftedCase = EPtiCaseChrLower;
       
   378             }
       
   379         else if (shiftedCase == EPtiCaseUpper)
       
   380             {
       
   381             shiftedCase = EPtiCaseChrUpper;
       
   382             }
       
   383         }
       
   384     
       
   385     ptiengine->SetCase(shiftedCase);
       
   386     
       
   387     fepMan->ClearFlag(CAknFepManager::EFlagNoActionDuringShiftKeyPress);
       
   388     }
       
   389 
       
   390 
       
   391 //////////////////////////////////////////////////////////////////////////////////
       
   392 //
       
   393 
       
   394 TBool TAknFepInputStateEntryQwertyWesternPredictive::HandleWordBreakingKeysL(TInt aKey)
       
   395     {
       
   396     TBool retVal = EFalse; // in most cases we let also the upper levels handle these key events
       
   397     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   398     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   399     CAknFepFnKeyManager::TFnKeyState fnKeyState  = fepMan->FnKeyState();
       
   400     
       
   401 
       
   402     // Up and down arrows break the inline word input only when shift or chr is held down
       
   403     if ( !fepMan->IsFlagSet(CAknFepManager::EFlagQwertyChrKeyDepressed) &&
       
   404          !fepMan->IsFlagSet(CAknFepManager::EFlagQwertyShiftMode) &&
       
   405          ( aKey==EStdKeyUpArrow || aKey==EStdKeyDownArrow ) )
       
   406         {
       
   407         return retVal;    
       
   408         }
       
   409 
       
   410 
       
   411     if ( fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction) )
       
   412         {
       
   413         TBool rightToLeftLang = fepMan->IsRightToLeftLanguage();
       
   414         TInt tailLength = 0;
       
   415 	    ptiengine->HandleCommandL( EPtiCommandGetAutoCompletionTailLength, &tailLength );
       
   416         switch (aKey)
       
   417             {
       
   418             case EStdKeyLeftArrow:
       
   419             case EStdKeyRightArrow:    
       
   420             	// In case the inline editing is ongoing and there is a word completion
       
   421                 // currently shown, the first backwards tap will remove the suggested 
       
   422                 // completion. 
       
   423                 if(tailLength > 0)
       
   424 	                {
       
   425 	                if ((rightToLeftLang && aKey == EStdKeyLeftArrow) 
       
   426 	                	|| (! rightToLeftLang && aKey == EStdKeyRightArrow ))
       
   427 	                    {
       
   428 					    ptiengine->HandleCommandL( EPtiCommandLockCurrentCandidate);
       
   429 					    TPtrC selectedWord = ptiengine->CurrentWord();
       
   430                         fepMan->UpdateInlineEditL( selectedWord, selectedWord.Length() );  //selection.iAnchorPosition
       
   431                         // To fix the bug: STAA-7GYBJC Suggested word is not committed when Arrow right key is pressed.
       
   432                         ptiengine->CommitCurrentWord();
       
   433                         fepMan->TryCloseUiL();
       
   434                         // Asyncronous case update after the editor has handled the key
       
   435                 		fepMan->SimulateKeyEventL(EKeyF19); 
       
   436 	                    retVal = ETrue;
       
   437 	                    }
       
   438 	                else if((rightToLeftLang && aKey == EStdKeyRightArrow) 
       
   439 	                	|| (! rightToLeftLang && aKey == EStdKeyLeftArrow )) 
       
   440 		                {
       
   441 	                    fepMan->RemoveSuggestedAdvanceCompletionL();
       
   442 	                    retVal = ETrue;
       
   443 		                }    	
       
   444 	                }
       
   445                 else
       
   446 	                {
       
   447 	                ptiengine->CommitCurrentWord();
       
   448 	                retVal = EFalse;
       
   449 	                }
       
   450             break;  
       
   451             case EStdKeyUpArrow:
       
   452             case EStdKeyDownArrow:
       
   453             case EStdKeyEnter:
       
   454             case EStdKeySpace:
       
   455             case EStdKeyTab:
       
   456             {  
       
   457             	//retVal = ETrue;
       
   458             	TBool wasInlineEditing = EFalse;	
       
   459             	wasInlineEditing = 
       
   460                           fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction);
       
   461             	ptiengine->CommitCurrentWord();
       
   462                 fepMan->CommitInlineEditL();
       
   463                 /* Temporary Fix */
       
   464                 //EFlagInsideInlineEditingTransaction flag check is not required
       
   465                 //but just to make sure.
       
   466                 if (aKey == EStdKeySpace && fnKeyState == CAknFepFnKeyManager::EFnKeyDown)
       
   467                     fepMan->LaunchSelectModeMenuL();
       
   468                 else if(aKey == EStdKeySpace && wasInlineEditing)
       
   469                 	{
       
   470                 	_LIT(KSpace," ");                
       
   471 	                fepMan->StartInlineEditL();
       
   472 	                fepMan->UpdateInlineEditL(KSpace,0);
       
   473 	                fepMan->CommitInlineEditL();
       
   474                 	retVal = ETrue;
       
   475                 	}                
       
   476                 /* Temporary Fix */
       
   477                 fepMan->TryCloseUiL();                
       
   478                 // Asyncronous case update after the editor has handled the key
       
   479                 fepMan->SimulateKeyEventL(EKeyF19); 
       
   480             	}                
       
   481             break;
       
   482             default:
       
   483                 __ASSERT_DEBUG( EFalse, AknFepPanic(EAknFepPanicNotSupportKey) );
       
   484             }
       
   485 
       
   486         }
       
   487     else
       
   488         {
       
   489         iOwner->ChangeState( EInitial );
       
   490         }
       
   491 
       
   492     return retVal;
       
   493     }
       
   494 
       
   495 
       
   496 /////////////////////////////////////////////////////////////////////////////////
       
   497 //
       
   498 TBool TAknFepInputStateEntryQwertyWesternPredictive::HandleQwertyKeysL(TInt aKey)
       
   499     {
       
   500     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   501     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   502     
       
   503     CAknFepCaseManager* caseMan = iOwner->CaseMan(); 
       
   504     CAknFepFnKeyManager::TFnKeyState fnKeyState  = fepMan->FnKeyState();
       
   505     
       
   506     // Key is consumed if the PtiEngine maps it to some character
       
   507     TBuf<KKeyMappingsLength> keyMappings; 
       
   508     
       
   509     if(fnKeyState  != CAknFepFnKeyManager::EFnKeyNone)
       
   510 		{
       
   511 		
       
   512 		// Try to know is there any mapping for function upper
       
   513 		// char. For user point of view this changes has been made.
       
   514 		if( ptiengine->Case() == EPtiCaseFnUpper )
       
   515 			{
       
   516 	    	ptiengine->MappingDataForKey( (TPtiKey)aKey, keyMappings, EPtiCaseFnUpper);
       
   517 			}
       
   518 		else
       
   519 			{
       
   520 		   	ptiengine->MappingDataForKey( (TPtiKey)aKey, keyMappings, EPtiCaseFnLower);			
       
   521 			}
       
   522 		}
       
   523 	else
       
   524  		{
       
   525 	    ptiengine->MappingDataForKey( (TPtiKey)aKey, keyMappings, EPtiCaseLower);   
       
   526  		}
       
   527     //ITI : Pti Engine can be asked to give the proper data for the keys under Fn Key.
       
   528     TBool keyIsMapped = ( keyMappings.Length() > 0 );
       
   529     
       
   530     // The dead key handling inside the PtiDefaultCore assumes that no other key mapping queries
       
   531     // have been made between handling the dead key and the next one (these queries change the
       
   532     // internal state of the key mapping object). For this reason, we must return the key mappings
       
   533     // to their previous state. This is quite dirty hack, but so is the dead key handling code which
       
   534     // forces us to do this.
       
   535     if(fnKeyState  != CAknFepFnKeyManager::EFnKeyNone)
       
   536 		{
       
   537 	    ptiengine->MappingDataForKey( (TPtiKey)iData, keyMappings, EPtiCaseFnLower);
       
   538 		}
       
   539 	else
       
   540  		{
       
   541  		ptiengine->MappingDataForKey( (TPtiKey)iData, keyMappings, EPtiCaseLower);
       
   542  		}
       
   543  		
       
   544  	// For user point of view this changes has been made.
       
   545  	// If key does not map to function upper char, then try to insert
       
   546  	// functionized char.
       
   547 	if( (EPtiCaseFnUpper == ptiengine->Case()) && !keyIsMapped )
       
   548   		{
       
   549         ptiengine->SetCase((TPtiTextCase)EPtiCaseFnLower);
       
   550        	ptiengine->MappingDataForKey( (TPtiKey)aKey, keyMappings, EPtiCaseFnLower);
       
   551         keyIsMapped = ( keyMappings.Length() > 0 );
       
   552  		}
       
   553 
       
   554     if ( keyIsMapped )
       
   555         {
       
   556         if ( !(fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction)) )
       
   557             { // 'new' inline edit                        
       
   558             ptiengine->ClearCurrentWord();
       
   559             if (caseMan->CurrentCase() == EAknEditorTextCase)
       
   560                 {
       
   561                 ptiengine->MarkAutoCapitalized();    
       
   562                 }            
       
   563             
       
   564             fepMan->StartInlineEditL();
       
   565             }
       
   566                        
       
   567         TPtrC newText = ptiengine->AppendKeyPress((TPtiKey)aKey);
       
   568         fepMan->UpdateInlineEditL(newText, newText.Length());
       
   569         
       
   570         // Normally we update the case after key press. However, if Chr key is held down, the case update
       
   571         // must not happen until when the Chr is released or the timer expires (in both of these cases
       
   572         // the function KeyTimerExpired() will get callled).         
       
   573         if ( !fepMan->IsFlagSet(CAknFepManager::EFlagQwertyChrKeyDepressed) )
       
   574             {
       
   575        	    iOwner->CaseMan()->UpdateCase(ENullNaviEvent);
       
   576        	    }
       
   577     	else
       
   578             {
       
   579             fepMan->ClearFlag(CAknFepManager::EFlagNoActionDuringChrKeyPress);
       
   580             }
       
   581            
       
   582         return ETrue;
       
   583         }
       
   584         // MT error fixing : If any key does not map any functionized char, 
       
   585         // its should not display any char fn mode, other behaviour as usual.
       
   586         // If the Fn key stae indicate that fn key pres & we are looking for functionnized
       
   587         // char, if its not availble it will do nothing. So we have to block the event
       
   588         // go to framework.
       
   589         if( aKey!=EStdKeyBackspace && fnKeyState  != CAknFepFnKeyManager::EFnKeyNone)
       
   590         	return ETrue;
       
   591         
       
   592         // Framework will handle the key event.
       
   593        	return EFalse;
       
   594     }
       
   595     
       
   596 
       
   597 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
   598 //
       
   599 TBool TAknFepInputStateEntryQwertyWesternPredictive::HandleNaviKeysL(TInt aKey, TKeyPressLength /*aLength*/)
       
   600     {
       
   601     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   602     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   603 
       
   604     if (!(fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction)))
       
   605         {
       
   606         TBuf<CAknFepManager::EMaximumFepWordLength> textToUncommit;
       
   607         TBool comsumeKey;
       
   608         if (!(fepMan->TryGetTextToUncommitL(textToUncommit, aKey, comsumeKey)))
       
   609             {
       
   610             // If T9 word length > 32, the navi key is consumed without action.
       
   611             // Maybe should navigate inside word.
       
   612             return comsumeKey;
       
   613             }
       
   614         ptiengine->ClearCurrentWord();
       
   615         ptiengine->SetCurrentWord(textToUncommit); // this set the input sequence of PtiEngine
       
   616         fepMan->StartInlineEditL(fepMan->UncommittedText(), textToUncommit, 
       
   617         						 textToUncommit.Length(), EFalse);
       
   618         }
       
   619 
       
   620     if (aKey == EKeyBackspace)
       
   621         {
       
   622         TInt activeIdx = KErrNone;
       
   623         TPtrC newText = ptiengine->DeleteKeyPress();
       
   624         // To fix the Backspace Key issue in which focused word needs to be present in the editor.
       
   625         ptiengine->HandleCommandL( EPtiCommandUserActionSetCurrentIndexOfCandidates, &activeIdx );
       
   626         TPtrC selectedWord = ptiengine->CurrentWord();
       
   627         fepMan->UpdateInlineEditL(selectedWord, selectedWord.Length());
       
   628 
       
   629 		fepMan->ClearFlag(CAknFepManager::EFlagRemoveMatchesMenuItem);           
       
   630         if (ptiengine->NumberOfCandidates() <= 1)
       
   631         	{
       
   632 			fepMan->SetFlag(CAknFepManager::EFlagRemoveMatchesMenuItem);           	
       
   633         	}
       
   634 
       
   635         iOwner->CaseMan()->UpdateCase(EBackspaceEvent);
       
   636         fepMan->CloseUiIfWordDeletedL();
       
   637         }
       
   638     
       
   639     return ETrue;
       
   640     }
       
   641 
       
   642 
       
   643 /////////////////////////////////////////////////////////////////////////////
       
   644 //
       
   645 void TAknFepInputStateEntryQwertyWesternPredictive::LastWordInSelectionList()
       
   646     {
       
   647 
       
   648     }
       
   649 
       
   650 
       
   651 //////////////////////////////////////////////////////////////////////////////
       
   652 //
       
   653 void TAknFepInputStateEntryQwertyWesternPredictive::FirstWordInSelectionList()
       
   654     {   
       
   655     }
       
   656 
       
   657 
       
   658 /////////////////////////////////////////////////////////////////
       
   659 //
       
   660 void TAknFepInputStateEntryQwertyWesternPredictive::KeyTimerExpired()
       
   661     {
       
   662     if (iData)
       
   663         {
       
   664         MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   665         CAknFepCaseManager* caseMan = iOwner->CaseMan(); 
       
   666         caseMan->UpdateCase(ENullNaviEvent); 
       
   667         fepMan->ClearFlag( CAknFepManager::EFlagInsideMultitapInlineEditingTransaction );
       
   668         iData = 0;
       
   669         }
       
   670     }
       
   671    
       
   672 
       
   673 // End of file