+#if wxUSE_STL
+
+#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_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) \
+
+#define WX_DECLARE_LIST_WITH_DECL(elT, liT, decl) \
+ WX_DECLARE_LIST_XO(elT*, liT, decl)
+
+#if !defined(__VISUALC__) || __VISUALC__ >= 1300 // == !VC6
+
+template<class T>
+class WXDLLIMPEXP_BASE wxList_SortFunction
+{
+public:
+ wxList_SortFunction(wxSortCompareFunction f) : m_f(f) { }
+ bool operator()(const T& i1, const T& i2)
+ { return m_f((T*)&i1, (T*)&i2) < 0; }
+private:
+ wxSortCompareFunction m_f;
+};
+
+#define WX_LIST_SORTFUNCTION( elT, f ) wxList_SortFunction<elT>(f)
+#define VC6_WORKAROUND(elT, liT, decl)
+
+#else // if defined( __VISUALC__ ) && __VISUALC__ < 1300 // == VC6
+
+#define WX_LIST_SORTFUNCTION( elT, f ) std::greater<elT>( f )
+#define VC6_WORKAROUND(elT, liT, decl) \
+ decl liT; \
+ \
+ /* Workaround for broken VC6 STL incorrectly requires a std::greater<> */ \
+ /* to be passed into std::list::sort() */ \
+ template <> \
+ struct std::greater<elT> \
+ { \
+ private: \
+ wxSortCompareFunction m_CompFunc; \
+ public: \
+ greater( wxSortCompareFunction compfunc = NULL ) \
+ : m_CompFunc( compfunc ) {} \
+ bool operator()(const elT X, const elT Y) const \
+ { \
+ return m_CompFunc ? \
+ ( m_CompFunc( wxListCastElementToVoidPtr(X), \
+ wxListCastElementToVoidPtr(Y) ) < 0 ) : \
+ ( X > Y ); \
+ } \
+ };
+
+// helper for std::greater<elT> above:
+template<typename T>
+inline const void *wxListCastElementToVoidPtr(const T* ptr) { return ptr; }
+inline const void *wxListCastElementToVoidPtr(const wxString& str)
+ { return (const char*)str; }
+
+#endif // VC6/!VC6
+
+/*
+ Note 1: the outer helper class _WX_LIST_HELPER_##liT below is a workaround
+ for mingw 3.2.3 compiler bug that prevents a static function of liT class
+ from being exported into dll. A minimal code snippet reproducing the bug:
+
+ struct WXDLLEXPORT Foo
+ {
+ static void Bar();
+ struct SomeInnerClass
+ {
+ friend class Foo; // comment this out to make it link
+ };
+ ~Foo()
+ {
+ Bar();
+ }
+ };
+
+ The program does not link under mingw_gcc 3.2.3 producing undefined
+ reference to Foo::Bar() function
+
+
+ Note 2: the EmptyList is needed to allow having a NULL pointer-like
+ invalid iterator. We used to use just an uninitialized iterator object
+ instead but this fails with some debug/checked versions of STL, notably the
+ glibc version activated with _GLIBCXX_DEBUG, so we need to have a separate
+ invalid iterator.
+ */
+
+// the real wxList-class declaration
+#define WX_DECLARE_LIST_XO(elT, liT, decl) \
+ decl _WX_LIST_HELPER_##liT \
+ { \
+ typedef elT _WX_LIST_ITEM_TYPE_##liT; \
+ public: \
+ static void DeleteFunction( _WX_LIST_ITEM_TYPE_##liT X ); \
+ }; \
+ \
+ VC6_WORKAROUND(elT, liT, decl) \
+ decl liT : public std::list<elT> \
+ { \
+ private: \
+ typedef std::list<elT> BaseListType; \
+ static BaseListType EmptyList; \
+ \
+ bool m_destroy; \
+ \
+ public: \
+ decl compatibility_iterator \
+ { \
+ private: \
+ /* Workaround for broken VC6 nested class name resolution */ \
+ typedef std::list<elT>::iterator iterator; \
+ friend class liT; \
+ \
+ iterator m_iter; \
+ liT * m_list; \
+ \
+ public: \
+ compatibility_iterator() \
+ : m_iter(EmptyList.end()), m_list( NULL ) {} \
+ compatibility_iterator( liT* li, iterator i ) \
+ : m_iter( i ), m_list( li ) {} \
+ compatibility_iterator( const liT* li, iterator i ) \
+ : m_iter( i ), m_list( const_cast< liT* >( li ) ) {} \
+ \
+ compatibility_iterator* operator->() { return this; } \
+ const compatibility_iterator* operator->() const { return this; } \
+ \
+ bool operator==(const compatibility_iterator& i) const \
+ { \
+ wxASSERT_MSG( m_list && i.m_list, \
+ _T("comparing invalid iterators is illegal") ); \
+ return (m_list == i.m_list) && (m_iter == i.m_iter); \
+ } \
+ bool operator!=(const compatibility_iterator& i) const \
+ { return !( operator==( i ) ); } \
+ operator bool() const \
+ { return m_list ? m_iter != m_list->end() : false; } \
+ bool operator !() const \
+ { return !( operator bool() ); } \
+ \
+ elT GetData() const \
+ { return *m_iter; } \
+ void SetData( elT e ) \
+ { *m_iter = e; } \
+ \
+ compatibility_iterator GetNext() const \
+ { \
+ iterator i = m_iter; \
+ return compatibility_iterator( m_list, ++i ); \
+ } \
+ compatibility_iterator GetPrevious() const \
+ { \
+ if ( m_iter == m_list->begin() ) \
+ return compatibility_iterator(); \
+ \
+ iterator i = m_iter; \
+ return compatibility_iterator( m_list, --i ); \
+ } \
+ int IndexOf() const \
+ { \
+ return *this ? std::distance( m_list->begin(), m_iter ) \
+ : wxNOT_FOUND; \
+ } \
+ }; \
+ public: \
+ liT() : m_destroy( false ) {} \
+ \
+ compatibility_iterator Find( const elT e ) const \
+ { \
+ liT* _this = const_cast< liT* >( this ); \
+ return compatibility_iterator( _this, \
+ std::find( _this->begin(), _this->end(), e ) ); \
+ } \
+ \
+ bool IsEmpty() const \
+ { return empty(); } \
+ size_t GetCount() const \
+ { return size(); } \
+ int Number() const \
+ { return static_cast< int >( GetCount() ); } \
+ \
+ compatibility_iterator Item( size_t idx ) const \
+ { \
+ iterator i = const_cast< liT* >(this)->begin(); \
+ std::advance( i, idx ); \
+ return compatibility_iterator( this, i ); \
+ } \
+ elT operator[](size_t idx) const \
+ { \
+ return Item(idx).GetData(); \
+ } \
+ \
+ compatibility_iterator GetFirst() const \
+ { \
+ return compatibility_iterator( this, \
+ const_cast< liT* >(this)->begin() ); \
+ } \
+ compatibility_iterator GetLast() const \
+ { \
+ iterator i = const_cast< liT* >(this)->end(); \
+ return compatibility_iterator( this, !empty() ? --i : i ); \
+ } \
+ compatibility_iterator Member( elT e ) const \
+ { return Find( e ); } \
+ compatibility_iterator Nth( int n ) const \
+ { return Item( n ); } \
+ int IndexOf( elT e ) const \
+ { return Find( e ).IndexOf(); } \
+ \
+ compatibility_iterator Append( elT e ) \
+ { \
+ push_back( e ); \
+ return GetLast(); \
+ } \
+ compatibility_iterator Insert( elT e ) \
+ { \
+ push_front( e ); \
+ return compatibility_iterator( this, begin() ); \
+ } \
+ compatibility_iterator Insert( compatibility_iterator & i, elT e ) \
+ { \
+ return compatibility_iterator( this, insert( i.m_iter, e ) ); \
+ } \
+ compatibility_iterator Insert( size_t idx, elT e ) \
+ { \
+ return compatibility_iterator( this, \
+ insert( Item( idx ).m_iter, e ) ); \
+ } \
+ \
+ void DeleteContents( bool destroy ) \
+ { m_destroy = destroy; } \
+ bool GetDeleteContents() const \
+ { return m_destroy; } \
+ void Erase( const compatibility_iterator& i ) \
+ { \
+ if ( m_destroy ) \
+ _WX_LIST_HELPER_##liT::DeleteFunction( i->GetData() ); \
+ erase( i.m_iter ); \
+ } \
+ bool DeleteNode( const compatibility_iterator& i ) \
+ { \
+ if( i ) \
+ { \
+ Erase( i ); \
+ return true; \
+ } \
+ return false; \
+ } \
+ bool DeleteObject( elT e ) \
+ { \
+ return DeleteNode( Find( e ) ); \
+ } \
+ void Clear() \
+ { \
+ if ( m_destroy ) \
+ std::for_each( begin(), end(), \
+ _WX_LIST_HELPER_##liT::DeleteFunction ); \
+ clear(); \
+ } \
+ /* Workaround for broken VC6 std::list::sort() see above */ \
+ void Sort( wxSortCompareFunction compfunc ) \
+ { sort( WX_LIST_SORTFUNCTION( elT, compfunc ) ); } \
+ ~liT() { Clear(); } \
+ \
+ /* It needs access to our EmptyList */ \
+ friend decl compatibility_iterator; \
+ }
+
+#define WX_DECLARE_LIST(elementtype, listname) \
+ WX_DECLARE_LIST_WITH_DECL(elementtype, listname, class)
+#define WX_DECLARE_LIST_PTR(elementtype, listname) \
+ WX_DECLARE_LIST(elementtype, listname)
+
+#define WX_DECLARE_EXPORTED_LIST(elementtype, listname) \
+ WX_DECLARE_LIST_WITH_DECL(elementtype, listname, class WXDLLEXPORT)
+#define WX_DECLARE_EXPORTED_LIST_PTR(elementtype, listname) \
+ WX_DECLARE_EXPORTED_LIST(elementtype, listname)
+
+#define WX_DECLARE_USER_EXPORTED_LIST(elementtype, listname, usergoo) \
+ WX_DECLARE_LIST_WITH_DECL(elementtype, listname, class usergoo)
+#define WX_DECLARE_USER_EXPORTED_LIST_PTR(elementtype, listname, usergoo) \
+ WX_DECLARE_USER_EXPORTED_LIST(elementtype, listname, usergoo)
+
+// this macro must be inserted in your program after
+// #include "wx/listimpl.cpp"
+#define WX_DEFINE_LIST(name) "don't forget to include listimpl.cpp!"
+
+#define WX_DEFINE_EXPORTED_LIST(name) WX_DEFINE_LIST(name)
+#define WX_DEFINE_USER_EXPORTED_LIST(name) WX_DEFINE_LIST(name)
+
+#else // if !wxUSE_STL
+
+
+// undef it to get rid of old, deprecated functions
+#define wxLIST_COMPATIBILITY
+