meetingrequest/mrgui/src/cmrlistpanephysics.cpp
branchRCL_3
changeset 25 3533d4323edc
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 2009 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:  MR listpane physics impl
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cmrlistpanephysics.h"
       
    19 #include "cmrlistpane.h"
       
    20 #include "nmrlayoutmanager.h"
       
    21 #include "cmrfieldcontainer.h"
       
    22 
       
    23 #include <aknphysics.h>
       
    24 
       
    25 //DEBUG
       
    26 #include "emailtrace.h"
       
    27 
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // CMRListPanePhysics::CMRListPanePhysics
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 CMRListPanePhysics::CMRListPanePhysics(
       
    34         CCoeControl& aParent,
       
    35         CMRFieldContainer& aViewControl,
       
    36         MMRPhysicsObserver& aPhysicsObserver )
       
    37     : iParent( aParent ),
       
    38       iViewControl( aViewControl ),
       
    39       iPhysicsObserver( aPhysicsObserver )
       
    40     {
       
    41     FUNC_LOG;
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CMRListPanePhysics::ConstructL
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 void CMRListPanePhysics::ConstructL()
       
    49     {
       
    50     FUNC_LOG;
       
    51     iFeatureEnabled = CAknPhysics::FeatureEnabled();
       
    52     if ( iFeatureEnabled )
       
    53         {
       
    54         // Physics: Create physics
       
    55         // Give pointer to control that should be able to flick/drag
       
    56         iPhysics = CAknPhysics::NewL( *this, &iViewControl );
       
    57         }
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // CMRListPanePhysics::NewL
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 CMRListPanePhysics* CMRListPanePhysics::NewL(
       
    65         CCoeControl& aParent,
       
    66         CMRFieldContainer& aViewControl,
       
    67         MMRPhysicsObserver& aPhysicsObserver )
       
    68     {
       
    69     FUNC_LOG;
       
    70     CMRListPanePhysics* self =
       
    71         new ( ELeave ) CMRListPanePhysics(
       
    72                 aParent,
       
    73                 aViewControl,
       
    74                 aPhysicsObserver );
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL();
       
    77     CleanupStack::Pop( self );
       
    78     return self;
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CMRListPanePhysics::~CMRListPanePhysics
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CMRListPanePhysics::~CMRListPanePhysics()
       
    86     {
       
    87     FUNC_LOG;
       
    88     delete iPhysics;
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // CMRListPanePhysics::HandlePointerEventL
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 TBool CMRListPanePhysics::HandlePointerEventL(
       
    96         const TPointerEvent& aPointerEvent, TBool& aEventsBlocked )
       
    97     {
       
    98     FUNC_LOG;
       
    99     TBool physicsStarted( EFalse );
       
   100     if ( !iFeatureEnabled || iPhysics->OngoingPhysicsAction() ==
       
   101             CAknPhysics::EAknPhysicsActionBouncing )
       
   102         {
       
   103         return physicsStarted;
       
   104         }
       
   105 
       
   106     // Down
       
   107     if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   108         {
       
   109         if ( iPhysics->OngoingPhysicsAction()
       
   110              != CAknPhysics::EAknPhysicsActionNone )
       
   111             {
       
   112             iPhysics->StopPhysics();
       
   113             }
       
   114         
       
   115         // Save start time and start point
       
   116         iStartTime.HomeTime();
       
   117         iStartPoint = aPointerEvent.iPosition;
       
   118         iDragPoint = iStartPoint;
       
   119         }
       
   120 
       
   121     // Drag
       
   122     else if ( aPointerEvent.iType == TPointerEvent::EDrag )
       
   123         {
       
   124         // Check how position was changed and report to physics
       
   125         TPoint deltaPoint( iDragPoint - aPointerEvent.iPosition );
       
   126         if( Abs( deltaPoint.iY ) > iPhysics->DragThreshold() )
       
   127         	{
       
   128 			iDragPoint = aPointerEvent.iPosition;
       
   129 			iPhysics->RegisterPanningPosition( deltaPoint );
       
   130         	}
       
   131         }
       
   132 
       
   133     // Up
       
   134     else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   135         {
       
   136         // Calculate dragging distance
       
   137         TPoint drag( iStartPoint - aPointerEvent.iPosition );
       
   138 
       
   139         if( Abs( drag.iY ) > iPhysics->DragThreshold() )
       
   140         	{
       
   141             // Start physics
       
   142             physicsStarted = iPhysics->StartPhysics( drag, iStartTime );
       
   143         	}
       
   144 
       
   145         if( physicsStarted )
       
   146         	{
       
   147 			aEventsBlocked = ETrue;
       
   148         	}
       
   149         else
       
   150         	{
       
   151 			aEventsBlocked = EFalse;
       
   152         	}
       
   153         }
       
   154 
       
   155     // Record previous pointer event
       
   156     iPreviousPointerEvent = aPointerEvent;
       
   157 
       
   158     return physicsStarted;
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // CMRListPanePhysics::InitPhysicsL
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 void CMRListPanePhysics::InitPhysics()
       
   166     {
       
   167     FUNC_LOG;
       
   168     if ( !iFeatureEnabled )
       
   169         {
       
   170         return;
       
   171         }
       
   172     TRect parentRect( iParent.Rect() );
       
   173 
       
   174     iWorldSize.iHeight = iViewControl.MinimumSize().iHeight;
       
   175     iWorldSize.iWidth = iViewControl.MinimumSize().iWidth;
       
   176 
       
   177     iViewSize.iHeight = parentRect.Height();
       
   178     iViewSize.iWidth = parentRect.Width();
       
   179 
       
   180     if( iWorldSize.iHeight < iViewSize.iHeight )
       
   181         {
       
   182     	iWorldSize.iHeight = iViewSize.iHeight;
       
   183         }
       
   184 
       
   185 
       
   186 
       
   187     iPhysics->ResetFriction();
       
   188 
       
   189     TRAP_IGNORE( iPhysics->InitPhysicsL( iWorldSize, iViewSize, EFalse ) );
       
   190     iPhysics->UpdateViewWindowControl( &iParent );
       
   191     }
       
   192 
       
   193 // ---------------------------------------------------------------------------
       
   194 // CMRListPanePhysics::SetWorldHeight
       
   195 // ---------------------------------------------------------------------------
       
   196 //
       
   197 void CMRListPanePhysics::SetWorldHeight( TInt aWorldHeight )
       
   198     {
       
   199     FUNC_LOG;
       
   200     if ( !iFeatureEnabled )
       
   201         {
       
   202         return;
       
   203         }
       
   204     iWorldSize.iHeight = aWorldHeight;
       
   205     }
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // CMRListPanePhysics::ViewPositionChanged
       
   209 // ---------------------------------------------------------------------------
       
   210 //
       
   211 void CMRListPanePhysics::ViewPositionChanged( const TPoint& aNewPosition,
       
   212                           TBool aDrawNow,
       
   213                           TUint /*aFlags*/ )
       
   214     {
       
   215     FUNC_LOG;
       
   216     if ( !iFeatureEnabled )
       
   217         {
       
   218         return;
       
   219         }
       
   220     if ( iPhysics->OngoingPhysicsAction() ==
       
   221             CAknPhysics::EAknPhysicsActionBouncing )
       
   222         {
       
   223         return;
       
   224         }
       
   225 
       
   226     iVerScrollIndex = aNewPosition.iY - iViewSize.iHeight / 2;
       
   227 
       
   228     // Parents position is taken into account, by
       
   229     // adding the extra x and y coordinates to field containers
       
   230     // new position.
       
   231     TPoint pos(
       
   232             iParent.Position().iX,
       
   233             -iVerScrollIndex + iParent.Position().iY );
       
   234     iViewControl.ScrollContainer( pos );
       
   235 
       
   236     // Draw only when drawing is allowed
       
   237     if ( aDrawNow )
       
   238         {
       
   239         iParent.DrawNow();
       
   240         }
       
   241 
       
   242     // Vertical scroll index has changed, we need to update scroll bar also
       
   243     iPhysicsObserver.UpdateScrollBarDuringOngoingPhysics();
       
   244     }
       
   245 
       
   246 // ---------------------------------------------------------------------------
       
   247 // CMRListPanePhysics::PhysicEmulationEnded
       
   248 // ---------------------------------------------------------------------------
       
   249 //
       
   250 void CMRListPanePhysics::PhysicEmulationEnded()
       
   251     {
       
   252     FUNC_LOG;
       
   253     iPhysicsObserver.PhysicsEmulationEnded();
       
   254     
       
   255     // Synchronize field container position
       
   256     iViewControl.Synchronize();
       
   257     }
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 // CMRListPanePhysics::ViewPosition
       
   261 // ---------------------------------------------------------------------------
       
   262 //
       
   263 TPoint CMRListPanePhysics::ViewPosition() const
       
   264     {
       
   265     FUNC_LOG;
       
   266     if ( !iFeatureEnabled )
       
   267         {
       
   268         return TPoint( iParent.Position() );
       
   269         }
       
   270 
       
   271     // This is the default implementation
       
   272     TPoint viewPosition(
       
   273             iViewSize.iWidth / 2,
       
   274             iViewSize.iHeight / 2 + iVerScrollIndex );
       
   275 
       
   276     return viewPosition;
       
   277     }
       
   278 
       
   279 // ---------------------------------------------------------------------------
       
   280 // CMRListPanePhysics::UpdateVerticalScrollIndex
       
   281 // ---------------------------------------------------------------------------
       
   282 //
       
   283 void CMRListPanePhysics::UpdateVerticalScrollIndex( TInt aVerScrollIndex )
       
   284     {
       
   285     FUNC_LOG;
       
   286     if ( iFeatureEnabled )
       
   287         {
       
   288         // Physics' new position is updated to this member, when field
       
   289         // container is scrolled by someone else than physics.
       
   290         iVerScrollIndex = aVerScrollIndex;
       
   291         }
       
   292     }
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 // CMRListPanePhysics::VerticalScrollIndex
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 TInt CMRListPanePhysics::VerticalScrollIndex()
       
   299     {
       
   300     return iVerScrollIndex;
       
   301     }
       
   302 // End of file
       
   303