predictivesearch/PcsAlgorithm/Algorithm2/src/CPcsKeyMap.cpp
branchRCL_3
changeset 85 38bb213f60ba
parent 63 f4a778e096c2
equal deleted inserted replaced
74:6b5524b4f673 85:38bb213f60ba
    21 #include "CPcsAlgorithm2.h"
    21 #include "CPcsAlgorithm2.h"
    22 #include "CPcsAlgorithm2Utils.h"
    22 #include "CPcsAlgorithm2Utils.h"
    23 #include "FindUtilChineseECE.h"
    23 #include "FindUtilChineseECE.h"
    24 #include "CPcsDebug.h"
    24 #include "CPcsDebug.h"
    25 #include "CPcsKeyMap.h"
    25 #include "CPcsKeyMap.h"
    26 #include "CPsQueryItem.h"
       
    27 #include <PtiEngine.h>
       
    28 #include <PtiKeyMapData.h>
       
    29 #include <bldvariant.hrh>
    26 #include <bldvariant.hrh>
    30 #include <AknFepInternalCRKeys.h>
    27 #include <AknFepInternalCRKeys.h>
    31 
       
    32 
       
    33 // Unnamed namespace for local definitions
       
    34 namespace {
       
    35 
       
    36 #ifdef _DEBUG
       
    37     enum TPanicCode
       
    38     {
       
    39         EPanicPreCond_MultipleSingleCharMatching = 1,
       
    40         EPanicPreCond_MultipleUIPriorityMatching = 2,
       
    41         EPanicPreCond_MultipleEnglishPriorityMatching = 3,
       
    42         EPanicPreCond_MultipleOthersPriorityMatching = 4,
       
    43         EPanic_OverflowInPoolIndex = 5,
       
    44         EPanic_InvalidKeyboardType = 6
       
    45    };
       
    46 
       
    47     void Panic(TInt aReason)
       
    48     {
       
    49         _LIT(KPanicText, "CPcsKeyMap");
       
    50         User::Panic(KPanicText, aReason);
       
    51     }
       
    52 #endif // DEBUG
       
    53 
       
    54 } // namespace
       
    55 
       
    56 
    28 
    57 // ============================== MEMBER FUNCTIONS ============================
    29 // ============================== MEMBER FUNCTIONS ============================
    58 
    30 
    59 // ----------------------------------------------------------------------------
    31 // ----------------------------------------------------------------------------
    60 // CPcsKeyMap::NewL
    32 // CPcsKeyMap::NewL
    87 // 2nd Phase Constructor
    59 // 2nd Phase Constructor
    88 // ----------------------------------------------------------------------------
    60 // ----------------------------------------------------------------------------
    89 void CPcsKeyMap::ConstructL(CPcsAlgorithm2* aAlgorithm)
    61 void CPcsKeyMap::ConstructL(CPcsAlgorithm2* aAlgorithm)
    90     {
    62     {
    91     iLanguageNotSupported.Append(ELangJapanese);
    63     iLanguageNotSupported.Append(ELangJapanese);
    92     iLanguageNotSupported.Append(ELangKorean);
       
    93 
    64 
    94     iAlgorithm = aAlgorithm;
    65     iAlgorithm = aAlgorithm;
    95     iPtiEngine = CPtiEngine::NewL();
    66     iPtiEngine = CPtiEngine::NewL();
    96 
    67 	
    97     SetupKeyboardTypesL();
       
    98     ConstructKeymapL();
    68     ConstructKeymapL();
    99     SetSpaceAndZeroOnSameKey();
       
   100     }
    69     }
   101 
    70 
   102 // ----------------------------------------------------------------------------
    71 // ----------------------------------------------------------------------------
   103 // CPcsKeyMap::ReconstructKeymapL
    72 // CPcsKeyMap::ReconstructKeymapL
   104 // When the writing language is changed, the keymap needs reconstruct.
    73 // When the writing language is changed, the keymap needs reconstruct.
   105 // ----------------------------------------------------------------------------
    74 // ----------------------------------------------------------------------------
   106 void CPcsKeyMap::ReconstructKeymapL()
    75 void CPcsKeyMap::ReconstructKeymapL()
   107     {
    76     {
       
    77     TLanguage lang = iAlgorithm->FindUtilECE()->CurrentInputLanguage();
       
    78         if (lang == ELangPrcChinese || !IsLanguageSupportedL(lang))
       
    79             lang = ELangEnglish;
       
    80 
       
    81     TInt keyboardType = CurrentKeyBoardTypeL();
       
    82     
   108     // Clear the keymap data array first when reconstruct the keymap.
    83     // Clear the keymap data array first when reconstruct the keymap.
   109     ResetKeyMap();
    84     ResetKeyMap();
   110     
    85     
   111     // Always add English mappings first
    86     // Add new keymap to the keymap data array according the current writing language.
   112     AddKeyMapforConcreteKeyboardL( ELangEnglish );
    87     AddKeyMapforConcreteKeyboardL( keyboardType, lang );
   113     
    88     }
   114     // Then append the mappings of the current input language
    89 
       
    90 // ----------------------------------------------------------------------------
       
    91 // CPcsKeyMap::ConstructKeymapL
       
    92 // 
       
    93 // ----------------------------------------------------------------------------
       
    94 void CPcsKeyMap::ConstructKeymapL()
       
    95     {
   115     TLanguage lang = iAlgorithm->FindUtilECE()->CurrentInputLanguage();
    96     TLanguage lang = iAlgorithm->FindUtilECE()->CurrentInputLanguage();
   116     if ( lang != ELangEnglish && IsLanguageSupportedL(lang) )
    97     if (lang == ELangPrcChinese || !IsLanguageSupportedL(lang))
   117         {
    98         lang = ELangEnglish;
   118         AddKeyMapforConcreteKeyboardL( lang );
    99 
   119         }
   100     TInt keyboardType = CurrentKeyBoardTypeL();
   120     }
   101     
   121 
   102     ConstructConcreteKeyMapL( keyboardType, lang );
   122 // ----------------------------------------------------------------------------
       
   123 // CPcsKeyMap::ConstructKeymapL
       
   124 // 
       
   125 // ----------------------------------------------------------------------------
       
   126 void CPcsKeyMap::ConstructKeymapL()
       
   127     {
       
   128     ConstructConcreteKeyMapL();
       
   129     
       
   130     // Always add English mappings first
       
   131     AddKeyMapforConcreteKeyboardL( ELangEnglish );
       
   132     
       
   133     // Then append the mappings of the current input language
       
   134     TLanguage lang = iAlgorithm->FindUtilECE()->CurrentInputLanguage();
       
   135     if ( lang != ELangEnglish && IsLanguageSupportedL(lang) )
       
   136         {
       
   137         AddKeyMapforConcreteKeyboardL( lang );
       
   138         }
       
   139     
   103     
   140     PRINT ( _L("----------------------------------------"));
   104     PRINT ( _L("----------------------------------------"));
   141     }
   105     
   142 
   106     }
   143 // ----------------------------------------------------------------------------
   107 
   144 // CPcsKeyMap::SetupKeyboardTypesL
   108 // ----------------------------------------------------------------------------
   145 // Initialise the keyboard type variables
   109 // CPcsKeyMap::CurrentKeyBoardTypeL
   146 // ----------------------------------------------------------------------------
   110 // 
   147 void CPcsKeyMap::SetupKeyboardTypesL()
   111 // ----------------------------------------------------------------------------
   148     {
   112 TInt CPcsKeyMap::CurrentKeyBoardTypeL()
       
   113     {
       
   114     TInt keyBoardType = EPtiKeyboardNone;
       
   115     
       
   116 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   117     
   149     TInt physicalKeyboard = 0;
   118     TInt physicalKeyboard = 0;
   150     CRepository* aknFepRepository = CRepository::NewL( KCRUidAknFep );
   119     CRepository* aknFepRepository = CRepository::NewL( KCRUidAknFep );
       
   120     // Get all the physical keyboards which are connected to the phone currently.
   151     aknFepRepository->Get( KAknFepPhysicalKeyboards, physicalKeyboard );
   121     aknFepRepository->Get( KAknFepPhysicalKeyboards, physicalKeyboard );
   152     delete aknFepRepository;
   122     delete aknFepRepository;
   153 
   123     
   154     PRINT1 ( _L("CPcsKeyMap::ConstructL: Physical keyboard support flag = 0x%02X"), physicalKeyboard );
   124     
       
   125     PRINT1 ( _L("CPcsKeyMap::CurrentKeyBoardTypeL: Physical keyboard support flag = 0x%02X"), physicalKeyboard );
   155 
   126 
   156     // Constants follow the definition of KAknFepPhysicalKeyboards
   127     // Constants follow the definition of KAknFepPhysicalKeyboards
   157     const TInt KPtiKeyboard12Key = 0x01;
   128     const TInt ptiKeyboard12Key = 0x01;         // Default
   158     const TInt KPtiKeyboardQwerty4x12 = 0x02;
   129     // const TInt ptiKeyboardQwerty4x12 = 0x02;    // Not used at the moment
   159     const TInt KPtiKeyboardQwerty4x10 = 0x04;
   130     const TInt ptiKeyboardQwerty4x10 = 0x04;
   160     const TInt KPtiKeyboardQwerty3x11 = 0x08;
   131     // const TInt ptiKeyboardQwerty3x11 = 0x08;    // Not used at the moment
   161     const TInt KPtiKeyboardHalfQwerty = 0x10;
   132     const TInt ptiKeyboardHalfQwerty = 0x10;
   162     const TInt KPtiKeyboardCustomQwerty = 0x20; 
   133     // const TInt ptiKeyboardCustomQwerty = 0x20;  // Not used at the moment
   163 
   134 
   164     // Setup ITU-T mode first.
   135     // If there are more than 1 keyboards on HW, The priority from high to low for 
   165     // Use always 12-key mode since all the supported devices should have at least
   136     // selecting keyboard is EPtiKeyboard12Key, EPtiKeyboardHalfQwerty, EPtiKeyboardQwerty4x10  
   166     // virtual ITU-T available.
   137     if ( physicalKeyboard & ptiKeyboard12Key )
   167     iItutKeyboardType = EPtiKeyboard12Key;
   138         {
   168     // TODO: ITU-T type could be set to "none" if device does not have either
   139         keyBoardType = EPtiKeyboard12Key;
   169     // virtual keypad or hardware ITU-T available. This could be decided according
   140         }
   170     // some cenrep value, feature flag, device model, or platform version.
   141     else if ( physicalKeyboard & ptiKeyboardHalfQwerty )
   171     
   142         {
   172     // Then setup QWERTY mode. On real-life devices there should never
   143         keyBoardType = EPtiKeyboardHalfQwerty;
   173     // be more than one QWERTY keyboard available but on emulator there can be several.
   144         }
   174     // Use the first one found in the following precedence
   145     else if ( physicalKeyboard & ptiKeyboardQwerty4x10 )
   175     if ( physicalKeyboard & KPtiKeyboardQwerty3x11 )
   146         {
   176         {
   147         keyBoardType = EPtiKeyboardQwerty4x10;
   177         iQwertyKeyboardType = EPtiKeyboardQwerty3x11;
       
   178         }
       
   179     else if ( physicalKeyboard & KPtiKeyboardQwerty4x10 )
       
   180         {
       
   181         iQwertyKeyboardType = EPtiKeyboardQwerty4x10;
       
   182         }
       
   183     else if ( physicalKeyboard & KPtiKeyboardQwerty4x12 )
       
   184         {
       
   185         iQwertyKeyboardType = EPtiKeyboardQwerty4x12;
       
   186         }
       
   187     else if ( physicalKeyboard & KPtiKeyboardCustomQwerty )
       
   188         {
       
   189         iQwertyKeyboardType = EPtiKeyboardCustomQwerty;
       
   190         }
       
   191     else if ( physicalKeyboard & KPtiKeyboardHalfQwerty )
       
   192         {
       
   193         iQwertyKeyboardType = EPtiKeyboardHalfQwerty;
       
   194         }
   148         }
   195     else
   149     else
   196         {
   150 #endif
   197         iQwertyKeyboardType = EPtiKeyboardNone;
   151         {
   198         }
   152         keyBoardType = EPtiKeyboard12Key;
   199     
   153         }
   200     // Decide, which keyboard is used for the "default" matching mode.
   154     return keyBoardType;
   201     // If there is physical ITU-T available, or there's no physical QWERTY,
   155     }
   202     // then ITU-T is default.
       
   203     iItutIsDefault = (physicalKeyboard & KPtiKeyboard12Key) || 
       
   204                      (iQwertyKeyboardType == EPtiKeyboardNone);
       
   205     
       
   206     PRINT1 ( _L("CPcsKeyMap::ConstructL: ITU-T Keyboard chosen for Predictive Search = %d"), iItutKeyboardType );
       
   207     PRINT1 ( _L("CPcsKeyMap::ConstructL: QWERTY Keyboard chosen for Predictive Search = %d"), iQwertyKeyboardType );
       
   208     }
       
   209 
       
   210 
   156 
   211 // ----------------------------------------------------------------------------
   157 // ----------------------------------------------------------------------------
   212 // CPcsKeyMap::ConstructConcreteKeyMapL
   158 // CPcsKeyMap::ConstructConcreteKeyMapL
   213 // 
   159 // 
   214 // ----------------------------------------------------------------------------
   160 // ----------------------------------------------------------------------------
   215 void CPcsKeyMap::ConstructConcreteKeyMapL()
   161 void CPcsKeyMap::ConstructConcreteKeyMapL( TInt aKeyboardType, TLanguage aLanguage )
   216     {
   162     {
   217     if ( iItutKeyboardType != EPtiKeyboardNone )
   163     switch ( aKeyboardType )
   218         {
   164         {
   219         // Construct for Itut keyboard by default
   165         case EPtiKeyboard12Key:
   220         PRINT ( _L("CPcsKeyMap::ConstructConcreteKeyMapL: Construct keymap for ITU-T"));
   166             {
   221         ConstructForItutKeyboardL();
   167             // Construct for Itut keyboard by default
   222         }
   168             PRINT ( _L("CPcsKeyMap::ConstructConcreteKeyMapL: Construct keymap for ContructForItutKeyboardL"));
   223     if ( iQwertyKeyboardType != EPtiKeyboardNone )
   169             
   224         {
   170             ContructForItutKeyboardL( aLanguage );
   225         // Construct for any QWERTY keyboard
   171             break;
   226         PRINT1 ( _L("CPcsKeyMap::ConstructConcreteKeyMapL: Construct keymap for QWERTY keyboard type %d"), 
   172             }
   227                  iQwertyKeyboardType );
   173         case EPtiKeyboardHalfQwerty:
   228         ConstructForQwertyKeyboardL( iQwertyKeyboardType );
   174             {
       
   175             // Construct for Half Qwerty keyboard
       
   176             PRINT ( _L("CPcsKeyMap::ConstructConcreteKeyMapL: Construct keymap for ContructForHalfQwertyKeyboardL"));
       
   177             
       
   178             ContructForHalfQwertyKeyboardL( aLanguage );
       
   179             break;
       
   180             }
       
   181         case EPtiKeyboardQwerty4x10:
       
   182             {
       
   183             // Construct for 4x10 Qwerty keyboard
       
   184             PRINT ( _L("CPcsKeyMap::ConstructConcreteKeyMapL: Construct keymap for ContructFor4x10QwertyKeyboardL"));
       
   185             
       
   186             ContructFor4x10QwertyKeyboardL( aLanguage );
       
   187             break;
       
   188             }
       
   189         default:
       
   190             {
       
   191             // Construct for Itut keyboard
       
   192             PRINT ( _L("CPcsKeyMap::ConstructConcreteKeyMapL: Construct keymap for ContructForItutKeyboardL"));
       
   193             
       
   194             ContructForItutKeyboardL( aLanguage );
       
   195             }
   229         }
   196         }
   230     }
   197     }
   231 
   198 
   232 // ----------------------------------------------------------------------------
   199 // ----------------------------------------------------------------------------
   233 // CPcsKeyMap::AddKeyMapforConcreteKeyboardL
   200 // CPcsKeyMap::AddKeyMapforConcreteKeyboardL
   234 // 
   201 // 
   235 // ----------------------------------------------------------------------------
   202 // ----------------------------------------------------------------------------
   236 void CPcsKeyMap::AddKeyMapforConcreteKeyboardL( TLanguage aLanguage )
   203 void CPcsKeyMap::AddKeyMapforConcreteKeyboardL( TInt aKeyboardType, TLanguage aLanguage )
   237     {
   204     {
   238     if ( iItutKeyboardType != EPtiKeyboardNone )
   205     // If it's TW or HK variant, the key map for English also needs add to current key map.
   239         {
   206     TBool needAddEnglishKeyMap = ( aLanguage == ELangTaiwanChinese || aLanguage == ELangHongKongChinese );
   240         AddKeyMapforItutL( aLanguage );
   207     
   241         }
   208     // Add the keymap for current writing language.
   242     
   209     switch ( aKeyboardType )
   243     if ( iQwertyKeyboardType != EPtiKeyboardNone )
   210         {
   244         {
   211         case EPtiKeyboard12Key:
   245         AddKeyMapForQwertyKeyboardL( aLanguage, iQwertyKeyboardType );
   212             {
       
   213             AddKeyMapforItutL( aLanguage );
       
   214             if ( needAddEnglishKeyMap )
       
   215                 {
       
   216                 AddKeyMapforItutL( ELangEnglish );
       
   217                 }
       
   218             break;
       
   219             }
       
   220         case EPtiKeyboardHalfQwerty:
       
   221             {
       
   222             AddKeyMapforHalfQwertyKeyboardL( aLanguage );
       
   223             if ( needAddEnglishKeyMap )
       
   224                 {
       
   225                 AddKeyMapforHalfQwertyKeyboardL( ELangEnglish );
       
   226                 }
       
   227             break;
       
   228             }
       
   229         case EPtiKeyboardQwerty4x10:
       
   230             {
       
   231             AddKeyMapfor4x10QwertyKeyboardL( aLanguage );
       
   232             if ( needAddEnglishKeyMap )
       
   233                 {
       
   234                 AddKeyMapfor4x10QwertyKeyboardL( ELangEnglish );
       
   235                 }
       
   236             break;
       
   237             }
       
   238         default:
       
   239             {
       
   240             AddKeyMapforItutL( aLanguage );
       
   241             if ( needAddEnglishKeyMap )
       
   242                 {
       
   243                 AddKeyMapforItutL( ELangEnglish );
       
   244                 }
       
   245             }
   246         }
   246         }
   247     }
   247     }
   248 
   248 
   249 // ----------------------------------------------------------------------------
   249 // ----------------------------------------------------------------------------
   250 // CPcsKeyMap::ResetKeyMap
   250 // CPcsKeyMap::ResetKeyMap
   251 // 
   251 // 
   252 // ----------------------------------------------------------------------------
   252 // ----------------------------------------------------------------------------
   253 void CPcsKeyMap::ResetKeyMap()
   253 void CPcsKeyMap::ResetKeyMap()
   254     {
   254     {
   255     const TInt ItutKeyMappingsCount = iItutKeyMappings.Count();
   255     for (TInt i = 0; i < iAllKeyMappingsPtrArr.Count(); i++)
   256     const TInt qwertyKeyMappingsCount = iQwertyKeyMappings.Count();
   256         {
   257     for (TInt i = 0; i < ItutKeyMappingsCount; i++)
   257         iAllKeyMappingsPtrArr[i]->iKeyMappingArray.Close();
   258         {
   258         }
   259         iItutKeyMappings[i]->iKeyMappingArray.Reset();
   259 
   260         }
   260     }
   261     for (TInt i = 0; i < qwertyKeyMappingsCount; i++)
       
   262         {
       
   263         iQwertyKeyMappings[i]->iKeyMappingArray.Reset();
       
   264         }
       
   265     }
       
   266 
       
   267 // ----------------------------------------------------------------------------
   261 // ----------------------------------------------------------------------------
   268 // CPcsKeyMap::~CPcsKeyMap
   262 // CPcsKeyMap::~CPcsKeyMap
   269 // Destructor
   263 // Destructor
   270 // ----------------------------------------------------------------------------
   264 // ----------------------------------------------------------------------------
   271 CPcsKeyMap::~CPcsKeyMap()
   265 CPcsKeyMap::~CPcsKeyMap()
   272     {
   266     {
   273     ResetKeyMap();
   267     ResetKeyMap();
   274 
   268 
   275     // Cleanup local arrays
   269     // Cleanup local arrays
   276     iLanguageNotSupported.Reset();
   270     iLanguageNotSupported.Reset();
   277     iItutKeyMappings.ResetAndDestroy();
   271     iAllKeyMappingsPtrArr.ResetAndDestroy();
   278     iItutKeys.Close();
   272     iKeysForPoolFormation.Close();
   279     iQwertyKeyMappings.ResetAndDestroy();
       
   280     iQwertyKeys.Close();
       
   281     delete iPtiEngine;
   273     delete iPtiEngine;
   282     }
   274     }
   283 
   275 
   284 // ----------------------------------------------------------------------------
   276 // ----------------------------------------------------------------------------
   285 // CPcsKeyMap::GetMixedKeyStringForQueryL
   277 // CPcsKeyMap::GetNumericKeyStringL
   286 // aDestStr will have the length as the number of items in aSrcQuery.
   278 // 
   287 // ----------------------------------------------------------------------------
   279 // ----------------------------------------------------------------------------
   288 void CPcsKeyMap::GetMixedKeyStringForQueryL(
   280 void CPcsKeyMap::GetNumericKeyString(const TDesC& aSrcStr, TDes& aDestStr)
   289         CPsQuery& aSrcQuery, TDes& aDestStr) const
   281     {
   290 {
   282     for (int i = 0; i < aSrcStr.Length(); i++)
   291     PRINT ( _L("Enter CPcsKeyMap::GetMixedKeyStringForQueryL") ); 
   283         {
   292 
   284         TInt index = KeyForCharacter(aSrcStr[i]);
   293     GetMixedKeyStringForDataL( aSrcQuery, aSrcQuery.QueryAsStringLC(), aDestStr );
   285 
   294     CleanupStack::PopAndDestroy(); //result of QueryAsStringLC
   286         // If a character is not mapped to numeric key append the character
   295 
   287         if (index == -1)
   296     PRINT ( _L("End CPcsKeyMap::GetMixedKeyStringForQueryL") );
   288             {
   297 }
   289             aDestStr.Append(aSrcStr[i]);
   298 
       
   299 // ----------------------------------------------------------------------------
       
   300 // CPcsKeyMap::GetMixedKeyStringForDataL
       
   301 // aDestStr will have the same length as aSrcData. aSrcQuery can be shorter.
       
   302 // ----------------------------------------------------------------------------
       
   303 void CPcsKeyMap::GetMixedKeyStringForDataL(
       
   304         CPsQuery& aSrcQuery, const TDesC& aSrcData, TDes& aDestStr) const
       
   305 {
       
   306     PRINT ( _L("Enter CPcsKeyMap::GetMixedKeyStringForDataL") );
       
   307 
       
   308     const TInt srcDataLength = aSrcData.Length(); 
       
   309     for ( TInt i = 0; i < srcDataLength; ++i )
       
   310         {
       
   311         TChar character( aSrcData[i] );
       
   312         character.LowerCase();
       
   313         if ( i < aSrcQuery.Count() )
       
   314             {
       
   315             CPsQueryItem& currentItem = aSrcQuery.GetItemAtL(i);
       
   316             TKeyboardModes curMode = ResolveKeyboardMode( currentItem.Mode() );
       
   317             TPtiKey key = KeyForCharacter( aSrcData[i], curMode );
       
   318             // If a character is not mapped to any key or it's entered in non-predictive mode,
       
   319             // then append the character as exact.
       
   320             if ( EPtiKeyNone == key )
       
   321                 {
       
   322                 aDestStr.Append( character );
       
   323                 }
       
   324             else
       
   325                 {
       
   326                 aDestStr.Append( DefaultCharForKey(key, curMode) );
       
   327                 }
       
   328             }
   290             }
   329         else
   291         else
   330             {
   292             {
   331             // characters over query length are taken as exact
   293             aDestStr.Append(index);
   332             aDestStr.Append( character );
   294             }
   333             }
   295         }
   334         }
   296     }
   335 
       
   336     PRINT1 ( _L("CPcsKeyMap::GetMixedKeyStringForDataL: Return string: \"%S\""),
       
   337              &aDestStr );
       
   338 
       
   339     PRINT ( _L("End CPcsKeyMap::GetMixedKeyStringForDataL") );
       
   340 }
       
   341 
   297 
   342 // ----------------------------------------------------------------------------
   298 // ----------------------------------------------------------------------------
   343 // CPcsKeyMap::KeyForCharacter
   299 // CPcsKeyMap::KeyForCharacter
   344 // 
   300 // 
   345 // ----------------------------------------------------------------------------
   301 // ----------------------------------------------------------------------------
   346 TPtiKey CPcsKeyMap::KeyForCharacter(TText aChar, TKeyboardModes aKbMode) const
   302 TInt CPcsKeyMap::KeyForCharacter(const TChar& aChar)
   347     {
   303     {
   348     const RPointerArray<TKeyMappingData>* keyMappings = KeyMappings( aKbMode );
       
   349     
       
   350     // Don't return any key in the exact mode
       
   351     if ( !keyMappings )
       
   352         {
       
   353         return EPtiKeyNone;
       
   354         }
       
   355     
       
   356     TInt index = KErrNotFound;
   304     TInt index = KErrNotFound;
   357 
   305 
   358     TText lChar = User::LowerCase(aChar);
   306     TChar lChar = User::LowerCase(aChar);
   359 
   307 
   360     const TInt count = keyMappings->Count() - 1;
   308     TInt count = iAllKeyMappingsPtrArr.Count() - 1;
   361 
   309 
   362     for (TInt i = 0; i < count; i++)
   310     for (TInt i = 0; i < count; i++)
   363         {
   311         {
   364         index = (*keyMappings)[i]->iKeyMappingArray.Find(lChar);
   312         index = iAllKeyMappingsPtrArr[i]->iKeyMappingArray.Find(lChar);
   365         if (index != KErrNotFound)
   313         if (index != KErrNotFound)
   366             {
   314             {
   367             return (*keyMappings)[i]->iKey;
   315             return (TInt) iAllKeyMappingsPtrArr[i]->key;
   368             }
   316             }
   369         }
   317         }
   370 
   318 
   371     return EPtiKeyNone;
   319     return index;
   372     }
   320     }
   373 
   321 // ----------------------------------------------------------------------------
   374 // ----------------------------------------------------------------------------
   322 // CPcsKeyMap::ContructForHalfQwertyKeyboardL
   375 // CPcsKeyMap::AddKeyMapForQwertyKeyboardL
   323 // 
   376 // 
   324 // ----------------------------------------------------------------------------
   377 // ----------------------------------------------------------------------------
   325 void CPcsKeyMap::ContructForHalfQwertyKeyboardL(TLanguage aLanguage)
   378 void CPcsKeyMap::AddKeyMapForQwertyKeyboardL(TLanguage aLanguage, TPtiKeyboardType aKbType)
   326     {
   379     {
   327 #ifdef RD_INTELLIGENT_TEXT_INPUT    
   380 #ifdef RD_INTELLIGENT_TEXT_INPUT
   328 
   381     iPtiEngine->ActivateLanguageL(aLanguage);
   329     iKeysForPoolFormation.Append(EPtiKeyQwertyQ);
   382     iPtiEngine->SetKeyboardType(aKbType);
   330     iKeysForPoolFormation.Append(EPtiKeyQwertyE);
   383 
   331     iKeysForPoolFormation.Append(EPtiKeyQwertyT);
       
   332     iKeysForPoolFormation.Append(EPtiKeyQwertyU);
       
   333     iKeysForPoolFormation.Append(EPtiKeyQwertyO);
       
   334     iKeysForPoolFormation.Append(EPtiKeyQwertyA);
       
   335     iKeysForPoolFormation.Append(EPtiKeyQwertyD);
       
   336     iKeysForPoolFormation.Append(EPtiKeyQwertyG);
       
   337     iKeysForPoolFormation.Append(EPtiKeyQwertyJ);
       
   338     iKeysForPoolFormation.Append(EPtiKeyQwertyL);
       
   339     iKeysForPoolFormation.Append(EPtiKeyQwertyZ);
       
   340     iKeysForPoolFormation.Append(EPtiKeyQwertyC);
       
   341     iKeysForPoolFormation.Append(EPtiKeyQwertyB);
       
   342     iKeysForPoolFormation.Append(EPtiKeyQwertyM);
       
   343     iKeysForPoolFormation.Append(EPtiKeyQwerty0);
       
   344     // one additional pool for special characters not mapped too any keys. 
       
   345     // This should always be the last one in the arrary
       
   346     iKeysForPoolFormation.Append(EPtiKeyNone);
       
   347 
       
   348     // Now add the keymap arrays to hold the keymap data
       
   349     for (TInt i = 0; i < iKeysForPoolFormation.Count(); i++)
       
   350         {
       
   351         TKeyMappingData *keyData = new (ELeave) TKeyMappingData;
       
   352         keyData->key = iKeysForPoolFormation[i];
       
   353         iAllKeyMappingsPtrArr.Append(keyData);
       
   354         }
       
   355     //  Add the keymap for current language
       
   356     AddKeyMapforHalfQwertyKeyboardL(aLanguage);
       
   357 
       
   358     // If it's TW or HK variant, add the keymap for English language
       
   359     if (aLanguage == ELangTaiwanChinese || aLanguage == ELangHongKongChinese)
       
   360         {
       
   361         AddKeyMapforHalfQwertyKeyboardL(ELangEnglish);
       
   362         }
       
   363 
       
   364     PRINT ( _L("----------------------------------------"));
       
   365 #endif // RD_INTELLIGENT_TEXT_INPUT
       
   366     }
       
   367 // ----------------------------------------------------------------------------
       
   368 // CPcsKeyMap::AddKeyMapforHalfQwertyKeyboardL
       
   369 // 
       
   370 // ----------------------------------------------------------------------------
       
   371 void CPcsKeyMap::AddKeyMapforHalfQwertyKeyboardL(TLanguage aLanguage)
       
   372     {
       
   373 #ifdef RD_INTELLIGENT_TEXT_INPUT     	
   384     // Make a language object based on current language
   374     // Make a language object based on current language
   385     CPtiCoreLanguage* coreLanguage = static_cast<CPtiCoreLanguage*>(iPtiEngine->GetLanguage( aLanguage ));
   375     CPtiCoreLanguage* iCoreLanguage = static_cast<CPtiCoreLanguage*>(iPtiEngine->GetLanguage(  aLanguage));
   386 
   376 
   387     //Perfrom the key mappings only if the corelanguage is available
   377     //Perfrom the key mappings only if the corelanguage is available
   388     if (coreLanguage)
   378     if (iCoreLanguage)
   389         {
   379         {
   390         // Get the keyboard mappings for the language
   380         // Get the keyboard mappings for the language
   391         CPtiKeyMapData* ptiKeyMapData = coreLanguage->RawKeyMapData();
   381         CPtiHalfQwertyKeyMappings* ptiKeyMappings = static_cast<CPtiHalfQwertyKeyMappings*> 
   392 
   382                 (iCoreLanguage->GetHalfQwertyKeymappings());
   393         const TInt qwertyKeyMappingsCount = iQwertyKeyMappings.Count() - 1;
   383 
   394         for (TInt i = 0; i < qwertyKeyMappingsCount; i++)
   384         iPtiEngine->ActivateLanguageL(aLanguage, EPtiEngineHalfQwerty);
   395             {
   385         iPtiEngine->SetKeyboardType(EPtiKeyboardHalfQwerty);
   396             AddDataForQwertyKeyboardL( ptiKeyMapData, aKbType, 
   386 
   397                     iQwertyKeys[i], *(iQwertyKeyMappings[i]) );
   387         for (TInt i = 0; i < iAllKeyMappingsPtrArr.Count() - 1; i++)
       
   388             {
       
   389             AddDataForHalfQwertyKeyboardL( ptiKeyMappings, iKeysForPoolFormation[i], *(iAllKeyMappingsPtrArr[i]));
   398             }
   390             }
   399         }
   391         }
   400 #endif // RD_INTELLIGENT_TEXT_INPUT        
   392 #endif // RD_INTELLIGENT_TEXT_INPUT        
   401     }
   393     }
   402 
   394 
   403 // ----------------------------------------------------------------------------
   395 // ----------------------------------------------------------------------------
   404 // CPcsKeyMap::ConstructForQwertyKeyboardL
   396 // CPcsKeyMap::AddDataForHalfQwertyKeyboardL
   405 // Destructor
   397 // 
   406 // ----------------------------------------------------------------------------
   398 // ----------------------------------------------------------------------------
   407 void CPcsKeyMap::ConstructForQwertyKeyboardL(TPtiKeyboardType aKbType)
   399 void CPcsKeyMap::AddDataForHalfQwertyKeyboardL( CPtiHalfQwertyKeyMappings* aPtiKeyMappings, 
   408     {
   400                                                TPtiKey aKey,  
   409 #ifdef RD_INTELLIGENT_TEXT_INPUT
   401                                                TKeyMappingData& aKeyDataList)
   410     CreateKeyListFromKeyBindingTable( iQwertyKeys, aKbType );
       
   411 
       
   412     // Now add the keymap arrays to hold the keymap data
       
   413     const TInt qwertyKeysCount = iQwertyKeys.Count();
       
   414     for (TInt i = 0; i < qwertyKeysCount; i++)
       
   415         {
       
   416         TKeyMappingData* keyData = new (ELeave) TKeyMappingData;
       
   417         keyData->iKey = iQwertyKeys[i];
       
   418         iQwertyKeyMappings.Append(keyData);
       
   419         }
       
   420 
       
   421     PRINT ( _L("----------------------------------------"));
       
   422 #endif //RD_INTELLIGENT_TEXT_INPUT
       
   423     }
       
   424 
       
   425 // ----------------------------------------------------------------------------
       
   426 // CPcsKeyMap::AddDataForQwertyKeyboardL
       
   427 // 
       
   428 // ----------------------------------------------------------------------------
       
   429 void CPcsKeyMap::AddDataForQwertyKeyboardL(CPtiKeyMapData* aPtiKeyMapData,
       
   430                                            TPtiKeyboardType aKbType,
       
   431                                            TPtiKey aKey,
       
   432                                            TKeyMappingData& aKeyDataList)
       
   433     {
   402     {
   434 #ifdef RD_INTELLIGENT_TEXT_INPUT     	
   403 #ifdef RD_INTELLIGENT_TEXT_INPUT     	
   435     TPtiTextCase caseArray[] =
   404     TPtiTextCase caseArray[] =
   436         {
   405         {
   437         EPtiCaseUpper,
   406         EPtiCaseUpper,
   440         EPtiCaseFnUpper,
   409         EPtiCaseFnUpper,
   441         EPtiCaseChrLower,
   410         EPtiCaseChrLower,
   442         EPtiCaseChrUpper
   411         EPtiCaseChrUpper
   443         };
   412         };
   444     
   413     
   445     for (TInt i = 0; i < sizeof(caseArray) / sizeof(TPtiTextCase); i++)
   414     TBuf<50> iResult;
   446         {
   415     for (int i = 0; i < sizeof(caseArray) / sizeof(TPtiTextCase); i++)
   447         TPtrC result = aPtiKeyMapData->DataForKey(aKbType, aKey, caseArray[i]);
   416         {
   448 
   417         iResult.Zero();
   449         const TInt resultLength = result.Length(); 
   418         aPtiKeyMappings->GetDataForKey(aKey, iResult, caseArray[i]);
   450         for (TInt j = 0; j < resultLength; j++)
   419 
   451             aKeyDataList.iKeyMappingArray.Append(result[j]);
   420         for (int j = 0; j < iResult.Length(); j++)
   452 
   421             aKeyDataList.iKeyMappingArray.Append(iResult[j]);
   453         PRINT2 ( _L("CPcsKeyMap: Mapping for Key %c = %S"), aKey, &result)
   422 
   454         }
   423         PRINT2 ( _L("CPcsKeyMap: Mapping for Key %c = %S"), aKey,&iResult)
   455 #endif //RD_INTELLIGENT_TEXT_INPUT        
   424         }
   456     }
   425 #endif // RD_INTELLIGENT_TEXT_INPUT        
   457 
   426     }
   458 // ----------------------------------------------------------------------------
   427 
   459 // CPcsKeyMap::ContructForItutKeyboardL
   428 // ----------------------------------------------------------------------------
   460 // 
   429 // CPcsKeyMap::ContructFor4x10QwertyKeyboardL
   461 // ----------------------------------------------------------------------------
   430 // Destructor
   462 void CPcsKeyMap::ConstructForItutKeyboardL()
   431 // ----------------------------------------------------------------------------
   463     {
   432 void CPcsKeyMap::ContructFor4x10QwertyKeyboardL(TLanguage aLanguage)
   464     // Add the keys for Pool formation
   433     {
   465     iItutKeys.Append(EPtiKey0);
   434 #ifdef RD_INTELLIGENT_TEXT_INPUT     
   466     iItutKeys.Append(EPtiKey1);
   435 // The special 4x10 Qwerty keyboard for Sonja.
   467     iItutKeys.Append(EPtiKey2);
   436     iKeysForPoolFormation.Append( EPtiKeyQwertyA );
   468     iItutKeys.Append(EPtiKey3);
   437     iKeysForPoolFormation.Append( EPtiKeyQwerty8 );
   469     iItutKeys.Append(EPtiKey4);
   438     iKeysForPoolFormation.Append( EPtiKeyQwertyC );
   470     iItutKeys.Append(EPtiKey5);
   439     iKeysForPoolFormation.Append( EPtiKeyQwertyD );
   471     iItutKeys.Append(EPtiKey6);
   440     iKeysForPoolFormation.Append( EPtiKeyQwertyE );
   472     iItutKeys.Append(EPtiKey7);
   441     iKeysForPoolFormation.Append( EPtiKeyQwerty4 );
   473     iItutKeys.Append(EPtiKey8);
   442     iKeysForPoolFormation.Append( EPtiKeyQwerty5 );
   474     iItutKeys.Append(EPtiKey9);
   443     iKeysForPoolFormation.Append( EPtiKeyQwerty6 );
       
   444     iKeysForPoolFormation.Append( EPtiKeyQwertyI );
       
   445     iKeysForPoolFormation.Append( EPtiKeyQwertyHash ); // Could have been EPtiKeyQwertyJ, EPtiKeyHash
       
   446     iKeysForPoolFormation.Append( EPtiKeyQwertyK );
       
   447     iKeysForPoolFormation.Append( EPtiKeyQwertyL );
       
   448     iKeysForPoolFormation.Append( EPtiKeyQwerty0 );
       
   449     iKeysForPoolFormation.Append( EPtiKeyQwerty9 );
       
   450     iKeysForPoolFormation.Append( EPtiKeyQwertyO );
       
   451     iKeysForPoolFormation.Append( EPtiKeyQwertyP );
       
   452     iKeysForPoolFormation.Append( EPtiKeyQwertyQ );
       
   453     iKeysForPoolFormation.Append( EPtiKeyQwerty1 );
       
   454     iKeysForPoolFormation.Append( EPtiKeyQwertyS );
       
   455     iKeysForPoolFormation.Append( EPtiKeyQwerty2 );
       
   456     iKeysForPoolFormation.Append( EPtiKeyStar );    // Could have been EPtiKeyQwertyU
       
   457     iKeysForPoolFormation.Append( EPtiKeyQwertyV );    // Could have been EPtiKeyQwerty7
       
   458     iKeysForPoolFormation.Append( EPtiKeyQwertyW );
       
   459     iKeysForPoolFormation.Append( EPtiKeyQwertyX );
       
   460     iKeysForPoolFormation.Append( EPtiKeyQwerty3 );
       
   461     iKeysForPoolFormation.Append( EPtiKeyQwertyZ );
       
   462     
   475     // one additional pool for special characters not mapped too any keys. 
   463     // one additional pool for special characters not mapped too any keys. 
   476     // This should always be the last one in the arrary
   464     // This should always be the last one in the arrary
   477     iItutKeys.Append(EPtiKeyNone);
   465     iKeysForPoolFormation.Append(EPtiKeyNone);
   478 
   466 
   479     // Now add the keymap arrays to hold the keymap data
   467     // Now add the keymap arrays to hold the keymap data
   480     const TInt ltutKeysCount = iItutKeys.Count();
   468     for (TInt i = 0; i < iKeysForPoolFormation.Count(); i++)
   481     for (TInt i = 0; i < ltutKeysCount; i++)
       
   482         {
   469         {
   483         TKeyMappingData *keyData = new (ELeave) TKeyMappingData;
   470         TKeyMappingData *keyData = new (ELeave) TKeyMappingData;
   484         keyData->iKey = iItutKeys[i];
   471         keyData->key = iKeysForPoolFormation[i];
   485         iItutKeyMappings.Append(keyData);
   472         iAllKeyMappingsPtrArr.Append(keyData);
       
   473         }
       
   474 
       
   475     //  Add the keymap for current language
       
   476     AddKeyMapfor4x10QwertyKeyboardL(aLanguage);
       
   477 
       
   478     // If it's TW or HK variant, add the keymap for English language
       
   479     if (aLanguage == ELangTaiwanChinese || aLanguage == ELangHongKongChinese)
       
   480         {
       
   481         AddKeyMapfor4x10QwertyKeyboardL(ELangEnglish);
   486         }
   482         }
   487 
   483 
   488     PRINT ( _L("----------------------------------------"));
   484     PRINT ( _L("----------------------------------------"));
   489     }
   485 #endif //RD_INTELLIGENT_TEXT_INPUT
   490 
   486     }
   491 // ----------------------------------------------------------------------------
   487 
   492 // CPcsKeyMap::AddKeyMapforItutLanguageL
   488 // ----------------------------------------------------------------------------
   493 // 
   489 // CPcsKeyMap::AddKeyMapfor4x10QwertyKeyboardL
   494 // ----------------------------------------------------------------------------
   490 // 
   495 void CPcsKeyMap::AddKeyMapforItutL(TLanguage aLanguage)
   491 // ----------------------------------------------------------------------------
   496     {
   492 void CPcsKeyMap::AddKeyMapfor4x10QwertyKeyboardL(TLanguage aLanguage)
   497     // Activate given language and get corresponding language object
   493     {
   498     iPtiEngine->ActivateLanguageL(aLanguage);
   494 #ifdef RD_INTELLIGENT_TEXT_INPUT     	
   499     CPtiCoreLanguage* coreLanguage = static_cast<CPtiCoreLanguage*> (iPtiEngine->GetLanguage(aLanguage));
   495     // Make a language object based on current language
       
   496     CPtiCoreLanguage* iCoreLanguage = static_cast<CPtiCoreLanguage*>(iPtiEngine->GetLanguage(aLanguage));
   500 
   497 
   501     //Perfrom the key mappings only if the corelanguage is available
   498     //Perfrom the key mappings only if the corelanguage is available
   502     if (coreLanguage)
   499     if (iCoreLanguage)
   503         {
   500         {
   504         // Get the keyboard mappings for the language
   501         // Get the keyboard mappings for the language
   505         CPtiKeyMapData* ptiKeyMapData = coreLanguage->RawKeyMapData();
   502         CPtiQwertyKeyMappings* iPtiKeyMappings = static_cast<CPtiQwertyKeyMappings *> 
   506 
   503                 (iCoreLanguage->GetQwertyKeymappings());
   507         const TInt ltutKeyMappingsCount = iItutKeyMappings.Count() - 1;
   504         iPtiEngine->SetKeyboardType(EPtiKeyboardQwerty4x10);
   508         for (TInt i = 0; i < ltutKeyMappingsCount; i++)
   505 
   509             {
   506         for (TInt i = 0; i < iAllKeyMappingsPtrArr.Count() - 1; i++)
   510             AddDataForItutKeyboardL(ptiKeyMapData, iItutKeys[i], *(iItutKeyMappings[i]));
   507             {
   511             }
   508             AddDataFor4x10QwertyKeyboardL(iPtiKeyMappings, iKeysForPoolFormation[i], *(iAllKeyMappingsPtrArr[i]));
   512         }
   509             }
   513 
   510 
   514     if ( (aLanguage == ELangPrcChinese || aLanguage == ELangTaiwanChinese || aLanguage == ELangHongKongChinese) && 
   511 #ifdef HACK_FOR_E72_J_KEY
   515          (iAlgorithm->FindUtilECE()->CurrentSearchMethod() == EAdptSearchStroke) )
   512         AddDataFor4x10QwertyKeyboardE72HackL();
   516         {
   513 #endif // HACK_FOR_E72_J_KEY
   517         (*(iItutKeyMappings[1])).iKeyMappingArray.Append(0x4E00); //heng
   514         }
   518         (*(iItutKeyMappings[2])).iKeyMappingArray.Append(0x4E28); //shu
   515 #endif //RD_INTELLIGENT_TEXT_INPUT        
   519         (*(iItutKeyMappings[3])).iKeyMappingArray.Append(0x4E3F); //pie
   516 
   520         (*(iItutKeyMappings[4])).iKeyMappingArray.Append(0x4E36); //dian
   517     }
   521         (*(iItutKeyMappings[5])).iKeyMappingArray.Append(0x4E5B); //zhe
   518 
   522         }
   519 #ifdef HACK_FOR_E72_J_KEY
   523 
   520 // ----------------------------------------------------------------------------
   524     }
   521 // CPcsKeyMap::AddDataFor4x10QwertyKeyboardE72HackL
   525 // ----------------------------------------------------------------------------
       
   526 // CPcsKeyMap::AddDataForItutKeyboardL
       
   527 // 
       
   528 // ----------------------------------------------------------------------------
       
   529 void CPcsKeyMap::AddDataForItutKeyboardL(CPtiKeyMapData* aPtiKeyMapData, TPtiKey aKey, TKeyMappingData& aKeyDataList)
       
   530     {
       
   531     TPtiTextCase caseArray[] = { EPtiCaseUpper, EPtiCaseLower };
       
   532     for (TInt i = 0; i< sizeof(caseArray) / sizeof(TPtiTextCase); i++)
       
   533         {
       
   534         TPtrC result = aPtiKeyMapData->DataForKey(EPtiKeyboard12Key, aKey, caseArray[i]);
       
   535         const TInt resultLength =  result.Length();
       
   536         for (TInt j = 0; j < resultLength; j++)
       
   537             aKeyDataList.iKeyMappingArray.Append(result[j]);
       
   538         PRINT2 ( _L("CPcsKeyMap: Mapping for Key %c = %S"), aKey,&result)
       
   539         }
       
   540     }
       
   541 
       
   542 // ----------------------------------------------------------------------------
       
   543 // CPcsKeyMap::CreateKeyMapFromKeyBindingTable
       
   544 //
   522 //
   545 // ----------------------------------------------------------------------------
   523 // Key code for J/# key in Sonja is EPtiKeyQwertyHash (127).
   546 void CPcsKeyMap::CreateKeyListFromKeyBindingTable( RArray<TPtiKey>& aKeyArray, 
   524 // No returned character code ('J', 'j', '#') has 127 as ASCII value.
   547         TPtiKeyboardType aKbType )
   525 // In this case we must add key to the list of characters for the pool.
   548     {
   526 // ----------------------------------------------------------------------------
   549     PRINT ( _L("Enter CPcsKeyMap::CreateKeyListFromKeyBindingTable") );
   527 void CPcsKeyMap::AddDataFor4x10QwertyKeyboardE72HackL()
   550 
   528     {
   551     // Use Eglish mappings to list the keys on the keyboard
   529 #ifdef RD_INTELLIGENT_TEXT_INPUT    
   552     TRAP_IGNORE( iPtiEngine->ActivateLanguageL( ELangEnglish ) );
   530     PRINT ( _L("Enter CPcsKeyMap::AddDataFor4x10QwertyKeyboardE72HackL") );
   553     CPtiCoreLanguage* ptiLang = 
   531 
   554             static_cast<CPtiCoreLanguage*>(iPtiEngine->GetLanguage( ELangEnglish ));
   532     TPtiKey keyValue = (TPtiKey) EPtiKeyQwertyHash;
   555 
   533     TInt keyIndex = iKeysForPoolFormation.Find(keyValue);    
   556     if (ptiLang)
   534 
   557         {
   535     PRINT3 ( _L("CPcsKeyMap: ===== At index %d appending key to list: '%c' (#%d) -Hack-for-E72-"),
   558         const CPtiKeyMapData* keyMapData = ptiLang->RawKeyMapData();
   536              keyIndex, (TInt) keyValue, (TInt) keyValue);
   559         const TPtiKeyBinding* table = NULL;
   537 
   560         TInt numItems = 0;
   538     if ( KErrNotFound != keyIndex )
   561         if ( keyMapData )
   539         {
   562             {
   540         iAllKeyMappingsPtrArr[keyIndex]->iKeyMappingArray.Append(keyValue);
   563             table = keyMapData->KeyBindingTable(aKbType, numItems);
   541         }
   564             }
   542 
   565         else
   543     PRINT ( _L("CPcsKeyMap: ===================================================") );  
   566             {
   544 
   567             PRINT( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: #### Failed to get RawKeyMapData ####") );
   545     PRINT ( _L("End CPcsKeyMap::AddDataFor4x10QwertyKeyboardE72HackL") );
   568             }
   546 #endif // RD_INTELLIGENT_TEXT_INPUT    
       
   547     }
       
   548 #endif // HACK_FOR_E72_J_KEY
       
   549 
       
   550 // ----------------------------------------------------------------------------
       
   551 // CPcsKeyMap::AddDataFor4x10QwertyKeyboardL
       
   552 // 
       
   553 // ----------------------------------------------------------------------------
       
   554 void CPcsKeyMap::AddDataFor4x10QwertyKeyboardL(CPtiQwertyKeyMappings* iPtiKeyMappings, 
       
   555                                                TPtiKey aKey,  
       
   556                                                TKeyMappingData& aKeyDataList)
       
   557     {
       
   558 #ifdef RD_INTELLIGENT_TEXT_INPUT     	
       
   559     TPtiTextCase caseArray[] =
       
   560             {
       
   561             EPtiCaseUpper,
       
   562             EPtiCaseLower,
       
   563             EPtiCaseFnLower,
       
   564             EPtiCaseFnUpper,
       
   565             EPtiCaseChrLower,
       
   566             EPtiCaseChrUpper
       
   567             };
   569         
   568         
   570         PRINT1 ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: Num of Items in KeyBindingTable is %d"), numItems );
   569     TBuf<50> iResult;
   571 
   570     for (int i = 0; i < sizeof(caseArray) / sizeof(TPtiTextCase); i++)
   572         // Get from the key table the keys for constructing the pools
   571         {
   573         if (table)
   572         iResult.Zero();
   574             {
   573         iPtiKeyMappings->GetDataForKey(aKey, iResult, caseArray[i]);
   575             for (TInt i = 0; i < numItems; i++)
   574 
   576                 {
   575         for (int j = 0; j < iResult.Length(); j++)
   577                 TPtiKey key = (TPtiKey) table[i].iScanCode;
   576             aKeyDataList.iKeyMappingArray.Append(iResult[j]);
   578                 // Get all keys with same EPtiCaseLower or EPtiCaseUpper case
   577 
   579                 // Only for one of the casing to avoid repetitions
   578         PRINT2 ( _L("CPcsKeyMap: Mapping for Key %c = %S"), aKey, &iResult)
   580                 if ( (EPtiKeyNone != key) && (EPtiCaseLower == table[i].iCase) )
   579         }
   581                     {
   580 #endif //RD_INTELLIGENT_TEXT_INPUT        
   582                     PRINT3 ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: Adding pool %d with key '%c' (0x%02X)"),
   581     }
   583                             aKeyArray.Count(), key, key );
   582 
   584                     aKeyArray.Append( key );
   583 // ----------------------------------------------------------------------------
   585                     }
   584 // CPcsKeyMap::ContructForItutKeyboardL
   586                 }
   585 // 
   587             }
   586 // ----------------------------------------------------------------------------
   588         else
   587 void CPcsKeyMap::ContructForItutKeyboardL(TLanguage aLanguage)
   589             {
   588     {
   590             PRINT ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: ##### Failed to create Key List (KeyBindingTable) #####") );
   589     // Add the keys for Pool formation
   591             }
   590     iKeysForPoolFormation.Append(EPtiKey0);
   592         }
   591     iKeysForPoolFormation.Append(EPtiKey1);
   593     else
   592     iKeysForPoolFormation.Append(EPtiKey2);
   594         {
   593     iKeysForPoolFormation.Append(EPtiKey3);
   595         PRINT ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: ##### Failed to create Key List (Language) #####") );
   594     iKeysForPoolFormation.Append(EPtiKey4);
   596         }
   595     iKeysForPoolFormation.Append(EPtiKey5);
   597 
   596     iKeysForPoolFormation.Append(EPtiKey6);
       
   597     iKeysForPoolFormation.Append(EPtiKey7);
       
   598     iKeysForPoolFormation.Append(EPtiKey8);
       
   599     iKeysForPoolFormation.Append(EPtiKey9);
   598     // one additional pool for special characters not mapped too any keys. 
   600     // one additional pool for special characters not mapped too any keys. 
   599     // This should always be the last one in the arrary
   601     // This should always be the last one in the arrary
   600     aKeyArray.Append(EPtiKeyNone);
   602     iKeysForPoolFormation.Append(EPtiKeyNone);
   601 
   603 
   602     PRINT ( _L("End CPcsKeyMap::CreateKeyListFromKeyBindingTable") );
   604     // Now add the keymap arrays to hold the keymap data
       
   605     for (TInt i = 0; i < iKeysForPoolFormation.Count(); i++)
       
   606         {
       
   607         TKeyMappingData *keyData = new (ELeave) TKeyMappingData;
       
   608         keyData->key = iKeysForPoolFormation[i];
       
   609         iAllKeyMappingsPtrArr.Append(keyData);
       
   610         }
       
   611 
       
   612     //  Add the keymap for current language
       
   613     AddKeyMapforItutL(aLanguage);
       
   614 
       
   615     // If it's TW or HK variant, add the keymap for English language
       
   616     if (aLanguage == ELangTaiwanChinese || aLanguage == ELangHongKongChinese)
       
   617         {
       
   618         AddKeyMapforItutL(ELangEnglish);
       
   619         }
       
   620 
       
   621     PRINT ( _L("----------------------------------------"));
       
   622 
       
   623     }
       
   624 
       
   625 // ----------------------------------------------------------------------------
       
   626 // CPcsKeyMap::AddKeyMapforItutLanguageL
       
   627 // 
       
   628 // ----------------------------------------------------------------------------
       
   629 void CPcsKeyMap::AddKeyMapforItutL(TLanguage aLanguage)
       
   630     {
       
   631     // Make a language object based on current language
       
   632     CPtiCoreLanguage* iCoreLanguage = static_cast<CPtiCoreLanguage*> (iPtiEngine->GetLanguage(aLanguage));
       
   633 
       
   634     //Perfrom the key mappings only if the corelanguage is available
       
   635     if (iCoreLanguage)
       
   636         {
       
   637         // Get the keyboard mappings for the language
       
   638         CPtiKeyMappings* iPtiKeyMappings =  static_cast<CPtiKeyMappings*> 
       
   639                 (iCoreLanguage->GetKeymappings());
       
   640 
       
   641         for (TInt i = 0; i < iAllKeyMappingsPtrArr.Count() - 1; i++)
       
   642             {
       
   643             AddDataForItutKeyboardL(iPtiKeyMappings, iKeysForPoolFormation[i], *(iAllKeyMappingsPtrArr[i]));
       
   644             }
       
   645         }
       
   646 
       
   647     if (iAlgorithm->FindUtilECE()->CurrentInputLanguage() == ELangHongKongChinese)
       
   648         {
       
   649         (*(iAllKeyMappingsPtrArr[1])).iKeyMappingArray.Append(0x4E00); //heng
       
   650         (*(iAllKeyMappingsPtrArr[2])).iKeyMappingArray.Append(0x4E28); //shu
       
   651         (*(iAllKeyMappingsPtrArr[3])).iKeyMappingArray.Append(0x4E3F); //pie
       
   652         (*(iAllKeyMappingsPtrArr[4])).iKeyMappingArray.Append(0x4E36); //dian
       
   653         (*(iAllKeyMappingsPtrArr[5])).iKeyMappingArray.Append(0x4E5B); //zhe
       
   654         }
       
   655 
       
   656     }
       
   657 // ----------------------------------------------------------------------------
       
   658 // CPcsKeyMap::AddDataForItutKeyboardL
       
   659 // 
       
   660 // ----------------------------------------------------------------------------
       
   661 void CPcsKeyMap::AddDataForItutKeyboardL(CPtiKeyMappings* iPtiKeyMappings, TPtiKey aKey, TKeyMappingData& aKeyDataList)
       
   662     {
       
   663     TPtiTextCase caseArray[] = { EPtiCaseUpper, EPtiCaseLower };
       
   664     TBuf<50> iResult;
       
   665     for (int i = 0; i< sizeof(caseArray) / sizeof(TPtiTextCase); i++)
       
   666         {
       
   667         iResult.Zero();
       
   668         iPtiKeyMappings->GetDataForKey(aKey, iResult, caseArray[i]);
       
   669         for (int j = 0; j < iResult.Length(); j++)
       
   670             aKeyDataList.iKeyMappingArray.Append(iResult[j]);
       
   671         PRINT2 ( _L("CPcsKeyMap: Mapping for Key %c = %S"), aKey,&iResult)
       
   672         }
   603     }
   673     }
   604 
   674 
   605 // ----------------------------------------------------------------------------
   675 // ----------------------------------------------------------------------------
   606 // CPcsKeyMap::IsLanguageSupportedL
   676 // CPcsKeyMap::IsLanguageSupportedL
   607 // Returns ETrue if this language is supported
   677 // Returns ETrue if this language is supported
   608 // ----------------------------------------------------------------------------
   678 // ----------------------------------------------------------------------------
   609 TBool CPcsKeyMap::IsLanguageSupportedL(TUint32 aLang)
   679 TBool CPcsKeyMap::IsLanguageSupportedL(TUint32 aLang)
   610     {
   680     {
   611 
   681 
   612     TBool flag = ETrue;
   682     TBool flag = ETrue;
   613     const TInt languageNotSupportedCount = iLanguageNotSupported.Count();
   683     for (int i = 0; i < iLanguageNotSupported.Count(); i++)
   614     for (TInt i = 0; i < languageNotSupportedCount; i++)
       
   615         {
   684         {
   616         if (iLanguageNotSupported[i] == aLang)
   685         if (iLanguageNotSupported[i] == aLang)
   617             {
   686             {
   618             flag = EFalse;
   687             flag = EFalse;
   619             }
   688             }
   620         }
   689         }
   621 
   690 
   622     return flag;
   691     return flag;
   623     }
   692     }
   624 
       
   625 // ----------------------------------------------------------------------------
       
   626 // CPcsKeyMap::PoolIdForKey
       
   627 //
       
   628 // ----------------------------------------------------------------------------
       
   629 TInt CPcsKeyMap::PoolIdForKey(TPtiKey aKey, TKeyboardModes aKbMode) const
       
   630     {
       
   631     __ASSERT_DEBUG( (aKbMode==EPredictiveItuT || aKbMode==EPredictiveQwerty),
       
   632                     Panic(EPanic_InvalidKeyboardType) );
       
   633     
       
   634     // From logical point of view, the Pool ID is an index of the key in
       
   635     // an array which is formed by concatenating QWERTY keys array in the end
       
   636     // of the ITU-T keys array.
       
   637     TInt poolId = KErrNotFound;
       
   638     if ( aKbMode == EPredictiveItuT && iItutKeys.Count() )
       
   639         {
       
   640         poolId = iItutKeys.Find(aKey);
       
   641         // IF the key is not found, then it should go to the special pool,
       
   642         // which is the pool of the dummy key in the ITU-T keys array
       
   643         if (KErrNotFound == poolId)
       
   644             {
       
   645             poolId = iItutKeys.Count() - 1;
       
   646             }
       
   647         }
       
   648     else if ( aKbMode == EPredictiveQwerty && iQwertyKeys.Count() )
       
   649         {
       
   650         poolId = iQwertyKeys.Find(aKey);
       
   651         // IF the key is not found, then it should go to the special pool,
       
   652         // which is the pool of the dummy key in the QWERTY keys array
       
   653         if (KErrNotFound == poolId)
       
   654             {
       
   655             poolId = iQwertyKeys.Count() - 1;
       
   656             }
       
   657         // Pools of QWERTY keys come after pools of ITU-T keys
       
   658         poolId += iItutKeys.Count();
       
   659         }
       
   660 
       
   661     // Pool ID must never exceed value 63, because CPcsCache class
       
   662     // stores these values as bitmask into 64 bit variable.
       
   663     __ASSERT_DEBUG( poolId < 64, Panic(EPanic_OverflowInPoolIndex) );
       
   664     return poolId;
       
   665     }
       
   666 
       
   667 // ----------------------------------------------------------------------------
   693 // ----------------------------------------------------------------------------
   668 // CPcsKeyMap::PoolIdForCharacter
   694 // CPcsKeyMap::PoolIdForCharacter
   669 // 
   695 // 
   670 // ----------------------------------------------------------------------------
   696 // ----------------------------------------------------------------------------
   671 TInt CPcsKeyMap::PoolIdForCharacter( TChar aChar, TKeyboardModes aKbMode )
   697 TInt CPcsKeyMap::PoolIdForCharacter(TChar aChar)
   672     {
   698     {
   673     // Pools are formed according the predictive keyboard mapping(s).
   699     TInt numValue = KErrNotFound;
   674     // When selecting pool for non-predictive mode, we use the pool of the
   700     
   675     // default keyboard. The non-predictive matches should be a sub set of the
       
   676     // predictive matches of the default keyboard, although strictly speaking,
       
   677     // there' no guarantee for this.
       
   678     if ( aKbMode == ENonPredictive || aKbMode == EPredictiveDefaultKeyboard )
       
   679         {
       
   680         aKbMode = ( iItutIsDefault ? EPredictiveItuT : EPredictiveQwerty );
       
   681         }
       
   682 
       
   683     // If character is a Chinese word character, then we select the
   701     // If character is a Chinese word character, then we select the
   684     // pool ID according the first character of the first spelling of the word.
   702     // pool ID according the first character of the first spelling of the word.
   685     TRAP_IGNORE( aChar = FirstCharFromSpellingL( aChar ) );
   703     TRAP_IGNORE( aChar = FirstCharFromSpellingL( aChar ) );
   686 
   704     
   687     TPtiKey key = KeyForCharacter( aChar, aKbMode );
   705     TInt key = KeyForCharacter(aChar);
   688     TInt poolId = PoolIdForKey( key, aKbMode );
   706     if (key != KErrNotFound)
   689 
   707         {
   690     return poolId;
   708         numValue = iKeysForPoolFormation.Find((TPtiKey) key);
   691     }
       
   692 
       
   693 // ----------------------------------------------------------------------------
       
   694 // CPcsKeyMap::PoolCount
       
   695 // 
       
   696 // ----------------------------------------------------------------------------
       
   697 TInt CPcsKeyMap::PoolCount()
       
   698     {
       
   699     return iItutKeyMappings.Count() + iQwertyKeyMappings.Count();
       
   700     }
       
   701 
       
   702 // ----------------------------------------------------------------------------
       
   703 // CPcsKeyMap::GetSpaceAndZeroOnSameKey
       
   704 // 
       
   705 // ----------------------------------------------------------------------------
       
   706 TBool CPcsKeyMap::GetSpaceAndZeroOnSameKey( TKeyboardModes aMode )
       
   707     {
       
   708     // Resolve ambiguous keyboard mode
       
   709     aMode = ResolveKeyboardMode( aMode );
       
   710     
       
   711     if ( aMode == EPredictiveItuT )
       
   712         {
       
   713         return iSpaceAndZeroOnSameKeyOnItut;
       
   714         }
       
   715     else if ( aMode == EPredictiveQwerty )
       
   716         {
       
   717         return iSpaceAndZeroOnSameKeyOnQwerty;
       
   718         }
   709         }
   719     else
   710     else
   720         {
   711         {
   721         return EFalse;
   712         // IF the key is not found, then it should go to the special pool,
   722         }
   713         // which is the last pool of iAllKeyMappingsPtrArr
   723     }
   714         numValue = iAllKeyMappingsPtrArr.Count() - 1;
   724 
   715         }
   725 // ----------------------------------------------------------------------------
   716 
   726 // CPcsKeyMap::SetSpaceAndZeroOnSameKey
   717     return numValue;
   727 // 
       
   728 // ----------------------------------------------------------------------------
       
   729 void CPcsKeyMap::SetSpaceAndZeroOnSameKey()
       
   730     {
       
   731     static const TInt KSpace = 0x20; // ASCII for " "
       
   732     static const TInt KZero  = 0x30; // ASCII for "0"
       
   733 
       
   734     TChar charSpace(KSpace);
       
   735     TChar charZero(KZero);
       
   736 
       
   737     TPtiKey keySpace;
       
   738     TPtiKey keyZero;
       
   739     
       
   740     // ITU-T mode
       
   741     keySpace = KeyForCharacter(charSpace, EPredictiveItuT);
       
   742     keyZero = KeyForCharacter(charZero, EPredictiveItuT);
       
   743     iSpaceAndZeroOnSameKeyOnItut = (keySpace == keyZero);
       
   744     
       
   745     // QWERTY mode
       
   746     keySpace = KeyForCharacter(charSpace, EPredictiveQwerty);
       
   747     keyZero = KeyForCharacter(charZero, EPredictiveQwerty);
       
   748     iSpaceAndZeroOnSameKeyOnQwerty = (keySpace == keyZero);
       
   749     }
   718     }
   750 
   719 
   751 // ----------------------------------------------------------------------------
   720 // ----------------------------------------------------------------------------
   752 // CPcsKeyMap::CPcsKeyMap::FirstCharFromSpellingL
   721 // CPcsKeyMap::CPcsKeyMap::FirstCharFromSpellingL
   753 // 
   722 // 
   755 TChar CPcsKeyMap::FirstCharFromSpellingL( TChar aChar ) const
   724 TChar CPcsKeyMap::FirstCharFromSpellingL( TChar aChar ) const
   756     {
   725     {
   757     TChar translated( aChar );
   726     TChar translated( aChar );
   758     TBuf<1> temp;
   727     TBuf<1> temp;
   759     temp.Append( aChar );
   728     temp.Append( aChar );
   760     if ( iAlgorithm->FindUtilECE()->IsChineseWordIncluded( temp ) )
   729     if ( iAlgorithm->FindUtilECE()->IsChineseWord( temp ) )
   761         {
   730         {
   762         RPointerArray<HBufC> spellList;
   731         RPointerArray<HBufC> spellList;
   763         CleanupResetAndDestroyPushL( spellList );
   732         CleanupResetAndDestroyPushL( spellList );
   764         if (iAlgorithm->FindUtilECE()->DoTranslationL(aChar, spellList))
   733         if (iAlgorithm->FindUtilECE()->DoTranslationL(aChar, spellList))
   765             {
   734             {
   767             }
   736             }
   768         CleanupStack::PopAndDestroy( &spellList ); // ResetAndDestroy
   737         CleanupStack::PopAndDestroy( &spellList ); // ResetAndDestroy
   769         }
   738         }
   770     return translated;
   739     return translated;
   771     }
   740     }
   772 
   741 // ----------------------------------------------------------------------------
   773 // ----------------------------------------------------------------------------
   742 // CPcsKeyMap::PoolCount
   774 // CPcsKeyMap::KeyMappings
   743 // 
   775 //
   744 // ----------------------------------------------------------------------------
   776 // ----------------------------------------------------------------------------
   745 TInt CPcsKeyMap::PoolCount()
   777 const RPointerArray<TKeyMappingData>* CPcsKeyMap::KeyMappings( TKeyboardModes aMode ) const
   746     {
   778     {
   747     return iAllKeyMappingsPtrArr.Count();
   779     const RPointerArray<TKeyMappingData>* mappings = NULL;
       
   780     
       
   781     if ( aMode == EPredictiveItuT )
       
   782         {
       
   783         mappings = &iItutKeyMappings;
       
   784         }
       
   785     else if ( aMode == EPredictiveQwerty )
       
   786         {
       
   787         mappings = &iQwertyKeyMappings;
       
   788         }
       
   789     else if ( aMode == ENonPredictive )
       
   790         {
       
   791         mappings = NULL;
       
   792         }
       
   793     else
       
   794         {
       
   795         mappings = NULL;
       
   796         __ASSERT_DEBUG( EFalse, Panic( EPanic_InvalidKeyboardType ) );
       
   797         }
       
   798     
       
   799     return mappings;
       
   800     }
       
   801 
       
   802 // ----------------------------------------------------------------------------
       
   803 // CPcsKeyMap::ResolveKeyboardMode
       
   804 // 
       
   805 // ----------------------------------------------------------------------------
       
   806 TKeyboardModes CPcsKeyMap::ResolveKeyboardMode( TKeyboardModes aKbMode ) const
       
   807     {
       
   808     TKeyboardModes resolvedMode = aKbMode;
       
   809     
       
   810     // Substitute "default predictive" mode with actual mode
       
   811     if ( resolvedMode == EPredictiveDefaultKeyboard )
       
   812         {
       
   813         resolvedMode = ( iItutIsDefault ? EPredictiveItuT : EPredictiveQwerty );
       
   814         }
       
   815 
       
   816     // Substitute predictive mode with non-predictive mode if corresponding
       
   817     // keyboard mappings are not available.
       
   818     if ( ( resolvedMode == EPredictiveItuT && iItutKeyboardType == EPtiKeyboardNone ) ||
       
   819          ( resolvedMode == EPredictiveQwerty && iQwertyKeyboardType == EPtiKeyboardNone ) )
       
   820         {
       
   821         PRINT1( _L("CPcsKeyMap::ResolveKeyboardMode: Mappings for requested mode %d unavailable. Falling back to non-predictive mode!"), aKbMode );
       
   822         resolvedMode = ENonPredictive;
       
   823         }
       
   824     
       
   825     return resolvedMode;
       
   826     }
       
   827 
       
   828 // ----------------------------------------------------------------------------
       
   829 // CPcsKeyMap::DefaultCharForKey
       
   830 // 
       
   831 // ----------------------------------------------------------------------------
       
   832 TText CPcsKeyMap::DefaultCharForKey( TPtiKey aKey, TKeyboardModes aKbMode ) const
       
   833     {
       
   834     // On ITU-T, the Pti key code can be directly interpreted as unicode character.
       
   835     // Thus, default characters for keys are 1,2,3,4,5,6,7,8,9,0,*,#.
       
   836     TText defChar = aKey;
       
   837     
       
   838     // On QWERTY, using PtiKey values directly is not safe since all PtiKey values are
       
   839     // not codepoints of printable Unicode characters.
       
   840     // Treating these arbitrary numerical values as Unicode characters could break 
       
   841     // the uniqueness of keys when collated comparison is used. Also, converting same
       
   842     // data multiple times to "compare format" would then break the data.
       
   843     if ( aKbMode == EPredictiveQwerty )
       
   844         {
       
   845         // Take first mapped character of the key and convert it to upper case.
       
   846         TInt index = iQwertyKeys.Find( aKey );
       
   847         if ( index != KErrNotFound )
       
   848             {
       
   849             const RArray<TInt>& mappings = iQwertyKeyMappings[index]->iKeyMappingArray;
       
   850             if ( mappings.Count() )
       
   851                 {
       
   852                 defChar = User::UpperCase( mappings[0] );
       
   853                 }
       
   854             }
       
   855         }
       
   856     
       
   857     return defChar;
       
   858     }
   748     }
   859 // End of file
   749 // End of file