From 81d9952dfe4585c9d2c8a537cf15d24167fa9992 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 13 Sep 2017 17:25:48 +0200 Subject: [PATCH] Really fix spurious asserts in wxGTK wxDataViewCtrl::EditItem() This replaces the changes of 24c0401e81a4d0206f89b21775adb90fb11bf32a which, for some reason, used a global variable for storing whether the selection function had been already set or not, when this clearly is a per-control (or per-selection, but this seems one and the same) bit of information. Replace global ms_firstTime with a wxDataViewCtrlInternal field to avoid asserts as soon as EditItem() is called on more than one wxDataViewCtrl. Closes #17946. --- src/gtk/dataview.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index c24b3eb3d6..ccf3421f93 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -115,16 +115,16 @@ gboolean wxdataview_selection_func(GtkTreeSelection * WXUNUSED(selection), class wxGtkTreeSelectionLock { public: - wxGtkTreeSelectionLock(GtkTreeSelection *selection) + wxGtkTreeSelectionLock(GtkTreeSelection *selection, bool& alreadySet) : m_selection(selection) { wxASSERT_MSG( !ms_instance, "this class is not reentrant currently" ); ms_instance = this; - if ( ms_firstTime ) + if ( !alreadySet ) { - ms_firstTime = false; + alreadySet = true; CheckCurrentSelectionFunc(NULL); } else @@ -177,7 +177,6 @@ private: } static wxGtkTreeSelectionLock *ms_instance; - static bool ms_firstTime; GtkTreeSelection * const m_selection; @@ -185,7 +184,6 @@ private: }; wxGtkTreeSelectionLock *wxGtkTreeSelectionLock::ms_instance = NULL; -bool wxGtkTreeSelectionLock::ms_firstTime = true; //----------------------------------------------------------------------------- // wxDataViewCtrlInternal @@ -296,6 +294,11 @@ private: wxGtkDataViewModelNotifier *m_notifier; bool m_dirty; + +public: + // Allow direct access to this one from wxDataViewCtrl as it's just a + // simple flag and it doesn't make much sense to encapsulate it. + bool m_selectionFuncSet; }; @@ -3515,6 +3518,7 @@ wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl *owner, wxDataVie m_dropDataObject = NULL; m_dirty = false; + m_selectionFuncSet = false; m_gtk_model = wxgtk_tree_model_new(); m_gtk_model->internal = this; @@ -4908,7 +4912,8 @@ void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem& item) // Unfortunately the only way to do it seems to use our own selection // function and forbid any selection changes during set cursor call. wxGtkTreeSelectionLock - lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview))); + lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview)), + m_internal->m_selectionFuncSet); // Do move the cursor now. GtkTreeIter iter; @@ -4949,7 +4954,8 @@ void wxDataViewCtrl::EditItem(const wxDataViewItem& item, const wxDataViewColumn // Unfortunately the only way to do it seems to use our own selection // function and forbid any selection changes during set cursor call. wxGtkTreeSelectionLock - lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview))); + lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview)), + m_internal->m_selectionFuncSet); // Do move the cursor now. GtkTreeIter iter;