idlehomescreen/widgetmanager/src/wmeffectmanager.cpp
branchRCL_3
changeset 34 5456b4e8b3a8
child 35 3321d3e205b6
equal deleted inserted replaced
33:5f0182e07bfb 34:5456b4e8b3a8
       
     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:  Effect manager.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDE FILES
       
    20 #include <eikapp.h>
       
    21 #include <aknappui.h>
       
    22 #include <gfxtranseffect/gfxtranseffect.h>  // For transition effects
       
    23 #include <akntranseffect.h>                 // For transition effects
       
    24 #include <alf/alfcompositionutility.h>
       
    25 
       
    26 // INCLUDE FILES
       
    27 #include "wmeffectmanager.h"
       
    28 
       
    29 // CONSTANTS
       
    30 const TInt KEffectTypeFullscreen = 1;
       
    31 
       
    32 const TInt KWaitForLayout = 1;
       
    33 const TInt KEffectStarted = 2;
       
    34 
       
    35 const TInt KEffectWaitInterval( 250000 ); //250ms
       
    36 const TInt KWaitInterval( 25000 ); // 25ms
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // C++ default constructor.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CWmEffectManager::CWmEffectManager( CCoeEnv& aCoeEnv ): iCoeEnv (aCoeEnv)
       
    45     {
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // Symbian 2nd phase constructor.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 void CWmEffectManager::ConstructL()
       
    53     {
       
    54     iObserver = CAlfEffectObserver::NewL(); 
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // Two-phased constructor.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CWmEffectManager* CWmEffectManager::NewL( CCoeEnv& aCoeEnv )
       
    62     {
       
    63     CWmEffectManager* self = new (ELeave) CWmEffectManager( aCoeEnv );
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructL();
       
    66     CleanupStack::Pop( self );
       
    67     return self;
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // Destructor.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CWmEffectManager::~CWmEffectManager()
       
    75     {
       
    76     delete iObserver;
       
    77     GfxTransEffect::AbortFullScreen();
       
    78     iEffects.ResetAndDestroy();
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CWmEffectManager::BeginFullscreenEffectL
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void CWmEffectManager::BeginFullscreenEffectL( TInt aId )
       
    86     {
       
    87     TWmEffect* effect = new (ELeave) TWmEffect;
       
    88     CleanupStack::PushL( effect );
       
    89     effect->iId = aId;
       
    90     effect->iType = KEffectTypeFullscreen;
       
    91     effect->iState = KWaitForLayout;
       
    92     iEffects.Append( effect );
       
    93     
       
    94     CleanupStack::Pop( effect );
       
    95 
       
    96     if ( !DoBeginFullscreenEffect( *effect ) )
       
    97         {
       
    98         RemoveEffect( effect );
       
    99         }
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CWmEffectManager::UiRendered
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 void CWmEffectManager::UiRendered()
       
   107     {
       
   108     for ( TInt i = 0; i < iEffects.Count(); )
       
   109         {
       
   110         TWmEffect* effect = iEffects[i];
       
   111         if ( effect && effect->iState == KEffectStarted )
       
   112             {
       
   113             GfxTransEffect::EndFullScreen();
       
   114             RemoveEffect( effect );
       
   115             }
       
   116         else
       
   117             {
       
   118             // RemoveEffect() will remove from iEffects array and
       
   119             // thats why we need to have conter in else
       
   120             i++;
       
   121             }
       
   122         }
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CWmEffectManager::DoBeginFullscreenEffect
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 TBool CWmEffectManager::DoBeginFullscreenEffect( TWmEffect& aEffect )
       
   130     {
       
   131     if ( iCoeEnv.WsSession().GetFocusWindowGroup() != 
       
   132          iCoeEnv.RootWin().Identifier() )
       
   133         {
       
   134         // Window group is not focused
       
   135         RemoveEffect( &aEffect );
       
   136         return EFalse;
       
   137         }
       
   138     
       
   139     if ( !WaitActiveEffect( KEffectWaitInterval ) )
       
   140         {
       
   141         return EFalse;
       
   142         }
       
   143 
       
   144     const TInt flags( AknTransEffect::TParameter::EActivateExplicitCancel );
       
   145     const TUid targetAppUid( iAvkonAppUi->Application()->AppDllUid() );
       
   146 
       
   147     // Set effect begin point
       
   148     GfxTransEffect::BeginFullScreen( aEffect.iId , iAvkonAppUi->ClientRect(),
       
   149         AknTransEffect::EParameterType, AknTransEffect::GfxTransParam(
       
   150         targetAppUid, flags ) );
       
   151     
       
   152     aEffect.iState = KEffectStarted;
       
   153     
       
   154     return ETrue;
       
   155     }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CWmEffectManager::WaitActiveEffect
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 TBool CWmEffectManager::WaitActiveEffect( TInt aInterval )     
       
   162     {
       
   163     TBool retval( EFalse );
       
   164     TInt loop( aInterval / KWaitInterval );
       
   165     
       
   166     while ( loop >= 0 )
       
   167         {               
       
   168         TInt count( iObserver->ActiveEffectsCount() );
       
   169         
       
   170         if ( count == 0 )
       
   171             {
       
   172             retval = ETrue;
       
   173             break;                        
       
   174             }
       
   175         
       
   176         User::After( KWaitInterval );
       
   177         loop--;
       
   178         }
       
   179 
       
   180     return retval;    
       
   181     }
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CXnEffectManager::RemoveEffect
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 void CWmEffectManager::RemoveEffect( TWmEffect* aEffect )
       
   188     {
       
   189     TInt index = iEffects.Find( aEffect );
       
   190     if ( index != KErrNotFound )
       
   191         {
       
   192         TWmEffect* temp = iEffects[index];
       
   193         iEffects.Remove( index );
       
   194         delete temp;
       
   195         }
       
   196     }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // CXnEffectManager::IsEffectActive
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 TBool CWmEffectManager::IsEffectActive()
       
   203     {
       
   204     TBool retVal( EFalse );
       
   205     if ( iObserver->ActiveEffectsCount() )
       
   206         retVal = ETrue;
       
   207     return retVal;
       
   208     }
       
   209 
       
   210 // End fo file
       
   211