predictivesearch/PcsAlgorithm/Algorithm1/src/CPcsKeyMap.cpp
changeset 0 e686773b3f54
child 15 e8e3147d53eb
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Retrieves the character map for each of the numeric keys.
       
    15 *               Uses services provided by the PTI Engine.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CPcsDebug.h"
       
    21 #include "CPcsKeyMap.h"
       
    22 #include <CPcsDefs.h>
       
    23 #include <bldvariant.hrh>
       
    24 #include <PtiDefs.h>
       
    25 #include <PtiKeyMappings.h>
       
    26 #include <PtiKeyMapData.h>
       
    27 #include <AknFepInternalCRKeys.h>
       
    28 #include <AvkonInternalCRKeys.h>
       
    29 #include <centralrepository.h>
       
    30 #include <CPsQuery.h>
       
    31 #include <CPsQueryItem.h>
       
    32 
       
    33 // Unnamed namespace for local definitions
       
    34 namespace {
       
    35 
       
    36 #ifdef _DEBUG
       
    37     enum TPanicCode
       
    38     {
       
    39         EPanicPreCond_MultipleSingleCharMatching = 1,
       
    40         EPanicPreCond_MultipleUIPriorityMatching = 2,
       
    41         EPanicPreCond_MultipleEnglishPriorityMatching = 3,
       
    42         EPanicPreCond_MultipleOthersPriorityMatching = 4,
       
    43    };
       
    44 
       
    45     void Panic(TInt aReason)
       
    46     {
       
    47         _LIT(KPanicText, "CPcsKeyMap");
       
    48         User::Panic(KPanicText, aReason);
       
    49     }
       
    50 #endif // DEBUG
       
    51 
       
    52 } // namespace
       
    53 
       
    54 // ============================== MEMBER FUNCTIONS ============================
       
    55 
       
    56 // ----------------------------------------------------------------------------
       
    57 // CPcsKeyMap::NewL
       
    58 // Two Phase Construction
       
    59 // ----------------------------------------------------------------------------
       
    60 CPcsKeyMap* CPcsKeyMap::NewL()
       
    61     {
       
    62     PRINT ( _L("Enter CPcsKeyMap::NewL") );
       
    63 
       
    64     CPcsKeyMap* self = new ( ELeave ) CPcsKeyMap();
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL();
       
    67     CleanupStack::Pop( self );
       
    68 
       
    69     PRINT ( _L("End CPcsKeyMap::NewL") );
       
    70 
       
    71     return self;
       
    72     }
       
    73 
       
    74 // ----------------------------------------------------------------------------
       
    75 // CPcsKeyMap::CPcsKeyMap
       
    76 // Constructor
       
    77 // ----------------------------------------------------------------------------
       
    78 CPcsKeyMap::CPcsKeyMap()
       
    79     {
       
    80     }
       
    81 
       
    82 // ----------------------------------------------------------------------------
       
    83 // CPcsKeyMap::ConstructL
       
    84 // 2nd Phase Constructor
       
    85 // ----------------------------------------------------------------------------
       
    86 void CPcsKeyMap::ConstructL()
       
    87     {
       
    88     PRINT ( _L("Enter CPcsKeyMap::ConstructL") );
       
    89 
       
    90     // UI Language
       
    91     iUILanguage = User::Language();
       
    92     
       
    93     // List of non-supported languages for this Algorithm
       
    94     iLanguageNotSupported.Append(ELangJapanese);
       
    95     iLanguageNotSupported.Append(ELangPrcChinese);
       
    96     iLanguageNotSupported.Append(ELangHongKongChinese);
       
    97     iLanguageNotSupported.Append(ELangTaiwanChinese);
       
    98 
       
    99 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   100 
       
   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 
       
   142     // Create structure for holding characters<-->key mappings
       
   143     CreateKeyMappingL();
       
   144 
       
   145     // 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
       
   147     SetSpaceAndZeroOnSameKey();
       
   148     
       
   149     PRINT ( _L("CPcsKeyMap::ConstructL: ----------------------------------------"));
       
   150 
       
   151     PRINT ( _L("End CPcsKeyMap::ConstructL") );
       
   152     }
       
   153 
       
   154 // ----------------------------------------------------------------------------
       
   155 // CPcsKeyMap::~CPcsKeyMap
       
   156 // Destructor
       
   157 // ----------------------------------------------------------------------------
       
   158 CPcsKeyMap::~CPcsKeyMap()
       
   159     {
       
   160     PRINT ( _L("Enter CPcsKeyMap::~CPcsKeyMap") );
       
   161 
       
   162     // Cleanup local arrays
       
   163     iLanguageNotSupported.Reset();
       
   164 
       
   165     for (TInt i = 0; i < PoolCount(); i++)
       
   166         {
       
   167         for (TInt j = 0; j < TKeyMappingData::EKeyMapNumberArr; j++)
       
   168             {
       
   169             iKeyMapPtrArr[i]->iKeyMapCharArr[j].Close();
       
   170             }
       
   171         }
       
   172     iKeyMapPtrArr.ResetAndDestroy();
       
   173     iKeysArr.Close();
       
   174 
       
   175     PRINT ( _L("End CPcsKeyMap::~CPcsKeyMap") );
       
   176     }
       
   177 
       
   178 // ----------------------------------------------------------------------------
       
   179 // CPcsKeyMap::GetMixedKeyStringForQueryL
       
   180 // aDestStr will have the length as the number of items in aSrcQuery.
       
   181 // ----------------------------------------------------------------------------
       
   182 void CPcsKeyMap::GetMixedKeyStringForQueryL(CPsQuery& aSrcQuery, TDes& aDestStr)
       
   183 {
       
   184     PRINT ( _L("Enter CPcsKeyMap::GetMixedKeyStringForQueryL") ); 
       
   185 
       
   186     GetMixedKeyStringForDataL( aSrcQuery, aSrcQuery.QueryAsStringLC(), aDestStr );
       
   187     CleanupStack::PopAndDestroy(); //result of QueryAsStringLC
       
   188 
       
   189     PRINT ( _L("End CPcsKeyMap::GetMixedKeyStringForQueryL") );
       
   190 }
       
   191 
       
   192 // ----------------------------------------------------------------------------
       
   193 // CPcsKeyMap::GetMixedKeyStringForDataL
       
   194 // aDestStr will have the same length as aSrcData. aSrcQuery can be shorter.
       
   195 // ----------------------------------------------------------------------------
       
   196 void CPcsKeyMap::GetMixedKeyStringForDataL(
       
   197         CPsQuery& aSrcQuery, const TDesC& aSrcData, TDes& aDestStr)
       
   198 {
       
   199     PRINT ( _L("Enter CPcsKeyMap::GetMixedKeyStringForDataL") );
       
   200 
       
   201     for ( TInt i = 0; i < aSrcData.Length(); ++i )
       
   202         {
       
   203         TChar character( aSrcData[i] );
       
   204         character.LowerCase();
       
   205         if ( i < aSrcQuery.Count() )
       
   206             {
       
   207             CPsQueryItem& currentItem = aSrcQuery.GetItemAtL(i);
       
   208             switch ( currentItem.Mode() )
       
   209                 {
       
   210                 case EItut:
       
   211                     {
       
   212                     TPtiKey key = KeyForCharacterMultiMatch(aSrcData[i]);
       
   213                     // If a character is not mapped to numeric key append the character
       
   214                     if ( EPtiKeyNone == key )
       
   215                         {
       
   216                         PRINT3 ( _L("CPcsKeyMap::GetMixedKeyStringForDataL: Char at index %d not mapped to a key, appending char '%c' (#%d)"),
       
   217                                  i, (TUint) character, (TUint) character );
       
   218 
       
   219                         aDestStr.Append( character );
       
   220                         }
       
   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                 }
       
   235             }
       
   236         else
       
   237             {            
       
   238             PRINT2 ( _L("CPcsKeyMap::GetMixedKeyStringForDataL: Char '%c' (#%d) is taken exact (over query length)"),
       
   239                     (TUint) character, (TUint) character );
       
   240 
       
   241             aDestStr.Append( character );
       
   242             }
       
   243         }
       
   244 
       
   245     PRINT1 ( _L("CPcsKeyMap::GetMixedKeyStringForDataL: Return string: \"%S\""),
       
   246              &aDestStr );
       
   247 
       
   248     PRINT ( _L("End CPcsKeyMap::GetMixedKeyStringForDataL") );
       
   249 }
       
   250 
       
   251 // ----------------------------------------------------------------------------
       
   252 // CPcsKeyMap::CharacterForKeyMappingExists
       
   253 // Returns true if the character is mapped to the key
       
   254 // ----------------------------------------------------------------------------
       
   255 TBool CPcsKeyMap::CharacterForKeyMappingExists(TKeyMappingData& aKeyMap, const TUint aIntChar)
       
   256     {
       
   257     TBool found = EFalse;
       
   258     
       
   259     for (TInt j = TKeyMappingData::EKeyMapUILangArr; j <= TKeyMappingData::EKeyMapOthersLangArr; j++)
       
   260         {
       
   261         if ( KErrNotFound != aKeyMap.iKeyMapCharArr[j].Find(aIntChar) )
       
   262             {
       
   263             found = ETrue;
       
   264             break;
       
   265             }
       
   266         
       
   267         }
       
   268     
       
   269     return found;
       
   270     }
       
   271 
       
   272 #ifdef _DEBUG
       
   273 // ----------------------------------------------------------------------------
       
   274 // CPcsKeyMap::CheckPotentialErrorConditions
       
   275 //
       
   276 // ----------------------------------------------------------------------------
       
   277 void CPcsKeyMap::CheckPotentialErrorConditions(RArray<TInt>& aPoolIndexArr, const TChar& aChar)
       
   278     {
       
   279     PRINT ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: ===================================================") );
       
   280     PRINT ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Checking potential error conditions") );
       
   281     PRINT ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: ---------------------------------------------------") );
       
   282 
       
   283     _LIT(KTextCharArr0, "is single char");
       
   284     _LIT(KTextCharArr1, "has \"UI\" priority");
       
   285     _LIT(KTextCharArr2, "has \"English\" priority");
       
   286     _LIT(KTextCharArr3, "has \"Others\" priority");
       
   287     const TPtrC charArrStr[] =
       
   288         { KTextCharArr0(), KTextCharArr1(), KTextCharArr2(), KTextCharArr3() };
       
   289     
       
   290     TFixedArray<TUint, TKeyMappingData::EKeyMapNumberArr> countArr;
       
   291 
       
   292     for ( TInt j = TKeyMappingData::EKeyMapSingleCharArr; j <= TKeyMappingData::EKeyMapOthersLangArr; j++ )
       
   293         {
       
   294         countArr[j] = 0;
       
   295         for ( TInt i = 0; i < aPoolIndexArr.Count(); i++ )
       
   296             {
       
   297             if ( KErrNotFound != iKeyMapPtrArr[aPoolIndexArr[i]]->iKeyMapCharArr[j].Find((TUint) aChar) )
       
   298                 {
       
   299                 PRINT5 ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Char '%c' (#%d) %S for pool %d with key '%c'"),
       
   300                         (TUint) aChar, (TUint) aChar, &charArrStr[j], aPoolIndexArr[i], iKeysArr[aPoolIndexArr[i]] );
       
   301                 countArr[j]++;
       
   302                 }
       
   303             }
       
   304         }
       
   305 
       
   306     PRINT ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: ===================================================") );
       
   307     
       
   308 #ifdef __WINS__
       
   309     // Check in debug mode if we have wrong situations
       
   310     __ASSERT_DEBUG( (countArr[TKeyMappingData::EKeyMapSingleCharArr]  > 1), Panic(EPanicPreCond_MultipleSingleCharMatching) );
       
   311     __ASSERT_DEBUG( (countArr[TKeyMappingData::EKeyMapUILangArr]      > 1), Panic(EPanicPreCond_MultipleUIPriorityMatching) );
       
   312     __ASSERT_DEBUG( (countArr[TKeyMappingData::EKeyMapEnglishLangArr] > 1), Panic(EPanicPreCond_MultipleEnglishPriorityMatching) );
       
   313     __ASSERT_DEBUG( (countArr[TKeyMappingData::EKeyMapOthersLangArr]  > 1), Panic(EPanicPreCond_MultipleOthersPriorityMatching) );
       
   314 #endif // __WINS__
       
   315     }
       
   316 #endif // _DEBUG        
       
   317 
       
   318 // ----------------------------------------------------------------------------
       
   319 // CPcsKeyMap::KeyForCharacterMultiMatch
       
   320 // Considers possible that the same character can be in more pools.
       
   321 // This case was verified at least in the following verified cases:
       
   322 // - For some language version (i.e. Scandinavian with keys 'ä', 'å', 'ö'.
       
   323 // - For some special characters in ITU-T 12 keys keyboards.
       
   324 //   Example: '$' is under key '1' and '7', '£' is under key '1' and '5'.
       
   325 // In case the character is in more pools the selection strategy is the following:
       
   326 //   - 1st choice: if the keyboard is EPtiKeyboard12Key exclude the pool with '1'.
       
   327 //   - 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.
       
   329 //   - 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.
       
   331 // ----------------------------------------------------------------------------
       
   332 TPtiKey CPcsKeyMap::KeyForCharacterMultiMatch(const TChar& aChar)
       
   333     {
       
   334     // Set an array of pool index matches (more matches are possible)
       
   335     RArray<TInt> poolIndexArr;
       
   336     for ( TInt i = 0; i < PoolCount(); i++ )
       
   337         {
       
   338         if ( CharacterForKeyMappingExists(*iKeyMapPtrArr[i], (TUint) aChar) )
       
   339             {
       
   340             poolIndexArr.Append(i);
       
   341 
       
   342             PRINT4 ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Char '%c' (#%d) found in pool %d with key '%c'"),
       
   343                     (TUint) aChar, (TUint) aChar, i, iKeysArr[i] );
       
   344             }
       
   345         }
       
   346 
       
   347     /* 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
       
   349      * a serie of conditions.
       
   350      */
       
   351     TInt poolIndex = KErrNotFound;
       
   352 
       
   353     // Character not found in any pool
       
   354     if ( poolIndexArr.Count() == 0 )
       
   355         {
       
   356         PRINT2 ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Char '%c' (#%d) NOT found in all pools"),
       
   357                  (TUint) aChar, (TUint) aChar );
       
   358         }
       
   359 
       
   360     // Character found in one pool (normal case)
       
   361     else if ( poolIndexArr.Count() == 1 )
       
   362         {
       
   363         poolIndex = poolIndexArr[0];
       
   364 
       
   365         PRINT2 ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Chosen (for unique match) pool %d with key '%c'"),
       
   366                 poolIndex, iKeysArr[poolIndex] );
       
   367         }
       
   368 
       
   369     /* Character found in more pools, this can happen in some known conditions:
       
   370      * - 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.
       
   372      * - For different languages in N97 '/' is in different keys.
       
   373      */
       
   374     else // ( poolIndexArr.Count() > 1 )
       
   375         {
       
   376 
       
   377         /* If keybord is ITUT we exclude the key '1' from the posibility of being choosen,
       
   378          * infact some characters can be typed by key '1' and another key.
       
   379          * For example:
       
   380          *     '$' is under key '1' and '7',
       
   381          *     '£' is under key '1' and '5'.
       
   382          *
       
   383          * This is needed when the client passes updated chars to the engine.
       
   384          * i.e.: Existing contact are "!Mat" and "$Nathan",
       
   385          *       User types '7' and client passes '7' or 'p' matching only contact "$Nathan",
       
   386          *       In next query user types '2' and client passes '$2' or '$a' matching "!Mat" and "$Nathan".
       
   387          *       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"),
       
   389          * this piece of code shall be removed.
       
   390          * With "client" it is referred to MCL contacts client.
       
   391          */
       
   392         if (EPtiKeyboard12Key == iKeyboardType)
       
   393             {
       
   394             for ( TInt i = 0; i < poolIndexArr.Count() ; i++ )
       
   395                 {
       
   396                 if ( EPtiKey1 == iKeysArr[poolIndexArr[i]] )
       
   397                     {
       
   398                     poolIndexArr.Remove(i);
       
   399     
       
   400                     PRINT ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Key '1' excluded (for multi match - EPtiKeyboard12Key)") );
       
   401                     break;
       
   402                     }
       
   403                 }
       
   404             if ( poolIndexArr.Count() == 1 )
       
   405                 {
       
   406                 poolIndex = poolIndexArr[0];
       
   407 
       
   408                 PRINT2 ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Chosen (for unique match after removing key '1') pool %d with key '%c'"),
       
   409                         poolIndex, iKeysArr[poolIndex] );
       
   410                 }
       
   411             }
       
   412 
       
   413 #ifdef _DEBUG
       
   414         CheckPotentialErrorConditions(poolIndexArr, aChar);
       
   415 #endif // _DEBUG        
       
   416 
       
   417         // 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++ )
       
   419             {
       
   420             if ( KErrNotFound == poolIndex )
       
   421                 {
       
   422                 TInt positionLeftMostOnKeys = KErrNotFound; 
       
   423 
       
   424                 for ( TInt i = 0; i < poolIndexArr.Count(); i++ )
       
   425                     {
       
   426                     TInt position = iKeyMapPtrArr[poolIndexArr[i]]->iKeyMapCharArr[j].Find((TUint) aChar);
       
   427                     if ( KErrNotFound != position )
       
   428                         {
       
   429                         // 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
       
   431                         // the case for instance in some Scandinavian variants).
       
   432                         // With this guess there is more possibility that we choose the key where the
       
   433                         // char is physically printed on the keyboard key.
       
   434                         // In order for this guessing strategy to work, chars for TPtiTextCase EPtiCaseUpper
       
   435                         // have to be added to the char arrays before any other TPtiTextCase.
       
   436                         if ( TKeyMappingData::EKeyMapUILangArr == j )
       
   437                             {
       
   438                             if ( ( KErrNotFound == positionLeftMostOnKeys ) || ( position < positionLeftMostOnKeys ) )
       
   439                                 {
       
   440                                 poolIndex = poolIndexArr[i];
       
   441                                 positionLeftMostOnKeys = position;
       
   442                                 }
       
   443 
       
   444                             }
       
   445                         // Get the 1st key that has the char mapped to it
       
   446                         else
       
   447                             {
       
   448                             poolIndex = poolIndexArr[i];
       
   449                     
       
   450                             PRINT3 ( _L("CPcsKeyMap::KeyForCharacterMultiMatch: Chosen (for multi match - char arr: %d) pool %d with key '%c'"),
       
   451                                      j, poolIndex, iKeysArr[poolIndex] );
       
   452                         
       
   453                             break;
       
   454                             }
       
   455                         }
       
   456                     }
       
   457                 }
       
   458             }
       
   459                     
       
   460         } // else -> ( poolIndexArr.Count() > 1 )
       
   461 
       
   462     // Set the key value from the pool index
       
   463     TPtiKey key = EPtiKeyNone;
       
   464     if ( KErrNotFound != poolIndex )
       
   465         {
       
   466         key = iKeysArr[poolIndex];
       
   467         }
       
   468     
       
   469     poolIndexArr.Close();
       
   470     return key;
       
   471     }
       
   472 
       
   473 // ----------------------------------------------------------------------------
       
   474 // CPcsKeyMap::PoolIdForKey
       
   475 //
       
   476 // ----------------------------------------------------------------------------
       
   477 TInt CPcsKeyMap::PoolIdForKey(const TPtiKey aKey)
       
   478     {
       
   479     TInt poolId = iKeysArr.Find(aKey);
       
   480 
       
   481     // IF the key is not found, then it should go to the special pool,
       
   482     // which is the last pool of iKeyMapPtrArr
       
   483     if (KErrNotFound == poolId)
       
   484         {
       
   485         poolId = PoolCount() - 1;
       
   486         }
       
   487 
       
   488     return poolId;
       
   489     }
       
   490 
       
   491 // ----------------------------------------------------------------------------
       
   492 // CPcsKeyMap::PoolIdForCharacter
       
   493 //
       
   494 // ----------------------------------------------------------------------------
       
   495 TInt CPcsKeyMap::PoolIdForCharacter(const TChar& aChar)
       
   496     {
       
   497     TPtiKey key = KeyForCharacterMultiMatch(aChar);
       
   498 
       
   499     TInt poolId = PoolIdForKey(key);
       
   500 
       
   501     return poolId;
       
   502     }
       
   503 
       
   504 // ----------------------------------------------------------------------------
       
   505 // CPcsKeyMap::PoolCount
       
   506 //
       
   507 // ----------------------------------------------------------------------------
       
   508 TInt CPcsKeyMap::PoolCount()
       
   509     {
       
   510     return iKeyMapPtrArr.Count();
       
   511     }
       
   512 
       
   513 // ----------------------------------------------------------------------------
       
   514 // CPcsKeyMap::SetSpaceAndZeroOnSameKey
       
   515 // 
       
   516 // ----------------------------------------------------------------------------
       
   517 void CPcsKeyMap::SetSpaceAndZeroOnSameKey()
       
   518     {
       
   519     const TInt KSpace = 32; // ASCII for " "
       
   520     const TInt KZero  = 48; // ASCII for "0"
       
   521 
       
   522     TChar charSpace(KSpace);
       
   523     TChar charZero(KZero);
       
   524 
       
   525     TPtiKey keySpace = KeyForCharacterMultiMatch(charSpace);
       
   526     TPtiKey keyZero = KeyForCharacterMultiMatch(charZero);
       
   527 
       
   528     iSpaceAndZeroOnSameKey = (keySpace == keyZero);
       
   529     }
       
   530 
       
   531 // ----------------------------------------------------------------------------
       
   532 // CPcsKeyMap::GetSpaceAndZeroOnSameKey
       
   533 // 
       
   534 // ----------------------------------------------------------------------------
       
   535 TBool CPcsKeyMap::GetSpaceAndZeroOnSameKey()
       
   536     {
       
   537     return iSpaceAndZeroOnSameKey;
       
   538     }
       
   539 
       
   540 // ----------------------------------------------------------------------------
       
   541 // CPcsKeyMap::GetKeyboardKeyMapping
       
   542 // Helper function to get Key Mappings depending on keyboard type
       
   543 // ----------------------------------------------------------------------------
       
   544 MPtiKeyMappings* CPcsKeyMap::GetKeyboardKeyMapping(CPtiCoreLanguage& aCurrLanguage)
       
   545     {
       
   546     MPtiKeyMappings* ptiKeyMappings;
       
   547 
       
   548     switch ( iKeyboardType )
       
   549         {
       
   550         case EPtiKeyboardQwerty4x12:
       
   551         case EPtiKeyboardQwerty4x10:
       
   552         case EPtiKeyboardQwerty3x11:
       
   553         case EPtiKeyboardCustomQwerty:
       
   554             ptiKeyMappings = aCurrLanguage.GetQwertyKeymappings();
       
   555             break;
       
   556 
       
   557         case EPtiKeyboard12Key:
       
   558             ptiKeyMappings = aCurrLanguage.GetKeymappings();
       
   559             break;
       
   560 
       
   561         case EPtiKeyboardHalfQwerty:
       
   562             ptiKeyMappings = aCurrLanguage.GetHalfQwertyKeymappings();
       
   563             break;
       
   564 
       
   565         default:
       
   566             ptiKeyMappings = aCurrLanguage.GetKeymappings();
       
   567             break;
       
   568         }
       
   569 
       
   570     return ptiKeyMappings;
       
   571     }
       
   572 
       
   573 // ----------------------------------------------------------------------------
       
   574 // CPcsKeyMap::GetKeyMapData
       
   575 //
       
   576 // ----------------------------------------------------------------------------
       
   577 CPtiKeyMapData* CPcsKeyMap::GetKeyMapData(CPtiCoreLanguage& aCurrLanguage)
       
   578     {
       
   579     MPtiKeyMappings* ptiKeyMappings = GetKeyboardKeyMapping( aCurrLanguage );
       
   580 
       
   581     CPtiKeyMapData* keyMapData;
       
   582 
       
   583     switch ( iKeyboardType )
       
   584         {
       
   585         case EPtiKeyboardQwerty4x12:
       
   586         case EPtiKeyboardQwerty4x10:
       
   587         case EPtiKeyboardQwerty3x11:
       
   588         case EPtiKeyboardCustomQwerty:
       
   589             keyMapData = static_cast<CPtiQwertyKeyMappings*>(ptiKeyMappings)->KeyMapData();
       
   590             break;
       
   591 
       
   592         case EPtiKeyboard12Key:
       
   593             keyMapData = static_cast<CPtiKeyMappings*>(ptiKeyMappings)->KeyMapData();
       
   594             break;
       
   595 
       
   596         case EPtiKeyboardHalfQwerty:
       
   597             keyMapData = static_cast<CPtiHalfQwertyKeyMappings*>(ptiKeyMappings)->KeyMapData();
       
   598             break;
       
   599 
       
   600         default:
       
   601             keyMapData = static_cast<CPtiKeyMappings*>(ptiKeyMappings)->KeyMapData();
       
   602             break;
       
   603         }
       
   604 
       
   605     return keyMapData;
       
   606     }
       
   607 
       
   608 // ----------------------------------------------------------------------------
       
   609 // CPcsKeyMap::AppendEntryWithFakeKeyToKeyList
       
   610 // Add pool with unused id for for key
       
   611 // ----------------------------------------------------------------------------
       
   612 void CPcsKeyMap::AppendEntryWithFakeKeyToKeyList()
       
   613     {
       
   614     TUint keyUInt = (TUint) EPtiKeyNone + 1;
       
   615 
       
   616     while ( KErrNotFound != iKeysArr.Find( (TPtiKey) keyUInt) )
       
   617         {
       
   618         keyUInt++;
       
   619         }
       
   620 
       
   621     TPtiKey key = (TPtiKey) keyUInt;
       
   622     iKeysArr.Append( key );
       
   623 
       
   624     // This should always be the last one in the array
       
   625     PRINT2 ( _L("CPcsKeyMap::AppendEntryWithFakeKeyToKeyList: Added additional last pool %d with key id #%d"),
       
   626              iKeysArr.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     }
       
   652 
       
   653 // ----------------------------------------------------------------------------
       
   654 // CPcsKeyMap::CreateKeyMapFromKeyBindingTable
       
   655 //
       
   656 // ----------------------------------------------------------------------------
       
   657 void CPcsKeyMap::CreateKeyListFromKeyBindingTable( CPtiEngine* aPtiEngine )
       
   658     {
       
   659     PRINT ( _L("Enter CPcsKeyMap::CreateKeyListFromKeyBindingTable") );
       
   660 
       
   661     // Get the user language
       
   662     TLanguage keyMapLanguage = iUILanguage;
       
   663     PRINT1 ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: Current User Language is %d"),
       
   664             keyMapLanguage  );
       
   665 
       
   666     // If the user language is not supported, then we use ELangEnglish as default
       
   667     if (!IsLanguageSupported((TInt) keyMapLanguage))
       
   668         {
       
   669         PRINT2 ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: Language %d is not supported, defaulting to %d"),
       
   670                 keyMapLanguage, ELangEnglish );
       
   671 
       
   672         keyMapLanguage = ELangEnglish;
       
   673         }
       
   674 
       
   675     CPtiCoreLanguage* currLanguage = static_cast<CPtiCoreLanguage*>(aPtiEngine->GetLanguage( keyMapLanguage ));
       
   676 
       
   677     // If we fail to get the language, we try again trying with ELangEnglish
       
   678     if ( (!currLanguage) && (ELangEnglish != keyMapLanguage) )
       
   679         {
       
   680         PRINT1 ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: Failed to get Current Language, trying with %d"),
       
   681                  ELangEnglish );
       
   682 
       
   683         currLanguage = static_cast<CPtiCoreLanguage*>(aPtiEngine->GetLanguage( ELangEnglish ));
       
   684         }
       
   685 
       
   686     if (currLanguage)
       
   687         {
       
   688         TInt numItems = 0;
       
   689         const TPtiKeyBinding* table = GetKeyMapData(*currLanguage)->KeyBindingTable(iKeyboardType, numItems);
       
   690         
       
   691         PRINT1 ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: Num of Items in KeyBindingTable is %d"), numItems );
       
   692 
       
   693         // Get from the key table the keys for constructing the pools
       
   694         if (table)
       
   695             {
       
   696             for (TInt i = 0; i < numItems; i++)
       
   697                 {
       
   698                 TPtiKey key = (TPtiKey) table[i].iScanCode;
       
   699                 // Get all keys with same EPtiCaseLower or EPtiCaseUpper case
       
   700                 // Only for one of the casing to avoid repetitions
       
   701                 if ( (EPtiKeyNone != key) && (EPtiCaseLower == table[i].iCase) )
       
   702                     {
       
   703                     PRINT3 ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: Adding pool %d with key '%c' (%d)"),
       
   704                             iKeysArr.Count(), key, key );
       
   705                     iKeysArr.Append( key );
       
   706                     }
       
   707                 }
       
   708             }
       
   709         else
       
   710             {
       
   711             PRINT ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: ##### Failed to create Key List (KeyBindingTable) #####") );
       
   712             }
       
   713         }
       
   714     else
       
   715         {
       
   716         PRINT ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: ##### Failed to create Key List (Language) #####") );
       
   717         }
       
   718 
       
   719     AppendEntryWithFakeKeyToKeyList();
       
   720 
       
   721     PRINT ( _L("End CPcsKeyMap::CreateKeyListFromKeyBindingTable") );
       
   722 }
       
   723 
       
   724 // ----------------------------------------------------------------------------
       
   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
       
   759 // Returns ETrue if this language is supported
       
   760 // ----------------------------------------------------------------------------
       
   761 TBool CPcsKeyMap::IsLanguageSupported(TInt aLang)
       
   762     {
       
   763     return (KErrNotFound == iLanguageNotSupported.Find((TLanguage) aLang));
       
   764     }
       
   765 
       
   766 // ----------------------------------------------------------------------------
       
   767 // CPcsKeyMap::CreateKeyMappingL
       
   768 //
       
   769 // ----------------------------------------------------------------------------
       
   770 void CPcsKeyMap::CreateKeyMappingL()
       
   771     {
       
   772     PRINT ( _L("Enter CPcsKeyMap::CreateKeyMappingL") );
       
   773 
       
   774     // Instantiate the engine
       
   775     CPtiEngine* ptiEngine = CPtiEngine::NewL(ETrue);
       
   776     CleanupStack::PushL( ptiEngine );
       
   777 
       
   778     ptiEngine->SetKeyboardType( iKeyboardType );
       
   779 
       
   780     CreateKeyListL( ptiEngine );
       
   781 
       
   782     // Now add the keymap arrays to hold the keymap data
       
   783     for (TInt i = 0; i < iKeysArr.Count(); i++)
       
   784     {
       
   785         TKeyMappingData *keyData = new(ELeave) TKeyMappingData;
       
   786         iKeyMapPtrArr.Append(keyData);
       
   787     }
       
   788 
       
   789     // Get the available Languages on the phone
       
   790     RArray<TInt> LanguagesOnThisPhone;
       
   791     ptiEngine->GetAvailableLanguagesL(LanguagesOnThisPhone);
       
   792     PRINT2 ( _L("CPcsKeyMap::CreateKeyMappingL: Languages on this phone %d, maximum is set to %d"),
       
   793              LanguagesOnThisPhone.Count(), KMaxNbrOfLangKeymapping );
       
   794     
       
   795     // Remove the non-supported languages
       
   796     for (TInt i = 0; i < LanguagesOnThisPhone.Count(); /* do not increment i */)
       
   797         {
       
   798         if ( (IsLanguageSupported(LanguagesOnThisPhone[i]))
       
   799 #ifdef __WINS__
       
   800              && (ELangEnglish == LanguagesOnThisPhone[i]) // Only English for emulator 
       
   801 #endif // __WINS__
       
   802            )
       
   803             {
       
   804             i++;
       
   805             }
       
   806         else
       
   807             {
       
   808             PRINT1 ( _L("CPcsKeyMap::CreateKeyMappingL: Removing not supported Language %d"),
       
   809                      LanguagesOnThisPhone[i] );
       
   810             LanguagesOnThisPhone.Remove(i);
       
   811             }
       
   812         }
       
   813 
       
   814     // Set current UI language as 1st language and English as 2nd language,
       
   815     // if present in AvailableLanguages
       
   816     TInt langIndex;
       
   817     if ( KErrNotFound != (langIndex = LanguagesOnThisPhone.Find(ELangEnglish)) )
       
   818         {
       
   819         LanguagesOnThisPhone.Remove(langIndex);
       
   820         LanguagesOnThisPhone.Insert(ELangEnglish, 0);
       
   821         }
       
   822     if ( KErrNotFound != (langIndex = LanguagesOnThisPhone.Find(iUILanguage)) )
       
   823         {
       
   824         LanguagesOnThisPhone.Remove(langIndex);
       
   825         LanguagesOnThisPhone.Insert(iUILanguage, 0);
       
   826         }
       
   827 
       
   828     // Set max number of languages for Key Map
       
   829     TInt count = LanguagesOnThisPhone.Count();
       
   830     if (count > KMaxNbrOfLangKeymapping)
       
   831         {
       
   832         PRINT2 ( _L("CPcsKeyMap::CreateKeyMappingL: Supported Languages on this phone %d, limiting to %d"),
       
   833                  count, KMaxNbrOfLangKeymapping );
       
   834         count = KMaxNbrOfLangKeymapping;
       
   835         }
       
   836 
       
   837     // Add Key Map for the languages
       
   838     for (TInt i = 0; i < count; i++)
       
   839         {
       
   840         TLanguage languageToUse = (TLanguage) LanguagesOnThisPhone[i];
       
   841 
       
   842         PRINT1 ( _L("CPcsKeyMap::CreateKeyMappingL: Constructing Key Map for Language %d"), languageToUse );
       
   843         TInt errStatus = ptiEngine->ActivateLanguageL(languageToUse);
       
   844         if (KErrNone == errStatus)
       
   845             {
       
   846             TRAP_IGNORE(AddKeyMappingForActiveLanguageL(ptiEngine, languageToUse));
       
   847             }
       
   848         else
       
   849             {
       
   850             PRINT1 ( _L("CPcsKeyMap::CreateKeyMappingL: ##### Unable to activate Language %d #####"),
       
   851                      languageToUse );
       
   852             }
       
   853 
       
   854         // Close the currently activated language
       
   855         ptiEngine->CloseCurrentLanguageL();
       
   856 
       
   857         PRINT ( _L("CPcsKeyMap::CreateKeyMappingL: ===================================================") );
       
   858         }
       
   859 
       
   860     LanguagesOnThisPhone.Close();
       
   861 
       
   862     CleanupStack::PopAndDestroy( ptiEngine );
       
   863 
       
   864     PRINT ( _L("End CPcsKeyMap::CreateKeyMappingL") );
       
   865     }
       
   866 
       
   867 // ----------------------------------------------------------------------------
       
   868 // CPcsKeyMap::AddKeyMappingForActiveLanguageL
       
   869 //
       
   870 // ----------------------------------------------------------------------------
       
   871 void CPcsKeyMap::AddKeyMappingForActiveLanguageL(CPtiEngine* aPtiEngine, TLanguage aLanguage)
       
   872 {
       
   873     PRINT ( _L("Enter CPcsKeyMap::AddKeyMappingForActiveLanguageL") );
       
   874 
       
   875     // Make a language object based on the language
       
   876     CPtiCoreLanguage* activeLanguage = static_cast<CPtiCoreLanguage*>(aPtiEngine->GetLanguage( aLanguage ));
       
   877 
       
   878     if (activeLanguage)
       
   879         {
       
   880         // Get the keyboard Mappings for the Active Language
       
   881         MPtiKeyMappings* ptiKeyMappings = GetKeyboardKeyMapping( *activeLanguage );
       
   882 
       
   883         for (TInt i = 0; i < PoolCount() - 1; i++)
       
   884             {
       
   885             TPtiKey key = iKeysArr[i];
       
   886 
       
   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 
       
   891             // Get the pointer to the language class (UI, English, Others)
       
   892             RArray<TUint>* keyMapLang;
       
   893             if (aLanguage == iUILanguage)
       
   894                 {
       
   895                 keyMapLang = &(iKeyMapPtrArr[i]->iKeyMapCharArr[TKeyMappingData::EKeyMapUILangArr]);
       
   896                 PRINT1 ( _L("CPcsKeyMap::AddKeyMappingForActiveLanguageL: Language %d is the UI language"), aLanguage );
       
   897                 }
       
   898             else if (aLanguage == ELangEnglish)
       
   899                 {
       
   900                 // If (iUILanguage == ELangEnglish) ok to be in previous if case
       
   901                 keyMapLang = &(iKeyMapPtrArr[i]->iKeyMapCharArr[TKeyMappingData::EKeyMapEnglishLangArr]);
       
   902                 PRINT1 ( _L("CPcsKeyMap::AddKeyMappingForActiveLanguageL: Language %d is English language"), aLanguage );
       
   903                 }
       
   904             else
       
   905                 {
       
   906                 keyMapLang = &(iKeyMapPtrArr[i]->iKeyMapCharArr[TKeyMappingData::EKeyMapOthersLangArr]);
       
   907                 PRINT1 ( _L("CPcsKeyMap::AddKeyMappingForActiveLanguageL: Language %d is in the Other languages"), aLanguage );
       
   908                 }
       
   909             
       
   910             PRINT ( _L("CPcsKeyMap::AddKeyMappingForActiveLanguageL: ---------------------------------------------------") );
       
   911 
       
   912             TBool isSingleCharForKey = ETrue;
       
   913             TUint singleChar = 0;
       
   914 
       
   915             // EPtiCaseUpper must be the 1st TPtiTextCase for iUILanguage
       
   916             AddCharactersToKey( *ptiKeyMappings, key, EPtiCaseUpper, *iKeyMapPtrArr[i], *keyMapLang, isSingleCharForKey, singleChar );
       
   917             AddCharactersToKey( *ptiKeyMappings, key, EPtiCaseLower, *iKeyMapPtrArr[i], *keyMapLang, isSingleCharForKey, singleChar );
       
   918 
       
   919             // 1. No other TPtiTextCase values for ITUT keyboard
       
   920             // 2. No language variants handling for ITUT keyboard
       
   921             if ( EPtiKeyboard12Key != iKeyboardType )
       
   922                 {
       
   923                 AddCharactersToKey( *ptiKeyMappings, key, EPtiCaseFnLower,  *iKeyMapPtrArr[i], *keyMapLang, isSingleCharForKey, singleChar );
       
   924                 AddCharactersToKey( *ptiKeyMappings, key, EPtiCaseFnUpper,  *iKeyMapPtrArr[i], *keyMapLang, isSingleCharForKey, singleChar );
       
   925                 AddCharactersToKey( *ptiKeyMappings, key, EPtiCaseChrLower, *iKeyMapPtrArr[i], *keyMapLang, isSingleCharForKey, singleChar );
       
   926                 AddCharactersToKey( *ptiKeyMappings, key, EPtiCaseChrUpper, *iKeyMapPtrArr[i], *keyMapLang, isSingleCharForKey, singleChar );
       
   927 
       
   928                 // Support for key guessing given the char in some phone language variants
       
   929                 if ( (isSingleCharForKey) && (0 != singleChar) )
       
   930                     {
       
   931                     iKeyMapPtrArr[i]->iKeyMapCharArr[TKeyMappingData::EKeyMapSingleCharArr].Append(singleChar); // singleChar is in LowerCase
       
   932                     iKeyMapPtrArr[i]->iKeyMapCharArr[TKeyMappingData::EKeyMapSingleCharArr].Append(User::UpperCase(singleChar));
       
   933 
       
   934                     PRINT ( _L("CPcsKeyMap::AddKeyMappingForActiveLanguageL: ---------------------------------------------------") );
       
   935                     PRINT5 ( _L("CPcsKeyMap::AddKeyMappingForActiveLanguageL: For Language %d and key '%c' of pool %d single char is '%c' (#%d)"),
       
   936                             aLanguage, (TInt) key, i, singleChar, singleChar );
       
   937                     }
       
   938                 }
       
   939             }
       
   940         PRINT ( _L("CPcsKeyMap::AddKeyMappingForActiveLanguageL: ===================================================") );
       
   941         }
       
   942 
       
   943     PRINT ( _L("End CPcsKeyMap::AddKeyMappingForActiveLanguageL") );
       
   944 }
       
   945 
       
   946 // ----------------------------------------------------------------------------
       
   947 // CPcsKeyMap::GetCharactersForKey
       
   948 //
       
   949 // ----------------------------------------------------------------------------
       
   950 void CPcsKeyMap::GetCharactersForKey(MPtiKeyMappings& aPtiKeyMappings,
       
   951                                      TPtiKey aKey,
       
   952                                      TPtiTextCase aTextCase,
       
   953                                      TDes& aResult)
       
   954     {
       
   955     switch ( iKeyboardType )
       
   956         {
       
   957         case EPtiKeyboardQwerty4x12:
       
   958         case EPtiKeyboardQwerty4x10:
       
   959         case EPtiKeyboardQwerty3x11:
       
   960         case EPtiKeyboardCustomQwerty:
       
   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         }
       
   976     }
       
   977 
       
   978 // ----------------------------------------------------------------------------
       
   979 // CPcsKeyMap::AddDataForKeyL
       
   980 //
       
   981 // ----------------------------------------------------------------------------
       
   982 void CPcsKeyMap::AddCharactersToKey(MPtiKeyMappings& aPtiKeyMappings,
       
   983                                     TPtiKey aKey,
       
   984                                     TPtiTextCase aTextCase,
       
   985                                     TKeyMappingData& aKeyDataList,
       
   986                                     RArray<TUint>& aKeyMapLang,
       
   987                                     TBool& aIsSingleCharForKey,
       
   988                                     TUint& aSingleChar)
       
   989     {
       
   990     PRINT ( _L("Enter CPcsKeyMap::AddCharactersToKey") );
       
   991 
       
   992     TBuf<255> result;
       
   993     GetCharactersForKey(aPtiKeyMappings, aKey, aTextCase, result);
       
   994 
       
   995     PRINT3 ( _L("CPcsKeyMap::AddCharactersToKey: Get mapping chars for Key '%c' (%d) and TextCase %d"),
       
   996              (TInt) aKey, (TInt) aKey, aTextCase );
       
   997     PRINT1 ( _L("CPcsKeyMap::AddCharactersToKey: Got chars: \"%S\""), &result );
       
   998 
       
   999     for ( TInt i = 0; i < result.Length(); i++ )
       
  1000         {
       
  1001         if ( !CharacterForKeyMappingExists(aKeyDataList, (TUint) result[i]) )
       
  1002             {
       
  1003             PRINT1 ( _L("CPcsKeyMap::AddCharactersToKey: ----- Appending char to list: '%c'"), result[i] );
       
  1004             aKeyMapLang.Append(result[i]);
       
  1005             }
       
  1006         else
       
  1007             {
       
  1008             PRINT1 ( _L("CPcsKeyMap::AddCharactersToKey: ***** NOT Appending char to list: '%c'"), result[i] );
       
  1009             }
       
  1010 
       
  1011         // No language variants handling for ITUT keyboard
       
  1012         if ( EPtiKeyboard12Key != iKeyboardType )
       
  1013             {
       
  1014             // Support for key guessing given the char in some phone language variants
       
  1015             if ( aIsSingleCharForKey )
       
  1016                 {
       
  1017                 if ( 0 == aSingleChar )
       
  1018                     {
       
  1019                     aSingleChar = User::LowerCase(result[i]);
       
  1020                     }
       
  1021                 else
       
  1022                     {
       
  1023                     TInt newChar = User::LowerCase(result[i]);
       
  1024                     if (newChar != aSingleChar)
       
  1025                         {
       
  1026                         aSingleChar = 0;
       
  1027                         aIsSingleCharForKey = EFalse;
       
  1028                         }
       
  1029                     }
       
  1030                 }
       
  1031             }
       
  1032         }
       
  1033 
       
  1034     PRINT ( _L("CPcsKeyMap::AddCharactersToKey: ---------------------------------------------------") );
       
  1035 
       
  1036     PRINT ( _L("End CPcsKeyMap::AddCharactersToKey") );
       
  1037     }
       
  1038 
       
  1039 // End of file