Skip to content

Commit

Permalink
Really fix spurious asserts in wxGTK wxDataViewCtrl::EditItem()
Browse files Browse the repository at this point in the history
This replaces the changes of 24c0401
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.

See #17946.

(cherry picked from commit 81d9952)
  • Loading branch information
vadz committed Sep 13, 2017
1 parent ddf2feb commit 28aee1b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/gtk/dataview.cpp
Expand Up @@ -163,16 +163,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
Expand Down Expand Up @@ -225,15 +225,13 @@ class wxGtkTreeSelectionLock
}

static wxGtkTreeSelectionLock *ms_instance;
static bool ms_firstTime;

GtkTreeSelection * const m_selection;

wxDECLARE_NO_COPY_CLASS(wxGtkTreeSelectionLock);
};

wxGtkTreeSelectionLock *wxGtkTreeSelectionLock::ms_instance = NULL;
bool wxGtkTreeSelectionLock::ms_firstTime = true;

//-----------------------------------------------------------------------------
// wxDataViewCtrlInternal
Expand Down Expand Up @@ -344,6 +342,11 @@ class wxDataViewCtrlInternal
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;
};


Expand Down Expand Up @@ -3419,6 +3422,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;
Expand Down Expand Up @@ -4849,7 +4853,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;
Expand Down Expand Up @@ -4890,7 +4895,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;
Expand Down

0 comments on commit 28aee1b

Please sign in to comment.