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.
This commit is contained in:
ali kettab 2022-12-08 10:21:10 +01:00 committed by Vadim Zeitlin
parent f802b869fa
commit 2578ffb54a
5 changed files with 23 additions and 0 deletions

View file

@ -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
-----------------------------------------------------

View file

@ -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));

View file

@ -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()") );

View file

@ -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" );

View file

@ -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);