From 5403ec4e086c4fbc3d9ee9bf4b38964a48357826 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 12 Sep 2019 23:08:10 +0200 Subject: [PATCH] Make Cleared() behave consistently with the other ports in wxGTK Instead of actually deleting all the items from the control, just refresh it by resetting the model, as this is what Cleared() does in both the generic and native macOS versions of wxDataViewCtrl, so calling it there resulted in very different results from doing it under wxGTK, where instead of refreshing the control contents it raelly cleared it. The name of this method is unfortunately confusing, but it seems better to change its behaviour in wxGTK, even if this doesn't match the name, rather than change it in the other ports to make them do the same thing, as this could break some currently working code. Also, this change results in a welcome code simplification. --- src/gtk/dataview.cpp | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index c46551b9ca..9aadc4c418 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -1895,35 +1895,7 @@ bool wxGtkDataViewModelNotifier::AfterReset() bool wxGtkDataViewModelNotifier::Cleared() { - GtkWxTreeModel *wxgtk_model = m_internal->GetGtkModel(); - - // There is no call to tell the model that everything - // has been deleted so call row_deleted() for every - // child of root... - - // It is important to avoid selection changed events being generated from - // here as they would reference the already deleted model items, which - // would result in crashes in any code attempting to handle these events. - wxDataViewCtrl::SelectionEventsSuppressor noSelection(m_internal->GetOwner()); - - // We also need to prevent wxGtkTreeCellDataFunc from using the model items - // not existing any longer, so change the model stamp to indicate that it - // temporarily can't be used. - const gint stampOrig = wxgtk_model->stamp; - wxgtk_model->stamp = 0; - - { - wxGtkTreePath path(gtk_tree_path_new_first()); // points to root - const int count = m_internal->iter_n_children( NULL ); // number of children of root - for (int i = 0; i < count; i++) - gtk_tree_model_row_deleted( GTK_TREE_MODEL(wxgtk_model), path ); - } - - wxgtk_model->stamp = stampOrig; - - m_internal->Cleared(); - - return true; + return BeforeReset() && AfterReset(); } // ---------------------------------------------------------