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