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