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