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