phoneapp/phoneuiutils/src/cphoneqwertyhandler.cpp
branchRCL_3
changeset 25 91c2fb4b78df
parent 17 38529f706030
equal deleted inserted replaced
19:544e34b3255a 25:91c2fb4b78df
    22 #include    "cphoneqwertymodemonitor.h"
    22 #include    "cphoneqwertymodemonitor.h"
    23 #include    <PtiEngine.h>
    23 #include    <PtiEngine.h>
    24 #include    <w32std.h>
    24 #include    <w32std.h>
    25 
    25 
    26 // CONSTANTS
    26 // CONSTANTS
       
    27 static const TUint32 KNumKeyModifiers( EModifierLeftShift | EModifierRightShift | EModifierShift |
       
    28                                        EModifierLeftFunc | EModifierRightFunc | EModifierFunc );
       
    29 
    27 
    30 
    28 // FORWARD DECLARATIONS
    31 // FORWARD DECLARATIONS
    29 
    32 
    30 // ============================ MEMBER FUNCTIONS ===============================
    33 // ============================ MEMBER FUNCTIONS ===============================
    31 
    34 
    58     iInputLanguageId = iLangSettingMonitor->InputLanguage();
    61     iInputLanguageId = iLangSettingMonitor->InputLanguage();
    59     iQwertyMode = iQwertyModeMonitor->QwertyMode();
    62     iQwertyMode = iQwertyModeMonitor->QwertyMode();
    60     
    63     
    61     if ( iQwertyMode )
    64     if ( iQwertyMode )
    62         {
    65         {
    63         LoadNumericKeyBindings( iInputLanguageId, iQwertyModeMonitor->Keyboard() );            
    66         LoadNumericKeyBindings( iInputLanguageId, iQwertyModeMonitor->Keyboard() );
    64         }
    67         }
    65     }
    68     }
    66 
    69 
    67 // -----------------------------------------------------------------------------
    70 // -----------------------------------------------------------------------------
    68 // CPhoneQwertyHandler::NewL
    71 // CPhoneQwertyHandler::NewL
    78     self->ConstructL();
    81     self->ConstructL();
    79     CleanupStack::Pop( self );
    82     CleanupStack::Pop( self );
    80 
    83 
    81     return self;
    84     return self;
    82     }
    85     }
    83     
    86 
    84 // Destructor
    87 // Destructor
    85 EXPORT_C CPhoneQwertyHandler::~CPhoneQwertyHandler()
    88 EXPORT_C CPhoneQwertyHandler::~CPhoneQwertyHandler()
    86     {
    89     {
    87 	iLangSettingMonitor->RemoveObserver( *this );
    90 	iLangSettingMonitor->RemoveObserver( *this );
    88     delete iLangSettingMonitor;
    91     delete iLangSettingMonitor;
    97 // CPhoneQwertyHandler::IsQwertyInput
   100 // CPhoneQwertyHandler::IsQwertyInput
    98 // -----------------------------------------------------------------------------
   101 // -----------------------------------------------------------------------------
    99 //    
   102 //    
   100 EXPORT_C TBool CPhoneQwertyHandler::IsQwertyInput() const
   103 EXPORT_C TBool CPhoneQwertyHandler::IsQwertyInput() const
   101     {
   104     {
   102     return iQwertyMode > 0 ? ETrue : EFalse;    
   105     return iQwertyMode > 0 ? ETrue : EFalse;
   103     }
   106     }
   104 
   107 
   105 // -----------------------------------------------------------------------------
   108 // -----------------------------------------------------------------------------
   106 // CPhoneQwertyHandler::HandleLanguageSettingChange
   109 // CPhoneQwertyHandler::HandleLanguageSettingChange
   107 // -----------------------------------------------------------------------------
   110 // -----------------------------------------------------------------------------
   122 // -----------------------------------------------------------------------------
   125 // -----------------------------------------------------------------------------
   123 //    
   126 //    
   124 void CPhoneQwertyHandler::HandleQwertyModeChange( TInt aMode )
   127 void CPhoneQwertyHandler::HandleQwertyModeChange( TInt aMode )
   125     {
   128     {
   126     iQwertyMode = aMode;
   129     iQwertyMode = aMode;
   127 #ifndef RD_INTELLIGENT_TEXT_INPUT    
   130 #ifndef RD_INTELLIGENT_TEXT_INPUT
   128     if ( iQwertyMode && !iNumericKeys.Count() )
   131     if ( iQwertyMode && !iNumericKeys.Count() )
   129         {
   132         {
   130         LoadNumericKeyBindings( iInputLanguageId, iQwertyModeMonitor->Keyboard() );            
   133         LoadNumericKeyBindings( iInputLanguageId, iQwertyModeMonitor->Keyboard() );
   131         }
   134         }
   132 #endif    
   135 #endif
   133     }
   136     }
   134 
   137 
   135 // -----------------------------------------------------------------------------
   138 // -----------------------------------------------------------------------------
   136 // CPhoneQwertyHandler::HandleKeyboardLayoutChange
   139 // CPhoneQwertyHandler::HandleKeyboardLayoutChange
   137 // This event comes after HandleQwertyModeChange
   140 // This event comes after HandleQwertyModeChange
   138 // -----------------------------------------------------------------------------
   141 // -----------------------------------------------------------------------------
   139 //
   142 //
   140 void CPhoneQwertyHandler::HandleKeyboardLayoutChange()
   143 void CPhoneQwertyHandler::HandleKeyboardLayoutChange()
   141     {
   144     {
   142     
   145     LoadNumericKeyBindings( iInputLanguageId, iQwertyModeMonitor->Keyboard() );
   143     LoadNumericKeyBindings( iInputLanguageId, iQwertyModeMonitor->Keyboard() );            
       
   144    
       
   145     }
   146     }
   146 
   147 
   147 // -----------------------------------------------------------------------------
   148 // -----------------------------------------------------------------------------
   148 // CPhoneQwertyHandler::LoadNumericKeyBindings
   149 // CPhoneQwertyHandler::LoadNumericKeyBindings
   149 // -----------------------------------------------------------------------------
   150 // -----------------------------------------------------------------------------
   159         CPtiEngine* ptiEngine = CPtiEngine::NewL();
   160         CPtiEngine* ptiEngine = CPtiEngine::NewL();
   160         CleanupStack::PushL( ptiEngine );
   161         CleanupStack::PushL( ptiEngine );
   161         
   162         
   162         ptiEngine->GetNumericModeKeysForQwertyL( aLanguage, 
   163         ptiEngine->GetNumericModeKeysForQwertyL( aLanguage, 
   163                                                  iNumericKeys,
   164                                                  iNumericKeys,
   164                                                  keyboard );         
   165                                                  keyboard );
   165         CleanupStack::PopAndDestroy( ptiEngine );                                                 
   166         CleanupStack::PopAndDestroy( ptiEngine );
   166         } ); // TRAP
   167         } ); // TRAP
   167 #else
   168 #else
   168     TRAPD( err, 
   169     TRAPD( err, 
   169         {
   170         {
   170         CPtiEngine* ptiEngine = CPtiEngine::NewL();
   171         CPtiEngine* ptiEngine = CPtiEngine::NewL();
   171         CleanupStack::PushL( ptiEngine );
   172         CleanupStack::PushL( ptiEngine );
   172         ptiEngine->GetNumericModeKeysForQwertyL( aLanguage, 
   173         ptiEngine->GetNumericModeKeysForQwertyL( aLanguage, 
   173                                                  iNumericKeys );         
   174                                                  iNumericKeys );
   174         CleanupStack::PopAndDestroy( ptiEngine );                                                 
   175         CleanupStack::PopAndDestroy( ptiEngine );
   175         } ); // TRAP
   176         } ); // TRAP
   176 #endif    
   177 #endif    
   177         
   178         
   178     if ( err )        
   179     if ( err )
   179         {
   180         {
   180         iNumericKeys.Reset();
   181         iNumericKeys.Reset();
   181         iQwertyMode = 0; // To default mode
   182         iQwertyMode = 0; // To default mode
   182         }
   183         }
   183     else
   184     else
   189             TPtiNumericKeyBinding numKeyBind = iNumericKeys[numericKeysCount];
   190             TPtiNumericKeyBinding numKeyBind = iNumericKeys[numericKeysCount];
   190             
   191             
   191             // This is PTI bug? Should not be in numeric keys list.
   192             // This is PTI bug? Should not be in numeric keys list.
   192             if ( numKeyBind.iKey == EPtiKeyQwertySpace ) 
   193             if ( numKeyBind.iKey == EPtiKeyQwertySpace ) 
   193                  {
   194                  {
   194                  iNumericKeys.Remove( numericKeysCount );                    
   195                  iNumericKeys.Remove( numericKeysCount );
   195                  }
   196                  }
   196             }    
   197             }
   197         }
   198         }
   198     }
   199     }
   199 
   200 
   200 // -----------------------------------------------------------------------------
   201 // -----------------------------------------------------------------------------
   201 // CPhoneQwertyHandler::NumericKeyCode
   202 // CPhoneQwertyHandler::NumericKeyCode
   202 // -----------------------------------------------------------------------------
   203 // -----------------------------------------------------------------------------
   203 //    
   204 //    
   204 EXPORT_C TInt CPhoneQwertyHandler::NumericKeyCode( const TKeyEvent& aKeyEvent )
   205 EXPORT_C TInt CPhoneQwertyHandler::NumericKeyCode( const TKeyEvent& aKeyEvent )
   205     {
   206     {
   206   
   207     TInt keyCode( EKeyNull );
   207     // Check shift state
   208     
   208     TBool shiftActive(EFalse);
   209     // It's possible that there are several numeric mode characters in same
   209     shiftActive = aKeyEvent.iModifiers & EModifierLeftShift ||
   210     // QWERTY key (for example, '2' and 'w' may be on same button) and there must 
   210                   aKeyEvent.iModifiers & EModifierRightShift; //||
   211     // be a way to enter each of these. 
   211     
   212     // Select numeric mode key code for the key event with the following logic:
   212     TInt numericKeysCount = iNumericKeys.Count();
   213     // 1. If key contains exactly one numeric mode character, return that
   213     
   214     //    regardless of the current modifiers.
   214     while ( numericKeysCount-- )
   215     // 2a. If key has two numeric mode characters, then actual numbers are preferred.
   215         {
   216     //     Pressing such key without modifiers will produce the number character.
   216         TPtiNumericKeyBinding numKeyBind = iNumericKeys[numericKeysCount];
   217     // 2b. Pressing key with two numeric mode characters together with any modifier
   217             
   218     //     (Fn, Shift, Chr) will produce the secondary numeric mode character.
   218         TBool shiftRequired = ( numKeyBind.iCase ==EPtiCaseUpper ) ||
   219     // 3. More than two numeric mode characters on one key are not supported.
   219                               ( numKeyBind.iCase ==EPtiCaseChrUpper );
   220     //    Such cases shouldn't ever occur, but if they will, then this algorithm
   220             
   221     //    must be changed.
   221         if ( numKeyBind.iKey == aKeyEvent.iScanCode &&
   222     
   222              (shiftRequired == shiftActive  )   )
   223     // Check modifier state
       
   224     TBool modifierActive = ( aKeyEvent.iModifiers & KNumKeyModifiers );
       
   225     
       
   226     TInt numBindIdx = iNumericKeys.Count();
       
   227     
       
   228     while ( numBindIdx-- )
       
   229         {
       
   230         const TPtiNumericKeyBinding& numKeyBind = iNumericKeys[numBindIdx];
       
   231         
       
   232         if ( numKeyBind.iKey == aKeyEvent.iScanCode )
   223             {
   233             {
   224             return numKeyBind.iChar;
   234             if ( !keyCode )
       
   235                 {
       
   236                 // first match for this key
       
   237                 keyCode = numKeyBind.iChar;
       
   238                 }
       
   239             else
       
   240                 {
       
   241                 // Second numeric mode character for this key. Override
       
   242                 // previous code if it was the number character but some
       
   243                 // modifier is active or it was not number character and no
       
   244                 // modifiers are active.
       
   245                 if ( ( IsNumber(keyCode) && modifierActive ) ||
       
   246                      ( !IsNumber(keyCode) && !modifierActive ) )
       
   247                     {
       
   248                     keyCode = numKeyBind.iChar;
       
   249                     }
       
   250                 }
   225             }
   251             }
   226         }
   252         }
   227         
   253         
   228     return EKeyNull;         
   254     return keyCode;
   229     }           
   255     }
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // CPhoneQwertyHandler::ConvertToNumeric
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 EXPORT_C TBool CPhoneQwertyHandler::ConvertToNumeric( TKeyEvent& aKeyEvent )
       
   262     {
       
   263     TBool ret( EFalse );
       
   264     TInt numericCode = NumericKeyCode( aKeyEvent );
       
   265     if ( numericCode )
       
   266         {
       
   267         aKeyEvent.iCode = numericCode;
       
   268         aKeyEvent.iModifiers &= ~KNumKeyModifiers;
       
   269         ret = ETrue;
       
   270         }
       
   271     return ret;
       
   272     }
   230 
   273 
   231 // -----------------------------------------------------------------------------
   274 // -----------------------------------------------------------------------------
   232 // CPhoneQwertyHandler::AddQwertyModeObserverL
   275 // CPhoneQwertyHandler::AddQwertyModeObserverL
   233 // -----------------------------------------------------------------------------
   276 // -----------------------------------------------------------------------------
   234 //
   277 //
   240     // Observer need to be notified with a current qwerty status so that
   283     // Observer need to be notified with a current qwerty status so that
   241     // status dependent objects would get correct initial value.
   284     // status dependent objects would get correct initial value.
   242     aObserver.HandleQwertyModeChange( iQwertyMode );
   285     aObserver.HandleQwertyModeChange( iQwertyMode );
   243     }
   286     }
   244 
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // CPhoneQwertyHandler::IsNumber
       
   290 // -----------------------------------------------------------------------------
       
   291 //
       
   292 TBool CPhoneQwertyHandler::IsNumber( TText aChar ) const
       
   293     {
       
   294     return TChar( aChar ).IsDigit();
       
   295     }
       
   296 
       
   297 
   245 //  End of File  
   298 //  End of File