uifw/AvKon/src/akngrid.cpp
branchRCL_3
changeset 19 aecbbf00d063
parent 18 fcdfafb36fe7
child 20 d48ab3b357f1
equal deleted inserted replaced
18:fcdfafb36fe7 19:aecbbf00d063
     1 /*
     1 /*
     2 * Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
   107                             const TPoint& aPoint ) const;
   107                             const TPoint& aPoint ) const;
   108     
   108     
   109 
   109 
   110     public: // data 
   110     public: // data 
   111         TInt iFlags;
   111         TInt iFlags;
   112 
   112         // EMMA-7A8B9F.Ugly hack. Prevent MopSupplyObject being invoked 
   113         // This is used to prevent MopSupplyObject being invoked 
   113         // from CEikListBox::MopGetObject()
   114         // from CEikListBox::MopGetObject().
       
   115         TBool iIsFromBaseClass;
   114         TBool iIsFromBaseClass;
   116 
       
   117         TPoint iLastPoint;
   115         TPoint iLastPoint;
       
   116         TBool iKineticScrolling;
   118         TBool iSingleClickEnabled;
   117         TBool iSingleClickEnabled;
   119     };
   118     };
   120 
   119 
   121 CAknGridExtension::CAknGridExtension() 
   120 CAknGridExtension::CAknGridExtension() 
   122     : 
   121     : 
   123     iFlags(0), 
   122     iFlags(0), 
   124     iIsFromBaseClass( EFalse ),
   123     iIsFromBaseClass( EFalse ),
   125     iLastPoint( 0, 0 ), 
   124     iLastPoint( 0, 0 ), 
       
   125     iKineticScrolling( CAknPhysics::FeatureEnabled() ),
   126     iSingleClickEnabled( iAvkonAppUi->IsSingleClickCompatible() )
   126     iSingleClickEnabled( iAvkonAppUi->IsSingleClickCompatible() )
   127     {
   127     {
   128     }
   128     }
   129 
   129 
   130 CAknGridExtension::~CAknGridExtension()
   130 CAknGridExtension::~CAknGridExtension()
   658         // because of iSBFrame->VerticalScrollBar owning window.
   658         // because of iSBFrame->VerticalScrollBar owning window.
   659         if( iSBFrame && TRect(iSBFrame->VerticalScrollBar()->Position(), 
   659         if( iSBFrame && TRect(iSBFrame->VerticalScrollBar()->Position(), 
   660             iSBFrame->VerticalScrollBar()->Size()).Contains ( aPointerEvent.iPosition ))
   660             iSBFrame->VerticalScrollBar()->Size()).Contains ( aPointerEvent.iPosition ))
   661             {
   661             {
   662             if ( !ScrollingDisabled()
   662             if ( !ScrollingDisabled()
   663                 && iExtension 
       
   664                 && iExtension->iFlags & EAknGridStateButton1DownInGrid )
   663                 && iExtension->iFlags & EAknGridStateButton1DownInGrid )
   665                 {
   664                 {
   666                 if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
   665                 if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
   667                     {
   666                     {
   668                     iExtension->iFlags &= ~EAknGridStateButton1DownInGrid;
   667                     iExtension->iFlags &= ~EAknGridStateButton1DownInGrid;
   686         
   685         
   687         // switch pointer event type and set button 1 down in grid flag on and off depending where event happened.
   686         // switch pointer event type and set button 1 down in grid flag on and off depending where event happened.
   688             switch (aPointerEvent.iType)
   687             switch (aPointerEvent.iType)
   689                 {
   688                 {
   690                 case TPointerEvent::EButton1Down:
   689                 case TPointerEvent::EButton1Down:
   691                 	{
   690                     iExtension->iLastPoint = aPointerEvent.iPosition;
   692                     if( iExtension )
   691                     if ( visibleItemsRect.Contains(aPointerEvent.iPosition) )
   693                       {
   692                         {
   694                       iExtension->iLastPoint = aPointerEvent.iPosition;
   693                         iExtension->iFlags |= EAknGridStateButton1DownInGrid;                
   695                       if ( visibleItemsRect.Contains(aPointerEvent.iPosition) )
   694                         }
   696                           {
       
   697                           iExtension->iFlags |= EAknGridStateButton1DownInGrid;
       
   698                           }
       
   699                       }
       
   700                     _AKNTRACE( "TPointerEvent::EButton1Down" );
   695                     _AKNTRACE( "TPointerEvent::EButton1Down" );
   701                     break;
   696                     break;
   702                 	}
   697 
   703                 	
       
   704                 case TPointerEvent::EButton1Up:
   698                 case TPointerEvent::EButton1Up:
   705                     {
   699                     {
   706                     if ( iExtension )
   700                     iExtension->iFlags &= ~EAknGridStateButton1DownInGrid;
   707                         {
       
   708                         iExtension->iFlags &= ~EAknGridStateButton1DownInGrid;
       
   709                         }
       
   710                     _AKNTRACE( "TPointerEvent::EButton1Up" );
   701                     _AKNTRACE( "TPointerEvent::EButton1Up" );
   711                     break;
   702                     break;
   712                     }
   703                     }
   713 
   704 
   714                 default:
   705                 default:
  1094         else
  1085         else
  1095             selectionMode = CListBoxView::ENoSelection;
  1086             selectionMode = CListBoxView::ENoSelection;
  1096         }
  1087         }
  1097         
  1088         
  1098     // With single click first key event enables highlight
  1089     // With single click first key event enables highlight
  1099     if ( iExtension 
  1090     if ( iExtension->iSingleClickEnabled
  1100             && iExtension->iSingleClickEnabled
       
  1101             && ItemDrawer()->Flags()
  1091             && ItemDrawer()->Flags()
  1102             &  CListItemDrawer::ESingleClickDisabledHighlight )
  1092             &  CListItemDrawer::ESingleClickDisabledHighlight )
  1103         {
  1093         {
  1104         if ( aKeyEvent.iCode == EKeyUpArrow || 
  1094         if ( aKeyEvent.iCode == EKeyUpArrow || 
  1105              aKeyEvent.iCode == EKeyDownArrow ||
  1095              aKeyEvent.iCode == EKeyDownArrow ||
  1344     }
  1334     }
  1345 
  1335 
  1346 EXPORT_C void CAknGrid::HandleResourceChange(TInt aType)
  1336 EXPORT_C void CAknGrid::HandleResourceChange(TInt aType)
  1347     {
  1337     {
  1348     _AKNTRACE_FUNC_ENTER;
  1338     _AKNTRACE_FUNC_ENTER;
  1349     if ( aType != KEikMessageWindowsFadeChange && 
  1339     // Need to do this to set up the scroll bar model
  1350     	 aType != KEikMessageUnfadeWindows && 
  1340     TRAP_IGNORE( UpdateScrollBarsL() );
  1351     	 aType != KEikMessageFadeAllWindows && 
       
  1352     	 aType != KEikMessageColorSchemeChange && 
       
  1353     	 aType != KAknsMessageSkinChange )
       
  1354     	{
       
  1355         // Need to do this to set up the scroll bar model
       
  1356         TRAP_IGNORE( UpdateScrollBarsL() );
       
  1357     	}
       
  1358     
       
  1359     
  1341     
  1360     if (aType==KEikDynamicLayoutVariantSwitch)
  1342     if (aType==KEikDynamicLayoutVariantSwitch)
  1361         {
  1343         {
  1362         CAknGridView* gridView = GridView();
  1344         CAknGridView* gridView = GridView();
  1363         
  1345         
  1407     CEikListBox::HandleResourceChange(aType);
  1389     CEikListBox::HandleResourceChange(aType);
  1408     
  1390     
  1409     TRAP_IGNORE( ItemDrawer()->FormattedCellData()->SetupSkinContextL());
  1391     TRAP_IGNORE( ItemDrawer()->FormattedCellData()->SetupSkinContextL());
  1410     // Data extension has animations which will change when skin changes.
  1392     // Data extension has animations which will change when skin changes.
  1411     ItemDrawer()->FormattedCellData()->HandleResourceChange( aType );
  1393     ItemDrawer()->FormattedCellData()->HandleResourceChange( aType );
  1412     
  1394 
  1413     if ( aType != KEikMessageWindowsFadeChange && 
  1395     // Need to do this to set up the scroll bar model
  1414     	 aType != KEikMessageUnfadeWindows && 
  1396     TRAP_IGNORE( UpdateScrollBarsL() );
  1415     	 aType != KEikMessageFadeAllWindows && 
       
  1416     	 aType != KEikMessageColorSchemeChange && 
       
  1417     	 aType != KAknsMessageSkinChange )
       
  1418         {
       
  1419         // Need to do this to set up the scroll bar model
       
  1420         TRAP_IGNORE( UpdateScrollBarsL() );
       
  1421         }
       
  1422     
       
  1423     _AKNTRACE_FUNC_EXIT;
  1397     _AKNTRACE_FUNC_EXIT;
  1424     }
  1398     }
  1425 
  1399 
  1426 
  1400 
  1427 EXPORT_C void CAknGrid::FocusChanged( TDrawNow aDrawNow )
  1401 EXPORT_C void CAknGrid::FocusChanged( TDrawNow aDrawNow )
  1505         newTopRow = currRow - rowsFitInView + 1; 
  1479         newTopRow = currRow - rowsFitInView + 1; 
  1506         newTopRow = Max( 0, newTopRow );
  1480         newTopRow = Max( 0, newTopRow );
  1507         
  1481         
  1508         // and calculate new top item index
  1482         // and calculate new top item index
  1509         TInt topItemIndex = newTopRow * iNumOfColsInView ;
  1483         TInt topItemIndex = newTopRow * iNumOfColsInView ;
  1510         if ( topItemIndex > KErrNotFound 
  1484         iView->SetItemOffsetInPixels(0);
  1511              && topItemIndex < iModel->NumberOfItems() )
  1485         SetTopItemIndex(topItemIndex);
  1512             {
       
  1513             iView->SetItemOffsetInPixels( 0 );
       
  1514             SetTopItemIndex( topItemIndex );
       
  1515             }
       
  1516         }
  1486         }
  1517     _AKNTRACE_FUNC_EXIT;
  1487     _AKNTRACE_FUNC_EXIT;
  1518     }
  1488     }
  1519 
  1489 
  1520 EXPORT_C void CAknGrid::HandleDragEventL(TPoint aPointerPos)
  1490 EXPORT_C void CAknGrid::HandleDragEventL(TPoint aPointerPos)
  1527         return;     
  1497         return;     
  1528         }
  1498         }
  1529     
  1499     
  1530     if ( AknLayoutUtils::PenEnabled() )
  1500     if ( AknLayoutUtils::PenEnabled() )
  1531         {
  1501         {
  1532         if ( !( iExtension && iExtension->iFlags & EAknGridStateButton1DownInGrid) )
  1502         if ( !(iExtension->iFlags & EAknGridStateButton1DownInGrid) )
  1533             {
  1503             {
  1534             _AKNTRACE_FUNC_EXIT;
  1504             _AKNTRACE_FUNC_EXIT;
  1535             return;
  1505             return;
  1536             }
  1506             }
  1537 
  1507 
  1543         TBool pointerIsOverAnItem = gridView->XYPosToItemIndex(aPointerPos, itemIndex);
  1513         TBool pointerIsOverAnItem = gridView->XYPosToItemIndex(aPointerPos, itemIndex);
  1544         // SERIES60 LAF
  1514         // SERIES60 LAF
  1545         CListBoxView::TSelectionMode selectionMode = CListBoxView::ENoSelection;
  1515         CListBoxView::TSelectionMode selectionMode = CListBoxView::ENoSelection;
  1546         //        CListBoxView::TSelectionMode selectionMode = (iListBoxFlags & EMultipleSelection) ? CListBoxView::EContiguousSelection : CListBoxView::ESingleSelection;
  1516         //        CListBoxView::TSelectionMode selectionMode = (iListBoxFlags & EMultipleSelection) ? CListBoxView::EContiguousSelection : CListBoxView::ESingleSelection;
  1547         // END OF SERIES60 LAF
  1517         // END OF SERIES60 LAF
  1548         TInt speed = iExtension ? iExtension->GetScrollingSpeed( pointerIsOverAnItem, itemIndex, 
  1518         TInt speed = iExtension->GetScrollingSpeed( pointerIsOverAnItem, itemIndex, 
  1549                                                     *gridView, aPointerPos ):0;
  1519                                                     *gridView, aPointerPos );
  1550         
  1520         
  1551         TInt oldCurrentItemIndex = CurrentItemIndex();
  1521         TInt oldCurrentItemIndex = CurrentItemIndex();
  1552         TRect currentItemRect(gridView->ItemPos(oldCurrentItemIndex), gridView->ItemSize(oldCurrentItemIndex));       
  1522         TRect currentItemRect(gridView->ItemPos(oldCurrentItemIndex), gridView->ItemSize(oldCurrentItemIndex));       
  1553         TInt numOfRows =  Max(GridView()->GridCellDimensions().iHeight,1);
  1523         TInt numOfRows =  Max(GridView()->GridCellDimensions().iHeight,1);
  1554         const TInt placesInGrid = numOfRows * iNumOfColsInView;   
  1524         const TInt placesInGrid = numOfRows * iNumOfColsInView;   
  1871 
  1841 
  1872         vSbarModel.iThumbPosition = row;
  1842         vSbarModel.iThumbPosition = row;
  1873         // EHXA-7AQ8N4. Only set it to 0 can make scrollbar empty.
  1843         // EHXA-7AQ8N4. Only set it to 0 can make scrollbar empty.
  1874         vSbarModel.iScrollSpan = GridModel()->NumberOfItems() >0 ? 
  1844         vSbarModel.iScrollSpan = GridModel()->NumberOfItems() >0 ? 
  1875             gridSize.iHeight : 0;
  1845             gridSize.iHeight : 0;
       
  1846         vSbarModel.iThumbSpan = gridView->NumberOfRowsInView();
  1876         vSbarModel.iScrollSpan = GridModel()->NumberOfItems() >0 ? 
  1847         vSbarModel.iScrollSpan = GridModel()->NumberOfItems() >0 ? 
  1877             gridSize.iHeight*iView->ItemHeight() : 0;
  1848             gridSize.iHeight*iView->ItemHeight() : 0;
  1878         vSbarModel.iThumbSpan = rect.Height();
  1849         vSbarModel.iThumbSpan = rect.Height();
  1879 
  1850 
  1880         if (iSBFrame->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan)
  1851         if (iSBFrame->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan)
  1887             vSbarModel.iThumbPosition = topRow;
  1858             vSbarModel.iThumbPosition = topRow;
  1888             }
  1859             }
  1889         if (vSbarModel.iScrollSpan-vSbarModel.iThumbPosition<vSbarModel.iThumbSpan)
  1860         if (vSbarModel.iScrollSpan-vSbarModel.iThumbPosition<vSbarModel.iThumbSpan)
  1890             {
  1861             {
  1891             vSbarModel.iThumbPosition=Max(0,vSbarModel.iScrollSpan-vSbarModel.iThumbSpan);
  1862             vSbarModel.iThumbPosition=Max(0,vSbarModel.iScrollSpan-vSbarModel.iThumbSpan);
  1892             if ( iExtension && !iExtension->iSingleClickEnabled )
  1863             gridView->MoveToItemIndexL(currentIndex,CListBoxView::ENoSelection); // force a scroll if neccessary
  1893                 {
       
  1894                 // force a scroll if neccessary
       
  1895                 gridView->MoveToItemIndexL( currentIndex, 
       
  1896                     CListBoxView::ENoSelection );
       
  1897                 }
       
  1898             }
  1864             }
  1899         }
  1865         }
  1900     if (iSBFrame->ScrollBarVisibility(CEikScrollBar::EHorizontal)!=CEikScrollBarFrame::EOff)
  1866     if (iSBFrame->ScrollBarVisibility(CEikScrollBar::EHorizontal)!=CEikScrollBarFrame::EOff)
  1901         {
  1867         {
  1902         GridView()->CalcDataWidth();
  1868         GridView()->CalcDataWidth();