uifw/EikStd/coctlsrc/gfxtransextension.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Utility class for passing data between controls.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "gfxtransextension.h"
       
    20 
       
    21 // -----------------------------------------------------------------------------
       
    22 // -----------------------------------------------------------------------------
       
    23 //
       
    24 CGfxTransExtension::TDataEntry::TDataEntry( const TInt aKey, 
       
    25                                             const TDesC8* aData ) :
       
    26         iKey( aKey ), iData( aData )
       
    27     {
       
    28     }
       
    29         
       
    30 // -----------------------------------------------------------------------------
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 TBool CGfxTransExtension::TDataEntry::SameKey( const TDataEntry& aEntry1, 
       
    34                                                const TDataEntry& aEntry2 )
       
    35     {
       
    36     return aEntry1.iKey == aEntry2.iKey;
       
    37     }
       
    38     
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CGfxTransExtension::TTransitionObserver::TTransitionObserver( 
       
    44             const TInt aKey, const TInt aEventType, 
       
    45             MAknTransitionUtilsObserver* aObserver ) :
       
    46         iKey( aKey ), iObserver( aObserver ), iEventType( ( TEvents )aEventType )
       
    47     {
       
    48     }
       
    49  
       
    50 // -----------------------------------------------------------------------------
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 TBool CGfxTransExtension::TTransitionObserver::SameKey( 
       
    54         const TTransitionObserver& aObserver1,
       
    55         const TTransitionObserver& aObserver2 )
       
    56     {
       
    57     return aObserver1.iKey == aObserver2.iKey;
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 TBool CGfxTransExtension::TTransitionObserver::Equal( 
       
    64         const TTransitionObserver& aObserver1,
       
    65         const TTransitionObserver& aObserver2 )
       
    66     {
       
    67     return ( aObserver1.iObserver == aObserver2.iObserver ) &&
       
    68            ( aObserver1.iEventType == aObserver2.iEventType );
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CGfxTransExtension::~CGfxTransExtension() 
       
    75     {
       
    76     TInt count = iUserData.Count();
       
    77         
       
    78     for ( TInt i = 0; i < count; i++ )
       
    79         {
       
    80         delete iUserData[i].iData;
       
    81         }
       
    82             
       
    83     iUserData.Reset();
       
    84     iObservers.Reset();
       
    85     };
       
    86 
       
    87 /*
       
    88     static TInt GetState(TInt aEvent, TInt* aState, TDes8* aParams = NULL);
       
    89 
       
    90     // FIXME: TDes8 instead of TAny
       
    91     static TInt SetData( const TInt aKey, TAny* aData );
       
    92     static TAny* GetData( const TInt aKey );
       
    93     static void RemoveData( const TInt aKey );
       
    94 */
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 TInt CGfxTransExtension::AddObserver( MAknTransitionUtilsObserver* aObserver,
       
   100                                       TInt aEvent,
       
   101                                       const TDesC8* aParams )
       
   102     {
       
   103     CGfxTransExtension* singleton = 
       
   104         reinterpret_cast<CGfxTransExtension*>(CCoeEnv::Static( KGfxTransExtensionUid ) );
       
   105     if ( !singleton )
       
   106         {
       
   107         return KErrNoMemory;
       
   108         }
       
   109     
       
   110     TInt key = ( TInt )aParams;
       
   111     TInt count = singleton->iObservers.Count();
       
   112     TBool exists = EFalse;
       
   113     for ( TInt i = 0; i < count; i++ )
       
   114         {
       
   115         TTransitionObserver o = singleton->iObservers[i];
       
   116         if ( ( o.iEventType == aEvent ) && ( o.iObserver == aObserver ) )
       
   117             {
       
   118             exists = ETrue;
       
   119             break;
       
   120             }
       
   121         }
       
   122         
       
   123     if ( !exists )
       
   124         {
       
   125         TTransitionObserver observer( key, aEvent, aObserver );
       
   126         singleton->iObservers.Append( observer );
       
   127         }
       
   128 
       
   129     if ( aEvent == EEventControlTransitionFinished )
       
   130         {
       
   131         GfxTransEffect::SetTransitionObserver( singleton );
       
   132         singleton->iNumControlTransitionObservers++;
       
   133         }
       
   134         
       
   135     return KErrNone;
       
   136     }
       
   137   
       
   138 // -----------------------------------------------------------------------------
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 TInt CGfxTransExtension::RemoveObserver( 
       
   142         MAknTransitionUtilsObserver* aObserver, TInt aEvent )
       
   143     {
       
   144     CGfxTransExtension* singleton = CGfxTransExtension::Static();
       
   145     if ( !singleton )
       
   146         {
       
   147         return KErrNotFound;
       
   148         }
       
   149 
       
   150     TIdentityRelation<TTransitionObserver> identity( TTransitionObserver::Equal );
       
   151     TTransitionObserver tmp( 0, aEvent, aObserver );
       
   152     TInt index = singleton->iObservers.Find( tmp, identity );
       
   153     if ( index != KErrNotFound )
       
   154         {
       
   155         singleton->iObservers.Remove( index );
       
   156         if ( aEvent == EEventControlTransitionFinished )
       
   157             {
       
   158             singleton->iNumControlTransitionObservers--;
       
   159             }
       
   160         
       
   161         if ( singleton->iNumControlTransitionObservers == 0 )
       
   162             {
       
   163             GfxTransEffect::SetTransitionObserver( NULL );
       
   164             }
       
   165             
       
   166         return KErrNone;
       
   167         }
       
   168         
       
   169     return KErrNotFound;
       
   170     }
       
   171     
       
   172 // -----------------------------------------------------------------------------
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 TInt CGfxTransExtension::GetState(TInt /*aEvent*/, TInt* /*aState*/, TDes8* /*aParams*/ )
       
   176     {
       
   177     return 0;
       
   178     }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 void CGfxTransExtension::TransitionFinished( const CCoeControl* aControl, 
       
   184                                              TUint /* aAction */ )
       
   185     {
       
   186     CGfxTransExtension* singleton = 
       
   187         reinterpret_cast<CGfxTransExtension*>(CCoeEnv::Static( KGfxTransExtensionUid ) );
       
   188     if ( !singleton )
       
   189         {
       
   190         return;
       
   191         }
       
   192 
       
   193     TInt key = ( TInt )aControl;
       
   194 
       
   195     TInt count = singleton->iObservers.Count();
       
   196     for ( TInt i = 0; i < count; i++ )
       
   197         {
       
   198         if ( singleton->iObservers[i].iKey == key )
       
   199             {
       
   200             singleton->iObservers[i].iObserver->AknTransitionCallback(
       
   201                 EEventControlTransitionFinished, 0, ( const TDesC8* )aControl );
       
   202             }
       
   203         }
       
   204     }
       
   205     
       
   206 // -----------------------------------------------------------------------------
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 void CGfxTransExtension::RemoveData( const TInt aKey )
       
   210     {
       
   211     CGfxTransExtension* singleton = CGfxTransExtension::Static();
       
   212     if ( !singleton )
       
   213         {
       
   214         return;
       
   215         }
       
   216 
       
   217     // Find the data
       
   218     TIdentityRelation<TDataEntry> identity( TDataEntry::SameKey );
       
   219     TDataEntry tmp( aKey, NULL );
       
   220     TInt index = singleton->iUserData.Find( tmp, identity );
       
   221     if ( index != KErrNotFound )
       
   222         {
       
   223         delete singleton->iUserData[index].iData;
       
   224         singleton->iUserData.Remove( index );
       
   225         }
       
   226     }
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 TInt CGfxTransExtension::SetData( const TInt aKey, const TDesC8* aData )
       
   232     {
       
   233     CGfxTransExtension* singleton = CGfxTransExtension::Static();
       
   234     if ( !singleton )
       
   235         {
       
   236         return KErrNoMemory;
       
   237         }
       
   238         
       
   239     TIdentityRelation<TDataEntry> identity( TDataEntry::SameKey );
       
   240     TDataEntry tmp( aKey, aData );
       
   241     TInt index = singleton->iUserData.Find( tmp, identity );
       
   242     if ( index != KErrNotFound )
       
   243         {
       
   244         delete singleton->iUserData[index].iData;
       
   245         singleton->iUserData[index].iData = aData;
       
   246         }
       
   247     else
       
   248         {
       
   249         singleton->iUserData.Append( tmp );
       
   250         }
       
   251 
       
   252     return KErrNone;
       
   253     }
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 const TDesC8* CGfxTransExtension::GetData( const TInt aKey )
       
   259     {
       
   260     CGfxTransExtension* singleton = CGfxTransExtension::Static();
       
   261     if ( !singleton )
       
   262         {
       
   263         return NULL;
       
   264         }
       
   265         
       
   266     TIdentityRelation<TDataEntry> identity( TDataEntry::SameKey );
       
   267     TDataEntry tmp( aKey, NULL );
       
   268     TInt index = singleton->iUserData.Find( tmp, identity );
       
   269     if ( index != KErrNotFound )
       
   270         {
       
   271         return singleton->iUserData[index].iData;
       
   272         }
       
   273     else
       
   274         {
       
   275         return NULL;
       
   276         }
       
   277     }
       
   278         
       
   279 // -----------------------------------------------------------------------------
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 CGfxTransExtension::CGfxTransExtension() :
       
   283         CCoeStatic( KGfxTransExtensionUid, -1, CCoeStatic::EThread ),
       
   284         iNumControlTransitionObservers( 0 )
       
   285     {
       
   286     }
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 CGfxTransExtension* CGfxTransExtension::Static()
       
   292     {
       
   293     CGfxTransExtension* singleton = 
       
   294         reinterpret_cast<CGfxTransExtension*>(CCoeEnv::Static( KGfxTransExtensionUid ) );
       
   295     if ( !singleton )
       
   296         {
       
   297         singleton = new CGfxTransExtension();
       
   298         }
       
   299         
       
   300     return singleton;
       
   301     }