]> git.saurik.com Git - wxWidgets.git/blame - include/wx/object.h
implemented IsModified() and DiscardEdits()
[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
cafc76a4 110#ifdef WXWIN_COMPATIBILITY_2_4
d1d738f1 111 // Initializes parent pointers and hash table for fast searching.
cafc76a4 112 wxDEPRECATED( static void InitializeClasses() );
d1d738f1 113 // Cleans up hash table used for fast searching.
cafc76a4
VS
114 wxDEPRECATED( static void CleanUpClasses() );
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
cafc76a4
VS
152#ifdef WXWIN_COMPATIBILITY_2_4
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: \
163 static wxClassInfo sm_class##name; \
164 virtual wxClassInfo *GetClassInfo() const \
0c32066b 165 { return &name::sm_class##name; }
c801d85f 166
fc7a2a60 167#define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
a6cbc4db 168 DECLARE_NO_ASSIGN_CLASS(name) \
fc7a2a60
VZ
169 DECLARE_DYNAMIC_CLASS(name)
170
171#define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \
172 DECLARE_NO_COPY_CLASS(name) \
173 DECLARE_DYNAMIC_CLASS(name)
174
c801d85f
KB
175#define DECLARE_ABSTRACT_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
176#define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
177
0b9ab0bd
RL
178// -----------------------------------
179// for concrete classes
180// -----------------------------------
181
182 // Single inheritance with one base class
c801d85f 183
0b9ab0bd 184#define IMPLEMENT_DYNAMIC_CLASS(name, basename) \
648762b1 185 wxObject* wxConstructorFor##name() \
0b9ab0bd 186 { return new name; } \
d1d738f1
VS
187 wxClassInfo name::sm_class##name(wxT(#name), \
188 &basename::sm_class##basename, NULL, \
189 (int) sizeof(name), \
0b9ab0bd 190 (wxObjectConstructorFn) wxConstructorFor##name);
c801d85f 191
0b9ab0bd 192 // Multiple inheritance with two base classes
c801d85f 193
0b9ab0bd 194#define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
648762b1 195 wxObject* wxConstructorFor##name() \
0b9ab0bd 196 { return new name; } \
d1d738f1
VS
197 wxClassInfo name::sm_class##name(wxT(#name), \
198 &basename1::sm_class##basename1, \
199 &basename2::sm_class##basename2, \
0b9ab0bd
RL
200 wxT(#basename2), (int) sizeof(name), \
201 (wxObjectConstructorFn) wxConstructorFor##name);
c801d85f 202
0b9ab0bd
RL
203// -----------------------------------
204// for abstract classes
205// -----------------------------------
c801d85f 206
0b9ab0bd
RL
207 // Single inheritance with one base class
208
209#define IMPLEMENT_ABSTRACT_CLASS(name, basename) \
d1d738f1
VS
210 wxClassInfo name::sm_class##name(wxT(#name), \
211 &basename::sm_class##basename, NULL, \
212 (int) sizeof(name), (wxObjectConstructorFn) 0);
0b9ab0bd
RL
213
214 // Multiple inheritance with two base classes
215
216#define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
d1d738f1
VS
217 wxClassInfo name::sm_class##name(wxT(#name), \
218 &basename1::sm_class##basename1, \
219 &basename2::sm_class##basename2, \
220 (int) sizeof(name), \
0b9ab0bd 221 (wxObjectConstructorFn) 0);
c801d85f
KB
222
223#define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
224#define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
225
6d553b5f 226#endif // !wxUSE_EXTENDED_RTTI
a095505c
SC
227
228
0b9ab0bd
RL
229// -----------------------------------
230// for pluggable classes
231// -----------------------------------
232
233 // NOTE: this should probably be the very first statement
234 // in the class declaration so wxPluginSentinel is
235 // the first member initialised and the last destroyed.
236
237// _DECLARE_DL_SENTINEL(name) wxPluginSentinel m_pluginsentinel;
238
239#if wxUSE_NESTED_CLASSES
240
60b73526
RL
241#define _DECLARE_DL_SENTINEL(name, exportdecl) \
242class exportdecl name##PluginSentinel { \
243private: \
244 static const wxString sm_className; \
245public: \
246 name##PluginSentinel(); \
2e0b1b11 247 ~name##PluginSentinel(); \
60b73526 248}; \
0b9ab0bd 249name##PluginSentinel m_pluginsentinel;
0b9ab0bd
RL
250
251#define _IMPLEMENT_DL_SENTINEL(name) \
252 const wxString name::name##PluginSentinel::sm_className(#name); \
253 name::name##PluginSentinel::name##PluginSentinel() { \
4f89dbc4 254 wxPluginLibrary *e = (wxPluginLibrary*) wxPluginLibrary::ms_classes.Get(#name); \
7c1e2b44 255 if( e != 0 ) { e->RefObj(); } \
0b9ab0bd 256 } \
abad5367 257 name::name##PluginSentinel::~name##PluginSentinel() { \
4f89dbc4 258 wxPluginLibrary *e = (wxPluginLibrary*) wxPluginLibrary::ms_classes.Get(#name); \
7c1e2b44 259 if( e != 0 ) { e->UnrefObj(); } \
0b9ab0bd
RL
260 }
261#else
262
263#define _DECLARE_DL_SENTINEL(name)
264#define _IMPLEMENT_DL_SENTINEL(name)
265
266#endif // wxUSE_NESTED_CLASSES
267
268#define DECLARE_PLUGGABLE_CLASS(name) \
60b73526 269 DECLARE_DYNAMIC_CLASS(name) _DECLARE_DL_SENTINEL(name, WXDLLEXPORT)
0b9ab0bd 270#define DECLARE_ABSTRACT_PLUGGABLE_CLASS(name) \
60b73526
RL
271 DECLARE_ABSTRACT_CLASS(name) _DECLARE_DL_SENTINEL(name, WXDLLEXPORT)
272
273#define DECLARE_USER_EXPORTED_PLUGGABLE_CLASS(name, usergoo) \
274 DECLARE_DYNAMIC_CLASS(name) _DECLARE_DL_SENTINEL(name, usergoo)
275#define DECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, usergoo) \
276 DECLARE_ABSTRACT_CLASS(name) _DECLARE_DL_SENTINEL(name, usergoo)
0b9ab0bd
RL
277
278#define IMPLEMENT_PLUGGABLE_CLASS(name, basename) \
279 IMPLEMENT_DYNAMIC_CLASS(name, basename) _IMPLEMENT_DL_SENTINEL(name)
280#define IMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2) \
281 IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) _IMPLEMENT_DL_SENTINEL(name)
0b9ab0bd
RL
282#define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename) \
283 IMPLEMENT_ABSTRACT_CLASS(name, basename) _IMPLEMENT_DL_SENTINEL(name)
284#define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) \
285 IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) _IMPLEMENT_DL_SENTINEL(name)
286
60b73526
RL
287#define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS(name, basename) \
288 IMPLEMENT_PLUGGABLE_CLASS(name, basename)
289#define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS2(name, basename1, basename2) \
290 IMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2)
291#define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, basename) \
292 IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename)
293#define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) \
294 IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2)
295
0c32066b 296#define CLASSINFO(name) (&name::sm_class##name)
c801d85f 297
34636400 298#else // !wxUSE_DYNAMIC_CLASSES
c801d85f 299
0b9ab0bd
RL
300 // No dynamic class system: so stub out the macros
301
c801d85f
KB
302#define DECLARE_DYNAMIC_CLASS(name)
303#define DECLARE_ABSTRACT_CLASS(name)
304#define DECLARE_CLASS(name)
305#define IMPLEMENT_DYNAMIC_CLASS(name, basename)
306#define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2)
307#define IMPLEMENT_ABSTRACT_CLASS(name, basename)
308#define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2)
309#define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
310#define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
311
0b9ab0bd
RL
312#define DECLARE_PLUGGABLE_CLASS(name)
313#define DECLARE_ABSTRACT_PLUGGABLE_CLASS(name)
314#define IMPLEMENT_PLUGGABLE_CLASS(name, basename)
315#define IMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2)
316#define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename)
317#define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2)
318
60b73526
RL
319#define DECLARE_USER_EXPORTED_PLUGGABLE_CLASS(name, usergoo)
320#define DECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, usergoo)
321#define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS(name, basename)
322#define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS2(name, basename1, basename2)
323#define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, basename)
324#define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2)
325
0b9ab0bd
RL
326#endif // wxUSE_DYNAMIC_CLASSES
327
3013b6f4
JS
328#define wxIS_KIND_OF(obj, className) obj->IsKindOf(&className::sm_class##className)
329
b2edef6f 330// Just seems a bit nicer-looking (pretend it's not a macro)
3013b6f4 331#define wxIsKindOf(obj, className) obj->IsKindOf(&className::sm_class##className)
c801d85f 332
b2edef6f 333// to be replaced by dynamic_cast<> in the future
34636400 334#define wxDynamicCast(obj, className) \
768f1af6 335 ((className *) wxCheckDynamicCast((wxObject*)(obj), &className::sm_class##className))
0b9ab0bd 336
b2edef6f
VZ
337// The 'this' pointer is always true, so use this version
338// to cast the this pointer and avoid compiler warnings.
f7637829 339#define wxDynamicCastThis(className) \
0b9ab0bd 340 (IsKindOf(&className::sm_class##className) ? (className *)(this) : (className *)0)
33ac7e6f 341
521196a2
MB
342#ifdef HAVE_CONST_CAST
343#define wxConstCast(obj, className) const_cast<className *>(obj)
344#else
f6bcfd97 345#define wxConstCast(obj, className) ((className *)(obj))
521196a2 346#endif
f6bcfd97 347
0b9ab0bd 348
f6bcfd97 349#ifdef __WXDEBUG__
0b9ab0bd
RL
350inline void wxCheckCast(void *ptr)
351{
352 wxASSERT_MSG( ptr, _T("wxStaticCast() used incorrectly") );
353}
354#define wxStaticCast(obj, className) \
355 (wxCheckCast(wxDynamicCast(obj, className)), ((className *)(obj)))
f6bcfd97 356
0b9ab0bd
RL
357#else // !__WXDEBUG__
358#define wxStaticCast(obj, className) ((className *)(obj))
f6bcfd97 359
0b9ab0bd 360#endif // __WXDEBUG__
f6bcfd97 361
b2edef6f
VZ
362// ----------------------------------------------------------------------------
363// set up memory debugging macros
364// ----------------------------------------------------------------------------
365
366/*
367 Which new/delete operator variants do we want?
368
369 _WX_WANT_NEW_SIZET_WXCHAR_INT = void *operator new (size_t size, wxChar *fileName = 0, int lineNum = 0)
370 _WX_WANT_DELETE_VOID = void operator delete (void * buf)
371 _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET = void operator delete (void *buf, const char *_fname, size_t _line)
372 _WX_WANT_DELETE_VOID_WXCHAR_INT = void operator delete(void *buf, wxChar*, int)
373 _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT = void *operator new[] (size_t size, wxChar *fileName , int lineNum = 0)
374 _WX_WANT_ARRAY_DELETE_VOID = void operator delete[] (void *buf)
375 _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT = void operator delete[] (void* buf, wxChar*, int )
376*/
377
378#if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
379
380// All compilers get this one
381#define _WX_WANT_NEW_SIZET_WXCHAR_INT
382
383// Everyone except Visage gets the next one
384#ifndef __VISAGECPP__
385 #define _WX_WANT_DELETE_VOID
c801d85f 386#endif
b2edef6f
VZ
387
388// Only visage gets this one under the correct circumstances
389#if defined(__VISAGECPP__) && __DEBUG_ALLOC__
390 #define _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET
391#endif
392
393// Only VC++ 6.0 and CodeWarrior compilers get overloaded delete that matches new
684242c6 394#if ( defined(__VISUALC__) && (__VISUALC__ >= 1200) ) || (defined(__MWERKS__) && (__MWERKS__ >= 0x2400))
b2edef6f 395 #define _WX_WANT_DELETE_VOID_WXCHAR_INT
fd85b064 396#endif
c801d85f 397
b2edef6f
VZ
398// Now see who (if anyone) gets the array memory operators
399#if wxUSE_ARRAY_MEMORY_OPERATORS
400
401 // Everyone except Visual C++ (cause problems for VC++ - crashes)
402 #if !defined(__VISUALC__)
403 #define _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT
404 #endif
405
406 // Everyone except Visual C++ (cause problems for VC++ - crashes)
407 #if !defined(__VISUALC__)
408 #define _WX_WANT_ARRAY_DELETE_VOID
409 #endif
410
411 // Only CodeWarrior 6 or higher
412 #if defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
413 #define _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT
414 #endif
415
416#endif // wxUSE_ARRAY_MEMORY_OPERATORS
417
418#endif // WXDEBUG && wxUSE_MEMORY_TRACING
419
0b9ab0bd 420// ----------------------------------------------------------------------------
b2edef6f 421// wxObject: the root class of wxWindows object hierarchy
0b9ab0bd
RL
422// ----------------------------------------------------------------------------
423
bddd7a8d 424class WXDLLIMPEXP_BASE wxObject
c801d85f 425{
684242c6 426 DECLARE_ABSTRACT_CLASS(wxObject)
c801d85f 427
a6391d30
GD
428private:
429 void InitFrom(const wxObject& other);
4393b50c 430
0b9ab0bd 431public:
b2edef6f 432 wxObject() { m_refData = NULL; }
0b9ab0bd 433 virtual ~wxObject() { UnRef(); }
4393b50c 434
a6391d30
GD
435 wxObject(const wxObject& other)
436 {
437 InitFrom(other);
438 }
4393b50c 439
a6391d30
GD
440 wxObject& operator=(const wxObject& other)
441 {
442 if ( this != &other )
443 {
444 UnRef();
445 InitFrom(other);
446 }
447 return *this;
448 }
449
0b9ab0bd 450 bool IsKindOf(wxClassInfo *info) const;
c801d85f 451
0b9ab0bd 452
b2edef6f
VZ
453 // Turn on the correct set of new and delete operators
454
455#ifdef _WX_WANT_NEW_SIZET_WXCHAR_INT
cf760e4c 456 void *operator new ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 );
0b9ab0bd 457#endif
27198be4 458
b2edef6f
VZ
459#ifdef _WX_WANT_DELETE_VOID
460 void operator delete ( void * buf );
461#endif
0b9ab0bd 462
b2edef6f
VZ
463#ifdef _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET
464 void operator delete ( void *buf, const char *_fname, size_t _line );
0b9ab0bd 465#endif
76626af2 466
b2edef6f 467#ifdef _WX_WANT_DELETE_VOID_WXCHAR_INT
cf760e4c 468 void operator delete ( void *buf, const wxChar*, int );
b2edef6f 469#endif
8cfc5426 470
b2edef6f 471#ifdef _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT
cf760e4c 472 void *operator new[] ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 );
0b9ab0bd
RL
473#endif
474
b2edef6f
VZ
475#ifdef _WX_WANT_ARRAY_DELETE_VOID
476 void operator delete[] ( void *buf );
0b9ab0bd 477#endif
27198be4 478
b2edef6f 479#ifdef _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT
cf760e4c 480 void operator delete[] (void* buf, const wxChar*, int );
b2edef6f 481#endif
c801d85f 482
807d8487
VZ
483 // ref counted data handling methods
484
485 // get/set
486 wxObjectRefData *GetRefData() const { return m_refData; }
487 void SetRefData(wxObjectRefData *data) { m_refData = data; }
488
489 // make a 'clone' of the object
0b9ab0bd 490 void Ref(const wxObject& clone);
c801d85f 491
807d8487 492 // destroy a reference
0b9ab0bd 493 void UnRef();
c801d85f 494
c801d85f 495protected:
807d8487
VZ
496 // ensure that our data is not shared with anybody else: if we have no
497 // data, it is created using CreateRefData() below, if we have shared data
498 // it is copied using CloneRefData(), otherwise nothing is done
499 void AllocExclusive();
500
501 // both methods must be implemented if Unshare() is used, not pure virtual
502 // only because of the backwards compatibility reasons
503
504 // create a new m_refData
505 virtual wxObjectRefData *CreateRefData() const;
506
507 // create a new m_refData initialized with the given one
b8027888 508 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
807d8487 509
0b9ab0bd 510 wxObjectRefData *m_refData;
c801d85f
KB
511};
512
b2edef6f
VZ
513// ----------------------------------------------------------------------------
514// wxObjectRefData: ref counted data meant to be stored in wxObject
515// ----------------------------------------------------------------------------
c801d85f 516
bddd7a8d 517class WXDLLIMPEXP_BASE wxObjectRefData
0b9ab0bd 518{
bddd7a8d 519 friend class WXDLLIMPEXP_BASE wxObject;
c801d85f
KB
520
521public:
b2edef6f
VZ
522 wxObjectRefData() : m_count(1) { }
523 virtual ~wxObjectRefData() { }
524
525 int GetRefCount() const { return m_count; }
c801d85f 526
c801d85f
KB
527private:
528 int m_count;
529};
530
0b9ab0bd 531
ea1e6c4b
RL
532inline wxObject *wxCheckDynamicCast(wxObject *obj, wxClassInfo *classInfo)
533{
b2edef6f 534 return obj && obj->GetClassInfo()->IsKindOf(classInfo) ? obj : NULL;
ea1e6c4b
RL
535}
536
2d51f067
SC
537#if wxUSE_EXTENDED_RTTI
538class WXDLLIMPEXP_BASE wxDynamicObject : public wxObject
539{
540public:
541 // instantiates this object with an instance of its superclass
542 wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info) ;
543 ~wxDynamicObject();
544
545 void SetProperty (const wxChar *PropertyName, const wxxVariant &Value);
546 wxxVariant GetProperty (const wxChar *PropertyName) const ;
547
548 // get the runtime identity of this object
549 wxClassInfo *GetClassInfo() const
550 {
551 return const_cast<wxClassInfo*>((const wxClassInfo*)m_classInfo);
552 }
553
554 wxObject* GetSuperClassInstance() const
555 {
556 return m_superClassInstance ;
557 }
558private :
559 wxObject *m_superClassInstance ;
560 const wxDynamicClassInfo *m_classInfo;
561 struct wxDynamicObjectInternal;
562 wxDynamicObjectInternal *m_data;
563};
564#endif
565
b2edef6f
VZ
566// ----------------------------------------------------------------------------
567// more debugging macros
568// ----------------------------------------------------------------------------
569
7fe7d506 570#ifdef __WXDEBUG__
b2edef6f
VZ
571 #ifndef WXDEBUG_NEW
572 #define WXDEBUG_NEW new(__TFILE__,__LINE__)
573 #endif
574#else // !__WXDEBUG__
575 #define WXDEBUG_NEW new
7fe7d506
JS
576#endif
577
b2edef6f
VZ
578// Redefine new to be the debugging version. This doesn't work with all
579// compilers, in which case you need to use WXDEBUG_NEW explicitly if you wish
580// to use the debugging version.
7fe7d506
JS
581
582#if defined(__WXDEBUG__) && wxUSE_GLOBAL_MEMORY_OPERATORS && wxUSE_DEBUG_NEW_ALWAYS
b2edef6f 583 #define new new(__TFILE__,__LINE__)
c801d85f
KB
584#endif
585
0b9ab0bd 586#endif // _WX_OBJECTH__
c801d85f 587