Fix wxStandardDialogLayoutAdapter compilation with wxUSE_BUTTON==0.
[wxWidgets.git] / include / wx / object.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/object.h
3 // Purpose: wxObject class, plus run-time type information macros
4 // Author: Julian Smart
5 // Modified by: Ron Lee
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) 1997 Julian Smart
9 // (c) 2001 Ron Lee <ron@debian.org>
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef _WX_OBJECTH__
14 #define _WX_OBJECTH__
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #include "wx/memory.h"
21
22 class WXDLLIMPEXP_FWD_BASE wxObject;
23 class WXDLLIMPEXP_FWD_BASE wxString;
24
25 #ifndef wxUSE_EXTENDED_RTTI
26 #define wxUSE_EXTENDED_RTTI 0
27 #endif
28
29 #define wxDECLARE_CLASS_INFO_ITERATORS() \
30 class WXDLLIMPEXP_BASE const_iterator \
31 { \
32 typedef wxHashTable_Node Node; \
33 public: \
34 typedef const wxClassInfo* value_type; \
35 typedef const value_type& const_reference; \
36 typedef const_iterator itor; \
37 typedef value_type* ptr_type; \
38 \
39 Node* m_node; \
40 wxHashTable* m_table; \
41 public: \
42 typedef const_reference reference_type; \
43 typedef ptr_type pointer_type; \
44 \
45 const_iterator(Node* node, wxHashTable* table) \
46 : m_node(node), m_table(table) { } \
47 const_iterator() : m_node(NULL), m_table(NULL) { } \
48 value_type operator*() const; \
49 itor& operator++(); \
50 const itor operator++(int); \
51 bool operator!=(const itor& it) const \
52 { return it.m_node != m_node; } \
53 bool operator==(const itor& it) const \
54 { return it.m_node == m_node; } \
55 }; \
56 \
57 static const_iterator begin_classinfo(); \
58 static const_iterator end_classinfo()
59
60 #if wxUSE_EXTENDED_RTTI
61 #include "wx/xti.h"
62 #else
63
64 // ----------------------------------------------------------------------------
65 // conditional compilation
66 // ----------------------------------------------------------------------------
67
68 class WXDLLIMPEXP_FWD_BASE wxClassInfo;
69 class WXDLLIMPEXP_FWD_BASE wxHashTable;
70 class WXDLLIMPEXP_FWD_BASE wxObject;
71 class WXDLLIMPEXP_FWD_BASE wxPluginLibrary;
72 class WXDLLIMPEXP_FWD_BASE wxHashTable_Node;
73
74 // ----------------------------------------------------------------------------
75 // wxClassInfo
76 // ----------------------------------------------------------------------------
77
78 typedef wxObject *(*wxObjectConstructorFn)(void);
79
80 class WXDLLIMPEXP_BASE wxClassInfo
81 {
82 friend class WXDLLIMPEXP_FWD_BASE wxObject;
83 friend WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxString& name);
84 public:
85 wxClassInfo( const wxChar *className,
86 const wxClassInfo *baseInfo1,
87 const wxClassInfo *baseInfo2,
88 int size,
89 wxObjectConstructorFn ctor )
90 : m_className(className)
91 , m_objectSize(size)
92 , m_objectConstructor(ctor)
93 , m_baseInfo1(baseInfo1)
94 , m_baseInfo2(baseInfo2)
95 , m_next(sm_first)
96 {
97 sm_first = this;
98 Register();
99 }
100
101 ~wxClassInfo();
102
103 wxObject *CreateObject() const
104 { return m_objectConstructor ? (*m_objectConstructor)() : 0; }
105 bool IsDynamic() const { return (NULL != m_objectConstructor); }
106
107 const wxChar *GetClassName() const { return m_className; }
108 const wxChar *GetBaseClassName1() const
109 { return m_baseInfo1 ? m_baseInfo1->GetClassName() : NULL; }
110 const wxChar *GetBaseClassName2() const
111 { return m_baseInfo2 ? m_baseInfo2->GetClassName() : NULL; }
112 const wxClassInfo *GetBaseClass1() const { return m_baseInfo1; }
113 const wxClassInfo *GetBaseClass2() const { return m_baseInfo2; }
114 int GetSize() const { return m_objectSize; }
115
116 wxObjectConstructorFn GetConstructor() const
117 { return m_objectConstructor; }
118 static const wxClassInfo *GetFirst() { return sm_first; }
119 const wxClassInfo *GetNext() const { return m_next; }
120 static wxClassInfo *FindClass(const wxString& className);
121
122 // Climb upwards through inheritance hierarchy.
123 // Dual inheritance is catered for.
124
125 bool IsKindOf(const wxClassInfo *info) const
126 {
127 return info != 0 &&
128 ( info == this ||
129 ( m_baseInfo1 && m_baseInfo1->IsKindOf(info) ) ||
130 ( m_baseInfo2 && m_baseInfo2->IsKindOf(info) ) );
131 }
132
133 wxDECLARE_CLASS_INFO_ITERATORS();
134
135 private:
136 const wxChar *m_className;
137 int m_objectSize;
138 wxObjectConstructorFn m_objectConstructor;
139
140 // Pointers to base wxClassInfos
141
142 const wxClassInfo *m_baseInfo1;
143 const wxClassInfo *m_baseInfo2;
144
145 // class info object live in a linked list:
146 // pointers to its head and the next element in it
147
148 static wxClassInfo *sm_first;
149 wxClassInfo *m_next;
150
151 static wxHashTable *sm_classTable;
152
153 protected:
154 // registers the class
155 void Register();
156 void Unregister();
157
158 wxDECLARE_NO_COPY_CLASS(wxClassInfo);
159 };
160
161 WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxString& name);
162
163 // ----------------------------------------------------------------------------
164 // Dynamic class macros
165 // ----------------------------------------------------------------------------
166
167 #define wxDECLARE_ABSTRACT_CLASS(name) \
168 public: \
169 static wxClassInfo ms_classInfo; \
170 virtual wxClassInfo *GetClassInfo() const
171
172 #define wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
173 wxDECLARE_NO_ASSIGN_CLASS(name); \
174 wxDECLARE_DYNAMIC_CLASS(name)
175
176 #define wxDECLARE_DYNAMIC_CLASS_NO_COPY(name) \
177 wxDECLARE_NO_COPY_CLASS(name); \
178 wxDECLARE_DYNAMIC_CLASS(name)
179
180 #define wxDECLARE_DYNAMIC_CLASS(name) \
181 wxDECLARE_ABSTRACT_CLASS(name); \
182 static wxObject* wxCreateObject()
183
184 #define wxDECLARE_CLASS(name) \
185 wxDECLARE_DYNAMIC_CLASS(name)
186
187
188 // common part of the macros below
189 #define wxIMPLEMENT_CLASS_COMMON(name, basename, baseclsinfo2, func) \
190 wxClassInfo name::ms_classInfo(wxT(#name), \
191 &basename::ms_classInfo, \
192 baseclsinfo2, \
193 (int) sizeof(name), \
194 func); \
195 \
196 wxClassInfo *name::GetClassInfo() const \
197 { return &name::ms_classInfo; }
198
199 #define wxIMPLEMENT_CLASS_COMMON1(name, basename, func) \
200 wxIMPLEMENT_CLASS_COMMON(name, basename, NULL, func)
201
202 #define wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, func) \
203 wxIMPLEMENT_CLASS_COMMON(name, basename1, &basename2::ms_classInfo, func)
204
205 // -----------------------------------
206 // for concrete classes
207 // -----------------------------------
208
209 // Single inheritance with one base class
210 #define wxIMPLEMENT_DYNAMIC_CLASS(name, basename) \
211 wxIMPLEMENT_CLASS_COMMON1(name, basename, name::wxCreateObject) \
212 wxObject* name::wxCreateObject() \
213 { return new name; }
214
215 // Multiple inheritance with two base classes
216 #define wxIMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
217 wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, \
218 name::wxCreateObject) \
219 wxObject* name::wxCreateObject() \
220 { return new name; }
221
222 // -----------------------------------
223 // for abstract classes
224 // -----------------------------------
225
226 // Single inheritance with one base class
227 #define wxIMPLEMENT_ABSTRACT_CLASS(name, basename) \
228 wxIMPLEMENT_CLASS_COMMON1(name, basename, NULL)
229
230 // Multiple inheritance with two base classes
231 #define wxIMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
232 wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, NULL)
233
234 #define wxIMPLEMENT_CLASS(name, basename) \
235 wxIMPLEMENT_ABSTRACT_CLASS(name, basename)
236
237 #define wxIMPLEMENT_CLASS2(name, basename1, basename2) \
238 IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2)
239
240 #endif // !wxUSE_EXTENDED_RTTI
241
242
243 // -----------------------------------
244 // for pluggable classes
245 // -----------------------------------
246
247 // NOTE: this should probably be the very first statement
248 // in the class declaration so wxPluginSentinel is
249 // the first member initialised and the last destroyed.
250
251 // _DECLARE_DL_SENTINEL(name) wxPluginSentinel m_pluginsentinel;
252
253 #if wxUSE_NESTED_CLASSES
254
255 #define _DECLARE_DL_SENTINEL(name, exportdecl) \
256 class exportdecl name##PluginSentinel { \
257 private: \
258 static const wxString sm_className; \
259 public: \
260 name##PluginSentinel(); \
261 ~name##PluginSentinel(); \
262 }; \
263 name##PluginSentinel m_pluginsentinel
264
265 #define _IMPLEMENT_DL_SENTINEL(name) \
266 const wxString name::name##PluginSentinel::sm_className(#name); \
267 name::name##PluginSentinel::name##PluginSentinel() { \
268 wxPluginLibrary *e = (wxPluginLibrary*) wxPluginLibrary::ms_classes.Get(#name); \
269 if( e != 0 ) { e->RefObj(); } \
270 } \
271 name::name##PluginSentinel::~name##PluginSentinel() { \
272 wxPluginLibrary *e = (wxPluginLibrary*) wxPluginLibrary::ms_classes.Get(#name); \
273 if( e != 0 ) { e->UnrefObj(); } \
274 }
275 #else
276
277 #define _DECLARE_DL_SENTINEL(name)
278 #define _IMPLEMENT_DL_SENTINEL(name)
279
280 #endif // wxUSE_NESTED_CLASSES
281
282 #define wxDECLARE_PLUGGABLE_CLASS(name) \
283 wxDECLARE_DYNAMIC_CLASS(name); _DECLARE_DL_SENTINEL(name, WXDLLIMPEXP_CORE)
284 #define wxDECLARE_ABSTRACT_PLUGGABLE_CLASS(name) \
285 wxDECLARE_ABSTRACT_CLASS(name); _DECLARE_DL_SENTINEL(name, WXDLLIMPEXP_CORE)
286
287 #define wxDECLARE_USER_EXPORTED_PLUGGABLE_CLASS(name, usergoo) \
288 wxDECLARE_DYNAMIC_CLASS(name); _DECLARE_DL_SENTINEL(name, usergoo)
289 #define wxDECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, usergoo) \
290 wxDECLARE_ABSTRACT_CLASS(name); _DECLARE_DL_SENTINEL(name, usergoo)
291
292 #define wxIMPLEMENT_PLUGGABLE_CLASS(name, basename) \
293 wxIMPLEMENT_DYNAMIC_CLASS(name, basename) _IMPLEMENT_DL_SENTINEL(name)
294 #define wxIMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2) \
295 wxIMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) _IMPLEMENT_DL_SENTINEL(name)
296 #define wxIMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename) \
297 wxIMPLEMENT_ABSTRACT_CLASS(name, basename) _IMPLEMENT_DL_SENTINEL(name)
298 #define wxIMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) \
299 wxIMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) _IMPLEMENT_DL_SENTINEL(name)
300
301 #define wxIMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS(name, basename) \
302 wxIMPLEMENT_PLUGGABLE_CLASS(name, basename)
303 #define wxIMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS2(name, basename1, basename2) \
304 wxIMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2)
305 #define wxIMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, basename) \
306 wxIMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename)
307 #define wxIMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) \
308 wxIMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2)
309
310 #define wxCLASSINFO(name) (&name::ms_classInfo)
311
312 #define wxIS_KIND_OF(obj, className) obj->IsKindOf(&className::ms_classInfo)
313
314 // Just seems a bit nicer-looking (pretend it's not a macro)
315 #define wxIsKindOf(obj, className) obj->IsKindOf(&className::ms_classInfo)
316
317 // this cast does some more checks at compile time as it uses static_cast
318 // internally
319 //
320 // note that it still has different semantics from dynamic_cast<> and so can't
321 // be replaced by it as long as there are any compilers not supporting it
322 #define wxDynamicCast(obj, className) \
323 ((className *) wxCheckDynamicCast( \
324 const_cast<wxObject *>(static_cast<const wxObject *>(\
325 const_cast<className *>(static_cast<const className *>(obj)))), \
326 &className::ms_classInfo))
327
328 // The 'this' pointer is always true, so use this version
329 // to cast the this pointer and avoid compiler warnings.
330 #define wxDynamicCastThis(className) \
331 (IsKindOf(&className::ms_classInfo) ? (className *)(this) : (className *)0)
332
333 // FIXME-VC6: dummy argument needed because VC6 doesn't support explicitly
334 // choosing the template function to call
335 template <class T>
336 inline T *wxCheckCast(const void *ptr, T * = NULL)
337 {
338 wxASSERT_MSG( wxDynamicCast(ptr, T), "wxStaticCast() used incorrectly" );
339 return const_cast<T *>(static_cast<const T *>(ptr));
340 }
341
342 #define wxStaticCast(obj, className) wxCheckCast((obj), (className *)NULL)
343
344 // ----------------------------------------------------------------------------
345 // set up memory debugging macros
346 // ----------------------------------------------------------------------------
347
348 /*
349 Which new/delete operator variants do we want?
350
351 _WX_WANT_NEW_SIZET_WXCHAR_INT = void *operator new (size_t size, wxChar *fileName = 0, int lineNum = 0)
352 _WX_WANT_DELETE_VOID = void operator delete (void * buf)
353 _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET = void operator delete (void *buf, const char *_fname, size_t _line)
354 _WX_WANT_DELETE_VOID_WXCHAR_INT = void operator delete(void *buf, wxChar*, int)
355 _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT = void *operator new[] (size_t size, wxChar *fileName , int lineNum = 0)
356 _WX_WANT_ARRAY_DELETE_VOID = void operator delete[] (void *buf)
357 _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT = void operator delete[] (void* buf, wxChar*, int )
358 */
359
360 #if wxUSE_MEMORY_TRACING
361
362 // All compilers get this one
363 #define _WX_WANT_NEW_SIZET_WXCHAR_INT
364
365 // Everyone except Visage gets the next one
366 #ifndef __VISAGECPP__
367 #define _WX_WANT_DELETE_VOID
368 #endif
369
370 // Only visage gets this one under the correct circumstances
371 #if defined(__VISAGECPP__) && __DEBUG_ALLOC__
372 #define _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET
373 #endif
374
375 // Only VC++ 6 and CodeWarrior get overloaded delete that matches new
376 #if (defined(__VISUALC__) && (__VISUALC__ >= 1200)) || \
377 (defined(__MWERKS__) && (__MWERKS__ >= 0x2400))
378 #define _WX_WANT_DELETE_VOID_WXCHAR_INT
379 #endif
380
381 // Now see who (if anyone) gets the array memory operators
382 #if wxUSE_ARRAY_MEMORY_OPERATORS
383
384 // Everyone except Visual C++ (cause problems for VC++ - crashes)
385 #if !defined(__VISUALC__)
386 #define _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT
387 #endif
388
389 // Everyone except Visual C++ (cause problems for VC++ - crashes)
390 #if !defined(__VISUALC__)
391 #define _WX_WANT_ARRAY_DELETE_VOID
392 #endif
393
394 // Only CodeWarrior 6 or higher
395 #if defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
396 #define _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT
397 #endif
398
399 #endif // wxUSE_ARRAY_MEMORY_OPERATORS
400
401 #endif // wxUSE_MEMORY_TRACING
402
403 // ----------------------------------------------------------------------------
404 // wxRefCounter: ref counted data "manager"
405 // ----------------------------------------------------------------------------
406
407 class WXDLLIMPEXP_BASE wxRefCounter
408 {
409 public:
410 wxRefCounter() { m_count = 1; }
411
412 int GetRefCount() const { return m_count; }
413
414 void IncRef() { m_count++; }
415 void DecRef();
416
417 protected:
418 // this object should never be destroyed directly but only as a
419 // result of a DecRef() call:
420 virtual ~wxRefCounter() { }
421
422 private:
423 // our refcount:
424 int m_count;
425 };
426
427 // ----------------------------------------------------------------------------
428 // wxObjectRefData: ref counted data meant to be stored in wxObject
429 // ----------------------------------------------------------------------------
430
431 typedef wxRefCounter wxObjectRefData;
432
433
434 // ----------------------------------------------------------------------------
435 // wxObjectDataPtr: helper class to avoid memleaks because of missing calls
436 // to wxObjectRefData::DecRef
437 // ----------------------------------------------------------------------------
438
439 template <class T>
440 class wxObjectDataPtr
441 {
442 public:
443 typedef T element_type;
444
445 wxEXPLICIT wxObjectDataPtr(T *ptr = NULL) : m_ptr(ptr) {}
446
447 // copy ctor
448 wxObjectDataPtr(const wxObjectDataPtr<T> &tocopy)
449 : m_ptr(tocopy.m_ptr)
450 {
451 if (m_ptr)
452 m_ptr->IncRef();
453 }
454
455 ~wxObjectDataPtr()
456 {
457 if (m_ptr)
458 m_ptr->DecRef();
459 }
460
461 T *get() const { return m_ptr; }
462
463 // test for pointer validity: defining conversion to unspecified_bool_type
464 // and not more obvious bool to avoid implicit conversions to integer types
465 typedef T *(wxObjectDataPtr<T>::*unspecified_bool_type)() const;
466 operator unspecified_bool_type() const
467 {
468 return m_ptr ? &wxObjectDataPtr<T>::get : NULL;
469 }
470
471 T& operator*() const
472 {
473 wxASSERT(m_ptr != NULL);
474 return *(m_ptr);
475 }
476
477 T *operator->() const
478 {
479 wxASSERT(m_ptr != NULL);
480 return get();
481 }
482
483 void reset(T *ptr)
484 {
485 if (m_ptr)
486 m_ptr->DecRef();
487 m_ptr = ptr;
488 }
489
490 wxObjectDataPtr& operator=(const wxObjectDataPtr &tocopy)
491 {
492 if (m_ptr)
493 m_ptr->DecRef();
494 m_ptr = tocopy.m_ptr;
495 if (m_ptr)
496 m_ptr->IncRef();
497 return *this;
498 }
499
500 wxObjectDataPtr& operator=(T *ptr)
501 {
502 if (m_ptr)
503 m_ptr->DecRef();
504 m_ptr = ptr;
505 return *this;
506 }
507
508 private:
509 T *m_ptr;
510 };
511
512 // ----------------------------------------------------------------------------
513 // wxObject: the root class of wxWidgets object hierarchy
514 // ----------------------------------------------------------------------------
515
516 class WXDLLIMPEXP_BASE wxObject
517 {
518 wxDECLARE_ABSTRACT_CLASS(wxObject);
519
520 public:
521 wxObject() { m_refData = NULL; }
522 virtual ~wxObject() { UnRef(); }
523
524 wxObject(const wxObject& other)
525 {
526 m_refData = other.m_refData;
527 if (m_refData)
528 m_refData->IncRef();
529 }
530
531 wxObject& operator=(const wxObject& other)
532 {
533 if ( this != &other )
534 {
535 Ref(other);
536 }
537 return *this;
538 }
539
540 bool IsKindOf(const wxClassInfo *info) const;
541
542
543 // Turn on the correct set of new and delete operators
544
545 #ifdef _WX_WANT_NEW_SIZET_WXCHAR_INT
546 void *operator new ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 );
547 #endif
548
549 #ifdef _WX_WANT_DELETE_VOID
550 void operator delete ( void * buf );
551 #endif
552
553 #ifdef _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET
554 void operator delete ( void *buf, const char *_fname, size_t _line );
555 #endif
556
557 #ifdef _WX_WANT_DELETE_VOID_WXCHAR_INT
558 void operator delete ( void *buf, const wxChar*, int );
559 #endif
560
561 #ifdef _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT
562 void *operator new[] ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 );
563 #endif
564
565 #ifdef _WX_WANT_ARRAY_DELETE_VOID
566 void operator delete[] ( void *buf );
567 #endif
568
569 #ifdef _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT
570 void operator delete[] (void* buf, const wxChar*, int );
571 #endif
572
573 // ref counted data handling methods
574
575 // get/set
576 wxObjectRefData *GetRefData() const { return m_refData; }
577 void SetRefData(wxObjectRefData *data) { m_refData = data; }
578
579 // make a 'clone' of the object
580 void Ref(const wxObject& clone);
581
582 // destroy a reference
583 void UnRef();
584
585 // Make sure this object has only one reference
586 void UnShare() { AllocExclusive(); }
587
588 // check if this object references the same data as the other one
589 bool IsSameAs(const wxObject& o) const { return m_refData == o.m_refData; }
590
591 protected:
592 // ensure that our data is not shared with anybody else: if we have no
593 // data, it is created using CreateRefData() below, if we have shared data
594 // it is copied using CloneRefData(), otherwise nothing is done
595 void AllocExclusive();
596
597 // both methods must be implemented if AllocExclusive() is used, not pure
598 // virtual only because of the backwards compatibility reasons
599
600 // create a new m_refData
601 virtual wxObjectRefData *CreateRefData() const;
602
603 // create a new m_refData initialized with the given one
604 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
605
606 wxObjectRefData *m_refData;
607 };
608
609 inline wxObject *wxCheckDynamicCast(wxObject *obj, wxClassInfo *classInfo)
610 {
611 return obj && obj->GetClassInfo()->IsKindOf(classInfo) ? obj : NULL;
612 }
613
614 #if wxUSE_EXTENDED_RTTI
615 class WXDLLIMPEXP_BASE wxDynamicObject : public wxObject
616 {
617 friend class WXDLLIMPEXP_FWD_BASE wxDynamicClassInfo ;
618 public:
619 // instantiates this object with an instance of its superclass
620 wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info) ;
621 virtual ~wxDynamicObject();
622
623 void SetProperty (const wxChar *propertyName, const wxxVariant &value);
624 wxxVariant GetProperty (const wxChar *propertyName) const ;
625
626 // get the runtime identity of this object
627 wxClassInfo *GetClassInfo() const
628 {
629 #ifdef _MSC_VER
630 return (wxClassInfo*) m_classInfo;
631 #else
632 wxDynamicClassInfo *nonconst = const_cast<wxDynamicClassInfo *>(m_classInfo);
633 return static_cast<wxClassInfo *>(nonconst);
634 #endif
635 }
636
637 wxObject* GetSuperClassInstance() const
638 {
639 return m_superClassInstance ;
640 }
641 private :
642 // removes an existing runtime-property
643 void RemoveProperty( const wxChar *propertyName ) ;
644
645 // renames an existing runtime-property
646 void RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName ) ;
647
648 wxObject *m_superClassInstance ;
649 const wxDynamicClassInfo *m_classInfo;
650 struct wxDynamicObjectInternal;
651 wxDynamicObjectInternal *m_data;
652 };
653 #endif
654
655 // ----------------------------------------------------------------------------
656 // more debugging macros
657 // ----------------------------------------------------------------------------
658
659 #if wxUSE_DEBUG_NEW_ALWAYS
660 #define WXDEBUG_NEW new(__TFILE__,__LINE__)
661
662 #if wxUSE_GLOBAL_MEMORY_OPERATORS
663 #define new WXDEBUG_NEW
664 #elif defined(__VISUALC__)
665 // Including this file redefines new and allows leak reports to
666 // contain line numbers
667 #include "wx/msw/msvcrt.h"
668 #endif
669 #endif // wxUSE_DEBUG_NEW_ALWAYS
670
671 // ----------------------------------------------------------------------------
672 // Compatibility macro aliases
673 // ----------------------------------------------------------------------------
674
675 // deprecated variants _not_ requiring a semicolon after them and without wx prefix.
676 // (note that also some wx-prefixed macro do _not_ require a semicolon because
677 // it's not always possible to force the compire to require it)
678
679 #define DECLARE_CLASS_INFO_ITERATORS() wxDECLARE_CLASS_INFO_ITERATORS();
680 #define DECLARE_ABSTRACT_CLASS(n) wxDECLARE_ABSTRACT_CLASS(n);
681 #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(n) wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(n);
682 #define DECLARE_DYNAMIC_CLASS_NO_COPY(n) wxDECLARE_DYNAMIC_CLASS_NO_COPY(n);
683 #define DECLARE_DYNAMIC_CLASS(n) wxDECLARE_DYNAMIC_CLASS(n);
684 #define DECLARE_CLASS(n) wxDECLARE_CLASS(n);
685
686 #define IMPLEMENT_DYNAMIC_CLASS(n,b) wxIMPLEMENT_DYNAMIC_CLASS(n,b)
687 #define IMPLEMENT_DYNAMIC_CLASS2(n,b1,b2) wxIMPLEMENT_DYNAMIC_CLASS2(n,b1,b2)
688 #define IMPLEMENT_ABSTRACT_CLASS(n,b) wxIMPLEMENT_ABSTRACT_CLASS(n,b)
689 #define IMPLEMENT_ABSTRACT_CLASS2(n,b1,b2) wxIMPLEMENT_ABSTRACT_CLASS2(n,b1,b2)
690 #define IMPLEMENT_CLASS(n,b) wxIMPLEMENT_CLASS(n,b)
691 #define IMPLEMENT_CLASS2(n,b1,b2) wxIMPLEMENT_CLASS2(n,b1,b2)
692
693 #define DECLARE_PLUGGABLE_CLASS(n) wxDECLARE_PLUGGABLE_CLASS(n);
694 #define DECLARE_ABSTRACT_PLUGGABLE_CLASS(n) wxDECLARE_ABSTRACT_PLUGGABLE_CLASS(n);
695 #define DECLARE_USER_EXPORTED_PLUGGABLE_CLASS(n,u) wxDECLARE_USER_EXPORTED_PLUGGABLE_CLASS(n,u);
696 #define DECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(n,u) wxDECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(n,u);
697
698 #define IMPLEMENT_PLUGGABLE_CLASS(n,b) wxIMPLEMENT_PLUGGABLE_CLASS(n,b)
699 #define IMPLEMENT_PLUGGABLE_CLASS2(n,b,b2) wxIMPLEMENT_PLUGGABLE_CLASS2(n,b,b2)
700 #define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(n,b) wxIMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(n,b)
701 #define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(n,b,b2) wxIMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(n,b,b2)
702 #define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS(n,b) wxIMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS(n,b)
703 #define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS2(n,b,b2) wxIMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS2(n,b,b2)
704 #define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(n,b) wxIMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(n,b)
705 #define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS2(n,b,b2) wxIMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS2(n,b,b2)
706
707 #define CLASSINFO(n) wxCLASSINFO(n)
708
709 #endif // _WX_OBJECTH__