predictivesearch/PcsAlgorithm/Algorithm2/src/CPcsKeyMap.cpp
branchRCL_3
changeset 58 d4f567ce2e7c
parent 21 b3431bff8c19
child 64 c1e8ba0c2b16
equal deleted inserted replaced
57:2666d9724c76 58:d4f567ce2e7c
    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>
    26 #include <bldvariant.hrh>
    29 #include <bldvariant.hrh>
    27 #include <AknFepInternalCRKeys.h>
    30 #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 
    28 
    56 
    29 // ============================== MEMBER FUNCTIONS ============================
    57 // ============================== MEMBER FUNCTIONS ============================
    30 
    58 
    31 // ----------------------------------------------------------------------------
    59 // ----------------------------------------------------------------------------
    32 // CPcsKeyMap::NewL
    60 // CPcsKeyMap::NewL
    59 // 2nd Phase Constructor
    87 // 2nd Phase Constructor
    60 // ----------------------------------------------------------------------------
    88 // ----------------------------------------------------------------------------
    61 void CPcsKeyMap::ConstructL(CPcsAlgorithm2* aAlgorithm)
    89 void CPcsKeyMap::ConstructL(CPcsAlgorithm2* aAlgorithm)
    62     {
    90     {
    63     iLanguageNotSupported.Append(ELangJapanese);
    91     iLanguageNotSupported.Append(ELangJapanese);
       
    92     iLanguageNotSupported.Append(ELangKorean);
    64 
    93 
    65     iAlgorithm = aAlgorithm;
    94     iAlgorithm = aAlgorithm;
    66     iPtiEngine = CPtiEngine::NewL();
    95     iPtiEngine = CPtiEngine::NewL();
    67 	
    96 
       
    97     SetupKeyboardTypesL();
    68     ConstructKeymapL();
    98     ConstructKeymapL();
       
    99     SetSpaceAndZeroOnSameKey();
    69     }
   100     }
    70 
   101 
    71 // ----------------------------------------------------------------------------
   102 // ----------------------------------------------------------------------------
    72 // CPcsKeyMap::ReconstructKeymapL
   103 // CPcsKeyMap::ReconstructKeymapL
    73 // When the writing language is changed, the keymap needs reconstruct.
   104 // When the writing language is changed, the keymap needs reconstruct.
    74 // ----------------------------------------------------------------------------
   105 // ----------------------------------------------------------------------------
    75 void CPcsKeyMap::ReconstructKeymapL()
   106 void CPcsKeyMap::ReconstructKeymapL()
    76     {
   107     {
    77     TLanguage lang = iAlgorithm->FindUtilECE()->CurrentInputLanguage();
       
    78         if (lang == ELangPrcChinese || !IsLanguageSupportedL(lang))
       
    79             lang = ELangEnglish;
       
    80 
       
    81     TInt keyboardType = CurrentKeyBoardTypeL();
       
    82     
       
    83     // Clear the keymap data array first when reconstruct the keymap.
   108     // Clear the keymap data array first when reconstruct the keymap.
    84     ResetKeyMap();
   109     ResetKeyMap();
    85     
   110     
    86     // Add new keymap to the keymap data array according the current writing language.
   111     // Always add English mappings first
    87     AddKeyMapforConcreteKeyboardL( keyboardType, lang );
   112     AddKeyMapforConcreteKeyboardL( ELangEnglish );
       
   113     
       
   114     // Then append the mappings of the current input language
       
   115     TLanguage lang = iAlgorithm->FindUtilECE()->CurrentInputLanguage();
       
   116     if ( lang != ELangEnglish && IsLanguageSupportedL(lang) )
       
   117         {
       
   118         AddKeyMapforConcreteKeyboardL( lang );
       
   119         }
    88     }
   120     }
    89 
   121 
    90 // ----------------------------------------------------------------------------
   122 // ----------------------------------------------------------------------------
    91 // CPcsKeyMap::ConstructKeymapL
   123 // CPcsKeyMap::ConstructKeymapL
    92 // 
   124 // 
    93 // ----------------------------------------------------------------------------
   125 // ----------------------------------------------------------------------------
    94 void CPcsKeyMap::ConstructKeymapL()
   126 void CPcsKeyMap::ConstructKeymapL()
    95     {
   127     {
       
   128     ConstructConcreteKeyMapL();
       
   129     
       
   130     // Always add English mappings first
       
   131     AddKeyMapforConcreteKeyboardL( ELangEnglish );
       
   132     
       
   133     // Then append the mappings of the current input language
    96     TLanguage lang = iAlgorithm->FindUtilECE()->CurrentInputLanguage();
   134     TLanguage lang = iAlgorithm->FindUtilECE()->CurrentInputLanguage();
    97     if (lang == ELangPrcChinese || !IsLanguageSupportedL(lang))
   135     if ( lang != ELangEnglish && IsLanguageSupportedL(lang) )
    98         lang = ELangEnglish;
   136         {
    99 
   137         AddKeyMapforConcreteKeyboardL( lang );
   100     TInt keyboardType = CurrentKeyBoardTypeL();
   138         }
   101     
       
   102     ConstructConcreteKeyMapL( keyboardType, lang );
       
   103     
   139     
   104     PRINT ( _L("----------------------------------------"));
   140     PRINT ( _L("----------------------------------------"));
   105     
   141     }
   106     }
   142 
   107 
   143 // ----------------------------------------------------------------------------
   108 // ----------------------------------------------------------------------------
   144 // CPcsKeyMap::SetupKeyboardTypesL
   109 // CPcsKeyMap::CurrentKeyBoardTypeL
   145 // Initialise the keyboard type variables
   110 // 
   146 // ----------------------------------------------------------------------------
   111 // ----------------------------------------------------------------------------
   147 void CPcsKeyMap::SetupKeyboardTypesL()
   112 TInt CPcsKeyMap::CurrentKeyBoardTypeL()
   148     {
   113     {
       
   114     TInt keyBoardType = EPtiKeyboardNone;
       
   115     
       
   116 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   117     
       
   118     TInt physicalKeyboard = 0;
   149     TInt physicalKeyboard = 0;
   119     CRepository* aknFepRepository = CRepository::NewL( KCRUidAknFep );
   150     CRepository* aknFepRepository = CRepository::NewL( KCRUidAknFep );
   120     // Get all the physical keyboards which are connected to the phone currently.
       
   121     aknFepRepository->Get( KAknFepPhysicalKeyboards, physicalKeyboard );
   151     aknFepRepository->Get( KAknFepPhysicalKeyboards, physicalKeyboard );
   122     delete aknFepRepository;
   152     delete aknFepRepository;
   123     
   153 
   124     
   154     PRINT1 ( _L("CPcsKeyMap::ConstructL: Physical keyboard support flag = 0x%02X"), physicalKeyboard );
   125     PRINT1 ( _L("CPcsKeyMap::CurrentKeyBoardTypeL: Physical keyboard support flag = 0x%02X"), physicalKeyboard );
       
   126 
   155 
   127     // Constants follow the definition of KAknFepPhysicalKeyboards
   156     // Constants follow the definition of KAknFepPhysicalKeyboards
   128     const TInt ptiKeyboard12Key = 0x01;         // Default
   157     const TInt KPtiKeyboard12Key = 0x01;
   129     // const TInt ptiKeyboardQwerty4x12 = 0x02;    // Not used at the moment
   158     const TInt KPtiKeyboardQwerty4x12 = 0x02;
   130     const TInt ptiKeyboardQwerty4x10 = 0x04;
   159     const TInt KPtiKeyboardQwerty4x10 = 0x04;
   131     // const TInt ptiKeyboardQwerty3x11 = 0x08;    // Not used at the moment
   160     const TInt KPtiKeyboardQwerty3x11 = 0x08;
   132     const TInt ptiKeyboardHalfQwerty = 0x10;
   161     const TInt KPtiKeyboardHalfQwerty = 0x10;
   133     // const TInt ptiKeyboardCustomQwerty = 0x20;  // Not used at the moment
   162     const TInt KPtiKeyboardCustomQwerty = 0x20; 
   134 
   163 
   135     // If there are more than 1 keyboards on HW, The priority from high to low for 
   164     // Setup ITU-T mode first.
   136     // selecting keyboard is EPtiKeyboard12Key, EPtiKeyboardHalfQwerty, EPtiKeyboardQwerty4x10  
   165     // Use always 12-key mode since all the supported devices should have at least
   137     if ( physicalKeyboard & ptiKeyboard12Key )
   166     // virtual ITU-T available.
   138         {
   167     iItutKeyboardType = EPtiKeyboard12Key;
   139         keyBoardType = EPtiKeyboard12Key;
   168     // TODO: ITU-T type could be set to "none" if device does not have either
   140         }
   169     // virtual keypad or hardware ITU-T available. This could be decided according
   141     else if ( physicalKeyboard & ptiKeyboardHalfQwerty )
   170     // some cenrep value, feature flag, device model, or platform version.
   142         {
   171     
   143         keyBoardType = EPtiKeyboardHalfQwerty;
   172     // Then setup QWERTY mode. On real-life devices there should never
   144         }
   173     // be more than one QWERTY keyboard available but on emulator there can be several.
   145     else if ( physicalKeyboard & ptiKeyboardQwerty4x10 )
   174     // Use the first one found in the following precedence
   146         {
   175     if ( physicalKeyboard & KPtiKeyboardQwerty3x11 )
   147         keyBoardType = EPtiKeyboardQwerty4x10;
   176         {
       
   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;
   148         }
   194         }
   149     else
   195     else
   150 #endif
   196         {
   151         {
   197         iQwertyKeyboardType = EPtiKeyboardNone;
   152         keyBoardType = EPtiKeyboard12Key;
   198         }
   153         }
   199     
   154     return keyBoardType;
   200     // Decide, which keyboard is used for the "default" matching mode.
   155     }
   201     // If there is physical ITU-T available, or there's no physical QWERTY,
       
   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 
   156 
   210 
   157 // ----------------------------------------------------------------------------
   211 // ----------------------------------------------------------------------------
   158 // CPcsKeyMap::ConstructConcreteKeyMapL
   212 // CPcsKeyMap::ConstructConcreteKeyMapL
   159 // 
   213 // 
   160 // ----------------------------------------------------------------------------
   214 // ----------------------------------------------------------------------------
   161 void CPcsKeyMap::ConstructConcreteKeyMapL( TInt aKeyboardType, TLanguage aLanguage )
   215 void CPcsKeyMap::ConstructConcreteKeyMapL()
   162     {
   216     {
   163     switch ( aKeyboardType )
   217     if ( iItutKeyboardType != EPtiKeyboardNone )
   164         {
   218         {
   165         case EPtiKeyboard12Key:
   219         // Construct for Itut keyboard by default
   166             {
   220         PRINT ( _L("CPcsKeyMap::ConstructConcreteKeyMapL: Construct keymap for ITU-T"));
   167             // Construct for Itut keyboard by default
   221         ConstructForItutKeyboardL();
   168             PRINT ( _L("CPcsKeyMap::ConstructConcreteKeyMapL: Construct keymap for ContructForItutKeyboardL"));
   222         }
   169             
   223     if ( iQwertyKeyboardType != EPtiKeyboardNone )
   170             ContructForItutKeyboardL( aLanguage );
   224         {
   171             break;
   225         // Construct for any QWERTY keyboard
   172             }
   226         PRINT1 ( _L("CPcsKeyMap::ConstructConcreteKeyMapL: Construct keymap for QWERTY keyboard type %d"), 
   173         case EPtiKeyboardHalfQwerty:
   227                  iQwertyKeyboardType );
   174             {
   228         ConstructForQwertyKeyboardL( iQwertyKeyboardType );
   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             }
       
   196         }
   229         }
   197     }
   230     }
   198 
   231 
   199 // ----------------------------------------------------------------------------
   232 // ----------------------------------------------------------------------------
   200 // CPcsKeyMap::AddKeyMapforConcreteKeyboardL
   233 // CPcsKeyMap::AddKeyMapforConcreteKeyboardL
   201 // 
   234 // 
   202 // ----------------------------------------------------------------------------
   235 // ----------------------------------------------------------------------------
   203 void CPcsKeyMap::AddKeyMapforConcreteKeyboardL( TInt aKeyboardType, TLanguage aLanguage )
   236 void CPcsKeyMap::AddKeyMapforConcreteKeyboardL( TLanguage aLanguage )
   204     {
   237     {
   205     // If it's TW or HK variant, the key map for English also needs add to current key map.
   238     if ( iItutKeyboardType != EPtiKeyboardNone )
   206     TBool needAddEnglishKeyMap = ( aLanguage == ELangTaiwanChinese || aLanguage == ELangHongKongChinese );
   239         {
   207     
   240         AddKeyMapforItutL( aLanguage );
   208     // Add the keymap for current writing language.
   241         }
   209     switch ( aKeyboardType )
   242     
   210         {
   243     if ( iQwertyKeyboardType != EPtiKeyboardNone )
   211         case EPtiKeyboard12Key:
   244         {
   212             {
   245         AddKeyMapForQwertyKeyboardL( aLanguage, iQwertyKeyboardType );
   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     for (TInt i = 0; i < iAllKeyMappingsPtrArr.Count(); i++)
   255     const TInt ItutKeyMappingsCount = iItutKeyMappings.Count();
   256         {
   256     const TInt qwertyKeyMappingsCount = iQwertyKeyMappings.Count();
   257         iAllKeyMappingsPtrArr[i]->iKeyMappingArray.Close();
   257     for (TInt i = 0; i < ItutKeyMappingsCount; i++)
   258         }
   258         {
   259 
   259         iItutKeyMappings[i]->iKeyMappingArray.Reset();
   260     }
   260         }
       
   261     for (TInt i = 0; i < qwertyKeyMappingsCount; i++)
       
   262         {
       
   263         iQwertyKeyMappings[i]->iKeyMappingArray.Reset();
       
   264         }
       
   265     }
       
   266 
   261 // ----------------------------------------------------------------------------
   267 // ----------------------------------------------------------------------------
   262 // CPcsKeyMap::~CPcsKeyMap
   268 // CPcsKeyMap::~CPcsKeyMap
   263 // Destructor
   269 // Destructor
   264 // ----------------------------------------------------------------------------
   270 // ----------------------------------------------------------------------------
   265 CPcsKeyMap::~CPcsKeyMap()
   271 CPcsKeyMap::~CPcsKeyMap()
   266     {
   272     {
   267     ResetKeyMap();
   273     ResetKeyMap();
   268 
   274 
   269     // Cleanup local arrays
   275     // Cleanup local arrays
   270     iLanguageNotSupported.Reset();
   276     iLanguageNotSupported.Reset();
   271     iAllKeyMappingsPtrArr.ResetAndDestroy();
   277     iItutKeyMappings.ResetAndDestroy();
   272     iKeysForPoolFormation.Close();
   278     iItutKeys.Close();
       
   279     iQwertyKeyMappings.ResetAndDestroy();
       
   280     iQwertyKeys.Close();
   273     delete iPtiEngine;
   281     delete iPtiEngine;
   274     }
   282     }
   275 
   283 
   276 // ----------------------------------------------------------------------------
   284 // ----------------------------------------------------------------------------
   277 // CPcsKeyMap::GetNumericKeyStringL
   285 // CPcsKeyMap::GetMixedKeyStringForQueryL
   278 // 
   286 // aDestStr will have the length as the number of items in aSrcQuery.
   279 // ----------------------------------------------------------------------------
   287 // ----------------------------------------------------------------------------
   280 void CPcsKeyMap::GetNumericKeyString(const TDesC& aSrcStr, TDes& aDestStr)
   288 void CPcsKeyMap::GetMixedKeyStringForQueryL(
   281     {
   289         CPsQuery& aSrcQuery, TDes& aDestStr) const
   282     for (int i = 0; i < aSrcStr.Length(); i++)
   290 {
   283         {
   291     PRINT ( _L("Enter CPcsKeyMap::GetMixedKeyStringForQueryL") ); 
   284         TInt index = KeyForCharacter(aSrcStr[i]);
   292 
   285 
   293     GetMixedKeyStringForDataL( aSrcQuery, aSrcQuery.QueryAsStringLC(), aDestStr );
   286         // If a character is not mapped to numeric key append the character
   294     CleanupStack::PopAndDestroy(); //result of QueryAsStringLC
   287         if (index == -1)
   295 
   288             {
   296     PRINT ( _L("End CPcsKeyMap::GetMixedKeyStringForQueryL") );
   289             aDestStr.Append(aSrcStr[i]);
   297 }
       
   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                 }
   290             }
   328             }
   291         else
   329         else
   292             {
   330             {
   293             aDestStr.Append(index);
   331             // characters over query length are taken as exact
   294             }
   332             aDestStr.Append( character );
   295         }
   333             }
   296     }
   334         }
       
   335 
       
   336     PRINT1 ( _L("CPcsKeyMap::GetMixedKeyStringForDataL: Return string: \"%S\""),
       
   337              &aDestStr );
       
   338 
       
   339     PRINT ( _L("End CPcsKeyMap::GetMixedKeyStringForDataL") );
       
   340 }
   297 
   341 
   298 // ----------------------------------------------------------------------------
   342 // ----------------------------------------------------------------------------
   299 // CPcsKeyMap::KeyForCharacter
   343 // CPcsKeyMap::KeyForCharacter
   300 // 
   344 // 
   301 // ----------------------------------------------------------------------------
   345 // ----------------------------------------------------------------------------
   302 TInt CPcsKeyMap::KeyForCharacter(const TChar& aChar)
   346 TPtiKey CPcsKeyMap::KeyForCharacter(TText aChar, TKeyboardModes aKbMode) const
   303     {
   347     {
       
   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     
   304     TInt index = KErrNotFound;
   356     TInt index = KErrNotFound;
   305 
   357 
   306     TChar lChar = User::LowerCase(aChar);
   358     TText lChar = User::LowerCase(aChar);
   307 
   359 
   308     TInt count = iAllKeyMappingsPtrArr.Count() - 1;
   360     const TInt count = keyMappings->Count() - 1;
   309 
   361 
   310     for (TInt i = 0; i < count; i++)
   362     for (TInt i = 0; i < count; i++)
   311         {
   363         {
   312         index = iAllKeyMappingsPtrArr[i]->iKeyMappingArray.Find(lChar);
   364         index = (*keyMappings)[i]->iKeyMappingArray.Find(lChar);
   313         if (index != KErrNotFound)
   365         if (index != KErrNotFound)
   314             {
   366             {
   315             return (TInt) iAllKeyMappingsPtrArr[i]->key;
   367             return (*keyMappings)[i]->iKey;
   316             }
   368             }
   317         }
   369         }
   318 
   370 
   319     return index;
   371     return EPtiKeyNone;
   320     }
   372     }
   321 // ----------------------------------------------------------------------------
   373 
   322 // CPcsKeyMap::ContructForHalfQwertyKeyboardL
   374 // ----------------------------------------------------------------------------
   323 // 
   375 // CPcsKeyMap::AddKeyMapForQwertyKeyboardL
   324 // ----------------------------------------------------------------------------
   376 // 
   325 void CPcsKeyMap::ContructForHalfQwertyKeyboardL(TLanguage aLanguage)
   377 // ----------------------------------------------------------------------------
   326     {
   378 void CPcsKeyMap::AddKeyMapForQwertyKeyboardL(TLanguage aLanguage, TPtiKeyboardType aKbType)
   327 #ifdef RD_INTELLIGENT_TEXT_INPUT    
   379     {
   328 
   380 #ifdef RD_INTELLIGENT_TEXT_INPUT
   329     iKeysForPoolFormation.Append(EPtiKeyQwertyQ);
   381     iPtiEngine->ActivateLanguageL(aLanguage);
   330     iKeysForPoolFormation.Append(EPtiKeyQwertyE);
   382     iPtiEngine->SetKeyboardType(aKbType);
   331     iKeysForPoolFormation.Append(EPtiKeyQwertyT);
   383 
   332     iKeysForPoolFormation.Append(EPtiKeyQwertyU);
   384     // Make a language object based on current language
   333     iKeysForPoolFormation.Append(EPtiKeyQwertyO);
   385     CPtiCoreLanguage* coreLanguage = static_cast<CPtiCoreLanguage*>(iPtiEngine->GetLanguage( aLanguage ));
   334     iKeysForPoolFormation.Append(EPtiKeyQwertyA);
   386 
   335     iKeysForPoolFormation.Append(EPtiKeyQwertyD);
   387     //Perfrom the key mappings only if the corelanguage is available
   336     iKeysForPoolFormation.Append(EPtiKeyQwertyG);
   388     if (coreLanguage)
   337     iKeysForPoolFormation.Append(EPtiKeyQwertyJ);
   389         {
   338     iKeysForPoolFormation.Append(EPtiKeyQwertyL);
   390         // Get the keyboard mappings for the language
   339     iKeysForPoolFormation.Append(EPtiKeyQwertyZ);
   391         CPtiKeyMapData* ptiKeyMapData = coreLanguage->RawKeyMapData();
   340     iKeysForPoolFormation.Append(EPtiKeyQwertyC);
   392 
   341     iKeysForPoolFormation.Append(EPtiKeyQwertyB);
   393         const TInt qwertyKeyMappingsCount = iQwertyKeyMappings.Count() - 1;
   342     iKeysForPoolFormation.Append(EPtiKeyQwertyM);
   394         for (TInt i = 0; i < qwertyKeyMappingsCount; i++)
   343     iKeysForPoolFormation.Append(EPtiKeyQwerty0);
   395             {
   344     // one additional pool for special characters not mapped too any keys. 
   396             AddDataForQwertyKeyboardL( ptiKeyMapData, aKbType, 
   345     // This should always be the last one in the arrary
   397                     iQwertyKeys[i], *(iQwertyKeyMappings[i]) );
   346     iKeysForPoolFormation.Append(EPtiKeyNone);
   398             }
       
   399         }
       
   400 #endif // RD_INTELLIGENT_TEXT_INPUT        
       
   401     }
       
   402 
       
   403 // ----------------------------------------------------------------------------
       
   404 // CPcsKeyMap::ConstructForQwertyKeyboardL
       
   405 // Destructor
       
   406 // ----------------------------------------------------------------------------
       
   407 void CPcsKeyMap::ConstructForQwertyKeyboardL(TPtiKeyboardType aKbType)
       
   408     {
       
   409 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   410     CreateKeyListFromKeyBindingTable( iQwertyKeys, aKbType );
   347 
   411 
   348     // Now add the keymap arrays to hold the keymap data
   412     // Now add the keymap arrays to hold the keymap data
   349     for (TInt i = 0; i < iKeysForPoolFormation.Count(); i++)
   413     const TInt qwertyKeysCount = iQwertyKeys.Count();
   350         {
   414     for (TInt i = 0; i < qwertyKeysCount; i++)
   351         TKeyMappingData *keyData = new (ELeave) TKeyMappingData;
   415         {
   352         keyData->key = iKeysForPoolFormation[i];
   416         TKeyMappingData* keyData = new (ELeave) TKeyMappingData;
   353         iAllKeyMappingsPtrArr.Append(keyData);
   417         keyData->iKey = iQwertyKeys[i];
   354         }
   418         iQwertyKeyMappings.Append(keyData);
   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         }
   419         }
   363 
   420 
   364     PRINT ( _L("----------------------------------------"));
   421     PRINT ( _L("----------------------------------------"));
   365 #endif // RD_INTELLIGENT_TEXT_INPUT
   422 #endif //RD_INTELLIGENT_TEXT_INPUT
   366     }
   423     }
   367 // ----------------------------------------------------------------------------
   424 
   368 // CPcsKeyMap::AddKeyMapforHalfQwertyKeyboardL
   425 // ----------------------------------------------------------------------------
   369 // 
   426 // CPcsKeyMap::AddDataForQwertyKeyboardL
   370 // ----------------------------------------------------------------------------
   427 // 
   371 void CPcsKeyMap::AddKeyMapforHalfQwertyKeyboardL(TLanguage aLanguage)
   428 // ----------------------------------------------------------------------------
   372     {
   429 void CPcsKeyMap::AddDataForQwertyKeyboardL(CPtiKeyMapData* aPtiKeyMapData,
   373 #ifdef RD_INTELLIGENT_TEXT_INPUT     	
   430                                            TPtiKeyboardType aKbType,
   374     // Make a language object based on current language
   431                                            TPtiKey aKey,
   375     CPtiCoreLanguage* iCoreLanguage = static_cast<CPtiCoreLanguage*>(iPtiEngine->GetLanguage(  aLanguage));
   432                                            TKeyMappingData& aKeyDataList)
   376 
       
   377     //Perfrom the key mappings only if the corelanguage is available
       
   378     if (iCoreLanguage)
       
   379         {
       
   380         // Get the keyboard mappings for the language
       
   381         CPtiHalfQwertyKeyMappings* ptiKeyMappings = static_cast<CPtiHalfQwertyKeyMappings*> 
       
   382                 (iCoreLanguage->GetHalfQwertyKeymappings());
       
   383 
       
   384         iPtiEngine->ActivateLanguageL(aLanguage, EPtiEngineHalfQwerty);
       
   385         iPtiEngine->SetKeyboardType(EPtiKeyboardHalfQwerty);
       
   386 
       
   387         for (TInt i = 0; i < iAllKeyMappingsPtrArr.Count() - 1; i++)
       
   388             {
       
   389             AddDataForHalfQwertyKeyboardL( ptiKeyMappings, iKeysForPoolFormation[i], *(iAllKeyMappingsPtrArr[i]));
       
   390             }
       
   391         }
       
   392 #endif // RD_INTELLIGENT_TEXT_INPUT        
       
   393     }
       
   394 
       
   395 // ----------------------------------------------------------------------------
       
   396 // CPcsKeyMap::AddDataForHalfQwertyKeyboardL
       
   397 // 
       
   398 // ----------------------------------------------------------------------------
       
   399 void CPcsKeyMap::AddDataForHalfQwertyKeyboardL( CPtiHalfQwertyKeyMappings* aPtiKeyMappings, 
       
   400                                                TPtiKey aKey,  
       
   401                                                TKeyMappingData& aKeyDataList)
       
   402     {
   433     {
   403 #ifdef RD_INTELLIGENT_TEXT_INPUT     	
   434 #ifdef RD_INTELLIGENT_TEXT_INPUT     	
   404     TPtiTextCase caseArray[] =
   435     TPtiTextCase caseArray[] =
   405         {
   436         {
   406         EPtiCaseUpper,
   437         EPtiCaseUpper,
   409         EPtiCaseFnUpper,
   440         EPtiCaseFnUpper,
   410         EPtiCaseChrLower,
   441         EPtiCaseChrLower,
   411         EPtiCaseChrUpper
   442         EPtiCaseChrUpper
   412         };
   443         };
   413     
   444     
   414     TBuf<50> iResult;
   445     for (TInt i = 0; i < sizeof(caseArray) / sizeof(TPtiTextCase); i++)
   415     for (int i = 0; i < sizeof(caseArray) / sizeof(TPtiTextCase); i++)
   446         {
   416         {
   447         TPtrC result = aPtiKeyMapData->DataForKey(aKbType, aKey, caseArray[i]);
   417         iResult.Zero();
   448 
   418         aPtiKeyMappings->GetDataForKey(aKey, iResult, caseArray[i]);
   449         const TInt resultLength = result.Length(); 
   419 
   450         for (TInt j = 0; j < resultLength; j++)
   420         for (int j = 0; j < iResult.Length(); j++)
   451             aKeyDataList.iKeyMappingArray.Append(result[j]);
   421             aKeyDataList.iKeyMappingArray.Append(iResult[j]);
   452 
   422 
   453         PRINT2 ( _L("CPcsKeyMap: Mapping for Key %c = %S"), aKey, &result)
   423         PRINT2 ( _L("CPcsKeyMap: Mapping for Key %c = %S"), aKey,&iResult)
   454         }
   424         }
   455 #endif //RD_INTELLIGENT_TEXT_INPUT        
   425 #endif // RD_INTELLIGENT_TEXT_INPUT        
   456     }
   426     }
   457 
   427 
   458 // ----------------------------------------------------------------------------
   428 // ----------------------------------------------------------------------------
   459 // CPcsKeyMap::ContructForItutKeyboardL
   429 // CPcsKeyMap::ContructFor4x10QwertyKeyboardL
   460 // 
   430 // Destructor
   461 // ----------------------------------------------------------------------------
   431 // ----------------------------------------------------------------------------
   462 void CPcsKeyMap::ConstructForItutKeyboardL()
   432 void CPcsKeyMap::ContructFor4x10QwertyKeyboardL(TLanguage aLanguage)
   463     {
   433     {
   464     // Add the keys for Pool formation
   434 #ifdef RD_INTELLIGENT_TEXT_INPUT     
   465     iItutKeys.Append(EPtiKey0);
   435 // The special 4x10 Qwerty keyboard for Sonja.
   466     iItutKeys.Append(EPtiKey1);
   436     iKeysForPoolFormation.Append( EPtiKeyQwertyA );
   467     iItutKeys.Append(EPtiKey2);
   437     iKeysForPoolFormation.Append( EPtiKeyQwerty8 );
   468     iItutKeys.Append(EPtiKey3);
   438     iKeysForPoolFormation.Append( EPtiKeyQwertyC );
   469     iItutKeys.Append(EPtiKey4);
   439     iKeysForPoolFormation.Append( EPtiKeyQwertyD );
   470     iItutKeys.Append(EPtiKey5);
   440     iKeysForPoolFormation.Append( EPtiKeyQwertyE );
   471     iItutKeys.Append(EPtiKey6);
   441     iKeysForPoolFormation.Append( EPtiKeyQwerty4 );
   472     iItutKeys.Append(EPtiKey7);
   442     iKeysForPoolFormation.Append( EPtiKeyQwerty5 );
   473     iItutKeys.Append(EPtiKey8);
   443     iKeysForPoolFormation.Append( EPtiKeyQwerty6 );
   474     iItutKeys.Append(EPtiKey9);
   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     
       
   463     // one additional pool for special characters not mapped too any keys. 
   475     // one additional pool for special characters not mapped too any keys. 
   464     // This should always be the last one in the arrary
   476     // This should always be the last one in the arrary
   465     iKeysForPoolFormation.Append(EPtiKeyNone);
   477     iItutKeys.Append(EPtiKeyNone);
   466 
   478 
   467     // Now add the keymap arrays to hold the keymap data
   479     // Now add the keymap arrays to hold the keymap data
   468     for (TInt i = 0; i < iKeysForPoolFormation.Count(); i++)
   480     const TInt ltutKeysCount = iItutKeys.Count();
       
   481     for (TInt i = 0; i < ltutKeysCount; i++)
   469         {
   482         {
   470         TKeyMappingData *keyData = new (ELeave) TKeyMappingData;
   483         TKeyMappingData *keyData = new (ELeave) TKeyMappingData;
   471         keyData->key = iKeysForPoolFormation[i];
   484         keyData->iKey = iItutKeys[i];
   472         iAllKeyMappingsPtrArr.Append(keyData);
   485         iItutKeyMappings.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);
       
   482         }
   486         }
   483 
   487 
   484     PRINT ( _L("----------------------------------------"));
   488     PRINT ( _L("----------------------------------------"));
   485 #endif //RD_INTELLIGENT_TEXT_INPUT
   489     }
   486     }
   490 
   487 
   491 // ----------------------------------------------------------------------------
   488 // ----------------------------------------------------------------------------
   492 // CPcsKeyMap::AddKeyMapforItutLanguageL
   489 // CPcsKeyMap::AddKeyMapfor4x10QwertyKeyboardL
   493 // 
   490 // 
   494 // ----------------------------------------------------------------------------
   491 // ----------------------------------------------------------------------------
   495 void CPcsKeyMap::AddKeyMapforItutL(TLanguage aLanguage)
   492 void CPcsKeyMap::AddKeyMapfor4x10QwertyKeyboardL(TLanguage aLanguage)
   496     {
   493     {
   497     // Activate given language and get corresponding language object
   494 #ifdef RD_INTELLIGENT_TEXT_INPUT     	
   498     iPtiEngine->ActivateLanguageL(aLanguage);
   495     // Make a language object based on current language
   499     CPtiCoreLanguage* coreLanguage = static_cast<CPtiCoreLanguage*> (iPtiEngine->GetLanguage(aLanguage));
   496     CPtiCoreLanguage* iCoreLanguage = static_cast<CPtiCoreLanguage*>(iPtiEngine->GetLanguage(aLanguage));
       
   497 
   500 
   498     //Perfrom the key mappings only if the corelanguage is available
   501     //Perfrom the key mappings only if the corelanguage is available
   499     if (iCoreLanguage)
   502     if (coreLanguage)
   500         {
   503         {
   501         // Get the keyboard mappings for the language
   504         // Get the keyboard mappings for the language
   502         CPtiQwertyKeyMappings* iPtiKeyMappings = static_cast<CPtiQwertyKeyMappings *> 
   505         CPtiKeyMapData* ptiKeyMapData = coreLanguage->RawKeyMapData();
   503                 (iCoreLanguage->GetQwertyKeymappings());
   506 
   504         iPtiEngine->SetKeyboardType(EPtiKeyboardQwerty4x10);
   507         const TInt ltutKeyMappingsCount = iItutKeyMappings.Count() - 1;
   505 
   508         for (TInt i = 0; i < ltutKeyMappingsCount; i++)
   506         for (TInt i = 0; i < iAllKeyMappingsPtrArr.Count() - 1; i++)
   509             {
   507             {
   510             AddDataForItutKeyboardL(ptiKeyMapData, iItutKeys[i], *(iItutKeyMappings[i]));
   508             AddDataFor4x10QwertyKeyboardL(iPtiKeyMappings, iKeysForPoolFormation[i], *(iAllKeyMappingsPtrArr[i]));
   511             }
   509             }
   512         }
   510 
   513 
   511 #ifdef HACK_FOR_E72_J_KEY
   514     if ( (aLanguage == ELangPrcChinese || aLanguage == ELangTaiwanChinese || aLanguage == ELangHongKongChinese) && 
   512         AddDataFor4x10QwertyKeyboardE72HackL();
   515          (iAlgorithm->FindUtilECE()->CurrentSearchMethod() == EAdptSearchStroke) )
   513 #endif // HACK_FOR_E72_J_KEY
   516         {
   514         }
   517         (*(iItutKeyMappings[1])).iKeyMappingArray.Append(0x4E00); //heng
   515 #endif //RD_INTELLIGENT_TEXT_INPUT        
   518         (*(iItutKeyMappings[2])).iKeyMappingArray.Append(0x4E28); //shu
   516 
   519         (*(iItutKeyMappings[3])).iKeyMappingArray.Append(0x4E3F); //pie
   517     }
   520         (*(iItutKeyMappings[4])).iKeyMappingArray.Append(0x4E36); //dian
   518 
   521         (*(iItutKeyMappings[5])).iKeyMappingArray.Append(0x4E5B); //zhe
   519 #ifdef HACK_FOR_E72_J_KEY
   522         }
   520 // ----------------------------------------------------------------------------
   523 
   521 // CPcsKeyMap::AddDataFor4x10QwertyKeyboardE72HackL
   524     }
       
   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
   522 //
   544 //
   523 // Key code for J/# key in Sonja is EPtiKeyQwertyHash (127).
   545 // ----------------------------------------------------------------------------
   524 // No returned character code ('J', 'j', '#') has 127 as ASCII value.
   546 void CPcsKeyMap::CreateKeyListFromKeyBindingTable( RArray<TPtiKey>& aKeyArray, 
   525 // In this case we must add key to the list of characters for the pool.
   547         TPtiKeyboardType aKbType )
   526 // ----------------------------------------------------------------------------
   548     {
   527 void CPcsKeyMap::AddDataFor4x10QwertyKeyboardE72HackL()
   549     PRINT ( _L("Enter CPcsKeyMap::CreateKeyListFromKeyBindingTable") );
   528     {
   550 
   529 #ifdef RD_INTELLIGENT_TEXT_INPUT    
   551     // Use Eglish mappings to list the keys on the keyboard
   530     PRINT ( _L("Enter CPcsKeyMap::AddDataFor4x10QwertyKeyboardE72HackL") );
   552     TRAP_IGNORE( iPtiEngine->ActivateLanguageL( ELangEnglish ) );
   531 
   553     CPtiCoreLanguage* ptiLang = 
   532     TPtiKey keyValue = (TPtiKey) EPtiKeyQwertyHash;
   554             static_cast<CPtiCoreLanguage*>(iPtiEngine->GetLanguage( ELangEnglish ));
   533     TInt keyIndex = iKeysForPoolFormation.Find(keyValue);    
   555 
   534 
   556     if (ptiLang)
   535     PRINT3 ( _L("CPcsKeyMap: ===== At index %d appending key to list: '%c' (#%d) -Hack-for-E72-"),
   557         {
   536              keyIndex, (TInt) keyValue, (TInt) keyValue);
   558         const CPtiKeyMapData* keyMapData = ptiLang->RawKeyMapData();
   537 
   559         const TPtiKeyBinding* table = NULL;
   538     if ( KErrNotFound != keyIndex )
   560         TInt numItems = 0;
   539         {
   561         if ( keyMapData )
   540         iAllKeyMappingsPtrArr[keyIndex]->iKeyMappingArray.Append(keyValue);
   562             {
   541         }
   563             table = keyMapData->KeyBindingTable(aKbType, numItems);
   542 
   564             }
   543     PRINT ( _L("CPcsKeyMap: ===================================================") );  
   565         else
   544 
   566             {
   545     PRINT ( _L("End CPcsKeyMap::AddDataFor4x10QwertyKeyboardE72HackL") );
   567             PRINT( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: #### Failed to get RawKeyMapData ####") );
   546 #endif // RD_INTELLIGENT_TEXT_INPUT    
   568             }
   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             };
       
   568         
   569         
   569     TBuf<50> iResult;
   570         PRINT1 ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: Num of Items in KeyBindingTable is %d"), numItems );
   570     for (int i = 0; i < sizeof(caseArray) / sizeof(TPtiTextCase); i++)
   571 
   571         {
   572         // Get from the key table the keys for constructing the pools
   572         iResult.Zero();
   573         if (table)
   573         iPtiKeyMappings->GetDataForKey(aKey, iResult, caseArray[i]);
   574             {
   574 
   575             for (TInt i = 0; i < numItems; i++)
   575         for (int j = 0; j < iResult.Length(); j++)
   576                 {
   576             aKeyDataList.iKeyMappingArray.Append(iResult[j]);
   577                 TPtiKey key = (TPtiKey) table[i].iScanCode;
   577 
   578                 // Get all keys with same EPtiCaseLower or EPtiCaseUpper case
   578         PRINT2 ( _L("CPcsKeyMap: Mapping for Key %c = %S"), aKey, &iResult)
   579                 // Only for one of the casing to avoid repetitions
   579         }
   580                 if ( (EPtiKeyNone != key) && (EPtiCaseLower == table[i].iCase) )
   580 #endif //RD_INTELLIGENT_TEXT_INPUT        
   581                     {
   581     }
   582                     PRINT3 ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: Adding pool %d with key '%c' (0x%02X)"),
   582 
   583                             aKeyArray.Count(), key, key );
   583 // ----------------------------------------------------------------------------
   584                     aKeyArray.Append( key );
   584 // CPcsKeyMap::ContructForItutKeyboardL
   585                     }
   585 // 
   586                 }
   586 // ----------------------------------------------------------------------------
   587             }
   587 void CPcsKeyMap::ContructForItutKeyboardL(TLanguage aLanguage)
   588         else
   588     {
   589             {
   589     // Add the keys for Pool formation
   590             PRINT ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: ##### Failed to create Key List (KeyBindingTable) #####") );
   590     iKeysForPoolFormation.Append(EPtiKey0);
   591             }
   591     iKeysForPoolFormation.Append(EPtiKey1);
   592         }
   592     iKeysForPoolFormation.Append(EPtiKey2);
   593     else
   593     iKeysForPoolFormation.Append(EPtiKey3);
   594         {
   594     iKeysForPoolFormation.Append(EPtiKey4);
   595         PRINT ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: ##### Failed to create Key List (Language) #####") );
   595     iKeysForPoolFormation.Append(EPtiKey5);
   596         }
   596     iKeysForPoolFormation.Append(EPtiKey6);
   597 
   597     iKeysForPoolFormation.Append(EPtiKey7);
       
   598     iKeysForPoolFormation.Append(EPtiKey8);
       
   599     iKeysForPoolFormation.Append(EPtiKey9);
       
   600     // one additional pool for special characters not mapped too any keys. 
   598     // one additional pool for special characters not mapped too any keys. 
   601     // This should always be the last one in the arrary
   599     // This should always be the last one in the arrary
   602     iKeysForPoolFormation.Append(EPtiKeyNone);
   600     aKeyArray.Append(EPtiKeyNone);
   603 
   601 
   604     // Now add the keymap arrays to hold the keymap data
   602     PRINT ( _L("End CPcsKeyMap::CreateKeyListFromKeyBindingTable") );
   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         }
       
   673     }
   603     }
   674 
   604 
   675 // ----------------------------------------------------------------------------
   605 // ----------------------------------------------------------------------------
   676 // CPcsKeyMap::IsLanguageSupportedL
   606 // CPcsKeyMap::IsLanguageSupportedL
   677 // Returns ETrue if this language is supported
   607 // Returns ETrue if this language is supported
   678 // ----------------------------------------------------------------------------
   608 // ----------------------------------------------------------------------------
   679 TBool CPcsKeyMap::IsLanguageSupportedL(TUint32 aLang)
   609 TBool CPcsKeyMap::IsLanguageSupportedL(TUint32 aLang)
   680     {
   610     {
   681 
   611 
   682     TBool flag = ETrue;
   612     TBool flag = ETrue;
   683     for (int i = 0; i < iLanguageNotSupported.Count(); i++)
   613     const TInt languageNotSupportedCount = iLanguageNotSupported.Count();
       
   614     for (TInt i = 0; i < languageNotSupportedCount; i++)
   684         {
   615         {
   685         if (iLanguageNotSupported[i] == aLang)
   616         if (iLanguageNotSupported[i] == aLang)
   686             {
   617             {
   687             flag = EFalse;
   618             flag = EFalse;
   688             }
   619             }
   689         }
   620         }
   690 
   621 
   691     return flag;
   622     return flag;
   692     }
   623     }
       
   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 
   693 // ----------------------------------------------------------------------------
   667 // ----------------------------------------------------------------------------
   694 // CPcsKeyMap::PoolIdForCharacter
   668 // CPcsKeyMap::PoolIdForCharacter
   695 // 
   669 // 
   696 // ----------------------------------------------------------------------------
   670 // ----------------------------------------------------------------------------
   697 TInt CPcsKeyMap::PoolIdForCharacter(TChar aChar)
   671 TInt CPcsKeyMap::PoolIdForCharacter( TChar aChar, TKeyboardModes aKbMode )
   698     {
   672     {
   699     TInt numValue = KErrNotFound;
   673     // Pools are formed according the predictive keyboard mapping(s).
   700     
   674     // When selecting pool for non-predictive mode, we use the pool of the
       
   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 
   701     // If character is a Chinese word character, then we select the
   683     // If character is a Chinese word character, then we select the
   702     // pool ID according the first character of the first spelling of the word.
   684     // pool ID according the first character of the first spelling of the word.
   703     TRAP_IGNORE( aChar = FirstCharFromSpellingL( aChar ) );
   685     TRAP_IGNORE( aChar = FirstCharFromSpellingL( aChar ) );
   704     
   686 
   705     TInt key = KeyForCharacter(aChar);
   687     TPtiKey key = KeyForCharacter( aChar, aKbMode );
   706     if (key != KErrNotFound)
   688     TInt poolId = PoolIdForKey( key, aKbMode );
   707         {
   689 
   708         numValue = iKeysForPoolFormation.Find((TPtiKey) key);
   690     return poolId;
       
   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;
   709         }
   718         }
   710     else
   719     else
   711         {
   720         {
   712         // IF the key is not found, then it should go to the special pool,
   721         return EFalse;
   713         // which is the last pool of iAllKeyMappingsPtrArr
   722         }
   714         numValue = iAllKeyMappingsPtrArr.Count() - 1;
   723     }
   715         }
   724 
   716 
   725 // ----------------------------------------------------------------------------
   717     return numValue;
   726 // CPcsKeyMap::SetSpaceAndZeroOnSameKey
       
   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);
   718     }
   749     }
   719 
   750 
   720 // ----------------------------------------------------------------------------
   751 // ----------------------------------------------------------------------------
   721 // CPcsKeyMap::CPcsKeyMap::FirstCharFromSpellingL
   752 // CPcsKeyMap::CPcsKeyMap::FirstCharFromSpellingL
   722 // 
   753 // 
   724 TChar CPcsKeyMap::FirstCharFromSpellingL( TChar aChar ) const
   755 TChar CPcsKeyMap::FirstCharFromSpellingL( TChar aChar ) const
   725     {
   756     {
   726     TChar translated( aChar );
   757     TChar translated( aChar );
   727     TBuf<1> temp;
   758     TBuf<1> temp;
   728     temp.Append( aChar );
   759     temp.Append( aChar );
   729     if ( iAlgorithm->FindUtilECE()->IsChineseWord( temp ) )
   760     if ( iAlgorithm->FindUtilECE()->IsChineseWordIncluded( temp ) )
   730         {
   761         {
   731         RPointerArray<HBufC> spellList;
   762         RPointerArray<HBufC> spellList;
   732         CleanupResetAndDestroyPushL( spellList );
   763         CleanupResetAndDestroyPushL( spellList );
   733         if (iAlgorithm->FindUtilECE()->DoTranslationL(aChar, spellList))
   764         if (iAlgorithm->FindUtilECE()->DoTranslationL(aChar, spellList))
   734             {
   765             {
   736             }
   767             }
   737         CleanupStack::PopAndDestroy( &spellList ); // ResetAndDestroy
   768         CleanupStack::PopAndDestroy( &spellList ); // ResetAndDestroy
   738         }
   769         }
   739     return translated;
   770     return translated;
   740     }
   771     }
   741 // ----------------------------------------------------------------------------
   772 
   742 // CPcsKeyMap::PoolCount
   773 // ----------------------------------------------------------------------------
   743 // 
   774 // CPcsKeyMap::KeyMappings
   744 // ----------------------------------------------------------------------------
   775 //
   745 TInt CPcsKeyMap::PoolCount()
   776 // ----------------------------------------------------------------------------
   746     {
   777 const RPointerArray<TKeyMappingData>* CPcsKeyMap::KeyMappings( TKeyboardModes aMode ) const
   747     return iAllKeyMappingsPtrArr.Count();
   778     {
       
   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;
   748     }
   858     }
   749 // End of file
   859 // End of file