1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: runtime metadata information (extended class info)
4 // Author: Stefan Csomor
8 // Copyright: (c) 1997 Julian Smart
9 // (c) 2003 Stefan Csomor
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
16 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
17 #pragma interface "xti.h"
20 // We want to support properties, event sources and events sinks through
21 // explicit declarations, using templates and specialization to make the
22 // effort as painless as possible.
24 // This means we have the following domains :
26 // - Type Information for categorizing built in types as well as custom types
27 // this includes information about enums, their values and names
28 // - Type safe value storage : a kind of wxVariant, called right now wxxVariant
29 // which will be merged with wxVariant
30 // - Property Information and Property Accessors providing access to a class'
31 // values and exposed event delegates
32 // - Information about event handlers
33 // - extended Class Information for accessing all these
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
40 #include "wx/memory.h"
42 #include "wx/string.h"
43 #include "wx/arrstr.h"
44 #include "wx/hashmap.h"
48 // we will move this later to defs.h
50 #if !wxCHECK_GCC_VERSION( 3 , 4 )
51 # define wxUSE_MEMBER_TEMPLATES 0
56 # define wxUSE_MEMBER_TEMPLATES 0
60 #ifndef wxUSE_MEMBER_TEMPLATES
61 #define wxUSE_MEMBER_TEMPLATES 1
64 #if wxUSE_MEMBER_TEMPLATES
65 #define WX_TEMPLATED_MEMBER_CALL( method , type ) method<type>()
66 #define WX_TEMPLATED_MEMBER_FIX( type )
68 #define WX_TEMPLATED_MEMBER_CALL( method , type ) method((type*)NULL)
69 #define WX_TEMPLATED_MEMBER_FIX( type ) type* =NULL
72 class WXDLLIMPEXP_BASE wxObject
;
73 class WXDLLIMPEXP_BASE wxClassInfo
;
74 class WXDLLIMPEXP_BASE wxDynamicClassInfo
;
75 class WXDLLIMPEXP_BASE wxHashTable
;
76 class WXDLLIMPEXP_BASE wxObjectRefData
;
77 class WXDLLIMPEXP_BASE wxEvent
;
79 typedef void (wxObject::*wxObjectEventFunction
)(wxEvent
&);
81 // ----------------------------------------------------------------------------
84 // In the header files there would no change from pure c++ code, in the
85 // implementation, an enum would have
86 // to be enumerated eg :
88 // WX_BEGIN_ENUM( wxFlavor )
89 // WX_ENUM_MEMBER( Vanilla )
90 // WX_ENUM_MEMBER( Chocolate )
91 // WX_ENUM_MEMBER( Strawberry )
92 // WX_END_ENUM( wxFlavor )
93 // ----------------------------------------------------------------------------
95 struct WXDLLIMPEXP_BASE wxEnumMemberData
101 class WXDLLIMPEXP_BASE wxEnumData
104 wxEnumData( wxEnumMemberData
* data
) ;
106 // returns true if the member has been found and sets the int value
107 // pointed to accordingly (if ptr != null )
108 // if not found returns false, value left unchanged
109 bool HasEnumMemberValue( const wxChar
*name
, int *value
= NULL
) const ;
111 // returns the value of the member, if not found in debug mode an
112 // assert is issued, in release 0 is returned
113 int GetEnumMemberValue(const wxChar
*name
) const ;
115 // returns the name of the enum member having the passed in value
116 // returns an emtpy string if not found
117 const wxChar
*GetEnumMemberName(int value
) const ;
119 // returns the number of members in this enum
120 int GetEnumCount() const { return m_count
; }
122 // returns the value of the nth member
123 int GetEnumMemberValueByIndex( int n
) const ;
125 // returns the value of the nth member
126 const wxChar
*GetEnumMemberNameByIndex( int n
) const ;
128 wxEnumMemberData
*m_members
;
132 #define WX_BEGIN_ENUM( e ) \
133 wxEnumMemberData s_enumDataMembers##e[] = {
135 #define WX_ENUM_MEMBER( v ) { wxT(#v), v } ,
137 #define WX_END_ENUM( e ) { NULL , 0 } } ; \
138 wxEnumData s_enumData##e( s_enumDataMembers##e ) ; \
139 wxEnumData *wxGetEnumData(e) { return &s_enumData##e ; } \
140 template<> void wxStringReadValue(const wxString& s , e &data ) \
142 data = (e) s_enumData##e.GetEnumMemberValue(s) ; \
144 template<> void wxStringWriteValue(wxString &s , const e &data ) \
146 s = s_enumData##e.GetEnumMemberName((int)data) ; \
148 void FromLong##e( long data , wxxVariant& result ) { result = wxxVariant((e)data) ;} \
149 void ToLong##e( const wxxVariant& data , long &result ) { result = (long) data.Get<e>() ;} \
150 wxEnumTypeInfo s_typeInfo##e(wxT_ENUM , &s_enumData##e , &wxToStringConverter<e> , &wxFromStringConverter<e> , &ToLong##e , &FromLong##e , typeid(e).name() ) ;
152 // ----------------------------------------------------------------------------
164 // typedef wxBitset<wxFlavor> wxCoupe ;
166 // in the implementation file :
168 // WX_BEGIN_ENUM( wxFlavor )
169 // WX_ENUM_MEMBER( Vanilla )
170 // WX_ENUM_MEMBER( Chocolate )
171 // WX_ENUM_MEMBER( Strawberry )
172 // WX_END_ENUM( wxFlavor )
174 // WX_IMPLEMENT_SET_STREAMING( wxCoupe , wxFlavor )
176 // implementation note : no partial specialization for streaming, but a delegation to a
179 // ----------------------------------------------------------------------------
181 // in order to remove dependancy on string tokenizer
182 void wxSetStringToArray( const wxString
&s
, wxArrayString
&array
) ;
185 void wxSetFromString(const wxString
&s
, wxBitset
<e
> &data
)
187 wxEnumData
* edata
= wxGetEnumData((e
) 0) ;
190 wxArrayString array
;
191 wxSetStringToArray( s
, array
) ;
193 for ( int i
= 0 ; i
< array
.Count() ; ++i
)
197 if ( edata
->HasEnumMemberValue( flag
, &ivalue
) )
199 data
.set( (e
) ivalue
) ;
205 void wxSetToString( wxString
&s
, const wxBitset
<e
> &data
)
207 wxEnumData
* edata
= wxGetEnumData((e
) 0) ;
208 int count
= edata
->GetEnumCount() ;
211 for ( i
= 0 ; i
< count
; i
++ )
213 e value
= (e
) edata
->GetEnumMemberValueByIndex(i
) ;
214 if ( data
.test( value
) )
216 // this could also be done by the templated calls
219 s
+= edata
->GetEnumMemberNameByIndex(i
) ;
224 #define WX_IMPLEMENT_SET_STREAMING(SetName,e) \
225 template<> void wxStringReadValue(const wxString &s , wxBitset<e> &data ) \
227 wxSetFromString( s , data ) ; \
229 template<> void wxStringWriteValue( wxString &s , const wxBitset<e> &data ) \
231 wxSetToString( s , data ) ; \
233 void FromLong##SetName( long data , wxxVariant& result ) { result = wxxVariant(SetName((unsigned long)data)) ;} \
234 void ToLong##SetName( const wxxVariant& data , long &result ) { result = (long) data.Get<SetName>().to_ulong() ;} \
235 wxEnumTypeInfo s_typeInfo##SetName(wxT_SET , &s_enumData##e , &wxToStringConverter<SetName> , &wxFromStringConverter<SetName> , &ToLong##SetName , &FromLong##SetName, typeid(SetName).name() ) ; \
239 void wxFlagsFromString(const wxString
&s
, e
&data
)
241 wxEnumData
* edata
= wxGetEnumData((e
*) 0) ;
244 wxArrayString array
;
245 wxSetStringToArray( s
, array
) ;
247 for ( size_t i
= 0 ; i
< array
.Count() ; ++i
)
251 if ( edata
->HasEnumMemberValue( flag
, &ivalue
) )
253 data
.m_data
|= ivalue
;
259 void wxFlagsToString( wxString
&s
, const e
& data
)
261 wxEnumData
* edata
= wxGetEnumData((e
*) 0) ;
262 int count
= edata
->GetEnumCount() ;
265 long dataValue
= data
.m_data
;
266 for ( i
= 0 ; i
< count
; i
++ )
268 int value
= edata
->GetEnumMemberValueByIndex(i
) ;
269 // make this to allow for multi-bit constants to work
270 if ( value
&& ( dataValue
& value
) == value
)
272 // clear the flags we just set
273 dataValue
&= ~value
;
274 // this could also be done by the templated calls
277 s
+= edata
->GetEnumMemberNameByIndex(i
) ;
282 #define WX_BEGIN_FLAGS( e ) \
283 wxEnumMemberData s_enumDataMembers##e[] = {
285 #define WX_FLAGS_MEMBER( v ) { wxT(#v), v } ,
287 #define WX_END_FLAGS( e ) { NULL , 0 } } ; \
288 wxEnumData s_enumData##e( s_enumDataMembers##e ) ; \
289 wxEnumData *wxGetEnumData(e*) { return &s_enumData##e ; } \
290 template<> void wxStringReadValue(const wxString &s , e &data ) \
292 wxFlagsFromString<e>( s , data ) ; \
294 template<> void wxStringWriteValue( wxString &s , const e& data ) \
296 wxFlagsToString<e>( s , data ) ; \
298 void FromLong##e( long data , wxxVariant& result ) { result = wxxVariant(e(data)) ;} \
299 void ToLong##e( const wxxVariant& data , long &result ) { result = (long) data.Get<e>().m_data ;} \
300 wxEnumTypeInfo s_typeInfo##e(wxT_SET , &s_enumData##e , &wxToStringConverter<e> , &wxFromStringConverter<e> , &ToLong##e , &FromLong##e, typeid(e).name() ) ;
301 // ----------------------------------------------------------------------------
303 // ----------------------------------------------------------------------------
306 // All data exposed by the RTTI is characterized using the following classes.
307 // The first characterization is done by wxTypeKind. All enums up to and including
308 // wxT_CUSTOM represent so called simple types. These cannot be divided any further.
309 // They can be converted to and from wxStrings, that's all.
314 wxT_VOID
= 0, // unknown type
324 wxT_STRING
, // must be wxString
325 wxT_SET
, // must be wxBitset<> template
327 wxT_CUSTOM
, // user defined type (e.g. wxPoint)
329 wxT_LAST_SIMPLE_TYPE_KIND
= wxT_CUSTOM
,
331 wxT_OBJECT_PTR
, // object reference
332 wxT_OBJECT
, // embedded object
333 wxT_COLLECTION
, // collection
335 wxT_DELEGATE
, // for connecting against an event source
337 wxT_LAST_TYPE_KIND
= wxT_DELEGATE
// sentinel for bad data, asserts, debugging
340 class WXDLLIMPEXP_BASE wxxVariant
;
341 class WXDLLIMPEXP_BASE wxTypeInfo
;
343 WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxTypeInfo
* , wxTypeInfoMap
, class WXDLLIMPEXP_BASE
) ;
345 class WXDLLIMPEXP_BASE wxTypeInfo
348 typedef void (*converterToString_t
)( const wxxVariant
& data
, wxString
&result
) ;
349 typedef void (*converterFromString_t
)( const wxString
& data
, wxxVariant
&result
) ;
351 wxTypeInfo(wxTypeKind kind
,
352 converterToString_t to
= NULL
, converterFromString_t from
= NULL
,
353 const wxString
&name
= wxEmptyString
):
354 m_toString(to
), m_fromString(from
), m_kind(kind
), m_name(name
)
359 wxTypeInfo(wxTypeKind kind
,
360 converterToString_t to
= NULL
, converterFromString_t from
= NULL
,
361 const char *name
= ""):
362 m_toString(to
), m_fromString(from
), m_kind(kind
), m_name(wxString::FromAscii(name
))
368 virtual ~wxTypeInfo()
373 // return the kind of this type (wxT_... constants)
374 wxTypeKind
GetKind() const { return m_kind
; }
376 // returns the unique name of this type
377 const wxString
& GetTypeName() const { return m_name
; }
379 // is this type a delegate type
380 bool IsDelegateType() const { return m_kind
== wxT_DELEGATE
; }
382 // is this type a custom type
383 bool IsCustomType() const { return m_kind
== wxT_CUSTOM
; }
385 // is this type an object type
386 bool IsObjectType() const { return m_kind
== wxT_OBJECT
|| m_kind
== wxT_OBJECT_PTR
; }
388 // can the content of this type be converted to and from strings ?
389 bool HasStringConverters() const { return m_toString
!= NULL
&& m_fromString
!= NULL
; }
391 // convert a wxxVariant holding data of this type into a string
392 void ConvertToString( const wxxVariant
& data
, wxString
&result
) const
394 { wxASSERT_MSG( m_toString
, wxT("String conversions not supported") ) ; (*m_toString
)( data
, result
) ; }
396 // convert a string into a wxxVariant holding the corresponding data in this type
397 void ConvertFromString( const wxString
& data
, wxxVariant
&result
) const
398 { wxASSERT_MSG( m_fromString
, wxT("String conversions not supported") ) ; (*m_fromString
)( data
, result
) ; }
401 static wxTypeInfo
*FindType(const char *typeName
) { return FindType( wxString::FromAscii(typeName
) ) ; }
403 static wxTypeInfo
*FindType(const wxChar
*typeName
);
410 converterToString_t m_toString
;
411 converterFromString_t m_fromString
;
413 static wxTypeInfoMap
* sm_typeTable
;
419 class WXDLLIMPEXP_BASE wxBuiltInTypeInfo
: public wxTypeInfo
422 wxBuiltInTypeInfo( wxTypeKind kind
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
, const wxString
&name
= wxEmptyString
) :
423 wxTypeInfo( kind
, to
, from
, name
)
424 { wxASSERT_MSG( GetKind() < wxT_SET
, wxT("Illegal Kind for Base Type") ) ; }
426 wxBuiltInTypeInfo( wxTypeKind kind
, converterToString_t to
, converterFromString_t from
, const char *name
) :
427 wxTypeInfo( kind
, to
, from
, name
)
428 { wxASSERT_MSG( GetKind() < wxT_SET
, wxT("Illegal Kind for Base Type") ) ; }
432 class WXDLLIMPEXP_BASE wxCustomTypeInfo
: public wxTypeInfo
435 wxCustomTypeInfo( const wxString
&name
, converterToString_t to
, converterFromString_t from
) :
436 wxTypeInfo( wxT_CUSTOM
, to
, from
, name
)
439 wxCustomTypeInfo( const char *name
, converterToString_t to
, converterFromString_t from
) :
440 wxTypeInfo( wxT_CUSTOM
, to
, from
, name
)
445 class WXDLLIMPEXP_BASE wxEnumTypeInfo
: public wxTypeInfo
448 typedef void (*converterToLong_t
)( const wxxVariant
& data
, long &result
) ;
449 typedef void (*converterFromLong_t
)( long data
, wxxVariant
&result
) ;
451 wxEnumTypeInfo( wxTypeKind kind
, wxEnumData
* enumInfo
, converterToString_t to
, converterFromString_t from
,
452 converterToLong_t toLong
, converterFromLong_t fromLong
, const wxString
&name
) :
453 wxTypeInfo( kind
, to
, from
, name
) , m_toLong( toLong
) , m_fromLong( fromLong
)
454 { wxASSERT_MSG( kind
== wxT_ENUM
|| kind
== wxT_SET
, wxT("Illegal Kind for Enum Type")) ; m_enumInfo
= enumInfo
;}
457 wxEnumTypeInfo( wxTypeKind kind
, wxEnumData
* enumInfo
, converterToString_t to
, converterFromString_t from
,
458 converterToLong_t toLong
, converterFromLong_t fromLong
, const char * name
) :
459 wxTypeInfo( kind
, to
, from
, name
) , m_toLong( toLong
) , m_fromLong( fromLong
)
460 { wxASSERT_MSG( kind
== wxT_ENUM
|| kind
== wxT_SET
, wxT("Illegal Kind for Enum Type")) ; m_enumInfo
= enumInfo
;}
462 const wxEnumData
* GetEnumData() const { return m_enumInfo
; }
464 // convert a wxxVariant holding data of this type into a long
465 void ConvertToLong( const wxxVariant
& data
, long &result
) const
467 { wxASSERT_MSG( m_toLong
, wxT("Long conversions not supported") ) ; (*m_toLong
)( data
, result
) ; }
469 // convert a long into a wxxVariant holding the corresponding data in this type
470 void ConvertFromLong( long data
, wxxVariant
&result
) const
471 { wxASSERT_MSG( m_fromLong
, wxT("Long conversions not supported") ) ; (*m_fromLong
)( data
, result
) ; }
474 converterToLong_t m_toLong
;
475 converterFromLong_t m_fromLong
;
477 wxEnumData
*m_enumInfo
; // Kind == wxT_ENUM or Kind == wxT_SET
480 class WXDLLIMPEXP_BASE wxClassTypeInfo
: public wxTypeInfo
483 wxClassTypeInfo( wxTypeKind kind
, wxClassInfo
* classInfo
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
, const wxString
&name
= wxEmptyString
) ;
485 wxClassTypeInfo( wxTypeKind kind
, wxClassInfo
* classInfo
, converterToString_t to
, converterFromString_t from
, const char *name
) ;
487 const wxClassInfo
*GetClassInfo() const { return m_classInfo
; }
489 wxClassInfo
*m_classInfo
; // Kind == wxT_OBJECT - could be NULL
492 class WXDLLIMPEXP_BASE wxCollectionTypeInfo
: public wxTypeInfo
495 wxCollectionTypeInfo( const wxString
&elementName
, converterToString_t to
, converterFromString_t from
, const wxString
&name
) :
496 wxTypeInfo( wxT_COLLECTION
, to
, from
, name
)
497 { m_elementTypeName
= elementName
; m_elementType
= NULL
;}
499 wxCollectionTypeInfo( const char *elementName
, converterToString_t to
, converterFromString_t from
, const char *name
) :
500 wxTypeInfo( wxT_COLLECTION
, to
, from
, name
)
501 { m_elementTypeName
= wxString::FromAscii( elementName
) ; m_elementType
= NULL
;}
503 const wxTypeInfo
* GetElementType() const
505 if ( m_elementType
== NULL
)
506 m_elementType
= wxTypeInfo::FindType( m_elementTypeName
) ;
507 return m_elementType
; }
509 mutable wxTypeInfo
* m_elementType
;
510 wxString m_elementTypeName
;
513 // a delegate is an exposed event source
515 class WXDLLIMPEXP_BASE wxDelegateTypeInfo
: public wxTypeInfo
518 wxDelegateTypeInfo( int eventType
, wxClassInfo
* eventClass
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
) ;
519 wxDelegateTypeInfo( int eventType
, int lastEventType
, wxClassInfo
* eventClass
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
) ;
520 int GetEventType() const { return m_eventType
; }
521 int GetLastEventType() const { return m_lastEventType
; }
522 const wxClassInfo
* GetEventClass() const { return m_eventClass
; }
524 const wxClassInfo
*m_eventClass
; // (extended will merge into classinfo)
526 int m_lastEventType
;
529 template<typename T
> const wxTypeInfo
* wxGetTypeInfo( T
* ) { return wxTypeInfo::FindType(typeid(T
).name()) ; }
531 // this macro is for usage with custom, non-object derived classes and structs, wxPoint is such a custom type
533 #define WX_CUSTOM_TYPE_INFO( e , toString , fromString ) \
534 wxCustomTypeInfo s_typeInfo##e(typeid(e).name() , &toString , &fromString) ;
536 #define WX_COLLECTION_TYPE_INFO( element , collection ) \
537 wxCollectionTypeInfo s_typeInfo##collection( typeid(element).name() , NULL , NULL , typeid(collection).name() ) ;
539 // sometimes a compiler invents specializations that are nowhere called, use this macro to satisfy the refs
541 #define WX_ILLEGAL_TYPE_SPECIALIZATION( a )
543 template<> const wxTypeInfo* wxGetTypeInfo( a * ) { assert(0) ; \
544 static wxBuiltInTypeInfo s_typeInfo( wxT_VOID ) ; return &s_typeInfo ; } \
545 template<> void wxStringReadValue(const wxString & , a & ) { assert(0) ; }\
546 template<> void wxStringWriteValue(wxString & , a const & ) { assert(0) ; }
549 // ----------------------------------------------------------------------------
550 // wxxVariant as typesafe data holder
551 // ----------------------------------------------------------------------------
553 class WXDLLIMPEXP_BASE wxxVariantData
556 virtual ~wxxVariantData() {}
558 // return a heap allocated duplicate
559 virtual wxxVariantData
* Clone() const = 0 ;
561 // returns the type info of the contentc
562 virtual const wxTypeInfo
* GetTypeInfo() const = 0 ;
565 template<typename T
> class wxxVariantDataT
: public wxxVariantData
568 wxxVariantDataT(const T
& d
) : m_data(d
) {}
569 virtual ~wxxVariantDataT() {}
571 // get a ref to the stored data
572 T
& Get() { return m_data
; }
574 // get a const ref to the stored data
575 const T
& Get() const { return m_data
; }
578 void Set(const T
& d
) { m_data
= d
; }
580 // return a heap allocated duplicate
581 virtual wxxVariantData
* Clone() const { return new wxxVariantDataT
<T
>( Get() ) ; }
583 // returns the type info of the contentc
584 virtual const wxTypeInfo
* GetTypeInfo() const { return wxGetTypeInfo( (T
*) NULL
) ; }
590 class WXDLLIMPEXP_BASE wxxVariant
593 wxxVariant() { m_data
= NULL
; }
594 wxxVariant( wxxVariantData
* data
, const wxString
& name
= wxT("") ) : m_data(data
) , m_name(name
) {}
595 wxxVariant( const wxxVariant
&d
) { if ( d
.m_data
) m_data
= d
.m_data
->Clone() ; else m_data
= NULL
; m_name
= d
.m_name
; }
597 template<typename T
> wxxVariant( const T
& data
, const wxString
& name
= wxT("") ) :
598 m_data(new wxxVariantDataT
<T
>(data
) ), m_name(name
) {}
600 ~wxxVariant() { delete m_data
; }
602 // get a ref to the stored data
603 template<typename T
> T
& Get(WX_TEMPLATED_MEMBER_FIX(T
))
605 wxxVariantDataT
<T
> *dataptr
= dynamic_cast<wxxVariantDataT
<T
>*> (m_data
) ;
606 wxASSERT_MSG( dataptr
, wxT("Cast not possible") ) ;
607 return dataptr
->Get() ;
610 // get a ref to the stored data
611 template<typename T
> const T
& Get(WX_TEMPLATED_MEMBER_FIX(T
)) const
613 const wxxVariantDataT
<T
> *dataptr
= dynamic_cast<const wxxVariantDataT
<T
>*> (m_data
) ;
614 wxASSERT_MSG( dataptr
, wxT("Cast not possible") ) ;
615 return dataptr
->Get() ;
618 bool IsEmpty() const { return m_data
== NULL
; }
620 template<typename T
> bool HasData() const
622 const wxxVariantDataT
<T
> *dataptr
= dynamic_cast<const wxxVariantDataT
<T
>*> (m_data
) ;
623 return dataptr
!= NULL
;
627 template<typename T
> void Set(const T
& data
) const
630 m_data
= new wxxVariantDataT
<T
>(data
) ;
633 wxxVariant
& operator=(const wxxVariant
&d
)
635 m_data
= d
.m_data
->Clone() ;
640 // gets the stored data casted to a wxObject* , returning NULL if cast is not possible
641 wxObject
* GetAsObject() ;
643 // get the typeinfo of the stored object
644 const wxTypeInfo
* GetTypeInfo() const { return m_data
->GetTypeInfo() ; }
646 // returns this value as string
647 wxString
GetAsString() const
650 GetTypeInfo()->ConvertToString( *this , s
) ;
653 const wxString
& GetName() const { return m_name
; }
655 wxxVariantData
* m_data
;
659 #include <wx/dynarray.h>
661 WX_DECLARE_OBJARRAY_WITH_DECL(wxxVariant
, wxxVariantArray
, class WXDLLIMPEXP_BASE
);
663 // templated streaming, every type must have their specialization for these methods
666 void wxStringReadValue( const wxString
&s
, T
&data
);
669 void wxStringWriteValue( wxString
&s
, const T
&data
);
672 void wxToStringConverter( const wxxVariant
&v
, wxString
&s
) { wxStringWriteValue( s
, v
.WX_TEMPLATED_MEMBER_CALL(Get
, T
) ) ; }
675 void wxFromStringConverter( const wxString
&s
, wxxVariant
&v
) { T d
; wxStringReadValue( s
, d
) ; v
= wxxVariant(d
) ; } \
677 // ----------------------------------------------------------------------------
680 // wxPropertyInfo is used to inquire of the property by name. It doesn't
681 // provide access to the property, only information about it. If you
682 // want access, look at wxPropertyAccessor.
683 // ----------------------------------------------------------------------------
685 class WXDLLIMPEXP_BASE wxSetter
688 wxSetter( const wxString name
) { m_name
= name
; }
689 virtual ~wxSetter() {}
690 virtual void Set( wxObject
*object
, const wxxVariant
&variantValue
) const = 0;
691 const wxString
& GetName() const { return m_name
; }
696 class WXDLLIMPEXP_BASE wxGetter
699 wxGetter( const wxString name
) { m_name
= name
; }
700 virtual ~wxGetter() {}
701 virtual void Get( const wxObject
*object
, wxxVariant
& result
) const = 0;
702 const wxString
& GetName() const { return m_name
; }
707 class WXDLLIMPEXP_BASE wxCollectionGetter
710 wxCollectionGetter( const wxString name
) { m_name
= name
; }
711 virtual ~wxCollectionGetter() {}
712 virtual void Get( const wxObject
*object
, wxxVariantArray
& result
) const = 0;
713 const wxString
& GetName() const { return m_name
; }
718 template<typename coll_t
> void wxCollectionToVariantArray( const coll_t
& coll
, wxxVariantArray
& result
) ;
720 class WXDLLIMPEXP_BASE wxAdder
723 wxAdder( const wxString name
) { m_name
= name
; }
724 virtual ~wxAdder() {}
725 virtual void Add( wxObject
*object
, const wxxVariant
&variantValue
) const= 0;
726 const wxString
& GetName() const { return m_name
; }
733 #define WX_SETTER( property, Klass, valueType, setterMethod ) \
734 class wxSetter##property : public wxSetter \
737 wxSetter##property() : wxSetter( wxT(#setterMethod) ) {} \
738 ~wxSetter##property() {} \
739 void Set( wxObject *object, const wxxVariant &variantValue ) const \
741 Klass *obj = dynamic_cast<Klass*>(object) ; \
742 if ( variantValue.HasData<valueType>() ) \
743 obj->setterMethod(variantValue.Get<valueType>()) ; \
745 obj->setterMethod(*variantValue.Get<valueType*>()) ; \
749 #define WX_GETTER( property, Klass, valueType , gettermethod ) \
750 class wxGetter##property : public wxGetter \
753 wxGetter##property() : wxGetter( wxT(#gettermethod) ) {} \
754 ~wxGetter##property() {} \
755 void Get( const wxObject *object , wxxVariant &result) const \
757 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
758 result = wxxVariant( obj->gettermethod() ) ; \
762 #define WX_ADDER( property, Klass, valueType , addermethod ) \
763 class wxAdder##property : public wxAdder \
766 wxAdder##property() : wxAdder( wxT(#addermethod) ) {} \
767 ~wxAdder##property() {} \
768 void Add( wxObject *object, const wxxVariant &variantValue ) const \
770 Klass *obj = dynamic_cast<Klass*>(object) ; \
771 if ( variantValue.HasData<valueType>() ) \
772 obj->addermethod(variantValue.Get<valueType>()) ; \
774 obj->addermethod(*variantValue.Get<valueType*>()) ; \
778 #define WX_COLLECTION_GETTER( property, Klass, valueType , gettermethod ) \
779 class wxCollectionGetter##property : public wxCollectionGetter \
782 wxCollectionGetter##property() : wxCollectionGetter( wxT(#gettermethod) ) {} \
783 ~wxCollectionGetter##property() {} \
784 void Get( const wxObject *object , wxxVariantArray &result) const \
786 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
787 wxCollectionToVariantArray( obj->gettermethod() , result ) ; \
791 class WXDLLIMPEXP_BASE wxPropertyAccessor
794 wxPropertyAccessor( wxSetter
*setter
, wxGetter
*getter
, wxAdder
*adder
, wxCollectionGetter
*collectionGetter
)
795 { m_setter
= setter
; m_getter
= getter
; m_adder
= adder
; m_collectionGetter
= collectionGetter
;}
797 virtual ~wxPropertyAccessor() {}
799 // Setting a simple property (non-collection)
800 virtual void SetProperty(wxObject
*object
, const wxxVariant
&value
) const
801 { wxASSERT_MSG(m_setter
,wxT("SetProperty called w/o valid setter") ) ; m_setter
->Set( object
, value
) ;}
803 // Getting a simple property (non-collection)
804 virtual void GetProperty(const wxObject
*object
, wxxVariant
&result
) const
805 { wxASSERT_MSG(m_getter
,wxT("GetProperty called w/o valid getter") ) ; m_getter
->Get( object
, result
) ;}
807 // Adding an element to a collection property
808 virtual void AddToPropertyCollection(wxObject
*object
, const wxxVariant
&value
) const
809 { wxASSERT_MSG(m_adder
,wxT("AddToPropertyCollection called w/o valid adder") ) ; m_adder
->Add( object
, value
) ;}
811 // Getting a collection property
812 virtual void GetPropertyCollection( const wxObject
*obj
, wxxVariantArray
&result
) const
813 { wxASSERT_MSG(m_collectionGetter
,wxT("GetPropertyCollection called w/o valid collection getter") ) ; m_collectionGetter
->Get( obj
, result
) ;}
815 virtual bool HasSetter() const { return m_setter
!= NULL
; }
816 virtual bool HasCollectionGetter() const { return m_collectionGetter
!= NULL
; }
817 virtual bool HasGetter() const { return m_getter
!= NULL
; }
818 virtual bool HasAdder() const { return m_adder
!= NULL
; }
820 virtual const wxString
& GetCollectionGetterName() const
821 { return m_collectionGetter
->GetName() ; }
822 virtual const wxString
& GetGetterName() const
823 { return m_getter
->GetName() ; }
824 virtual const wxString
& GetSetterName() const
825 { return m_setter
->GetName() ; }
826 virtual const wxString
& GetAdderName() const
827 { return m_adder
->GetName() ; }
833 wxCollectionGetter
* m_collectionGetter
;
836 class WXDLLIMPEXP_BASE wxGenericPropertyAccessor
: public wxPropertyAccessor
839 wxGenericPropertyAccessor( const wxString
&propName
) ;
840 ~wxGenericPropertyAccessor() ;
842 void RenameProperty( const wxString
&oldName
, const wxString
&newName
)
844 wxASSERT( oldName
== m_propertyName
) ; m_propertyName
= newName
;
846 virtual bool HasSetter() const { return true ; }
847 virtual bool HasGetter() const { return true ; }
848 virtual bool HasAdder() const { return false ; }
849 virtual bool HasCollectionGetter() const { return false ; }
851 virtual const wxString
& GetGetterName() const
852 { return m_getterName
; }
853 virtual const wxString
& GetSetterName() const
854 { return m_setterName
; }
856 virtual void SetProperty(wxObject
*object
, const wxxVariant
&value
) const ;
857 virtual void GetProperty(const wxObject
*object
, wxxVariant
&value
) const ;
859 // Adding an element to a collection property
860 virtual void AddToPropertyCollection(wxObject
*WXUNUSED(object
), const wxxVariant
&WXUNUSED(value
)) const
861 { wxASSERT_MSG(0,wxT("AddToPropertyCollection called on a generic accessor") ) ;}
863 // Getting a collection property
864 virtual void GetPropertyCollection( const wxObject
*WXUNUSED(obj
), wxxVariantArray
&WXUNUSED(result
)) const
865 { wxASSERT_MSG(0,wxT("GetPropertyCollection called on a generic accessor") ) ;}
867 struct wxGenericPropertyAccessorInternal
;
868 wxGenericPropertyAccessorInternal
* m_data
;
869 wxString m_propertyName
;
870 wxString m_setterName
;
871 wxString m_getterName
;
874 typedef long wxPropertyInfoFlags
;
876 // will be removed in future releases
877 wxPROP_DEPRECATED
= 0x00000001 ,
878 // object graph property, will be streamed with priority (after constructor properties)
879 wxPROP_OBJECT_GRAPH
= 0x00000002 ,
880 // this will only be streamed out and in as enum/set, the internal representation is still a long
881 wxPROP_ENUM_STORE_LONG
= 0x00000004 ,
882 // don't stream out this property, needed eg to avoid streaming out children that are always created by their parents
883 wxPROP_DONT_STREAM
= 0x00000008 ,
886 class WXDLLIMPEXP_BASE wxPropertyInfo
888 friend class WXDLLIMPEXP_BASE wxDynamicClassInfo
;
890 wxPropertyInfo(wxPropertyInfo
* &iter
,
891 wxClassInfo
* itsClass
,
892 const wxString
& name
,
893 const wxString
& typeName
,
894 wxPropertyAccessor
*accessor
,
896 wxPropertyInfoFlags flags
= 0,
897 const wxString
& helpString
= wxEmptyString
,
898 const wxString
& groupString
= wxEmptyString
) :
899 m_itsClass(itsClass
),
902 m_typeName(typeName
) ,
903 m_collectionElementTypeInfo(NULL
),
904 m_accessor(accessor
),
907 m_helpString(helpString
),
908 m_groupString(groupString
)
914 wxPropertyInfo(wxPropertyInfo
* &iter
,
915 wxClassInfo
* itsClass
,
916 const wxString
& name
,
917 const char* typeName
,
918 wxPropertyAccessor
*accessor
,
920 wxPropertyInfoFlags flags
= 0,
921 const wxString
& helpString
= wxEmptyString
,
922 const wxString
& groupString
= wxEmptyString
) :
923 m_itsClass(itsClass
),
926 m_typeName(wxString::FromAscii(typeName
)) ,
927 m_collectionElementTypeInfo(NULL
),
928 m_accessor(accessor
),
931 m_helpString(helpString
),
932 m_groupString(groupString
)
937 wxPropertyInfo(wxPropertyInfo
* &iter
,
938 wxClassInfo
* itsClass
,
939 const wxString
& name
,
940 wxDelegateTypeInfo
* type
,
941 wxPropertyAccessor
*accessor
,
943 wxPropertyInfoFlags flags
= 0,
944 const wxString
& helpString
= wxEmptyString
,
945 const wxString
& groupString
= wxEmptyString
) :
946 m_itsClass(itsClass
),
949 m_collectionElementTypeInfo(NULL
),
950 m_accessor(accessor
),
953 m_helpString(helpString
),
954 m_groupString(groupString
)
959 wxPropertyInfo(wxPropertyInfo
* &iter
,
960 wxClassInfo
* itsClass
, const wxString
& name
,
961 const wxString
& collectionTypeName
,
962 const wxString
& elementTypeName
,
963 wxPropertyAccessor
*accessor
,
964 wxPropertyInfoFlags flags
= 0,
965 const wxString
& helpString
= wxEmptyString
,
966 const wxString
& groupString
= wxEmptyString
) :
967 m_itsClass(itsClass
),
970 m_typeName(collectionTypeName
) ,
971 m_collectionElementTypeInfo(NULL
),
972 m_collectionElementTypeName(elementTypeName
),
973 m_accessor(accessor
) ,
975 m_helpString(helpString
),
976 m_groupString(groupString
)
982 wxPropertyInfo(wxPropertyInfo
* &iter
,
983 wxClassInfo
* itsClass
, const wxString
& name
,
984 const char* collectionTypeName
,
985 const char* elementTypeName
,
986 wxPropertyAccessor
*accessor
,
987 wxPropertyInfoFlags flags
= 0,
988 const wxString
& helpString
= wxEmptyString
,
989 const wxString
& groupString
= wxEmptyString
) :
990 m_itsClass(itsClass
),
993 m_typeName(wxString::FromAscii(collectionTypeName
)) ,
994 m_collectionElementTypeInfo(NULL
),
995 m_collectionElementTypeName(wxString::FromAscii(elementTypeName
)),
996 m_accessor(accessor
) ,
998 m_helpString(helpString
),
999 m_groupString(groupString
)
1006 // return the class this property is declared in
1007 const wxClassInfo
* GetDeclaringClass() const { return m_itsClass
; }
1009 // return the name of this property
1010 const wxString
& GetName() const { return m_name
; }
1012 // returns the flags of this property
1013 wxPropertyInfoFlags
GetFlags() const { return m_flags
;}
1015 // returns the short help string of this property
1016 const wxString
& GetHelpString() const { return m_helpString
; }
1018 // returns the group string of this property
1019 const wxString
& GetGroupString() const { return m_groupString
; }
1021 // return the element type info of this property (for collections, otherwise NULL)
1022 const wxTypeInfo
* GetCollectionElementTypeInfo() const
1024 if ( m_collectionElementTypeInfo
== NULL
)
1025 m_collectionElementTypeInfo
= wxTypeInfo::FindType(m_collectionElementTypeName
) ;
1026 return m_collectionElementTypeInfo
;
1029 // return the type info of this property
1030 const wxTypeInfo
* GetTypeInfo() const
1032 if ( m_typeInfo
== NULL
)
1033 m_typeInfo
= wxTypeInfo::FindType(m_typeName
) ;
1037 // return the accessor for this property
1038 wxPropertyAccessor
* GetAccessor() const { return m_accessor
; }
1040 // returns NULL if this is the last property of this class
1041 wxPropertyInfo
* GetNext() const { return m_next
; }
1043 // returns the default value of this property, its kind may be wxT_VOID if it is not valid
1044 wxxVariant
GetDefaultValue() const { return m_defaultValue
; }
1046 void Insert(wxPropertyInfo
* &iter
)
1053 wxPropertyInfo
* i
= iter
;
1061 wxClassInfo
* m_itsClass
;
1063 mutable wxTypeInfo
* m_typeInfo
;
1064 wxString m_typeName
;
1065 mutable wxTypeInfo
* m_collectionElementTypeInfo
;
1066 wxString m_collectionElementTypeName
;
1067 wxPropertyAccessor
* m_accessor
;
1068 wxxVariant m_defaultValue
;
1069 wxPropertyInfoFlags m_flags
;
1070 wxString m_helpString
;
1071 wxString m_groupString
;
1072 // string representation of the default value
1073 // to be assigned by the designer to the property
1074 // when the component is dropped on the container.
1075 wxPropertyInfo
* m_next
;
1078 WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxPropertyInfo
* , wxPropertyInfoMap
, class WXDLLIMPEXP_BASE
) ;
1080 #define WX_BEGIN_PROPERTIES_TABLE(theClass) \
1081 wxPropertyInfo *theClass::GetPropertiesStatic() \
1083 typedef theClass class_t; \
1084 static wxPropertyInfo* first = NULL ;
1086 #define WX_END_PROPERTIES_TABLE() \
1089 #define WX_HIDE_PROPERTY( pname ) \
1090 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(void).name() ,NULL , wxxVariant() , wxPROP_DONT_STREAM , wxEmptyString , wxEmptyString ) ;
1092 #define WX_PROPERTY( pname , type , setter , getter ,defaultValue , flags , help , group) \
1093 WX_SETTER( pname , class_t , type , setter ) \
1094 static wxSetter##pname _setter##pname ; \
1095 WX_GETTER( pname , class_t , type , getter ) \
1096 static wxGetter##pname _getter##pname ; \
1097 static wxPropertyAccessor _accessor##pname( &_setter##pname , &_getter##pname , NULL , NULL ) ; \
1098 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(type).name() ,&_accessor##pname , wxxVariant(defaultValue) , flags , group , help ) ;
1100 #define WX_PROPERTY_FLAGS( pname , flags , type , setter , getter ,defaultValue , pflags , help , group) \
1101 WX_SETTER( pname , class_t , type , setter ) \
1102 static wxSetter##pname _setter##pname ; \
1103 WX_GETTER( pname , class_t , type , getter ) \
1104 static wxGetter##pname _getter##pname ; \
1105 static wxPropertyAccessor _accessor##pname( &_setter##pname , &_getter##pname , NULL , NULL ) ; \
1106 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(flags).name() ,&_accessor##pname , wxxVariant(defaultValue), wxPROP_ENUM_STORE_LONG | pflags , help , group ) ;
1108 #define WX_READONLY_PROPERTY( pname , type , getter ,defaultValue , flags , help , group) \
1109 WX_GETTER( pname , class_t , type , getter ) \
1110 static wxGetter##pname _getter##pname ; \
1111 static wxPropertyAccessor _accessor##pname( NULL , &_getter##pname , NULL , NULL ) ; \
1112 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(type).name() ,&_accessor##pname , wxxVariant(defaultValue), flags , help , group ) ;
1114 #define WX_READONLY_PROPERTY_FLAGS( pname , flags , type , getter ,defaultValue , pflags , help , group) \
1115 WX_GETTER( pname , class_t , type , getter ) \
1116 static wxGetter##pname _getter##pname ; \
1117 static wxPropertyAccessor _accessor##pname( NULL , &_getter##pname , NULL , NULL ) ; \
1118 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(flags).name() ,&_accessor##pname , wxxVariant(defaultValue), wxPROP_ENUM_STORE_LONG | pflags , help , group ) ;
1120 #define WX_PROPERTY_COLLECTION( pname , colltype , addelemtype , adder , getter , flags , help , group ) \
1121 WX_ADDER( pname , class_t , addelemtype , adder ) \
1122 static wxAdder##pname _adder##pname ; \
1123 WX_COLLECTION_GETTER( pname , class_t , colltype , getter ) \
1124 static wxCollectionGetter##pname _collectionGetter##pname ; \
1125 static wxPropertyAccessor _accessor##pname( NULL , NULL ,&_adder##pname , &_collectionGetter##pname ) ; \
1126 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(colltype).name() ,typeid(addelemtype).name() ,&_accessor##pname , flags , help , group ) ;
1128 #define WX_READONLY_PROPERTY_COLLECTION( pname , colltype , addelemtype , getter , flags , help , group) \
1129 WX_COLLECTION_GETTER( pname , class_t , colltype , getter ) \
1130 static wxCollectionGetter##pname _collectionGetter##pname ; \
1131 static wxPropertyAccessor _accessor##pname( NULL , NULL , NULL , &_collectionGetter##pname ) ; \
1132 static wxPropertyInfo _propertyInfo##pname( first ,class_t::GetClassInfoStatic() , wxT(#pname) , typeid(colltype).name() ,typeid(addelemtype).name() ,&_accessor##pname , flags , help , group ) ;
1135 #define WX_EVENT_PROPERTY( name , eventType , eventClass ) \
1136 static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \
1137 static wxPropertyInfo _propertyInfo##name( first ,class_t::GetClassInfoStatic() , wxT(#name) , &_typeInfo##name , NULL , wxxVariant() ) ; \
1139 #define WX_EVENT_RANGE_PROPERTY( name , eventType , lastEventType , eventClass ) \
1140 static wxDelegateTypeInfo _typeInfo##name( eventType , lastEventType , CLASSINFO( eventClass ) ) ; \
1141 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , wxT(#name) , &_typeInfo##name , NULL , wxxVariant() ) ; \
1143 // ----------------------------------------------------------------------------
1144 // Implementation Helper for Simple Properties
1145 // ----------------------------------------------------------------------------
1147 #define WX_IMPLEMENT_PROPERTY(name, type) \
1151 void Set##name( type const & p) { m_##name = p; } \
1152 type const & Get##name() const { return m_##name; }
1154 // ----------------------------------------------------------------------------
1157 // this is describing an event sink
1158 // ----------------------------------------------------------------------------
1160 class WXDLLIMPEXP_BASE wxHandlerInfo
1162 friend class WXDLLIMPEXP_BASE wxDynamicClassInfo
;
1164 wxHandlerInfo(wxHandlerInfo
* &iter
,
1165 wxClassInfo
* itsClass
,
1166 const wxString
& name
,
1167 wxObjectEventFunction address
,
1168 const wxClassInfo
* eventClassInfo
) :
1169 m_eventFunction(address
),
1171 m_eventClassInfo(eventClassInfo
) ,
1172 m_itsClass(itsClass
)
1179 wxHandlerInfo
* i
= iter
;
1189 // return the name of this handler
1190 const wxString
& GetName() const { return m_name
; }
1192 // return the class info of the event
1193 const wxClassInfo
* GetEventClassInfo() const { return m_eventClassInfo
; }
1195 // get the handler function pointer
1196 wxObjectEventFunction
GetEventFunction() const { return m_eventFunction
; }
1198 // returns NULL if this is the last handler of this class
1199 wxHandlerInfo
* GetNext() const { return m_next
; }
1201 // return the class this property is declared in
1202 const wxClassInfo
* GetDeclaringClass() const { return m_itsClass
; }
1205 wxObjectEventFunction m_eventFunction
;
1207 const wxClassInfo
* m_eventClassInfo
;
1208 wxHandlerInfo
* m_next
;
1209 wxClassInfo
* m_itsClass
;
1212 #define WX_HANDLER(name,eventClassType) \
1213 static wxHandlerInfo _handlerInfo##name( first , class_t::GetClassInfoStatic() , #name , (wxObjectEventFunction) (wxEventFunction) &name , CLASSINFO( eventClassType ) ) ;
1215 #define WX_BEGIN_HANDLERS_TABLE(theClass) \
1216 wxHandlerInfo *theClass::GetHandlersStatic() \
1218 typedef theClass class_t; \
1219 static wxHandlerInfo* first = NULL ;
1221 #define WX_END_HANDLERS_TABLE() \
1224 // ----------------------------------------------------------------------------
1225 // Constructor Bridges
1227 // allow to set up constructors with params during runtime
1228 // ----------------------------------------------------------------------------
1230 class WXDLLIMPEXP_BASE wxConstructorBridge
1233 virtual void Create(wxObject
* &o
, wxxVariant
*args
) = 0;
1236 // a direct constructor bridge calls the operator new for this class and
1237 // passes all params to the constructor. needed for classes that cannot be
1238 // instantiated using alloc-create semantics
1239 class WXDLLIMPEXP_BASE wxDirectConstructorBrigde
: public wxConstructorBridge
1242 virtual void Create(wxObject
* &o
, wxxVariant
*args
) = 0;
1245 // Creator Bridges for all Numbers of Params
1249 template<typename Class
>
1250 struct wxConstructorBridge_0
: public wxConstructorBridge
1252 void Create(wxObject
* &o
, wxxVariant
*)
1254 Class
*obj
= dynamic_cast<Class
*>(o
);
1259 struct wxConstructorBridge_Dummy
: public wxConstructorBridge
1261 void Create(wxObject
*&, wxxVariant
*)
1266 #define WX_CONSTRUCTOR_0(klass) \
1267 wxConstructorBridge_0<klass> constructor##klass ; \
1268 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1269 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
1270 const int klass::sm_constructorPropertiesCount##klass = 0 ;
1272 #define WX_CONSTRUCTOR_DUMMY(klass) \
1273 wxConstructorBridge_Dummy constructor##klass ; \
1274 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1275 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
1276 const int klass::sm_constructorPropertiesCount##klass = 0 ;
1280 template<typename Class
, typename T0
>
1281 struct wxConstructorBridge_1
: public wxConstructorBridge
1283 void Create(wxObject
* &o
, wxxVariant
*args
)
1285 Class
*obj
= dynamic_cast<Class
*>(o
);
1287 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
)
1292 #define WX_CONSTRUCTOR_1(klass,t0,v0) \
1293 wxConstructorBridge_1<klass,t0> constructor##klass ; \
1294 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1295 const wxChar *klass::sm_constructorProperties##klass[] = { wxT(#v0) } ; \
1296 const int klass::sm_constructorPropertiesCount##klass = 1 ;
1300 template<typename Class
,
1301 typename T0
, typename T1
>
1302 struct wxConstructorBridge_2
: 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
)
1314 #define WX_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
1315 wxConstructorBridge_2<klass,t0,t1> constructor##klass ; \
1316 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1317 const wxChar *klass::sm_constructorProperties##klass[] = { wxT(#v0) , wxT(#v1) } ; \
1318 const int klass::sm_constructorPropertiesCount##klass = 2;
1320 // direct constructor version
1322 template<typename Class
,
1323 typename T0
, typename T1
>
1324 struct wxDirectConstructorBridge_2
: public wxDirectConstructorBrigde
1326 void Create(wxObject
* &o
, wxxVariant
*args
)
1329 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1330 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
)
1335 #define WX_DIRECT_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
1336 wxDirectConstructorBridge_2<klass,t0,t1> constructor##klass ; \
1337 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1338 const wxChar *klass::sm_constructorProperties##klass[] = { wxT(#v0) , wxT(#v1) } ; \
1339 const int klass::sm_constructorPropertiesCount##klass = 2;
1344 template<typename Class
,
1345 typename T0
, typename T1
, typename T2
>
1346 struct wxConstructorBridge_3
: public wxConstructorBridge
1348 void Create(wxObject
* &o
, wxxVariant
*args
)
1350 Class
*obj
= dynamic_cast<Class
*>(o
);
1352 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1353 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1354 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
)
1359 #define WX_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
1360 wxConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \
1361 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1362 const wxChar *klass::sm_constructorProperties##klass[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) } ; \
1363 const int klass::sm_constructorPropertiesCount##klass = 3 ;
1367 template<typename Class
,
1368 typename T0
, typename T1
, typename T2
, typename T3
>
1369 struct wxConstructorBridge_4
: public wxConstructorBridge
1371 void Create(wxObject
* &o
, wxxVariant
*args
)
1373 Class
*obj
= dynamic_cast<Class
*>(o
);
1375 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1376 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1377 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1378 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
)
1383 #define WX_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
1384 wxConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass ; \
1385 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1386 const wxChar *klass::sm_constructorProperties##klass[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) } ; \
1387 const int klass::sm_constructorPropertiesCount##klass = 4 ;
1391 template<typename Class
,
1392 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
>
1393 struct wxConstructorBridge_5
: public wxConstructorBridge
1395 void Create(wxObject
* &o
, wxxVariant
*args
)
1397 Class
*obj
= dynamic_cast<Class
*>(o
);
1399 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1400 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1401 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1402 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1403 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
)
1408 #define WX_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
1409 wxConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass ; \
1410 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1411 const wxChar *klass::sm_constructorProperties##klass[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) } ; \
1412 const int klass::sm_constructorPropertiesCount##klass = 5;
1416 template<typename Class
,
1417 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
1418 struct wxConstructorBridge_6
: public wxConstructorBridge
1420 void Create(wxObject
* &o
, wxxVariant
*args
)
1422 Class
*obj
= dynamic_cast<Class
*>(o
);
1424 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1425 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1426 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1427 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1428 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
) ,
1429 args
[5].WX_TEMPLATED_MEMBER_CALL(Get
, T5
)
1434 #define WX_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1435 wxConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1436 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1437 const wxChar *klass::sm_constructorProperties##klass[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) } ; \
1438 const int klass::sm_constructorPropertiesCount##klass = 6;
1440 // direct constructor version
1442 template<typename Class
,
1443 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
1444 struct wxDirectConstructorBridge_6
: public wxDirectConstructorBrigde
1446 void Create(wxObject
* &o
, wxxVariant
*args
)
1449 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1450 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1451 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1452 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1453 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
) ,
1454 args
[5].WX_TEMPLATED_MEMBER_CALL(Get
, T5
)
1459 #define WX_DIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1460 wxDirectConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1461 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1462 const wxChar *klass::sm_constructorProperties##klass[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) } ; \
1463 const int klass::sm_constructorPropertiesCount##klass = 6;
1467 template<typename Class
,
1468 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
>
1469 struct wxConstructorBridge_7
: public wxConstructorBridge
1471 void Create(wxObject
* &o
, wxxVariant
*args
)
1473 Class
*obj
= dynamic_cast<Class
*>(o
);
1475 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1476 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1477 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1478 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1479 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
) ,
1480 args
[5].WX_TEMPLATED_MEMBER_CALL(Get
, T5
) ,
1481 args
[6].WX_TEMPLATED_MEMBER_CALL(Get
, T6
)
1486 #define WX_CONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
1487 wxConstructorBridge_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass ; \
1488 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1489 const wxChar *klass::sm_constructorProperties##klass[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) , wxT(#v6) } ; \
1490 const int klass::sm_constructorPropertiesCount##klass = 7;
1494 template<typename Class
,
1495 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
, typename T7
>
1496 struct wxConstructorBridge_8
: public wxConstructorBridge
1498 void Create(wxObject
* &o
, wxxVariant
*args
)
1500 Class
*obj
= dynamic_cast<Class
*>(o
);
1502 args
[0].WX_TEMPLATED_MEMBER_CALL(Get
, T0
) ,
1503 args
[1].WX_TEMPLATED_MEMBER_CALL(Get
, T1
) ,
1504 args
[2].WX_TEMPLATED_MEMBER_CALL(Get
, T2
) ,
1505 args
[3].WX_TEMPLATED_MEMBER_CALL(Get
, T3
) ,
1506 args
[4].WX_TEMPLATED_MEMBER_CALL(Get
, T4
) ,
1507 args
[5].WX_TEMPLATED_MEMBER_CALL(Get
, T5
) ,
1508 args
[6].WX_TEMPLATED_MEMBER_CALL(Get
, T6
) ,
1509 args
[7].WX_TEMPLATED_MEMBER_CALL(Get
, T7
)
1514 #define WX_CONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
1515 wxConstructorBridge_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass ; \
1516 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1517 const wxChar *klass::sm_constructorProperties##klass[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) , wxT(#v6) , wxT(#v7) } ; \
1518 const int klass::sm_constructorPropertiesCount##klass = 8;
1519 // ----------------------------------------------------------------------------
1521 // ----------------------------------------------------------------------------
1523 typedef wxObject
*(*wxObjectConstructorFn
)(void);
1524 typedef wxObject
* (*wxVariantToObjectConverter
)( wxxVariant
&data
) ;
1525 typedef wxxVariant (*wxObjectToVariantConverter
)( wxObject
* ) ;
1527 class WXDLLIMPEXP_BASE wxWriter
;
1528 class WXDLLIMPEXP_BASE wxPersister
;
1530 typedef bool (*wxObjectStreamingCallback
) ( const wxObject
*, wxWriter
* , wxPersister
* , wxxVariantArray
& ) ;
1532 class WXDLLIMPEXP_BASE wxClassInfo
1534 friend class WXDLLIMPEXP_BASE wxPropertyInfo
;
1535 friend class WXDLLIMPEXP_BASE wxHandlerInfo
;
1537 wxClassInfo(const wxClassInfo
**_Parents
,
1538 const wxChar
*_UnitName
,
1539 const wxChar
*_ClassName
,
1541 wxObjectConstructorFn ctor
,
1542 wxPropertyInfo
*_Props
,
1543 wxHandlerInfo
*_Handlers
,
1544 wxConstructorBridge
* _Constructor
,
1545 const wxChar
** _ConstructorProperties
,
1546 const int _ConstructorPropertiesCount
,
1547 wxVariantToObjectConverter _PtrConverter1
,
1548 wxVariantToObjectConverter _Converter2
,
1549 wxObjectToVariantConverter _Converter3
,
1550 wxObjectStreamingCallback _streamingCallback
= NULL
1553 m_className(_ClassName
),
1555 m_objectConstructor(ctor
),
1557 m_firstProperty(_Props
),
1558 m_firstHandler(_Handlers
),
1559 m_parents(_Parents
),
1560 m_unitName(_UnitName
),
1561 m_constructor(_Constructor
),
1562 m_constructorProperties(_ConstructorProperties
),
1563 m_constructorPropertiesCount(_ConstructorPropertiesCount
),
1564 m_variantOfPtrToObjectConverter(_PtrConverter1
),
1565 m_variantToObjectConverter(_Converter2
),
1566 m_objectToVariantConverter(_Converter3
),
1567 m_streamingCallback(_streamingCallback
)
1573 wxClassInfo(const wxChar
*_UnitName
, const wxChar
*_ClassName
,
1574 const wxClassInfo
**_Parents
) :
1575 m_className(_ClassName
),
1577 m_objectConstructor(NULL
),
1579 m_firstProperty(NULL
),
1580 m_firstHandler(NULL
),
1581 m_parents(_Parents
),
1582 m_unitName(_UnitName
),
1583 m_constructor(NULL
),
1584 m_constructorProperties(NULL
),
1585 m_constructorPropertiesCount(0),
1586 m_variantOfPtrToObjectConverter(NULL
),
1587 m_variantToObjectConverter(NULL
),
1588 m_objectToVariantConverter(NULL
),
1589 m_streamingCallback(NULL
)
1595 virtual ~wxClassInfo() ;
1597 // allocates an instance of this class, this object does not have to be initialized or fully constructed
1598 // as this call will be followed by a call to Create
1599 virtual wxObject
*AllocateObject() const { return m_objectConstructor
? (*m_objectConstructor
)() : 0; }
1601 // 'old naming' for AllocateObject staying here for backward compatibility
1602 wxObject
*CreateObject() const { return AllocateObject() ; }
1604 // direct construction call for classes that cannot construct instances via alloc/create
1605 wxObject
*ConstructObject(int ParamCount
, wxxVariant
*Params
) const
1607 wxASSERT_MSG( ParamCount
== m_constructorPropertiesCount
, wxT("Illegal Parameter Count for ConstructObject Method")) ;
1608 wxObject
*object
= NULL
;
1609 m_constructor
->Create( object
, Params
) ;
1613 bool NeedsDirectConstruction() const { return dynamic_cast<wxDirectConstructorBrigde
*>( m_constructor
) != NULL
; }
1615 const wxChar
*GetClassName() const { return m_className
; }
1616 const wxChar
*GetIncludeName() const { return m_unitName
; }
1617 const wxClassInfo
**GetParents() const { return m_parents
; }
1618 int GetSize() const { return m_objectSize
; }
1620 wxObjectConstructorFn
GetConstructor() const { return m_objectConstructor
; }
1621 static const wxClassInfo
*GetFirst() { return sm_first
; }
1622 const wxClassInfo
*GetNext() const { return m_next
; }
1623 static wxClassInfo
*FindClass(const wxChar
*className
);
1625 // Climb upwards through inheritance hierarchy.
1626 // Dual inheritance is catered for.
1628 bool IsKindOf(const wxClassInfo
*info
) const
1635 for ( int i
= 0 ; m_parents
[i
] ; ++ i
)
1637 if ( m_parents
[i
]->IsKindOf( info
) )
1644 // if there is a callback registered with that class it will be called
1645 // before this object will be written to disk, it can veto streaming out
1646 // this object by returning false, if this class has not registered a
1647 // callback, the search will go up the inheritance tree if no callback has
1648 // been registered true will be returned by default
1649 bool BeforeWriteObject( const wxObject
*obj
, wxWriter
*streamer
, wxPersister
*persister
, wxxVariantArray
&metadata
) const ;
1651 // gets the streaming callback from this class or any superclass
1652 wxObjectStreamingCallback
GetStreamingCallback() const ;
1654 #ifdef WXWIN_COMPATIBILITY_2_4
1655 // Initializes parent pointers and hash table for fast searching.
1656 wxDEPRECATED( static void InitializeClasses() );
1657 // Cleans up hash table used for fast searching.
1658 wxDEPRECATED( static void CleanUpClasses() );
1660 static void CleanUp();
1662 // returns the first property
1663 const wxPropertyInfo
* GetFirstProperty() const { return m_firstProperty
; }
1665 // returns the first handler
1666 const wxHandlerInfo
* GetFirstHandler() const { return m_firstHandler
; }
1668 // Call the Create upon an instance of the class, in the end the object is fully
1670 virtual void Create (wxObject
*object
, int ParamCount
, wxxVariant
*Params
) const
1672 wxASSERT_MSG( ParamCount
== m_constructorPropertiesCount
, wxT("Illegal Parameter Count for Create Method")) ;
1673 m_constructor
->Create( object
, Params
) ;
1676 // get number of parameters for constructor
1677 virtual int GetCreateParamCount() const { return m_constructorPropertiesCount
; }
1679 // get n-th constructor parameter
1680 virtual const wxChar
* GetCreateParamName(int n
) const { return m_constructorProperties
[n
] ; }
1682 // Runtime access to objects for simple properties (get/set) by property name, and variant data
1683 virtual void SetProperty (wxObject
*object
, const wxChar
*propertyName
, const wxxVariant
&value
) const ;
1684 virtual wxxVariant
GetProperty (wxObject
*object
, const wxChar
*propertyName
) const;
1686 // Runtime access to objects for collection properties by property name
1687 virtual wxxVariantArray
GetPropertyCollection(wxObject
*object
, const wxChar
*propertyName
) const ;
1688 virtual void AddToPropertyCollection(wxObject
*object
, const wxChar
*propertyName
, const wxxVariant
& value
) const ;
1690 // we must be able to cast variants to wxObject pointers, templates seem not to be suitable
1691 wxObject
* VariantToInstance( wxxVariant
&data
) const
1692 { if ( data
.GetTypeInfo()->GetKind() == wxT_OBJECT
)
1693 return m_variantToObjectConverter( data
) ;
1695 return m_variantOfPtrToObjectConverter( data
) ;
1698 wxxVariant
InstanceToVariant( wxObject
*object
) const { return m_objectToVariantConverter( object
) ; }
1700 // find property by name
1701 virtual const wxPropertyInfo
*FindPropertyInfo (const wxChar
*PropertyName
) const ;
1703 // find handler by name
1704 virtual const wxHandlerInfo
*FindHandlerInfo (const wxChar
*PropertyName
) const ;
1706 // find property by name
1707 virtual wxPropertyInfo
*FindPropertyInfoInThisClass (const wxChar
*PropertyName
) const ;
1709 // find handler by name
1710 virtual wxHandlerInfo
*FindHandlerInfoInThisClass (const wxChar
*PropertyName
) const ;
1712 // puts all the properties of this class and its superclasses in the map, as long as there is not yet
1713 // an entry with the same name (overriding mechanism)
1714 void GetProperties( wxPropertyInfoMap
&map
) const ;
1716 const wxChar
*m_className
;
1718 wxObjectConstructorFn m_objectConstructor
;
1720 // class info object live in a linked list:
1721 // pointers to its head and the next element in it
1723 static wxClassInfo
*sm_first
;
1724 wxClassInfo
*m_next
;
1726 // FIXME: this should be private (currently used directly by way too
1728 static wxHashTable
*sm_classTable
;
1731 wxPropertyInfo
* m_firstProperty
;
1732 wxHandlerInfo
* m_firstHandler
;
1734 const wxClassInfo
** m_parents
;
1735 const wxChar
* m_unitName
;
1737 wxConstructorBridge
* m_constructor
;
1738 const wxChar
** m_constructorProperties
;
1739 const int m_constructorPropertiesCount
;
1740 wxVariantToObjectConverter m_variantOfPtrToObjectConverter
;
1741 wxVariantToObjectConverter m_variantToObjectConverter
;
1742 wxObjectToVariantConverter m_objectToVariantConverter
;
1743 wxObjectStreamingCallback m_streamingCallback
;
1744 const wxPropertyAccessor
*FindAccessor (const wxChar
*propertyName
) const ;
1747 // InitializeClasses() helper
1748 static wxClassInfo
*GetBaseByName(const wxChar
*name
) ;
1751 // registers the class
1755 DECLARE_NO_COPY_CLASS(wxClassInfo
)
1759 WXDLLIMPEXP_BASE wxObject
*wxCreateDynamicObject(const wxChar
*name
);
1761 // ----------------------------------------------------------------------------
1763 // ----------------------------------------------------------------------------
1765 // this object leads to having a pure runtime-instantiation
1767 class WXDLLIMPEXP_BASE wxDynamicClassInfo
: public wxClassInfo
1770 wxDynamicClassInfo( const wxChar
*_UnitName
, const wxChar
*_ClassName
, const wxClassInfo
* superClass
) ;
1771 virtual ~wxDynamicClassInfo() ;
1773 // constructs a wxDynamicObject with an instance
1774 virtual wxObject
*AllocateObject() const ;
1776 // Call the Create method for a class
1777 virtual void Create (wxObject
*object
, int ParamCount
, wxxVariant
*Params
) const ;
1779 // get number of parameters for constructor
1780 virtual int GetCreateParamCount() const ;
1782 // get i-th constructor parameter
1783 virtual const wxChar
* GetCreateParamName(int i
) const ;
1785 // Runtime access to objects by property name, and variant data
1786 virtual void SetProperty (wxObject
*object
, const wxChar
*PropertyName
, const wxxVariant
&Value
) const ;
1787 virtual wxxVariant
GetProperty (wxObject
*object
, const wxChar
*PropertyName
) const ;
1789 // adds a property to this class at runtime
1790 void AddProperty( const wxChar
*propertyName
, const wxTypeInfo
* typeInfo
) ;
1792 // removes an existing runtime-property
1793 void RemoveProperty( const wxChar
*propertyName
) ;
1795 // renames an existing runtime-property
1796 void RenameProperty( const wxChar
*oldPropertyName
, const wxChar
*newPropertyName
) ;
1798 // as a handler to this class at runtime
1799 void AddHandler( const wxChar
*handlerName
, wxObjectEventFunction address
, const wxClassInfo
* eventClassInfo
) ;
1801 // removes an existing runtime-handler
1802 void RemoveHandler( const wxChar
*handlerName
) ;
1804 // renames an existing runtime-handler
1805 void RenameHandler( const wxChar
*oldHandlerName
, const wxChar
*newHandlerName
) ;
1808 // ----------------------------------------------------------------------------
1809 // Dynamic class macros
1810 // ----------------------------------------------------------------------------
1812 #define _DECLARE_DYNAMIC_CLASS(name) \
1814 static wxClassInfo sm_class##name; \
1815 static const wxClassInfo* sm_classParents##name[] ; \
1816 static wxPropertyInfo* GetPropertiesStatic() ; \
1817 static wxHandlerInfo* GetHandlersStatic() ; \
1818 static wxClassInfo *GetClassInfoStatic() \
1819 { return &name::sm_class##name; } \
1820 virtual wxClassInfo *GetClassInfo() const \
1821 { return &name::sm_class##name; }
1823 #define DECLARE_DYNAMIC_CLASS(name) \
1824 static wxConstructorBridge* sm_constructor##name ; \
1825 static const wxChar * sm_constructorProperties##name[] ; \
1826 static const int sm_constructorPropertiesCount##name ; \
1827 _DECLARE_DYNAMIC_CLASS(name)
1829 #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
1830 DECLARE_NO_ASSIGN_CLASS(name) \
1831 DECLARE_DYNAMIC_CLASS(name)
1833 #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \
1834 DECLARE_NO_COPY_CLASS(name) \
1835 DECLARE_DYNAMIC_CLASS(name)
1837 #define DECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name)
1838 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
1840 // -----------------------------------
1841 // for concrete classes
1842 // -----------------------------------
1844 // Single inheritance with one base class
1846 #define _TYPEINFO_CLASSES(n , toString , fromString ) \
1847 wxClassTypeInfo s_typeInfo##n(wxT_OBJECT , &n::sm_class##n , toString , fromString , typeid(n).name()) ; \
1848 wxClassTypeInfo s_typeInfoPtr##n(wxT_OBJECT_PTR , &n::sm_class##n , toString , fromString , typeid(n*).name()) ;
1850 #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit , callback) \
1851 wxObject* wxConstructorFor##name() \
1852 { return new name; } \
1853 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1854 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1855 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1856 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1857 (int) sizeof(name), \
1858 (wxObjectConstructorFn) wxConstructorFor##name , \
1859 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1860 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name , callback);
1862 #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \
1863 wxObject* wxConstructorFor##name() \
1864 { return new name; } \
1865 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1866 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return &data.Get<name>() ; } \
1867 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1868 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1869 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1870 (int) sizeof(name), \
1871 (wxObjectConstructorFn) wxConstructorFor##name , \
1872 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1873 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name, callback);
1875 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \
1876 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" , NULL ) \
1877 _TYPEINFO_CLASSES(name, NULL , NULL) \
1878 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1879 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1880 WX_CONSTRUCTOR_DUMMY( name )
1882 #define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \
1883 _IMPLEMENT_DYNAMIC_CLASS( name , basename , "" , NULL ) \
1884 _TYPEINFO_CLASSES(name, NULL , NULL) \
1885 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1886 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1887 WX_CONSTRUCTOR_DUMMY( name )
1889 #define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \
1890 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , NULL ) \
1891 _TYPEINFO_CLASSES(name, NULL , NULL)
1893 #define IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name , basename , unit , callback ) \
1894 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , &callback ) \
1895 _TYPEINFO_CLASSES(name, NULL , NULL)
1897 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \
1898 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit , NULL ) \
1899 _TYPEINFO_CLASSES(name, NULL , NULL)
1901 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name , basename , unit , toString , fromString ) \
1902 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit , NULL ) \
1903 _TYPEINFO_CLASSES(name, toString , fromString)
1905 // this is for classes that do not derive from wxobject, there are no creators for these
1907 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name , unit ) \
1908 const wxClassInfo* name::sm_classParents##name[] = { NULL } ; \
1909 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1910 (int) sizeof(name), \
1911 (wxObjectConstructorFn) 0 , \
1912 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1914 _TYPEINFO_CLASSES(name, NULL , NULL)
1916 // this is for subclasses that still do not derive from wxobject
1918 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name , basename, unit ) \
1919 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1920 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1921 (int) sizeof(name), \
1922 (wxObjectConstructorFn) 0 , \
1923 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1925 _TYPEINFO_CLASSES(name, NULL , NULL)
1928 // Multiple inheritance with two base classes
1930 #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit) \
1931 wxObject* wxConstructorFor##name() \
1932 { return new name; } \
1933 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,&basename2::sm_class##basename2 , NULL } ; \
1934 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1935 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1936 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1937 (int) sizeof(name), \
1938 (wxObjectConstructorFn) wxConstructorFor##name , \
1939 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1940 name::sm_constructorPropertiesCount##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1942 #define IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2) \
1943 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , "") \
1944 _TYPEINFO_CLASSES(name, NULL , NULL) \
1945 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1946 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1947 WX_CONSTRUCTOR_DUMMY( name )
1949 #define IMPLEMENT_DYNAMIC_CLASS2_XTI( name , basename , basename2, unit) \
1950 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , unit) \
1951 _TYPEINFO_CLASSES(name, NULL , NULL)
1954 // -----------------------------------
1955 // for abstract classes
1956 // -----------------------------------
1958 // Single inheritance with one base class
1960 #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
1961 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1962 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1963 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1964 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1965 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1966 (int) sizeof(name), \
1967 (wxObjectConstructorFn) 0 , \
1968 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1969 0 , wxVariantOfPtrToObjectConverter##name ,wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1970 _TYPEINFO_CLASSES(name, NULL , NULL)
1972 #define IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1973 _IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1974 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1975 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; }
1977 // Multiple inheritance with two base classes
1979 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
1980 wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \
1981 wxT(#basename2), (int) sizeof(name), \
1982 (wxObjectConstructorFn) 0);
1984 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
1985 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
1987 // --------------------------------------------------------------------------
1988 // Collection Support
1989 // --------------------------------------------------------------------------
1991 template<typename iter
, typename collection_t
> void wxListCollectionToVariantArray( const collection_t
& coll
, wxxVariantArray
&value
)
1993 iter current
= coll
.GetFirst() ;
1996 value
.Add( new wxxVariant(current
->GetData()) ) ;
1997 current
= current
->GetNext();
2001 template<typename collection_t
> void wxArrayCollectionToVariantArray( const collection_t
& coll
, wxxVariantArray
&value
)
2003 for( size_t i
= 0 ; i
< coll
.GetCount() ; i
++ )
2005 value
.Add( new wxxVariant(coll
[i
]) ) ;