Fix wxTextCtrl creation in wxGenericListCtrl::EditLabel()

Ensure the edit control is created before sending wxEVT_LIST_BEGIN_LABEL_EDIT
event, as calling wxListCtrl::GetEditControl() from inside the handler should
always return a valid pointer

Closes #23024.
This commit is contained in:
ali kettab 2022-12-07 12:47:08 +01:00 committed by Vadim Zeitlin
parent 50a9c8cbe8
commit f802b869fa

View file

@ -2401,8 +2401,14 @@ wxTextCtrl *wxListMainWindow::EditLabel(long item, wxClassInfo* textControlClass
wxCHECK_MSG( data, nullptr, wxT("invalid index in EditLabel()") );
data->GetItem( 0, le.m_item );
// See comment in EditLabel() (src/msw/listctrl.cpp) for why we create the
// text control before sending the wxEVT_LIST_BEGIN_LABEL_EDIT event.
wxTextCtrl * const text = (wxTextCtrl *)textControlClass->CreateObject();
m_textctrlWrapper = new wxListTextCtrlWrapper(this, text, item);
if ( GetParent()->GetEventHandler()->ProcessEvent( le ) && !le.IsAllowed() )
{
m_textctrlWrapper->EndEdit(wxListTextCtrlWrapper::End_Destroy);
// vetoed by user code
return nullptr;
}
@ -2413,8 +2419,6 @@ wxTextCtrl *wxListMainWindow::EditLabel(long item, wxClassInfo* textControlClass
Update();
}
wxTextCtrl * const text = (wxTextCtrl *)textControlClass->CreateObject();
m_textctrlWrapper = new wxListTextCtrlWrapper(this, text, item);
return m_textctrlWrapper->GetText();
}