calendarui/views/src/calenmonthcontainer.cpp
branchRCL_3
changeset 15 9711e452b5e9
parent 10 38571fd2a704
child 20 9c5b1510919f
--- a/calendarui/views/src/calenmonthcontainer.cpp	Wed Apr 14 15:55:57 2010 +0300
+++ b/calendarui/views/src/calenmonthcontainer.cpp	Tue Apr 27 16:36:22 2010 +0300
@@ -1051,6 +1051,7 @@
     TRACE_ENTRY_POINT;
 
     iChangeMonth = EFalse;
+    iChangeDay = EFalse;
     iDayFormat = KMonthCellFormat;
 
     iMonthDataArray = new(ELeave) CMonthDataArray(KCalenDaysInWeek * KNumberOfRows);
@@ -1673,6 +1674,10 @@
             }
         TInt pointerIndex(-1);
         TBool isItem (iGrid->View()->XYPosToItemIndex(aPointerEvent.iPosition, pointerIndex));
+        if( isItem )
+            {
+            pointerIndex = static_cast<CAknGridView*>(iGrid->View())->ActualDataIndex( pointerIndex );
+            }
         CAknGridM* gridModel = static_cast<CAknGridM*>(iGrid->Model());
 
         if(gridModel->NumberOfData() <= 0)
@@ -1705,7 +1710,7 @@
             TPointerEvent pointerEvent( aPointerEvent );
             pointerEvent.iModifiers =
                 ( aPointerEvent.iModifiers & ( ~EAllModifiers ) );
-            TInt index( iGrid->CurrentItemIndex() );
+            TInt index( iGrid->CurrentDataIndex() );
             TTime isValidDay;
             if( TPointerEvent::EButton1Up == aPointerEvent.iType )
                 {
@@ -1735,15 +1740,15 @@
                         iDate + TTimeIntervalDays( pointerIndex - index ) );
                 TDateTime newActiveDayTime = newActiveDay.DateTime();
                 
-                // set the context
-                TCalTime time;
-                time.SetTimeLocalL( newActiveDay );
-                iServices.Context().SetFocusDateL( time,
-                        TVwsViewId( KUidCalendar, KUidCalenMonthView ) );
                 TMonth activeMonth( iDate.DateTime().Month() );
                 TMonth newMonth( newActiveDay.DateTime().Month() );
                 if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
                     {
+                    // set the context
+                    TCalTime time;
+                    time.SetTimeLocalL( newActiveDay );
+                    iServices.Context().SetFocusDateL( time,
+                    TVwsViewId( KUidCalendar, KUidCalenMonthView ) );
                     iGrid->HandlePointerEventL( pointerEvent );
                     if (iPreview)
                         {
@@ -1757,6 +1762,7 @@
                             iChangeMonth = ETrue;   
                             iGrid->View()->SetDisableRedraw(ETrue);
                             iView->BeginRepopulationL();
+                            iDate = newActiveDay;
                             }
                         HandleDayChangeL( newActiveDay );
                         }
@@ -1764,19 +1770,22 @@
                 else if ( activeMonth == newMonth
                         && newActiveDay != iDate  && !iChangeMonth )
                     {
-                    iGrid->HandlePointerEventL( pointerEvent );
+                    iChangeDay = ETrue;
                     // use grid index to make sure that correct grid 
                     // element is focused when dragged
                     TInt gridIndex = GridIndex();
                     newActiveDay =
                         ( iFirstDayOfGrid + TTimeIntervalDays( gridIndex ) );
-                    HandleDayChangeL( newActiveDay );
-                    iChangeMonth = EFalse;
                     }
                 }
             else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
                 {
-                iGrid->HandlePointerEventL( pointerEvent );
+                if( !iChangeDay && !iChangeMonth )
+                    {
+                    iGrid->HandlePointerEventL( pointerEvent );
+                    }
+                    iChangeDay = EFalse;
+                    iChangeMonth = EFalse;
                 }
             }
         }