]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix assert when destroying wxDataViewCtrl being edited in wxGTK.
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 26 Apr 2011 22:57:01 +0000 (22:57 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 26 Apr 2011 22:57:01 +0000 (22:57 +0000)
If wxDataViewCtrl was destroyed while showing a generic editor, an assert
occurred in wxWindowBase dtor as the event handler pushed on it by the editor.

Fix this by calling CancelEditing() when the control is destroyed and also fix
the crash in CancelEditing() in wxGTK due to recursive calls to FinishEditing().

Closes #12683.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67612 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/dataview.h
src/common/datavcmn.cpp
src/gtk/dataview.cpp

index 9ff89012ec1e4b6abf376030f467421b335c773f..03bcbdf1c30cc3a3a0ec41808e3687438fac7d1a 100644 (file)
@@ -192,6 +192,12 @@ private:
     virtual wxDataViewItem DoGetCurrentItem() const;
     virtual void DoSetCurrentItem(const wxDataViewItem& item);
 
+    // Return wxDataViewColumn matching the given GtkTreeViewColumn.
+    //
+    // If the input argument is NULL, return NULL too. Otherwise we must find
+    // the matching column and assert if we didn't.
+    wxDataViewColumn* FromGTKColumn(GtkTreeViewColumn *gtk_col) const;
+
     friend class wxDataViewCtrlDCImpl;
     friend class wxDataViewColumn;
     friend class wxDataViewCtrlInternal;
index fa3d3563d5e562ca254aec5be87ce75d2acfca87..8e2469c228dd59c0ac90b064a504862802f6478f 100644 (file)
@@ -728,12 +728,15 @@ bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect la
 
 void wxDataViewRendererBase::DestroyEditControl()
 {
+    // Remove our event handler first to prevent it from (recursively) calling
+    // us again as it would do via a call to FinishEditing() when the editor
+    // loses focus when we hide it below.
+    wxEvtHandler * const handler = m_editorCtrl->PopEventHandler();
+
     // Hide the control immediately but don't delete it yet as there could be
     // some pending messages for it.
     m_editorCtrl->Hide();
 
-    wxEvtHandler * const handler = m_editorCtrl->PopEventHandler();
-
     wxPendingDelete.Append(handler);
     wxPendingDelete.Append(m_editorCtrl);
 }
@@ -743,8 +746,6 @@ void wxDataViewRendererBase::CancelEditing()
     if (!m_editorCtrl)
         return;
 
-    GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
-
     DestroyEditControl();
 }
 
index 6201a6c42dc977918f9d6d27661ee5487bd58772..249abb706dc4ae6287a97372ff2ab099e571682f 100644 (file)
@@ -4447,6 +4447,22 @@ IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase)
 
 wxDataViewCtrl::~wxDataViewCtrl()
 {
+    // Stop editing before destroying the control to remove any event handlers
+    // which are added when editing started: if we didn't do this, the base
+    // class dtor would assert as it checks for any leftover handlers.
+    if ( m_treeview )
+    {
+        GtkTreeViewColumn *col;
+        gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview), NULL, &col);
+
+        wxDataViewColumn * const wxcol = FromGTKColumn(col);
+        if ( wxcol )
+        {
+            // This won't do anything if we're not editing it
+            wxcol->GetRenderer()->CancelEditing();
+        }
+    }
+
     m_cols.Clear();
 
     delete m_internal;
@@ -4689,10 +4705,9 @@ unsigned int wxDataViewCtrl::GetColumnCount() const
     return m_cols.GetCount();
 }
 
-wxDataViewColumn* wxDataViewCtrl::GetColumn( unsigned int pos ) const
+wxDataViewColumn* wxDataViewCtrl::FromGTKColumn(GtkTreeViewColumn *gtk_col) const
 {
-    GtkTreeViewColumn *gtk_col = gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview), pos );
-    if (!gtk_col)
+    if ( !gtk_col )
         return NULL;
 
     wxDataViewColumnList::const_iterator iter;
@@ -4705,9 +4720,18 @@ wxDataViewColumn* wxDataViewCtrl::GetColumn( unsigned int pos ) const
         }
     }
 
+    wxFAIL_MSG( "No matching column?" );
+
     return NULL;
 }
 
+wxDataViewColumn* wxDataViewCtrl::GetColumn( unsigned int pos ) const
+{
+    GtkTreeViewColumn *gtk_col = gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview), pos );
+
+    return FromGTKColumn(gtk_col);
+}
+
 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn *column )
 {
     gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview),