uifw/EikStd/coctlsrc/EIKLBV.CPP
branchRCL_3
changeset 56 d48ab3b357f1
parent 55 aecbbf00d063
child 72 a5e7a4f63858
equal deleted inserted replaced
55:aecbbf00d063 56:d48ab3b357f1
     1 /*
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 1997-2010 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".
   655     _AKNTRACE_FUNC_EXIT;
   655     _AKNTRACE_FUNC_EXIT;
   656 	}
   656 	}
   657 
   657 
   658 EXPORT_C TInt CListBoxView::NumberOfItemsThatFitInRect(const TRect& aRect) const
   658 EXPORT_C TInt CListBoxView::NumberOfItemsThatFitInRect(const TRect& aRect) const
   659 	{
   659 	{
       
   660     TInt itemNumber = 0;
   660 	if (iItemHeight == 0)
   661 	if (iItemHeight == 0)
   661 	    {
   662 	    {
   662 	    _AKNTRACE( "Number of items is 0" );
   663 	    _AKNTRACE( "Number of items is 0" );
   663 		return 0;
   664 		return itemNumber;
   664 	    }
   665 	    }
   665     TInt items = aRect.Height() / iItemHeight;
   666     TInt items = aRect.Height() / iItemHeight;     
   666 	if ( ( iVerticalOffset != 0 ) || ( (aRect.Height() - iVerticalOffset) % iItemHeight > 0 ) ) items++;
   667     TInt extraHeight = aRect.Height() % iItemHeight;
   667 	_AKNTRACE( "Number of items is %d", items );
   668     // if there is offset or extra height, then there is at least one partical
   668 	return items;
   669     // displayed item
       
   670     if ( iVerticalOffset != 0 || extraHeight > 0 )
       
   671         {
       
   672         items++;
       
   673         }
       
   674     // if extra height is not totally taken by top partically displayed item,
       
   675     // then there is still place to display a partcial item in bottom. consider
       
   676     // a example which view height is 35 and item height is 10, then it's possible
       
   677     // to display 5 items with the height like 3,10,10,10,2
       
   678     if ( iVerticalOffset != 0 && 
       
   679          extraHeight != 0 && 
       
   680          ( iItemHeight + iVerticalOffset ) < extraHeight )
       
   681         {
       
   682         items++;
       
   683         }
       
   684     itemNumber = items;
       
   685 	_AKNTRACE( "Number of items is %d", itemNumber );
       
   686 	return itemNumber;
   669 	}
   687 	}
   670 
   688 
   671 EXPORT_C void CListBoxView::DeselectRangeL(TInt aItemIndex1, TInt aItemIndex2)
   689 EXPORT_C void CListBoxView::DeselectRangeL(TInt aItemIndex1, TInt aItemIndex2)
   672 	{
   690 	{
   673 	TInt startItem, endItem;
   691 	TInt startItem, endItem;
   813                 DrawItem(oldCurrentItemIndex);
   831                 DrawItem(oldCurrentItemIndex);
   814 	            }	    
   832 	            }	    
   815 	        }
   833 	        }
   816 	    else // items will get redrawn anyway
   834 	    else // items will get redrawn anyway
   817 	        {
   835 	        {
       
   836             // As the iVerticalOffset is changed in CalcNewTopItemIndexSoItemIsVisible(),
       
   837             // and ScrollToMakeItemVisible() will call the CalcNewTopItemIndexSoItemIsVisible() again,
       
   838             // which will use iVerticalOffset to do some judgementes,
       
   839             // we must set iVerticalOffset back to original value.
       
   840             iVerticalOffset = oldVerticalOffset;
   818 	        ScrollToMakeItemVisible(iCurrentItemIndex);
   841 	        ScrollToMakeItemVisible(iCurrentItemIndex);
   819 	        }
   842 	        }
   820         UpdateSelectionL(aSelectionMode);
   843         UpdateSelectionL(aSelectionMode);
   821         iFlags &= ~EOffsetChanged;
   844         iFlags &= ~EOffsetChanged;
   822 	    }
   845 	    }
   949 	    {
   972 	    {
   950 	    _AKNTRACE_FUNC_EXIT;
   973 	    _AKNTRACE_FUNC_EXIT;
   951 		return;
   974 		return;
   952 	    }
   975 	    }
   953 
   976 
   954     TBool transparencyEnabled( CAknEnv::Static()->TransparencyEnabled() );
       
   955 
       
   956     if ((ITEM_EXISTS_ONCE(aItemIndex)) && ItemIsVisible(aItemIndex))
   977     if ((ITEM_EXISTS_ONCE(aItemIndex)) && ItemIsVisible(aItemIndex))
   957 		{
   978 		{
   958 		TBool drawingInitiated = ETrue;
   979 		TBool drawingInitiated = ETrue;
   959 
   980 
   960 		if ( transparencyEnabled )
   981         if ( iWin && iWin->GetDrawRect() == TRect::EUninitialized )
   961 		    {
   982             {
   962 		    if ( iWin && iWin->GetDrawRect() == TRect::EUninitialized )
       
   963 			    {
       
   964 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
   983 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
   965                 MAknListBoxTfxInternal* transApi =
   984             MAknListBoxTfxInternal* transApi =
   966                     CAknListLoader::TfxApiInternal( iGc );
   985                 CAknListLoader::TfxApiInternal( iGc );
   967                 drawingInitiated = transApi && !transApi->EffectsDisabled();
   986             drawingInitiated = transApi && !transApi->EffectsDisabled();
   968 #else
   987 #else
   969                 drawingInitiated = EFalse;
   988             drawingInitiated = EFalse;
   970 #endif			
   989 #endif			
   971                 }
   990             }
   972 
   991 
   973             if ( !drawingInitiated )
   992         if ( !drawingInitiated )
   974 			    {
   993             {
   975                 TRect rect( ItemPos(aItemIndex), ItemSize(aItemIndex) );
   994             TRect rect( ItemPos(aItemIndex), iItemDrawer->ItemCellSize() );
   976 			    rect.Intersection( iViewRect );
   995             rect.Intersection( iViewRect );
   977 			    iWin->Invalidate( rect );
   996             iWin->Invalidate( rect );
   978 			    iWin->BeginRedraw( rect );
   997             iWin->BeginRedraw( rect );
   979 			    }
   998             }
   980 		    }
       
   981 		
   999 		
   982 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
  1000 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
   983         MAknListBoxTfxInternal *transApi = CAknListLoader::TfxApiInternal( iGc );
  1001         MAknListBoxTfxInternal *transApi = CAknListLoader::TfxApiInternal( iGc );
   984         if ( transApi )
  1002         if ( transApi )
   985             {
  1003             {
   987                                 ItemSize(aItemIndex) );
  1005                                 ItemSize(aItemIndex) );
   988             transApi->BeginRedraw( MAknListBoxTfxInternal::EListItem, rect, aItemIndex );
  1006             transApi->BeginRedraw( MAknListBoxTfxInternal::EListItem, rect, aItemIndex );
   989             transApi->StartDrawing( MAknListBoxTfxInternal::EListItem );
  1007             transApi->StartDrawing( MAknListBoxTfxInternal::EListItem );
   990             }
  1008             }
   991 #endif // RD_UI_TRANSITION_EFFECTS_LIST
  1009 #endif // RD_UI_TRANSITION_EFFECTS_LIST
       
  1010 
       
  1011         TBool backgroundDrawingSuppressed = ( iItemDrawer 
       
  1012 		        && ( iItemDrawer->Flags() 
       
  1013                 & ( CListItemDrawer::EDrawWholeBackground
       
  1014                 | CListItemDrawer::EBackgroundDrawn ) ) );
   992         
  1015         
   993         iGc->SetClippingRect( iViewRect );
  1016         if ( !backgroundDrawingSuppressed )
       
  1017             {
       
  1018             iGc->SetClippingRect( iViewRect );
       
  1019             }
   994 
  1020 
   995 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
  1021 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
   996         if ( transApi )
  1022         if ( transApi )
   997             {
  1023             {
   998             transApi->StopDrawing();
  1024             transApi->StopDrawing();
  1009             {
  1035             {
  1010             transApi->StartDrawing( MAknListBoxTfxInternal::EListItem );
  1036             transApi->StartDrawing( MAknListBoxTfxInternal::EListItem );
  1011             }
  1037             }
  1012 #endif // RD_UI_TRANSITION_EFFECTS_LIST
  1038 #endif // RD_UI_TRANSITION_EFFECTS_LIST
  1013             
  1039             
  1014 		iGc->CancelClippingRect();
  1040         if ( !backgroundDrawingSuppressed )
       
  1041             {
       
  1042     		iGc->CancelClippingRect();
       
  1043             }
  1015 
  1044 
  1016 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
  1045 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
  1017         if ( transApi )
  1046         if ( transApi )
  1018             {
  1047             {
  1019             transApi->StopDrawing();
  1048             transApi->StopDrawing();
  1025             {
  1054             {
  1026             transApi->EndRedraw( MAknListBoxTfxInternal::EListItem, aItemIndex );
  1055             transApi->EndRedraw( MAknListBoxTfxInternal::EListItem, aItemIndex );
  1027             }
  1056             }
  1028 #endif // RD_UI_TRANSITION_EFFECTS_LIST
  1057 #endif // RD_UI_TRANSITION_EFFECTS_LIST
  1029 
  1058 
  1030 		if ( transparencyEnabled && !drawingInitiated )
  1059         if ( !drawingInitiated )
  1031 			{
  1060 			{
  1032 			iWin->EndRedraw();
  1061 			iWin->EndRedraw();
  1033 			}
  1062 			}
  1034 		}
  1063 		}
  1035     _AKNTRACE_FUNC_EXIT;
  1064     _AKNTRACE_FUNC_EXIT;
  1180 	_AKNTRACE_FUNC_ENTER;
  1209 	_AKNTRACE_FUNC_ENTER;
  1181 #ifdef _DEBUG
  1210 #ifdef _DEBUG
  1182     RDebug::Print( _L( "CListBoxView::CalcNewTopItemIndexSoItemIsVisible" ) );
  1211     RDebug::Print( _L( "CListBoxView::CalcNewTopItemIndexSoItemIsVisible" ) );
  1183 #endif // _DEBUG
  1212 #endif // _DEBUG
  1184 	TInt newTopItemIndex=iTopItemIndex;
  1213 	TInt newTopItemIndex=iTopItemIndex;
  1185 	const TInt numItemsThatFitInRect=NumberOfItemsThatFitInRect(iViewRect);
  1214 	const TInt numItemsThatFitInRect=NumberOfItemsThatFitInRect( iViewRect );
  1186 	if (aItemIndex < iTopItemIndex || numItemsThatFitInRect == 0)
  1215 	if ( aItemIndex < iTopItemIndex || numItemsThatFitInRect == 0 )
       
  1216         {
  1187 		newTopItemIndex = aItemIndex;
  1217 		newTopItemIndex = aItemIndex;
  1188 	else if (aItemIndex > iBottomItemIndex)
  1218         }   
  1189 		newTopItemIndex = aItemIndex - numItemsThatFitInRect + 1;
  1219 	else 
       
  1220         {
       
  1221         if (aItemIndex > iBottomItemIndex)
       
  1222 		   {
       
  1223 	       newTopItemIndex = aItemIndex - numItemsThatFitInRect + 1;
       
  1224 		   }
       
  1225         }
  1190 
  1226 
  1191 	if (!ITEM_EXISTS_ONCE(newTopItemIndex) && newTopItemIndex != 0 )
  1227 	if (!ITEM_EXISTS_ONCE(newTopItemIndex) && newTopItemIndex != 0 )
  1192 		{ // if application fails to call HandleItemAdditionL(), we might go here.
  1228 		{ // if application fails to call HandleItemAdditionL(), we might go here.
  1193 		  // we dont want our OfferKeyEventL() to panic in that case.
  1229 		  // we dont want our OfferKeyEventL() to panic in that case.
  1194 		newTopItemIndex = iTopItemIndex;
  1230 		newTopItemIndex = iTopItemIndex;
  1210             }
  1246             }
  1211         else
  1247         else
  1212             {
  1248             {
  1213             me->SetItemOffsetInPixels( 0 );
  1249             me->SetItemOffsetInPixels( 0 );
  1214             }
  1250             }
       
  1251         //after reset vertical offset, 
       
  1252         //the number of items which fit in the view maybe change
       
  1253         TInt newNumItemsThatFitInRect = NumberOfItemsThatFitInRect( iViewRect );
       
  1254         if ( newNumItemsThatFitInRect != numItemsThatFitInRect )
       
  1255         	{
       
  1256 			newTopItemIndex = aItemIndex - newNumItemsThatFitInRect + 1;
       
  1257         	}
  1215 	    }
  1258 	    }
  1216 
  1259 
  1217 	_AKNTRACE_FUNC_EXIT;
  1260 	_AKNTRACE_FUNC_EXIT;
  1218     return newTopItemIndex;
  1261     return newTopItemIndex;
  1219 	}
  1262 	}
  1405     _AKNTRACE( "itemPartiallyVisible is %d", itemPartiallyVisible );
  1448     _AKNTRACE( "itemPartiallyVisible is %d", itemPartiallyVisible );
  1406     _AKNTRACE_FUNC_EXIT;
  1449     _AKNTRACE_FUNC_EXIT;
  1407     return itemPartiallyVisible;
  1450     return itemPartiallyVisible;
  1408     }
  1451     }
  1409 
  1452 
       
  1453 
       
  1454 // ---------------------------------------------------------------------------
       
  1455 // Resets the selection state so that there is nothing selected.
       
  1456 // ---------------------------------------------------------------------------
       
  1457 //
       
  1458 void CListBoxView::ClearSelection( TBool aDrawItems )
       
  1459     {
       
  1460     _AKNTRACE_FUNC_ENTER;
       
  1461 
       
  1462     __ASSERT_DEBUG( iSelectionIndexes,
       
  1463                     Panic( EEikPanicListBoxNoSelIndexArray ) );
       
  1464 
       
  1465     TInt numSelectedItems = iSelectionIndexes->Count();
       
  1466     TKeyArrayFix key( 0, ECmpTInt );
       
  1467     TInt selectedItemIndex;
       
  1468     TInt pos;
       
  1469 
       
  1470 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
  1471     MAknListBoxTfxInternal* transApi = CAknListLoader::TfxApiInternal( iGc );
       
  1472 #endif // RD_UI_TRANSITION_EFFECTS_LIST
       
  1473     
       
  1474     for ( TInt i = 0; i < numSelectedItems; i++ )
       
  1475         {
       
  1476         selectedItemIndex = ( *( iSelectionIndexes ) )[0];
       
  1477 
       
  1478         if ( !( iSelectionIndexes->Find( selectedItemIndex, key, pos ) ) )
       
  1479             {
       
  1480 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
  1481             if ( transApi )
       
  1482                 {
       
  1483                 transApi->Invalidate( MAknListBoxTfxInternal::EListItem,
       
  1484                                       selectedItemIndex );
       
  1485                 }
       
  1486 #endif // RD_UI_TRANSITION_EFFECTS_LIST
       
  1487 
       
  1488             iSelectionIndexes->Delete( pos );
       
  1489 
       
  1490             if ( aDrawItems )
       
  1491                 {
       
  1492                 DrawItem( selectedItemIndex );
       
  1493                 }
       
  1494             }
       
  1495         }
       
  1496 
       
  1497     ClearSelectionAnchorAndActiveIndex();
       
  1498 
       
  1499     _AKNTRACE_FUNC_EXIT;
       
  1500     }
       
  1501 
       
  1502 
       
  1503 // ---------------------------------------------------------------------------
       
  1504 // Sets all items selected.
       
  1505 // ---------------------------------------------------------------------------
       
  1506 //
       
  1507 void CListBoxView::SelectAllL( TBool aDrawItems )
       
  1508     {
       
  1509     _AKNTRACE_FUNC_ENTER;
       
  1510     
       
  1511     __ASSERT_DEBUG( iSelectionIndexes, 
       
  1512                     Panic( EEikPanicListBoxNoSelIndexArray ) );
       
  1513     __ASSERT_DEBUG( iModel, Panic( EEikPanicListBoxNoModel ) );
       
  1514     
       
  1515 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
  1516     MAknListBoxTfxInternal* transApi = CAknListLoader::TfxApiInternal( iGc );
       
  1517 #endif // RD_UI_TRANSITION_EFFECTS_LIST    
       
  1518     
       
  1519     ClearSelection();
       
  1520     TInt numItems = iModel->NumberOfItems();
       
  1521     
       
  1522     for ( TInt i = 0; i < numItems; i++ )
       
  1523         {
       
  1524         if ( !iItemDrawer->Properties( i ).IsSelectionHidden() ) 
       
  1525             { 
       
  1526 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
  1527             if ( transApi )
       
  1528                 {
       
  1529                 transApi->Invalidate( MAknListBoxTfxInternal::EListItem, i );
       
  1530                 }
       
  1531 #endif // RD_UI_TRANSITION_EFFECTS_LIST
       
  1532             
       
  1533             iSelectionIndexes->AppendL( i );
       
  1534             
       
  1535             if ( aDrawItems )
       
  1536                 {
       
  1537                 DrawItem( i );
       
  1538                 }
       
  1539             }
       
  1540         }
       
  1541     _AKNTRACE_FUNC_EXIT;
       
  1542     }
  1410 
  1543 
  1411 
  1544 
  1412 // class CSnakingListBoxView
  1545 // class CSnakingListBoxView
  1413 
  1546 
  1414 EXPORT_C CSnakingListBoxView::CSnakingListBoxView()
  1547 EXPORT_C CSnakingListBoxView::CSnakingListBoxView()