From 303d899cc031c6abb7a6267cda087184526ed465 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 2 Sep 2021 00:52:50 +0200 Subject: [PATCH] Make STL-based wxList more compatible with the default one This is done to fix the build error in STL builds after the previous commit, as using Find() or DeleteObject() with a pointer of the "base type" worked when using wxWindowList in the default build, but not in the STL build, so this commit avoids this mismatch by allowing to use a base class pointer where it is safe to do so, i.e. where it can be done without a downcast, as there doesn't seem to be any reason to have this difference between the builds in this case. Note that there is still a difference between Append() and Insert() methods which (correctly) require the pointer of right type in STL build but still accept a pointer of the base type in the default build for compatibility reasons. In particular, this means that one of the casts removed in the last commit from wxWindowBase code needs to be restored, as Append() still requires a wxWindow and not just a wxWindowBase. --- include/wx/list.h | 27 ++++++++++++++------------- src/common/wincmn.cpp | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/wx/list.h b/include/wx/list.h index 866e2fb2bc..802e7d162a 100644 --- a/include/wx/list.h +++ b/include/wx/list.h @@ -52,18 +52,19 @@ typedef wxObjectListNode wxNode; #define wxLIST_COMPATIBILITY -#define WX_DECLARE_LIST_3(elT, dummy1, liT, dummy2, decl) \ - WX_DECLARE_LIST_WITH_DECL(elT, liT, decl) -#define WX_DECLARE_LIST_PTR_3(elT, dummy1, liT, dummy2, decl) \ - WX_DECLARE_LIST_3(elT, dummy1, liT, dummy2, decl) +#define WX_DECLARE_LIST_WITH_DECL(elT, liT, decl) \ + WX_DECLARE_LIST_3(elT, elT, liT, dummy, decl) + +#define WX_DECLARE_LIST_PTR_3(elT, baseT, liT, dummy, decl) \ + WX_DECLARE_LIST_3(elT, baseT, liT, dummy, decl) #define WX_DECLARE_LIST_2(elT, liT, dummy, decl) \ WX_DECLARE_LIST_WITH_DECL(elT, liT, decl) #define WX_DECLARE_LIST_PTR_2(elT, liT, dummy, decl) \ - WX_DECLARE_LIST_2(elT, liT, dummy, decl) \ + WX_DECLARE_LIST_2(elT, liT, dummy, decl) -#define WX_DECLARE_LIST_WITH_DECL(elT, liT, decl) \ - WX_DECLARE_LIST_XO(elT*, liT, decl) +#define WX_DECLARE_LIST_3(elT, baseT, liT, dummy, decl) \ + WX_DECLARE_LIST_XO(elT*, baseT*, liT, decl) template class wxList_SortFunction @@ -106,7 +107,7 @@ private: */ // the real wxList-class declaration -#define WX_DECLARE_LIST_XO(elT, liT, decl) \ +#define WX_DECLARE_LIST_XO(elT, baseT, liT, decl) \ decl _WX_LIST_HELPER_##liT \ { \ typedef elT _WX_LIST_ITEM_TYPE_##liT; \ @@ -183,7 +184,7 @@ private: public: \ liT() : m_destroy( false ) {} \ \ - compatibility_iterator Find( const elT e ) const \ + compatibility_iterator Find( const baseT e ) const \ { \ liT* _this = const_cast< liT* >( this ); \ return compatibility_iterator( _this, \ @@ -218,11 +219,11 @@ private: iterator i = const_cast< liT* >(this)->end(); \ return compatibility_iterator( this, !empty() ? --i : i ); \ } \ - bool Member( elT e ) const \ + bool Member( baseT e ) const \ { return Find( e ); } \ compatibility_iterator Nth( int n ) const \ { return Item( n ); } \ - int IndexOf( elT e ) const \ + int IndexOf( baseT e ) const \ { return Find( e ).IndexOf(); } \ \ compatibility_iterator Append( elT e ) \ @@ -264,7 +265,7 @@ private: } \ return false; \ } \ - bool DeleteObject( elT e ) \ + bool DeleteObject( baseT e ) \ { \ return DeleteNode( Find( e ) ); \ } \ @@ -1258,7 +1259,7 @@ private: #else // if wxUSE_STD_CONTAINERS -WX_DECLARE_LIST_XO(wxString, wxStringListBase, class WXDLLIMPEXP_BASE); +WX_DECLARE_LIST_XO(wxString, wxString, wxStringListBase, class WXDLLIMPEXP_BASE); class WXDLLIMPEXP_BASE wxStringList : public wxStringListBase { diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index a0a775ed0b..42621feea4 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -1393,7 +1393,7 @@ bool wxWindowBase::Reparent(wxWindowBase *newParent) } else { - wxTopLevelWindows.Append(this); + wxTopLevelWindows.Append(static_cast(this)); } // We need to notify window (and its subwindows) if by changing the parent