Unicode fix
[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.reset() ;
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.test( 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((unsigned long)data)) ;} \
219 void ToLong##SetName( const wxxVariant& data , long &result ) { result = (long) data.Get<SetName>().to_ulong() ;} \
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 , wxT("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 , wxT("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 // don't stream out this property, needed eg to avoid streaming out children that are always created by their parents
753 wxPROP_DONT_STREAM = 0x00000008 ,
754 } ;
755
756 class WXDLLIMPEXP_BASE wxPropertyInfo
757 {
758 public :
759 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 ) :
760 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)
761 {
762 Insert(iter) ;
763 }
764
765 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 ) :
766 m_name( name ) , m_itsClass( itsClass ) , m_typeInfo( collTypeInfo ) , m_accessor( accessor ) , m_collectionElementTypeInfo(elemTypeInfo) , m_helpString (helpString ) , m_groupString( groupString ) , m_flags(flags)
767 {
768 Insert(iter) ;
769 }
770
771 // return the class this property is declared in
772 const wxClassInfo* GetDeclaringClass() const { return m_itsClass ; }
773
774 // return the name of this property
775 const wxString& GetName() const { return m_name ; }
776
777 // returns the flags of this property
778 wxPropertyInfoFlags GetFlags() const { return m_flags ;}
779
780 // returns the short help string of this property
781 const wxString& GetHelpString() const { return m_helpString ; }
782
783 // returns the group string of this property
784 const wxString& GetGroupString() const { return m_groupString ; }
785
786 // return the element type info of this property (for collections, otherwise NULL)
787 const wxTypeInfo * GetCollectionElementTypeInfo() const { return m_collectionElementTypeInfo ; }
788
789 // return the type info of this property
790 const wxTypeInfo * GetTypeInfo() const { return m_typeInfo ; }
791
792 // return the accessor for this property
793 wxPropertyAccessor* GetAccessor() const { return m_accessor ; }
794
795 // returns NULL if this is the last property of this class
796 wxPropertyInfo* GetNext() const { return m_next ; }
797
798 // returns the default value of this property, its kind may be wxT_VOID if it is not valid
799 wxxVariant GetDefaultValue() const { return m_defaultValue ; }
800 private :
801 void Insert(wxPropertyInfo* &iter)
802 {
803 m_next = NULL ;
804 if ( iter == NULL )
805 iter = this ;
806 else
807 {
808 wxPropertyInfo* i = iter ;
809 while( i->m_next )
810 i = i->m_next ;
811
812 i->m_next = this ;
813 }
814 }
815
816 wxString m_name;
817 wxString m_typeName ;
818 wxString m_groupString ;
819 wxString m_helpString ;
820 const wxClassInfo* m_itsClass ;
821 wxPropertyInfoFlags m_flags ;
822 const wxTypeInfo* m_typeInfo ;
823 const wxTypeInfo* m_collectionElementTypeInfo ;
824 wxPropertyAccessor* m_accessor ;
825 wxxVariant m_defaultValue;
826 // string representation of the default value
827 // to be assigned by the designer to the property
828 // when the component is dropped on the container.
829 wxPropertyInfo* m_next ;
830 };
831
832 WX_DECLARE_EXPORTED_STRING_HASH_MAP( wxPropertyInfo* , wxPropertyInfoMap ) ;
833
834 #define WX_BEGIN_PROPERTIES_TABLE(theClass) \
835 wxPropertyInfo *theClass::GetPropertiesStatic() \
836 { \
837 typedef theClass class_t; \
838 static wxPropertyInfo* first = NULL ;
839
840 #define WX_END_PROPERTIES_TABLE() \
841 return first ; }
842
843 #define WX_HIDE_PROPERTY( name ) \
844 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (void*) NULL ) ,NULL , wxxVariant() , wxPROP_DONT_STREAM , wxEmptyString , wxEmptyString ) ;
845
846 #define WX_PROPERTY( name , type , setter , getter ,defaultValue , flags , help , group) \
847 WX_SETTER( name , class_t , type , setter ) \
848 static wxSetter##name _setter##name ; \
849 WX_GETTER( name , class_t , type , getter ) \
850 static wxGetter##name _getter##name ; \
851 static wxPropertyAccessor _accessor##name( &_setter##name , &_getter##name , NULL , NULL ) ; \
852 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) , flags , group , help ) ;
853
854 #define WX_PROPERTY_FLAGS( name , flags , type , setter , getter ,defaultValue , pflags , help , group) \
855 WX_SETTER( name , class_t , type , setter ) \
856 static wxSetter##name _setter##name ; \
857 WX_GETTER( name , class_t , type , getter ) \
858 static wxGetter##name _getter##name ; \
859 static wxPropertyAccessor _accessor##name( &_setter##name , &_getter##name , NULL , NULL ) ; \
860 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (flags*) NULL ) ,&_accessor##name , wxxVariant(defaultValue), wxPROP_ENUM_STORE_LONG | pflags , help , group ) ;
861
862 #define WX_READONLY_PROPERTY( name , type , getter ,defaultValue , flags , help , group) \
863 WX_GETTER( name , class_t , type , getter ) \
864 static wxGetter##name _getter##name ; \
865 static wxPropertyAccessor _accessor##name( NULL , &_getter##name , NULL , NULL ) ; \
866 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue), flags , help , group ) ;
867
868 #define WX_PROPERTY_COLLECTION( name , colltype , addelemtype , adder , getter , flags , help , group ) \
869 WX_ADDER( name , class_t , addelemtype , adder ) \
870 static wxAdder##name _adder##name ; \
871 WX_COLLECTION_GETTER( name , class_t , colltype , getter ) \
872 static wxCollectionGetter##name _collectionGetter##name ; \
873 static wxPropertyAccessor _accessor##name( NULL , NULL ,&_adder##name , &_collectionGetter##name ) ; \
874 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name , flags , help , group ) ;
875
876 #define WX_READONLY_PROPERTY_COLLECTION( name , colltype , addelemtype , getter , flags , help , group) \
877 WX_COLLECTION_GETTER( name , class_t , colltype , getter ) \
878 static wxCollectionGetter##name _collectionGetter##name ; \
879 static wxPropertyAccessor _accessor##name( NULL , NULL , NULL , &_collectionGetter##name ) ; \
880 static wxPropertyInfo _propertyInfo##name( first ,class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name , flags , help , group ) ;
881 /*
882 #define WX_PROPERTY_COLLECTION( name , colltype , addelemtype , adder , getter ) \
883 static wxPropertyCollectionAccessorT<class_t , colltype , addelemtype > _accessor##name( &adder , &getter , #adder , #getter ) ; \
884 static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name ) ;
885
886 #define WX_READONLY_PROPERTY_COLLECTION( name , colltype , addelemtype , getter ) \
887 static wxPropertyCollectionAccessorT<class_t , colltype , addelemtype > _accessor##name( &getter , #getter ) ; \
888 static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name ) ;
889 */
890
891
892
893 #define WX_DELEGATE( name , eventType , eventClass ) \
894 static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \
895 static wxPropertyInfo _propertyInfo##name( first ,class_t::GetClassInfoStatic() , #name , &_typeInfo##name , NULL , wxxVariant() ) ; \
896
897 // ----------------------------------------------------------------------------
898 // Handler Info
899 //
900 // this is describing an event sink
901 // ----------------------------------------------------------------------------
902
903 class wxHandlerInfo
904 {
905 public :
906 wxHandlerInfo( wxHandlerInfo* &iter , const wxString& name , wxObjectEventFunction address , const wxClassInfo* eventClassInfo ) :
907 m_name( name ) , m_eventClassInfo( eventClassInfo ) , m_eventFunction( address )
908 {
909 m_next = NULL ;
910 if ( iter == NULL )
911 iter = this ;
912 else
913 {
914 wxHandlerInfo* i = iter ;
915 while( i->m_next )
916 i = i->m_next ;
917
918 i->m_next = this ;
919 }
920 }
921
922 // return the name of this handler
923 const wxString& GetName() const { return m_name ; }
924
925 // return the class info of the event
926 const wxClassInfo * GetEventClassInfo() const { return m_eventClassInfo ; }
927
928 // get the handler function pointer
929 wxObjectEventFunction GetEventFunction() const { return m_eventFunction ; }
930
931 // returns NULL if this is the last handler of this class
932 wxHandlerInfo* GetNext() const { return m_next ; }
933 private :
934 wxObjectEventFunction m_eventFunction ;
935 wxString m_name;
936 const wxClassInfo* m_eventClassInfo ;
937 wxHandlerInfo* m_next ;
938 };
939
940 #define WX_HANDLER(name,eventClassType) \
941 static wxHandlerInfo _handlerInfo##name( first , #name , (wxObjectEventFunction) (wxEventFunction) &name , CLASSINFO( eventClassType ) ) ;
942
943 #define WX_BEGIN_HANDLERS_TABLE(theClass) \
944 wxHandlerInfo *theClass::GetHandlersStatic() \
945 { \
946 typedef theClass class_t; \
947 static wxHandlerInfo* first = NULL ;
948
949 #define WX_END_HANDLERS_TABLE() \
950 return first ; }
951
952 // ----------------------------------------------------------------------------
953 // Constructor Bridges
954 //
955 // allow to set up constructors with params during runtime
956 // ----------------------------------------------------------------------------
957
958 class WXDLLIMPEXP_BASE wxConstructorBridge
959 {
960 public :
961 virtual void Create(wxObject *o, wxxVariant *args) = 0;
962 };
963
964 // Creator Bridges for all Numbers of Params
965
966 // no params
967
968 template<typename Class>
969 struct wxConstructorBridge_0 : public wxConstructorBridge
970 {
971 void Create(wxObject *o, wxxVariant *)
972 {
973 Class *obj = dynamic_cast<Class*>(o);
974 obj->Create();
975 }
976 };
977
978 struct wxConstructorBridge_Dummy : public wxConstructorBridge
979 {
980 void Create(wxObject *, wxxVariant *)
981 {
982 }
983 } ;
984
985 #define WX_CONSTRUCTOR_0(klass) \
986 wxConstructorBridge_0<klass> constructor##klass ; \
987 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
988 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
989 const int klass::sm_constructorPropertiesCount##klass = 0 ;
990
991 #define WX_CONSTRUCTOR_DUMMY(klass) \
992 wxConstructorBridge_Dummy constructor##klass ; \
993 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
994 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
995 const int klass::sm_constructorPropertiesCount##klass = 0 ;
996
997 // 1 param
998
999 template<typename Class, typename T0>
1000 struct wxConstructorBridge_1 : public wxConstructorBridge
1001 {
1002 void Create(wxObject *o, wxxVariant *args)
1003 {
1004 Class *obj = dynamic_cast<Class*>(o);
1005 obj->Create(
1006 args[0].Get<T0>()
1007 );
1008 }
1009 };
1010
1011 #define WX_CONSTRUCTOR_1(klass,t0,v0) \
1012 wxConstructorBridge_1<klass,t0> constructor##klass ; \
1013 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1014 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 } ; \
1015 const int klass::sm_constructorPropertiesCount##klass = 1 ;
1016
1017 // 2 params
1018
1019 template<typename Class,
1020 typename T0, typename T1>
1021 struct wxConstructorBridge_2 : public wxConstructorBridge
1022 {
1023 void Create(wxObject *o, wxxVariant *args)
1024 {
1025 Class *obj = dynamic_cast<Class*>(o);
1026 obj->Create(
1027 args[0].Get<T0>() ,
1028 args[1].Get<T1>()
1029 );
1030 }
1031 };
1032
1033 #define WX_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
1034 wxConstructorBridge_2<klass,t0,t1> constructor##klass ; \
1035 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1036 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 } ; \
1037 const int klass::sm_constructorPropertiesCount##klass = 2;
1038
1039 // 3 params
1040
1041 template<typename Class,
1042 typename T0, typename T1, typename T2>
1043 struct wxConstructorBridge_3 : public wxConstructorBridge
1044 {
1045 void Create(wxObject *o, wxxVariant *args)
1046 {
1047 Class *obj = dynamic_cast<Class*>(o);
1048 obj->Create(
1049 args[0].Get<T0>() ,
1050 args[1].Get<T1>() ,
1051 args[2].Get<T2>()
1052 );
1053 }
1054 };
1055
1056 #define WX_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
1057 wxConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \
1058 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1059 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 } ; \
1060 const int klass::sm_constructorPropertiesCount##klass = 3 ;
1061
1062 // 4 params
1063
1064 template<typename Class,
1065 typename T0, typename T1, typename T2, typename T3>
1066 struct wxConstructorBridge_4 : public wxConstructorBridge
1067 {
1068 void Create(wxObject *o, wxxVariant *args)
1069 {
1070 Class *obj = dynamic_cast<Class*>(o);
1071 obj->Create(
1072 args[0].Get<T0>() ,
1073 args[1].Get<T1>() ,
1074 args[2].Get<T2>() ,
1075 args[3].Get<T3>()
1076 );
1077 }
1078 };
1079
1080 #define WX_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
1081 wxConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass ; \
1082 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1083 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 } ; \
1084 const int klass::sm_constructorPropertiesCount##klass = 4 ;
1085
1086 // 5 params
1087
1088 template<typename Class,
1089 typename T0, typename T1, typename T2, typename T3, typename T4>
1090 struct wxConstructorBridge_5 : public wxConstructorBridge
1091 {
1092 void Create(wxObject *o, wxxVariant *args)
1093 {
1094 Class *obj = dynamic_cast<Class*>(o);
1095 obj->Create(
1096 args[0].Get<T0>() ,
1097 args[1].Get<T1>() ,
1098 args[2].Get<T2>() ,
1099 args[3].Get<T3>() ,
1100 args[4].Get<T4>()
1101 );
1102 }
1103 };
1104
1105 #define WX_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
1106 wxConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass ; \
1107 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1108 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 } ; \
1109 const int klass::sm_constructorPropertiesCount##klass = 5;
1110
1111 // 6 params
1112
1113 template<typename Class,
1114 typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
1115 struct wxConstructorBridge_6 : public wxConstructorBridge
1116 {
1117 void Create(wxObject *o, wxxVariant *args)
1118 {
1119 Class *obj = dynamic_cast<Class*>(o);
1120 obj->Create(
1121 args[0].Get<T0>() ,
1122 args[1].Get<T1>() ,
1123 args[2].Get<T2>() ,
1124 args[3].Get<T3>() ,
1125 args[4].Get<T4>() ,
1126 args[5].Get<T5>()
1127 );
1128 }
1129 };
1130
1131 #define WX_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1132 wxConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1133 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1134 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 } ; \
1135 const int klass::sm_constructorPropertiesCount##klass = 6;
1136
1137 // 7 params
1138
1139 template<typename Class,
1140 typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
1141 struct wxConstructorBridge_7 : public wxConstructorBridge
1142 {
1143 void Create(wxObject *o, wxxVariant *args)
1144 {
1145 Class *obj = dynamic_cast<Class*>(o);
1146 obj->Create(
1147 args[0].Get<T0>() ,
1148 args[1].Get<T1>() ,
1149 args[2].Get<T2>() ,
1150 args[3].Get<T3>() ,
1151 args[4].Get<T4>() ,
1152 args[5].Get<T5>() ,
1153 args[6].Get<T6>()
1154 );
1155 }
1156 };
1157
1158 #define WX_CONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
1159 wxConstructorBridge_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass ; \
1160 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1161 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 , #v6} ; \
1162 const int klass::sm_constructorPropertiesCount##klass = 7;
1163
1164 // 8 params
1165
1166 template<typename Class,
1167 typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
1168 struct wxConstructorBridge_8 : public wxConstructorBridge
1169 {
1170 void Create(wxObject *o, wxxVariant *args)
1171 {
1172 Class *obj = dynamic_cast<Class*>(o);
1173 obj->Create(
1174 args[0].Get<T0>() ,
1175 args[1].Get<T1>() ,
1176 args[2].Get<T2>() ,
1177 args[3].Get<T3>() ,
1178 args[4].Get<T4>() ,
1179 args[5].Get<T5>() ,
1180 args[6].Get<T6>() ,
1181 args[7].Get<T7>()
1182 );
1183 }
1184 };
1185
1186 #define WX_CONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
1187 wxConstructorBridge_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass ; \
1188 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1189 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 , #v6 , #v7} ; \
1190 const int klass::sm_constructorPropertiesCount##klass = 8;
1191 // ----------------------------------------------------------------------------
1192 // wxClassInfo
1193 // ----------------------------------------------------------------------------
1194
1195 typedef wxObject *(*wxObjectConstructorFn)(void);
1196 typedef wxObject* (*wxVariantToObjectConverter)( wxxVariant &data ) ;
1197 typedef wxxVariant (*wxObjectToVariantConverter)( wxObject* ) ;
1198 class wxWriter ;
1199 class wxPersister ;
1200 typedef bool (*wxObjectStreamingCallback) ( const wxObject *, wxWriter * , wxPersister * , wxxVariantArray & ) ;
1201
1202 class WXDLLIMPEXP_BASE wxClassInfo
1203 {
1204 public:
1205 wxClassInfo(const wxClassInfo **_Parents,
1206 const wxChar *_UnitName,
1207 const wxChar *_ClassName,
1208 int size,
1209 wxObjectConstructorFn ctor ,
1210 wxPropertyInfo *_Props ,
1211 wxHandlerInfo *_Handlers ,
1212 wxConstructorBridge* _Constructor ,
1213 const wxChar ** _ConstructorProperties ,
1214 const int _ConstructorPropertiesCount ,
1215 wxVariantToObjectConverter _PtrConverter1 ,
1216 wxVariantToObjectConverter _Converter2 ,
1217 wxObjectToVariantConverter _Converter3 ,
1218 wxObjectStreamingCallback _streamingCallback = NULL
1219 ) : m_parents(_Parents) , m_unitName(_UnitName) ,m_className(_ClassName),
1220 m_objectSize(size), m_objectConstructor(ctor) , m_firstProperty(_Props ) , m_firstHandler(_Handlers ) , m_constructor( _Constructor ) ,
1221 m_constructorProperties(_ConstructorProperties) , m_constructorPropertiesCount(_ConstructorPropertiesCount),
1222 m_variantOfPtrToObjectConverter( _PtrConverter1 ) , m_variantToObjectConverter( _Converter2 ) , m_objectToVariantConverter( _Converter3 ) ,
1223 m_next(sm_first) , m_streamingCallback( _streamingCallback )
1224 {
1225 sm_first = this;
1226 Register() ;
1227 }
1228
1229 wxClassInfo(const wxChar *_UnitName, const wxChar *_ClassName, const wxClassInfo **_Parents) : m_parents(_Parents) , m_unitName(_UnitName) ,m_className(_ClassName),
1230 m_objectSize(0), m_objectConstructor(NULL) , m_firstProperty(NULL ) , m_firstHandler(NULL ) , m_constructor( NULL ) ,
1231 m_constructorProperties(NULL) , m_constructorPropertiesCount(NULL),
1232 m_variantOfPtrToObjectConverter( NULL ) , m_variantToObjectConverter( NULL ) , m_objectToVariantConverter( NULL ) , m_next(sm_first) ,
1233 m_streamingCallback( NULL )
1234 {
1235 sm_first = this;
1236 Register() ;
1237 }
1238
1239 virtual ~wxClassInfo() ;
1240
1241 // allocates an instance of this class, this object does not have to be initialized or fully constructed
1242 // as this call will be followed by a call to Create
1243 virtual wxObject *AllocateObject() const { return m_objectConstructor ? (*m_objectConstructor)() : 0; }
1244
1245 // 'old naming' for AllocateObject staying here for backward compatibility
1246 wxObject *CreateObject() const { return AllocateObject() ; }
1247
1248 const wxChar *GetClassName() const { return m_className; }
1249 const wxChar *GetIncludeName() const { return m_unitName ; }
1250 const wxClassInfo **GetParents() const { return m_parents; }
1251 int GetSize() const { return m_objectSize; }
1252
1253 wxObjectConstructorFn GetConstructor() const { return m_objectConstructor; }
1254 static const wxClassInfo *GetFirst() { return sm_first; }
1255 const wxClassInfo *GetNext() const { return m_next; }
1256 static wxClassInfo *FindClass(const wxChar *className);
1257
1258 // Climb upwards through inheritance hierarchy.
1259 // Dual inheritance is catered for.
1260
1261 bool IsKindOf(const wxClassInfo *info) const
1262 {
1263 if ( info != 0 )
1264 {
1265 if ( info == this )
1266 return true ;
1267
1268 for ( int i = 0 ; m_parents[i] ; ++ i )
1269 {
1270 if ( m_parents[i]->IsKindOf( info ) )
1271 return true ;
1272 }
1273 }
1274 return false ;
1275 }
1276
1277 // if there is a callback registered with that class it will be called before this
1278 // object will be written to disk, it can veto streaming out this object by returning
1279 // false, if this class has not registered a callback, the search will go up the inheritance tree
1280 // if no callback has been registered true will be returned by default
1281 bool BeforeWriteObject( const wxObject *obj, wxWriter *streamer , wxPersister *persister , wxxVariantArray &metadata) const ;
1282
1283 // gets the streaming callback from this class or any superclass
1284 wxObjectStreamingCallback GetStreamingCallback() const ;
1285
1286 #ifdef WXWIN_COMPATIBILITY_2_4
1287 // Initializes parent pointers and hash table for fast searching.
1288 wxDEPRECATED( static void InitializeClasses() );
1289 // Cleans up hash table used for fast searching.
1290 wxDEPRECATED( static void CleanUpClasses() );
1291 #endif
1292 static void CleanUp();
1293
1294 // returns the first property
1295 const wxPropertyInfo* GetFirstProperty() const { return m_firstProperty ; }
1296
1297 // returns the first handler
1298 const wxHandlerInfo* GetFirstHandler() const { return m_firstHandler ; }
1299
1300 // Call the Create upon an instance of the class, in the end the object is fully
1301 // initialized
1302 virtual void Create (wxObject *object, int ParamCount, wxxVariant *Params) const
1303 {
1304 wxASSERT_MSG( ParamCount == m_constructorPropertiesCount , wxT("Illegal Parameter Count for Create Method")) ;
1305 m_constructor->Create( object , Params ) ;
1306 }
1307
1308 // get number of parameters for constructor
1309 virtual int GetCreateParamCount() const { return m_constructorPropertiesCount; }
1310
1311 // get n-th constructor parameter
1312 virtual const wxChar* GetCreateParamName(int n) const { return m_constructorProperties[n] ; }
1313
1314 // Runtime access to objects for simple properties (get/set) by property name, and variant data
1315 virtual void SetProperty (wxObject *object, const wxChar *propertyName, const wxxVariant &value) const ;
1316 virtual wxxVariant GetProperty (wxObject *object, const wxChar *propertyName) const;
1317
1318 // Runtime access to objects for collection properties by property name
1319 virtual wxxVariantArray GetPropertyCollection(wxObject *object, const wxChar *propertyName) const ;
1320 virtual void AddToPropertyCollection(wxObject *object, const wxChar *propertyName , const wxxVariant& value) const ;
1321
1322 // we must be able to cast variants to wxObject pointers, templates seem not to be suitable
1323 wxObject* VariantToInstance( wxxVariant &data ) const
1324 { if ( data.GetTypeInfo()->GetKind() == wxT_OBJECT )
1325 return m_variantToObjectConverter( data ) ;
1326 else
1327 return m_variantOfPtrToObjectConverter( data ) ;
1328 }
1329
1330 wxxVariant InstanceToVariant( wxObject *object ) const { return m_objectToVariantConverter( object ) ; }
1331
1332 // find property by name
1333 virtual const wxPropertyInfo *FindPropertyInfo (const wxChar *PropertyName) const ;
1334
1335 // find handler by name
1336 virtual const wxHandlerInfo *FindHandlerInfo (const wxChar *PropertyName) const ;
1337
1338 // find property by name
1339 virtual const wxPropertyInfo *FindPropertyInfoInThisClass (const wxChar *PropertyName) const ;
1340
1341 // find handler by name
1342 virtual const wxHandlerInfo *FindHandlerInfoInThisClass (const wxChar *PropertyName) const ;
1343
1344 // puts all the properties of this class and its superclasses in the map, as long as there is not yet
1345 // an entry with the same name (overriding mechanism)
1346 void GetProperties( wxPropertyInfoMap &map ) const ;
1347 public:
1348 const wxChar *m_className;
1349 int m_objectSize;
1350 wxObjectConstructorFn m_objectConstructor;
1351
1352 // class info object live in a linked list:
1353 // pointers to its head and the next element in it
1354
1355 static wxClassInfo *sm_first;
1356 wxClassInfo *m_next;
1357
1358 // FIXME: this should be private (currently used directly by way too
1359 // many clients)
1360 static wxHashTable *sm_classTable;
1361
1362 protected :
1363 wxPropertyInfo * m_firstProperty ;
1364 wxHandlerInfo * m_firstHandler ;
1365 private:
1366 const wxClassInfo** m_parents ;
1367 const wxChar* m_unitName;
1368
1369 wxConstructorBridge* m_constructor ;
1370 const wxChar ** m_constructorProperties ;
1371 const int m_constructorPropertiesCount ;
1372 wxVariantToObjectConverter m_variantOfPtrToObjectConverter ;
1373 wxVariantToObjectConverter m_variantToObjectConverter ;
1374 wxObjectToVariantConverter m_objectToVariantConverter ;
1375 wxObjectStreamingCallback m_streamingCallback ;
1376 const wxPropertyAccessor *FindAccessor (const wxChar *propertyName) const ;
1377
1378
1379 // InitializeClasses() helper
1380 static wxClassInfo *GetBaseByName(const wxChar *name) ;
1381
1382 protected:
1383 // registers the class
1384 void Register();
1385 void Unregister();
1386
1387 DECLARE_NO_COPY_CLASS(wxClassInfo)
1388 };
1389
1390
1391 WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name);
1392
1393 // ----------------------------------------------------------------------------
1394 // wxDynamicObject
1395 // ----------------------------------------------------------------------------
1396 //
1397 // this object leads to having a pure runtime-instantiation
1398
1399 class wxDynamicClassInfo : public wxClassInfo
1400 {
1401 public :
1402 wxDynamicClassInfo( const wxChar *_UnitName, const wxChar *_ClassName , const wxClassInfo* superClass ) ;
1403 virtual ~wxDynamicClassInfo() ;
1404
1405 // constructs a wxDynamicObject with an instance
1406 virtual wxObject *AllocateObject() const ;
1407
1408 // Call the Create method for a class
1409 virtual void Create (wxObject *object, int ParamCount, wxxVariant *Params) const ;
1410
1411 // get number of parameters for constructor
1412 virtual int GetCreateParamCount() const ;
1413
1414 // get i-th constructor parameter
1415 virtual const wxChar* GetCreateParamName(int i) const ;
1416
1417 // Runtime access to objects by property name, and variant data
1418 virtual void SetProperty (wxObject *object, const wxChar *PropertyName, const wxxVariant &Value) const ;
1419 virtual wxxVariant GetProperty (wxObject *object, const wxChar *PropertyName) const ;
1420
1421 void AddProperty( const wxChar *propertyName , const wxTypeInfo* typeInfo ) ;
1422 void AddHandler( const wxChar *handlerName , wxObjectEventFunction address , const wxClassInfo* eventClassInfo ) ;
1423 } ;
1424
1425 // ----------------------------------------------------------------------------
1426 // Dynamic class macros
1427 // ----------------------------------------------------------------------------
1428
1429 #define _DECLARE_DYNAMIC_CLASS(name) \
1430 public: \
1431 static wxClassInfo sm_class##name; \
1432 static const wxClassInfo* sm_classParents##name[] ; \
1433 static wxPropertyInfo* GetPropertiesStatic() ; \
1434 static wxHandlerInfo* GetHandlersStatic() ; \
1435 static wxClassInfo *GetClassInfoStatic() \
1436 { return &name::sm_class##name; } \
1437 virtual wxClassInfo *GetClassInfo() const \
1438 { return &name::sm_class##name; }
1439
1440 #define DECLARE_DYNAMIC_CLASS(name) \
1441 static wxConstructorBridge* sm_constructor##name ; \
1442 static const wxChar * sm_constructorProperties##name[] ; \
1443 static const int sm_constructorPropertiesCount##name ; \
1444 _DECLARE_DYNAMIC_CLASS(name)
1445
1446 #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
1447 DECLARE_NO_ASSIGN_CLASS(name) \
1448 DECLARE_DYNAMIC_CLASS(name)
1449
1450 #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \
1451 DECLARE_NO_COPY_CLASS(name) \
1452 DECLARE_DYNAMIC_CLASS(name)
1453
1454 #define DECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name)
1455 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
1456
1457 // -----------------------------------
1458 // for concrete classes
1459 // -----------------------------------
1460
1461 // Single inheritance with one base class
1462
1463 #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit , callback) \
1464 wxObject* wxConstructorFor##name() \
1465 { return new name; } \
1466 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1467 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1468 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1469 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1470 (int) sizeof(name), \
1471 (wxObjectConstructorFn) wxConstructorFor##name , \
1472 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1473 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name , callback); \
1474 template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1475 template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1476 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1477 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1478 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1479 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1480 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1481 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1482 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1483
1484 #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \
1485 wxObject* wxConstructorFor##name() \
1486 { return new name; } \
1487 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1488 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return &data.Get<name>() ; } \
1489 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1490 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1491 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1492 (int) sizeof(name), \
1493 (wxObjectConstructorFn) wxConstructorFor##name , \
1494 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1495 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name, callback); \
1496 template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1497 template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1498 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1499 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1500 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1501 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1502 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1503 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1504 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1505
1506 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \
1507 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" , NULL ) \
1508 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1509 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1510 WX_CONSTRUCTOR_DUMMY( name )
1511
1512 #define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \
1513 _IMPLEMENT_DYNAMIC_CLASS( name , basename , "" , NULL ) \
1514 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1515 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1516 WX_CONSTRUCTOR_DUMMY( name )
1517
1518 #define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \
1519 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , NULL )
1520
1521 #define IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name , basename , unit , callback ) \
1522 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , &callback )
1523
1524 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \
1525 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit , NULL )
1526
1527 // this is for classes that do not derive from wxobject, there are no creators for these
1528
1529 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name , unit ) \
1530 const wxClassInfo* name::sm_classParents##name[] = { NULL } ; \
1531 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1532 (int) sizeof(name), \
1533 (wxObjectConstructorFn) 0 , \
1534 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1535 0 , 0 , 0 ); \
1536 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1537 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1538 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1539 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1540 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1541 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1542 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1543
1544 // this is for subclasses that still do not derive from wxobject
1545
1546 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name , basename, unit ) \
1547 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1548 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1549 (int) sizeof(name), \
1550 (wxObjectConstructorFn) 0 , \
1551 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1552 0 , 0 , 0 ); \
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
1562 // Multiple inheritance with two base classes
1563
1564 #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit) \
1565 wxObject* wxConstructorFor##name() \
1566 { return new name; } \
1567 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,&basename2::sm_class##basename2 , NULL } ; \
1568 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1569 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1570 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1571 (int) sizeof(name), \
1572 (wxObjectConstructorFn) wxConstructorFor##name , \
1573 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1574 name::sm_constructorPropertiesCount##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1575 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1576 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1577 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1578 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1579 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1580 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1581 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1582
1583 #define IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2) \
1584 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , "") \
1585 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1586 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1587 WX_CONSTRUCTOR_DUMMY( name )
1588
1589 #define IMPLEMENT_DYNAMIC_CLASS2_XTI( name , basename , basename2, unit) \
1590 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , unit)
1591
1592 // -----------------------------------
1593 // for abstract classes
1594 // -----------------------------------
1595
1596 // Single inheritance with one base class
1597
1598 #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
1599 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1600 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1601 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1602 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1603 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1604 (int) sizeof(name), \
1605 (wxObjectConstructorFn) 0 , \
1606 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1607 0 , wxVariantOfPtrToObjectConverter##name ,wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1608 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1609 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1610 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1611 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1612 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1613 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } \
1614 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID) ; assert(0) ; return &s_typeInfo ; }
1615
1616 #define IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1617 _IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1618 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1619 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; }
1620
1621 // Multiple inheritance with two base classes
1622
1623 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
1624 wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \
1625 wxT(#basename2), (int) sizeof(name), \
1626 (wxObjectConstructorFn) 0);
1627
1628 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
1629 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
1630
1631 // --------------------------------------------------------------------------
1632 // Collection Support
1633 // --------------------------------------------------------------------------
1634
1635 template<typename collection_t> void wxListCollectionToVariantArray( const collection_t& coll , wxxVariantArray &value )
1636 {
1637 collection_t::compatibility_iterator current = coll.GetFirst() ;
1638 while (current)
1639 {
1640 value.Add( new wxxVariant(current->GetData()) ) ;
1641 current = current->GetNext();
1642 }
1643 }
1644
1645 template<typename collection_t> void wxArrayCollectionToVariantArray( const collection_t& coll , wxxVariantArray &value )
1646 {
1647 for( size_t i = 0 ; i < coll.GetCount() ; i++ )
1648 {
1649 value.Add( new wxxVariant(coll[i]) ) ;
1650 }
1651 }
1652
1653
1654 #endif