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:
@@ -111,6 +111,7 @@ protected:
|
|||||||
virtual int DoInsertItems(const wxArrayStringsAdapter& items,
|
virtual int DoInsertItems(const wxArrayStringsAdapter& items,
|
||||||
unsigned int pos,
|
unsigned int pos,
|
||||||
void **clientData, wxClientDataType type);
|
void **clientData, wxClientDataType type);
|
||||||
|
virtual int DoInsertOneItem(const wxString& item, unsigned int pos);
|
||||||
|
|
||||||
virtual void DoSetFirstItem(int n);
|
virtual void DoSetFirstItem(int n);
|
||||||
virtual void DoSetItemClientData(unsigned int n, void* clientData);
|
virtual void DoSetItemClientData(unsigned int n, void* clientData);
|
||||||
|
@@ -454,38 +454,26 @@ int wxListBox::DoInsertItems(const wxArrayStringsAdapter& items,
|
|||||||
wxCHECK_MSG( m_treeview != NULL, wxNOT_FOUND, wxT("invalid listbox") );
|
wxCHECK_MSG( m_treeview != NULL, wxNOT_FOUND, wxT("invalid listbox") );
|
||||||
|
|
||||||
InvalidateBestSize();
|
InvalidateBestSize();
|
||||||
|
int n = DoInsertItemsInLoop(items, pos, clientData, type);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateOldSelections();
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -151,10 +151,6 @@ static void gtk_tree_entry_string_transform_func(const GValue *src_value,
|
|||||||
GtkTreeEntry *entry;
|
GtkTreeEntry *entry;
|
||||||
void* src_ptr = g_value_peek_pointer(src_value);
|
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 */
|
/* Make sure src is a treeentry and dest can hold a string */
|
||||||
g_assert(GTK_IS_TREE_ENTRY(src_ptr));
|
g_assert(GTK_IS_TREE_ENTRY(src_ptr));
|
||||||
g_assert(G_VALUE_HOLDS(dest_value, G_TYPE_STRING));
|
g_assert(G_VALUE_HOLDS(dest_value, G_TYPE_STRING));
|
||||||
|
Reference in New Issue
Block a user