From 6bc4a1e1de62ec1bcebdb641799fe1ca077f87b3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 12 Jul 2025 04:12:59 +0200 Subject: [PATCH] Fix losing text of generic wxListCtrl items when copying them During the switch from copy to move ctor of wxListCtrl in a5777cdcbd (Make wxListItemData movable and not copyable, 2023-01-19) copying the item text was simply lost, resulting in items forgetting their text when they were moved internally by the vector in which they are stored, which could result in e.g. their text becoming empty when a new column was appended. Fix this by adding the missing text (and also image and user data) field to the move ctor and move assignment operator. Closes #25519. --- src/generic/listctrl.cpp | 7 +++++-- tests/controls/listviewtest.cpp | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 8142a35518..68a3ff3de1 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -96,9 +96,11 @@ static const int MARGIN_AROUND_CHECKBOX = 5; // ---------------------------------------------------------------------------- wxListItemData::wxListItemData(wxListItemData&& other) + : m_image(other.m_image), + m_data(other.m_data), + m_owner(other.m_owner), + m_text(std::move(other.m_text)) { - m_owner = other.m_owner; - // Take ownership of the pointers from the other object and reset them. std::swap(m_attr, other.m_attr); std::swap(m_rect, other.m_rect); @@ -109,6 +111,7 @@ wxListItemData& wxListItemData::operator=(wxListItemData&& other) m_image = other.m_image; m_data = other.m_data; m_owner = other.m_owner; + m_text = std::move(other.m_text); // Swap them to let our pointers be deleted by the other object if necessary. std::swap(m_attr, other.m_attr); diff --git a/tests/controls/listviewtest.cpp b/tests/controls/listviewtest.cpp index 636903c4b3..1c2cec91ad 100644 --- a/tests/controls/listviewtest.cpp +++ b/tests/controls/listviewtest.cpp @@ -105,4 +105,19 @@ TEST_CASE_METHOD(ListViewTestCase, "ListView::Focus", "[listctrl][listview]") CHECK( m_list->GetFocusedItem() == 0 ); } +TEST_CASE_METHOD(ListViewTestCase, "ListView::AppendColumn", "[listctrl][listview]") +{ + m_list->AppendColumn("Column 0"); + m_list->AppendColumn("Column 1"); + + m_list->InsertItem(0, "First item"); + m_list->SetItem(0, 1, "First subitem"); + + // Appending a column shouldn't change the existing items. + m_list->AppendColumn("Column 2"); + + CHECK( m_list->GetItemText(0) == "First item" ); + CHECK( m_list->GetItemText(0, 1) == "First subitem" ); +} + #endif