/** * Delete the selected item or items from the list box. */ void CSettingList::DeleteSelectedListBoxItemsL( CEikTextListBox* aListBox ) { CAknFilteredTextListBoxModel* model = static_cast< CAknFilteredTextListBoxModel *> ( aListBox->Model() ); if ( model->NumberOfItems() == 0 ) return; RArray< TInt >* orderedSelectedIndices = GetSelectedListBoxItemsLC( aListBox ); if ( !orderedSelectedIndices ) return; // Delete selected items from bottom up so indices don't change on us CDesCArray* itemArray = static_cast< CDesCArray* > ( model->ItemTextArray() ); TInt currentItem = 0; for ( TInt idx = orderedSelectedIndices->Count(); idx-- > 0; ) { currentItem = ( *orderedSelectedIndices )[ idx ]; itemArray->Delete ( currentItem ); } // dispose the array resources CleanupStack::PopAndDestroy(); // dispose the array pointer CleanupStack::PopAndDestroy( orderedSelectedIndices ); // refresh listbox's cursor now that items are deleted AknListBoxUtils::HandleItemRemovalAndPositionHighlightL( aListBox, currentItem, ETrue ); }
/** * Get the array of selected item indices, with respect to the list model. * The array is sorted in ascending order. * The array should be destroyed with two calls to CleanupStack::PopAndDestroy(), * the first with no argument (referring to the internal resource) and the * second with the array pointer. * @return newly allocated array, which is left on the cleanup stack; * or NULL for empty list. */ RArray< TInt >* CSettingList::GetSelectedListBoxItemsLC( CEikTextListBox* aListBox ) { CAknFilteredTextListBoxModel* model = static_cast< CAknFilteredTextListBoxModel *> ( aListBox->Model() ); if ( model->NumberOfItems() == 0 ) return NULL; // get currently selected indices const CListBoxView::CSelectionIndexArray* selectionIndexes = aListBox->SelectionIndexes(); TInt selectedIndexesCount = selectionIndexes->Count(); if ( selectedIndexesCount == 0 ) return NULL; // copy the indices and sort numerically RArray<TInt>* orderedSelectedIndices = new (ELeave) RArray< TInt >( selectedIndexesCount ); // push the allocated array CleanupStack::PushL( orderedSelectedIndices ); // dispose the array resource CleanupClosePushL( *orderedSelectedIndices ); // see if the search field is enabled CAknListBoxFilterItems* filter = model->Filter(); if ( filter != NULL ) { // when filtering enabled, translate indices back to underlying model for ( TInt idx = 0; idx < selectedIndexesCount; idx++ ) { TInt filteredItem = ( *selectionIndexes ) [ idx ]; TInt actualItem = filter->FilteredItemIndex ( filteredItem ); orderedSelectedIndices->InsertInOrder( actualItem ); } } else { // the selection indices refer directly to the model for ( TInt idx = 0; idx < selectedIndexesCount; idx++ ) orderedSelectedIndices->InsertInOrder( ( *selectionIndexes ) [ idx ] ); } return orderedSelectedIndices; }