274 |
274 |
275 // ----------------------------------------------------------------------------- |
275 // ----------------------------------------------------------------------------- |
276 // Cleans up remaining objects in the window |
276 // Cleans up remaining objects in the window |
277 // ----------------------------------------------------------------------------- |
277 // ----------------------------------------------------------------------------- |
278 // |
278 // |
279 EXPORT_C void CGlxListWindow::Cleanup() |
279 EXPORT_C void CGlxListWindow::CleanupL() |
280 { |
280 { |
281 TRACER("CGlxListWindow::Cleanup"); |
281 TRACER("CGlxListWindow::CleanupL"); |
282 |
282 |
283 // make the window empty. this will clean up all remaining objects. |
283 // make the window empty. this will clean up all remaining objects. |
284 Update( TChange( KErrNotFound, 0, EChangeObjectsRemoved, 0, iWindow->TotalSize() - 1 ) ); |
284 UpdateL( TChange( KErrNotFound, 0, EChangeObjectsRemoved, 0, iWindow->TotalSize() - 1 ) ); |
285 } |
285 } |
286 |
286 |
287 // ----------------------------------------------------------------------------- |
287 // ----------------------------------------------------------------------------- |
288 // SetRangeOffsetsL |
288 // SetRangeOffsetsL |
289 // ----------------------------------------------------------------------------- |
289 // ----------------------------------------------------------------------------- |
324 // create enough new objects into the unused objects pool |
324 // create enough new objects into the unused objects pool |
325 // objects are either in the main window or in the pool |
325 // objects are either in the main window or in the pool |
326 for ( TInt i = iWindow->Size() + iUnusedObjects.Count(); i < maxObjectCount; i++ ) |
326 for ( TInt i = iWindow->Size() + iUnusedObjects.Count(); i < maxObjectCount; i++ ) |
327 { |
327 { |
328 // cannot fail since reservation made above |
328 // cannot fail since reservation made above |
329 ( void ) iUnusedObjects.Append( iObjectFactory.CreateObjectL() ); |
329 ( void )iUnusedObjects.AppendL( iObjectFactory.CreateObjectL() ); |
330 } |
330 } |
331 |
331 |
332 Update( TChange( aFocusIndex, aTotalSize, EChangeNone, 0, 0 ) ); |
332 UpdateL( TChange( aFocusIndex, aTotalSize, EChangeNone, 0, 0 ) ); |
333 } |
333 } |
334 |
334 |
335 // ----------------------------------------------------------------------------- |
335 // ----------------------------------------------------------------------------- |
336 // Iterator |
336 // Iterator |
337 // ----------------------------------------------------------------------------- |
337 // ----------------------------------------------------------------------------- |
345 |
345 |
346 // ----------------------------------------------------------------------------- |
346 // ----------------------------------------------------------------------------- |
347 // SetFocusIndexL |
347 // SetFocusIndexL |
348 // ----------------------------------------------------------------------------- |
348 // ----------------------------------------------------------------------------- |
349 // DEPRICATED |
349 // DEPRICATED |
350 EXPORT_C void CGlxListWindow::SetFocusIndex( TInt aFocusIndex ) |
350 EXPORT_C void CGlxListWindow::SetFocusIndexL( TInt aFocusIndex ) |
351 { |
351 { |
352 TRACER("CGlxListWindow::SetFocusIndex"); |
352 TRACER("CGlxListWindow::SetFocusIndexL"); |
353 |
353 |
354 SetFocusIndex( aFocusIndex, iWindow->TotalSize() ); |
354 SetFocusIndexL( aFocusIndex, iWindow->TotalSize() ); |
355 } |
355 } |
356 |
356 |
357 // ----------------------------------------------------------------------------- |
357 // ----------------------------------------------------------------------------- |
358 // SetFocusIndexL |
358 // SetFocusIndexL |
359 // ----------------------------------------------------------------------------- |
359 // ----------------------------------------------------------------------------- |
360 // |
360 // |
361 EXPORT_C void CGlxListWindow::SetFocusIndex( TInt aFocusIndex, TInt aTotalSize ) |
361 EXPORT_C void CGlxListWindow::SetFocusIndexL( TInt aFocusIndex, TInt aTotalSize ) |
362 { |
362 { |
363 TRACER("CGlxListWindow::SetFocusIndex"); |
363 TRACER("CGlxListWindow::SetFocusIndexL"); |
364 |
364 |
365 __ASSERT_DEBUG( ( 0 <= aFocusIndex && aFocusIndex < aTotalSize ) || |
365 __ASSERT_DEBUG( ( 0 <= aFocusIndex && aFocusIndex < aTotalSize ) || |
366 ( KErrNotFound == aFocusIndex && 0 == aTotalSize ), |
366 ( KErrNotFound == aFocusIndex && 0 == aTotalSize ), |
367 Panic( EGlxPanicIllegalArgument ) ); |
367 Panic( EGlxPanicIllegalArgument ) ); |
368 __TEST_INVARIANT; |
368 __TEST_INVARIANT; |
369 |
369 |
370 Update( TChange( aFocusIndex, aTotalSize, EChangeNone, 0, 0 ) ); |
370 UpdateL( TChange( aFocusIndex, aTotalSize, EChangeNone, 0, 0 ) ); |
371 |
371 |
372 __TEST_INVARIANT; |
372 __TEST_INVARIANT; |
373 } |
373 } |
374 |
374 |
375 // ----------------------------------------------------------------------------- |
375 // ----------------------------------------------------------------------------- |
376 // AddObjects |
376 // AddObjectsL |
377 // ----------------------------------------------------------------------------- |
377 // ----------------------------------------------------------------------------- |
378 // DEPRICATED |
378 // DEPRICATED |
379 EXPORT_C void CGlxListWindow::AddObjects( TInt aFirstNewIndex, TInt aLastNewIndex ) |
379 EXPORT_C void CGlxListWindow::AddObjectsL( TInt aFirstNewIndex, TInt aLastNewIndex ) |
380 { |
380 { |
381 TRACER("CGlxListWindow::AddObjects"); |
381 TRACER("CGlxListWindow::AddObjectsL"); |
382 |
382 |
383 TInt newItemCount = aLastNewIndex - aFirstNewIndex + 1; |
383 TInt newItemCount = aLastNewIndex - aFirstNewIndex + 1; |
384 TInt newTotalSize = iWindow->TotalSize() + newItemCount; |
384 TInt newTotalSize = iWindow->TotalSize() + newItemCount; |
385 |
385 |
386 // Check if it is necessary to move focus |
386 // Check if it is necessary to move focus |
396 // Move focus, so that the focus stays on the same item that was |
396 // Move focus, so that the focus stays on the same item that was |
397 // focused before items were added |
397 // focused before items were added |
398 newFocusIndex += newItemCount; |
398 newFocusIndex += newItemCount; |
399 } |
399 } |
400 |
400 |
401 AddObjects( newFocusIndex, newTotalSize, aFirstNewIndex, aLastNewIndex ); |
401 AddObjectsL( newFocusIndex, newTotalSize, aFirstNewIndex, aLastNewIndex ); |
402 } |
402 } |
403 |
403 |
404 // ----------------------------------------------------------------------------- |
404 // ----------------------------------------------------------------------------- |
405 // AddObjects |
405 // AddObjectsL |
406 // ----------------------------------------------------------------------------- |
406 // ----------------------------------------------------------------------------- |
407 // |
407 // |
408 EXPORT_C void CGlxListWindow::AddObjects( TInt aFocusIndex, |
408 EXPORT_C void CGlxListWindow::AddObjectsL( TInt aFocusIndex, |
409 TInt aTotalSize, TInt aFirstNewIndex, TInt aLastNewIndex ) |
409 TInt aTotalSize, TInt aFirstNewIndex, TInt aLastNewIndex ) |
410 { |
410 { |
411 TRACER("CGlxListWindow::AddObjects"); |
411 TRACER("CGlxListWindow::AddObjectsL"); |
412 |
412 |
413 __ASSERT_DEBUG( 0 <= aFirstNewIndex && aFirstNewIndex <= aLastNewIndex && |
413 __ASSERT_DEBUG( 0 <= aFirstNewIndex && aFirstNewIndex <= aLastNewIndex && |
414 aLastNewIndex < aTotalSize && |
414 aLastNewIndex < aTotalSize && |
415 0 <= aFocusIndex && aFocusIndex < aTotalSize, |
415 0 <= aFocusIndex && aFocusIndex < aTotalSize, |
416 Panic( EGlxPanicIllegalArgument ) ); |
416 Panic( EGlxPanicIllegalArgument ) ); |
417 __TEST_INVARIANT; |
417 __TEST_INVARIANT; |
418 |
418 |
419 Update( TChange( aFocusIndex, aTotalSize, EChangeObjectsAdded, |
419 UpdateL( TChange( aFocusIndex, aTotalSize, EChangeObjectsAdded, |
420 aFirstNewIndex, aLastNewIndex ) ); |
420 aFirstNewIndex, aLastNewIndex ) ); |
421 |
421 |
422 __TEST_INVARIANT; |
422 __TEST_INVARIANT; |
423 } |
423 } |
424 |
424 |
425 // ----------------------------------------------------------------------------- |
425 // ----------------------------------------------------------------------------- |
426 // RemoveObjects |
426 // RemoveObjectsL |
427 // ----------------------------------------------------------------------------- |
427 // ----------------------------------------------------------------------------- |
428 // DEPRICATED |
428 // DEPRICATED |
429 EXPORT_C void CGlxListWindow::RemoveObjects( TInt aFirstRemovedIndex, TInt aLastRemovedIndex ) |
429 EXPORT_C void CGlxListWindow::RemoveObjectsL( TInt aFirstRemovedIndex, TInt aLastRemovedIndex ) |
430 { |
430 { |
431 TRACER("CGlxListWindow::RemoveObjects"); |
431 TRACER("CGlxListWindow::RemoveObjectsL"); |
432 |
432 |
433 TInt itemsRemovedCount = aLastRemovedIndex - aFirstRemovedIndex + 1; |
433 TInt itemsRemovedCount = aLastRemovedIndex - aFirstRemovedIndex + 1; |
434 TInt newTotalSize = iWindow->TotalSize() - itemsRemovedCount; |
434 TInt newTotalSize = iWindow->TotalSize() - itemsRemovedCount; |
435 TInt newFocusIndex = iFocusIndex; |
435 TInt newFocusIndex = iFocusIndex; |
436 |
436 |
458 newFocusIndex = 0; |
458 newFocusIndex = 0; |
459 } |
459 } |
460 } |
460 } |
461 } |
461 } |
462 |
462 |
463 RemoveObjects( newFocusIndex, newTotalSize, aFirstRemovedIndex, aLastRemovedIndex ); |
463 RemoveObjectsL( newFocusIndex, newTotalSize, aFirstRemovedIndex, aLastRemovedIndex ); |
464 } |
464 } |
465 |
465 |
466 // ----------------------------------------------------------------------------- |
466 // ----------------------------------------------------------------------------- |
467 // RemoveObjects |
467 // RemoveObjectsL |
468 // ----------------------------------------------------------------------------- |
468 // ----------------------------------------------------------------------------- |
469 // |
469 // |
470 EXPORT_C void CGlxListWindow::RemoveObjects( TInt aFocusIndex, |
470 EXPORT_C void CGlxListWindow::RemoveObjectsL( TInt aFocusIndex, |
471 TInt aTotalSize, TInt aFirstRemovedIndex, TInt aLastRemovedIndex ) |
471 TInt aTotalSize, TInt aFirstRemovedIndex, TInt aLastRemovedIndex ) |
472 { |
472 { |
473 TRACER("CGlxListWindow::RemoveObjects"); |
473 TRACER("CGlxListWindow::RemoveObjectsL"); |
474 |
474 |
475 __ASSERT_DEBUG( 0 <= aFirstRemovedIndex && aFirstRemovedIndex <= aLastRemovedIndex && |
475 __ASSERT_DEBUG( 0 <= aFirstRemovedIndex && aFirstRemovedIndex <= aLastRemovedIndex && |
476 ( ( 0 <= aFocusIndex && aFocusIndex < aTotalSize ) || |
476 ( ( 0 <= aFocusIndex && aFocusIndex < aTotalSize ) || |
477 ( KErrNotFound == aFocusIndex && aTotalSize == 0 ) ), |
477 ( KErrNotFound == aFocusIndex && aTotalSize == 0 ) ), |
478 Panic( EGlxPanicIllegalArgument ) ); |
478 Panic( EGlxPanicIllegalArgument ) ); |
479 __TEST_INVARIANT; |
479 __TEST_INVARIANT; |
480 |
480 |
481 Update( TChange( aFocusIndex, aTotalSize, EChangeObjectsRemoved, |
481 UpdateL( TChange( aFocusIndex, aTotalSize, EChangeObjectsRemoved, |
482 aFirstRemovedIndex, aLastRemovedIndex ) ); |
482 aFirstRemovedIndex, aLastRemovedIndex ) ); |
483 |
483 |
484 __TEST_INVARIANT; |
484 __TEST_INVARIANT; |
485 } |
485 } |
486 |
486 |
487 // ----------------------------------------------------------------------------- |
487 // ----------------------------------------------------------------------------- |
488 // Update |
488 // UpdateL |
489 // ----------------------------------------------------------------------------- |
489 // ----------------------------------------------------------------------------- |
490 // |
490 // |
491 void CGlxListWindow::Update( const TChange& aChange ) |
491 void CGlxListWindow::UpdateL( const TChange& aChange ) |
492 { |
492 { |
493 TRACER("CGlxListWindow::Update"); |
493 TRACER("CGlxListWindow::UpdateL"); |
494 |
494 |
495 // (in a list of: |abcdefghijklm| |
495 // (in a list of: |abcdefghijklm| |
496 // iWindow: |----efghi----| |
496 // iWindow: |----efghi----| |
497 // iWorkingWindow: undefined state |
497 // iWorkingWindow: undefined state |
498 // iUnusedObjects: XXX (3 objects, in reality only contains objects if list |
498 // iUnusedObjects: XXX (3 objects, in reality only contains objects if list |
499 // is shorter than max window length) |
499 // is shorter than max window length) |
500 |
500 |
501 // Prepare the working window to accept objects |
501 // Prepare the working window to accept objects |
502 iWorkingWindow->Initialize( Range( aChange ), aChange.iNewTotalSize ); |
502 iWorkingWindow->InitializeL( Range( aChange ), aChange.iNewTotalSize ); |
503 |
503 |
504 // iWindow: |----efghi----| |
504 // iWindow: |----efghi----| |
505 // iWorkingWindow: |------00000--| |
505 // iWorkingWindow: |------00000--| |
506 // iUnusedObjects: XXX |
506 // iUnusedObjects: XXX |
507 |
507 |
508 // move unused objects to pool, and reusable objects to working window |
508 // move unused objects to pool, and reusable objects to working window |
509 PopulateExistingAndUnuseOld( aChange ); |
509 PopulateExistingAndUnuseOldL( aChange ); |
510 |
510 |
511 // iWindow: |----efghi----| |
511 // iWindow: |----efghi----| |
512 // iWorkingWindow: |------ghi00--| |
512 // iWorkingWindow: |------ghi00--| |
513 // iUnusedObjects: XXXXX (2 objects added, used to be e and f) |
513 // iUnusedObjects: XXXXX (2 objects added, used to be e and f) |
514 |
514 |
531 // iWorkingWindow: |----xxxxx----| = undefined |
531 // iWorkingWindow: |----xxxxx----| = undefined |
532 // iUnusedObjects: XXX (2 objects moved to iWindow) |
532 // iUnusedObjects: XXX (2 objects moved to iWindow) |
533 } |
533 } |
534 |
534 |
535 // ----------------------------------------------------------------------------- |
535 // ----------------------------------------------------------------------------- |
536 // PopulateExistingAndUnuseOld |
536 // PopulateExistingAndUnuseOldL |
537 // ----------------------------------------------------------------------------- |
537 // ----------------------------------------------------------------------------- |
538 // |
538 // |
539 void CGlxListWindow::PopulateExistingAndUnuseOld( const TChange& aChange ) |
539 void CGlxListWindow::PopulateExistingAndUnuseOldL( const TChange& aChange ) |
540 { |
540 { |
541 TRACER("CGlxListWindow::PopulateExistingAndUnuseOld"); |
541 TRACER("CGlxListWindow::PopulateExistingAndUnuseOldL"); |
542 |
542 |
543 // move objects that are needed after the change into the working window, |
543 // move objects that are needed after the change into the working window, |
544 // and objects that are not needed into the object pool |
544 // and objects that are not needed into the object pool |
545 TGlxWindowIterator currentWindowIterator = iWindow->Iterator(); |
545 TGlxWindowIterator currentWindowIterator = iWindow->Iterator(); |
546 TInt index = 0; |
546 TInt index = 0; |
560 // do this first, so that the deriving class can access the window |
560 // do this first, so that the deriving class can access the window |
561 // by index, if needed |
561 // by index, if needed |
562 iObjectFactory.CleanupObject( index, *( *iWindow )[ index ] ); |
562 iObjectFactory.CleanupObject( index, *( *iWindow )[ index ] ); |
563 // add the object to the unused objects pool |
563 // add the object to the unused objects pool |
564 // cannot fail since reservation made |
564 // cannot fail since reservation made |
565 ( void ) iUnusedObjects.Append( ( *iWindow )[ index ] ); |
565 ( void )iUnusedObjects.AppendL( ( *iWindow )[ index ] ); |
566 } |
566 } |
567 |
567 |
568 // clear the pointer in the existing window. it is not strictly necessary |
568 // clear the pointer in the existing window. it is not strictly necessary |
569 // to do here, but saves a loop from doing it in CGlxDataWindow::Initialize |
569 // to do here, but saves a loop from doing it in CGlxDataWindow::InitializeL |
570 ( *iWindow )[ index ] = NULL; |
570 ( *iWindow )[ index ] = NULL; |
571 } |
571 } |
572 } |
572 } |
573 |
573 |
574 // ----------------------------------------------------------------------------- |
574 // ----------------------------------------------------------------------------- |