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 // We want to support properties, event sources and events sinks through
17 // explicit declarations, using templates and specialization to make the
18 // effort as painless as possible.
20 // This means we have the following domains :
22 // - Type Information for categorizing built in types as well as custom types
23 // this includes information about enums, their values and names
24 // - Type safe value storage : a kind of wxVariant, called right now wxxVariant
25 // which will be merged with wxVariant
26 // - Property Information and Property Accessors providing access to a class'
27 // values and exposed event delegates
28 // - Information about event handlers
29 // - extended Class Information for accessing all these
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
36 #include "wx/memory.h"
38 #include "wx/string.h"
39 #include "wx/arrstr.h"
40 #include "wx/hashmap.h"
46 // we will move this later to defs.h
48 #if defined(__GNUC__) && !wxCHECK_GCC_VERSION( 3 , 4 )
49 # define wxUSE_MEMBER_TEMPLATES 0
52 #if defined(_MSC_VER) && _MSC_VER <= 1200
53 # define wxUSE_MEMBER_TEMPLATES 0
54 # define wxUSE_FUNC_TEMPLATE_POINTER 0
57 #ifndef wxUSE_MEMBER_TEMPLATES
58 # define wxUSE_MEMBER_TEMPLATES 1
61 #ifndef wxUSE_FUNC_TEMPLATE_POINTER
62 # define wxUSE_FUNC_TEMPLATE_POINTER 1
65 #if wxUSE_MEMBER_TEMPLATES
66 # define wxTEMPLATED_MEMBER_CALL( method , type ) method<type>()
67 # define wxTEMPLATED_MEMBER_FIX( type )
69 # define wxTEMPLATED_MEMBER_CALL( method , type ) method((type*)NULL)
70 # define wxTEMPLATED_MEMBER_FIX( type ) type* =NULL
73 #if defined(_MSC_VER) && _MSC_VER <= 1200
74 # define wxTEMPLATED_FUNCTION_FIX( type ) , wxTEMPLATED_MEMBER_FIX(type)
75 # define wxINFUNC_CLASS_TYPE_FIX( type ) typedef type type;
77 # define wxTEMPLATED_FUNCTION_FIX( type )
78 # define wxINFUNC_CLASS_TYPE_FIX( type )
81 #define EMPTY_MACROVALUE /**/
83 class WXDLLIMPEXP_BASE wxObject
;
84 class WXDLLIMPEXP_BASE wxClassInfo
;
85 class WXDLLIMPEXP_BASE wxDynamicClassInfo
;
86 class WXDLLIMPEXP_BASE wxHashTable
;
87 class WXDLLIMPEXP_BASE wxObjectRefData
;
88 class WXDLLIMPEXP_BASE wxEvent
;
89 class WXDLLIMPEXP_BASE wxEvtHandler
;
91 typedef void (wxObject::*wxObjectEventFunction
)(wxEvent
&);
93 #if wxUSE_FUNC_TEMPLATE_POINTER
94 # define wxTO_STRING(type) wxToStringConverter<type>
95 # define wxTO_STRING_IMP(type)
96 # define wxFROM_STRING(type) wxFromStringConverter<type>
97 # define wxFROM_STRING_IMP(type)
99 # define wxTO_STRING(type) ToString##type
100 # define wxTO_STRING_IMP(type) inline void ToString##type( const wxxVariant& data , wxString &result ) { wxToStringConverter<type>(data, result); }
101 # define wxFROM_STRING(type) FromString##type
102 # define wxFROM_STRING_IMP(type) inline void FromString##type( const wxString& data , wxxVariant &result ) { wxFromStringConverter<type>(data, result); }
105 // ----------------------------------------------------------------------------
108 // In the header files there would no change from pure c++ code, in the
109 // implementation, an enum would have
110 // to be enumerated eg :
112 // wxBEGIN_ENUM( wxFlavor )
113 // wxENUM_MEMBER( Vanilla )
114 // wxENUM_MEMBER( Chocolate )
115 // wxENUM_MEMBER( Strawberry )
116 // wxEND_ENUM( wxFlavor )
117 // ----------------------------------------------------------------------------
119 struct WXDLLIMPEXP_BASE wxEnumMemberData
121 const wxChar
* m_name
;
125 class WXDLLIMPEXP_BASE wxEnumData
128 wxEnumData( wxEnumMemberData
* data
) ;
130 // returns true if the member has been found and sets the int value
131 // pointed to accordingly (if ptr != null )
132 // if not found returns false, value left unchanged
133 bool HasEnumMemberValue( const wxChar
*name
, int *value
= NULL
) const ;
135 // returns the value of the member, if not found in debug mode an
136 // assert is issued, in release 0 is returned
137 int GetEnumMemberValue(const wxChar
*name
) const ;
139 // returns the name of the enum member having the passed in value
140 // returns an emtpy string if not found
141 const wxChar
*GetEnumMemberName(int value
) const ;
143 // returns the number of members in this enum
144 int GetEnumCount() const { return m_count
; }
146 // returns the value of the nth member
147 int GetEnumMemberValueByIndex( int n
) const ;
149 // returns the value of the nth member
150 const wxChar
*GetEnumMemberNameByIndex( int n
) const ;
152 wxEnumMemberData
*m_members
;
156 #define wxBEGIN_ENUM( e ) \
157 wxEnumMemberData s_enumDataMembers##e[] = {
159 #define wxENUM_MEMBER( v ) { wxT(#v), v } ,
161 #define wxEND_ENUM( e ) { NULL , 0 } } ; \
162 wxEnumData s_enumData##e( s_enumDataMembers##e ) ; \
163 wxEnumData *wxGetEnumData(e) { return &s_enumData##e ; } \
164 template<> void wxStringReadValue(const wxString& s , e &data ) \
166 data = (e) s_enumData##e.GetEnumMemberValue(s) ; \
168 template<> void wxStringWriteValue(wxString &s , const e &data ) \
170 s = s_enumData##e.GetEnumMemberName((int)data) ; \
172 void FromLong##e( long data , wxxVariant& result ) { result = wxxVariant((e)data) ;} \
173 void ToLong##e( const wxxVariant& data , long &result ) { result = (long) data.wxTEMPLATED_MEMBER_CALL(Get , e) ;} \
174 wxTO_STRING_IMP( e ) \
175 wxFROM_STRING_IMP( e ) \
176 wxEnumTypeInfo s_typeInfo##e(wxT_ENUM , &s_enumData##e , &wxTO_STRING( e ) , &wxFROM_STRING( e ) , &ToLong##e , &FromLong##e , typeid(e).name() ) ;
178 // ----------------------------------------------------------------------------
190 // typedef wxBitset<wxFlavor> wxCoupe ;
192 // in the implementation file :
194 // wxBEGIN_ENUM( wxFlavor )
195 // wxENUM_MEMBER( Vanilla )
196 // wxENUM_MEMBER( Chocolate )
197 // wxENUM_MEMBER( Strawberry )
198 // wxEND_ENUM( wxFlavor )
200 // wxIMPLEMENT_SET_STREAMING( wxCoupe , wxFlavor )
202 // implementation note : no partial specialization for streaming, but a delegation to a
205 // ----------------------------------------------------------------------------
207 // in order to remove dependancy on string tokenizer
208 void WXDLLIMPEXP_BASE
wxSetStringToArray( const wxString
&s
, wxArrayString
&array
) ;
211 void wxSetFromString(const wxString
&s
, wxBitset
<e
> &data
)
213 wxEnumData
* edata
= wxGetEnumData((e
) 0) ;
216 wxArrayString array
;
217 wxSetStringToArray( s
, array
) ;
219 for ( int i
= 0 ; i
< array
.Count() ; ++i
)
223 if ( edata
->HasEnumMemberValue( flag
, &ivalue
) )
225 data
.set( (e
) ivalue
) ;
231 void wxSetToString( wxString
&s
, const wxBitset
<e
> &data
)
233 wxEnumData
* edata
= wxGetEnumData((e
) 0) ;
234 int count
= edata
->GetEnumCount() ;
237 for ( i
= 0 ; i
< count
; i
++ )
239 e value
= (e
) edata
->GetEnumMemberValueByIndex(i
) ;
240 if ( data
.test( value
) )
242 // this could also be done by the templated calls
245 s
+= edata
->GetEnumMemberNameByIndex(i
) ;
250 #define wxIMPLEMENT_SET_STREAMING(SetName,e) \
251 template<> void wxStringReadValue(const wxString &s , wxBitset<e> &data ) \
253 wxSetFromString( s , data ) ; \
255 template<> void wxStringWriteValue( wxString &s , const wxBitset<e> &data ) \
257 wxSetToString( s , data ) ; \
259 void FromLong##SetName( long data , wxxVariant& result ) { result = wxxVariant(SetName((unsigned long)data)) ;} \
260 void ToLong##SetName( const wxxVariant& data , long &result ) { result = (long) data.wxTEMPLATED_MEMBER_CALL(Get , SetName).to_ulong() ;} \
261 wxTO_STRING_IMP( SetName ) \
262 wxFROM_STRING_IMP( SetName ) \
263 wxEnumTypeInfo s_typeInfo##SetName(wxT_SET , &s_enumData##e , &wxTO_STRING( SetName ) , &wxFROM_STRING( SetName ) , &ToLong##SetName , &FromLong##SetName, typeid(SetName).name() ) ; \
267 void wxFlagsFromString(const wxString
&s
, e
&data
)
269 wxEnumData
* edata
= wxGetEnumData((e
*) 0) ;
272 wxArrayString array
;
273 wxSetStringToArray( s
, array
) ;
275 for ( size_t i
= 0 ; i
< array
.Count() ; ++i
)
279 if ( edata
->HasEnumMemberValue( flag
, &ivalue
) )
281 data
.m_data
|= ivalue
;
287 void wxFlagsToString( wxString
&s
, const e
& data
)
289 wxEnumData
* edata
= wxGetEnumData((e
*) 0) ;
290 int count
= edata
->GetEnumCount() ;
293 long dataValue
= data
.m_data
;
294 for ( i
= 0 ; i
< count
; i
++ )
296 int value
= edata
->GetEnumMemberValueByIndex(i
) ;
297 // make this to allow for multi-bit constants to work
298 if ( value
&& ( dataValue
& value
) == value
)
300 // clear the flags we just set
301 dataValue
&= ~value
;
302 // this could also be done by the templated calls
305 s
+= edata
->GetEnumMemberNameByIndex(i
) ;
310 #define wxBEGIN_FLAGS( e ) \
311 wxEnumMemberData s_enumDataMembers##e[] = {
313 #define wxFLAGS_MEMBER( v ) { wxT(#v), v } ,
315 #define wxEND_FLAGS( e ) { NULL , 0 } } ; \
316 wxEnumData s_enumData##e( s_enumDataMembers##e ) ; \
317 wxEnumData *wxGetEnumData(e*) { return &s_enumData##e ; } \
318 template<> void wxStringReadValue(const wxString &s , e &data ) \
320 wxFlagsFromString<e>( s , data ) ; \
322 template<> void wxStringWriteValue( wxString &s , const e& data ) \
324 wxFlagsToString<e>( s , data ) ; \
326 void FromLong##e( long data , wxxVariant& result ) { result = wxxVariant(e(data)) ;} \
327 void ToLong##e( const wxxVariant& data , long &result ) { result = (long) data.wxTEMPLATED_MEMBER_CALL(Get , e).m_data ;} \
328 wxTO_STRING_IMP( e ) \
329 wxFROM_STRING_IMP( e ) \
330 wxEnumTypeInfo s_typeInfo##e(wxT_SET , &s_enumData##e , &wxTO_STRING( e ) , &wxFROM_STRING( e ) , &ToLong##e , &FromLong##e, typeid(e).name() ) ;
331 // ----------------------------------------------------------------------------
333 // ----------------------------------------------------------------------------
336 // All data exposed by the RTTI is characterized using the following classes.
337 // The first characterization is done by wxTypeKind. All enums up to and including
338 // wxT_CUSTOM represent so called simple types. These cannot be divided any further.
339 // They can be converted to and from wxStrings, that's all.
344 wxT_VOID
= 0, // unknown type
354 wxT_STRING
, // must be wxString
355 wxT_SET
, // must be wxBitset<> template
357 wxT_CUSTOM
, // user defined type (e.g. wxPoint)
359 wxT_LAST_SIMPLE_TYPE_KIND
= wxT_CUSTOM
,
361 wxT_OBJECT_PTR
, // object reference
362 wxT_OBJECT
, // embedded object
363 wxT_COLLECTION
, // collection
365 wxT_DELEGATE
, // for connecting against an event source
367 wxT_LAST_TYPE_KIND
= wxT_DELEGATE
// sentinel for bad data, asserts, debugging
370 class WXDLLIMPEXP_BASE wxxVariant
;
371 class WXDLLIMPEXP_BASE wxTypeInfo
;
373 WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxTypeInfo
* , wxTypeInfoMap
, class WXDLLIMPEXP_BASE
) ;
375 class WXDLLIMPEXP_BASE wxTypeInfo
378 typedef void (*converterToString_t
)( const wxxVariant
& data
, wxString
&result
) ;
379 typedef void (*converterFromString_t
)( const wxString
& data
, wxxVariant
&result
) ;
381 wxTypeInfo(wxTypeKind kind
,
382 converterToString_t to
= NULL
, converterFromString_t from
= NULL
,
383 const wxString
&name
= wxEmptyString
):
384 m_toString(to
), m_fromString(from
), m_kind(kind
), m_name(name
)
389 wxTypeInfo(wxTypeKind kind
,
390 converterToString_t to
, converterFromString_t from
,
392 m_toString(to
), m_fromString(from
), m_kind(kind
), m_name(wxString::FromAscii(name
))
398 virtual ~wxTypeInfo()
403 // return the kind of this type (wxT_... constants)
404 wxTypeKind
GetKind() const { return m_kind
; }
406 // returns the unique name of this type
407 const wxString
& GetTypeName() const { return m_name
; }
409 // is this type a delegate type
410 bool IsDelegateType() const { return m_kind
== wxT_DELEGATE
; }
412 // is this type a custom type
413 bool IsCustomType() const { return m_kind
== wxT_CUSTOM
; }
415 // is this type an object type
416 bool IsObjectType() const { return m_kind
== wxT_OBJECT
|| m_kind
== wxT_OBJECT_PTR
; }
418 // can the content of this type be converted to and from strings ?
419 bool HasStringConverters() const { return m_toString
!= NULL
&& m_fromString
!= NULL
; }
421 // convert a wxxVariant holding data of this type into a string
422 void ConvertToString( const wxxVariant
& data
, wxString
&result
) const
424 { if ( m_toString
) (*m_toString
)( data
, result
) ; else wxLogError( _("String conversions not supported") ) ; }
426 // convert a string into a wxxVariant holding the corresponding data in this type
427 void ConvertFromString( const wxString
& data
, wxxVariant
&result
) const
428 { if( m_fromString
) (*m_fromString
)( data
, result
) ; else wxLogError( _("String conversions not supported") ) ; }
431 static wxTypeInfo
*FindType(const char *typeName
) { return FindType( wxString::FromAscii(typeName
) ) ; }
433 static wxTypeInfo
*FindType(const wxChar
*typeName
);
440 converterToString_t m_toString
;
441 converterFromString_t m_fromString
;
443 static wxTypeInfoMap
* ms_typeTable
;
449 class WXDLLIMPEXP_BASE wxBuiltInTypeInfo
: public wxTypeInfo
452 wxBuiltInTypeInfo( wxTypeKind kind
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
, const wxString
&name
= wxEmptyString
) :
453 wxTypeInfo( kind
, to
, from
, name
)
454 { wxASSERT_MSG( GetKind() < wxT_SET
, wxT("Illegal Kind for Base Type") ) ; }
456 wxBuiltInTypeInfo( wxTypeKind kind
, converterToString_t to
, converterFromString_t from
, const char *name
) :
457 wxTypeInfo( kind
, to
, from
, name
)
458 { wxASSERT_MSG( GetKind() < wxT_SET
, wxT("Illegal Kind for Base Type") ) ; }
462 class WXDLLIMPEXP_BASE wxCustomTypeInfo
: public wxTypeInfo
465 wxCustomTypeInfo( const wxString
&name
, converterToString_t to
, converterFromString_t from
) :
466 wxTypeInfo( wxT_CUSTOM
, to
, from
, name
)
469 wxCustomTypeInfo( const char *name
, converterToString_t to
, converterFromString_t from
) :
470 wxTypeInfo( wxT_CUSTOM
, to
, from
, name
)
475 class WXDLLIMPEXP_BASE wxEnumTypeInfo
: public wxTypeInfo
478 typedef void (*converterToLong_t
)( const wxxVariant
& data
, long &result
) ;
479 typedef void (*converterFromLong_t
)( long data
, wxxVariant
&result
) ;
481 wxEnumTypeInfo( wxTypeKind kind
, wxEnumData
* enumInfo
, converterToString_t to
, converterFromString_t from
,
482 converterToLong_t toLong
, converterFromLong_t fromLong
, const wxString
&name
) :
483 wxTypeInfo( kind
, to
, from
, name
) , m_toLong( toLong
) , m_fromLong( fromLong
)
484 { wxASSERT_MSG( kind
== wxT_ENUM
|| kind
== wxT_SET
, wxT("Illegal Kind for Enum Type")) ; m_enumInfo
= enumInfo
;}
487 wxEnumTypeInfo( wxTypeKind kind
, wxEnumData
* enumInfo
, converterToString_t to
, converterFromString_t from
,
488 converterToLong_t toLong
, converterFromLong_t fromLong
, const char * name
) :
489 wxTypeInfo( kind
, to
, from
, name
) , m_toLong( toLong
) , m_fromLong( fromLong
)
490 { wxASSERT_MSG( kind
== wxT_ENUM
|| kind
== wxT_SET
, wxT("Illegal Kind for Enum Type")) ; m_enumInfo
= enumInfo
;}
492 const wxEnumData
* GetEnumData() const { return m_enumInfo
; }
494 // convert a wxxVariant holding data of this type into a long
495 void ConvertToLong( const wxxVariant
& data
, long &result
) const
497 { if( m_toLong
) (*m_toLong
)( data
, result
) ; else wxLogError( _("Long Conversions not supported") ) ; }
499 // convert a long into a wxxVariant holding the corresponding data in this type
500 void ConvertFromLong( long data
, wxxVariant
&result
) const
501 { if( m_fromLong
) (*m_fromLong
)( data
, result
) ; else wxLogError( _("Long Conversions not supported") ) ;}
504 converterToLong_t m_toLong
;
505 converterFromLong_t m_fromLong
;
507 wxEnumData
*m_enumInfo
; // Kind == wxT_ENUM or Kind == wxT_SET
510 class WXDLLIMPEXP_BASE wxClassTypeInfo
: public wxTypeInfo
513 wxClassTypeInfo( wxTypeKind kind
, wxClassInfo
* classInfo
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
, const wxString
&name
= wxEmptyString
) ;
515 wxClassTypeInfo( wxTypeKind kind
, wxClassInfo
* classInfo
, converterToString_t to
, converterFromString_t from
, const char *name
) ;
517 const wxClassInfo
*GetClassInfo() const { return m_classInfo
; }
519 wxClassInfo
*m_classInfo
; // Kind == wxT_OBJECT - could be NULL
522 class WXDLLIMPEXP_BASE wxCollectionTypeInfo
: public wxTypeInfo
525 wxCollectionTypeInfo( const wxString
&elementName
, converterToString_t to
, converterFromString_t from
, const wxString
&name
) :
526 wxTypeInfo( wxT_COLLECTION
, to
, from
, name
)
527 { m_elementTypeName
= elementName
; m_elementType
= NULL
;}
529 wxCollectionTypeInfo( const char *elementName
, converterToString_t to
, converterFromString_t from
, const char *name
) :
530 wxTypeInfo( wxT_COLLECTION
, to
, from
, name
)
531 { m_elementTypeName
= wxString::FromAscii( elementName
) ; m_elementType
= NULL
;}
533 const wxTypeInfo
* GetElementType() const
535 if ( m_elementType
== NULL
)
536 m_elementType
= wxTypeInfo::FindType( m_elementTypeName
) ;
537 return m_elementType
; }
539 mutable wxTypeInfo
* m_elementType
;
540 wxString m_elementTypeName
;
543 // a delegate is an exposed event source
545 class WXDLLIMPEXP_BASE wxDelegateTypeInfo
: public wxTypeInfo
548 wxDelegateTypeInfo( int eventType
, wxClassInfo
* eventClass
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
) ;
549 wxDelegateTypeInfo( int eventType
, int lastEventType
, wxClassInfo
* eventClass
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
) ;
550 int GetEventType() const { return m_eventType
; }
551 int GetLastEventType() const { return m_lastEventType
; }
552 const wxClassInfo
* GetEventClass() const { return m_eventClass
; }
554 const wxClassInfo
*m_eventClass
; // (extended will merge into classinfo)
556 int m_lastEventType
;
559 template<typename T
> const wxTypeInfo
* wxGetTypeInfo( T
* ) { return wxTypeInfo::FindType(typeid(T
).name()) ; }
561 // this macro is for usage with custom, non-object derived classes and structs, wxPoint is such a custom type
563 #if wxUSE_FUNC_TEMPLATE_POINTER
564 #define wxCUSTOM_TYPE_INFO( e , toString , fromString ) \
565 wxCustomTypeInfo s_typeInfo##e(typeid(e).name() , &toString , &fromString) ;
567 #define wxCUSTOM_TYPE_INFO( e , toString , fromString ) \
568 void ToString##e( const wxxVariant& data , wxString &result ) { toString(data, result); } \
569 void FromString##e( const wxString& data , wxxVariant &result ) { fromString(data, result); } \
570 wxCustomTypeInfo s_typeInfo##e(typeid(e).name() , &ToString##e , &FromString##e) ;
573 #define wxCOLLECTION_TYPE_INFO( element , collection ) \
574 wxCollectionTypeInfo s_typeInfo##collection( typeid(element).name() , NULL , NULL , typeid(collection).name() ) ;
576 // sometimes a compiler invents specializations that are nowhere called, use this macro to satisfy the refs, currently
577 // we don't have to play tricks, but if we will have to according to the compiler, we will use that macro for that
579 #define wxILLEGAL_TYPE_SPECIALIZATION( a )
581 // ----------------------------------------------------------------------------
582 // wxxVariant as typesafe data holder
583 // ----------------------------------------------------------------------------
585 class WXDLLIMPEXP_BASE wxxVariantData
588 virtual ~wxxVariantData() {}
590 // return a heap allocated duplicate
591 virtual wxxVariantData
* Clone() const = 0 ;
593 // returns the type info of the contentc
594 virtual const wxTypeInfo
* GetTypeInfo() const = 0 ;
597 template<typename T
> class wxxVariantDataT
: public wxxVariantData
600 wxxVariantDataT(const T
& d
) : m_data(d
) {}
601 virtual ~wxxVariantDataT() {}
603 // get a ref to the stored data
604 T
& Get() { return m_data
; }
606 // get a const ref to the stored data
607 const T
& Get() const { return m_data
; }
610 void Set(const T
& d
) { m_data
= d
; }
612 // return a heap allocated duplicate
613 virtual wxxVariantData
* Clone() const { return new wxxVariantDataT
<T
>( Get() ) ; }
615 // returns the type info of the contentc
616 virtual const wxTypeInfo
* GetTypeInfo() const { return wxGetTypeInfo( (T
*) NULL
) ; }
622 class WXDLLIMPEXP_BASE wxxVariant
625 wxxVariant() { m_data
= NULL
; }
626 wxxVariant( wxxVariantData
* data
, const wxString
& name
= wxEmptyString
) : m_data(data
) , m_name(name
) {}
627 wxxVariant( const wxxVariant
&d
) { if ( d
.m_data
) m_data
= d
.m_data
->Clone() ; else m_data
= NULL
; m_name
= d
.m_name
; }
629 template<typename T
> wxxVariant( const T
& data
, const wxString
& name
= wxEmptyString
) :
630 m_data(new wxxVariantDataT
<T
>(data
) ), m_name(name
) {}
632 ~wxxVariant() { delete m_data
; }
634 // get a ref to the stored data
635 template<typename T
> T
& Get(wxTEMPLATED_MEMBER_FIX(T
))
637 wxxVariantDataT
<T
> *dataptr
= dynamic_cast<wxxVariantDataT
<T
>*> (m_data
) ;
638 wxASSERT_MSG( dataptr
, wxString::Format(wxT("Cast to %s not possible"), typeid(T
).name()) ) ;
639 return dataptr
->Get() ;
642 // get a ref to the stored data
643 template<typename T
> const T
& Get(wxTEMPLATED_MEMBER_FIX(T
)) const
645 const wxxVariantDataT
<T
> *dataptr
= dynamic_cast<const wxxVariantDataT
<T
>*> (m_data
) ;
646 wxASSERT_MSG( dataptr
, wxString::Format(wxT("Cast to %s not possible"), typeid(T
).name()) ) ;
647 return dataptr
->Get() ;
650 bool IsEmpty() const { return m_data
== NULL
; }
652 template<typename T
> bool HasData(wxTEMPLATED_MEMBER_FIX(T
)) const
654 const wxxVariantDataT
<T
> *dataptr
= dynamic_cast<const wxxVariantDataT
<T
>*> (m_data
) ;
655 return dataptr
!= NULL
;
659 template<typename T
> void Set(const T
& data
) const
662 m_data
= new wxxVariantDataT
<T
>(data
) ;
665 wxxVariant
& operator=(const wxxVariant
&d
)
668 m_data
= d
.m_data
? d
.m_data
->Clone() : NULL
;
673 // gets the stored data casted to a wxObject* , returning NULL if cast is not possible
674 wxObject
* GetAsObject() ;
676 // get the typeinfo of the stored object
677 const wxTypeInfo
* GetTypeInfo() const { return m_data
->GetTypeInfo() ; }
679 // returns this value as string
680 wxString
GetAsString() const
683 GetTypeInfo()->ConvertToString( *this , s
) ;
686 const wxString
& GetName() const { return m_name
; }
688 wxxVariantData
* m_data
;
692 #include "wx/dynarray.h"
694 WX_DECLARE_OBJARRAY_WITH_DECL(wxxVariant
, wxxVariantArray
, class WXDLLIMPEXP_BASE
);
696 // templated streaming, every type must have their specialization for these methods
699 void wxStringReadValue( const wxString
&s
, T
&data
);
702 void wxStringWriteValue( wxString
&s
, const T
&data
);
705 void wxToStringConverter( const wxxVariant
&v
, wxString
&s
wxTEMPLATED_FUNCTION_FIX(T
)) { wxStringWriteValue( s
, v
.wxTEMPLATED_MEMBER_CALL(Get
, T
) ) ; }
708 void wxFromStringConverter( const wxString
&s
, wxxVariant
&v
wxTEMPLATED_FUNCTION_FIX(T
)) { T d
; wxStringReadValue( s
, d
) ; v
= wxxVariant(d
) ; }
710 // ----------------------------------------------------------------------------
713 // wxPropertyInfo is used to inquire of the property by name. It doesn't
714 // provide access to the property, only information about it. If you
715 // want access, look at wxPropertyAccessor.
716 // ----------------------------------------------------------------------------
718 class WXDLLIMPEXP_BASE wxSetter
721 wxSetter( const wxString name
) { m_name
= name
; }
722 virtual ~wxSetter() {}
723 virtual void Set( wxObject
*object
, const wxxVariant
&variantValue
) const = 0;
724 const wxString
& GetName() const { return m_name
; }
729 class WXDLLIMPEXP_BASE wxGetter
732 wxGetter( const wxString name
) { m_name
= name
; }
733 virtual ~wxGetter() {}
734 virtual void Get( const wxObject
*object
, wxxVariant
& result
) const = 0;
735 const wxString
& GetName() const { return m_name
; }
740 class WXDLLIMPEXP_BASE wxCollectionGetter
743 wxCollectionGetter( const wxString name
) { m_name
= name
; }
744 virtual ~wxCollectionGetter() {}
745 virtual void Get( const wxObject
*object
, wxxVariantArray
& result
) const = 0;
746 const wxString
& GetName() const { return m_name
; }
751 template<typename coll_t
> void WXDLLIMPEXP_BASE
wxCollectionToVariantArray( const coll_t
& coll
, wxxVariantArray
& result
) ;
753 class WXDLLIMPEXP_BASE wxAdder
756 wxAdder( const wxString name
) { m_name
= name
; }
757 virtual ~wxAdder() {}
758 virtual void Add( wxObject
*object
, const wxxVariant
&variantValue
) const= 0;
759 const wxString
& GetName() const { return m_name
; }
765 #define wxSETTER( property, Klass, valueType, setterMethod ) \
766 class wxSetter##property : public wxSetter \
769 wxINFUNC_CLASS_TYPE_FIX(Klass) \
770 wxSetter##property() : wxSetter( wxT(#setterMethod) ) {} \
771 ~wxSetter##property() {} \
772 void Set( wxObject *object, const wxxVariant &variantValue ) const \
774 Klass *obj = dynamic_cast<Klass*>(object) ; \
775 if ( variantValue.wxTEMPLATED_MEMBER_CALL(HasData, valueType) ) \
776 obj->setterMethod(variantValue.wxTEMPLATED_MEMBER_CALL(Get , valueType)) ; \
778 obj->setterMethod(*variantValue.wxTEMPLATED_MEMBER_CALL(Get , valueType*)) ; \
782 #define wxGETTER( property, Klass, valueType , gettermethod ) \
783 class wxGetter##property : public wxGetter \
786 wxINFUNC_CLASS_TYPE_FIX(Klass) \
787 wxGetter##property() : wxGetter( wxT(#gettermethod) ) {} \
788 ~wxGetter##property() {} \
789 void Get( const wxObject *object , wxxVariant &result) const \
791 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
792 result = wxxVariant( obj->gettermethod() ) ; \
796 #define wxADDER( property, Klass, valueType , addermethod ) \
797 class wxAdder##property : public wxAdder \
800 wxINFUNC_CLASS_TYPE_FIX(Klass) \
801 wxAdder##property() : wxAdder( wxT(#addermethod) ) {} \
802 ~wxAdder##property() {} \
803 void Add( wxObject *object, const wxxVariant &variantValue ) const \
805 Klass *obj = dynamic_cast<Klass*>(object) ; \
806 if ( variantValue.wxTEMPLATED_MEMBER_CALL(HasData, valueType) ) \
807 obj->addermethod(variantValue.wxTEMPLATED_MEMBER_CALL(Get , valueType)) ; \
809 obj->addermethod(*variantValue.wxTEMPLATED_MEMBER_CALL(Get , valueType*)) ; \
813 #define wxCOLLECTION_GETTER( property, Klass, valueType , gettermethod ) \
814 class wxCollectionGetter##property : public wxCollectionGetter \
817 wxINFUNC_CLASS_TYPE_FIX(Klass) \
818 wxCollectionGetter##property() : wxCollectionGetter( wxT(#gettermethod) ) {} \
819 ~wxCollectionGetter##property() {} \
820 void Get( const wxObject *object , wxxVariantArray &result) const \
822 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
823 wxCollectionToVariantArray( obj->gettermethod() , result ) ; \
827 class WXDLLIMPEXP_BASE wxPropertyAccessor
830 wxPropertyAccessor( wxSetter
*setter
, wxGetter
*getter
, wxAdder
*adder
, wxCollectionGetter
*collectionGetter
)
831 { m_setter
= setter
; m_getter
= getter
; m_adder
= adder
; m_collectionGetter
= collectionGetter
;}
833 virtual ~wxPropertyAccessor() {}
835 // Setting a simple property (non-collection)
836 virtual void SetProperty(wxObject
*object
, const wxxVariant
&value
) const
837 { if ( m_setter
) m_setter
->Set( object
, value
) ; else wxLogError( _("SetProperty called w/o valid setter") ) ;}
839 // Getting a simple property (non-collection)
840 virtual void GetProperty(const wxObject
*object
, wxxVariant
&result
) const
841 { if ( m_getter
) m_getter
->Get( object
, result
) ; else wxLogError( _("GetProperty called w/o valid getter") ) ;}
843 // Adding an element to a collection property
844 virtual void AddToPropertyCollection(wxObject
*object
, const wxxVariant
&value
) const
845 { if ( m_adder
) m_adder
->Add( object
, value
) ; else wxLogError( _("AddToPropertyCollection called w/o valid adder") ) ;}
847 // Getting a collection property
848 virtual void GetPropertyCollection( const wxObject
*obj
, wxxVariantArray
&result
) const
849 { if ( m_collectionGetter
) m_collectionGetter
->Get( obj
, result
) ; else wxLogError( _("GetPropertyCollection called w/o valid collection getter") ) ;}
851 virtual bool HasSetter() const { return m_setter
!= NULL
; }
852 virtual bool HasCollectionGetter() const { return m_collectionGetter
!= NULL
; }
853 virtual bool HasGetter() const { return m_getter
!= NULL
; }
854 virtual bool HasAdder() const { return m_adder
!= NULL
; }
856 virtual const wxString
& GetCollectionGetterName() const
857 { return m_collectionGetter
->GetName() ; }
858 virtual const wxString
& GetGetterName() const
859 { return m_getter
->GetName() ; }
860 virtual const wxString
& GetSetterName() const
861 { return m_setter
->GetName() ; }
862 virtual const wxString
& GetAdderName() const
863 { return m_adder
->GetName() ; }
869 wxCollectionGetter
* m_collectionGetter
;
872 class WXDLLIMPEXP_BASE wxGenericPropertyAccessor
: public wxPropertyAccessor
875 wxGenericPropertyAccessor( const wxString
&propName
) ;
876 ~wxGenericPropertyAccessor() ;
878 void RenameProperty( const wxString
& WXUNUSED_UNLESS_DEBUG(oldName
),
879 const wxString
& newName
)
881 wxASSERT( oldName
== m_propertyName
) ; m_propertyName
= newName
;
883 virtual bool HasSetter() const { return true ; }
884 virtual bool HasGetter() const { return true ; }
885 virtual bool HasAdder() const { return false ; }
886 virtual bool HasCollectionGetter() const { return false ; }
888 virtual const wxString
& GetGetterName() const
889 { return m_getterName
; }
890 virtual const wxString
& GetSetterName() const
891 { return m_setterName
; }
893 virtual void SetProperty(wxObject
*object
, const wxxVariant
&value
) const ;
894 virtual void GetProperty(const wxObject
*object
, wxxVariant
&value
) const ;
896 // Adding an element to a collection property
897 virtual void AddToPropertyCollection(wxObject
*WXUNUSED(object
), const wxxVariant
&WXUNUSED(value
)) const
898 { wxLogError( _("AddToPropertyCollection called on a generic accessor") ) ;}
900 // Getting a collection property
901 virtual void GetPropertyCollection( const wxObject
*WXUNUSED(obj
), wxxVariantArray
&WXUNUSED(result
)) const
902 { wxLogError ( _("GetPropertyCollection called on a generic accessor") ) ;}
904 struct wxGenericPropertyAccessorInternal
;
905 wxGenericPropertyAccessorInternal
* m_data
;
906 wxString m_propertyName
;
907 wxString m_setterName
;
908 wxString m_getterName
;
911 typedef long wxPropertyInfoFlags
;
913 // will be removed in future releases
914 wxPROP_DEPRECATED
= 0x00000001 ,
915 // object graph property, will be streamed with priority (after constructor properties)
916 wxPROP_OBJECT_GRAPH
= 0x00000002 ,
917 // this will only be streamed out and in as enum/set, the internal representation is still a long
918 wxPROP_ENUM_STORE_LONG
= 0x00000004 ,
919 // don't stream out this property, needed eg to avoid streaming out children that are always created by their parents
920 wxPROP_DONT_STREAM
= 0x00000008 ,
923 class WXDLLIMPEXP_BASE wxPropertyInfo
925 friend class WXDLLIMPEXP_BASE wxDynamicClassInfo
;
927 wxPropertyInfo(wxPropertyInfo
* &iter
,
928 wxClassInfo
* itsClass
,
929 const wxString
& name
,
930 const wxString
& typeName
,
931 wxPropertyAccessor
*accessor
,
933 wxPropertyInfoFlags flags
= 0,
934 const wxString
& helpString
= wxEmptyString
,
935 const wxString
& groupString
= wxEmptyString
) :
936 m_itsClass(itsClass
),
939 m_typeName(typeName
) ,
940 m_collectionElementTypeInfo(NULL
),
941 m_accessor(accessor
),
944 m_helpString(helpString
),
945 m_groupString(groupString
)
951 wxPropertyInfo(wxPropertyInfo
* &iter
,
952 wxClassInfo
* itsClass
,
953 const wxString
& name
,
954 const char* typeName
,
955 wxPropertyAccessor
*accessor
,
957 wxPropertyInfoFlags flags
= 0,
958 const wxString
& helpString
= wxEmptyString
,
959 const wxString
& groupString
= wxEmptyString
) :
960 m_itsClass(itsClass
),
963 m_typeName(wxString::FromAscii(typeName
)) ,
964 m_collectionElementTypeInfo(NULL
),
965 m_accessor(accessor
),
968 m_helpString(helpString
),
969 m_groupString(groupString
)
974 wxPropertyInfo(wxPropertyInfo
* &iter
,
975 wxClassInfo
* itsClass
,
976 const wxString
& name
,
977 wxDelegateTypeInfo
* type
,
978 wxPropertyAccessor
*accessor
,
980 wxPropertyInfoFlags flags
= 0,
981 const wxString
& helpString
= wxEmptyString
,
982 const wxString
& groupString
= wxEmptyString
) :
983 m_itsClass(itsClass
),
986 m_collectionElementTypeInfo(NULL
),
987 m_accessor(accessor
),
990 m_helpString(helpString
),
991 m_groupString(groupString
)
996 wxPropertyInfo(wxPropertyInfo
* &iter
,
997 wxClassInfo
* itsClass
, const wxString
& name
,
998 const wxString
& collectionTypeName
,
999 const wxString
& elementTypeName
,
1000 wxPropertyAccessor
*accessor
,
1001 wxPropertyInfoFlags flags
= 0,
1002 const wxString
& helpString
= wxEmptyString
,
1003 const wxString
& groupString
= wxEmptyString
) :
1004 m_itsClass(itsClass
),
1007 m_typeName(collectionTypeName
) ,
1008 m_collectionElementTypeInfo(NULL
),
1009 m_collectionElementTypeName(elementTypeName
),
1010 m_accessor(accessor
) ,
1012 m_helpString(helpString
),
1013 m_groupString(groupString
)
1019 wxPropertyInfo(wxPropertyInfo
* &iter
,
1020 wxClassInfo
* itsClass
, const wxString
& name
,
1021 const char* collectionTypeName
,
1022 const char* elementTypeName
,
1023 wxPropertyAccessor
*accessor
,
1024 wxPropertyInfoFlags flags
= 0,
1025 const wxString
& helpString
= wxEmptyString
,
1026 const wxString
& groupString
= wxEmptyString
) :
1027 m_itsClass(itsClass
),
1030 m_typeName(wxString::FromAscii(collectionTypeName
)) ,
1031 m_collectionElementTypeInfo(NULL
),
1032 m_collectionElementTypeName(wxString::FromAscii(elementTypeName
)),
1033 m_accessor(accessor
) ,
1035 m_helpString(helpString
),
1036 m_groupString(groupString
)
1043 // return the class this property is declared in
1044 const wxClassInfo
* GetDeclaringClass() const { return m_itsClass
; }
1046 // return the name of this property
1047 const wxString
& GetName() const { return m_name
; }
1049 // returns the flags of this property
1050 wxPropertyInfoFlags
GetFlags() const { return m_flags
;}
1052 // returns the short help string of this property
1053 const wxString
& GetHelpString() const { return m_helpString
; }
1055 // returns the group string of this property
1056 const wxString
& GetGroupString() const { return m_groupString
; }
1058 // return the element type info of this property (for collections, otherwise NULL)
1059 const wxTypeInfo
* GetCollectionElementTypeInfo() const
1061 if ( m_collectionElementTypeInfo
== NULL
)
1062 m_collectionElementTypeInfo
= wxTypeInfo::FindType(m_collectionElementTypeName
) ;
1063 return m_collectionElementTypeInfo
;
1066 // return the type info of this property
1067 const wxTypeInfo
* GetTypeInfo() const
1069 if ( m_typeInfo
== NULL
)
1070 m_typeInfo
= wxTypeInfo::FindType(m_typeName
) ;
1074 // return the accessor for this property
1075 wxPropertyAccessor
* GetAccessor() const { return m_accessor
; }
1077 // returns NULL if this is the last property of this class
1078 wxPropertyInfo
* GetNext() const { return m_next
; }
1080 // returns the default value of this property, its kind may be wxT_VOID if it is not valid
1081 wxxVariant
GetDefaultValue() const { return m_defaultValue
; }
1083 void Insert(wxPropertyInfo
* &iter
)
1090 wxPropertyInfo
* i
= iter
;
1098 wxClassInfo
* m_itsClass
;
1100 mutable wxTypeInfo
* m_typeInfo
;
1101 wxString m_typeName
;
1102 mutable wxTypeInfo
* m_collectionElementTypeInfo
;
1103 wxString m_collectionElementTypeName
;
1104 wxPropertyAccessor
* m_accessor
;
1105 wxxVariant m_defaultValue
;
1106 wxPropertyInfoFlags m_flags
;
1107 wxString m_helpString
;
1108 wxString m_groupString
;
1109 // string representation of the default value
1110 // to be assigned by the designer to the property
1111 // when the component is dropped on the container.
1112 wxPropertyInfo
* m_next
;
1115 WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxPropertyInfo
* , wxPropertyInfoMap
, class WXDLLIMPEXP_BASE
) ;
1117 #define wxBEGIN_PROPERTIES_TABLE(theClass) \
1118 wxPropertyInfo *theClass::GetPropertiesStatic() \
1120 typedef theClass class_t; \
1121 static wxPropertyInfo* first = NULL ;
1123 #define wxEND_PROPERTIES_TABLE() \
1126 #define wxHIDE_PROPERTY( pname ) \
1127 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(void).name() ,NULL , wxxVariant() , wxPROP_DONT_STREAM , wxEmptyString , wxEmptyString ) ;
1129 #define wxPROPERTY( pname , type , setter , getter , defaultValue , flags , help , group) \
1130 wxSETTER( pname , class_t , type , setter ) \
1131 static wxSetter##pname _setter##pname ; \
1132 wxGETTER( pname , class_t , type , getter ) \
1133 static wxGetter##pname _getter##pname ; \
1134 static wxPropertyAccessor _accessor##pname( &_setter##pname , &_getter##pname , NULL , NULL ) ; \
1135 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(type).name() ,&_accessor##pname , wxxVariant(defaultValue) , flags , group , help ) ;
1137 #define wxPROPERTY_FLAGS( pname , flags , type , setter , getter ,defaultValue , pflags , help , group) \
1138 wxSETTER( pname , class_t , type , setter ) \
1139 static wxSetter##pname _setter##pname ; \
1140 wxGETTER( pname , class_t , type , getter ) \
1141 static wxGetter##pname _getter##pname ; \
1142 static wxPropertyAccessor _accessor##pname( &_setter##pname , &_getter##pname , NULL , NULL ) ; \
1143 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(flags).name() ,&_accessor##pname , wxxVariant(defaultValue), wxPROP_ENUM_STORE_LONG | pflags , help , group ) ;
1145 #define wxREADONLY_PROPERTY( pname , type , getter ,defaultValue , flags , help , group) \
1146 wxGETTER( pname , class_t , type , getter ) \
1147 static wxGetter##pname _getter##pname ; \
1148 static wxPropertyAccessor _accessor##pname( NULL , &_getter##pname , NULL , NULL ) ; \
1149 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(type).name() ,&_accessor##pname , wxxVariant(defaultValue), flags , help , group ) ;
1151 #define wxREADONLY_PROPERTY_FLAGS( pname , flags , type , getter ,defaultValue , pflags , help , group) \
1152 wxGETTER( pname , class_t , type , getter ) \
1153 static wxGetter##pname _getter##pname ; \
1154 static wxPropertyAccessor _accessor##pname( NULL , &_getter##pname , NULL , NULL ) ; \
1155 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(flags).name() ,&_accessor##pname , wxxVariant(defaultValue), wxPROP_ENUM_STORE_LONG | pflags , help , group ) ;
1157 #define wxPROPERTY_COLLECTION( pname , colltype , addelemtype , adder , getter , flags , help , group ) \
1158 wxADDER( pname , class_t , addelemtype , adder ) \
1159 static wxAdder##pname _adder##pname ; \
1160 wxCOLLECTION_GETTER( pname , class_t , colltype , getter ) \
1161 static wxCollectionGetter##pname _collectionGetter##pname ; \
1162 static wxPropertyAccessor _accessor##pname( NULL , NULL ,&_adder##pname , &_collectionGetter##pname ) ; \
1163 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(colltype).name() ,typeid(addelemtype).name() ,&_accessor##pname , flags , help , group ) ;
1165 #define wxREADONLY_PROPERTY_COLLECTION( pname , colltype , addelemtype , getter , flags , help , group) \
1166 wxCOLLECTION_GETTER( pname , class_t , colltype , getter ) \
1167 static wxCollectionGetter##pname _collectionGetter##pname ; \
1168 static wxPropertyAccessor _accessor##pname( NULL , NULL , NULL , &_collectionGetter##pname ) ; \
1169 static wxPropertyInfo _propertyInfo##pname( first ,class_t::GetClassInfoStatic() , wxT(#pname) , typeid(colltype).name() ,typeid(addelemtype).name() ,&_accessor##pname , flags , help , group ) ;
1172 #define wxEVENT_PROPERTY( name , eventType , eventClass ) \
1173 static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \
1174 static wxPropertyInfo _propertyInfo##name( first ,class_t::GetClassInfoStatic() , wxT(#name) , &_typeInfo##name , NULL , wxxVariant() ) ; \
1176 #define wxEVENT_RANGE_PROPERTY( name , eventType , lastEventType , eventClass ) \
1177 static wxDelegateTypeInfo _typeInfo##name( eventType , lastEventType , CLASSINFO( eventClass ) ) ; \
1178 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , wxT(#name) , &_typeInfo##name , NULL , wxxVariant() ) ; \
1180 // ----------------------------------------------------------------------------
1181 // Implementation Helper for Simple Properties
1182 // ----------------------------------------------------------------------------
1184 #define wxIMPLEMENT_PROPERTY(name, type) \
1188 void Set##name( type const & p) { m_##name = p; } \
1189 type const & Get##name() const { return m_##name; }
1191 // ----------------------------------------------------------------------------
1194 // this is describing an event sink
1195 // ----------------------------------------------------------------------------
1197 class WXDLLIMPEXP_BASE wxHandlerInfo
1199 friend class WXDLLIMPEXP_BASE wxDynamicClassInfo
;
1201 wxHandlerInfo(wxHandlerInfo
* &iter
,
1202 wxClassInfo
* itsClass
,
1203 const wxString
& name
,
1204 wxObjectEventFunction address
,
1205 const wxClassInfo
* eventClassInfo
) :
1206 m_eventFunction(address
),
1208 m_eventClassInfo(eventClassInfo
) ,
1209 m_itsClass(itsClass
)
1216 wxHandlerInfo
* i
= iter
;
1226 // return the name of this handler
1227 const wxString
& GetName() const { return m_name
; }
1229 // return the class info of the event
1230 const wxClassInfo
*GetEventClassInfo() const { return m_eventClassInfo
; }
1232 // get the handler function pointer
1233 wxObjectEventFunction
GetEventFunction() const { return m_eventFunction
; }
1235 // returns NULL if this is the last handler of this class
1236 wxHandlerInfo
* GetNext() const { return m_next
; }
1238 // return the class this property is declared in
1239 const wxClassInfo
* GetDeclaringClass() const { return m_itsClass
; }
1242 wxObjectEventFunction m_eventFunction
;
1244 const wxClassInfo
* m_eventClassInfo
;
1245 wxHandlerInfo
* m_next
;
1246 wxClassInfo
* m_itsClass
;
1249 #define wxHANDLER(name,eventClassType) \
1250 static wxHandlerInfo _handlerInfo##name( first , class_t::GetClassInfoStatic() , wxT(#name) , (wxObjectEventFunction) (wxEventFunction) &name , CLASSINFO( eventClassType ) ) ;
1252 #define wxBEGIN_HANDLERS_TABLE(theClass) \
1253 wxHandlerInfo *theClass::GetHandlersStatic() \
1255 typedef theClass class_t; \
1256 static wxHandlerInfo* first = NULL ;
1258 #define wxEND_HANDLERS_TABLE() \
1261 // ----------------------------------------------------------------------------
1262 // Constructor Bridges
1264 // allow to set up constructors with params during runtime
1265 // ----------------------------------------------------------------------------
1267 class WXDLLIMPEXP_BASE wxConstructorBridge
1270 virtual void Create(wxObject
* &o
, wxxVariant
*args
) = 0;
1273 // a direct constructor bridge calls the operator new for this class and
1274 // passes all params to the constructor. needed for classes that cannot be
1275 // instantiated using alloc-create semantics
1276 class WXDLLIMPEXP_BASE wxDirectConstructorBrigde
: public wxConstructorBridge
1279 virtual void Create(wxObject
* &o
, wxxVariant
*args
) = 0;
1282 // Creator Bridges for all Numbers of Params
1286 template<typename Class
>
1287 struct wxConstructorBridge_0
: public wxConstructorBridge
1289 void Create(wxObject
* &o
, wxxVariant
*)
1291 Class
*obj
= dynamic_cast<Class
*>(o
);
1296 struct wxConstructorBridge_Dummy
: public wxConstructorBridge
1298 void Create(wxObject
*&, wxxVariant
*)
1303 #define wxCONSTRUCTOR_0(klass) \
1304 wxConstructorBridge_0<klass> constructor##klass ; \
1305 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1306 const wxChar *klass::ms_constructorProperties[] = { NULL } ; \
1307 const int klass::ms_constructorPropertiesCount = 0 ;
1309 #define wxCONSTRUCTOR_DUMMY(klass) \
1310 wxConstructorBridge_Dummy constructor##klass ; \
1311 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1312 const wxChar *klass::ms_constructorProperties[] = { NULL } ; \
1313 const int klass::ms_constructorPropertiesCount = 0 ;
1317 template<typename Class
, typename T0
>
1318 struct wxConstructorBridge_1
: public wxConstructorBridge
1320 void Create(wxObject
* &o
, wxxVariant
*args
)
1322 Class
*obj
= dynamic_cast<Class
*>(o
);
1324 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
)
1329 #define wxCONSTRUCTOR_1(klass,t0,v0) \
1330 wxConstructorBridge_1<klass,t0> constructor##klass ; \
1331 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1332 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) } ; \
1333 const int klass::ms_constructorPropertiesCount = 1 ;
1337 template<typename Class
,
1338 typename T0
, typename T1
>
1339 struct wxConstructorBridge_2
: public wxConstructorBridge
1341 void Create(wxObject
* &o
, wxxVariant
*args
)
1343 Class
*obj
= dynamic_cast<Class
*>(o
);
1345 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1346 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
)
1351 #define wxCONSTRUCTOR_2(klass,t0,v0,t1,v1) \
1352 wxConstructorBridge_2<klass,t0,t1> constructor##klass ; \
1353 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1354 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) } ; \
1355 const int klass::ms_constructorPropertiesCount = 2;
1357 // direct constructor version
1359 template<typename Class
,
1360 typename T0
, typename T1
>
1361 struct wxDirectConstructorBridge_2
: public wxDirectConstructorBrigde
1363 void Create(wxObject
* &o
, wxxVariant
*args
)
1366 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1367 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
)
1372 #define wxDIRECT_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
1373 wxDirectConstructorBridge_2<klass,t0,t1> constructor##klass ; \
1374 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1375 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) } ; \
1376 const int klass::ms_constructorPropertiesCount = 2;
1381 template<typename Class
,
1382 typename T0
, typename T1
, typename T2
>
1383 struct wxConstructorBridge_3
: public wxConstructorBridge
1385 void Create(wxObject
* &o
, wxxVariant
*args
)
1387 Class
*obj
= dynamic_cast<Class
*>(o
);
1389 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1390 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1391 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
)
1396 #define wxCONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
1397 wxConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \
1398 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1399 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) } ; \
1400 const int klass::ms_constructorPropertiesCount = 3 ;
1402 // direct constructor version
1404 template<typename Class
,
1405 typename T0
, typename T1
, typename T2
>
1406 struct wxDirectConstructorBridge_3
: public wxDirectConstructorBrigde
1408 void Create(wxObject
* &o
, wxxVariant
*args
)
1411 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1412 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1413 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
)
1418 #define wxDIRECT_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
1419 wxDirectConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \
1420 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1421 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) } ; \
1422 const int klass::ms_constructorPropertiesCount = 3;
1426 template<typename Class
,
1427 typename T0
, typename T1
, typename T2
, typename T3
>
1428 struct wxConstructorBridge_4
: public wxConstructorBridge
1430 void Create(wxObject
* &o
, wxxVariant
*args
)
1432 Class
*obj
= dynamic_cast<Class
*>(o
);
1434 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1435 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1436 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
) ,
1437 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
)
1442 #define wxCONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
1443 wxConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass ; \
1444 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1445 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) } ; \
1446 const int klass::ms_constructorPropertiesCount = 4 ;
1450 template<typename Class
,
1451 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
>
1452 struct wxConstructorBridge_5
: public wxConstructorBridge
1454 void Create(wxObject
* &o
, wxxVariant
*args
)
1456 Class
*obj
= dynamic_cast<Class
*>(o
);
1458 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1459 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1460 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
) ,
1461 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
) ,
1462 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
)
1467 #define wxCONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
1468 wxConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass ; \
1469 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1470 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) } ; \
1471 const int klass::ms_constructorPropertiesCount = 5;
1475 template<typename Class
,
1476 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
1477 struct wxConstructorBridge_6
: public wxConstructorBridge
1479 void Create(wxObject
* &o
, wxxVariant
*args
)
1481 Class
*obj
= dynamic_cast<Class
*>(o
);
1483 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1484 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1485 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
) ,
1486 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
) ,
1487 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
) ,
1488 args
[5].wxTEMPLATED_MEMBER_CALL(Get
, T5
)
1493 #define wxCONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1494 wxConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1495 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1496 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) } ; \
1497 const int klass::ms_constructorPropertiesCount = 6;
1499 // direct constructor version
1501 template<typename Class
,
1502 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
1503 struct wxDirectConstructorBridge_6
: public wxDirectConstructorBrigde
1505 void Create(wxObject
* &o
, wxxVariant
*args
)
1508 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1509 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1510 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
) ,
1511 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
) ,
1512 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
) ,
1513 args
[5].wxTEMPLATED_MEMBER_CALL(Get
, T5
)
1518 #define wxDIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1519 wxDirectConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1520 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1521 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) } ; \
1522 const int klass::ms_constructorPropertiesCount = 6;
1526 template<typename Class
,
1527 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
>
1528 struct wxConstructorBridge_7
: public wxConstructorBridge
1530 void Create(wxObject
* &o
, wxxVariant
*args
)
1532 Class
*obj
= dynamic_cast<Class
*>(o
);
1534 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1535 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1536 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
) ,
1537 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
) ,
1538 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
) ,
1539 args
[5].wxTEMPLATED_MEMBER_CALL(Get
, T5
) ,
1540 args
[6].wxTEMPLATED_MEMBER_CALL(Get
, T6
)
1545 #define wxCONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
1546 wxConstructorBridge_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass ; \
1547 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1548 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) , wxT(#v6) } ; \
1549 const int klass::ms_constructorPropertiesCount = 7;
1553 template<typename Class
,
1554 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
, typename T7
>
1555 struct wxConstructorBridge_8
: public wxConstructorBridge
1557 void Create(wxObject
* &o
, wxxVariant
*args
)
1559 Class
*obj
= dynamic_cast<Class
*>(o
);
1561 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1562 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1563 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
) ,
1564 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
) ,
1565 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
) ,
1566 args
[5].wxTEMPLATED_MEMBER_CALL(Get
, T5
) ,
1567 args
[6].wxTEMPLATED_MEMBER_CALL(Get
, T6
) ,
1568 args
[7].wxTEMPLATED_MEMBER_CALL(Get
, T7
)
1573 #define wxCONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
1574 wxConstructorBridge_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass ; \
1575 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1576 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) , wxT(#v6) , wxT(#v7) } ; \
1577 const int klass::ms_constructorPropertiesCount = 8;
1578 // ----------------------------------------------------------------------------
1580 // ----------------------------------------------------------------------------
1582 typedef wxObject
*(*wxObjectConstructorFn
)(void);
1583 typedef wxObject
* (*wxVariantToObjectConverter
)( wxxVariant
&data
) ;
1584 typedef wxxVariant (*wxObjectToVariantConverter
)( wxObject
* ) ;
1586 class WXDLLIMPEXP_BASE wxWriter
;
1587 class WXDLLIMPEXP_BASE wxPersister
;
1589 typedef bool (*wxObjectStreamingCallback
) ( const wxObject
*, wxWriter
* , wxPersister
* , wxxVariantArray
& ) ;
1591 class WXDLLIMPEXP_BASE wxClassInfo
1593 friend class WXDLLIMPEXP_BASE wxPropertyInfo
;
1594 friend class WXDLLIMPEXP_BASE wxHandlerInfo
;
1596 wxClassInfo(const wxClassInfo
**_Parents
,
1597 const wxChar
*_UnitName
,
1598 const wxChar
*_ClassName
,
1600 wxObjectConstructorFn ctor
,
1601 wxPropertyInfo
*_Props
,
1602 wxHandlerInfo
*_Handlers
,
1603 wxConstructorBridge
* _Constructor
,
1604 const wxChar
** _ConstructorProperties
,
1605 const int _ConstructorPropertiesCount
,
1606 wxVariantToObjectConverter _PtrConverter1
,
1607 wxVariantToObjectConverter _Converter2
,
1608 wxObjectToVariantConverter _Converter3
,
1609 wxObjectStreamingCallback _streamingCallback
= NULL
1612 m_className(_ClassName
),
1614 m_objectConstructor(ctor
),
1616 m_firstProperty(_Props
),
1617 m_firstHandler(_Handlers
),
1618 m_parents(_Parents
),
1619 m_unitName(_UnitName
),
1620 m_constructor(_Constructor
),
1621 m_constructorProperties(_ConstructorProperties
),
1622 m_constructorPropertiesCount(_ConstructorPropertiesCount
),
1623 m_variantOfPtrToObjectConverter(_PtrConverter1
),
1624 m_variantToObjectConverter(_Converter2
),
1625 m_objectToVariantConverter(_Converter3
),
1626 m_streamingCallback(_streamingCallback
)
1632 wxClassInfo(const wxChar
*_UnitName
, const wxChar
*_ClassName
,
1633 const wxClassInfo
**_Parents
) :
1634 m_className(_ClassName
),
1636 m_objectConstructor(NULL
),
1638 m_firstProperty(NULL
),
1639 m_firstHandler(NULL
),
1640 m_parents(_Parents
),
1641 m_unitName(_UnitName
),
1642 m_constructor(NULL
),
1643 m_constructorProperties(NULL
),
1644 m_constructorPropertiesCount(0),
1645 m_variantOfPtrToObjectConverter(NULL
),
1646 m_variantToObjectConverter(NULL
),
1647 m_objectToVariantConverter(NULL
),
1648 m_streamingCallback(NULL
)
1654 virtual ~wxClassInfo() ;
1656 // allocates an instance of this class, this object does not have to be initialized or fully constructed
1657 // as this call will be followed by a call to Create
1658 virtual wxObject
*AllocateObject() const { return m_objectConstructor
? (*m_objectConstructor
)() : 0; }
1660 // 'old naming' for AllocateObject staying here for backward compatibility
1661 wxObject
*CreateObject() const { return AllocateObject() ; }
1663 // direct construction call for classes that cannot construct instances via alloc/create
1664 wxObject
*ConstructObject(int ParamCount
, wxxVariant
*Params
) const
1666 if ( ParamCount
!= m_constructorPropertiesCount
)
1668 wxLogError( _("Illegal Parameter Count for ConstructObject Method") ) ;
1671 wxObject
*object
= NULL
;
1672 m_constructor
->Create( object
, Params
) ;
1676 bool NeedsDirectConstruction() const { return dynamic_cast<wxDirectConstructorBrigde
*>( m_constructor
) != NULL
; }
1678 const wxChar
*GetClassName() const { return m_className
; }
1679 const wxChar
*GetBaseClassName1() const
1680 { return m_parents
[0] ? m_parents
[0]->GetClassName() : NULL
; }
1681 const wxChar
*GetBaseClassName2() const
1682 { return (m_parents
[0] && m_parents
[1]) ? m_parents
[1]->GetClassName() : NULL
; }
1683 const wxChar
*GetIncludeName() const { return m_unitName
; }
1684 const wxClassInfo
**GetParents() const { return m_parents
; }
1685 int GetSize() const { return m_objectSize
; }
1686 bool IsDynamic() const { return (NULL
!= m_objectConstructor
); }
1688 wxObjectConstructorFn
GetConstructor() const { return m_objectConstructor
; }
1689 static const wxClassInfo
*GetFirst() { return sm_first
; }
1690 const wxClassInfo
*GetNext() const { return m_next
; }
1691 static wxClassInfo
*FindClass(const wxChar
*className
);
1693 // Climb upwards through inheritance hierarchy.
1694 // Dual inheritance is catered for.
1696 bool IsKindOf(const wxClassInfo
*info
) const
1703 for ( int i
= 0 ; m_parents
[i
] ; ++ i
)
1705 if ( m_parents
[i
]->IsKindOf( info
) )
1712 // if there is a callback registered with that class it will be called
1713 // before this object will be written to disk, it can veto streaming out
1714 // this object by returning false, if this class has not registered a
1715 // callback, the search will go up the inheritance tree if no callback has
1716 // been registered true will be returned by default
1717 bool BeforeWriteObject( const wxObject
*obj
, wxWriter
*streamer
, wxPersister
*persister
, wxxVariantArray
&metadata
) const ;
1719 // gets the streaming callback from this class or any superclass
1720 wxObjectStreamingCallback
GetStreamingCallback() const ;
1722 #if WXWIN_COMPATIBILITY_2_4
1723 // Initializes parent pointers and hash table for fast searching.
1724 wxDEPRECATED( static void InitializeClasses() );
1725 // Cleans up hash table used for fast searching.
1726 wxDEPRECATED( static void CleanUpClasses() );
1728 static void CleanUp();
1730 // returns the first property
1731 const wxPropertyInfo
* GetFirstProperty() const { return m_firstProperty
; }
1733 // returns the first handler
1734 const wxHandlerInfo
* GetFirstHandler() const { return m_firstHandler
; }
1736 // Call the Create upon an instance of the class, in the end the object is fully
1738 virtual void Create (wxObject
*object
, int ParamCount
, wxxVariant
*Params
) const
1740 if ( ParamCount
!= m_constructorPropertiesCount
)
1742 wxLogError( _("Illegal Parameter Count for Create Method") ) ;
1745 m_constructor
->Create( object
, Params
) ;
1748 // get number of parameters for constructor
1749 virtual int GetCreateParamCount() const { return m_constructorPropertiesCount
; }
1751 // get n-th constructor parameter
1752 virtual const wxChar
* GetCreateParamName(int n
) const { return m_constructorProperties
[n
] ; }
1754 // Runtime access to objects for simple properties (get/set) by property name, and variant data
1755 virtual void SetProperty (wxObject
*object
, const wxChar
*propertyName
, const wxxVariant
&value
) const ;
1756 virtual wxxVariant
GetProperty (wxObject
*object
, const wxChar
*propertyName
) const;
1758 // Runtime access to objects for collection properties by property name
1759 virtual wxxVariantArray
GetPropertyCollection(wxObject
*object
, const wxChar
*propertyName
) const ;
1760 virtual void AddToPropertyCollection(wxObject
*object
, const wxChar
*propertyName
, const wxxVariant
& value
) const ;
1762 // we must be able to cast variants to wxObject pointers, templates seem not to be suitable
1763 wxObject
* VariantToInstance( wxxVariant
&data
) const
1765 if ( data
.GetTypeInfo()->GetKind() == wxT_OBJECT
)
1766 return m_variantToObjectConverter( data
) ;
1768 return m_variantOfPtrToObjectConverter( data
) ;
1771 wxxVariant
InstanceToVariant( wxObject
*object
) const { return m_objectToVariantConverter( object
) ; }
1773 // find property by name
1774 virtual const wxPropertyInfo
*FindPropertyInfo (const wxChar
*PropertyName
) const ;
1776 // find handler by name
1777 virtual const wxHandlerInfo
*FindHandlerInfo (const wxChar
*PropertyName
) const ;
1779 // find property by name
1780 virtual wxPropertyInfo
*FindPropertyInfoInThisClass (const wxChar
*PropertyName
) const ;
1782 // find handler by name
1783 virtual wxHandlerInfo
*FindHandlerInfoInThisClass (const wxChar
*PropertyName
) const ;
1785 // puts all the properties of this class and its superclasses in the map, as long as there is not yet
1786 // an entry with the same name (overriding mechanism)
1787 void GetProperties( wxPropertyInfoMap
&map
) const ;
1789 const wxChar
*m_className
;
1791 wxObjectConstructorFn m_objectConstructor
;
1793 // class info object live in a linked list:
1794 // pointers to its head and the next element in it
1796 static wxClassInfo
*sm_first
;
1797 wxClassInfo
*m_next
;
1799 // FIXME: this should be private (currently used directly by way too
1801 static wxHashTable
*sm_classTable
;
1804 wxPropertyInfo
* m_firstProperty
;
1805 wxHandlerInfo
* m_firstHandler
;
1807 const wxClassInfo
** m_parents
;
1808 const wxChar
* m_unitName
;
1810 wxConstructorBridge
* m_constructor
;
1811 const wxChar
** m_constructorProperties
;
1812 const int m_constructorPropertiesCount
;
1813 wxVariantToObjectConverter m_variantOfPtrToObjectConverter
;
1814 wxVariantToObjectConverter m_variantToObjectConverter
;
1815 wxObjectToVariantConverter m_objectToVariantConverter
;
1816 wxObjectStreamingCallback m_streamingCallback
;
1817 const wxPropertyAccessor
*FindAccessor (const wxChar
*propertyName
) const ;
1820 // InitializeClasses() helper
1821 static wxClassInfo
*GetBaseByName(const wxChar
*name
) ;
1824 // registers the class
1828 DECLARE_NO_COPY_CLASS(wxClassInfo
)
1832 WXDLLIMPEXP_BASE wxObject
*wxCreateDynamicObject(const wxChar
*name
);
1834 // ----------------------------------------------------------------------------
1836 // ----------------------------------------------------------------------------
1838 // this object leads to having a pure runtime-instantiation
1840 class WXDLLIMPEXP_BASE wxDynamicClassInfo
: public wxClassInfo
1842 friend class WXDLLIMPEXP_BASE wxDynamicObject
;
1844 wxDynamicClassInfo( const wxChar
*_UnitName
, const wxChar
*_ClassName
, const wxClassInfo
* superClass
) ;
1845 virtual ~wxDynamicClassInfo() ;
1847 // constructs a wxDynamicObject with an instance
1848 virtual wxObject
*AllocateObject() const ;
1850 // Call the Create method for a class
1851 virtual void Create (wxObject
*object
, int ParamCount
, wxxVariant
*Params
) const ;
1853 // get number of parameters for constructor
1854 virtual int GetCreateParamCount() const ;
1856 // get i-th constructor parameter
1857 virtual const wxChar
* GetCreateParamName(int i
) const ;
1859 // Runtime access to objects by property name, and variant data
1860 virtual void SetProperty (wxObject
*object
, const wxChar
*PropertyName
, const wxxVariant
&Value
) const ;
1861 virtual wxxVariant
GetProperty (wxObject
*object
, const wxChar
*PropertyName
) const ;
1863 // adds a property to this class at runtime
1864 void AddProperty( const wxChar
*propertyName
, const wxTypeInfo
* typeInfo
) ;
1866 // removes an existing runtime-property
1867 void RemoveProperty( const wxChar
*propertyName
) ;
1869 // renames an existing runtime-property
1870 void RenameProperty( const wxChar
*oldPropertyName
, const wxChar
*newPropertyName
) ;
1872 // as a handler to this class at runtime
1873 void AddHandler( const wxChar
*handlerName
, wxObjectEventFunction address
, const wxClassInfo
* eventClassInfo
) ;
1875 // removes an existing runtime-handler
1876 void RemoveHandler( const wxChar
*handlerName
) ;
1878 // renames an existing runtime-handler
1879 void RenameHandler( const wxChar
*oldHandlerName
, const wxChar
*newHandlerName
) ;
1881 struct wxDynamicClassInfoInternal
;
1882 wxDynamicClassInfoInternal
* m_data
;
1885 // ----------------------------------------------------------------------------
1886 // Dynamic class macros
1887 // ----------------------------------------------------------------------------
1889 #define _DECLARE_DYNAMIC_CLASS(name) \
1891 static wxClassInfo ms_classInfo; \
1892 static const wxClassInfo* ms_classParents[] ; \
1893 static wxPropertyInfo* GetPropertiesStatic() ; \
1894 static wxHandlerInfo* GetHandlersStatic() ; \
1895 static wxClassInfo *GetClassInfoStatic() \
1896 { return &name::ms_classInfo; } \
1897 virtual wxClassInfo *GetClassInfo() const \
1898 { return &name::ms_classInfo; }
1901 #define _DECLARE_DYNAMIC_CLASS(name) \
1903 static wxClassInfo ms_class##name; \
1904 static const wxClassInfo* ms_classParents##name[] ; \
1905 static wxPropertyInfo* GetPropertiesStatic() ; \
1906 static wxHandlerInfo* GetHandlersStatic() ; \
1907 static wxClassInfo *GetClassInfoStatic() \
1908 { return &name::ms_class##name; } \
1909 virtual wxClassInfo *GetClassInfo() const \
1910 { return &name::ms_class##name; }
1912 #define DECLARE_DYNAMIC_CLASS(name) \
1913 static wxConstructorBridge* ms_constructor ; \
1914 static const wxChar * ms_constructorProperties[] ; \
1915 static const int ms_constructorPropertiesCount ; \
1916 _DECLARE_DYNAMIC_CLASS(name)
1918 #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
1919 DECLARE_NO_ASSIGN_CLASS(name) \
1920 DECLARE_DYNAMIC_CLASS(name)
1922 #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \
1923 DECLARE_NO_COPY_CLASS(name) \
1924 DECLARE_DYNAMIC_CLASS(name)
1926 #define DECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name)
1927 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
1929 // -----------------------------------
1930 // for concrete classes
1931 // -----------------------------------
1933 // Single inheritance with one base class
1935 #define _TYPEINFO_CLASSES(n , toString , fromString ) \
1936 wxClassTypeInfo s_typeInfo##n(wxT_OBJECT , &n::ms_classInfo , toString , fromString , typeid(n).name()) ; \
1937 wxClassTypeInfo s_typeInfoPtr##n(wxT_OBJECT_PTR , &n::ms_classInfo , toString , fromString , typeid(n*).name()) ;
1939 #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit , callback) \
1940 wxObject* wxConstructorFor##name() \
1941 { return new name; } \
1942 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo ,NULL } ; \
1943 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.wxTEMPLATED_MEMBER_CALL(Get , name*) ; } \
1944 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1945 wxClassInfo name::ms_classInfo(name::ms_classParents , wxT(unit) , wxT(#name), \
1946 (int) sizeof(name), \
1947 (wxObjectConstructorFn) wxConstructorFor##name , \
1948 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::ms_constructor , name::ms_constructorProperties , \
1949 name::ms_constructorPropertiesCount , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name , callback);
1951 #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \
1952 wxObject* wxConstructorFor##name() \
1953 { return new name; } \
1954 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo ,NULL } ; \
1955 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return &data.wxTEMPLATED_MEMBER_CALL(Get , name) ; } \
1956 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.wxTEMPLATED_MEMBER_CALL(Get , name*) ; } \
1957 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1958 wxClassInfo name::ms_classInfo(name::ms_classParents , wxT(unit) , wxT(#name), \
1959 (int) sizeof(name), \
1960 (wxObjectConstructorFn) wxConstructorFor##name , \
1961 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::ms_constructor , name::ms_constructorProperties, \
1962 name::ms_constructorPropertiesCount , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name, callback);
1964 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \
1965 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" , NULL ) \
1966 _TYPEINFO_CLASSES(name, NULL , NULL) \
1967 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1968 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1969 wxCONSTRUCTOR_DUMMY( name )
1971 #define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \
1972 _IMPLEMENT_DYNAMIC_CLASS( name , basename , "" , NULL ) \
1973 _TYPEINFO_CLASSES(name, NULL , NULL) \
1974 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1975 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1976 wxCONSTRUCTOR_DUMMY( name )
1978 #define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \
1979 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , NULL ) \
1980 _TYPEINFO_CLASSES(name, NULL , NULL)
1982 #define IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name , basename , unit , callback ) \
1983 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , &callback ) \
1984 _TYPEINFO_CLASSES(name, NULL , NULL)
1986 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \
1987 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit , NULL ) \
1988 _TYPEINFO_CLASSES(name, NULL , NULL)
1990 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name , basename , unit , toString , fromString ) \
1991 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit , NULL ) \
1992 _TYPEINFO_CLASSES(name, toString , fromString)
1994 // this is for classes that do not derive from wxobject, there are no creators for these
1996 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name , unit ) \
1997 const wxClassInfo* name::ms_classParents[] = { NULL } ; \
1998 wxClassInfo name::ms_classInfo(name::ms_classParents , wxEmptyString , wxT(#name), \
1999 (int) sizeof(name), \
2000 (wxObjectConstructorFn) 0 , \
2001 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
2003 _TYPEINFO_CLASSES(name, NULL , NULL)
2005 // this is for subclasses that still do not derive from wxobject
2007 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name , basename, unit ) \
2008 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo ,NULL } ; \
2009 wxClassInfo name::ms_classInfo(name::ms_classParents , wxEmptyString , wxT(#name), \
2010 (int) sizeof(name), \
2011 (wxObjectConstructorFn) 0 , \
2012 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
2014 _TYPEINFO_CLASSES(name, NULL , NULL)
2017 // Multiple inheritance with two base classes
2019 #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit) \
2020 wxObject* wxConstructorFor##name() \
2021 { return new name; } \
2022 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo ,&basename2::ms_classInfo , NULL } ; \
2023 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.wxTEMPLATED_MEMBER_CALL(Get , name*) ; } \
2024 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
2025 wxClassInfo name::ms_classInfo(name::ms_classParents , wxT(unit) , wxT(#name), \
2026 (int) sizeof(name), \
2027 (wxObjectConstructorFn) wxConstructorFor##name , \
2028 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::ms_constructor , name::ms_constructorProperties , \
2029 name::ms_constructorPropertiesCount , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
2031 #define IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2) \
2032 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , "") \
2033 _TYPEINFO_CLASSES(name, NULL , NULL) \
2034 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
2035 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
2036 wxCONSTRUCTOR_DUMMY( name )
2038 #define IMPLEMENT_DYNAMIC_CLASS2_XTI( name , basename , basename2, unit) \
2039 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , unit) \
2040 _TYPEINFO_CLASSES(name, NULL , NULL)
2043 // -----------------------------------
2044 // for abstract classes
2045 // -----------------------------------
2047 // Single inheritance with one base class
2049 #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
2050 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo ,NULL } ; \
2051 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.wxTEMPLATED_MEMBER_CALL(Get , name*) ; } \
2052 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.wxTEMPLATED_MEMBER_CALL(Get , name*) ; } \
2053 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
2054 wxClassInfo name::ms_classInfo(name::ms_classParents , wxEmptyString , wxT(#name), \
2055 (int) sizeof(name), \
2056 (wxObjectConstructorFn) 0 , \
2057 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
2058 0 , wxVariantOfPtrToObjectConverter##name ,wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
2059 _TYPEINFO_CLASSES(name, NULL , NULL)
2061 #define IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
2062 _IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
2063 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
2064 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; }
2066 // Multiple inheritance with two base classes
2068 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
2069 wxClassInfo name::ms_classInfo(wxT(#name), wxT(#basename1), \
2070 wxT(#basename2), (int) sizeof(name), \
2071 (wxObjectConstructorFn) 0);
2073 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
2074 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
2076 #define wxBEGIN_EVENT_TABLE( a , b ) BEGIN_EVENT_TABLE( a , b )
2077 #define wxEND_EVENT_TABLE() END_EVENT_TABLE()
2079 // --------------------------------------------------------------------------
2080 // Collection Support
2081 // --------------------------------------------------------------------------
2083 template<typename iter
, typename collection_t
> void wxListCollectionToVariantArray( const collection_t
& coll
, wxxVariantArray
&value
)
2085 iter current
= coll
.GetFirst() ;
2088 value
.Add( new wxxVariant(current
->GetData()) ) ;
2089 current
= current
->GetNext();
2093 template<typename collection_t
> void wxArrayCollectionToVariantArray( const collection_t
& coll
, wxxVariantArray
&value
)
2095 for( size_t i
= 0 ; i
< coll
.GetCount() ; i
++ )
2097 value
.Add( new wxxVariant(coll
[i
]) ) ;
2102 #endif // _WX_XTIH__