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.
This commit is contained in:
@@ -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 T>
|
||||
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
|
||||
{
|
||||
|
@@ -1393,7 +1393,7 @@ bool wxWindowBase::Reparent(wxWindowBase *newParent)
|
||||
}
|
||||
else
|
||||
{
|
||||
wxTopLevelWindows.Append(this);
|
||||
wxTopLevelWindows.Append(static_cast<wxWindow*>(this));
|
||||
}
|
||||
|
||||
// We need to notify window (and its subwindows) if by changing the parent
|
||||
|
Reference in New Issue
Block a user