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