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
,
367 converterToString_t to
= NULL
, converterFromString_t from
= NULL
,
368 const wxString
&name
= wxEmptyString
):
369 m_toString(to
), m_fromString(from
), m_kind(kind
), m_name(name
)
374 virtual ~wxTypeInfo()
379 // return the kind of this type (wxT_... constants)
380 wxTypeKind
GetKind() const { return m_kind
; }
382 // returns the unique name of this type
383 const wxString
& GetTypeName() const { return m_name
; }
385 // is this type a delegate type
386 bool IsDelegateType() const { return m_kind
== wxT_DELEGATE
; }
388 // is this type a custom type
389 bool IsCustomType() const { return m_kind
== wxT_CUSTOM
; }
391 // is this type an object type
392 bool IsObjectType() const { return m_kind
== wxT_OBJECT
|| m_kind
== wxT_OBJECT_PTR
; }
394 // can the content of this type be converted to and from strings ?
395 bool HasStringConverters() const { return m_toString
!= NULL
&& m_fromString
!= NULL
; }
397 // convert a wxxVariant holding data of this type into a string
398 void ConvertToString( const wxxVariant
& data
, wxString
&result
) const
400 { wxASSERT_MSG( m_toString
, wxT("String conversions not supported") ) ; (*m_toString
)( data
, result
) ; }
402 // convert a string into a wxxVariant holding the corresponding data in this type
403 void ConvertFromString( const wxString
& data
, wxxVariant
&result
) const
404 { wxASSERT_MSG( m_fromString
, wxT("String conversions not supported") ) ; (*m_fromString
)( data
, result
) ; }
406 static wxTypeInfo
*FindType(const wxChar
*typeName
);
413 converterToString_t m_toString
;
414 converterFromString_t m_fromString
;
416 static wxTypeInfoMap
* sm_typeTable
;
422 class WXDLLIMPEXP_BASE wxBuiltInTypeInfo
: public wxTypeInfo
425 wxBuiltInTypeInfo( wxTypeKind kind
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
, const wxString
&name
= wxEmptyString
) :
426 wxTypeInfo( kind
, to
, from
, name
)
427 { wxASSERT_MSG( GetKind() < wxT_SET
, wxT("Illegal Kind for Base Type") ) ; }
430 class WXDLLIMPEXP_BASE wxCustomTypeInfo
: public wxTypeInfo
433 wxCustomTypeInfo( const wxString
&name
, converterToString_t to
, converterFromString_t from
) :
434 wxTypeInfo( wxT_CUSTOM
, to
, from
, name
)
438 class WXDLLIMPEXP_BASE wxEnumTypeInfo
: public wxTypeInfo
441 typedef void (*converterToLong_t
)( const wxxVariant
& data
, long &result
) ;
442 typedef void (*converterFromLong_t
)( long data
, wxxVariant
&result
) ;
444 wxEnumTypeInfo( wxTypeKind kind
, wxEnumData
* enumInfo
, converterToString_t to
, converterFromString_t from
,
445 converterToLong_t toLong
, converterFromLong_t fromLong
, const wxString
&name
) :
446 wxTypeInfo( kind
, to
, from
, name
) , m_toLong( toLong
) , m_fromLong( fromLong
)
447 { wxASSERT_MSG( kind
== wxT_ENUM
|| kind
== wxT_SET
, wxT("Illegal Kind for Enum Type")) ; m_enumInfo
= enumInfo
;}
448 const wxEnumData
* GetEnumData() const { return m_enumInfo
; }
450 // convert a wxxVariant holding data of this type into a long
451 void ConvertToLong( const wxxVariant
& data
, long &result
) const
453 { wxASSERT_MSG( m_toLong
, wxT("Long conversions not supported") ) ; (*m_toLong
)( data
, result
) ; }
455 // convert a long into a wxxVariant holding the corresponding data in this type
456 void ConvertFromLong( long data
, wxxVariant
&result
) const
457 { wxASSERT_MSG( m_fromLong
, wxT("Long conversions not supported") ) ; (*m_fromLong
)( data
, result
) ; }
460 converterToLong_t m_toLong
;
461 converterFromLong_t m_fromLong
;
463 wxEnumData
*m_enumInfo
; // Kind == wxT_ENUM or Kind == wxT_SET
466 class WXDLLIMPEXP_BASE wxClassTypeInfo
: public wxTypeInfo
469 wxClassTypeInfo( wxTypeKind kind
, wxClassInfo
* classInfo
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
) ;
470 const wxClassInfo
*GetClassInfo() const { return m_classInfo
; }
472 wxClassInfo
*m_classInfo
; // Kind == wxT_OBJECT - could be NULL
475 class WXDLLIMPEXP_BASE wxCollectionTypeInfo
: public wxTypeInfo
478 wxCollectionTypeInfo( wxTypeInfo
*elementType
, converterToString_t to
, converterFromString_t from
, const wxString
&name
) :
479 wxTypeInfo( wxT_COLLECTION
, to
, from
, name
)
480 { m_elementType
= elementType
;}
482 const wxTypeInfo
* GetElementType() const { return m_elementType
; }
484 wxTypeInfo
* m_elementType
;
487 // a delegate is an exposed event source
489 class WXDLLIMPEXP_BASE wxDelegateTypeInfo
: public wxTypeInfo
492 wxDelegateTypeInfo( int eventType
, wxClassInfo
* eventClass
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
) ;
493 int GetEventType() const { return m_eventType
; }
495 const wxClassInfo
*m_eventClass
; // (extended will merge into classinfo)
499 template<typename T
> const wxTypeInfo
* wxGetTypeInfo( T
* ) ;
501 // this macro is for usage with custom, non-object derived classes and structs, wxPoint is such a custom type
503 #define WX_CUSTOM_TYPE_INFO( e ) \
504 template<> const wxTypeInfo* wxGetTypeInfo( e ** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID) ; assert(0) ; return &s_typeInfo ; } \
505 template<> const wxTypeInfo* wxGetTypeInfo( e * ){ static wxCustomTypeInfo s_typeInfo(#e, &wxToStringConverter<e> , &wxFromStringConverter<e>) ; return &s_typeInfo ; }
507 #define WX_COLLECTION_TYPE_INFO( element , collection ) \
508 template<> const wxTypeInfo* wxGetTypeInfo( collection * ) \
510 static wxCollectionTypeInfo s_typeInfo( (wxTypeInfo*) wxGetTypeInfo( (element *) NULL) , NULL , NULL , #collection ) ; \
511 return &s_typeInfo ; \
514 // sometimes a compiler invents specializations that are nowhere called, use this macro to satisfy the refs
516 #define WX_ILLEGAL_TYPE_SPECIALIZATION( a ) \
517 template<> const wxTypeInfo* wxGetTypeInfo( a * ) { assert(0) ; \
518 static wxBuiltInTypeInfo s_typeInfo( wxT_VOID ) ; return &s_typeInfo ; } \
519 template<> void wxStringReadValue(const wxString & , a & ) { assert(0) ; }\
520 template<> void wxStringWriteValue(wxString & , a const & ) { assert(0) ; }
522 // ----------------------------------------------------------------------------
523 // wxxVariant as typesafe data holder
524 // ----------------------------------------------------------------------------
526 class WXDLLIMPEXP_BASE wxxVariantData
529 virtual ~wxxVariantData() {}
531 // return a heap allocated duplicate
532 virtual wxxVariantData
* Clone() const = 0 ;
534 // returns the type info of the contentc
535 virtual const wxTypeInfo
* GetTypeInfo() const = 0 ;
538 template<typename T
> class WXDLLIMPEXP_BASE wxxVariantDataT
: public wxxVariantData
541 wxxVariantDataT(const T
& d
) : m_data(d
) {}
542 virtual ~wxxVariantDataT() {}
544 // get a ref to the stored data
545 T
& Get() { return m_data
; }
547 // get a const ref to the stored data
548 const T
& Get() const { return m_data
; }
551 void Set(const T
& d
) { m_data
= d
; }
553 // return a heap allocated duplicate
554 virtual wxxVariantData
* Clone() const { return new wxxVariantDataT
<T
>( Get() ) ; }
556 // returns the type info of the contentc
557 virtual const wxTypeInfo
* GetTypeInfo() const { return wxGetTypeInfo( (T
*) NULL
) ; }
562 class WXDLLIMPEXP_BASE wxxVariant
565 wxxVariant() { m_data
= NULL
; }
566 wxxVariant( wxxVariantData
* data
, const wxString
& name
= wxT("") ) : m_data(data
) , m_name(name
) {}
567 wxxVariant( const wxxVariant
&d
) { if ( d
.m_data
) m_data
= d
.m_data
->Clone() ; else m_data
= NULL
; m_name
= d
.m_name
; }
569 template<typename T
> wxxVariant( const T
& data
, const wxString
& name
= wxT("") ) :
570 m_data(new wxxVariantDataT
<T
>(data
) ), m_name(name
) {}
572 ~wxxVariant() { delete m_data
; }
574 // get a ref to the stored data
575 template<typename T
> T
& Get(WX_TEMPLATED_MEMBER_FIX(T
))
577 wxxVariantDataT
<T
> *dataptr
= dynamic_cast<wxxVariantDataT
<T
>*> (m_data
) ;
578 wxASSERT_MSG( dataptr
, wxT("Cast not possible") ) ;
579 return dataptr
->Get() ;
582 // get a ref to the stored data
583 template<typename T
> const T
& Get(WX_TEMPLATED_MEMBER_FIX(T
)) const
585 const wxxVariantDataT
<T
> *dataptr
= dynamic_cast<const wxxVariantDataT
<T
>*> (m_data
) ;
586 wxASSERT_MSG( dataptr
, wxT("Cast not possible") ) ;
587 return dataptr
->Get() ;
590 template<typename T
> bool HasData() const
592 const wxxVariantDataT
<T
> *dataptr
= dynamic_cast<const wxxVariantDataT
<T
>*> (m_data
) ;
593 return dataptr
!= NULL
;
597 template<typename T
> void Set(const T
& data
) const
600 m_data
= new wxxVariantDataT
<T
>(data
) ;
603 wxxVariant
& operator=(const wxxVariant
&d
)
605 m_data
= d
.m_data
->Clone() ;
610 // gets the stored data casted to a wxObject* , returning NULL if cast is not possible
611 wxObject
* GetAsObject() ;
613 // get the typeinfo of the stored object
614 const wxTypeInfo
* GetTypeInfo() const { return m_data
->GetTypeInfo() ; }
616 // returns this value as string
617 wxString
GetAsString() const
620 GetTypeInfo()->ConvertToString( *this , s
) ;
623 const wxString
& GetName() const { return m_name
; }
625 wxxVariantData
* m_data
;
629 #include <wx/dynarray.h>
631 WX_DECLARE_OBJARRAY_WITH_DECL(wxxVariant
, wxxVariantArray
, class WXDLLIMPEXP_BASE
);
633 // templated streaming, every type must have their specialization for these methods
636 void wxStringReadValue( const wxString
&s
, T
&data
);
639 void wxStringWriteValue( wxString
&s
, const T
&data
);
642 void wxToStringConverter( const wxxVariant
&v
, wxString
&s
) { wxStringWriteValue( s
, v
.WX_TEMPLATED_MEMBER_CALL(Get
, T
) ) ; }
645 void wxFromStringConverter( const wxString
&s
, wxxVariant
&v
) { T d
; wxStringReadValue( s
, d
) ; v
= wxxVariant(d
) ; } \
647 // ----------------------------------------------------------------------------
650 // wxPropertyInfo is used to inquire of the property by name. It doesn't
651 // provide access to the property, only information about it. If you
652 // want access, look at wxPropertyAccessor.
653 // ----------------------------------------------------------------------------
658 wxSetter( const wxString name
) { m_name
= name
; }
659 virtual ~wxSetter() {}
660 virtual void Set( wxObject
*object
, const wxxVariant
&variantValue
) const = 0;
661 const wxString
& GetName() const { return m_name
; }
669 wxGetter( const wxString name
) { m_name
= name
; }
670 virtual ~wxGetter() {}
671 virtual void Get( const wxObject
*object
, wxxVariant
& result
) const = 0;
672 const wxString
& GetName() const { return m_name
; }
677 class wxCollectionGetter
680 wxCollectionGetter( const wxString name
) { m_name
= name
; }
681 virtual ~wxCollectionGetter() {}
682 virtual void Get( const wxObject
*object
, wxxVariantArray
& result
) const = 0;
683 const wxString
& GetName() const { return m_name
; }
688 template<typename coll_t
> void wxCollectionToVariantArray( const coll_t
& coll
, wxxVariantArray
& result
) ;
693 wxAdder( const wxString name
) { m_name
= name
; }
694 virtual ~wxAdder() {}
695 virtual void Add( wxObject
*object
, const wxxVariant
&variantValue
) const= 0;
696 const wxString
& GetName() const { return m_name
; }
703 #define WX_SETTER( property, Klass, valueType, setterMethod ) \
704 class wxSetter##property : public wxSetter \
707 wxSetter##property() : wxSetter( #setterMethod ) {} \
708 void Set( wxObject *object, const wxxVariant &variantValue ) const \
710 Klass *obj = dynamic_cast<Klass*>(object) ; \
711 if ( variantValue.HasData<valueType>() ) \
712 obj->setterMethod(variantValue.Get<valueType>()) ; \
714 obj->setterMethod(*variantValue.Get<valueType*>()) ; \
718 #define WX_GETTER( property, Klass, valueType , gettermethod ) \
719 class wxGetter##property : public wxGetter \
722 wxGetter##property() : wxGetter( #gettermethod ) {} \
723 void Get( const wxObject *object , wxxVariant &result) const \
725 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
726 result = wxxVariant( obj->gettermethod() ) ; \
730 #define WX_ADDER( property, Klass, valueType , addermethod ) \
731 class wxAdder##property : public wxAdder \
734 wxAdder##property() : wxAdder( #addermethod ) {} \
735 void Add( wxObject *object, const wxxVariant &variantValue ) const \
737 Klass *obj = dynamic_cast<Klass*>(object) ; \
738 if ( variantValue.HasData<valueType>() ) \
739 obj->addermethod(variantValue.Get<valueType>()) ; \
741 obj->addermethod(*variantValue.Get<valueType*>()) ; \
745 #define WX_COLLECTION_GETTER( property, Klass, valueType , gettermethod ) \
746 class wxCollectionGetter##property : public wxCollectionGetter \
749 wxCollectionGetter##property() : wxCollectionGetter( #gettermethod ) {} \
750 void Get( const wxObject *object , wxxVariantArray &result) const \
752 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
753 wxCollectionToVariantArray( obj->gettermethod() , result ) ; \
757 class WXDLLIMPEXP_BASE wxPropertyAccessor
760 wxPropertyAccessor( wxSetter
*setter
, wxGetter
*getter
, wxAdder
*adder
, wxCollectionGetter
*collectionGetter
)
761 { m_setter
= setter
; m_getter
= getter
; m_adder
= adder
; m_collectionGetter
= collectionGetter
;}
763 virtual ~wxPropertyAccessor() {}
765 // Setting a simple property (non-collection)
766 virtual void SetProperty(wxObject
*object
, const wxxVariant
&value
) const
767 { wxASSERT_MSG(m_setter
,wxT("SetProperty called w/o valid setter") ) ; m_setter
->Set( object
, value
) ;}
769 // Getting a simple property (non-collection)
770 virtual void GetProperty(const wxObject
*object
, wxxVariant
&result
) const
771 { wxASSERT_MSG(m_getter
,wxT("GetProperty called w/o valid getter") ) ; m_getter
->Get( object
, result
) ;}
773 // Adding an element to a collection property
774 virtual void AddToPropertyCollection(wxObject
*object
, const wxxVariant
&value
) const
775 { wxASSERT_MSG(m_adder
,wxT("AddToPropertyCollection called w/o valid adder") ) ; m_adder
->Add( object
, value
) ;}
777 // Getting a collection property
778 virtual void GetPropertyCollection( const wxObject
*obj
, wxxVariantArray
&result
) const
779 { wxASSERT_MSG(m_collectionGetter
,wxT("GetPropertyCollection called w/o valid collection getter") ) ; m_collectionGetter
->Get( obj
, result
) ;}
781 virtual bool HasSetter() const { return m_setter
!= NULL
; }
782 virtual bool HasCollectionGetter() const { return m_collectionGetter
!= NULL
; }
783 virtual bool HasGetter() const { return m_getter
!= NULL
; }
784 virtual bool HasAdder() const { return m_adder
!= NULL
; }
786 virtual const wxString
& GetCollectionGetterName() const
787 { return m_collectionGetter
->GetName() ; }
788 virtual const wxString
& GetGetterName() const
789 { return m_getter
->GetName() ; }
790 virtual const wxString
& GetSetterName() const
791 { return m_setter
->GetName() ; }
792 virtual const wxString
& GetAdderName() const
793 { return m_adder
->GetName() ; }
795 virtual wxxVariant ReadValue( const wxString &value ) const ;
796 virtual void WriteValue( wxString& value , const wxObject *o ) const ;
802 wxCollectionGetter
* m_collectionGetter
;
805 class WXDLLIMPEXP_BASE wxGenericPropertyAccessor
: public wxPropertyAccessor
808 wxGenericPropertyAccessor( const wxString
&propName
) ;
809 ~wxGenericPropertyAccessor() ;
811 virtual bool HasSetter() const { return true ; }
812 virtual bool HasGetter() const { return true ; }
813 virtual bool HasAdder() const { return false ; }
814 virtual bool HasCollectionGetter() const { return false ; }
816 virtual const wxString
& GetGetterName() const
817 { return m_getterName
; }
818 virtual const wxString
& GetSetterName() const
819 { return m_setterName
; }
821 virtual void SetProperty(wxObject
*object
, const wxxVariant
&value
) const ;
822 virtual void GetProperty(const wxObject
*object
, wxxVariant
&value
) const ;
824 // Adding an element to a collection property
825 virtual void AddToPropertyCollection(wxObject
*WXUNUSED(object
), const wxxVariant
&WXUNUSED(value
)) const
826 { wxASSERT_MSG(0,wxT("AddToPropertyCollection called on a generic accessor") ) ;}
828 // Getting a collection property
829 virtual void GetPropertyCollection( const wxObject
*WXUNUSED(obj
), wxxVariantArray
&WXUNUSED(result
)) const
830 { wxASSERT_MSG(0,wxT("GetPropertyCollection called on a generic accessor") ) ;}
832 struct wxGenericPropertyAccessorInternal
;
833 wxGenericPropertyAccessorInternal
* m_data
;
834 wxString m_propertyName
;
835 wxString m_setterName
;
836 wxString m_getterName
;
839 typedef long wxPropertyInfoFlags
;
841 // will be removed in future releases
842 wxPROP_DEPRECATED
= 0x00000001 ,
843 // object graph property, will be streamed with priority (after constructor properties)
844 wxPROP_OBJECT_GRAPH
= 0x00000002 ,
845 // this will only be streamed out and in as enum/set, the internal representation is still a long
846 wxPROP_ENUM_STORE_LONG
= 0x00000004 ,
847 // don't stream out this property, needed eg to avoid streaming out children that are always created by their parents
848 wxPROP_DONT_STREAM
= 0x00000008 ,
851 class WXDLLIMPEXP_BASE wxPropertyInfo
854 wxPropertyInfo(wxPropertyInfo
* &iter
,
855 const wxClassInfo
* itsClass
,
856 const wxString
& name
,
857 const wxTypeInfo
* typeInfo
,
858 wxPropertyAccessor
*accessor
,
860 wxPropertyInfoFlags flags
= 0,
861 const wxString
& helpString
= wxEmptyString
,
862 const wxString
& groupString
= wxEmptyString
) :
864 m_groupString(groupString
),
865 m_helpString(helpString
),
866 m_itsClass(itsClass
),
868 m_typeInfo(typeInfo
),
869 m_collectionElementTypeInfo(NULL
),
870 m_accessor(accessor
),
876 wxPropertyInfo(wxPropertyInfo
* &iter
,
877 const wxClassInfo
* itsClass
, const wxString
& name
,
878 const wxTypeInfo
* collTypeInfo
,
879 const wxTypeInfo
* elemTypeInfo
,
880 wxPropertyAccessor
*accessor
,
881 wxPropertyInfoFlags flags
= 0,
882 const wxString
& helpString
= wxEmptyString
,
883 const wxString
& groupString
= wxEmptyString
) :
885 m_groupString(groupString
),
886 m_helpString(helpString
),
887 m_itsClass(itsClass
),
889 m_typeInfo(collTypeInfo
),
890 m_collectionElementTypeInfo(elemTypeInfo
),
896 // return the class this property is declared in
897 const wxClassInfo
* GetDeclaringClass() const { return m_itsClass
; }
899 // return the name of this property
900 const wxString
& GetName() const { return m_name
; }
902 // returns the flags of this property
903 wxPropertyInfoFlags
GetFlags() const { return m_flags
;}
905 // returns the short help string of this property
906 const wxString
& GetHelpString() const { return m_helpString
; }
908 // returns the group string of this property
909 const wxString
& GetGroupString() const { return m_groupString
; }
911 // return the element type info of this property (for collections, otherwise NULL)
912 const wxTypeInfo
* GetCollectionElementTypeInfo() const { return m_collectionElementTypeInfo
; }
914 // return the type info of this property
915 const wxTypeInfo
* GetTypeInfo() const { return m_typeInfo
; }
917 // return the accessor for this property
918 wxPropertyAccessor
* GetAccessor() const { return m_accessor
; }
920 // returns NULL if this is the last property of this class
921 wxPropertyInfo
* GetNext() const { return m_next
; }
923 // returns the default value of this property, its kind may be wxT_VOID if it is not valid
924 wxxVariant
GetDefaultValue() const { return m_defaultValue
; }
926 void Insert(wxPropertyInfo
* &iter
)
933 wxPropertyInfo
* i
= iter
;
942 wxString m_typeName
;
943 wxString m_groupString
;
944 wxString m_helpString
;
945 const wxClassInfo
* m_itsClass
;
946 wxPropertyInfoFlags m_flags
;
947 const wxTypeInfo
* m_typeInfo
;
948 const wxTypeInfo
* m_collectionElementTypeInfo
;
949 wxPropertyAccessor
* m_accessor
;
950 wxxVariant m_defaultValue
;
951 // string representation of the default value
952 // to be assigned by the designer to the property
953 // when the component is dropped on the container.
954 wxPropertyInfo
* m_next
;
957 WX_DECLARE_EXPORTED_STRING_HASH_MAP( wxPropertyInfo
* , wxPropertyInfoMap
) ;
959 #define WX_BEGIN_PROPERTIES_TABLE(theClass) \
960 wxPropertyInfo *theClass::GetPropertiesStatic() \
962 typedef theClass class_t; \
963 static wxPropertyInfo* first = NULL ;
965 #define WX_END_PROPERTIES_TABLE() \
968 #define WX_HIDE_PROPERTY( name ) \
969 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (void*) NULL ) ,NULL , wxxVariant() , wxPROP_DONT_STREAM , wxEmptyString , wxEmptyString ) ;
971 #define WX_PROPERTY( name , type , setter , getter ,defaultValue , flags , help , group) \
972 WX_SETTER( name , class_t , type , setter ) \
973 static wxSetter##name _setter##name ; \
974 WX_GETTER( name , class_t , type , getter ) \
975 static wxGetter##name _getter##name ; \
976 static wxPropertyAccessor _accessor##name( &_setter##name , &_getter##name , NULL , NULL ) ; \
977 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) , flags , group , help ) ;
979 #define WX_PROPERTY_FLAGS( name , flags , type , setter , getter ,defaultValue , pflags , help , group) \
980 WX_SETTER( name , class_t , type , setter ) \
981 static wxSetter##name _setter##name ; \
982 WX_GETTER( name , class_t , type , getter ) \
983 static wxGetter##name _getter##name ; \
984 static wxPropertyAccessor _accessor##name( &_setter##name , &_getter##name , NULL , NULL ) ; \
985 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (flags*) NULL ) ,&_accessor##name , wxxVariant(defaultValue), wxPROP_ENUM_STORE_LONG | pflags , help , group ) ;
987 #define WX_READONLY_PROPERTY( name , type , getter ,defaultValue , flags , help , group) \
988 WX_GETTER( name , class_t , type , getter ) \
989 static wxGetter##name _getter##name ; \
990 static wxPropertyAccessor _accessor##name( NULL , &_getter##name , NULL , NULL ) ; \
991 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue), flags , help , group ) ;
993 #define WX_PROPERTY_COLLECTION( name , colltype , addelemtype , adder , getter , flags , help , group ) \
994 WX_ADDER( name , class_t , addelemtype , adder ) \
995 static wxAdder##name _adder##name ; \
996 WX_COLLECTION_GETTER( name , class_t , colltype , getter ) \
997 static wxCollectionGetter##name _collectionGetter##name ; \
998 static wxPropertyAccessor _accessor##name( NULL , NULL ,&_adder##name , &_collectionGetter##name ) ; \
999 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name , flags , help , group ) ;
1001 #define WX_READONLY_PROPERTY_COLLECTION( name , colltype , addelemtype , getter , flags , help , group) \
1002 WX_COLLECTION_GETTER( name , class_t , colltype , getter ) \
1003 static wxCollectionGetter##name _collectionGetter##name ; \
1004 static wxPropertyAccessor _accessor##name( NULL , NULL , NULL , &_collectionGetter##name ) ; \
1005 static wxPropertyInfo _propertyInfo##name( first ,class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name , flags , help , group ) ;
1007 #define WX_PROPERTY_COLLECTION( name , colltype , addelemtype , adder , getter ) \
1008 static wxPropertyCollectionAccessorT<class_t , colltype , addelemtype > _accessor##name( &adder , &getter , #adder , #getter ) ; \
1009 static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name ) ;
1011 #define WX_READONLY_PROPERTY_COLLECTION( name , colltype , addelemtype , getter ) \
1012 static wxPropertyCollectionAccessorT<class_t , colltype , addelemtype > _accessor##name( &getter , #getter ) ; \
1013 static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name ) ;
1018 #define WX_DELEGATE( name , eventType , eventClass ) \
1019 static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \
1020 static wxPropertyInfo _propertyInfo##name( first ,class_t::GetClassInfoStatic() , #name , &_typeInfo##name , NULL , wxxVariant() ) ; \
1022 // ----------------------------------------------------------------------------
1025 // this is describing an event sink
1026 // ----------------------------------------------------------------------------
1031 wxHandlerInfo(wxHandlerInfo
* &iter
,
1032 const wxString
& name
,
1033 wxObjectEventFunction address
,
1034 const wxClassInfo
* eventClassInfo
) :
1035 m_eventFunction(address
),
1037 m_eventClassInfo(eventClassInfo
)
1044 wxHandlerInfo
* i
= iter
;
1052 // return the name of this handler
1053 const wxString
& GetName() const { return m_name
; }
1055 // return the class info of the event
1056 const wxClassInfo
* GetEventClassInfo() const { return m_eventClassInfo
; }
1058 // get the handler function pointer
1059 wxObjectEventFunction
GetEventFunction() const { return m_eventFunction
; }
1061 // returns NULL if this is the last handler of this class
1062 wxHandlerInfo
* GetNext() const { return m_next
; }
1064 wxObjectEventFunction m_eventFunction
;
1066 const wxClassInfo
* m_eventClassInfo
;
1067 wxHandlerInfo
* m_next
;
1070 #define WX_HANDLER(name,eventClassType) \
1071 static wxHandlerInfo _handlerInfo##name( first , #name , (wxObjectEventFunction) (wxEventFunction) &name , CLASSINFO( eventClassType ) ) ;
1073 #define WX_BEGIN_HANDLERS_TABLE(theClass) \
1074 wxHandlerInfo *theClass::GetHandlersStatic() \
1076 typedef theClass class_t; \
1077 static wxHandlerInfo* first = NULL ;
1079 #define WX_END_HANDLERS_TABLE() \
1082 // ----------------------------------------------------------------------------
1083 // Constructor Bridges
1085 // allow to set up constructors with params during runtime
1086 // ----------------------------------------------------------------------------
1088 class WXDLLIMPEXP_BASE wxConstructorBridge
1091 virtual void Create(wxObject
*o
, wxxVariant
*args
) = 0;
1094 // Creator Bridges for all Numbers of Params
1098 template<typename Class
>
1099 struct wxConstructorBridge_0
: public wxConstructorBridge
1101 void Create(wxObject
*o
, wxxVariant
*)
1103 Class
*obj
= dynamic_cast<Class
*>(o
);
1108 struct wxConstructorBridge_Dummy
: public wxConstructorBridge
1110 void Create(wxObject
*, wxxVariant
*)
1115 #define WX_CONSTRUCTOR_0(klass) \
1116 wxConstructorBridge_0<klass> constructor##klass ; \
1117 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1118 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
1119 const int klass::sm_constructorPropertiesCount##klass = 0 ;
1121 #define WX_CONSTRUCTOR_DUMMY(klass) \
1122 wxConstructorBridge_Dummy constructor##klass ; \
1123 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1124 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
1125 const int klass::sm_constructorPropertiesCount##klass = 0 ;
1129 template<typename Class
, typename T0
>
1130 struct wxConstructorBridge_1
: public wxConstructorBridge
1132 void Create(wxObject
*o
, wxxVariant
*args
)
1134 Class
*obj
= dynamic_cast<Class
*>(o
);
1136 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
)
1141 #define WX_CONSTRUCTOR_1(klass,t0,v0) \
1142 wxConstructorBridge_1<klass,t0> constructor##klass ; \
1143 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1144 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 } ; \
1145 const int klass::sm_constructorPropertiesCount##klass = 1 ;
1149 template<typename Class
,
1150 typename T0
, typename T1
>
1151 struct wxConstructorBridge_2
: public wxConstructorBridge
1153 void Create(wxObject
*o
, wxxVariant
*args
)
1155 Class
*obj
= dynamic_cast<Class
*>(o
);
1157 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1158 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
)
1163 #define WX_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
1164 wxConstructorBridge_2<klass,t0,t1> constructor##klass ; \
1165 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1166 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 } ; \
1167 const int klass::sm_constructorPropertiesCount##klass = 2;
1171 template<typename Class
,
1172 typename T0
, typename T1
, typename T2
>
1173 struct wxConstructorBridge_3
: public wxConstructorBridge
1175 void Create(wxObject
*o
, wxxVariant
*args
)
1177 Class
*obj
= dynamic_cast<Class
*>(o
);
1179 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1180 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1181 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
)
1186 #define WX_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
1187 wxConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \
1188 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1189 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 } ; \
1190 const int klass::sm_constructorPropertiesCount##klass = 3 ;
1194 template<typename Class
,
1195 typename T0
, typename T1
, typename T2
, typename T3
>
1196 struct wxConstructorBridge_4
: public wxConstructorBridge
1198 void Create(wxObject
*o
, wxxVariant
*args
)
1200 Class
*obj
= dynamic_cast<Class
*>(o
);
1202 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1203 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1204 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1205 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
)
1210 #define WX_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
1211 wxConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass ; \
1212 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1213 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 } ; \
1214 const int klass::sm_constructorPropertiesCount##klass = 4 ;
1218 template<typename Class
,
1219 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
>
1220 struct wxConstructorBridge_5
: public wxConstructorBridge
1222 void Create(wxObject
*o
, wxxVariant
*args
)
1224 Class
*obj
= dynamic_cast<Class
*>(o
);
1226 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1227 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1228 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1229 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1230 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
)
1235 #define WX_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
1236 wxConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass ; \
1237 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1238 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 } ; \
1239 const int klass::sm_constructorPropertiesCount##klass = 5;
1243 template<typename Class
,
1244 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
1245 struct wxConstructorBridge_6
: public wxConstructorBridge
1247 void Create(wxObject
*o
, wxxVariant
*args
)
1249 Class
*obj
= dynamic_cast<Class
*>(o
);
1251 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1252 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1253 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1254 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1255 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
) ,
1256 args
[5].WX_TEMPLATED_MEMBER_CALL(Get
, T5
)
1261 template<typename Class
,
1262 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
1263 struct wxDirectConstructorBridge_6
: public wxConstructorBridge
1265 void Create(wxObject
*o
, wxxVariant
*args
)
1267 Class
*obj
= new Class(
1268 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1269 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1270 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1271 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1272 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
) ,
1273 args
[5].WX_TEMPLATED_MEMBER_CALL(Get
, T5
)
1278 #define WX_DIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1279 wxDirectConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1280 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1281 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 } ; \
1282 const int klass::sm_constructorPropertiesCount##klass = 6;
1284 #define WX_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1285 wxConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1286 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1287 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 } ; \
1288 const int klass::sm_constructorPropertiesCount##klass = 6;
1292 template<typename Class
,
1293 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
>
1294 struct wxConstructorBridge_7
: public wxConstructorBridge
1296 void Create(wxObject
*o
, wxxVariant
*args
)
1298 Class
*obj
= dynamic_cast<Class
*>(o
);
1300 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1301 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1302 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1303 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1304 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
) ,
1305 args
[5].WX_TEMPLATED_MEMBER_CALL(Get
, T5
) ,
1306 args
[6].WX_TEMPLATED_MEMBER_CALL(Get
, T6
)
1311 #define WX_CONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
1312 wxConstructorBridge_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass ; \
1313 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1314 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 , #v6} ; \
1315 const int klass::sm_constructorPropertiesCount##klass = 7;
1319 template<typename Class
,
1320 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
, typename T7
>
1321 struct wxConstructorBridge_8
: public wxConstructorBridge
1323 void Create(wxObject
*o
, wxxVariant
*args
)
1325 Class
*obj
= dynamic_cast<Class
*>(o
);
1327 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1328 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1329 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1330 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1331 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
) ,
1332 args
[5].WX_TEMPLATED_MEMBER_CALL(Get
, T5
) ,
1333 args
[6].WX_TEMPLATED_MEMBER_CALL(Get
, T6
) ,
1334 args
[7].WX_TEMPLATED_MEMBER_CALL(Get
, T7
)
1339 #define WX_CONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
1340 wxConstructorBridge_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass ; \
1341 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1342 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 , #v6 , #v7} ; \
1343 const int klass::sm_constructorPropertiesCount##klass = 8;
1344 // ----------------------------------------------------------------------------
1346 // ----------------------------------------------------------------------------
1348 typedef wxObject
*(*wxObjectConstructorFn
)(void);
1349 typedef wxObject
* (*wxVariantToObjectConverter
)( wxxVariant
&data
) ;
1350 typedef wxxVariant (*wxObjectToVariantConverter
)( wxObject
* ) ;
1353 typedef bool (*wxObjectStreamingCallback
) ( const wxObject
*, wxWriter
* , wxPersister
* , wxxVariantArray
& ) ;
1355 class WXDLLIMPEXP_BASE wxClassInfo
1358 wxClassInfo(const wxClassInfo
**_Parents
,
1359 const wxChar
*_UnitName
,
1360 const wxChar
*_ClassName
,
1362 wxObjectConstructorFn ctor
,
1363 wxPropertyInfo
*_Props
,
1364 wxHandlerInfo
*_Handlers
,
1365 wxConstructorBridge
* _Constructor
,
1366 const wxChar
** _ConstructorProperties
,
1367 const int _ConstructorPropertiesCount
,
1368 wxVariantToObjectConverter _PtrConverter1
,
1369 wxVariantToObjectConverter _Converter2
,
1370 wxObjectToVariantConverter _Converter3
,
1371 wxObjectStreamingCallback _streamingCallback
= NULL
1374 m_className(_ClassName
),
1376 m_objectConstructor(ctor
),
1378 m_firstProperty(_Props
),
1379 m_firstHandler(_Handlers
),
1380 m_parents(_Parents
),
1381 m_unitName(_UnitName
),
1382 m_constructor(_Constructor
),
1383 m_constructorProperties(_ConstructorProperties
),
1384 m_constructorPropertiesCount(_ConstructorPropertiesCount
),
1385 m_variantOfPtrToObjectConverter(_PtrConverter1
),
1386 m_variantToObjectConverter(_Converter2
),
1387 m_objectToVariantConverter(_Converter3
),
1388 m_streamingCallback(_streamingCallback
)
1394 wxClassInfo(const wxChar
*_UnitName
, const wxChar
*_ClassName
,
1395 const wxClassInfo
**_Parents
) :
1396 m_className(_ClassName
),
1398 m_objectConstructor(NULL
),
1400 m_firstProperty(NULL
),
1401 m_firstHandler(NULL
),
1402 m_parents(_Parents
),
1403 m_unitName(_UnitName
),
1404 m_constructor(NULL
),
1405 m_constructorProperties(NULL
),
1406 m_constructorPropertiesCount(0),
1407 m_variantOfPtrToObjectConverter(NULL
),
1408 m_variantToObjectConverter(NULL
),
1409 m_objectToVariantConverter(NULL
),
1410 m_streamingCallback(NULL
)
1416 virtual ~wxClassInfo() ;
1418 // allocates an instance of this class, this object does not have to be initialized or fully constructed
1419 // as this call will be followed by a call to Create
1420 virtual wxObject
*AllocateObject() const { return m_objectConstructor ?
(*m_objectConstructor
)() : 0; }
1422 // 'old naming' for AllocateObject staying here for backward compatibility
1423 wxObject
*CreateObject() const { return AllocateObject() ; }
1425 const wxChar
*GetClassName() const { return m_className
; }
1426 const wxChar
*GetIncludeName() const { return m_unitName
; }
1427 const wxClassInfo
**GetParents() const { return m_parents
; }
1428 int GetSize() const { return m_objectSize
; }
1430 wxObjectConstructorFn
GetConstructor() const { return m_objectConstructor
; }
1431 static const wxClassInfo
*GetFirst() { return sm_first
; }
1432 const wxClassInfo
*GetNext() const { return m_next
; }
1433 static wxClassInfo
*FindClass(const wxChar
*className
);
1435 // Climb upwards through inheritance hierarchy.
1436 // Dual inheritance is catered for.
1438 bool IsKindOf(const wxClassInfo
*info
) const
1445 for ( int i
= 0 ; m_parents
[i
] ; ++ i
)
1447 if ( m_parents
[i
]->IsKindOf( info
) )
1454 // if there is a callback registered with that class it will be called
1455 // before this object will be written to disk, it can veto streaming out
1456 // this object by returning false, if this class has not registered a
1457 // callback, the search will go up the inheritance tree if no callback has
1458 // been registered true will be returned by default
1459 bool BeforeWriteObject( const wxObject
*obj
, wxWriter
*streamer
, wxPersister
*persister
, wxxVariantArray
&metadata
) const ;
1461 // gets the streaming callback from this class or any superclass
1462 wxObjectStreamingCallback
GetStreamingCallback() const ;
1464 #ifdef WXWIN_COMPATIBILITY_2_4
1465 // Initializes parent pointers and hash table for fast searching.
1466 wxDEPRECATED( static void InitializeClasses() );
1467 // Cleans up hash table used for fast searching.
1468 wxDEPRECATED( static void CleanUpClasses() );
1470 static void CleanUp();
1472 // returns the first property
1473 const wxPropertyInfo
* GetFirstProperty() const { return m_firstProperty
; }
1475 // returns the first handler
1476 const wxHandlerInfo
* GetFirstHandler() const { return m_firstHandler
; }
1478 // Call the Create upon an instance of the class, in the end the object is fully
1480 virtual void Create (wxObject
*object
, int ParamCount
, wxxVariant
*Params
) const
1482 wxASSERT_MSG( ParamCount
== m_constructorPropertiesCount
, wxT("Illegal Parameter Count for Create Method")) ;
1483 m_constructor
->Create( object
, Params
) ;
1486 // get number of parameters for constructor
1487 virtual int GetCreateParamCount() const { return m_constructorPropertiesCount
; }
1489 // get n-th constructor parameter
1490 virtual const wxChar
* GetCreateParamName(int n
) const { return m_constructorProperties
[n
] ; }
1492 // Runtime access to objects for simple properties (get/set) by property name, and variant data
1493 virtual void SetProperty (wxObject
*object
, const wxChar
*propertyName
, const wxxVariant
&value
) const ;
1494 virtual wxxVariant
GetProperty (wxObject
*object
, const wxChar
*propertyName
) const;
1496 // Runtime access to objects for collection properties by property name
1497 virtual wxxVariantArray
GetPropertyCollection(wxObject
*object
, const wxChar
*propertyName
) const ;
1498 virtual void AddToPropertyCollection(wxObject
*object
, const wxChar
*propertyName
, const wxxVariant
& value
) const ;
1500 // we must be able to cast variants to wxObject pointers, templates seem not to be suitable
1501 wxObject
* VariantToInstance( wxxVariant
&data
) const
1502 { if ( data
.GetTypeInfo()->GetKind() == wxT_OBJECT
)
1503 return m_variantToObjectConverter( data
) ;
1505 return m_variantOfPtrToObjectConverter( data
) ;
1508 wxxVariant
InstanceToVariant( wxObject
*object
) const { return m_objectToVariantConverter( object
) ; }
1510 // find property by name
1511 virtual const wxPropertyInfo
*FindPropertyInfo (const wxChar
*PropertyName
) const ;
1513 // find handler by name
1514 virtual const wxHandlerInfo
*FindHandlerInfo (const wxChar
*PropertyName
) const ;
1516 // find property by name
1517 virtual const wxPropertyInfo
*FindPropertyInfoInThisClass (const wxChar
*PropertyName
) const ;
1519 // find handler by name
1520 virtual const wxHandlerInfo
*FindHandlerInfoInThisClass (const wxChar
*PropertyName
) const ;
1522 // puts all the properties of this class and its superclasses in the map, as long as there is not yet
1523 // an entry with the same name (overriding mechanism)
1524 void GetProperties( wxPropertyInfoMap
&map
) const ;
1526 const wxChar
*m_className
;
1528 wxObjectConstructorFn m_objectConstructor
;
1530 // class info object live in a linked list:
1531 // pointers to its head and the next element in it
1533 static wxClassInfo
*sm_first
;
1534 wxClassInfo
*m_next
;
1536 // FIXME: this should be private (currently used directly by way too
1538 static wxHashTable
*sm_classTable
;
1541 wxPropertyInfo
* m_firstProperty
;
1542 wxHandlerInfo
* m_firstHandler
;
1544 const wxClassInfo
** m_parents
;
1545 const wxChar
* m_unitName
;
1547 wxConstructorBridge
* m_constructor
;
1548 const wxChar
** m_constructorProperties
;
1549 const int m_constructorPropertiesCount
;
1550 wxVariantToObjectConverter m_variantOfPtrToObjectConverter
;
1551 wxVariantToObjectConverter m_variantToObjectConverter
;
1552 wxObjectToVariantConverter m_objectToVariantConverter
;
1553 wxObjectStreamingCallback m_streamingCallback
;
1554 const wxPropertyAccessor
*FindAccessor (const wxChar
*propertyName
) const ;
1557 // InitializeClasses() helper
1558 static wxClassInfo
*GetBaseByName(const wxChar
*name
) ;
1561 // registers the class
1565 DECLARE_NO_COPY_CLASS(wxClassInfo
)
1569 WXDLLIMPEXP_BASE wxObject
*wxCreateDynamicObject(const wxChar
*name
);
1571 // ----------------------------------------------------------------------------
1573 // ----------------------------------------------------------------------------
1575 // this object leads to having a pure runtime-instantiation
1577 class wxDynamicClassInfo
: public wxClassInfo
1580 wxDynamicClassInfo( const wxChar
*_UnitName
, const wxChar
*_ClassName
, const wxClassInfo
* superClass
) ;
1581 virtual ~wxDynamicClassInfo() ;
1583 // constructs a wxDynamicObject with an instance
1584 virtual wxObject
*AllocateObject() const ;
1586 // Call the Create method for a class
1587 virtual void Create (wxObject
*object
, int ParamCount
, wxxVariant
*Params
) const ;
1589 // get number of parameters for constructor
1590 virtual int GetCreateParamCount() const ;
1592 // get i-th constructor parameter
1593 virtual const wxChar
* GetCreateParamName(int i
) const ;
1595 // Runtime access to objects by property name, and variant data
1596 virtual void SetProperty (wxObject
*object
, const wxChar
*PropertyName
, const wxxVariant
&Value
) const ;
1597 virtual wxxVariant
GetProperty (wxObject
*object
, const wxChar
*PropertyName
) const ;
1599 // adds a property to this class at runtime
1600 void AddProperty( const wxChar
*propertyName
, const wxTypeInfo
* typeInfo
) ;
1602 // removes an existing runtime-property
1603 void RemoveProperty( const wxChar
*propertyName
) ;
1605 // as a handler to this class at runtime
1606 void AddHandler( const wxChar
*handlerName
, wxObjectEventFunction address
, const wxClassInfo
* eventClassInfo
) ;
1608 // removes an existing runtime-handler
1609 void RemoveHandler( const wxChar
*handlerName
) ;
1612 // ----------------------------------------------------------------------------
1613 // Dynamic class macros
1614 // ----------------------------------------------------------------------------
1616 #define _DECLARE_DYNAMIC_CLASS(name) \
1618 static wxClassInfo sm_class##name; \
1619 static const wxClassInfo* sm_classParents##name[] ; \
1620 static wxPropertyInfo* GetPropertiesStatic() ; \
1621 static wxHandlerInfo* GetHandlersStatic() ; \
1622 static wxClassInfo *GetClassInfoStatic() \
1623 { return &name::sm_class##name; } \
1624 virtual wxClassInfo *GetClassInfo() const \
1625 { return &name::sm_class##name; }
1627 #define DECLARE_DYNAMIC_CLASS(name) \
1628 static wxConstructorBridge* sm_constructor##name ; \
1629 static const wxChar * sm_constructorProperties##name[] ; \
1630 static const int sm_constructorPropertiesCount##name ; \
1631 _DECLARE_DYNAMIC_CLASS(name)
1633 #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
1634 DECLARE_NO_ASSIGN_CLASS(name) \
1635 DECLARE_DYNAMIC_CLASS(name)
1637 #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \
1638 DECLARE_NO_COPY_CLASS(name) \
1639 DECLARE_DYNAMIC_CLASS(name)
1641 #define DECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name)
1642 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
1644 // -----------------------------------
1645 // for concrete classes
1646 // -----------------------------------
1648 // Single inheritance with one base class
1650 #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit , callback) \
1651 wxObject* wxConstructorFor##name() \
1652 { return new name; } \
1653 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1654 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1655 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1656 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1657 (int) sizeof(name), \
1658 (wxObjectConstructorFn) wxConstructorFor##name , \
1659 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1660 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name , callback); \
1661 template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1662 template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1663 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1664 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1665 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1666 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1667 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1668 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1669 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1671 #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \
1672 wxObject* wxConstructorFor##name() \
1673 { return new name; } \
1674 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1675 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return &data.Get<name>() ; } \
1676 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1677 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1678 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1679 (int) sizeof(name), \
1680 (wxObjectConstructorFn) wxConstructorFor##name , \
1681 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1682 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name, callback); \
1683 template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1684 template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1685 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1686 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1687 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1688 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1689 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1690 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1691 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1693 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \
1694 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" , NULL ) \
1695 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1696 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1697 WX_CONSTRUCTOR_DUMMY( name )
1699 #define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \
1700 _IMPLEMENT_DYNAMIC_CLASS( name , basename , "" , NULL ) \
1701 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1702 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1703 WX_CONSTRUCTOR_DUMMY( name )
1705 #define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \
1706 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , NULL )
1708 #define IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name , basename , unit , callback ) \
1709 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , &callback )
1711 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \
1712 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit , NULL )
1714 // this is for classes that do not derive from wxobject, there are no creators for these
1716 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name , unit ) \
1717 const wxClassInfo* name::sm_classParents##name[] = { NULL } ; \
1718 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1719 (int) sizeof(name), \
1720 (wxObjectConstructorFn) 0 , \
1721 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1723 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1724 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1725 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1726 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1727 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1728 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1729 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1731 // this is for subclasses that still do not derive from wxobject
1733 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name , basename, unit ) \
1734 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1735 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1736 (int) sizeof(name), \
1737 (wxObjectConstructorFn) 0 , \
1738 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1740 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1741 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1742 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1743 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1744 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1745 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1746 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1749 // Multiple inheritance with two base classes
1751 #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit) \
1752 wxObject* wxConstructorFor##name() \
1753 { return new name; } \
1754 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,&basename2::sm_class##basename2 , NULL } ; \
1755 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1756 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1757 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1758 (int) sizeof(name), \
1759 (wxObjectConstructorFn) wxConstructorFor##name , \
1760 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1761 name::sm_constructorPropertiesCount##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1762 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1763 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1764 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1765 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1766 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1767 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1768 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1770 #define IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2) \
1771 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , "") \
1772 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1773 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1774 WX_CONSTRUCTOR_DUMMY( name )
1776 #define IMPLEMENT_DYNAMIC_CLASS2_XTI( name , basename , basename2, unit) \
1777 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , unit)
1779 // -----------------------------------
1780 // for abstract classes
1781 // -----------------------------------
1783 // Single inheritance with one base class
1785 #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
1786 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1787 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1788 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1789 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1790 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1791 (int) sizeof(name), \
1792 (wxObjectConstructorFn) 0 , \
1793 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1794 0 , wxVariantOfPtrToObjectConverter##name ,wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1795 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1796 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1797 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1798 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1799 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1800 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } \
1801 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID) ; assert(0) ; return &s_typeInfo ; }
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
]) ) ;