/** * 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 ); }
void CSearchableListBoxContainer::InitializeControlsL() { iListBox = new ( ELeave ) CAknSingleStyleListBox; iListBox->SetContainerWindowL( *this ); { TResourceReader reader; iEikonEnv->CreateResourceReaderLC( reader, R_WAYFINDER_SEARCHABLE_LISTBOX ); iListBox->ConstructFromResourceL( reader ); CleanupStack::PopAndDestroy(); // reader internal state } // the listbox owns the items in the list and will free them //iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray ); iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray ); // setup the icon array so graphics-style boxes work SetupListBoxIconsL(); iListBox->SetListBoxObserver( this ); // set up the Search Field CAknSearchField* searchField = CAknSearchField::NewL( *this, CAknSearchField::ESearch, 0, 40 ); CleanupStack::PushL ( searchField ); CAknFilteredTextListBoxModel* filteredModel = static_cast< CAknFilteredTextListBoxModel* >( iListBox->Model() ); filteredModel->CreateFilterL( iListBox, searchField ); CleanupStack::Pop( searchField ); searchField->MakeVisible( ETrue ); iListBoxSearchField = searchField; iListBox->SetFocus( ETrue ); iFocusControl = iListBox; }
CAknSearchField* CSymellaSearchContainer::CreateFindBoxL( CEikListBox* aListBox, CTextListBoxModel* aModel, CAknSearchField::TSearchFieldStyle aStyle ) { CAknSearchField* findbox = NULL; if ( aListBox && aModel ) { // Gets pointer of CAknFilteredTextListBoxModel. CAknFilteredTextListBoxModel* model = static_cast<CAknFilteredTextListBoxModel*>( aModel ); // Creates FindBox. findbox = CAknSearchField::NewL( *this, aStyle, NULL, KListFindBoxTextLength ); CleanupStack::PushL( findbox ); // Creates CAknListBoxFilterItems class. model->CreateFilterL( aListBox, findbox ); //Filter can get by model->Filter(); CleanupStack::Pop( findbox ); // findbox } return findbox; }
TInt CSymellaSearchContainer::CurrentItemIndex() { if ((iListBox->CurrentItemIndex() >= 0) && (iFindBox) && (iFindBox->TextLength() > 0)) { CAknFilteredTextListBoxModel* model = static_cast<CAknFilteredTextListBoxModel*>(iListBox->Model()); CAknListBoxFilterItems* filter = model->Filter(); return filter->FilteredItemIndex(iListBox->CurrentItemIndex()); } else return iListBox->CurrentItemIndex(); }
/** * 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; }
void MobiStegoContacts::ConstructL(const TRect& aRect, CMobiStegoDocument* aDocument) { iDocument = aDocument; CreateWindowL(); SetRect(aRect); /*other iListBox = new (ELeave) CAknSingleStyleListBox; iListBox->ConstructL(this, EAknListBoxSelectionList ); iListBox->Model()->SetItemTextArray(iListBoxRows); iListBox->CreateScrollBarFrameL(); iListBox->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray); iListBox->SetListBoxObserver(this); //UpdateL(); // iListBox->HandleItemAdditionL(); // set up the Search Field CAknSearchField* findbox = NULL; // Gets pointer of CAknFilteredTextListBoxModel. CAknFilteredTextListBoxModel* model = STATIC_CAST( CAknFilteredTextListBoxModel*, iListBox->Model() ); // Creates FindBox. findbox = CAknSearchField::NewL(*this, CAknSearchField::EPopup, NULL, 40); CleanupStack::PushL(findbox); // Creates CAknListBoxFilterItems class. model->CreateFilterL(iListBox, findbox); //Filter can get by model->Filter(); CleanupStack::Pop(findbox); // findbox SizeChanged(); iListBox->ActivateL(); TInt ItemsCount = iListBox->Model()->ItemTextArray()->MdcaCount(); iListBox->SetCurrentItemIndex(0); // UpdateScrollBar(iListBox); DrawNow();*/ /* CAknSearchField* searchField = CAknSearchField::NewL(*this, CAknSearchField::EPopup, 0, 40); CleanupStack::PushL(searchField); CAknFilteredTextListBoxModel* filteredModel = static_cast<CAknFilteredTextListBoxModel*> (iListBox->Model()); filteredModel->CreateFilterL(iListBox, searchField); CleanupStack::Pop(searchField); searchField->MakeVisible(ETrue); iListBoxSearchField = searchField; iListBoxSearchField->SetFocus(ETrue); //Set Up the CBA for the searchbox CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current(); cba->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_BACK); TInt posBack = cba->PositionById(EAknSoftkeyBack); cba->SetCommandL(posBack, EContactsViewGoBackCmdNone, KNullDesC); iSpdDialPos = -1; SetRect(aRect); */ /**/ // create listbox control iListBox = new (ELeave) CAknSingleStyleListBox; iListBox->ConstructL(this, 0); iListBox->SetContainerWindowL(*this); iListBox->SetRect(aRect.Size()); iListBoxRows = new (ELeave) CDesCArrayFlat(KGranularityOfArray); iListBox->Model()->SetItemTextArray(iListBoxRows); iListBox->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray); iListBox->ActivateL(); iListBox->CreateScrollBarFrameL(ETrue); iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto); //------------------------------------------------------ searchField = CAknSearchField::NewL(*this, CAknSearchField::EPopup, 0, 40); CleanupStack::PushL(searchField); CAknFilteredTextListBoxModel* filteredModel = static_cast<CAknFilteredTextListBoxModel*> (iListBox->Model()); filteredModel->CreateFilterL(iListBox, searchField); CleanupStack::Pop(searchField); searchField->MakeVisible(ETrue); SizeChanged(); //----------------------------------------------------- ActivateL(); MakeVisible(ETrue); searchField->SetFocus(ETrue); }