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