predictivesearch/PcsAlgorithm/Algorithm1/src/CPcsKeyMap.cpp
branchRCL_3
changeset 6 e8e3147d53eb
parent 0 e686773b3f54
child 7 b3431bff8c19
equal deleted inserted replaced
5:81f8547efd4f 6:e8e3147d53eb
    19 // INCLUDE FILES
    19 // INCLUDE FILES
    20 #include "CPcsDebug.h"
    20 #include "CPcsDebug.h"
    21 #include "CPcsKeyMap.h"
    21 #include "CPcsKeyMap.h"
    22 #include <CPcsDefs.h>
    22 #include <CPcsDefs.h>
    23 #include <bldvariant.hrh>
    23 #include <bldvariant.hrh>
    24 #include <PtiDefs.h>
    24 #include <PtiEngine.h>
    25 #include <PtiKeyMappings.h>
       
    26 #include <PtiKeyMapData.h>
    25 #include <PtiKeyMapData.h>
    27 #include <AknFepInternalCRKeys.h>
    26 #include <AknFepInternalCRKeys.h>
    28 #include <AvkonInternalCRKeys.h>
    27 #include <AvkonInternalCRKeys.h>
    29 #include <centralrepository.h>
    28 #include <centralrepository.h>
    30 #include <CPsQuery.h>
    29 #include <CPsQuery.h>
    38     {
    37     {
    39         EPanicPreCond_MultipleSingleCharMatching = 1,
    38         EPanicPreCond_MultipleSingleCharMatching = 1,
    40         EPanicPreCond_MultipleUIPriorityMatching = 2,
    39         EPanicPreCond_MultipleUIPriorityMatching = 2,
    41         EPanicPreCond_MultipleEnglishPriorityMatching = 3,
    40         EPanicPreCond_MultipleEnglishPriorityMatching = 3,
    42         EPanicPreCond_MultipleOthersPriorityMatching = 4,
    41         EPanicPreCond_MultipleOthersPriorityMatching = 4,
       
    42         EPanic_OverflowInPoolIndex = 5,
       
    43         EPanic_InvalidKeyboardType = 6
    43    };
    44    };
    44 
    45 
    45     void Panic(TInt aReason)
    46     void Panic(TInt aReason)
    46     {
    47     {
    47         _LIT(KPanicText, "CPcsKeyMap");
    48         _LIT(KPanicText, "CPcsKeyMap");
    93     // List of non-supported languages for this Algorithm
    94     // List of non-supported languages for this Algorithm
    94     iLanguageNotSupported.Append(ELangJapanese);
    95     iLanguageNotSupported.Append(ELangJapanese);
    95     iLanguageNotSupported.Append(ELangPrcChinese);
    96     iLanguageNotSupported.Append(ELangPrcChinese);
    96     iLanguageNotSupported.Append(ELangHongKongChinese);
    97     iLanguageNotSupported.Append(ELangHongKongChinese);
    97     iLanguageNotSupported.Append(ELangTaiwanChinese);
    98     iLanguageNotSupported.Append(ELangTaiwanChinese);
    98 
    99     iLanguageNotSupported.Append(ELangKorean);
    99 #ifdef RD_INTELLIGENT_TEXT_INPUT
   100 
   100 
   101     SetupKeyboardTypesL();
   101     TInt physicalKeyboard = 0;
       
   102     CRepository* aknFepRepository = CRepository::NewL( KCRUidAknFep );
       
   103     aknFepRepository->Get( KAknFepPhysicalKeyboards, physicalKeyboard );
       
   104     delete aknFepRepository;
       
   105 
       
   106     PRINT1 ( _L("CPcsKeyMap::ConstructL: Physical keyboard support flag = 0x%02X"), physicalKeyboard );
       
   107 
       
   108     // Constants follow the definition of KAknFepPhysicalKeyboards
       
   109     const TInt ptiKeyboard12Key = 0x01;
       
   110     //const TInt ptiKeyboardQwerty4x12 = 0x02;    // Not used at the moment
       
   111     const TInt ptiKeyboardQwerty4x10 = 0x04;
       
   112     const TInt ptiKeyboardQwerty3x11 = 0x08;
       
   113     const TInt ptiKeyboardHalfQwerty = 0x10;
       
   114     //const TInt ptiKeyboardCustomQwerty = 0x20;  // Not used at the moment
       
   115 
       
   116     // The following if contains the order of precedence given for keyboards
       
   117     // i.e. one phone has both "ITUT 12 Key" and "Qwerty 4x10" physical keyboards
       
   118     if ( physicalKeyboard & ptiKeyboard12Key )
       
   119         {
       
   120         iKeyboardType = EPtiKeyboard12Key;
       
   121         }
       
   122     else if ( physicalKeyboard & ptiKeyboardHalfQwerty )
       
   123         {
       
   124         iKeyboardType = EPtiKeyboardHalfQwerty;
       
   125         }
       
   126     else if ( physicalKeyboard & ptiKeyboardQwerty4x10 )
       
   127         {
       
   128         iKeyboardType = EPtiKeyboardQwerty4x10;
       
   129         }
       
   130     else if ( physicalKeyboard & ptiKeyboardQwerty3x11 )
       
   131         {
       
   132         iKeyboardType = EPtiKeyboardQwerty3x11;
       
   133         }
       
   134     else
       
   135 #endif // RD_INTELLIGENT_TEXT_INPUT
       
   136         {
       
   137         iKeyboardType = EPtiKeyboard12Key; // default
       
   138         }
       
   139 
       
   140     PRINT1 ( _L("CPcsKeyMap::ConstructL: Keyboard chosen for Predictive Search = %d"), iKeyboardType );
       
   141 
   102 
   142     // Create structure for holding characters<-->key mappings
   103     // Create structure for holding characters<-->key mappings
   143     CreateKeyMappingL();
   104     CreateKeyMappingL( EPredictiveItuT );
       
   105     CreateKeyMappingL( EPredictiveQwerty );
   144 
   106 
   145     // Sets attribute for holding info if "0" and " " are on the same key
   107     // Sets attribute for holding info if "0" and " " are on the same key
   146     // Needed for decision if the "0" should be considered as a possible separator
   108     // Needed for decision if the "0" should be considered as a possible separator
   147     SetSpaceAndZeroOnSameKey();
   109     SetSpaceAndZeroOnSameKey();
   148     
   110     
   160     PRINT ( _L("Enter CPcsKeyMap::~CPcsKeyMap") );
   122     PRINT ( _L("Enter CPcsKeyMap::~CPcsKeyMap") );
   161 
   123 
   162     // Cleanup local arrays
   124     // Cleanup local arrays
   163     iLanguageNotSupported.Reset();
   125     iLanguageNotSupported.Reset();
   164 
   126 
   165     for (TInt i = 0; i < PoolCount(); i++)
   127     for (TInt i = 0; i < iItutKeyMaps.Count(); i++)
   166         {
   128         {
   167         for (TInt j = 0; j < TKeyMappingData::EKeyMapNumberArr; j++)
   129         for (TInt j = 0; j < TKeyMappingData::EKeyMapNumberArr; j++)
   168             {
   130             {
   169             iKeyMapPtrArr[i]->iKeyMapCharArr[j].Close();
   131             iItutKeyMaps[i]->iKeyMapCharArr[j].Close();
   170             }
   132             }
   171         }
   133         }
   172     iKeyMapPtrArr.ResetAndDestroy();
   134     iItutKeyMaps.ResetAndDestroy();
   173     iKeysArr.Close();
   135     
       
   136     for (TInt i = 0; i < iQwertyKeyMaps.Count(); i++)
       
   137         {
       
   138         for (TInt j = 0; j < TKeyMappingData::EKeyMapNumberArr; j++)
       
   139             {
       
   140             iQwertyKeyMaps[i]->iKeyMapCharArr[j].Close();
       
   141             }
       
   142         }
       
   143     iQwertyKeyMaps.ResetAndDestroy();
       
   144     
       
   145     iItutKeys.Close();
       
   146     iQwertyKeys.Close();
   174 
   147 
   175     PRINT ( _L("End CPcsKeyMap::~CPcsKeyMap") );
   148     PRINT ( _L("End CPcsKeyMap::~CPcsKeyMap") );
       
   149     }
       
   150 
       
   151 // ----------------------------------------------------------------------------
       
   152 // CPcsKeyMap::IsModePredictive
       
   153 // 
       
   154 // ----------------------------------------------------------------------------
       
   155 TBool CPcsKeyMap::IsModePredictive( TKeyboardModes aKbMode )
       
   156     {
       
   157     return ( (EPredictiveDefaultKeyboard == aKbMode) ||
       
   158              (EPredictiveItuT == aKbMode) ||
       
   159              (EPredictiveQwerty == aKbMode) );
       
   160     }
       
   161 
       
   162 // ----------------------------------------------------------------------------
       
   163 // CPcsKeyMap::ResolveKeyboardMode
       
   164 // Resolve EPredictiveDefaultKeyboard or ENonPredictive mode to EPredictiveItuT
       
   165 // or EPredictiveQwerty mode
       
   166 // ----------------------------------------------------------------------------
       
   167 TKeyboardModes CPcsKeyMap::ResolveKeyboardMode( TKeyboardModes aKbMode,
       
   168                                                 TKeyboardModes aKbModeToResolve ) const
       
   169     {    
       
   170     // Substitute "default predictive" mode with actual mode
       
   171     if ( (aKbMode == aKbModeToResolve) &&
       
   172          ((aKbMode == ENonPredictive) || (aKbMode == EPredictiveDefaultKeyboard)) )
       
   173         {
       
   174         return iPredictiveDefaultKeyboardMode;
       
   175         }
       
   176     else
       
   177         {
       
   178         return aKbMode;
       
   179         }
   176     }
   180     }
   177 
   181 
   178 // ----------------------------------------------------------------------------
   182 // ----------------------------------------------------------------------------
   179 // CPcsKeyMap::GetMixedKeyStringForQueryL
   183 // CPcsKeyMap::GetMixedKeyStringForQueryL
   180 // aDestStr will have the length as the number of items in aSrcQuery.
   184 // aDestStr will have the length as the number of items in aSrcQuery.
   181 // ----------------------------------------------------------------------------
   185 // ----------------------------------------------------------------------------
   182 void CPcsKeyMap::GetMixedKeyStringForQueryL(CPsQuery& aSrcQuery, TDes& aDestStr)
   186 void CPcsKeyMap::GetMixedKeyStringForQueryL(
   183 {
   187         CPsQuery& aSrcQuery, TDes& aDestStr) const
       
   188     {
   184     PRINT ( _L("Enter CPcsKeyMap::GetMixedKeyStringForQueryL") ); 
   189     PRINT ( _L("Enter CPcsKeyMap::GetMixedKeyStringForQueryL") ); 
   185 
   190 
   186     GetMixedKeyStringForDataL( aSrcQuery, aSrcQuery.QueryAsStringLC(), aDestStr );
   191     GetMixedKeyStringForDataL( aSrcQuery, aSrcQuery.QueryAsStringLC(), aDestStr );
   187     CleanupStack::PopAndDestroy(); //result of QueryAsStringLC
   192     CleanupStack::PopAndDestroy(); //result of QueryAsStringLC
   188 
   193 
   189     PRINT ( _L("End CPcsKeyMap::GetMixedKeyStringForQueryL") );
   194     PRINT ( _L("End CPcsKeyMap::GetMixedKeyStringForQueryL") );
   190 }
   195     }
   191 
   196 
   192 // ----------------------------------------------------------------------------
   197 // ----------------------------------------------------------------------------
   193 // CPcsKeyMap::GetMixedKeyStringForDataL
   198 // CPcsKeyMap::GetMixedKeyStringForDataL
   194 // aDestStr will have the same length as aSrcData. aSrcQuery can be shorter.
   199 // aDestStr will have the same length as aSrcData. aSrcQuery can be shorter.
   195 // ----------------------------------------------------------------------------
   200 // ----------------------------------------------------------------------------
   196 void CPcsKeyMap::GetMixedKeyStringForDataL(
   201 void CPcsKeyMap::GetMixedKeyStringForDataL(
   197         CPsQuery& aSrcQuery, const TDesC& aSrcData, TDes& aDestStr)
   202         CPsQuery& aSrcQuery, const TDesC& aSrcData, TDes& aDestStr) const
   198 {
   203     {
   199     PRINT ( _L("Enter CPcsKeyMap::GetMixedKeyStringForDataL") );
   204     PRINT ( _L("Enter CPcsKeyMap::GetMixedKeyStringForDataL") );
   200 
   205 
   201     for ( TInt i = 0; i < aSrcData.Length(); ++i )
   206     for ( TInt i = 0; i < aSrcData.Length(); ++i )
   202         {
   207         {
   203         TChar character( aSrcData[i] );
   208         TChar character( aSrcData[i] );
   204         character.LowerCase();
   209         character.LowerCase();
   205         if ( i < aSrcQuery.Count() )
   210         if ( i < aSrcQuery.Count() )
   206             {
   211             {
   207             CPsQueryItem& currentItem = aSrcQuery.GetItemAtL(i);
   212             CPsQueryItem& currentItem = aSrcQuery.GetItemAtL(i);
   208             switch ( currentItem.Mode() )
   213             TPtiKey key = KeyForCharacterMultiMatch( aSrcData[i], currentItem.Mode() );
   209                 {
   214             // If a character is not mapped to any key or it's entered in non-predictive mode,
   210                 case EItut:
   215             // then append the character.
   211                     {
   216             if ( EPtiKeyNone == key )
   212                     TPtiKey key = KeyForCharacterMultiMatch(aSrcData[i]);
   217                 {
   213                     // If a character is not mapped to numeric key append the character
   218                 PRINT3 ( _L("CPcsKeyMap::GetMixedKeyStringForDataL: Char at index %d not mapped to a key, appending char '%c' (#%d)"),
   214                     if ( EPtiKeyNone == key )
   219                          i, (TUint) character, (TUint) character );
   215                         {
   220 
   216                         PRINT3 ( _L("CPcsKeyMap::GetMixedKeyStringForDataL: Char at index %d not mapped to a key, appending char '%c' (#%d)"),
   221                 aDestStr.Append( character );
   217                                  i, (TUint) character, (TUint) character );
   222                 }
   218 
   223             else 
   219                         aDestStr.Append( character );
   224                 {
   220                         }
   225                 aDestStr.Append( key );
   221                     else 
       
   222                         {
       
   223                         aDestStr.Append( key );
       
   224                         }
       
   225                     }
       
   226                     break;
       
   227                 case EQwerty:
       
   228                     //fall through
       
   229                 default:
       
   230                     PRINT2 ( _L("CPcsKeyMap::GetMixedKeyStringForDataL: Char '%c' (#%d) is taken exact (non predictive in query)"),
       
   231                             (TUint) character, (TUint) character );
       
   232                     aDestStr.Append( character );
       
   233                     break;
       
   234                 }
   226                 }
   235             }
   227             }
   236         else
   228         else
   237             {            
   229             {            
   238             PRINT2 ( _L("CPcsKeyMap::GetMixedKeyStringForDataL: Char '%c' (#%d) is taken exact (over query length)"),
   230             PRINT2 ( _L("CPcsKeyMap::GetMixedKeyStringForDataL: Char '%c' (#%d) is taken exact (over query length)"),
   244 
   236 
   245     PRINT1 ( _L("CPcsKeyMap::GetMixedKeyStringForDataL: Return string: \"%S\""),
   237     PRINT1 ( _L("CPcsKeyMap::GetMixedKeyStringForDataL: Return string: \"%S\""),
   246              &aDestStr );
   238              &aDestStr );
   247 
   239 
   248     PRINT ( _L("End CPcsKeyMap::GetMixedKeyStringForDataL") );
   240     PRINT ( _L("End CPcsKeyMap::GetMixedKeyStringForDataL") );
   249 }
   241     }
   250 
   242 
   251 // ----------------------------------------------------------------------------
   243 // ----------------------------------------------------------------------------
   252 // CPcsKeyMap::CharacterForKeyMappingExists
   244 // CPcsKeyMap::CharacterForKeyMappingExists
   253 // Returns true if the character is mapped to the key
   245 // Returns true if the character is mapped to the key
   254 // ----------------------------------------------------------------------------
   246 // ----------------------------------------------------------------------------
   255 TBool CPcsKeyMap::CharacterForKeyMappingExists(TKeyMappingData& aKeyMap, const TUint aIntChar)
   247 TBool CPcsKeyMap::CharacterForKeyMappingExists(
       
   248         TKeyMappingData& aKeyMap, TUint aIntChar) const
   256     {
   249     {
   257     TBool found = EFalse;
   250     TBool found = EFalse;
   258     
   251     
   259     for (TInt j = TKeyMappingData::EKeyMapUILangArr; j <= TKeyMappingData::EKeyMapOthersLangArr; j++)
   252     for (TInt j = TKeyMappingData::EKeyMapUILangArr; j <= TKeyMappingData::EKeyMapOthersLangArr; j++)
   260         {
   253         {
   272 #ifdef _DEBUG
   265 #ifdef _DEBUG
   273 // ----------------------------------------------------------------------------
   266 // ----------------------------------------------------------------------------
   274 // CPcsKeyMap::CheckPotentialErrorConditions
   267 // CPcsKeyMap::CheckPotentialErrorConditions
   275 //
   268 //
   276 // ----------------------------------------------------------------------------
   269 // ----------------------------------------------------------------------------
   277 void CPcsKeyMap::CheckPotentialErrorConditions(RArray<TInt>& aPoolIndexArr, const TChar& aChar)
   270 void CPcsKeyMap::CheckPotentialErrorConditions(const RArray<TInt>& aPoolIndexArr, 
       
   271                                                const TChar& aChar,
       
   272                                                const RArray<TPtiKey>& aPtiKeys,
       
   273                                                const RPointerArray<TKeyMappingData>& aKeyMappings) const
   278     {
   274     {
   279     PRINT ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: ===================================================") );
   275     PRINT ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: ===================================================") );
   280     PRINT ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Checking potential error conditions") );
   276     PRINT ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Checking potential error conditions") );
   281     PRINT ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: ---------------------------------------------------") );
   277     PRINT ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: ---------------------------------------------------") );
   282 
   278 
   292     for ( TInt j = TKeyMappingData::EKeyMapSingleCharArr; j <= TKeyMappingData::EKeyMapOthersLangArr; j++ )
   288     for ( TInt j = TKeyMappingData::EKeyMapSingleCharArr; j <= TKeyMappingData::EKeyMapOthersLangArr; j++ )
   293         {
   289         {
   294         countArr[j] = 0;
   290         countArr[j] = 0;
   295         for ( TInt i = 0; i < aPoolIndexArr.Count(); i++ )
   291         for ( TInt i = 0; i < aPoolIndexArr.Count(); i++ )
   296             {
   292             {
   297             if ( KErrNotFound != iKeyMapPtrArr[aPoolIndexArr[i]]->iKeyMapCharArr[j].Find((TUint) aChar) )
   293             if ( KErrNotFound != aKeyMappings[aPoolIndexArr[i]]->iKeyMapCharArr[j].Find((TUint) aChar) )
   298                 {
   294                 {
   299                 PRINT5 ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Char '%c' (#%d) %S for pool %d with key '%c'"),
   295                 PRINT5 ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Char '%c' (0x%04X) %S for pool %d with key '%c'"),
   300                         (TUint) aChar, (TUint) aChar, &charArrStr[j], aPoolIndexArr[i], iKeysArr[aPoolIndexArr[i]] );
   296                         (TUint) aChar, (TUint) aChar, &charArrStr[j], aPoolIndexArr[i], aPtiKeys[aPoolIndexArr[i]] );
   301                 countArr[j]++;
   297                 countArr[j]++;
   302                 }
   298                 }
   303             }
   299             }
   304         }
   300         }
   305 
   301 
   306     PRINT ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: ===================================================") );
   302     PRINT ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: ===================================================") );
   307     
   303     
   308 #ifdef __WINS__
   304 #ifdef __WINS__
       
   305     /*
       
   306     The reference 4x10 QWERTY mappings of 9.2 emulator have each number mapped to two keys.
       
   307     That kind of mappings can't be handled correctly, so panic in debug would basically be correct.
       
   308     However, assertions are commented out for now to be able to do some testing.
       
   309     
   309     // Check in debug mode if we have wrong situations
   310     // Check in debug mode if we have wrong situations
   310     __ASSERT_DEBUG( (countArr[TKeyMappingData::EKeyMapSingleCharArr]  > 1), Panic(EPanicPreCond_MultipleSingleCharMatching) );
   311     __ASSERT_DEBUG( (countArr[TKeyMappingData::EKeyMapSingleCharArr]  <= 1), Panic(EPanicPreCond_MultipleSingleCharMatching) );
   311     __ASSERT_DEBUG( (countArr[TKeyMappingData::EKeyMapUILangArr]      > 1), Panic(EPanicPreCond_MultipleUIPriorityMatching) );
   312     __ASSERT_DEBUG( (countArr[TKeyMappingData::EKeyMapUILangArr]      <= 1), Panic(EPanicPreCond_MultipleUIPriorityMatching) );
   312     __ASSERT_DEBUG( (countArr[TKeyMappingData::EKeyMapEnglishLangArr] > 1), Panic(EPanicPreCond_MultipleEnglishPriorityMatching) );
   313     __ASSERT_DEBUG( (countArr[TKeyMappingData::EKeyMapEnglishLangArr] <= 1), Panic(EPanicPreCond_MultipleEnglishPriorityMatching) );
   313     __ASSERT_DEBUG( (countArr[TKeyMappingData::EKeyMapOthersLangArr]  > 1), Panic(EPanicPreCond_MultipleOthersPriorityMatching) );
   314     __ASSERT_DEBUG( (countArr[TKeyMappingData::EKeyMapOthersLangArr]  <= 1), Panic(EPanicPreCond_MultipleOthersPriorityMatching) );
       
   315     */
   314 #endif // __WINS__
   316 #endif // __WINS__
   315     }
   317     }
   316 #endif // _DEBUG        
   318 #endif // _DEBUG        
   317 
   319 
   318 // ----------------------------------------------------------------------------
   320 // ----------------------------------------------------------------------------
   327 //   - 2nd choice: choose the 1st pool that has for a language the char as single char.
   329 //   - 2nd choice: choose the 1st pool that has for a language the char as single char.
   328 //   - 3rd choice: choose the 1st pool that has the char mapped for the UI language.
   330 //   - 3rd choice: choose the 1st pool that has the char mapped for the UI language.
   329 //   - 4th choice: choose the 1st pool that has the char mapped for the English language.
   331 //   - 4th choice: choose the 1st pool that has the char mapped for the English language.
   330 //   - 5th choice: choose the 1st pool that has the char mapped for the Other languages.
   332 //   - 5th choice: choose the 1st pool that has the char mapped for the Other languages.
   331 // ----------------------------------------------------------------------------
   333 // ----------------------------------------------------------------------------
   332 TPtiKey CPcsKeyMap::KeyForCharacterMultiMatch(const TChar& aChar)
   334 TPtiKey CPcsKeyMap::KeyForCharacterMultiMatch( const TChar& aChar, TKeyboardModes aKbMode ) const
   333     {
   335     {    
       
   336     aKbMode = ResolveKeyboardMode( aKbMode, EPredictiveDefaultKeyboard ); 
       
   337 
       
   338     // Select key arrays to use according to keyboard mode
       
   339     const RArray<TPtiKey>* ptiKeyArray;
       
   340     const RPointerArray<TKeyMappingData>* keyMappingArray;
       
   341     TPtiKeyboardType kbType;
       
   342     GetPredictiveKeyboardData( aKbMode, ptiKeyArray, keyMappingArray, kbType );
       
   343     if ( !ptiKeyArray || !keyMappingArray || ptiKeyArray->Count() == 0 )
       
   344         {
       
   345         // No mappings available. This may be, for example, because aKbMode is non-predictive.
       
   346         // Return no mapping in that case to indicate that character should be treated in
       
   347         // non-predictive way.
       
   348         return EPtiKeyNone;
       
   349         }
       
   350     
   334     // Set an array of pool index matches (more matches are possible)
   351     // Set an array of pool index matches (more matches are possible)
   335     RArray<TInt> poolIndexArr;
   352     RArray<TInt> poolIndexArr;
   336     for ( TInt i = 0; i < PoolCount(); i++ )
   353     for ( TInt i = 0; i < keyMappingArray->Count(); i++ )
   337         {
   354         {
   338         if ( CharacterForKeyMappingExists(*iKeyMapPtrArr[i], (TUint) aChar) )
   355         if ( CharacterForKeyMappingExists(*(*keyMappingArray)[i], (TUint) aChar) )
   339             {
   356             {
   340             poolIndexArr.Append(i);
   357             poolIndexArr.Append(i);
   341 
   358 
   342             PRINT4 ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Char '%c' (#%d) found in pool %d with key '%c'"),
   359             PRINT4 ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Char '%c' (0x%04X) found in pool %d with key '%c'"),
   343                     (TUint) aChar, (TUint) aChar, i, iKeysArr[i] );
   360                     (TUint) aChar, (TUint) aChar, i, (*ptiKeyArray)[i] );
   344             }
   361             }
   345         }
   362         }
   346 
   363 
   347     /* Choose the pool index depending on the number of matches.
   364     /* Choose the pool index depending on the number of matches.
   348      * If there are 2 or more matches, then the choice of the pool index depends on
   365      * If there are 2 or more matches, then the choice of the pool index depends on
   351     TInt poolIndex = KErrNotFound;
   368     TInt poolIndex = KErrNotFound;
   352 
   369 
   353     // Character not found in any pool
   370     // Character not found in any pool
   354     if ( poolIndexArr.Count() == 0 )
   371     if ( poolIndexArr.Count() == 0 )
   355         {
   372         {
   356         PRINT2 ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Char '%c' (#%d) NOT found in all pools"),
   373         PRINT2 ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Char '%c' (0x%04X) NOT found from any pool"),
   357                  (TUint) aChar, (TUint) aChar );
   374                  (TUint) aChar, (TUint) aChar );
   358         }
   375         }
   359 
   376 
   360     // Character found in one pool (normal case)
   377     // Character found in one pool (normal case)
   361     else if ( poolIndexArr.Count() == 1 )
   378     else if ( poolIndexArr.Count() == 1 )
   362         {
   379         {
   363         poolIndex = poolIndexArr[0];
   380         poolIndex = poolIndexArr[0];
   364 
   381 
   365         PRINT2 ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Chosen (for unique match) pool %d with key '%c'"),
   382         PRINT2 ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Chosen (for unique match) pool %d with key '%c'"),
   366                 poolIndex, iKeysArr[poolIndex] );
   383                 poolIndex, (*ptiKeyArray)[poolIndex] );
   367         }
   384         }
   368 
   385 
   369     /* Character found in more pools, this can happen in some known conditions:
   386     /* Character found in more pools, this can happen in some known conditions:
   370      * - In some variants 'Ä' is in key 'A' and in key 'Ä'
   387      * - In some variants 'Ä' is in key 'A' and in key 'Ä'
   371      * - In ITUT keyboard '$' is in keys '1' and '7'. This happens for more chars.
   388      * - In ITUT keyboard '$' is in keys '1' and '7'. This happens for more chars.
   387          *       This is wrong, as "!Mat" should not be matched.
   404          *       This is wrong, as "!Mat" should not be matched.
   388          * When the client will not pass updated chars to the engine, but the original (i.e.: "72" or "pa"),
   405          * When the client will not pass updated chars to the engine, but the original (i.e.: "72" or "pa"),
   389          * this piece of code shall be removed.
   406          * this piece of code shall be removed.
   390          * With "client" it is referred to MCL contacts client.
   407          * With "client" it is referred to MCL contacts client.
   391          */
   408          */
   392         if (EPtiKeyboard12Key == iKeyboardType)
   409         if (EPtiKeyboard12Key == kbType)
   393             {
   410             {
   394             for ( TInt i = 0; i < poolIndexArr.Count() ; i++ )
   411             for ( TInt i = 0; i < poolIndexArr.Count() ; i++ )
   395                 {
   412                 {
   396                 if ( EPtiKey1 == iKeysArr[poolIndexArr[i]] )
   413                 if ( EPtiKey1 == (*ptiKeyArray)[poolIndexArr[i]] )
   397                     {
   414                     {
   398                     poolIndexArr.Remove(i);
   415                     poolIndexArr.Remove(i);
   399     
   416     
   400                     PRINT ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Key '1' excluded (for multi match - EPtiKeyboard12Key)") );
   417                     PRINT ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Key '1' excluded (for multi match - EPtiKeyboard12Key)") );
   401                     break;
   418                     break;
   404             if ( poolIndexArr.Count() == 1 )
   421             if ( poolIndexArr.Count() == 1 )
   405                 {
   422                 {
   406                 poolIndex = poolIndexArr[0];
   423                 poolIndex = poolIndexArr[0];
   407 
   424 
   408                 PRINT2 ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Chosen (for unique match after removing key '1') pool %d with key '%c'"),
   425                 PRINT2 ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Chosen (for unique match after removing key '1') pool %d with key '%c'"),
   409                         poolIndex, iKeysArr[poolIndex] );
   426                         poolIndex, (*ptiKeyArray)[poolIndex] );
   410                 }
   427                 }
   411             }
   428             }
   412 
   429 
   413 #ifdef _DEBUG
   430 #ifdef _DEBUG
   414         CheckPotentialErrorConditions(poolIndexArr, aChar);
   431         CheckPotentialErrorConditions(poolIndexArr, aChar, *ptiKeyArray, *keyMappingArray);
   415 #endif // _DEBUG        
   432 #endif // _DEBUG        
   416 
   433 
   417         // Search the char in the char arrays in priority order, the 1st match is taken
   434         // Search the char in the char arrays in priority order, the 1st match is taken
   418         for ( TInt j = TKeyMappingData::EKeyMapSingleCharArr; j <= TKeyMappingData::EKeyMapOthersLangArr; j++ )
   435         for ( TInt j = TKeyMappingData::EKeyMapSingleCharArr; j <= TKeyMappingData::EKeyMapOthersLangArr; j++ )
   419             {
   436             {
   421                 {
   438                 {
   422                 TInt positionLeftMostOnKeys = KErrNotFound; 
   439                 TInt positionLeftMostOnKeys = KErrNotFound; 
   423 
   440 
   424                 for ( TInt i = 0; i < poolIndexArr.Count(); i++ )
   441                 for ( TInt i = 0; i < poolIndexArr.Count(); i++ )
   425                     {
   442                     {
   426                     TInt position = iKeyMapPtrArr[poolIndexArr[i]]->iKeyMapCharArr[j].Find((TUint) aChar);
   443                     TInt position = (*keyMappingArray)[poolIndexArr[i]]->iKeyMapCharArr[j].Find((TUint) aChar);
   427                     if ( KErrNotFound != position )
   444                     if ( KErrNotFound != position )
   428                         {
   445                         {
   429                         // Get the key that has the char in the leftmost index.
   446                         // Get the key that has the char in the leftmost index.
   430                         // We consider that the char can be mapped in more than one key (this is really
   447                         // We consider that the char can be mapped in more than one key (this is really
   431                         // the case for instance in some Scandinavian variants).
   448                         // the case for instance in some Scandinavian variants).
   438                             if ( ( KErrNotFound == positionLeftMostOnKeys ) || ( position < positionLeftMostOnKeys ) )
   455                             if ( ( KErrNotFound == positionLeftMostOnKeys ) || ( position < positionLeftMostOnKeys ) )
   439                                 {
   456                                 {
   440                                 poolIndex = poolIndexArr[i];
   457                                 poolIndex = poolIndexArr[i];
   441                                 positionLeftMostOnKeys = position;
   458                                 positionLeftMostOnKeys = position;
   442                                 }
   459                                 }
   443 
       
   444                             }
   460                             }
   445                         // Get the 1st key that has the char mapped to it
   461                         // Get the 1st key that has the char mapped to it
   446                         else
   462                         else
   447                             {
   463                             {
   448                             poolIndex = poolIndexArr[i];
   464                             poolIndex = poolIndexArr[i];
   449                     
   465                     
   450                             PRINT3 ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Chosen (for multi match - char arr: %d) pool %d with key '%c'"),
   466                             PRINT3 ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Chosen (for multi match - char arr: %d) pool %d with key '%c'"),
   451                                      j, poolIndex, iKeysArr[poolIndex] );
   467                                      j, poolIndex, (*ptiKeyArray)[poolIndex] );
   452                         
   468                         
   453                             break;
   469                             break;
   454                             }
   470                             }
   455                         }
   471                         }
   456                     }
   472                     }
   461 
   477 
   462     // Set the key value from the pool index
   478     // Set the key value from the pool index
   463     TPtiKey key = EPtiKeyNone;
   479     TPtiKey key = EPtiKeyNone;
   464     if ( KErrNotFound != poolIndex )
   480     if ( KErrNotFound != poolIndex )
   465         {
   481         {
   466         key = iKeysArr[poolIndex];
   482         key = (*ptiKeyArray)[poolIndex];
   467         }
   483         }
   468     
   484     
   469     poolIndexArr.Close();
   485     poolIndexArr.Close();
   470     return key;
   486     return key;
   471     }
   487     }
   472 
   488 
   473 // ----------------------------------------------------------------------------
   489 // ----------------------------------------------------------------------------
   474 // CPcsKeyMap::PoolIdForKey
   490 // CPcsKeyMap::PoolIdForKey
   475 //
   491 //
   476 // ----------------------------------------------------------------------------
   492 // ----------------------------------------------------------------------------
   477 TInt CPcsKeyMap::PoolIdForKey(const TPtiKey aKey)
   493 TInt CPcsKeyMap::PoolIdForKey(const TPtiKey aKey, TKeyboardModes aKbMode)
   478     {
   494     {
   479     TInt poolId = iKeysArr.Find(aKey);
   495     aKbMode = ResolveKeyboardMode( aKbMode, EPredictiveDefaultKeyboard ); 
   480 
   496 
   481     // IF the key is not found, then it should go to the special pool,
   497     // From logical point of view, the Pool ID is an index of the key in
   482     // which is the last pool of iKeyMapPtrArr
   498     // an array which is formed by concatenating QWERTY keys array in the end
   483     if (KErrNotFound == poolId)
   499     // of the ITU-T keys array.
   484         {
   500     TInt poolId = KErrNotFound;
   485         poolId = PoolCount() - 1;
   501     if ( aKbMode == EPredictiveItuT && iItutKeys.Count() )
   486         }
   502         {
       
   503         poolId = iItutKeys.Find(aKey);
       
   504         // IF the key is not found, then it should go to the special pool,
       
   505         // which is the pool of the dummy key in the ITU-T keys array
       
   506         if (KErrNotFound == poolId)
       
   507             {
       
   508             poolId = iItutKeys.Count() - 1;
       
   509             }
       
   510         }
       
   511     else if ( aKbMode == EPredictiveQwerty && iQwertyKeys.Count() )
       
   512         {
       
   513         poolId = iQwertyKeys.Find(aKey);
       
   514         // IF the key is not found, then it should go to the special pool,
       
   515         // which is the pool of the dummy key in the QWERTY keys array
       
   516         if (KErrNotFound == poolId)
       
   517             {
       
   518             poolId = iQwertyKeys.Count() - 1;
       
   519             }
       
   520         // Pools of QWERTY keys come after pools of ITU-T keys
       
   521         poolId += iItutKeys.Count();
       
   522         }
       
   523 
       
   524     // Pool ID must never exceed value 63, because CPcsCache class
       
   525     // stores these values as bitmask into 64 bit variable.
       
   526     __ASSERT_DEBUG( poolId < 64, Panic(EPanic_OverflowInPoolIndex) );
   487 
   527 
   488     return poolId;
   528     return poolId;
   489     }
   529     }
   490 
   530 
   491 // ----------------------------------------------------------------------------
   531 // ----------------------------------------------------------------------------
   492 // CPcsKeyMap::PoolIdForCharacter
   532 // CPcsKeyMap::PoolIdForCharacter
   493 //
   533 //
   494 // ----------------------------------------------------------------------------
   534 // ----------------------------------------------------------------------------
   495 TInt CPcsKeyMap::PoolIdForCharacter(const TChar& aChar)
   535 TInt CPcsKeyMap::PoolIdForCharacter(const TChar& aChar, TKeyboardModes aKbMode)
   496     {
   536     {
   497     TPtiKey key = KeyForCharacterMultiMatch(aChar);
   537     // Pools are formed according the predictive keyboard mapping(s).
   498 
   538     // When selecting pool for non-predictive mode, we use the pool of the
   499     TInt poolId = PoolIdForKey(key);
   539     // default keyboard. The non-predictive matches should be a sub set of the
       
   540     // predictive matches of the default keyboard, although strictly speaking,
       
   541     // there' no guarantee for this.
       
   542     aKbMode = ResolveKeyboardMode( aKbMode, ENonPredictive ); 
       
   543 
       
   544     TPtiKey key = KeyForCharacterMultiMatch( aChar, aKbMode );
       
   545 
       
   546     TInt poolId = (key == EPtiKeyNone) ? KErrNotFound : PoolIdForKey(key, aKbMode);
   500 
   547 
   501     return poolId;
   548     return poolId;
   502     }
   549     }
   503 
   550 
   504 // ----------------------------------------------------------------------------
   551 // ----------------------------------------------------------------------------
   505 // CPcsKeyMap::PoolCount
   552 // CPcsKeyMap::PoolCount
   506 //
   553 //
   507 // ----------------------------------------------------------------------------
   554 // ----------------------------------------------------------------------------
   508 TInt CPcsKeyMap::PoolCount()
   555 TInt CPcsKeyMap::PoolCount()
   509     {
   556     {
   510     return iKeyMapPtrArr.Count();
   557     return iItutKeyMaps.Count() + iQwertyKeyMaps.Count();
   511     }
   558     }
   512 
   559 
   513 // ----------------------------------------------------------------------------
   560 // ----------------------------------------------------------------------------
   514 // CPcsKeyMap::SetSpaceAndZeroOnSameKey
   561 // CPcsKeyMap::SetSpaceAndZeroOnSameKey
   515 // 
   562 // 
   516 // ----------------------------------------------------------------------------
   563 // ----------------------------------------------------------------------------
   517 void CPcsKeyMap::SetSpaceAndZeroOnSameKey()
   564 void CPcsKeyMap::SetSpaceAndZeroOnSameKey()
   518     {
   565     {
   519     const TInt KSpace = 32; // ASCII for " "
   566     PRINT ( _L("Enter CPcsKeyMap::SetSpaceAndZeroOnSameKey") );
   520     const TInt KZero  = 48; // ASCII for "0"
   567 
       
   568     static const TInt KSpace = 0x20; // ASCII for " "
       
   569     static const TInt KZero  = 0x30; // ASCII for "0"
   521 
   570 
   522     TChar charSpace(KSpace);
   571     TChar charSpace(KSpace);
   523     TChar charZero(KZero);
   572     TChar charZero(KZero);
   524 
   573 
   525     TPtiKey keySpace = KeyForCharacterMultiMatch(charSpace);
   574     TPtiKey keySpace;
   526     TPtiKey keyZero = KeyForCharacterMultiMatch(charZero);
   575     TPtiKey keyZero;
   527 
   576 	
   528     iSpaceAndZeroOnSameKey = (keySpace == keyZero);
   577     // ITU-T mode
       
   578     keySpace = KeyForCharacterMultiMatch(charSpace, EPredictiveItuT);
       
   579     keyZero = KeyForCharacterMultiMatch(charZero, EPredictiveItuT);
       
   580     iSpaceAndZeroOnSameKeyOnItut = (keySpace == keyZero && keyZero != EPtiKeyNone);
       
   581     PRINT1 ( _L("CPcsKeyMap::iSpaceAndZeroOnSameKeyOnItut = %d"), iSpaceAndZeroOnSameKeyOnItut );
       
   582     
       
   583     // QWERTY mode
       
   584     keySpace = KeyForCharacterMultiMatch(charSpace, EPredictiveQwerty);
       
   585     keyZero = KeyForCharacterMultiMatch(charZero, EPredictiveQwerty);
       
   586     iSpaceAndZeroOnSameKeyOnQwerty = (keySpace == keyZero && keyZero != EPtiKeyNone);
       
   587     PRINT1 ( _L("CPcsKeyMap::iSpaceAndZeroOnSameKeyOnQwerty = %d"), iSpaceAndZeroOnSameKeyOnQwerty );
       
   588 
       
   589     PRINT ( _L("CPcsKeyMap::SetSpaceAndZeroOnSameKey") );
   529     }
   590     }
   530 
   591 
   531 // ----------------------------------------------------------------------------
   592 // ----------------------------------------------------------------------------
   532 // CPcsKeyMap::GetSpaceAndZeroOnSameKey
   593 // CPcsKeyMap::GetSpaceAndZeroOnSameKey
   533 // 
   594 // 
   534 // ----------------------------------------------------------------------------
   595 // ----------------------------------------------------------------------------
   535 TBool CPcsKeyMap::GetSpaceAndZeroOnSameKey()
   596 TBool CPcsKeyMap::GetSpaceAndZeroOnSameKey( TKeyboardModes aKbMode )
   536     {
   597     {
   537     return iSpaceAndZeroOnSameKey;
   598     TBool result = EFalse;
   538     }
   599 
   539 
   600     aKbMode = ResolveKeyboardMode( aKbMode, EPredictiveDefaultKeyboard );
   540 // ----------------------------------------------------------------------------
   601 
   541 // CPcsKeyMap::GetKeyboardKeyMapping
   602     if ( aKbMode == EPredictiveItuT )
   542 // Helper function to get Key Mappings depending on keyboard type
   603         {
   543 // ----------------------------------------------------------------------------
   604         result = iSpaceAndZeroOnSameKeyOnItut;
   544 MPtiKeyMappings* CPcsKeyMap::GetKeyboardKeyMapping(CPtiCoreLanguage& aCurrLanguage)
   605         }
   545     {
   606     else if ( aKbMode == EPredictiveQwerty )
   546     MPtiKeyMappings* ptiKeyMappings;
   607         {
   547 
   608         result = iSpaceAndZeroOnSameKeyOnQwerty;
   548     switch ( iKeyboardType )
   609         }
   549         {
   610 
   550         case EPtiKeyboardQwerty4x12:
   611     return result;
   551         case EPtiKeyboardQwerty4x10:
   612     }
   552         case EPtiKeyboardQwerty3x11:
   613 
   553         case EPtiKeyboardCustomQwerty:
   614 // ----------------------------------------------------------------------------
   554             ptiKeyMappings = aCurrLanguage.GetQwertyKeymappings();
   615 // CPcsKeyMap::SetupKeyboardTypesL
   555             break;
   616 // Initialise the keyboard type variables
   556 
   617 // ----------------------------------------------------------------------------
   557         case EPtiKeyboard12Key:
   618 void CPcsKeyMap::SetupKeyboardTypesL()
   558             ptiKeyMappings = aCurrLanguage.GetKeymappings();
   619     {
   559             break;
   620     TInt physicalKeyboard = 0;
   560 
   621     CRepository* aknFepRepository = CRepository::NewL( KCRUidAknFep );
   561         case EPtiKeyboardHalfQwerty:
   622     aknFepRepository->Get( KAknFepPhysicalKeyboards, physicalKeyboard );
   562             ptiKeyMappings = aCurrLanguage.GetHalfQwertyKeymappings();
   623     delete aknFepRepository;
   563             break;
   624 
   564 
   625     PRINT1 ( _L("CPcsKeyMap::SetupKeyboardTypesL: Physical keyboard support flag = 0x%02X"), physicalKeyboard );
   565         default:
   626 
   566             ptiKeyMappings = aCurrLanguage.GetKeymappings();
   627     // Constants follow the definition of KAknFepPhysicalKeyboards
   567             break;
   628     const TInt KPtiKeyboard12Key = 0x01;
   568         }
   629     const TInt KPtiKeyboardQwerty4x12 = 0x02;
   569 
   630     const TInt KPtiKeyboardQwerty4x10 = 0x04;
   570     return ptiKeyMappings;
   631     const TInt KPtiKeyboardQwerty3x11 = 0x08;
   571     }
   632     const TInt KPtiKeyboardHalfQwerty = 0x10;
   572 
   633     const TInt KPtiKeyboardCustomQwerty = 0x20; 
   573 // ----------------------------------------------------------------------------
   634 
   574 // CPcsKeyMap::GetKeyMapData
   635     // Setup ITU-T mode first.
   575 //
   636     // Use always 12-key mode since all the supported devices should have at least
   576 // ----------------------------------------------------------------------------
   637     // virtual ITU-T available.
   577 CPtiKeyMapData* CPcsKeyMap::GetKeyMapData(CPtiCoreLanguage& aCurrLanguage)
   638     iItutKeyboardType = EPtiKeyboard12Key;
   578     {
   639     // TODO: ITU-T type could be set to "none" if device does not have either
   579     MPtiKeyMappings* ptiKeyMappings = GetKeyboardKeyMapping( aCurrLanguage );
   640     // virtual keypad or hardware ITU-T available. This could be decided according
   580 
   641     // some cenrep value, feature flag, device model, or platform version.
   581     CPtiKeyMapData* keyMapData;
   642     
   582 
   643     // Then setup QWERTY mode. On real-life devices there should never
   583     switch ( iKeyboardType )
   644     // be more than one QWERTY keyboard available but on emulator there can be several.
   584         {
   645     // Use the first one found in the following precedence
   585         case EPtiKeyboardQwerty4x12:
   646     if ( physicalKeyboard & KPtiKeyboardQwerty3x11 )
   586         case EPtiKeyboardQwerty4x10:
   647         {
   587         case EPtiKeyboardQwerty3x11:
   648         iQwertyKeyboardType = EPtiKeyboardQwerty3x11;
   588         case EPtiKeyboardCustomQwerty:
   649         }
   589             keyMapData = static_cast<CPtiQwertyKeyMappings*>(ptiKeyMappings)->KeyMapData();
   650     else if ( physicalKeyboard & KPtiKeyboardQwerty4x10 )
   590             break;
   651         {
   591 
   652         iQwertyKeyboardType = EPtiKeyboardQwerty4x10;
   592         case EPtiKeyboard12Key:
   653         }
   593             keyMapData = static_cast<CPtiKeyMappings*>(ptiKeyMappings)->KeyMapData();
   654     else if ( physicalKeyboard & KPtiKeyboardQwerty4x12 )
   594             break;
   655         {
   595 
   656         iQwertyKeyboardType = EPtiKeyboardQwerty4x12;
   596         case EPtiKeyboardHalfQwerty:
   657         }
   597             keyMapData = static_cast<CPtiHalfQwertyKeyMappings*>(ptiKeyMappings)->KeyMapData();
   658     else if ( physicalKeyboard & KPtiKeyboardCustomQwerty )
   598             break;
   659         {
   599 
   660         iQwertyKeyboardType = EPtiKeyboardCustomQwerty;
   600         default:
   661         }
   601             keyMapData = static_cast<CPtiKeyMappings*>(ptiKeyMappings)->KeyMapData();
   662     else if ( physicalKeyboard & KPtiKeyboardHalfQwerty )
   602             break;
   663         {
   603         }
   664         iQwertyKeyboardType = EPtiKeyboardHalfQwerty;
   604 
   665         }
   605     return keyMapData;
   666     else
       
   667         {
       
   668         iQwertyKeyboardType = EPtiKeyboardNone;
       
   669         }
       
   670     
       
   671     // Set the Default Predictive keyboard mode
       
   672     iPredictiveDefaultKeyboardMode = ( 
       
   673             (physicalKeyboard & KPtiKeyboard12Key) || (iQwertyKeyboardType == EPtiKeyboardNone) ?
       
   674                 EPredictiveItuT : EPredictiveQwerty );
       
   675     
       
   676     PRINT1 ( _L("CPcsKeyMap::SetupKeyboardTypesL: ITU-T Keyboard chosen for Predictive Search = %d"), iItutKeyboardType );
       
   677     PRINT1 ( _L("CPcsKeyMap::SetupKeyboardTypesL: QWERTY Keyboard chosen for Predictive Search = %d"), iQwertyKeyboardType );
   606     }
   678     }
   607 
   679 
   608 // ----------------------------------------------------------------------------
   680 // ----------------------------------------------------------------------------
   609 // CPcsKeyMap::AppendEntryWithFakeKeyToKeyList
   681 // CPcsKeyMap::AppendEntryWithFakeKeyToKeyList
   610 // Add pool with unused id for for key
   682 // Add pool with unused id for for key
   611 // ----------------------------------------------------------------------------
   683 // ----------------------------------------------------------------------------
   612 void CPcsKeyMap::AppendEntryWithFakeKeyToKeyList()
   684 void CPcsKeyMap::AppendEntryWithFakeKeyToKeyList( RArray<TPtiKey>& aKeyArray )
   613     {
   685     {
   614     TUint keyUInt = (TUint) EPtiKeyNone + 1;
   686     TUint keyUInt = (TUint) EPtiKeyNone + 1;
   615 
   687 
   616     while ( KErrNotFound != iKeysArr.Find( (TPtiKey) keyUInt) )
   688     while ( KErrNotFound != aKeyArray.Find( (TPtiKey) keyUInt) )
   617         {
   689         {
   618         keyUInt++;
   690         keyUInt++;
   619         }
   691         }
   620 
   692 
   621     TPtiKey key = (TPtiKey) keyUInt;
   693     TPtiKey key = (TPtiKey) keyUInt;
   622     iKeysArr.Append( key );
   694     aKeyArray.Append( key );
   623 
   695 
   624     // This should always be the last one in the array
   696     // This should always be the last one in the array
   625     PRINT2 ( _L("CPcsKeyMap::AppendEntryWithFakeKeyToKeyList: Added additional last pool %d with key id #%d"),
   697     PRINT2 ( _L("CPcsKeyMap::AppendEntryWithFakeKeyToKeyList: Added additional last pool %d with key id #%d"),
   626              iKeysArr.Count()-1, key );
   698             aKeyArray.Count()-1, key );
   627     }
       
   628 
       
   629 // ----------------------------------------------------------------------------
       
   630 // CPcsKeyMap::CreateKeyMapFromITUTHardcodedKeys
       
   631 //
       
   632 // ----------------------------------------------------------------------------
       
   633 void CPcsKeyMap::CreateKeyListFromITUTHardcodedKeys()
       
   634     {
       
   635     PRINT ( _L("Enter CPcsKeyMap::CreateKeyListFromITUTHardcodedKeys") );
       
   636 
       
   637     iKeysArr.Append( EPtiKey0 );
       
   638     iKeysArr.Append( EPtiKey1 );
       
   639     iKeysArr.Append( EPtiKey2 );
       
   640     iKeysArr.Append( EPtiKey3 );
       
   641     iKeysArr.Append( EPtiKey4 );
       
   642     iKeysArr.Append( EPtiKey5 );
       
   643     iKeysArr.Append( EPtiKey6 );
       
   644     iKeysArr.Append( EPtiKey7 );
       
   645     iKeysArr.Append( EPtiKey8 );
       
   646     iKeysArr.Append( EPtiKey9 );
       
   647 
       
   648     AppendEntryWithFakeKeyToKeyList();
       
   649 
       
   650     PRINT ( _L("End CPcsKeyMap::CreateKeyListFromITUTHardcodedKeys") );
       
   651     }
   699     }
   652 
   700 
   653 // ----------------------------------------------------------------------------
   701 // ----------------------------------------------------------------------------
   654 // CPcsKeyMap::CreateKeyMapFromKeyBindingTable
   702 // CPcsKeyMap::CreateKeyMapFromKeyBindingTable
   655 //
   703 //
   656 // ----------------------------------------------------------------------------
   704 // ----------------------------------------------------------------------------
   657 void CPcsKeyMap::CreateKeyListFromKeyBindingTable( CPtiEngine* aPtiEngine )
   705 void CPcsKeyMap::CreateKeyListFromKeyBindingTable( RArray<TPtiKey>& aKeyArray, 
       
   706         TPtiKeyboardType aKbType, CPtiEngine* aPtiEngine )
   658     {
   707     {
   659     PRINT ( _L("Enter CPcsKeyMap::CreateKeyListFromKeyBindingTable") );
   708     PRINT ( _L("Enter CPcsKeyMap::CreateKeyListFromKeyBindingTable") );
       
   709 
       
   710     PRINT1 ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: Creating KeyList for TPtiKeyboardType=%d"),
       
   711              aKbType  );
   660 
   712 
   661     // Get the user language
   713     // Get the user language
   662     TLanguage keyMapLanguage = iUILanguage;
   714     TLanguage keyMapLanguage = iUILanguage;
   663     PRINT1 ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: Current User Language is %d"),
   715     PRINT1 ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: Current User Language is %d"),
   664             keyMapLanguage  );
   716             keyMapLanguage  );
   683         currLanguage = static_cast<CPtiCoreLanguage*>(aPtiEngine->GetLanguage( ELangEnglish ));
   735         currLanguage = static_cast<CPtiCoreLanguage*>(aPtiEngine->GetLanguage( ELangEnglish ));
   684         }
   736         }
   685 
   737 
   686     if (currLanguage)
   738     if (currLanguage)
   687         {
   739         {
       
   740         TInt langCode = currLanguage->LanguageCode();
       
   741         TRAP_IGNORE( aPtiEngine->ActivateLanguageL( langCode ) );
       
   742         const CPtiKeyMapData* keyMapData = currLanguage->RawKeyMapData();
       
   743         const TPtiKeyBinding* table = NULL;
   688         TInt numItems = 0;
   744         TInt numItems = 0;
   689         const TPtiKeyBinding* table = GetKeyMapData(*currLanguage)->KeyBindingTable(iKeyboardType, numItems);
   745         if ( keyMapData )
       
   746             {
       
   747             table = keyMapData->KeyBindingTable(aKbType, numItems);
       
   748             }
       
   749         else
       
   750             {
       
   751             PRINT1( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: #### Failed to get RawKeyMapData for language %d ####"), langCode );
       
   752             }
   690         
   753         
   691         PRINT1 ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: Num of Items in KeyBindingTable is %d"), numItems );
   754         PRINT1 ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: Num of Items in KeyBindingTable is %d"), numItems );
   692 
   755 
   693         // Get from the key table the keys for constructing the pools
   756         // Get from the key table the keys for constructing the pools
   694         if (table)
   757         if (table)
   698                 TPtiKey key = (TPtiKey) table[i].iScanCode;
   761                 TPtiKey key = (TPtiKey) table[i].iScanCode;
   699                 // Get all keys with same EPtiCaseLower or EPtiCaseUpper case
   762                 // Get all keys with same EPtiCaseLower or EPtiCaseUpper case
   700                 // Only for one of the casing to avoid repetitions
   763                 // Only for one of the casing to avoid repetitions
   701                 if ( (EPtiKeyNone != key) && (EPtiCaseLower == table[i].iCase) )
   764                 if ( (EPtiKeyNone != key) && (EPtiCaseLower == table[i].iCase) )
   702                     {
   765                     {
   703                     PRINT3 ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: Adding pool %d with key '%c' (%d)"),
   766                     PRINT3 ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: Adding pool %d with key '%c' (0x%02X)"),
   704                             iKeysArr.Count(), key, key );
   767                             aKeyArray.Count(), key, key );
   705                     iKeysArr.Append( key );
   768                     aKeyArray.Append( key );
   706                     }
   769                     }
   707                 }
   770                 }
       
   771             // Add a fake key at the end if the KeyList is not empty
       
   772             if (aKeyArray.Count() > 0)
       
   773                 {
       
   774                 AppendEntryWithFakeKeyToKeyList(aKeyArray);
       
   775                 }
   708             }
   776             }
   709         else
   777         else
   710             {
   778             {
   711             PRINT ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: ##### Failed to create Key List (KeyBindingTable) #####") );
   779             PRINT ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: ##### Failed to create Key List (KeyBindingTable) #####") );
   712             }
   780             }
   713         }
   781         }
   714     else
   782     else
   715         {
   783         {
   716         PRINT ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: ##### Failed to create Key List (Language) #####") );
   784         PRINT ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: ##### Failed to create Key List (Language) #####") );
   717         }
   785         }
   718 
       
   719     AppendEntryWithFakeKeyToKeyList();
       
   720 
   786 
   721     PRINT ( _L("End CPcsKeyMap::CreateKeyListFromKeyBindingTable") );
   787     PRINT ( _L("End CPcsKeyMap::CreateKeyListFromKeyBindingTable") );
   722 }
   788 }
   723 
   789 
   724 // ----------------------------------------------------------------------------
   790 // ----------------------------------------------------------------------------
   725 // CPcsKeyMap::CreateKeyListL
       
   726 //
       
   727 // ----------------------------------------------------------------------------
       
   728 void CPcsKeyMap::CreateKeyListL( CPtiEngine* aPtiEngine )
       
   729     {
       
   730     PRINT ( _L("Enter CPcsKeyMap::CreateKeyListL") );
       
   731 
       
   732     switch ( iKeyboardType )
       
   733         {
       
   734         case EPtiKeyboardQwerty4x12:
       
   735         case EPtiKeyboardQwerty4x10:
       
   736         case EPtiKeyboardQwerty3x11:
       
   737         case EPtiKeyboardCustomQwerty:
       
   738             CreateKeyListFromKeyBindingTable( aPtiEngine );
       
   739             break;
       
   740 
       
   741         case EPtiKeyboard12Key:
       
   742             CreateKeyListFromITUTHardcodedKeys( );
       
   743             break;
       
   744 
       
   745         case EPtiKeyboardHalfQwerty:
       
   746             CreateKeyListFromKeyBindingTable( aPtiEngine );
       
   747             break;
       
   748 
       
   749         default:
       
   750             CreateKeyListFromKeyBindingTable( aPtiEngine );
       
   751             break;
       
   752         }
       
   753 
       
   754     PRINT ( _L("End CPcsKeyMap::CreateKeyListL") );
       
   755     }
       
   756 
       
   757 // ----------------------------------------------------------------------------
       
   758 // CPcsKeyMap::IsLanguageSupported
   791 // CPcsKeyMap::IsLanguageSupported
   759 // Returns ETrue if this language is supported
   792 // Returns ETrue if this language is supported
   760 // ----------------------------------------------------------------------------
   793 // ----------------------------------------------------------------------------
   761 TBool CPcsKeyMap::IsLanguageSupported(TInt aLang)
   794 TBool CPcsKeyMap::IsLanguageSupported(TInt aLang)
   762     {
   795     {
   763     return (KErrNotFound == iLanguageNotSupported.Find((TLanguage) aLang));
   796     TBool supported = 
       
   797 #ifdef __WINS__
       
   798             // Only few languages for emulator 
       
   799             ( ELangEnglish == aLang || 
       
   800               ELangRussian == aLang || 
       
   801               ELangHebrew == aLang || 
       
   802               ELangFinnish == aLang ) &&
       
   803 #endif // __WINS__
       
   804             ( KErrNotFound == iLanguageNotSupported.Find((TLanguage)aLang) );
       
   805                 
       
   806     return supported;
   764     }
   807     }
   765 
   808 
   766 // ----------------------------------------------------------------------------
   809 // ----------------------------------------------------------------------------
   767 // CPcsKeyMap::CreateKeyMappingL
   810 // CPcsKeyMap::CreateKeyMappingL
   768 //
   811 //
   769 // ----------------------------------------------------------------------------
   812 // ----------------------------------------------------------------------------
   770 void CPcsKeyMap::CreateKeyMappingL()
   813 void CPcsKeyMap::CreateKeyMappingL( TKeyboardModes aKbMode )
   771     {
   814     {
   772     PRINT ( _L("Enter CPcsKeyMap::CreateKeyMappingL") );
   815     PRINT ( _L("Enter CPcsKeyMap::CreateKeyMappingL") );
   773 
   816 
       
   817     __ASSERT_DEBUG( (aKbMode==EPredictiveItuT || aKbMode==EPredictiveQwerty),
       
   818                     Panic(EPanic_InvalidKeyboardType) );
       
   819 
       
   820     // Select the arrays we are operating on
       
   821     RArray<TPtiKey>* ptiKeysArray;
       
   822     RPointerArray<TKeyMappingData>* keyMappingArray;
       
   823     TPtiKeyboardType kbType;
       
   824     GetPredictiveKeyboardData( aKbMode, ptiKeysArray, keyMappingArray, kbType );
       
   825     if ( kbType == EPtiKeyboardNone )
       
   826         {
       
   827         PRINT1( _L("CPcsKeyMap::CreateKeyMappingL: ##### No Keyboard available for mode %d => skipping #####"), aKbMode );
       
   828         return;
       
   829         }
       
   830     
   774     // Instantiate the engine
   831     // Instantiate the engine
   775     CPtiEngine* ptiEngine = CPtiEngine::NewL(ETrue);
   832     CPtiEngine* ptiEngine = CPtiEngine::NewL(ETrue);
   776     CleanupStack::PushL( ptiEngine );
   833     CleanupStack::PushL( ptiEngine );
   777 
   834 
   778     ptiEngine->SetKeyboardType( iKeyboardType );
   835     ptiEngine->SetKeyboardType( kbType );
   779 
   836 
   780     CreateKeyListL( ptiEngine );
   837     CreateKeyListFromKeyBindingTable( *ptiKeysArray, kbType, ptiEngine );
   781 
   838 
   782     // Now add the keymap arrays to hold the keymap data
   839     if ( ptiKeysArray->Count() > 0 )
   783     for (TInt i = 0; i < iKeysArr.Count(); i++)
   840         {
   784     {
   841         // Now add the keymap arrays to hold the keymap data
   785         TKeyMappingData *keyData = new(ELeave) TKeyMappingData;
   842         for (TInt i = 0; i < ptiKeysArray->Count(); i++)
   786         iKeyMapPtrArr.Append(keyData);
   843             {
   787     }
   844             TKeyMappingData *keyData = new(ELeave) TKeyMappingData;
   788 
   845             keyMappingArray->Append(keyData);
   789     // Get the available Languages on the phone
   846             }
   790     RArray<TInt> LanguagesOnThisPhone;
   847     
   791     ptiEngine->GetAvailableLanguagesL(LanguagesOnThisPhone);
   848         // Get the available Languages on the phone
   792     PRINT2 ( _L("CPcsKeyMap::CreateKeyMappingL: Languages on this phone %d, maximum is set to %d"),
   849         RArray<TInt> languagesOnThisPhone;
   793              LanguagesOnThisPhone.Count(), KMaxNbrOfLangKeymapping );
   850         CleanupClosePushL( languagesOnThisPhone );
   794     
   851         ptiEngine->GetAvailableLanguagesL(languagesOnThisPhone);
   795     // Remove the non-supported languages
   852         PRINT2 ( _L("CPcsKeyMap::CreateKeyMappingL: Languages on this phone %d, maximum is set to %d"),
   796     for (TInt i = 0; i < LanguagesOnThisPhone.Count(); /* do not increment i */)
   853                  languagesOnThisPhone.Count(), KMaxNbrOfLangKeymapping );
   797         {
   854         
   798         if ( (IsLanguageSupported(LanguagesOnThisPhone[i]))
   855         // Remove the non-supported languages
   799 #ifdef __WINS__
   856         for (TInt i = 0; i < languagesOnThisPhone.Count(); /* do not increment i */)
   800              && (ELangEnglish == LanguagesOnThisPhone[i]) // Only English for emulator 
   857             {
   801 #endif // __WINS__
   858             if ( IsLanguageSupported(languagesOnThisPhone[i]) )
   802            )
   859                 {
   803             {
   860                 i++;
   804             i++;
   861                 }
   805             }
   862             else
   806         else
   863                 {
   807             {
   864                 PRINT1 ( _L("CPcsKeyMap::CreateKeyMappingL: Removing not supported Language %d"),
   808             PRINT1 ( _L("CPcsKeyMap::CreateKeyMappingL: Removing not supported Language %d"),
   865                          languagesOnThisPhone[i] );
   809                      LanguagesOnThisPhone[i] );
   866                 languagesOnThisPhone.Remove(i);
   810             LanguagesOnThisPhone.Remove(i);
   867                 }
   811             }
   868             }
   812         }
   869     
   813 
   870         // Set current UI language as 1st language and English as 2nd language,
   814     // Set current UI language as 1st language and English as 2nd language,
   871         // if present in AvailableLanguages
   815     // if present in AvailableLanguages
   872         TInt langIndex;
   816     TInt langIndex;
   873         if ( KErrNotFound != (langIndex = languagesOnThisPhone.Find(ELangEnglish)) )
   817     if ( KErrNotFound != (langIndex = LanguagesOnThisPhone.Find(ELangEnglish)) )
   874             {
   818         {
   875             languagesOnThisPhone.Remove(langIndex);
   819         LanguagesOnThisPhone.Remove(langIndex);
   876             languagesOnThisPhone.Insert(ELangEnglish, 0);
   820         LanguagesOnThisPhone.Insert(ELangEnglish, 0);
   877             }
   821         }
   878         if ( KErrNotFound != (langIndex = languagesOnThisPhone.Find(iUILanguage)) )
   822     if ( KErrNotFound != (langIndex = LanguagesOnThisPhone.Find(iUILanguage)) )
   879             {
   823         {
   880             languagesOnThisPhone.Remove(langIndex);
   824         LanguagesOnThisPhone.Remove(langIndex);
   881             languagesOnThisPhone.Insert(iUILanguage, 0);
   825         LanguagesOnThisPhone.Insert(iUILanguage, 0);
   882             }
   826         }
   883     
   827 
   884         // Set max number of languages for Key Map
   828     // Set max number of languages for Key Map
   885         TInt count = languagesOnThisPhone.Count();
   829     TInt count = LanguagesOnThisPhone.Count();
   886         if (count > KMaxNbrOfLangKeymapping)
   830     if (count > KMaxNbrOfLangKeymapping)
   887             {
   831         {
   888             PRINT2 ( _L("CPcsKeyMap::CreateKeyMappingL: Supported Languages on this phone %d, limiting to %d"),
   832         PRINT2 ( _L("CPcsKeyMap::CreateKeyMappingL: Supported Languages on this phone %d, limiting to %d"),
   889                      count, KMaxNbrOfLangKeymapping );
   833                  count, KMaxNbrOfLangKeymapping );
   890             count = KMaxNbrOfLangKeymapping;
   834         count = KMaxNbrOfLangKeymapping;
   891             }
   835         }
   892     
   836 
   893         // Add Key Map for the languages
   837     // Add Key Map for the languages
   894         for (TInt i = 0; i < count; i++)
   838     for (TInt i = 0; i < count; i++)
   895             {
   839         {
   896             TLanguage languageToUse = (TLanguage) languagesOnThisPhone[i];
   840         TLanguage languageToUse = (TLanguage) LanguagesOnThisPhone[i];
   897     
   841 
   898             PRINT1 ( _L("CPcsKeyMap::CreateKeyMappingL: Constructing Key Map for Language %d"), languageToUse );
   842         PRINT1 ( _L("CPcsKeyMap::CreateKeyMappingL: Constructing Key Map for Language %d"), languageToUse );
   899             TRAPD( leaveCode, AddKeyMappingForLanguageL(ptiEngine, languageToUse, kbType, *ptiKeysArray, *keyMappingArray) );
   843         TInt errStatus = ptiEngine->ActivateLanguageL(languageToUse);
   900             if ( leaveCode )
   844         if (KErrNone == errStatus)
   901                 {
   845             {
   902                 PRINT2 ( _L("CPcsKeyMap::CreateKeyMappingL: ##### Adding mappings for language %d failed, leave code = %d #####"),
   846             TRAP_IGNORE(AddKeyMappingForActiveLanguageL(ptiEngine, languageToUse));
   903                          languageToUse, leaveCode );
   847             }
   904                 }
   848         else
   905     
   849             {
   906             PRINT ( _L("CPcsKeyMap::CreateKeyMappingL: ===================================================") );
   850             PRINT1 ( _L("CPcsKeyMap::CreateKeyMappingL: ##### Unable to activate Language %d #####"),
   907             }
   851                      languageToUse );
   908     
   852             }
   909         CleanupStack::PopAndDestroy( &languagesOnThisPhone );
   853 
   910         }
   854         // Close the currently activated language
       
   855         ptiEngine->CloseCurrentLanguageL();
       
   856 
       
   857         PRINT ( _L("CPcsKeyMap::CreateKeyMappingL: ===================================================") );
       
   858         }
       
   859 
       
   860     LanguagesOnThisPhone.Close();
       
   861 
   911 
   862     CleanupStack::PopAndDestroy( ptiEngine );
   912     CleanupStack::PopAndDestroy( ptiEngine );
   863 
   913 
   864     PRINT ( _L("End CPcsKeyMap::CreateKeyMappingL") );
   914     PRINT ( _L("End CPcsKeyMap::CreateKeyMappingL") );
   865     }
   915     }
   866 
   916 
   867 // ----------------------------------------------------------------------------
   917 // ----------------------------------------------------------------------------
   868 // CPcsKeyMap::AddKeyMappingForActiveLanguageL
   918 // CPcsKeyMap::AddKeyMappingForActiveLanguageL
   869 //
   919 //
   870 // ----------------------------------------------------------------------------
   920 // ----------------------------------------------------------------------------
   871 void CPcsKeyMap::AddKeyMappingForActiveLanguageL(CPtiEngine* aPtiEngine, TLanguage aLanguage)
   921 void CPcsKeyMap::AddKeyMappingForLanguageL(
       
   922         CPtiEngine* aPtiEngine, 
       
   923         TLanguage aLanguage,
       
   924         TPtiKeyboardType aKbType,
       
   925         const RArray<TPtiKey>& aPtiKeys,
       
   926         RPointerArray<TKeyMappingData>& aResultMapping )
   872 {
   927 {
   873     PRINT ( _L("Enter CPcsKeyMap::AddKeyMappingForActiveLanguageL") );
   928     PRINT ( _L("Enter CPcsKeyMap::AddKeyMappingForLanguageL") );
       
   929 
       
   930     TInt err = aPtiEngine->ActivateLanguageL( aLanguage );
       
   931     if ( err )
       
   932         {
       
   933         PRINT2 ( _L("##### CPcsKeyMap::AddKeyMappingForLanguageL failed to activate language %d, error=%d) #####"),
       
   934                 aLanguage, err );
       
   935         User::Leave( err );
       
   936         }
   874 
   937 
   875     // Make a language object based on the language
   938     // Make a language object based on the language
   876     CPtiCoreLanguage* activeLanguage = static_cast<CPtiCoreLanguage*>(aPtiEngine->GetLanguage( aLanguage ));
   939     CPtiCoreLanguage* language = static_cast<CPtiCoreLanguage*>(aPtiEngine->GetLanguage( aLanguage ));
   877 
   940 
   878     if (activeLanguage)
   941     if (language)
   879         {
   942         {
   880         // Get the keyboard Mappings for the Active Language
   943         for (TInt i = 0; i < aResultMapping.Count() - 1; i++)
   881         MPtiKeyMappings* ptiKeyMappings = GetKeyboardKeyMapping( *activeLanguage );
   944             {
   882 
   945             TPtiKey key = aPtiKeys[i];
   883         for (TInt i = 0; i < PoolCount() - 1; i++)
   946 
   884             {
   947             PRINT ( _L("CPcsKeyMap::AddKeyMappingForLanguageL: ===================================================") );
   885             TPtiKey key = iKeysArr[i];
   948             PRINT4 ( _L("CPcsKeyMap::AddKeyMappingForLanguageL: Adding chars for Key '%c' (0x%02X) for Keyboard Type %d and Language %d"),
   886 
   949                      key, key, aKbType, aLanguage );
   887             PRINT ( _L("CPcsKeyMap::AddKeyMappingForActiveLanguageL: ===================================================") );
       
   888             PRINT4 ( _L("CPcsKeyMap::AddKeyMappingForActiveLanguageL: Adding characters for Key '%c' (%d) at Pool %d and Language %d"),
       
   889                      (TInt) key, (TInt) key, PoolIdForKey(key), aLanguage );
       
   890 
   950 
   891             // Get the pointer to the language class (UI, English, Others)
   951             // Get the pointer to the language class (UI, English, Others)
   892             RArray<TUint>* keyMapLang;
   952             RArray<TUint>* keyMapLang;
   893             if (aLanguage == iUILanguage)
   953             if (aLanguage == iUILanguage)
   894                 {
   954                 {
   895                 keyMapLang = &(iKeyMapPtrArr[i]->iKeyMapCharArr[TKeyMappingData::EKeyMapUILangArr]);
   955                 keyMapLang = &(aResultMapping[i]->iKeyMapCharArr[TKeyMappingData::EKeyMapUILangArr]);
   896                 PRINT1 ( _L("CPcsKeyMap::AddKeyMappingForActiveLanguageL: Language %d is the UI language"), aLanguage );
   956                 PRINT1 ( _L("CPcsKeyMap::AddKeyMappingForLanguageL: Language %d is the UI language"), aLanguage );
   897                 }
   957                 }
   898             else if (aLanguage == ELangEnglish)
   958             else if (aLanguage == ELangEnglish)
   899                 {
   959                 {
   900                 // If (iUILanguage == ELangEnglish) ok to be in previous if case
   960                 // If (iUILanguage == ELangEnglish) ok to be in previous if case
   901                 keyMapLang = &(iKeyMapPtrArr[i]->iKeyMapCharArr[TKeyMappingData::EKeyMapEnglishLangArr]);
   961                 keyMapLang = &(aResultMapping[i]->iKeyMapCharArr[TKeyMappingData::EKeyMapEnglishLangArr]);
   902                 PRINT1 ( _L("CPcsKeyMap::AddKeyMappingForActiveLanguageL: Language %d is English language"), aLanguage );
   962                 PRINT1 ( _L("CPcsKeyMap::AddKeyMappingForLanguageL: Language %d is English language"), aLanguage );
   903                 }
   963                 }
   904             else
   964             else
   905                 {
   965                 {
   906                 keyMapLang = &(iKeyMapPtrArr[i]->iKeyMapCharArr[TKeyMappingData::EKeyMapOthersLangArr]);
   966                 keyMapLang = &(aResultMapping[i]->iKeyMapCharArr[TKeyMappingData::EKeyMapOthersLangArr]);
   907                 PRINT1 ( _L("CPcsKeyMap::AddKeyMappingForActiveLanguageL: Language %d is in the Other languages"), aLanguage );
   967                 PRINT1 ( _L("CPcsKeyMap::AddKeyMappingForLanguageL: Language %d is in the Other languages"), aLanguage );
   908                 }
   968                 }
   909             
   969             
   910             PRINT ( _L("CPcsKeyMap::AddKeyMappingForActiveLanguageL: ---------------------------------------------------") );
   970             PRINT ( _L("CPcsKeyMap::AddKeyMappingForLanguageL: ---------------------------------------------------") );
   911 
   971 
   912             TBool isSingleCharForKey = ETrue;
   972             TBool isSingleCharForKey = ETrue;
   913             TUint singleChar = 0;
   973             TUint singleChar = 0;
   914 
   974 
   915             // EPtiCaseUpper must be the 1st TPtiTextCase for iUILanguage
   975             // EPtiCaseUpper must be the 1st TPtiTextCase for iUILanguage
   916             AddCharactersToKey( *ptiKeyMappings, key, EPtiCaseUpper, *iKeyMapPtrArr[i], *keyMapLang, isSingleCharForKey, singleChar );
   976             AddCharactersToKey( *language, aKbType, key, EPtiCaseUpper, *aResultMapping[i], *keyMapLang, isSingleCharForKey, singleChar );
   917             AddCharactersToKey( *ptiKeyMappings, key, EPtiCaseLower, *iKeyMapPtrArr[i], *keyMapLang, isSingleCharForKey, singleChar );
   977             AddCharactersToKey( *language, aKbType, key, EPtiCaseLower, *aResultMapping[i], *keyMapLang, isSingleCharForKey, singleChar );
   918 
   978 
   919             // 1. No other TPtiTextCase values for ITUT keyboard
   979             // 1. No other TPtiTextCase values for ITUT keyboard
   920             // 2. No language variants handling for ITUT keyboard
   980             // 2. No language variants handling for ITUT keyboard
   921             if ( EPtiKeyboard12Key != iKeyboardType )
   981             if ( EPtiKeyboard12Key != aKbType )
   922                 {
   982                 {
   923                 AddCharactersToKey( *ptiKeyMappings, key, EPtiCaseFnLower,  *iKeyMapPtrArr[i], *keyMapLang, isSingleCharForKey, singleChar );
   983                 AddCharactersToKey( *language, aKbType, key, EPtiCaseFnLower,  *aResultMapping[i], *keyMapLang, isSingleCharForKey, singleChar );
   924                 AddCharactersToKey( *ptiKeyMappings, key, EPtiCaseFnUpper,  *iKeyMapPtrArr[i], *keyMapLang, isSingleCharForKey, singleChar );
   984                 AddCharactersToKey( *language, aKbType, key, EPtiCaseFnUpper,  *aResultMapping[i], *keyMapLang, isSingleCharForKey, singleChar );
   925                 AddCharactersToKey( *ptiKeyMappings, key, EPtiCaseChrLower, *iKeyMapPtrArr[i], *keyMapLang, isSingleCharForKey, singleChar );
   985                 AddCharactersToKey( *language, aKbType, key, EPtiCaseChrLower, *aResultMapping[i], *keyMapLang, isSingleCharForKey, singleChar );
   926                 AddCharactersToKey( *ptiKeyMappings, key, EPtiCaseChrUpper, *iKeyMapPtrArr[i], *keyMapLang, isSingleCharForKey, singleChar );
   986                 AddCharactersToKey( *language, aKbType, key, EPtiCaseChrUpper, *aResultMapping[i], *keyMapLang, isSingleCharForKey, singleChar );
   927 
   987 
   928                 // Support for key guessing given the char in some phone language variants
   988                 // Support for key guessing given the char in some phone language variants
   929                 if ( (isSingleCharForKey) && (0 != singleChar) )
   989                 if ( (isSingleCharForKey) && (0 != singleChar) )
   930                     {
   990                     {
   931                     iKeyMapPtrArr[i]->iKeyMapCharArr[TKeyMappingData::EKeyMapSingleCharArr].Append(singleChar); // singleChar is in LowerCase
   991                     aResultMapping[i]->iKeyMapCharArr[TKeyMappingData::EKeyMapSingleCharArr].Append(singleChar); // singleChar is in LowerCase
   932                     iKeyMapPtrArr[i]->iKeyMapCharArr[TKeyMappingData::EKeyMapSingleCharArr].Append(User::UpperCase(singleChar));
   992                     aResultMapping[i]->iKeyMapCharArr[TKeyMappingData::EKeyMapSingleCharArr].Append(User::UpperCase(singleChar));
   933 
   993 
   934                     PRINT ( _L("CPcsKeyMap::AddKeyMappingForActiveLanguageL: ---------------------------------------------------") );
   994                     PRINT ( _L("CPcsKeyMap::AddKeyMappingForLanguageL: ---------------------------------------------------") );
   935                     PRINT5 ( _L("CPcsKeyMap::AddKeyMappingForActiveLanguageL: For Language %d and key '%c' of pool %d single char is '%c' (#%d)"),
   995                     PRINT5 ( _L("CPcsKeyMap::AddKeyMappingForLanguageL: For Language %d and key '%c' of pool %d single char is '%c' (0x%04X)"),
   936                             aLanguage, (TInt) key, i, singleChar, singleChar );
   996                             aLanguage, key, i, singleChar, singleChar );
   937                     }
   997                     }
   938                 }
   998                 }
   939             }
   999             }
   940         PRINT ( _L("CPcsKeyMap::AddKeyMappingForActiveLanguageL: ===================================================") );
  1000         PRINT ( _L("CPcsKeyMap::AddKeyMappingForLanguageL: ===================================================") );
   941         }
  1001         }
   942 
  1002 
   943     PRINT ( _L("End CPcsKeyMap::AddKeyMappingForActiveLanguageL") );
  1003     PRINT ( _L("End CPcsKeyMap::AddKeyMappingForLanguageL") );
   944 }
  1004 }
   945 
  1005 
   946 // ----------------------------------------------------------------------------
  1006 // ----------------------------------------------------------------------------
   947 // CPcsKeyMap::GetCharactersForKey
  1007 // CPcsKeyMap::GetCharactersForKey
   948 //
  1008 //
   949 // ----------------------------------------------------------------------------
  1009 // ----------------------------------------------------------------------------
   950 void CPcsKeyMap::GetCharactersForKey(MPtiKeyMappings& aPtiKeyMappings,
  1010 void CPcsKeyMap::GetCharactersForKey(CPtiCoreLanguage& aPtiLanguage,
       
  1011                                      TPtiKeyboardType aKbType,
   951                                      TPtiKey aKey,
  1012                                      TPtiKey aKey,
   952                                      TPtiTextCase aTextCase,
  1013                                      TPtiTextCase aTextCase,
   953                                      TDes& aResult)
  1014                                      TDes& aResult)
   954     {
  1015     {
   955     switch ( iKeyboardType )
  1016     const CPtiKeyMapData* keyMapData = aPtiLanguage.RawKeyMapData();
   956         {
  1017     if  ( keyMapData )
   957         case EPtiKeyboardQwerty4x12:
  1018         {
   958         case EPtiKeyboardQwerty4x10:
  1019         TPtrC dataPtr = keyMapData->DataForKey( aKbType, aKey, aTextCase );
   959         case EPtiKeyboardQwerty3x11:
  1020         // truncate results if supplied buffer is not large enough
   960         case EPtiKeyboardCustomQwerty:
  1021         aResult = dataPtr.Left( aResult.MaxLength() );
   961             (static_cast<CPtiQwertyKeyMappings*>(&aPtiKeyMappings))->GetDataForKey(aKey, aResult, aTextCase);
       
   962             break;
       
   963 
       
   964         case EPtiKeyboard12Key:
       
   965             (static_cast<CPtiKeyMappings*>(&aPtiKeyMappings))->GetDataForKey(aKey, aResult, aTextCase);
       
   966             break;
       
   967 
       
   968         case EPtiKeyboardHalfQwerty:
       
   969             (static_cast<CPtiHalfQwertyKeyMappings*>(&aPtiKeyMappings))->GetDataForKey(aKey, aResult, aTextCase);
       
   970             break;
       
   971 
       
   972         default:
       
   973             (static_cast<CPtiKeyMappings*>(&aPtiKeyMappings))->GetDataForKey(aKey, aResult, aTextCase);
       
   974             break;
       
   975         }
  1022         }
   976     }
  1023     }
   977 
  1024 
   978 // ----------------------------------------------------------------------------
  1025 // ----------------------------------------------------------------------------
   979 // CPcsKeyMap::AddDataForKeyL
  1026 // CPcsKeyMap::AddDataForKeyL
   980 //
  1027 //
   981 // ----------------------------------------------------------------------------
  1028 // ----------------------------------------------------------------------------
   982 void CPcsKeyMap::AddCharactersToKey(MPtiKeyMappings& aPtiKeyMappings,
  1029 void CPcsKeyMap::AddCharactersToKey(CPtiCoreLanguage& aPtiLanguage,
       
  1030                                     TPtiKeyboardType aKbType,
   983                                     TPtiKey aKey,
  1031                                     TPtiKey aKey,
   984                                     TPtiTextCase aTextCase,
  1032                                     TPtiTextCase aTextCase,
   985                                     TKeyMappingData& aKeyDataList,
  1033                                     TKeyMappingData& aKeyDataList,
   986                                     RArray<TUint>& aKeyMapLang,
  1034                                     RArray<TUint>& aKeyMapLang,
   987                                     TBool& aIsSingleCharForKey,
  1035                                     TBool& aIsSingleCharForKey,
   988                                     TUint& aSingleChar)
  1036                                     TUint& aSingleChar)
   989     {
  1037     {
   990     PRINT ( _L("Enter CPcsKeyMap::AddCharactersToKey") );
  1038     PRINT ( _L("Enter CPcsKeyMap::AddCharactersToKey") );
   991 
  1039 
   992     TBuf<255> result;
  1040     TBuf<255> result;
   993     GetCharactersForKey(aPtiKeyMappings, aKey, aTextCase, result);
  1041     GetCharactersForKey(aPtiLanguage, aKbType, aKey, aTextCase, result);
   994 
  1042 
   995     PRINT3 ( _L("CPcsKeyMap::AddCharactersToKey: Get mapping chars for Key '%c' (%d) and TextCase %d"),
  1043     PRINT3 ( _L("CPcsKeyMap::AddCharactersToKey: Get mapping chars for Key '%c' (0x%02X) and TextCase %d"),
   996              (TInt) aKey, (TInt) aKey, aTextCase );
  1044              aKey, aKey, aTextCase );
   997     PRINT1 ( _L("CPcsKeyMap::AddCharactersToKey: Got chars: \"%S\""), &result );
  1045     PRINT1 ( _L("CPcsKeyMap::AddCharactersToKey: Got chars: \"%S\""), &result );
   998 
  1046 
   999     for ( TInt i = 0; i < result.Length(); i++ )
  1047     for ( TInt i = 0; i < result.Length(); i++ )
  1000         {
  1048         {
  1001         if ( !CharacterForKeyMappingExists(aKeyDataList, (TUint) result[i]) )
  1049         TText character = result[i];
  1002             {
  1050         if ( !CharacterForKeyMappingExists(aKeyDataList, character ) )
  1003             PRINT1 ( _L("CPcsKeyMap::AddCharactersToKey: ----- Appending char to list: '%c'"), result[i] );
  1051             {
  1004             aKeyMapLang.Append(result[i]);
  1052             PRINT2 ( _L("CPcsKeyMap::AddCharactersToKey: ----- Appending char to list: '%c' (0x%04X)"), character, character );
       
  1053             aKeyMapLang.Append(character);
  1005             }
  1054             }
  1006         else
  1055         else
  1007             {
  1056             {
  1008             PRINT1 ( _L("CPcsKeyMap::AddCharactersToKey: ***** NOT Appending char to list: '%c'"), result[i] );
  1057             PRINT2 ( _L("CPcsKeyMap::AddCharactersToKey: ***** NOT Appending char to list: '%c' (0x%04X)"), character, character );
  1009             }
  1058             }
  1010 
  1059 
  1011         // No language variants handling for ITUT keyboard
  1060         // No language variants handling for ITUT keyboard
  1012         if ( EPtiKeyboard12Key != iKeyboardType )
  1061         if ( EPtiKeyboard12Key != aKbType )
  1013             {
  1062             {
  1014             // Support for key guessing given the char in some phone language variants
  1063             // Support for key guessing given the char in some phone language variants
  1015             if ( aIsSingleCharForKey )
  1064             if ( aIsSingleCharForKey )
  1016                 {
  1065                 {
  1017                 if ( 0 == aSingleChar )
  1066                 if ( 0 == aSingleChar )
  1018                     {
  1067                     {
  1019                     aSingleChar = User::LowerCase(result[i]);
  1068                     aSingleChar = User::LowerCase(character);
  1020                     }
  1069                     }
  1021                 else
  1070                 else
  1022                     {
  1071                     {
  1023                     TInt newChar = User::LowerCase(result[i]);
  1072                     TInt newChar = User::LowerCase(character);
  1024                     if (newChar != aSingleChar)
  1073                     if (newChar != aSingleChar)
  1025                         {
  1074                         {
  1026                         aSingleChar = 0;
  1075                         aSingleChar = 0;
  1027                         aIsSingleCharForKey = EFalse;
  1076                         aIsSingleCharForKey = EFalse;
  1028                         }
  1077                         }
  1034     PRINT ( _L("CPcsKeyMap::AddCharactersToKey: ---------------------------------------------------") );
  1083     PRINT ( _L("CPcsKeyMap::AddCharactersToKey: ---------------------------------------------------") );
  1035 
  1084 
  1036     PRINT ( _L("End CPcsKeyMap::AddCharactersToKey") );
  1085     PRINT ( _L("End CPcsKeyMap::AddCharactersToKey") );
  1037     }
  1086     }
  1038 
  1087 
       
  1088 // ----------------------------------------------------------------------------
       
  1089 // CPcsKeyMap::GetPredictiveKeyboardData
       
  1090 //
       
  1091 // ----------------------------------------------------------------------------
       
  1092 void CPcsKeyMap::GetPredictiveKeyboardData( TKeyboardModes aKbMode, 
       
  1093                                             RArray<TPtiKey>*& aPtiKeys, 
       
  1094                                             RPointerArray<TKeyMappingData>*& aKeyMappings, 
       
  1095                                             TPtiKeyboardType& aKbType )
       
  1096     {
       
  1097     // Get the data from constant version of this function
       
  1098     const RArray<TPtiKey>* constKeys;
       
  1099     const RPointerArray<TKeyMappingData>* constMappings;
       
  1100     GetPredictiveKeyboardData( aKbMode, constKeys, constMappings, aKbType );
       
  1101     
       
  1102     // Convert pointers to non-const
       
  1103     aPtiKeys = const_cast< RArray<TPtiKey>* >( constKeys );
       
  1104     aKeyMappings = const_cast< RPointerArray<TKeyMappingData>* >( constMappings );
       
  1105     }
       
  1106 
       
  1107 // ----------------------------------------------------------------------------
       
  1108 // CPcsKeyMap::GetPredictiveKeyboardData
       
  1109 //
       
  1110 // ----------------------------------------------------------------------------
       
  1111 void CPcsKeyMap::GetPredictiveKeyboardData( TKeyboardModes aKbMode, 
       
  1112                                             const RArray<TPtiKey>*& aPtiKeys, 
       
  1113                                             const RPointerArray<TKeyMappingData>*& aKeyMappings, 
       
  1114                                             TPtiKeyboardType& aKbType ) const
       
  1115     {
       
  1116     PRINT1 ( _L("CPcsKeyMap::GetPredictiveKeyboardData: aKbMode=%d "), aKbMode );
       
  1117     
       
  1118     // EPredictiveItuT or EPredictiveQwerty mode to ENonPredictive mode if keyboard is not mapped
       
  1119     if ( aKbMode == EPredictiveItuT && iItutKeyboardType == EPtiKeyboardNone )
       
  1120         {
       
  1121         aKbMode = ENonPredictive;    
       
  1122         }
       
  1123     if ( aKbMode == EPredictiveQwerty && iQwertyKeyboardType == EPtiKeyboardNone )
       
  1124         {
       
  1125         aKbMode = ENonPredictive;    
       
  1126         }
       
  1127 
       
  1128     // Get Predictive Keyboard Data
       
  1129     switch (aKbMode)
       
  1130         {
       
  1131         case EPredictiveItuT:
       
  1132             {
       
  1133             aPtiKeys = &iItutKeys;
       
  1134             aKeyMappings = &iItutKeyMaps;
       
  1135             aKbType = iItutKeyboardType;
       
  1136             break;
       
  1137             }
       
  1138 
       
  1139         case EPredictiveQwerty:
       
  1140             {
       
  1141             aPtiKeys = &iQwertyKeys;
       
  1142             aKeyMappings = &iQwertyKeyMaps;
       
  1143             aKbType = iQwertyKeyboardType;
       
  1144             break;
       
  1145             }
       
  1146 
       
  1147         case ENonPredictive:
       
  1148             {
       
  1149             aPtiKeys = NULL;
       
  1150             aKeyMappings = NULL;
       
  1151             aKbType = EPtiKeyboardNone;
       
  1152             break;
       
  1153             }
       
  1154 
       
  1155         // EPredictiveDefaultKeyboard must have been resolved previously
       
  1156         // to EPredictiveItuT or EPredictiveQwerty mode
       
  1157         case EPredictiveDefaultKeyboard: 
       
  1158         default:
       
  1159             {
       
  1160             aPtiKeys = NULL;
       
  1161             aKeyMappings = NULL;
       
  1162             aKbType = EPtiKeyboardNone;
       
  1163             __ASSERT_DEBUG( EFalse, Panic( EPanic_InvalidKeyboardType ) );
       
  1164             break;
       
  1165             }
       
  1166         }
       
  1167     }
       
  1168 
  1039 // End of file
  1169 // End of file