From 8e125ff1145c4c3154a59efe3e60c58a7fd0861d Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Mon, 1 Jul 2013 05:10:22 +0000 Subject: [PATCH] Use gtk_list_store_insert_with_values() to set entry at same time item is inserted. This should ensure that the entry is always valid, removing the need for r74315. Also simplify DoInsertItems() by using DoInsertItemsInLoop(). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74317 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/listbox.h | 1 + src/gtk/listbox.cpp | 46 +++++++++++++++------------------------- src/gtk/treeentry_gtk.c | 4 ---- 3 files changed, 18 insertions(+), 33 deletions(-) diff --git a/include/wx/gtk/listbox.h b/include/wx/gtk/listbox.h index 038a53464b..ed73ca33d8 100644 --- a/include/wx/gtk/listbox.h +++ b/include/wx/gtk/listbox.h @@ -111,6 +111,7 @@ protected: virtual int DoInsertItems(const wxArrayStringsAdapter& items, unsigned int pos, void **clientData, wxClientDataType type); + virtual int DoInsertOneItem(const wxString& item, unsigned int pos); virtual void DoSetFirstItem(int n); virtual void DoSetItemClientData(unsigned int n, void* clientData); diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index 4f44746313..27d7440ae2 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -454,38 +454,26 @@ int wxListBox::DoInsertItems(const wxArrayStringsAdapter& items, wxCHECK_MSG( m_treeview != NULL, wxNOT_FOUND, wxT("invalid listbox") ); InvalidateBestSize(); + int n = DoInsertItemsInLoop(items, pos, clientData, type); + UpdateOldSelections(); + return n; +} - 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 ) - { - wxGtkObject 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); - - if (clientData) - AssignNewItemClientData(GTKGetIndexFor(itercur), clientData, i, type); - } +int wxListBox::DoInsertOneItem(const wxString& item, unsigned int pos) +{ + GtkTreeEntry* entry = gtk_tree_entry_new(); + gtk_tree_entry_set_label(entry, wxGTK_CONV(item)); + gtk_tree_entry_set_destroy_func(entry, (GtkTreeEntryDestroy)gtk_tree_entry_destroy_cb, this); - UpdateOldSelections(); +#if wxUSE_CHECKLISTBOX + int entryCol = int(m_hasCheckBoxes); +#else + int entryCol = 0; +#endif + gtk_list_store_insert_with_values(m_liststore, NULL, pos, entryCol, entry, -1); + g_object_unref(entry); - return pos + numItems - 1; + return pos; } // ---------------------------------------------------------------------------- diff --git a/src/gtk/treeentry_gtk.c b/src/gtk/treeentry_gtk.c index 1f3bf2b7f4..5b76211109 100644 --- a/src/gtk/treeentry_gtk.c +++ b/src/gtk/treeentry_gtk.c @@ -151,10 +151,6 @@ static void gtk_tree_entry_string_transform_func(const GValue *src_value, GtkTreeEntry *entry; void* src_ptr = g_value_peek_pointer(src_value); - /* can be NULL if transform is requested before entry is set */ - if (src_ptr == NULL) - return; - /* Make sure src is a treeentry and dest can hold a string */ g_assert(GTK_IS_TREE_ENTRY(src_ptr)); g_assert(G_VALUE_HOLDS(dest_value, G_TYPE_STRING)); -- 2.45.2