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"
46 // we will move this later to defs.h
48 #if !wxCHECK_GCC_VERSION( 3 , 4 )
49 # define wxUSE_MEMBER_TEMPLATES 0
54 # define wxUSE_MEMBER_TEMPLATES 0
58 #ifndef wxUSE_MEMBER_TEMPLATES
59 #define wxUSE_MEMBER_TEMPLATES 1
62 #if wxUSE_MEMBER_TEMPLATES
63 #define WX_TEMPLATED_MEMBER_CALL( method , type ) method<type>()
64 #define WX_TEMPLATED_MEMBER_FIX( type )
66 #define WX_TEMPLATED_MEMBER_CALL( method , type ) method((type*)NULL)
67 #define WX_TEMPLATED_MEMBER_FIX( type ) type* =NULL
70 class WXDLLIMPEXP_BASE wxObject
;
71 class WXDLLIMPEXP_BASE wxClassInfo
;
72 class WXDLLIMPEXP_BASE wxHashTable
;
73 class WXDLLIMPEXP_BASE wxObjectRefData
;
74 class WXDLLIMPEXP_BASE wxEvent
;
76 typedef void (wxObject
::*wxObjectEventFunction
)(wxEvent
&);
78 // ----------------------------------------------------------------------------
81 // In the header files there would no change from pure c++ code, in the
82 // implementation, an enum would have
83 // to be enumerated eg :
85 // WX_BEGIN_ENUM( wxFlavor )
86 // WX_ENUM_MEMBER( Vanilla )
87 // WX_ENUM_MEMBER( Chocolate )
88 // WX_ENUM_MEMBER( Strawberry )
89 // WX_END_ENUM( wxFlavor )
90 // ----------------------------------------------------------------------------
92 struct WXDLLIMPEXP_BASE wxEnumMemberData
98 class WXDLLIMPEXP_BASE wxEnumData
101 wxEnumData( wxEnumMemberData
* data
) ;
103 // returns true if the member has been found and sets the int value
104 // pointed to accordingly (if ptr != null )
105 // if not found returns false, value left unchanged
106 bool HasEnumMemberValue( const wxChar
*name
, int *value
= NULL
) ;
108 // returns the value of the member, if not found in debug mode an
109 // assert is issued, in release 0 is returned
110 int GetEnumMemberValue(const wxChar
*name
);
112 // returns the name of the enum member having the passed in value
113 // returns an emtpy string if not found
114 const wxChar
*GetEnumMemberName(int value
);
116 // returns the number of members in this enum
117 int GetEnumCount() { return m_count
; }
119 // returns the value of the nth member
120 int GetEnumMemberValueByIndex( int n
) ;
122 // returns the value of the nth member
123 const wxChar
*GetEnumMemberNameByIndex( int n
) ;
125 wxEnumMemberData
*m_members
;
129 #define WX_BEGIN_ENUM( e ) \
130 wxEnumMemberData s_enumDataMembers##e[] = {
132 #define WX_ENUM_MEMBER( v ) { #v, v } ,
134 #define WX_END_ENUM( e ) { NULL , 0 } } ; \
135 wxEnumData s_enumData##e( s_enumDataMembers##e ) ; \
136 wxEnumData *wxGetEnumData(e) { return &s_enumData##e ; } \
137 template<> void wxStringReadValue(const wxString& s , e &data ) \
139 data = (e) s_enumData##e.GetEnumMemberValue(s) ; \
141 template<> void wxStringWriteValue(wxString &s , const e &data ) \
143 s = s_enumData##e.GetEnumMemberName((int)data) ; \
145 void FromLong##e( long data , wxxVariant& result ) { result = wxxVariant((e)data) ;} \
146 void ToLong##e( const wxxVariant& data , long &result ) { result = (long) data.Get<e>() ;} \
147 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 ; } \
148 template<> const wxTypeInfo* wxGetTypeInfo( e ** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; assert(0) ; return &s_typeInfo ; } \
149 template<> void wxStringReadValue(const wxString& , e* & ) \
153 template<> void wxStringWriteValue(wxString &s , e* const & ) \
158 // ----------------------------------------------------------------------------
170 // typedef wxBitset<wxFlavor> wxCoupe ;
172 // in the implementation file :
174 // WX_BEGIN_ENUM( wxFlavor )
175 // WX_ENUM_MEMBER( Vanilla )
176 // WX_ENUM_MEMBER( Chocolate )
177 // WX_ENUM_MEMBER( Strawberry )
178 // WX_END_ENUM( wxFlavor )
180 // WX_IMPLEMENT_SET_STREAMING( wxCoupe , wxFlavor )
182 // implementation note : no partial specialization for streaming, but a delegation to a
185 // ----------------------------------------------------------------------------
187 // in order to remove dependancy on string tokenizer
188 void wxSetStringToArray( const wxString
&s
, wxArrayString
&array
) ;
191 void wxSetFromString(const wxString
&s
, wxBitset
<e
> &data
)
193 wxEnumData
* edata
= wxGetEnumData((e
) 0) ;
196 wxArrayString array
;
197 wxSetStringToArray( s
, array
) ;
199 for ( int i
= 0 ; i
< array
.Count() ; ++i
)
203 if ( edata
->HasEnumMemberValue( flag
, &ivalue
) )
205 data
.set( (e
) ivalue
) ;
211 void wxSetToString( wxString
&s
, const wxBitset
<e
> &data
)
213 wxEnumData
* edata
= wxGetEnumData((e
) 0) ;
214 int count
= edata
->GetEnumCount() ;
217 for ( i
= 0 ; i
< count
; i
++ )
219 e value
= (e
) edata
->GetEnumMemberValueByIndex(i
) ;
220 if ( data
.test( value
) )
222 // this could also be done by the templated calls
225 s
+= edata
->GetEnumMemberNameByIndex(i
) ;
230 // if the wxBitset specialization above does not work for all compilers, add this to the WX_IMPLEMENT_SET_STREAMING macro
231 // template<> const wxTypeInfo* wxGetTypeInfo( SetName * ){ static wxEnumTypeInfo s_typeInfo(wxT_SET , &s_enumData##e) ; return &s_typeInfo ; }
233 #define WX_IMPLEMENT_SET_STREAMING(SetName,e) \
234 template<> void wxStringReadValue(const wxString &s , wxBitset<e> &data ) \
236 wxSetFromString( s , data ) ; \
238 template<> void wxStringWriteValue( wxString &s , const wxBitset<e> &data ) \
240 wxSetToString( s , data ) ; \
242 void FromLong##SetName( long data , wxxVariant& result ) { result = wxxVariant(SetName((unsigned long)data)) ;} \
243 void ToLong##SetName( const wxxVariant& data , long &result ) { result = (long) data.Get<SetName>().to_ulong() ;} \
244 template<> const wxTypeInfo* wxGetTypeInfo( SetName * ) \
246 static wxEnumTypeInfo s_typeInfo(wxT_SET , &s_enumData##e , &wxToStringConverter<SetName> , &wxFromStringConverter<SetName> , &ToLong##SetName , &FromLong##SetName, #SetName ) ; return &s_typeInfo ; \
250 void wxFlagsFromString(const wxString
&s
, e
&data
)
252 wxEnumData
* edata
= wxGetEnumData((e
*) 0) ;
255 wxArrayString array
;
256 wxSetStringToArray( s
, array
) ;
258 for ( int i
= 0 ; i
< array
.Count() ; ++i
)
262 if ( edata
->HasEnumMemberValue( flag
, &ivalue
) )
264 data
.m_data
|= ivalue
;
270 void wxFlagsToString( wxString
&s
, const e
& data
)
272 wxEnumData
* edata
= wxGetEnumData((e
*) 0) ;
273 int count
= edata
->GetEnumCount() ;
276 long dataValue
= data
.m_data
;
277 for ( i
= 0 ; i
< count
; i
++ )
279 int value
= edata
->GetEnumMemberValueByIndex(i
) ;
280 // make this to allow for multi-bit constants to work
281 if ( value
&& ( dataValue
& value
) == value
)
283 // clear the flags we just set
284 dataValue
&= ~value
;
285 // this could also be done by the templated calls
288 s
+= edata
->GetEnumMemberNameByIndex(i
) ;
293 #define WX_BEGIN_FLAGS( e ) \
294 wxEnumMemberData s_enumDataMembers##e[] = {
296 #define WX_FLAGS_MEMBER( v ) { #v, v } ,
298 #define WX_END_FLAGS( e ) { NULL , 0 } } ; \
299 wxEnumData s_enumData##e( s_enumDataMembers##e ) ; \
300 wxEnumData *wxGetEnumData(e*) { return &s_enumData##e ; } \
301 template<> void wxStringReadValue(const wxString &s , e &data ) \
303 wxFlagsFromString<e>( s , data ) ; \
305 template<> void wxStringWriteValue( wxString &s , const e& data ) \
307 wxFlagsToString<e>( s , data ) ; \
309 void FromLong##e( long data , wxxVariant& result ) { result = wxxVariant(e(data)) ;} \
310 void ToLong##e( const wxxVariant& data , long &result ) { result = (long) data.Get<e>().m_data ;} \
311 template<> const wxTypeInfo* wxGetTypeInfo( e * ) \
313 static wxEnumTypeInfo s_typeInfo(wxT_SET , &s_enumData##e , &wxToStringConverter<e> , &wxFromStringConverter<e> , &ToLong##e , &FromLong##e, #e ) ; return &s_typeInfo ; \
316 // ----------------------------------------------------------------------------
318 // ----------------------------------------------------------------------------
321 // All data exposed by the RTTI is characterized using the following classes.
322 // The first characterization is done by wxTypeKind. All enums up to and including
323 // wxT_CUSTOM represent so called simple types. These cannot be divided any further.
324 // They can be converted to and from wxStrings, that's all.
329 wxT_VOID
= 0, // unknown type
339 wxT_STRING
, // must be wxString
340 wxT_SET
, // must be wxBitset<> template
342 wxT_CUSTOM
, // user defined type (e.g. wxPoint)
344 wxT_LAST_SIMPLE_TYPE_KIND
= wxT_CUSTOM
,
346 wxT_OBJECT_PTR
, // object reference
347 wxT_OBJECT
, // embedded object
348 wxT_COLLECTION
, // collection
350 wxT_DELEGATE
, // for connecting against an event source
352 wxT_LAST_TYPE_KIND
= wxT_DELEGATE
// sentinel for bad data, asserts, debugging
358 WX_DECLARE_EXPORTED_STRING_HASH_MAP( wxTypeInfo
* , wxTypeInfoMap
) ;
360 class WXDLLIMPEXP_BASE wxTypeInfo
363 typedef void (*converterToString_t
)( const wxxVariant
& data
, wxString
&result
) ;
364 typedef void (*converterFromString_t
)( const wxString
& data
, wxxVariant
&result
) ;
366 wxTypeInfo(wxTypeKind kind
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
, const wxString
&name
= wxEmptyString
) :
367 m_kind( kind
) , m_toString(to
) , m_fromString(from
) , m_name(name
)
372 virtual ~wxTypeInfo()
377 // return the kind of this type (wxT_... constants)
378 wxTypeKind
GetKind() const { return m_kind
; }
380 // returns the unique name of this type
381 const wxString
& GetTypeName() const { return m_name
; }
383 // is this type a delegate type
384 bool IsDelegateType() const { return m_kind
== wxT_DELEGATE
; }
386 // is this type a custom type
387 bool IsCustomType() const { return m_kind
== wxT_CUSTOM
; }
389 // is this type an object type
390 bool IsObjectType() const { return m_kind
== wxT_OBJECT
|| m_kind
== wxT_OBJECT_PTR
; }
392 // can the content of this type be converted to and from strings ?
393 bool HasStringConverters() const { return m_toString
!= NULL
&& m_fromString
!= NULL
; }
395 // convert a wxxVariant holding data of this type into a string
396 void ConvertToString( const wxxVariant
& data
, wxString
&result
) const
398 { wxASSERT_MSG( m_toString
, wxT("String conversions not supported") ) ; (*m_toString
)( data
, result
) ; }
400 // convert a string into a wxxVariant holding the corresponding data in this type
401 void ConvertFromString( const wxString
& data
, wxxVariant
&result
) const
402 { wxASSERT_MSG( m_fromString
, wxT("String conversions not supported") ) ; (*m_fromString
)( data
, result
) ; }
404 static wxTypeInfo
*FindType(const wxChar
*typeName
);
411 converterToString_t m_toString
;
412 converterFromString_t m_fromString
;
414 static wxTypeInfoMap
* sm_typeTable
;
420 class WXDLLIMPEXP_BASE wxBuiltInTypeInfo
: public wxTypeInfo
423 wxBuiltInTypeInfo( wxTypeKind kind
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
, const wxString
&name
= wxEmptyString
) :
424 wxTypeInfo( kind
, to
, from
, name
)
425 { wxASSERT_MSG( GetKind() < wxT_SET
, wxT("Illegal Kind for Base Type") ) ; }
428 class WXDLLIMPEXP_BASE wxCustomTypeInfo
: public wxTypeInfo
431 wxCustomTypeInfo( const wxString
&name
, converterToString_t to
, converterFromString_t from
) :
432 wxTypeInfo( wxT_CUSTOM
, to
, from
, name
)
436 class WXDLLIMPEXP_BASE wxEnumTypeInfo
: public wxTypeInfo
439 typedef void (*converterToLong_t
)( const wxxVariant
& data
, long &result
) ;
440 typedef void (*converterFromLong_t
)( long data
, wxxVariant
&result
) ;
442 wxEnumTypeInfo( wxTypeKind kind
, wxEnumData
* enumInfo
, converterToString_t to
, converterFromString_t from
,
443 converterToLong_t toLong
, converterFromLong_t fromLong
, const wxString
&name
) :
444 wxTypeInfo( kind
, to
, from
, name
) , m_toLong( toLong
) , m_fromLong( fromLong
)
445 { wxASSERT_MSG( kind
== wxT_ENUM
|| kind
== wxT_SET
, wxT("Illegal Kind for Enum Type")) ; m_enumInfo
= enumInfo
;}
446 const wxEnumData
* GetEnumData() const { return m_enumInfo
; }
448 // convert a wxxVariant holding data of this type into a long
449 void ConvertToLong( const wxxVariant
& data
, long &result
) const
451 { wxASSERT_MSG( m_toLong
, wxT("Long conversions not supported") ) ; (*m_toLong
)( data
, result
) ; }
453 // convert a long into a wxxVariant holding the corresponding data in this type
454 void ConvertFromLong( long data
, wxxVariant
&result
) const
455 { wxASSERT_MSG( m_fromLong
, wxT("Long conversions not supported") ) ; (*m_fromLong
)( data
, result
) ; }
458 converterToLong_t m_toLong
;
459 converterFromLong_t m_fromLong
;
461 wxEnumData
*m_enumInfo
; // Kind == wxT_ENUM or Kind == wxT_SET
464 class WXDLLIMPEXP_BASE wxClassTypeInfo
: public wxTypeInfo
467 wxClassTypeInfo( wxTypeKind kind
, wxClassInfo
* classInfo
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
) ;
468 const wxClassInfo
*GetClassInfo() const { return m_classInfo
; }
470 wxClassInfo
*m_classInfo
; // Kind == wxT_OBJECT - could be NULL
473 class WXDLLIMPEXP_BASE wxCollectionTypeInfo
: public wxTypeInfo
476 wxCollectionTypeInfo( wxTypeInfo
*elementType
, converterToString_t to
, converterFromString_t from
, const wxString
&name
) :
477 wxTypeInfo( wxT_COLLECTION
, to
, from
, name
)
478 { m_elementType
= elementType
;}
480 const wxTypeInfo
* GetElementType() const { return m_elementType
; }
482 wxTypeInfo
* m_elementType
;
485 // a delegate is an exposed event source
487 class WXDLLIMPEXP_BASE wxDelegateTypeInfo
: public wxTypeInfo
490 wxDelegateTypeInfo( int eventType
, wxClassInfo
* eventClass
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
) ;
491 int GetEventType() const { return m_eventType
; }
493 const wxClassInfo
*m_eventClass
; // (extended will merge into classinfo)
497 template<typename T
> const wxTypeInfo
* wxGetTypeInfo( T
* ) ;
499 // this macro is for usage with custom, non-object derived classes and structs, wxPoint is such a custom type
501 #define WX_CUSTOM_TYPE_INFO( e ) \
502 template<> const wxTypeInfo* wxGetTypeInfo( e ** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID) ; assert(0) ; return &s_typeInfo ; } \
503 template<> const wxTypeInfo* wxGetTypeInfo( e * ){ static wxCustomTypeInfo s_typeInfo(#e, &wxToStringConverter<e> , &wxFromStringConverter<e>) ; return &s_typeInfo ; }
505 #define WX_COLLECTION_TYPE_INFO( element , collection ) \
506 template<> const wxTypeInfo* wxGetTypeInfo( collection * ) \
508 static wxCollectionTypeInfo s_typeInfo( (wxTypeInfo*) wxGetTypeInfo( (element *) NULL) , NULL , NULL , #collection ) ; \
509 return &s_typeInfo ; \
512 // sometimes a compiler invents specializations that are nowhere called, use this macro to satisfy the refs
514 #define WX_ILLEGAL_TYPE_SPECIALIZATION( a ) \
515 template<> const wxTypeInfo* wxGetTypeInfo( a * ) { assert(0) ; \
516 static wxBuiltInTypeInfo s_typeInfo( wxT_VOID ) ; return &s_typeInfo ; } \
517 template<> void wxStringReadValue(const wxString & , a & ) { assert(0) ; }\
518 template<> void wxStringWriteValue(wxString & , a const & ) { assert(0) ; }
520 // ----------------------------------------------------------------------------
521 // wxxVariant as typesafe data holder
522 // ----------------------------------------------------------------------------
524 class WXDLLIMPEXP_BASE wxxVariantData
527 virtual ~wxxVariantData() {}
529 // return a heap allocated duplicate
530 virtual wxxVariantData
* Clone() const = 0 ;
532 // returns the type info of the contentc
533 virtual const wxTypeInfo
* GetTypeInfo() const = 0 ;
536 template<typename T
> class WXDLLIMPEXP_BASE wxxVariantDataT
: public wxxVariantData
539 wxxVariantDataT(const T
& d
) : m_data(d
) {}
540 virtual ~wxxVariantDataT() {}
542 // get a ref to the stored data
543 T
& Get() { return m_data
; }
545 // get a const ref to the stored data
546 const T
& Get() const { return m_data
; }
549 void Set(const T
& d
) { m_data
= d
; }
551 // return a heap allocated duplicate
552 virtual wxxVariantData
* Clone() const { return new wxxVariantDataT
<T
>( Get() ) ; }
554 // returns the type info of the contentc
555 virtual const wxTypeInfo
* GetTypeInfo() const { return wxGetTypeInfo( (T
*) NULL
) ; }
560 class WXDLLIMPEXP_BASE wxxVariant
563 wxxVariant() { m_data
= NULL
; }
564 wxxVariant( wxxVariantData
* data
, const wxString
& name
= wxT("") ) : m_data(data
) , m_name(name
) {}
565 wxxVariant( const wxxVariant
&d
) { if ( d
.m_data
) m_data
= d
.m_data
->Clone() ; else m_data
= NULL
; m_name
= d
.m_name
; }
567 template<typename T
> wxxVariant( const T
& data
, const wxString
& name
= wxT("") ) :
568 m_data(new wxxVariantDataT
<T
>(data
) ), m_name(name
) {}
570 ~wxxVariant() { delete m_data
; }
572 // get a ref to the stored data
573 template<typename T
> T
& Get(WX_TEMPLATED_MEMBER_FIX(T
))
575 wxxVariantDataT
<T
> *dataptr
= dynamic_cast<wxxVariantDataT
<T
>*> (m_data
) ;
576 wxASSERT_MSG( dataptr
, wxT("Cast not possible") ) ;
577 return dataptr
->Get() ;
580 // get a ref to the stored data
581 template<typename T
> const T
& Get(WX_TEMPLATED_MEMBER_FIX(T
)) const
583 const wxxVariantDataT
<T
> *dataptr
= dynamic_cast<const wxxVariantDataT
<T
>*> (m_data
) ;
584 wxASSERT_MSG( dataptr
, wxT("Cast not possible") ) ;
585 return dataptr
->Get() ;
588 template<typename T
> bool HasData() const
590 const wxxVariantDataT
<T
> *dataptr
= dynamic_cast<const wxxVariantDataT
<T
>*> (m_data
) ;
591 return dataptr
!= NULL
;
595 template<typename T
> void Set(const T
& data
) const
598 m_data
= new wxxVariantDataT
<T
>(data
) ;
601 wxxVariant
& operator=(const wxxVariant
&d
)
603 m_data
= d
.m_data
->Clone() ;
608 // gets the stored data casted to a wxObject* , returning NULL if cast is not possible
609 wxObject
* GetAsObject() ;
611 // get the typeinfo of the stored object
612 const wxTypeInfo
* GetTypeInfo() const { return m_data
->GetTypeInfo() ; }
614 // returns this value as string
615 wxString
GetAsString() const
618 GetTypeInfo()->ConvertToString( *this , s
) ;
621 const wxString
& GetName() const { return m_name
; }
623 wxxVariantData
* m_data
;
627 #include <wx/dynarray.h>
629 WX_DECLARE_OBJARRAY_WITH_DECL(wxxVariant
, wxxVariantArray
, class WXDLLIMPEXP_BASE
);
631 // templated streaming, every type must have their specialization for these methods
634 void wxStringReadValue( const wxString
&s
, T
&data
);
637 void wxStringWriteValue( wxString
&s
, const T
&data
);
640 void wxToStringConverter( const wxxVariant
&v
, wxString
&s
) { wxStringWriteValue( s
, v
.WX_TEMPLATED_MEMBER_CALL(Get
, T
) ) ; }
643 void wxFromStringConverter( const wxString
&s
, wxxVariant
&v
) { T d
; wxStringReadValue( s
, d
) ; v
= wxxVariant(d
) ; } \
645 // ----------------------------------------------------------------------------
648 // wxPropertyInfo is used to inquire of the property by name. It doesn't
649 // provide access to the property, only information about it. If you
650 // want access, look at wxPropertyAccessor.
651 // ----------------------------------------------------------------------------
656 wxSetter( const wxString name
) { m_name
= name
; }
657 virtual void Set( wxObject
*object
, const wxxVariant
&variantValue
) const = 0;
658 const wxString
& GetName() const { return m_name
; }
666 wxGetter( const wxString name
) { m_name
= name
; }
667 virtual void Get( const wxObject
*object
, wxxVariant
& result
) const = 0;
668 const wxString
& GetName() const { return m_name
; }
673 class wxCollectionGetter
676 wxCollectionGetter( const wxString name
) { m_name
= name
; }
677 virtual void Get( const wxObject
*object
, wxxVariantArray
& result
) const = 0;
678 const wxString
& GetName() const { return m_name
; }
683 template<typename coll_t
> void wxCollectionToVariantArray( const coll_t
& coll
, wxxVariantArray
& result
) ;
688 wxAdder( const wxString name
) { m_name
= name
; }
689 virtual void Add( wxObject
*object
, const wxxVariant
&variantValue
) const= 0;
690 const wxString
& GetName() const { return m_name
; }
697 #define WX_SETTER( property, Klass, valueType, setterMethod ) \
698 class wxSetter##property : public wxSetter \
701 wxSetter##property() : wxSetter( #setterMethod ) {} \
702 void Set( wxObject *object, const wxxVariant &variantValue ) const \
704 Klass *obj = dynamic_cast<Klass*>(object) ; \
705 if ( variantValue.HasData<valueType>() ) \
706 obj->setterMethod(variantValue.Get<valueType>()) ; \
708 obj->setterMethod(*variantValue.Get<valueType*>()) ; \
712 #define WX_GETTER( property, Klass, valueType , gettermethod ) \
713 class wxGetter##property : public wxGetter \
716 wxGetter##property() : wxGetter( #gettermethod ) {} \
717 void Get( const wxObject *object , wxxVariant &result) const \
719 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
720 result = wxxVariant( obj->gettermethod() ) ; \
724 #define WX_ADDER( property, Klass, valueType , addermethod ) \
725 class wxAdder##property : public wxAdder \
728 wxAdder##property() : wxAdder( #addermethod ) {} \
729 void Add( wxObject *object, const wxxVariant &variantValue ) const \
731 Klass *obj = dynamic_cast<Klass*>(object) ; \
732 if ( variantValue.HasData<valueType>() ) \
733 obj->addermethod(variantValue.Get<valueType>()) ; \
735 obj->addermethod(*variantValue.Get<valueType*>()) ; \
739 #define WX_COLLECTION_GETTER( property, Klass, valueType , gettermethod ) \
740 class wxCollectionGetter##property : public wxCollectionGetter \
743 wxCollectionGetter##property() : wxCollectionGetter( #gettermethod ) {} \
744 void Get( const wxObject *object , wxxVariantArray &result) const \
746 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
747 wxCollectionToVariantArray( obj->gettermethod() , result ) ; \
751 class WXDLLIMPEXP_BASE wxPropertyAccessor
754 wxPropertyAccessor( wxSetter
*setter
, wxGetter
*getter
, wxAdder
*adder
, wxCollectionGetter
*collectionGetter
)
755 { m_setter
= setter
; m_getter
= getter
; m_adder
= adder
; m_collectionGetter
= collectionGetter
;}
757 virtual ~wxPropertyAccessor() {}
759 // Setting a simple property (non-collection)
760 virtual void SetProperty(wxObject
*object
, const wxxVariant
&value
) const
761 { wxASSERT_MSG(m_setter
,wxT("SetProperty called w/o valid setter") ) ; m_setter
->Set( object
, value
) ;}
763 // Getting a simple property (non-collection)
764 virtual void GetProperty(const wxObject
*object
, wxxVariant
&result
) const
765 { wxASSERT_MSG(m_getter
,wxT("GetProperty called w/o valid getter") ) ; m_getter
->Get( object
, result
) ;}
767 // Adding an element to a collection property
768 virtual void AddToPropertyCollection(wxObject
*object
, const wxxVariant
&value
) const
769 { wxASSERT_MSG(m_adder
,wxT("AddToPropertyCollection called w/o valid adder") ) ; m_adder
->Add( object
, value
) ;}
771 // Getting a collection property
772 virtual void GetPropertyCollection( const wxObject
*obj
, wxxVariantArray
&result
) const
773 { wxASSERT_MSG(m_collectionGetter
,wxT("GetPropertyCollection called w/o valid collection getter") ) ; m_collectionGetter
->Get( obj
, result
) ;}
775 virtual bool HasSetter() const { return m_setter
!= NULL
; }
776 virtual bool HasCollectionGetter() const { return m_collectionGetter
!= NULL
; }
777 virtual bool HasGetter() const { return m_getter
!= NULL
; }
778 virtual bool HasAdder() const { return m_adder
!= NULL
; }
780 virtual const wxString
& GetCollectionGetterName() const
781 { return m_collectionGetter
->GetName() ; }
782 virtual const wxString
& GetGetterName() const
783 { return m_getter
->GetName() ; }
784 virtual const wxString
& GetSetterName() const
785 { return m_setter
->GetName() ; }
786 virtual const wxString
& GetAdderName() const
787 { return m_adder
->GetName() ; }
789 virtual wxxVariant ReadValue( const wxString &value ) const ;
790 virtual void WriteValue( wxString& value , const wxObject *o ) const ;
796 wxCollectionGetter
* m_collectionGetter
;
799 class WXDLLIMPEXP_BASE wxGenericPropertyAccessor
: public wxPropertyAccessor
802 wxGenericPropertyAccessor( const wxString
&propName
) ;
803 ~wxGenericPropertyAccessor() ;
805 virtual bool HasSetter() const { return true ; }
806 virtual bool HasGetter() const { return true ; }
807 virtual bool HasAdder() const { return false ; }
808 virtual bool HasCollectionGetter() const { return false ; }
810 virtual const wxString
& GetGetterName() const
811 { return m_getterName
; }
812 virtual const wxString
& GetSetterName() const
813 { return m_setterName
; }
815 virtual void SetProperty(wxObject
*object
, const wxxVariant
&value
) const ;
816 virtual void GetProperty(const wxObject
*object
, wxxVariant
&value
) const ;
818 // Adding an element to a collection property
819 virtual void AddToPropertyCollection(wxObject
*WXUNUSED(object
), const wxxVariant
&WXUNUSED(value
)) const
820 { wxASSERT_MSG(0,wxT("AddToPropertyCollection called on a generic accessor") ) ;}
822 // Getting a collection property
823 virtual void GetPropertyCollection( const wxObject
*WXUNUSED(obj
), wxxVariantArray
&WXUNUSED(result
)) const
824 { wxASSERT_MSG(0,wxT("GetPropertyCollection called on a generic accessor") ) ;}
826 struct wxGenericPropertyAccessorInternal
;
827 wxGenericPropertyAccessorInternal
* m_data
;
828 wxString m_propertyName
;
829 wxString m_setterName
;
830 wxString m_getterName
;
833 typedef long wxPropertyInfoFlags
;
835 // will be removed in future releases
836 wxPROP_DEPRECATED
= 0x00000001 ,
837 // object graph property, will be streamed with priority (after constructor properties)
838 wxPROP_OBJECT_GRAPH
= 0x00000002 ,
839 // this will only be streamed out and in as enum/set, the internal representation is still a long
840 wxPROP_ENUM_STORE_LONG
= 0x00000004 ,
841 // don't stream out this property, needed eg to avoid streaming out children that are always created by their parents
842 wxPROP_DONT_STREAM
= 0x00000008 ,
845 class WXDLLIMPEXP_BASE wxPropertyInfo
848 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
) :
849 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
)
854 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
) :
855 m_name( name
) , m_itsClass( itsClass
) , m_typeInfo( collTypeInfo
) , m_accessor( accessor
) , m_collectionElementTypeInfo(elemTypeInfo
) , m_helpString (helpString
) , m_groupString( groupString
) , m_flags(flags
)
860 // return the class this property is declared in
861 const wxClassInfo
* GetDeclaringClass() const { return m_itsClass
; }
863 // return the name of this property
864 const wxString
& GetName() const { return m_name
; }
866 // returns the flags of this property
867 wxPropertyInfoFlags
GetFlags() const { return m_flags
;}
869 // returns the short help string of this property
870 const wxString
& GetHelpString() const { return m_helpString
; }
872 // returns the group string of this property
873 const wxString
& GetGroupString() const { return m_groupString
; }
875 // return the element type info of this property (for collections, otherwise NULL)
876 const wxTypeInfo
* GetCollectionElementTypeInfo() const { return m_collectionElementTypeInfo
; }
878 // return the type info of this property
879 const wxTypeInfo
* GetTypeInfo() const { return m_typeInfo
; }
881 // return the accessor for this property
882 wxPropertyAccessor
* GetAccessor() const { return m_accessor
; }
884 // returns NULL if this is the last property of this class
885 wxPropertyInfo
* GetNext() const { return m_next
; }
887 // returns the default value of this property, its kind may be wxT_VOID if it is not valid
888 wxxVariant
GetDefaultValue() const { return m_defaultValue
; }
890 void Insert(wxPropertyInfo
* &iter
)
897 wxPropertyInfo
* i
= iter
;
906 wxString m_typeName
;
907 wxString m_groupString
;
908 wxString m_helpString
;
909 const wxClassInfo
* m_itsClass
;
910 wxPropertyInfoFlags m_flags
;
911 const wxTypeInfo
* m_typeInfo
;
912 const wxTypeInfo
* m_collectionElementTypeInfo
;
913 wxPropertyAccessor
* m_accessor
;
914 wxxVariant m_defaultValue
;
915 // string representation of the default value
916 // to be assigned by the designer to the property
917 // when the component is dropped on the container.
918 wxPropertyInfo
* m_next
;
921 WX_DECLARE_EXPORTED_STRING_HASH_MAP( wxPropertyInfo
* , wxPropertyInfoMap
) ;
923 #define WX_BEGIN_PROPERTIES_TABLE(theClass) \
924 wxPropertyInfo *theClass::GetPropertiesStatic() \
926 typedef theClass class_t; \
927 static wxPropertyInfo* first = NULL ;
929 #define WX_END_PROPERTIES_TABLE() \
932 #define WX_HIDE_PROPERTY( name ) \
933 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (void*) NULL ) ,NULL , wxxVariant() , wxPROP_DONT_STREAM , wxEmptyString , wxEmptyString ) ;
935 #define WX_PROPERTY( name , type , setter , getter ,defaultValue , flags , help , group) \
936 WX_SETTER( name , class_t , type , setter ) \
937 static wxSetter##name _setter##name ; \
938 WX_GETTER( name , class_t , type , getter ) \
939 static wxGetter##name _getter##name ; \
940 static wxPropertyAccessor _accessor##name( &_setter##name , &_getter##name , NULL , NULL ) ; \
941 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) , flags , group , help ) ;
943 #define WX_PROPERTY_FLAGS( name , flags , type , setter , getter ,defaultValue , pflags , help , group) \
944 WX_SETTER( name , class_t , type , setter ) \
945 static wxSetter##name _setter##name ; \
946 WX_GETTER( name , class_t , type , getter ) \
947 static wxGetter##name _getter##name ; \
948 static wxPropertyAccessor _accessor##name( &_setter##name , &_getter##name , NULL , NULL ) ; \
949 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (flags*) NULL ) ,&_accessor##name , wxxVariant(defaultValue), wxPROP_ENUM_STORE_LONG | pflags , help , group ) ;
951 #define WX_READONLY_PROPERTY( name , type , getter ,defaultValue , flags , help , group) \
952 WX_GETTER( name , class_t , type , getter ) \
953 static wxGetter##name _getter##name ; \
954 static wxPropertyAccessor _accessor##name( NULL , &_getter##name , NULL , NULL ) ; \
955 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue), flags , help , group ) ;
957 #define WX_PROPERTY_COLLECTION( name , colltype , addelemtype , adder , getter , flags , help , group ) \
958 WX_ADDER( name , class_t , addelemtype , adder ) \
959 static wxAdder##name _adder##name ; \
960 WX_COLLECTION_GETTER( name , class_t , colltype , getter ) \
961 static wxCollectionGetter##name _collectionGetter##name ; \
962 static wxPropertyAccessor _accessor##name( NULL , NULL ,&_adder##name , &_collectionGetter##name ) ; \
963 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name , flags , help , group ) ;
965 #define WX_READONLY_PROPERTY_COLLECTION( name , colltype , addelemtype , getter , flags , help , group) \
966 WX_COLLECTION_GETTER( name , class_t , colltype , getter ) \
967 static wxCollectionGetter##name _collectionGetter##name ; \
968 static wxPropertyAccessor _accessor##name( NULL , NULL , NULL , &_collectionGetter##name ) ; \
969 static wxPropertyInfo _propertyInfo##name( first ,class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name , flags , help , group ) ;
971 #define WX_PROPERTY_COLLECTION( name , colltype , addelemtype , adder , getter ) \
972 static wxPropertyCollectionAccessorT<class_t , colltype , addelemtype > _accessor##name( &adder , &getter , #adder , #getter ) ; \
973 static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name ) ;
975 #define WX_READONLY_PROPERTY_COLLECTION( name , colltype , addelemtype , getter ) \
976 static wxPropertyCollectionAccessorT<class_t , colltype , addelemtype > _accessor##name( &getter , #getter ) ; \
977 static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name ) ;
982 #define WX_DELEGATE( name , eventType , eventClass ) \
983 static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \
984 static wxPropertyInfo _propertyInfo##name( first ,class_t::GetClassInfoStatic() , #name , &_typeInfo##name , NULL , wxxVariant() ) ; \
986 // ----------------------------------------------------------------------------
989 // this is describing an event sink
990 // ----------------------------------------------------------------------------
995 wxHandlerInfo( wxHandlerInfo
* &iter
, const wxString
& name
, wxObjectEventFunction address
, const wxClassInfo
* eventClassInfo
) :
996 m_name( name
) , m_eventClassInfo( eventClassInfo
) , m_eventFunction( address
)
1003 wxHandlerInfo
* i
= iter
;
1011 // return the name of this handler
1012 const wxString
& GetName() const { return m_name
; }
1014 // return the class info of the event
1015 const wxClassInfo
* GetEventClassInfo() const { return m_eventClassInfo
; }
1017 // get the handler function pointer
1018 wxObjectEventFunction
GetEventFunction() const { return m_eventFunction
; }
1020 // returns NULL if this is the last handler of this class
1021 wxHandlerInfo
* GetNext() const { return m_next
; }
1023 wxObjectEventFunction m_eventFunction
;
1025 const wxClassInfo
* m_eventClassInfo
;
1026 wxHandlerInfo
* m_next
;
1029 #define WX_HANDLER(name,eventClassType) \
1030 static wxHandlerInfo _handlerInfo##name( first , #name , (wxObjectEventFunction) (wxEventFunction) &name , CLASSINFO( eventClassType ) ) ;
1032 #define WX_BEGIN_HANDLERS_TABLE(theClass) \
1033 wxHandlerInfo *theClass::GetHandlersStatic() \
1035 typedef theClass class_t; \
1036 static wxHandlerInfo* first = NULL ;
1038 #define WX_END_HANDLERS_TABLE() \
1041 // ----------------------------------------------------------------------------
1042 // Constructor Bridges
1044 // allow to set up constructors with params during runtime
1045 // ----------------------------------------------------------------------------
1047 class WXDLLIMPEXP_BASE wxConstructorBridge
1050 virtual void Create(wxObject
*o
, wxxVariant
*args
) = 0;
1053 // Creator Bridges for all Numbers of Params
1057 template<typename Class
>
1058 struct wxConstructorBridge_0
: public wxConstructorBridge
1060 void Create(wxObject
*o
, wxxVariant
*)
1062 Class
*obj
= dynamic_cast<Class
*>(o
);
1067 struct wxConstructorBridge_Dummy
: public wxConstructorBridge
1069 void Create(wxObject
*, wxxVariant
*)
1074 #define WX_CONSTRUCTOR_0(klass) \
1075 wxConstructorBridge_0<klass> constructor##klass ; \
1076 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1077 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
1078 const int klass::sm_constructorPropertiesCount##klass = 0 ;
1080 #define WX_CONSTRUCTOR_DUMMY(klass) \
1081 wxConstructorBridge_Dummy constructor##klass ; \
1082 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1083 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
1084 const int klass::sm_constructorPropertiesCount##klass = 0 ;
1088 template<typename Class
, typename T0
>
1089 struct wxConstructorBridge_1
: public wxConstructorBridge
1091 void Create(wxObject
*o
, wxxVariant
*args
)
1093 Class
*obj
= dynamic_cast<Class
*>(o
);
1095 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
)
1100 #define WX_CONSTRUCTOR_1(klass,t0,v0) \
1101 wxConstructorBridge_1<klass,t0> constructor##klass ; \
1102 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1103 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 } ; \
1104 const int klass::sm_constructorPropertiesCount##klass = 1 ;
1108 template<typename Class
,
1109 typename T0
, typename T1
>
1110 struct wxConstructorBridge_2
: public wxConstructorBridge
1112 void Create(wxObject
*o
, wxxVariant
*args
)
1114 Class
*obj
= dynamic_cast<Class
*>(o
);
1116 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1117 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
)
1122 #define WX_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
1123 wxConstructorBridge_2<klass,t0,t1> constructor##klass ; \
1124 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1125 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 } ; \
1126 const int klass::sm_constructorPropertiesCount##klass = 2;
1130 template<typename Class
,
1131 typename T0
, typename T1
, typename T2
>
1132 struct wxConstructorBridge_3
: public wxConstructorBridge
1134 void Create(wxObject
*o
, wxxVariant
*args
)
1136 Class
*obj
= dynamic_cast<Class
*>(o
);
1138 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1139 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1140 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
)
1145 #define WX_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
1146 wxConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \
1147 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1148 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 } ; \
1149 const int klass::sm_constructorPropertiesCount##klass = 3 ;
1153 template<typename Class
,
1154 typename T0
, typename T1
, typename T2
, typename T3
>
1155 struct wxConstructorBridge_4
: public wxConstructorBridge
1157 void Create(wxObject
*o
, wxxVariant
*args
)
1159 Class
*obj
= dynamic_cast<Class
*>(o
);
1161 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1162 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1163 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1164 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
)
1169 #define WX_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
1170 wxConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass ; \
1171 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1172 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 } ; \
1173 const int klass::sm_constructorPropertiesCount##klass = 4 ;
1177 template<typename Class
,
1178 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
>
1179 struct wxConstructorBridge_5
: public wxConstructorBridge
1181 void Create(wxObject
*o
, wxxVariant
*args
)
1183 Class
*obj
= dynamic_cast<Class
*>(o
);
1185 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1186 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1187 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1188 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1189 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
)
1194 #define WX_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
1195 wxConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass ; \
1196 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1197 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 } ; \
1198 const int klass::sm_constructorPropertiesCount##klass = 5;
1202 template<typename Class
,
1203 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
1204 struct wxConstructorBridge_6
: public wxConstructorBridge
1206 void Create(wxObject
*o
, wxxVariant
*args
)
1208 Class
*obj
= dynamic_cast<Class
*>(o
);
1210 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1211 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1212 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1213 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1214 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
) ,
1215 args
[5].WX_TEMPLATED_MEMBER_CALL(Get
, T5
)
1220 template<typename Class
,
1221 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
1222 struct wxDirectConstructorBridge_6
: public wxConstructorBridge
1224 void Create(wxObject
*o
, wxxVariant
*args
)
1226 Class
*obj
= new Class(
1227 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1228 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1229 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1230 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1231 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
) ,
1232 args
[5].WX_TEMPLATED_MEMBER_CALL(Get
, T5
)
1237 #define WX_DIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1238 wxDirectConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1239 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1240 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 } ; \
1241 const int klass::sm_constructorPropertiesCount##klass = 6;
1243 #define WX_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1244 wxConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1245 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1246 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 } ; \
1247 const int klass::sm_constructorPropertiesCount##klass = 6;
1251 template<typename Class
,
1252 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
>
1253 struct wxConstructorBridge_7
: public wxConstructorBridge
1255 void Create(wxObject
*o
, wxxVariant
*args
)
1257 Class
*obj
= dynamic_cast<Class
*>(o
);
1259 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1260 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1261 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1262 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1263 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
) ,
1264 args
[5].WX_TEMPLATED_MEMBER_CALL(Get
, T5
) ,
1265 args
[6].WX_TEMPLATED_MEMBER_CALL(Get
, T6
)
1270 #define WX_CONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
1271 wxConstructorBridge_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass ; \
1272 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1273 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 , #v6} ; \
1274 const int klass::sm_constructorPropertiesCount##klass = 7;
1278 template<typename Class
,
1279 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
, typename T7
>
1280 struct wxConstructorBridge_8
: public wxConstructorBridge
1282 void Create(wxObject
*o
, wxxVariant
*args
)
1284 Class
*obj
= dynamic_cast<Class
*>(o
);
1286 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1287 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1288 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1289 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1290 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
) ,
1291 args
[5].WX_TEMPLATED_MEMBER_CALL(Get
, T5
) ,
1292 args
[6].WX_TEMPLATED_MEMBER_CALL(Get
, T6
) ,
1293 args
[7].WX_TEMPLATED_MEMBER_CALL(Get
, T7
)
1298 #define WX_CONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
1299 wxConstructorBridge_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass ; \
1300 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1301 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 , #v6 , #v7} ; \
1302 const int klass::sm_constructorPropertiesCount##klass = 8;
1303 // ----------------------------------------------------------------------------
1305 // ----------------------------------------------------------------------------
1307 typedef wxObject
*(*wxObjectConstructorFn
)(void);
1308 typedef wxObject
* (*wxVariantToObjectConverter
)( wxxVariant
&data
) ;
1309 typedef wxxVariant (*wxObjectToVariantConverter
)( wxObject
* ) ;
1312 typedef bool (*wxObjectStreamingCallback
) ( const wxObject
*, wxWriter
* , wxPersister
* , wxxVariantArray
& ) ;
1314 class WXDLLIMPEXP_BASE wxClassInfo
1317 wxClassInfo(const wxClassInfo
**_Parents
,
1318 const wxChar
*_UnitName
,
1319 const wxChar
*_ClassName
,
1321 wxObjectConstructorFn ctor
,
1322 wxPropertyInfo
*_Props
,
1323 wxHandlerInfo
*_Handlers
,
1324 wxConstructorBridge
* _Constructor
,
1325 const wxChar
** _ConstructorProperties
,
1326 const int _ConstructorPropertiesCount
,
1327 wxVariantToObjectConverter _PtrConverter1
,
1328 wxVariantToObjectConverter _Converter2
,
1329 wxObjectToVariantConverter _Converter3
,
1330 wxObjectStreamingCallback _streamingCallback
= NULL
1331 ) : m_parents(_Parents
) , m_unitName(_UnitName
) ,m_className(_ClassName
),
1332 m_objectSize(size
), m_objectConstructor(ctor
) , m_firstProperty(_Props
) , m_firstHandler(_Handlers
) , m_constructor( _Constructor
) ,
1333 m_constructorProperties(_ConstructorProperties
) , m_constructorPropertiesCount(_ConstructorPropertiesCount
),
1334 m_variantOfPtrToObjectConverter( _PtrConverter1
) , m_variantToObjectConverter( _Converter2
) , m_objectToVariantConverter( _Converter3
) ,
1335 m_next(sm_first
) , m_streamingCallback( _streamingCallback
)
1341 wxClassInfo(const wxChar
*_UnitName
, const wxChar
*_ClassName
, const wxClassInfo
**_Parents
) : m_parents(_Parents
) , m_unitName(_UnitName
) ,m_className(_ClassName
),
1342 m_objectSize(0), m_objectConstructor(NULL
) , m_firstProperty(NULL
) , m_firstHandler(NULL
) , m_constructor( NULL
) ,
1343 m_constructorProperties(NULL
) , m_constructorPropertiesCount(0),
1344 m_variantOfPtrToObjectConverter( NULL
) , m_variantToObjectConverter( NULL
) , m_objectToVariantConverter( NULL
) , m_next(sm_first
) ,
1345 m_streamingCallback( NULL
)
1351 virtual ~wxClassInfo() ;
1353 // allocates an instance of this class, this object does not have to be initialized or fully constructed
1354 // as this call will be followed by a call to Create
1355 virtual wxObject
*AllocateObject() const { return m_objectConstructor ?
(*m_objectConstructor
)() : 0; }
1357 // 'old naming' for AllocateObject staying here for backward compatibility
1358 wxObject
*CreateObject() const { return AllocateObject() ; }
1360 const wxChar
*GetClassName() const { return m_className
; }
1361 const wxChar
*GetIncludeName() const { return m_unitName
; }
1362 const wxClassInfo
**GetParents() const { return m_parents
; }
1363 int GetSize() const { return m_objectSize
; }
1365 wxObjectConstructorFn
GetConstructor() const { return m_objectConstructor
; }
1366 static const wxClassInfo
*GetFirst() { return sm_first
; }
1367 const wxClassInfo
*GetNext() const { return m_next
; }
1368 static wxClassInfo
*FindClass(const wxChar
*className
);
1370 // Climb upwards through inheritance hierarchy.
1371 // Dual inheritance is catered for.
1373 bool IsKindOf(const wxClassInfo
*info
) const
1380 for ( int i
= 0 ; m_parents
[i
] ; ++ i
)
1382 if ( m_parents
[i
]->IsKindOf( info
) )
1389 // if there is a callback registered with that class it will be called before this
1390 // object will be written to disk, it can veto streaming out this object by returning
1391 // false, if this class has not registered a callback, the search will go up the inheritance tree
1392 // if no callback has been registered true will be returned by default
1393 bool BeforeWriteObject( const wxObject
*obj
, wxWriter
*streamer
, wxPersister
*persister
, wxxVariantArray
&metadata
) const ;
1395 // gets the streaming callback from this class or any superclass
1396 wxObjectStreamingCallback
GetStreamingCallback() const ;
1398 #ifdef WXWIN_COMPATIBILITY_2_4
1399 // Initializes parent pointers and hash table for fast searching.
1400 wxDEPRECATED( static void InitializeClasses() );
1401 // Cleans up hash table used for fast searching.
1402 wxDEPRECATED( static void CleanUpClasses() );
1404 static void CleanUp();
1406 // returns the first property
1407 const wxPropertyInfo
* GetFirstProperty() const { return m_firstProperty
; }
1409 // returns the first handler
1410 const wxHandlerInfo
* GetFirstHandler() const { return m_firstHandler
; }
1412 // Call the Create upon an instance of the class, in the end the object is fully
1414 virtual void Create (wxObject
*object
, int ParamCount
, wxxVariant
*Params
) const
1416 wxASSERT_MSG( ParamCount
== m_constructorPropertiesCount
, wxT("Illegal Parameter Count for Create Method")) ;
1417 m_constructor
->Create( object
, Params
) ;
1420 // get number of parameters for constructor
1421 virtual int GetCreateParamCount() const { return m_constructorPropertiesCount
; }
1423 // get n-th constructor parameter
1424 virtual const wxChar
* GetCreateParamName(int n
) const { return m_constructorProperties
[n
] ; }
1426 // Runtime access to objects for simple properties (get/set) by property name, and variant data
1427 virtual void SetProperty (wxObject
*object
, const wxChar
*propertyName
, const wxxVariant
&value
) const ;
1428 virtual wxxVariant
GetProperty (wxObject
*object
, const wxChar
*propertyName
) const;
1430 // Runtime access to objects for collection properties by property name
1431 virtual wxxVariantArray
GetPropertyCollection(wxObject
*object
, const wxChar
*propertyName
) const ;
1432 virtual void AddToPropertyCollection(wxObject
*object
, const wxChar
*propertyName
, const wxxVariant
& value
) const ;
1434 // we must be able to cast variants to wxObject pointers, templates seem not to be suitable
1435 wxObject
* VariantToInstance( wxxVariant
&data
) const
1436 { if ( data
.GetTypeInfo()->GetKind() == wxT_OBJECT
)
1437 return m_variantToObjectConverter( data
) ;
1439 return m_variantOfPtrToObjectConverter( data
) ;
1442 wxxVariant
InstanceToVariant( wxObject
*object
) const { return m_objectToVariantConverter( object
) ; }
1444 // find property by name
1445 virtual const wxPropertyInfo
*FindPropertyInfo (const wxChar
*PropertyName
) const ;
1447 // find handler by name
1448 virtual const wxHandlerInfo
*FindHandlerInfo (const wxChar
*PropertyName
) const ;
1450 // find property by name
1451 virtual const wxPropertyInfo
*FindPropertyInfoInThisClass (const wxChar
*PropertyName
) const ;
1453 // find handler by name
1454 virtual const wxHandlerInfo
*FindHandlerInfoInThisClass (const wxChar
*PropertyName
) const ;
1456 // puts all the properties of this class and its superclasses in the map, as long as there is not yet
1457 // an entry with the same name (overriding mechanism)
1458 void GetProperties( wxPropertyInfoMap
&map
) const ;
1460 const wxChar
*m_className
;
1462 wxObjectConstructorFn m_objectConstructor
;
1464 // class info object live in a linked list:
1465 // pointers to its head and the next element in it
1467 static wxClassInfo
*sm_first
;
1468 wxClassInfo
*m_next
;
1470 // FIXME: this should be private (currently used directly by way too
1472 static wxHashTable
*sm_classTable
;
1475 wxPropertyInfo
* m_firstProperty
;
1476 wxHandlerInfo
* m_firstHandler
;
1478 const wxClassInfo
** m_parents
;
1479 const wxChar
* m_unitName
;
1481 wxConstructorBridge
* m_constructor
;
1482 const wxChar
** m_constructorProperties
;
1483 const int m_constructorPropertiesCount
;
1484 wxVariantToObjectConverter m_variantOfPtrToObjectConverter
;
1485 wxVariantToObjectConverter m_variantToObjectConverter
;
1486 wxObjectToVariantConverter m_objectToVariantConverter
;
1487 wxObjectStreamingCallback m_streamingCallback
;
1488 const wxPropertyAccessor
*FindAccessor (const wxChar
*propertyName
) const ;
1491 // InitializeClasses() helper
1492 static wxClassInfo
*GetBaseByName(const wxChar
*name
) ;
1495 // registers the class
1499 DECLARE_NO_COPY_CLASS(wxClassInfo
)
1503 WXDLLIMPEXP_BASE wxObject
*wxCreateDynamicObject(const wxChar
*name
);
1505 // ----------------------------------------------------------------------------
1507 // ----------------------------------------------------------------------------
1509 // this object leads to having a pure runtime-instantiation
1511 class wxDynamicClassInfo
: public wxClassInfo
1514 wxDynamicClassInfo( const wxChar
*_UnitName
, const wxChar
*_ClassName
, const wxClassInfo
* superClass
) ;
1515 virtual ~wxDynamicClassInfo() ;
1517 // constructs a wxDynamicObject with an instance
1518 virtual wxObject
*AllocateObject() const ;
1520 // Call the Create method for a class
1521 virtual void Create (wxObject
*object
, int ParamCount
, wxxVariant
*Params
) const ;
1523 // get number of parameters for constructor
1524 virtual int GetCreateParamCount() const ;
1526 // get i-th constructor parameter
1527 virtual const wxChar
* GetCreateParamName(int i
) const ;
1529 // Runtime access to objects by property name, and variant data
1530 virtual void SetProperty (wxObject
*object
, const wxChar
*PropertyName
, const wxxVariant
&Value
) const ;
1531 virtual wxxVariant
GetProperty (wxObject
*object
, const wxChar
*PropertyName
) const ;
1533 // adds a property to this class at runtime
1534 void AddProperty( const wxChar
*propertyName
, const wxTypeInfo
* typeInfo
) ;
1536 // removes an existing runtime-property
1537 void RemoveProperty( const wxChar
*propertyName
) ;
1539 // as a handler to this class at runtime
1540 void AddHandler( const wxChar
*handlerName
, wxObjectEventFunction address
, const wxClassInfo
* eventClassInfo
) ;
1542 // removes an existing runtime-handler
1543 void RemoveHandler( const wxChar
*handlerName
) ;
1546 // ----------------------------------------------------------------------------
1547 // Dynamic class macros
1548 // ----------------------------------------------------------------------------
1550 #define _DECLARE_DYNAMIC_CLASS(name) \
1552 static wxClassInfo sm_class##name; \
1553 static const wxClassInfo* sm_classParents##name[] ; \
1554 static wxPropertyInfo* GetPropertiesStatic() ; \
1555 static wxHandlerInfo* GetHandlersStatic() ; \
1556 static wxClassInfo *GetClassInfoStatic() \
1557 { return &name::sm_class##name; } \
1558 virtual wxClassInfo *GetClassInfo() const \
1559 { return &name::sm_class##name; }
1561 #define DECLARE_DYNAMIC_CLASS(name) \
1562 static wxConstructorBridge* sm_constructor##name ; \
1563 static const wxChar * sm_constructorProperties##name[] ; \
1564 static const int sm_constructorPropertiesCount##name ; \
1565 _DECLARE_DYNAMIC_CLASS(name)
1567 #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
1568 DECLARE_NO_ASSIGN_CLASS(name) \
1569 DECLARE_DYNAMIC_CLASS(name)
1571 #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \
1572 DECLARE_NO_COPY_CLASS(name) \
1573 DECLARE_DYNAMIC_CLASS(name)
1575 #define DECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name)
1576 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
1578 // -----------------------------------
1579 // for concrete classes
1580 // -----------------------------------
1582 // Single inheritance with one base class
1584 #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit , callback) \
1585 wxObject* wxConstructorFor##name() \
1586 { return new name; } \
1587 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1588 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1589 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1590 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1591 (int) sizeof(name), \
1592 (wxObjectConstructorFn) wxConstructorFor##name , \
1593 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1594 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name , callback); \
1595 template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1596 template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1597 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1598 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1599 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1600 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1601 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1602 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1603 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1605 #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \
1606 wxObject* wxConstructorFor##name() \
1607 { return new name; } \
1608 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1609 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return &data.Get<name>() ; } \
1610 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1611 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1612 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1613 (int) sizeof(name), \
1614 (wxObjectConstructorFn) wxConstructorFor##name , \
1615 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1616 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name, callback); \
1617 template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1618 template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1619 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1620 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1621 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1622 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1623 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1624 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1625 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1627 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \
1628 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" , NULL ) \
1629 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1630 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1631 WX_CONSTRUCTOR_DUMMY( name )
1633 #define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \
1634 _IMPLEMENT_DYNAMIC_CLASS( name , basename , "" , NULL ) \
1635 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1636 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1637 WX_CONSTRUCTOR_DUMMY( name )
1639 #define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \
1640 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , NULL )
1642 #define IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name , basename , unit , callback ) \
1643 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , &callback )
1645 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \
1646 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit , NULL )
1648 // this is for classes that do not derive from wxobject, there are no creators for these
1650 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name , unit ) \
1651 const wxClassInfo* name::sm_classParents##name[] = { NULL } ; \
1652 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1653 (int) sizeof(name), \
1654 (wxObjectConstructorFn) 0 , \
1655 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1657 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1658 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1659 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1660 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1661 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1662 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1663 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1665 // this is for subclasses that still do not derive from wxobject
1667 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name , basename, unit ) \
1668 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1669 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1670 (int) sizeof(name), \
1671 (wxObjectConstructorFn) 0 , \
1672 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1674 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1675 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1676 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1677 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1678 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1679 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1680 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1683 // Multiple inheritance with two base classes
1685 #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit) \
1686 wxObject* wxConstructorFor##name() \
1687 { return new name; } \
1688 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,&basename2::sm_class##basename2 , NULL } ; \
1689 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1690 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1691 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1692 (int) sizeof(name), \
1693 (wxObjectConstructorFn) wxConstructorFor##name , \
1694 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1695 name::sm_constructorPropertiesCount##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1696 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1697 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1698 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1699 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1700 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1701 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1702 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1704 #define IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2) \
1705 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , "") \
1706 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1707 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1708 WX_CONSTRUCTOR_DUMMY( name )
1710 #define IMPLEMENT_DYNAMIC_CLASS2_XTI( name , basename , basename2, unit) \
1711 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , unit)
1713 // -----------------------------------
1714 // for abstract classes
1715 // -----------------------------------
1717 // Single inheritance with one base class
1719 #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
1720 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1721 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1722 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1723 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1724 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1725 (int) sizeof(name), \
1726 (wxObjectConstructorFn) 0 , \
1727 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1728 0 , wxVariantOfPtrToObjectConverter##name ,wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1729 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1730 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1731 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1732 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1733 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1734 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } \
1735 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID) ; assert(0) ; return &s_typeInfo ; }
1737 #define IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1738 _IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1739 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1740 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; }
1742 // Multiple inheritance with two base classes
1744 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
1745 wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \
1746 wxT(#basename2), (int) sizeof(name), \
1747 (wxObjectConstructorFn) 0);
1749 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
1750 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
1752 // --------------------------------------------------------------------------
1753 // Collection Support
1754 // --------------------------------------------------------------------------
1756 template<typename iter
, typename collection_t
> void wxListCollectionToVariantArray( const collection_t
& coll
, wxxVariantArray
&value
)
1758 iter current
= coll
.GetFirst() ;
1761 value
.Add( new wxxVariant(current
->GetData()) ) ;
1762 current
= current
->GetNext();
1766 template<typename collection_t
> void wxArrayCollectionToVariantArray( const collection_t
& coll
, wxxVariantArray
&value
)
1768 for( size_t i
= 0 ; i
< coll
.GetCount() ; i
++ )
1770 value
.Add( new wxxVariant(coll
[i
]) ) ;