From bceace12b5d236ca6badb66e559133bc4419440d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 11 Apr 2023 16:29:00 +0200 Subject: [PATCH] Use wxBaseArray instead of object arrays for wxAuiNotebook arrays These classes can also be potentially used in the user code, as they are used for the protected members of wxAuiTabContainer, so don't replace them with just std::vector, but do, at least, use wxBaseArray template for them instead of the macro-based object arrays. Note that this required the check for the button presence in m_buttons in wxAuiTabContainer::TabHitTest() as wxBaseArray::Index() relies on object comparison, whereas the original version relied on object address comparison, so keep it like this, even though we probably could compare the buttons IDs instead (and, possibly, not compare anything at all but just return the result of the button we found from ButtonHitTest() directly). Also document these container classes. --- include/wx/aui/auibook.h | 17 +++++++++++++---- interface/wx/aui/auibook.h | 23 +++++++++++++++++++++++ src/aui/auibook.cpp | 11 +++++------ 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/include/wx/aui/auibook.h b/include/wx/aui/auibook.h index 02af6173ee..171a22380e 100644 --- a/include/wx/aui/auibook.h +++ b/include/wx/aui/auibook.h @@ -109,10 +109,19 @@ public: }; -#ifndef SWIG -WX_DECLARE_USER_EXPORTED_OBJARRAY(wxAuiNotebookPage, wxAuiNotebookPageArray, WXDLLIMPEXP_AUI); -WX_DECLARE_USER_EXPORTED_OBJARRAY(wxAuiTabContainerButton, wxAuiTabContainerButtonArray, WXDLLIMPEXP_AUI); -#endif +// These legacy classes can't be just typedefs as they can be (and are) +// forward-declared in the existing code. +class wxAuiNotebookPageArray : public wxBaseArray +{ +public: + using wxBaseArray::wxBaseArray; +}; + +class wxAuiTabContainerButtonArray : public wxBaseArray +{ +public: + using wxBaseArray::wxBaseArray; +}; class WXDLLIMPEXP_AUI wxAuiTabContainer diff --git a/interface/wx/aui/auibook.h b/interface/wx/aui/auibook.h index d308c887f5..c8d6510f78 100644 --- a/interface/wx/aui/auibook.h +++ b/interface/wx/aui/auibook.h @@ -453,6 +453,17 @@ public: bool active; // true if the page is currently active }; +/** + A vector of AUI notebook pages. + + This class is actually a legacy container (see @ref overview_container for + more details), but it can, and should be, handled as just a vector of + wxAuiNotebookPage objects in the application code. +*/ +class wxAuiNotebookPageArray : public std::vector +{ +}; + /** @class wxAuiTabContainerButton @@ -480,6 +491,18 @@ public: }; +/** + A vector of AUI tab buttons. + + This class is actually a legacy container (see @ref overview_container for + more details), but it can, and should be, handled as just a vector of + wxAuiTabContainerButton objects in the application code. +*/ +class wxAuiTabContainerButtonArray : public std::vector +{ +}; + + /** @class wxAuiTabContainer diff --git a/src/aui/auibook.cpp b/src/aui/auibook.cpp index f355542892..d10384b71b 100644 --- a/src/aui/auibook.cpp +++ b/src/aui/auibook.cpp @@ -34,10 +34,6 @@ #include "wx/osx/private.h" #endif -#include "wx/arrimpl.cpp" -WX_DEFINE_OBJARRAY(wxAuiNotebookPageArray) -WX_DEFINE_OBJARRAY(wxAuiTabContainerButtonArray) - wxDEFINE_EVENT(wxEVT_AUINOTEBOOK_PAGE_CLOSE, wxAuiNotebookEvent); wxDEFINE_EVENT(wxEVT_AUINOTEBOOK_PAGE_CLOSED, wxAuiNotebookEvent); wxDEFINE_EVENT(wxEVT_AUINOTEBOOK_PAGE_CHANGING, wxAuiNotebookEvent); @@ -866,8 +862,11 @@ bool wxAuiTabContainer::TabHitTest(int x, int y, wxWindow** hit) const wxAuiTabContainerButton* btn = nullptr; if (ButtonHitTest(x, y, &btn) && !(btn->curState & wxAUI_BUTTON_STATE_DISABLED)) { - if (m_buttons.Index(*btn) != wxNOT_FOUND) - return false; + for ( const auto& button : m_buttons ) + { + if ( btn == &button ) + return false; + } } size_t i, page_count = m_pages.GetCount();