void wxListBox::DoInsertItems(const wxArrayString& items, unsigned int pos) { wxCHECK_RET( IsValidInsert(pos), wxT("invalid index in wxListBox::InsertItems") ); unsigned int nItems = items.GetCount(); for ( unsigned int i = 0; i < nItems; i++ ) { int idx = ListBox_InsertString(GetHwnd(), i + pos, items[i]); #if wxUSE_OWNER_DRAWN if ( m_windowStyle & wxLB_OWNERDRAW ) { wxOwnerDrawn *pNewItem = CreateLboxItem(idx); pNewItem->SetName(items[i]); pNewItem->SetFont(GetFont()); m_aItems.Insert(pNewItem, idx); ListBox_SetItemData(GetHwnd(), idx, pNewItem); } #else wxUnusedVar(idx); #endif // wxUSE_OWNER_DRAWN } m_noItems += nItems; SetHorizontalExtent(); }
int wxListBox::DoInsertItems(const wxArrayStringsAdapter & items, unsigned int pos, void **clientData, wxClientDataType type) { MSWAllocStorage(items, LB_INITSTORAGE); const bool append = pos == GetCount(); // we must use CB_ADDSTRING when appending as only it works correctly for // the sorted controls const unsigned msg = append ? LB_ADDSTRING : LB_INSERTSTRING; if ( append ) pos = 0; int n = wxNOT_FOUND; const unsigned int numItems = items.GetCount(); for ( unsigned int i = 0; i < numItems; i++ ) { n = MSWInsertOrAppendItem(pos, items[i], msg); if ( n == wxNOT_FOUND ) return n; if ( !append ) pos++; ++m_noItems; #if wxUSE_OWNER_DRAWN if ( HasFlag(wxLB_OWNERDRAW) ) { wxOwnerDrawn *pNewItem = CreateLboxItem(n); pNewItem->SetName(items[i]); pNewItem->SetFont(GetFont()); m_aItems.Insert(pNewItem, n); } #endif // wxUSE_OWNER_DRAWN AssignNewItemClientData(n, clientData, i, type); } m_updateHorizontalExtent = true; UpdateOldSelections(); return n; }
void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData) { // avoid flicker - but don't need to do this for a hidden listbox bool hideAndShow = IsShown(); if ( hideAndShow ) { ShowWindow(GetHwnd(), SW_HIDE); } ListBox_ResetContent(GetHwnd()); m_noItems = choices.GetCount(); int i; for (i = 0; i < m_noItems; i++) { ListBox_AddString(GetHwnd(), choices[i]); if ( clientData ) { SetClientData(i, clientData[i]); } } #if wxUSE_OWNER_DRAWN if ( m_windowStyle & wxLB_OWNERDRAW ) { // first delete old items WX_CLEAR_ARRAY(m_aItems); // then create new ones for ( size_t ui = 0; ui < (size_t)m_noItems; ui++ ) { wxOwnerDrawn *pNewItem = CreateLboxItem(ui); pNewItem->SetName(choices[ui]); m_aItems.Add(pNewItem); ListBox_SetItemData(GetHwnd(), ui, pNewItem); } } #endif // wxUSE_OWNER_DRAWN SetHorizontalExtent(); if ( hideAndShow ) { // show the listbox back if we hid it ShowWindow(GetHwnd(), SW_SHOW); } InvalidateBestSize(); }
int wxListBox::DoAppend(const wxString& item) { int index = ListBox_AddString(GetHwnd(), item); m_noItems++; #if wxUSE_OWNER_DRAWN if ( m_windowStyle & wxLB_OWNERDRAW ) { wxOwnerDrawn *pNewItem = CreateLboxItem(index); // dummy argument pNewItem->SetName(item); m_aItems.Insert(pNewItem, index); ListBox_SetItemData(GetHwnd(), index, pNewItem); pNewItem->SetFont(GetFont()); } #endif // wxUSE_OWNER_DRAWN SetHorizontalExtent(item); return index; }