]> git.saurik.com Git - wxWidgets.git/commitdiff
Pop event handler from wxDVC edit control before destroying it.
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 5 May 2010 12:45:09 +0000 (12:45 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 5 May 2010 12:45:09 +0000 (12:45 +0000)
This fixes the assert in wxWindow dtor checking that all event handlers pushed
on the window were removed.

Also fix a memory leak by not creating an unnecessary object of wxKillRef
class. In fact remove this class entirely.

Closes #11732.

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

include/wx/dvrenderers.h
src/common/datavcmn.cpp

index 34939a685ea9fa6aa8a546a5a52d4bfb7041b7ac..c05c109522b8db5ecff17c06ab6394021e575248 100644 (file)
@@ -154,6 +154,9 @@ public:
     wxControl *GetEditorCtrl() { return m_editorCtrl; }
 
 protected:
+    // Called from {Cancel,Finish}Editing() to cleanup m_editorCtrl
+    void DestroyEditControl();
+
     wxString                m_variantType;
     wxDataViewColumn       *m_owner;
     wxWeakRef<wxControl>    m_editorCtrl;
index de0608121e47d0e4915eba3d293c719908712171..beccdb2b512417f08357887d92f6f01b672f9784 100644 (file)
@@ -589,18 +589,6 @@ const wxDataViewCtrl* wxDataViewRendererBase::GetView() const
     return const_cast<wxDataViewRendererBase*>(this)->GetOwner()->GetOwner();
 }
 
-class wxKillRef: public wxWindowRef
-{
-public:
-   wxKillRef( wxWindow *win ) : wxWindowRef( win ) { }
-   virtual void OnObjectDestroy()
-   {
-      get()->PopEventHandler( true );
-      m_pobj = NULL;
-      delete this;
-   }
-};
-
 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect )
 {
     wxDataViewCtrl* dv_ctrl = GetOwner()->GetOwner();
@@ -627,8 +615,6 @@ bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect la
     if(!m_editorCtrl)
         return false;
 
-    (void) new wxKillRef( m_editorCtrl.get() );
-
     wxDataViewEditorCtrlEvtHandler *handler =
         new wxDataViewEditorCtrlEvtHandler( m_editorCtrl, (wxDataViewRenderer*) this );
 
@@ -651,6 +637,18 @@ bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect la
     return true;
 }
 
+void wxDataViewRendererBase::DestroyEditControl()
+{
+    // 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);
+}
+
 void wxDataViewRendererBase::CancelEditing()
 {
     if (!m_editorCtrl)
@@ -658,8 +656,7 @@ void wxDataViewRendererBase::CancelEditing()
 
     GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
 
-    m_editorCtrl->Hide();
-    wxPendingDelete.Append( m_editorCtrl );
+    DestroyEditControl();
 }
 
 bool wxDataViewRendererBase::FinishEditing()
@@ -674,8 +671,7 @@ bool wxDataViewRendererBase::FinishEditing()
 
     dv_ctrl->GetMainWindow()->SetFocus();
 
-    m_editorCtrl->Hide();
-    wxPendingDelete.Append( m_editorCtrl );
+    DestroyEditControl();
 
     if (!Validate(value))
         return false;