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