uifw/AknGlobalUI/AknCapServer/src/aknKeyFilter.cpp
changeset 0 2f259fa3e83a
child 4 8ca85d2f0db7
child 47 2f0c06423c72
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2005-2008 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:  Translates key events for different UI related situations.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <barsread.h>
       
    21 #include <apgwgnam.h>
       
    22 #include <e32property.h>
       
    23 #include <UikonInternalPSKeys.h>    // KUikLayoutState, KUikFlipStatus
       
    24 #include <AvkonInternalCRKeys.h>    // KAknQwertyInputModeActive
       
    25 #include <eikpriv.rsg>
       
    26 #include <AknDef.h>
       
    27 #include <AknSgcc.h>
       
    28 #include <aknenv.h>
       
    29 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    30 #include <uikon/eikenvinterface.h>
       
    31 #endif
       
    32 
       
    33 
       
    34 #include <AknSettingCache.h>
       
    35 #include <AknLayoutConfig.h>
       
    36 
       
    37 #include "AknKeyFilter.h"
       
    38 #include <AknTaskList.h>
       
    39 #include <aknconsts.h>
       
    40 
       
    41 #include <gfxtranseffect/gfxtranseffect.h>
       
    42 #include "akntranseffect.h" // for Transition effect enumerations
       
    43 #include <hwrmdomainpskeys.h>
       
    44 
       
    45 #include "AknCapServerEntry.h"
       
    46 
       
    47 /** Phone application's AppUID. */
       
    48 const TUid KPhoneAppUid  = { 0x100058B3 };
       
    49 
       
    50 /** Phone application's view UID. */
       
    51 const TUid KPhoneViewUid = { 0x10282D81 };
       
    52 
       
    53 
       
    54 
       
    55 /** Video call application's AppUID */
       
    56 const TUid KVideoCallAppUid     = { 0x101F8681 }; 
       
    57 
       
    58 /**
       
    59 * Command used in activating the phone view.
       
    60 * Null command allows the the phone app to decide whether
       
    61 * to open dialer or call handling.
       
    62 */
       
    63 const TUid KPhoneVievCommand = { 0x0 };
       
    64 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
    65 #include <PtiDefs.h>
       
    66 #include <AknFepInternalCRKeys.h>
       
    67 #endif
       
    68 
       
    69 
       
    70 // ================= MEMBER FUNCTIONS =======================
       
    71 
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CAknServKeyFilter::CAknServKeyFilter
       
    75 // Default constructor.
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 CAknServKeyFilter::CAknServKeyFilter()
       
    79     : iHardwareStateKeyCaptures( 2 )
       
    80     {
       
    81     }
       
    82 
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // CAknServKeyFilter::~CAknServKeyFilter
       
    86 // Destructor.
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 CAknServKeyFilter::~CAknServKeyFilter()
       
    90     {
       
    91     FreeHardwareStateKeys();
       
    92 
       
    93     RWindowGroup& groupWin = iCoeEnv->RootWin();
       
    94     groupWin.CancelCaptureKeyUpAndDowns( iHomeKeyHandle );
       
    95     groupWin.CancelCaptureKeyUpAndDowns( iQwertyOnKeyHandle );
       
    96     groupWin.CancelCaptureKeyUpAndDowns( iQwertyOffKeyHandle );
       
    97     groupWin.CancelCaptureKey( iFlipOpenKeyHandle );
       
    98     groupWin.CancelCaptureKey( iFlipCloseKeyHandle );
       
    99 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   100     delete iAvkonRepository;
       
   101 #endif
       
   102     delete iHomeTimer;
       
   103     }
       
   104 
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // CAknServKeyFilter::ConstructL
       
   108 // Second-phase constructor.
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 void CAknServKeyFilter::ConstructL( CAknCapAppServerAppUi& aAppUi )
       
   112     {
       
   113     RWindowGroup& groupWin = iCoeEnv->RootWin();
       
   114     iHomeKeyHandle      = groupWin.CaptureKeyUpAndDowns(EStdKeyApplication0, 0, 0);
       
   115     iQwertyOnKeyHandle  = groupWin.CaptureKeyUpAndDowns(EStdKeyApplication7, 0, 0); // EKeyQwertyOn
       
   116     iQwertyOffKeyHandle = groupWin.CaptureKeyUpAndDowns(EStdKeyApplication8, 0, 0); // EKeyQwertyOff
       
   117     iFlipOpenKeyHandle  = groupWin.CaptureKey(EKeyDeviceA, 0, 0); // EKeyFlipOpen
       
   118     iFlipCloseKeyHandle = groupWin.CaptureKey(EKeyDeviceB, 0, 0); // EKeyFlipClose
       
   119 
       
   120     // Get the default view id
       
   121     TResourceReader reader;
       
   122     // AppUi loads this resource
       
   123     iEikonEnv->CreateResourceReaderLC( reader, R_EIK_SYSTEM_DEFAULT_VIEW_ID );
       
   124     iHomeViewId.iAppUid.iUid  = reader.ReadInt32();
       
   125     iHomeViewId.iViewUid.iUid = reader.ReadInt32();
       
   126     CleanupStack::PopAndDestroy(); // reader
       
   127 
       
   128     aAppUi.AddToStackL(
       
   129         this,
       
   130         ECoeStackPriorityEnvironmentFilter,
       
   131         ECoeStackFlagRefusesFocus|ECoeStackFlagOwnershipTransfered|ECoeStackFlagSharable);
       
   132 
       
   133     iAppUi = &aAppUi;
       
   134 
       
   135     CaptureHardwareStateKeysL();
       
   136     InitHardwareStateL();
       
   137 
       
   138     RProperty::Define( KPSUidUikon, KUikFlipStatus, RProperty::EInt );
       
   139     // Set default value for the KUikFlipStatus Pub&Sub key.
       
   140     RProperty::Set( KPSUidUikon, KUikFlipStatus, 0 );
       
   141 
       
   142     RProperty::Define( KCRUidAvkon, KAknQwertyInputModeActive, RProperty::EInt );
       
   143     
       
   144     // Set default value for the KAknQwertyInputModeActive Pub&Sub key.
       
   145     RProperty::Set(KCRUidAvkon, KAknQwertyInputModeActive, 0);
       
   146     iAppUi->iQwertyStatus = EFalse;
       
   147 
       
   148 
       
   149 #ifdef RD_INTELLIGENT_TEXT_INPUT        
       
   150 #if defined(__WINS__)    
       
   151 
       
   152     TInt layoutState = 0;
       
   153     TInt hwKeyCode = 0;
       
   154     RProperty::Get(KPSUidUikon, KUikLayoutState, layoutState);
       
   155     CAknLayoutConfig::THardwareStateArray hwStates = CAknSgcClient::LayoutConfig().HardwareStates();
       
   156     TInt count = hwStates.Count();
       
   157     for (TInt ii=0; ii<count; ii++)
       
   158         {
       
   159         const CAknLayoutConfig::THardwareState& hwState = hwStates.At(ii);
       
   160         if (hwState.StateNumber() == layoutState)
       
   161             {
       
   162             hwKeyCode = hwState.KeyCode();
       
   163             break;
       
   164             }
       
   165         }
       
   166         
       
   167     RProperty::Define( KCRUidAvkon, KAknKeyBoardLayout, RProperty::EInt );
       
   168     iAvkonRepository = CRepository::NewL(KCRUidAvkon);
       
   169     TInt keyboardLayout = HwKeyToKeyBoardType(hwKeyCode);
       
   170     
       
   171     // Set default value for the KAknKeyBoardLayout Pub&Sub key.
       
   172     RProperty::Set(KCRUidAvkon, KAknKeyBoardLayout, keyboardLayout);
       
   173 #else
       
   174     
       
   175     RProperty::Define( KCRUidAvkon, KAknKeyBoardLayout, RProperty::EInt );
       
   176     iAvkonRepository = CRepository::NewL(KCRUidAvkon);
       
   177     TInt keyboardLayout = EPtiKeyboard12Key;
       
   178     iAvkonRepository->Get(KAknKeyBoardLayout, keyboardLayout); 
       
   179     RProperty::Set(KCRUidAvkon, KAknKeyBoardLayout, keyboardLayout);
       
   180 
       
   181 #endif // !__WINS__   
       
   182     TBool isQwertyOn = EFalse;
       
   183     switch(keyboardLayout)
       
   184         {
       
   185         case EPtiKeyboardQwerty4x12:
       
   186         case EPtiKeyboardQwerty4x10:
       
   187         case EPtiKeyboardQwerty3x11:
       
   188         case EPtiKeyboardHalfQwerty:
       
   189         case EPtiKeyboardCustomQwerty:
       
   190             {
       
   191             isQwertyOn = ETrue;
       
   192             break;
       
   193             }
       
   194         default:
       
   195             break;
       
   196         }
       
   197     if(isQwertyOn)
       
   198         {
       
   199         RProperty::Set(KCRUidAvkon, KAknQwertyInputModeActive, 1);
       
   200         iAppUi->iQwertyStatus = ETrue;
       
   201         }
       
   202     else
       
   203         {
       
   204         RProperty::Set(KCRUidAvkon, KAknQwertyInputModeActive, 0);
       
   205         iAppUi->iQwertyStatus = EFalse;
       
   206         }
       
   207 #endif // RD_INTELLIGENT_TEXT_INPUT
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // CAknServKeyFilter::ToggleShellL
       
   212 // This method handles the short press of the applications key.
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 void CAknServKeyFilter::ToggleShellL()
       
   216     {
       
   217     RWsSession& ws = iCoeEnv->WsSession();
       
   218     TInt fgWgId    = ws.GetFocusWindowGroup();
       
   219 
       
   220     // Foreground application might be embedded into another application,
       
   221     // find root.
       
   222     CAknTaskList* taskList = CAknTaskList::NewL( ws );
       
   223     const RArray<RWsSession::TWindowGroupChainInfo>& chain = taskList->WgArray();
       
   224     const TInt chainCount = chain.Count();
       
   225 
       
   226     TBool found = ETrue;
       
   227     TInt wgId = fgWgId;
       
   228     while ( found )
       
   229         {
       
   230         found = EFalse;
       
   231 
       
   232         for ( TInt ii = 0; ii < chainCount; ii++ )
       
   233             {
       
   234             const RWsSession::TWindowGroupChainInfo& info = chain[ ii ];
       
   235             if ( info.iId == wgId && info.iParentId > 0 )
       
   236                 {
       
   237                 wgId = info.iParentId;
       
   238                 found = ETrue;
       
   239                 ii = chainCount; // break from for loop.
       
   240                 }
       
   241             }
       
   242         }
       
   243     delete taskList;
       
   244 
       
   245     // Get application UID of root window group.
       
   246     CApaWindowGroupName* wgName = CApaWindowGroupName::NewL( ws, wgId );
       
   247     CleanupStack::PushL( wgName );
       
   248     TUid appUid = wgName->AppUid();
       
   249     CleanupStack::PopAndDestroy( wgName );
       
   250 
       
   251     TVwsViewId idleView = TVwsViewId();
       
   252     TInt err = AknDef::GetPhoneIdleViewId( idleView );
       
   253     if ( err )
       
   254         {
       
   255         return;
       
   256         }
       
   257     
       
   258     if ( appUid == iHomeViewId.iAppUid )
       
   259         {
       
   260         // We are in AppShell, so try to activate the idle app
       
   261         // or phone app if there's a call ongoing.
       
   262         TInt value = 0;
       
   263         err = RProperty::Get( KPSUidUikon, KUikVideoCallTopApp, value );
       
   264       	if ( value == KPhoneAppUid.iUid )
       
   265       	    {
       
   266             ActivateViewL( TVwsViewId( TUid::Uid( value ), KPhoneViewUid ), KPhoneVievCommand );
       
   267             }
       
   268       	else if ( value == KVideoCallAppUid.iUid )
       
   269             {
       
   270             ActivateViewL( TVwsViewId( TUid::Uid( value ), KVideoCallAppUid ), TUid::Null() );
       
   271       	    }
       
   272         else
       
   273             {
       
   274             ActivateViewL( idleView, TUid::Uid( 1 ) );
       
   275             }
       
   276           }
       
   277     else if ( appUid == idleView.iAppUid || iAppUi->IsIdelActive( ))
       
   278         {
       
   279         ActivateViewL( iHomeViewId, TUid::Uid(1) );
       
   280         }
       
   281     else
       
   282         {
       
   283         GfxTransEffect::AbortFullScreen();
       
   284         ActivateViewL( idleView, TUid::Uid(1) );
       
   285         }
       
   286     }
       
   287 
       
   288 void CAknServKeyFilter::ActivateViewL( const TVwsViewId& aViewId, TUid aCustomMessageId )
       
   289     {
       
   290     RWsSession& ws = iCoeEnv->WsSession();
       
   291     TApaTaskList appList( ws );
       
   292     TApaTask task = appList.FindApp( aViewId.iAppUid );
       
   293     
       
   294     if ( task.Exists() )
       
   295         {
       
   296         // If the task already exists, bring it to foreground.
       
   297         if ( aViewId.iAppUid == iHomeViewId.iAppUid )
       
   298             {
       
   299             // special process for appshell
       
   300             RThread menuThread;
       
   301             TInt error = menuThread.Open(task.ThreadId());
       
   302             if ( error == KErrNone )
       
   303                {
       
   304                menuThread.SetProcessPriority(EPriorityForeground);  
       
   305                }
       
   306             // matrix menu will bring itself foreground when getting the message below
       
   307             task.SendMessage( KUidApaMessageSwitchOpenFile , KNullDesC8 );
       
   308             }
       
   309         else
       
   310             {
       
   311             CAknSgcClient::MoveApp(task.WgId(), ESgcMoveAppToForeground);
       
   312             }
       
   313         }
       
   314     else
       
   315         {
       
   316         // Shell app wants reactivation, so send a non-zero message ID.
       
   317         // Note that in high CPU load situations this might
       
   318         // cause the view server to panic an application,
       
   319         // that's why we try to bring an existing task
       
   320         // to foreground first.
       
   321         iAppUi->CreateActivateViewEventL( aViewId, aCustomMessageId, KNullDesC8() );
       
   322         }
       
   323     }
       
   324 
       
   325 
       
   326 
       
   327 // ---------------------------------------------------------------------------
       
   328 // CAknServKeyFilter::OfferKeyEventL
       
   329 // Handles key events.
       
   330 // ---------------------------------------------------------------------------
       
   331 //
       
   332 TKeyResponse CAknServKeyFilter::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   333                                                 TEventCode aType )
       
   334     {
       
   335     // Forward up event to app ui because of soft notification
       
   336     // key forwaring to phone app.
       
   337     if ( aType == EEventKeyUp &&
       
   338          iAppUi->iScanCodeCaptureHandle &&
       
   339          iAppUi->iPhoneKey.iScanCode == aKeyEvent.iScanCode )
       
   340         {
       
   341         iAppUi->PhoneKeyUpReceived();
       
   342         return EKeyWasConsumed;
       
   343         }
       
   344 
       
   345     if ( aKeyEvent.iScanCode == EStdKeyApplication0 )
       
   346         {
       
   347         return HandleHomeKeyEventL( aType );
       
   348         }
       
   349     else if ( aKeyEvent.iScanCode == EStdKeyApplication7 || // EKeyQwertyOn
       
   350               aKeyEvent.iScanCode == EStdKeyApplication8 )  // EKeyQwertyOff
       
   351         {
       
   352         return HandleQwertyKeyEvent( aKeyEvent, aType );
       
   353         }
       
   354     else if ( aType==EEventKey && HandleHardwareStateKeyL( aKeyEvent.iCode ) )
       
   355         {
       
   356         return EKeyWasConsumed;
       
   357         }
       
   358 
       
   359     return EKeyWasNotConsumed;
       
   360     }
       
   361 
       
   362 
       
   363 // ---------------------------------------------------------------------------
       
   364 // CAknServKeyFilter::HandleHomeKeyEventL
       
   365 // Handles the pressing of applications key.
       
   366 // ---------------------------------------------------------------------------
       
   367 //
       
   368 TKeyResponse CAknServKeyFilter::HandleHomeKeyEventL( TEventCode aType )
       
   369     {
       
   370     if ( iAppUi->IsAppsKeySuppressed() )
       
   371         {
       
   372         return EKeyWasNotConsumed;
       
   373         }
       
   374 
       
   375     if ( aType == EEventKeyDown )
       
   376         {
       
   377         delete iHomeTimer;
       
   378         iHomeTimer = NULL;
       
   379         iHomeTimer = CPeriodic::NewL( CActive::EPriorityHigh );
       
   380 
       
   381         iHomeTimer->Start( KHomeHoldDelay, 1, TCallBack( HomeTickL, this ) );
       
   382         return EKeyWasConsumed;
       
   383         }
       
   384     else if ( aType == EEventKeyUp )
       
   385         {
       
   386         if ( iHomeTimer && iHomeTimer->IsActive() )
       
   387             {
       
   388             iHomeTimer->Cancel();
       
   389             delete iHomeTimer;
       
   390             iHomeTimer = NULL;
       
   391             if ( !iAppUi->HandleShortAppsKeyPressL() )
       
   392                 {
       
   393                 RWsSession& ws = iEikonEnv->WsSession();
       
   394                 TApaTaskList apList( ws );
       
   395                 TApaTask task = apList.FindApp( iHomeViewId.iAppUid );
       
   396                 if( task.Exists() && task.WgId() == ws.GetFocusWindowGroup() )
       
   397                     {
       
   398                     GfxTransEffect::BeginFullScreen(
       
   399                         AknTransEffect::EApplicationExit,
       
   400                         TRect(),
       
   401                         AknTransEffect::EParameterType,
       
   402                         AknTransEffect::GfxTransParam( iHomeViewId.iAppUid ) );
       
   403                     }
       
   404 
       
   405                 ToggleShellL();
       
   406                 }
       
   407 
       
   408             return EKeyWasConsumed;
       
   409             }
       
   410         }
       
   411 
       
   412     return EKeyWasNotConsumed;
       
   413     }
       
   414 
       
   415 
       
   416 // ---------------------------------------------------------------------------
       
   417 // CAknServKeyFilter::HandleQwertyKeyEvent
       
   418 // Handles the pressing of QWERTY key.
       
   419 // ---------------------------------------------------------------------------
       
   420 //
       
   421 TKeyResponse CAknServKeyFilter::HandleQwertyKeyEvent( const TKeyEvent& /*aKeyEvent*/,
       
   422                                                       TEventCode aType )
       
   423     {
       
   424     if ( aType == EEventKeyDown )
       
   425         {
       
   426         TInt qwertyOn = 0;
       
   427 #ifdef RD_INTELLIGENT_TEXT_INPUT                
       
   428         TInt keyboardLayout = EPtiKeyboard12Key;
       
   429         iAvkonRepository->Get(KAknKeyBoardLayout, keyboardLayout);            
       
   430         switch(keyboardLayout)
       
   431             {
       
   432             case EPtiKeyboardQwerty4x12:
       
   433             case EPtiKeyboardQwerty4x10:
       
   434             case EPtiKeyboardQwerty3x11:
       
   435             case EPtiKeyboardHalfQwerty:
       
   436             case EPtiKeyboardCustomQwerty:
       
   437                 {
       
   438                 qwertyOn = 1;
       
   439                 break;
       
   440                 }
       
   441             default:
       
   442                 break;
       
   443             }
       
   444 #endif            
       
   445 
       
   446         TInt err = RProperty::Set( KCRUidAvkon,
       
   447                                    KAknQwertyInputModeActive,
       
   448                                    qwertyOn );
       
   449         iAppUi->iQwertyStatus = qwertyOn;
       
   450 
       
   451 #ifdef _DEBUG
       
   452         _LIT( KDMsg, "xxxx KAknQwertyInputModeActive err=%d" );
       
   453         RDebug::Print( KDMsg, err );
       
   454 #endif
       
   455 #ifdef RD_INTELLIGENT_TEXT_INPUT                
       
   456         err = RProperty::Set(KCRUidAvkon, KAknKeyBoardLayout, keyboardLayout);
       
   457 #endif
       
   458 
       
   459         }
       
   460 
       
   461     return EKeyWasConsumed;
       
   462     }
       
   463 
       
   464 
       
   465 // ---------------------------------------------------------------------------
       
   466 // CAknServKeyFilter::HandleFlipKeyEvent
       
   467 // Handles the flip events.
       
   468 // ---------------------------------------------------------------------------
       
   469 //
       
   470 void CAknServKeyFilter::HandleFlipKeyEvent( TInt aCode )
       
   471     {
       
   472     if ( aCode == EKeyFlipOpen )
       
   473         {
       
   474         RProperty::Set( KPSUidUikon, KUikFlipStatus, 1 ); // flip opened
       
   475         // hack solution for mcl only, need refactory after summer vacation by SysAp
       
   476         //RProperty::Set( KPSUidHWRM, KHWRMFlipStatus, EPSHWRMFlipOpen ); // valid API
       
   477         }
       
   478     else
       
   479         {
       
   480         RProperty::Set( KPSUidUikon, KUikFlipStatus, 0 ); // flip closed
       
   481         // hack solution for mcl only, need refactory after summer vacation by SysAp
       
   482         //RProperty::Set( KPSUidHWRM, KHWRMFlipStatus, EPSHWRMFlipClosed ); // valid API
       
   483         }
       
   484     }
       
   485 
       
   486 
       
   487 // ---------------------------------------------------------------------------
       
   488 // CAknServKeyFilter::HomeTickL
       
   489 // Static callback method of the long keypress detector of applications key.
       
   490 // ---------------------------------------------------------------------------
       
   491 //
       
   492 TInt CAknServKeyFilter::HomeTickL( TAny* aThis )
       
   493     {
       
   494     static_cast<CAknServKeyFilter*>( aThis )->DoHomeTickL();
       
   495     return 0;   // do not continue
       
   496     }
       
   497 
       
   498 
       
   499 // ---------------------------------------------------------------------------
       
   500 // CAknServKeyFilter::HomeTickL
       
   501 // Callback method of the long keypress detector of applications key.
       
   502 // ---------------------------------------------------------------------------
       
   503 //
       
   504 void CAknServKeyFilter::DoHomeTickL()
       
   505     {
       
   506     iHomeTimer->Cancel();
       
   507     delete iHomeTimer;
       
   508     iHomeTimer = NULL;
       
   509     // method return value ignored (not needed)
       
   510     // leave should not happen in this level
       
   511     TRAP_IGNORE( iAppUi->HandleLongAppsKeyPressL() );
       
   512     }
       
   513 
       
   514 
       
   515 // ---------------------------------------------------------------------------
       
   516 // CAknServKeyFilter::CaptureHardwareStateKeysL
       
   517 // Reads the hardware state keys of supported layouts and appends them
       
   518 // to the captured keys.
       
   519 // ---------------------------------------------------------------------------
       
   520 //
       
   521 void CAknServKeyFilter::CaptureHardwareStateKeysL()
       
   522     {
       
   523     RWindowGroup& groupWin = iCoeEnv->RootWin();
       
   524 
       
   525     CAknLayoutConfig::THardwareStateArray hwStates =
       
   526         CAknSgcClient::LayoutConfig().HardwareStates();
       
   527     TInt count = hwStates.Count();
       
   528     iHardwareStateKeyCaptures.ReserveL( count );
       
   529     for ( TInt ii = 0; ii < count; ii++ )
       
   530         {
       
   531         const CAknLayoutConfig::THardwareState& hwState = hwStates.At( ii );
       
   532         TInt key = hwState.KeyCode();
       
   533         // EKeyFlipOpen and EKeyFlipClose are already captured
       
   534         // (iFlipOpenKeyHandle and iFlipCloseKeyHandle).
       
   535         if ( key && !( key == EKeyFlipOpen || key == EKeyFlipClose ) )
       
   536             {
       
   537             iHardwareStateKeyCaptures.AppendL(groupWin.CaptureKey(key, 0, 0));
       
   538             }
       
   539         }
       
   540     }
       
   541 
       
   542 
       
   543 // ---------------------------------------------------------------------------
       
   544 // CAknServKeyFilter::InitHardwareStateL
       
   545 // Initializes the hardware state P&S key.
       
   546 // ---------------------------------------------------------------------------
       
   547 //
       
   548 void CAknServKeyFilter::InitHardwareStateL()
       
   549     {
       
   550     // Initialise the hardware state shared data key, so that a value exists,
       
   551     // use a state that results in screen mode zero for normal apps.
       
   552     CAknLayoutConfig::THardwareStateArray hwStates =
       
   553         CAknSgcClient::LayoutConfig().HardwareStates();
       
   554     TInt count = hwStates.Count();
       
   555     for ( TInt ii = 0; ii < count; ii++ )
       
   556         {
       
   557         const CAknLayoutConfig::THardwareState& hwState = hwStates.At( ii );
       
   558         if ( hwState.ScreenMode() == 0 )
       
   559             {
       
   560             SetHardwareStateL( hwState.StateNumber() );
       
   561             return;
       
   562             }
       
   563         }
       
   564 
       
   565     // Fall back to state 0.
       
   566     SetHardwareStateL( 0 );
       
   567     }
       
   568 
       
   569 
       
   570 // ---------------------------------------------------------------------------
       
   571 // CAknServKeyFilter::HandleHardwareStateKeyL
       
   572 // Handles hardware state key events.
       
   573 // ---------------------------------------------------------------------------
       
   574 //
       
   575 TBool CAknServKeyFilter::HandleHardwareStateKeyL( TInt aCode )
       
   576     {
       
   577     if ( aCode == EKeyFlipOpen || aCode == EKeyFlipClose )
       
   578         {
       
   579         HandleFlipKeyEvent(aCode);
       
   580         }
       
   581 
       
   582     CWsScreenDevice* screen = iEikonEnv->ScreenDevice();
       
   583     TInt screenMode = screen->CurrentScreenMode();
       
   584 
       
   585     CAknLayoutConfig::THardwareStateArray hwStates =
       
   586         CAknSgcClient::LayoutConfig().HardwareStates();
       
   587     TInt count = hwStates.Count();
       
   588     for ( TInt ii = 0; ii < count; ii++ )
       
   589         {
       
   590         const CAknLayoutConfig::THardwareState& hwState = hwStates.At( ii );
       
   591         if ( hwState.KeyCode() == aCode )
       
   592             {
       
   593             SetHardwareStateL( hwState.StateNumber() );
       
   594 
       
   595             // Update the setting cache and get SGCS to process the screen
       
   596             // mode change. This may broadcast a screen device change to
       
   597             // the apps, to inform them of the update.
       
   598             iAvkonEnv->SettingCache().Update( KAknHardwareLayoutSwitch );
       
   599             iAppUi->SgcServer()->HandleWindowGroupParamChangeL(
       
   600                 iEikonEnv->RootWin().Identifier(),
       
   601                 0,
       
   602                 0,
       
   603                 0,
       
   604                 KAknScreenModeUnset );
       
   605 
       
   606             if ( screenMode == screen->CurrentScreenMode() )
       
   607                 {
       
   608                 // Apps will not have received a screen device changed event
       
   609                 // so send a KAknHardwareLayoutSwitch to the apps to ensure
       
   610                 // they get to know about the key.
       
   611                 TWsEvent event;
       
   612                 event.SetType( KAknHardwareLayoutSwitch );
       
   613                 event.SetHandle( 0 );
       
   614                 iEikonEnv->WsSession().SendEventToAllWindowGroups( 0, event );
       
   615                 }
       
   616 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   617 #if defined(__WINS__)
       
   618             
       
   619             TInt keyboardLayout = HwKeyToKeyBoardType(aCode);
       
   620             TInt curkeyLayout = 0;
       
   621             TBool qwertyOn = EFalse;
       
   622             RProperty::Get(KCRUidAvkon, KAknKeyBoardLayout, curkeyLayout);
       
   623             
       
   624 		        switch(keyboardLayout)
       
   625                 {
       
   626                 case EPtiKeyboardQwerty4x12:
       
   627                 case EPtiKeyboardQwerty4x10:
       
   628                 case EPtiKeyboardQwerty3x11:
       
   629                 case EPtiKeyboardHalfQwerty:
       
   630                 case EPtiKeyboardCustomQwerty:
       
   631                     {
       
   632                     qwertyOn = ETrue;
       
   633                     break;
       
   634                     }
       
   635                 default:
       
   636                     break;
       
   637                 }					  
       
   638         
       
   639             if(curkeyLayout != keyboardLayout)
       
   640                 {
       
   641                 RProperty::Set(KCRUidAvkon, KAknKeyBoardLayout, keyboardLayout);
       
   642                 }
       
   643             if(qwertyOn)
       
   644                 {
       
   645                 iAppUi->iQwertyStatus = ETrue;
       
   646                 TInt err = RProperty::Set(KCRUidAvkon, KAknQwertyInputModeActive, 1); 
       
   647                 iAvkonRepository->Set(KAknQwertyInputModeActive,1);
       
   648                 } 
       
   649             else
       
   650                 {
       
   651                 iAppUi->iQwertyStatus = EFalse;
       
   652                 TInt err = RProperty::Set(KCRUidAvkon, KAknQwertyInputModeActive, 0); 
       
   653                 iAvkonRepository->Set(KAknQwertyInputModeActive,0); 
       
   654                 }
       
   655 #endif // __WINS__            
       
   656 #else
       
   657 #if defined(__WINS__)
       
   658             // On emulator environment, Qwerty input mode is set active when
       
   659             // the emulator facia bitmap has Qwerty keyboard. Otherwise the
       
   660             // Qwerty input mode is set off.
       
   661             // Key code EKeyDeviceF is used when the Qwerty emulator is activated.
       
   662             TInt err;
       
   663             if ( aCode == EKeyDeviceF )
       
   664                 {
       
   665                 err = RProperty::Set( KCRUidAvkon, KAknQwertyInputModeActive, 1 );
       
   666                 iAppUi->iQwertyStatus = 1;
       
   667                 }
       
   668             else
       
   669                 {
       
   670                 err = RProperty::Set( KCRUidAvkon, KAknQwertyInputModeActive, 0 );
       
   671                 iAppUi->iQwertyStatus = 0;
       
   672                 }
       
   673 
       
   674 #ifdef _DEBUG
       
   675             _LIT( KDMsg, "xxxx KAknQwertyInputModeActive err=%d" );
       
   676             RDebug::Print( KDMsg, err );
       
   677 #endif
       
   678 
       
   679 #endif // __WINS__
       
   680 #endif //RD_INTELLIGENT_TEXT_INPUT
       
   681             return ETrue;
       
   682             }
       
   683         }
       
   684 
       
   685     return EFalse;
       
   686     }
       
   687 
       
   688 
       
   689 // ---------------------------------------------------------------------------
       
   690 // CAknServKeyFilter::FreeHardwareStateKeys
       
   691 // Frees the captured hardware state keys.
       
   692 // ---------------------------------------------------------------------------
       
   693 //
       
   694 void CAknServKeyFilter::FreeHardwareStateKeys()
       
   695     {
       
   696     RWindowGroup& groupWin = iCoeEnv->RootWin();
       
   697     TInt count = iHardwareStateKeyCaptures.Count();
       
   698     for ( TInt ii = 0; ii < count; ii++ )
       
   699         {
       
   700         groupWin.CancelCaptureKey( iHardwareStateKeyCaptures[ii] );
       
   701         }
       
   702     iHardwareStateKeyCaptures.Close();
       
   703     }
       
   704 
       
   705 
       
   706 // ---------------------------------------------------------------------------
       
   707 // CAknServKeyFilter::SetHardwareStateL
       
   708 // Updates the hardware state P&S key.
       
   709 // ---------------------------------------------------------------------------
       
   710 //
       
   711 void CAknServKeyFilter::SetHardwareStateL( TInt aState )
       
   712     {
       
   713     TInt err = RProperty::Set( KPSUidUikon, KUikLayoutState, aState );
       
   714 
       
   715 #ifdef _DEBUG
       
   716     _LIT( KDMsg1, "xxxx KUikLayoutState err=%d" );
       
   717     RDebug::Print( KDMsg1, err );
       
   718 #endif
       
   719 
       
   720 #ifdef _DEBUG // should we omit error as we used to
       
   721     User::LeaveIfError( err );
       
   722 #endif
       
   723 
       
   724     // Reset preferred orientation
       
   725     err = RProperty::Set( KPSUidUikon,
       
   726                           KUikPreferredOrientation,
       
   727                           EPreferredOrientationNormal );
       
   728 
       
   729 #ifdef _DEBUG
       
   730     _LIT( KDMsg2, "xxxx KUikPreferredOrientation err=%d" );
       
   731     RDebug::Print( KDMsg2, err );
       
   732 #endif
       
   733 
       
   734 #ifdef _DEBUG
       
   735     User::LeaveIfError( err );
       
   736 #endif
       
   737     }
       
   738 
       
   739 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   740 TInt CAknServKeyFilter::HwKeyToKeyBoardType(TInt aKeyCode)
       
   741     {
       
   742     TInt ret = EPtiKeyboardNone;
       
   743     switch(aKeyCode)
       
   744         {
       
   745         case EKeyApplicationE:
       
   746             {
       
   747             ret = EPtiKeyboardQwerty4x10;
       
   748             break;
       
   749             }
       
   750         case EKeyApplication10:
       
   751             {
       
   752             ret = EPtiKeyboardQwerty3x11; //mini Qwerty
       
   753             break;
       
   754             }
       
   755         case EKeyApplication11:
       
   756             {
       
   757             ret = EPtiKeyboardHalfQwerty; // half Qwerty
       
   758             break;
       
   759             }
       
   760 //The EKeyDeviceF is done only for emulator. Borrowed from the old code.
       
   761 #if defined(__WINS__)
       
   762         case EKeyDeviceF:
       
   763             {
       
   764             ret = EPtiKeyboardQwerty4x12;
       
   765             break;
       
   766             }
       
   767 #endif
       
   768 		// ITU-T screen event
       
   769         case EKeyApplication12:
       
   770         case EKeyApplication15:
       
   771         case EKeyApplication16:
       
   772         case EKeyFlipClose:
       
   773             {
       
   774             ret = EPtiKeyboard12Key;
       
   775             break;
       
   776             }
       
   777         default:
       
   778             {
       
   779             iAvkonRepository->Get(KAknKeyBoardLayout, ret);
       
   780             break;
       
   781             }
       
   782         }
       
   783     return ret;
       
   784     }
       
   785 #endif //RD_INTELLIGENT_TEXT_INPUT
       
   786 // End of file