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