]> git.saurik.com Git - wxWidgets.git/blame - include/wx/object.h
changed wxArrayString::m_pItems from wxChar* to const wxChar*, the strings are not...
[wxWidgets.git] / include / wx / object.h
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
b2edef6f 2// Name: wx/object.h
c801d85f
KB
3// Purpose: wxObject class, plus run-time type information macros
4// Author: Julian Smart
0b9ab0bd 5// Modified by: Ron Lee
c801d85f
KB
6// Created: 01/02/97
7// RCS-ID: $Id$
371a5b4e 8// Copyright: (c) 1997 Julian Smart
0b9ab0bd 9// (c) 2001 Ron Lee <ron@debian.org>
65571936 10// Licence: wxWindows licence
c801d85f
KB
11/////////////////////////////////////////////////////////////////////////////
12
34138703
JS
13#ifndef _WX_OBJECTH__
14#define _WX_OBJECTH__
c801d85f 15
0b9ab0bd
RL
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
e55ad60e 20#include "wx/memory.h"
c801d85f 21
bddd7a8d 22class WXDLLIMPEXP_BASE wxObject;
c801d85f 23
4393b50c 24#ifndef wxUSE_EXTENDED_RTTI
6d553b5f 25#define wxUSE_EXTENDED_RTTI 0
a095505c
SC
26#endif
27
6d553b5f 28#if wxUSE_EXTENDED_RTTI
a095505c 29#include "wx/xti.h"
a095505c
SC
30#else
31
0b9ab0bd
RL
32// ----------------------------------------------------------------------------
33// conditional compilation
34// ----------------------------------------------------------------------------
35
bddd7a8d
VZ
36class WXDLLIMPEXP_BASE wxClassInfo;
37class WXDLLIMPEXP_BASE wxHashTable;
38class WXDLLIMPEXP_BASE wxObjectRefData;
c801d85f 39
0b9ab0bd
RL
40// ----------------------------------------------------------------------------
41// wxClassInfo
42// ----------------------------------------------------------------------------
43
44typedef wxObject *(*wxObjectConstructorFn)(void);
c801d85f 45
bddd7a8d 46class WXDLLIMPEXP_BASE wxClassInfo
c801d85f 47{
aac65598 48public:
38befbee 49 wxClassInfo( const wxChar *className,
d1d738f1
VS
50 const wxClassInfo *baseInfo1,
51 const wxClassInfo *baseInfo2,
38befbee
RL
52 int size,
53 wxObjectConstructorFn ctor )
0b9ab0bd 54 : m_className(className)
0b9ab0bd
RL
55 , m_objectSize(size)
56 , m_objectConstructor(ctor)
d1d738f1
VS
57 , m_baseInfo1(baseInfo1)
58 , m_baseInfo2(baseInfo2)
0b9ab0bd 59 , m_next(sm_first)
7e548f6b 60 {
d1d738f1
VS
61 sm_first = this;
62 Register();
63 }
0b9ab0bd 64
aa4b7ef9 65 ~wxClassInfo();
1d2eddff 66
4e124582
VZ
67 wxObject *CreateObject() const
68 { return m_objectConstructor ? (*m_objectConstructor)() : 0; }
0c06c983 69 bool IsDynamic() const { return (NULL != m_objectConstructor); }
0b9ab0bd
RL
70
71 const wxChar *GetClassName() const { return m_className; }
469349b5
MB
72 const wxChar *GetBaseClassName1() const
73 { return m_baseInfo1 ? m_baseInfo1->GetClassName() : NULL; }
74 const wxChar *GetBaseClassName2() const
75 { return m_baseInfo2 ? m_baseInfo2->GetClassName() : NULL; }
0b9ab0bd
RL
76 const wxClassInfo *GetBaseClass1() const { return m_baseInfo1; }
77 const wxClassInfo *GetBaseClass2() const { return m_baseInfo2; }
78 int GetSize() const { return m_objectSize; }
79
4e124582
VZ
80 wxObjectConstructorFn GetConstructor() const
81 { return m_objectConstructor; }
0b9ab0bd
RL
82 static const wxClassInfo *GetFirst() { return sm_first; }
83 const wxClassInfo *GetNext() const { return m_next; }
84 static wxClassInfo *FindClass(const wxChar *className);
807d8487 85
0b9ab0bd
RL
86 // Climb upwards through inheritance hierarchy.
87 // Dual inheritance is catered for.
88
89 bool IsKindOf(const wxClassInfo *info) const
90 {
91 return info != 0 &&
92 ( info == this ||
93 ( m_baseInfo1 && m_baseInfo1->IsKindOf(info) ) ||
94 ( m_baseInfo2 && m_baseInfo2->IsKindOf(info) ) );
95 }
3f4a0c5b 96
45bbbc54 97#if WXWIN_COMPATIBILITY_2_4
d1d738f1 98 // Initializes parent pointers and hash table for fast searching.
45bbbc54 99 wxDEPRECATED( static void InitializeClasses() );
d1d738f1 100 // Cleans up hash table used for fast searching.
45bbbc54 101 wxDEPRECATED( static void CleanUpClasses() );
cafc76a4 102#endif
7e548f6b 103
0c32066b 104public:
0b9ab0bd 105 const wxChar *m_className;
0b9ab0bd
RL
106 int m_objectSize;
107 wxObjectConstructorFn m_objectConstructor;
108
109 // Pointers to base wxClassInfos: set in InitializeClasses
110
111 const wxClassInfo *m_baseInfo1;
112 const wxClassInfo *m_baseInfo2;
113
114 // class info object live in a linked list:
115 // pointers to its head and the next element in it
116
117 static wxClassInfo *sm_first;
118 wxClassInfo *m_next;
119
1f428942
VZ
120 // FIXME: this should be private (currently used directly by way too
121 // many clients)
0b9ab0bd 122 static wxHashTable *sm_classTable;
1f428942
VZ
123
124private:
125 // InitializeClasses() helper
126 static wxClassInfo *GetBaseByName(const wxChar *name);
684242c6
GD
127
128 DECLARE_NO_COPY_CLASS(wxClassInfo)
7e548f6b
WS
129
130protected:
d1d738f1
VS
131 // registers the class
132 void Register();
133 void Unregister();
c801d85f
KB
134};
135
bddd7a8d 136WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name);
c801d85f 137
45bbbc54 138#if WXWIN_COMPATIBILITY_2_4
cafc76a4
VS
139inline void wxClassInfo::InitializeClasses() {}
140inline void wxClassInfo::CleanUpClasses() {}
141#endif
142
0b9ab0bd
RL
143// ----------------------------------------------------------------------------
144// Dynamic class macros
145// ----------------------------------------------------------------------------
146
14ca93a0
VZ
147#define DECLARE_ABSTRACT_CLASS(name) \
148 public: \
149 static wxClassInfo ms_classInfo; \
150 virtual wxClassInfo *GetClassInfo() const;
151
152#define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
153 DECLARE_NO_ASSIGN_CLASS(name) \
fc7a2a60
VZ
154 DECLARE_DYNAMIC_CLASS(name)
155
14ca93a0
VZ
156#define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \
157 DECLARE_NO_COPY_CLASS(name) \
fc7a2a60
VZ
158 DECLARE_DYNAMIC_CLASS(name)
159
14ca93a0
VZ
160#define DECLARE_DYNAMIC_CLASS(name) \
161 DECLARE_ABSTRACT_CLASS(name) \
162 static wxObject* wxCreateObject();
163
c801d85f
KB
164#define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
165
14ca93a0
VZ
166
167// common part of the macros below
168#define wxIMPLEMENT_CLASS_COMMON(name, basename, baseclsinfo2, func) \
169 wxClassInfo name::ms_classInfo(wxT(#name), \
170 &basename::ms_classInfo, \
171 baseclsinfo2, \
172 (int) sizeof(name), \
173 (wxObjectConstructorFn) func); \
174 \
175 wxClassInfo *name::GetClassInfo() const \
176 { return &name::ms_classInfo; }
177
178#define wxIMPLEMENT_CLASS_COMMON1(name, basename, func) \
179 wxIMPLEMENT_CLASS_COMMON(name, basename, NULL, func)
180
181#define wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, func) \
2b199a38 182 wxIMPLEMENT_CLASS_COMMON(name, basename1, &basename2::ms_classInfo, func)
14ca93a0 183
0b9ab0bd
RL
184// -----------------------------------
185// for concrete classes
186// -----------------------------------
187
188 // Single inheritance with one base class
14ca93a0
VZ
189#define IMPLEMENT_DYNAMIC_CLASS(name, basename) \
190 wxIMPLEMENT_CLASS_COMMON1(name, basename, name::wxCreateObject) \
191 wxObject* name::wxCreateObject() \
192 { return new name; }
c801d85f 193
0b9ab0bd 194 // Multiple inheritance with two base classes
14ca93a0
VZ
195#define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
196 wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, \
197 name::wxCreateObject) \
198 wxObject* name::wxCreateObject() \
199 { return new name; }
c801d85f 200
0b9ab0bd
RL
201// -----------------------------------
202// for abstract classes
203// -----------------------------------
c801d85f 204
0b9ab0bd
RL
205 // Single inheritance with one base class
206
14ca93a0
VZ
207#define IMPLEMENT_ABSTRACT_CLASS(name, basename) \
208 wxIMPLEMENT_CLASS_COMMON1(name, basename, NULL)
0b9ab0bd
RL
209
210 // Multiple inheritance with two base classes
211
14ca93a0
VZ
212#define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
213 wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, NULL)
c801d85f
KB
214
215#define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
216#define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
217
6d553b5f 218#endif // !wxUSE_EXTENDED_RTTI
a095505c
SC
219
220
0b9ab0bd
RL
221// -----------------------------------
222// for pluggable classes
223// -----------------------------------
224
225 // NOTE: this should probably be the very first statement
226 // in the class declaration so wxPluginSentinel is
227 // the first member initialised and the last destroyed.
228
229// _DECLARE_DL_SENTINEL(name) wxPluginSentinel m_pluginsentinel;
230
231#if wxUSE_NESTED_CLASSES
232
60b73526
RL
233#define _DECLARE_DL_SENTINEL(name, exportdecl) \
234class exportdecl name##PluginSentinel { \
235private: \
236 static const wxString sm_className; \
237public: \
238 name##PluginSentinel(); \
2e0b1b11 239 ~name##PluginSentinel(); \
60b73526 240}; \
0b9ab0bd 241name##PluginSentinel m_pluginsentinel;
0b9ab0bd
RL
242
243#define _IMPLEMENT_DL_SENTINEL(name) \
244 const wxString name::name##PluginSentinel::sm_className(#name); \
245 name::name##PluginSentinel::name##PluginSentinel() { \
4f89dbc4 246 wxPluginLibrary *e = (wxPluginLibrary*) wxPluginLibrary::ms_classes.Get(#name); \
7c1e2b44 247 if( e != 0 ) { e->RefObj(); } \
0b9ab0bd 248 } \
abad5367 249 name::name##PluginSentinel::~name##PluginSentinel() { \
4f89dbc4 250 wxPluginLibrary *e = (wxPluginLibrary*) wxPluginLibrary::ms_classes.Get(#name); \
7c1e2b44 251 if( e != 0 ) { e->UnrefObj(); } \
0b9ab0bd
RL
252 }
253#else
254
255#define _DECLARE_DL_SENTINEL(name)
256#define _IMPLEMENT_DL_SENTINEL(name)
257
258#endif // wxUSE_NESTED_CLASSES
259
260#define DECLARE_PLUGGABLE_CLASS(name) \
60b73526 261 DECLARE_DYNAMIC_CLASS(name) _DECLARE_DL_SENTINEL(name, WXDLLEXPORT)
0b9ab0bd 262#define DECLARE_ABSTRACT_PLUGGABLE_CLASS(name) \
60b73526
RL
263 DECLARE_ABSTRACT_CLASS(name) _DECLARE_DL_SENTINEL(name, WXDLLEXPORT)
264
265#define DECLARE_USER_EXPORTED_PLUGGABLE_CLASS(name, usergoo) \
266 DECLARE_DYNAMIC_CLASS(name) _DECLARE_DL_SENTINEL(name, usergoo)
267#define DECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, usergoo) \
268 DECLARE_ABSTRACT_CLASS(name) _DECLARE_DL_SENTINEL(name, usergoo)
0b9ab0bd
RL
269
270#define IMPLEMENT_PLUGGABLE_CLASS(name, basename) \
271 IMPLEMENT_DYNAMIC_CLASS(name, basename) _IMPLEMENT_DL_SENTINEL(name)
272#define IMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2) \
273 IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) _IMPLEMENT_DL_SENTINEL(name)
0b9ab0bd
RL
274#define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename) \
275 IMPLEMENT_ABSTRACT_CLASS(name, basename) _IMPLEMENT_DL_SENTINEL(name)
276#define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) \
277 IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) _IMPLEMENT_DL_SENTINEL(name)
278
60b73526
RL
279#define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS(name, basename) \
280 IMPLEMENT_PLUGGABLE_CLASS(name, basename)
281#define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS2(name, basename1, basename2) \
282 IMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2)
283#define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, basename) \
284 IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename)
285#define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) \
286 IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2)
287
c0db9626 288#define CLASSINFO(name) (&name::ms_classInfo)
c801d85f 289
c0db9626 290#define wxIS_KIND_OF(obj, className) obj->IsKindOf(&className::ms_classInfo)
3013b6f4 291
b2edef6f 292// Just seems a bit nicer-looking (pretend it's not a macro)
c0db9626 293#define wxIsKindOf(obj, className) obj->IsKindOf(&className::ms_classInfo)
c801d85f 294
73fbb031
VZ
295// this cast does some more checks at compile time as it uses static_cast
296// internally
297//
298// note that it still has different semantics from dynamic_cast<> and so can't
299// be replaced by it as long as there are any compilers not supporting it
34636400 300#define wxDynamicCast(obj, className) \
5232d996
VZ
301 ((className *) wxCheckDynamicCast( \
302 wx_const_cast(wxObject *, wx_static_cast(const wxObject *, \
303 wx_const_cast(className *, wx_static_cast(const className *, obj)))), \
304 &className::ms_classInfo))
0b9ab0bd 305
b2edef6f
VZ
306// The 'this' pointer is always true, so use this version
307// to cast the this pointer and avoid compiler warnings.
f7637829 308#define wxDynamicCastThis(className) \
73fbb031 309 (IsKindOf(&className::ms_classInfo) ? (className *)(this) : (className *)0)
33ac7e6f 310
f6bcfd97 311#ifdef __WXDEBUG__
e32d4836 312inline void* wxCheckCast(void *ptr)
0b9ab0bd
RL
313{
314 wxASSERT_MSG( ptr, _T("wxStaticCast() used incorrectly") );
e32d4836 315 return ptr;
0b9ab0bd
RL
316}
317#define wxStaticCast(obj, className) \
e32d4836 318 ((className *)wxCheckCast(wxDynamicCast(obj, className)))
f6bcfd97 319
0b9ab0bd 320#else // !__WXDEBUG__
ef0aea5a
VZ
321#define wxStaticCast(obj, className) \
322 wx_const_cast(className *, wx_static_cast(const className *, obj))
f6bcfd97 323
0b9ab0bd 324#endif // __WXDEBUG__
f6bcfd97 325
b2edef6f
VZ
326// ----------------------------------------------------------------------------
327// set up memory debugging macros
328// ----------------------------------------------------------------------------
329
330/*
331 Which new/delete operator variants do we want?
332
333 _WX_WANT_NEW_SIZET_WXCHAR_INT = void *operator new (size_t size, wxChar *fileName = 0, int lineNum = 0)
334 _WX_WANT_DELETE_VOID = void operator delete (void * buf)
335 _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET = void operator delete (void *buf, const char *_fname, size_t _line)
336 _WX_WANT_DELETE_VOID_WXCHAR_INT = void operator delete(void *buf, wxChar*, int)
337 _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT = void *operator new[] (size_t size, wxChar *fileName , int lineNum = 0)
338 _WX_WANT_ARRAY_DELETE_VOID = void operator delete[] (void *buf)
339 _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT = void operator delete[] (void* buf, wxChar*, int )
340*/
341
342#if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
343
344// All compilers get this one
345#define _WX_WANT_NEW_SIZET_WXCHAR_INT
346
347// Everyone except Visage gets the next one
348#ifndef __VISAGECPP__
349 #define _WX_WANT_DELETE_VOID
c801d85f 350#endif
b2edef6f
VZ
351
352// Only visage gets this one under the correct circumstances
353#if defined(__VISAGECPP__) && __DEBUG_ALLOC__
354 #define _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET
355#endif
356
4e124582
VZ
357// Only VC++ 6 and CodeWarrior get overloaded delete that matches new
358#if (defined(__VISUALC__) && (__VISUALC__ >= 1200)) || \
359 (defined(__MWERKS__) && (__MWERKS__ >= 0x2400))
b2edef6f 360 #define _WX_WANT_DELETE_VOID_WXCHAR_INT
fd85b064 361#endif
c801d85f 362
b2edef6f
VZ
363// Now see who (if anyone) gets the array memory operators
364#if wxUSE_ARRAY_MEMORY_OPERATORS
365
366 // Everyone except Visual C++ (cause problems for VC++ - crashes)
367 #if !defined(__VISUALC__)
368 #define _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT
369 #endif
370
371 // Everyone except Visual C++ (cause problems for VC++ - crashes)
372 #if !defined(__VISUALC__)
373 #define _WX_WANT_ARRAY_DELETE_VOID
374 #endif
375
376 // Only CodeWarrior 6 or higher
377 #if defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
378 #define _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT
379 #endif
380
381#endif // wxUSE_ARRAY_MEMORY_OPERATORS
382
e755eb67 383#endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING
b2edef6f 384
f8855e47
VZ
385// ----------------------------------------------------------------------------
386// wxObjectRefData: ref counted data meant to be stored in wxObject
387// ----------------------------------------------------------------------------
388
389class WXDLLIMPEXP_BASE wxObjectRefData
390{
391 friend class WXDLLIMPEXP_BASE wxObject;
392
393public:
394 wxObjectRefData() : m_count(1) { }
f8855e47
VZ
395
396 int GetRefCount() const { return m_count; }
397
4a11340a
RR
398 void IncRef() { m_count++; }
399 void DecRef();
400
401protected:
402 // this object should never be destroyed directly but only as a
403 // result of a DecRef() call:
404 virtual ~wxObjectRefData() { }
405
f8855e47 406private:
4a11340a 407 // our refcount:
f8855e47
VZ
408 int m_count;
409};
410
4a11340a
RR
411// ----------------------------------------------------------------------------
412// wxObjectDataPtr: helper class to avoid memleaks because of missing calls
413// to wxObjectRefData::DecRef
414// ----------------------------------------------------------------------------
415
416template <class T>
417class wxObjectDataPtr
418{
419public:
420 typedef T element_type;
421
422 wxEXPLICIT wxObjectDataPtr(T *ptr = NULL) : m_ptr(ptr) {}
423
424 // copy ctor
425 wxObjectDataPtr(const wxObjectDataPtr<T> &tocopy)
426 : m_ptr(tocopy.m_ptr)
427 {
428 if (m_ptr)
429 m_ptr->IncRef();
430 }
431
432 ~wxObjectDataPtr()
433 {
434 if (m_ptr)
435 m_ptr->DecRef();
436 }
437
438 T *get() const { return m_ptr; }
439 T *operator->() const { return get(); }
440
441 void reset(T *ptr)
442 {
443 if (m_ptr)
444 m_ptr->DecRef();
445 m_ptr = ptr;
446 }
447
448 wxObjectDataPtr& operator=(const wxObjectDataPtr &tocopy)
449 {
450 if (m_ptr)
451 m_ptr->DecRef();
452 m_ptr = tocopy.m_ptr;
453 if (m_ptr)
454 m_ptr->IncRef();
455 return *this;
456 }
457
458 wxObjectDataPtr& operator=(T *ptr)
459 {
460 if (m_ptr)
461 m_ptr->DecRef();
462 m_ptr = ptr;
463 if (m_ptr)
464 m_ptr->IncRef();
465 return *this;
466 }
467
468private:
469 T *m_ptr;
470};
471
0b9ab0bd 472// ----------------------------------------------------------------------------
77ffb593 473// wxObject: the root class of wxWidgets object hierarchy
0b9ab0bd
RL
474// ----------------------------------------------------------------------------
475
bddd7a8d 476class WXDLLIMPEXP_BASE wxObject
c801d85f 477{
684242c6 478 DECLARE_ABSTRACT_CLASS(wxObject)
c801d85f 479
0b9ab0bd 480public:
b2edef6f 481 wxObject() { m_refData = NULL; }
0b9ab0bd 482 virtual ~wxObject() { UnRef(); }
4393b50c 483
a6391d30 484 wxObject(const wxObject& other)
66e9a9f0 485 {
f8855e47
VZ
486 m_refData = other.m_refData;
487 if (m_refData)
488 m_refData->m_count++;
66e9a9f0 489 }
4393b50c 490
a6391d30
GD
491 wxObject& operator=(const wxObject& other)
492 {
493 if ( this != &other )
494 {
f8855e47 495 Ref(other);
a6391d30
GD
496 }
497 return *this;
498 }
499
0b9ab0bd 500 bool IsKindOf(wxClassInfo *info) const;
c801d85f 501
0b9ab0bd 502
b2edef6f
VZ
503 // Turn on the correct set of new and delete operators
504
505#ifdef _WX_WANT_NEW_SIZET_WXCHAR_INT
cf760e4c 506 void *operator new ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 );
0b9ab0bd 507#endif
27198be4 508
b2edef6f
VZ
509#ifdef _WX_WANT_DELETE_VOID
510 void operator delete ( void * buf );
511#endif
0b9ab0bd 512
b2edef6f
VZ
513#ifdef _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET
514 void operator delete ( void *buf, const char *_fname, size_t _line );
0b9ab0bd 515#endif
76626af2 516
b2edef6f 517#ifdef _WX_WANT_DELETE_VOID_WXCHAR_INT
cf760e4c 518 void operator delete ( void *buf, const wxChar*, int );
b2edef6f 519#endif
8cfc5426 520
b2edef6f 521#ifdef _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT
cf760e4c 522 void *operator new[] ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 );
0b9ab0bd
RL
523#endif
524
b2edef6f
VZ
525#ifdef _WX_WANT_ARRAY_DELETE_VOID
526 void operator delete[] ( void *buf );
0b9ab0bd 527#endif
27198be4 528
b2edef6f 529#ifdef _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT
cf760e4c 530 void operator delete[] (void* buf, const wxChar*, int );
b2edef6f 531#endif
c801d85f 532
807d8487
VZ
533 // ref counted data handling methods
534
535 // get/set
536 wxObjectRefData *GetRefData() const { return m_refData; }
537 void SetRefData(wxObjectRefData *data) { m_refData = data; }
538
539 // make a 'clone' of the object
0b9ab0bd 540 void Ref(const wxObject& clone);
c801d85f 541
807d8487 542 // destroy a reference
0b9ab0bd 543 void UnRef();
c801d85f 544
93c5f755
PC
545 // Make sure this object has only one reference
546 void UnShare() { AllocExclusive(); }
547
a3ab1c18
VZ
548 // check if this object references the same data as the other one
549 bool IsSameAs(const wxObject& o) const { return m_refData == o.m_refData; }
55ccdb93 550
c801d85f 551protected:
807d8487
VZ
552 // ensure that our data is not shared with anybody else: if we have no
553 // data, it is created using CreateRefData() below, if we have shared data
554 // it is copied using CloneRefData(), otherwise nothing is done
555 void AllocExclusive();
556
4e124582
VZ
557 // both methods must be implemented if AllocExclusive() is used, not pure
558 // virtual only because of the backwards compatibility reasons
807d8487
VZ
559
560 // create a new m_refData
561 virtual wxObjectRefData *CreateRefData() const;
562
563 // create a new m_refData initialized with the given one
b8027888 564 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
807d8487 565
0b9ab0bd 566 wxObjectRefData *m_refData;
c801d85f
KB
567};
568
ea1e6c4b
RL
569inline wxObject *wxCheckDynamicCast(wxObject *obj, wxClassInfo *classInfo)
570{
b2edef6f 571 return obj && obj->GetClassInfo()->IsKindOf(classInfo) ? obj : NULL;
ea1e6c4b
RL
572}
573
2d51f067
SC
574#if wxUSE_EXTENDED_RTTI
575class WXDLLIMPEXP_BASE wxDynamicObject : public wxObject
576{
8f2b1cfd 577 friend class WXDLLIMPEXP_BASE wxDynamicClassInfo ;
2d51f067
SC
578public:
579 // instantiates this object with an instance of its superclass
580 wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info) ;
d3c7fc99 581 virtual ~wxDynamicObject();
2d51f067 582
8f2b1cfd
SC
583 void SetProperty (const wxChar *propertyName, const wxxVariant &value);
584 wxxVariant GetProperty (const wxChar *propertyName) const ;
2d51f067
SC
585
586 // get the runtime identity of this object
587 wxClassInfo *GetClassInfo() const
588 {
f525dc35
JS
589#ifdef _MSC_VER
590 return (wxClassInfo*) m_classInfo;
591#else
4a11340a
RR
592 wxDynamicClassInfo *nonconst = wx_const_cast(wxDynamicClassInfo *, m_classInfo);
593 return wx_static_cast(wxClassInfo *, nonconst);
f525dc35 594#endif
2d51f067
SC
595 }
596
597 wxObject* GetSuperClassInstance() const
598 {
599 return m_superClassInstance ;
600 }
601private :
8f2b1cfd
SC
602 // removes an existing runtime-property
603 void RemoveProperty( const wxChar *propertyName ) ;
604
605 // renames an existing runtime-property
606 void RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName ) ;
607
2d51f067
SC
608 wxObject *m_superClassInstance ;
609 const wxDynamicClassInfo *m_classInfo;
610 struct wxDynamicObjectInternal;
611 wxDynamicObjectInternal *m_data;
612};
613#endif
614
b2edef6f
VZ
615// ----------------------------------------------------------------------------
616// more debugging macros
617// ----------------------------------------------------------------------------
618
b2edef6f
VZ
619// Redefine new to be the debugging version. This doesn't work with all
620// compilers, in which case you need to use WXDEBUG_NEW explicitly if you wish
621// to use the debugging version.
7fe7d506 622
70bf6180
VZ
623#ifdef __WXDEBUG__
624 #define WXDEBUG_NEW new(__TFILE__,__LINE__)
625
626 #if wxUSE_DEBUG_NEW_ALWAYS
627 #if wxUSE_GLOBAL_MEMORY_OPERATORS
628 #define new WXDEBUG_NEW
629 #elif defined(__VISUALC__)
630 // Including this file redefines new and allows leak reports to
631 // contain line numbers
632 #include "wx/msw/msvcrt.h"
633 #endif
634 #endif // wxUSE_DEBUG_NEW_ALWAYS
635#else // !__WXDEBUG__
636 #define WXDEBUG_NEW new
637#endif // __WXDEBUG__/!__WXDEBUG__
c801d85f 638
c0089c96 639#endif // _WX_OBJECTH__