fep/aknfep/src/AknFepUiInputStateEntryVietnamesePredictive.cpp
changeset 0 eb1f2e154e89
child 9 e6a39382bb9c
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     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 TAknFepUiInputStateEntryVietnamesePredictive methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 
       
    30 #include "AknFepUiInputStateEntryVietnamesePredictive.h"
       
    31 #include "AknFepUIInputStateInitialVietnameseMultitap.h"
       
    32 #include "AknFepUIManagerStateInterface.h"      //MAknFepUIManagerStateInterface
       
    33 #include "AknFepCaseManager.h"
       
    34 #include "AknFepVietnameseToneManager.h"
       
    35 
       
    36 #include <uikon.hrh>
       
    37 #include <PtiEngine.h>                          //CPtiEngine
       
    38 #include <PtiDefs.h>                            //keys
       
    39 #include <aknSctDialog.h>
       
    40 #include <avkon.rsg>
       
    41 #include <AknFep.rsg>
       
    42 
       
    43 #include "AknFepUiManagerWestern.h"
       
    44 TAknFepInputStateEntryVietnamesePredictive::
       
    45 TAknFepInputStateEntryVietnamesePredictive(MAknFepUIManagerStateInterface* aOwner)
       
    46 : TAknFepInputStateEntryWesternPredictive(aOwner)   
       
    47     {
       
    48     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
    49     if (ptiengine->CurrentLanguage()->LanguageCode() != ELangVietnamese)
       
    50         {
       
    51         TRAP_IGNORE(ptiengine->ActivateLanguageL(ELangVietnamese));
       
    52         }
       
    53 #ifndef RD_INTELLIGENT_TEXT_INPUT
       
    54         MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
    55         if(fepMan->IsAutoCompleteOn())
       
    56     	{
       
    57     	   ptiengine->SetInputMode(EPtiEngineWordCompletion);
       
    58     	}
       
    59     	else
       
    60 #endif
       
    61         {
       
    62         ptiengine->SetInputMode(EPtiEnginePredictive);
       
    63         }
       
    64     }
       
    65 
       
    66 TBool TAknFepInputStateEntryVietnamesePredictive::HandleKeyL(TInt aKey, TKeyPressLength aLength)
       
    67     {
       
    68     
       
    69     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
    70     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
    71 
       
    72     TBool response = ETrue;
       
    73 
       
    74     switch (aKey)
       
    75         {
       
    76     case EPtiKey1: //fall through
       
    77     case EPtiKey2:
       
    78     case EPtiKey3:
       
    79     case EPtiKey4:
       
    80     case EPtiKey5:
       
    81     case EPtiKey6:
       
    82     case EPtiKey7:
       
    83     case EPtiKey8:
       
    84     case EPtiKey9:
       
    85         response = HandleStandardNumericKeysL(aKey, aLength);
       
    86         break;
       
    87     case EPtiKey0:
       
    88         if ( fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction) )
       
    89             {
       
    90             fepMan->TryRemoveNoMatchesIndicatorL();
       
    91 #ifndef RD_INTELLIGENT_TEXT_INPUT
       
    92             if(fepMan->IsAutoCompleteOn())
       
    93 					{
       
    94 					fepMan->RemoveSuggestedCompletionL();
       
    95 					}
       
    96 #endif
       
    97             }
       
    98         fepMan->UpdateCbaL(NULL);
       
    99         if (fepMan->IsFlagSet(CAknFepManager::EFlagCompoundWord))
       
   100             { 
       
   101             if (fepMan->IsCursorAtEndOfWord())
       
   102                 {            
       
   103                 fepMan->AddCompoundWordToUdbL();
       
   104                 }
       
   105             fepMan->ClearFlag(CAknFepManager::EFlagCompoundWord);
       
   106             }
       
   107         ptiengine->CommitCurrentWord();  // commit word after calling TryCloseUiL().
       
   108         fepMan->TryCloseUiL();
       
   109         response = EFalse;  //pass to initial state to handle key
       
   110         break;
       
   111     case EKeyLeftArrow: // fall through
       
   112     case EKeyRightArrow:
       
   113         response = HandleNaviKeysL(aKey, aLength);
       
   114         break;    
       
   115     case EKeyBackspace:
       
   116         response = HandleDeleteKeysL(aKey, aLength);
       
   117         break;
       
   118     case EPtiKeyStar:
       
   119         response = HandleStarKeyL(aLength);
       
   120         break;
       
   121     case EKeyDownArrow: // Japanese input required
       
   122         if (fepMan->IsAbleScrollLatinPredictive())
       
   123             {
       
   124             if (fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction))
       
   125                 {
       
   126                 DoNextMatch();
       
   127                 }
       
   128             else
       
   129                 {
       
   130                 response = EFalse;
       
   131                 }
       
   132             }
       
   133         else
       
   134             {
       
   135             response = EFalse;
       
   136             }
       
   137         break;
       
   138     case EKeyUpArrow: // Japanese input required
       
   139         if (fepMan->IsAbleScrollLatinPredictive())
       
   140             {
       
   141             if (fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction))
       
   142                 {
       
   143                 DoPreviousMatchL();
       
   144                 }
       
   145             else
       
   146                 {
       
   147                 response = EFalse;
       
   148                 }
       
   149             }
       
   150         else
       
   151             {
       
   152             response = EFalse;
       
   153             }
       
   154         break;
       
   155     default:
       
   156         response = EFalse;
       
   157         break;
       
   158         }
       
   159     return response;
       
   160     }
       
   161 
       
   162 TBool TAknFepInputStateEntryVietnamesePredictive::HandleStarKeyL(TKeyPressLength aLength)
       
   163     {
       
   164     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   165     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   166 
       
   167     if (aLength == ELongKeyPress)
       
   168         { 
       
   169         if (fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction))
       
   170             {
       
   171             // replace with previous match
       
   172             fepMan->TryRemoveNoMatchesIndicatorL();
       
   173             iMatchState = EWordMatchStd;
       
   174             TPtrC newText = ptiengine->PreviousCandidate();
       
   175             fepMan->UpdateInlineEditL(newText, newText.Length());
       
   176             }
       
   177             
       
   178 #ifndef RD_INTELLIGENT_TEXT_INPUT
       
   179         	// to rip off suggested completion when SCT is launched
       
   180 		if(fepMan->IsAutoCompleteOn()) 
       
   181 			{
       
   182 			fepMan->RemoveSuggestedCompletionL();	
       
   183 			}
       
   184 #endif
       
   185        	if (!fepMan->EditSubmenuInUse())
       
   186         	{
       
   187         	fepMan->LaunchSpecialCharacterTableL();
       
   188         	}            
       
   189         }
       
   190     else 
       
   191         {
       
   192         if (fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction))
       
   193             {
       
   194             if (fepMan->IsFlagSet(CAknFepManager::EFlagNoMatches))
       
   195                 {
       
   196                 //no more matches
       
   197                 fepMan->PlaySound(EAvkonSIDWarningTone);
       
   198                 }
       
   199             else if (ptiengine->NumberOfCandidates()<=1)
       
   200                 { 
       
   201                 // only one match
       
   202                 if (iMatchState == EWordMatchFirst || iMatchState == EWordMatchNone)
       
   203                     {
       
   204                     fepMan->UpdateCbaL(R_AKNFEP_SOFTKEYS_SPELL_EMPTY);
       
   205                     iMatchState = EWordMatchLast;
       
   206                     }
       
   207                 }
       
   208             else
       
   209                 { 
       
   210                 // > 1 match
       
   211                 if (iMatchState == EWordMatchLast && !(ptiengine->LastEnteredKey() == EPtiKey1))
       
   212                     {
       
   213                     fepMan->UpdateCbaL(R_AKNFEP_SOFTKEYS_SPELL_PREVIOUS);
       
   214                     }
       
   215                 else if (iMatchState == EWordMatchFirst || iMatchState == EWordMatchNone)
       
   216                     {
       
   217                     fepMan->UpdateCbaL(R_AKNFEP_SOFTKEYS_EMPTY_PREVIOUS);
       
   218                     iMatchState = EWordMatchStd;
       
   219                     }
       
   220                 TPtrC newText = ptiengine->NextCandidate();
       
   221            		if(newText.Length() == 1)
       
   222            			{
       
   223 	            	TDigitType digittype = fepMan->LocalDigit();
       
   224 	                TChar chchar(newText[0]);
       
   225 	                if(!chchar.IsDigit() || (chchar.IsDigit() && !digittype))
       
   226 	                	{ 	
       
   227 	                	fepMan->UpdateInlineEditL(newText, newText.Length());    
       
   228     	            	}
       
   229 	                else 
       
   230 	                	{
       
   231 	                	TBuf<1> tempbuf;
       
   232 	                	switch(digittype)
       
   233 		                	{
       
   234 		                	case EDigitTypeDevanagari:
       
   235 			                	{
       
   236 			                	chchar = (newText[0] + KLatinToDevanagariDigitsDelta);
       
   237 	            		    	}
       
   238 			                	break;	
       
   239 			                case EDigitTypeArabicIndic:
       
   240 				                {
       
   241 			                	chchar = (newText[0] + KLatinToArabicIndicDigitsDelta);
       
   242 	            		        }
       
   243 				                break;
       
   244 		                	case EDigitTypeEasternArabicIndic:
       
   245 			                	{
       
   246 			                	chchar = (newText[0] + KLatinToEasternArabicIndicDigitsDelta);
       
   247 			                	}
       
   248 		                	}
       
   249 	            		tempbuf.Append(chchar);				                	
       
   250 		                fepMan->UpdateInlineEditL(tempbuf, tempbuf.Length());	
       
   251 	                	}
       
   252            			}
       
   253            		else 
       
   254            			{
       
   255            			fepMan->UpdateInlineEditL(newText, newText.Length());	
       
   256            			}
       
   257                 }
       
   258             }
       
   259         else
       
   260             {
       
   261   			if (!fepMan->EditSubmenuInUse())
       
   262         		{
       
   263         		fepMan->LaunchSpecialCharacterTableL();
       
   264         		}
       
   265             }
       
   266         }
       
   267     return ETrue;
       
   268     }
       
   269 
       
   270 TBool TAknFepInputStateEntryVietnamesePredictive::HandleDeleteKeysL(TInt aKey, TKeyPressLength /*aLength*/)
       
   271     {
       
   272     MAknFepManagerUIInterface* fepMan = iOwner->FepMan();
       
   273     CPtiEngine* ptiengine = iOwner->PtiEngine();
       
   274 
       
   275     if (!(fepMan->IsFlagSet(CAknFepManager::EFlagInsideInlineEditingTransaction)))
       
   276         {
       
   277         if(fepMan->PreviousChar() == TText(0x0020))      // 0x0020 is space 
       
   278         {
       
   279         	return EFalse;
       
   280         }
       
   281         TBuf<CAknFepManager::EMaximumFepWordLength> textToUncommit;
       
   282         TBool comsumeKey;
       
   283         if (!(fepMan->TryGetTextToUncommitL(textToUncommit, aKey, comsumeKey)))
       
   284             {
       
   285             // If T9 word length > 32, the navi key is consumed without action.
       
   286             // Maybe should navigate inside word.
       
   287             return comsumeKey;
       
   288             }
       
   289         ptiengine->SetCurrentWord(textToUncommit);
       
   290 		fepMan->ClearFlag(CAknFepManager::EFlagRemoveMatchesMenuItem);           
       
   291         if (ptiengine->NumberOfCandidates() <= 1)
       
   292         	{
       
   293 			fepMan->SetFlag(CAknFepManager::EFlagRemoveMatchesMenuItem);           	
       
   294         	}        
       
   295         fepMan->StartInlineEditL(fepMan->UncommittedText(), textToUncommit, 
       
   296                                  textToUncommit.Length(), EFalse);
       
   297         }
       
   298   
       
   299     if (aKey == EKeyBackspace)
       
   300         {
       
   301         if (fepMan->IsFlagSet(CAknFepManager::EFlagNoMatches))
       
   302             {
       
   303             fepMan->TryRemoveNoMatchesIndicatorL();
       
   304             fepMan->UpdateCbaL(NULL);
       
   305             return ETrue;
       
   306             }
       
   307         else if (iMatchState != EWordMatchFirst)
       
   308             {
       
   309             //let FirstWordInSelectionList() reset the CBA
       
   310             iMatchState = EWordMatchNone;
       
   311             }
       
   312         
       
   313         TBuf<2> newText;
       
   314         // Get the last character from the current editor
       
   315         TText prevChar = fepMan->PreviousChar();
       
   316         TBool vowelList = EFalse;
       
   317         for (TInt index = 0; index < KNumberOfToneMarks; index ++)
       
   318             {
       
   319             if (VietToneMatrix[0][index] == prevChar)
       
   320                 {
       
   321                 vowelList = ETrue;
       
   322                 break;
       
   323                 }
       
   324             }
       
   325         
       
   326         if (vowelList)
       
   327             {
       
   328                 ((CAknFepManager*)fepMan)->RemovePreviousCharacterL();
       
   329             }
       
   330         else
       
   331             {
       
   332             if (prevChar <= 0)
       
   333                 {
       
   334                 return EFalse;
       
   335                 }
       
   336             
       
   337             // Judge if the last character needs to be converted
       
   338             if ( TAknFepInputStateInitialVietnameseMultitap::NeedsVietnameseBkDelSupport(prevChar,
       
   339                                                                                          newText) )
       
   340                 {
       
   341                 ((CAknFepManager*)fepMan)->RemovePreviousCharacterL();
       
   342                 }
       
   343             else
       
   344                 {
       
   345                 TPtrC  updatedText = ptiengine->DeleteKeyPress();
       
   346                 if(ptiengine->InputMode() != EPtiEngineWordCompletion && newText.Length())
       
   347                 	{
       
   348                 	fepMan->UpdateInlineEditL(updatedText, newText.Length());
       
   349                 	}
       
   350                 else
       
   351                 	{
       
   352                 	fepMan->UpdateInlineEditL(updatedText, updatedText.Length());	
       
   353                 	}
       
   354                 }
       
   355             }
       
   356 
       
   357 		fepMan->ClearFlag(CAknFepManager::EFlagRemoveMatchesMenuItem);           
       
   358         if (ptiengine->NumberOfCandidates() <= 1)
       
   359         	{
       
   360 			fepMan->SetFlag(CAknFepManager::EFlagRemoveMatchesMenuItem);           	
       
   361         	}
       
   362 
       
   363         iOwner->CaseMan()->UpdateCase(EBackspaceEvent);
       
   364         fepMan->CloseUiIfWordDeletedL();
       
   365         }
       
   366         
       
   367     return ETrue;
       
   368     }
       
   369 
       
   370 // End of file