uifw/EikStd/coctlsrc/EIKLBV.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) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 1997-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".
   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;
       
   661 	if (iItemHeight == 0)
   660 	if (iItemHeight == 0)
   662 	    {
   661 	    {
   663 	    _AKNTRACE( "Number of items is 0" );
   662 	    _AKNTRACE( "Number of items is 0" );
   664 		return itemNumber;
   663 		return 0;
   665 	    }
   664 	    }
   666     TInt items = aRect.Height() / iItemHeight;     
   665     TInt items = aRect.Height() / iItemHeight;
   667     TInt extraHeight = aRect.Height() % iItemHeight;
   666 	if ( ( iVerticalOffset != 0 ) || ( (aRect.Height() - iVerticalOffset) % iItemHeight > 0 ) ) items++;
   668     // if there is offset or extra height, then there is at least one partical
   667 	_AKNTRACE( "Number of items is %d", items );
   669     // displayed item
   668 	return items;
   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;
       
   687 	}
   669 	}
   688 
   670 
   689 EXPORT_C void CListBoxView::DeselectRangeL(TInt aItemIndex1, TInt aItemIndex2)
   671 EXPORT_C void CListBoxView::DeselectRangeL(TInt aItemIndex1, TInt aItemIndex2)
   690 	{
   672 	{
   691 	TInt startItem, endItem;
   673 	TInt startItem, endItem;
   831                 DrawItem(oldCurrentItemIndex);
   813                 DrawItem(oldCurrentItemIndex);
   832 	            }	    
   814 	            }	    
   833 	        }
   815 	        }
   834 	    else // items will get redrawn anyway
   816 	    else // items will get redrawn anyway
   835 	        {
   817 	        {
   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;
       
   841 	        ScrollToMakeItemVisible(iCurrentItemIndex);
   818 	        ScrollToMakeItemVisible(iCurrentItemIndex);
   842 	        }
   819 	        }
   843         UpdateSelectionL(aSelectionMode);
   820         UpdateSelectionL(aSelectionMode);
   844         iFlags &= ~EOffsetChanged;
   821         iFlags &= ~EOffsetChanged;
   845 	    }
   822 	    }
   972 	    {
   949 	    {
   973 	    _AKNTRACE_FUNC_EXIT;
   950 	    _AKNTRACE_FUNC_EXIT;
   974 		return;
   951 		return;
   975 	    }
   952 	    }
   976 
   953 
       
   954     TBool transparencyEnabled( CAknEnv::Static()->TransparencyEnabled() );
       
   955 
   977     if ((ITEM_EXISTS_ONCE(aItemIndex)) && ItemIsVisible(aItemIndex))
   956     if ((ITEM_EXISTS_ONCE(aItemIndex)) && ItemIsVisible(aItemIndex))
   978 		{
   957 		{
   979 		TBool drawingInitiated = ETrue;
   958 		TBool drawingInitiated = ETrue;
   980 
   959 
   981         if ( iWin && iWin->GetDrawRect() == TRect::EUninitialized )
   960 		if ( transparencyEnabled )
   982             {
   961 		    {
       
   962 		    if ( iWin && iWin->GetDrawRect() == TRect::EUninitialized )
       
   963 			    {
   983 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
   964 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
   984             MAknListBoxTfxInternal* transApi =
   965                 MAknListBoxTfxInternal* transApi =
   985                 CAknListLoader::TfxApiInternal( iGc );
   966                     CAknListLoader::TfxApiInternal( iGc );
   986             drawingInitiated = transApi && !transApi->EffectsDisabled();
   967                 drawingInitiated = transApi && !transApi->EffectsDisabled();
   987 #else
   968 #else
   988             drawingInitiated = EFalse;
   969                 drawingInitiated = EFalse;
   989 #endif			
   970 #endif			
   990             }
   971                 }
   991 
   972 
   992         if ( !drawingInitiated )
   973             if ( !drawingInitiated )
   993             {
   974 			    {
   994             TRect rect( ItemPos(aItemIndex), iItemDrawer->ItemCellSize() );
   975                 TRect rect( ItemPos(aItemIndex), ItemSize(aItemIndex) );
   995             rect.Intersection( iViewRect );
   976 			    rect.Intersection( iViewRect );
   996             iWin->Invalidate( rect );
   977 			    iWin->Invalidate( rect );
   997             iWin->BeginRedraw( rect );
   978 			    iWin->BeginRedraw( rect );
   998             }
   979 			    }
       
   980 		    }
   999 		
   981 		
  1000 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
   982 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
  1001         MAknListBoxTfxInternal *transApi = CAknListLoader::TfxApiInternal( iGc );
   983         MAknListBoxTfxInternal *transApi = CAknListLoader::TfxApiInternal( iGc );
  1002         if ( transApi )
   984         if ( transApi )
  1003             {
   985             {
  1005                                 ItemSize(aItemIndex) );
   987                                 ItemSize(aItemIndex) );
  1006             transApi->BeginRedraw( MAknListBoxTfxInternal::EListItem, rect, aItemIndex );
   988             transApi->BeginRedraw( MAknListBoxTfxInternal::EListItem, rect, aItemIndex );
  1007             transApi->StartDrawing( MAknListBoxTfxInternal::EListItem );
   989             transApi->StartDrawing( MAknListBoxTfxInternal::EListItem );
  1008             }
   990             }
  1009 #endif // RD_UI_TRANSITION_EFFECTS_LIST
   991 #endif // RD_UI_TRANSITION_EFFECTS_LIST
  1010 
       
  1011         TBool backgroundDrawingSuppressed = ( iItemDrawer 
       
  1012 		        && ( iItemDrawer->Flags() 
       
  1013                 & ( CListItemDrawer::EDrawWholeBackground
       
  1014                 | CListItemDrawer::EBackgroundDrawn ) ) );
       
  1015         
   992         
  1016         if ( !backgroundDrawingSuppressed )
   993         iGc->SetClippingRect( iViewRect );
  1017             {
       
  1018             iGc->SetClippingRect( iViewRect );
       
  1019             }
       
  1020 
   994 
  1021 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
   995 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
  1022         if ( transApi )
   996         if ( transApi )
  1023             {
   997             {
  1024             transApi->StopDrawing();
   998             transApi->StopDrawing();
  1035             {
  1009             {
  1036             transApi->StartDrawing( MAknListBoxTfxInternal::EListItem );
  1010             transApi->StartDrawing( MAknListBoxTfxInternal::EListItem );
  1037             }
  1011             }
  1038 #endif // RD_UI_TRANSITION_EFFECTS_LIST
  1012 #endif // RD_UI_TRANSITION_EFFECTS_LIST
  1039             
  1013             
  1040         if ( !backgroundDrawingSuppressed )
  1014 		iGc->CancelClippingRect();
  1041             {
       
  1042     		iGc->CancelClippingRect();
       
  1043             }
       
  1044 
  1015 
  1045 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
  1016 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
  1046         if ( transApi )
  1017         if ( transApi )
  1047             {
  1018             {
  1048             transApi->StopDrawing();
  1019             transApi->StopDrawing();
  1054             {
  1025             {
  1055             transApi->EndRedraw( MAknListBoxTfxInternal::EListItem, aItemIndex );
  1026             transApi->EndRedraw( MAknListBoxTfxInternal::EListItem, aItemIndex );
  1056             }
  1027             }
  1057 #endif // RD_UI_TRANSITION_EFFECTS_LIST
  1028 #endif // RD_UI_TRANSITION_EFFECTS_LIST
  1058 
  1029 
  1059         if ( !drawingInitiated )
  1030 		if ( transparencyEnabled && !drawingInitiated )
  1060 			{
  1031 			{
  1061 			iWin->EndRedraw();
  1032 			iWin->EndRedraw();
  1062 			}
  1033 			}
  1063 		}
  1034 		}
  1064     _AKNTRACE_FUNC_EXIT;
  1035     _AKNTRACE_FUNC_EXIT;
  1209 	_AKNTRACE_FUNC_ENTER;
  1180 	_AKNTRACE_FUNC_ENTER;
  1210 #ifdef _DEBUG
  1181 #ifdef _DEBUG
  1211     RDebug::Print( _L( "CListBoxView::CalcNewTopItemIndexSoItemIsVisible" ) );
  1182     RDebug::Print( _L( "CListBoxView::CalcNewTopItemIndexSoItemIsVisible" ) );
  1212 #endif // _DEBUG
  1183 #endif // _DEBUG
  1213 	TInt newTopItemIndex=iTopItemIndex;
  1184 	TInt newTopItemIndex=iTopItemIndex;
  1214 	const TInt numItemsThatFitInRect=NumberOfItemsThatFitInRect( iViewRect );
  1185 	const TInt numItemsThatFitInRect=NumberOfItemsThatFitInRect(iViewRect);
  1215 	if ( aItemIndex < iTopItemIndex || numItemsThatFitInRect == 0 )
  1186 	if (aItemIndex < iTopItemIndex || numItemsThatFitInRect == 0)
  1216         {
       
  1217 		newTopItemIndex = aItemIndex;
  1187 		newTopItemIndex = aItemIndex;
  1218         }   
  1188 	else if (aItemIndex > iBottomItemIndex)
  1219 	else 
  1189 		newTopItemIndex = aItemIndex - numItemsThatFitInRect + 1;
  1220         {
       
  1221         if (aItemIndex > iBottomItemIndex)
       
  1222 		   {
       
  1223 	       newTopItemIndex = aItemIndex - numItemsThatFitInRect + 1;
       
  1224 		   }
       
  1225         }
       
  1226 
  1190 
  1227 	if (!ITEM_EXISTS_ONCE(newTopItemIndex) && newTopItemIndex != 0 )
  1191 	if (!ITEM_EXISTS_ONCE(newTopItemIndex) && newTopItemIndex != 0 )
  1228 		{ // if application fails to call HandleItemAdditionL(), we might go here.
  1192 		{ // if application fails to call HandleItemAdditionL(), we might go here.
  1229 		  // we dont want our OfferKeyEventL() to panic in that case.
  1193 		  // we dont want our OfferKeyEventL() to panic in that case.
  1230 		newTopItemIndex = iTopItemIndex;
  1194 		newTopItemIndex = iTopItemIndex;
  1246             }
  1210             }
  1247         else
  1211         else
  1248             {
  1212             {
  1249             me->SetItemOffsetInPixels( 0 );
  1213             me->SetItemOffsetInPixels( 0 );
  1250             }
  1214             }
  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         	}
       
  1258 	    }
  1215 	    }
  1259 
  1216 
  1260 	_AKNTRACE_FUNC_EXIT;
  1217 	_AKNTRACE_FUNC_EXIT;
  1261     return newTopItemIndex;
  1218     return newTopItemIndex;
  1262 	}
  1219 	}
  1448     _AKNTRACE( "itemPartiallyVisible is %d", itemPartiallyVisible );
  1405     _AKNTRACE( "itemPartiallyVisible is %d", itemPartiallyVisible );
  1449     _AKNTRACE_FUNC_EXIT;
  1406     _AKNTRACE_FUNC_EXIT;
  1450     return itemPartiallyVisible;
  1407     return itemPartiallyVisible;
  1451     }
  1408     }
  1452 
  1409 
  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     }
       
  1543 
  1410 
  1544 
  1411 
  1545 // class CSnakingListBoxView
  1412 // class CSnakingListBoxView
  1546 
  1413 
  1547 EXPORT_C CSnakingListBoxView::CSnakingListBoxView()
  1414 EXPORT_C CSnakingListBoxView::CSnakingListBoxView()