xti additions / changes
[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/flags.h"
42 #include "wx/string.h"
43 #include "wx/arrstr.h"
44 #include "wx/hashmap.h"
45
46 class WXDLLIMPEXP_BASE wxObject;
47 class WXDLLIMPEXP_BASE wxClassInfo;
48 class WXDLLIMPEXP_BASE wxHashTable;
49 class WXDLLIMPEXP_BASE wxObjectRefData;
50 class WXDLLIMPEXP_BASE wxEvent;
51
52 typedef void (wxObject::*wxObjectEventFunction)(wxEvent&);
53
54 // ----------------------------------------------------------------------------
55 // Enum Support
56 //
57 // In the header files there would no change from pure c++ code, in the
58 // implementation, an enum would have
59 // to be enumerated eg :
60 //
61 // WX_BEGIN_ENUM( wxFlavor )
62 // WX_ENUM_MEMBER( Vanilla )
63 // WX_ENUM_MEMBER( Chocolate )
64 // WX_ENUM_MEMBER( Strawberry )
65 // WX_END_ENUM( wxFlavor )
66 // ----------------------------------------------------------------------------
67
68 struct WXDLLIMPEXP_BASE wxEnumMemberData
69 {
70 const wxChar* m_name;
71 int m_value;
72 };
73
74 class WXDLLIMPEXP_BASE wxEnumData
75 {
76 public :
77 wxEnumData( wxEnumMemberData* data ) ;
78
79 // returns true if the member has been found and sets the int value
80 // pointed to accordingly (if ptr != null )
81 // if not found returns false, value left unchanged
82 bool HasEnumMemberValue( const wxChar *name , int *value = NULL ) ;
83
84 // returns the value of the member, if not found in debug mode an
85 // assert is issued, in release 0 is returned
86 int GetEnumMemberValue(const wxChar *name );
87
88 // returns the name of the enum member having the passed in value
89 // returns an emtpy string if not found
90 const wxChar *GetEnumMemberName(int value);
91
92 // returns the number of members in this enum
93 int GetEnumCount() { return m_count ; }
94
95 // returns the value of the nth member
96 int GetEnumMemberValueByIndex( int n ) ;
97
98 // returns the value of the nth member
99 const wxChar *GetEnumMemberNameByIndex( int n ) ;
100 private :
101 wxEnumMemberData *m_members;
102 int m_count ;
103 };
104
105 #define WX_BEGIN_ENUM( e ) \
106 wxEnumMemberData s_enumDataMembers##e[] = {
107
108 #define WX_ENUM_MEMBER( v ) { #v, v } ,
109
110 #define WX_END_ENUM( e ) { NULL , 0 } } ; \
111 wxEnumData s_enumData##e( s_enumDataMembers##e ) ; \
112 wxEnumData *wxGetEnumData(e) { return &s_enumData##e ; } \
113 template<> void wxStringReadValue(const wxString& s , e &data ) \
114 { \
115 data = (e) s_enumData##e.GetEnumMemberValue(s) ; \
116 } \
117 template<> void wxStringWriteValue(wxString &s , const e &data ) \
118 { \
119 s = s_enumData##e.GetEnumMemberName((int)data) ; \
120 } \
121 void FromLong##e( long data , wxxVariant& result ) { result = wxxVariant((e)data) ;} \
122 void ToLong##e( const wxxVariant& data , long &result ) { result = (long) data.Get<e>() ;} \
123 template<> const wxTypeInfo* wxGetTypeInfo( e * ){ static wxEnumTypeInfo s_typeInfo(wxT_ENUM , &s_enumData##e , &wxToStringConverter<e> , &wxFromStringConverter<e> , &ToLong##e , &FromLong##e , #e) ; return &s_typeInfo ; } \
124 template<> const wxTypeInfo* wxGetTypeInfo( e ** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; assert(0) ; return &s_typeInfo ; } \
125 template<> void wxStringReadValue(const wxString& , e* & ) \
126 { \
127 assert(0) ; \
128 } \
129 template<> void wxStringWriteValue(wxString &s , e* const & ) \
130 { \
131 assert(0) ; \
132 }
133
134 // ----------------------------------------------------------------------------
135 // Set Support
136 //
137 // in the header :
138 //
139 // enum wxFlavor
140 // {
141 // Vanilla,
142 // Chocolate,
143 // Strawberry,
144 // };
145 //
146 // typedef wxFlags<wxFlavor> wxCoupe ;
147 //
148 // in the implementation file :
149 //
150 // WX_BEGIN_ENUM( wxFlavor )
151 // WX_ENUM_MEMBER( Vanilla )
152 // WX_ENUM_MEMBER( Chocolate )
153 // WX_ENUM_MEMBER( Strawberry )
154 // WX_END_ENUM( wxFlavor )
155 //
156 // WX_IMPLEMENT_SET_STREAMING( wxCoupe , wxFlavor )
157 //
158 // implementation note : no partial specialization for streaming, but a delegation to a
159 // different class
160 //
161 // ----------------------------------------------------------------------------
162
163 // in order to remove dependancy on string tokenizer
164 void wxSetStringToArray( const wxString &s , wxArrayString &array ) ;
165
166 template<typename e>
167 void wxSetFromString(const wxString &s , wxFlags<e> &data )
168 {
169 wxEnumData* edata = wxGetEnumData((e) 0) ;
170 data.Clear() ;
171
172 wxArrayString array ;
173 wxSetStringToArray( s , array ) ;
174 wxString flag;
175 for ( int i = 0 ; i < array.Count() ; ++i )
176 {
177 flag = array[i] ;
178 int ivalue ;
179 if ( edata->HasEnumMemberValue( flag , &ivalue ) )
180 {
181 data.Set( (e) ivalue ) ;
182 }
183 }
184 }
185
186 template<typename e>
187 void wxSetToString( wxString &s , const wxFlags<e> &data )
188 {
189 wxEnumData* edata = wxGetEnumData((e) 0) ;
190 int count = edata->GetEnumCount() ;
191 int i ;
192 s.Clear() ;
193 for ( i = 0 ; i < count ; i++ )
194 {
195 e value = (e) edata->GetEnumMemberValueByIndex(i) ;
196 if ( data.Contains( value ) )
197 {
198 // this could also be done by the templated calls
199 if ( !s.IsEmpty() )
200 s +="|" ;
201 s += edata->GetEnumMemberNameByIndex(i) ;
202 }
203 }
204 }
205
206 // if the wxFlags specialization above does not work for all compilers, add this to the WX_IMPLEMENT_SET_STREAMING macro
207 // template<> const wxTypeInfo* wxGetTypeInfo( SetName * ){ static wxEnumTypeInfo s_typeInfo(wxT_SET , &s_enumData##e) ; return &s_typeInfo ; }
208
209 #define WX_IMPLEMENT_SET_STREAMING(SetName,e) \
210 template<> void wxStringReadValue(const wxString &s , wxFlags<e> &data ) \
211 { \
212 wxSetFromString( s , data ) ; \
213 } \
214 template<> void wxStringWriteValue( wxString &s , const wxFlags<e> &data ) \
215 { \
216 wxSetToString( s , data ) ; \
217 } \
218 void FromLong##SetName( long data , wxxVariant& result ) { result = wxxVariant(SetName(data)) ;} \
219 void ToLong##SetName( const wxxVariant& data , long &result ) { result = (long) data.Get<SetName>() ;} \
220 template<> const wxTypeInfo* wxGetTypeInfo( SetName * ) \
221 { \
222 static wxEnumTypeInfo s_typeInfo(wxT_SET , &s_enumData##e , &wxToStringConverter<SetName> , &wxFromStringConverter<SetName> , &ToLong##SetName , &FromLong##SetName, #SetName ) ; return &s_typeInfo ; \
223 }
224
225
226 // ----------------------------------------------------------------------------
227 // Type Information
228 // ----------------------------------------------------------------------------
229 //
230 //
231 // All data exposed by the RTTI is characterized using the following classes.
232 // The first characterization is done by wxTypeKind. All enums up to and including
233 // wxT_CUSTOM represent so called simple types. These cannot be divided any further.
234 // They can be converted to and from wxStrings, that's all.
235
236
237 enum wxTypeKind
238 {
239 wxT_VOID = 0, // unknown type
240 wxT_BOOL,
241 wxT_CHAR,
242 wxT_UCHAR,
243 wxT_INT,
244 wxT_UINT,
245 wxT_LONG,
246 wxT_ULONG,
247 wxT_FLOAT,
248 wxT_DOUBLE,
249 wxT_STRING, // must be wxString
250 wxT_SET, // must be wxFlags<> template
251 wxT_ENUM,
252 wxT_CUSTOM, // user defined type (e.g. wxPoint)
253
254 wxT_LAST_SIMPLE_TYPE_KIND = wxT_CUSTOM ,
255
256 wxT_OBJECT_PTR, // object reference
257 wxT_OBJECT , // embedded object
258 wxT_COLLECTION , // collection
259
260 wxT_DELEGATE , // for connecting against an event source
261
262 wxT_LAST_TYPE_KIND = wxT_DELEGATE // sentinel for bad data, asserts, debugging
263 };
264
265 class wxxVariant ;
266 class wxTypeInfo ;
267
268 WX_DECLARE_EXPORTED_STRING_HASH_MAP( wxTypeInfo* , wxTypeInfoMap ) ;
269
270 class WXDLLIMPEXP_BASE wxTypeInfo
271 {
272 public :
273 typedef void (*converterToString_t)( const wxxVariant& data , wxString &result ) ;
274 typedef void (*converterFromString_t)( const wxString& data , wxxVariant &result ) ;
275
276 wxTypeInfo(wxTypeKind kind , converterToString_t to = NULL , converterFromString_t from= NULL, const wxString &name = wxEmptyString ) :
277 m_kind( kind) , m_toString(to) , m_fromString(from) , m_name(name)
278 {
279 Register() ;
280 }
281
282 virtual ~wxTypeInfo()
283 {
284 Unregister() ;
285 }
286
287 // return the kind of this type (wxT_... constants)
288 wxTypeKind GetKind() const { return m_kind ; }
289
290 // returns the unique name of this type
291 const wxString& GetTypeName() const { return m_name ; }
292
293 // is this type a delegate type
294 bool IsDelegateType() const { return m_kind == wxT_DELEGATE ; }
295
296 // is this type a custom type
297 bool IsCustomType() const { return m_kind == wxT_CUSTOM ; }
298
299 // is this type an object type
300 bool IsObjectType() const { return m_kind == wxT_OBJECT || m_kind == wxT_OBJECT_PTR ; }
301
302 // can the content of this type be converted to and from strings ?
303 bool HasStringConverters() const { return m_toString != NULL && m_fromString != NULL ; }
304
305 // convert a wxxVariant holding data of this type into a string
306 void ConvertToString( const wxxVariant& data , wxString &result ) const
307
308 { wxASSERT_MSG( m_toString , wxT("String conversions not supported") ) ; (*m_toString)( data , result ) ; }
309
310 // convert a string into a wxxVariant holding the corresponding data in this type
311 void ConvertFromString( const wxString& data , wxxVariant &result ) const
312 { wxASSERT_MSG( m_fromString , wxT("String conversions not supported") ) ; (*m_fromString)( data , result ) ; }
313
314 static wxTypeInfo *FindType(const wxChar *typeName);
315
316 private :
317
318 void Register();
319 void Unregister();
320
321 converterToString_t m_toString ;
322 converterFromString_t m_fromString ;
323
324 static wxTypeInfoMap* sm_typeTable ;
325
326 wxTypeKind m_kind ;
327 wxString m_name ;
328 };
329
330 class WXDLLIMPEXP_BASE wxBuiltInTypeInfo : public wxTypeInfo
331 {
332 public :
333 wxBuiltInTypeInfo( wxTypeKind kind , converterToString_t to = NULL , converterFromString_t from = NULL , const wxString &name = wxEmptyString ) :
334 wxTypeInfo( kind , to , from , name )
335 { wxASSERT_MSG( GetKind() < wxT_SET , wxT("Illegal Kind for Base Type") ) ; }
336 } ;
337
338 class WXDLLIMPEXP_BASE wxCustomTypeInfo : public wxTypeInfo
339 {
340 public :
341 wxCustomTypeInfo( const wxString &name , converterToString_t to , converterFromString_t from ) :
342 wxTypeInfo( wxT_CUSTOM , to , from , name )
343 {}
344 } ;
345
346 class WXDLLIMPEXP_BASE wxEnumTypeInfo : public wxTypeInfo
347 {
348 public :
349 typedef void (*converterToLong_t)( const wxxVariant& data , long &result ) ;
350 typedef void (*converterFromLong_t)( long data , wxxVariant &result ) ;
351
352 wxEnumTypeInfo( wxTypeKind kind , wxEnumData* enumInfo , converterToString_t to , converterFromString_t from ,
353 converterToLong_t toLong , converterFromLong_t fromLong , const wxString &name ) :
354 wxTypeInfo( kind , to , from , name ) , m_toLong( toLong ) , m_fromLong( fromLong )
355 { wxASSERT_MSG( kind == wxT_ENUM || kind == wxT_SET , wxT("Illegal Kind for Enum Type")) ; m_enumInfo = enumInfo ;}
356 const wxEnumData* GetEnumData() const { return m_enumInfo ; }
357
358 // convert a wxxVariant holding data of this type into a long
359 void ConvertToLong( const wxxVariant& data , long &result ) const
360
361 { wxASSERT_MSG( m_toLong , wxT("Long conversions not supported") ) ; (*m_toLong)( data , result ) ; }
362
363 // convert a long into a wxxVariant holding the corresponding data in this type
364 void ConvertFromLong( long data , wxxVariant &result ) const
365 { wxASSERT_MSG( m_fromLong , wxT("Long conversions not supported") ) ; (*m_fromLong)( data , result ) ; }
366
367 private :
368 converterToLong_t m_toLong ;
369 converterFromLong_t m_fromLong ;
370
371 wxEnumData *m_enumInfo; // Kind == wxT_ENUM or Kind == wxT_SET
372 } ;
373
374 class WXDLLIMPEXP_BASE wxClassTypeInfo : public wxTypeInfo
375 {
376 public :
377 wxClassTypeInfo( wxTypeKind kind , wxClassInfo* classInfo , converterToString_t to = NULL , converterFromString_t from = NULL ) ;
378 const wxClassInfo *GetClassInfo() const { return m_classInfo ; }
379 private :
380 wxClassInfo *m_classInfo; // Kind == wxT_OBJECT - could be NULL
381 } ;
382
383 class WXDLLIMPEXP_BASE wxCollectionTypeInfo : public wxTypeInfo
384 {
385 public :
386 wxCollectionTypeInfo( wxTypeInfo *elementType , converterToString_t to , converterFromString_t from , const wxString &name) :
387 wxTypeInfo( wxT_COLLECTION , to , from , name )
388 { m_elementType = elementType ;}
389
390 const wxTypeInfo* GetElementType() const { return m_elementType ; }
391 private :
392 wxTypeInfo * m_elementType ;
393 } ;
394
395 // a delegate is an exposed event source
396
397 class WXDLLIMPEXP_BASE wxDelegateTypeInfo : public wxTypeInfo
398 {
399 public :
400 wxDelegateTypeInfo( int eventType , wxClassInfo* eventClass , converterToString_t to = NULL , converterFromString_t from = NULL ) ;
401 int GetEventType() const { return m_eventType ; }
402 private :
403 const wxClassInfo *m_eventClass; // (extended will merge into classinfo)
404 int m_eventType ;
405 } ;
406
407 template<typename T> const wxTypeInfo* wxGetTypeInfo( T * ) ;
408
409 // this macro is for usage with custom, non-object derived classes and structs, wxPoint is such a custom type
410
411 #define WX_CUSTOM_TYPE_INFO( e ) \
412 template<> const wxTypeInfo* wxGetTypeInfo( e ** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID) ; assert(0) ; return &s_typeInfo ; } \
413 template<> const wxTypeInfo* wxGetTypeInfo( e * ){ static wxCustomTypeInfo s_typeInfo(#e, &wxToStringConverter<e> , &wxFromStringConverter<e>) ; return &s_typeInfo ; }
414
415 #define WX_COLLECTION_TYPE_INFO( element , collection ) \
416 template<> const wxTypeInfo* wxGetTypeInfo( collection * ) \
417 { \
418 static wxCollectionTypeInfo s_typeInfo( (wxTypeInfo*) wxGetTypeInfo( (element *) NULL) , NULL , NULL , #collection ) ; \
419 return &s_typeInfo ; \
420 } \
421
422
423 // templated streaming, every type must have their specialization for these methods
424
425 template<typename T>
426 void wxStringReadValue( const wxString &s , T &data );
427
428 template<typename T>
429 void wxStringWriteValue( wxString &s , const T &data);
430
431 template<typename T>
432 void wxToStringConverter( const wxxVariant &v, wxString &s) { wxStringWriteValue( s , v.Get<T>() ) ; }
433
434 template<typename T>
435 void wxFromStringConverter( const wxString &s, wxxVariant &v) { T d ; wxStringReadValue( s , d ) ; v = wxxVariant(d) ; } \
436
437 // sometimes a compiler invents specializations that are nowhere called, use this macro to satisfy the refs
438
439 #define WX_ILLEGAL_TYPE_SPECIALIZATION( a ) \
440 template<> const wxTypeInfo* wxGetTypeInfo( a * ) { assert(0) ; \
441 static wxBuiltInTypeInfo s_typeInfo( wxT_VOID ) ; return &s_typeInfo ; } \
442 template<> void wxStringReadValue(const wxString & , a & ) { assert(0) ; }\
443 template<> void wxStringWriteValue(wxString & , a const & ) { assert(0) ; }
444
445 // ----------------------------------------------------------------------------
446 // wxxVariant as typesafe data holder
447 // ----------------------------------------------------------------------------
448
449 class WXDLLIMPEXP_BASE wxxVariantData
450 {
451 public:
452 virtual ~wxxVariantData() {}
453
454 // return a heap allocated duplicate
455 virtual wxxVariantData* Clone() const = 0 ;
456
457 // returns the type info of the contentc
458 virtual const wxTypeInfo* GetTypeInfo() const = 0 ;
459 } ;
460
461 template<typename T> class WXDLLIMPEXP_BASE wxxVariantDataT : public wxxVariantData
462 {
463 public:
464 wxxVariantDataT(const T& d) : m_data(d) {}
465 virtual ~wxxVariantDataT() {}
466
467 // get a ref to the stored data
468 T & Get() { return m_data; }
469
470 // get a const ref to the stored data
471 const T & Get() const { return m_data; }
472
473 // set the data
474 void Set(const T& d) { m_data = d; }
475
476 // return a heap allocated duplicate
477 virtual wxxVariantData* Clone() const { return new wxxVariantDataT<T>( Get() ) ; }
478
479 // returns the type info of the contentc
480 virtual const wxTypeInfo* GetTypeInfo() const { return wxGetTypeInfo( (T*) NULL ) ; }
481 private:
482 T m_data;
483 };
484
485 class WXDLLIMPEXP_BASE wxxVariant
486 {
487 public :
488 wxxVariant() { m_data = NULL ; }
489 wxxVariant( wxxVariantData* data , const wxString& name = wxT("") ) : m_data(data) , m_name(name) {}
490 wxxVariant( const wxxVariant &d ) { if ( d.m_data ) m_data = d.m_data->Clone() ; else m_data = NULL ; m_name = d.m_name ; }
491
492 template<typename T> wxxVariant( const T& data , const wxString& name = wxT("") ) :
493 m_data(new wxxVariantDataT<T>(data) ), m_name(name) {}
494
495 ~wxxVariant() { delete m_data ; }
496
497 // get a ref to the stored data
498 template<typename T> T& Get()
499 {
500 wxxVariantDataT<T> *dataptr = dynamic_cast<wxxVariantDataT<T>*> (m_data) ;
501 wxASSERT_MSG( dataptr , "Cast not possible" ) ;
502 return dataptr->Get() ;
503 }
504
505 // get a ref to the stored data
506 template<typename T> const T& Get() const
507 {
508 const wxxVariantDataT<T> *dataptr = dynamic_cast<const wxxVariantDataT<T>*> (m_data) ;
509 wxASSERT_MSG( dataptr , "Cast not possible" ) ;
510 return dataptr->Get() ;
511 }
512
513 template<typename T> bool HasData() const
514 {
515 const wxxVariantDataT<T> *dataptr = dynamic_cast<const wxxVariantDataT<T>*> (m_data) ;
516 return dataptr != NULL ;
517 }
518
519 // stores the data
520 template<typename T> void Set(const T& data) const
521 {
522 delete m_data ;
523 m_data = new wxxVariantDataT<T>(data) ;
524 }
525
526 wxxVariant& operator=(const wxxVariant &d)
527 {
528 m_data = d.m_data->Clone() ;
529 m_name = d.m_name ;
530 return *this ;
531 }
532
533 // gets the stored data casted to a wxObject* , returning NULL if cast is not possible
534 wxObject* GetAsObject() ;
535
536 // get the typeinfo of the stored object
537 const wxTypeInfo* GetTypeInfo() const { return m_data->GetTypeInfo() ; }
538
539 // returns this value as string
540 wxString GetAsString() const
541 {
542 wxString s ;
543 GetTypeInfo()->ConvertToString( *this , s ) ;
544 return s ;
545 }
546 const wxString& GetName() const { return m_name ; }
547 private :
548 wxxVariantData* m_data ;
549 wxString m_name ;
550 } ;
551
552 #include <wx/dynarray.h>
553
554 WX_DECLARE_OBJARRAY_WITH_DECL(wxxVariant, wxxVariantArray, class WXDLLIMPEXP_BASE);
555
556 // ----------------------------------------------------------------------------
557 // Property Support
558 //
559 // wxPropertyInfo is used to inquire of the property by name. It doesn't
560 // provide access to the property, only information about it. If you
561 // want access, look at wxPropertyAccessor.
562 // ----------------------------------------------------------------------------
563
564 class wxSetter
565 {
566 public :
567 wxSetter( const wxString name ) { m_name = name ; }
568 virtual void Set( wxObject *object, const wxxVariant &variantValue ) const = 0;
569 const wxString& GetName() const { return m_name ; }
570 private :
571 wxString m_name ;
572 } ;
573
574 class wxGetter
575 {
576 public :
577 wxGetter( const wxString name ) { m_name = name ; }
578 virtual void Get( const wxObject *object , wxxVariant& result) const = 0;
579 const wxString& GetName() const { return m_name ; }
580 private :
581 wxString m_name ;
582 } ;
583
584 class wxCollectionGetter
585 {
586 public :
587 wxCollectionGetter( const wxString name ) { m_name = name ; }
588 virtual void Get( const wxObject *object , wxxVariantArray& result) const = 0;
589 const wxString& GetName() const { return m_name ; }
590 private :
591 wxString m_name ;
592 } ;
593
594 template<typename coll_t> void wxCollectionToVariantArray( const coll_t& coll , wxxVariantArray& result ) ;
595
596 class wxAdder
597 {
598 public :
599 wxAdder( const wxString name ) { m_name = name ; }
600 virtual void Add( wxObject *object, const wxxVariant &variantValue ) const= 0;
601 const wxString& GetName() const { return m_name ; }
602 private :
603 wxString m_name ;
604 } ;
605
606
607
608 #define WX_SETTER( property, Klass, valueType, setterMethod ) \
609 class wxSetter##property : public wxSetter \
610 { \
611 public: \
612 wxSetter##property() : wxSetter( #setterMethod ) {} \
613 void Set( wxObject *object, const wxxVariant &variantValue ) const \
614 { \
615 Klass *obj = dynamic_cast<Klass*>(object) ; \
616 if ( variantValue.HasData<valueType>() ) \
617 obj->setterMethod(variantValue.Get<valueType>()) ; \
618 else \
619 obj->setterMethod(*variantValue.Get<valueType*>()) ; \
620 } \
621 } ;
622
623 #define WX_GETTER( property, Klass, valueType , gettermethod ) \
624 class wxGetter##property : public wxGetter \
625 { \
626 public : \
627 wxGetter##property() : wxGetter( #gettermethod ) {} \
628 void Get( const wxObject *object , wxxVariant &result) const \
629 { \
630 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
631 result = wxxVariant( obj->gettermethod() ) ; \
632 } \
633 } ;
634
635 #define WX_ADDER( property, Klass, valueType , addermethod ) \
636 class wxAdder##property : public wxAdder \
637 { \
638 public: \
639 wxAdder##property() : wxAdder( #addermethod ) {} \
640 void Add( wxObject *object, const wxxVariant &variantValue ) const \
641 { \
642 Klass *obj = dynamic_cast<Klass*>(object) ; \
643 if ( variantValue.HasData<valueType>() ) \
644 obj->addermethod(variantValue.Get<valueType>()) ; \
645 else \
646 obj->addermethod(*variantValue.Get<valueType*>()) ; \
647 } \
648 } ;
649
650 #define WX_COLLECTION_GETTER( property, Klass, valueType , gettermethod ) \
651 class wxCollectionGetter##property : public wxCollectionGetter \
652 { \
653 public : \
654 wxCollectionGetter##property() : wxCollectionGetter( #gettermethod ) {} \
655 void Get( const wxObject *object , wxxVariantArray &result) const \
656 { \
657 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
658 wxCollectionToVariantArray( obj->gettermethod() , result ) ; \
659 } \
660 } ;
661
662 class WXDLLIMPEXP_BASE wxPropertyAccessor
663 {
664 public :
665 wxPropertyAccessor( wxSetter *setter , wxGetter *getter , wxAdder *adder , wxCollectionGetter *collectionGetter )
666 { m_setter = setter ; m_getter = getter ; m_adder = adder ; m_collectionGetter = collectionGetter ;}
667
668 virtual ~wxPropertyAccessor() {}
669
670 // Setting a simple property (non-collection)
671 virtual void SetProperty(wxObject *object, const wxxVariant &value) const
672 { wxASSERT_MSG(m_setter,wxT("SetProperty called w/o valid setter") ) ; m_setter->Set( object , value ) ;}
673
674 // Getting a simple property (non-collection)
675 virtual void GetProperty(const wxObject *object, wxxVariant &result) const
676 { wxASSERT_MSG(m_getter,wxT("GetProperty called w/o valid getter") ) ; m_getter->Get( object , result ) ;}
677
678 // Adding an element to a collection property
679 virtual void AddToPropertyCollection(wxObject *object, const wxxVariant &value) const
680 { wxASSERT_MSG(m_adder,wxT("AddToPropertyCollection called w/o valid adder") ) ; m_adder->Add( object , value ) ;}
681
682 // Getting a collection property
683 virtual void GetPropertyCollection( const wxObject *obj, wxxVariantArray &result) const
684 { wxASSERT_MSG(m_collectionGetter,wxT("GetPropertyCollection called w/o valid collection getter") ) ; m_collectionGetter->Get( obj , result) ;}
685
686 virtual bool HasSetter() const { return m_setter != NULL ; }
687 virtual bool HasCollectionGetter() const { return m_collectionGetter != NULL ; }
688 virtual bool HasGetter() const { return m_getter != NULL ; }
689 virtual bool HasAdder() const { return m_adder != NULL ; }
690
691 virtual const wxString& GetCollectionGetterName() const
692 { return m_collectionGetter->GetName() ; }
693 virtual const wxString& GetGetterName() const
694 { return m_getter->GetName() ; }
695 virtual const wxString& GetSetterName() const
696 { return m_setter->GetName() ; }
697 virtual const wxString& GetAdderName() const
698 { return m_adder->GetName() ; }
699 /*
700 virtual wxxVariant ReadValue( const wxString &value ) const ;
701 virtual void WriteValue( wxString& value , const wxObject *o ) const ;
702 */
703 protected :
704 wxSetter *m_setter ;
705 wxAdder *m_adder ;
706 wxGetter *m_getter ;
707 wxCollectionGetter* m_collectionGetter ;
708 };
709
710 class WXDLLIMPEXP_BASE wxGenericPropertyAccessor : public wxPropertyAccessor
711 {
712 public :
713 wxGenericPropertyAccessor( const wxString &propName ) ;
714 ~wxGenericPropertyAccessor() ;
715
716 virtual bool HasSetter() const { return true ; }
717 virtual bool HasGetter() const { return true ; }
718 virtual bool HasAdder() const { return false ; }
719 virtual bool HasCollectionGetter() const { return false ; }
720
721 virtual const wxString& GetGetterName() const
722 { return m_getterName ; }
723 virtual const wxString& GetSetterName() const
724 { return m_setterName ; }
725
726 virtual void SetProperty(wxObject *object, const wxxVariant &value) const ;
727 virtual void GetProperty(const wxObject *object, wxxVariant &value) const ;
728
729 // Adding an element to a collection property
730 virtual void AddToPropertyCollection(wxObject *WXUNUSED(object), const wxxVariant &WXUNUSED(value)) const
731 { wxASSERT_MSG(0,wxT("AddToPropertyCollection called on a generic accessor") ) ;}
732
733 // Getting a collection property
734 virtual void GetPropertyCollection( const wxObject *WXUNUSED(obj), wxxVariantArray &WXUNUSED(result)) const
735 { wxASSERT_MSG(0,wxT("GetPropertyCollection called on a generic accessor") ) ;}
736 private :
737 struct wxGenericPropertyAccessorInternal ;
738 wxGenericPropertyAccessorInternal* m_data ;
739 wxString m_propertyName ;
740 wxString m_setterName ;
741 wxString m_getterName ;
742 } ;
743
744 typedef long wxPropertyInfoFlags ;
745 enum {
746 // will be removed in future releases
747 wxPROP_DEPRECATED = 0x00000001 ,
748 // object graph property, will be streamed with priority (after constructor properties)
749 wxPROP_OBJECT_GRAPH = 0x00000002 ,
750 // this will only be streamed out and in as enum/set, the internal representation is still a long
751 wxPROP_ENUM_STORE_LONG = 0x00000004 ,
752 } ;
753
754 class WXDLLIMPEXP_BASE wxPropertyInfo
755 {
756 public :
757 wxPropertyInfo( wxPropertyInfo* &iter , const wxClassInfo* itsClass , const wxString& name , const wxTypeInfo* typeInfo , wxPropertyAccessor *accessor , wxxVariant dv , wxPropertyInfoFlags flags = 0 , const wxString& helpString=wxEmptyString, const wxString& groupString=wxEmptyString ) :
758 m_name( name ) , m_itsClass( itsClass ) , m_typeInfo( typeInfo ) , m_accessor( accessor ) , m_defaultValue( dv ) , m_collectionElementTypeInfo(NULL) , m_helpString (helpString ) , m_groupString( groupString ) , m_flags(flags)
759 {
760 Insert(iter) ;
761 }
762
763 wxPropertyInfo( wxPropertyInfo* &iter , const wxClassInfo* itsClass , const wxString& name , const wxTypeInfo* collTypeInfo , const wxTypeInfo* elemTypeInfo , wxPropertyAccessor *accessor , wxPropertyInfoFlags flags = 0 , const wxString& helpString=wxEmptyString, const wxString& groupString=wxEmptyString ) :
764 m_name( name ) , m_itsClass( itsClass ) , m_typeInfo( collTypeInfo ) , m_accessor( accessor ) , m_collectionElementTypeInfo(elemTypeInfo) , m_helpString (helpString ) , m_groupString( groupString ) , m_flags(flags)
765 {
766 Insert(iter) ;
767 }
768
769 // return the class this property is declared in
770 const wxClassInfo* GetDeclaringClass() const { return m_itsClass ; }
771
772 // return the name of this property
773 const wxString& GetName() const { return m_name ; }
774
775 // returns the flags of this property
776 wxPropertyInfoFlags GetFlags() const { return m_flags ;}
777
778 // returns the short help string of this property
779 const wxString& GetHelpString() const { return m_helpString ; }
780
781 // returns the group string of this property
782 const wxString& GetGroupString() const { return m_groupString ; }
783
784 // return the element type info of this property (for collections, otherwise NULL)
785 const wxTypeInfo * GetCollectionElementTypeInfo() const { return m_collectionElementTypeInfo ; }
786
787 // return the type info of this property
788 const wxTypeInfo * GetTypeInfo() const { return m_typeInfo ; }
789
790 // return the accessor for this property
791 wxPropertyAccessor* GetAccessor() const { return m_accessor ; }
792
793 // returns NULL if this is the last property of this class
794 wxPropertyInfo* GetNext() const { return m_next ; }
795
796 // returns the default value of this property, its kind may be wxT_VOID if it is not valid
797 wxxVariant GetDefaultValue() const { return m_defaultValue ; }
798 private :
799 void Insert(wxPropertyInfo* &iter)
800 {
801 m_next = NULL ;
802 if ( iter == NULL )
803 iter = this ;
804 else
805 {
806 wxPropertyInfo* i = iter ;
807 while( i->m_next )
808 i = i->m_next ;
809
810 i->m_next = this ;
811 }
812 }
813
814 wxString m_name;
815 wxString m_typeName ;
816 wxString m_groupString ;
817 wxString m_helpString ;
818 const wxClassInfo* m_itsClass ;
819 wxPropertyInfoFlags m_flags ;
820 const wxTypeInfo* m_typeInfo ;
821 const wxTypeInfo* m_collectionElementTypeInfo ;
822 wxPropertyAccessor* m_accessor ;
823 wxxVariant m_defaultValue;
824 // string representation of the default value
825 // to be assigned by the designer to the property
826 // when the component is dropped on the container.
827 wxPropertyInfo* m_next ;
828 };
829
830 WX_DECLARE_EXPORTED_STRING_HASH_MAP( wxPropertyInfo* , wxPropertyInfoMap ) ;
831
832 #define WX_BEGIN_PROPERTIES_TABLE(theClass) \
833 wxPropertyInfo *theClass::GetPropertiesStatic() \
834 { \
835 typedef theClass class_t; \
836 static wxPropertyInfo* first = NULL ;
837
838 #define WX_END_PROPERTIES_TABLE() \
839 return first ; }
840
841
842
843 #define WX_PROPERTY( name , type , setter , getter ,defaultValue , flags , help , group) \
844 WX_SETTER( name , class_t , type , setter ) \
845 static wxSetter##name _setter##name ; \
846 WX_GETTER( name , class_t , type , getter ) \
847 static wxGetter##name _getter##name ; \
848 static wxPropertyAccessor _accessor##name( &_setter##name , &_getter##name , NULL , NULL ) ; \
849 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) , flags , group , help ) ;
850
851 #define WX_PROPERTY_FLAGS( name , flags , type , setter , getter ,defaultValue , pflags , help , group) \
852 WX_SETTER( name , class_t , type , setter ) \
853 static wxSetter##name _setter##name ; \
854 WX_GETTER( name , class_t , type , getter ) \
855 static wxGetter##name _getter##name ; \
856 static wxPropertyAccessor _accessor##name( &_setter##name , &_getter##name , NULL , NULL ) ; \
857 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (flags*) NULL ) ,&_accessor##name , wxxVariant(defaultValue), wxPROP_ENUM_STORE_LONG | pflags , help , group ) ;
858
859 #define WX_READONLY_PROPERTY( name , type , getter ,defaultValue , flags , help , group) \
860 WX_GETTER( name , class_t , type , getter ) \
861 static wxGetter##name _getter##name ; \
862 static wxPropertyAccessor _accessor##name( NULL , &_getter##name , NULL , NULL ) ; \
863 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue), flags , help , group ) ;
864
865 #define WX_PROPERTY_COLLECTION( name , colltype , addelemtype , adder , getter , flags , help , group ) \
866 WX_ADDER( name , class_t , addelemtype , adder ) \
867 static wxAdder##name _adder##name ; \
868 WX_COLLECTION_GETTER( name , class_t , colltype , getter ) \
869 static wxCollectionGetter##name _collectionGetter##name ; \
870 static wxPropertyAccessor _accessor##name( NULL , NULL ,&_adder##name , &_collectionGetter##name ) ; \
871 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name , flags , help , group ) ;
872
873 #define WX_READONLY_PROPERTY_COLLECTION( name , colltype , addelemtype , getter , flags , help , group) \
874 WX_COLLECTION_GETTER( name , class_t , colltype , getter ) \
875 static wxCollectionGetter##name _collectionGetter##name ; \
876 static wxPropertyAccessor _accessor##name( NULL , NULL , NULL , &_collectionGetter##name ) ; \
877 static wxPropertyInfo _propertyInfo##name( first ,class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name , flags , help , group ) ;
878 /*
879 #define WX_PROPERTY_COLLECTION( name , colltype , addelemtype , adder , getter ) \
880 static wxPropertyCollectionAccessorT<class_t , colltype , addelemtype > _accessor##name( &adder , &getter , #adder , #getter ) ; \
881 static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name ) ;
882
883 #define WX_READONLY_PROPERTY_COLLECTION( name , colltype , addelemtype , getter ) \
884 static wxPropertyCollectionAccessorT<class_t , colltype , addelemtype > _accessor##name( &getter , #getter ) ; \
885 static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name ) ;
886 */
887
888
889
890 #define WX_DELEGATE( name , eventType , eventClass ) \
891 static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \
892 static wxPropertyInfo _propertyInfo##name( first ,class_t::GetClassInfoStatic() , #name , &_typeInfo##name , NULL , wxxVariant() ) ; \
893
894 // ----------------------------------------------------------------------------
895 // Handler Info
896 //
897 // this is describing an event sink
898 // ----------------------------------------------------------------------------
899
900 class wxHandlerInfo
901 {
902 public :
903 wxHandlerInfo( wxHandlerInfo* &iter , const wxString& name , wxObjectEventFunction address , const wxClassInfo* eventClassInfo ) :
904 m_name( name ) , m_eventClassInfo( eventClassInfo ) , m_eventFunction( address )
905 {
906 m_next = NULL ;
907 if ( iter == NULL )
908 iter = this ;
909 else
910 {
911 wxHandlerInfo* i = iter ;
912 while( i->m_next )
913 i = i->m_next ;
914
915 i->m_next = this ;
916 }
917 }
918
919 // return the name of this handler
920 const wxString& GetName() const { return m_name ; }
921
922 // return the class info of the event
923 const wxClassInfo * GetEventClassInfo() const { return m_eventClassInfo ; }
924
925 // get the handler function pointer
926 wxObjectEventFunction GetEventFunction() const { return m_eventFunction ; }
927
928 // returns NULL if this is the last handler of this class
929 wxHandlerInfo* GetNext() const { return m_next ; }
930 private :
931 wxObjectEventFunction m_eventFunction ;
932 wxString m_name;
933 const wxClassInfo* m_eventClassInfo ;
934 wxHandlerInfo* m_next ;
935 };
936
937 #define WX_HANDLER(name,eventClassType) \
938 static wxHandlerInfo _handlerInfo##name( first , #name , (wxObjectEventFunction) (wxEventFunction) &name , CLASSINFO( eventClassType ) ) ;
939
940 #define WX_BEGIN_HANDLERS_TABLE(theClass) \
941 wxHandlerInfo *theClass::GetHandlersStatic() \
942 { \
943 typedef theClass class_t; \
944 static wxHandlerInfo* first = NULL ;
945
946 #define WX_END_HANDLERS_TABLE() \
947 return first ; }
948
949 // ----------------------------------------------------------------------------
950 // Constructor Bridges
951 //
952 // allow to set up constructors with params during runtime
953 // ----------------------------------------------------------------------------
954
955 class WXDLLIMPEXP_BASE wxConstructorBridge
956 {
957 public :
958 virtual void Create(wxObject *o, wxxVariant *args) = 0;
959 };
960
961 // Creator Bridges for all Numbers of Params
962
963 // no params
964
965 template<typename Class>
966 struct wxConstructorBridge_0 : public wxConstructorBridge
967 {
968 void Create(wxObject *o, wxxVariant *)
969 {
970 Class *obj = dynamic_cast<Class*>(o);
971 obj->Create();
972 }
973 };
974
975 struct wxConstructorBridge_Dummy : public wxConstructorBridge
976 {
977 void Create(wxObject *, wxxVariant *)
978 {
979 }
980 } ;
981
982 #define WX_CONSTRUCTOR_0(klass) \
983 wxConstructorBridge_0<klass> constructor##klass ; \
984 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
985 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
986 const int klass::sm_constructorPropertiesCount##klass = 0 ;
987
988 #define WX_CONSTRUCTOR_DUMMY(klass) \
989 wxConstructorBridge_Dummy constructor##klass ; \
990 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
991 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
992 const int klass::sm_constructorPropertiesCount##klass = 0 ;
993
994 // 1 param
995
996 template<typename Class, typename T0>
997 struct wxConstructorBridge_1 : public wxConstructorBridge
998 {
999 void Create(wxObject *o, wxxVariant *args)
1000 {
1001 Class *obj = dynamic_cast<Class*>(o);
1002 obj->Create(
1003 args[0].Get<T0>()
1004 );
1005 }
1006 };
1007
1008 #define WX_CONSTRUCTOR_1(klass,t0,v0) \
1009 wxConstructorBridge_1<klass,t0> constructor##klass ; \
1010 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1011 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 } ; \
1012 const int klass::sm_constructorPropertiesCount##klass = 1 ;
1013
1014 // 2 params
1015
1016 template<typename Class,
1017 typename T0, typename T1>
1018 struct wxConstructorBridge_2 : public wxConstructorBridge
1019 {
1020 void Create(wxObject *o, wxxVariant *args)
1021 {
1022 Class *obj = dynamic_cast<Class*>(o);
1023 obj->Create(
1024 args[0].Get<T0>() ,
1025 args[1].Get<T1>()
1026 );
1027 }
1028 };
1029
1030 #define WX_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
1031 wxConstructorBridge_2<klass,t0,t1> constructor##klass ; \
1032 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1033 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 } ; \
1034 const int klass::sm_constructorPropertiesCount##klass = 2;
1035
1036 // 3 params
1037
1038 template<typename Class,
1039 typename T0, typename T1, typename T2>
1040 struct wxConstructorBridge_3 : public wxConstructorBridge
1041 {
1042 void Create(wxObject *o, wxxVariant *args)
1043 {
1044 Class *obj = dynamic_cast<Class*>(o);
1045 obj->Create(
1046 args[0].Get<T0>() ,
1047 args[1].Get<T1>() ,
1048 args[2].Get<T2>()
1049 );
1050 }
1051 };
1052
1053 #define WX_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
1054 wxConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \
1055 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1056 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 } ; \
1057 const int klass::sm_constructorPropertiesCount##klass = 3 ;
1058
1059 // 4 params
1060
1061 template<typename Class,
1062 typename T0, typename T1, typename T2, typename T3>
1063 struct wxConstructorBridge_4 : public wxConstructorBridge
1064 {
1065 void Create(wxObject *o, wxxVariant *args)
1066 {
1067 Class *obj = dynamic_cast<Class*>(o);
1068 obj->Create(
1069 args[0].Get<T0>() ,
1070 args[1].Get<T1>() ,
1071 args[2].Get<T2>() ,
1072 args[3].Get<T3>()
1073 );
1074 }
1075 };
1076
1077 #define WX_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
1078 wxConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass ; \
1079 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1080 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 } ; \
1081 const int klass::sm_constructorPropertiesCount##klass = 4 ;
1082
1083 // 5 params
1084
1085 template<typename Class,
1086 typename T0, typename T1, typename T2, typename T3, typename T4>
1087 struct wxConstructorBridge_5 : public wxConstructorBridge
1088 {
1089 void Create(wxObject *o, wxxVariant *args)
1090 {
1091 Class *obj = dynamic_cast<Class*>(o);
1092 obj->Create(
1093 args[0].Get<T0>() ,
1094 args[1].Get<T1>() ,
1095 args[2].Get<T2>() ,
1096 args[3].Get<T3>() ,
1097 args[4].Get<T4>()
1098 );
1099 }
1100 };
1101
1102 #define WX_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
1103 wxConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass ; \
1104 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1105 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 } ; \
1106 const int klass::sm_constructorPropertiesCount##klass = 5;
1107
1108 // 6 params
1109
1110 template<typename Class,
1111 typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
1112 struct wxConstructorBridge_6 : public wxConstructorBridge
1113 {
1114 void Create(wxObject *o, wxxVariant *args)
1115 {
1116 Class *obj = dynamic_cast<Class*>(o);
1117 obj->Create(
1118 args[0].Get<T0>() ,
1119 args[1].Get<T1>() ,
1120 args[2].Get<T2>() ,
1121 args[3].Get<T3>() ,
1122 args[4].Get<T4>() ,
1123 args[5].Get<T5>()
1124 );
1125 }
1126 };
1127
1128 #define WX_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1129 wxConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1130 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1131 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 } ; \
1132 const int klass::sm_constructorPropertiesCount##klass = 6;
1133
1134 // 7 params
1135
1136 template<typename Class,
1137 typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
1138 struct wxConstructorBridge_7 : public wxConstructorBridge
1139 {
1140 void Create(wxObject *o, wxxVariant *args)
1141 {
1142 Class *obj = dynamic_cast<Class*>(o);
1143 obj->Create(
1144 args[0].Get<T0>() ,
1145 args[1].Get<T1>() ,
1146 args[2].Get<T2>() ,
1147 args[3].Get<T3>() ,
1148 args[4].Get<T4>() ,
1149 args[5].Get<T5>() ,
1150 args[6].Get<T6>()
1151 );
1152 }
1153 };
1154
1155 #define WX_CONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
1156 wxConstructorBridge_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass ; \
1157 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1158 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 , #v6} ; \
1159 const int klass::sm_constructorPropertiesCount##klass = 7;
1160
1161 // 8 params
1162
1163 template<typename Class,
1164 typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
1165 struct wxConstructorBridge_8 : public wxConstructorBridge
1166 {
1167 void Create(wxObject *o, wxxVariant *args)
1168 {
1169 Class *obj = dynamic_cast<Class*>(o);
1170 obj->Create(
1171 args[0].Get<T0>() ,
1172 args[1].Get<T1>() ,
1173 args[2].Get<T2>() ,
1174 args[3].Get<T3>() ,
1175 args[4].Get<T4>() ,
1176 args[5].Get<T5>() ,
1177 args[6].Get<T6>() ,
1178 args[7].Get<T7>()
1179 );
1180 }
1181 };
1182
1183 #define WX_CONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
1184 wxConstructorBridge_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass ; \
1185 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1186 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 , #v6 , #v7} ; \
1187 const int klass::sm_constructorPropertiesCount##klass = 8;
1188 // ----------------------------------------------------------------------------
1189 // wxClassInfo
1190 // ----------------------------------------------------------------------------
1191
1192 typedef wxObject *(*wxObjectConstructorFn)(void);
1193 typedef wxObject* (*wxVariantToObjectConverter)( wxxVariant &data ) ;
1194 typedef wxxVariant (*wxObjectToVariantConverter)( wxObject* ) ;
1195
1196 class WXDLLIMPEXP_BASE wxClassInfo
1197 {
1198 public:
1199 wxClassInfo(const wxClassInfo **_Parents,
1200 const wxChar *_UnitName,
1201 const wxChar *_ClassName,
1202 int size,
1203 wxObjectConstructorFn ctor ,
1204 wxPropertyInfo *_Props ,
1205 wxHandlerInfo *_Handlers ,
1206 wxConstructorBridge* _Constructor ,
1207 const wxChar ** _ConstructorProperties ,
1208 const int _ConstructorPropertiesCount ,
1209 wxVariantToObjectConverter _PtrConverter1 ,
1210 wxVariantToObjectConverter _Converter2 ,
1211 wxObjectToVariantConverter _Converter3
1212 ) : m_parents(_Parents) , m_unitName(_UnitName) ,m_className(_ClassName),
1213 m_objectSize(size), m_objectConstructor(ctor) , m_firstProperty(_Props ) , m_firstHandler(_Handlers ) , m_constructor( _Constructor ) ,
1214 m_constructorProperties(_ConstructorProperties) , m_constructorPropertiesCount(_ConstructorPropertiesCount),
1215 m_variantOfPtrToObjectConverter( _PtrConverter1 ) , m_variantToObjectConverter( _Converter2 ) , m_objectToVariantConverter( _Converter3 ) , m_next(sm_first)
1216 {
1217 sm_first = this;
1218 Register() ;
1219 }
1220
1221 wxClassInfo(const wxChar *_UnitName, const wxChar *_ClassName, const wxClassInfo **_Parents) : m_parents(_Parents) , m_unitName(_UnitName) ,m_className(_ClassName),
1222 m_objectSize(0), m_objectConstructor(NULL) , m_firstProperty(NULL ) , m_firstHandler(NULL ) , m_constructor( NULL ) ,
1223 m_constructorProperties(NULL) , m_constructorPropertiesCount(NULL),
1224 m_variantOfPtrToObjectConverter( NULL ) , m_variantToObjectConverter( NULL ) , m_objectToVariantConverter( NULL ) , m_next(sm_first)
1225 {
1226 sm_first = this;
1227 Register() ;
1228 }
1229
1230 virtual ~wxClassInfo() ;
1231
1232 // allocates an instance of this class, this object does not have to be initialized or fully constructed
1233 // as this call will be followed by a call to Create
1234 virtual wxObject *AllocateObject() const { return m_objectConstructor ? (*m_objectConstructor)() : 0; }
1235
1236 // 'old naming' for AllocateObject staying here for backward compatibility
1237 wxObject *CreateObject() const { return AllocateObject() ; }
1238
1239 const wxChar *GetClassName() const { return m_className; }
1240 const wxClassInfo **GetParents() const { return m_parents; }
1241 int GetSize() const { return m_objectSize; }
1242
1243 wxObjectConstructorFn GetConstructor() const { return m_objectConstructor; }
1244 static const wxClassInfo *GetFirst() { return sm_first; }
1245 const wxClassInfo *GetNext() const { return m_next; }
1246 static wxClassInfo *FindClass(const wxChar *className);
1247
1248 // Climb upwards through inheritance hierarchy.
1249 // Dual inheritance is catered for.
1250
1251 bool IsKindOf(const wxClassInfo *info) const
1252 {
1253 if ( info != 0 )
1254 {
1255 if ( info == this )
1256 return true ;
1257
1258 for ( int i = 0 ; m_parents[i] ; ++ i )
1259 {
1260 if ( m_parents[i]->IsKindOf( info ) )
1261 return true ;
1262 }
1263 }
1264 return false ;
1265 }
1266
1267 #ifdef WXWIN_COMPATIBILITY_2_4
1268 // Initializes parent pointers and hash table for fast searching.
1269 wxDEPRECATED( static void InitializeClasses() );
1270 // Cleans up hash table used for fast searching.
1271 wxDEPRECATED( static void CleanUpClasses() );
1272 #endif
1273 static void CleanUp();
1274
1275 // returns the first property
1276 const wxPropertyInfo* GetFirstProperty() const { return m_firstProperty ; }
1277
1278 // returns the first handler
1279 const wxHandlerInfo* GetFirstHandler() const { return m_firstHandler ; }
1280
1281 // Call the Create upon an instance of the class, in the end the object is fully
1282 // initialized
1283 virtual void Create (wxObject *object, int ParamCount, wxxVariant *Params) const
1284 {
1285 wxASSERT_MSG( ParamCount == m_constructorPropertiesCount , wxT("Illegal Parameter Count for Create Method")) ;
1286 m_constructor->Create( object , Params ) ;
1287 }
1288
1289 // get number of parameters for constructor
1290 virtual int GetCreateParamCount() const { return m_constructorPropertiesCount; }
1291
1292 // get n-th constructor parameter
1293 virtual const wxChar* GetCreateParamName(int n) const { return m_constructorProperties[n] ; }
1294
1295 // Runtime access to objects for simple properties (get/set) by property name, and variant data
1296 virtual void SetProperty (wxObject *object, const wxChar *propertyName, const wxxVariant &value) const ;
1297 virtual wxxVariant GetProperty (wxObject *object, const wxChar *propertyName) const;
1298
1299 // Runtime access to objects for collection properties by property name
1300 virtual wxxVariantArray GetPropertyCollection(wxObject *object, const wxChar *propertyName) const ;
1301 virtual void AddToPropertyCollection(wxObject *object, const wxChar *propertyName , const wxxVariant& value) const ;
1302
1303 // we must be able to cast variants to wxObject pointers, templates seem not to be suitable
1304 wxObject* VariantToInstance( wxxVariant &data ) const
1305 { if ( data.GetTypeInfo()->GetKind() == wxT_OBJECT )
1306 return m_variantToObjectConverter( data ) ;
1307 else
1308 return m_variantOfPtrToObjectConverter( data ) ;
1309 }
1310
1311 wxxVariant InstanceToVariant( wxObject *object ) const { return m_objectToVariantConverter( object ) ; }
1312
1313 // find property by name
1314 virtual const wxPropertyInfo *FindPropertyInfo (const wxChar *PropertyName) const ;
1315
1316 // find handler by name
1317 virtual const wxHandlerInfo *FindHandlerInfo (const wxChar *PropertyName) const ;
1318
1319 // find property by name
1320 virtual const wxPropertyInfo *FindPropertyInfoInThisClass (const wxChar *PropertyName) const ;
1321
1322 // find handler by name
1323 virtual const wxHandlerInfo *FindHandlerInfoInThisClass (const wxChar *PropertyName) const ;
1324
1325 // puts all the properties of this class and its superclasses in the map, as long as there is not yet
1326 // an entry with the same name (overriding mechanism)
1327 void GetProperties( wxPropertyInfoMap &map ) const ;
1328 public:
1329 const wxChar *m_className;
1330 int m_objectSize;
1331 wxObjectConstructorFn m_objectConstructor;
1332
1333 // class info object live in a linked list:
1334 // pointers to its head and the next element in it
1335
1336 static wxClassInfo *sm_first;
1337 wxClassInfo *m_next;
1338
1339 // FIXME: this should be private (currently used directly by way too
1340 // many clients)
1341 static wxHashTable *sm_classTable;
1342
1343 protected :
1344 wxPropertyInfo * m_firstProperty ;
1345 wxHandlerInfo * m_firstHandler ;
1346 private:
1347 const wxClassInfo** m_parents ;
1348 const wxChar* m_unitName;
1349
1350 wxConstructorBridge* m_constructor ;
1351 const wxChar ** m_constructorProperties ;
1352 const int m_constructorPropertiesCount ;
1353 wxVariantToObjectConverter m_variantOfPtrToObjectConverter ;
1354 wxVariantToObjectConverter m_variantToObjectConverter ;
1355 wxObjectToVariantConverter m_objectToVariantConverter ;
1356
1357 const wxPropertyAccessor *FindAccessor (const wxChar *propertyName) const ;
1358
1359
1360 // InitializeClasses() helper
1361 static wxClassInfo *GetBaseByName(const wxChar *name) ;
1362
1363 protected:
1364 // registers the class
1365 void Register();
1366 void Unregister();
1367
1368 DECLARE_NO_COPY_CLASS(wxClassInfo)
1369 };
1370
1371
1372 WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name);
1373
1374 // ----------------------------------------------------------------------------
1375 // wxDynamicObject
1376 // ----------------------------------------------------------------------------
1377 //
1378 // this object leads to having a pure runtime-instantiation
1379
1380 class wxDynamicClassInfo : public wxClassInfo
1381 {
1382 public :
1383 wxDynamicClassInfo( const wxChar *_UnitName, const wxChar *_ClassName , const wxClassInfo* superClass ) ;
1384 virtual ~wxDynamicClassInfo() ;
1385
1386 // constructs a wxDynamicObject with an instance
1387 virtual wxObject *AllocateObject() const ;
1388
1389 // Call the Create method for a class
1390 virtual void Create (wxObject *object, int ParamCount, wxxVariant *Params) const ;
1391
1392 // get number of parameters for constructor
1393 virtual int GetCreateParamCount() const ;
1394
1395 // get i-th constructor parameter
1396 virtual const wxChar* GetCreateParamName(int i) const ;
1397
1398 // Runtime access to objects by property name, and variant data
1399 virtual void SetProperty (wxObject *object, const wxChar *PropertyName, const wxxVariant &Value) const ;
1400 virtual wxxVariant GetProperty (wxObject *object, const wxChar *PropertyName) const ;
1401
1402 void AddProperty( const wxChar *propertyName , const wxTypeInfo* typeInfo ) ;
1403 void AddHandler( const wxChar *handlerName , wxObjectEventFunction address , const wxClassInfo* eventClassInfo ) ;
1404 } ;
1405
1406 // ----------------------------------------------------------------------------
1407 // Dynamic class macros
1408 // ----------------------------------------------------------------------------
1409
1410 #define _DECLARE_DYNAMIC_CLASS(name) \
1411 public: \
1412 static wxClassInfo sm_class##name; \
1413 static const wxClassInfo* sm_classParents##name[] ; \
1414 static wxPropertyInfo* GetPropertiesStatic() ; \
1415 static wxHandlerInfo* GetHandlersStatic() ; \
1416 static wxClassInfo *GetClassInfoStatic() \
1417 { return &name::sm_class##name; } \
1418 virtual wxClassInfo *GetClassInfo() const \
1419 { return &name::sm_class##name; }
1420
1421 #define DECLARE_DYNAMIC_CLASS(name) \
1422 static wxConstructorBridge* sm_constructor##name ; \
1423 static const wxChar * sm_constructorProperties##name[] ; \
1424 static const int sm_constructorPropertiesCount##name ; \
1425 _DECLARE_DYNAMIC_CLASS(name)
1426
1427 #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
1428 DECLARE_NO_ASSIGN_CLASS(name) \
1429 DECLARE_DYNAMIC_CLASS(name)
1430
1431 #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \
1432 DECLARE_NO_COPY_CLASS(name) \
1433 DECLARE_DYNAMIC_CLASS(name)
1434
1435 #define DECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name)
1436 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
1437
1438 // -----------------------------------
1439 // for concrete classes
1440 // -----------------------------------
1441
1442 // Single inheritance with one base class
1443
1444 #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit) \
1445 wxObject* wxConstructorFor##name() \
1446 { return new name; } \
1447 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1448 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1449 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1450 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1451 (int) sizeof(name), \
1452 (wxObjectConstructorFn) wxConstructorFor##name , \
1453 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1454 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name); \
1455 template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1456 template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1457 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1458 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1459 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1460 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1461 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1462 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1463 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1464
1465 #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit) \
1466 wxObject* wxConstructorFor##name() \
1467 { return new name; } \
1468 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1469 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return &data.Get<name>() ; } \
1470 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1471 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1472 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1473 (int) sizeof(name), \
1474 (wxObjectConstructorFn) wxConstructorFor##name , \
1475 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1476 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1477 template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1478 template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1479 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1480 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1481 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1482 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1483 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1484 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1485 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1486
1487 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \
1488 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" ) \
1489 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1490 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1491 WX_CONSTRUCTOR_DUMMY( name )
1492
1493 #define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \
1494 _IMPLEMENT_DYNAMIC_CLASS( name , basename , "" ) \
1495 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1496 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1497 WX_CONSTRUCTOR_DUMMY( name )
1498
1499 #define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \
1500 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit )
1501
1502 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \
1503 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit )
1504
1505 // this is for classes that do not derive from wxobject, there are no creators for these
1506
1507 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name , unit ) \
1508 const wxClassInfo* name::sm_classParents##name[] = { NULL } ; \
1509 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1510 (int) sizeof(name), \
1511 (wxObjectConstructorFn) 0 , \
1512 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1513 0 , 0 , 0 ); \
1514 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1515 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1516 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1517 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1518 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1519 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1520 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1521
1522 // this is for subclasses that still do not derive from wxobject
1523
1524 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name , basename, unit ) \
1525 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1526 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1527 (int) sizeof(name), \
1528 (wxObjectConstructorFn) 0 , \
1529 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1530 0 , 0 , 0 ); \
1531 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1532 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1533 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1534 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1535 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1536 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1537 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1538
1539
1540 // Multiple inheritance with two base classes
1541
1542 #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit) \
1543 wxObject* wxConstructorFor##name() \
1544 { return new name; } \
1545 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,&basename2::sm_class##basename2 , NULL } ; \
1546 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1547 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1548 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1549 (int) sizeof(name), \
1550 (wxObjectConstructorFn) wxConstructorFor##name , \
1551 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1552 name::sm_constructorPropertiesCount##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1553 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1554 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1555 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1556 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1557 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1558 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1559 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1560
1561 #define IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2) \
1562 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , "") \
1563 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1564 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1565 WX_CONSTRUCTOR_DUMMY( name )
1566
1567 #define IMPLEMENT_DYNAMIC_CLASS2_XTI( name , basename , basename2, unit) \
1568 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , unit)
1569
1570 // -----------------------------------
1571 // for abstract classes
1572 // -----------------------------------
1573
1574 // Single inheritance with one base class
1575
1576 #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
1577 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1578 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1579 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1580 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1581 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1582 (int) sizeof(name), \
1583 (wxObjectConstructorFn) 0 , \
1584 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1585 0 , wxVariantOfPtrToObjectConverter##name ,wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1586 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1587 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1588 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1589 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1590 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1591 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } \
1592 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID) ; assert(0) ; return &s_typeInfo ; }
1593
1594 #define IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1595 _IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1596 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1597 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; }
1598
1599 // Multiple inheritance with two base classes
1600
1601 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
1602 wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \
1603 wxT(#basename2), (int) sizeof(name), \
1604 (wxObjectConstructorFn) 0);
1605
1606 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
1607 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
1608
1609 // --------------------------------------------------------------------------
1610 // Collection Support
1611 // --------------------------------------------------------------------------
1612
1613 template<typename collection_t> void wxListCollectionToVariantArray( const collection_t& coll , wxxVariantArray &value )
1614 {
1615 collection_t::compatibility_iterator current = coll.GetFirst() ;
1616 while (current)
1617 {
1618 value.Add( new wxxVariant(current->GetData()) ) ;
1619 current = current->GetNext();
1620 }
1621 }
1622
1623 template<typename collection_t> void wxArrayCollectionToVariantArray( const collection_t& coll , wxxVariantArray &value )
1624 {
1625 for( size_t i = 0 ; i < coll.GetCount() ; i++ )
1626 {
1627 value.Add( new wxxVariant(coll[i]) ) ;
1628 }
1629 }
1630
1631
1632 #endif