emailuis/uicomponents/src/fsslideeffect.cpp
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     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:  Freestyle tree node implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //////SYSTEM INCLUDES
       
    20 #include "emailtrace.h"
       
    21 #include <AknUtils.h>
       
    22 
       
    23 //////TOOLKIT INCLUDES
       
    24 // <cmail> SF
       
    25 #include <alf/alfvisual.h>
       
    26 #include <alf/alftimedvalue.h>
       
    27 #include <alf/alflayout.h>
       
    28 #include <alf/alfenv.h>
       
    29 #include <alf/alfcommand.h>
       
    30 #include <alf/alfcontrol.h>
       
    31 #include <alf/alfevent.h>
       
    32 // </cmail>
       
    33 
       
    34 //////PROJECT INCLUDES
       
    35 //<cmail> removed __FS_ALFRED_SUPPORT flag
       
    36 //#include <fsconfig.h>
       
    37 //</cmail> removed __FS_ALFRED_SUPPORT flag
       
    38 #include "fsslideeffect.h"
       
    39 #include "fsslideeffectobserver.h"
       
    40 
       
    41 
       
    42 // ======== MEMBER FUNCTIONS ========
       
    43 
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // Two-phased constructor.
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CFsSlideEffect* CFsSlideEffect::NewL( CAlfControl* aControl, CAlfVisual* aRoot, TInt aTime )
       
    50     {
       
    51     FUNC_LOG;
       
    52     CFsSlideEffect* self = new (ELeave) CFsSlideEffect( aControl, aRoot, aTime );
       
    53     return self;
       
    54     }
       
    55     
       
    56 // ---------------------------------------------------------------------------
       
    57 // Two-phased constructor.
       
    58 // ---------------------------------------------------------------------------
       
    59 //    
       
    60 CFsSlideEffect* CFsSlideEffect::NewL(
       
    61     CAlfControl* aControl,
       
    62     MFsSlideEffectObserver* aObserver, 
       
    63     CAlfVisual* aRoot, 
       
    64     TInt aTime)
       
    65     {
       
    66     FUNC_LOG;
       
    67     CFsSlideEffect* self = new (ELeave) CFsSlideEffect( aControl, aObserver, aRoot, aTime );
       
    68     return self;
       
    69     }
       
    70 
       
    71     
       
    72 // ---------------------------------------------------------------------------
       
    73 // Constructor.
       
    74 // ---------------------------------------------------------------------------
       
    75 //    
       
    76 CFsSlideEffect::CFsSlideEffect(CAlfControl* aControl, CAlfVisual* aRoot, TInt aTime)
       
    77     : iControl(aControl), 
       
    78       iRoot(aRoot), 
       
    79       iTime(aTime)
       
    80     {
       
    81     FUNC_LOG;
       
    82     //No implementation nedeed
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // Constructor.
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 CFsSlideEffect::CFsSlideEffect(
       
    90     CAlfControl* aControl,
       
    91     MFsSlideEffectObserver* aObserver, 
       
    92     CAlfVisual* aRoot, TInt aTime)
       
    93     : iControl(aControl),
       
    94       iRoot(aRoot),
       
    95       iObserver(aObserver), 
       
    96       iTime(aTime)
       
    97     {
       
    98     FUNC_LOG;
       
    99     //No implementation needed.
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // Launches slide in effect.
       
   104 // ---------------------------------------------------------------------------
       
   105 //    
       
   106 void CFsSlideEffect::SlideIn(
       
   107     CFsSlideEffect::TSlideEffectDirection aDirection)
       
   108     {
       
   109     FUNC_LOG;
       
   110     
       
   111     TAlfRealPoint pos( iRoot->Layout()->Pos().ValueNow() );
       
   112     TAlfRealPoint size( iRoot->Layout()->Size().ValueNow() );
       
   113 
       
   114     TAlfRealRect rectFinal;
       
   115     TAlfRealRect rectStart;    
       
   116     
       
   117     //coordinates in reference to parent layout
       
   118     rectFinal.iTl.iX = 0;
       
   119     rectFinal.iTl.iY = 0;
       
   120     rectFinal.iBr.iX = size.iX;
       
   121     rectFinal.iBr.iY = size.iY;
       
   122     
       
   123     TRect sreenRect;
       
   124     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, sreenRect );
       
   125     
       
   126     switch(aDirection)
       
   127         {
       
   128         case ESlideNone:
       
   129             {
       
   130             iRoot->SetRect(rectFinal,0);
       
   131             break;
       
   132             }
       
   133         case ESlideFromTop:
       
   134             {
       
   135             rectStart.iTl.iX = rectFinal.iTl.iX;
       
   136             rectStart.iTl.iY = -pos.iY - size.iY;
       
   137             rectStart.iBr.iX = rectFinal.iTl.iX + size.iX;
       
   138             rectStart.iBr.iY = -pos.iY;
       
   139             iRoot->SetRect( rectStart, 0 );
       
   140             iRoot->SetRect(rectFinal,iTime);
       
   141             break;
       
   142             }
       
   143             
       
   144         case ESlideFromBottom:
       
   145             {
       
   146             rectStart.iTl.iX = rectFinal.iTl.iX;
       
   147             rectStart.iTl.iY = sreenRect.Height() - pos.iY;
       
   148             rectStart.iBr.iX = rectFinal.iTl.iX + size.iX;
       
   149             rectStart.iBr.iY = sreenRect.Height() - pos.iY + size.iY;
       
   150             iRoot->SetRect( rectStart, 0 );
       
   151             iRoot->SetRect(rectFinal,iTime);
       
   152             break;
       
   153             }
       
   154             
       
   155         case ESlideFromLeft:
       
   156             {
       
   157             rectStart.iTl.iX = -pos.iX - size.iX;
       
   158             rectStart.iTl.iY = rectFinal.iTl.iY;
       
   159             rectStart.iBr.iX = -pos.iX;
       
   160             rectStart.iBr.iY = rectFinal.iBr.iY;
       
   161             iRoot->SetRect( rectStart, 0 );
       
   162             iRoot->SetRect(rectFinal,iTime);
       
   163             break;
       
   164             }
       
   165             
       
   166         case ESlideFromRight:
       
   167             {
       
   168             rectStart.iTl.iX = sreenRect.Width();
       
   169             rectStart.iTl.iY = rectFinal.iTl.iY;
       
   170             rectStart.iBr.iX = sreenRect.Width() + size.iX;
       
   171             rectStart.iBr.iY = rectFinal.iBr.iY;
       
   172             iRoot->SetRect( rectStart, 0 );
       
   173             iRoot->SetRect(rectFinal,iTime);
       
   174             break;
       
   175             }
       
   176         default:
       
   177             return;
       
   178         }
       
   179         
       
   180     
       
   181     if (iObserver)
       
   182         {
       
   183         iObserver->SlideEffectEvent(MFsSlideEffectObserver::ESlidingIn);
       
   184         }
       
   185     
       
   186     //cancel pending events
       
   187     if ( iControl )
       
   188         {
       
   189         iControl->Env().CancelCustomCommands(this);
       
   190 
       
   191         //send a command to inform about end of slide in effect
       
   192         TInt error = iControl->Env().Send(TAlfCustomEventCommand( ECustomEventSlideInFinished, this), iTime);
       
   193         if (error != KErrNone)
       
   194             {
       
   195             
       
   196             }
       
   197         }
       
   198     }
       
   199     
       
   200 // ---------------------------------------------------------------------------
       
   201 // Launches slide out effect.
       
   202 // ---------------------------------------------------------------------------
       
   203 //        
       
   204 void CFsSlideEffect::SlideOut(
       
   205     CFsSlideEffect::TSlideEffectDirection aDirection)
       
   206     {
       
   207     FUNC_LOG;
       
   208     TAlfRealPoint pos = iRoot->Layout()->Pos().ValueNow();
       
   209     TAlfRealPoint size = iRoot->Layout()->Size().ValueNow();
       
   210     
       
   211     TAlfRealRect rectStart;
       
   212     TAlfRealRect rectFinal;
       
   213 
       
   214     rectStart.iTl.iX = 0;
       
   215     rectStart.iTl.iY = 0;
       
   216     rectStart.iBr.iX = size.iX;
       
   217     rectStart.iBr.iY = size.iY;
       
   218     
       
   219     TRect sreenRect;
       
   220     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, sreenRect );
       
   221     
       
   222     switch( aDirection )
       
   223         {
       
   224         case ESlideNone:
       
   225             {
       
   226             iRoot->SetRect( rectStart, 0 );
       
   227             break;
       
   228             }
       
   229         case ESlideFromTop:
       
   230             {
       
   231             rectFinal.iTl.iX = rectStart.iTl.iX;
       
   232             rectFinal.iTl.iY = (pos.iY - sreenRect.Height()) - size.iY;
       
   233             rectFinal.iBr.iX = rectStart.iBr.iX;
       
   234             rectFinal.iBr.iY = (pos.iY - sreenRect.Height());            
       
   235             iRoot->SetRect( rectFinal ,iTime );
       
   236             break;
       
   237             }
       
   238             
       
   239         case ESlideFromBottom:
       
   240             {
       
   241             rectFinal.iTl.iX = rectStart.iTl.iX;
       
   242             rectFinal.iTl.iY = sreenRect.Height() - pos.iY;
       
   243             rectFinal.iBr.iX = rectStart.iBr.iX;
       
   244             rectFinal.iBr.iY = sreenRect.Height() - pos.iY + size.iY;
       
   245             iRoot->SetRect( rectFinal ,iTime );
       
   246             break;
       
   247             }
       
   248             
       
   249         case ESlideFromLeft:
       
   250             {
       
   251             rectFinal.iTl.iX = ( pos.iX - sreenRect.Width() ) - size.iX;
       
   252             rectFinal.iTl.iY = rectStart.iTl.iY;
       
   253             rectFinal.iBr.iX = pos.iX - sreenRect.Width();
       
   254             rectFinal.iBr.iY = rectStart.iBr.iY;
       
   255             iRoot->SetRect( rectFinal ,iTime );
       
   256             break;
       
   257             }
       
   258             
       
   259         case ESlideFromRight:
       
   260             {
       
   261             rectFinal.iTl.iX = sreenRect.Width();
       
   262             rectFinal.iTl.iY = rectStart.iTl.iY;
       
   263             rectFinal.iBr.iX = sreenRect.Width() + size.iX;
       
   264             rectFinal.iBr.iY = rectStart.iBr.iY;
       
   265             iRoot->SetRect( rectFinal ,iTime );
       
   266             break;
       
   267             }
       
   268         default:
       
   269             return;
       
   270         }
       
   271         
       
   272     
       
   273     if ( iObserver )
       
   274         {
       
   275         iObserver->SlideEffectEvent( MFsSlideEffectObserver::ESlidingOut );
       
   276         }
       
   277     
       
   278     //cancel pending events
       
   279     if ( iControl )
       
   280         {
       
   281         iControl->Env().CancelCustomCommands(this);
       
   282 
       
   283         //send a command to inform about end of slide out effect
       
   284         TInt error = iControl->Env().Send(TAlfCustomEventCommand( ECustomEventSlideOutFinished, this), iTime);
       
   285         if (error != KErrNone)
       
   286             {
       
   287             
       
   288             }
       
   289         }
       
   290     }
       
   291     
       
   292 // ---------------------------------------------------------------------------
       
   293 // Sets duration of slide in/out effect.
       
   294 // ---------------------------------------------------------------------------
       
   295 //        
       
   296 void CFsSlideEffect::SetTime( const TInt aTime)
       
   297     {
       
   298     FUNC_LOG;
       
   299     iTime = aTime;
       
   300     }
       
   301     
       
   302 
       
   303 // ---------------------------------------------------------------------------
       
   304 // Returns duration of the slide effect
       
   305 // ---------------------------------------------------------------------------
       
   306 //    
       
   307 TInt CFsSlideEffect::Time() const
       
   308     {
       
   309     FUNC_LOG;
       
   310     return iTime;    
       
   311     }
       
   312 
       
   313 
       
   314 // ---------------------------------------------------------------------------
       
   315 // From MAlfEventHandler
       
   316 // Called when an input event is being offered to this object.
       
   317 // ---------------------------------------------------------------------------
       
   318 //
       
   319 TBool CFsSlideEffect::OfferEventL(const TAlfEvent& aEvent)
       
   320     {
       
   321     FUNC_LOG;
       
   322     TBool result(EFalse);
       
   323     if( aEvent.IsCustomEvent() )
       
   324         {
       
   325         if ( aEvent.CustomParameter() == ECustomEventSlideInFinished )
       
   326             {
       
   327             result = ETrue;
       
   328             //inform observer
       
   329             if ( iObserver )
       
   330                 {
       
   331                 iObserver->SlideEffectEvent(MFsSlideEffectObserver::ESlideInFinished);
       
   332                 }
       
   333             }
       
   334         else if ( aEvent.CustomParameter() == ECustomEventSlideOutFinished )
       
   335             {
       
   336             result = ETrue;
       
   337             //inform observer
       
   338             if ( iObserver )
       
   339                 {
       
   340                 iObserver->SlideEffectEvent(MFsSlideEffectObserver::ESlideOutFinished);
       
   341                 }
       
   342             }
       
   343         }
       
   344     else
       
   345         {
       
   346         result = EFalse;
       
   347         }
       
   348     
       
   349     return result;
       
   350     }
       
   351 
       
   352 
       
   353 //End Of File
       
   354