idlehomescreen/xmluirendering/uiengine/src/xnbackgroundmanager.cpp
changeset 5 c743ef5928ba
parent 4 4d54b72983ae
child 9 f966699dea19
child 24 5cd117f4994f
equal deleted inserted replaced
4:4d54b72983ae 5:c743ef5928ba
    53 // C++ default constructor.
    53 // C++ default constructor.
    54 // -----------------------------------------------------------------------------
    54 // -----------------------------------------------------------------------------
    55 //
    55 //
    56 CXnBackgroundManager::CXnBackgroundManager( CXnViewManager& aViewManager, CHspsWrapper& aWrapper )
    56 CXnBackgroundManager::CXnBackgroundManager( CXnViewManager& aViewManager, CHspsWrapper& aWrapper )
    57     : iViewManager( aViewManager ), 
    57     : iViewManager( aViewManager ), 
    58       iHspsWrapper( aWrapper ),
    58       iHspsWrapper( aWrapper )
    59       iTransparencyEnabled( ETrue )
       
    60     {
    59     {
    61     }
    60     }
    62 
    61 
    63 // -----------------------------------------------------------------------------
    62 // -----------------------------------------------------------------------------
    64 // Symbian 2nd phase constructor.
    63 // Symbian 2nd phase constructor.
    65 // -----------------------------------------------------------------------------
    64 // -----------------------------------------------------------------------------
    66 //
    65 //
    67 void CXnBackgroundManager::ConstructL()
    66 void CXnBackgroundManager::ConstructL()
    68     {
    67     {    
    69     // Register for view activation & deactivation
       
    70     iViewManager.AppUiAdapter().AddViewActivationObserverL( this );
       
    71     
       
    72     CreateWindowL();
    68     CreateWindowL();
    73 
    69 
    74     iBgContext = CAknsLayeredBackgroundControlContext::NewL(
    70     iBgContext = CAknsLayeredBackgroundControlContext::NewL(
    75             KAknsIIDQsnBgScreenIdle, TRect(), ETrue, 1 );
    71             KAknsIIDQsnBgScreenIdle, TRect(), ETrue, 1 );
    76 
    72 
   131 // CXnBackgroundManager::Draw
   127 // CXnBackgroundManager::Draw
   132 // -----------------------------------------------------------------------------
   128 // -----------------------------------------------------------------------------
   133 //    
   129 //    
   134 void CXnBackgroundManager::Draw(const TRect& aRect) const
   130 void CXnBackgroundManager::Draw(const TRect& aRect) const
   135     {
   131     {
   136     if( iTransparencyEnabled )
   132     if( iFeatureSuppoted )
   137         {
   133         {
   138         if( iFeatureSuppoted )
   134         CXnViewData& viewData( iViewManager.ActiveViewData() );
   139             {
   135         CFbsBitmap* wallpaper = viewData.WallpaperImage();
   140             CXnViewData& viewData( iViewManager.ActiveViewData() );
   136         if( wallpaper )
   141             CFbsBitmap* wallpaper = viewData.WallpaperImage();
   137             {
   142             if( wallpaper )
   138             SystemGc().BitBlt( TPoint(0, 0), wallpaper ); 
   143                 {
       
   144                 SystemGc().BitBlt( TPoint(0, 0), wallpaper ); 
       
   145                 return;
       
   146                 }
       
   147             }
       
   148         else if( iBgImage )
       
   149             {
       
   150             SystemGc().BitBlt( TPoint(0, 0), iBgImage ); 
       
   151             return;
   139             return;
   152             }    
   140             }
   153         }
   141         }
       
   142     else if( iBgImage )
       
   143         {
       
   144         SystemGc().BitBlt( TPoint(0, 0), iBgImage ); 
       
   145         return;
       
   146         }    
   154     MAknsSkinInstance* skin( AknsUtils::SkinInstance() );     
   147     MAknsSkinInstance* skin( AknsUtils::SkinInstance() );     
   155     AknsDrawUtils::Background( skin, iBgContext, this, 
   148     AknsDrawUtils::Background( skin, iBgContext, this, SystemGc(), aRect );
   156         SystemGc(), aRect );
       
   157     }
   149     }
   158 
   150 
   159 // -----------------------------------------------------------------------------
   151 // -----------------------------------------------------------------------------
   160 // CXnBackgroundManager::SizeChanged
   152 // CXnBackgroundManager::SizeChanged
   161 // -----------------------------------------------------------------------------
   153 // -----------------------------------------------------------------------------
   176             TRAP_IGNORE( iBgImage = iSkinSrv.WallpaperImageL( *iBgImagePath ) );
   168             TRAP_IGNORE( iBgImage = iSkinSrv.WallpaperImageL( *iBgImagePath ) );
   177             }
   169             }
   178         }
   170         }
   179     iBgContext->SetRect( iRect );
   171     iBgContext->SetRect( iRect );
   180     }
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CXnBackgroundManager::MakeVisible
       
   176 // -----------------------------------------------------------------------------
       
   177 // 
       
   178 void CXnBackgroundManager::MakeVisible( TBool aVisible )
       
   179     {    
       
   180     CCoeControl::MakeVisible( aVisible );
       
   181     if ( aVisible && iScreenUpdateNeeded )
       
   182         {
       
   183         iScreenUpdateNeeded = EFalse;
       
   184         DrawNow();
       
   185         }
       
   186     }
       
   187 
   181 
   188 
   182 // -----------------------------------------------------------------------------
   189 // -----------------------------------------------------------------------------
   183 // Handle disk drive notifications.
   190 // Handle disk drive notifications.
   184 // -----------------------------------------------------------------------------
   191 // -----------------------------------------------------------------------------
   185 //
   192 //
   241 
   248 
   242 // ---------------------------------------------------------------------------
   249 // ---------------------------------------------------------------------------
   243 // CXnBackgroundManager::AddWallpaperL
   250 // CXnBackgroundManager::AddWallpaperL
   244 // ---------------------------------------------------------------------------
   251 // ---------------------------------------------------------------------------
   245 //
   252 //
   246 void CXnBackgroundManager::AddWallpaperL( const TDesC& aFileName )
   253 TInt CXnBackgroundManager::AddWallpaperL( const TDesC& aFileName )
   247     {
   254     {
       
   255     TInt retVal = KErrNone;
   248     if( iFeatureSuppoted )
   256     if( iFeatureSuppoted )
   249         {
   257         {
   250         AddPageSpecificWallpaperL( aFileName );
   258         retVal = AddPageSpecificWallpaperL( aFileName );
   251         }
   259         }
   252     else
   260     else
   253         {
   261         {
   254         AddCommonWallpaperL( aFileName );
   262         retVal = AddCommonWallpaperL( aFileName );
   255         }
   263         }
   256     }
   264     return retVal;
   257 
   265     }
       
   266 
       
   267 // ---------------------------------------------------------------------------
       
   268 // CXnBackgroundManager::DeleteWallpaper
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 void CXnBackgroundManager::DeleteWallpaper( CXnViewData& aViewData )
       
   272     {
       
   273     if( iFeatureSuppoted )
       
   274         {
       
   275         const TDesC& path = aViewData.WallpaperImagePath();
       
   276         if( path != KNullDesC )
       
   277             {
       
   278             RemoveWallpaperFromCache( path, &aViewData );
       
   279             TRAP_IGNORE( aViewData.SetWallpaperImagePathL( KNullDesC ) );
       
   280             aViewData.SetWallpaperImage( NULL );
       
   281             }
       
   282         }
       
   283     else
       
   284         {
       
   285         if( iBgImagePath )
       
   286             {
       
   287             iSkinSrv.RemoveWallpaper( *iBgImagePath );          
       
   288             delete iBgImagePath;
       
   289             iBgImagePath = NULL;
       
   290             }
       
   291         delete iBgImage;
       
   292         iBgImage = NULL;
       
   293         }
       
   294     }
       
   295     
   258 // ---------------------------------------------------------------------------
   296 // ---------------------------------------------------------------------------
   259 // CXnBackgroundManager::ActivatedL
   297 // CXnBackgroundManager::ActivatedL
   260 // ---------------------------------------------------------------------------
   298 // ---------------------------------------------------------------------------
   261 //
   299 //
   262 TBool CXnBackgroundManager::ActivatedL()
   300 TBool CXnBackgroundManager::ActivatedL()
   271 void CXnBackgroundManager::WallpaperChanged( CXnViewData& aOldView, CXnViewData& aNewView )
   309 void CXnBackgroundManager::WallpaperChanged( CXnViewData& aOldView, CXnViewData& aNewView )
   272     {
   310     {
   273     if( iFeatureSuppoted && 
   311     if( iFeatureSuppoted && 
   274         aOldView.WallpaperImagePath().Compare( aNewView.WallpaperImagePath() ) )
   312         aOldView.WallpaperImagePath().Compare( aNewView.WallpaperImagePath() ) )
   275         {
   313         {
   276         DrawNow();
   314         UpdateScreen();
   277         TInt err = AknsWallpaperUtils::SetIdleWallpaper( aNewView.WallpaperImagePath(), NULL );
   315         TInt err = AknsWallpaperUtils::SetIdleWallpaper( aNewView.WallpaperImagePath(), NULL );
   278         if( err == KErrNone )
   316         if( err == KErrNone )
   279             {
   317             {
   280             iIntUpdate++;
   318             iIntUpdate++;
   281             }
   319             }
   444             TRAP_IGNORE( ReadWallpaperFromCenrepL() );
   482             TRAP_IGNORE( ReadWallpaperFromCenrepL() );
   445             }
   483             }
   446         }
   484         }
   447     else if ( aReason == EAknsSkinStatusConfigurationDeployed )
   485     else if ( aReason == EAknsSkinStatusConfigurationDeployed )
   448         {
   486         {
   449         DrawNow();
   487         UpdateScreen();
   450         }
   488         }
   451     }
   489     }
   452     
   490     
   453 // ---------------------------------------------------------------------------
   491 // ---------------------------------------------------------------------------
   454 // CXnBackgroundManager::SkinPackageChanged
   492 // CXnBackgroundManager::SkinPackageChanged
   457 void CXnBackgroundManager::SkinPackageChanged(
   495 void CXnBackgroundManager::SkinPackageChanged(
   458         const TAknsSkinStatusPackageChangeReason /*aReason*/ )
   496         const TAknsSkinStatusPackageChangeReason /*aReason*/ )
   459     {
   497     {
   460     }
   498     }
   461 
   499 
   462 // ----------------------------------------------------------------------------
       
   463 // CXnBackgroundManager::HandleViewActivation()
       
   464 // ----------------------------------------------------------------------------
       
   465 //
       
   466 void CXnBackgroundManager::HandleViewActivation( 
       
   467     const TVwsViewId& aNewlyActivatedViewId, 
       
   468     const TVwsViewId& aViewIdToBeDeactivated )
       
   469     {
       
   470     TVwsViewId viewId( iViewManager.AppUiAdapter().View().ViewId() );
       
   471     if ( viewId == aNewlyActivatedViewId && !iTransparencyEnabled )
       
   472         {
       
   473         iTransparencyEnabled = ETrue;
       
   474         DrawNow();
       
   475         }
       
   476     else if ( viewId == aViewIdToBeDeactivated && iTransparencyEnabled )
       
   477         {
       
   478         iTransparencyEnabled = EFalse;
       
   479         DrawNow();
       
   480         }
       
   481     }
       
   482 
       
   483 // -----------------------------------------------------------------------------
   500 // -----------------------------------------------------------------------------
   484 // CXnBackgroundManager::CleanCache
   501 // CXnBackgroundManager::CleanCache
   485 // -----------------------------------------------------------------------------
   502 // -----------------------------------------------------------------------------
   486 //
   503 //
   487 void CXnBackgroundManager::CleanCache()
   504 void CXnBackgroundManager::CleanCache()
   491 
   508 
   492 // -----------------------------------------------------------------------------
   509 // -----------------------------------------------------------------------------
   493 // CXnBackgroundManager::RemoveWallpaper
   510 // CXnBackgroundManager::RemoveWallpaper
   494 // -----------------------------------------------------------------------------
   511 // -----------------------------------------------------------------------------
   495 //
   512 //
   496 void CXnBackgroundManager::RemoveWallpaperFromCache( const TDesC& aFileName )
   513 void CXnBackgroundManager::RemoveWallpaperFromCache( const TDesC& aFileName,
   497     {
   514     CXnViewData* aViewData )
   498     CXnViewData& activeViewData( iViewManager.ActiveViewData() );
   515     {
       
   516     CXnViewData* currentViewData( aViewData );
       
   517     if( !currentViewData )
       
   518         {
       
   519         currentViewData = &iViewManager.ActiveViewData();
       
   520         }
   499     CXnRootData& rootData = iViewManager.ActiveAppData();
   521     CXnRootData& rootData = iViewManager.ActiveAppData();
   500     RPointerArray<CXnPluginData>& rootDataArr = rootData.PluginData();
   522     RPointerArray<CXnPluginData>& rootDataArr = rootData.PluginData();
   501 
   523 
   502     for( TInt i = 0; i < rootDataArr.Count(); i++ )
   524     for( TInt i = 0; i < rootDataArr.Count(); i++ )
   503         {
   525         {
   504         CXnViewData* viewData = static_cast<CXnViewData*>( rootDataArr[i] );
   526         CXnViewData* viewData = static_cast<CXnViewData*>( rootDataArr[i] );
   505         if( viewData == &activeViewData )
   527         if( currentViewData == viewData )
   506             {
   528             {
   507             continue;
   529             continue;
   508             }
   530             }
   509         else if( viewData->WallpaperImagePath() == aFileName )
   531         else if( viewData->WallpaperImagePath() == aFileName )
   510             {
   532             {
   585                     }
   607                     }
   586                 }
   608                 }
   587             }
   609             }
   588         if( drawingNeeded )
   610         if( drawingNeeded )
   589             {
   611             {
   590             DrawNow();
   612             UpdateScreen();
   591             }    
   613             }    
   592         }
   614         }
   593     else
   615     else
   594         {
   616         {
   595         if( iBgImagePath )
   617         if( iBgImagePath )
   632 
   654 
   633 // ---------------------------------------------------------------------------
   655 // ---------------------------------------------------------------------------
   634 // CXnBackgroundManager::AddPageSpecificWallpaperL
   656 // CXnBackgroundManager::AddPageSpecificWallpaperL
   635 // ---------------------------------------------------------------------------
   657 // ---------------------------------------------------------------------------
   636 //
   658 //
   637 void CXnBackgroundManager::AddPageSpecificWallpaperL( const TDesC& aFileName )
   659 TInt CXnBackgroundManager::AddPageSpecificWallpaperL( const TDesC& aFileName )
   638     {
   660     {
       
   661     TInt err = KErrNone;
   639     CXnViewData& viewData( iViewManager.ActiveViewData() );
   662     CXnViewData& viewData( iViewManager.ActiveViewData() );
   640     const TDesC& old = viewData.WallpaperImagePath();
   663     const TDesC& old = viewData.WallpaperImagePath();
   641 
   664 
   642     if( aFileName.Compare( old ) )
   665     if( aFileName.Compare( old ) )
   643         {
   666         {
   654                 {
   677                 {
   655                 SaveWallpaperL(); // to HSPS
   678                 SaveWallpaperL(); // to HSPS
   656                 }
   679                 }
   657             else
   680             else
   658                 {
   681                 {
   659                 return;
   682                 // image is corrupted or format is not supported
   660                 }
   683                 return KErrCACorruptContent;
   661             }
   684                 }
   662         
   685             }
   663         // WallpaperImage changed back to default. Update view data.
   686         // WallpaperImage changed back to default. Update view data.
   664         else
   687         else
   665             {
   688             {
   666             viewData.SetWallpaperImagePathL( KNullDesC );
   689             viewData.SetWallpaperImagePathL( KNullDesC );
   667             viewData.SetWallpaperImage( NULL );            
   690             viewData.SetWallpaperImage( NULL );            
   668             }
   691             }
   669 
   692 
   670         // Update screen
   693         // Update screen
   671         DrawNow();        
   694         UpdateScreen();
   672 
   695         
   673         TInt err = AknsWallpaperUtils::SetIdleWallpaper( aFileName, NULL );
   696         err = AknsWallpaperUtils::SetIdleWallpaper( aFileName, NULL );
   674         if( err == KErrNone )
   697         if( err == KErrNone )
   675             {
   698             {
   676             iIntUpdate++;        
   699             iIntUpdate++;
   677             }                
   700             }
   678         }
   701         }
   679     }
   702     return err;
   680 
   703     }
       
   704         
   681 // ---------------------------------------------------------------------------
   705 // ---------------------------------------------------------------------------
   682 // CXnBackgroundManager::AddCommonWallpaperL
   706 // CXnBackgroundManager::AddCommonWallpaperL
   683 // ---------------------------------------------------------------------------
   707 // ---------------------------------------------------------------------------
   684 //
   708 //
   685 void CXnBackgroundManager::AddCommonWallpaperL( const TDesC& aFileName, 
   709 TInt CXnBackgroundManager::AddCommonWallpaperL( const TDesC& aFileName, 
   686     TBool aSave )
   710     TBool aSave )
   687     {
   711     {
       
   712     TInt err = KErrNone;      
   688     // Remove old from the cache
   713     // Remove old from the cache
   689     if( iBgImagePath )
   714     if( iBgImagePath )
   690         {
   715         {
   691         iSkinSrv.RemoveWallpaper( aFileName );          
   716         iSkinSrv.RemoveWallpaper( *iBgImagePath );          
   692         delete iBgImagePath;
   717         delete iBgImagePath;
   693         iBgImagePath = NULL;
   718         iBgImagePath = NULL;
   694         }
   719         }
   695     delete iBgImage;
   720     delete iBgImage;
   696     iBgImage = NULL;
   721     iBgImage = NULL;
   701     
   726     
   702         TBool err( KErrNone );
   727         TBool err( KErrNone );
   703         TRAP( err, iSkinSrv.AddWallpaperL( aFileName, iRect.Size() ) );
   728         TRAP( err, iSkinSrv.AddWallpaperL( aFileName, iRect.Size() ) );
   704         if( err )
   729         if( err )
   705             {
   730             {
   706             return;
   731             // image is corrupted or format is not supported
       
   732             return KErrCACorruptContent;
   707             }
   733             }
   708         TRAP( err, iBgImage = iSkinSrv.WallpaperImageL( aFileName ) );
   734         TRAP( err, iBgImage = iSkinSrv.WallpaperImageL( aFileName ) );
   709         if( err )
   735         if( err )
   710             {
   736             {
   711             iSkinSrv.RemoveWallpaper( aFileName );
   737             iSkinSrv.RemoveWallpaper( aFileName );
   712             delete iBgImage;
   738             delete iBgImage;
   713             iBgImage = NULL;
   739             iBgImage = NULL;
   714             return;
   740             // image is corrupted or format is not supported
       
   741             return KErrCACorruptContent;
   715             }
   742             }
   716         }
   743         }
   717     
   744     
   718     // Update screen
   745     // Update screen
   719     DrawNow();        
   746     UpdateScreen();        
   720 
   747 
   721     // Save path to cenrep
   748     // Save path to cenrep
   722     if( aSave )
   749     if( aSave )
   723         {
   750         {
   724         SaveWallpaperL();
   751         SaveWallpaperL();
   725         }
   752         }
   726 
   753 
   727     TInt err = AknsWallpaperUtils::SetIdleWallpaper( aFileName, NULL );
   754     err = AknsWallpaperUtils::SetIdleWallpaper( aFileName, NULL );
   728     if( !err )
   755     if( err == KErrNone )
   729         {
   756         {
   730         iIntUpdate++;        
   757         iIntUpdate++;
   731         }                
   758         }
       
   759 
       
   760     return err;
   732     }
   761     }
   733 
   762 
   734 // ---------------------------------------------------------------------------
   763 // ---------------------------------------------------------------------------
   735 // CXnBackgroundManager::ReadWallpaperFromCenrepL
   764 // CXnBackgroundManager::ReadWallpaperFromCenrepL
   736 // ---------------------------------------------------------------------------
   765 // ---------------------------------------------------------------------------
   782                         {
   811                         {
   783                         AddCommonWallpaperL( wallpaper, EFalse );
   812                         AddCommonWallpaperL( wallpaper, EFalse );
   784                         }
   813                         }
   785                     }                
   814                     }                
   786                 }
   815                 }
   787             DrawNow();
   816             UpdateScreen();
   788             }
   817             }
   789 
   818 
   790         CleanupStack::PopAndDestroy( repository );
   819         CleanupStack::PopAndDestroy( repository );
   791         }    
   820         }    
   792     }
   821     }
   793 
   822 
       
   823 // ---------------------------------------------------------------------------
       
   824 // CXnBackgroundManager::UpdateScreen
       
   825 // ---------------------------------------------------------------------------
       
   826 //
       
   827 void CXnBackgroundManager::UpdateScreen()
       
   828     {
       
   829     if( !IsVisible() )
       
   830         {
       
   831         iScreenUpdateNeeded = ETrue;
       
   832         }
       
   833     else
       
   834         {
       
   835         DrawNow();  
       
   836         }
       
   837     }
       
   838 
   794 //  End of File
   839 //  End of File