Make GetIndexOf() and get_path() work for virtual list models, fixes #12073: wxDataViewCtrl crashes when deleting an item

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64362 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2010-05-20 18:39:20 +00:00
parent caec2e7835
commit 559c42a5b2
2 changed files with 20 additions and 8 deletions

View File

@@ -543,8 +543,8 @@ void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt &rows )
unsigned int i; unsigned int i;
for (i = 0; i < sorted.GetCount(); i++) for (i = 0; i < sorted.GetCount(); i++)
{ {
wxDataViewItem item( wxUIntToPtr(sorted[i]+1) ); wxDataViewItem item( wxUIntToPtr(sorted[i]+1) );
array.Add( item ); array.Add( item );
} }
/* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array ); /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array );
} }

View File

@@ -3529,6 +3529,10 @@ GtkTreePath *wxDataViewCtrlInternal::get_path( GtkTreeIter *iter )
if (m_wx_model->IsVirtualListModel()) if (m_wx_model->IsVirtualListModel())
{ {
// iter is root, add nothing
if (!iter->user_data)
return retval;
// user_data is just the index +1 // user_data is just the index +1
int i = ( (wxUIntPtr) iter->user_data ) -1; int i = ( (wxUIntPtr) iter->user_data ) -1;
gtk_tree_path_append_index (retval, i); gtk_tree_path_append_index (retval, i);
@@ -3776,13 +3780,21 @@ gboolean wxDataViewCtrlInternal::iter_parent( GtkTreeIter *iter, GtkTreeIter *ch
// item can be deleted already in the model // item can be deleted already in the model
int wxDataViewCtrlInternal::GetIndexOf( const wxDataViewItem &parent, const wxDataViewItem &item ) int wxDataViewCtrlInternal::GetIndexOf( const wxDataViewItem &parent, const wxDataViewItem &item )
{ {
wxGtkTreeModelNode *parent_node = FindNode( parent ); if (m_wx_model->IsVirtualListModel())
wxGtkTreeModelChildren &children = parent_node->GetChildren();
size_t j;
for (j = 0; j < children.GetCount(); j++)
{ {
if (children[j] == item.GetID()) int index = ((int)(item.GetID())) - 1;
return j; return index;
}
else
{
wxGtkTreeModelNode *parent_node = FindNode( parent );
wxGtkTreeModelChildren &children = parent_node->GetChildren();
size_t j;
for (j = 0; j < children.GetCount(); j++)
{
if (children[j] == item.GetID())
return j;
}
} }
return -1; return -1;
} }