+inline void* wxCheckCast(void *ptr)
+{
+ wxASSERT_MSG( ptr, _T("wxStaticCast() used incorrectly") );
+ return ptr;
+}
+#define wxStaticCast(obj, className) \
+ ((className *)wxCheckCast(wxDynamicCast(obj, className)))
+
+#else // !__WXDEBUG__
+#define wxStaticCast(obj, className) \
+ wx_const_cast(className *, wx_static_cast(const className *, obj))
+
+#endif // __WXDEBUG__
+
+// ----------------------------------------------------------------------------
+// set up memory debugging macros
+// ----------------------------------------------------------------------------
+
+/*
+ Which new/delete operator variants do we want?
+
+ _WX_WANT_NEW_SIZET_WXCHAR_INT = void *operator new (size_t size, wxChar *fileName = 0, int lineNum = 0)
+ _WX_WANT_DELETE_VOID = void operator delete (void * buf)
+ _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET = void operator delete (void *buf, const char *_fname, size_t _line)
+ _WX_WANT_DELETE_VOID_WXCHAR_INT = void operator delete(void *buf, wxChar*, int)
+ _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT = void *operator new[] (size_t size, wxChar *fileName , int lineNum = 0)
+ _WX_WANT_ARRAY_DELETE_VOID = void operator delete[] (void *buf)
+ _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT = void operator delete[] (void* buf, wxChar*, int )
+*/
+
+#if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
+
+// All compilers get this one
+#define _WX_WANT_NEW_SIZET_WXCHAR_INT
+
+// Everyone except Visage gets the next one
+#ifndef __VISAGECPP__
+ #define _WX_WANT_DELETE_VOID
+#endif
+
+// Only visage gets this one under the correct circumstances
+#if defined(__VISAGECPP__) && __DEBUG_ALLOC__
+ #define _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET
+#endif
+
+// Only VC++ 6 and CodeWarrior get overloaded delete that matches new
+#if (defined(__VISUALC__) && (__VISUALC__ >= 1200)) || \
+ (defined(__MWERKS__) && (__MWERKS__ >= 0x2400))
+ #define _WX_WANT_DELETE_VOID_WXCHAR_INT
+#endif
+
+// Now see who (if anyone) gets the array memory operators
+#if wxUSE_ARRAY_MEMORY_OPERATORS
+
+ // Everyone except Visual C++ (cause problems for VC++ - crashes)
+ #if !defined(__VISUALC__)
+ #define _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT
+ #endif
+
+ // Everyone except Visual C++ (cause problems for VC++ - crashes)
+ #if !defined(__VISUALC__)
+ #define _WX_WANT_ARRAY_DELETE_VOID
+ #endif
+
+ // Only CodeWarrior 6 or higher
+ #if defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
+ #define _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT
+ #endif
+
+#endif // wxUSE_ARRAY_MEMORY_OPERATORS
+
+#endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING
+
+// ----------------------------------------------------------------------------
+// wxObjectRefData: ref counted data meant to be stored in wxObject
+// ----------------------------------------------------------------------------
+
+class WXDLLIMPEXP_BASE wxObjectRefData
+{
+ friend class WXDLLIMPEXP_FWD_BASE wxObject;
+
+public:
+ wxObjectRefData() : m_count(1) { }
+
+ int GetRefCount() const { return m_count; }
+
+ void IncRef() { m_count++; }
+ void DecRef();
+
+protected:
+ // this object should never be destroyed directly but only as a
+ // result of a DecRef() call:
+ virtual ~wxObjectRefData() { }
+
+private:
+ // our refcount:
+ int m_count;
+};
+
+// ----------------------------------------------------------------------------
+// wxObjectDataPtr: helper class to avoid memleaks because of missing calls
+// to wxObjectRefData::DecRef
+// ----------------------------------------------------------------------------
+
+template <class T>
+class wxObjectDataPtr
+{
+public:
+ typedef T element_type;
+
+ wxEXPLICIT wxObjectDataPtr(T *ptr = NULL) : m_ptr(ptr) {}
+
+ // copy ctor
+ wxObjectDataPtr(const wxObjectDataPtr<T> &tocopy)
+ : m_ptr(tocopy.m_ptr)
+ {
+ if (m_ptr)
+ m_ptr->IncRef();
+ }
+
+ ~wxObjectDataPtr()
+ {
+ if (m_ptr)
+ m_ptr->DecRef();
+ }
+
+ T *get() const { return m_ptr; }
+ T *operator->() const { return get(); }
+
+ void reset(T *ptr)