predictivesearch/PcsAlgorithm/Algorithm2/src/CPcsKeyMap.cpp
changeset 0 e686773b3f54
child 7 b3431bff8c19
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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:  Retrieves the character map for each of the numeric keys.
       
    15 *                Uses services provided by the PTI Engine.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "CPcsAlgorithm2.h"
       
    22 #include "FindUtilChineseECE.h"
       
    23 #include "CPcsDebug.h"
       
    24 #include "CPcsKeyMap.h"
       
    25 #include <bldvariant.hrh>
       
    26 #include <AknFepInternalCRKeys.h>
       
    27 
       
    28 // ============================== MEMBER FUNCTIONS ============================
       
    29 
       
    30 // ----------------------------------------------------------------------------
       
    31 // CPcsKeyMap::NewL
       
    32 // Two Phase Construction
       
    33 // ----------------------------------------------------------------------------
       
    34 CPcsKeyMap* CPcsKeyMap::NewL(CPcsAlgorithm2* aAlgorithm)
       
    35     {
       
    36     PRINT ( _L("Enter CPcsKeyMap::NewL") );
       
    37 
       
    38     CPcsKeyMap* self = new (ELeave) CPcsKeyMap();
       
    39     CleanupStack::PushL(self);
       
    40     self->ConstructL(aAlgorithm);
       
    41     CleanupStack::Pop(self);
       
    42 
       
    43     PRINT ( _L("End CPcsKeyMap::NewL") );
       
    44 
       
    45     return self;
       
    46     }
       
    47 
       
    48 // ----------------------------------------------------------------------------
       
    49 // CPcsKeyMap::CPcsKeyMap
       
    50 // Constructor
       
    51 // ----------------------------------------------------------------------------
       
    52 CPcsKeyMap::CPcsKeyMap()
       
    53     {
       
    54     }
       
    55 
       
    56 // ----------------------------------------------------------------------------
       
    57 // CPcsKeyMap::ConstructL
       
    58 // 2nd Phase Constructor
       
    59 // ----------------------------------------------------------------------------
       
    60 void CPcsKeyMap::ConstructL(CPcsAlgorithm2* aAlgorithm)
       
    61     {
       
    62     iLanguageNotSupported.Append(ELangJapanese);
       
    63 
       
    64     iAlgorithm = aAlgorithm;
       
    65     iPtiEngine = CPtiEngine::NewL();
       
    66 	
       
    67     ConstructKeymapL();
       
    68     }
       
    69 
       
    70 // ----------------------------------------------------------------------------
       
    71 // CPcsKeyMap::ReconstructKeymapL
       
    72 // When the writing language is changed, the keymap needs reconstruct.
       
    73 // ----------------------------------------------------------------------------
       
    74 void CPcsKeyMap::ReconstructKeymapL()
       
    75     {
       
    76     TLanguage lang = iAlgorithm->FindUtilECE()->CurrentInputLanguage();
       
    77         if (lang == ELangPrcChinese || !IsLanguageSupportedL(lang))
       
    78             lang = ELangEnglish;
       
    79 
       
    80     TInt keyboardType = CurrentKeyBoardTypeL();
       
    81     
       
    82     // Clear the keymap data array first when reconstruct the keymap.
       
    83     ResetKeyMap();
       
    84     
       
    85     // Add new keymap to the keymap data array according the current writing language.
       
    86     AddKeyMapforConcreteKeyboardL( keyboardType, lang );
       
    87     }
       
    88 
       
    89 // ----------------------------------------------------------------------------
       
    90 // CPcsKeyMap::ConstructKeymapL
       
    91 // 
       
    92 // ----------------------------------------------------------------------------
       
    93 void CPcsKeyMap::ConstructKeymapL()
       
    94     {
       
    95     TLanguage lang = iAlgorithm->FindUtilECE()->CurrentInputLanguage();
       
    96     if (lang == ELangPrcChinese || !IsLanguageSupportedL(lang))
       
    97         lang = ELangEnglish;
       
    98 
       
    99     TInt keyboardType = CurrentKeyBoardTypeL();
       
   100     
       
   101     ConstructConcreteKeyMapL( keyboardType, lang );
       
   102     
       
   103     PRINT ( _L("----------------------------------------"));
       
   104     
       
   105     }
       
   106 
       
   107 // ----------------------------------------------------------------------------
       
   108 // CPcsKeyMap::CurrentKeyBoardTypeL
       
   109 // 
       
   110 // ----------------------------------------------------------------------------
       
   111 TInt CPcsKeyMap::CurrentKeyBoardTypeL()
       
   112     {
       
   113     TInt keyBoardType = EPtiKeyboardNone;
       
   114     
       
   115 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   116     
       
   117     TInt physicalKeyboard = 0;
       
   118     CRepository* aknFepRepository = CRepository::NewL( KCRUidAknFep );
       
   119     // Get all the physical keyboards which are connected to the phone currently.
       
   120     aknFepRepository->Get( KAknFepPhysicalKeyboards, physicalKeyboard );
       
   121     delete aknFepRepository;
       
   122     
       
   123     
       
   124     PRINT1 ( _L("CPcsKeyMap::CurrentKeyBoardTypeL: Physical keyboard support flag = 0x%02X"), physicalKeyboard );
       
   125 
       
   126     // Constants follow the definition of KAknFepPhysicalKeyboards
       
   127     const TInt ptiKeyboard12Key = 0x01;         // Default
       
   128     // const TInt ptiKeyboardQwerty4x12 = 0x02;    // Not used at the moment
       
   129     const TInt ptiKeyboardQwerty4x10 = 0x04;
       
   130     // const TInt ptiKeyboardQwerty3x11 = 0x08;    // Not used at the moment
       
   131     const TInt ptiKeyboardHalfQwerty = 0x10;
       
   132     // const TInt ptiKeyboardCustomQwerty = 0x20;  // Not used at the moment
       
   133 
       
   134     // If there are more than 1 keyboards on HW, The priority from high to low for 
       
   135     // selecting keyboard is EPtiKeyboard12Key, EPtiKeyboardHalfQwerty, EPtiKeyboardQwerty4x10  
       
   136     if ( physicalKeyboard & ptiKeyboard12Key )
       
   137         {
       
   138         keyBoardType = EPtiKeyboard12Key;
       
   139         }
       
   140     else if ( physicalKeyboard & ptiKeyboardHalfQwerty )
       
   141         {
       
   142         keyBoardType = EPtiKeyboardHalfQwerty;
       
   143         }
       
   144     else if ( physicalKeyboard & ptiKeyboardQwerty4x10 )
       
   145         {
       
   146         keyBoardType = EPtiKeyboardQwerty4x10;
       
   147         }
       
   148     else
       
   149 #endif
       
   150         {
       
   151         keyBoardType = EPtiKeyboard12Key;
       
   152         }
       
   153     return keyBoardType;
       
   154     }
       
   155 
       
   156 // ----------------------------------------------------------------------------
       
   157 // CPcsKeyMap::ConstructConcreteKeyMapL
       
   158 // 
       
   159 // ----------------------------------------------------------------------------
       
   160 void CPcsKeyMap::ConstructConcreteKeyMapL( TInt aKeyboardType, TLanguage aLanguage )
       
   161     {
       
   162     switch ( aKeyboardType )
       
   163         {
       
   164         case EPtiKeyboard12Key:
       
   165             {
       
   166             // Construct for Itut keyboard by default
       
   167             PRINT ( _L("CPcsKeyMap::ConstructConcreteKeyMapL: Construct keymap for ContructForItutKeyboardL"));
       
   168             
       
   169             ContructForItutKeyboardL( aLanguage );
       
   170             break;
       
   171             }
       
   172         case EPtiKeyboardHalfQwerty:
       
   173             {
       
   174             // Construct for Half Qwerty keyboard
       
   175             PRINT ( _L("CPcsKeyMap::ConstructConcreteKeyMapL: Construct keymap for ContructForHalfQwertyKeyboardL"));
       
   176             
       
   177             ContructForHalfQwertyKeyboardL( aLanguage );
       
   178             break;
       
   179             }
       
   180         case EPtiKeyboardQwerty4x10:
       
   181             {
       
   182             // Construct for 4x10 Qwerty keyboard
       
   183             PRINT ( _L("CPcsKeyMap::ConstructConcreteKeyMapL: Construct keymap for ContructFor4x10QwertyKeyboardL"));
       
   184             
       
   185             ContructFor4x10QwertyKeyboardL( aLanguage );
       
   186             break;
       
   187             }
       
   188         default:
       
   189             {
       
   190             // Construct for Itut keyboard
       
   191             PRINT ( _L("CPcsKeyMap::ConstructConcreteKeyMapL: Construct keymap for ContructForItutKeyboardL"));
       
   192             
       
   193             ContructForItutKeyboardL( aLanguage );
       
   194             }
       
   195         }
       
   196     }
       
   197 
       
   198 // ----------------------------------------------------------------------------
       
   199 // CPcsKeyMap::AddKeyMapforConcreteKeyboardL
       
   200 // 
       
   201 // ----------------------------------------------------------------------------
       
   202 void CPcsKeyMap::AddKeyMapforConcreteKeyboardL( TInt aKeyboardType, TLanguage aLanguage )
       
   203     {
       
   204     // If it's TW or HK variant, the key map for English also needs add to current key map.
       
   205     TBool needAddEnglishKeyMap = ( aLanguage == ELangTaiwanChinese || aLanguage == ELangHongKongChinese );
       
   206     
       
   207     // Add the keymap for current writing language.
       
   208     switch ( aKeyboardType )
       
   209         {
       
   210         case EPtiKeyboard12Key:
       
   211             {
       
   212             AddKeyMapforItutL( aLanguage );
       
   213             if ( needAddEnglishKeyMap )
       
   214                 {
       
   215                 AddKeyMapforItutL( ELangEnglish );
       
   216                 }
       
   217             break;
       
   218             }
       
   219         case EPtiKeyboardHalfQwerty:
       
   220             {
       
   221             AddKeyMapforHalfQwertyKeyboardL( aLanguage );
       
   222             if ( needAddEnglishKeyMap )
       
   223                 {
       
   224                 AddKeyMapforHalfQwertyKeyboardL( ELangEnglish );
       
   225                 }
       
   226             break;
       
   227             }
       
   228         case EPtiKeyboardQwerty4x10:
       
   229             {
       
   230             AddKeyMapfor4x10QwertyKeyboardL( aLanguage );
       
   231             if ( needAddEnglishKeyMap )
       
   232                 {
       
   233                 AddKeyMapfor4x10QwertyKeyboardL( ELangEnglish );
       
   234                 }
       
   235             break;
       
   236             }
       
   237         default:
       
   238             {
       
   239             AddKeyMapforItutL( aLanguage );
       
   240             if ( needAddEnglishKeyMap )
       
   241                 {
       
   242                 AddKeyMapforItutL( ELangEnglish );
       
   243                 }
       
   244             }
       
   245         }
       
   246     }
       
   247 
       
   248 // ----------------------------------------------------------------------------
       
   249 // CPcsKeyMap::ResetKeyMap
       
   250 // 
       
   251 // ----------------------------------------------------------------------------
       
   252 void CPcsKeyMap::ResetKeyMap()
       
   253     {
       
   254     for (TInt i = 0; i < iAllKeyMappingsPtrArr.Count(); i++)
       
   255         {
       
   256         iAllKeyMappingsPtrArr[i]->iKeyMappingArray.Close();
       
   257         }
       
   258 
       
   259     }
       
   260 // ----------------------------------------------------------------------------
       
   261 // CPcsKeyMap::~CPcsKeyMap
       
   262 // Destructor
       
   263 // ----------------------------------------------------------------------------
       
   264 CPcsKeyMap::~CPcsKeyMap()
       
   265     {
       
   266     ResetKeyMap();
       
   267 
       
   268     // Cleanup local arrays
       
   269     iLanguageNotSupported.Reset();
       
   270     iAllKeyMappingsPtrArr.ResetAndDestroy();
       
   271     iKeysForPoolFormation.Close();
       
   272     delete iPtiEngine;
       
   273     }
       
   274 
       
   275 // ----------------------------------------------------------------------------
       
   276 // CPcsKeyMap::GetNumericKeyStringL
       
   277 // 
       
   278 // ----------------------------------------------------------------------------
       
   279 void CPcsKeyMap::GetNumericKeyString(const TDesC& aSrcStr, TDes& aDestStr)
       
   280     {
       
   281     for (int i = 0; i < aSrcStr.Length(); i++)
       
   282         {
       
   283         TInt index = KeyForCharacter(aSrcStr[i]);
       
   284 
       
   285         // If a character is not mapped to numeric key append the character
       
   286         if (index == -1)
       
   287             {
       
   288             aDestStr.Append(aSrcStr[i]);
       
   289             }
       
   290         else
       
   291             {
       
   292             aDestStr.Append(index);
       
   293             }
       
   294         }
       
   295     }
       
   296 
       
   297 // ----------------------------------------------------------------------------
       
   298 // CPcsKeyMap::KeyForCharacter
       
   299 // 
       
   300 // ----------------------------------------------------------------------------
       
   301 TInt CPcsKeyMap::KeyForCharacter(const TChar& aChar)
       
   302     {
       
   303     TInt index = KErrNotFound;
       
   304 
       
   305     TChar lChar = User::LowerCase(aChar);
       
   306 
       
   307     TInt count = iAllKeyMappingsPtrArr.Count() - 1;
       
   308 
       
   309     for (TInt i = 0; i < count; i++)
       
   310         {
       
   311         index = iAllKeyMappingsPtrArr[i]->iKeyMappingArray.Find(lChar);
       
   312         if (index != KErrNotFound)
       
   313             {
       
   314             return (TInt) iAllKeyMappingsPtrArr[i]->key;
       
   315             }
       
   316         }
       
   317 
       
   318     return index;
       
   319     }
       
   320 // ----------------------------------------------------------------------------
       
   321 // CPcsKeyMap::ContructForHalfQwertyKeyboardL
       
   322 // 
       
   323 // ----------------------------------------------------------------------------
       
   324 void CPcsKeyMap::ContructForHalfQwertyKeyboardL(TLanguage aLanguage)
       
   325     {
       
   326 #ifdef RD_INTELLIGENT_TEXT_INPUT    
       
   327 
       
   328     iKeysForPoolFormation.Append(EPtiKeyQwertyQ);
       
   329     iKeysForPoolFormation.Append(EPtiKeyQwertyE);
       
   330     iKeysForPoolFormation.Append(EPtiKeyQwertyT);
       
   331     iKeysForPoolFormation.Append(EPtiKeyQwertyU);
       
   332     iKeysForPoolFormation.Append(EPtiKeyQwertyO);
       
   333     iKeysForPoolFormation.Append(EPtiKeyQwertyA);
       
   334     iKeysForPoolFormation.Append(EPtiKeyQwertyD);
       
   335     iKeysForPoolFormation.Append(EPtiKeyQwertyG);
       
   336     iKeysForPoolFormation.Append(EPtiKeyQwertyJ);
       
   337     iKeysForPoolFormation.Append(EPtiKeyQwertyL);
       
   338     iKeysForPoolFormation.Append(EPtiKeyQwertyZ);
       
   339     iKeysForPoolFormation.Append(EPtiKeyQwertyC);
       
   340     iKeysForPoolFormation.Append(EPtiKeyQwertyB);
       
   341     iKeysForPoolFormation.Append(EPtiKeyQwertyM);
       
   342     iKeysForPoolFormation.Append(EPtiKeyQwerty0);
       
   343     // one additional pool for special characters not mapped too any keys. 
       
   344     // This should always be the last one in the arrary
       
   345     iKeysForPoolFormation.Append(EPtiKeyNone);
       
   346 
       
   347     // Now add the keymap arrays to hold the keymap data
       
   348     for (TInt i = 0; i < iKeysForPoolFormation.Count(); i++)
       
   349         {
       
   350         TKeyMappingData *keyData = new (ELeave) TKeyMappingData;
       
   351         keyData->key = iKeysForPoolFormation[i];
       
   352         iAllKeyMappingsPtrArr.Append(keyData);
       
   353         }
       
   354     //  Add the keymap for current language
       
   355     AddKeyMapforHalfQwertyKeyboardL(aLanguage);
       
   356 
       
   357     // If it's TW or HK variant, add the keymap for English language
       
   358     if (aLanguage == ELangTaiwanChinese || aLanguage == ELangHongKongChinese)
       
   359         {
       
   360         AddKeyMapforHalfQwertyKeyboardL(ELangEnglish);
       
   361         }
       
   362 
       
   363     PRINT ( _L("----------------------------------------"));
       
   364 #endif // RD_INTELLIGENT_TEXT_INPUT
       
   365     }
       
   366 // ----------------------------------------------------------------------------
       
   367 // CPcsKeyMap::AddKeyMapforHalfQwertyKeyboardL
       
   368 // 
       
   369 // ----------------------------------------------------------------------------
       
   370 void CPcsKeyMap::AddKeyMapforHalfQwertyKeyboardL(TLanguage aLanguage)
       
   371     {
       
   372 #ifdef RD_INTELLIGENT_TEXT_INPUT     	
       
   373     // Make a language object based on current language
       
   374     CPtiCoreLanguage* iCoreLanguage = static_cast<CPtiCoreLanguage*>(iPtiEngine->GetLanguage(  aLanguage));
       
   375 
       
   376     //Perfrom the key mappings only if the corelanguage is available
       
   377     if (iCoreLanguage)
       
   378         {
       
   379         // Get the keyboard mappings for the language
       
   380         CPtiHalfQwertyKeyMappings* ptiKeyMappings = static_cast<CPtiHalfQwertyKeyMappings*> 
       
   381                 (iCoreLanguage->GetHalfQwertyKeymappings());
       
   382 
       
   383         iPtiEngine->ActivateLanguageL(aLanguage, EPtiEngineHalfQwerty);
       
   384         iPtiEngine->SetKeyboardType(EPtiKeyboardHalfQwerty);
       
   385 
       
   386         for (TInt i = 0; i < iAllKeyMappingsPtrArr.Count() - 1; i++)
       
   387             {
       
   388             AddDataForHalfQwertyKeyboardL( ptiKeyMappings, iKeysForPoolFormation[i], *(iAllKeyMappingsPtrArr[i]));
       
   389             }
       
   390         }
       
   391 #endif // RD_INTELLIGENT_TEXT_INPUT        
       
   392     }
       
   393 
       
   394 // ----------------------------------------------------------------------------
       
   395 // CPcsKeyMap::AddDataForHalfQwertyKeyboardL
       
   396 // 
       
   397 // ----------------------------------------------------------------------------
       
   398 void CPcsKeyMap::AddDataForHalfQwertyKeyboardL( CPtiHalfQwertyKeyMappings* aPtiKeyMappings, 
       
   399                                                TPtiKey aKey,  
       
   400                                                TKeyMappingData& aKeyDataList)
       
   401     {
       
   402 #ifdef RD_INTELLIGENT_TEXT_INPUT     	
       
   403     TPtiTextCase caseArray[] =
       
   404         {
       
   405         EPtiCaseUpper,
       
   406         EPtiCaseLower,
       
   407         EPtiCaseFnLower,
       
   408         EPtiCaseFnUpper,
       
   409         EPtiCaseChrLower,
       
   410         EPtiCaseChrUpper
       
   411         };
       
   412     
       
   413     TBuf<50> iResult;
       
   414     for (int i = 0; i < sizeof(caseArray) / sizeof(TPtiTextCase); i++)
       
   415         {
       
   416         iResult.Zero();
       
   417         aPtiKeyMappings->GetDataForKey(aKey, iResult, caseArray[i]);
       
   418 
       
   419         for (int j = 0; j < iResult.Length(); j++)
       
   420             aKeyDataList.iKeyMappingArray.Append(iResult[j]);
       
   421 
       
   422         PRINT2 ( _L("CPcsKeyMap: Mapping for Key %c = %S"), aKey,&iResult)
       
   423         }
       
   424 #endif // RD_INTELLIGENT_TEXT_INPUT        
       
   425     }
       
   426 
       
   427 // ----------------------------------------------------------------------------
       
   428 // CPcsKeyMap::ContructFor4x10QwertyKeyboardL
       
   429 // Destructor
       
   430 // ----------------------------------------------------------------------------
       
   431 void CPcsKeyMap::ContructFor4x10QwertyKeyboardL(TLanguage aLanguage)
       
   432     {
       
   433 #ifdef RD_INTELLIGENT_TEXT_INPUT     
       
   434 // The special 4x10 Qwerty keyboard for Sonja.
       
   435     iKeysForPoolFormation.Append( EPtiKeyQwertyA );
       
   436     iKeysForPoolFormation.Append( EPtiKeyQwerty8 );
       
   437     iKeysForPoolFormation.Append( EPtiKeyQwertyC );
       
   438     iKeysForPoolFormation.Append( EPtiKeyQwertyD );
       
   439     iKeysForPoolFormation.Append( EPtiKeyQwertyE );
       
   440     iKeysForPoolFormation.Append( EPtiKeyQwerty4 );
       
   441     iKeysForPoolFormation.Append( EPtiKeyQwerty5 );
       
   442     iKeysForPoolFormation.Append( EPtiKeyQwerty6 );
       
   443     iKeysForPoolFormation.Append( EPtiKeyQwertyI );
       
   444     iKeysForPoolFormation.Append( EPtiKeyQwertyHash ); // Could have been EPtiKeyQwertyJ, EPtiKeyHash
       
   445     iKeysForPoolFormation.Append( EPtiKeyQwertyK );
       
   446     iKeysForPoolFormation.Append( EPtiKeyQwertyL );
       
   447     iKeysForPoolFormation.Append( EPtiKeyQwerty0 );
       
   448     iKeysForPoolFormation.Append( EPtiKeyQwerty9 );
       
   449     iKeysForPoolFormation.Append( EPtiKeyQwertyO );
       
   450     iKeysForPoolFormation.Append( EPtiKeyQwertyP );
       
   451     iKeysForPoolFormation.Append( EPtiKeyQwertyQ );
       
   452     iKeysForPoolFormation.Append( EPtiKeyQwerty1 );
       
   453     iKeysForPoolFormation.Append( EPtiKeyQwertyS );
       
   454     iKeysForPoolFormation.Append( EPtiKeyQwerty2 );
       
   455     iKeysForPoolFormation.Append( EPtiKeyStar );    // Could have been EPtiKeyQwertyU
       
   456     iKeysForPoolFormation.Append( EPtiKeyQwertyV );    // Could have been EPtiKeyQwerty7
       
   457     iKeysForPoolFormation.Append( EPtiKeyQwertyW );
       
   458     iKeysForPoolFormation.Append( EPtiKeyQwertyX );
       
   459     iKeysForPoolFormation.Append( EPtiKeyQwerty3 );
       
   460     iKeysForPoolFormation.Append( EPtiKeyQwertyZ );
       
   461     
       
   462     // one additional pool for special characters not mapped too any keys. 
       
   463     // This should always be the last one in the arrary
       
   464     iKeysForPoolFormation.Append(EPtiKeyNone);
       
   465 
       
   466     // Now add the keymap arrays to hold the keymap data
       
   467     for (TInt i = 0; i < iKeysForPoolFormation.Count(); i++)
       
   468         {
       
   469         TKeyMappingData *keyData = new (ELeave) TKeyMappingData;
       
   470         keyData->key = iKeysForPoolFormation[i];
       
   471         iAllKeyMappingsPtrArr.Append(keyData);
       
   472         }
       
   473 
       
   474     //  Add the keymap for current language
       
   475     AddKeyMapfor4x10QwertyKeyboardL(aLanguage);
       
   476 
       
   477     // If it's TW or HK variant, add the keymap for English language
       
   478     if (aLanguage == ELangTaiwanChinese || aLanguage == ELangHongKongChinese)
       
   479         {
       
   480         AddKeyMapfor4x10QwertyKeyboardL(ELangEnglish);
       
   481         }
       
   482 
       
   483     PRINT ( _L("----------------------------------------"));
       
   484 #endif //RD_INTELLIGENT_TEXT_INPUT
       
   485     }
       
   486 
       
   487 // ----------------------------------------------------------------------------
       
   488 // CPcsKeyMap::AddKeyMapfor4x10QwertyKeyboardL
       
   489 // 
       
   490 // ----------------------------------------------------------------------------
       
   491 void CPcsKeyMap::AddKeyMapfor4x10QwertyKeyboardL(TLanguage aLanguage)
       
   492     {
       
   493 #ifdef RD_INTELLIGENT_TEXT_INPUT     	
       
   494     // Make a language object based on current language
       
   495     CPtiCoreLanguage* iCoreLanguage = static_cast<CPtiCoreLanguage*>(iPtiEngine->GetLanguage(aLanguage));
       
   496 
       
   497     //Perfrom the key mappings only if the corelanguage is available
       
   498     if (iCoreLanguage)
       
   499         {
       
   500         // Get the keyboard mappings for the language
       
   501         CPtiQwertyKeyMappings* iPtiKeyMappings = static_cast<CPtiQwertyKeyMappings *> 
       
   502                 (iCoreLanguage->GetQwertyKeymappings());
       
   503         iPtiEngine->SetKeyboardType(EPtiKeyboardQwerty4x10);
       
   504 
       
   505         for (TInt i = 0; i < iAllKeyMappingsPtrArr.Count() - 1; i++)
       
   506             {
       
   507             AddDataFor4x10QwertyKeyboardL(iPtiKeyMappings, iKeysForPoolFormation[i], *(iAllKeyMappingsPtrArr[i]));
       
   508             }
       
   509 
       
   510 #ifdef HACK_FOR_E72_J_KEY
       
   511         AddDataFor4x10QwertyKeyboardE72HackL();
       
   512 #endif // HACK_FOR_E72_J_KEY
       
   513         }
       
   514 #endif //RD_INTELLIGENT_TEXT_INPUT        
       
   515 
       
   516     }
       
   517 
       
   518 #ifdef HACK_FOR_E72_J_KEY
       
   519 // ----------------------------------------------------------------------------
       
   520 // CPcsKeyMap::AddDataFor4x10QwertyKeyboardE72HackL
       
   521 //
       
   522 // Key code for J/# key in Sonja is EPtiKeyQwertyHash (127).
       
   523 // No returned character code ('J', 'j', '#') has 127 as ASCII value.
       
   524 // In this case we must add key to the list of characters for the pool.
       
   525 // ----------------------------------------------------------------------------
       
   526 void CPcsKeyMap::AddDataFor4x10QwertyKeyboardE72HackL()
       
   527     {
       
   528 #ifdef RD_INTELLIGENT_TEXT_INPUT    
       
   529     PRINT ( _L("Enter CPcsKeyMap::AddDataFor4x10QwertyKeyboardE72HackL") );
       
   530 
       
   531     TPtiKey keyValue = (TPtiKey) EPtiKeyQwertyHash;
       
   532     TInt keyIndex = iKeysForPoolFormation.Find(keyValue);    
       
   533 
       
   534     PRINT3 ( _L("CPcsKeyMap: ===== At index %d appending key to list: '%c' (#%d) -Hack-for-E72-"),
       
   535              keyIndex, (TInt) keyValue, (TInt) keyValue);
       
   536 
       
   537     if ( KErrNotFound != keyIndex )
       
   538         {
       
   539         iAllKeyMappingsPtrArr[keyIndex]->iKeyMappingArray.Append(keyValue);
       
   540         }
       
   541 
       
   542     PRINT ( _L("CPcsKeyMap: ===================================================") );  
       
   543 
       
   544     PRINT ( _L("End CPcsKeyMap::AddDataFor4x10QwertyKeyboardE72HackL") );
       
   545 #endif // RD_INTELLIGENT_TEXT_INPUT    
       
   546     }
       
   547 #endif // HACK_FOR_E72_J_KEY
       
   548 
       
   549 // ----------------------------------------------------------------------------
       
   550 // CPcsKeyMap::AddDataFor4x10QwertyKeyboardL
       
   551 // 
       
   552 // ----------------------------------------------------------------------------
       
   553 void CPcsKeyMap::AddDataFor4x10QwertyKeyboardL(CPtiQwertyKeyMappings* iPtiKeyMappings, 
       
   554                                                TPtiKey aKey,  
       
   555                                                TKeyMappingData& aKeyDataList)
       
   556     {
       
   557 #ifdef RD_INTELLIGENT_TEXT_INPUT     	
       
   558     TPtiTextCase caseArray[] =
       
   559             {
       
   560             EPtiCaseUpper,
       
   561             EPtiCaseLower,
       
   562             EPtiCaseFnLower,
       
   563             EPtiCaseFnUpper,
       
   564             EPtiCaseChrLower,
       
   565             EPtiCaseChrUpper
       
   566             };
       
   567         
       
   568     TBuf<50> iResult;
       
   569     for (int i = 0; i < sizeof(caseArray) / sizeof(TPtiTextCase); i++)
       
   570         {
       
   571         iResult.Zero();
       
   572         iPtiKeyMappings->GetDataForKey(aKey, iResult, caseArray[i]);
       
   573 
       
   574         for (int j = 0; j < iResult.Length(); j++)
       
   575             aKeyDataList.iKeyMappingArray.Append(iResult[j]);
       
   576 
       
   577         PRINT2 ( _L("CPcsKeyMap: Mapping for Key %c = %S"), aKey, &iResult)
       
   578         }
       
   579 #endif //RD_INTELLIGENT_TEXT_INPUT        
       
   580     }
       
   581 
       
   582 // ----------------------------------------------------------------------------
       
   583 // CPcsKeyMap::ContructForItutKeyboardL
       
   584 // 
       
   585 // ----------------------------------------------------------------------------
       
   586 void CPcsKeyMap::ContructForItutKeyboardL(TLanguage aLanguage)
       
   587     {
       
   588     // Add the keys for Pool formation
       
   589     iKeysForPoolFormation.Append(EPtiKey0);
       
   590     iKeysForPoolFormation.Append(EPtiKey1);
       
   591     iKeysForPoolFormation.Append(EPtiKey2);
       
   592     iKeysForPoolFormation.Append(EPtiKey3);
       
   593     iKeysForPoolFormation.Append(EPtiKey4);
       
   594     iKeysForPoolFormation.Append(EPtiKey5);
       
   595     iKeysForPoolFormation.Append(EPtiKey6);
       
   596     iKeysForPoolFormation.Append(EPtiKey7);
       
   597     iKeysForPoolFormation.Append(EPtiKey8);
       
   598     iKeysForPoolFormation.Append(EPtiKey9);
       
   599     // one additional pool for special characters not mapped too any keys. 
       
   600     // This should always be the last one in the arrary
       
   601     iKeysForPoolFormation.Append(EPtiKeyNone);
       
   602 
       
   603     // Now add the keymap arrays to hold the keymap data
       
   604     for (TInt i = 0; i < iKeysForPoolFormation.Count(); i++)
       
   605         {
       
   606         TKeyMappingData *keyData = new (ELeave) TKeyMappingData;
       
   607         keyData->key = iKeysForPoolFormation[i];
       
   608         iAllKeyMappingsPtrArr.Append(keyData);
       
   609         }
       
   610 
       
   611     //  Add the keymap for current language
       
   612     AddKeyMapforItutL(aLanguage);
       
   613 
       
   614     // If it's TW or HK variant, add the keymap for English language
       
   615     if (aLanguage == ELangTaiwanChinese || aLanguage == ELangHongKongChinese)
       
   616         {
       
   617         AddKeyMapforItutL(ELangEnglish);
       
   618         }
       
   619 
       
   620     PRINT ( _L("----------------------------------------"));
       
   621 
       
   622     }
       
   623 
       
   624 // ----------------------------------------------------------------------------
       
   625 // CPcsKeyMap::AddKeyMapforItutLanguageL
       
   626 // 
       
   627 // ----------------------------------------------------------------------------
       
   628 void CPcsKeyMap::AddKeyMapforItutL(TLanguage aLanguage)
       
   629     {
       
   630     // Make a language object based on current language
       
   631     CPtiCoreLanguage* iCoreLanguage = static_cast<CPtiCoreLanguage*> (iPtiEngine->GetLanguage(aLanguage));
       
   632 
       
   633     //Perfrom the key mappings only if the corelanguage is available
       
   634     if (iCoreLanguage)
       
   635         {
       
   636         // Get the keyboard mappings for the language
       
   637         CPtiKeyMappings* iPtiKeyMappings =  static_cast<CPtiKeyMappings*> 
       
   638                 (iCoreLanguage->GetKeymappings());
       
   639 
       
   640         for (TInt i = 0; i < iAllKeyMappingsPtrArr.Count() - 1; i++)
       
   641             {
       
   642             AddDataForItutKeyboardL(iPtiKeyMappings, iKeysForPoolFormation[i], *(iAllKeyMappingsPtrArr[i]));
       
   643             }
       
   644         }
       
   645 
       
   646     if (iAlgorithm->FindUtilECE()->CurrentInputLanguage() == ELangHongKongChinese)
       
   647         {
       
   648         (*(iAllKeyMappingsPtrArr[1])).iKeyMappingArray.Append(0x4E00); //heng
       
   649         (*(iAllKeyMappingsPtrArr[2])).iKeyMappingArray.Append(0x4E28); //shu
       
   650         (*(iAllKeyMappingsPtrArr[3])).iKeyMappingArray.Append(0x4E3F); //pie
       
   651         (*(iAllKeyMappingsPtrArr[4])).iKeyMappingArray.Append(0x4E36); //dian
       
   652         (*(iAllKeyMappingsPtrArr[5])).iKeyMappingArray.Append(0x4E5B); //zhe
       
   653         }
       
   654 
       
   655     }
       
   656 // ----------------------------------------------------------------------------
       
   657 // CPcsKeyMap::AddDataForItutKeyboardL
       
   658 // 
       
   659 // ----------------------------------------------------------------------------
       
   660 void CPcsKeyMap::AddDataForItutKeyboardL(CPtiKeyMappings* iPtiKeyMappings, TPtiKey aKey, TKeyMappingData& aKeyDataList)
       
   661     {
       
   662     TPtiTextCase caseArray[] = { EPtiCaseUpper, EPtiCaseLower };
       
   663     TBuf<50> iResult;
       
   664     for (int i = 0; i< sizeof(caseArray) / sizeof(TPtiTextCase); i++)
       
   665         {
       
   666         iResult.Zero();
       
   667         iPtiKeyMappings->GetDataForKey(aKey, iResult, caseArray[i]);
       
   668         for (int j = 0; j < iResult.Length(); j++)
       
   669             aKeyDataList.iKeyMappingArray.Append(iResult[j]);
       
   670         PRINT2 ( _L("CPcsKeyMap: Mapping for Key %c = %S"), aKey,&iResult)
       
   671         }
       
   672     }
       
   673 
       
   674 // ----------------------------------------------------------------------------
       
   675 // CPcsKeyMap::IsLanguageSupportedL
       
   676 // Returns ETrue if this language is supported
       
   677 // ----------------------------------------------------------------------------
       
   678 TBool CPcsKeyMap::IsLanguageSupportedL(TUint32 aLang)
       
   679     {
       
   680 
       
   681     TBool flag = ETrue;
       
   682     for (int i = 0; i < iLanguageNotSupported.Count(); i++)
       
   683         {
       
   684         if (iLanguageNotSupported[i] == aLang)
       
   685             {
       
   686             flag = EFalse;
       
   687             }
       
   688         }
       
   689 
       
   690     return flag;
       
   691     }
       
   692 // ----------------------------------------------------------------------------
       
   693 // CPcsKeyMap::PoolIdForCharacter
       
   694 // 
       
   695 // ----------------------------------------------------------------------------
       
   696 TInt CPcsKeyMap::PoolIdForCharacter(const TChar& aChar)
       
   697     {
       
   698     TInt numValue = KErrNotFound;
       
   699     TInt key = KeyForCharacter(aChar);
       
   700     if (key != KErrNotFound)
       
   701         {
       
   702         numValue = iKeysForPoolFormation.Find((TPtiKey) key);
       
   703         }
       
   704     else
       
   705         {
       
   706         // IF the key is not found, then it should go to the special pool,
       
   707         // which is the last pool of iAllKeyMappingsPtrArr
       
   708         numValue = iAllKeyMappingsPtrArr.Count() - 1;
       
   709         }
       
   710 
       
   711     return numValue;
       
   712     }
       
   713 
       
   714 // ----------------------------------------------------------------------------
       
   715 // CPcsKeyMap::PoolCount
       
   716 // 
       
   717 // ----------------------------------------------------------------------------
       
   718 TInt CPcsKeyMap::PoolCount()
       
   719     {
       
   720     return iAllKeyMappingsPtrArr.Count();
       
   721     }
       
   722 // End of file