textinput/ptienginev2/src/PtiEngineImpl.cpp
branchRCL_3
changeset 21 ecbabf52600f
parent 20 ebd48d2de13c
child 22 bd83ceabce89
equal deleted inserted replaced
20:ebd48d2de13c 21:ecbabf52600f
    36 #include <Languages.hrh>
    36 #include <Languages.hrh>
    37 #endif
    37 #endif
    38 #include <AknUtils.h>
    38 #include <AknUtils.h>
    39 #include <e32property.h>
    39 #include <e32property.h>
    40 #include <AknFepInternalCRKeys.h>
    40 #include <AknFepInternalCRKeys.h>
       
    41 #include <AknFepInternalPSKeys.h>
    41 #include <AvkonInternalCRKeys.h>
    42 #include <AvkonInternalCRKeys.h>
    42 
    43 
    43 const TInt KDefaultLanguageGran = 5;
    44 const TInt KDefaultLanguageGran = 5;
    44 const TInt KDefaultLangNamesGran = 40;
    45 const TInt KDefaultLangNamesGran = 40;
    45 const TInt KPhraseSeparator = 0x0020;
    46 const TInt KPhraseSeparator = 0x0020;
   131 const TInt16 KStrokeUnicode = 0x2461;
   132 const TInt16 KStrokeUnicode = 0x2461;
   132 const TInt16 KZhuyinIndicator = 0x2462;
   133 const TInt16 KZhuyinIndicator = 0x2462;
   133 
   134 
   134 // Local method declarations.
   135 // Local method declarations.
   135 LOCAL_C TInt RemapVietnameseAccentedCharacter(TUint16 aChr);
   136 LOCAL_C TInt RemapVietnameseAccentedCharacter(TUint16 aChr);
       
   137 LOCAL_C TBool IsRegionalLang(TInt aVariantCode, TInt& aMainCode)
       
   138     {   
       
   139     TBool ret = ETrue;
       
   140     switch(aVariantCode)
       
   141         {
       
   142         case ELangBrazilianPortuguese:
       
   143             aMainCode = ELangPortuguese;
       
   144             break;
       
   145         case ELangCanadianFrench:
       
   146             aMainCode = ELangFrench;
       
   147             break;
       
   148         case ELangLatinAmericanSpanish:
       
   149             aMainCode = ELangSpanish;
       
   150             break;
       
   151         case ELangEnglish_Taiwan:
       
   152         case ELangEnglish_HongKong:
       
   153         case ELangEnglish_Prc:
       
   154             aMainCode = ELangEnglish;
       
   155             break;
       
   156         default:
       
   157             aMainCode = aVariantCode; 
       
   158             ret = EFalse;
       
   159         }
       
   160     return ret;
       
   161     }
       
   162 LOCAL_C TBool AlreadyExistLang(CArrayPtrFlat<CPtiCoreLanguage>* aLangArray, TInt aLangCode)
       
   163     {
       
   164     if (aLangArray)
       
   165         {
       
   166         for (TInt i=0; i < aLangArray->Count(); i++)
       
   167             {
       
   168             if (aLangArray->At(i)->LanguageCode() == aLangCode)
       
   169                 {
       
   170                 return ETrue;
       
   171                 }
       
   172             }
       
   173         }
       
   174     return EFalse;
       
   175     }
       
   176 const TUid KXt9ImplementationUid = {0x102830B9};
   136 	
   177 	
   137 //
   178 //
   138 // CPtiEngineImpl implementation
   179 // CPtiEngineImpl implementation
   139 //
   180 //
   140 
   181 
   283 				}
   324 				}
   284 			}
   325 			}
   285 #endif
   326 #endif
   286 		for (TInt i = 0; i < count; i++)
   327 		for (TInt i = 0; i < count; i++)
   287 			{
   328 			{
       
   329 		    TInt code = 0;		    
   288 			if ((iLanguages->At(i)->LanguageCode() != ELangNumeric)
   330 			if ((iLanguages->At(i)->LanguageCode() != ELangNumeric)
   289 #ifdef RD_HINDI_PHONETIC_INPUT
   331 #ifdef RD_HINDI_PHONETIC_INPUT
   290 				&& (iLanguages->At(i)->LanguageCode() != KLangHindiPhonetic)
   332 				&& (iLanguages->At(i)->LanguageCode() != KLangHindiPhonetic)
   291 #endif
   333 #endif
   292                 )
   334                 )
   293 				{
   335 				{
   294 				aResult->AppendL(iLanguages->At(i)->LanguageCode());
   336 			    if(IsRegionalLang(iLanguages->At(i)->LanguageCode(),code))
       
   337                     {
       
   338                     if(AlreadyExistLang(iLanguages,code))
       
   339                         {
       
   340                         continue;
       
   341                         }
       
   342                     }
       
   343 				aResult->AppendL(code);
   295 #ifdef RD_HINDI_PHONETIC_INPUT
   344 #ifdef RD_HINDI_PHONETIC_INPUT
   296 				if (iLanguages->At(i)->LanguageCode() == ELangHindi && isIndicPhoneticInputPresent)
   345 				if (iLanguages->At(i)->LanguageCode() == ELangHindi && isIndicPhoneticInputPresent)
   297 					aResult->AppendL(KLangHindiPhonetic);
   346 					aResult->AppendL(KLangHindiPhonetic);
   298 #endif
   347 #endif
   299 				}
   348 				}
   661 		else if (!iCurrentLanguage->HasInputMode(aMode))
   710 		else if (!iCurrentLanguage->HasInputMode(aMode))
   662 			{
   711 			{
   663 			return KErrNoSuitableCore;	
   712 			return KErrNoSuitableCore;	
   664 			}
   713 			}
   665 		}
   714 		}
   666 
   715 	
   667     iInputMode = aMode;	
   716 	if (iInputMode != aMode)
       
   717 		{
       
   718 		OnInputModeChanged(iInputMode, aMode);
       
   719 		iInputMode = aMode;		
       
   720 		}
   668 
   721 
   669 	TFileName temp;
   722 	TFileName temp;
   670 	temp.Copy(iTextBuffer);
   723 	temp.Copy(iTextBuffer);
   671 	return SetCurrentWord( temp );
   724 	return SetCurrentWord( temp );
   672 	}
   725 	}
   673 
   726 
       
   727 void CPtiEngineImpl::OnInputModeChanged(TPtiEngineInputMode /*aOldMode*/, TPtiEngineInputMode aNewMode)
       
   728 	{
       
   729 	if (aNewMode == EPtiEngineQwertyPredictive)
       
   730 		{
       
   731 		HBufC16* oldTextBuf = iTextBuffer.Alloc(); 
       
   732 		ClearCurrentWord();
       
   733 		if (oldTextBuf)
       
   734 			{
       
   735 			// why assigned here? eh, I don't want to do that either.
       
   736 			// SetCurrentWord will use core(), which will use iInputMode, and 
       
   737 			// obviously, the core should return the new core, that is why.
       
   738 			iInputMode = aNewMode;
       
   739 		
       
   740 			SetCurrentWord(oldTextBuf->Des());
       
   741 			delete oldTextBuf;
       
   742 			}
       
   743 		}
       
   744 	}
   674 
   745 
   675 // ---------------------------------------------------------------------------
   746 // ---------------------------------------------------------------------------
   676 // CPtiEngineImpl::CountToneMarks
   747 // CPtiEngineImpl::CountToneMarks
   677 // 
   748 // 
   678 // ---------------------------------------------------------------------------
   749 // ---------------------------------------------------------------------------
  1034 
  1105 
  1035 		case EPtiEngineStrokeQwerty:
  1106 		case EPtiEngineStrokeQwerty:
  1036 		case EPtiEngineStrokePhraseHalfQwerty:
  1107 		case EPtiEngineStrokePhraseHalfQwerty:
  1037 		case EPtiEngineStrokePhraseQwerty:
  1108 		case EPtiEngineStrokePhraseQwerty:
  1038 			{
  1109 			{
  1039 			TPtiKeyboardType keyboardType = EPtiKeyboardNone;
  1110 			TPtiKeyboardType keyboardType = ActiveKeyboardType();
  1040 			TBool IsStokeKey = EFalse;
  1111 			TBool IsStokeKey = EFalse;            
  1041             TRAP_IGNORE(keyboardType = ActiveKeyboardTypeL());
       
  1042              if(EPtiKeyboardQwerty4x10 == keyboardType ||
  1112              if(EPtiKeyboardQwerty4x10 == keyboardType ||
  1043                      EPtiKeyboardQwerty3x11 == keyboardType )
  1113                      EPtiKeyboardQwerty3x11 == keyboardType )
  1044                  {
  1114                  {
  1045                 TBuf<KMaxName> lowerdata;
  1115                 TBuf<KMaxName> lowerdata;
  1046                  TInt StrokeUnicodePosition =0;
  1116                  TInt StrokeUnicodePosition =0;
  2050 	__ASSERT_DEBUG(iCurrentLanguage, User::Panic(KPtiEngineImplPanic, KErrCorrupt));
  2120 	__ASSERT_DEBUG(iCurrentLanguage, User::Panic(KPtiEngineImplPanic, KErrCorrupt));
  2051 	
  2121 	
  2052 	// Predictive QWERTY (XT9) changes ---->
  2122 	// Predictive QWERTY (XT9) changes ---->
  2053 	// PtiXt9Core handles the capitalization it self, and it should not be overriden 
  2123 	// PtiXt9Core handles the capitalization it self, and it should not be overriden 
  2054 	// byt the PtiEngine.
  2124 	// byt the PtiEngine.
  2055 	if ( iInputMode==EPtiEngineQwertyPredictive )
  2125 	if ( IsCurrentCoreSupportCaseInfo() )
  2056 	    {
  2126 	    {
  2057 	    return;
  2127 	    return;
  2058 	    }
  2128 	    }
  2059 	// Predictive QWERTY (XT9) changes <----
  2129 	// Predictive QWERTY (XT9) changes <----
  2060 	
  2130 	
  2655 // 
  2725 // 
  2656 // ---------------------------------------------------------------------------
  2726 // ---------------------------------------------------------------------------
  2657 //
  2727 //
  2658 void CPtiEngineImpl::GetModeNameIndexL(TPtiChineseVariant aVariant, RArray<TInt>& aResult)
  2728 void CPtiEngineImpl::GetModeNameIndexL(TPtiChineseVariant aVariant, RArray<TInt>& aResult)
  2659 	{
  2729 	{
       
  2730 	CleanupClosePushL( aResult );
  2660 	TResourceReader reader;	
  2731 	TResourceReader reader;	
  2661 	TFileName fileName;
  2732 	TFileName fileName;
  2662 
  2733 
  2663 	TParse* fp = new(ELeave) TParse(); 
  2734 	TParse* fp = new(ELeave) TParse(); 
  2664 	fp->Set(KCEResourceFile, &KDC_RESOURCE_FILES_DIR, NULL); 
  2735 	fp->Set(KCEResourceFile, &KDC_RESOURCE_FILES_DIR, NULL); 
  2701 			User::LeaveIfError(aResult.Append(value));
  2772 			User::LeaveIfError(aResult.Append(value));
  2702 			}
  2773 			}
  2703 		}
  2774 		}
  2704 
  2775 
  2705 	CleanupStack::PopAndDestroy(3);   // fsSession, rsFile, rBuffer
  2776 	CleanupStack::PopAndDestroy(3);   // fsSession, rsFile, rBuffer
       
  2777     CleanupStack::Pop();
  2706 	}
  2778 	}
  2707 
  2779 
  2708 
  2780 
  2709 // ---------------------------------------------------------------------------
  2781 // ---------------------------------------------------------------------------
  2710 // CPtiEngineImpl::IsValidKey
  2782 // CPtiEngineImpl::IsValidKey
  2883 // 
  2955 // 
  2884 // ---------------------------------------------------------------------------
  2956 // ---------------------------------------------------------------------------
  2885 //	
  2957 //	
  2886 void CPtiEngineImpl::GetAvailableLanguagesL(RArray<TInt>& aResult)
  2958 void CPtiEngineImpl::GetAvailableLanguagesL(RArray<TInt>& aResult)
  2887 	{
  2959 	{
       
  2960 	CleanupClosePushL( aResult ); 
  2888 	aResult.Reset();
  2961 	aResult.Reset();
  2889 	
  2962 	
  2890 	const TInt count = iLanguages->Count();
  2963 	const TInt count = iLanguages->Count();
  2891 	for (TInt i = 0; i < count; i++)
  2964 	for (TInt i = 0; i < count; i++)
  2892 		{
  2965 		{
       
  2966 	    TInt code = 0;
  2893 		if (iLanguages->At(i)->LanguageCode() != ELangNumeric)
  2967 		if (iLanguages->At(i)->LanguageCode() != ELangNumeric)
  2894 			{
  2968 			{
  2895 			aResult.AppendL(iLanguages->At(i)->LanguageCode());
  2969 		    if(IsRegionalLang(iLanguages->At(i)->LanguageCode(),code))
  2896 			}
  2970 		        {
  2897 		}	
  2971 		        if(AlreadyExistLang(iLanguages,code))
       
  2972 		            {
       
  2973 		            continue;
       
  2974 			        }
       
  2975 		        }	
       
  2976 			aResult.AppendL(code);
       
  2977 		    }	
       
  2978 		}
       
  2979     CleanupStack::Pop();
  2898 	}
  2980 	}
  2899 
  2981 
  2900 
  2982 
  2901 // ---------------------------------------------------------------------------
  2983 // ---------------------------------------------------------------------------
  2902 // CPtiEngineImpl::CreateDefaultUserDictionaryFileL
  2984 // CPtiEngineImpl::CreateDefaultUserDictionaryFileL
  3251 void CPtiEngineImpl::NumericModeKeysForQwertyL(TInt aLanguage,
  3333 void CPtiEngineImpl::NumericModeKeysForQwertyL(TInt aLanguage,
  3252                                                RArray<TPtiNumericKeyBinding>& aResult,
  3334                                                RArray<TPtiNumericKeyBinding>& aResult,
  3253                                                TBool aUseExtendedSet,
  3335                                                TBool aUseExtendedSet,
  3254                                                TPtiKeyboardType aKeyboardType)
  3336                                                TPtiKeyboardType aKeyboardType)
  3255 	{
  3337 	{
       
  3338 	CleanupClosePushL( aResult );
  3256 	aResult.Reset();		
  3339 	aResult.Reset();		
  3257 	TPtiNumericKeyBinding bind;		
  3340 	TPtiNumericKeyBinding bind;		
  3258 	
  3341 	
  3259 	TPtiKeyboardType keyboardType = aKeyboardType;
  3342 	TPtiKeyboardType keyboardType = aKeyboardType;
  3260 	if (keyboardType == EPtiKeyboardNone)
  3343 	if (keyboardType == EPtiKeyboardNone)
  3261 	    {
  3344 	    {
  3262 	    keyboardType = ActiveKeyboardTypeL();
  3345 	    keyboardType = ActiveKeyboardType();
  3263 	    
  3346 	    
  3264 	    if (keyboardType == EPtiKeyboard12Key ||
  3347 	    if (keyboardType == EPtiKeyboard12Key ||
  3265 	        keyboardType == EPtiKeyboardNone)
  3348 	        keyboardType == EPtiKeyboardNone)
  3266 	        {
  3349 	        {
  3267 	        keyboardType = FindFirstAvailableQwertyKeyboardType(aLanguage);	        
  3350 	        keyboardType = FindFirstAvailableQwertyKeyboardType(aLanguage);	        
  3269 	    }		 
  3352 	    }		 
  3270 	
  3353 	
  3271 	if (keyboardType == EPtiKeyboard12Key ||
  3354 	if (keyboardType == EPtiKeyboard12Key ||
  3272 	    keyboardType == EPtiKeyboardNone)
  3355 	    keyboardType == EPtiKeyboardNone)
  3273 	    {
  3356 	    {
       
  3357 		CleanupStack::Pop();
  3274 	    // No qwerty data available, can't go on.
  3358 	    // No qwerty data available, can't go on.
  3275 	    return;
  3359 	    return;
  3276 	    }
  3360 	    }
  3277 	
  3361 	
  3278 	if (aLanguage == ELangJapanese)	
  3362 	if (aLanguage == ELangJapanese)	
  3287 		for (TInt i = 0; i < count; i++)
  3371 		for (TInt i = 0; i < count; i++)
  3288 			{
  3372 			{
  3289 			bind = NumericModeKeysForNonLatinNumberLanguages[i];
  3373 			bind = NumericModeKeysForNonLatinNumberLanguages[i];
  3290 			User::LeaveIfError(aResult.Append(bind));		
  3374 			User::LeaveIfError(aResult.Append(bind));		
  3291 			}	
  3375 			}	
       
  3376 		CleanupStack::Pop();
  3292 		
  3377 		
  3293 		return;			
  3378 		return;			
  3294 		}
  3379 		}
  3295 		
  3380 		
  3296     TPtiEngineInputMode mode = EPtiEngineQwerty;
  3381     TPtiEngineInputMode mode = EPtiEngineQwerty;
  3370                 {
  3455                 {
  3371                 qmappings->SetKeyboardType(origKeyb);
  3456                 qmappings->SetKeyboardType(origKeyb);
  3372                 }				
  3457                 }				
  3373 			}			      
  3458 			}			      
  3374 		}		
  3459 		}		
       
  3460 	CleanupStack::Pop();
  3375 	}	
  3461 	}	
  3376 	
  3462 	
  3377 	
  3463 	
  3378 // ---------------------------------------------------------------------------
  3464 // ---------------------------------------------------------------------------
  3379 // CPtiEngineImpl::GetNumericModeKeysForQwertyL
  3465 // CPtiEngineImpl::GetNumericModeKeysForQwertyL
  3722         {
  3808         {
  3723         return maps->KeyboardType();
  3809         return maps->KeyboardType();
  3724         }
  3810         }
  3725 		    		    
  3811 		    		    
  3726     return EPtiKeyboardNone;*/
  3812     return EPtiKeyboardNone;*/
  3727 	TInt keyboardLayout = 0;
  3813 	TInt keyboardLayout = ActiveKeyboardType();          
  3728     
       
  3729     RProperty::Get(KCRUidAvkon, KAknKeyBoardLayout, keyboardLayout);
       
  3730 
  3814 
  3731     if (keyboardLayout <= 0 ||
  3815     if (keyboardLayout <= 0 ||
  3732         keyboardLayout > EPtiKeyboardMaxLayout - 1)
  3816         keyboardLayout > EPtiKeyboardMaxLayout - 1)
  3733         {
  3817         {
  3734         return EPtiKeyboardNone;
  3818         return EPtiKeyboardNone;
  3815 // ---------------------------------------------------------------------------
  3899 // ---------------------------------------------------------------------------
  3816 //
  3900 //
  3817 void CPtiEngineImpl::KeyboardTypesSupportedByLanguageL(TInt aLanguage,
  3901 void CPtiEngineImpl::KeyboardTypesSupportedByLanguageL(TInt aLanguage,
  3818                                                        RArray<TPtiKeyboardType>& aResult)
  3902                                                        RArray<TPtiKeyboardType>& aResult)
  3819     {
  3903     {
       
  3904 	CleanupClosePushL( aResult );
  3820     CPtiCoreLanguage* lang = NULL;
  3905     CPtiCoreLanguage* lang = NULL;
  3821     
  3906     
  3822     if (iCurrentLanguage && iCurrentLanguage->LanguageCode() == aLanguage)
  3907     if (iCurrentLanguage && iCurrentLanguage->LanguageCode() == aLanguage)
  3823         {
  3908         {
  3824         lang = iCurrentLanguage;
  3909         lang = iCurrentLanguage;
  3876             hmaps->KeyMapData()->KeyData(EPtiKeyboardHalfQwerty, tmpSize))
  3961             hmaps->KeyMapData()->KeyData(EPtiKeyboardHalfQwerty, tmpSize))
  3877             {
  3962             {
  3878             User::LeaveIfError(aResult.Append(EPtiKeyboardHalfQwerty));
  3963             User::LeaveIfError(aResult.Append(EPtiKeyboardHalfQwerty));
  3879             }            
  3964             }            
  3880         }                
  3965         }                
       
  3966     CleanupStack::Pop();
  3881     }
  3967     }
  3882 
  3968 
  3883 
  3969 
  3884 // ---------------------------------------------------------------------------
  3970 // ---------------------------------------------------------------------------
  3885 // CPtiEngineImpl::ActiveKeyboardTypeL
  3971 // CPtiEngineImpl::ActiveKeyboardType
  3886 // 
  3972 // 
  3887 // ---------------------------------------------------------------------------
  3973 // ---------------------------------------------------------------------------
  3888 //
  3974 //
  3889 TPtiKeyboardType CPtiEngineImpl::ActiveKeyboardTypeL()
  3975 TPtiKeyboardType CPtiEngineImpl::ActiveKeyboardType() const
  3890     {    
  3976     {    
  3891     // Qwerty Keyboard layout
  3977 	TInt keyboardType = EPtiKeyboardNone;
  3892     TInt keyboardLayout = 0;
  3978 #ifdef RD_SCALABLE_UI_V2
  3893     
  3979 	// Get physical keyboard type
  3894     RProperty::Get(KCRUidAvkon, KAknKeyBoardLayout, keyboardLayout);
  3980 	RProperty::Get(KCRUidAvkon, KAknKeyBoardLayout, keyboardType );
  3895 
  3981 
  3896     if (keyboardLayout <= 0 ||
  3982 	// When active keyboard is virtual keyboard, 
  3897         keyboardLayout > EPtiKeyboardMaxLayout - 1)
  3983 	// need to get the active virtual keyboard type 
  3898         {
  3984 	// and set keyboardType again.
  3899         return EPtiKeyboardNone;
  3985 	
  3900         }
  3986 	// When the default physical keyboard is 0, 
  3901         
  3987 	// it means that there is no physical keyboard,
  3902     return (TPtiKeyboardType)keyboardLayout;
  3988 	// also need to get the active virtual keyboard type.
       
  3989 	TInt isQwertyOn = 0;
       
  3990 	RProperty::Get(KCRUidAvkon, KAknQwertyInputModeActive, isQwertyOn);	
       
  3991 	TInt isVirtualInputActive = 0;
       
  3992 	RProperty::Get( KPSUidAknFep, KAknFepTouchInputActive, 
       
  3993 					isVirtualInputActive );    
       
  3994 	if (( isVirtualInputActive > 0 || keyboardType == 0) && !isQwertyOn)
       
  3995 		{
       
  3996 		// Active keyboard is virtual keyboard          
       
  3997 		RProperty::Get( KPSUidAknFep, KAknFepVirtualKeyboardType, 
       
  3998 						keyboardType );      
       
  3999 		}
       
  4000 #else
       
  4001 	// Get physical keyboard type
       
  4002 	RProperty::Get(KCRUidAvkon, KAknKeyBoardLayout, keyboardType );	    
       
  4003 #endif
       
  4004 
       
  4005 	if ( keyboardType <= 0 || keyboardType >= EPtiKeyboardMaxLayout )
       
  4006 		{
       
  4007 	    keyboardType = EPtiKeyboardNone;
       
  4008 		}        
       
  4009 	return (TPtiKeyboardType)keyboardType;
  3903     }
  4010     }
  3904 
       
  3905         
  4011         
  3906 // ---------------------------------------------------------------------------
  4012 // ---------------------------------------------------------------------------
  3907 // CPtiEngineImpl::GetNumericModeKeysForQwertyL
  4013 // CPtiEngineImpl::GetNumericModeKeysForQwertyL
  3908 // 
  4014 // 
  3909 // ---------------------------------------------------------------------------
  4015 // ---------------------------------------------------------------------------
  4211                 
  4317                 
  4212         return err;    
  4318         return err;    
  4213     
  4319     
  4214     }
  4320     }
  4215 #endif //FF_DUAL_LANGUAGE_SUPPORT
  4321 #endif //FF_DUAL_LANGUAGE_SUPPORT
       
  4322 TBool CPtiEngineImpl::IsCurrentCoreSupportCaseInfo()
       
  4323     {
       
  4324     if ( Core() )
       
  4325         {
       
  4326         if ( Core()->GetCoreInfo()->Uid() == KXt9ImplementationUid.iUid )
       
  4327             {
       
  4328             return ETrue;
       
  4329             }
       
  4330         }
       
  4331     return EFalse;
       
  4332     }
  4216 // End of file
  4333 // End of file
  4217 
  4334