int wxListBox::GetSelection() const { wxCHECK_MSG( m_treeview != NULL, wxNOT_FOUND, wxT("invalid listbox")); wxCHECK_MSG( HasFlag(wxLB_SINGLE), wxNOT_FOUND, wxT("must be single selection listbox")); GtkTreeIter iter; GtkTreeSelection* selection = gtk_tree_view_get_selection(m_treeview); // only works on single-sel if (!gtk_tree_selection_get_selected(selection, NULL, &iter)) return wxNOT_FOUND; return GTKGetIndexFor(iter); }
int wxListBox::DoInsertItems(const wxArrayStringsAdapter& items, unsigned int pos, void **clientData, wxClientDataType type) { wxCHECK_MSG( m_treeview != NULL, wxNOT_FOUND, wxT("invalid listbox") ); InvalidateBestSize(); GtkTreeIter* pIter = NULL; // append by default GtkTreeIter iter; if ( pos != GetCount() ) { wxCHECK_MSG( GTKGetIteratorFor(pos, &iter), wxNOT_FOUND, wxT("internal wxListBox error in insertion") ); pIter = &iter; } const unsigned int numItems = items.GetCount(); for ( unsigned int i = 0; i < numItems; ++i ) { GtkTreeEntry* entry = gtk_tree_entry_new(); gtk_tree_entry_set_label(entry, wxGTK_CONV(items[i])); gtk_tree_entry_set_destroy_func(entry, (GtkTreeEntryDestroy)gtk_tree_entry_destroy_cb, this); GtkTreeIter itercur; gtk_list_store_insert_before(m_liststore, &itercur, pIter); GTKSetItem(itercur, entry); g_object_unref (entry); if (clientData) AssignNewItemClientData(GTKGetIndexFor(itercur), clientData, i, type); } UpdateOldSelections(); return pos + numItems - 1; }
int wxListBox::DoInsertOneItem(const wxString& item, unsigned int pos) { wxTreeEntry* entry = wx_tree_entry_new(); wx_tree_entry_set_label(entry, wxGTK_CONV(item)); wx_tree_entry_set_destroy_func(entry, (wxTreeEntryDestroy)tree_entry_destroy_cb, this); #if wxUSE_CHECKLISTBOX int entryCol = int(m_hasCheckBoxes); #else int entryCol = 0; #endif GtkTreeIter iter; gtk_list_store_insert_with_values(m_liststore, &iter, pos, entryCol, entry, -1); g_object_unref(entry); if (HasFlag(wxLB_SORT)) pos = GTKGetIndexFor(iter); return pos; }