idlehomescreen/xmluirendering/uiengine/src/xnviewmanager.cpp
changeset 0 f72a12da539e
child 1 5315654608de
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  View Manager
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <AknUtils.h>
       
    20 #include <AknsWallpaperUtils.h>
       
    21 #include <AknSkinsInternalCRKeys.h>
       
    22 #include <StringLoader.h>
       
    23 #include <xnuiengine.rsg>
       
    24 #include <aknnotewrappers.h>
       
    25 
       
    26 #if 0 // MSK icon change
       
    27 #include <AknsConstants.h>
       
    28 #include <avkon.mbg>
       
    29 #endif // MSK icon change
       
    30 
       
    31 // User includes
       
    32 #include "xnapplication.h"
       
    33 #include "xnuiengine.h"
       
    34 #include "xnproperty.h"
       
    35 #include "xndomnode.h"
       
    36 #include "xndomlist.h"
       
    37 #include "xnnode.h"
       
    38 #include "xncomposer.h"
       
    39 #include "xneditor.h"
       
    40 #include "xnrootdata.h"
       
    41 #include "xnviewdata.h"
       
    42 #include "xnappuiadapter.h"
       
    43 #include "xncontroladapter.h"
       
    44 #include "xnviewnodeimpl.h"
       
    45 #include "xnviewadapter.h"
       
    46 #include "xnodt.h"
       
    47 #include "xndomdocument.h"
       
    48 #include "xntype.h"
       
    49 #include "xntext.h"
       
    50 #include "xnpanic.h"
       
    51 #include "xnmenu.h"
       
    52 #include "xnmenuadapter.h"
       
    53 #include "xncomponentnodeimpl.h"
       
    54 #include "xnnodepluginif.h"
       
    55 #include "xnoomsyshandler.h"
       
    56 
       
    57 // Constants
       
    58 _LIT8( KEmptyWidgetUid, "0x2001f47f" );
       
    59 _LIT8( KViewSwitcherText, "switcher_text" );
       
    60 _LIT8( KStateError, "Error" );
       
    61 _LIT8( KMax, "max" );
       
    62 
       
    63 _LIT8( KTemplateViewUID, "0x20026f50" );
       
    64 
       
    65 enum
       
    66     {
       
    67     EFirstPassDrawComplete,
       
    68     EDataPluginsComplete,
       
    69     EViewIsValid,       
       
    70     };
       
    71 
       
    72 const TInt KMinPages = 1;
       
    73 
       
    74 
       
    75 #if 0 // MSK icon change
       
    76 
       
    77 const TInt KIconIds[] = {
       
    78         EMbmAvkonQgnQgn_home_page_11,
       
    79         EMbmAvkonQgnQgn_home_page_21,
       
    80         EMbmAvkonQgnQgn_home_page_22,
       
    81         EMbmAvkonQgnQgn_home_page_31,
       
    82         EMbmAvkonQgnQgn_home_page_32,
       
    83         EMbmAvkonQgnQgn_home_page_33,
       
    84         EMbmAvkonQgnQgn_home_page_41,
       
    85         EMbmAvkonQgnQgn_home_page_42,
       
    86         EMbmAvkonQgnQgn_home_page_43,
       
    87         EMbmAvkonQgnQgn_home_page_44,
       
    88         EMbmAvkonQgnQgn_home_page_51,
       
    89         EMbmAvkonQgnQgn_home_page_52,
       
    90         EMbmAvkonQgnQgn_home_page_53,
       
    91         EMbmAvkonQgnQgn_home_page_54,
       
    92         EMbmAvkonQgnQgn_home_page_55,
       
    93         EMbmAvkonQgnQgn_home_page_61,
       
    94         EMbmAvkonQgnQgn_home_page_62,
       
    95         EMbmAvkonQgnQgn_home_page_63,
       
    96         EMbmAvkonQgnQgn_home_page_64,
       
    97         EMbmAvkonQgnQgn_home_page_65,
       
    98         EMbmAvkonQgnQgn_home_page_66
       
    99         };
       
   100 
       
   101 const TInt KMaskIds[] = {
       
   102         EMbmAvkonQgnQgn_home_page_11_mask,
       
   103         EMbmAvkonQgnQgn_home_page_21_mask,
       
   104         EMbmAvkonQgnQgn_home_page_22_mask,
       
   105         EMbmAvkonQgnQgn_home_page_31_mask,
       
   106         EMbmAvkonQgnQgn_home_page_32_mask,
       
   107         EMbmAvkonQgnQgn_home_page_33_mask,
       
   108         EMbmAvkonQgnQgn_home_page_41_mask,
       
   109         EMbmAvkonQgnQgn_home_page_42_mask,
       
   110         EMbmAvkonQgnQgn_home_page_43_mask,
       
   111         EMbmAvkonQgnQgn_home_page_44_mask,
       
   112         EMbmAvkonQgnQgn_home_page_51_mask,
       
   113         EMbmAvkonQgnQgn_home_page_52_mask,
       
   114         EMbmAvkonQgnQgn_home_page_53_mask,
       
   115         EMbmAvkonQgnQgn_home_page_54_mask,
       
   116         EMbmAvkonQgnQgn_home_page_55_mask,
       
   117         EMbmAvkonQgnQgn_home_page_61_mask,
       
   118         EMbmAvkonQgnQgn_home_page_62_mask,
       
   119         EMbmAvkonQgnQgn_home_page_63_mask,
       
   120         EMbmAvkonQgnQgn_home_page_64_mask,
       
   121         EMbmAvkonQgnQgn_home_page_65_mask,
       
   122         EMbmAvkonQgnQgn_home_page_66_mask
       
   123         };
       
   124 
       
   125 const TAknsItemID KSkinIds[] = {            
       
   126         KAknsIIDQgnHomePage11,
       
   127         KAknsIIDQgnHomePage21,
       
   128         KAknsIIDQgnHomePage22,
       
   129         KAknsIIDQgnHomePage31,
       
   130         KAknsIIDQgnHomePage32,
       
   131         KAknsIIDQgnHomePage33,
       
   132         KAknsIIDQgnHomePage41,
       
   133         KAknsIIDQgnHomePage42,
       
   134         KAknsIIDQgnHomePage43,
       
   135         KAknsIIDQgnHomePage44,
       
   136         KAknsIIDQgnHomePage51,
       
   137         KAknsIIDQgnHomePage52,
       
   138         KAknsIIDQgnHomePage53,
       
   139         KAknsIIDQgnHomePage54,
       
   140         KAknsIIDQgnHomePage55,
       
   141         KAknsIIDQgnHomePage61,
       
   142         KAknsIIDQgnHomePage62,
       
   143         KAknsIIDQgnHomePage63,
       
   144         KAknsIIDQgnHomePage64,
       
   145         KAknsIIDQgnHomePage65,
       
   146         KAknsIIDQgnHomePage66
       
   147         };
       
   148 
       
   149 #endif // MSK icon change
       
   150 
       
   151 
       
   152 // ============================ LOCAL FUNCTIONS ===============================
       
   153 
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // BuildTriggerL
       
   157 // Builds a trigger node
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 static CXnNode* BuildTriggerL( CXnUiEngine& aUiEngine,
       
   161     const TDesC8& aStringValue )
       
   162     {
       
   163     CXnNode* node = CXnNode::NewL();
       
   164     CleanupStack::PushL( node );
       
   165 
       
   166     CXnType* type = CXnType::NewL( XnPropertyNames::action::KTrigger );
       
   167     CleanupStack::PushL( type );
       
   168 
       
   169     CXnNodeImpl* impl = CXnNodeImpl::NewL( type );
       
   170     CleanupStack::Pop( type );
       
   171 
       
   172     node->SetImpl( impl );
       
   173     node->SetUiEngine( aUiEngine );
       
   174 
       
   175     CXnDomStringPool& sp( aUiEngine.ODT()->DomDocument().StringPool() );
       
   176 
       
   177     CXnProperty* name = CXnProperty::NewL(
       
   178         XnPropertyNames::action::trigger::KName, aStringValue,
       
   179         CXnDomPropertyValue::EString, sp );
       
   180 
       
   181     CleanupStack::PushL( name );
       
   182     node->SetPropertyL( name );
       
   183     CleanupStack::Pop( name );
       
   184 
       
   185     CXnProperty* value = CXnProperty::NewL(
       
   186         XnPropertyNames::action::KValue,
       
   187         KNullDesC8, CXnDomPropertyValue::EString, sp );
       
   188 
       
   189     CleanupStack::PushL( value );
       
   190     node->SetPropertyL( value );
       
   191     CleanupStack::Pop( value );
       
   192 
       
   193     CleanupStack::Pop( node ); 
       
   194 
       
   195     return node;
       
   196     }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // SetOnlineStateL
       
   200 // 
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 static void SetOnlineStateL( CXnAppUiAdapter& aAdapter, 
       
   204     CXnViewData& aViewData )
       
   205     {
       
   206     if( !aViewData.Active() )
       
   207         {
       
   208         // Only active view can change online/offline state
       
   209         return;
       
   210         }
       
   211     
       
   212     RPointerArray< CXnNode > nodes;
       
   213     CleanupClosePushL( nodes );
       
   214 
       
   215     RPointerArray< CXnNodeAppIf > list;
       
   216     CleanupClosePushL( list );
       
   217 
       
   218     aViewData.ContentSourceNodesL( nodes );
       
   219 
       
   220     for ( TInt i = 0; i < nodes.Count(); i++ )
       
   221         {
       
   222         list.AppendL( &nodes[i]->AppIfL() );
       
   223         }
       
   224 
       
   225     aAdapter.SetOnlineStateL( list );
       
   226 
       
   227     CleanupStack::PopAndDestroy( 2, &nodes ); // &list                                                 
       
   228     }
       
   229 
       
   230 // ============================ MEMBER FUNCTIONS ===============================
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CXnViewManager::NewL()
       
   234 // Two-phased constructor.
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 CXnViewManager* CXnViewManager::NewL( CXnAppUiAdapter& aAdapter )    
       
   238     {
       
   239     CXnViewManager* self = CXnViewManager::NewLC( aAdapter );
       
   240     CleanupStack::Pop( self );
       
   241     return self;
       
   242     }
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // CXnViewManager::NewLC()
       
   246 // Two-phased constructor.
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 CXnViewManager* CXnViewManager::NewLC( CXnAppUiAdapter& aAdapter )
       
   250     {
       
   251     CXnViewManager* self = new( ELeave ) CXnViewManager( aAdapter );
       
   252     CleanupStack::PushL( self );
       
   253     self->ConstructL();
       
   254     return self;
       
   255     }
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // CXnViewManager::CXnViewManager()
       
   259 // C++ default constructor
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 CXnViewManager::CXnViewManager( CXnAppUiAdapter& aAdapter ) 
       
   263     : iAppUiAdapter( aAdapter ), 
       
   264       iApplicationUid( iAppUiAdapter.Application()->AppDllUid() )
       
   265     {
       
   266     }
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 // CXnViewManager::~CXnViewManager()
       
   270 // C++ default destructor.
       
   271 // -----------------------------------------------------------------------------
       
   272 //
       
   273 CXnViewManager::~CXnViewManager()
       
   274     {
       
   275     iObservers.Reset();
       
   276     
       
   277     delete iRootData;
       
   278     
       
   279     delete iWidgetAmountTrigger;       
       
   280 
       
   281     if ( iResources )
       
   282         {
       
   283         iResources->Reset();
       
   284         }
       
   285     
       
   286     delete iResources;
       
   287 
       
   288     iControls.Reset();
       
   289     iAppearanceNodes.Reset();
       
   290        
       
   291     iFailedPlugins.Reset();
       
   292     
       
   293     delete iComposer;
       
   294     delete iEditor;
       
   295     delete iOomSysHandler;
       
   296     }
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CXnViewManager::ConstructL()
       
   300 // 2nd phase constructor
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 void CXnViewManager::ConstructL()
       
   304     {
       
   305     iOomSysHandler = CXnOomSysHandler::NewL();
       
   306     
       
   307     // Create resource list
       
   308     iResources = new ( ELeave ) CArrayPtrSeg< CXnResource > ( 16 );
       
   309        
       
   310     const TInt KMaxUidLength( 10 );
       
   311     _LIT8( KUint, "%u" );
       
   312 
       
   313     TBuf8< KMaxUidLength > uid;
       
   314     uid.Format( KUint, iApplicationUid.iUid );
       
   315     
       
   316     iEditor = CXnEditor::NewL( *this, uid );
       
   317 
       
   318     iHspsWrapper = &iEditor->HspsWrapper();
       
   319     
       
   320     iComposer = CXnComposer::NewL( *iHspsWrapper );
       
   321     }
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 // CXnViewManager::LoadUiL()
       
   325 // Loads the application UI and initial view
       
   326 // -----------------------------------------------------------------------------
       
   327 //
       
   328 void CXnViewManager::LoadUiL()
       
   329     {
       
   330     iUiEngine->DisableRenderUiLC();
       
   331     
       
   332     // Load application root configuration
       
   333     iRootData = CXnRootData::NewL( *this, iApplicationUid );
       
   334            
       
   335     // Load root configuration and initial view.
       
   336     iRootData->LoadL();
       
   337     
       
   338     CleanupStack::PopAndDestroy(); // DisableRenderUiLC();
       
   339     }
       
   340 
       
   341 // -----------------------------------------------------------------------------
       
   342 // CXnViewManager::ReloadUiL()
       
   343 // Reloads the application UI and initial ivew
       
   344 // -----------------------------------------------------------------------------
       
   345 void CXnViewManager::ReloadUiL()  
       
   346     {
       
   347 #ifdef _XN_PERFORMANCE_TEST_
       
   348     RDebug::Print( _L( "CXnViewManager::ReloadUiL() - start" ) );
       
   349 #endif //_XN_PERFORMANCE_TEST_
       
   350     
       
   351     NotifyViewDeactivatedL( ActiveViewData() );
       
   352     
       
   353     delete iWidgetAmountTrigger;
       
   354     iWidgetAmountTrigger = NULL;
       
   355           
       
   356     // Destroy active view data
       
   357     ActiveViewData().Destroy();
       
   358          
       
   359     // Schedule application configuration destroyal
       
   360     iRootData->Destroy();
       
   361     iRootData = NULL;
       
   362     
       
   363     iFlags.ClearAll();
       
   364     
       
   365     User::Heap().Compress();
       
   366     
       
   367     LoadUiL();
       
   368     
       
   369     // Activate first view from the new configuration
       
   370     iAppUiAdapter.ViewAdapter().ActivateContainerL( ActiveViewData() );    
       
   371    
       
   372 #ifdef _XN_PERFORMANCE_TEST_
       
   373     RDebug::Print( _L( "CXnViewManager::ReloadUiL() - end" ) );
       
   374 #endif //_XN_PERFORMANCE_TEST_
       
   375     }
       
   376 
       
   377 // -----------------------------------------------------------------------------
       
   378 // CXnViewManager::LoadWidgetToPluginL()
       
   379 // -----------------------------------------------------------------------------
       
   380 //
       
   381 TInt CXnViewManager::LoadWidgetToPluginL( CHsContentInfo& aContentInfo,
       
   382     CXnPluginData& aPluginData )
       
   383     {
       
   384     // Plugin must not have widget when about to add
       
   385     if ( aPluginData.Occupied() )
       
   386         {
       
   387         return KErrAlreadyExists;
       
   388         }
       
   389 
       
   390     CXnViewData& viewData( 
       
   391         static_cast< CXnViewData& >( *aPluginData.Parent() ) );
       
   392 
       
   393     TBool emptyInUse( viewData.UseEmptyWidget() );
       
   394             
       
   395     // By default widget is added to active view configuration
       
   396     const TDesC8& configurationId( viewData.ConfigurationId() );
       
   397 
       
   398     TInt retval( KErrGeneral );
       
   399               
       
   400     if ( emptyInUse && aPluginData.Empty() )
       
   401         {
       
   402         retval = iHspsWrapper->ReplacePluginL( 
       
   403             aPluginData.PluginId(), aContentInfo.Uid() );   
       
   404         
       
   405         if( retval == KErrDiskFull )
       
   406             {
       
   407             ShowDiskFullMessageL();
       
   408             }
       
   409         }
       
   410     else
       
   411         {
       
   412         TInt index( viewData.PluginData().Find( &aPluginData ) );
       
   413         
       
   414         CAddPluginResult* result = iHspsWrapper->AddPluginL( 
       
   415             configurationId, aContentInfo.Uid(), index );
       
   416     
       
   417         CleanupStack::PushL( result );
       
   418         
       
   419         retval = result->Status();        
       
   420         if ( retval == KErrNone )
       
   421             {
       
   422             aPluginData.SetPluginIdL( result->PluginId() );
       
   423             }
       
   424         else if( retval == KErrDiskFull )
       
   425             {
       
   426             ShowDiskFullMessageL();
       
   427             }        
       
   428         
       
   429         CleanupStack::PopAndDestroy( result ); 
       
   430         }
       
   431              
       
   432     if ( retval == KErrNone )
       
   433         {              
       
   434         iUiEngine->DisableRenderUiLC();
       
   435                                      
       
   436         NotifyConfigureWidgetL( aContentInfo, aPluginData );
       
   437     
       
   438         aPluginData.LoadL();
       
   439                    
       
   440         UpdateCachesL();
       
   441     
       
   442         NotifyWidgetAdditionL( aPluginData );
       
   443 
       
   444         // Report widget amount in the view
       
   445         ReportWidgetAmountL( viewData );
       
   446         
       
   447         CleanupStack::PopAndDestroy(); // DisableRenderUiLC
       
   448         }
       
   449            
       
   450     return retval;
       
   451     }
       
   452 
       
   453 // -----------------------------------------------------------------------------
       
   454 // CXnViewManager::UnloadWidgetFromPluginL()
       
   455 // -----------------------------------------------------------------------------
       
   456 //
       
   457 TInt CXnViewManager::UnloadWidgetFromPluginL( CXnPluginData& aPluginData )    
       
   458     {          
       
   459     TBool error( aPluginData.PluginState().CompareF( KStateError ) == 0 );
       
   460     
       
   461     // Plugins in error state are always removed
       
   462     if ( !error && !aPluginData.Occupied() )
       
   463         {
       
   464         // Plugin must have widget when about to remove
       
   465         return KErrNotFound;            
       
   466         }
       
   467     
       
   468     CXnViewData& viewData( 
       
   469         static_cast< CXnViewData& >( *aPluginData.Parent() ) );
       
   470     
       
   471     TBool emptyInUse( viewData.UseEmptyWidget() );
       
   472     
       
   473     TInt retval( KErrGeneral );
       
   474     
       
   475     // Save temporary
       
   476     TBuf8< 32 > id( aPluginData.PluginId() );
       
   477            
       
   478     if ( emptyInUse )
       
   479         {
       
   480         retval = iHspsWrapper->ReplacePluginL( 
       
   481             aPluginData.PluginId(), KEmptyWidgetUid );                       
       
   482         }
       
   483     else 
       
   484         {        
       
   485         retval = iHspsWrapper->RemovePluginL( aPluginData.PluginId() );
       
   486         }
       
   487        
       
   488     if ( retval == KErrNone )
       
   489         {
       
   490         TBool active( aPluginData.Active() );
       
   491         
       
   492         iUiEngine->DisableRenderUiLC();
       
   493         
       
   494         NotifyWidgetRemovalL( aPluginData );
       
   495                  
       
   496         aPluginData.Destroy();
       
   497         
       
   498         if ( emptyInUse )
       
   499             {
       
   500             // Write id back for for later usage
       
   501             aPluginData.SetEmptyL( id );
       
   502             }
       
   503         else
       
   504             {
       
   505             // Reorder plugindata array
       
   506             RPointerArray< CXnPluginData >& plugins( viewData.PluginData() ); 
       
   507                 
       
   508             TInt index( plugins.Find( &aPluginData ) );
       
   509 
       
   510             plugins.Remove( index );
       
   511             plugins.Insert( &aPluginData, plugins.Count() - 1 );                                           
       
   512             }
       
   513                                                            
       
   514         UpdateCachesL();
       
   515 
       
   516         // Report widget amount in the view 
       
   517         ReportWidgetAmountL( viewData );
       
   518         
       
   519         if ( active )
       
   520             {            
       
   521             iUiEngine->RenderUIL();
       
   522             SetOnlineStateL( iAppUiAdapter, ActiveViewData() );
       
   523             }
       
   524                
       
   525         CleanupStack::PopAndDestroy(); // DisableRenderUiLC               
       
   526         }
       
   527 
       
   528     return retval;
       
   529     }
       
   530 
       
   531 // -----------------------------------------------------------------------------
       
   532 // CXnViewManager::ReplaceWidgetToPluginL
       
   533 // -----------------------------------------------------------------------------
       
   534 //
       
   535 TInt CXnViewManager::ReplaceWidgetToPluginL( CHsContentInfo& aContentInfo,
       
   536     CXnPluginData& aPluginData, TBool aUseHsps )
       
   537     {
       
   538     TInt ret = KErrNone;
       
   539     
       
   540     // if aUseHsps is false, the plugin was already replaced by
       
   541     // another process
       
   542     if( aUseHsps )
       
   543         {
       
   544         ret = iHspsWrapper->ReplacePluginL( aPluginData.PluginId(),
       
   545                                            aContentInfo.Uid() );
       
   546         }
       
   547 
       
   548     if ( ret == KErrNone )
       
   549         {
       
   550         iUiEngine->DisableRenderUiLC();
       
   551         
       
   552         NotifyWidgetRemovalL( aPluginData );
       
   553 
       
   554         TBuf8< 32 > id( aPluginData.PluginId() );
       
   555         TBuf8< 32 > uid( aContentInfo.Uid() );
       
   556         
       
   557         aPluginData.Destroy();
       
   558                         
       
   559         UpdateCachesL();
       
   560         aPluginData.SetPluginIdL( id );
       
   561         
       
   562         NotifyConfigureWidgetL( aContentInfo, aPluginData );
       
   563         
       
   564         aPluginData.LoadL();
       
   565                                                                   
       
   566         UpdateCachesL();
       
   567         
       
   568         // notify addition if not replaced with empty widget
       
   569         // NotifyWidgetAdditionL will call RenderUIL()
       
   570         if( uid != KEmptyWidgetUid )
       
   571             {
       
   572             NotifyWidgetAdditionL( aPluginData );
       
   573             }
       
   574         else
       
   575             {
       
   576             if( aPluginData.Active() )
       
   577                 {
       
   578                 iUiEngine->RenderUIL();
       
   579                 }
       
   580             }
       
   581         
       
   582         CleanupStack::PopAndDestroy(); // DisableRenderUiLC
       
   583         }
       
   584     
       
   585     return ret;
       
   586     }
       
   587 
       
   588 // -----------------------------------------------------------------------------
       
   589 // CXnViewManager::ODT()
       
   590 // Get the ODT
       
   591 // -----------------------------------------------------------------------------
       
   592 //
       
   593 CXnODT* CXnViewManager::ODT() const
       
   594     {
       
   595     return iRootData->ODT();
       
   596     }
       
   597 
       
   598 // -----------------------------------------------------------------------------
       
   599 // CXnViewManager::RootNode()
       
   600 // Finds the root node 
       
   601 // -----------------------------------------------------------------------------
       
   602 //
       
   603 CXnNode* CXnViewManager::RootNode() const
       
   604     {
       
   605     return iRootData->RootNode();
       
   606     }
       
   607 
       
   608 // -----------------------------------------------------------------------------
       
   609 // CXnViewManager::ViewNode()
       
   610 // Finds the view node from active view data
       
   611 // -----------------------------------------------------------------------------
       
   612 //
       
   613 CXnNode* CXnViewManager::ViewNode() const
       
   614     {
       
   615     return ActiveViewData().ViewNode();
       
   616     }
       
   617 
       
   618 // -----------------------------------------------------------------------------
       
   619 // CXnViewManager::Parser()
       
   620 // Gets ODT parser
       
   621 // -----------------------------------------------------------------------------
       
   622 //
       
   623 CXnODTParser& CXnViewManager::Parser() const
       
   624     {
       
   625     return iRootData->Parser();
       
   626     }
       
   627 
       
   628 // -----------------------------------------------------------------------------
       
   629 // CXnViewManager::EcomHandler()
       
   630 // Gets Ecom handler
       
   631 // -----------------------------------------------------------------------------
       
   632 //
       
   633 CXnEcomHandler& CXnViewManager::EcomHandler() const
       
   634     {
       
   635     return iRootData->EcomHandler();
       
   636     }
       
   637 
       
   638 // -----------------------------------------------------------------------------
       
   639 // CXnViewManager::Controls()
       
   640 // Finds the controls from active view data
       
   641 // -----------------------------------------------------------------------------
       
   642 //
       
   643 const RPointerArray< CXnControlAdapter >& CXnViewManager::Controls() const
       
   644     {
       
   645     return iControls;
       
   646     }
       
   647 
       
   648 // -----------------------------------------------------------------------------
       
   649 // CXnViewManager::PluginNodes()
       
   650 // Finds the plugin nodes from active view data
       
   651 // -----------------------------------------------------------------------------
       
   652 //
       
   653 RPointerArray< CXnNode >& CXnViewManager::PluginNodes() const
       
   654     {
       
   655     // These must be fetched from layout tree to get correct order of plugins
       
   656     CXnViewData& activeViewData( ActiveViewData() );
       
   657 
       
   658     // Get first plugin data
       
   659     CXnPluginData* pluginData( activeViewData.PluginData()[0] );
       
   660     CXnNode* parent( pluginData->Owner()->LayoutNode()->Parent() );
       
   661 
       
   662     // This assumes that the parent has only "plugin" nodes as its children
       
   663     RPointerArray< CXnNode >& children( parent->Children() );
       
   664 
       
   665     return children;
       
   666     }
       
   667 
       
   668 // -----------------------------------------------------------------------------
       
   669 // CXnViewManager::PluginDataL()
       
   670 // 
       
   671 // -----------------------------------------------------------------------------
       
   672 //
       
   673 void CXnViewManager::PluginDataL( RPointerArray< CXnPluginData >& aList, 
       
   674     TBool aGlobal ) const
       
   675     {
       
   676     if ( aGlobal )
       
   677         {
       
   678         RPointerArray< CXnPluginData >& views( iRootData->PluginData() );
       
   679         
       
   680         for ( TInt i = 0; i < views.Count(); i++ )
       
   681             {
       
   682             RPointerArray< CXnPluginData >& plugins( views[i]->PluginData() );
       
   683             
       
   684             for ( TInt j = 0; j < plugins.Count(); j++ )
       
   685                 {
       
   686                 aList.AppendL( plugins[ j ] );
       
   687                 }
       
   688             }            
       
   689         }
       
   690     else
       
   691         {
       
   692         RPointerArray< CXnPluginData >& 
       
   693             plugins( ActiveViewData().PluginData() ); 
       
   694 
       
   695         for ( TInt j = 0; j < plugins.Count(); j++ )
       
   696             {
       
   697             aList.AppendL( plugins[ j ] );
       
   698             }        
       
   699         }
       
   700     }
       
   701 
       
   702 // -----------------------------------------------------------------------------
       
   703 // CXnViewManager::Resources()
       
   704 // Finds the resources from the active view data
       
   705 // -----------------------------------------------------------------------------
       
   706 //
       
   707 CArrayPtrSeg< CXnResource >& CXnViewManager::Resources() const
       
   708     {
       
   709     return *iResources;
       
   710     }
       
   711 
       
   712 // -----------------------------------------------------------------------------
       
   713 // CXnViewManager::AppearanceNodes()
       
   714 // -----------------------------------------------------------------------------
       
   715 //
       
   716 RPointerArray< CXnNode >& CXnViewManager::AppearanceNodes() const
       
   717     {
       
   718     return iAppearanceNodes;
       
   719     }
       
   720 
       
   721 // -----------------------------------------------------------------------------
       
   722 // CXnViewManager::ViewData()
       
   723 // Finds a view data based on a view node
       
   724 // -----------------------------------------------------------------------------
       
   725 //
       
   726 CXnViewData* CXnViewManager::ViewData( CXnNode& aNode ) const
       
   727     {    
       
   728     if ( !aNode.ViewNodeImpl() )
       
   729         {
       
   730         return NULL;
       
   731         }
       
   732 
       
   733     RPointerArray< CXnPluginData >& views( iRootData->PluginData() );
       
   734     
       
   735     for ( TInt i = 0; i < views.Count(); i++ )
       
   736         {
       
   737         if ( views[i]->Occupied() )
       
   738             {
       
   739             if ( views[i]->Node()->LayoutNode() == &aNode )
       
   740                 {
       
   741                 return static_cast< CXnViewData* >( views[ i ] );                
       
   742                 }
       
   743             }
       
   744         }
       
   745 
       
   746     return NULL;
       
   747     }
       
   748 
       
   749 // -----------------------------------------------------------------------------
       
   750 // CXnViewManager::ActiveAppData()
       
   751 // Gets the active app data
       
   752 // -----------------------------------------------------------------------------
       
   753 //
       
   754 CXnRootData& CXnViewManager::ActiveAppData() const
       
   755     {
       
   756     return *iRootData;
       
   757     }
       
   758 
       
   759 // -----------------------------------------------------------------------------
       
   760 // CXnViewManager::ActiveViewData()
       
   761 // Gets the active view data
       
   762 // -----------------------------------------------------------------------------
       
   763 //
       
   764 CXnViewData& CXnViewManager::ActiveViewData() const
       
   765     {
       
   766     return iRootData->ActiveViewData();
       
   767     }
       
   768 
       
   769 // -----------------------------------------------------------------------------
       
   770 // CXnViewManager::PreviousViewData()
       
   771 // Gets the previous view data 
       
   772 // -----------------------------------------------------------------------------
       
   773 //
       
   774 CXnViewData& CXnViewManager::PreviousViewData() const
       
   775     {
       
   776     return iRootData->PreviousViewData();
       
   777     }
       
   778 
       
   779 // -----------------------------------------------------------------------------
       
   780 // CXnViewManager::NextViewData()
       
   781 // Gets the next view data 
       
   782 // -----------------------------------------------------------------------------
       
   783 //
       
   784 CXnViewData& CXnViewManager::NextViewData() const
       
   785     {
       
   786     return iRootData->NextViewData();
       
   787     }
       
   788 
       
   789 // -----------------------------------------------------------------------------
       
   790 // CXnViewManager::ActivateNextViewL()
       
   791 // Activates the next view
       
   792 // -----------------------------------------------------------------------------
       
   793 //
       
   794 void CXnViewManager::ActivateNextViewL()
       
   795     {
       
   796     CXnViewData& current( ActiveViewData() );
       
   797     CXnViewData& next( NextViewData() );
       
   798 
       
   799     if ( !next.Occupied() )
       
   800         {
       
   801         next.LoadL();
       
   802         }
       
   803         
       
   804     // Activate view
       
   805     if ( next.Occupied() )
       
   806         {            
       
   807         iAppUiAdapter.ViewAdapter().ActivateContainerL( next );                
       
   808         }
       
   809     }
       
   810 
       
   811 // -----------------------------------------------------------------------------
       
   812 // CXnViewManager::ActivatePreviousViewL()
       
   813 // Activates the previous view
       
   814 // -----------------------------------------------------------------------------
       
   815 //
       
   816 void CXnViewManager::ActivatePreviousViewL()
       
   817     {
       
   818     CXnViewData& current( ActiveViewData() );
       
   819     CXnViewData& prev( PreviousViewData() );
       
   820 
       
   821     if ( !prev.Occupied() )
       
   822         {
       
   823         prev.LoadL();
       
   824         }
       
   825         
       
   826     // Activate view
       
   827     if ( prev.Occupied() )
       
   828         {   
       
   829         iAppUiAdapter.ViewAdapter().ActivateContainerL( prev );
       
   830         }
       
   831     }
       
   832 
       
   833 // -----------------------------------------------------------------------------
       
   834 // CXnViewManager::AddViewL()
       
   835 // Adds a new view based on info
       
   836 // -----------------------------------------------------------------------------
       
   837 //
       
   838 TInt CXnViewManager::AddViewL( CHsContentInfo& aInfo )
       
   839     {    
       
   840     if ( iRootData->PluginData().Count() >= iRootData->MaxPages() )
       
   841         {
       
   842         return KErrGeneral;
       
   843         }
       
   844 
       
   845     // Add new view (template view) to hsps
       
   846     CAddPluginResult* result = iHspsWrapper->AddPluginL( 
       
   847         iRootData->ConfigurationId(), aInfo.Uid(),
       
   848         ViewIndex() + 1 ); 
       
   849     CleanupStack::PushL( result );
       
   850 
       
   851     TInt retval( result->Status() );
       
   852     
       
   853     if( retval == KErrDiskFull )
       
   854         {
       
   855         ShowDiskFullMessageL();
       
   856         }        
       
   857     else if ( retval == KErrNone )
       
   858         {                             
       
   859         // Create new view        
       
   860         CXnViewData* newView = CXnViewData::NewLC( *iRootData );    
       
   861         
       
   862         newView->SetPluginIdL( result->PluginId() );
       
   863         
       
   864         newView->SetOwner( iRootData->Node() );
       
   865         
       
   866         newView->LoadL();
       
   867                 
       
   868         if ( newView->Occupied() )
       
   869             {
       
   870             // Load succeed, add the new view behind the current view               
       
   871             RPointerArray< CXnPluginData >& views( iRootData->PluginData() );
       
   872             
       
   873             TInt index( views.Find( &ActiveViewData() ) );
       
   874             
       
   875             views.InsertL( newView, index + 1 );
       
   876             
       
   877             // Root data owns the new view now
       
   878             CleanupStack::Pop( newView );            
       
   879 
       
   880             // Inform observers about added view
       
   881             NotifyViewAdditionL( *newView );
       
   882             
       
   883             UpdatePageManagementInformationL();
       
   884             
       
   885             iUiEngine->RenderUIL();
       
   886             }
       
   887         else
       
   888             {                                  
       
   889             // creation failed, remove it from hsps
       
   890             iHspsWrapper->RemovePluginL( result->PluginId() );
       
   891             
       
   892             // ... and destroy it
       
   893             CleanupStack::PopAndDestroy( newView );            
       
   894             
       
   895             retval = KErrGeneral;
       
   896 
       
   897             }
       
   898         }
       
   899 
       
   900     CleanupStack::PopAndDestroy( result );   
       
   901     
       
   902     return retval;
       
   903     }
       
   904 
       
   905 // -----------------------------------------------------------------------------
       
   906 // CXnViewManager::AddViewL()
       
   907 // Adds a new view
       
   908 // -----------------------------------------------------------------------------
       
   909 //
       
   910 void CXnViewManager::AddViewL()
       
   911     {
       
   912     if ( iRootData->PluginData().Count() >= iRootData->MaxPages() ) 
       
   913         { 
       
   914         HBufC* msg( StringLoader::LoadLC( 
       
   915             R_QTN_HS_MAX_AMOUNT_OF_PAGES_NOTE ) ); 
       
   916 
       
   917         CAknErrorNote* note = new ( ELeave ) CAknErrorNote; 
       
   918         CleanupStack::PushL( note ); 
       
   919                
       
   920         note->ExecuteLD( *msg ); 
       
   921                
       
   922         CleanupStack::Pop( note ); 
       
   923         CleanupStack::PopAndDestroy( msg ); 
       
   924 
       
   925         return; 
       
   926         }
       
   927 
       
   928     // Add new view (template view) to hsps
       
   929     CAddPluginResult* result = iHspsWrapper->AddPluginL( 
       
   930         iRootData->ConfigurationId(), KTemplateViewUID,
       
   931         ViewIndex() + 1 ); 
       
   932     CleanupStack::PushL( result );
       
   933         
       
   934     TInt status( result->Status() );
       
   935     
       
   936     if( status == KErrDiskFull )
       
   937         {
       
   938         ShowDiskFullMessageL();
       
   939         }            
       
   940     else if ( status == KErrNone )
       
   941         {                             
       
   942         // Create new view        
       
   943         CXnViewData* newView = CXnViewData::NewLC( *iRootData );    
       
   944         
       
   945         newView->SetPluginIdL( result->PluginId() );
       
   946         
       
   947         newView->SetOwner( iRootData->Node() );
       
   948         
       
   949         newView->LoadL();
       
   950                 
       
   951         if ( newView->Occupied() )
       
   952             {
       
   953             // Load succeed, add the new view behind the current view               
       
   954             RPointerArray< CXnPluginData >& views( iRootData->PluginData() );
       
   955             
       
   956             TInt index( views.Find( &ActiveViewData() ) );
       
   957             
       
   958             views.InsertL( newView, index + 1 );
       
   959             
       
   960             // Root data owns the new view now
       
   961             CleanupStack::Pop( newView );
       
   962             
       
   963             // Activate view
       
   964             iAppUiAdapter.ViewAdapter().ActivateContainerL( *newView, ETrue );
       
   965             
       
   966             // Inform observers about added view
       
   967             NotifyViewAdditionL( *newView );
       
   968             }
       
   969         else
       
   970             {                      
       
   971             // creation failed, remove it from hsps
       
   972             iHspsWrapper->RemovePluginL( result->PluginId() );
       
   973             
       
   974             // ... and destroy it
       
   975             CleanupStack::PopAndDestroy( newView );            
       
   976             }
       
   977         }
       
   978 
       
   979     CleanupStack::PopAndDestroy( result );       
       
   980     }
       
   981 
       
   982 // -----------------------------------------------------------------------------
       
   983 // CXnViewManager::RemoveViewL()
       
   984 // Removes view based info
       
   985 // -----------------------------------------------------------------------------
       
   986 //
       
   987 TInt CXnViewManager::RemoveViewL( const CHsContentInfo& aInfo )
       
   988     {
       
   989     TInt retval( KErrGeneral );
       
   990     
       
   991     if ( iRootData->PluginData().Count() <= 1 )
       
   992         {
       
   993         // Only one page left, not allowed to remove
       
   994         return retval;        
       
   995         }
       
   996     
       
   997     RPointerArray< CXnPluginData >& views( iRootData->PluginData() );
       
   998 
       
   999     for ( TInt i = 0; i < views.Count(); i++ )
       
  1000         {
       
  1001         CXnViewData* view( static_cast< CXnViewData* >( views[i] ) );
       
  1002         
       
  1003         if ( view->PluginId() == aInfo.PluginId() )
       
  1004             {
       
  1005             if ( !view->Removable() )
       
  1006                 {
       
  1007                 return retval;
       
  1008                 }
       
  1009             
       
  1010             if ( view->Active() )
       
  1011                 {
       
  1012                 // Activate the next view, or first if in the last view 
       
  1013                 CXnViewData& next( NextViewData() );
       
  1014                 iAppUiAdapter.ViewAdapter().ActivateContainerL( next );
       
  1015                 }
       
  1016 
       
  1017             retval = iHspsWrapper->RemovePluginL( view->PluginId() );
       
  1018             
       
  1019             // Notify observers of view list change
       
  1020             NotifyViewRemovalL( *view );
       
  1021 
       
  1022             iRootData->DestroyViewData( view );
       
  1023                                                                    
       
  1024             // Need to update after view is removed
       
  1025             UpdatePageManagementInformationL();                
       
  1026                                    
       
  1027             break;
       
  1028             }
       
  1029         }
       
  1030     
       
  1031     return retval;
       
  1032     }
       
  1033 
       
  1034 // -----------------------------------------------------------------------------
       
  1035 // CXnViewManager::RemoveViewL()
       
  1036 // Removes active view if more than one view.
       
  1037 // -----------------------------------------------------------------------------
       
  1038 //
       
  1039 void CXnViewManager::RemoveViewL()
       
  1040     {   
       
  1041     if ( iRootData->PluginData().Count() <= 1 || 
       
  1042         !ActiveViewData().Removable() )
       
  1043         {
       
  1044         // Only one page left, this should not happen,  
       
  1045         // or active view is not removable
       
  1046         return;        
       
  1047         }
       
  1048           
       
  1049     RPointerArray< CXnPluginData >& views( iRootData->PluginData() );
       
  1050     
       
  1051     TInt index( views.Find( &ActiveViewData() ) );
       
  1052            
       
  1053     CAknQueryDialog* query = CAknQueryDialog::NewL(); 
       
  1054     query->PrepareLC( R_YES_NO_HS_REMOVE_VIEW );
       
  1055     
       
  1056     HBufC* queryText( StringLoader::LoadLC( R_QTN_HS_DELETE_PAGE ) ); 
       
  1057     
       
  1058     query->SetPromptL( queryText->Des() );
       
  1059     
       
  1060     CleanupStack::PopAndDestroy( queryText );
       
  1061 
       
  1062     if ( query->RunLD() )
       
  1063         { 
       
  1064         // Activate the next view, or first if in the last view 
       
  1065         CXnViewData& next( NextViewData() );
       
  1066 
       
  1067         iAppUiAdapter.ViewAdapter().ActivateContainerL( next );
       
  1068                 
       
  1069         CXnViewData* view( static_cast< CXnViewData* >( views[ index ] ) );
       
  1070 
       
  1071         // Remove plugin from HSPS
       
  1072         iHspsWrapper->RemovePluginL( view->PluginId() );
       
  1073         
       
  1074         // Notify observers of view list change
       
  1075         NotifyViewRemovalL( *view );
       
  1076 
       
  1077         iRootData->DestroyViewData( view );
       
  1078         
       
  1079         // Need to update after view is removed
       
  1080         UpdatePageManagementInformationL();        
       
  1081         }       
       
  1082     }
       
  1083 
       
  1084 // -----------------------------------------------------------------------------
       
  1085 // CXnViewManager::AddObserver()
       
  1086 // -----------------------------------------------------------------------------
       
  1087 //
       
  1088 void CXnViewManager::AddObserver( const MXnViewObserver& aObserver )
       
  1089     {
       
  1090     TInt index( iObservers.Find( &aObserver ) );
       
  1091 
       
  1092     if ( index == KErrNotFound )
       
  1093         {
       
  1094         iObservers.Append( &aObserver );
       
  1095         }
       
  1096     }
       
  1097 
       
  1098 // -----------------------------------------------------------------------------
       
  1099 // CXnViewManager::RemoveObserver()
       
  1100 // -----------------------------------------------------------------------------
       
  1101 //
       
  1102 void CXnViewManager::RemoveObserver( const MXnViewObserver& aObserver )
       
  1103     {
       
  1104     TInt index( iObservers.Find( &aObserver ) );
       
  1105 
       
  1106     if ( index != KErrNotFound )
       
  1107         {
       
  1108         iObservers.Remove( index );
       
  1109         }
       
  1110     }
       
  1111 
       
  1112 // -----------------------------------------------------------------------------
       
  1113 // CXnViewManager::ActivateAppL()
       
  1114 // Activates application configuration
       
  1115 // -----------------------------------------------------------------------------
       
  1116 TInt CXnViewManager::ActivateAppL( const TDesC8& aPluginUid )
       
  1117     {
       
  1118     if ( aPluginUid == KNullDesC8 )
       
  1119         {
       
  1120         return KErrArgument;
       
  1121         }
       
  1122 
       
  1123     if ( iRootData->PluginUid().Compare( aPluginUid ) == 0 )
       
  1124         {
       
  1125         // Nothing to do
       
  1126         return KErrNone;
       
  1127         }
       
  1128     
       
  1129     return iHspsWrapper->SetAppConfigurationL( aPluginUid );
       
  1130     }
       
  1131 
       
  1132 // -----------------------------------------------------------------------------
       
  1133 // CXnViewManager::ActivateViewL()
       
  1134 // Activates view
       
  1135 // -----------------------------------------------------------------------------
       
  1136 TInt CXnViewManager::ActivateViewL( const TDesC8& aPluginId )
       
  1137     {
       
  1138     if ( aPluginId == KNullDesC8 )
       
  1139         {
       
  1140         return KErrArgument;
       
  1141         }
       
  1142            
       
  1143     CXnViewData& current( ActiveViewData() );
       
  1144        
       
  1145     if ( current.PluginId() == aPluginId )
       
  1146         {
       
  1147         // Nothing to do
       
  1148         return KErrNone;
       
  1149         }
       
  1150 
       
  1151     TInt retval( KErrNotFound );
       
  1152     
       
  1153     RPointerArray< CXnPluginData >& views( iRootData->PluginData() );
       
  1154         
       
  1155     for ( TInt i = 0; i < views.Count(); i++ )
       
  1156         {
       
  1157         CXnViewData* view( static_cast< CXnViewData* >( views[ i ] ) );
       
  1158 
       
  1159         if( view->Occupied() && view->PluginId() == aPluginId )
       
  1160             {
       
  1161             iAppUiAdapter.ViewAdapter().ActivateContainerL( *view );
       
  1162             
       
  1163             retval = KErrNone;
       
  1164             
       
  1165             break;
       
  1166             }
       
  1167         }
       
  1168     
       
  1169     return retval;
       
  1170     }
       
  1171 
       
  1172 // -----------------------------------------------------------------------------
       
  1173 // CXnViewManager::ViewAmount()
       
  1174 // Gets current view amount
       
  1175 // -----------------------------------------------------------------------------
       
  1176 TInt CXnViewManager::ViewAmount() const
       
  1177     {
       
  1178     return iRootData->PluginData().Count();
       
  1179     }
       
  1180 
       
  1181 
       
  1182 // -----------------------------------------------------------------------------
       
  1183 // CXnViewManager::ViewIndex()
       
  1184 // Gets index of current view
       
  1185 // -----------------------------------------------------------------------------
       
  1186 TInt CXnViewManager::ViewIndex() const
       
  1187     {
       
  1188     TInt index( KErrNotFound );
       
  1189     CXnViewData* view = &( ActiveViewData() );
       
  1190     RPointerArray< CXnPluginData >& views( iRootData->PluginData() );
       
  1191     index = views.Find( view );
       
  1192     return index;
       
  1193     }
       
  1194 
       
  1195 // -----------------------------------------------------------------------------
       
  1196 // CXnViewManager::NotifyContainerChangedL()
       
  1197 // Notifies container is changed, this is called always by CXnViewAdapter
       
  1198 // -----------------------------------------------------------------------------
       
  1199 void CXnViewManager::NotifyContainerChangedL( CXnViewData& aViewToActivate )
       
  1200     {
       
  1201 #ifdef _XN_PERFORMANCE_TEST_
       
  1202     RDebug::Print( _L( "CXnViewManager::NotifyContainerChangedL - start" ) );
       
  1203 #endif //_XN_PERFORMANCE_TEST_        
       
  1204               
       
  1205     InvalidateActiveView();
       
  1206     
       
  1207     CXnViewData& viewToDeactivate( ActiveViewData() );
       
  1208     
       
  1209     if ( &aViewToActivate != &viewToDeactivate )
       
  1210         {
       
  1211         // Store focus
       
  1212         CXnNode* focused( iUiEngine->FocusedNode() );
       
  1213         
       
  1214         if ( focused )
       
  1215             {
       
  1216             viewToDeactivate.SetFocusedNode( focused );
       
  1217             }
       
  1218         
       
  1219         NotifyViewDeactivatedL( viewToDeactivate );
       
  1220 
       
  1221         // Switch active view data
       
  1222         iAppUiAdapter.HandlePageSwitch();
       
  1223         
       
  1224         viewToDeactivate.SetActiveL( EFalse );
       
  1225         aViewToActivate.SetActiveL( ETrue );
       
  1226         
       
  1227         iHspsWrapper->SetActivePluginL( aViewToActivate.PluginId() );
       
  1228 
       
  1229         // Cache update is needed after view activation
       
  1230         UpdateCachesL();        
       
  1231         }
       
  1232     else
       
  1233         {
       
  1234         // Activate first view
       
  1235         aViewToActivate.SetActiveL( ETrue );
       
  1236 
       
  1237         // Cache update is needed after view activation
       
  1238         UpdateCachesL();
       
  1239         }
       
  1240     
       
  1241     NotifyViewActivatedL( aViewToActivate );
       
  1242     UpdatePageManagementInformationL();
       
  1243     
       
  1244 #ifdef _XN_PERFORMANCE_TEST_
       
  1245     RDebug::Print( _L( "CXnViewManager::NotifyContainerChangedL - end" ) );
       
  1246 #endif //_XN_PERFORMANCE_TEST_
       
  1247     }
       
  1248 
       
  1249 // -----------------------------------------------------------------------------
       
  1250 // CXnViewManager::NotifyViewActivatedL()
       
  1251 // Notifies view is activated
       
  1252 // -----------------------------------------------------------------------------
       
  1253 //
       
  1254 void CXnViewManager::NotifyViewActivatedL( const CXnViewData& aViewData )
       
  1255     {
       
  1256     // Report widget amount in the view
       
  1257     ReportWidgetAmountL( aViewData );
       
  1258 
       
  1259     for ( TInt i = 0; i < iObservers.Count(); i++ )
       
  1260         {
       
  1261         iObservers[i]->NotifyViewActivatedL( aViewData );
       
  1262         }
       
  1263     }
       
  1264 
       
  1265 // -----------------------------------------------------------------------------
       
  1266 // CXnViewManager::NotifyViewDeactivatedL()
       
  1267 // Notifies view is deactivated
       
  1268 // -----------------------------------------------------------------------------
       
  1269 //
       
  1270 void CXnViewManager::NotifyViewDeactivatedL( const CXnViewData& aViewData )
       
  1271     {
       
  1272     for ( TInt i = 0; i < iObservers.Count(); i++ )
       
  1273         {
       
  1274         iObservers[i]->NotifyViewDeactivatedL( aViewData );
       
  1275         }
       
  1276     }
       
  1277 
       
  1278 // -----------------------------------------------------------------------------
       
  1279 // CXnViewManager::NotifyViewAdditionL()
       
  1280 // Notifies view is added
       
  1281 // -----------------------------------------------------------------------------
       
  1282 //
       
  1283 void CXnViewManager::NotifyViewAdditionL( const CXnViewData& aViewData )
       
  1284     {
       
  1285     for ( TInt i = 0; i < iObservers.Count(); i++ )
       
  1286         {
       
  1287         iObservers[i]->NotifyViewAdditionL( aViewData );
       
  1288         }
       
  1289     }
       
  1290 
       
  1291 // -----------------------------------------------------------------------------
       
  1292 // CXnViewManager::NotifyViewRemovalL()
       
  1293 // Notifies view is removed
       
  1294 // -----------------------------------------------------------------------------
       
  1295 //
       
  1296 void CXnViewManager::NotifyViewRemovalL( const CXnViewData& aViewData )
       
  1297     {
       
  1298     for ( TInt i = 0; i < iObservers.Count(); i++ )
       
  1299         {
       
  1300         iObservers[i]->NotifyViewRemovalL( aViewData );
       
  1301         }
       
  1302     }
       
  1303 
       
  1304 // -----------------------------------------------------------------------------
       
  1305 // CXnViewManager::NotifyConfigureWidgetL()
       
  1306 // Notifies to configure widget
       
  1307 // -----------------------------------------------------------------------------
       
  1308 //
       
  1309 void CXnViewManager::NotifyConfigureWidgetL( const CHsContentInfo& aContentInfo,
       
  1310     CXnPluginData& aPluginData )
       
  1311     {
       
  1312     for ( TInt i = 0; i < iObservers.Count(); i++ )
       
  1313         {
       
  1314         iObservers[i]->NotifyConfigureWidgetL( aContentInfo, aPluginData );
       
  1315         }
       
  1316     
       
  1317     if ( aPluginData.Active() )
       
  1318         {
       
  1319         // Active view configuration is about to change
       
  1320         InvalidateActiveView();
       
  1321         }    
       
  1322     }
       
  1323 
       
  1324 // -----------------------------------------------------------------------------
       
  1325 // CXnViewManager::NotifyWidgetAdditionL()
       
  1326 // Notifys widget is added
       
  1327 // -----------------------------------------------------------------------------
       
  1328 //
       
  1329 void CXnViewManager::NotifyWidgetAdditionL( const CXnPluginData& aPluginData )
       
  1330     {
       
  1331     for ( TInt i = 0; i < iObservers.Count(); i++ )
       
  1332         {
       
  1333         iObservers[i]->NotifyWidgetAdditionL( aPluginData );
       
  1334         }
       
  1335     
       
  1336     if ( aPluginData.Active() )
       
  1337         {
       
  1338         // Update UI appearance after active view configuration is changed
       
  1339         iUiEngine->RenderUIL();
       
  1340         }
       
  1341     }
       
  1342 
       
  1343 // -----------------------------------------------------------------------------
       
  1344 // CXnViewManager::NotifyWidgetRemovalL()
       
  1345 // Notifys widget is removed
       
  1346 // -----------------------------------------------------------------------------
       
  1347 //
       
  1348 void CXnViewManager::NotifyWidgetRemovalL( const CXnPluginData& aPluginData )
       
  1349     {
       
  1350     // This loop is intend to go from "count - 1 to 0", because CXnEditor is
       
  1351     // the first registered observer and it must be notified as the last one
       
  1352     for ( TInt i = iObservers.Count() - 1; i >= 0 ; i-- )
       
  1353         {
       
  1354         iObservers[i]->NotifyWidgetRemovalL( aPluginData ); 
       
  1355         }
       
  1356     }
       
  1357 
       
  1358 // -----------------------------------------------------------------------------
       
  1359 // CXnViewManager::UpdateCachesL()
       
  1360 // -----------------------------------------------------------------------------
       
  1361 //
       
  1362 void CXnViewManager::UpdateCachesL()
       
  1363     {
       
  1364     CXnViewData& activeViewData( ActiveViewData() );
       
  1365     iControls.Reset();
       
  1366     activeViewData.ControlsL( iControls );
       
  1367     iAppearanceNodes.Reset();
       
  1368     activeViewData.AppearanceNodesL( iAppearanceNodes );
       
  1369     iResources->Reset();
       
  1370     activeViewData.ResourcesL( *iResources );
       
  1371     }
       
  1372 
       
  1373 // -----------------------------------------------------------------------------
       
  1374 // CXnViewManager::SetFirstPassDrawCompleteL()
       
  1375 // -----------------------------------------------------------------------------
       
  1376 //
       
  1377 void CXnViewManager::SetFirstPassDrawCompleteL()
       
  1378     {
       
  1379     if ( iFlags.IsClear( EFirstPassDrawComplete ) )
       
  1380         {
       
  1381         iFlags.Set( EFirstPassDrawComplete );
       
  1382         
       
  1383         ValidateActiveViewL();
       
  1384         }    
       
  1385     }
       
  1386 
       
  1387 // -----------------------------------------------------------------------------
       
  1388 // CXnViewManager::SetDataPluginLoadCompleteL()
       
  1389 // -----------------------------------------------------------------------------
       
  1390 //
       
  1391 void CXnViewManager::SetDataPluginLoadCompleteL( 
       
  1392     const CXnPluginData& aPluginData )
       
  1393     {                             
       
  1394     if ( !aPluginData.Active() )
       
  1395         {
       
  1396         // Not interested
       
  1397         return;
       
  1398         }
       
  1399     
       
  1400     if ( ActiveViewData().DataPluginsLoaded() )
       
  1401         {
       
  1402         if ( iFlags.IsClear( EDataPluginsComplete ) )
       
  1403             {
       
  1404             iFlags.Set( EDataPluginsComplete );
       
  1405             
       
  1406             ValidateActiveViewL();
       
  1407             }
       
  1408         }
       
  1409     }
       
  1410 
       
  1411 // -----------------------------------------------------------------------------
       
  1412 // CXnViewManager::ValidateActiveViewL()
       
  1413 // -----------------------------------------------------------------------------
       
  1414 //
       
  1415 void CXnViewManager::ValidateActiveViewL()
       
  1416     {
       
  1417     if ( iFlags.IsSet( EViewIsValid ) )
       
  1418         {
       
  1419         // Already ok
       
  1420         return;
       
  1421         }
       
  1422     
       
  1423     if ( iFlags.IsClear( EFirstPassDrawComplete ) || 
       
  1424          iFlags.IsClear( EDataPluginsComplete ) )
       
  1425         {
       
  1426         // Not able to confirm yet
       
  1427         return;        
       
  1428         }
       
  1429 
       
  1430     RPointerArray< CXnPluginData >& plugins( ActiveViewData().PluginData() );
       
  1431 
       
  1432     TInt count( iFailedPlugins.Count() );
       
  1433         
       
  1434     for ( TInt i = 0; i < plugins.Count(); i++ )
       
  1435         {
       
  1436         CXnPluginData* plugin( plugins[i] );
       
  1437                 
       
  1438         const TDesC8& state( plugin->PluginState() );
       
  1439         
       
  1440         if ( state.CompareF( KStateError ) == 0 && plugin->Removable() )
       
  1441             {
       
  1442             if ( iFailedPlugins.Find( plugin ) == KErrNotFound )
       
  1443                 {
       
  1444                 iFailedPlugins.AppendL( plugin );
       
  1445                 }
       
  1446             }            
       
  1447         }
       
  1448 
       
  1449     // This condition prevents recursion
       
  1450     if ( iFailedPlugins.Count() > 0 && count == 0 )
       
  1451         {
       
  1452         // Disable layout and redraw until all plugins are removed
       
  1453         iUiEngine->DisableRenderUiLC();
       
  1454         
       
  1455         for ( TInt i = 0; i < iFailedPlugins.Count(); i++ )
       
  1456             {
       
  1457             UnloadWidgetFromPluginL( *iFailedPlugins[i] );
       
  1458             }        
       
  1459         
       
  1460         HBufC* msg( StringLoader::LoadLC( R_QTN_HS_ERROR_WIDGETS_REMOVED ) );
       
  1461             
       
  1462         CAknErrorNote* note = new ( ELeave ) CAknErrorNote;
       
  1463         CleanupStack::PushL( note );
       
  1464         
       
  1465         note->ExecuteLD( *msg );
       
  1466         
       
  1467         CleanupStack::Pop( note );
       
  1468         CleanupStack::PopAndDestroy( msg );
       
  1469         
       
  1470         iUiEngine->RenderUIL();
       
  1471 
       
  1472         CleanupStack::PopAndDestroy(); // DisableRenderUiLC()
       
  1473         
       
  1474         iFailedPlugins.Reset();               
       
  1475         }
       
  1476     
       
  1477     // All failed plugins are handled
       
  1478     if( iFailedPlugins.Count() == 0 )
       
  1479         {
       
  1480         iFlags.Set( EViewIsValid );
       
  1481         
       
  1482         SetOnlineStateL( iAppUiAdapter, ActiveViewData() );
       
  1483         
       
  1484         // Remaining views can be now loaded
       
  1485         iRootData->LoadRemainingViews();        
       
  1486         }       
       
  1487     }
       
  1488 
       
  1489 // -----------------------------------------------------------------------------
       
  1490 // CXnViewManager::InvalidateActiveView()
       
  1491 // -----------------------------------------------------------------------------
       
  1492 //
       
  1493 void CXnViewManager::InvalidateActiveView()
       
  1494     {
       
  1495     // Need to cancel async activities while view is invalidated
       
  1496     iRootData->CancelLoadRemainingViews();
       
  1497 
       
  1498     iFlags.Clear( EFirstPassDrawComplete );
       
  1499     iFlags.Clear( EDataPluginsComplete );
       
  1500     iFlags.Clear( EViewIsValid );
       
  1501     }
       
  1502 
       
  1503 // -----------------------------------------------------------------------------
       
  1504 // CXnViewManager::ReportWidgetAmountL()
       
  1505 // -----------------------------------------------------------------------------
       
  1506 //
       
  1507 void CXnViewManager::ReportWidgetAmountL( const CXnViewData& aViewData )
       
  1508     {
       
  1509     CXnNode* node( aViewData.ViewNode() );
       
  1510 
       
  1511     if ( !iWidgetAmountTrigger )
       
  1512         {
       
  1513         iWidgetAmountTrigger = BuildTriggerL( *iUiEngine,              
       
  1514             XnPropertyNames::action::trigger::name::KWidgetAmount );
       
  1515         }
       
  1516 
       
  1517     RPointerArray< CXnPluginData >& plugins( aViewData.PluginData() );
       
  1518     TInt max( plugins.Count() );
       
  1519     TInt count( 0 );
       
  1520 
       
  1521     for ( TInt i = 0; i < plugins.Count(); i++ )
       
  1522         {
       
  1523         CXnPluginData* plugin( plugins[i] );
       
  1524         
       
  1525         if ( plugin->Occupied() )
       
  1526             {
       
  1527             if( plugin->Removable() )
       
  1528                 {
       
  1529                 count++;
       
  1530                 }
       
  1531             else
       
  1532                 {
       
  1533                 // non-removable widget consumes max amount
       
  1534                 max--;
       
  1535                 }                      
       
  1536             }
       
  1537         }
       
  1538 
       
  1539     CXnProperty* prop(
       
  1540         iWidgetAmountTrigger->GetPropertyL( XnPropertyNames::action::KValue ) );
       
  1541 
       
  1542     if ( prop )
       
  1543         {
       
  1544         if ( count == max )
       
  1545             {
       
  1546             // All plugins occupied, report max widget amount reached
       
  1547             _LIT8( KMax, "max" );
       
  1548             
       
  1549             static_cast< CXnDomPropertyValue* >(
       
  1550                 prop->Property()->PropertyValueList().Item( 0 ) )
       
  1551                 ->SetStringValueL( CXnDomPropertyValue::EString, KMax() );
       
  1552             }
       
  1553         else
       
  1554             {
       
  1555             // Report number of widgets
       
  1556             TBuf8< 8 > value;
       
  1557             
       
  1558             value.AppendNum( count );
       
  1559             
       
  1560             static_cast< CXnDomPropertyValue* >(
       
  1561                 prop->Property()->PropertyValueList().Item( 0 ) )
       
  1562                 ->SetStringValueL( CXnDomPropertyValue::EString, value );
       
  1563             }
       
  1564         }
       
  1565 
       
  1566     node->ReportXuikonEventL( *iWidgetAmountTrigger );
       
  1567     }
       
  1568 
       
  1569 // -----------------------------------------------------------------------------
       
  1570 // CXnViewManager::ShowOperationFailedMessageL
       
  1571 // -----------------------------------------------------------------------------
       
  1572 //
       
  1573 void CXnViewManager::ShowDiskFullMessageL() const
       
  1574     {
       
  1575     HBufC* msg( StringLoader::LoadLC( R_QTN_HS_OPERATION_FAILED_NO_DISK ) ); 
       
  1576 
       
  1577     CAknErrorNote* note = new ( ELeave ) CAknErrorNote; 
       
  1578     CleanupStack::PushL( note ); 
       
  1579            
       
  1580     note->ExecuteLD( *msg );
       
  1581            
       
  1582     CleanupStack::Pop( note ); 
       
  1583     CleanupStack::PopAndDestroy( msg );     
       
  1584     }
       
  1585 
       
  1586 // -----------------------------------------------------------------------------
       
  1587 // CXnViewManager::OOMSysHandler
       
  1588 // -----------------------------------------------------------------------------
       
  1589 //
       
  1590 CXnOomSysHandler& CXnViewManager::OomSysHandler() const
       
  1591     {
       
  1592     return *iOomSysHandler;
       
  1593     }
       
  1594 
       
  1595 // -----------------------------------------------------------------------------
       
  1596 // CXnViewManager::UpdateViewSwitcherInformationL()
       
  1597 // -----------------------------------------------------------------------------
       
  1598 //
       
  1599 void CXnViewManager::UpdatePageManagementInformationL()
       
  1600     { 
       
  1601     // Update MSK info
       
  1602     // Obtain menu bar
       
  1603     CXnNode* menuBar( iUiEngine->MenuBarNode() );
       
  1604 
       
  1605     if ( menuBar )
       
  1606         {
       
  1607         // Get object implementing MXnMenuInterface
       
  1608         XnMenuInterface::MXnMenuInterface* menuIf( NULL );
       
  1609         XnComponentInterface::MakeInterfaceL( menuIf, menuBar->AppIfL() );
       
  1610         
       
  1611         if ( menuIf )
       
  1612             {
       
  1613 #if 0 // MSK icon change
       
  1614             // Get count of views in array and index of actual view
       
  1615             TInt count( ViewAmount() );
       
  1616             TInt current( ViewIndex() + 1 );
       
  1617 
       
  1618             // Update MSK icon
       
  1619             TInt index = ResolveIconIndex( count, current );
       
  1620             menuIf->SetSoftKeyImageL( KSkinIds[index],
       
  1621                                       AknIconUtils::AvkonIconFileName(), 
       
  1622                                       KIconIds[index],
       
  1623                                       KMaskIds[index],
       
  1624                                       XnMenuInterface::MXnMenuInterface::ECenter, 
       
  1625                                       ETrue );
       
  1626 
       
  1627 #else // MSK icon change
       
  1628             // Get array of views
       
  1629             RPointerArray< CXnPluginData >& views( iRootData->PluginData() );
       
  1630             // Get count of views in array and index of actual view
       
  1631             TInt count( views.Count() );
       
  1632             TInt actual( views.Find( &ActiveViewData() ) + 1 );
       
  1633             
       
  1634             // Construct a text info
       
  1635             _LIT( KSeparator, "/" );
       
  1636             TBuf< 32 >info( KNullDesC );
       
  1637             
       
  1638             if ( AknLayoutUtils::LayoutMirrored() )
       
  1639                 {
       
  1640                 info.AppendNum( actual );
       
  1641                 info.Append( KSeparator );
       
  1642                 info.AppendNum( count );
       
  1643                 }
       
  1644             else
       
  1645                 {
       
  1646                 info.AppendNum( actual );
       
  1647                 info.Append( KSeparator );
       
  1648                 info.AppendNum( count );
       
  1649                 }
       
  1650       
       
  1651             AknTextUtils::LanguageSpecificNumberConversion( info );
       
  1652 
       
  1653             // Update info
       
  1654             menuIf->SetSoftKeyTextL( info, 
       
  1655                 XnMenuInterface::MXnMenuInterface::ECenter );
       
  1656 #endif // MSK icon change
       
  1657             }
       
  1658         }
       
  1659     }
       
  1660 
       
  1661 // -----------------------------------------------------------------------------
       
  1662 // CXnViewManager::UpdatePluginStateL()
       
  1663 // -----------------------------------------------------------------------------
       
  1664 //
       
  1665 void CXnViewManager::UpdatePluginStateL( CXnPluginData& aPluginData )
       
  1666     {
       
  1667     if ( aPluginData.ConfigurationId().Length() == 0 && 
       
  1668          aPluginData.PluginId().Length() )
       
  1669         {
       
  1670         CHspsConfiguration* configuration( 
       
  1671             iHspsWrapper->GetPluginConfigurationL( aPluginData.PluginId() ) );
       
  1672         CleanupStack::PushL( configuration );
       
  1673         aPluginData.SetConfigurationIdL( configuration->ConfId() );
       
  1674         CleanupStack::PopAndDestroy( configuration );
       
  1675         }
       
  1676 
       
  1677     if ( aPluginData.ConfigurationId().Length() && 
       
  1678          aPluginData.PluginId().Length() )
       
  1679         {
       
  1680         iHspsWrapper->SetConfStateL( 
       
  1681                 aPluginData.ConfigurationId(), aPluginData.PluginState() );        
       
  1682         }
       
  1683     }
       
  1684 
       
  1685 // -----------------------------------------------------------------------------
       
  1686 // CXnViewManager::MaxPages()
       
  1687 // 
       
  1688 // -----------------------------------------------------------------------------
       
  1689 //
       
  1690 TInt32 CXnViewManager::MaxPages()
       
  1691     {
       
  1692     return iRootData->MaxPages();
       
  1693     }
       
  1694 
       
  1695 
       
  1696 #if 0 // MSK icon change
       
  1697 
       
  1698 
       
  1699 // -----------------------------------------------------------------------------
       
  1700 // CXnViewManager::ResolveIconIndex
       
  1701 // 
       
  1702 // -----------------------------------------------------------------------------
       
  1703 TInt CXnViewManager::ResolveIconIndex( TInt aPageCount, TInt aPageNum ) const
       
  1704     {
       
  1705     TInt iconCount( 0 );
       
  1706 
       
  1707     // Calculate total amount of icons. Each page has a aPage amount of icons.
       
  1708     for ( TInt i( aPageCount ); 0 < i; i-- )
       
  1709         {
       
  1710         iconCount += i;
       
  1711         }
       
  1712 
       
  1713     TInt index( iconCount - aPageCount + aPageNum - 1 );
       
  1714 
       
  1715     return index;
       
  1716     }
       
  1717 
       
  1718 #endif // MSK icon change
       
  1719 // End of file