From 50dcf06bff60e8ef6733bfbb45e33fa6d8d3f767 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 6 May 2023 20:01:31 +0100 Subject: [PATCH] Revert to using wxBaseObjectArray for wxAuiToolBarItemArray This partially undoes the changes of bc23b1f4f0 (Use wxBaseArray instead of object array for wxAuiToolBarItemArray, 2023-04-11) as they broke the existing code using wxAuiToolBar because the pointers to the tools were not stable any more. At least avoid the use of the ugly -WX_DECLARE_USER_EXPORTED_OBJARRAY() macro by just using wxBaseObjectArray<> directly, which is simpler now, after the change in the parent commit. Add a trivial test checking that pointers to wxAuiToolBar tools remain stable when more tools are added. Closes #23514. --- include/wx/aui/auibar.h | 2 +- tests/controls/auitest.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/wx/aui/auibar.h b/include/wx/aui/auibar.h index 08485ac771..3515fa3bd5 100644 --- a/include/wx/aui/auibar.h +++ b/include/wx/aui/auibar.h @@ -254,7 +254,7 @@ private: int m_alignment; // sizer alignment flag, defaults to wxCENTER, may be wxEXPAND or any other }; -using wxAuiToolBarItemArray = wxBaseArray; +using wxAuiToolBarItemArray = wxBaseObjectArray; diff --git a/tests/controls/auitest.cpp b/tests/controls/auitest.cpp index 81649a39f4..74c75f6825 100644 --- a/tests/controls/auitest.cpp +++ b/tests/controls/auitest.cpp @@ -21,10 +21,13 @@ #include "wx/panel.h" +#include "wx/aui/auibar.h" #include "wx/aui/auibook.h" #include "asserthelper.h" +#include + // ---------------------------------------------------------------------------- // test fixtures // ---------------------------------------------------------------------------- @@ -165,4 +168,15 @@ TEST_CASE_METHOD(AuiNotebookTestCase, "wxAuiNotebook::FindPage", "[aui]") CHECK( nb->FindPage(p3) == wxNOT_FOUND ); } +TEST_CASE("wxAuiToolBar::Items", "[aui][toolbar]") +{ + std::unique_ptr tbar{new wxAuiToolBar(wxTheApp->GetTopWindow())}; + + // Check that adding more toolbar elements doesn't invalidate the existing + // pointers. + auto first = tbar->AddLabel(wxID_ANY, "first"); + tbar->AddLabel(wxID_ANY, "second"); + CHECK( first->GetLabel() == "first" ); +} + #endif