1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: runtime metadata information (extended class info)
4 // Author: Stefan Csomor
8 // Copyright: (c) 1997 Julian Smart
9 // (c) 2003 Stefan Csomor
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
16 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
17 #pragma interface "xti.h"
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.
24 // This means we have the following domains :
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
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
40 #include "wx/memory.h"
42 #include "wx/string.h"
43 #include "wx/arrstr.h"
44 #include "wx/hashmap.h"
48 // we will move this later to defs.h
50 #if !wxCHECK_GCC_VERSION( 3 , 4 )
51 # define wxUSE_MEMBER_TEMPLATES 0
56 # define wxUSE_MEMBER_TEMPLATES 0
60 #ifndef wxUSE_MEMBER_TEMPLATES
61 #define wxUSE_MEMBER_TEMPLATES 1
64 #if wxUSE_MEMBER_TEMPLATES
65 #define WX_TEMPLATED_MEMBER_CALL( method , type ) method<type>()
66 #define WX_TEMPLATED_MEMBER_FIX( type )
68 #define WX_TEMPLATED_MEMBER_CALL( method , type ) method((type*)NULL)
69 #define WX_TEMPLATED_MEMBER_FIX( type ) type* =NULL
72 class WXDLLIMPEXP_BASE wxObject
;
73 class WXDLLIMPEXP_BASE wxClassInfo
;
74 class WXDLLIMPEXP_BASE wxDynamicClassInfo
;
75 class WXDLLIMPEXP_BASE wxHashTable
;
76 class WXDLLIMPEXP_BASE wxObjectRefData
;
77 class WXDLLIMPEXP_BASE wxEvent
;
79 typedef void (wxObject::*wxObjectEventFunction
)(wxEvent
&);
81 // ----------------------------------------------------------------------------
84 // In the header files there would no change from pure c++ code, in the
85 // implementation, an enum would have
86 // to be enumerated eg :
88 // WX_BEGIN_ENUM( wxFlavor )
89 // WX_ENUM_MEMBER( Vanilla )
90 // WX_ENUM_MEMBER( Chocolate )
91 // WX_ENUM_MEMBER( Strawberry )
92 // WX_END_ENUM( wxFlavor )
93 // ----------------------------------------------------------------------------
95 struct WXDLLIMPEXP_BASE wxEnumMemberData
101 class WXDLLIMPEXP_BASE wxEnumData
104 wxEnumData( wxEnumMemberData
* data
) ;
106 // returns true if the member has been found and sets the int value
107 // pointed to accordingly (if ptr != null )
108 // if not found returns false, value left unchanged
109 bool HasEnumMemberValue( const wxChar
*name
, int *value
= NULL
) ;
111 // returns the value of the member, if not found in debug mode an
112 // assert is issued, in release 0 is returned
113 int GetEnumMemberValue(const wxChar
*name
);
115 // returns the name of the enum member having the passed in value
116 // returns an emtpy string if not found
117 const wxChar
*GetEnumMemberName(int value
);
119 // returns the number of members in this enum
120 int GetEnumCount() { return m_count
; }
122 // returns the value of the nth member
123 int GetEnumMemberValueByIndex( int n
) ;
125 // returns the value of the nth member
126 const wxChar
*GetEnumMemberNameByIndex( int n
) ;
128 wxEnumMemberData
*m_members
;
132 #define WX_BEGIN_ENUM( e ) \
133 wxEnumMemberData s_enumDataMembers##e[] = {
135 #define WX_ENUM_MEMBER( v ) { #v, v } ,
137 #define WX_END_ENUM( e ) { NULL , 0 } } ; \
138 wxEnumData s_enumData##e( s_enumDataMembers##e ) ; \
139 wxEnumData *wxGetEnumData(e) { return &s_enumData##e ; } \
140 template<> void wxStringReadValue(const wxString& s , e &data ) \
142 data = (e) s_enumData##e.GetEnumMemberValue(s) ; \
144 template<> void wxStringWriteValue(wxString &s , const e &data ) \
146 s = s_enumData##e.GetEnumMemberName((int)data) ; \
148 void FromLong##e( long data , wxxVariant& result ) { result = wxxVariant((e)data) ;} \
149 void ToLong##e( const wxxVariant& data , long &result ) { result = (long) data.Get<e>() ;} \
150 wxEnumTypeInfo s_typeInfo##e(wxT_ENUM , &s_enumData##e , &wxToStringConverter<e> , &wxFromStringConverter<e> , &ToLong##e , &FromLong##e , typeid(e).name() ) ;
152 // ----------------------------------------------------------------------------
164 // typedef wxBitset<wxFlavor> wxCoupe ;
166 // in the implementation file :
168 // WX_BEGIN_ENUM( wxFlavor )
169 // WX_ENUM_MEMBER( Vanilla )
170 // WX_ENUM_MEMBER( Chocolate )
171 // WX_ENUM_MEMBER( Strawberry )
172 // WX_END_ENUM( wxFlavor )
174 // WX_IMPLEMENT_SET_STREAMING( wxCoupe , wxFlavor )
176 // implementation note : no partial specialization for streaming, but a delegation to a
179 // ----------------------------------------------------------------------------
181 // in order to remove dependancy on string tokenizer
182 void wxSetStringToArray( const wxString
&s
, wxArrayString
&array
) ;
185 void wxSetFromString(const wxString
&s
, wxBitset
<e
> &data
)
187 wxEnumData
* edata
= wxGetEnumData((e
) 0) ;
190 wxArrayString array
;
191 wxSetStringToArray( s
, array
) ;
193 for ( int i
= 0 ; i
< array
.Count() ; ++i
)
197 if ( edata
->HasEnumMemberValue( flag
, &ivalue
) )
199 data
.set( (e
) ivalue
) ;
205 void wxSetToString( wxString
&s
, const wxBitset
<e
> &data
)
207 wxEnumData
* edata
= wxGetEnumData((e
) 0) ;
208 int count
= edata
->GetEnumCount() ;
211 for ( i
= 0 ; i
< count
; i
++ )
213 e value
= (e
) edata
->GetEnumMemberValueByIndex(i
) ;
214 if ( data
.test( value
) )
216 // this could also be done by the templated calls
219 s
+= edata
->GetEnumMemberNameByIndex(i
) ;
224 #define WX_IMPLEMENT_SET_STREAMING(SetName,e) \
225 template<> void wxStringReadValue(const wxString &s , wxBitset<e> &data ) \
227 wxSetFromString( s , data ) ; \
229 template<> void wxStringWriteValue( wxString &s , const wxBitset<e> &data ) \
231 wxSetToString( s , data ) ; \
233 void FromLong##SetName( long data , wxxVariant& result ) { result = wxxVariant(SetName((unsigned long)data)) ;} \
234 void ToLong##SetName( const wxxVariant& data , long &result ) { result = (long) data.Get<SetName>().to_ulong() ;} \
235 wxEnumTypeInfo s_typeInfo##SetName(wxT_SET , &s_enumData##e , &wxToStringConverter<SetName> , &wxFromStringConverter<SetName> , &ToLong##SetName , &FromLong##SetName, typeid(SetName).name() ) ; \
239 void wxFlagsFromString(const wxString
&s
, e
&data
)
241 wxEnumData
* edata
= wxGetEnumData((e
*) 0) ;
244 wxArrayString array
;
245 wxSetStringToArray( s
, array
) ;
247 for ( size_t i
= 0 ; i
< array
.Count() ; ++i
)
251 if ( edata
->HasEnumMemberValue( flag
, &ivalue
) )
253 data
.m_data
|= ivalue
;
259 void wxFlagsToString( wxString
&s
, const e
& data
)
261 wxEnumData
* edata
= wxGetEnumData((e
*) 0) ;
262 int count
= edata
->GetEnumCount() ;
265 long dataValue
= data
.m_data
;
266 for ( i
= 0 ; i
< count
; i
++ )
268 int value
= edata
->GetEnumMemberValueByIndex(i
) ;
269 // make this to allow for multi-bit constants to work
270 if ( value
&& ( dataValue
& value
) == value
)
272 // clear the flags we just set
273 dataValue
&= ~value
;
274 // this could also be done by the templated calls
277 s
+= edata
->GetEnumMemberNameByIndex(i
) ;
282 #define WX_BEGIN_FLAGS( e ) \
283 wxEnumMemberData s_enumDataMembers##e[] = {
285 #define WX_FLAGS_MEMBER( v ) { #v, v } ,
287 #define WX_END_FLAGS( e ) { NULL , 0 } } ; \
288 wxEnumData s_enumData##e( s_enumDataMembers##e ) ; \
289 wxEnumData *wxGetEnumData(e*) { return &s_enumData##e ; } \
290 template<> void wxStringReadValue(const wxString &s , e &data ) \
292 wxFlagsFromString<e>( s , data ) ; \
294 template<> void wxStringWriteValue( wxString &s , const e& data ) \
296 wxFlagsToString<e>( s , data ) ; \
298 void FromLong##e( long data , wxxVariant& result ) { result = wxxVariant(e(data)) ;} \
299 void ToLong##e( const wxxVariant& data , long &result ) { result = (long) data.Get<e>().m_data ;} \
300 wxEnumTypeInfo s_typeInfo##e(wxT_SET , &s_enumData##e , &wxToStringConverter<e> , &wxFromStringConverter<e> , &ToLong##e , &FromLong##e, typeid(e).name() ) ;
301 // ----------------------------------------------------------------------------
303 // ----------------------------------------------------------------------------
306 // All data exposed by the RTTI is characterized using the following classes.
307 // The first characterization is done by wxTypeKind. All enums up to and including
308 // wxT_CUSTOM represent so called simple types. These cannot be divided any further.
309 // They can be converted to and from wxStrings, that's all.
314 wxT_VOID
= 0, // unknown type
324 wxT_STRING
, // must be wxString
325 wxT_SET
, // must be wxBitset<> template
327 wxT_CUSTOM
, // user defined type (e.g. wxPoint)
329 wxT_LAST_SIMPLE_TYPE_KIND
= wxT_CUSTOM
,
331 wxT_OBJECT_PTR
, // object reference
332 wxT_OBJECT
, // embedded object
333 wxT_COLLECTION
, // collection
335 wxT_DELEGATE
, // for connecting against an event source
337 wxT_LAST_TYPE_KIND
= wxT_DELEGATE
// sentinel for bad data, asserts, debugging
340 class WXDLLIMPEXP_BASE wxxVariant
;
341 class WXDLLIMPEXP_BASE wxTypeInfo
;
343 WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxTypeInfo
* , wxTypeInfoMap
, class WXDLLIMPEXP_BASE
) ;
345 class WXDLLIMPEXP_BASE wxTypeInfo
348 typedef void (*converterToString_t
)( const wxxVariant
& data
, wxString
&result
) ;
349 typedef void (*converterFromString_t
)( const wxString
& data
, wxxVariant
&result
) ;
351 wxTypeInfo(wxTypeKind kind
,
352 converterToString_t to
= NULL
, converterFromString_t from
= NULL
,
353 const wxString
&name
= wxEmptyString
):
354 m_toString(to
), m_fromString(from
), m_kind(kind
), m_name(name
)
359 virtual ~wxTypeInfo()
364 // return the kind of this type (wxT_... constants)
365 wxTypeKind
GetKind() const { return m_kind
; }
367 // returns the unique name of this type
368 const wxString
& GetTypeName() const { return m_name
; }
370 // is this type a delegate type
371 bool IsDelegateType() const { return m_kind
== wxT_DELEGATE
; }
373 // is this type a custom type
374 bool IsCustomType() const { return m_kind
== wxT_CUSTOM
; }
376 // is this type an object type
377 bool IsObjectType() const { return m_kind
== wxT_OBJECT
|| m_kind
== wxT_OBJECT_PTR
; }
379 // can the content of this type be converted to and from strings ?
380 bool HasStringConverters() const { return m_toString
!= NULL
&& m_fromString
!= NULL
; }
382 // convert a wxxVariant holding data of this type into a string
383 void ConvertToString( const wxxVariant
& data
, wxString
&result
) const
385 { wxASSERT_MSG( m_toString
, wxT("String conversions not supported") ) ; (*m_toString
)( data
, result
) ; }
387 // convert a string into a wxxVariant holding the corresponding data in this type
388 void ConvertFromString( const wxString
& data
, wxxVariant
&result
) const
389 { wxASSERT_MSG( m_fromString
, wxT("String conversions not supported") ) ; (*m_fromString
)( data
, result
) ; }
391 static wxTypeInfo
*FindType(const wxChar
*typeName
);
398 converterToString_t m_toString
;
399 converterFromString_t m_fromString
;
401 static wxTypeInfoMap
* sm_typeTable
;
407 class WXDLLIMPEXP_BASE wxBuiltInTypeInfo
: public wxTypeInfo
410 wxBuiltInTypeInfo( wxTypeKind kind
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
, const wxString
&name
= wxEmptyString
) :
411 wxTypeInfo( kind
, to
, from
, name
)
412 { wxASSERT_MSG( GetKind() < wxT_SET
, wxT("Illegal Kind for Base Type") ) ; }
415 class WXDLLIMPEXP_BASE wxCustomTypeInfo
: public wxTypeInfo
418 wxCustomTypeInfo( const wxString
&name
, converterToString_t to
, converterFromString_t from
) :
419 wxTypeInfo( wxT_CUSTOM
, to
, from
, name
)
423 class WXDLLIMPEXP_BASE wxEnumTypeInfo
: public wxTypeInfo
426 typedef void (*converterToLong_t
)( const wxxVariant
& data
, long &result
) ;
427 typedef void (*converterFromLong_t
)( long data
, wxxVariant
&result
) ;
429 wxEnumTypeInfo( wxTypeKind kind
, wxEnumData
* enumInfo
, converterToString_t to
, converterFromString_t from
,
430 converterToLong_t toLong
, converterFromLong_t fromLong
, const wxString
&name
) :
431 wxTypeInfo( kind
, to
, from
, name
) , m_toLong( toLong
) , m_fromLong( fromLong
)
432 { wxASSERT_MSG( kind
== wxT_ENUM
|| kind
== wxT_SET
, wxT("Illegal Kind for Enum Type")) ; m_enumInfo
= enumInfo
;}
433 const wxEnumData
* GetEnumData() const { return m_enumInfo
; }
435 // convert a wxxVariant holding data of this type into a long
436 void ConvertToLong( const wxxVariant
& data
, long &result
) const
438 { wxASSERT_MSG( m_toLong
, wxT("Long conversions not supported") ) ; (*m_toLong
)( data
, result
) ; }
440 // convert a long into a wxxVariant holding the corresponding data in this type
441 void ConvertFromLong( long data
, wxxVariant
&result
) const
442 { wxASSERT_MSG( m_fromLong
, wxT("Long conversions not supported") ) ; (*m_fromLong
)( data
, result
) ; }
445 converterToLong_t m_toLong
;
446 converterFromLong_t m_fromLong
;
448 wxEnumData
*m_enumInfo
; // Kind == wxT_ENUM or Kind == wxT_SET
451 class WXDLLIMPEXP_BASE wxClassTypeInfo
: public wxTypeInfo
454 wxClassTypeInfo( wxTypeKind kind
, wxClassInfo
* classInfo
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
, const wxString
&name
= wxEmptyString
) ;
455 const wxClassInfo
*GetClassInfo() const { return m_classInfo
; }
457 wxClassInfo
*m_classInfo
; // Kind == wxT_OBJECT - could be NULL
460 class WXDLLIMPEXP_BASE wxCollectionTypeInfo
: public wxTypeInfo
463 wxCollectionTypeInfo( wxTypeInfo
*elementType
, converterToString_t to
, converterFromString_t from
, const wxString
&name
) :
464 wxTypeInfo( wxT_COLLECTION
, to
, from
, name
)
465 { m_elementType
= elementType
;}
467 const wxTypeInfo
* GetElementType() const { return m_elementType
; }
469 wxTypeInfo
* m_elementType
;
472 // a delegate is an exposed event source
474 class WXDLLIMPEXP_BASE wxDelegateTypeInfo
: public wxTypeInfo
477 wxDelegateTypeInfo( int eventType
, wxClassInfo
* eventClass
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
) ;
478 int GetEventType() const { return m_eventType
; }
480 const wxClassInfo
*m_eventClass
; // (extended will merge into classinfo)
484 template<typename T
> const wxTypeInfo
* wxGetTypeInfo( T
* ) { return wxTypeInfo::FindType(typeid(T
).name()) ; }
486 // this macro is for usage with custom, non-object derived classes and structs, wxPoint is such a custom type
488 #define WX_CUSTOM_TYPE_INFO( e , toString , fromString ) \
489 wxCustomTypeInfo s_typeInfo##e(typeid(e).name() , &toString , &fromString) ;
491 #define WX_COLLECTION_TYPE_INFO( element , collection ) \
492 wxCollectionTypeInfo s_typeInfo##collection( (wxTypeInfo*) wxGetTypeInfo( (element *) NULL) , NULL , NULL , typeid(collection).name() ) ;
494 // sometimes a compiler invents specializations that are nowhere called, use this macro to satisfy the refs
496 #define WX_ILLEGAL_TYPE_SPECIALIZATION( a )
498 template<> const wxTypeInfo* wxGetTypeInfo( a * ) { assert(0) ; \
499 static wxBuiltInTypeInfo s_typeInfo( wxT_VOID ) ; return &s_typeInfo ; } \
500 template<> void wxStringReadValue(const wxString & , a & ) { assert(0) ; }\
501 template<> void wxStringWriteValue(wxString & , a const & ) { assert(0) ; }
504 // ----------------------------------------------------------------------------
505 // wxxVariant as typesafe data holder
506 // ----------------------------------------------------------------------------
508 class WXDLLIMPEXP_BASE wxxVariantData
511 virtual ~wxxVariantData() {}
513 // return a heap allocated duplicate
514 virtual wxxVariantData
* Clone() const = 0 ;
516 // returns the type info of the contentc
517 virtual const wxTypeInfo
* GetTypeInfo() const = 0 ;
520 template<typename T
> class wxxVariantDataT
: public wxxVariantData
523 wxxVariantDataT(const T
& d
) : m_data(d
) {}
524 virtual ~wxxVariantDataT() {}
526 // get a ref to the stored data
527 T
& Get() { return m_data
; }
529 // get a const ref to the stored data
530 const T
& Get() const { return m_data
; }
533 void Set(const T
& d
) { m_data
= d
; }
535 // return a heap allocated duplicate
536 virtual wxxVariantData
* Clone() const { return new wxxVariantDataT
<T
>( Get() ) ; }
538 // returns the type info of the contentc
539 virtual const wxTypeInfo
* GetTypeInfo() const { return wxGetTypeInfo( (T
*) NULL
) ; }
544 class WXDLLIMPEXP_BASE wxxVariant
547 wxxVariant() { m_data
= NULL
; }
548 wxxVariant( wxxVariantData
* data
, const wxString
& name
= wxT("") ) : m_data(data
) , m_name(name
) {}
549 wxxVariant( const wxxVariant
&d
) { if ( d
.m_data
) m_data
= d
.m_data
->Clone() ; else m_data
= NULL
; m_name
= d
.m_name
; }
551 template<typename T
> wxxVariant( const T
& data
, const wxString
& name
= wxT("") ) :
552 m_data(new wxxVariantDataT
<T
>(data
) ), m_name(name
) {}
554 ~wxxVariant() { delete m_data
; }
556 // get a ref to the stored data
557 template<typename T
> T
& Get(WX_TEMPLATED_MEMBER_FIX(T
))
559 wxxVariantDataT
<T
> *dataptr
= dynamic_cast<wxxVariantDataT
<T
>*> (m_data
) ;
560 wxASSERT_MSG( dataptr
, wxT("Cast not possible") ) ;
561 return dataptr
->Get() ;
564 // get a ref to the stored data
565 template<typename T
> const T
& Get(WX_TEMPLATED_MEMBER_FIX(T
)) const
567 const wxxVariantDataT
<T
> *dataptr
= dynamic_cast<const wxxVariantDataT
<T
>*> (m_data
) ;
568 wxASSERT_MSG( dataptr
, wxT("Cast not possible") ) ;
569 return dataptr
->Get() ;
572 template<typename T
> bool HasData() const
574 const wxxVariantDataT
<T
> *dataptr
= dynamic_cast<const wxxVariantDataT
<T
>*> (m_data
) ;
575 return dataptr
!= NULL
;
579 template<typename T
> void Set(const T
& data
) const
582 m_data
= new wxxVariantDataT
<T
>(data
) ;
585 wxxVariant
& operator=(const wxxVariant
&d
)
587 m_data
= d
.m_data
->Clone() ;
592 // gets the stored data casted to a wxObject* , returning NULL if cast is not possible
593 wxObject
* GetAsObject() ;
595 // get the typeinfo of the stored object
596 const wxTypeInfo
* GetTypeInfo() const { return m_data
->GetTypeInfo() ; }
598 // returns this value as string
599 wxString
GetAsString() const
602 GetTypeInfo()->ConvertToString( *this , s
) ;
605 const wxString
& GetName() const { return m_name
; }
607 wxxVariantData
* m_data
;
611 #include <wx/dynarray.h>
613 WX_DECLARE_OBJARRAY_WITH_DECL(wxxVariant
, wxxVariantArray
, class WXDLLIMPEXP_BASE
);
615 // templated streaming, every type must have their specialization for these methods
618 void wxStringReadValue( const wxString
&s
, T
&data
);
621 void wxStringWriteValue( wxString
&s
, const T
&data
);
624 void wxToStringConverter( const wxxVariant
&v
, wxString
&s
) { wxStringWriteValue( s
, v
.WX_TEMPLATED_MEMBER_CALL(Get
, T
) ) ; }
627 void wxFromStringConverter( const wxString
&s
, wxxVariant
&v
) { T d
; wxStringReadValue( s
, d
) ; v
= wxxVariant(d
) ; } \
629 // ----------------------------------------------------------------------------
632 // wxPropertyInfo is used to inquire of the property by name. It doesn't
633 // provide access to the property, only information about it. If you
634 // want access, look at wxPropertyAccessor.
635 // ----------------------------------------------------------------------------
637 class WXDLLIMPEXP_BASE wxSetter
640 wxSetter( const wxString name
) { m_name
= name
; }
641 virtual ~wxSetter() {}
642 virtual void Set( wxObject
*object
, const wxxVariant
&variantValue
) const = 0;
643 const wxString
& GetName() const { return m_name
; }
648 class WXDLLIMPEXP_BASE wxGetter
651 wxGetter( const wxString name
) { m_name
= name
; }
652 virtual ~wxGetter() {}
653 virtual void Get( const wxObject
*object
, wxxVariant
& result
) const = 0;
654 const wxString
& GetName() const { return m_name
; }
659 class WXDLLIMPEXP_BASE wxCollectionGetter
662 wxCollectionGetter( const wxString name
) { m_name
= name
; }
663 virtual ~wxCollectionGetter() {}
664 virtual void Get( const wxObject
*object
, wxxVariantArray
& result
) const = 0;
665 const wxString
& GetName() const { return m_name
; }
670 template<typename coll_t
> void wxCollectionToVariantArray( const coll_t
& coll
, wxxVariantArray
& result
) ;
672 class WXDLLIMPEXP_BASE wxAdder
675 wxAdder( const wxString name
) { m_name
= name
; }
676 virtual ~wxAdder() {}
677 virtual void Add( wxObject
*object
, const wxxVariant
&variantValue
) const= 0;
678 const wxString
& GetName() const { return m_name
; }
685 #define WX_SETTER( property, Klass, valueType, setterMethod ) \
686 class wxSetter##property : public wxSetter \
689 wxSetter##property() : wxSetter( #setterMethod ) {} \
690 ~wxSetter##property() {} \
691 void Set( wxObject *object, const wxxVariant &variantValue ) const \
693 Klass *obj = dynamic_cast<Klass*>(object) ; \
694 if ( variantValue.HasData<valueType>() ) \
695 obj->setterMethod(variantValue.Get<valueType>()) ; \
697 obj->setterMethod(*variantValue.Get<valueType*>()) ; \
701 #define WX_GETTER( property, Klass, valueType , gettermethod ) \
702 class wxGetter##property : public wxGetter \
705 wxGetter##property() : wxGetter( #gettermethod ) {} \
706 ~wxGetter##property() {} \
707 void Get( const wxObject *object , wxxVariant &result) const \
709 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
710 result = wxxVariant( obj->gettermethod() ) ; \
714 #define WX_ADDER( property, Klass, valueType , addermethod ) \
715 class wxAdder##property : public wxAdder \
718 wxAdder##property() : wxAdder( #addermethod ) {} \
719 ~wxAdder##property() {} \
720 void Add( wxObject *object, const wxxVariant &variantValue ) const \
722 Klass *obj = dynamic_cast<Klass*>(object) ; \
723 if ( variantValue.HasData<valueType>() ) \
724 obj->addermethod(variantValue.Get<valueType>()) ; \
726 obj->addermethod(*variantValue.Get<valueType*>()) ; \
730 #define WX_COLLECTION_GETTER( property, Klass, valueType , gettermethod ) \
731 class wxCollectionGetter##property : public wxCollectionGetter \
734 wxCollectionGetter##property() : wxCollectionGetter( #gettermethod ) {} \
735 ~wxCollectionGetter##property() {} \
736 void Get( const wxObject *object , wxxVariantArray &result) const \
738 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
739 wxCollectionToVariantArray( obj->gettermethod() , result ) ; \
743 class WXDLLIMPEXP_BASE wxPropertyAccessor
746 wxPropertyAccessor( wxSetter
*setter
, wxGetter
*getter
, wxAdder
*adder
, wxCollectionGetter
*collectionGetter
)
747 { m_setter
= setter
; m_getter
= getter
; m_adder
= adder
; m_collectionGetter
= collectionGetter
;}
749 virtual ~wxPropertyAccessor() {}
751 // Setting a simple property (non-collection)
752 virtual void SetProperty(wxObject
*object
, const wxxVariant
&value
) const
753 { wxASSERT_MSG(m_setter
,wxT("SetProperty called w/o valid setter") ) ; m_setter
->Set( object
, value
) ;}
755 // Getting a simple property (non-collection)
756 virtual void GetProperty(const wxObject
*object
, wxxVariant
&result
) const
757 { wxASSERT_MSG(m_getter
,wxT("GetProperty called w/o valid getter") ) ; m_getter
->Get( object
, result
) ;}
759 // Adding an element to a collection property
760 virtual void AddToPropertyCollection(wxObject
*object
, const wxxVariant
&value
) const
761 { wxASSERT_MSG(m_adder
,wxT("AddToPropertyCollection called w/o valid adder") ) ; m_adder
->Add( object
, value
) ;}
763 // Getting a collection property
764 virtual void GetPropertyCollection( const wxObject
*obj
, wxxVariantArray
&result
) const
765 { wxASSERT_MSG(m_collectionGetter
,wxT("GetPropertyCollection called w/o valid collection getter") ) ; m_collectionGetter
->Get( obj
, result
) ;}
767 virtual bool HasSetter() const { return m_setter
!= NULL
; }
768 virtual bool HasCollectionGetter() const { return m_collectionGetter
!= NULL
; }
769 virtual bool HasGetter() const { return m_getter
!= NULL
; }
770 virtual bool HasAdder() const { return m_adder
!= NULL
; }
772 virtual const wxString
& GetCollectionGetterName() const
773 { return m_collectionGetter
->GetName() ; }
774 virtual const wxString
& GetGetterName() const
775 { return m_getter
->GetName() ; }
776 virtual const wxString
& GetSetterName() const
777 { return m_setter
->GetName() ; }
778 virtual const wxString
& GetAdderName() const
779 { return m_adder
->GetName() ; }
785 wxCollectionGetter
* m_collectionGetter
;
788 class WXDLLIMPEXP_BASE wxGenericPropertyAccessor
: public wxPropertyAccessor
791 wxGenericPropertyAccessor( const wxString
&propName
) ;
792 ~wxGenericPropertyAccessor() ;
794 void RenameProperty( const wxString
&oldName
, const wxString
&newName
)
796 wxASSERT( oldName
== m_propertyName
) ; m_propertyName
= newName
;
798 virtual bool HasSetter() const { return true ; }
799 virtual bool HasGetter() const { return true ; }
800 virtual bool HasAdder() const { return false ; }
801 virtual bool HasCollectionGetter() const { return false ; }
803 virtual const wxString
& GetGetterName() const
804 { return m_getterName
; }
805 virtual const wxString
& GetSetterName() const
806 { return m_setterName
; }
808 virtual void SetProperty(wxObject
*object
, const wxxVariant
&value
) const ;
809 virtual void GetProperty(const wxObject
*object
, wxxVariant
&value
) const ;
811 // Adding an element to a collection property
812 virtual void AddToPropertyCollection(wxObject
*WXUNUSED(object
), const wxxVariant
&WXUNUSED(value
)) const
813 { wxASSERT_MSG(0,wxT("AddToPropertyCollection called on a generic accessor") ) ;}
815 // Getting a collection property
816 virtual void GetPropertyCollection( const wxObject
*WXUNUSED(obj
), wxxVariantArray
&WXUNUSED(result
)) const
817 { wxASSERT_MSG(0,wxT("GetPropertyCollection called on a generic accessor") ) ;}
819 struct wxGenericPropertyAccessorInternal
;
820 wxGenericPropertyAccessorInternal
* m_data
;
821 wxString m_propertyName
;
822 wxString m_setterName
;
823 wxString m_getterName
;
826 typedef long wxPropertyInfoFlags
;
828 // will be removed in future releases
829 wxPROP_DEPRECATED
= 0x00000001 ,
830 // object graph property, will be streamed with priority (after constructor properties)
831 wxPROP_OBJECT_GRAPH
= 0x00000002 ,
832 // this will only be streamed out and in as enum/set, the internal representation is still a long
833 wxPROP_ENUM_STORE_LONG
= 0x00000004 ,
834 // don't stream out this property, needed eg to avoid streaming out children that are always created by their parents
835 wxPROP_DONT_STREAM
= 0x00000008 ,
838 class WXDLLIMPEXP_BASE wxPropertyInfo
840 friend class WXDLLIMPEXP_BASE wxDynamicClassInfo
;
842 wxPropertyInfo(wxPropertyInfo
* &iter
,
843 wxClassInfo
* itsClass
,
844 const wxString
& name
,
845 const wxString
& typeName
,
846 wxPropertyAccessor
*accessor
,
848 wxPropertyInfoFlags flags
= 0,
849 const wxString
& helpString
= wxEmptyString
,
850 const wxString
& groupString
= wxEmptyString
) :
852 m_groupString(groupString
),
853 m_helpString(helpString
),
854 m_itsClass(itsClass
),
856 m_typeName(typeName
) ,
858 m_collectionElementTypeInfo(NULL
),
859 m_accessor(accessor
),
865 wxPropertyInfo(wxPropertyInfo
* &iter
,
866 wxClassInfo
* itsClass
,
867 const wxString
& name
,
868 wxDelegateTypeInfo
* type
,
869 wxPropertyAccessor
*accessor
,
871 wxPropertyInfoFlags flags
= 0,
872 const wxString
& helpString
= wxEmptyString
,
873 const wxString
& groupString
= wxEmptyString
) :
875 m_groupString(groupString
),
876 m_helpString(helpString
),
877 m_itsClass(itsClass
),
880 m_collectionElementTypeInfo(NULL
),
881 m_accessor(accessor
),
887 wxPropertyInfo(wxPropertyInfo
* &iter
,
888 wxClassInfo
* itsClass
, const wxString
& name
,
889 const wxString
& collectionTypeName
,
890 const wxString
& elementTypeName
,
891 wxPropertyAccessor
*accessor
,
892 wxPropertyInfoFlags flags
= 0,
893 const wxString
& helpString
= wxEmptyString
,
894 const wxString
& groupString
= wxEmptyString
) :
896 m_groupString(groupString
),
897 m_helpString(helpString
),
898 m_itsClass(itsClass
),
901 m_typeName(collectionTypeName
) ,
902 m_collectionElementTypeInfo(NULL
),
903 m_collectionElementTypeName(elementTypeName
),
911 // return the class this property is declared in
912 const wxClassInfo
* GetDeclaringClass() const { return m_itsClass
; }
914 // return the name of this property
915 const wxString
& GetName() const { return m_name
; }
917 // returns the flags of this property
918 wxPropertyInfoFlags
GetFlags() const { return m_flags
;}
920 // returns the short help string of this property
921 const wxString
& GetHelpString() const { return m_helpString
; }
923 // returns the group string of this property
924 const wxString
& GetGroupString() const { return m_groupString
; }
926 // return the element type info of this property (for collections, otherwise NULL)
927 const wxTypeInfo
* GetCollectionElementTypeInfo() const
929 if ( m_collectionElementTypeInfo
== NULL
)
930 m_collectionElementTypeInfo
= wxTypeInfo::FindType(m_collectionElementTypeName
) ;
931 return m_collectionElementTypeInfo
;
934 // return the type info of this property
935 const wxTypeInfo
* GetTypeInfo() const
937 if ( m_typeInfo
== NULL
)
938 m_typeInfo
= wxTypeInfo::FindType(m_typeName
) ;
942 // return the accessor for this property
943 wxPropertyAccessor
* GetAccessor() const { return m_accessor
; }
945 // returns NULL if this is the last property of this class
946 wxPropertyInfo
* GetNext() const { return m_next
; }
948 // returns the default value of this property, its kind may be wxT_VOID if it is not valid
949 wxxVariant
GetDefaultValue() const { return m_defaultValue
; }
951 void Insert(wxPropertyInfo
* &iter
)
958 wxPropertyInfo
* i
= iter
;
967 wxString m_typeName
;
968 wxString m_collectionElementTypeName
;
969 wxString m_groupString
;
970 wxString m_helpString
;
971 wxClassInfo
* m_itsClass
;
972 wxPropertyInfoFlags m_flags
;
973 mutable wxTypeInfo
* m_typeInfo
;
974 mutable wxTypeInfo
* m_collectionElementTypeInfo
;
975 wxPropertyAccessor
* m_accessor
;
976 wxxVariant m_defaultValue
;
977 // string representation of the default value
978 // to be assigned by the designer to the property
979 // when the component is dropped on the container.
980 wxPropertyInfo
* m_next
;
983 WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxPropertyInfo
* , wxPropertyInfoMap
, class WXDLLIMPEXP_BASE
) ;
985 #define WX_BEGIN_PROPERTIES_TABLE(theClass) \
986 wxPropertyInfo *theClass::GetPropertiesStatic() \
988 typedef theClass class_t; \
989 static wxPropertyInfo* first = NULL ;
991 #define WX_END_PROPERTIES_TABLE() \
994 #define WX_HIDE_PROPERTY( pname ) \
995 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , #pname , typeid(void).name() ,NULL , wxxVariant() , wxPROP_DONT_STREAM , wxEmptyString , wxEmptyString ) ;
997 #define WX_PROPERTY( pname , type , setter , getter ,defaultValue , flags , help , group) \
998 WX_SETTER( pname , class_t , type , setter ) \
999 static wxSetter##pname _setter##pname ; \
1000 WX_GETTER( pname , class_t , type , getter ) \
1001 static wxGetter##pname _getter##pname ; \
1002 static wxPropertyAccessor _accessor##pname( &_setter##pname , &_getter##pname , NULL , NULL ) ; \
1003 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , #pname , typeid(type).name() ,&_accessor##pname , wxxVariant(defaultValue) , flags , group , help ) ;
1005 #define WX_PROPERTY_FLAGS( pname , flags , type , setter , getter ,defaultValue , pflags , help , group) \
1006 WX_SETTER( pname , class_t , type , setter ) \
1007 static wxSetter##pname _setter##pname ; \
1008 WX_GETTER( pname , class_t , type , getter ) \
1009 static wxGetter##pname _getter##pname ; \
1010 static wxPropertyAccessor _accessor##pname( &_setter##pname , &_getter##pname , NULL , NULL ) ; \
1011 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , #pname , typeid(flags).name() ,&_accessor##pname , wxxVariant(defaultValue), wxPROP_ENUM_STORE_LONG | pflags , help , group ) ;
1013 #define WX_READONLY_PROPERTY( pname , type , getter ,defaultValue , flags , help , group) \
1014 WX_GETTER( pname , class_t , type , getter ) \
1015 static wxGetter##pname _getter##pname ; \
1016 static wxPropertyAccessor _accessor##pname( NULL , &_getter##pname , NULL , NULL ) ; \
1017 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , #pname , typeid(type).name() ,&_accessor##pname , wxxVariant(defaultValue), flags , help , group ) ;
1019 #define WX_PROPERTY_COLLECTION( pname , colltype , addelemtype , adder , getter , flags , help , group ) \
1020 WX_ADDER( pname , class_t , addelemtype , adder ) \
1021 static wxAdder##pname _adder##pname ; \
1022 WX_COLLECTION_GETTER( pname , class_t , colltype , getter ) \
1023 static wxCollectionGetter##pname _collectionGetter##pname ; \
1024 static wxPropertyAccessor _accessor##pname( NULL , NULL ,&_adder##pname , &_collectionGetter##pname ) ; \
1025 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , #pname , typeid(colltype).name() ,typeid(addelemtype).name() ,&_accessor##pname , flags , help , group ) ;
1027 #define WX_READONLY_PROPERTY_COLLECTION( pname , colltype , addelemtype , getter , flags , help , group) \
1028 WX_COLLECTION_GETTER( pname , class_t , colltype , getter ) \
1029 static wxCollectionGetter##pname _collectionGetter##pname ; \
1030 static wxPropertyAccessor _accessor##pname( NULL , NULL , NULL , &_collectionGetter##pname ) ; \
1031 static wxPropertyInfo _propertyInfo##pname( first ,class_t::GetClassInfoStatic() , #pname , typeid(colltype).name() ,typeid(addelemtype).name() ,&_accessor##pname , flags , help , group ) ;
1034 #define WX_DELEGATE( name , eventType , eventClass ) \
1035 static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \
1036 static wxPropertyInfo _propertyInfo##name( first ,class_t::GetClassInfoStatic() , #name , &_typeInfo##name , NULL , wxxVariant() ) ; \
1038 // ----------------------------------------------------------------------------
1041 // this is describing an event sink
1042 // ----------------------------------------------------------------------------
1044 class WXDLLIMPEXP_BASE wxHandlerInfo
1046 friend class WXDLLIMPEXP_BASE wxDynamicClassInfo
;
1048 wxHandlerInfo(wxHandlerInfo
* &iter
,
1049 wxClassInfo
* itsClass
,
1050 const wxString
& name
,
1051 wxObjectEventFunction address
,
1052 const wxClassInfo
* eventClassInfo
) :
1053 m_eventFunction(address
),
1055 m_eventClassInfo(eventClassInfo
) ,
1056 m_itsClass(itsClass
)
1063 wxHandlerInfo
* i
= iter
;
1073 // return the name of this handler
1074 const wxString
& GetName() const { return m_name
; }
1076 // return the class info of the event
1077 const wxClassInfo
* GetEventClassInfo() const { return m_eventClassInfo
; }
1079 // get the handler function pointer
1080 wxObjectEventFunction
GetEventFunction() const { return m_eventFunction
; }
1082 // returns NULL if this is the last handler of this class
1083 wxHandlerInfo
* GetNext() const { return m_next
; }
1085 // return the class this property is declared in
1086 const wxClassInfo
* GetDeclaringClass() const { return m_itsClass
; }
1089 wxObjectEventFunction m_eventFunction
;
1091 const wxClassInfo
* m_eventClassInfo
;
1092 wxHandlerInfo
* m_next
;
1093 wxClassInfo
* m_itsClass
;
1096 #define WX_HANDLER(name,eventClassType) \
1097 static wxHandlerInfo _handlerInfo##name( first , class_t::GetClassInfoStatic() , #name , (wxObjectEventFunction) (wxEventFunction) &name , CLASSINFO( eventClassType ) ) ;
1099 #define WX_BEGIN_HANDLERS_TABLE(theClass) \
1100 wxHandlerInfo *theClass::GetHandlersStatic() \
1102 typedef theClass class_t; \
1103 static wxHandlerInfo* first = NULL ;
1105 #define WX_END_HANDLERS_TABLE() \
1108 // ----------------------------------------------------------------------------
1109 // Constructor Bridges
1111 // allow to set up constructors with params during runtime
1112 // ----------------------------------------------------------------------------
1114 class WXDLLIMPEXP_BASE wxConstructorBridge
1117 virtual void Create(wxObject
*o
, wxxVariant
*args
) = 0;
1120 // Creator Bridges for all Numbers of Params
1124 template<typename Class
>
1125 struct wxConstructorBridge_0
: public wxConstructorBridge
1127 void Create(wxObject
*o
, wxxVariant
*)
1129 Class
*obj
= dynamic_cast<Class
*>(o
);
1134 struct wxConstructorBridge_Dummy
: public wxConstructorBridge
1136 void Create(wxObject
*, wxxVariant
*)
1141 #define WX_CONSTRUCTOR_0(klass) \
1142 wxConstructorBridge_0<klass> constructor##klass ; \
1143 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1144 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
1145 const int klass::sm_constructorPropertiesCount##klass = 0 ;
1147 #define WX_CONSTRUCTOR_DUMMY(klass) \
1148 wxConstructorBridge_Dummy constructor##klass ; \
1149 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1150 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
1151 const int klass::sm_constructorPropertiesCount##klass = 0 ;
1155 template<typename Class
, typename T0
>
1156 struct wxConstructorBridge_1
: public wxConstructorBridge
1158 void Create(wxObject
*o
, wxxVariant
*args
)
1160 Class
*obj
= dynamic_cast<Class
*>(o
);
1162 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
)
1167 #define WX_CONSTRUCTOR_1(klass,t0,v0) \
1168 wxConstructorBridge_1<klass,t0> constructor##klass ; \
1169 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1170 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 } ; \
1171 const int klass::sm_constructorPropertiesCount##klass = 1 ;
1175 template<typename Class
,
1176 typename T0
, typename T1
>
1177 struct wxConstructorBridge_2
: public wxConstructorBridge
1179 void Create(wxObject
*o
, wxxVariant
*args
)
1181 Class
*obj
= dynamic_cast<Class
*>(o
);
1183 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1184 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
)
1189 #define WX_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
1190 wxConstructorBridge_2<klass,t0,t1> constructor##klass ; \
1191 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1192 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 } ; \
1193 const int klass::sm_constructorPropertiesCount##klass = 2;
1197 template<typename Class
,
1198 typename T0
, typename T1
, typename T2
>
1199 struct wxConstructorBridge_3
: public wxConstructorBridge
1201 void Create(wxObject
*o
, wxxVariant
*args
)
1203 Class
*obj
= dynamic_cast<Class
*>(o
);
1205 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1206 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1207 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
)
1212 #define WX_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
1213 wxConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \
1214 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1215 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 } ; \
1216 const int klass::sm_constructorPropertiesCount##klass = 3 ;
1220 template<typename Class
,
1221 typename T0
, typename T1
, typename T2
, typename T3
>
1222 struct wxConstructorBridge_4
: public wxConstructorBridge
1224 void Create(wxObject
*o
, wxxVariant
*args
)
1226 Class
*obj
= dynamic_cast<Class
*>(o
);
1228 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1229 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1230 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1231 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
)
1236 #define WX_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
1237 wxConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass ; \
1238 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1239 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 } ; \
1240 const int klass::sm_constructorPropertiesCount##klass = 4 ;
1244 template<typename Class
,
1245 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
>
1246 struct wxConstructorBridge_5
: public wxConstructorBridge
1248 void Create(wxObject
*o
, wxxVariant
*args
)
1250 Class
*obj
= dynamic_cast<Class
*>(o
);
1252 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1253 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1254 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1255 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1256 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
)
1261 #define WX_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
1262 wxConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass ; \
1263 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1264 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 } ; \
1265 const int klass::sm_constructorPropertiesCount##klass = 5;
1269 template<typename Class
,
1270 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
1271 struct wxConstructorBridge_6
: public wxConstructorBridge
1273 void Create(wxObject
*o
, wxxVariant
*args
)
1275 Class
*obj
= dynamic_cast<Class
*>(o
);
1277 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1278 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1279 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1280 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1281 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
) ,
1282 args
[5].WX_TEMPLATED_MEMBER_CALL(Get
, T5
)
1287 template<typename Class
,
1288 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
1289 struct wxDirectConstructorBridge_6
: public wxConstructorBridge
1291 void Create(wxObject
*o
, wxxVariant
*args
)
1293 Class
*obj
= new Class(
1294 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1295 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1296 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1297 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1298 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
) ,
1299 args
[5].WX_TEMPLATED_MEMBER_CALL(Get
, T5
)
1304 #define WX_DIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1305 wxDirectConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1306 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1307 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 } ; \
1308 const int klass::sm_constructorPropertiesCount##klass = 6;
1310 #define WX_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1311 wxConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1312 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1313 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 } ; \
1314 const int klass::sm_constructorPropertiesCount##klass = 6;
1318 template<typename Class
,
1319 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
>
1320 struct wxConstructorBridge_7
: public wxConstructorBridge
1322 void Create(wxObject
*o
, wxxVariant
*args
)
1324 Class
*obj
= dynamic_cast<Class
*>(o
);
1326 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1327 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1328 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1329 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1330 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
) ,
1331 args
[5].WX_TEMPLATED_MEMBER_CALL(Get
, T5
) ,
1332 args
[6].WX_TEMPLATED_MEMBER_CALL(Get
, T6
)
1337 #define WX_CONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
1338 wxConstructorBridge_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass ; \
1339 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1340 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 , #v6} ; \
1341 const int klass::sm_constructorPropertiesCount##klass = 7;
1345 template<typename Class
,
1346 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
, typename T7
>
1347 struct wxConstructorBridge_8
: public wxConstructorBridge
1349 void Create(wxObject
*o
, wxxVariant
*args
)
1351 Class
*obj
= dynamic_cast<Class
*>(o
);
1353 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1354 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1355 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1356 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1357 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
) ,
1358 args
[5].WX_TEMPLATED_MEMBER_CALL(Get
, T5
) ,
1359 args
[6].WX_TEMPLATED_MEMBER_CALL(Get
, T6
) ,
1360 args
[7].WX_TEMPLATED_MEMBER_CALL(Get
, T7
)
1365 #define WX_CONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
1366 wxConstructorBridge_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass ; \
1367 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1368 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 , #v6 , #v7} ; \
1369 const int klass::sm_constructorPropertiesCount##klass = 8;
1370 // ----------------------------------------------------------------------------
1372 // ----------------------------------------------------------------------------
1374 typedef wxObject
*(*wxObjectConstructorFn
)(void);
1375 typedef wxObject
* (*wxVariantToObjectConverter
)( wxxVariant
&data
) ;
1376 typedef wxxVariant (*wxObjectToVariantConverter
)( wxObject
* ) ;
1378 class WXDLLIMPEXP_BASE wxWriter
;
1379 class WXDLLIMPEXP_BASE wxPersister
;
1381 typedef bool (*wxObjectStreamingCallback
) ( const wxObject
*, wxWriter
* , wxPersister
* , wxxVariantArray
& ) ;
1383 class WXDLLIMPEXP_BASE wxClassInfo
1385 friend class WXDLLIMPEXP_BASE wxPropertyInfo
;
1386 friend class WXDLLIMPEXP_BASE wxHandlerInfo
;
1388 wxClassInfo(const wxClassInfo
**_Parents
,
1389 const wxChar
*_UnitName
,
1390 const wxChar
*_ClassName
,
1392 wxObjectConstructorFn ctor
,
1393 wxPropertyInfo
*_Props
,
1394 wxHandlerInfo
*_Handlers
,
1395 wxConstructorBridge
* _Constructor
,
1396 const wxChar
** _ConstructorProperties
,
1397 const int _ConstructorPropertiesCount
,
1398 wxVariantToObjectConverter _PtrConverter1
,
1399 wxVariantToObjectConverter _Converter2
,
1400 wxObjectToVariantConverter _Converter3
,
1401 wxObjectStreamingCallback _streamingCallback
= NULL
1404 m_className(_ClassName
),
1406 m_objectConstructor(ctor
),
1408 m_firstProperty(_Props
),
1409 m_firstHandler(_Handlers
),
1410 m_parents(_Parents
),
1411 m_unitName(_UnitName
),
1412 m_constructor(_Constructor
),
1413 m_constructorProperties(_ConstructorProperties
),
1414 m_constructorPropertiesCount(_ConstructorPropertiesCount
),
1415 m_variantOfPtrToObjectConverter(_PtrConverter1
),
1416 m_variantToObjectConverter(_Converter2
),
1417 m_objectToVariantConverter(_Converter3
),
1418 m_streamingCallback(_streamingCallback
)
1424 wxClassInfo(const wxChar
*_UnitName
, const wxChar
*_ClassName
,
1425 const wxClassInfo
**_Parents
) :
1426 m_className(_ClassName
),
1428 m_objectConstructor(NULL
),
1430 m_firstProperty(NULL
),
1431 m_firstHandler(NULL
),
1432 m_parents(_Parents
),
1433 m_unitName(_UnitName
),
1434 m_constructor(NULL
),
1435 m_constructorProperties(NULL
),
1436 m_constructorPropertiesCount(0),
1437 m_variantOfPtrToObjectConverter(NULL
),
1438 m_variantToObjectConverter(NULL
),
1439 m_objectToVariantConverter(NULL
),
1440 m_streamingCallback(NULL
)
1446 virtual ~wxClassInfo() ;
1448 // allocates an instance of this class, this object does not have to be initialized or fully constructed
1449 // as this call will be followed by a call to Create
1450 virtual wxObject
*AllocateObject() const { return m_objectConstructor
? (*m_objectConstructor
)() : 0; }
1452 // 'old naming' for AllocateObject staying here for backward compatibility
1453 wxObject
*CreateObject() const { return AllocateObject() ; }
1455 const wxChar
*GetClassName() const { return m_className
; }
1456 const wxChar
*GetIncludeName() const { return m_unitName
; }
1457 const wxClassInfo
**GetParents() const { return m_parents
; }
1458 int GetSize() const { return m_objectSize
; }
1460 wxObjectConstructorFn
GetConstructor() const { return m_objectConstructor
; }
1461 static const wxClassInfo
*GetFirst() { return sm_first
; }
1462 const wxClassInfo
*GetNext() const { return m_next
; }
1463 static wxClassInfo
*FindClass(const wxChar
*className
);
1465 // Climb upwards through inheritance hierarchy.
1466 // Dual inheritance is catered for.
1468 bool IsKindOf(const wxClassInfo
*info
) const
1475 for ( int i
= 0 ; m_parents
[i
] ; ++ i
)
1477 if ( m_parents
[i
]->IsKindOf( info
) )
1484 // if there is a callback registered with that class it will be called
1485 // before this object will be written to disk, it can veto streaming out
1486 // this object by returning false, if this class has not registered a
1487 // callback, the search will go up the inheritance tree if no callback has
1488 // been registered true will be returned by default
1489 bool BeforeWriteObject( const wxObject
*obj
, wxWriter
*streamer
, wxPersister
*persister
, wxxVariantArray
&metadata
) const ;
1491 // gets the streaming callback from this class or any superclass
1492 wxObjectStreamingCallback
GetStreamingCallback() const ;
1494 #ifdef WXWIN_COMPATIBILITY_2_4
1495 // Initializes parent pointers and hash table for fast searching.
1496 wxDEPRECATED( static void InitializeClasses() );
1497 // Cleans up hash table used for fast searching.
1498 wxDEPRECATED( static void CleanUpClasses() );
1500 static void CleanUp();
1502 // returns the first property
1503 const wxPropertyInfo
* GetFirstProperty() const { return m_firstProperty
; }
1505 // returns the first handler
1506 const wxHandlerInfo
* GetFirstHandler() const { return m_firstHandler
; }
1508 // Call the Create upon an instance of the class, in the end the object is fully
1510 virtual void Create (wxObject
*object
, int ParamCount
, wxxVariant
*Params
) const
1512 wxASSERT_MSG( ParamCount
== m_constructorPropertiesCount
, wxT("Illegal Parameter Count for Create Method")) ;
1513 m_constructor
->Create( object
, Params
) ;
1516 // get number of parameters for constructor
1517 virtual int GetCreateParamCount() const { return m_constructorPropertiesCount
; }
1519 // get n-th constructor parameter
1520 virtual const wxChar
* GetCreateParamName(int n
) const { return m_constructorProperties
[n
] ; }
1522 // Runtime access to objects for simple properties (get/set) by property name, and variant data
1523 virtual void SetProperty (wxObject
*object
, const wxChar
*propertyName
, const wxxVariant
&value
) const ;
1524 virtual wxxVariant
GetProperty (wxObject
*object
, const wxChar
*propertyName
) const;
1526 // Runtime access to objects for collection properties by property name
1527 virtual wxxVariantArray
GetPropertyCollection(wxObject
*object
, const wxChar
*propertyName
) const ;
1528 virtual void AddToPropertyCollection(wxObject
*object
, const wxChar
*propertyName
, const wxxVariant
& value
) const ;
1530 // we must be able to cast variants to wxObject pointers, templates seem not to be suitable
1531 wxObject
* VariantToInstance( wxxVariant
&data
) const
1532 { if ( data
.GetTypeInfo()->GetKind() == wxT_OBJECT
)
1533 return m_variantToObjectConverter( data
) ;
1535 return m_variantOfPtrToObjectConverter( data
) ;
1538 wxxVariant
InstanceToVariant( wxObject
*object
) const { return m_objectToVariantConverter( object
) ; }
1540 // find property by name
1541 virtual const wxPropertyInfo
*FindPropertyInfo (const wxChar
*PropertyName
) const ;
1543 // find handler by name
1544 virtual const wxHandlerInfo
*FindHandlerInfo (const wxChar
*PropertyName
) const ;
1546 // find property by name
1547 virtual wxPropertyInfo
*FindPropertyInfoInThisClass (const wxChar
*PropertyName
) const ;
1549 // find handler by name
1550 virtual wxHandlerInfo
*FindHandlerInfoInThisClass (const wxChar
*PropertyName
) const ;
1552 // puts all the properties of this class and its superclasses in the map, as long as there is not yet
1553 // an entry with the same name (overriding mechanism)
1554 void GetProperties( wxPropertyInfoMap
&map
) const ;
1556 const wxChar
*m_className
;
1558 wxObjectConstructorFn m_objectConstructor
;
1560 // class info object live in a linked list:
1561 // pointers to its head and the next element in it
1563 static wxClassInfo
*sm_first
;
1564 wxClassInfo
*m_next
;
1566 // FIXME: this should be private (currently used directly by way too
1568 static wxHashTable
*sm_classTable
;
1571 wxPropertyInfo
* m_firstProperty
;
1572 wxHandlerInfo
* m_firstHandler
;
1574 const wxClassInfo
** m_parents
;
1575 const wxChar
* m_unitName
;
1577 wxConstructorBridge
* m_constructor
;
1578 const wxChar
** m_constructorProperties
;
1579 const int m_constructorPropertiesCount
;
1580 wxVariantToObjectConverter m_variantOfPtrToObjectConverter
;
1581 wxVariantToObjectConverter m_variantToObjectConverter
;
1582 wxObjectToVariantConverter m_objectToVariantConverter
;
1583 wxObjectStreamingCallback m_streamingCallback
;
1584 const wxPropertyAccessor
*FindAccessor (const wxChar
*propertyName
) const ;
1587 // InitializeClasses() helper
1588 static wxClassInfo
*GetBaseByName(const wxChar
*name
) ;
1591 // registers the class
1595 DECLARE_NO_COPY_CLASS(wxClassInfo
)
1599 WXDLLIMPEXP_BASE wxObject
*wxCreateDynamicObject(const wxChar
*name
);
1601 // ----------------------------------------------------------------------------
1603 // ----------------------------------------------------------------------------
1605 // this object leads to having a pure runtime-instantiation
1607 class WXDLLIMPEXP_BASE wxDynamicClassInfo
: public wxClassInfo
1610 wxDynamicClassInfo( const wxChar
*_UnitName
, const wxChar
*_ClassName
, const wxClassInfo
* superClass
) ;
1611 virtual ~wxDynamicClassInfo() ;
1613 // constructs a wxDynamicObject with an instance
1614 virtual wxObject
*AllocateObject() const ;
1616 // Call the Create method for a class
1617 virtual void Create (wxObject
*object
, int ParamCount
, wxxVariant
*Params
) const ;
1619 // get number of parameters for constructor
1620 virtual int GetCreateParamCount() const ;
1622 // get i-th constructor parameter
1623 virtual const wxChar
* GetCreateParamName(int i
) const ;
1625 // Runtime access to objects by property name, and variant data
1626 virtual void SetProperty (wxObject
*object
, const wxChar
*PropertyName
, const wxxVariant
&Value
) const ;
1627 virtual wxxVariant
GetProperty (wxObject
*object
, const wxChar
*PropertyName
) const ;
1629 // adds a property to this class at runtime
1630 void AddProperty( const wxChar
*propertyName
, const wxTypeInfo
* typeInfo
) ;
1632 // removes an existing runtime-property
1633 void RemoveProperty( const wxChar
*propertyName
) ;
1635 // renames an existing runtime-property
1636 void RenameProperty( const wxChar
*oldPropertyName
, const wxChar
*newPropertyName
) ;
1638 // as a handler to this class at runtime
1639 void AddHandler( const wxChar
*handlerName
, wxObjectEventFunction address
, const wxClassInfo
* eventClassInfo
) ;
1641 // removes an existing runtime-handler
1642 void RemoveHandler( const wxChar
*handlerName
) ;
1644 // renames an existing runtime-handler
1645 void RenameHandler( const wxChar
*oldHandlerName
, const wxChar
*newHandlerName
) ;
1648 // ----------------------------------------------------------------------------
1649 // Dynamic class macros
1650 // ----------------------------------------------------------------------------
1652 #define _DECLARE_DYNAMIC_CLASS(name) \
1654 static wxClassInfo sm_class##name; \
1655 static const wxClassInfo* sm_classParents##name[] ; \
1656 static wxPropertyInfo* GetPropertiesStatic() ; \
1657 static wxHandlerInfo* GetHandlersStatic() ; \
1658 static wxClassInfo *GetClassInfoStatic() \
1659 { return &name::sm_class##name; } \
1660 virtual wxClassInfo *GetClassInfo() const \
1661 { return &name::sm_class##name; }
1663 #define DECLARE_DYNAMIC_CLASS(name) \
1664 static wxConstructorBridge* sm_constructor##name ; \
1665 static const wxChar * sm_constructorProperties##name[] ; \
1666 static const int sm_constructorPropertiesCount##name ; \
1667 _DECLARE_DYNAMIC_CLASS(name)
1669 #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
1670 DECLARE_NO_ASSIGN_CLASS(name) \
1671 DECLARE_DYNAMIC_CLASS(name)
1673 #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \
1674 DECLARE_NO_COPY_CLASS(name) \
1675 DECLARE_DYNAMIC_CLASS(name)
1677 #define DECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name)
1678 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
1680 // -----------------------------------
1681 // for concrete classes
1682 // -----------------------------------
1684 // Single inheritance with one base class
1686 #define _TYPEINFO_CLASSES(n) \
1687 wxClassTypeInfo s_typeInfo##n(wxT_OBJECT , &n::sm_class##n , NULL , NULL , typeid(n).name()) ; \
1688 wxClassTypeInfo s_typeInfoPtr##n(wxT_OBJECT_PTR , &n::sm_class##n , NULL , NULL , typeid(n*).name()) ;
1690 #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit , callback) \
1691 wxObject* wxConstructorFor##name() \
1692 { return new name; } \
1693 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1694 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1695 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1696 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1697 (int) sizeof(name), \
1698 (wxObjectConstructorFn) wxConstructorFor##name , \
1699 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1700 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name , callback); \
1701 _TYPEINFO_CLASSES(name)
1703 #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \
1704 wxObject* wxConstructorFor##name() \
1705 { return new name; } \
1706 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1707 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return &data.Get<name>() ; } \
1708 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1709 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1710 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1711 (int) sizeof(name), \
1712 (wxObjectConstructorFn) wxConstructorFor##name , \
1713 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1714 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name, callback); \
1715 _TYPEINFO_CLASSES(name)
1717 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \
1718 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" , NULL ) \
1719 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1720 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1721 WX_CONSTRUCTOR_DUMMY( name )
1723 #define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \
1724 _IMPLEMENT_DYNAMIC_CLASS( name , basename , "" , NULL ) \
1725 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1726 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1727 WX_CONSTRUCTOR_DUMMY( name )
1729 #define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \
1730 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , NULL )
1732 #define IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name , basename , unit , callback ) \
1733 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , &callback )
1735 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \
1736 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit , NULL )
1738 // this is for classes that do not derive from wxobject, there are no creators for these
1740 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name , unit ) \
1741 const wxClassInfo* name::sm_classParents##name[] = { NULL } ; \
1742 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1743 (int) sizeof(name), \
1744 (wxObjectConstructorFn) 0 , \
1745 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1747 _TYPEINFO_CLASSES(name)
1749 // this is for subclasses that still do not derive from wxobject
1751 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name , basename, unit ) \
1752 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1753 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1754 (int) sizeof(name), \
1755 (wxObjectConstructorFn) 0 , \
1756 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1758 _TYPEINFO_CLASSES(name)
1761 // Multiple inheritance with two base classes
1763 #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit) \
1764 wxObject* wxConstructorFor##name() \
1765 { return new name; } \
1766 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,&basename2::sm_class##basename2 , NULL } ; \
1767 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1768 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1769 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1770 (int) sizeof(name), \
1771 (wxObjectConstructorFn) wxConstructorFor##name , \
1772 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1773 name::sm_constructorPropertiesCount##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1774 _TYPEINFO_CLASSES(name)
1776 #define IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2) \
1777 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , "") \
1778 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1779 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1780 WX_CONSTRUCTOR_DUMMY( name )
1782 #define IMPLEMENT_DYNAMIC_CLASS2_XTI( name , basename , basename2, unit) \
1783 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , unit)
1785 // -----------------------------------
1786 // for abstract classes
1787 // -----------------------------------
1789 // Single inheritance with one base class
1791 #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
1792 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1793 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1794 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1795 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1796 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1797 (int) sizeof(name), \
1798 (wxObjectConstructorFn) 0 , \
1799 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1800 0 , wxVariantOfPtrToObjectConverter##name ,wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1801 _TYPEINFO_CLASSES(name)
1803 #define IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1804 _IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1805 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1806 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; }
1808 // Multiple inheritance with two base classes
1810 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
1811 wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \
1812 wxT(#basename2), (int) sizeof(name), \
1813 (wxObjectConstructorFn) 0);
1815 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
1816 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
1818 // --------------------------------------------------------------------------
1819 // Collection Support
1820 // --------------------------------------------------------------------------
1822 template<typename iter
, typename collection_t
> void wxListCollectionToVariantArray( const collection_t
& coll
, wxxVariantArray
&value
)
1824 iter current
= coll
.GetFirst() ;
1827 value
.Add( new wxxVariant(current
->GetData()) ) ;
1828 current
= current
->GetNext();
1832 template<typename collection_t
> void wxArrayCollectionToVariantArray( const collection_t
& coll
, wxxVariantArray
&value
)
1834 for( size_t i
= 0 ; i
< coll
.GetCount() ; i
++ )
1836 value
.Add( new wxxVariant(coll
[i
]) ) ;