From 2578ffb54a8daa5a54277d0872e6837e8c829d49 Mon Sep 17 00:00:00 2001 From: ali kettab Date: Thu, 8 Dec 2022 10:21:10 +0100 Subject: [PATCH] Assert if wxListCtrl::EditLabel() is used without wxLC_EDIT_LABELS Since wxListCtrl under wxMSW cannot edit labels without the presence of this flag, and an assertion failure triggered if the flag is missing to it and also all the other ports for consistency. Also document that wxLC_EDIT_LABELS flag is required in EditLabel() description. See #23024. --- docs/changes.txt | 3 +++ interface/wx/listctrl.h | 3 +++ src/generic/listctrl.cpp | 6 ++++++ src/msw/listctrl.cpp | 5 +++++ src/qt/listctrl.cpp | 6 ++++++ 5 files changed, 23 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index 75248e641f..8da9cacdf2 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -56,6 +56,9 @@ Changes in behaviour not resulting in compilation errors used instead, but if you do use it, you need to update your code to prevent the last character of the data from being chopped. +- Calling wxListCtrl::EditLabel() now asserts if the control doesn't have + wxLC_EDIT_LABELS style: previously this silently didn't work in wxMSW. + Changes in behaviour which may result in build errors ----------------------------------------------------- diff --git a/interface/wx/listctrl.h b/interface/wx/listctrl.h index f1a9757291..730b9ce3bc 100644 --- a/interface/wx/listctrl.h +++ b/interface/wx/listctrl.h @@ -453,6 +453,9 @@ public: If the user changed the label (i.e. s/he does not press ESC or leave the text control without changes, a @c EVT_LIST_END_LABEL_EDIT event will be sent which can be vetoed as well. + + Notice that this function should only be called if wxLC_EDIT_LABELS flag + is already set on the control. an assertion failure is triggered otherwise. */ wxTextCtrl* EditLabel(long item, wxClassInfo* textControlClass = wxCLASSINFO(wxTextCtrl)); diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 92dcd8a16d..62a2a33df6 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -2385,6 +2385,12 @@ void wxListMainWindow::ChangeCurrent(size_t current) wxTextCtrl *wxListMainWindow::EditLabel(long item, wxClassInfo* textControlClass) { + // Calling this function for control without wxLC_EDIT_LABELS flag set + // is not portable. i.e. on wxMSW this function cannot edit labels if + // the flag is not already set on the control. + wxASSERT_MSG( HasFlag(wxLC_EDIT_LABELS), + "should only be called if wxLC_EDIT_LABELS flag is set"); + wxCHECK_MSG( (item >= 0) && ((size_t)item < GetItemCount()), nullptr, wxT("wrong index in wxGenericListCtrl::EditLabel()") ); diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index a466d52c90..c110506a69 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -1753,6 +1753,11 @@ void wxListCtrl::InitEditControl(WXHWND hWnd) wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass) { + // This function will fail to edit labels if the wxLC_EDIT_LABELS flag + // is not already set on the control. + wxASSERT_MSG( HasFlag(wxLC_EDIT_LABELS), + "should only be called if wxLC_EDIT_LABELS flag is set"); + wxCHECK_MSG( textControlClass->IsKindOf(wxCLASSINFO(wxTextCtrl)), nullptr, "control used for label editing must be a wxTextCtrl" ); diff --git a/src/qt/listctrl.cpp b/src/qt/listctrl.cpp index 4ebc6d494f..12cc8056fb 100644 --- a/src/qt/listctrl.cpp +++ b/src/qt/listctrl.cpp @@ -1622,6 +1622,12 @@ void wxListCtrl::ClearAll() wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* WXUNUSED(textControlClass)) { + // Calling this function for control without wxLC_EDIT_LABELS flag set + // is not portable. i.e. on wxMSW this function cannot edit labels if + // the flag is not already set on the control. + wxASSERT_MSG( HasFlag(wxLC_EDIT_LABELS), + "should only be called if wxLC_EDIT_LABELS flag is set"); + // Open the editor first so that it's available when handling events as per // wx standard. const QModelIndex index = m_model->index(item, 0);