idlehomescreen/xmluirendering/uiengine/src/xnkeyeventdispatcher.cpp
changeset 0 f72a12da539e
child 1 5315654608de
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  Event dispatcher
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <AknUtils.h>
       
    20 
       
    21 // User includes
       
    22 #include "xnappuiadapter.h"
       
    23 #include "xnfocuscontrol.h"
       
    24 #include "xnkeyeventdispatcher.h"
       
    25 #include "xntype.h"
       
    26 #include "xncomponentnodeimpl.h"
       
    27 #include "xnproperty.h"
       
    28 #include "xnuiengine.h"
       
    29 #include "xnodt.h"
       
    30 #include "xndomdocument.h"
       
    31 #include "xndomnode.h"
       
    32 #include "xnmenuadapter.h"
       
    33 #include "xneditmode.h"
       
    34 #include "xnviewmanager.h"
       
    35 #include "xnviewdata.h"
       
    36 #include "xnnode.h"
       
    37 
       
    38 // Local macros
       
    39 #define IS_ARROW_KEY( k ) \
       
    40     ( k == EStdKeyLeftArrow || k == EStdKeyRightArrow || \
       
    41       k == EStdKeyUpArrow || k == EStdKeyDownArrow ) 
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // SetInitialFocusL
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 static void SetInitialFocusL( RPointerArray< CXnNode >& aArray )
       
    48     {
       
    49     for ( TInt i = 0; i < aArray.Count(); i++ )
       
    50         {
       
    51         CXnNode* node( aArray[i] );
       
    52 
       
    53         node->SetStateWithoutNotificationL(
       
    54             XnPropertyNames::style::common::KFocus );
       
    55 
       
    56         if ( node->IsStateSet( XnPropertyNames::style::common::KFocus ) )
       
    57             {
       
    58             break;
       
    59             }
       
    60         }
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // BuildTriggerNodeL
       
    65 // Builds a trigger node
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 static CXnNode* BuildTriggerNodeL(
       
    69     CXnUiEngine& aUiEngine,
       
    70     const TDesC8& aTriggerName )
       
    71     {
       
    72     CXnNode* node = CXnNode::NewL();
       
    73     CleanupStack::PushL( node );
       
    74 
       
    75     CXnType* type = CXnType::NewL( XnPropertyNames::action::KTrigger );
       
    76     CleanupStack::PushL( type );
       
    77 
       
    78     CXnNodeImpl* impl = CXnNodeImpl::NewL( type );
       
    79 
       
    80     CleanupStack::Pop( type );
       
    81 
       
    82     node->SetImpl( impl );
       
    83     node->SetUiEngine( aUiEngine );
       
    84 
       
    85     CXnDomPropertyValue* nameValue =
       
    86         CXnDomPropertyValue::NewL( aUiEngine.ODT()->DomDocument().StringPool() );
       
    87 
       
    88     CleanupStack::PushL( nameValue );
       
    89 
       
    90     nameValue->SetStringValueL( CXnDomPropertyValue::EString, aTriggerName );
       
    91 
       
    92     CXnProperty* name =
       
    93         CXnProperty::NewL( XnPropertyNames::action::trigger::KName, nameValue,
       
    94                            aUiEngine.ODT()->DomDocument().StringPool() );
       
    95 
       
    96     CleanupStack::Pop( nameValue );
       
    97     CleanupStack::PushL( name );
       
    98     node->SetPropertyL( name );
       
    99     CleanupStack::Pop( name );
       
   100 
       
   101     CleanupStack::Pop( node );
       
   102 
       
   103     return node;
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // MenuAdapter
       
   108 // Gets menuadapter from node, NULL if not available
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 static CXnMenuAdapter* MenuAdapter( CXnNode* aNode )
       
   112     {
       
   113     if ( aNode )
       
   114         {        
       
   115         return static_cast< CXnMenuAdapter* >( aNode->Control() );
       
   116         }
       
   117 
       
   118     return NULL;
       
   119     }
       
   120 
       
   121 // ============================ MEMBER FUNCTIONS ===============================
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CXnKeyEventDispatcher::NewL
       
   125 // Two-phased constructor. Can leave.
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 CXnKeyEventDispatcher* CXnKeyEventDispatcher::NewL( CXnUiEngine& aUiEngine )
       
   129     {
       
   130     CXnKeyEventDispatcher* self = new ( ELeave ) CXnKeyEventDispatcher( aUiEngine );
       
   131     CleanupStack::PushL( self );
       
   132     self->ConstructL();
       
   133     CleanupStack::Pop();
       
   134     return self;
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CXnKeyEventDispatcher::~CXnKeyEventDispatcher
       
   139 // Destructor.
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 CXnKeyEventDispatcher::~CXnKeyEventDispatcher()
       
   143     {
       
   144     iCoeEnv->RemoveMessageMonitorObserver( *this );
       
   145     
       
   146     iUiEngine.ViewManager()->RemoveObserver( *this );
       
   147     
       
   148     delete iLoseFocus;
       
   149     delete iGainFocus;
       
   150     iPassiveFocusedNodes.Reset();
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CXnKeyEventDispatcher::CXnKeyEventDispatcher
       
   155 // C++ default constructor. Must not leave.
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 CXnKeyEventDispatcher::CXnKeyEventDispatcher( CXnUiEngine& aUiEngine )
       
   159     : iUiEngine( aUiEngine )
       
   160     {
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CXnKeyEventDispatcher::ConstructL
       
   165 // 2nd phase constructor. Can leave.
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 void CXnKeyEventDispatcher::ConstructL()
       
   169     {
       
   170     MakeVisible( EFalse );
       
   171 
       
   172     iUiEngine.ViewManager()->AddObserver( *this );
       
   173            
       
   174     iCoeEnv->AddMessageMonitorObserverL( *this );    
       
   175     }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CXnKeyEventDispatcher::MonitorWsMessage
       
   179 // 
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 void CXnKeyEventDispatcher::MonitorWsMessage( const TWsEvent& aEvent )
       
   183     {
       
   184     TInt type( aEvent.Type() );
       
   185     
       
   186     if ( type == EEventPointer && AknLayoutUtils::PenEnabled() )
       
   187         {    
       
   188         const TUint handle( aEvent.Handle() );
       
   189         
       
   190         CCoeControl* destination = reinterpret_cast< CCoeControl* >( handle );        
       
   191                                        
       
   192         TPointerEvent& event( *aEvent.Pointer() );
       
   193                 
       
   194         if ( iCbaContainer )
       
   195             {
       
   196             CEikCba* cba = 
       
   197                 static_cast< CEikCba* >( iCbaContainer->ButtonGroup() ); 
       
   198                     
       
   199             if ( destination == cba && iCbaContainer->IsVisible() )
       
   200                 {
       
   201                 CXnMenuAdapter* adapter( MenuAdapter( iMenuNode ) );
       
   202                 
       
   203                 if ( adapter )
       
   204                     {
       
   205                     TRAP_IGNORE( 
       
   206                         adapter->HandlePointerEventL( *aEvent.Pointer() ) );
       
   207                     }
       
   208                 }
       
   209             }
       
   210         }
       
   211     }
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // CXnKeyEventDispatcher::OfferKeyEventL
       
   215 // Handles key events.
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 TKeyResponse CXnKeyEventDispatcher::OfferKeyEventL(
       
   219     const TKeyEvent& aKeyEvent,
       
   220     TEventCode aType )
       
   221     {
       
   222     TKeyResponse resp( EKeyWasNotConsumed );
       
   223     
       
   224     iEventCode = aType;
       
   225     
       
   226     CXnNode* node( NULL );
       
   227     
       
   228     TBool keyYesNoApps( EFalse );
       
   229     
       
   230     if ( iUiEngine.IsMenuDisplaying() ||
       
   231          aKeyEvent.iScanCode == EStdKeyDevice0 ||
       
   232          aKeyEvent.iScanCode == EStdKeyDevice1 )
       
   233         {
       
   234         iFocusChanged = EFalse;
       
   235         // When menu is focused or LSK/RSK is pressed,
       
   236         // then forward events to menuadapter.
       
   237         // Note that MSK is handled directly in the base class as it used only
       
   238         // for activating
       
   239         node = iMenuNode;
       
   240         }
       
   241     else if ( aKeyEvent.iScanCode == EStdKeyApplication0 ||
       
   242               aKeyEvent.iScanCode == EStdKeyYes ||
       
   243               aKeyEvent.iScanCode == EStdKeyNo )
       
   244         {
       
   245         keyYesNoApps = ETrue;
       
   246         
       
   247         iFocusChanged = EFalse;
       
   248         // AppsKey, YesKey, NoKey events must be always handled, and if we don't
       
   249         // have a focused node, then let the view node do the job
       
   250         node = ( !iNode ) ? iUiEngine.ActiveView() : iNode;
       
   251         }
       
   252     else
       
   253         {
       
   254         CXnAppUiAdapter& appui( iUiEngine.AppUiAdapter() );
       
   255         
       
   256         if ( IS_ARROW_KEY( aKeyEvent.iScanCode ) && aType == EEventKey )
       
   257             {
       
   258             if ( !appui.FocusShown() )
       
   259                 {
       
   260                 appui.ShowFocus();
       
   261                 
       
   262                 if ( !iNode )
       
   263                     {
       
   264                     // Find initial location for focus
       
   265                     ResolveAndSetFocusL(); 
       
   266                                             
       
   267                     return EKeyWasConsumed;
       
   268                     }
       
   269                 }
       
   270             }
       
   271         
       
   272         CCoeControl* editmode( iUiEngine.EditMode() );
       
   273         
       
   274         if ( editmode->OfferKeyEventL( aKeyEvent, aType ) == EKeyWasConsumed )
       
   275             {
       
   276             return EKeyWasConsumed;
       
   277             }
       
   278         
       
   279         // Offer keyevent to the focused node        
       
   280         node = iNode;
       
   281 
       
   282         if ( aType == EEventKeyDown )
       
   283             {
       
   284             // Reset state
       
   285             iFocusChanged = EFalse;
       
   286             iKeyEventNode = iNode;
       
   287             }
       
   288 
       
   289         if ( iFocusChanged && ( aType == EEventKeyUp ) )
       
   290             {
       
   291             // Pass keyup event to
       
   292             // previously focused node
       
   293             node = iKeyEventNode;
       
   294             }
       
   295         }
       
   296 
       
   297     if ( !keyYesNoApps )
       
   298         {
       
   299         if ( iEventCode == EEventNull && aType != EEventKeyDown )
       
   300             {    
       
   301             // We are waiting for down event
       
   302             return resp;
       
   303             }        
       
   304         }
       
   305         
       
   306     if ( !node )
       
   307         {
       
   308         return resp;
       
   309         }
       
   310 
       
   311     iUiEngine.DisableRenderUiLC();
       
   312     
       
   313     CXnControlAdapter* adapter( node->Control() );
       
   314 
       
   315     if( adapter && adapter->IsVisible() )                            
       
   316         {
       
   317         resp = adapter->OfferKeyEventL( aKeyEvent, aType );
       
   318         }
       
   319 
       
   320     if ( aType != EEventKeyUp && iKeyEventNode != iNode )
       
   321         {
       
   322         // Focused node is changed during keyevent
       
   323         iFocusChanged = ETrue;
       
   324         }
       
   325     
       
   326     if ( aType == EEventKeyUp )
       
   327         {
       
   328         iEventCode = EEventNull;
       
   329         }
       
   330 
       
   331     iUiEngine.RenderUIL();
       
   332     CleanupStack::PopAndDestroy(); // DisableRenderUiLC
       
   333     
       
   334     return resp;
       
   335     }
       
   336 
       
   337 // -----------------------------------------------------------------------------
       
   338 // CXnKeyEventDispatcher::SetNode
       
   339 // -----------------------------------------------------------------------------
       
   340 //
       
   341 void CXnKeyEventDispatcher::SetNodeL( CXnNode* aNode, TInt aSource )
       
   342     {
       
   343     if ( iNode == aNode )
       
   344         {
       
   345         return;
       
   346         }
       
   347 
       
   348     iPreviousNode = iNode;
       
   349     iNode = aNode;
       
   350 
       
   351     SetNodeL( iPreviousNode, iNode, ETrue, aSource );
       
   352     }
       
   353 
       
   354 // -----------------------------------------------------------------------------
       
   355 // CXnKeyEventDispatcher::SetNodeWithoutNotificationL
       
   356 // -----------------------------------------------------------------------------
       
   357 //
       
   358 void CXnKeyEventDispatcher::SetNodeWithoutNotificationL( CXnNode* aNode )
       
   359     {
       
   360     if ( iNode == aNode )
       
   361         {
       
   362         return;
       
   363         }
       
   364 
       
   365     iPreviousNode = iNode;
       
   366     iNode = aNode;
       
   367 
       
   368     SetNodeL( iPreviousNode, iNode, EFalse );
       
   369     }
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // SetNodeL
       
   373 // Changes focused node, runs gain focus/lose focus triggers if needed
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 void CXnKeyEventDispatcher::SetNodeL( CXnNode* aToLose, CXnNode* aToGain,
       
   377     TBool aNotify, TInt aSource )
       
   378     {
       
   379     if ( aToLose )
       
   380         {
       
   381         aToLose->SetDirtyL( XnDirtyLevel::ERender );
       
   382 
       
   383         aToLose->UnsetStateL( XnPropertyNames::style::common::KFocus );
       
   384         aToLose->UnsetStateL( XnPropertyNames::style::common::KHold );
       
   385         aToLose->UnsetStateL( XnPropertyNames::style::common::KActive );
       
   386 
       
   387         if ( aNotify )
       
   388             {
       
   389             if ( !iLoseFocus )
       
   390                 {
       
   391                 iLoseFocus = BuildTriggerNodeL( iUiEngine,
       
   392                     XnPropertyNames::action::trigger::name::KLoseFocus );
       
   393                 }
       
   394 
       
   395             aToLose->ReportXuikonEventL( *iLoseFocus );
       
   396             }
       
   397 
       
   398         CXnControlAdapter* adapter( aToLose->Control() );
       
   399 
       
   400         if ( adapter )
       
   401             {
       
   402             adapter->SetFocus( EFalse );
       
   403             }
       
   404         }
       
   405 
       
   406     if ( aToGain )
       
   407         {
       
   408         aToGain->SetDirtyL( XnDirtyLevel::ERender );
       
   409 
       
   410         if ( aNotify )
       
   411             {
       
   412             if ( !iGainFocus )
       
   413                 {
       
   414                 iGainFocus = BuildTriggerNodeL( iUiEngine,
       
   415                         XnPropertyNames::action::trigger::name::KGainFocus );
       
   416                 }
       
   417 
       
   418             aToGain->ReportXuikonEventL( *iGainFocus, aSource );
       
   419             }
       
   420 
       
   421         CXnControlAdapter* adapter( aToGain->Control() );
       
   422 
       
   423         if ( adapter )
       
   424             {
       
   425             adapter->SetFocus( ETrue );
       
   426             }
       
   427         }
       
   428     }
       
   429 
       
   430 // -----------------------------------------------------------------------------
       
   431 // CXnKeyEventDispatcher::FocusedNode
       
   432 // -----------------------------------------------------------------------------
       
   433 //
       
   434 CXnNode* CXnKeyEventDispatcher::FocusedNode() const
       
   435     {
       
   436     if ( iNode && iNode->IsStateSet( XnPropertyNames::style::common::KFocus ) )
       
   437         {
       
   438         return iNode;
       
   439         }
       
   440 
       
   441     return NULL;
       
   442     }
       
   443 
       
   444 // -----------------------------------------------------------------------------
       
   445 // CXnKeyEventDispatcher::RefreshMenu
       
   446 // -----------------------------------------------------------------------------
       
   447 //
       
   448 void CXnKeyEventDispatcher::RefreshMenuL()
       
   449     {
       
   450     CXnMenuAdapter* menuAdapter( MenuAdapter( iMenuNode ) );
       
   451 
       
   452     if ( menuAdapter )
       
   453         {
       
   454         menuAdapter->SetContainerL( *iCbaContainer );
       
   455         }
       
   456     }
       
   457 
       
   458 // -----------------------------------------------------------------------------
       
   459 // CXnKeyEventDispatcher::SetMenuNode
       
   460 // -----------------------------------------------------------------------------
       
   461 //
       
   462 void CXnKeyEventDispatcher::SetMenuNodeL( CXnNode* aNode )
       
   463     {
       
   464     CXnMenuAdapter* menuAdapter( MenuAdapter( aNode ) );
       
   465     
       
   466     iCbaContainer = iAvkonAppUi->Cba();
       
   467 
       
   468     if ( menuAdapter )
       
   469         {
       
   470         iMenuNode = aNode;
       
   471                 
       
   472         menuAdapter->SetContainerL( *iCbaContainer );
       
   473 
       
   474         CXnProperty* prop( iMenuNode->DisplayL() );
       
   475 
       
   476         if ( prop && prop->StringValue() == 
       
   477             XnPropertyNames::style::common::display::KNone )
       
   478             {
       
   479             iCbaContainer->MakeVisible( EFalse );
       
   480             }
       
   481         else
       
   482             {
       
   483             iCbaContainer->MakeVisible( ETrue );
       
   484             }
       
   485         }
       
   486     else
       
   487         {
       
   488         iCbaContainer->MakeVisible( EFalse );
       
   489 
       
   490         // The node passed in wasn't a valid menu node
       
   491         ResetMenuNodeL();
       
   492         }
       
   493     }
       
   494 
       
   495 // -----------------------------------------------------------------------------
       
   496 // CXnKeyEventDispatcher::ResetMenuNodeL
       
   497 // -----------------------------------------------------------------------------
       
   498 //
       
   499 void CXnKeyEventDispatcher::ResetMenuNodeL()
       
   500     {
       
   501     iMenuNode = NULL;
       
   502 
       
   503     iCbaContainer = NULL;
       
   504     }
       
   505 
       
   506 // -----------------------------------------------------------------------------
       
   507 // CXnKeyEventDispatcher::IsMenuFocused
       
   508 // -----------------------------------------------------------------------------
       
   509 //
       
   510 TBool CXnKeyEventDispatcher::IsMenuFocused() const
       
   511     {
       
   512     CXnMenuAdapter* menuAdapter( MenuAdapter( iMenuNode ) );
       
   513 
       
   514     if ( menuAdapter )
       
   515         {
       
   516         return menuAdapter->IsMenuFocused();
       
   517         }
       
   518 
       
   519     return EFalse;
       
   520     }
       
   521 
       
   522 // -----------------------------------------------------------------------------
       
   523 // CXnKeyEventDispatcher::AddPassiveFocusedNode
       
   524 // -----------------------------------------------------------------------------
       
   525 //
       
   526 void CXnKeyEventDispatcher::AddPassiveFocusedNodeL( CXnNode* aNode )
       
   527     {
       
   528     if ( !aNode->IsStateSet( XnPropertyNames::style::common::KFocus ) &&
       
   529          !aNode->IsStateSet( XnPropertyNames::style::common::KPassiveFocus ) )
       
   530         {
       
   531         iPassiveFocusedNodes.AppendL( aNode );
       
   532         aNode->SetStateL( XnPropertyNames::style::common::KPassiveFocus );
       
   533         }
       
   534     }
       
   535 
       
   536 // -----------------------------------------------------------------------------
       
   537 // CXnKeyEventDispatcher::RemovePassiveFocusedNode
       
   538 // -----------------------------------------------------------------------------
       
   539 //
       
   540 void CXnKeyEventDispatcher::RemovePassiveFocusedNodeL( CXnNode* aNode )
       
   541     {
       
   542     for ( TInt i = 0; i < iPassiveFocusedNodes.Count(); i++ )
       
   543         {
       
   544         CXnNode* node( iPassiveFocusedNodes[i] );
       
   545 
       
   546         if ( node == aNode )
       
   547             {
       
   548             iPassiveFocusedNodes.Remove( i );
       
   549             
       
   550             aNode->UnsetStateL( 
       
   551                     XnPropertyNames::style::common::KPassiveFocus );
       
   552             }
       
   553         }
       
   554     }
       
   555 
       
   556 // -----------------------------------------------------------------------------
       
   557 // CXnKeyEventDispatcher::AddPassiveFocusedNode
       
   558 // -----------------------------------------------------------------------------
       
   559 //
       
   560 void CXnKeyEventDispatcher::ClearPassiveFocusedNodesL()
       
   561     {
       
   562     for ( TInt i = 0; i < iPassiveFocusedNodes.Count(); i++ )
       
   563         {
       
   564         iPassiveFocusedNodes[i]->UnsetStateL(
       
   565             XnPropertyNames::style::common::KPassiveFocus );
       
   566         }
       
   567 
       
   568     iPassiveFocusedNodes.Reset();
       
   569     }
       
   570 
       
   571 // -----------------------------------------------------------------------------
       
   572 // CXnKeyEventDispatcher::NotifyViewActivatedL
       
   573 // -----------------------------------------------------------------------------
       
   574 //
       
   575 void CXnKeyEventDispatcher::NotifyViewActivatedL(
       
   576     const CXnViewData& /*aViewData*/ )
       
   577     {    
       
   578     }
       
   579 
       
   580 // -----------------------------------------------------------------------------
       
   581 // CXnKeyEventDispatcher::NotifyViewDeactivatedL
       
   582 // -----------------------------------------------------------------------------
       
   583 //
       
   584 void CXnKeyEventDispatcher::NotifyViewDeactivatedL(
       
   585     const CXnViewData& /*aViewData*/ )
       
   586     {    
       
   587     iMenuNode = NULL;
       
   588     ClearPassiveFocusedNodesL();
       
   589     ClearStateL();
       
   590     
       
   591     iUiEngine.AppUiAdapter().HideFocus();
       
   592     }
       
   593 
       
   594 // -----------------------------------------------------------------------------
       
   595 // CXnKeyEventDispatcher::NotifyWidgetAdditionL
       
   596 // -----------------------------------------------------------------------------
       
   597 //
       
   598 void CXnKeyEventDispatcher::NotifyWidgetAdditionL(
       
   599     const CXnPluginData& aPluginData )
       
   600     {
       
   601     if ( aPluginData.Active() )
       
   602         {               
       
   603         iUiEngine.AppUiAdapter().ShowFocus();
       
   604         
       
   605         RPointerArray< CXnNode > initial;
       
   606         CleanupClosePushL( initial );
       
   607         
       
   608         if ( iUiEngine.IsEditMode() )
       
   609             {
       
   610             initial.AppendL( aPluginData.Owner()->LayoutNode() );
       
   611             }
       
   612         else
       
   613             {
       
   614             aPluginData.InitialFocusNodesL( initial );
       
   615             }
       
   616         
       
   617         SetInitialFocusL( initial );
       
   618         
       
   619         CleanupStack::PopAndDestroy( &initial );
       
   620         }
       
   621     }
       
   622 
       
   623 // -----------------------------------------------------------------------------
       
   624 // CXnKeyEventDispatcher::NotifyWidgetRemovalL
       
   625 // -----------------------------------------------------------------------------
       
   626 //
       
   627 void CXnKeyEventDispatcher::NotifyWidgetRemovalL(
       
   628     const CXnPluginData& aPluginData )
       
   629     {
       
   630     if ( aPluginData.Active() )
       
   631         {
       
   632         ClearPassiveFocusedNodesL();
       
   633 
       
   634         if ( iNode )
       
   635             {                              
       
   636             CXnViewData& activeViewData(
       
   637                 iUiEngine.ViewManager()->ActiveViewData() );
       
   638     
       
   639             const CXnPluginData& pluginData(
       
   640                 activeViewData.Plugin( iNode ) );
       
   641     
       
   642             if ( &pluginData == &aPluginData )
       
   643                 {
       
   644                 // The plugin is removed which was holding focus
       
   645                 ClearStateL();
       
   646                 }
       
   647             }
       
   648         }    
       
   649     }
       
   650 
       
   651 // -----------------------------------------------------------------------------
       
   652 // CCXnKeyEventDispatcher::NotifyConfigureWidgetL
       
   653 // -----------------------------------------------------------------------------
       
   654 //
       
   655 void CXnKeyEventDispatcher::NotifyConfigureWidgetL( 
       
   656     const CHsContentInfo& /*aContentInfo*/, CXnPluginData& /*aPluginData*/ )
       
   657     {
       
   658     }
       
   659 
       
   660 // -----------------------------------------------------------------------------
       
   661 // CXnKeyEventDispatcher::ResolveAndSetFocusL
       
   662 // Used to bring focus visible in the initial location when focus is invisible
       
   663 // -----------------------------------------------------------------------------
       
   664 //
       
   665 void CXnKeyEventDispatcher::ResolveAndSetFocusL() 
       
   666     {
       
   667     // <plugin> elements are always kept in appearance order
       
   668     RPointerArray< CXnNode >& list( *iUiEngine.Plugins() );
       
   669     
       
   670     if ( iUiEngine.IsEditMode() )
       
   671         {               
       
   672         SetInitialFocusL( list );        
       
   673         }
       
   674     else
       
   675         {
       
   676         RPointerArray< CXnNode > initial;
       
   677         CleanupClosePushL( initial );
       
   678         
       
   679         CXnViewData& activeView( iUiEngine.ViewManager()->ActiveViewData() );
       
   680 
       
   681         // first, search only in plugins which have popup window open
       
   682         for ( TInt i = 0; i < list.Count(); i++ )
       
   683             {
       
   684             CXnPluginData& plugin( activeView.Plugin( list[i] ) );
       
   685             if ( plugin.IsDisplayingPopup() )
       
   686                 {
       
   687                 plugin.InitialFocusNodesL( initial );
       
   688                 }
       
   689             }
       
   690         
       
   691         // if no inital focus nodes were found in plugins with
       
   692         // open popups, search again with all plugins
       
   693         if ( initial.Count() == 0 )
       
   694             {        
       
   695             for ( TInt i = 0; i < list.Count(); i++ )
       
   696                 {
       
   697                 CXnPluginData& plugin( activeView.Plugin( list[i] ) );
       
   698                 plugin.InitialFocusNodesL( initial );
       
   699                 }
       
   700             }
       
   701         
       
   702         // set initial focus
       
   703         SetInitialFocusL( initial );
       
   704         
       
   705         CleanupStack::PopAndDestroy( &initial );        
       
   706         }    
       
   707     }
       
   708 
       
   709 // -----------------------------------------------------------------------------
       
   710 // CXnKeyEventDispatcher::ClearStateL
       
   711 // -----------------------------------------------------------------------------
       
   712 //
       
   713 void CXnKeyEventDispatcher::ClearStateL()
       
   714     {
       
   715     SetNodeL( NULL );
       
   716     
       
   717     iNode = NULL;
       
   718     iPreviousNode = NULL;
       
   719     iKeyEventNode = NULL;
       
   720     iFocusChanged = EFalse;
       
   721     iEventCode = EEventNull;
       
   722     }
       
   723 
       
   724 // End of file