From 4e790786bbf7ca3804293c959afba0d3fe839668 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 17 Nov 2002 13:08:24 +0000 Subject: [PATCH] reset m_textCtrl after finishing editing a label (part of patch 639394) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17885 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/listctrl.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index d7ceb9433d..4b6191aa84 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -1280,16 +1280,23 @@ wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass) // ListView_EditLabel requires that the list has focus. SetFocus(); - WXHWND hWnd = (WXHWND) ListView_EditLabel(GetHwnd(), item); - if (m_textCtrl) + WXHWND hWnd = (WXHWND) ListView_EditLabel(GetHwnd(), item); + if ( !hWnd ) + { + // failed to start editing + return NULL; + } + + // [re]create the text control wrapping the HWND we got + if ( m_textCtrl ) { m_textCtrl->SetHWND(0); m_textCtrl->UnsubclassWin(); delete m_textCtrl; } - m_textCtrl = (wxTextCtrl*) textControlClass->CreateObject(); + m_textCtrl = (wxTextCtrl *)textControlClass->CreateObject(); m_textCtrl->SetHWND(hWnd); m_textCtrl->SubclassWin(hWnd); m_textCtrl->SetParent(this); @@ -2124,6 +2131,17 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) // logic here is inversed compared to all the other messages *result = event.IsAllowed(); + // don't keep a stale wxTextCtrl around + if ( m_textCtrl ) + { + // EDIT control will be deleted by the list control itself so + // prevent us from deleting it as well + m_textCtrl->SetHWND(0); + m_textCtrl->UnsubclassWin(); + delete m_textCtrl; + m_textCtrl = NULL; + } + return TRUE; }