From 559c42a5b23f07b4303333631018b8b4df661d00 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Thu, 20 May 2010 18:39:20 +0000 Subject: [PATCH] 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 --- src/common/datavcmn.cpp | 4 ++-- src/gtk/dataview.cpp | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 753128781e..dca9eaab7d 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -543,8 +543,8 @@ void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt &rows ) unsigned int i; for (i = 0; i < sorted.GetCount(); i++) { - wxDataViewItem item( wxUIntToPtr(sorted[i]+1) ); - array.Add( item ); + wxDataViewItem item( wxUIntToPtr(sorted[i]+1) ); + array.Add( item ); } /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array ); } diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index f62853a3db..e2db524fd8 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -3529,6 +3529,10 @@ GtkTreePath *wxDataViewCtrlInternal::get_path( GtkTreeIter *iter ) if (m_wx_model->IsVirtualListModel()) { + // iter is root, add nothing + if (!iter->user_data) + return retval; + // user_data is just the index +1 int i = ( (wxUIntPtr) iter->user_data ) -1; 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 int wxDataViewCtrlInternal::GetIndexOf( const wxDataViewItem &parent, const wxDataViewItem &item ) { - wxGtkTreeModelNode *parent_node = FindNode( parent ); - wxGtkTreeModelChildren &children = parent_node->GetChildren(); - size_t j; - for (j = 0; j < children.GetCount(); j++) + if (m_wx_model->IsVirtualListModel()) + { + int index = ((int)(item.GetID())) - 1; + return index; + } + else { - if (children[j] == item.GetID()) - return j; + 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; } -- 2.49.0