]> git.saurik.com Git - wxWidgets.git/blame - include/wx/object.h
added wxConvFileName which is a variable, not define as wxConvFile; added comments...
[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
73fbb031
VZ
307// this cast does some more checks at compile time as it uses static_cast
308// internally
309//
310// note that it still has different semantics from dynamic_cast<> and so can't
311// be replaced by it as long as there are any compilers not supporting it
34636400 312#define wxDynamicCast(obj, className) \
5232d996
VZ
313 ((className *) wxCheckDynamicCast( \
314 wx_const_cast(wxObject *, wx_static_cast(const wxObject *, \
315 wx_const_cast(className *, wx_static_cast(const className *, obj)))), \
316 &className::ms_classInfo))
0b9ab0bd 317
b2edef6f
VZ
318// The 'this' pointer is always true, so use this version
319// to cast the this pointer and avoid compiler warnings.
f7637829 320#define wxDynamicCastThis(className) \
73fbb031 321 (IsKindOf(&className::ms_classInfo) ? (className *)(this) : (className *)0)
33ac7e6f 322
f6bcfd97 323#ifdef __WXDEBUG__
e32d4836 324inline void* wxCheckCast(void *ptr)
0b9ab0bd
RL
325{
326 wxASSERT_MSG( ptr, _T("wxStaticCast() used incorrectly") );
e32d4836 327 return ptr;
0b9ab0bd
RL
328}
329#define wxStaticCast(obj, className) \
e32d4836 330 ((className *)wxCheckCast(wxDynamicCast(obj, className)))
f6bcfd97 331
0b9ab0bd 332#else // !__WXDEBUG__
ef0aea5a
VZ
333#define wxStaticCast(obj, className) \
334 wx_const_cast(className *, wx_static_cast(const className *, obj))
f6bcfd97 335
0b9ab0bd 336#endif // __WXDEBUG__
f6bcfd97 337
b2edef6f
VZ
338// ----------------------------------------------------------------------------
339// set up memory debugging macros
340// ----------------------------------------------------------------------------
341
342/*
343 Which new/delete operator variants do we want?
344
345 _WX_WANT_NEW_SIZET_WXCHAR_INT = void *operator new (size_t size, wxChar *fileName = 0, int lineNum = 0)
346 _WX_WANT_DELETE_VOID = void operator delete (void * buf)
347 _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET = void operator delete (void *buf, const char *_fname, size_t _line)
348 _WX_WANT_DELETE_VOID_WXCHAR_INT = void operator delete(void *buf, wxChar*, int)
349 _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT = void *operator new[] (size_t size, wxChar *fileName , int lineNum = 0)
350 _WX_WANT_ARRAY_DELETE_VOID = void operator delete[] (void *buf)
351 _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT = void operator delete[] (void* buf, wxChar*, int )
352*/
353
354#if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
355
356// All compilers get this one
357#define _WX_WANT_NEW_SIZET_WXCHAR_INT
358
359// Everyone except Visage gets the next one
360#ifndef __VISAGECPP__
361 #define _WX_WANT_DELETE_VOID
c801d85f 362#endif
b2edef6f
VZ
363
364// Only visage gets this one under the correct circumstances
365#if defined(__VISAGECPP__) && __DEBUG_ALLOC__
366 #define _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET
367#endif
368
369// Only VC++ 6.0 and CodeWarrior compilers get overloaded delete that matches new
684242c6 370#if ( defined(__VISUALC__) && (__VISUALC__ >= 1200) ) || (defined(__MWERKS__) && (__MWERKS__ >= 0x2400))
b2edef6f 371 #define _WX_WANT_DELETE_VOID_WXCHAR_INT
fd85b064 372#endif
c801d85f 373
b2edef6f
VZ
374// Now see who (if anyone) gets the array memory operators
375#if wxUSE_ARRAY_MEMORY_OPERATORS
376
377 // Everyone except Visual C++ (cause problems for VC++ - crashes)
378 #if !defined(__VISUALC__)
379 #define _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT
380 #endif
381
382 // Everyone except Visual C++ (cause problems for VC++ - crashes)
383 #if !defined(__VISUALC__)
384 #define _WX_WANT_ARRAY_DELETE_VOID
385 #endif
386
387 // Only CodeWarrior 6 or higher
388 #if defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
389 #define _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT
390 #endif
391
392#endif // wxUSE_ARRAY_MEMORY_OPERATORS
393
394#endif // WXDEBUG && wxUSE_MEMORY_TRACING
395
0b9ab0bd 396// ----------------------------------------------------------------------------
77ffb593 397// wxObject: the root class of wxWidgets object hierarchy
0b9ab0bd
RL
398// ----------------------------------------------------------------------------
399
bddd7a8d 400class WXDLLIMPEXP_BASE wxObject
c801d85f 401{
684242c6 402 DECLARE_ABSTRACT_CLASS(wxObject)
c801d85f 403
a6391d30
GD
404private:
405 void InitFrom(const wxObject& other);
4393b50c 406
0b9ab0bd 407public:
b2edef6f 408 wxObject() { m_refData = NULL; }
0b9ab0bd 409 virtual ~wxObject() { UnRef(); }
4393b50c 410
a6391d30
GD
411 wxObject(const wxObject& other)
412 {
413 InitFrom(other);
414 }
4393b50c 415
a6391d30
GD
416 wxObject& operator=(const wxObject& other)
417 {
418 if ( this != &other )
419 {
420 UnRef();
421 InitFrom(other);
422 }
423 return *this;
424 }
425
0b9ab0bd 426 bool IsKindOf(wxClassInfo *info) const;
c801d85f 427
0b9ab0bd 428
b2edef6f
VZ
429 // Turn on the correct set of new and delete operators
430
431#ifdef _WX_WANT_NEW_SIZET_WXCHAR_INT
cf760e4c 432 void *operator new ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 );
0b9ab0bd 433#endif
27198be4 434
b2edef6f
VZ
435#ifdef _WX_WANT_DELETE_VOID
436 void operator delete ( void * buf );
437#endif
0b9ab0bd 438
b2edef6f
VZ
439#ifdef _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET
440 void operator delete ( void *buf, const char *_fname, size_t _line );
0b9ab0bd 441#endif
76626af2 442
b2edef6f 443#ifdef _WX_WANT_DELETE_VOID_WXCHAR_INT
cf760e4c 444 void operator delete ( void *buf, const wxChar*, int );
b2edef6f 445#endif
8cfc5426 446
b2edef6f 447#ifdef _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT
cf760e4c 448 void *operator new[] ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 );
0b9ab0bd
RL
449#endif
450
b2edef6f
VZ
451#ifdef _WX_WANT_ARRAY_DELETE_VOID
452 void operator delete[] ( void *buf );
0b9ab0bd 453#endif
27198be4 454
b2edef6f 455#ifdef _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT
cf760e4c 456 void operator delete[] (void* buf, const wxChar*, int );
b2edef6f 457#endif
c801d85f 458
807d8487
VZ
459 // ref counted data handling methods
460
461 // get/set
462 wxObjectRefData *GetRefData() const { return m_refData; }
463 void SetRefData(wxObjectRefData *data) { m_refData = data; }
464
465 // make a 'clone' of the object
0b9ab0bd 466 void Ref(const wxObject& clone);
c801d85f 467
807d8487 468 // destroy a reference
0b9ab0bd 469 void UnRef();
c801d85f 470
c801d85f 471protected:
807d8487
VZ
472 // ensure that our data is not shared with anybody else: if we have no
473 // data, it is created using CreateRefData() below, if we have shared data
474 // it is copied using CloneRefData(), otherwise nothing is done
475 void AllocExclusive();
476
477 // both methods must be implemented if Unshare() is used, not pure virtual
478 // only because of the backwards compatibility reasons
479
480 // create a new m_refData
481 virtual wxObjectRefData *CreateRefData() const;
482
483 // create a new m_refData initialized with the given one
b8027888 484 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
807d8487 485
0b9ab0bd 486 wxObjectRefData *m_refData;
c801d85f
KB
487};
488
b2edef6f
VZ
489// ----------------------------------------------------------------------------
490// wxObjectRefData: ref counted data meant to be stored in wxObject
491// ----------------------------------------------------------------------------
c801d85f 492
bddd7a8d 493class WXDLLIMPEXP_BASE wxObjectRefData
0b9ab0bd 494{
bddd7a8d 495 friend class WXDLLIMPEXP_BASE wxObject;
c801d85f
KB
496
497public:
b2edef6f
VZ
498 wxObjectRefData() : m_count(1) { }
499 virtual ~wxObjectRefData() { }
500
501 int GetRefCount() const { return m_count; }
c801d85f 502
c801d85f
KB
503private:
504 int m_count;
505};
506
0b9ab0bd 507
ea1e6c4b
RL
508inline wxObject *wxCheckDynamicCast(wxObject *obj, wxClassInfo *classInfo)
509{
b2edef6f 510 return obj && obj->GetClassInfo()->IsKindOf(classInfo) ? obj : NULL;
ea1e6c4b
RL
511}
512
2d51f067
SC
513#if wxUSE_EXTENDED_RTTI
514class WXDLLIMPEXP_BASE wxDynamicObject : public wxObject
515{
8f2b1cfd 516 friend class WXDLLIMPEXP_BASE wxDynamicClassInfo ;
2d51f067
SC
517public:
518 // instantiates this object with an instance of its superclass
519 wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info) ;
520 ~wxDynamicObject();
521
8f2b1cfd
SC
522 void SetProperty (const wxChar *propertyName, const wxxVariant &value);
523 wxxVariant GetProperty (const wxChar *propertyName) const ;
2d51f067
SC
524
525 // get the runtime identity of this object
526 wxClassInfo *GetClassInfo() const
527 {
f525dc35
JS
528#ifdef _MSC_VER
529 return (wxClassInfo*) m_classInfo;
530#else
7e548f6b 531 return wx_const_cast(wxClassInfo *, m_classInfo);
f525dc35 532#endif
2d51f067
SC
533 }
534
535 wxObject* GetSuperClassInstance() const
536 {
537 return m_superClassInstance ;
538 }
539private :
8f2b1cfd
SC
540 // removes an existing runtime-property
541 void RemoveProperty( const wxChar *propertyName ) ;
542
543 // renames an existing runtime-property
544 void RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName ) ;
545
2d51f067
SC
546 wxObject *m_superClassInstance ;
547 const wxDynamicClassInfo *m_classInfo;
548 struct wxDynamicObjectInternal;
549 wxDynamicObjectInternal *m_data;
550};
551#endif
552
b2edef6f
VZ
553// ----------------------------------------------------------------------------
554// more debugging macros
555// ----------------------------------------------------------------------------
556
7fe7d506 557#ifdef __WXDEBUG__
b2edef6f
VZ
558 #ifndef WXDEBUG_NEW
559 #define WXDEBUG_NEW new(__TFILE__,__LINE__)
560 #endif
561#else // !__WXDEBUG__
562 #define WXDEBUG_NEW new
7fe7d506
JS
563#endif
564
b2edef6f
VZ
565// Redefine new to be the debugging version. This doesn't work with all
566// compilers, in which case you need to use WXDEBUG_NEW explicitly if you wish
567// to use the debugging version.
7fe7d506
JS
568
569#if defined(__WXDEBUG__) && wxUSE_GLOBAL_MEMORY_OPERATORS && wxUSE_DEBUG_NEW_ALWAYS
b2edef6f 570 #define new new(__TFILE__,__LINE__)
70dfc4ed 571#elif (defined(__WXDEBUG__) && defined(__VISUALC__) && !wxUSE_GLOBAL_MEMORY_OPERATORS && wxUSE_DEBUG_NEW_ALWAYS)
c86abb56
JS
572 // Including this file redefines new and allows leak reports to contain line numbers
573 #include "wx/msw/msvcrt.h"
c801d85f
KB
574#endif
575
0b9ab0bd 576#endif // _WX_OBJECTH__
c801d85f 577