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; |
1191 _AKNTRACE_FUNC_ENTER; |
1209 _AKNTRACE_FUNC_ENTER; |
1192 #ifdef _DEBUG |
1210 #ifdef _DEBUG |
1193 RDebug::Print( _L( "CListBoxView::CalcNewTopItemIndexSoItemIsVisible" ) ); |
1211 RDebug::Print( _L( "CListBoxView::CalcNewTopItemIndexSoItemIsVisible" ) ); |
1194 #endif // _DEBUG |
1212 #endif // _DEBUG |
1195 TInt newTopItemIndex=iTopItemIndex; |
1213 TInt newTopItemIndex=iTopItemIndex; |
1196 const TInt numItemsThatFitInRect=NumberOfItemsThatFitInRect(iViewRect); |
1214 const TInt numItemsThatFitInRect=NumberOfItemsThatFitInRect( iViewRect ); |
1197 if (aItemIndex < iTopItemIndex || numItemsThatFitInRect == 0) |
1215 if ( aItemIndex < iTopItemIndex || numItemsThatFitInRect == 0 ) |
|
1216 { |
1198 newTopItemIndex = aItemIndex; |
1217 newTopItemIndex = aItemIndex; |
1199 else if (aItemIndex > iBottomItemIndex) |
1218 } |
1200 newTopItemIndex = aItemIndex - numItemsThatFitInRect + 1; |
1219 else |
1201 else if ( ( iVerticalOffset < 0 ) |
|
1202 && ( aItemIndex == iBottomItemIndex ) |
|
1203 && ( 0 == iViewRect.Height() % iItemHeight ) ) |
|
1204 { |
1220 { |
1205 newTopItemIndex += 1; |
1221 if (aItemIndex > iBottomItemIndex) |
|
1222 { |
|
1223 newTopItemIndex = aItemIndex - numItemsThatFitInRect + 1; |
|
1224 } |
1206 } |
1225 } |
1207 |
1226 |
1208 if (!ITEM_EXISTS_ONCE(newTopItemIndex) && newTopItemIndex != 0 ) |
1227 if (!ITEM_EXISTS_ONCE(newTopItemIndex) && newTopItemIndex != 0 ) |
1209 { // if application fails to call HandleItemAdditionL(), we might go here. |
1228 { // if application fails to call HandleItemAdditionL(), we might go here. |
1210 // we dont want our OfferKeyEventL() to panic in that case. |
1229 // we dont want our OfferKeyEventL() to panic in that case. |
1227 } |
1246 } |
1228 else |
1247 else |
1229 { |
1248 { |
1230 me->SetItemOffsetInPixels( 0 ); |
1249 me->SetItemOffsetInPixels( 0 ); |
1231 } |
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 } |
1232 } |
1258 } |
1233 |
1259 |
1234 _AKNTRACE_FUNC_EXIT; |
1260 _AKNTRACE_FUNC_EXIT; |
1235 return newTopItemIndex; |
1261 return newTopItemIndex; |
1236 } |
1262 } |