added flag for broken compilers with regard to templated getters/setters resolution...
[wxWidgets.git] / include / wx / xti.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/xti.h
3 // Purpose: runtime metadata information (extended class info)
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 27/07/03
7 // RCS-ID: $Id$
8 // Copyright: (c) 1997 Julian Smart
9 // (c) 2003 Stefan Csomor
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef _WX_XTIH__
14 #define _WX_XTIH__
15
16 #if defined(__GNUG__) && !defined(__APPLE__)
17 #pragma interface "xti.h"
18 #endif
19
20 // We want to support properties, event sources and events sinks through
21 // explicit declarations, using templates and specialization to make the
22 // effort as painless as possible.
23 //
24 // This means we have the following domains :
25 //
26 // - Type Information for categorizing built in types as well as custom types
27 // this includes information about enums, their values and names
28 // - Type safe value storage : a kind of wxVariant, called right now wxxVariant
29 // which will be merged with wxVariant
30 // - Property Information and Property Accessors providing access to a class'
31 // values and exposed event delegates
32 // - Information about event handlers
33 // - extended Class Information for accessing all these
34
35 // ----------------------------------------------------------------------------
36 // headers
37 // ----------------------------------------------------------------------------
38
39 #include "wx/defs.h"
40 #include "wx/memory.h"
41 #include "wx/set.h"
42 #include "wx/string.h"
43 #include "wx/arrstr.h"
44
45 // some compilers have troubles getting the correct wxPropertyAccessorT constructor
46 // set this to 1 to make things work for these, too
47
48 #define WX_XTI_TEMPLATE_FIX 0
49
50 #if WX_XTI_TEMPLATE_FIX
51 #define WX_XTI_PARAM_FIX(a,b) a,b
52 #else
53 #define WX_XTI_PARAM_FIX(a,b)
54 #endif
55
56 class WXDLLIMPEXP_BASE wxObject;
57 class WXDLLIMPEXP_BASE wxClassInfo;
58 class WXDLLIMPEXP_BASE wxHashTable;
59 class WXDLLIMPEXP_BASE wxObjectRefData;
60 class WXDLLIMPEXP_BASE wxEvent;
61
62 typedef void (wxObject::*wxObjectEventFunction)(wxEvent&);
63
64 // ----------------------------------------------------------------------------
65 // Enum Support
66 //
67 // In the header files there would no change from pure c++ code, in the
68 // implementation, an enum would have
69 // to be enumerated eg :
70 //
71 // WX_BEGIN_ENUM( wxFlavor )
72 // WX_ENUM_MEMBER( Vanilla )
73 // WX_ENUM_MEMBER( Chocolate )
74 // WX_ENUM_MEMBER( Strawberry )
75 // WX_END_ENUM( wxFlavor )
76 // ----------------------------------------------------------------------------
77
78 struct WXDLLIMPEXP_BASE wxEnumMemberData
79 {
80 const wxChar* m_name;
81 int m_value;
82 };
83
84 class WXDLLIMPEXP_BASE wxEnumData
85 {
86 public :
87 wxEnumData( wxEnumMemberData* data ) ;
88
89 // returns true if the member has been found and sets the int value
90 // pointed to accordingly (if ptr != null )
91 // if not found returns false, value left unchanged
92 bool HasEnumMemberValue( const wxChar *name , int *value = NULL ) ;
93
94 // returns the value of the member, if not found in debug mode an
95 // assert is issued, in release 0 is returned
96 int GetEnumMemberValue(const wxChar *name );
97
98 // returns the name of the enum member having the passed in value
99 // returns an emtpy string if not found
100 const wxChar *GetEnumMemberName(int value);
101
102 // returns the number of members in this enum
103 int GetEnumCount() { return m_count ; }
104
105 // returns the value of the nth member
106 int GetEnumMemberValueByIndex( int n ) ;
107
108 // returns the value of the nth member
109 const wxChar *GetEnumMemberNameByIndex( int n ) ;
110 private :
111 wxEnumMemberData *m_members;
112 int m_count ;
113 };
114
115 #define WX_BEGIN_ENUM( e ) \
116 wxEnumMemberData s_enumDataMembers##e[] = {
117
118 #define WX_ENUM_MEMBER( v ) { #v, v } ,
119
120 #define WX_END_ENUM( e ) { NULL , 0 } } ; \
121 wxEnumData s_enumData##e( s_enumDataMembers##e ) ; \
122 wxEnumData *wxGetEnumData(e) { return &s_enumData##e ; } \
123 template<> const wxTypeInfo* wxGetTypeInfo( e * ){ static wxEnumTypeInfo s_typeInfo(wxT_ENUM , &s_enumData##e) ; return &s_typeInfo ; } \
124 template<> void wxStringReadValue(const wxString& s , e &data ) \
125 { \
126 data = (e) s_enumData##e.GetEnumMemberValue(s) ; \
127 } \
128 template<> void wxStringWriteValue(wxString &s , const e &data ) \
129 { \
130 s = s_enumData##e.GetEnumMemberName((int)data) ; \
131 } \
132 template<> const wxTypeInfo* wxGetTypeInfo( e ** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; assert(0) ; return &s_typeInfo ; } \
133 template<> void wxStringReadValue(const wxString& , e* & ) \
134 { \
135 assert(0) ; \
136 } \
137 template<> void wxStringWriteValue(wxString &s , e* const & ) \
138 { \
139 assert(0) ; \
140 }
141
142 // ----------------------------------------------------------------------------
143 // Set Support
144 //
145 // in the header :
146 //
147 // enum wxFlavor
148 // {
149 // Vanilla,
150 // Chocolate,
151 // Strawberry,
152 // };
153 //
154 // typedef wxSet<wxFlavor> wxCoupe ;
155 //
156 // in the implementation file :
157 //
158 // WX_BEGIN_ENUM( wxFlavor )
159 // WX_ENUM_MEMBER( Vanilla )
160 // WX_ENUM_MEMBER( Chocolate )
161 // WX_ENUM_MEMBER( Strawberry )
162 // WX_END_ENUM( wxFlavor )
163 //
164 // WX_IMPLEMENT_SET_STREAMING( wxCoupe , wxFlavor )
165 //
166 // implementation note : no partial specialization for streaming, but a delegation to a
167 // different class
168 //
169 // ----------------------------------------------------------------------------
170
171 // in order to remove dependancy on string tokenizer
172 void wxSetStringToArray( const wxString &s , wxArrayString &array ) ;
173
174 template<typename e>
175 void wxSetFromString(const wxString &s , wxSet<e> &data )
176 {
177 wxEnumData* edata = wxGetEnumData((e) 0) ;
178 data.Clear() ;
179
180 wxArrayString array ;
181 wxSetStringToArray( s , array ) ;
182 wxString flag;
183 for ( int i = 0 ; i < array.Count() ; ++i )
184 {
185 flag = array[i] ;
186 int ivalue ;
187 if ( edata->HasEnumMemberValue( flag , &ivalue ) )
188 {
189 data.Set( (e) ivalue ) ;
190 }
191 }
192 }
193
194 template<typename e>
195 void wxSetToString( wxString &s , const wxSet<e> &data )
196 {
197 wxEnumData* edata = wxGetEnumData((e) 0) ;
198 int count = edata->GetEnumCount() ;
199 int i ;
200 s.Clear() ;
201 for ( i = 0 ; i < count ; i++ )
202 {
203 e value = (e) edata->GetEnumMemberValueByIndex(i) ;
204 if ( data.Contains( value ) )
205 {
206 // this could also be done by the templated calls
207 if ( !s.IsEmpty() )
208 s +="|" ;
209 s += edata->GetEnumMemberNameByIndex(i) ;
210 }
211 }
212 }
213
214 // if the wxSet specialization above does not work for all compilers, add this to the WX_IMPLEMENT_SET_STREAMING macro
215 // template<> const wxTypeInfo* wxGetTypeInfo( SetName * ){ static wxEnumTypeInfo s_typeInfo(wxT_SET , &s_enumData##e) ; return &s_typeInfo ; }
216
217 #define WX_IMPLEMENT_SET_STREAMING(SetName,e) \
218 template<> void wxStringReadValue(const wxString &s , wxSet<e> &data ) \
219 { \
220 wxSetFromString( s , data ) ; \
221 } \
222 template<> void wxStringWriteValue( wxString &s , const wxSet<e> &data ) \
223 { \
224 wxSetToString( s , data ) ; \
225 } \
226
227
228 // ----------------------------------------------------------------------------
229 // Type Information
230 // ----------------------------------------------------------------------------
231
232 enum wxTypeKind
233 {
234 wxT_VOID = 0, // unknown type
235 wxT_BOOL,
236 wxT_CHAR,
237 wxT_UCHAR,
238 wxT_INT,
239 wxT_UINT,
240 wxT_LONG,
241 wxT_ULONG,
242 wxT_FLOAT,
243 wxT_DOUBLE,
244 wxT_STRING, // must be wxString
245 wxT_SET, // must be wxSet<> template
246 wxT_ENUM,
247 wxT_OBJECT_PTR, // pointer to wxObject
248 wxT_OBJECT , // wxObject
249 wxT_CUSTOM, // user defined type (e.g. wxPoint)
250 wxT_DELEGATE , // for connecting against an event source
251 wxT_LAST_TYPE_KIND // sentinel for bad data, asserts, debugging
252 };
253
254 class WXDLLIMPEXP_BASE wxTypeInfo
255 {
256 public :
257 wxTypeInfo() : m_kind( wxT_VOID) {}
258 virtual ~wxTypeInfo() {}
259 wxTypeKind GetKind() const { return m_kind ; }
260 bool IsDelegateType() const { return m_kind == wxT_DELEGATE ; }
261 bool IsCustomType() const { return m_kind == wxT_CUSTOM ; }
262 bool IsObjectType() const { return m_kind == wxT_OBJECT || m_kind == wxT_OBJECT_PTR ; }
263 protected :
264 wxTypeKind m_kind ;
265 };
266
267 class WXDLLIMPEXP_BASE wxBuiltInTypeInfo : public wxTypeInfo
268 {
269 public :
270 wxBuiltInTypeInfo( wxTypeKind kind ) { wxASSERT_MSG( kind < wxT_SET , wxT("Illegal Kind for Base Type") ) ; m_kind = kind ;}
271 } ;
272
273 class WXDLLIMPEXP_BASE wxCustomTypeInfo : public wxTypeInfo
274 {
275 public :
276 wxCustomTypeInfo( const wxChar *typeName )
277 { m_kind = wxT_CUSTOM ; m_typeName = typeName ;}
278 const wxChar *GetTypeName() const { return m_typeName ; }
279 private :
280 const wxChar *m_typeName; // Kind == wxT_CUSTOM
281 } ;
282
283 class WXDLLIMPEXP_BASE wxEnumTypeInfo : public wxTypeInfo
284 {
285 public :
286 wxEnumTypeInfo( wxTypeKind kind , wxEnumData* enumInfo )
287 { wxASSERT_MSG( kind == wxT_ENUM || kind == wxT_SET , wxT("Illegal Kind for Enum Type")) ; m_kind = kind ; m_enumInfo = enumInfo ;}
288 const wxEnumData* GetEnumData() const { return m_enumInfo ; }
289 private :
290 wxEnumData *m_enumInfo; // Kind == wxT_ENUM or Kind == wxT_SET
291 } ;
292
293 class WXDLLIMPEXP_BASE wxClassTypeInfo : public wxTypeInfo
294 {
295 public :
296 wxClassTypeInfo( wxTypeKind kind , wxClassInfo* classInfo )
297 { wxASSERT_MSG( kind == wxT_OBJECT_PTR || kind == wxT_OBJECT , wxT("Illegal Kind for Enum Type")) ; m_kind = kind ; m_classInfo = classInfo ;}
298 const wxClassInfo *GetClassInfo() const { return m_classInfo ; }
299 private :
300 wxClassInfo *m_classInfo; // Kind == wxT_OBJECT - could be NULL
301 } ;
302
303 // a delegate is an exposed event source
304
305 class WXDLLIMPEXP_BASE wxDelegateTypeInfo : public wxTypeInfo
306 {
307 public :
308 wxDelegateTypeInfo( int eventType , wxClassInfo* eventClass )
309 { m_kind = wxT_DELEGATE ; m_eventClass = eventClass ; m_eventType = eventType ;}
310 const wxClassInfo *GetEventClass() const { assert( m_kind == wxT_DELEGATE ) ; return m_eventClass ; }
311 int GetEventType() const { return m_eventType ; }
312 private :
313 const wxClassInfo *m_eventClass; // (extended will merge into classinfo)
314 int m_eventType ;
315 } ;
316
317 template<typename T> const wxTypeInfo* wxGetTypeInfo( T * ) ;
318
319 template<typename T> const wxTypeInfo* wxGetTypeInfo( wxSet<T> * )
320 {
321 static wxEnumTypeInfo s_typeInfo(wxT_SET , wxGetEnumData((T) 0) ) ; return &s_typeInfo ;
322 }
323
324 // this macro is for usage with custom, non-object derived classes and structs, wxPoint is such a custom type
325
326 #define WX_CUSTOM_TYPE_INFO( e ) \
327 template<> const wxTypeInfo* wxGetTypeInfo( e ** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID) ; assert(0) ; return &s_typeInfo ; } \
328 template<> const wxTypeInfo* wxGetTypeInfo( e * ){ static wxCustomTypeInfo s_typeInfo(#e) ; return &s_typeInfo ; }
329
330 // templated streaming, every type must have their specialization for these methods
331
332 template<typename T>
333 void wxStringReadValue( const wxString &s , T &data );
334
335 template<typename T>
336 void wxStringWriteValue( wxString &s , const T &data);
337
338 // sometimes a compiler invents specializations that are nowhere called, use this macro to satisfy the refs
339
340 #define WX_ILLEGAL_TYPE_SPECIALIZATION( a ) \
341 template<> const wxTypeInfo* wxGetTypeInfo( a * ) { assert(0) ; \
342 static wxBuiltInTypeInfo s_typeInfo( wxT_VOID ) ; return &s_typeInfo ; } \
343 template<> void wxStringReadValue(const wxString & , a & ) { assert(0) ; }\
344 template<> void wxStringWriteValue(wxString & , a const & ) { assert(0) ; }
345
346 // ----------------------------------------------------------------------------
347 // wxxVariant as typesafe data holder
348 // ----------------------------------------------------------------------------
349
350 class WXDLLIMPEXP_BASE wxxVariantData
351 {
352 public:
353 virtual ~wxxVariantData() {}
354
355 // return a heap allocated duplicate
356 virtual wxxVariantData* Clone() const = 0 ;
357
358 // returns the type info of the contentc
359 virtual const wxTypeInfo* GetTypeInfo() const = 0 ;
360
361 // write the value into a string
362 virtual void Write( wxString &s ) const = 0 ;
363
364 // read the value from a string
365 virtual void Read( const wxString &s) = 0 ;
366 } ;
367
368 template<typename T> class WXDLLIMPEXP_BASE wxxVariantDataT : public wxxVariantData
369 {
370 public:
371 wxxVariantDataT(const T& d) : m_data(d) {}
372 virtual ~wxxVariantDataT() {}
373
374 // get a ref to the stored data
375 T & Get() { return m_data; }
376
377 // get a const ref to the stored data
378 const T & Get() const { return m_data; }
379
380 // set the data
381 void Set(const T& d) { m_data = d; }
382
383 // return a heap allocated duplicate
384 virtual wxxVariantData* Clone() const { return new wxxVariantDataT<T>( Get() ) ; }
385
386 // returns the type info of the contentc
387 virtual const wxTypeInfo* GetTypeInfo() const { return wxGetTypeInfo( (T*) NULL ) ; }
388
389 // write the value into a string
390 virtual void Write( wxString &s ) const { wxStringWriteValue( s , m_data ) ; }
391
392 // read the value from a string
393 virtual void Read( const wxString &s) { wxStringReadValue( s , m_data ) ; }
394
395 private:
396 T m_data;
397 };
398
399 class WXDLLIMPEXP_BASE wxxVariant
400 {
401 public :
402 wxxVariant() { m_data = NULL ; }
403 wxxVariant( wxxVariantData* data , const wxString& name = wxT("") ) : m_data(data) , m_name(name) {}
404 wxxVariant( const wxxVariant &d ) { if ( d.m_data ) m_data = d.m_data->Clone() ; else m_data = NULL ; m_name = d.m_name ; }
405
406 template<typename T> wxxVariant( T data , const wxString& name = wxT("") ) :
407 m_data(new wxxVariantDataT<T>(data) ), m_name(name) {}
408 ~wxxVariant() { delete m_data ; }
409
410 // get a ref to the stored data
411 template<typename T> T& Get()
412 {
413 wxxVariantDataT<T> *dataptr = dynamic_cast<wxxVariantDataT<T>*> (m_data) ;
414 wxASSERT_MSG( dataptr , "Cast not possible" ) ;
415 return dataptr->Get() ;
416 }
417
418 // get a ref to the stored data
419 template<typename T> const T& Get() const
420 {
421 const wxxVariantDataT<T> *dataptr = dynamic_cast<const wxxVariantDataT<T>*> (m_data) ;
422 wxASSERT_MSG( dataptr , "Cast not possible" ) ;
423 return dataptr->Get() ;
424 }
425
426 // stores the data
427 template<typename T> void Set(const T& data) const
428 {
429 delete m_data ;
430 m_data = new wxxVariantDataT<T>(data) ;
431 }
432
433 wxxVariant& operator=(const wxxVariant &d)
434 {
435 m_data = d.m_data->Clone() ;
436 m_name = d.m_name ;
437 return *this ;
438 }
439
440 // gets the stored data casted to a wxObject* , returning NULL if cast is not possible
441 wxObject* GetAsObject() ;
442
443 // get the typeinfo of the stored object
444 const wxTypeInfo* GetTypeInfo() const { return m_data->GetTypeInfo() ; }
445
446 // write the value into a string
447 void Write( wxString &s ) const { m_data->Write( s ) ; }
448
449 // read the value from a string
450 void Read( const wxString &s) { m_data->Read( s ) ; }
451
452 // returns this value as string
453 wxString GetAsString() const
454 {
455 wxString s ;
456 Write( s ) ;
457 return s ;
458 }
459
460 void SetFromString( const wxString &s)
461 {
462 Read( s ) ;
463 }
464 private :
465 wxxVariantData* m_data ;
466 wxString m_name ;
467 } ;
468
469 // ----------------------------------------------------------------------------
470 // Property Support
471 //
472 // wxPropertyInfo is used to inquire of the property by name. It doesn't
473 // provide access to the property, only information about it. If you
474 // want access, look at wxPropertyAccessor.
475 // ----------------------------------------------------------------------------
476
477 class WXDLLIMPEXP_BASE wxPropertyAccessor
478 {
479 public :
480 #if WX_XTI_TEMPLATE_FIX
481 class SetByRef ;
482 class SetByRefRetBool ;
483 class SetRetBool ;
484 class SetAndGetByRef ;
485 class SetAndGetByRefRetBool ;
486 class GetByRef ;
487 #endif
488 virtual void SetProperty(wxObject *object, const wxxVariant &value) const = 0 ;
489 virtual wxxVariant GetProperty(const wxObject *object) const = 0 ;
490 virtual bool HasSetter() const = 0 ;
491 virtual bool HasGetter() const = 0 ;
492 const wxChar * GetGetterName() const { return m_setterName ; }
493 const wxChar * GetSetterName() const { return m_getterName ; }
494 virtual wxxVariant ReadValue( const wxString &value ) const = 0 ;
495 virtual void WriteValue( wxString& value , const wxObject *o ) const = 0 ;
496 protected :
497 const wxChar *m_setterName ;
498 const wxChar *m_getterName ;
499 };
500
501 template<class Klass, typename T>
502 class WXDLLIMPEXP_BASE wxPropertyAccessorT : public wxPropertyAccessor
503 {
504 public:
505
506 typedef void (Klass::*setter_t)(T value);
507 typedef bool (Klass::*setter_bool_t)(T value);
508 typedef void (Klass::*setter_ref_t)(const T& value);
509 typedef bool (Klass::*setter_ref_bool_t)(const T& value);
510 typedef T (Klass::*getter_t)() const;
511 typedef const T& (Klass::*getter_ref_t)() const;
512
513 wxPropertyAccessorT(setter_t setter, getter_t getter, const wxChar *g, const wxChar *s)
514 : m_setter_bool( NULL ) , m_setter_ref_bool( NULL ) , m_setter(setter), m_setter_ref(NULL), m_getter(getter) ,m_getter_ref(NULL) {m_setterName = s;m_getterName=g ;}
515
516 wxPropertyAccessorT( getter_t getter, const wxChar *g)
517 : m_setter_bool( NULL ) , m_setter_ref_bool( NULL ) , m_setter(NULL), m_setter_ref(NULL), m_getter(getter) ,m_getter_ref(NULL) {m_setterName = "";m_getterName=g ;}
518
519 wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetRetBool*,) setter_bool_t setter, getter_t getter, const wxChar *g, const wxChar *s)
520 : m_setter_bool( setter ) , m_setter_ref_bool( NULL ) , m_setter(NULL), m_setter_ref(NULL), m_getter(getter) , m_getter_ref(NULL){m_setterName = s;m_getterName=g ;}
521
522 wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetByRef*,) setter_ref_t setter, getter_t getter, const wxChar *g, const wxChar *s)
523 : m_setter_bool( NULL ) , m_setter_ref_bool( NULL ) , m_setter(NULL), m_setter_ref(setter), m_getter(getter) , m_getter_ref(NULL){m_setterName = s;m_getterName=g ;}
524
525 wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetByRefRetBool*,) setter_ref_bool_t setter, getter_t getter, const wxChar *g, const wxChar *s)
526 : m_setter_bool( NULL ) , m_setter_ref_bool( setter ) , m_setter(NULL), m_setter_ref(NULL), m_getter(getter) , m_getter_ref(NULL){m_setterName = s;m_getterName=g ;}
527
528 wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetAndGetByRef*,) setter_ref_t setter, getter_ref_t getter, const wxChar *g, const wxChar *s)
529 : m_setter_bool( NULL ) , m_setter_ref_bool( NULL ) , m_setter(NULL), m_setter_ref(setter), m_getter(NULL) , m_getter_ref(getter){m_setterName = s;m_getterName=g ;}
530
531 wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetAndGetByRefRetBool*,) setter_ref_bool_t setter, getter_ref_t getter, const wxChar *g, const wxChar *s)
532 : m_setter_bool( NULL ) , m_setter_ref_bool( setter ) , m_setter(NULL), m_setter_ref(NULL), m_getter(NULL) , m_getter_ref(getter){m_setterName = s;m_getterName=g ;}
533
534 wxPropertyAccessorT(WX_XTI_PARAM_FIX(GetByRef*,) setter_t setter, getter_ref_t getter, const wxChar *g, const wxChar *s)
535 : m_setter_bool( NULL ) , m_setter_ref_bool( NULL ) , m_setter(NULL), m_setter(setter), m_getter(NULL) , m_getter_ref(getter){m_setterName = s;m_getterName=g ;}
536
537 // returns true if this accessor has a setter
538 bool HasSetter() const { return m_setter != NULL || m_setter_ref != NULL ; }
539
540 // return true if this accessor has a getter
541 bool HasGetter() const { return m_getter != NULL || m_getter_ref != NULL ; }
542
543 // set the property this accessor is responsible for in an object
544 void SetProperty(wxObject *o, const wxxVariant &v) const
545 {
546 Klass *obj = dynamic_cast<Klass*>(o);
547 T value ;
548
549 if ( wxGetTypeInfo((T*)NULL)->GetKind() == wxT_OBJECT && v.GetTypeInfo()->GetKind() == wxT_OBJECT_PTR )
550 value = *v.Get<T*>();
551 else
552 value = v.Get<T>();
553 if (m_setter)
554 (obj->*(m_setter))(value);
555 else if ( m_setter_ref )
556 (obj->*(m_setter_ref))(value);
557 else if ( m_setter_ref_bool )
558 (obj->*(m_setter_ref_bool))(value);
559 else if ( m_setter_bool )
560 (obj->*(m_setter_bool))(value);
561 else
562 {
563 wxASSERT_MSG(0 , wxT("SetPropertyCalled without a valid Setter") ) ;
564 }
565 }
566
567 // gets the property this accessor is responsible for from an object
568 wxxVariant GetProperty(const wxObject *o) const
569 {
570 return wxxVariant( (wxxVariantData* ) DoGetProperty( o ) ) ;
571 }
572
573 // write the property this accessor is responsible for from an object into
574 // a string
575 void WriteValue( wxString& s , const wxObject *o ) const
576 {
577 DoGetProperty( o )->Write( s ) ;
578 }
579
580 // read a wxxVariant having the correct type for the property this accessor
581 // is responsible for from a string
582 wxxVariant ReadValue( const wxString &value ) const
583 {
584 T data ;
585 wxStringReadValue( value , data ) ;
586 return wxxVariant( data ) ;
587 }
588
589 private :
590 wxxVariantDataT<T>* DoGetProperty(const wxObject *o) const
591 {
592 const Klass *obj = dynamic_cast<const Klass*>(o);
593 if ( m_getter )
594 return new wxxVariantDataT<T>( (obj->*(m_getter))() ) ;
595 else
596 return new wxxVariantDataT<T>( (obj->*(m_getter_ref))() ) ;
597 }
598
599 setter_t m_setter;
600 setter_ref_t m_setter_ref;
601 setter_ref_bool_t m_setter_ref_bool ;
602 setter_bool_t m_setter_bool ;
603 getter_t m_getter;
604 getter_ref_t m_getter_ref ;
605 };
606
607 class WXDLLIMPEXP_BASE wxPropertyInfo
608 {
609 public :
610 wxPropertyInfo( wxPropertyInfo* &iter , const wxChar *name , const wxChar *typeName , const wxTypeInfo* typeInfo , wxPropertyAccessor *accessor , wxxVariant dv ) :
611 m_name( name ) , m_typeName(typeName) , m_typeInfo( typeInfo ) , m_accessor( accessor ) , m_defaultValue( dv )
612 {
613 m_next = NULL ;
614 if ( iter == NULL )
615 iter = this ;
616 else
617 {
618 wxPropertyInfo* i = iter ;
619 while( i->m_next )
620 i = i->m_next ;
621
622 i->m_next = this ;
623 }
624 }
625 // return the name of this property
626 const wxChar * GetName() const { return m_name ; }
627
628 // return the typename of this property
629 const wxChar * GetTypeName() const { return m_typeName ; }
630
631 // return the type info of this property
632 const wxTypeInfo * GetTypeInfo() const { return m_typeInfo ; }
633
634 // return the accessor for this property
635 wxPropertyAccessor* GetAccessor() const { return m_accessor ; }
636
637 // returns NULL if this is the last property of this class
638 wxPropertyInfo* GetNext() const { return m_next ; }
639
640 // returns the default value of this property, its kind may be wxT_VOID if it is not valid
641 wxxVariant GetDefaultValue() const { return m_defaultValue ; }
642 private :
643 const wxChar * m_name;
644 const wxChar * m_typeName ;
645 const wxTypeInfo* m_typeInfo ;
646 wxPropertyAccessor* m_accessor ;
647 wxxVariant m_defaultValue;
648 // string representation of the default value
649 // to be assigned by the designer to the property
650 // when the component is dropped on the container.
651 wxPropertyInfo* m_next ;
652 };
653
654 #define WX_BEGIN_PROPERTIES_TABLE(theClass) \
655 const wxPropertyInfo *theClass::GetPropertiesStatic() \
656 { \
657 typedef theClass class_t; \
658 static wxPropertyInfo* first = NULL ;
659
660 #define WX_END_PROPERTIES_TABLE() \
661 return first ; }
662
663
664 #if WX_XTI_TEMPLATE_FIX
665
666 #define WX_PROPERTY( name , type , setter , getter ,defaultValue ) \
667 static wxPropertyAccessorT<class_t , type> _accessor##name( &setter , &getter , #setter , #getter ) ; \
668 static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
669
670 #define WX_PROPERTY_SET_RET_BOOL( name , type , setter , getter ,defaultValue ) \
671 static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetRetBool*)NULL , &setter , &getter , #setter , #getter ) ; \
672 static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
673
674 #define WX_PROPERTY_SET_BY_REF( name , type , setter , getter ,defaultValue ) \
675 static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetByRef*)NULL, &setter , &getter , #setter , #getter ) ; \
676 static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
677
678 #define WX_PROPERTY_SET_BY_REF_RET_BOOL( name , type , setter , getter ,defaultValue ) \
679 static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetByRefRetBool*)NULL, &setter , &getter , #setter , #getter ) ; \
680 static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
681
682 #define WX_PROPERTY_SET_AND_GET_BY_REF_RET_BOOL( name , type , setter , getter ,defaultValue ) \
683 static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetAndGetByRefRetBool*)NULL, &setter , &getter , #setter , #getter ) ; \
684 static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
685
686 #else
687
688 #define WX_PROPERTY( name , type , setter , getter ,defaultValue ) \
689 static wxPropertyAccessorT<class_t , type> _accessor##name( &setter , &getter , #setter , #getter ) ; \
690 static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
691
692 #define WX_PROPERTY_SET_RET_BOOL( name , type , setter , getter ,defaultValue ) \
693 WX_PROPERTY( name , type , setter , getter , defaultValue )
694
695 #define WX_PROPERTY_SET_BY_REF( name , type , setter , getter ,defaultValue ) \
696 WX_PROPERTY( name , type , setter , getter , defaultValue )
697
698 #define WX_PROPERTY_SET_BY_REF_RET_BOOL( name , type , setter , getter ,defaultValue ) \
699 WX_PROPERTY( name , type , setter , getter , defaultValue )
700
701 #define WX_PROPERTY_SET_AND_GET_BY_REF_RET_BOOL( name , type , setter , getter ,defaultValue ) \
702 WX_PROPERTY( name , type , setter , getter , defaultValue )
703
704 #endif
705
706 #define WX_READONLY_PROPERTY( name , type , getter ,defaultValue ) \
707 static wxPropertyAccessorT<class_t , type> _accessor##name( &getter , #getter ) ; \
708 static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
709
710 #define WX_DELEGATE( name , eventType , eventClass ) \
711 static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \
712 static wxPropertyInfo _propertyInfo##name( first , #name , NULL , &_typeInfo##name , NULL , wxxVariant() ) ; \
713
714 // ----------------------------------------------------------------------------
715 // Handler Info
716 //
717 // this is describing an event sink
718 // ----------------------------------------------------------------------------
719
720 class wxHandlerInfo
721 {
722 public :
723 wxHandlerInfo( wxHandlerInfo* &iter , const wxChar *name , wxObjectEventFunction address , const wxClassInfo* eventClassInfo ) :
724 m_name( name ) , m_eventClassInfo( eventClassInfo ) , m_eventFunction( address )
725 {
726 m_next = NULL ;
727 if ( iter == NULL )
728 iter = this ;
729 else
730 {
731 wxHandlerInfo* i = iter ;
732 while( i->m_next )
733 i = i->m_next ;
734
735 i->m_next = this ;
736 }
737 }
738
739 // get the name of the handler method
740 const wxChar * GetName() const { return m_name ; }
741
742 // return the class info of the event
743 const wxClassInfo * GetEventClassInfo() const { return m_eventClassInfo ; }
744
745 // get the handler function pointer
746 wxObjectEventFunction GetEventFunction() const { return m_eventFunction ; }
747
748 // returns NULL if this is the last handler of this class
749 wxHandlerInfo* GetNext() const { return m_next ; }
750 private :
751 wxObjectEventFunction m_eventFunction ;
752 const wxChar * m_name;
753 const wxClassInfo* m_eventClassInfo ;
754 wxHandlerInfo* m_next ;
755 };
756
757 #define WX_HANDLER(name,eventClassType) \
758 static wxHandlerInfo _handlerInfo##name( first , #name , (wxObjectEventFunction) (wxEventFunction) &name , CLASSINFO( eventClassType ) ) ;
759
760 #define WX_BEGIN_HANDLERS_TABLE(theClass) \
761 const wxHandlerInfo *theClass::GetHandlersStatic() \
762 { \
763 typedef theClass class_t; \
764 static wxHandlerInfo* first = NULL ;
765
766 #define WX_END_HANDLERS_TABLE() \
767 return first ; }
768
769 // ----------------------------------------------------------------------------
770 // Constructor Bridges
771 //
772 // allow to set up constructors with params during runtime
773 // ----------------------------------------------------------------------------
774
775 class WXDLLIMPEXP_BASE wxConstructorBridge
776 {
777 public :
778 virtual void Create(wxObject *o, wxxVariant *args) = 0;
779 };
780
781 // Creator Bridges for all Numbers of Params
782
783 // no params
784
785 template<typename Class>
786 struct wxConstructorBridge_0 : public wxConstructorBridge
787 {
788 void Create(wxObject *o, wxxVariant *)
789 {
790 Class *obj = dynamic_cast<Class*>(o);
791 obj->Create();
792 }
793 };
794
795 struct wxConstructorBridge_Dummy : public wxConstructorBridge
796 {
797 void Create(wxObject *, wxxVariant *)
798 {
799 }
800 } ;
801
802 #define WX_CONSTRUCTOR_0(klass) \
803 wxConstructorBridge_0<klass> constructor##klass ; \
804 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
805 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
806 const int klass::sm_constructorPropertiesCount##klass = 0 ;
807
808 #define WX_CONSTRUCTOR_DUMMY(klass) \
809 wxConstructorBridge_Dummy constructor##klass ; \
810 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
811 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
812 const int klass::sm_constructorPropertiesCount##klass = 0 ;
813
814 // 1 param
815
816 template<typename Class, typename T0>
817 struct wxConstructorBridge_1 : public wxConstructorBridge
818 {
819 void Create(wxObject *o, wxxVariant *args)
820 {
821 Class *obj = dynamic_cast<Class*>(o);
822 obj->Create(
823 args[0].Get<T0>()
824 );
825 }
826 };
827
828 #define WX_CONSTRUCTOR_1(klass,t0,v0) \
829 wxConstructorBridge_1<klass,t0> constructor##klass ; \
830 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
831 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 } ; \
832 const int klass::sm_constructorPropertiesCount##klass = 1 ;
833
834 // 2 params
835
836 template<typename Class,
837 typename T0, typename T1>
838 struct wxConstructorBridge_2 : public wxConstructorBridge
839 {
840 void Create(wxObject *o, wxxVariant *args)
841 {
842 Class *obj = dynamic_cast<Class*>(o);
843 obj->Create(
844 args[0].Get<T0>() ,
845 args[1].Get<T1>()
846 );
847 }
848 };
849
850 #define WX_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
851 wxConstructorBridge_2<klass,t0,t1> constructor##klass ; \
852 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
853 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 } ; \
854 const int klass::sm_constructorPropertiesCount##klass = 2;
855
856 // 3 params
857
858 template<typename Class,
859 typename T0, typename T1, typename T2>
860 struct wxConstructorBridge_3 : public wxConstructorBridge
861 {
862 void Create(wxObject *o, wxxVariant *args)
863 {
864 Class *obj = dynamic_cast<Class*>(o);
865 obj->Create(
866 args[0].Get<T0>() ,
867 args[1].Get<T1>() ,
868 args[2].Get<T2>()
869 );
870 }
871 };
872
873 #define WX_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
874 wxConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \
875 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
876 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 } ; \
877 const int klass::sm_constructorPropertiesCount##klass = 3 ;
878
879 // 4 params
880
881 template<typename Class,
882 typename T0, typename T1, typename T2, typename T3>
883 struct wxConstructorBridge_4 : public wxConstructorBridge
884 {
885 void Create(wxObject *o, wxxVariant *args)
886 {
887 Class *obj = dynamic_cast<Class*>(o);
888 obj->Create(
889 args[0].Get<T0>() ,
890 args[1].Get<T1>() ,
891 args[2].Get<T2>() ,
892 args[3].Get<T3>()
893 );
894 }
895 };
896
897 #define WX_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
898 wxConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass ; \
899 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
900 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 } ; \
901 const int klass::sm_constructorPropertiesCount##klass = 4 ;
902
903 // 5 params
904
905 template<typename Class,
906 typename T0, typename T1, typename T2, typename T3, typename T4>
907 struct wxConstructorBridge_5 : public wxConstructorBridge
908 {
909 void Create(wxObject *o, wxxVariant *args)
910 {
911 Class *obj = dynamic_cast<Class*>(o);
912 obj->Create(
913 args[0].Get<T0>() ,
914 args[1].Get<T1>() ,
915 args[2].Get<T2>() ,
916 args[3].Get<T3>() ,
917 args[4].Get<T4>()
918 );
919 }
920 };
921
922 #define WX_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
923 wxConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass ; \
924 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
925 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 } ; \
926 const int klass::sm_constructorPropertiesCount##klass = 5;
927
928 // 6 params
929
930 template<typename Class,
931 typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
932 struct wxConstructorBridge_6 : public wxConstructorBridge
933 {
934 void Create(wxObject *o, wxxVariant *args)
935 {
936 Class *obj = dynamic_cast<Class*>(o);
937 obj->Create(
938 args[0].Get<T0>() ,
939 args[1].Get<T1>() ,
940 args[2].Get<T2>() ,
941 args[3].Get<T3>() ,
942 args[4].Get<T4>() ,
943 args[5].Get<T5>()
944 );
945 }
946 };
947
948 #define WX_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
949 wxConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
950 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
951 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 } ; \
952 const int klass::sm_constructorPropertiesCount##klass = 6;
953
954
955 // ----------------------------------------------------------------------------
956 // wxClassInfo
957 // ----------------------------------------------------------------------------
958
959 typedef wxObject *(*wxObjectConstructorFn)(void);
960 typedef wxObject* (*wxVariantToObjectConverter)( wxxVariant &data ) ;
961 typedef wxxVariant (*wxObjectToVariantConverter)( wxObject* ) ;
962
963 class WXDLLIMPEXP_BASE wxClassInfo
964 {
965 public:
966 wxClassInfo(const wxClassInfo **_Parents,
967 const wxChar *_UnitName,
968 const wxChar *_ClassName,
969 int size,
970 wxObjectConstructorFn ctor ,
971 const wxPropertyInfo *_Props ,
972 const wxHandlerInfo *_Handlers ,
973 wxConstructorBridge* _Constructor ,
974 const wxChar ** _ConstructorProperties ,
975 const int _ConstructorPropertiesCount ,
976 wxVariantToObjectConverter _PtrConverter1 ,
977 wxVariantToObjectConverter _Converter2 ,
978 wxObjectToVariantConverter _Converter3
979 ) : m_parents(_Parents) , m_unitName(_UnitName) ,m_className(_ClassName),
980 m_objectSize(size), m_objectConstructor(ctor) , m_firstProperty(_Props ) , m_firstHandler(_Handlers ) , m_constructor( _Constructor ) ,
981 m_constructorProperties(_ConstructorProperties) , m_constructorPropertiesCount(_ConstructorPropertiesCount),
982 m_variantOfPtrToObjectConverter( _PtrConverter1 ) , m_variantToObjectConverter( _Converter2 ) , m_objectToVariantConverter( _Converter3 ) , m_next(sm_first)
983 {
984 sm_first = this;
985 Register() ;
986 }
987
988 virtual ~wxClassInfo() ;
989
990 wxObject *CreateObject() const { return m_objectConstructor ? (*m_objectConstructor)() : 0; }
991
992 const wxChar *GetClassName() const { return m_className; }
993 const wxClassInfo **GetParents() const { return m_parents; }
994 int GetSize() const { return m_objectSize; }
995
996 wxObjectConstructorFn GetConstructor() const { return m_objectConstructor; }
997 static const wxClassInfo *GetFirst() { return sm_first; }
998 const wxClassInfo *GetNext() const { return m_next; }
999 static wxClassInfo *FindClass(const wxChar *className);
1000
1001 // Climb upwards through inheritance hierarchy.
1002 // Dual inheritance is catered for.
1003
1004 bool IsKindOf(const wxClassInfo *info) const
1005 {
1006 if ( info != 0 )
1007 {
1008 if ( info == this )
1009 return true ;
1010
1011 for ( int i = 0 ; m_parents[i] ; ++ i )
1012 {
1013 if ( m_parents[i]->IsKindOf( info ) )
1014 return true ;
1015 }
1016 }
1017 return false ;
1018 }
1019
1020 #ifdef WXWIN_COMPATIBILITY_2_4
1021 // Initializes parent pointers and hash table for fast searching.
1022 wxDEPRECATED( static void InitializeClasses() );
1023 // Cleans up hash table used for fast searching.
1024 wxDEPRECATED( static void CleanUpClasses() );
1025 #endif
1026 static void CleanUp();
1027
1028 // returns the first property
1029 const wxPropertyInfo* GetFirstProperty() const { return m_firstProperty ; }
1030
1031 // returns the first handler
1032 const wxHandlerInfo* GetFirstHandler() const { return m_firstHandler ; }
1033
1034 // Call the Create method for a class
1035 virtual void Create (wxObject *object, int ParamCount, wxxVariant *Params) const
1036 {
1037 wxASSERT_MSG( ParamCount == m_constructorPropertiesCount , wxT("Illegal Parameter Count for Create Method")) ;
1038 m_constructor->Create( object , Params ) ;
1039 }
1040
1041 // get number of parameters for constructor
1042 virtual int GetCreateParamCount() const { return m_constructorPropertiesCount; }
1043
1044 // get i-th constructor parameter
1045 virtual const wxChar* GetCreateParamName(int i) const { return m_constructorProperties[i] ; }
1046
1047 // Runtime access to objects by property name, and variant data
1048 virtual void SetProperty (wxObject *object, const wxChar *PropertyName, const wxxVariant &Value);
1049 virtual wxxVariant GetProperty (wxObject *object, const wxChar *PropertyName);
1050
1051 // we must be able to cast variants to wxObject pointers, templates seem not to be suitable
1052 wxObject* VariantToInstance( wxxVariant &data ) const
1053 { if ( data.GetTypeInfo()->GetKind() == wxT_OBJECT )
1054 return m_variantToObjectConverter( data ) ;
1055 else
1056 return m_variantOfPtrToObjectConverter( data ) ;
1057 }
1058
1059 wxxVariant InstanceToVariant( wxObject *object ) const { return m_objectToVariantConverter( object ) ; }
1060
1061 // find property by name
1062 virtual const wxPropertyInfo *FindPropertyInfo (const wxChar *PropertyName) const ;
1063
1064 // find handler by name
1065 virtual const wxHandlerInfo *FindHandlerInfo (const wxChar *PropertyName) const ;
1066
1067 public:
1068 const wxChar *m_className;
1069 int m_objectSize;
1070 wxObjectConstructorFn m_objectConstructor;
1071
1072 // class info object live in a linked list:
1073 // pointers to its head and the next element in it
1074
1075 static wxClassInfo *sm_first;
1076 wxClassInfo *m_next;
1077
1078 // FIXME: this should be private (currently used directly by way too
1079 // many clients)
1080 static wxHashTable *sm_classTable;
1081
1082 private:
1083 const wxClassInfo** m_parents ;
1084 const wxPropertyInfo * m_firstProperty ;
1085 const wxHandlerInfo * m_firstHandler ;
1086 const wxChar* m_unitName;
1087
1088 wxConstructorBridge* m_constructor ;
1089 const wxChar ** m_constructorProperties ;
1090 const int m_constructorPropertiesCount ;
1091 wxVariantToObjectConverter m_variantOfPtrToObjectConverter ;
1092 wxVariantToObjectConverter m_variantToObjectConverter ;
1093 wxObjectToVariantConverter m_objectToVariantConverter ;
1094
1095 const wxPropertyAccessor *FindAccessor (const wxChar *propertyName);
1096
1097
1098 // InitializeClasses() helper
1099 static wxClassInfo *GetBaseByName(const wxChar *name);
1100
1101 protected:
1102 // registers the class
1103 void Register();
1104 void Unregister();
1105
1106 DECLARE_NO_COPY_CLASS(wxClassInfo)
1107 };
1108
1109 WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name);
1110
1111 // ----------------------------------------------------------------------------
1112 // Dynamic class macros
1113 // ----------------------------------------------------------------------------
1114
1115 #define _DECLARE_DYNAMIC_CLASS(name) \
1116 public: \
1117 static wxClassInfo sm_class##name; \
1118 static const wxClassInfo* sm_classParents##name[] ; \
1119 static const wxPropertyInfo* GetPropertiesStatic() ; \
1120 static const wxHandlerInfo* GetHandlersStatic() ; \
1121 virtual wxClassInfo *GetClassInfo() const \
1122 { return &name::sm_class##name; }
1123
1124 #define DECLARE_DYNAMIC_CLASS(name) \
1125 static wxConstructorBridge* sm_constructor##name ; \
1126 static const wxChar * sm_constructorProperties##name[] ; \
1127 static const int sm_constructorPropertiesCount##name ; \
1128 _DECLARE_DYNAMIC_CLASS(name)
1129
1130 #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
1131 DECLARE_NO_ASSIGN_CLASS(name) \
1132 DECLARE_DYNAMIC_CLASS(name)
1133
1134 #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \
1135 DECLARE_NO_COPY_CLASS(name) \
1136 DECLARE_DYNAMIC_CLASS(name)
1137
1138 #define DECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name)
1139 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
1140
1141 // -----------------------------------
1142 // for concrete classes
1143 // -----------------------------------
1144
1145 // Single inheritance with one base class
1146
1147 #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit) \
1148 wxObject* wxConstructorFor##name() \
1149 { return new name; } \
1150 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1151 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1152 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1153 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1154 (int) sizeof(name), \
1155 (wxObjectConstructorFn) wxConstructorFor##name , \
1156 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1157 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name); \
1158 template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1159 template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1160 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1161 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1162 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1163 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1164 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1165 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1166 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1167
1168 #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit) \
1169 wxObject* wxConstructorFor##name() \
1170 { return new name; } \
1171 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1172 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return &data.Get<name>() ; } \
1173 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1174 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1175 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1176 (int) sizeof(name), \
1177 (wxObjectConstructorFn) wxConstructorFor##name , \
1178 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1179 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1180 template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1181 template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1182 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1183 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1184 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1185 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1186 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1187 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1188 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1189
1190 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \
1191 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" ) \
1192 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1193 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1194 WX_CONSTRUCTOR_DUMMY( name )
1195
1196 #define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \
1197 _IMPLEMENT_DYNAMIC_CLASS( name , basename , "" ) \
1198 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1199 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1200 WX_CONSTRUCTOR_DUMMY( name )
1201
1202 #define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \
1203 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit )
1204
1205 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \
1206 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit )
1207
1208 // this is for classes that do not derive from wxobject, there are no creators for these
1209
1210 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name , unit ) \
1211 const wxClassInfo* name::sm_classParents##name[] = { NULL } ; \
1212 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1213 (int) sizeof(name), \
1214 (wxObjectConstructorFn) 0 , \
1215 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1216 0 , 0 , 0 ); \
1217 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1218 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1219 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1220 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1221 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1222 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1223 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1224
1225 // this is for subclasses that still do not derive from wxobject
1226
1227 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name , basename, unit ) \
1228 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1229 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1230 (int) sizeof(name), \
1231 (wxObjectConstructorFn) 0 , \
1232 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1233 0 , 0 , 0 ); \
1234 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1235 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1236 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1237 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1238 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1239 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1240 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1241
1242
1243 // Multiple inheritance with two base classes
1244
1245 #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit) \
1246 wxObject* wxConstructorFor##name() \
1247 { return new name; } \
1248 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,&basename2::sm_class##basename2 , NULL } ; \
1249 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1250 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1251 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1252 (int) sizeof(name), \
1253 (wxObjectConstructorFn) wxConstructorFor##name , \
1254 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1255 name::sm_constructorPropertiesCount##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1256 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1257 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1258 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1259 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1260 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1261 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1262 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1263
1264 #define IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2) \
1265 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , "") \
1266 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1267 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1268 WX_CONSTRUCTOR_DUMMY( name )
1269
1270 #define IMPLEMENT_DYNAMIC_CLASS2_XTI( name , basename , basename2, unit) \
1271 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , unit)
1272
1273 // -----------------------------------
1274 // for abstract classes
1275 // -----------------------------------
1276
1277 // Single inheritance with one base class
1278
1279 #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
1280 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1281 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1282 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1283 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1284 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1285 (int) sizeof(name), \
1286 (wxObjectConstructorFn) 0 , \
1287 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1288 0 , wxVariantOfPtrToObjectConverter##name ,wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1289 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1290 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1291 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1292 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1293 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1294 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } \
1295 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID) ; assert(0) ; return &s_typeInfo ; }
1296
1297 #define IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1298 _IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1299 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1300 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; }
1301
1302 // Multiple inheritance with two base classes
1303
1304 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
1305 wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \
1306 wxT(#basename2), (int) sizeof(name), \
1307 (wxObjectConstructorFn) 0);
1308
1309 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
1310 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
1311
1312 #endif