predictivesearch/PcsAlgorithm/Algorithm1/inc/CPcsKeyMap.h
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
equal deleted inserted replaced
62:5b6f26637ad3 63:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2006-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:  Class to hold the character to key mappings
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef __CPCS_KEY_MAP_H__
       
    19 #define __CPCS_KEY_MAP_H__
       
    20 
       
    21 // INCLUDES
       
    22 #include <e32base.h>
       
    23 #include <PtiDefs.h>
       
    24 #include <AvkonInternalCRKeys.h>
       
    25 #include <e32property.h>
       
    26 #include <CPcsDefs.h>
       
    27 
       
    28 class CPsQuery;
       
    29 class CPtiEngine;
       
    30 class CPtiCoreLanguage;
       
    31 
       
    32 
       
    33 class TKeyMappingData
       
    34     {
       
    35     public:
       
    36         // Keep the following order as it follows the search priority
       
    37         enum TCharArraySelector
       
    38             {
       
    39             EKeyMapSingleCharArr = 0,
       
    40             EKeyMapUILangArr,
       
    41             EKeyMapEnglishLangArr,
       
    42             EKeyMapOthersLangArr,
       
    43             EKeyMapNumberArr
       
    44             };
       
    45 
       
    46         TFixedArray<RArray<TUint>, TKeyMappingData::EKeyMapNumberArr> iKeyMapCharArr; 
       
    47         
       
    48         /* Help for deciding the key from the char in devices language variants
       
    49          *   iKeyMapCharArr[EKeyMapSingleCharArr]:  All the single chars for the languages
       
    50          * 
       
    51          * Sharing the chars in the following 3 classes helps for guessing the key from the key
       
    52          * in a more appropriate way (giving language preferences) when the same character can be mapped
       
    53          * to more keys considering all the supported languages together
       
    54          *   iKeyMapCharArr[EKeyMapUILangArr]:      All chars mapped to the key for UI Language
       
    55          *   iKeyMapCharArr[EKeyMapEnglishLangArr]: All remaining chars mapped to the key for English Language
       
    56          *   iKeyMapCharArr[EKeyMapOthersLangArr]:  All remaining chars mapped to the key for the other languages
       
    57          */
       
    58     };
       
    59 
       
    60 // CLASS DECLARATION
       
    61 class CPcsKeyMap : public CBase
       
    62 {
       
    63 
       
    64     public:
       
    65 
       
    66         /**
       
    67          * Two phase construction
       
    68          */
       
    69         static CPcsKeyMap* NewL();
       
    70 
       
    71         /**
       
    72          * Destructor
       
    73          */
       
    74         virtual ~CPcsKeyMap();
       
    75 
       
    76         TBool IsItutPredictiveAvailable() const;
       
    77         TBool IsQwertyPredictiveAvailable() const;
       
    78 
       
    79         static TBool IsModePredictive( TKeyboardModes aKbMode );
       
    80 
       
    81         /**
       
    82          * Convert functions to get the key string from query and/or chars string
       
    83          */
       
    84         void GetMixedKeyStringForQueryL(CPsQuery& aSrcQuery, TDes& aDestStr) const;
       
    85         void GetMixedKeyStringForDataL(CPsQuery& aSrcQuery, const TDesC& aSrcData, TDes& aDestStr) const;
       
    86 
       
    87         /**
       
    88          * Returns true if the character is mapped to the key
       
    89          */
       
    90         TBool CharacterForKeyMappingExists(TKeyMappingData& aKeyMap, TUint aIntChar) const;
       
    91 
       
    92         /**
       
    93          * Returns the numeric key id corresponding to a specific character
       
    94          * Considers possible multiple matches for some phone variants
       
    95          */
       
    96         TPtiKey KeyForCharacterMultiMatch( const TChar& aChar, TKeyboardModes aKbMode ) const;
       
    97 
       
    98         /**
       
    99          * Returns true if the characters "0" and " " are on the same key
       
   100          */
       
   101         TBool GetSpaceAndZeroOnSameKey( TKeyboardModes aKbMode );
       
   102 
       
   103         /**
       
   104          * Returns true if this language is supported
       
   105          */
       
   106         TBool IsLanguageSupported(TInt aLang);
       
   107 
       
   108         /**
       
   109          * Returns the pool Id for a character
       
   110          */
       
   111         TInt PoolIdForCharacter(const TChar& aChar, TKeyboardModes aKbMode);
       
   112 
       
   113         /**
       
   114          * Returns total number of pools
       
   115          */
       
   116         TInt PoolCount();
       
   117 
       
   118     private:
       
   119 
       
   120         /**
       
   121          * Constructor
       
   122          */
       
   123         CPcsKeyMap();
       
   124 
       
   125         /**
       
   126          * Second phase constructor
       
   127          */
       
   128         void ConstructL();
       
   129 
       
   130         /**
       
   131          * Get physical Itu-T and QWERTY keyboard types of the device
       
   132          */
       
   133         void GetPhysicalKeyboardTypesL( TPtiKeyboardType& aItutKbType,
       
   134                                         TPtiKeyboardType& aQwertyKbType );
       
   135 
       
   136         /**
       
   137          * Returns the pool Id for a key
       
   138          */
       
   139         TInt PoolIdForKey(const TPtiKey aKey, TKeyboardModes aKbMode);
       
   140 
       
   141         /**
       
   142          * Helper function to construct Key Mappings
       
   143          */
       
   144         void CreateKeyMappingL( TKeyboardModes aKbMode );
       
   145 
       
   146         /**
       
   147          * Create list of PTI keys for the given keyboard type
       
   148          */
       
   149         void CreateKeyListFromKeyBindingTable( RArray<TPtiKey>& aKeyArray, TPtiKeyboardType aKbType, CPtiEngine* aPtiEngine );
       
   150 
       
   151         /**
       
   152          * Add a non-existing key ID in the end of given array
       
   153          */
       
   154         void AppendEntryWithFakeKeyToKeyList( RArray<TPtiKey>& aKeyArray );
       
   155 
       
   156         /**
       
   157          * Helper functions to populate Keyboard Key Mappings (Characters for
       
   158          * all Keys) for the given Language
       
   159          */
       
   160         void AddKeyMappingForLanguageL( CPtiEngine* aPtiEngine, 
       
   161                                         TLanguage aLanguage,
       
   162                                         TPtiKeyboardType aKbType,
       
   163                                         const RArray<TPtiKey>& aPtiKeys,
       
   164                                         RPointerArray<TKeyMappingData>& aResultMapping );
       
   165         void GetCharactersForKey( CPtiCoreLanguage& aPtiLanguage,
       
   166                                   TPtiKeyboardType aKbType,
       
   167                                   TPtiKey aKey,
       
   168                                   TPtiTextCase aTextCase,
       
   169                                   TDes& aResult );
       
   170         void AddCharactersToKey( CPtiCoreLanguage& aPtiLanguage,
       
   171                                  TPtiKeyboardType aKbType,
       
   172                                  TPtiKey aKey,
       
   173                                  TPtiTextCase aTextCase,
       
   174                                  TKeyMappingData& aKeyDataList,
       
   175                                  RArray<TUint>& aKeyMapLang,
       
   176                                  TBool& aIsSingleCharForKey,
       
   177                                  TUint& aSingleChar );
       
   178 
       
   179         /**
       
   180          * Sets attribute to true if the characters "0" and " " are on the same key
       
   181          */
       
   182         void SetSpaceAndZeroOnSameKey();
       
   183 
       
   184         /**
       
   185          * Gets predictive keyboard mapping data for given match mode.
       
   186          * @param   aKbMode      Matching mode for which data is asked. 
       
   187          * @param   aPtiKeys     On return, will point to the array of PtiKeys for the given mode.
       
   188          * @param   aKeyMappings On return, will point to key mapping array for the given mode.
       
   189          * @param   aKbType      On return, will hold the keyboard type for the given mode.
       
   190          */
       
   191         void GetPredictiveKeyboardData( TKeyboardModes aKbMode, 
       
   192                                         RArray<TPtiKey>*& aPtiKeys, 
       
   193                                         RPointerArray<TKeyMappingData>*& aKeyMappings, 
       
   194                                         TPtiKeyboardType& aKbType );
       
   195         /**
       
   196          * Constant overload of the GetPredictiveKeyboardData function.
       
   197          */
       
   198         void GetPredictiveKeyboardData( TKeyboardModes aKbMode, 
       
   199                                         const RArray<TPtiKey>*& aPtiKeys, 
       
   200                                         const RPointerArray<TKeyMappingData>*& aKeyMappings, 
       
   201                                         TPtiKeyboardType& aKbType ) const;
       
   202 
       
   203         /**
       
   204          * Resolve keyboard mode to "ITU-T predictive" or "QWERTY predictive".
       
   205          */
       
   206         TKeyboardModes ResolveKeyboardMode( TKeyboardModes aKbMode,
       
   207                                             TKeyboardModes aKbModeToResolve ) const;
       
   208 
       
   209 
       
   210 #ifdef _DEBUG
       
   211         /**
       
   212          * Check potential error conditions for KeyForCharacterMultiMatch
       
   213          */
       
   214         void CheckPotentialErrorConditions(const RArray<TInt>& aPoolIndexArr, 
       
   215                                            const TChar& aChar,
       
   216                                            const RArray<TPtiKey>& aPtiKeys,
       
   217                                            const RPointerArray<TKeyMappingData>& aKeyMappings) const;
       
   218 #endif // _DEBUG
       
   219 
       
   220     private:
       
   221 
       
   222         /**
       
   223          * Array to hold the list of languages not supported
       
   224          */
       
   225         RArray<TLanguage> iLanguageNotSupported;
       
   226 
       
   227         /**
       
   228          * UI Language
       
   229          */
       
   230         TLanguage iUILanguage;
       
   231 
       
   232         /**
       
   233          * Type of keyboard used in ITU-T search mode. Typically this is
       
   234          * standard ITU-T 12-key keypad.
       
   235          */
       
   236         TPtiKeyboardType iItutKeyboardType;
       
   237         
       
   238         /**
       
   239          * Type of keyboard used in QWERTY search mode. Typically this is either
       
   240          * 3x11 or 4x10 QWERTY or EPtiKeyboardNone if there's no any kind of
       
   241          * QWERTY available. This may also be half-QWERTY.
       
   242          */
       
   243         TPtiKeyboardType iQwertyKeyboardType;
       
   244 
       
   245         /**
       
   246          * Type of keyboard used in Default Preditive search mode. This will
       
   247          * point to ITU-T or QWERTY keypad.
       
   248          */
       
   249         TKeyboardModes iPredictiveDefaultKeyboardMode;
       
   250 
       
   251         /**
       
   252          * Pti keys of ITU-T mode
       
   253          */
       
   254         RArray<TPtiKey> iItutKeys;
       
   255 
       
   256         /**
       
   257          * Pti keys of QWERTY mode
       
   258          */
       
   259         RArray<TPtiKey> iQwertyKeys;
       
   260 
       
   261         /**
       
   262          * Contains all the keys and the characters mapped to each key in ITU-T mode. Owned.
       
   263          */
       
   264         RPointerArray<TKeyMappingData> iItutKeyMaps;
       
   265 
       
   266         /**
       
   267          * Contains all the keys and the characters mapped to each key in QWERTY mode. Owned.
       
   268          */
       
   269         RPointerArray<TKeyMappingData> iQwertyKeyMaps;
       
   270 
       
   271         /**
       
   272          * True if "0" and " " are on the same key in the ITU-T mode
       
   273          */
       
   274         TBool iSpaceAndZeroOnSameKeyOnItut;
       
   275         
       
   276         /**
       
   277          * True if "0" and " " are on the same key in the QWERTY mode
       
   278          */
       
   279         TBool iSpaceAndZeroOnSameKeyOnQwerty;
       
   280 
       
   281 };
       
   282 
       
   283 #endif // __CPCS_KEY_MAP_H__
       
   284 
       
   285 // End of file