37 #include <akntransitionutils.h> |
37 #include <akntransitionutils.h> |
38 #include <aknlistloadertfx.h> |
38 #include <aknlistloadertfx.h> |
39 #endif |
39 #endif |
40 |
40 |
41 CMmListBoxView::CMmListBoxView () |
41 CMmListBoxView::CMmListBoxView () |
42 { |
42 { |
43 // No implementation required |
43 // No implementation required |
44 } |
44 } |
45 |
45 |
46 // ----------------------------------------------------------------------------- |
46 // ----------------------------------------------------------------------------- |
47 // |
47 // |
48 // ----------------------------------------------------------------------------- |
48 // ----------------------------------------------------------------------------- |
49 // |
49 // |
50 CMmListBoxView::~CMmListBoxView () |
50 CMmListBoxView::~CMmListBoxView () |
51 { |
51 { |
52 } |
52 } |
53 |
53 |
54 // ----------------------------------------------------------------------------- |
54 // ----------------------------------------------------------------------------- |
55 // |
55 // |
56 // ----------------------------------------------------------------------------- |
56 // ----------------------------------------------------------------------------- |
57 // |
57 // |
58 CMmListBoxView* CMmListBoxView::NewLC () |
58 CMmListBoxView* CMmListBoxView::NewLC () |
59 { |
59 { |
60 CMmListBoxView* self = new (ELeave)CMmListBoxView(); |
60 CMmListBoxView* self = new (ELeave)CMmListBoxView(); |
61 CleanupStack::PushL (self); |
61 CleanupStack::PushL (self); |
62 self->ConstructL (); |
62 self->ConstructL (); |
63 return self; |
63 return self; |
64 } |
64 } |
65 |
65 |
66 // ----------------------------------------------------------------------------- |
66 // ----------------------------------------------------------------------------- |
67 // |
67 // |
68 // ----------------------------------------------------------------------------- |
68 // ----------------------------------------------------------------------------- |
69 // |
69 // |
70 CMmListBoxView* CMmListBoxView::NewL () |
70 CMmListBoxView* CMmListBoxView::NewL () |
71 { |
71 { |
72 CMmListBoxView* self=CMmListBoxView::NewLC (); |
72 CMmListBoxView* self=CMmListBoxView::NewLC (); |
73 CleanupStack::Pop( self ); |
73 CleanupStack::Pop( self ); |
74 return self; |
74 return self; |
75 } |
75 } |
76 |
76 |
77 // ----------------------------------------------------------------------------- |
77 // ----------------------------------------------------------------------------- |
78 // |
78 // |
79 // ----------------------------------------------------------------------------- |
79 // ----------------------------------------------------------------------------- |
80 // |
80 // |
81 void CMmListBoxView::ConstructL () |
81 void CMmListBoxView::ConstructL () |
82 { |
82 { |
83 iScrollbarIsVisible = ETrue; |
83 iScrollbarIsVisible = ETrue; |
84 iPreviouslyDrawnCurrentItemIndex = KErrNotFound; |
84 iPreviouslyDrawnCurrentItemIndex = KErrNotFound; |
85 } |
85 } |
86 |
86 |
87 // ----------------------------------------------------------------------------- |
87 // ----------------------------------------------------------------------------- |
88 // |
88 // |
89 // ----------------------------------------------------------------------------- |
89 // ----------------------------------------------------------------------------- |
90 // |
90 // |
91 void CMmListBoxView::UpdateAverageItemHeight () |
91 void CMmListBoxView::UpdateAverageItemHeight () |
92 { |
92 { |
93 TInt count( iModel->NumberOfItems() ); |
93 TInt count( iModel->NumberOfItems() ); |
94 if ( !count ) |
94 if ( !count ) |
95 { |
95 { |
96 SetItemHeight( 2 ); |
96 SetItemHeight( 2 ); |
97 } |
97 } |
98 else |
98 else |
99 { |
99 { |
100 TInt totalHeight = GetTotalHeight( 0, count - 1 ); |
100 TInt totalHeight = GetTotalHeight( 0, count - 1 ); |
101 TInt averageItemHeight = totalHeight / count; |
101 TInt averageItemHeight = totalHeight / count; |
102 if ( totalHeight % count ) |
102 if ( totalHeight % count ) |
103 { |
103 { |
104 ++averageItemHeight; |
104 ++averageItemHeight; |
105 // this ensures that it is always possible to |
105 // this ensures that it is always possible to |
106 // scroll to the very bottom of the view by |
106 // scroll to the very bottom of the view by |
107 // using scrollbar. |
107 // using scrollbar. |
108 } |
108 } |
109 SetItemHeight( averageItemHeight ); |
109 SetItemHeight( averageItemHeight ); |
110 } |
110 } |
111 } |
111 } |
112 // ----------------------------------------------------------------------------- |
112 // ----------------------------------------------------------------------------- |
113 // |
113 // |
114 // ----------------------------------------------------------------------------- |
114 // ----------------------------------------------------------------------------- |
115 // |
115 // |
116 TInt CMmListBoxView::GetTotalHeight (const TInt aStartIndex, TInt aEndIndex) const |
116 TInt CMmListBoxView::GetTotalHeight (const TInt aStartIndex, TInt aEndIndex) const |
117 { |
117 { |
118 TInt totalHeight = 0; |
118 TInt totalHeight = 0; |
119 |
119 |
120 if ( aEndIndex >= 0) |
120 if ( aEndIndex >= 0) |
121 { |
121 { |
122 TInt itemCount = iModel->NumberOfItems (); |
122 TInt itemCount = iModel->NumberOfItems (); |
123 aEndIndex = (aEndIndex >= itemCount ) ? itemCount-1 : aEndIndex; |
123 aEndIndex = (aEndIndex >= itemCount ) ? itemCount-1 : aEndIndex; |
124 CMmListBoxItemDrawer* drawer= STATIC_CAST( CMmListBoxItemDrawer*, iItemDrawer); |
124 CMmListBoxItemDrawer* drawer= STATIC_CAST( CMmListBoxItemDrawer*, iItemDrawer); |
125 for (TInt i(aStartIndex); i <= aEndIndex; i++) |
125 for (TInt i(aStartIndex); i <= aEndIndex; i++) |
126 { |
126 { |
127 totalHeight += drawer->GetItemHeight (i, CurrentItemIndex () == i); |
127 totalHeight += drawer->GetItemHeight (i, CurrentItemIndex () == i); |
128 } |
128 } |
129 } |
129 } |
130 |
130 |
131 return totalHeight; |
131 return totalHeight; |
132 } |
132 } |
133 |
133 |
134 // ----------------------------------------------------------------------------- |
134 // ----------------------------------------------------------------------------- |
135 // |
135 // |
136 // ----------------------------------------------------------------------------- |
136 // ----------------------------------------------------------------------------- |
137 // |
137 // |
138 TInt CMmListBoxView::GetLastIndexInHeight (const TInt aStartIndex, TInt aHeight) const |
138 TInt CMmListBoxView::GetLastIndexInHeight (const TInt aStartIndex, TInt aHeight) const |
139 { |
139 { |
140 TInt i = aStartIndex; |
140 TInt i = aStartIndex; |
141 TInt totalHeight = 0; |
141 TInt totalHeight = 0; |
142 |
142 |
143 TInt itemCount(iModel->NumberOfItems () ); |
143 TInt itemCount(iModel->NumberOfItems () ); |
144 CMmListBoxItemDrawer* drawer= STATIC_CAST( CMmListBoxItemDrawer*, iItemDrawer); |
144 CMmListBoxItemDrawer* drawer= STATIC_CAST( CMmListBoxItemDrawer*, iItemDrawer); |
145 |
145 |
146 for (; (i > -1) && (i < itemCount); i++) |
146 for (; (i > -1) && (i < itemCount); i++) |
147 { |
147 { |
148 totalHeight += drawer->GetItemHeight (i, CurrentItemIndex () == i); |
148 totalHeight += drawer->GetItemHeight (i, CurrentItemIndex () == i); |
149 if ( totalHeight > aHeight) |
149 if ( totalHeight > aHeight) |
150 break; |
150 break; |
151 } |
151 } |
152 |
152 |
153 TInt ret(i - aStartIndex); |
153 TInt ret(i - aStartIndex); |
154 |
154 |
155 if ( !AknLayoutUtils::PenEnabled() && totalHeight > aHeight ) |
155 if ( !AknLayoutUtils::PenEnabled() && totalHeight > aHeight ) |
156 { |
156 { |
157 ret--; // exclude partial item |
157 ret--; // exclude partial item |
158 } |
158 } |
159 |
159 |
160 return ret; |
160 return ret; |
161 } |
161 } |
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 TInt CMmListBoxView::NumberOfItemsThatFitInRect(const TRect& aRect) const |
|
168 { |
|
169 return GetNumberOfItemsThatFitInRect( aRect, EFalse ); |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 TInt CMmListBoxView::GetNumberOfItemsThatFitInRect (const TRect& aRect, |
|
177 TBool aIncludePartialItem ) const |
|
178 { |
|
179 TInt i = iTopItemIndex; |
|
180 TInt totalHeight = iVerticalOffset; |
|
181 |
|
182 TInt itemCount( iModel->NumberOfItems () ); |
|
183 CMmListBoxItemDrawer* drawer= STATIC_CAST( CMmListBoxItemDrawer*, iItemDrawer); |
|
184 while (totalHeight < aRect.Height ()) |
|
185 { |
|
186 totalHeight += ((i > -1) && (i < itemCount )) ? drawer->GetItemHeight ( |
|
187 i, CurrentItemIndex () == i) : iItemHeight; |
|
188 ++i; |
|
189 } |
|
190 |
|
191 TInt ret(i - iTopItemIndex); |
|
192 |
|
193 if ( !AknLayoutUtils::PenEnabled() && !aIncludePartialItem && totalHeight > aRect.Height() ) |
|
194 { |
|
195 ret--; // exclude partial item |
|
196 } |
|
197 |
|
198 return ret; |
|
199 } |
|
200 |
162 |
201 // ----------------------------------------------------------------------------- |
163 // ----------------------------------------------------------------------------- |
202 // |
164 // |
203 // ----------------------------------------------------------------------------- |
165 // ----------------------------------------------------------------------------- |
204 // |
166 // |
267 itemDrawer->DrawFloatingItems( rect ); |
229 itemDrawer->DrawFloatingItems( rect ); |
268 // iGc->CancelClippingRect(); |
230 // iGc->CancelClippingRect(); |
269 } |
231 } |
270 |
232 |
271 if ( CAknEnv::Static()->TransparencyEnabled() && |
233 if ( CAknEnv::Static()->TransparencyEnabled() && |
272 iWin && drawingInitiated ) |
234 iWin && drawingInitiated ) |
273 { |
235 { |
274 drawingInitiated = EFalse; |
236 drawingInitiated = EFalse; |
275 iWin->EndRedraw( ); |
237 iWin->EndRedraw( ); |
276 } |
238 } |
277 } |
239 } |
278 |
240 |
279 // ----------------------------------------------------------------------------- |
241 // ----------------------------------------------------------------------------- |
280 // |
242 // |
281 // ----------------------------------------------------------------------------- |
243 // ----------------------------------------------------------------------------- |
282 // |
244 // |
283 void CMmListBoxView::DoDraw(const TRect* aClipRect) const |
245 void CMmListBoxView::DoDraw(const TRect* aClipRect) const |
284 { |
246 { |
285 CMmListBoxView* view= CONST_CAST( CMmListBoxView*, this ); |
247 CMmListBoxView* view= CONST_CAST( CMmListBoxView*, this ); |
286 view->UpdateAverageItemHeight (); |
248 view->UpdateAverageItemHeight (); |
287 |
249 |
288 CMmListBoxModel* model = static_cast< CMmListBoxModel* > ( iModel ); |
250 CMmListBoxModel* model = static_cast< CMmListBoxModel* > ( iModel ); |
289 if ( model && model->GetSuiteModel() |
251 if ( model && model->GetSuiteModel() |
290 && !model->GetSuiteModel()->GetItemsOrder()->IsSuiteReadyToShow() ) |
252 && !model->GetSuiteModel()->GetItemsOrder()->IsSuiteReadyToShow() ) |
291 { |
253 { |
292 return; |
254 return; |
293 } |
255 } |
294 |
256 |
295 if ( RedrawDisabled () || !IsVisible () ) |
257 if ( RedrawDisabled () || !IsVisible () ) |
296 { |
258 { |
297 return; |
259 return; |
298 } |
260 } |
299 |
261 |
300 TInt i = iTopItemIndex; |
262 TInt i = iTopItemIndex; |
301 CMmListBoxItemDrawer* itemDrawer = |
263 CMmListBoxItemDrawer* itemDrawer = |
302 static_cast<CMmListBoxItemDrawer*>(iItemDrawer ); |
264 static_cast<CMmListBoxItemDrawer*>(iItemDrawer ); |
303 MAknsSkinInstance *skin = AknsUtils::SkinInstance (); |
265 MAknsSkinInstance *skin = AknsUtils::SkinInstance (); |
304 CCoeControl* control = itemDrawer->FormattedCellData()->Control (); |
266 CCoeControl* control = itemDrawer->FormattedCellData()->Control (); |
305 MAknsControlContext *cc = AknsDrawUtils::ControlContext (control); |
267 MAknsControlContext *cc = AknsDrawUtils::ControlContext (control); |
306 |
268 |
307 if ( !cc) |
269 if ( !cc) |
308 { |
270 { |
309 cc = itemDrawer->FormattedCellData()->SkinBackgroundContext (); |
271 cc = itemDrawer->FormattedCellData()->SkinBackgroundContext (); |
310 } |
272 } |
311 |
273 |
312 itemDrawer->SetTopItemIndex (iTopItemIndex); |
274 itemDrawer->SetTopItemIndex (iTopItemIndex); |
313 |
275 |
314 if ( iModel->NumberOfItems () > 0) |
276 if ( iModel->NumberOfItems () > 0) |
315 { |
277 { |
316 TBool drawingInitiated = ETrue; |
278 TBool drawingInitiated = ETrue; |
317 if ( CAknEnv::Static()->TransparencyEnabled () ) |
279 if ( CAknEnv::Static()->TransparencyEnabled () ) |
318 { |
280 { |
319 if ( iWin && iWin->GetDrawRect () == TRect::EUninitialized) |
281 if ( iWin && iWin->GetDrawRect () == TRect::EUninitialized) |
320 { |
282 { |
321 #ifdef RD_UI_TRANSITION_EFFECTS_LIST |
283 #ifdef RD_UI_TRANSITION_EFFECTS_LIST |
322 MAknListBoxTfxInternal* transApi = |
284 MAknListBoxTfxInternal* transApi = |
323 CAknListLoader::TfxApiInternal( iGc ); |
285 CAknListLoader::TfxApiInternal( iGc ); |
324 drawingInitiated = transApi && !transApi->EffectsDisabled(); |
286 drawingInitiated = transApi && !transApi->EffectsDisabled(); |
325 #else |
287 #else |
326 drawingInitiated = EFalse; |
288 drawingInitiated = EFalse; |
327 #endif |
289 #endif |
328 } |
290 } |
329 |
291 |
330 if ( !drawingInitiated) |
292 if ( !drawingInitiated) |
331 { |
293 { |
332 iWin->Invalidate ( *aClipRect); |
294 iWin->Invalidate ( *aClipRect); |
333 iWin->BeginRedraw ( *aClipRect); |
295 iWin->BeginRedraw ( *aClipRect); |
334 } |
296 } |
335 } |
297 } |
336 |
298 |
337 TInt lastPotentialItemIndex = Min (iModel->NumberOfItems (), |
299 TInt lastPotentialItemIndex = Min( iModel->NumberOfItems(), |
338 iTopItemIndex + GetNumberOfItemsThatFitInRect( ViewRect (), ETrue ) ); |
300 iTopItemIndex + NumberOfItemsThatFitInRect( ViewRect() ) ); |
339 |
301 |
340 if ( !itemDrawer->IsEditMode() ) |
302 if ( !itemDrawer->IsEditMode() ) |
341 { |
303 { |
342 itemDrawer->DrawBackground( ViewRect() ); |
304 itemDrawer->DrawBackground( ViewRect() ); |
343 itemDrawer->SetRedrawItemBackground( EFalse ); |
305 itemDrawer->SetRedrawItemBackground( EFalse ); |
344 itemDrawer->SetDrawSeparatorLines( ETrue ); |
306 itemDrawer->SetDrawSeparatorLines( ETrue ); |
345 while (i < lastPotentialItemIndex) |
307 while (i < lastPotentialItemIndex) |
346 { |
308 { |
347 DrawItem(i++); |
309 DrawItem(i++); |
348 } |
310 } |
349 itemDrawer->SetRedrawItemBackground( ETrue ); |
311 itemDrawer->SetRedrawItemBackground( ETrue ); |
350 itemDrawer->SetDrawSeparatorLines( EFalse ); |
312 itemDrawer->SetDrawSeparatorLines( EFalse ); |
351 } |
313 } |
352 else |
314 else |
353 { |
315 { |
354 while (i < lastPotentialItemIndex) |
316 while (i < lastPotentialItemIndex) |
355 { |
317 { |
356 DrawItem(i++); |
318 DrawItem(i++); |
357 } |
319 } |
358 // this redraws background in the view portion not covered by items |
320 // this redraws background in the view portion not covered by items |
359 RedrawBackground(); |
321 RedrawBackground(); |
360 } |
322 } |
361 |
323 |
362 |
324 |
363 if ( CAknEnv::Static()->TransparencyEnabled () && !drawingInitiated) |
325 if ( CAknEnv::Static()->TransparencyEnabled () && !drawingInitiated) |
364 { |
326 { |
365 iWin->EndRedraw (); |
327 iWin->EndRedraw (); |
366 } |
328 } |
367 } |
329 } |
368 |
330 |
369 } |
331 } |
370 |
332 |
371 // ----------------------------------------------------------------------------- |
333 // ----------------------------------------------------------------------------- |
372 // |
334 // |
373 // ----------------------------------------------------------------------------- |
335 // ----------------------------------------------------------------------------- |
374 // |
336 // |
375 void CMmListBoxView::DrawItem (TInt aItemIndex) const |
337 void CMmListBoxView::DrawItem (TInt aItemIndex) const |
376 { |
338 { |
377 CMmListBoxItemDrawer* itemDrawer= STATIC_CAST( CMmListBoxItemDrawer*, iItemDrawer ); |
339 CMmListBoxItemDrawer* itemDrawer= STATIC_CAST( CMmListBoxItemDrawer*, iItemDrawer ); |
378 TBool currentChanged( CurrentItemIndex() != iPreviouslyDrawnCurrentItemIndex ); |
340 TBool currentChanged( CurrentItemIndex() != iPreviouslyDrawnCurrentItemIndex ); |
379 TBool redrawConsumed(EFalse); |
341 TBool redrawConsumed(EFalse); |
380 if ( currentChanged ) |
342 if ( currentChanged ) |
381 { |
343 { |
382 CMmListBoxView* view= CONST_CAST( CMmListBoxView*, this ); |
344 CMmListBoxView* view= CONST_CAST( CMmListBoxView*, this ); |
383 redrawConsumed = |
345 redrawConsumed = |
384 static_cast<CMmListBox*> (itemDrawer->Widget())->RedrawIfNecessary( |
346 static_cast<CMmListBox*> (itemDrawer->Widget())->RedrawIfNecessary( |
385 iPreviouslyDrawnCurrentItemIndex, |
347 iPreviouslyDrawnCurrentItemIndex, |
386 CurrentItemIndex()); |
348 CurrentItemIndex()); |
387 view->SetPreviouslyDrawnCurrentItemIndex( CurrentItemIndex() ); |
349 view->SetPreviouslyDrawnCurrentItemIndex( CurrentItemIndex() ); |
388 } |
350 } |
389 |
351 |
390 if ( !redrawConsumed ) |
352 if ( !redrawConsumed ) |
391 { |
353 { |
392 itemDrawer->SetDrawSeparatorLines( ETrue ); |
354 itemDrawer->SetDrawSeparatorLines( ETrue ); |
393 DrawSingleItem ( aItemIndex ); |
355 DrawSingleItem ( aItemIndex ); |
394 itemDrawer->SetDrawSeparatorLines( EFalse ); |
356 itemDrawer->SetDrawSeparatorLines( EFalse ); |
395 } |
357 } |
396 } |
358 } |
397 |
|
398 // ----------------------------------------------------------------------------- |
|
399 // |
|
400 // ----------------------------------------------------------------------------- |
|
401 // |
|
402 TSize CMmListBoxView::ItemSize (TInt aItemIndex) const |
|
403 { |
|
404 CMmListBoxView* view= CONST_CAST( CMmListBoxView*, this ); |
|
405 view->UpdateAverageItemHeight (); |
|
406 |
|
407 CMmListBoxItemDrawer* itemDrawer= STATIC_CAST( CMmListBoxItemDrawer*, iItemDrawer ); |
|
408 TSize size(CFormattedCellListBoxView::ItemSize(aItemIndex).iWidth, itemDrawer->GetItemHeight (aItemIndex, |
|
409 CurrentItemIndex () == aItemIndex) ); |
|
410 |
|
411 if ( size.iHeight < 2) |
|
412 size.iHeight = 2; |
|
413 |
|
414 return size; |
|
415 } |
|
416 |
359 |
417 // ----------------------------------------------------------------------------- |
360 // ----------------------------------------------------------------------------- |
418 // |
361 // |
419 // ----------------------------------------------------------------------------- |
362 // ----------------------------------------------------------------------------- |
420 // |
363 // |
421 TPoint CMmListBoxView::ItemPos (TInt aItemIndex) const |
364 TPoint CMmListBoxView::ItemPos (TInt aItemIndex) const |
422 { |
365 { |
423 TInt vRealPos = CFormattedCellListBoxView::ItemPos(TopItemIndex()).iY; |
366 TInt vRealPos = CFormattedCellListBoxView::ItemPos(TopItemIndex()).iY; |
424 TInt totalHeight = 0; |
367 TInt totalHeight = 0; |
425 if ( aItemIndex > iTopItemIndex ) |
368 if ( aItemIndex > iTopItemIndex ) |
426 { |
369 { |
427 totalHeight = GetTotalHeight( iTopItemIndex, aItemIndex - 1 ); |
370 totalHeight = GetTotalHeight( iTopItemIndex, aItemIndex - 1 ); |
428 } |
371 } |
429 else if ( aItemIndex < iTopItemIndex ) |
372 else if ( aItemIndex < iTopItemIndex ) |
430 { |
373 { |
431 totalHeight = -GetTotalHeight( aItemIndex, iTopItemIndex - 1 ); |
374 totalHeight = -GetTotalHeight( aItemIndex, iTopItemIndex - 1 ); |
432 } |
375 } |
433 |
376 |
434 return TPoint (-iHScrollOffset + iViewRect.iTl.iX, iViewRect.iTl.iY |
377 return TPoint (-iHScrollOffset + iViewRect.iTl.iX, iViewRect.iTl.iY |
435 + totalHeight + vRealPos); |
378 + totalHeight + vRealPos); |
436 } |
379 } |
437 |
380 |
438 // ----------------------------------------------------------------------------- |
381 // ----------------------------------------------------------------------------- |
439 // |
382 // |
440 // ----------------------------------------------------------------------------- |
383 // ----------------------------------------------------------------------------- |
441 // |
384 // |
442 TBool CMmListBoxView::XYPosToItemIndex (TPoint aPosition, TInt& aItemIndex) const |
385 TBool CMmListBoxView::XYPosToItemIndex (TPoint aPosition, TInt& aItemIndex) const |
443 { |
386 { |
444 // returns ETrue and sets aItemIndex to the index of the item whose bounding box contains aPosition |
387 // returns ETrue and sets aItemIndex to the index of the item whose bounding box contains aPosition |
445 // returns EFalse if no such item exists |
388 // returns EFalse if no such item exists |
446 TBool itemFound = EFalse; |
389 TBool itemFound = EFalse; |
447 if ( iViewRect.Contains (aPosition)) |
390 if ( iViewRect.Contains (aPosition)) |
448 { |
391 { |
449 TInt vRealPos = CFormattedCellListBoxView::ItemPos(TopItemIndex()).iY; |
392 TInt vRealPos = CFormattedCellListBoxView::ItemPos(TopItemIndex()).iY; |
450 // aPosition is inside the display area |
393 // aPosition is inside the display area |
451 TInt numberOfVisibleItems = GetLastIndexInHeight (iTopItemIndex, |
394 TInt numberOfVisibleItems = GetLastIndexInHeight (iTopItemIndex, |
452 aPosition.iY - iViewRect.iTl.iY - vRealPos ); |
395 aPosition.iY - iViewRect.iTl.iY - vRealPos ); |
453 TInt itemAtSpecifiedPos = iTopItemIndex + numberOfVisibleItems; |
396 TInt itemAtSpecifiedPos = iTopItemIndex + numberOfVisibleItems; |
454 aItemIndex = itemAtSpecifiedPos; |
397 aItemIndex = itemAtSpecifiedPos; |
455 itemFound = ( GetTotalHeight( iTopItemIndex, iBottomItemIndex ) |
398 itemFound = ( GetTotalHeight( iTopItemIndex, iBottomItemIndex ) |
456 >= aPosition.iY ) && ( iModel->NumberOfItems() > itemAtSpecifiedPos ); |
399 >= aPosition.iY ) && ( iModel->NumberOfItems() > itemAtSpecifiedPos ); |
457 // if ( itemFound ) |
400 // if ( itemFound ) |
458 // { |
401 // { |
459 // // aPosition is inside the display area |
402 // // aPosition is inside the display area |
460 // TInt numberOfVisibleItems = GetLastIndexInHeight (iTopItemIndex, |
403 // TInt numberOfVisibleItems = GetLastIndexInHeight (iTopItemIndex, |
461 // aPosition.iY - iViewRect.iTl.iY); |
404 // aPosition.iY - iViewRect.iTl.iY); |
462 // TInt itemAtSpecifiedPos = iTopItemIndex + numberOfVisibleItems; |
405 // TInt itemAtSpecifiedPos = iTopItemIndex + numberOfVisibleItems; |
463 // aItemIndex = itemAtSpecifiedPos; |
406 // aItemIndex = itemAtSpecifiedPos; |
464 // } |
407 // } |
465 } |
408 } |
466 return itemFound; |
409 return itemFound; |
467 } |
410 } |
468 |
411 |
469 // ----------------------------------------------------------------------------- |
412 // ----------------------------------------------------------------------------- |
470 // |
413 // |
471 // ----------------------------------------------------------------------------- |
414 // ----------------------------------------------------------------------------- |
472 // |
415 // |
473 void CMmListBoxView::SetItemHeight (TInt aItemHeight) |
416 void CMmListBoxView::SetItemHeight (TInt aItemHeight) |
474 { |
417 { |
475 // we need to update the iItemHeight member in widget also (there are two different item height value holders - in widget and here in widget view) |
418 // we need to update the iItemHeight member in widget also (there are two different item height value holders - in widget and here in widget view) |
476 iItemHeight = aItemHeight; |
419 iItemHeight = aItemHeight; |
477 |
420 |
478 CMmListBoxItemDrawer* itemDrawer = |
421 CMmListBoxItemDrawer* itemDrawer = |
479 STATIC_CAST( CMmListBoxItemDrawer*, ItemDrawer() ); |
422 STATIC_CAST( CMmListBoxItemDrawer*, ItemDrawer() ); |
480 static_cast<CMmListBox*>(itemDrawer->Widget())->SetItemHeight( aItemHeight ); |
423 static_cast<CMmListBox*>(itemDrawer->Widget())->SetItemHeight( aItemHeight ); |
481 |
424 |
482 } |
425 } |
483 |
426 |
484 // ----------------------------------------------------------------------------- |
427 // ----------------------------------------------------------------------------- |
485 // |
428 // |
486 // ----------------------------------------------------------------------------- |
429 // ----------------------------------------------------------------------------- |
487 // |
430 // |
488 TInt CMmListBoxView::CalcNewTopItemIndexSoItemIsVisible (TInt aItemIndex) const |
431 TInt CMmListBoxView::CalcNewTopItemIndexSoItemIsVisible (TInt aItemIndex) const |
489 { |
432 { |
490 CMmListBoxItemDrawer* itemDrawer = |
433 CMmListBoxItemDrawer* itemDrawer = |
491 static_cast<CMmListBoxItemDrawer*>( iItemDrawer ); |
434 static_cast<CMmListBoxItemDrawer*>( iItemDrawer ); |
492 |
435 |
493 TInt newTopItemIndex = iTopItemIndex; |
436 TInt newTopItemIndex = iTopItemIndex; |
494 |
437 |
495 TInt itemHeight = itemDrawer-> |
438 TInt itemHeight = itemDrawer-> |
496 GetItemHeight( aItemIndex, aItemIndex == CurrentItemIndex() ); |
439 GetItemHeight( aItemIndex, aItemIndex == CurrentItemIndex() ); |
497 |
440 |
498 // ItemIsPartiallyVisible uses fixed iItemHeight, but we have to support |
441 // ItemIsPartiallyVisible uses fixed iItemHeight, but we have to support |
499 // variable item height in lists, unfortunately ItemIsPartiallyVisible |
442 // variable item height in lists, unfortunately ItemIsPartiallyVisible |
500 // is not virtual |
443 // is not virtual |
501 TPoint itemPosition( ItemPos( aItemIndex ) ); |
444 TPoint itemPosition( ItemPos( aItemIndex ) ); |
502 TBool itemPartiallyVisible = |
445 TBool itemPartiallyVisible = |
503 ( itemPosition.iY < iViewRect.iTl.iY && |
446 ( itemPosition.iY < iViewRect.iTl.iY && |
504 itemPosition.iY + itemHeight >= iViewRect.iTl.iY ) || |
447 itemPosition.iY + itemHeight >= iViewRect.iTl.iY ) || |
505 ( itemPosition.iY <= iViewRect.iBr.iY && |
448 ( itemPosition.iY <= iViewRect.iBr.iY && |
506 itemPosition.iY + itemHeight > iViewRect.iBr.iY ); |
449 itemPosition.iY + itemHeight > iViewRect.iBr.iY ); |
507 |
450 |
508 TBool itemIsFullyVisible = ItemIsVisible( aItemIndex ) && |
451 TBool itemIsFullyVisible = ItemIsVisible( aItemIndex ) && |
509 !itemPartiallyVisible; |
452 !itemPartiallyVisible; |
510 |
453 |
511 TBool itemIsAboveVisibleArea = !itemIsFullyVisible && |
454 TBool itemIsAboveVisibleArea = !itemIsFullyVisible && |
512 ItemPos( aItemIndex ).iY < ViewRect().iTl.iY; |
455 ItemPos( aItemIndex ).iY < ViewRect().iTl.iY; |
513 |
456 |
514 TBool itemIsBeneathVisibleArea = !itemIsFullyVisible && |
457 TBool itemIsBeneathVisibleArea = !itemIsFullyVisible && |
515 !itemIsAboveVisibleArea && ItemPos( aItemIndex ).iY + itemDrawer-> |
458 !itemIsAboveVisibleArea && ItemPos( aItemIndex ).iY + itemDrawer-> |
516 GetItemHeight( aItemIndex, aItemIndex == CurrentItemIndex() ) > |
459 GetItemHeight( aItemIndex, aItemIndex == CurrentItemIndex() ) > |
517 ViewRect().iBr.iY; |
460 ViewRect().iBr.iY; |
518 |
461 |
519 if ( itemIsAboveVisibleArea ) |
462 if ( itemIsAboveVisibleArea ) |
520 { |
463 { |
521 newTopItemIndex = aItemIndex; |
464 newTopItemIndex = aItemIndex; |
522 const_cast<CMmListBoxView*>( this )->SetItemOffsetInPixels( 0 ); |
465 const_cast<CMmListBoxView*>( this )->SetItemOffsetInPixels( 0 ); |
523 } |
466 } |
524 |
467 |
525 if ( itemIsBeneathVisibleArea ) |
468 if ( itemIsBeneathVisibleArea ) |
526 { |
469 { |
527 const TInt viewHeight = ViewRect().Height(); |
470 const TInt viewHeight = ViewRect().Height(); |
528 newTopItemIndex = aItemIndex; |
471 newTopItemIndex = aItemIndex; |
529 for ( ;; ) |
472 for ( ;; ) |
530 { |
473 { |
605 usedPortionOfViewRect.Move(0, |
548 usedPortionOfViewRect.Move(0, |
606 CFormattedCellListBoxView::ItemPos(iTopItemIndex).iY); |
549 CFormattedCellListBoxView::ItemPos(iTopItemIndex).iY); |
607 |
550 |
608 RedrawBackground(usedPortionOfViewRect, iViewRect); |
551 RedrawBackground(usedPortionOfViewRect, iViewRect); |
609 #endif |
552 #endif |
610 } |
553 } |
611 |
554 |
612 // ----------------------------------------------------------------------------- |
555 // ----------------------------------------------------------------------------- |
613 // |
556 // |
614 // ----------------------------------------------------------------------------- |
557 // ----------------------------------------------------------------------------- |
615 // |
558 // |
616 void CMmListBoxView::SetPreviouslyDrawnCurrentItemIndex( TBool aIndex ) |
559 void CMmListBoxView::SetPreviouslyDrawnCurrentItemIndex( TBool aIndex ) |
617 { |
560 { |
618 iPreviouslyDrawnCurrentItemIndex = aIndex; |
561 iPreviouslyDrawnCurrentItemIndex = aIndex; |
619 } |
562 } |
620 |
563 |
621 // ----------------------------------------------------------------------------- |
564 // ----------------------------------------------------------------------------- |
622 // |
565 // |
623 // ----------------------------------------------------------------------------- |
566 // ----------------------------------------------------------------------------- |
624 // |
567 // |
625 void CMmListBoxView::DrawSingleItem (TInt aItemIndex) const |
568 void CMmListBoxView::DrawSingleItem (TInt aItemIndex) const |
626 { |
569 { |
627 CMmListBoxItemDrawer* itemDrawer = |
570 CMmListBoxItemDrawer* itemDrawer = |
628 STATIC_CAST( CMmListBoxItemDrawer*, iItemDrawer ); |
571 STATIC_CAST( CMmListBoxItemDrawer*, iItemDrawer ); |
629 TBool highlightVisible = !( itemDrawer->Flags() |
572 TBool highlightVisible = !( itemDrawer->Flags() |
630 & CListItemDrawer::ESingleClickDisabledHighlight ); |
573 & CListItemDrawer::ESingleClickDisabledHighlight ); |
631 TSize size = itemDrawer->GetItemSize( aItemIndex, highlightVisible && |
574 TSize size = itemDrawer->GetItemSize( aItemIndex, highlightVisible && |
632 CurrentItemIndex() == aItemIndex ); |
575 CurrentItemIndex() == aItemIndex ); |
633 itemDrawer->SetItemCellSize( size ); |
576 itemDrawer->SetItemCellSize( size ); |
634 |
577 |
635 // CMmListBoxView* view= CONST_CAST( CMmListBoxView*, this ); |
578 // CMmListBoxView* view= CONST_CAST( CMmListBoxView*, this ); |
636 // view->SetItemHeight( size.iHeight ); |
579 // view->SetItemHeight( size.iHeight ); |
637 // The above line (currently commented-out) was originaly needed to correct |
580 // The above line (currently commented-out) was originaly needed to correct |
638 // some drawing-related error which used to occur when moving highlight with |
581 // some drawing-related error which used to occur when moving highlight with |
639 // rocker keys. It seems that this is no longer needed. If anything should |
582 // rocker keys. It seems that this is no longer needed. If anything should |
640 // change, please note that now the SetItemHeight method does much more than |
583 // change, please note that now the SetItemHeight method does much more than |
641 // it used to, so simply uncommenting this line would be a bad idea (consider |
584 // it used to, so simply uncommenting this line would be a bad idea (consider |
642 // setting the iItemHeight member variable directly). |
585 // setting the iItemHeight member variable directly). |
643 |
586 |
644 CFormattedCellListBoxView::DrawItem (aItemIndex); |
587 CFormattedCellListBoxView::DrawItem (aItemIndex); |
645 |
588 |
646 //To eliminate the effect of undrawn fragment of background, when the last |
589 //To eliminate the effect of undrawn fragment of background, when the last |
647 //is drawn, background is refreshed |
590 //is drawn, background is refreshed |
648 if ( aItemIndex == ( iModel->NumberOfItems()-1 ) && ItemIsVisible( iModel->NumberOfItems()-1 ) ) |
591 if ( aItemIndex == ( iModel->NumberOfItems()-1 ) && ItemIsVisible( iModel->NumberOfItems()-1 ) ) |
649 { |
592 { |
650 CMmListBoxItemDrawer* itemDrawer= STATIC_CAST( CMmListBoxItemDrawer*, iItemDrawer ); |
593 CMmListBoxItemDrawer* itemDrawer= STATIC_CAST( CMmListBoxItemDrawer*, iItemDrawer ); |
651 if ( !itemDrawer->IsEditMode() ) |
594 if ( !itemDrawer->IsEditMode() ) |
652 { |
595 { |
653 RedrawBackground(); |
596 RedrawBackground(); |
654 } |
597 } |
655 } |
598 } |
656 } |
599 } |
657 |
600 |
658 // ----------------------------------------------------------------------------- |
601 // ----------------------------------------------------------------------------- |
659 // |
602 // |
660 // ----------------------------------------------------------------------------- |
603 // ----------------------------------------------------------------------------- |
661 // |
604 // |
662 TInt CMmListBoxView::VerticalItemOffset() const |
605 TInt CMmListBoxView::VerticalItemOffset() const |
663 { |
606 { |
664 return iVerticalOffset; |
607 return iVerticalOffset; |
665 } |
608 } |
666 |
609 |
667 // ----------------------------------------------------------------------------- |
610 // ----------------------------------------------------------------------------- |
668 // |
611 // |
669 // ----------------------------------------------------------------------------- |
612 // ----------------------------------------------------------------------------- |
670 // |
613 // |