idlefw/plugins/wsplugin/src/numerickeyhandler.cpp
changeset 0 79c6a41cd166
child 14 15e4dd19031c
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Numeric key forwarding handler implementation for Active Idle 
       
    15 *                WS Plug-in.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "numerickeyhandler.h"
       
    21 #include "uistate.h"
       
    22 
       
    23 #include <e32property.h>
       
    24 #include <centralrepository.h>
       
    25 #include <w32adll.h>
       
    26 
       
    27 #include <PtiEngine.h>
       
    28 #include <activeidle2domainpskeys.h>
       
    29 #include <AvkonInternalCRKeys.h>
       
    30 #include <AknFepInternalCRKeys.h>
       
    31 
       
    32 #include <aiutility.h>
       
    33 #include <aipspropertyobserver.h>
       
    34 
       
    35 namespace AiWsPlugin {
       
    36 
       
    37 
       
    38 CNumericKeyHandler::CNumericKeyHandler
       
    39         ( TInt aTargetWgId, MAnimGeneralFunctionsWindowExtension* aWindowExt ) :
       
    40     iTargetWgId( aTargetWgId ), 
       
    41     iWindowExt( aWindowExt )
       
    42     {
       
    43     }
       
    44     
       
    45 void CNumericKeyHandler::ConstructL()
       
    46     {
       
    47     // Read capability: ReadUserData.
       
    48     _LIT_SECURITY_POLICY_C1( KReadUserPolicy, ECapabilityReadUserData ); 
       
    49     // Write capability: WriteDeviceData.
       
    50     _LIT_SECURITY_POLICY_C1( KWriteDevicePolicy, ECapabilityWriteDeviceData );
       
    51 
       
    52     RProperty::Define( 
       
    53          	KPSUidAiInformation,
       
    54          	KActiveIdleState,
       
    55          	RProperty::EInt,
       
    56             KReadUserPolicy,
       
    57             KWriteDevicePolicy );
       
    58                     
       
    59 	iQwertyObserver = AiUtility::CreatePSPropertyObserverL(
       
    60 			TCallBack( HandleQwertyModeChanged, this ),
       
    61         	KCRUidAvkon, KAknQwertyInputModeActive );
       
    62 	
       
    63 	iInputLanguageRepository = CRepository::NewL( KCRUidAknFep );
       
    64 	iInputLanguageObserver = CCenRepNotifyHandler::NewL(*this, *iInputLanguageRepository);
       
    65 	iInputLanguageObserver->StartListeningL(); 
       
    66 	
       
    67 	RProperty::Get(KCRUidAvkon, KAknQwertyInputModeActive, iQwertyMode);
       
    68 	iInputLanguageRepository->Get( KAknFepInputTxtLang, iInputLanguage );
       
    69           
       
    70     // Load numeric keys mapping for qwerty 
       
    71     if ( iQwertyMode )
       
    72         {
       
    73         LoadInputLanguageKeyBindings( iInputLanguage );            
       
    74         }
       
    75     }
       
    76 
       
    77 CNumericKeyHandler* CNumericKeyHandler::NewLC
       
    78         ( TInt aTargetWgId, MAnimGeneralFunctionsWindowExtension* aWindowExt )
       
    79     {
       
    80     CNumericKeyHandler* self = new(ELeave) CNumericKeyHandler
       
    81         ( aTargetWgId, aWindowExt );
       
    82     CleanupStack::PushL( self );
       
    83     self->ConstructL();
       
    84     return self;
       
    85     }
       
    86     
       
    87 CNumericKeyHandler::~CNumericKeyHandler()
       
    88     {
       
    89     if( iInputLanguageObserver )
       
    90         {
       
    91         iInputLanguageObserver->StopListening();
       
    92         }
       
    93     delete iInputLanguageObserver;
       
    94     delete iInputLanguageRepository;
       
    95     Release(iQwertyObserver);
       
    96     iNumericKeys.Close();
       
    97     }
       
    98 
       
    99 void CNumericKeyHandler::SetUiStateQuery( MUiState& aUiState )
       
   100     {
       
   101     iUiState = &aUiState;
       
   102     }
       
   103 
       
   104 void CNumericKeyHandler::FocusChanged( TBool /*aState*/ )
       
   105     {
       
   106     }
       
   107     
       
   108 TBool CNumericKeyHandler::OfferRawEvent(const TRawEvent& aRawEvent)
       
   109     {
       
   110     switch( aRawEvent.Type() )
       
   111         {
       
   112         case TRawEvent::EKeyDown:
       
   113             {
       
   114             if ( iUiState->HasFocus() && CheckPostToTarget( aRawEvent ) )
       
   115                 {
       
   116                 TInt forwardKeys = EPSAiForwardNumericKeysToPhone;       
       
   117                 
       
   118                 TInt err = RProperty::Get(
       
   119                         KPSUidAiInformation,
       
   120                         KActiveIdleForwardNumericKeysToPhone,
       
   121                         forwardKeys);
       
   122                 // Key event forwarding disabled => Ignore the keys
       
   123                 if ( err == KErrNone && 
       
   124                         forwardKeys == EPSAiDontForwardNumericKeysToPhone )
       
   125                     {
       
   126                     return EFalse;
       
   127                     }
       
   128     			// Phone app is listening this key and knows that next
       
   129                 // focus event from window server is becuase key events
       
   130                 // are coming to it.                        
       
   131                 RProperty::Set(
       
   132                  	KPSUidAiInformation, 
       
   133                     KActiveIdleState,
       
   134                 	EPSAiNumberEntry );
       
   135 
       
   136                 // Switch focus to Phone app
       
   137                 if( iWindowExt )
       
   138                     {
       
   139                     iWindowExt->SetOrdinalPosition( iTargetWgId, 0, 0 );
       
   140                     }
       
   141                 }
       
   142             break;
       
   143             }
       
   144         }
       
   145     
       
   146     // Never consume the key event as we want target application to process it
       
   147     return EFalse;
       
   148     }
       
   149 
       
   150 /**
       
   151  * Returns true if event should be forwarded to Phone app.
       
   152  */
       
   153 TBool CNumericKeyHandler::CheckPostToTarget(const TRawEvent& aRawEvent ) const
       
   154     {
       
   155     const TInt scanCode = aRawEvent.ScanCode();
       
   156 
       
   157     if ( iQwertyMode ) 
       
   158         {
       
   159         // Don't pass the check if shift is pressed.
       
   160 		const TUint modifiers = iUiState->Modifiers();
       
   161         if(( modifiers & EModifierShift ) == 0 )
       
   162             {
       
   163             TInt numericKeysCount = iNumericKeys.Count();
       
   164             while( numericKeysCount-- )
       
   165                 {
       
   166                 TPtiNumericKeyBinding numKeyBind = iNumericKeys[numericKeysCount];
       
   167                 if( numKeyBind.iKey == scanCode )
       
   168                     {
       
   169                     return ETrue;
       
   170                     }
       
   171                 }
       
   172             }
       
   173         }
       
   174     else
       
   175         {
       
   176         // Normal check ignore modifiers
       
   177         static const TInt KIdPlgScanCodes[] = 
       
   178             { '1','2','3','4','5','6','7','8','9','0',
       
   179               '*',EStdKeyNkpAsterisk,EStdKeyHash,EStdKeyNkpPlus };
       
   180         static const TInt KIdPlgScanCodeCount = 
       
   181             sizeof( KIdPlgScanCodes ) / sizeof( KIdPlgScanCodes[0] );
       
   182         TInt count = KIdPlgScanCodeCount;
       
   183         while( count-- )
       
   184             {
       
   185             const TInt refCode = KIdPlgScanCodes[ count ];
       
   186             // Is one of [0,1,2,3,4,5,6,7,8,9,*,#]?
       
   187             if( refCode == scanCode )
       
   188                 {
       
   189                 return ETrue;
       
   190                 }
       
   191             }
       
   192         }
       
   193     return EFalse;
       
   194     }
       
   195 
       
   196 
       
   197 /**
       
   198  * Load input locales.
       
   199  */
       
   200 void CNumericKeyHandler::LoadInputLanguageKeyBindings( TInt aLanguage )
       
   201     {
       
   202     iNumericKeys.Reset();
       
   203     
       
   204     TRAPD( err, 
       
   205         {
       
   206         CPtiEngine* ptiEngine = CPtiEngine::NewL();
       
   207         CleanupStack::PushL( ptiEngine );
       
   208         ptiEngine->GetNumericModeKeysForQwertyL( aLanguage, 
       
   209                                                  iNumericKeys );         
       
   210         CleanupStack::PopAndDestroy( ptiEngine );                                                 
       
   211         } ); // TRAP
       
   212         
       
   213     if ( err )        
       
   214         {
       
   215         iNumericKeys.Reset();
       
   216         iQwertyMode = 0; // To default mode
       
   217         }
       
   218     else
       
   219         {
       
   220         // remove numeric chars that not open number entry
       
   221         TInt numericKeysCount = iNumericKeys.Count();
       
   222         while ( numericKeysCount-- )
       
   223             {
       
   224             TPtiNumericKeyBinding numKeyBind = iNumericKeys[numericKeysCount];
       
   225             
       
   226             if ( numKeyBind.iChar == 'w' ||
       
   227                  numKeyBind.iChar == 'p' 
       
   228 #ifndef RD_INTELLIGENT_TEXT_INPUT
       
   229                  /*
       
   230                  * The following code is commented because
       
   231                  * For GQF requirement Space is mapped to "0"
       
   232                  */
       
   233                  || numKeyBind.iKey == EPtiKeyQwertySpace  
       
   234 #endif
       
   235                )
       
   236                  {
       
   237                  iNumericKeys.Remove( numericKeysCount );                    
       
   238                  }
       
   239             }    
       
   240         }
       
   241     }
       
   242     
       
   243 /**
       
   244  * Handles qwerty mode change.
       
   245  */
       
   246 TInt CNumericKeyHandler::HandleQwertyModeChanged( TAny *aPtr )
       
   247     {
       
   248     CNumericKeyHandler* self = static_cast<CNumericKeyHandler*>( aPtr );
       
   249     if( self )
       
   250         {
       
   251         TInt value = self->iQwertyMode;
       
   252         TInt err = self->iQwertyObserver->Get( value );
       
   253 
       
   254         if( err == KErrNone )
       
   255             {
       
   256             self->SetQwertyMode( value );
       
   257             }
       
   258         // Load key bindings if not already loaded
       
   259 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   260         if ( self->iQwertyMode )
       
   261             {
       
   262             self->iNumericKeys.Reset();
       
   263 #else 
       
   264         if ( self->iQwertyMode && !self->iNumericKeys.Count() )
       
   265             {
       
   266 #endif
       
   267         	self->LoadInputLanguageKeyBindings( self->iInputLanguage );
       
   268             }
       
   269         }
       
   270     return KErrNone;
       
   271     }
       
   272 
       
   273 /**
       
   274  * Handles input language change.
       
   275  */
       
   276 TInt CNumericKeyHandler::HandleInputLanguageChanged( TInt aNewValue )
       
   277 	{    	
       
   278 	SetInputLanguage( aNewValue );
       
   279 	LoadInputLanguageKeyBindings( aNewValue );
       
   280     return KErrNone;
       
   281 	}
       
   282     
       
   283 /**
       
   284  * Set qwerty mode.
       
   285  */
       
   286 void CNumericKeyHandler::SetQwertyMode( TInt aValue )
       
   287 	{
       
   288 	iQwertyMode = aValue;
       
   289 	}
       
   290     
       
   291 /**
       
   292  * Set input language.
       
   293  */
       
   294 void CNumericKeyHandler::SetInputLanguage( TInt aValue )
       
   295     {
       
   296     iInputLanguage = aValue;
       
   297     }
       
   298 
       
   299 void CNumericKeyHandler::HandleNotifyGeneric(TUint32 aKey)
       
   300 	{
       
   301 	if( aKey == KAknFepInputTxtLang )
       
   302 		{
       
   303 		TInt newValue = iInputLanguage;
       
   304 		iInputLanguageRepository->Get( KAknFepInputTxtLang, newValue );
       
   305 		HandleInputLanguageChanged( newValue );
       
   306 		}
       
   307 	}
       
   308     
       
   309 void CNumericKeyHandler::HandleNotifyError
       
   310         (TUint32 /*aKey*/, TInt /*aError*/, CCenRepNotifyHandler* /*aHandler*/)
       
   311     {
       
   312     }
       
   313 
       
   314 } // namespace AiWsPlugin