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
This commit is contained in:
Paul Cornett
2013-07-01 05:10:22 +00:00
parent d642db66a5
commit 8e125ff114
3 changed files with 19 additions and 34 deletions

View File

@@ -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);

View File

@@ -454,38 +454,26 @@ int wxListBox::DoInsertItems(const wxArrayStringsAdapter& items,
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 )
{
wxGtkObject<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);
if (clientData)
AssignNewItemClientData(GTKGetIndexFor(itercur), clientData, i, type);
}
int n = DoInsertItemsInLoop(items, pos, clientData, type);
UpdateOldSelections();
return n;
}
return pos + numItems - 1;
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);
#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;
}
// ----------------------------------------------------------------------------

View File

@@ -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));