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 ( size_t 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 ) {} \
709 void Set( wxObject *object, const wxxVariant &variantValue ) const \
711 Klass *obj = dynamic_cast<Klass*>(object) ; \
712 if ( variantValue.HasData<valueType>() ) \
713 obj->setterMethod(variantValue.Get<valueType>()) ; \
715 obj->setterMethod(*variantValue.Get<valueType*>()) ; \
719 #define WX_GETTER( property, Klass, valueType , gettermethod ) \
720 class wxGetter##property : public wxGetter \
723 wxGetter##property() : wxGetter( #gettermethod ) {} \
725 void Get( const wxObject *object , wxxVariant &result) const \
727 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
728 result = wxxVariant( obj->gettermethod() ) ; \
732 #define WX_ADDER( property, Klass, valueType , addermethod ) \
733 class wxAdder##property : public wxAdder \
736 wxAdder##property() : wxAdder( #addermethod ) {} \
738 void Add( wxObject *object, const wxxVariant &variantValue ) const \
740 Klass *obj = dynamic_cast<Klass*>(object) ; \
741 if ( variantValue.HasData<valueType>() ) \
742 obj->addermethod(variantValue.Get<valueType>()) ; \
744 obj->addermethod(*variantValue.Get<valueType*>()) ; \
748 #define WX_COLLECTION_GETTER( property, Klass, valueType , gettermethod ) \
749 class wxCollectionGetter##property : public wxCollectionGetter \
752 wxCollectionGetter##property() : wxCollectionGetter( #gettermethod ) {} \
753 ~wxCollectionGetter() {} \
754 void Get( const wxObject *object , wxxVariantArray &result) const \
756 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
757 wxCollectionToVariantArray( obj->gettermethod() , result ) ; \
761 class WXDLLIMPEXP_BASE wxPropertyAccessor
764 wxPropertyAccessor( wxSetter
*setter
, wxGetter
*getter
, wxAdder
*adder
, wxCollectionGetter
*collectionGetter
)
765 { m_setter
= setter
; m_getter
= getter
; m_adder
= adder
; m_collectionGetter
= collectionGetter
;}
767 virtual ~wxPropertyAccessor() {}
769 // Setting a simple property (non-collection)
770 virtual void SetProperty(wxObject
*object
, const wxxVariant
&value
) const
771 { wxASSERT_MSG(m_setter
,wxT("SetProperty called w/o valid setter") ) ; m_setter
->Set( object
, value
) ;}
773 // Getting a simple property (non-collection)
774 virtual void GetProperty(const wxObject
*object
, wxxVariant
&result
) const
775 { wxASSERT_MSG(m_getter
,wxT("GetProperty called w/o valid getter") ) ; m_getter
->Get( object
, result
) ;}
777 // Adding an element to a collection property
778 virtual void AddToPropertyCollection(wxObject
*object
, const wxxVariant
&value
) const
779 { wxASSERT_MSG(m_adder
,wxT("AddToPropertyCollection called w/o valid adder") ) ; m_adder
->Add( object
, value
) ;}
781 // Getting a collection property
782 virtual void GetPropertyCollection( const wxObject
*obj
, wxxVariantArray
&result
) const
783 { wxASSERT_MSG(m_collectionGetter
,wxT("GetPropertyCollection called w/o valid collection getter") ) ; m_collectionGetter
->Get( obj
, result
) ;}
785 virtual bool HasSetter() const { return m_setter
!= NULL
; }
786 virtual bool HasCollectionGetter() const { return m_collectionGetter
!= NULL
; }
787 virtual bool HasGetter() const { return m_getter
!= NULL
; }
788 virtual bool HasAdder() const { return m_adder
!= NULL
; }
790 virtual const wxString
& GetCollectionGetterName() const
791 { return m_collectionGetter
->GetName() ; }
792 virtual const wxString
& GetGetterName() const
793 { return m_getter
->GetName() ; }
794 virtual const wxString
& GetSetterName() const
795 { return m_setter
->GetName() ; }
796 virtual const wxString
& GetAdderName() const
797 { return m_adder
->GetName() ; }
799 virtual wxxVariant ReadValue( const wxString &value ) const ;
800 virtual void WriteValue( wxString& value , const wxObject *o ) const ;
806 wxCollectionGetter
* m_collectionGetter
;
809 class WXDLLIMPEXP_BASE wxGenericPropertyAccessor
: public wxPropertyAccessor
812 wxGenericPropertyAccessor( const wxString
&propName
) ;
813 ~wxGenericPropertyAccessor() ;
815 virtual bool HasSetter() const { return true ; }
816 virtual bool HasGetter() const { return true ; }
817 virtual bool HasAdder() const { return false ; }
818 virtual bool HasCollectionGetter() const { return false ; }
820 virtual const wxString
& GetGetterName() const
821 { return m_getterName
; }
822 virtual const wxString
& GetSetterName() const
823 { return m_setterName
; }
825 virtual void SetProperty(wxObject
*object
, const wxxVariant
&value
) const ;
826 virtual void GetProperty(const wxObject
*object
, wxxVariant
&value
) const ;
828 // Adding an element to a collection property
829 virtual void AddToPropertyCollection(wxObject
*WXUNUSED(object
), const wxxVariant
&WXUNUSED(value
)) const
830 { wxASSERT_MSG(0,wxT("AddToPropertyCollection called on a generic accessor") ) ;}
832 // Getting a collection property
833 virtual void GetPropertyCollection( const wxObject
*WXUNUSED(obj
), wxxVariantArray
&WXUNUSED(result
)) const
834 { wxASSERT_MSG(0,wxT("GetPropertyCollection called on a generic accessor") ) ;}
836 struct wxGenericPropertyAccessorInternal
;
837 wxGenericPropertyAccessorInternal
* m_data
;
838 wxString m_propertyName
;
839 wxString m_setterName
;
840 wxString m_getterName
;
843 typedef long wxPropertyInfoFlags
;
845 // will be removed in future releases
846 wxPROP_DEPRECATED
= 0x00000001 ,
847 // object graph property, will be streamed with priority (after constructor properties)
848 wxPROP_OBJECT_GRAPH
= 0x00000002 ,
849 // this will only be streamed out and in as enum/set, the internal representation is still a long
850 wxPROP_ENUM_STORE_LONG
= 0x00000004 ,
851 // don't stream out this property, needed eg to avoid streaming out children that are always created by their parents
852 wxPROP_DONT_STREAM
= 0x00000008 ,
855 class WXDLLIMPEXP_BASE wxPropertyInfo
858 wxPropertyInfo(wxPropertyInfo
* &iter
,
859 const wxClassInfo
* itsClass
,
860 const wxString
& name
,
861 const wxTypeInfo
* typeInfo
,
862 wxPropertyAccessor
*accessor
,
864 wxPropertyInfoFlags flags
= 0,
865 const wxString
& helpString
= wxEmptyString
,
866 const wxString
& groupString
= wxEmptyString
) :
868 m_groupString(groupString
),
869 m_helpString(helpString
),
870 m_itsClass(itsClass
),
872 m_typeInfo(typeInfo
),
873 m_collectionElementTypeInfo(NULL
),
874 m_accessor(accessor
),
880 wxPropertyInfo(wxPropertyInfo
* &iter
,
881 const wxClassInfo
* itsClass
, const wxString
& name
,
882 const wxTypeInfo
* collTypeInfo
,
883 const wxTypeInfo
* elemTypeInfo
,
884 wxPropertyAccessor
*accessor
,
885 wxPropertyInfoFlags flags
= 0,
886 const wxString
& helpString
= wxEmptyString
,
887 const wxString
& groupString
= wxEmptyString
) :
889 m_groupString(groupString
),
890 m_helpString(helpString
),
891 m_itsClass(itsClass
),
893 m_typeInfo(collTypeInfo
),
894 m_collectionElementTypeInfo(elemTypeInfo
),
902 // return the class this property is declared in
903 const wxClassInfo
* GetDeclaringClass() const { return m_itsClass
; }
905 // return the name of this property
906 const wxString
& GetName() const { return m_name
; }
908 // returns the flags of this property
909 wxPropertyInfoFlags
GetFlags() const { return m_flags
;}
911 // returns the short help string of this property
912 const wxString
& GetHelpString() const { return m_helpString
; }
914 // returns the group string of this property
915 const wxString
& GetGroupString() const { return m_groupString
; }
917 // return the element type info of this property (for collections, otherwise NULL)
918 const wxTypeInfo
* GetCollectionElementTypeInfo() const { return m_collectionElementTypeInfo
; }
920 // return the type info of this property
921 const wxTypeInfo
* GetTypeInfo() const { return m_typeInfo
; }
923 // return the accessor for this property
924 wxPropertyAccessor
* GetAccessor() const { return m_accessor
; }
926 // returns NULL if this is the last property of this class
927 wxPropertyInfo
* GetNext() const { return m_next
; }
929 // returns the default value of this property, its kind may be wxT_VOID if it is not valid
930 wxxVariant
GetDefaultValue() const { return m_defaultValue
; }
932 void Insert(wxPropertyInfo
* &iter
)
939 wxPropertyInfo
* i
= iter
;
948 wxString m_typeName
;
949 wxString m_groupString
;
950 wxString m_helpString
;
951 const wxClassInfo
* m_itsClass
;
952 wxPropertyInfoFlags m_flags
;
953 const wxTypeInfo
* m_typeInfo
;
954 const wxTypeInfo
* m_collectionElementTypeInfo
;
955 wxPropertyAccessor
* m_accessor
;
956 wxxVariant m_defaultValue
;
957 // string representation of the default value
958 // to be assigned by the designer to the property
959 // when the component is dropped on the container.
960 wxPropertyInfo
* m_next
;
963 WX_DECLARE_EXPORTED_STRING_HASH_MAP( wxPropertyInfo
* , wxPropertyInfoMap
) ;
965 #define WX_BEGIN_PROPERTIES_TABLE(theClass) \
966 wxPropertyInfo *theClass::GetPropertiesStatic() \
968 typedef theClass class_t; \
969 static wxPropertyInfo* first = NULL ;
971 #define WX_END_PROPERTIES_TABLE() \
974 #define WX_HIDE_PROPERTY( name ) \
975 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (void*) NULL ) ,NULL , wxxVariant() , wxPROP_DONT_STREAM , wxEmptyString , wxEmptyString ) ;
977 #define WX_PROPERTY( name , type , setter , getter ,defaultValue , flags , help , group) \
978 WX_SETTER( name , class_t , type , setter ) \
979 static wxSetter##name _setter##name ; \
980 WX_GETTER( name , class_t , type , getter ) \
981 static wxGetter##name _getter##name ; \
982 static wxPropertyAccessor _accessor##name( &_setter##name , &_getter##name , NULL , NULL ) ; \
983 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) , flags , group , help ) ;
985 #define WX_PROPERTY_FLAGS( name , flags , type , setter , getter ,defaultValue , pflags , help , group) \
986 WX_SETTER( name , class_t , type , setter ) \
987 static wxSetter##name _setter##name ; \
988 WX_GETTER( name , class_t , type , getter ) \
989 static wxGetter##name _getter##name ; \
990 static wxPropertyAccessor _accessor##name( &_setter##name , &_getter##name , NULL , NULL ) ; \
991 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (flags*) NULL ) ,&_accessor##name , wxxVariant(defaultValue), wxPROP_ENUM_STORE_LONG | pflags , help , group ) ;
993 #define WX_READONLY_PROPERTY( name , type , getter ,defaultValue , flags , help , group) \
994 WX_GETTER( name , class_t , type , getter ) \
995 static wxGetter##name _getter##name ; \
996 static wxPropertyAccessor _accessor##name( NULL , &_getter##name , NULL , NULL ) ; \
997 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue), flags , help , group ) ;
999 #define WX_PROPERTY_COLLECTION( name , colltype , addelemtype , adder , getter , flags , help , group ) \
1000 WX_ADDER( name , class_t , addelemtype , adder ) \
1001 static wxAdder##name _adder##name ; \
1002 WX_COLLECTION_GETTER( name , class_t , colltype , getter ) \
1003 static wxCollectionGetter##name _collectionGetter##name ; \
1004 static wxPropertyAccessor _accessor##name( NULL , NULL ,&_adder##name , &_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_READONLY_PROPERTY_COLLECTION( name , colltype , addelemtype , getter , flags , help , group) \
1008 WX_COLLECTION_GETTER( name , class_t , colltype , getter ) \
1009 static wxCollectionGetter##name _collectionGetter##name ; \
1010 static wxPropertyAccessor _accessor##name( NULL , NULL , NULL , &_collectionGetter##name ) ; \
1011 static wxPropertyInfo _propertyInfo##name( first ,class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name , flags , help , group ) ;
1013 #define WX_PROPERTY_COLLECTION( name , colltype , addelemtype , adder , getter ) \
1014 static wxPropertyCollectionAccessorT<class_t , colltype , addelemtype > _accessor##name( &adder , &getter , #adder , #getter ) ; \
1015 static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name ) ;
1017 #define WX_READONLY_PROPERTY_COLLECTION( name , colltype , addelemtype , getter ) \
1018 static wxPropertyCollectionAccessorT<class_t , colltype , addelemtype > _accessor##name( &getter , #getter ) ; \
1019 static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name ) ;
1024 #define WX_DELEGATE( name , eventType , eventClass ) \
1025 static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \
1026 static wxPropertyInfo _propertyInfo##name( first ,class_t::GetClassInfoStatic() , #name , &_typeInfo##name , NULL , wxxVariant() ) ; \
1028 // ----------------------------------------------------------------------------
1031 // this is describing an event sink
1032 // ----------------------------------------------------------------------------
1037 wxHandlerInfo(wxHandlerInfo
* &iter
,
1038 const wxString
& name
,
1039 wxObjectEventFunction address
,
1040 const wxClassInfo
* eventClassInfo
) :
1041 m_eventFunction(address
),
1043 m_eventClassInfo(eventClassInfo
)
1050 wxHandlerInfo
* i
= iter
;
1060 // return the name of this handler
1061 const wxString
& GetName() const { return m_name
; }
1063 // return the class info of the event
1064 const wxClassInfo
* GetEventClassInfo() const { return m_eventClassInfo
; }
1066 // get the handler function pointer
1067 wxObjectEventFunction
GetEventFunction() const { return m_eventFunction
; }
1069 // returns NULL if this is the last handler of this class
1070 wxHandlerInfo
* GetNext() const { return m_next
; }
1072 wxObjectEventFunction m_eventFunction
;
1074 const wxClassInfo
* m_eventClassInfo
;
1075 wxHandlerInfo
* m_next
;
1078 #define WX_HANDLER(name,eventClassType) \
1079 static wxHandlerInfo _handlerInfo##name( first , #name , (wxObjectEventFunction) (wxEventFunction) &name , CLASSINFO( eventClassType ) ) ;
1081 #define WX_BEGIN_HANDLERS_TABLE(theClass) \
1082 wxHandlerInfo *theClass::GetHandlersStatic() \
1084 typedef theClass class_t; \
1085 static wxHandlerInfo* first = NULL ;
1087 #define WX_END_HANDLERS_TABLE() \
1090 // ----------------------------------------------------------------------------
1091 // Constructor Bridges
1093 // allow to set up constructors with params during runtime
1094 // ----------------------------------------------------------------------------
1096 class WXDLLIMPEXP_BASE wxConstructorBridge
1099 virtual void Create(wxObject
*o
, wxxVariant
*args
) = 0;
1102 // Creator Bridges for all Numbers of Params
1106 template<typename Class
>
1107 struct wxConstructorBridge_0
: public wxConstructorBridge
1109 void Create(wxObject
*o
, wxxVariant
*)
1111 Class
*obj
= dynamic_cast<Class
*>(o
);
1116 struct wxConstructorBridge_Dummy
: public wxConstructorBridge
1118 void Create(wxObject
*, wxxVariant
*)
1123 #define WX_CONSTRUCTOR_0(klass) \
1124 wxConstructorBridge_0<klass> constructor##klass ; \
1125 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1126 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
1127 const int klass::sm_constructorPropertiesCount##klass = 0 ;
1129 #define WX_CONSTRUCTOR_DUMMY(klass) \
1130 wxConstructorBridge_Dummy constructor##klass ; \
1131 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1132 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
1133 const int klass::sm_constructorPropertiesCount##klass = 0 ;
1137 template<typename Class
, typename T0
>
1138 struct wxConstructorBridge_1
: public wxConstructorBridge
1140 void Create(wxObject
*o
, wxxVariant
*args
)
1142 Class
*obj
= dynamic_cast<Class
*>(o
);
1144 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
)
1149 #define WX_CONSTRUCTOR_1(klass,t0,v0) \
1150 wxConstructorBridge_1<klass,t0> constructor##klass ; \
1151 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1152 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 } ; \
1153 const int klass::sm_constructorPropertiesCount##klass = 1 ;
1157 template<typename Class
,
1158 typename T0
, typename T1
>
1159 struct wxConstructorBridge_2
: public wxConstructorBridge
1161 void Create(wxObject
*o
, wxxVariant
*args
)
1163 Class
*obj
= dynamic_cast<Class
*>(o
);
1165 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1166 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
)
1171 #define WX_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
1172 wxConstructorBridge_2<klass,t0,t1> constructor##klass ; \
1173 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1174 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 } ; \
1175 const int klass::sm_constructorPropertiesCount##klass = 2;
1179 template<typename Class
,
1180 typename T0
, typename T1
, typename T2
>
1181 struct wxConstructorBridge_3
: public wxConstructorBridge
1183 void Create(wxObject
*o
, wxxVariant
*args
)
1185 Class
*obj
= dynamic_cast<Class
*>(o
);
1187 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1188 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1189 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
)
1194 #define WX_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
1195 wxConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \
1196 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1197 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 } ; \
1198 const int klass::sm_constructorPropertiesCount##klass = 3 ;
1202 template<typename Class
,
1203 typename T0
, typename T1
, typename T2
, typename T3
>
1204 struct wxConstructorBridge_4
: 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
)
1218 #define WX_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
1219 wxConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass ; \
1220 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1221 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 } ; \
1222 const int klass::sm_constructorPropertiesCount##klass = 4 ;
1226 template<typename Class
,
1227 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
>
1228 struct wxConstructorBridge_5
: public wxConstructorBridge
1230 void Create(wxObject
*o
, wxxVariant
*args
)
1232 Class
*obj
= dynamic_cast<Class
*>(o
);
1234 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1235 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1236 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1237 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1238 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
)
1243 #define WX_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
1244 wxConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass ; \
1245 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1246 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 } ; \
1247 const int klass::sm_constructorPropertiesCount##klass = 5;
1251 template<typename Class
,
1252 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
1253 struct wxConstructorBridge_6
: 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
)
1269 template<typename Class
,
1270 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
1271 struct wxDirectConstructorBridge_6
: public wxConstructorBridge
1273 void Create(wxObject
*o
, wxxVariant
*args
)
1275 Class
*obj
= new Class(
1276 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1277 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1278 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1279 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1280 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
) ,
1281 args
[5].WX_TEMPLATED_MEMBER_CALL(Get
, T5
)
1286 #define WX_DIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1287 wxDirectConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1288 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1289 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 } ; \
1290 const int klass::sm_constructorPropertiesCount##klass = 6;
1292 #define WX_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1293 wxConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1294 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1295 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 } ; \
1296 const int klass::sm_constructorPropertiesCount##klass = 6;
1300 template<typename Class
,
1301 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
>
1302 struct wxConstructorBridge_7
: public wxConstructorBridge
1304 void Create(wxObject
*o
, wxxVariant
*args
)
1306 Class
*obj
= dynamic_cast<Class
*>(o
);
1308 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1309 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1310 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1311 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1312 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
) ,
1313 args
[5].WX_TEMPLATED_MEMBER_CALL(Get
, T5
) ,
1314 args
[6].WX_TEMPLATED_MEMBER_CALL(Get
, T6
)
1319 #define WX_CONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
1320 wxConstructorBridge_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass ; \
1321 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1322 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 , #v6} ; \
1323 const int klass::sm_constructorPropertiesCount##klass = 7;
1327 template<typename Class
,
1328 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
, typename T7
>
1329 struct wxConstructorBridge_8
: public wxConstructorBridge
1331 void Create(wxObject
*o
, wxxVariant
*args
)
1333 Class
*obj
= dynamic_cast<Class
*>(o
);
1335 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1336 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1337 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1338 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1339 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
) ,
1340 args
[5].WX_TEMPLATED_MEMBER_CALL(Get
, T5
) ,
1341 args
[6].WX_TEMPLATED_MEMBER_CALL(Get
, T6
) ,
1342 args
[7].WX_TEMPLATED_MEMBER_CALL(Get
, T7
)
1347 #define WX_CONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
1348 wxConstructorBridge_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass ; \
1349 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1350 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 , #v6 , #v7} ; \
1351 const int klass::sm_constructorPropertiesCount##klass = 8;
1352 // ----------------------------------------------------------------------------
1354 // ----------------------------------------------------------------------------
1356 typedef wxObject
*(*wxObjectConstructorFn
)(void);
1357 typedef wxObject
* (*wxVariantToObjectConverter
)( wxxVariant
&data
) ;
1358 typedef wxxVariant (*wxObjectToVariantConverter
)( wxObject
* ) ;
1361 typedef bool (*wxObjectStreamingCallback
) ( const wxObject
*, wxWriter
* , wxPersister
* , wxxVariantArray
& ) ;
1363 class WXDLLIMPEXP_BASE wxClassInfo
1365 friend class WXDLLEXPORT wxPropertyInfo
;
1366 friend class WXDLLEXPORT wxHandlerInfo
;
1368 wxClassInfo(const wxClassInfo
**_Parents
,
1369 const wxChar
*_UnitName
,
1370 const wxChar
*_ClassName
,
1372 wxObjectConstructorFn ctor
,
1373 wxPropertyInfo
*_Props
,
1374 wxHandlerInfo
*_Handlers
,
1375 wxConstructorBridge
* _Constructor
,
1376 const wxChar
** _ConstructorProperties
,
1377 const int _ConstructorPropertiesCount
,
1378 wxVariantToObjectConverter _PtrConverter1
,
1379 wxVariantToObjectConverter _Converter2
,
1380 wxObjectToVariantConverter _Converter3
,
1381 wxObjectStreamingCallback _streamingCallback
= NULL
1384 m_className(_ClassName
),
1386 m_objectConstructor(ctor
),
1388 m_firstProperty(_Props
),
1389 m_firstHandler(_Handlers
),
1390 m_parents(_Parents
),
1391 m_unitName(_UnitName
),
1392 m_constructor(_Constructor
),
1393 m_constructorProperties(_ConstructorProperties
),
1394 m_constructorPropertiesCount(_ConstructorPropertiesCount
),
1395 m_variantOfPtrToObjectConverter(_PtrConverter1
),
1396 m_variantToObjectConverter(_Converter2
),
1397 m_objectToVariantConverter(_Converter3
),
1398 m_streamingCallback(_streamingCallback
)
1404 wxClassInfo(const wxChar
*_UnitName
, const wxChar
*_ClassName
,
1405 const wxClassInfo
**_Parents
) :
1406 m_className(_ClassName
),
1408 m_objectConstructor(NULL
),
1410 m_firstProperty(NULL
),
1411 m_firstHandler(NULL
),
1412 m_parents(_Parents
),
1413 m_unitName(_UnitName
),
1414 m_constructor(NULL
),
1415 m_constructorProperties(NULL
),
1416 m_constructorPropertiesCount(0),
1417 m_variantOfPtrToObjectConverter(NULL
),
1418 m_variantToObjectConverter(NULL
),
1419 m_objectToVariantConverter(NULL
),
1420 m_streamingCallback(NULL
)
1426 virtual ~wxClassInfo() ;
1428 // allocates an instance of this class, this object does not have to be initialized or fully constructed
1429 // as this call will be followed by a call to Create
1430 virtual wxObject
*AllocateObject() const { return m_objectConstructor ?
(*m_objectConstructor
)() : 0; }
1432 // 'old naming' for AllocateObject staying here for backward compatibility
1433 wxObject
*CreateObject() const { return AllocateObject() ; }
1435 const wxChar
*GetClassName() const { return m_className
; }
1436 const wxChar
*GetIncludeName() const { return m_unitName
; }
1437 const wxClassInfo
**GetParents() const { return m_parents
; }
1438 int GetSize() const { return m_objectSize
; }
1440 wxObjectConstructorFn
GetConstructor() const { return m_objectConstructor
; }
1441 static const wxClassInfo
*GetFirst() { return sm_first
; }
1442 const wxClassInfo
*GetNext() const { return m_next
; }
1443 static wxClassInfo
*FindClass(const wxChar
*className
);
1445 // Climb upwards through inheritance hierarchy.
1446 // Dual inheritance is catered for.
1448 bool IsKindOf(const wxClassInfo
*info
) const
1455 for ( int i
= 0 ; m_parents
[i
] ; ++ i
)
1457 if ( m_parents
[i
]->IsKindOf( info
) )
1464 // if there is a callback registered with that class it will be called
1465 // before this object will be written to disk, it can veto streaming out
1466 // this object by returning false, if this class has not registered a
1467 // callback, the search will go up the inheritance tree if no callback has
1468 // been registered true will be returned by default
1469 bool BeforeWriteObject( const wxObject
*obj
, wxWriter
*streamer
, wxPersister
*persister
, wxxVariantArray
&metadata
) const ;
1471 // gets the streaming callback from this class or any superclass
1472 wxObjectStreamingCallback
GetStreamingCallback() const ;
1474 #ifdef WXWIN_COMPATIBILITY_2_4
1475 // Initializes parent pointers and hash table for fast searching.
1476 wxDEPRECATED( static void InitializeClasses() );
1477 // Cleans up hash table used for fast searching.
1478 wxDEPRECATED( static void CleanUpClasses() );
1480 static void CleanUp();
1482 // returns the first property
1483 const wxPropertyInfo
* GetFirstProperty() const { return m_firstProperty
; }
1485 // returns the first handler
1486 const wxHandlerInfo
* GetFirstHandler() const { return m_firstHandler
; }
1488 // Call the Create upon an instance of the class, in the end the object is fully
1490 virtual void Create (wxObject
*object
, int ParamCount
, wxxVariant
*Params
) const
1492 wxASSERT_MSG( ParamCount
== m_constructorPropertiesCount
, wxT("Illegal Parameter Count for Create Method")) ;
1493 m_constructor
->Create( object
, Params
) ;
1496 // get number of parameters for constructor
1497 virtual int GetCreateParamCount() const { return m_constructorPropertiesCount
; }
1499 // get n-th constructor parameter
1500 virtual const wxChar
* GetCreateParamName(int n
) const { return m_constructorProperties
[n
] ; }
1502 // Runtime access to objects for simple properties (get/set) by property name, and variant data
1503 virtual void SetProperty (wxObject
*object
, const wxChar
*propertyName
, const wxxVariant
&value
) const ;
1504 virtual wxxVariant
GetProperty (wxObject
*object
, const wxChar
*propertyName
) const;
1506 // Runtime access to objects for collection properties by property name
1507 virtual wxxVariantArray
GetPropertyCollection(wxObject
*object
, const wxChar
*propertyName
) const ;
1508 virtual void AddToPropertyCollection(wxObject
*object
, const wxChar
*propertyName
, const wxxVariant
& value
) const ;
1510 // we must be able to cast variants to wxObject pointers, templates seem not to be suitable
1511 wxObject
* VariantToInstance( wxxVariant
&data
) const
1512 { if ( data
.GetTypeInfo()->GetKind() == wxT_OBJECT
)
1513 return m_variantToObjectConverter( data
) ;
1515 return m_variantOfPtrToObjectConverter( data
) ;
1518 wxxVariant
InstanceToVariant( wxObject
*object
) const { return m_objectToVariantConverter( object
) ; }
1520 // find property by name
1521 virtual const wxPropertyInfo
*FindPropertyInfo (const wxChar
*PropertyName
) const ;
1523 // find handler by name
1524 virtual const wxHandlerInfo
*FindHandlerInfo (const wxChar
*PropertyName
) const ;
1526 // find property by name
1527 virtual const wxPropertyInfo
*FindPropertyInfoInThisClass (const wxChar
*PropertyName
) const ;
1529 // find handler by name
1530 virtual const wxHandlerInfo
*FindHandlerInfoInThisClass (const wxChar
*PropertyName
) const ;
1532 // puts all the properties of this class and its superclasses in the map, as long as there is not yet
1533 // an entry with the same name (overriding mechanism)
1534 void GetProperties( wxPropertyInfoMap
&map
) const ;
1536 const wxChar
*m_className
;
1538 wxObjectConstructorFn m_objectConstructor
;
1540 // class info object live in a linked list:
1541 // pointers to its head and the next element in it
1543 static wxClassInfo
*sm_first
;
1544 wxClassInfo
*m_next
;
1546 // FIXME: this should be private (currently used directly by way too
1548 static wxHashTable
*sm_classTable
;
1551 wxPropertyInfo
* m_firstProperty
;
1552 wxHandlerInfo
* m_firstHandler
;
1554 const wxClassInfo
** m_parents
;
1555 const wxChar
* m_unitName
;
1557 wxConstructorBridge
* m_constructor
;
1558 const wxChar
** m_constructorProperties
;
1559 const int m_constructorPropertiesCount
;
1560 wxVariantToObjectConverter m_variantOfPtrToObjectConverter
;
1561 wxVariantToObjectConverter m_variantToObjectConverter
;
1562 wxObjectToVariantConverter m_objectToVariantConverter
;
1563 wxObjectStreamingCallback m_streamingCallback
;
1564 const wxPropertyAccessor
*FindAccessor (const wxChar
*propertyName
) const ;
1567 // InitializeClasses() helper
1568 static wxClassInfo
*GetBaseByName(const wxChar
*name
) ;
1571 // registers the class
1575 DECLARE_NO_COPY_CLASS(wxClassInfo
)
1579 WXDLLIMPEXP_BASE wxObject
*wxCreateDynamicObject(const wxChar
*name
);
1581 // ----------------------------------------------------------------------------
1583 // ----------------------------------------------------------------------------
1585 // this object leads to having a pure runtime-instantiation
1587 class wxDynamicClassInfo
: public wxClassInfo
1590 wxDynamicClassInfo( const wxChar
*_UnitName
, const wxChar
*_ClassName
, const wxClassInfo
* superClass
) ;
1591 virtual ~wxDynamicClassInfo() ;
1593 // constructs a wxDynamicObject with an instance
1594 virtual wxObject
*AllocateObject() const ;
1596 // Call the Create method for a class
1597 virtual void Create (wxObject
*object
, int ParamCount
, wxxVariant
*Params
) const ;
1599 // get number of parameters for constructor
1600 virtual int GetCreateParamCount() const ;
1602 // get i-th constructor parameter
1603 virtual const wxChar
* GetCreateParamName(int i
) const ;
1605 // Runtime access to objects by property name, and variant data
1606 virtual void SetProperty (wxObject
*object
, const wxChar
*PropertyName
, const wxxVariant
&Value
) const ;
1607 virtual wxxVariant
GetProperty (wxObject
*object
, const wxChar
*PropertyName
) const ;
1609 // adds a property to this class at runtime
1610 void AddProperty( const wxChar
*propertyName
, const wxTypeInfo
* typeInfo
) ;
1612 // removes an existing runtime-property
1613 void RemoveProperty( const wxChar
*propertyName
) ;
1615 // as a handler to this class at runtime
1616 void AddHandler( const wxChar
*handlerName
, wxObjectEventFunction address
, const wxClassInfo
* eventClassInfo
) ;
1618 // removes an existing runtime-handler
1619 void RemoveHandler( const wxChar
*handlerName
) ;
1622 // ----------------------------------------------------------------------------
1623 // Dynamic class macros
1624 // ----------------------------------------------------------------------------
1626 #define _DECLARE_DYNAMIC_CLASS(name) \
1628 static wxClassInfo sm_class##name; \
1629 static const wxClassInfo* sm_classParents##name[] ; \
1630 static wxPropertyInfo* GetPropertiesStatic() ; \
1631 static wxHandlerInfo* GetHandlersStatic() ; \
1632 static wxClassInfo *GetClassInfoStatic() \
1633 { return &name::sm_class##name; } \
1634 virtual wxClassInfo *GetClassInfo() const \
1635 { return &name::sm_class##name; }
1637 #define DECLARE_DYNAMIC_CLASS(name) \
1638 static wxConstructorBridge* sm_constructor##name ; \
1639 static const wxChar * sm_constructorProperties##name[] ; \
1640 static const int sm_constructorPropertiesCount##name ; \
1641 _DECLARE_DYNAMIC_CLASS(name)
1643 #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
1644 DECLARE_NO_ASSIGN_CLASS(name) \
1645 DECLARE_DYNAMIC_CLASS(name)
1647 #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \
1648 DECLARE_NO_COPY_CLASS(name) \
1649 DECLARE_DYNAMIC_CLASS(name)
1651 #define DECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name)
1652 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
1654 // -----------------------------------
1655 // for concrete classes
1656 // -----------------------------------
1658 // Single inheritance with one base class
1660 #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit , callback) \
1661 wxObject* wxConstructorFor##name() \
1662 { return new name; } \
1663 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1664 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1665 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1666 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1667 (int) sizeof(name), \
1668 (wxObjectConstructorFn) wxConstructorFor##name , \
1669 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1670 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name , callback); \
1671 template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1672 template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1673 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1674 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1675 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1676 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1677 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1678 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1679 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1681 #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \
1682 wxObject* wxConstructorFor##name() \
1683 { return new name; } \
1684 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1685 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return &data.Get<name>() ; } \
1686 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1687 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1688 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1689 (int) sizeof(name), \
1690 (wxObjectConstructorFn) wxConstructorFor##name , \
1691 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1692 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name, callback); \
1693 template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1694 template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1695 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1696 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1697 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1698 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1699 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1700 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1701 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1703 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \
1704 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" , NULL ) \
1705 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1706 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1707 WX_CONSTRUCTOR_DUMMY( name )
1709 #define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \
1710 _IMPLEMENT_DYNAMIC_CLASS( name , basename , "" , NULL ) \
1711 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1712 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1713 WX_CONSTRUCTOR_DUMMY( name )
1715 #define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \
1716 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , NULL )
1718 #define IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name , basename , unit , callback ) \
1719 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , &callback )
1721 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \
1722 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit , NULL )
1724 // this is for classes that do not derive from wxobject, there are no creators for these
1726 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name , unit ) \
1727 const wxClassInfo* name::sm_classParents##name[] = { NULL } ; \
1728 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1729 (int) sizeof(name), \
1730 (wxObjectConstructorFn) 0 , \
1731 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1733 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1734 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1735 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1736 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1737 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1738 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1739 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1741 // this is for subclasses that still do not derive from wxobject
1743 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name , basename, unit ) \
1744 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1745 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1746 (int) sizeof(name), \
1747 (wxObjectConstructorFn) 0 , \
1748 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1750 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1751 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1752 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1753 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1754 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1755 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1756 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1759 // Multiple inheritance with two base classes
1761 #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit) \
1762 wxObject* wxConstructorFor##name() \
1763 { return new name; } \
1764 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,&basename2::sm_class##basename2 , NULL } ; \
1765 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1766 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1767 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1768 (int) sizeof(name), \
1769 (wxObjectConstructorFn) wxConstructorFor##name , \
1770 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1771 name::sm_constructorPropertiesCount##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1772 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1773 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1774 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1775 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1776 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1777 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1778 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1780 #define IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2) \
1781 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , "") \
1782 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1783 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1784 WX_CONSTRUCTOR_DUMMY( name )
1786 #define IMPLEMENT_DYNAMIC_CLASS2_XTI( name , basename , basename2, unit) \
1787 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , unit)
1789 // -----------------------------------
1790 // for abstract classes
1791 // -----------------------------------
1793 // Single inheritance with one base class
1795 #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
1796 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1797 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1798 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1799 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1800 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1801 (int) sizeof(name), \
1802 (wxObjectConstructorFn) 0 , \
1803 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1804 0 , wxVariantOfPtrToObjectConverter##name ,wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1805 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1806 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1807 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1808 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1809 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1810 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } \
1811 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID) ; assert(0) ; return &s_typeInfo ; }
1813 #define IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1814 _IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1815 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1816 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; }
1818 // Multiple inheritance with two base classes
1820 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
1821 wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \
1822 wxT(#basename2), (int) sizeof(name), \
1823 (wxObjectConstructorFn) 0);
1825 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
1826 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
1828 // --------------------------------------------------------------------------
1829 // Collection Support
1830 // --------------------------------------------------------------------------
1832 template<typename iter
, typename collection_t
> void wxListCollectionToVariantArray( const collection_t
& coll
, wxxVariantArray
&value
)
1834 iter current
= coll
.GetFirst() ;
1837 value
.Add( new wxxVariant(current
->GetData()) ) ;
1838 current
= current
->GetNext();
1842 template<typename collection_t
> void wxArrayCollectionToVariantArray( const collection_t
& coll
, wxxVariantArray
&value
)
1844 for( size_t i
= 0 ; i
< coll
.GetCount() ; i
++ )
1846 value
.Add( new wxxVariant(coll
[i
]) ) ;