cmmanager/cmmgr/Framework/Src/cmdesticonmap.cpp
branchRCL_3
changeset 26 0a9e01492035
parent 1 40cb640ef159
equal deleted inserted replaced
24:c45d4fe2ff0a 26:0a9e01492035
   283     {
   283     {
   284     iRows = ( ( iConsArray->Count() - 1 ) / iMaxColumns ) + 1 ;
   284     iRows = ( ( iConsArray->Count() - 1 ) / iMaxColumns ) + 1 ;
   285     iFirstVisibleRow = 0;
   285     iFirstVisibleRow = 0;
   286     iAnimated = EFalse;
   286     iAnimated = EFalse;
   287     iCursorPos = TPoint( 0, 0 );
   287     iCursorPos = TPoint( 0, 0 );
   288     iNumPages = ( iRows / iExtension->iMaxVisibleRows ) + 
       
   289                 ( iRows % iExtension->iMaxVisibleRows ? 1 : 0 );
       
   290     iCurrentPage = 1;
       
   291     
   288     
   292     // Create and set the scb visible even though there is nothing to scroll   
   289     // Create and set the scb visible even though there is nothing to scroll   
   293     delete iSBFrame; iSBFrame=NULL;
   290     delete iSBFrame; iSBFrame=NULL;
   294 
   291 
   295     if ( AknLayoutUtils::PenEnabled() )
   292     if ( AknLayoutUtils::PenEnabled() )
   362     TAknLayoutRect dialogLayRect;
   359     TAknLayoutRect dialogLayRect;
   363         
   360         
   364     // Main pane without softkeys
   361     // Main pane without softkeys
   365     TRect mainPaneRect;
   362     TRect mainPaneRect;
   366     if ( !AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect ) )
   363     if ( !AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect ) )
   367     {
   364         {
   368     mainPaneRect = iAvkonAppUi->ClientRect();
   365         mainPaneRect = iAvkonAppUi->ClientRect();
   369     }
   366         }
   370     
   367     
   371     // Dialog layout, check variety first
   368     // Dialog layout, check variety first
   372     TAknLayoutScalableParameterLimits iconMapDialogVariety = 
   369     TAknLayoutScalableParameterLimits iconMapDialogVariety = 
   373                AknLayoutScalable_Avkon::popup_grid_graphic_window_ParamLimits();
   370                AknLayoutScalable_Avkon::popup_grid_graphic_window_ParamLimits();
   374     
   371     
   407     TInt varietyNumber = varietyOffset - iRows - 1; 
   404     TInt varietyNumber = varietyOffset - iRows - 1; 
   408     
   405     
   409     // if more lines than possible to show, use the default 
   406     // if more lines than possible to show, use the default 
   410     // ( the biggest grid ) variety
   407     // ( the biggest grid ) variety
   411     if ( varietyNumber < 0 )
   408     if ( varietyNumber < 0 )
   412        varietyNumber = 0;
   409         {
       
   410         varietyNumber = 0;
       
   411         }
   413     // if zero rows, use the minimum
   412     // if zero rows, use the minimum
   414     else if ( iRows<=0 )
   413     else if ( iRows<=0 )
   415        varietyNumber -= 1;
   414         {
       
   415         varietyNumber -= 1;
       
   416         }
   416     
   417     
   417     //add the varietyoffset
   418     //add the varietyoffset
   418     varietyNumber += maxVarietyOffset;
   419     varietyNumber += maxVarietyOffset;
   419 
   420 
   420     if ( Layout_Meta_Data::IsLandscapeOrientation() && 
   421     if ( Layout_Meta_Data::IsLandscapeOrientation() && 
   526 void CCmDestinationIconMap::HandlePointerEventL(
   527 void CCmDestinationIconMap::HandlePointerEventL(
   527                                 const TPointerEvent& aPointerEvent )
   528                                 const TPointerEvent& aPointerEvent )
   528     {
   529     {
   529     if ( AknLayoutUtils::PenEnabled() )
   530     if ( AknLayoutUtils::PenEnabled() )
   530         {
   531         {
   531         TInt newGridX; // For the whole
   532         TInt xInPixels = aPointerEvent.iPosition.iX - iGridTopLeft.iX;
   532         TInt newGridY; // For the whole grid.
       
   533         TInt yInPixels = aPointerEvent.iPosition.iY - iGridTopLeft.iY;
   533         TInt yInPixels = aPointerEvent.iPosition.iY - iGridTopLeft.iY;
   534         newGridY = yInPixels / iGridItemHeight;
   534         TInt newGridX = xInPixels / iGridItemWidth;
   535         if ( ( aPointerEvent.iPosition.iX - iGridTopLeft.iX ) < 0 )
   535         TInt newGridY = yInPixels / iGridItemHeight;
   536             {
   536         TInt globalY = newGridY + iFirstVisibleRow;
   537             newGridX = -1;
       
   538             }
       
   539         else
       
   540             {
       
   541             newGridX = ( aPointerEvent.iPosition.iX - iGridTopLeft.iX )
       
   542                                                         / iGridItemWidth;
       
   543             }
       
   544 
   537 
   545         // The pointer has been set down or dragged into the area of the grid. 
   538         // The pointer has been set down or dragged into the area of the grid. 
   546         // (it might be in the "white space" at the end of the grid)
   539         // Also, it may NOT be in the "empty slots" at the end of the grid.
   547         if ( ( yInPixels >= 0 && yInPixels < iGridItemHeight 
   540         if ( xInPixels >= 0 &&
   548                 * iExtension->iMaxVisibleRows) &&
   541                 yInPixels >= 0 && 
   549             // When the pointer is in rows except the recent icon row
   542                 newGridX < iMaxColumns &&
   550                 ( ( ( ( newGridY + iFirstVisibleRow ) != 0 ) && 
   543                 yInPixels < iGridItemHeight * iExtension->iMaxVisibleRows &&
   551                 newGridX < iMaxColumns && newGridX >= 0 ) ||
   544                 globalY * iMaxColumns + newGridX + 1 <= iConsArray->Count() )
   552             // When the pointer is in the recent icon row
   545             {
   553                 ( ( newGridY + iFirstVisibleRow == 0 ) && 
       
   554                 ( newGridX < iMaxColumns ) ) ) )
       
   555             {
       
   556             TUint globalY = newGridY + iFirstVisibleRow;
       
   557             // For any action to be taken, the pointer event must either be a
   546             // For any action to be taken, the pointer event must either be a
   558             // Button1Down or a drag event which has originated from a
   547             // Button1Down or a drag event which has originated from a
   559             // Button1Down in to the grid.
   548             // Button1Down in to the grid.
   560             if ( aPointerEvent.iType == TPointerEvent::EButton1Down ||
   549             if ( aPointerEvent.iType == TPointerEvent::EButton1Down ||
   561                  aPointerEvent.iType == TPointerEvent::EDrag )
   550                  aPointerEvent.iType == TPointerEvent::EDrag )
   725     TInt varietyNumber = varietyOffset - iRows - 1; 
   714     TInt varietyNumber = varietyOffset - iRows - 1; 
   726     
   715     
   727     // if more lines than possible to show, use the default 
   716     // if more lines than possible to show, use the default 
   728     // ( the biggest grid ) variety
   717     // ( the biggest grid ) variety
   729     if ( varietyNumber < 0 )
   718     if ( varietyNumber < 0 )
   730        varietyNumber = 0;
   719         {
       
   720         varietyNumber = 0;
       
   721         }
   731     // if zero rows, use the minimum
   722     // if zero rows, use the minimum
   732     else if ( iRows<=0 )
   723     else if ( iRows<=0 )
   733        varietyNumber -= 1;
   724         {
   734     
   725         varietyNumber -= 1;
       
   726         }
       
   727 
   735     //add the varietyoffset
   728     //add the varietyoffset
   736     varietyNumber += maxVarietyOffset;
   729     varietyNumber += maxVarietyOffset;
   737     
   730     
   738     if ( Layout_Meta_Data::IsLandscapeOrientation() && 
   731     if ( Layout_Meta_Data::IsLandscapeOrientation() && 
   739          location == AknLayoutUtils::EAknCbaLocationRight )
   732          location == AknLayoutUtils::EAknCbaLocationRight )
   747             varietyNumber = 5;
   740             varietyNumber = 5;
   748             }
   741             }
   749         else
   742         else
   750             {
   743             {
   751             varietyNumber = 3;
   744             varietyNumber = 3;
   752             }            
   745             }
   753         
   746         }
   754         }       
   747 
   755     
       
   756     TAknLayoutRect popupGridLayRect;
   748     TAknLayoutRect popupGridLayRect;
   757     popupGridLayRect.LayoutRect( mainPaneRect, 
   749     popupGridLayRect.LayoutRect( mainPaneRect, 
   758           AknLayoutScalable_Avkon::popup_grid_graphic_window( varietyNumber ) );
   750           AknLayoutScalable_Avkon::popup_grid_graphic_window( varietyNumber ) );
   759     
   751     
   760     // Calculate the size relatively
   752     // Calculate the size relatively
   830     {
   822     {
   831     if ( aType == KEikDynamicLayoutVariantSwitch )
   823     if ( aType == KEikDynamicLayoutVariantSwitch )
   832         {
   824         {
   833         // save the old info for the magnitudes of the SCT grid
   825         // save the old info for the magnitudes of the SCT grid
   834         TInt oldMaxColumns = iMaxColumns;
   826         TInt oldMaxColumns = iMaxColumns;
   835         //TInt oldMaxRows = 0;
   827 
   836         //oldMaxRows = iRows;
       
   837         // calculate the new magnitudes
   828         // calculate the new magnitudes
   838         DoLayout();
   829         DoLayout();
   839         
   830         
   840         // then calculate the index position of the cursor in the icon table
   831         // then calculate the index position of the cursor in the icon table
   841         // and update the x and y positions for the new grid with it
   832         // and update the x and y positions for the new grid with it
  1021         // how many left after the full rows
  1012         // how many left after the full rows
  1022         numberOfGridCellsToBeDrawn -= fullRows * iMaxColumns;
  1013         numberOfGridCellsToBeDrawn -= fullRows * iMaxColumns;
  1023 
  1014 
  1024         TPoint pos = iGridTopLeft;
  1015         TPoint pos = iGridTopLeft;
  1025 
  1016 
  1026         TInt endX = pos.iX + iGridItemWidth * iMaxColumns + 1;
  1017         TInt endX = pos.iX + iGridItemWidth * iMaxColumns;
  1027         TInt endY = pos.iY + iGridItemHeight * fullRows;
  1018         TInt endY = pos.iY + iGridItemHeight * fullRows;
  1028 
  1019 
  1029         TInt ii = 0;
  1020         TInt ii = 0;
  1030 
  1021 
  1031         if ( fullRows )
  1022         if ( fullRows )
  1037                 gc.SetPenSize( TSize( 1,1 ) );
  1028                 gc.SetPenSize( TSize( 1,1 ) );
  1038                 gc.DrawLine( pos, TPoint( pos.iX, endY ) );
  1029                 gc.DrawLine( pos, TPoint( pos.iX, endY ) );
  1039                 pos.iX += iGridItemWidth;
  1030                 pos.iX += iGridItemWidth;
  1040                 }
  1031                 }
  1041 
  1032 
  1042                 pos = iGridTopLeft;
  1033             pos = iGridTopLeft;
  1043 
  1034 
  1044             // Draw full horizontal lines
  1035             // Draw full horizontal lines
  1045             for ( ii = 0 ; ii <= fullRows ; ii++ )
  1036             for ( ii = 0 ; ii <= fullRows ; ii++ )
  1046                 {
  1037                 {
  1047                 gc.SetPenSize( TSize( 1,1 ) );    
  1038                 gc.SetPenSize( TSize( 1,1 ) );    
  1072                 else // not mirrored
  1063                 else // not mirrored
  1073                     pos.iX += iGridItemWidth; 
  1064                     pos.iX += iGridItemWidth; 
  1074                 }
  1065                 }
  1075             }
  1066             }
  1076         
  1067         
  1077         TInt iconIndex = ( iCurrentPage - 1 ) * 
  1068         TInt iconIndex = iFirstVisibleRow * iMaxColumns;
  1078                          ( iMaxColumns * iExtension->iMaxVisibleRows );
  1069         TInt lCnt = iConsArray->Count(); 
  1079         TInt lCnt =  iConsArray->Count(); 
       
  1080         cursorPos = iCursorPos.iX + iCursorPos.iY * iMaxColumns;
  1070         cursorPos = iCursorPos.iX + iCursorPos.iY * iMaxColumns;
  1081         if ( lCnt > 0 )
  1071         if ( lCnt > 0 )
  1082             {
  1072             {
  1083             TRect cellRect( TPoint( 0,0 ), 
  1073             TRect cellRect( TPoint( 0,0 ), 
  1084                             TSize( iGridItemWidth - 1, iGridItemHeight - 1 ) );
  1074                             TSize( iGridItemWidth - 1, iGridItemHeight - 1 ) );
  1085             for ( TInt j = iconIndex, i = 0; 
  1075             for ( TInt j = iconIndex, i = 0; 
  1086                   j < lCnt && i < numberOfIconsToBeDrawn;
  1076                   j < lCnt && i < numberOfIconsToBeDrawn;
  1087                   j++, i++ )
  1077                   j++, i++ )
  1088                 {
  1078                 {
  1089                 DrawItem( gc, CursorRect( i ), j, cursorPos == i, EFalse );        
  1079                 DrawItem( gc, i, j, cursorPos == i, EFalse );        
  1090                 }     
  1080                 }     
  1091             }
  1081             }
  1092             
  1082             
  1093         }
  1083         }
  1094     iDrawnBefore = ETrue;
  1084     iDrawnBefore = ETrue;
  1099 // CCmDestinationIconMap::DrawItem()
  1089 // CCmDestinationIconMap::DrawItem()
  1100 // -----------------------------------------------------------------------------
  1090 // -----------------------------------------------------------------------------
  1101 //
  1091 //
  1102 void CCmDestinationIconMap::DrawItem( 
  1092 void CCmDestinationIconMap::DrawItem( 
  1103     CWindowGc& aGc,
  1093     CWindowGc& aGc,
  1104     const TRect& aSctPosition,
  1094     TInt index,
  1105     TInt aIconIndex,
  1095     TInt aIconIndex,
  1106     TBool aHighlighted,
  1096     TBool aHighlighted,
  1107     TBool aDrawBackground ) const
  1097     TBool aDrawBackground ) const
  1108     {
  1098     {
       
  1099     TRect sctPosition = CursorRect( index );
  1109     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
  1100     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
  1110     MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
  1101     MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
  1111     
  1102     
  1112     TBool skins = AknsDrawUtils::Background( skin,cc,aGc, aSctPosition );    
  1103     TBool skins = AknsDrawUtils::Background( skin,cc,aGc, sctPosition );    
  1113     TRgb color;
  1104     TRgb color;
  1114     if ( !skins )
  1105     if ( !skins )
       
  1106         {
  1115         aGc.SetBrushStyle( CGraphicsContext::ESolidBrush );
  1107         aGc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
  1108         }
       
  1109     
  1116     if ( aHighlighted )
  1110     if ( aHighlighted )
  1117         {
  1111         {
  1118         TRgb colorHightLightRect = AKN_LAF_COLOR( 215 );
  1112         TRgb colorHightLightRect = AKN_LAF_COLOR( 215 );
  1119         AknsUtils::GetCachedColor( skin, 
  1113         AknsUtils::GetCachedColor( skin, 
  1120                                    colorHightLightRect, 
  1114                                    colorHightLightRect, 
  1121                                    KAknsIIDQsnLineColors, 
  1115                                    KAknsIIDQsnLineColors, 
  1122                                    EAknsCIQsnLineColorsCG7 );
  1116                                    EAknsCIQsnLineColorsCG7 );
  1123         aGc.SetPenColor( colorHightLightRect );
  1117         aGc.SetPenColor( colorHightLightRect );
  1124         aGc.DrawRect( aSctPosition );
  1118         aGc.DrawRect( sctPosition );
  1125 
  1119 
  1126         // Shrink by one pixel in all directions.
  1120         // Shrink by one pixel in all directions.
  1127         TRect innerRect = aSctPosition;
  1121         TRect innerRect = sctPosition;
  1128         innerRect.Shrink( 1,1 );
  1122         innerRect.Shrink( 1,1 );
  1129 
  1123 
  1130         color = AKN_LAF_COLOR( 210 );
  1124         color = AKN_LAF_COLOR( 210 );
  1131         AknsUtils::GetCachedColor( skin, 
  1125         AknsUtils::GetCachedColor( skin, 
  1132                                    color, 
  1126                                    color, 
  1135         aGc.SetBrushColor( color );       
  1129         aGc.SetBrushColor( color );       
  1136         aGc.Clear( innerRect );
  1130         aGc.Clear( innerRect );
  1137         }
  1131         }
  1138     else if ( aDrawBackground )
  1132     else if ( aDrawBackground )
  1139         {
  1133         {
  1140         TRect innerRect = aSctPosition;
  1134         TRect innerRect = sctPosition;
  1141         aGc.SetBrushColor( AKN_LAF_COLOR( 0 ) );
  1135         aGc.SetBrushColor( AKN_LAF_COLOR( 0 ) );
  1142         if ( !skins )
  1136         if ( !skins )
  1143             {
  1137             {
  1144             aGc.Clear( innerRect );
  1138             aGc.Clear( innerRect );
  1145             }
  1139             }
  1157             TRect cellRect( TPoint( 0,0 ), 
  1151             TRect cellRect( TPoint( 0,0 ), 
  1158                             TSize( iGridItemWidth - 1, iGridItemHeight - 1 ) );
  1152                             TSize( iGridItemWidth - 1, iGridItemHeight - 1 ) );
  1159 
  1153 
  1160             CGulIcon* bitmap = NULL;
  1154             CGulIcon* bitmap = NULL;
  1161             bitmap = iConsArray->At( aIconIndex );
  1155             bitmap = iConsArray->At( aIconIndex );
  1162             TInt numIconsInaPage = iExtension->iMaxVisibleRows * iMaxColumns;
  1156 
  1163             TInt cellIndex = aIconIndex;
  1157             aGc.BitBltMasked( CursorPoint( index ),
  1164             if ( aIconIndex >= numIconsInaPage )
       
  1165                 {
       
  1166                 cellIndex = aIconIndex % numIconsInaPage;
       
  1167                 }
       
  1168             aGc.BitBltMasked( CursorPoint( cellIndex ),
       
  1169                             bitmap->Bitmap(),
  1158                             bitmap->Bitmap(),
  1170                             cellRect,
  1159                             cellRect,
  1171                             bitmap->Mask(),
  1160                             bitmap->Mask(),
  1172                             EFalse );
  1161                             EFalse );
  1173             }
  1162             }
  1216     // items.
  1205     // items.
  1217     TRect rect = CursorRect( aCursorPos );
  1206     TRect rect = CursorRect( aCursorPos );
  1218 
  1207 
  1219     Window().Invalidate( rect );
  1208     Window().Invalidate( rect );
  1220     Window().BeginRedraw( rect );
  1209     Window().BeginRedraw( rect );
  1221     DrawItem( SystemGc(), rect, iconIndex, aHighlighted, ETrue );
  1210     DrawItem( SystemGc(), aCursorPos, iconIndex, aHighlighted, ETrue );
  1222     Window().EndRedraw();
  1211     Window().EndRedraw();
  1223     SystemGc().DiscardFont();
  1212     SystemGc().DiscardFont();
  1224     }
  1213     }
  1225 
  1214 
  1226 // -----------------------------------------------------------------------------
  1215 // -----------------------------------------------------------------------------
  1270 // -----------------------------------------------------------------------------
  1259 // -----------------------------------------------------------------------------
  1271 //
  1260 //
  1272 void CCmDestinationIconMap::MoveCursorL( TInt aDeltaX, TInt aDeltaY )
  1261 void CCmDestinationIconMap::MoveCursorL( TInt aDeltaX, TInt aDeltaY )
  1273     {           
  1262     {           
  1274     if ( iIsMirrored )
  1263     if ( iIsMirrored )
       
  1264         {
  1275         aDeltaX = -aDeltaX;
  1265         aDeltaX = -aDeltaX;
       
  1266         }
  1276     
  1267     
  1277     if ( ( iConsArray->Count() < 8 ) )
  1268     if ( ( iConsArray->Count() < 8 ) )
  1278        return;
  1269         {
       
  1270         return;
       
  1271         }
  1279 
  1272 
  1280     iOldCursorPos = iCursorPos;
  1273     iOldCursorPos = iCursorPos;
  1281     TInt oldFirstVisibleRow = iFirstVisibleRow;
  1274     TInt oldFirstVisibleRow = iFirstVisibleRow;
  1282 
  1275 
  1283     TInt globalYPos = iCursorPos.iY + iFirstVisibleRow;
  1276     TInt globalYPos = iCursorPos.iY + iFirstVisibleRow;
  1441             iFirstVisibleRow += iExtension->iMaxVisibleRows;
  1434             iFirstVisibleRow += iExtension->iMaxVisibleRows;
  1442             iCursorPos = TPoint( iCursorPos.iX, 0 );
  1435             iCursorPos = TPoint( iCursorPos.iX, 0 );
  1443             }
  1436             }
  1444         }
  1437         }
  1445        
  1438        
  1446     //TInt increment( 1 );
       
  1447     //if ( aDeltaY < 0 || aDeltaX < 0 )
       
  1448     //    {
       
  1449     ////    increment = -1;
       
  1450     //    }
       
  1451     if ( iRows > iExtension->iMaxVisibleRows && 
  1439     if ( iRows > iExtension->iMaxVisibleRows && 
  1452         ( iOldCursorPos.iY + oldFirstVisibleRow != 
  1440         ( iOldCursorPos.iY + oldFirstVisibleRow != 
  1453           iCursorPos.iY + iFirstVisibleRow ) )
  1441           iCursorPos.iY + iFirstVisibleRow ) )
  1454         {
  1442         {
  1455         UpdateScrollIndicatorL();
  1443         UpdateScrollIndicatorL();
  1569     TRect parent = gridWithScrollLayRect.Rect();
  1557     TRect parent = gridWithScrollLayRect.Rect();
  1570     
  1558     
  1571     TAknWindowComponentLayout scrollbarLayout = 
  1559     TAknWindowComponentLayout scrollbarLayout = 
  1572                                     AknLayoutScalable_Avkon::scroll_pane_cp5();
  1560                                     AknLayoutScalable_Avkon::scroll_pane_cp5();
  1573     
  1561     
  1574     iCurrentPage = ( iFirstVisibleRow / iExtension->iMaxVisibleRows ) + 1;
  1562     vSbarModel.iScrollSpan = iRows;
  1575 
       
  1576     vSbarModel.iScrollSpan = iNumPages * iExtension->iMaxVisibleRows;
       
  1577     vSbarModel.iThumbSpan = iExtension->iMaxVisibleRows;
  1563     vSbarModel.iThumbSpan = iExtension->iMaxVisibleRows;
  1578     
  1564     
  1579     if ( iSBFrame && iSBFrame->TypeOfVScrollBar() == 
  1565     if ( iSBFrame->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan )
  1580          CEikScrollBarFrame::EDoubleSpan )
       
  1581         {    
  1566         {    
  1582         // For EDoubleSpan type scrollbar
  1567         // For EDoubleSpan type scrollbar
  1583         vSbarModel.iThumbPosition = ( iCurrentPage - 1 ) * 
  1568         vSbarModel.iThumbPosition = iFirstVisibleRow;
  1584                                     iExtension->iMaxVisibleRows;
       
  1585         TAknDoubleSpanScrollBarModel hDsSbarModel( hSbarModel );
  1569         TAknDoubleSpanScrollBarModel hDsSbarModel( hSbarModel );
  1586         TAknDoubleSpanScrollBarModel vDsSbarModel( vSbarModel );
  1570         TAknDoubleSpanScrollBarModel vDsSbarModel( vSbarModel );
  1587         
  1571         
  1588         // The y coordinate must be sifted 3 pixels up and x 3 to left
  1572         // The y coordinate must be sifted 3 pixels up and x 3 to left
  1589         parent.iTl.iY -= KVerticalDialogMargin;
  1573         parent.iTl.iY -= KVerticalDialogMargin;
  1673                maxVarietyOffset = varietyOffset;
  1657                maxVarietyOffset = varietyOffset;
  1674                }
  1658                }
  1675             else if ( location == AknLayoutUtils::EAknCbaLocationLeft )
  1659             else if ( location == AknLayoutUtils::EAknCbaLocationLeft )
  1676                {
  1660                {
  1677                maxVarietyOffset = varietyOffset + varietyOffset; // 2*
  1661                maxVarietyOffset = varietyOffset + varietyOffset; // 2*
  1678                }   
  1662                }
       
  1663 
  1679             TInt varietyNumber = varietyOffset - iRows - 1; 
  1664             TInt varietyNumber = varietyOffset - iRows - 1; 
  1680             
  1665             
  1681             // if more lines than possible to show, use the default 
  1666             // if more lines than possible to show, use the default 
  1682             // ( the biggest grid ) variety
  1667             // ( the biggest grid ) variety
  1683             if ( varietyNumber < 0 )
  1668             if ( varietyNumber < 0 )
  1884     
  1869     
  1885     // get the item height
  1870     // get the item height
  1886     TInt cellHeight = cellRect.Height();
  1871     TInt cellHeight = cellRect.Height();
  1887     
  1872     
  1888     // calculate the number of items fitting to grid
  1873     // calculate the number of items fitting to grid
  1889     iExtension->iMaxVisibleRows = 3;//gridHeight / cellHeight;
  1874     iExtension->iMaxVisibleRows = 3; //gridHeight / cellHeight;
  1890     
  1875     
  1891     // Store the item height
  1876     // Store the item height
  1892     TAknLayoutRect secondRowLayRect;
  1877     TAknLayoutRect secondRowLayRect;
  1893     secondRowLayRect.LayoutRect( gridLayRect.Rect(), 
  1878     secondRowLayRect.LayoutRect( gridLayRect.Rect(), 
  1894        AknLayoutScalable_Avkon::cell_graphic_popup_pane( 0,0,1 ) );
  1879        AknLayoutScalable_Avkon::cell_graphic_popup_pane( 0,0,1 ) );
  1911         {       
  1896         {       
  1912         case EEikScrollUp:
  1897         case EEikScrollUp:
  1913         case EEikScrollPageUp:
  1898         case EEikScrollPageUp:
  1914             {           
  1899             {           
  1915             // nothing done if we are already on the first page.
  1900             // nothing done if we are already on the first page.
  1916             if ( iFirstVisibleRow != 0 )
  1901             if ( iFirstVisibleRow > 0 )
  1917                 {               
  1902                 {
  1918                 iFirstVisibleRow -= iExtension->iMaxVisibleRows;             
  1903                 iFirstVisibleRow -= iExtension->iMaxVisibleRows;
       
  1904                 if ( iFirstVisibleRow < 0 )
       
  1905                     {
       
  1906                     iFirstVisibleRow = 0;
       
  1907                     }
  1919                 update = ETrue;
  1908                 update = ETrue;
  1920                 }
  1909                 }
  1921             UpdateScrollIndicatorL();
  1910             UpdateScrollIndicatorL();
  1922             }
  1911             }
  1923             break;
  1912             break;
  1924         
  1913         
  1925         case EEikScrollDown:
  1914         case EEikScrollDown:
  1926         case EEikScrollPageDown:
  1915         case EEikScrollPageDown:
  1927             {           
  1916             {           
  1928             // nothing done if we are already on the last page.
  1917             // nothing done if we are already on the last page.
  1929             if ( iFirstVisibleRow != iRows/iExtension->iMaxVisibleRows * 
  1918             if ( iFirstVisibleRow < iRows - iExtension->iMaxVisibleRows ) 
  1930                                      iExtension->iMaxVisibleRows )
       
  1931                 {
  1919                 {
  1932                 iFirstVisibleRow += iExtension->iMaxVisibleRows;
  1920                 iFirstVisibleRow += iExtension->iMaxVisibleRows;
       
  1921                 if ( iFirstVisibleRow > iRows - iExtension->iMaxVisibleRows )
       
  1922                     {   
       
  1923                     iFirstVisibleRow = iRows - iExtension->iMaxVisibleRows;
       
  1924                     }
  1933                 update = ETrue;
  1925                 update = ETrue;
  1934                 }
  1926                 }
  1935             UpdateScrollIndicatorL();
  1927             UpdateScrollIndicatorL();
  1936             }
  1928             }
  1937             break;   
  1929             break;   
  1938                
  1930                
  1939         case EEikScrollThumbDragVert:
  1931         case EEikScrollThumbDragVert:
  1940             {           
  1932             {        	
  1941             TInt thumbPosition;         
       
  1942             TInt halfPage = iExtension->iMaxVisibleRows/2;
       
  1943             // Ask which type of scrollbar is shown
  1933             // Ask which type of scrollbar is shown
  1944             //CAknAppUi* appUi = iAvkonAppUi;            
  1934             TInt thumbPosition;
       
  1935             TBool isDoubleSpan = ( CEikScrollBarFrame::EDoubleSpan == iSBFrame->TypeOfVScrollBar() );
       
  1936             if ( isDoubleSpan )
       
  1937                 {
       
  1938                 thumbPosition = static_cast <const TAknDoubleSpanScrollBarModel*>( 
       
  1939                                             aScrollBar->Model() )->FocusPosition();
       
  1940                 }
       
  1941             else
       
  1942                 {
       
  1943                 thumbPosition = aScrollBar->Model()->iThumbPosition;
       
  1944                 }
       
  1945             
       
  1946             if ( thumbPosition != iFirstVisibleRow )
       
  1947                 {
       
  1948                 iFirstVisibleRow = thumbPosition;
       
  1949                 update = ETrue;
       
  1950                 }
       
  1951             }
       
  1952             break;
       
  1953         
       
  1954         case EEikScrollThumbReleaseVert:
       
  1955             {
       
  1956             // Ask which type of scrollbar is shown
  1945             TBool isDoubleSpan = 
  1957             TBool isDoubleSpan = 
  1946                 CEikScrollBarFrame::EDoubleSpan == iSBFrame->TypeOfVScrollBar();
  1958                 CEikScrollBarFrame::EDoubleSpan == iSBFrame->TypeOfVScrollBar();
  1947             if ( isDoubleSpan )
  1959             if ( isDoubleSpan )
  1948                 {
  1960                 {
  1949                 thumbPosition = static_cast <const TAknDoubleSpanScrollBarModel*>( 
  1961                 iFirstVisibleRow = static_cast <const TAknDoubleSpanScrollBarModel*>( 
  1950                                             aScrollBar->Model() )->FocusPosition();
  1962                                             aScrollBar->Model() )->FocusPosition();
  1951                 }
  1963                 }
  1952             else
  1964             else
  1953                 {
  1965                 {
  1954                 thumbPosition = aScrollBar->Model()->iThumbPosition;
  1966                 iFirstVisibleRow = aScrollBar->Model()->iThumbPosition;
  1955                 }
  1967                 }
  1956 
  1968             update = ETrue;
  1957             // If the slider is in the range of less then a half page from a 
       
  1958             // possible correct thumb position. thus 0 <= iFirstVisibleRow - 
       
  1959             // thumbPosition < halfPage. Or in the other direction:
       
  1960             // 0 <= thumbPosition - iFirstVisibleRow < halfPage
       
  1961             if ( !( ( 0 <= iFirstVisibleRow - thumbPosition &&
       
  1962                         iFirstVisibleRow - thumbPosition < halfPage )||                         
       
  1963                   ( 0 <= thumbPosition - iFirstVisibleRow && 
       
  1964                         thumbPosition - iFirstVisibleRow < halfPage ) ) )
       
  1965                 {               
       
  1966                 TReal toRound = thumbPosition / 
       
  1967                                 ( TReal )iExtension->iMaxVisibleRows;
       
  1968                 if ( toRound * 2 > ( TInt )toRound * 2 + 1 )
       
  1969                     {
       
  1970                     toRound++;
       
  1971                     }                  
       
  1972                 iFirstVisibleRow = ( TInt )toRound * 
       
  1973                                    iExtension->iMaxVisibleRows;
       
  1974                 update = ETrue;
       
  1975                 }
       
  1976             }
       
  1977             break;
       
  1978         
       
  1979         case EEikScrollThumbReleaseVert:
       
  1980             {
       
  1981             UpdateScrollIndicatorL();
  1969             UpdateScrollIndicatorL();
  1982             }
  1970             }
  1983             break;
  1971             break;
  1984         
  1972         
  1985         case EEikScrollLeft: // flow through            
  1973         case EEikScrollLeft: // flow through            
  1986         case EEikScrollRight: // flow through
  1974         case EEikScrollRight: // flow through
  1987         case EEikScrollPageLeft: // flow through
  1975         case EEikScrollPageLeft: // flow through
  1988         case EEikScrollPageRight: // flow through
  1976         case EEikScrollPageRight: // flow through
  1989         case EEikScrollThumbDragHoriz: // flow through
  1977         case EEikScrollThumbDragHoriz: // flow through
  1990         case EEikScrollThumbReleaseHoriz: // flow through
  1978         case EEikScrollThumbReleaseHoriz: // flow through
  1991             // do nothing
       
  1992             break;  
       
  1993             
       
  1994         default: 
  1979         default: 
  1995             // do nothing
  1980             // do nothing
  1996             break; 
  1981             break; 
  1997         }
  1982         }
  1998         
  1983                 
  1999     // If we have moved down to the last page we check that the cursor is in 
       
  2000     // a place where it can be drawn.       
       
  2001     if ( iFirstVisibleRow == 
       
  2002          iRows/iExtension->iMaxVisibleRows * iExtension->iMaxVisibleRows )
       
  2003         {
       
  2004         // the old cursor is set to a "safe" position where it at least can be.
       
  2005         iOldCursorPos.iX = 0;
       
  2006         iOldCursorPos.iY = 0;                                                    
       
  2007         // if the last page has only one line which isn't filled complitely.
       
  2008         if ( ( iConsArray->Count() % iMaxColumns - 1 < iCursorPos.iX ) && 
       
  2009              ( iRows % iExtension->iMaxVisibleRows ) == 1 )
       
  2010             {
       
  2011             iCursorPos.iX = iConsArray->Count()%iMaxColumns - 1;
       
  2012             }                        
       
  2013         // If the cursor is in a position where it would go unto a spot without 
       
  2014         // a icon when scrolled.
       
  2015         if ( iCursorPos.iY + iFirstVisibleRow >= iRows )
       
  2016             {                        
       
  2017             if ( iConsArray->Count() % iMaxColumns > iCursorPos.iX )
       
  2018                 {                                                      
       
  2019                 iCursorPos.iY = iRows - 1 - iFirstVisibleRow;                             
       
  2020                 }
       
  2021             else
       
  2022                 {                            
       
  2023                 iCursorPos.iY = iRows - 2 - iFirstVisibleRow;
       
  2024                 } 
       
  2025             }
       
  2026         // If the cursor is actually on the last row, but is still in the
       
  2027         // area where there is now icons. ( the rest of the last row )
       
  2028         if ( ( iConsArray->Count() <= ( iFirstVisibleRow + iCursorPos.iY ) 
       
  2029                                         * iMaxColumns + iCursorPos.iX ) &&
       
  2030              ( iCursorPos.iY + iFirstVisibleRow + 1 == iRows ) )
       
  2031             {
       
  2032             iCursorPos.iY--;
       
  2033             }
       
  2034         // if the corrections did not help and the cursor is in the area
       
  2035         // where there is a valid row, but no icons anymore
       
  2036         }
       
  2037         
       
  2038     // to avoid flicker we draw only if there really was something new to draw.
  1984     // to avoid flicker we draw only if there really was something new to draw.
  2039     if ( update )
  1985     if ( update )
  2040         {              
  1986         {              
  2041         if ( iExtension->iObserver )
  1987         if ( iExtension->iObserver )
  2042             {
  1988             {