vtuis/videotelui/src/compman/cvtuicomponentmanager.cpp
branchRCL_3
changeset 35 779871d1e4f4
parent 0 ed9695c8bcbe
equal deleted inserted replaced
34:f15ac8e65a02 35:779871d1e4f4
       
     1 /*
       
     2 * Copyright (c) 2009 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:  Component manager implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <cvtlogger.h>
       
    20 
       
    21 #include "cvtuicomponentmanager.h"
       
    22 #include "mvtuiwindowservereventobserver.h"
       
    23 #include "mvtuiresourcechangeobserver.h"
       
    24 #include "mvtuikeyeventobserver.h"
       
    25 #include "mvtuilayoutchangeobserver.h"
       
    26 
       
    27 // ======== LOCAL FUNCTIONS ========
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // CmpByPtr
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 template < class T >
       
    34 TInt CmpByPtr( const T& aObj1, const T& aObj2 )
       
    35     {
       
    36     return reinterpret_cast< TInt >( &aObj1 ) -
       
    37         reinterpret_cast< TInt >( &aObj2 );
       
    38     }
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // FindByPtr
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 template < class T >
       
    45 TInt FindByPtr( const TInt* aPtr, const T& aObj )
       
    46     {
       
    47     return *aPtr - reinterpret_cast< TInt >( &aObj );
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // CmpMVtUiComponent
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 TInt CmpMVtUiComponent( const MVtUiComponent& aC1, const MVtUiComponent& aC2 )
       
    55     {
       
    56     return ( aC1.ComponentId() - aC2.ComponentId() );
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CmpTVtUiComponentState
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 TInt CmpTVtUiComponentState( const TVtUiComponentState& aC1,
       
    64     const TVtUiComponentState& aC2 )
       
    65     {
       
    66     return ( aC1.Component().ComponentId() - aC2.Component().ComponentId() );
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CmpTVtUiComponentStateByKey
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 TInt CmpTVtUiComponentStateByKey( const MVtUiComponent::TComponentId* aKey,
       
    74     const TVtUiComponentState& aC )
       
    75     {
       
    76     return ( *aKey - aC.Component().ComponentId() );
       
    77     }
       
    78 
       
    79 // ======== MEMBER FUNCTIONS ========
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CVtUiComponentManager::NewL
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CVtUiComponentManager* CVtUiComponentManager::NewL()
       
    86     {
       
    87     __VTPRINTENTER( "CompMgr.NewL" )
       
    88     CVtUiComponentManager* self = new ( ELeave ) CVtUiComponentManager();
       
    89     CleanupStack::PushL( self );
       
    90     self->ConstructL();
       
    91     CleanupStack::Pop(); // self
       
    92     __VTPRINTEXIT( "CompMgr.NewL" )
       
    93     return self;
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CVtUiComponentManager::~CVtUiComponentManager
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 CVtUiComponentManager::~CVtUiComponentManager()
       
   101     {
       
   102     __VTPRINTENTER( "CompMgr.~" )
       
   103     iWsEventObservers.Close();
       
   104     iResourceChangeObservers.Close();
       
   105     iKeyEventObservers.Close();
       
   106     iLayoutChangeObservers.Close();
       
   107     iComponents.Close();
       
   108     __VTPRINTEXIT( "CompMgr.~" )
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // CVtUiComponentManager::HandleWsEventL
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 void CVtUiComponentManager::HandleWsEventL( const TWsEvent& aEvent,
       
   116     CCoeControl* aDestination )
       
   117     {
       
   118     for ( TInt i = iWsEventObservers.Count() - 1; i >= 0; i-- )
       
   119         {
       
   120         iWsEventObservers[ i ]->HandleWsEventL( aEvent, aDestination );
       
   121         }
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // CVtUiComponentManager::HandleResourceChangeL
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 void CVtUiComponentManager::HandleResourceChangeL( TInt aType )
       
   129     {
       
   130     for ( TInt i = iResourceChangeObservers.Count() - 1; i >= 0; i-- )
       
   131         {
       
   132         iResourceChangeObservers[ i ]->HandleResourceChangeL( aType );
       
   133         }
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // CVtUiComponentManager:OfferKeyEventL
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 TKeyResponse CVtUiComponentManager::OfferKeyEventL(
       
   141     const TKeyEvent& aEvent, TEventCode aCode )
       
   142     {
       
   143     TKeyResponse response( EKeyWasNotConsumed );
       
   144     for ( TInt i = iKeyEventObservers.Count() - 1; i >= 0; i-- )
       
   145         {
       
   146         response = iKeyEventObservers[ i ]->OfferKeyEventL( aEvent, aCode );
       
   147         if ( response == EKeyWasConsumed )
       
   148             {
       
   149             break;
       
   150             }
       
   151         }
       
   152     return response;
       
   153     }
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // CVtUiComponentManager::HandleLayoutChangeL
       
   157 // ---------------------------------------------------------------------------
       
   158 //
       
   159 void CVtUiComponentManager::HandleLayoutChangeL()
       
   160     {
       
   161     for ( TInt i = iLayoutChangeObservers.Count() - 1; i >= 0; i-- )
       
   162         {
       
   163         iLayoutChangeObservers[ i ]->HandleLayoutChangeL();
       
   164         }    
       
   165     }
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // CVtUiComponentManager::ChangeWsEventRegistration
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 TInt CVtUiComponentManager::ChangeWsEventRegistration(
       
   172     MVtUiWindowServerEventObserver& aObserver, TAction aAction )
       
   173     {
       
   174     return AddOrRemoveComponent( iWsEventObservers, &aObserver, aAction );
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // CVtUiComponentManager::ChangeResourceChangeRegistration
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 TInt CVtUiComponentManager::ChangeResourceChangeRegistration(
       
   182     MVtUiResourceChangeObserver& aObserver, TAction aAction )
       
   183     {
       
   184     return AddOrRemoveComponent( iResourceChangeObservers, &aObserver,
       
   185         aAction );
       
   186     }
       
   187 
       
   188 // ---------------------------------------------------------------------------
       
   189 // CVtUiComponentManager::ChangeKeyEventRegistration
       
   190 // ---------------------------------------------------------------------------
       
   191 //
       
   192 TInt CVtUiComponentManager::ChangeKeyEventRegistration(
       
   193     MVtUiKeyEventObserver& aObserver, TAction aAction )
       
   194     {
       
   195     return AddOrRemoveComponent( iKeyEventObservers, &aObserver, aAction );
       
   196     }
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // CVtUiComponentManager::ChangeLayoutChangeRegistration
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 TInt CVtUiComponentManager::ChangeLayoutChangeRegistration(
       
   203     MVtUiLayoutChangeObserver& aObserver, TAction aAction )
       
   204     {
       
   205     return AddOrRemoveComponent( iLayoutChangeObservers, &aObserver, aAction );
       
   206     }
       
   207 
       
   208 // ---------------------------------------------------------------------------
       
   209 // CVtUiComponentManager::ChangeComponentRegistration
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 TInt CVtUiComponentManager::ChangeComponentRegistration(
       
   213     TVtUiComponentState& aComponentState, TAction aAction )
       
   214     {
       
   215     __VTPRINTENTER( "CompMgr.ChangeComponentRegistrationL" )
       
   216     TInt result( KErrNone );
       
   217     if ( aAction == ERegister )
       
   218         {
       
   219         result =
       
   220             iComponents.InsertInOrder( &aComponentState,
       
   221                 ComponentStateOrder() );
       
   222         }
       
   223     else
       
   224         {
       
   225         TInt index( iComponents.FindInOrder(
       
   226             &aComponentState, ComponentStateOrder() ) );
       
   227         if ( index != KErrNotFound )
       
   228             {
       
   229             iComponents.Remove( index );
       
   230             }
       
   231         }
       
   232     __VTPRINTEXITR( "CompMgr.ChangeComponentRegistrationL %d", result )
       
   233     return result;
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // CVtUiComponentManager::RequestActivationL
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 void CVtUiComponentManager::RequestActivationL(
       
   241     MVtUiComponent::TComponentId aId )
       
   242     {
       
   243     __VTPRINTENTER( "CompMgr.RequestActivationL" )
       
   244     TInt index( iComponents.FindInOrder( aId, ::CmpTVtUiComponentStateByKey ) );
       
   245     if ( index == KErrNotFound )
       
   246         {
       
   247         User::Leave( index );
       
   248         }
       
   249     else
       
   250         {
       
   251         TVtUiComponentState& state( *iComponents[ index ] );
       
   252         if ( state.State() == TVtUiComponentState::EActive )
       
   253             {
       
   254             User::Leave( KErrNotReady );
       
   255             }
       
   256         else
       
   257             {
       
   258             DoActivationL( state, TVtUiComponentState::EActive );
       
   259             }
       
   260         }
       
   261     __VTPRINTEXIT( "CompMgr.RequestActivationL" )
       
   262     }
       
   263 
       
   264 // ---------------------------------------------------------------------------
       
   265 // CVtUiComponentManager::DeActivateComponentL
       
   266 // ---------------------------------------------------------------------------
       
   267 //
       
   268 void CVtUiComponentManager::DeActivateComponentL(
       
   269     MVtUiComponent::TComponentId aId )
       
   270     {
       
   271     __VTPRINTENTER( "CompMgr.DeActivateComponentL" )
       
   272     TInt index( iComponents.FindInOrder( aId, ::CmpTVtUiComponentStateByKey ) );
       
   273     if ( index == KErrNotFound )
       
   274         {
       
   275         User::Leave( index );
       
   276         }
       
   277     else
       
   278         {
       
   279         TVtUiComponentState& state( *iComponents[ index ] );
       
   280         if ( state.State() == TVtUiComponentState::EInactive )
       
   281             {
       
   282             User::Leave( KErrNotReady );
       
   283             }
       
   284         else
       
   285             {
       
   286             DoDeactivationL( state, TVtUiComponentState::EInactive );
       
   287             }
       
   288         }
       
   289     __VTPRINTEXIT( "CompMgr.DeActivateComponentL" )
       
   290     }
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // CVtUiComponentManager::DoActivationL
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 void CVtUiComponentManager::DoActivationL(
       
   297 	TVtUiComponentState& aComponentState,
       
   298 	TVtUiComponentState::TState aNewState )
       
   299     {
       
   300     __VTPRINTENTER( "CompMgr.DoActivationL" )
       
   301     TStateList stateList;
       
   302     ConstructStateListL( stateList );
       
   303     TInt index( stateList.FindItem(
       
   304     	aComponentState.Component().ComponentId() ) );
       
   305     if ( index != KErrNotFound )
       
   306         {
       
   307         TStateListItem& sli( stateList.At( index ) );
       
   308         TVtUiBlockListBitField exclList;
       
   309         for ( TInt i = stateList.ItemCount() - 1; i >= 0; i-- )
       
   310         	{
       
   311         	TStateListItem& sli2( stateList.At( i ) );
       
   312         	if ( sli2.ComponentId() != sli.ComponentId() )
       
   313         		{
       
   314         		if ( sli2.State() == TVtUiComponentState::EActive &&
       
   315         			 !sli.BlockList().Contains( sli2.ComponentId() ) )
       
   316         			{
       
   317         			exclList.Union( sli2.BlockList() );
       
   318         			}
       
   319         		}
       
   320         	}
       
   321        	sli.SetRoot();
       
   322         sli.SetState( aNewState );
       
   323         CalculateActivationL( sli.BlockList(), exclList, stateList, EHide );
       
   324         }
       
   325     CommitStateListL( stateList );
       
   326     __VTPRINTEXIT( "CompMgr.DoActivationL" )
       
   327     }
       
   328 
       
   329 // ---------------------------------------------------------------------------
       
   330 // CVtUiComponentManager::DoDeactivationL
       
   331 // ---------------------------------------------------------------------------
       
   332 //
       
   333 void CVtUiComponentManager::DoDeactivationL(
       
   334     TVtUiComponentState& aComponentState,
       
   335     TVtUiComponentState::TState aNewState )
       
   336     {
       
   337     __VTPRINTENTER( "CompMgr.DoDeactivationL" )
       
   338     TStateList stateList;
       
   339     ConstructStateListL( stateList );
       
   340     TInt index( stateList.FindItem(
       
   341         aComponentState.Component().ComponentId() ) );
       
   342     if ( index != KErrNotFound )
       
   343         {
       
   344         TStateListItem& sli( stateList.At( index ) );
       
   345         TVtUiBlockListBitField exclList;
       
   346         if ( sli.State() == TVtUiComponentState::EActive )
       
   347         	{
       
   348 	        for ( TInt i = stateList.ItemCount() - 1; i >= 0; i-- )
       
   349 	        	{
       
   350 	        	TStateListItem& sli2( stateList.At( i ) );
       
   351 	        	if ( sli2.ComponentId() != sli.ComponentId() )
       
   352 	        		{
       
   353 	        		if ( sli2.State() == TVtUiComponentState::EActive )
       
   354 	        			{
       
   355 	        			exclList.Union( sli2.BlockList() );
       
   356 	        			}
       
   357 	        		}
       
   358 	        	}
       
   359         	}
       
   360         sli.SetRoot();
       
   361         sli.SetState( aNewState );
       
   362         CalculateActivationL( sli.BlockList(), exclList, stateList, EShow );
       
   363         }
       
   364     CommitStateListL( stateList );
       
   365     __VTPRINTEXIT( "CompMgr.DoDeactivationL" )
       
   366     }
       
   367 
       
   368 // ---------------------------------------------------------------------------
       
   369 // CVtUiComponentManager::CommitStateListL
       
   370 // ---------------------------------------------------------------------------
       
   371 //
       
   372 void CVtUiComponentManager::CommitStateListL( TStateList& aList )
       
   373     {
       
   374     __VTPRINTENTER( "CompMgr.CommitStateListL" )
       
   375     // Sort list by component state. Components will first deactivated, then
       
   376     // blocked and finally activated.
       
   377     aList.Sort( TStateListItem::StateOrder() );
       
   378     for ( TInt i = 0; i < aList.ItemCount(); i++ )
       
   379         {
       
   380         const TStateListItem& sli( aList.At( i ) );
       
   381         TInt index( iComponents.FindInOrder( sli.ComponentId(),
       
   382             ::CmpTVtUiComponentStateByKey ) );
       
   383         if ( index != KErrNotFound )
       
   384             {
       
   385             TVtUiComponentState& cs( *iComponents[ index ] );
       
   386             if ( cs.State() != sli.State() )
       
   387                 {
       
   388                 switch ( sli.State() )
       
   389                     {
       
   390                 case TVtUiComponentState::EInactive:
       
   391                     cs.DeActivateComponentL();
       
   392                     break;
       
   393 
       
   394                 case TVtUiComponentState::EActive:
       
   395                     cs.ActivateComponentL();
       
   396                     break;
       
   397 
       
   398                 case TVtUiComponentState::EWaiting:
       
   399                     cs.BlockComponentL();
       
   400                     break;
       
   401 
       
   402                 default:
       
   403                     User::Leave( KErrArgument );
       
   404                     break;
       
   405                     }
       
   406                 }
       
   407             }
       
   408         }
       
   409     __VTPRINTEXIT( "CompMgr.CommitStateListL" )
       
   410     }
       
   411 
       
   412 // ---------------------------------------------------------------------------
       
   413 // CVtUiComponentManager::CalculateActivationL
       
   414 // ---------------------------------------------------------------------------
       
   415 //
       
   416 void CVtUiComponentManager::CalculateActivationL(
       
   417     const TVtUiBlockList& aBlockList,
       
   418     const TVtUiBlockList& aExclList,
       
   419     TStateList& aStateList, TActivationAction aAction )
       
   420     {
       
   421     __VTPRINTENTER( "CompMgr.CalculateActivationL" )
       
   422     __VTPRINT2( DEBUG_GEN, "aAction = %d", (TInt)aAction )
       
   423     TVtUiBlockListBitField blockList;
       
   424     CVtUiBlockListIterator* iterator = aBlockList.IteratorLC();
       
   425     while ( iterator->HasNext() )
       
   426         {
       
   427         MVtUiComponent::TComponentId cid( iterator->Next() );
       
   428 		if ( aExclList.Contains( cid ) )
       
   429 			{
       
   430 			continue;
       
   431 			}
       
   432         TInt index( aStateList.FindItem( cid ) );
       
   433         if ( index != KErrNotFound )
       
   434             {
       
   435             TStateListItem& sli( aStateList.At( index ) );
       
   436             __VTPRINT3( DEBUG_GEN, "@1, Id = %d, state = %d", (TInt)sli.ComponentId(), (TInt)sli.State() )
       
   437             if ( !sli.IsRoot() )
       
   438                 {
       
   439                 if ( aAction == EShow )
       
   440                     {
       
   441                     // if action == EShow and component is being blocked,
       
   442                     // then activate component
       
   443                     if ( sli.State() == TVtUiComponentState::EWaiting )
       
   444                         {
       
   445                         sli.SetState( TVtUiComponentState::EActive );
       
   446                         if ( !sli.IsVisited() )
       
   447                             {
       
   448                             blockList.Union( sli.BlockList() );
       
   449                             }
       
   450                         sli.SetVisited();
       
   451                         }
       
   452                     }
       
   453                 else // aAction == EHide
       
   454                     {
       
   455                     // if action == EHide and component is active, then
       
   456                     // block component
       
   457                     if ( sli.State() == TVtUiComponentState::EActive )
       
   458                         {
       
   459                         sli.SetState( TVtUiComponentState::EWaiting );
       
   460                         if ( !sli.IsVisited() )
       
   461                             {
       
   462                             blockList.Union( sli.BlockList() );
       
   463                             }
       
   464                         sli.SetVisited();
       
   465                         }
       
   466                     }
       
   467                 }
       
   468 			__VTPRINT3( DEBUG_GEN, "@2, Id = %d, state = %d", (TInt)sli.ComponentId(), (TInt)sli.State() )
       
   469             }
       
   470         }
       
   471     CleanupStack::PopAndDestroy(); // iterator
       
   472     if ( !blockList.IsEmpty() )
       
   473         {
       
   474         CalculateActivationL( blockList, aExclList, aStateList,
       
   475             ( aAction == EShow ) ? EHide : EShow );
       
   476         }
       
   477     __VTPRINTEXIT( "CompMgr.CalculateActivationL" )
       
   478     }
       
   479 
       
   480 // ---------------------------------------------------------------------------
       
   481 // CVtUiComponentManager::ConstructStateListL
       
   482 // ---------------------------------------------------------------------------
       
   483 //
       
   484 void CVtUiComponentManager::ConstructStateListL( TStateList& aList )
       
   485     {
       
   486     for ( TInt i = iComponents.Count() - 1; i >= 0; i-- )
       
   487         {
       
   488         TStateListItem sli( *iComponents[ i ] );
       
   489         aList.AddItemL( sli );
       
   490         }
       
   491     }
       
   492 
       
   493 // ---------------------------------------------------------------------------
       
   494 // CVtUiComponentManager::CVtUiComponentManager
       
   495 // ---------------------------------------------------------------------------
       
   496 //
       
   497 CVtUiComponentManager::CVtUiComponentManager()
       
   498     : iWsEventObservers( 1 ), iResourceChangeObservers( 1 ),
       
   499       iKeyEventObservers( 1 ),iLayoutChangeObservers( 1 ), iComponents( 1 )
       
   500     {
       
   501     }
       
   502 
       
   503 // ---------------------------------------------------------------------------
       
   504 // CVtUiComponentManager::ConstructL
       
   505 // ---------------------------------------------------------------------------
       
   506 //
       
   507 void CVtUiComponentManager::ConstructL()
       
   508     {
       
   509     }
       
   510 
       
   511 // ---------------------------------------------------------------------------
       
   512 // CVtUiComponentManager::AddOrRemoveComponent
       
   513 // ---------------------------------------------------------------------------
       
   514 //
       
   515 template < class T >
       
   516 TInt CVtUiComponentManager::AddOrRemoveComponent( RPointerArray< T >& aArray,
       
   517     T* aComponent, TAction aAction )
       
   518     {
       
   519     __VTPRINTENTER( "CompMgr.AddOrRemoveComponent" )
       
   520     TInt result( KErrNone );
       
   521     if ( aAction == ERegister )
       
   522         {
       
   523         result = aArray.InsertInOrder( aComponent, ::CmpByPtr );
       
   524         }
       
   525     else
       
   526         {
       
   527         TInt index( aArray.FindInOrder( aComponent, ::CmpByPtr ) );
       
   528         if ( index != KErrNotFound )
       
   529             {
       
   530             aArray.Remove( index );
       
   531             }
       
   532         }
       
   533     __VTPRINTEXITR( "CompMgr.AddOrRemoveComponent %d", result )
       
   534     return result;
       
   535     }
       
   536 
       
   537 // ---------------------------------------------------------------------------
       
   538 // CVtUiComponentManager::ComponentOrder
       
   539 // ---------------------------------------------------------------------------
       
   540 //
       
   541 TLinearOrder< MVtUiComponent > CVtUiComponentManager::ComponentOrder()
       
   542     {
       
   543     return TLinearOrder< MVtUiComponent >( ::CmpMVtUiComponent );
       
   544     }
       
   545 
       
   546 // ---------------------------------------------------------------------------
       
   547 // CVtUiComponentManager::ComponentStateOrder
       
   548 // ---------------------------------------------------------------------------
       
   549 //
       
   550 TLinearOrder< TVtUiComponentState > CVtUiComponentManager::ComponentStateOrder()
       
   551     {
       
   552     return TLinearOrder< TVtUiComponentState >( ::CmpTVtUiComponentState );
       
   553     }
       
   554 
       
   555 // Implementation of CVtUiComponentManager::TStateListItem
       
   556 
       
   557 // ---------------------------------------------------------------------------
       
   558 // CVtUiComponentManager::TStateListItem::TStateListItem
       
   559 // ---------------------------------------------------------------------------
       
   560 //
       
   561 CVtUiComponentManager::TStateListItem::TStateListItem(
       
   562     const TVtUiComponentState& aState )
       
   563     : iComponentId( aState.Component().ComponentId() ),
       
   564       iState( aState.State() ), iIsRoot( EFalse ), iIsVisited( EFalse )
       
   565     {
       
   566     iBlockList.Union( aState.BlockList() );
       
   567     }
       
   568 
       
   569 // ---------------------------------------------------------------------------
       
   570 // CVtUiComponentManager::TStateListItem::ComponentId
       
   571 // ---------------------------------------------------------------------------
       
   572 //
       
   573 MVtUiComponent::TComponentId
       
   574 CVtUiComponentManager::TStateListItem::ComponentId() const
       
   575     {
       
   576     return iComponentId;
       
   577     }
       
   578 
       
   579 // ---------------------------------------------------------------------------
       
   580 // CVtUiComponentManager::TStateListItem::State
       
   581 // ---------------------------------------------------------------------------
       
   582 //
       
   583 TVtUiComponentState::TState CVtUiComponentManager::TStateListItem::State() const
       
   584     {
       
   585     return iState;
       
   586     }
       
   587 
       
   588 // ---------------------------------------------------------------------------
       
   589 // CVtUiComponentManager::TStateListItem::SetState
       
   590 // ---------------------------------------------------------------------------
       
   591 //
       
   592 void CVtUiComponentManager::TStateListItem::SetState(
       
   593     TVtUiComponentState::TState aState )
       
   594     {
       
   595     iState = aState;
       
   596     }
       
   597 
       
   598 // ---------------------------------------------------------------------------
       
   599 // CVtUiComponentManager::TStateListItem::BlockList
       
   600 // ---------------------------------------------------------------------------
       
   601 //
       
   602 const TVtUiBlockList& CVtUiComponentManager::TStateListItem::BlockList() const
       
   603     {
       
   604     return iBlockList;
       
   605     }
       
   606 
       
   607 // ---------------------------------------------------------------------------
       
   608 // CVtUiComponentManager::TStateListItem::SetRoot
       
   609 // ---------------------------------------------------------------------------
       
   610 //
       
   611 void CVtUiComponentManager::TStateListItem::SetRoot()
       
   612     {
       
   613     iIsRoot = ETrue;
       
   614     }
       
   615 
       
   616 // ---------------------------------------------------------------------------
       
   617 // CVtUiComponentManager::TStateListItem::IsRoot
       
   618 // ---------------------------------------------------------------------------
       
   619 //
       
   620 TBool CVtUiComponentManager::TStateListItem::IsRoot() const
       
   621     {
       
   622     return iIsRoot;
       
   623     }
       
   624 
       
   625 // ---------------------------------------------------------------------------
       
   626 // CVtUiComponentManager::TStateListItem::SetVisited
       
   627 // ---------------------------------------------------------------------------
       
   628 //
       
   629 void CVtUiComponentManager::TStateListItem::SetVisited()
       
   630     {
       
   631     iIsVisited = ETrue;
       
   632     }
       
   633 
       
   634 // ---------------------------------------------------------------------------
       
   635 // CVtUiComponentManager::TStateListItem::IsVisited
       
   636 // ---------------------------------------------------------------------------
       
   637 //
       
   638 TBool CVtUiComponentManager::TStateListItem::IsVisited() const
       
   639     {
       
   640     return iIsVisited;
       
   641     }
       
   642 
       
   643 // ---------------------------------------------------------------------------
       
   644 // CVtUiComponentManager::TStateListItem::KeyOrder
       
   645 // ---------------------------------------------------------------------------
       
   646 //
       
   647 CVtUiComponentManager::TStateListItem::TKeyCmpFunc
       
   648 CVtUiComponentManager::TStateListItem::KeyOrder()
       
   649     {
       
   650     return KeyCmpFunc;
       
   651     }
       
   652 
       
   653 // ---------------------------------------------------------------------------
       
   654 // CVtUiComponentManager::TStateListItem::LinearOrder
       
   655 // ---------------------------------------------------------------------------
       
   656 //
       
   657 TLinearOrder< CVtUiComponentManager::TStateListItem >
       
   658 CVtUiComponentManager::TStateListItem::LinearOrder()
       
   659     {
       
   660     return TLinearOrder< TStateListItem >( ItemCmpFunc );
       
   661     }
       
   662 
       
   663 // ---------------------------------------------------------------------------
       
   664 // CVtUiComponentManager::TStateListItem::StateOrder
       
   665 // ---------------------------------------------------------------------------
       
   666 //
       
   667 TLinearOrder< CVtUiComponentManager::TStateListItem >
       
   668 CVtUiComponentManager::TStateListItem::StateOrder()
       
   669     {
       
   670     return TLinearOrder< TStateListItem >( StateCmpFunc );
       
   671     }
       
   672 
       
   673 // ---------------------------------------------------------------------------
       
   674 // CVtUiComponentManager::TStateListItem::ItemCmpFunc
       
   675 // ---------------------------------------------------------------------------
       
   676 //
       
   677 TInt CVtUiComponentManager::TStateListItem::ItemCmpFunc(
       
   678     const TStateListItem& aItem1, const TStateListItem& aItem2 )
       
   679     {
       
   680     return ( aItem1.ComponentId() - aItem2.ComponentId() );
       
   681     }
       
   682 
       
   683 // ---------------------------------------------------------------------------
       
   684 // CVtUiComponentManager::TStateListItem::KeyCmpFunc
       
   685 // ---------------------------------------------------------------------------
       
   686 //
       
   687 TInt CVtUiComponentManager::TStateListItem::KeyCmpFunc(
       
   688     const MVtUiComponent::TComponentId* aKey, const TStateListItem& aItem )
       
   689     {
       
   690     return ( *aKey - aItem.ComponentId() );
       
   691     }
       
   692 
       
   693 // ---------------------------------------------------------------------------
       
   694 // CVtUiComponentManager::TStateListItem::StateCmpFunc
       
   695 // ---------------------------------------------------------------------------
       
   696 //
       
   697 TInt CVtUiComponentManager::TStateListItem::StateCmpFunc(
       
   698     const TStateListItem& aItem1, const TStateListItem& aItem2 )
       
   699     {
       
   700     return ( aItem1.State() - aItem2.State() );
       
   701     }
       
   702 // Implementation of CVtUiComponentManager::TStateList
       
   703 
       
   704 // ---------------------------------------------------------------------------
       
   705 // CVtUiComponentManager::TStateList::TStateList
       
   706 // ---------------------------------------------------------------------------
       
   707 //
       
   708 CVtUiComponentManager::TStateList::TStateList() : iItems( 1 )
       
   709     {
       
   710     }
       
   711 
       
   712 // ---------------------------------------------------------------------------
       
   713 // CVtUiComponentManager::TStateList::~TStateList
       
   714 // ---------------------------------------------------------------------------
       
   715 //
       
   716 CVtUiComponentManager::TStateList::~TStateList()
       
   717     {
       
   718     iItems.Close();
       
   719     }
       
   720 
       
   721 // ---------------------------------------------------------------------------
       
   722 // CVtUiComponentManager::TStateList::AddItemL
       
   723 // ---------------------------------------------------------------------------
       
   724 //
       
   725 void CVtUiComponentManager::TStateList::AddItemL( TStateListItem& aItem )
       
   726     {
       
   727     iItems.InsertInOrderL( aItem, TStateListItem::LinearOrder() );
       
   728     }
       
   729 
       
   730 // ---------------------------------------------------------------------------
       
   731 // CVtUiComponentManager::TStateList::ItemCount
       
   732 // ---------------------------------------------------------------------------
       
   733 //
       
   734 TInt CVtUiComponentManager::TStateList::ItemCount() const
       
   735     {
       
   736     return iItems.Count();
       
   737     }
       
   738 
       
   739 // ---------------------------------------------------------------------------
       
   740 // CVtUiComponentManager::TStateList::FindItem
       
   741 // ---------------------------------------------------------------------------
       
   742 //
       
   743 TInt CVtUiComponentManager::TStateList::FindItem(
       
   744     MVtUiComponent::TComponentId aComponentId ) const
       
   745     {
       
   746     return iItems.FindInOrder( aComponentId, TStateListItem::KeyOrder() );
       
   747     }
       
   748 
       
   749 // ---------------------------------------------------------------------------
       
   750 // CVtUiComponentManager::TStateList::At
       
   751 // ---------------------------------------------------------------------------
       
   752 //
       
   753 CVtUiComponentManager::TStateListItem&
       
   754 CVtUiComponentManager::TStateList::At( TInt aIndex )
       
   755     {
       
   756     return iItems[ aIndex ];
       
   757     }
       
   758 
       
   759 // ---------------------------------------------------------------------------
       
   760 // CVtUiComponentManager::TStateList::At
       
   761 // ---------------------------------------------------------------------------
       
   762 //
       
   763 const CVtUiComponentManager::TStateListItem&
       
   764 CVtUiComponentManager::TStateList::At( TInt aIndex ) const
       
   765     {
       
   766     return iItems[ aIndex ];
       
   767     }
       
   768 
       
   769 // ---------------------------------------------------------------------------
       
   770 // CVtUiComponentManager::TStateList::Sort
       
   771 // ---------------------------------------------------------------------------
       
   772 //
       
   773 void CVtUiComponentManager::TStateList::Sort(
       
   774     TLinearOrder< CVtUiComponentManager::TStateListItem > aOrder )
       
   775     {
       
   776     iItems.Sort( aOrder );
       
   777     }