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 // AddObjects |
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 // AddObjects |
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 // RemoveObjects |
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 |
459 newFocusIndex = 0; |
459 newFocusIndex = 0; |
460 } |
460 } |
461 } |
461 } |
462 } |
462 } |
463 |
463 |
464 RemoveObjects( newFocusIndex, newTotalSize, aFirstRemovedIndex, aLastRemovedIndex ); |
464 RemoveObjectsL( newFocusIndex, newTotalSize, aFirstRemovedIndex, aLastRemovedIndex ); |
465 } |
465 } |
466 |
466 |
467 // ----------------------------------------------------------------------------- |
467 // ----------------------------------------------------------------------------- |
468 // RemoveObjects |
468 // RemoveObjects |
469 // ----------------------------------------------------------------------------- |
469 // ----------------------------------------------------------------------------- |
470 // |
470 // |
471 EXPORT_C void CGlxListWindow::RemoveObjects( TInt aFocusIndex, |
471 EXPORT_C void CGlxListWindow::RemoveObjectsL( TInt aFocusIndex, |
472 TInt aTotalSize, TInt aFirstRemovedIndex, TInt aLastRemovedIndex ) |
472 TInt aTotalSize, TInt aFirstRemovedIndex, TInt aLastRemovedIndex ) |
473 { |
473 { |
474 TRACER("CGlxListWindow::RemoveObjects"); |
474 TRACER("CGlxListWindow::RemoveObjectsL"); |
475 |
475 |
476 __ASSERT_DEBUG( 0 <= aFirstRemovedIndex && aFirstRemovedIndex <= aLastRemovedIndex && |
476 __ASSERT_DEBUG( 0 <= aFirstRemovedIndex && aFirstRemovedIndex <= aLastRemovedIndex && |
477 ( ( 0 <= aFocusIndex && aFocusIndex < aTotalSize ) || |
477 ( ( 0 <= aFocusIndex && aFocusIndex < aTotalSize ) || |
478 ( KErrNotFound == aFocusIndex && aTotalSize == 0 ) ), |
478 ( KErrNotFound == aFocusIndex && aTotalSize == 0 ) ), |
479 Panic( EGlxPanicIllegalArgument ) ); |
479 Panic( EGlxPanicIllegalArgument ) ); |
480 __TEST_INVARIANT; |
480 __TEST_INVARIANT; |
481 |
481 |
482 Update( TChange( aFocusIndex, aTotalSize, EChangeObjectsRemoved, |
482 UpdateL( TChange( aFocusIndex, aTotalSize, EChangeObjectsRemoved, |
483 aFirstRemovedIndex, aLastRemovedIndex ) ); |
483 aFirstRemovedIndex, aLastRemovedIndex ) ); |
484 |
484 |
485 __TEST_INVARIANT; |
485 __TEST_INVARIANT; |
486 } |
486 } |
487 |
487 |
488 // ----------------------------------------------------------------------------- |
488 // ----------------------------------------------------------------------------- |
489 // Update |
489 // Update |
490 // ----------------------------------------------------------------------------- |
490 // ----------------------------------------------------------------------------- |
491 // |
491 // |
492 void CGlxListWindow::Update( const TChange& aChange ) |
492 void CGlxListWindow::UpdateL( const TChange& aChange ) |
493 { |
493 { |
494 TRACER("CGlxListWindow::Update"); |
494 TRACER("CGlxListWindow::UpdateL"); |
495 |
495 |
496 // (in a list of: |abcdefghijklm| |
496 // (in a list of: |abcdefghijklm| |
497 // iWindow: |----efghi----| |
497 // iWindow: |----efghi----| |
498 // iWorkingWindow: undefined state |
498 // iWorkingWindow: undefined state |
499 // iUnusedObjects: XXX (3 objects, in reality only contains objects if list |
499 // iUnusedObjects: XXX (3 objects, in reality only contains objects if list |
500 // is shorter than max window length) |
500 // is shorter than max window length) |
501 |
501 |
502 // Prepare the working window to accept objects |
502 // Prepare the working window to accept objects |
503 iWorkingWindow->Initialize( Range( aChange ), aChange.iNewTotalSize ); |
503 iWorkingWindow->InitializeL( Range( aChange ), aChange.iNewTotalSize ); |
504 |
504 |
505 // iWindow: |----efghi----| |
505 // iWindow: |----efghi----| |
506 // iWorkingWindow: |------00000--| |
506 // iWorkingWindow: |------00000--| |
507 // iUnusedObjects: XXX |
507 // iUnusedObjects: XXX |
508 |
508 |
509 // move unused objects to pool, and reusable objects to working window |
509 // move unused objects to pool, and reusable objects to working window |
510 PopulateExistingAndUnuseOld( aChange ); |
510 PopulateExistingAndUnuseOldL( aChange ); |
511 |
511 |
512 // iWindow: |----efghi----| |
512 // iWindow: |----efghi----| |
513 // iWorkingWindow: |------ghi00--| |
513 // iWorkingWindow: |------ghi00--| |
514 // iUnusedObjects: XXXXX (2 objects added, used to be e and f) |
514 // iUnusedObjects: XXXXX (2 objects added, used to be e and f) |
515 |
515 |
535 |
535 |
536 // ----------------------------------------------------------------------------- |
536 // ----------------------------------------------------------------------------- |
537 // PopulateExistingAndUnuseOld |
537 // PopulateExistingAndUnuseOld |
538 // ----------------------------------------------------------------------------- |
538 // ----------------------------------------------------------------------------- |
539 // |
539 // |
540 void CGlxListWindow::PopulateExistingAndUnuseOld( const TChange& aChange ) |
540 void CGlxListWindow::PopulateExistingAndUnuseOldL( const TChange& aChange ) |
541 { |
541 { |
542 TRACER("CGlxListWindow::PopulateExistingAndUnuseOld"); |
542 TRACER("CGlxListWindow::PopulateExistingAndUnuseOldL"); |
543 |
543 |
544 // move objects that are needed after the change into the working window, |
544 // move objects that are needed after the change into the working window, |
545 // and objects that are not needed into the object pool |
545 // and objects that are not needed into the object pool |
546 TGlxWindowIterator currentWindowIterator = iWindow->Iterator(); |
546 TGlxWindowIterator currentWindowIterator = iWindow->Iterator(); |
547 TInt index = 0; |
547 TInt index = 0; |
561 // do this first, so that the deriving class can access the window |
561 // do this first, so that the deriving class can access the window |
562 // by index, if needed |
562 // by index, if needed |
563 iObjectFactory.CleanupObject( index, *( *iWindow )[ index ] ); |
563 iObjectFactory.CleanupObject( index, *( *iWindow )[ index ] ); |
564 // add the object to the unused objects pool |
564 // add the object to the unused objects pool |
565 // cannot fail since reservation made |
565 // cannot fail since reservation made |
566 ( void ) iUnusedObjects.Append( ( *iWindow )[ index ] ); |
566 ( void )iUnusedObjects.AppendL( ( *iWindow )[ index ] ); |
567 } |
567 } |
568 |
568 |
569 // clear the pointer in the existing window. it is not strictly necessary |
569 // clear the pointer in the existing window. it is not strictly necessary |
570 // to do here, but saves a loop from doing it in CGlxDataWindow::Initialize |
570 // to do here, but saves a loop from doing it in CGlxDataWindow::Initialize |
571 ( *iWindow )[ index ] = NULL; |
571 ( *iWindow )[ index ] = NULL; |