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( wxGetTranslation(_T("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( wxGetTranslation(_T("String conversions not supported")) ) ; }
431 static wxTypeInfo
*FindType(const char *typeName
) { return FindType( wxString::FromAscii(typeName
) ) ; }
433 static wxTypeInfo
*FindType(const wxChar
*typeName
);
434 static wxTypeInfo
*FindType(const wxString typeName
)
437 return FindType( typeName
.wchar_str() );
439 return FindType( typeName
.char_str() );
448 converterToString_t m_toString
;
449 converterFromString_t m_fromString
;
451 static wxTypeInfoMap
* ms_typeTable
;
457 class WXDLLIMPEXP_BASE wxBuiltInTypeInfo
: public wxTypeInfo
460 wxBuiltInTypeInfo( wxTypeKind kind
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
, const wxString
&name
= wxEmptyString
) :
461 wxTypeInfo( kind
, to
, from
, name
)
462 { wxASSERT_MSG( GetKind() < wxT_SET
, wxT("Illegal Kind for Base Type") ) ; }
464 wxBuiltInTypeInfo( wxTypeKind kind
, converterToString_t to
, converterFromString_t from
, const char *name
) :
465 wxTypeInfo( kind
, to
, from
, name
)
466 { wxASSERT_MSG( GetKind() < wxT_SET
, wxT("Illegal Kind for Base Type") ) ; }
470 class WXDLLIMPEXP_BASE wxCustomTypeInfo
: public wxTypeInfo
473 wxCustomTypeInfo( const wxString
&name
, converterToString_t to
, converterFromString_t from
) :
474 wxTypeInfo( wxT_CUSTOM
, to
, from
, name
)
477 wxCustomTypeInfo( const char *name
, converterToString_t to
, converterFromString_t from
) :
478 wxTypeInfo( wxT_CUSTOM
, to
, from
, name
)
483 class WXDLLIMPEXP_BASE wxEnumTypeInfo
: public wxTypeInfo
486 typedef void (*converterToLong_t
)( const wxxVariant
& data
, long &result
) ;
487 typedef void (*converterFromLong_t
)( long data
, wxxVariant
&result
) ;
489 wxEnumTypeInfo( wxTypeKind kind
, wxEnumData
* enumInfo
, converterToString_t to
, converterFromString_t from
,
490 converterToLong_t toLong
, converterFromLong_t fromLong
, const wxString
&name
) :
491 wxTypeInfo( kind
, to
, from
, name
) , m_toLong( toLong
) , m_fromLong( fromLong
)
492 { wxASSERT_MSG( kind
== wxT_ENUM
|| kind
== wxT_SET
, wxT("Illegal Kind for Enum Type")) ; m_enumInfo
= enumInfo
;}
495 wxEnumTypeInfo( wxTypeKind kind
, wxEnumData
* enumInfo
, converterToString_t to
, converterFromString_t from
,
496 converterToLong_t toLong
, converterFromLong_t fromLong
, const char * name
) :
497 wxTypeInfo( kind
, to
, from
, name
) , m_toLong( toLong
) , m_fromLong( fromLong
)
498 { wxASSERT_MSG( kind
== wxT_ENUM
|| kind
== wxT_SET
, wxT("Illegal Kind for Enum Type")) ; m_enumInfo
= enumInfo
;}
500 const wxEnumData
* GetEnumData() const { return m_enumInfo
; }
502 // convert a wxxVariant holding data of this type into a long
503 void ConvertToLong( const wxxVariant
& data
, long &result
) const
505 { if( m_toLong
) (*m_toLong
)( data
, result
) ; else wxLogError( wxGetTranslation(_T("Long Conversions not supported")) ) ; }
507 // convert a long into a wxxVariant holding the corresponding data in this type
508 void ConvertFromLong( long data
, wxxVariant
&result
) const
509 { if( m_fromLong
) (*m_fromLong
)( data
, result
) ; else wxLogError( wxGetTranslation(_T("Long Conversions not supported")) ) ;}
512 converterToLong_t m_toLong
;
513 converterFromLong_t m_fromLong
;
515 wxEnumData
*m_enumInfo
; // Kind == wxT_ENUM or Kind == wxT_SET
518 class WXDLLIMPEXP_BASE wxClassTypeInfo
: public wxTypeInfo
521 wxClassTypeInfo( wxTypeKind kind
, wxClassInfo
* classInfo
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
, const wxString
&name
= wxEmptyString
) ;
523 wxClassTypeInfo( wxTypeKind kind
, wxClassInfo
* classInfo
, converterToString_t to
, converterFromString_t from
, const char *name
) ;
525 const wxClassInfo
*GetClassInfo() const { return m_classInfo
; }
527 wxClassInfo
*m_classInfo
; // Kind == wxT_OBJECT - could be NULL
530 class WXDLLIMPEXP_BASE wxCollectionTypeInfo
: public wxTypeInfo
533 wxCollectionTypeInfo( const wxString
&elementName
, converterToString_t to
, converterFromString_t from
, const wxString
&name
) :
534 wxTypeInfo( wxT_COLLECTION
, to
, from
, name
)
535 { m_elementTypeName
= elementName
; m_elementType
= NULL
;}
537 wxCollectionTypeInfo( const char *elementName
, converterToString_t to
, converterFromString_t from
, const char *name
) :
538 wxTypeInfo( wxT_COLLECTION
, to
, from
, name
)
539 { m_elementTypeName
= wxString::FromAscii( elementName
) ; m_elementType
= NULL
;}
541 const wxTypeInfo
* GetElementType() const
543 if ( m_elementType
== NULL
)
544 m_elementType
= wxTypeInfo::FindType( m_elementTypeName
) ;
545 return m_elementType
; }
547 mutable wxTypeInfo
* m_elementType
;
548 wxString m_elementTypeName
;
551 // a delegate is an exposed event source
553 class WXDLLIMPEXP_BASE wxDelegateTypeInfo
: public wxTypeInfo
556 wxDelegateTypeInfo( int eventType
, wxClassInfo
* eventClass
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
) ;
557 wxDelegateTypeInfo( int eventType
, int lastEventType
, wxClassInfo
* eventClass
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
) ;
558 int GetEventType() const { return m_eventType
; }
559 int GetLastEventType() const { return m_lastEventType
; }
560 const wxClassInfo
* GetEventClass() const { return m_eventClass
; }
562 const wxClassInfo
*m_eventClass
; // (extended will merge into classinfo)
564 int m_lastEventType
;
567 template<typename T
> const wxTypeInfo
* wxGetTypeInfo( T
* ) { return wxTypeInfo::FindType(typeid(T
).name()) ; }
569 // this macro is for usage with custom, non-object derived classes and structs, wxPoint is such a custom type
571 #if wxUSE_FUNC_TEMPLATE_POINTER
572 #define wxCUSTOM_TYPE_INFO( e , toString , fromString ) \
573 wxCustomTypeInfo s_typeInfo##e(typeid(e).name() , &toString , &fromString) ;
575 #define wxCUSTOM_TYPE_INFO( e , toString , fromString ) \
576 void ToString##e( const wxxVariant& data , wxString &result ) { toString(data, result); } \
577 void FromString##e( const wxString& data , wxxVariant &result ) { fromString(data, result); } \
578 wxCustomTypeInfo s_typeInfo##e(typeid(e).name() , &ToString##e , &FromString##e) ;
581 #define wxCOLLECTION_TYPE_INFO( element , collection ) \
582 wxCollectionTypeInfo s_typeInfo##collection( typeid(element).name() , NULL , NULL , typeid(collection).name() ) ;
584 // sometimes a compiler invents specializations that are nowhere called, use this macro to satisfy the refs, currently
585 // we don't have to play tricks, but if we will have to according to the compiler, we will use that macro for that
587 #define wxILLEGAL_TYPE_SPECIALIZATION( a )
589 // ----------------------------------------------------------------------------
590 // wxxVariant as typesafe data holder
591 // ----------------------------------------------------------------------------
593 class WXDLLIMPEXP_BASE wxxVariantData
596 virtual ~wxxVariantData() {}
598 // return a heap allocated duplicate
599 virtual wxxVariantData
* Clone() const = 0 ;
601 // returns the type info of the contentc
602 virtual const wxTypeInfo
* GetTypeInfo() const = 0 ;
605 template<typename T
> class wxxVariantDataT
: public wxxVariantData
608 wxxVariantDataT(const T
& d
) : m_data(d
) {}
609 virtual ~wxxVariantDataT() {}
611 // get a ref to the stored data
612 T
& Get() { return m_data
; }
614 // get a const ref to the stored data
615 const T
& Get() const { return m_data
; }
618 void Set(const T
& d
) { m_data
= d
; }
620 // return a heap allocated duplicate
621 virtual wxxVariantData
* Clone() const { return new wxxVariantDataT
<T
>( Get() ) ; }
623 // returns the type info of the contentc
624 virtual const wxTypeInfo
* GetTypeInfo() const { return wxGetTypeInfo( (T
*) NULL
) ; }
630 class WXDLLIMPEXP_BASE wxxVariant
633 wxxVariant() { m_data
= NULL
; }
634 wxxVariant( wxxVariantData
* data
, const wxString
& name
= wxEmptyString
) : m_data(data
) , m_name(name
) {}
635 wxxVariant( const wxxVariant
&d
) { if ( d
.m_data
) m_data
= d
.m_data
->Clone() ; else m_data
= NULL
; m_name
= d
.m_name
; }
637 template<typename T
> wxxVariant( const T
& data
, const wxString
& name
= wxEmptyString
) :
638 m_data(new wxxVariantDataT
<T
>(data
) ), m_name(name
) {}
640 ~wxxVariant() { delete m_data
; }
642 // get a ref to the stored data
643 template<typename T
> T
& Get(wxTEMPLATED_MEMBER_FIX(T
))
645 wxxVariantDataT
<T
> *dataptr
= dynamic_cast<wxxVariantDataT
<T
>*> (m_data
) ;
646 wxASSERT_MSG( dataptr
, wxString::Format(wxT("Cast to %s not possible"), typeid(T
).name()) ) ;
647 return dataptr
->Get() ;
650 // get a ref to the stored data
651 template<typename T
> const T
& Get(wxTEMPLATED_MEMBER_FIX(T
)) const
653 const wxxVariantDataT
<T
> *dataptr
= dynamic_cast<const wxxVariantDataT
<T
>*> (m_data
) ;
654 wxASSERT_MSG( dataptr
, wxString::Format(wxT("Cast to %s not possible"), typeid(T
).name()) ) ;
655 return dataptr
->Get() ;
658 bool IsEmpty() const { return m_data
== NULL
; }
660 template<typename T
> bool HasData(wxTEMPLATED_MEMBER_FIX(T
)) const
662 const wxxVariantDataT
<T
> *dataptr
= dynamic_cast<const wxxVariantDataT
<T
>*> (m_data
) ;
663 return dataptr
!= NULL
;
667 template<typename T
> void Set(const T
& data
) const
670 m_data
= new wxxVariantDataT
<T
>(data
) ;
673 wxxVariant
& operator=(const wxxVariant
&d
)
676 m_data
= d
.m_data
? d
.m_data
->Clone() : NULL
;
681 // gets the stored data casted to a wxObject* , returning NULL if cast is not possible
682 wxObject
* GetAsObject() ;
684 // get the typeinfo of the stored object
685 const wxTypeInfo
* GetTypeInfo() const { return m_data
->GetTypeInfo() ; }
687 // returns this value as string
688 wxString
GetAsString() const
691 GetTypeInfo()->ConvertToString( *this , s
) ;
694 const wxString
& GetName() const { return m_name
; }
696 wxxVariantData
* m_data
;
700 #include "wx/dynarray.h"
702 WX_DECLARE_OBJARRAY_WITH_DECL(wxxVariant
, wxxVariantArray
, class WXDLLIMPEXP_BASE
);
704 // templated streaming, every type must have their specialization for these methods
707 void wxStringReadValue( const wxString
&s
, T
&data
);
710 void wxStringWriteValue( wxString
&s
, const T
&data
);
713 void wxToStringConverter( const wxxVariant
&v
, wxString
&s
wxTEMPLATED_FUNCTION_FIX(T
)) { wxStringWriteValue( s
, v
.wxTEMPLATED_MEMBER_CALL(Get
, T
) ) ; }
716 void wxFromStringConverter( const wxString
&s
, wxxVariant
&v
wxTEMPLATED_FUNCTION_FIX(T
)) { T d
; wxStringReadValue( s
, d
) ; v
= wxxVariant(d
) ; }
718 // ----------------------------------------------------------------------------
721 // wxPropertyInfo is used to inquire of the property by name. It doesn't
722 // provide access to the property, only information about it. If you
723 // want access, look at wxPropertyAccessor.
724 // ----------------------------------------------------------------------------
726 class WXDLLIMPEXP_BASE wxSetter
729 wxSetter( const wxString name
) { m_name
= name
; }
730 virtual ~wxSetter() {}
731 virtual void Set( wxObject
*object
, const wxxVariant
&variantValue
) const = 0;
732 const wxString
& GetName() const { return m_name
; }
737 class WXDLLIMPEXP_BASE wxGetter
740 wxGetter( const wxString name
) { m_name
= name
; }
741 virtual ~wxGetter() {}
742 virtual void Get( const wxObject
*object
, wxxVariant
& result
) const = 0;
743 const wxString
& GetName() const { return m_name
; }
748 class WXDLLIMPEXP_BASE wxCollectionGetter
751 wxCollectionGetter( const wxString name
) { m_name
= name
; }
752 virtual ~wxCollectionGetter() {}
753 virtual void Get( const wxObject
*object
, wxxVariantArray
& result
) const = 0;
754 const wxString
& GetName() const { return m_name
; }
759 template<typename coll_t
> void WXDLLIMPEXP_BASE
wxCollectionToVariantArray( const coll_t
& coll
, wxxVariantArray
& result
) ;
761 class WXDLLIMPEXP_BASE wxAdder
764 wxAdder( const wxString name
) { m_name
= name
; }
765 virtual ~wxAdder() {}
766 virtual void Add( wxObject
*object
, const wxxVariant
&variantValue
) const= 0;
767 const wxString
& GetName() const { return m_name
; }
773 #define wxSETTER( property, Klass, valueType, setterMethod ) \
774 class wxSetter##property : public wxSetter \
777 wxINFUNC_CLASS_TYPE_FIX(Klass) \
778 wxSetter##property() : wxSetter( wxT(#setterMethod) ) {} \
779 virtual ~wxSetter##property() {} \
780 void Set( wxObject *object, const wxxVariant &variantValue ) const \
782 Klass *obj = dynamic_cast<Klass*>(object) ; \
783 if ( variantValue.wxTEMPLATED_MEMBER_CALL(HasData, valueType) ) \
784 obj->setterMethod(variantValue.wxTEMPLATED_MEMBER_CALL(Get , valueType)) ; \
786 obj->setterMethod(*variantValue.wxTEMPLATED_MEMBER_CALL(Get , valueType*)) ; \
790 #define wxGETTER( property, Klass, valueType , gettermethod ) \
791 class wxGetter##property : public wxGetter \
794 wxINFUNC_CLASS_TYPE_FIX(Klass) \
795 wxGetter##property() : wxGetter( wxT(#gettermethod) ) {} \
796 virtual ~wxGetter##property() {} \
797 void Get( const wxObject *object , wxxVariant &result) const \
799 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
800 result = wxxVariant( obj->gettermethod() ) ; \
804 #define wxADDER( property, Klass, valueType , addermethod ) \
805 class wxAdder##property : public wxAdder \
808 wxINFUNC_CLASS_TYPE_FIX(Klass) \
809 wxAdder##property() : wxAdder( wxT(#addermethod) ) {} \
810 virtual ~wxAdder##property() {} \
811 void Add( wxObject *object, const wxxVariant &variantValue ) const \
813 Klass *obj = dynamic_cast<Klass*>(object) ; \
814 if ( variantValue.wxTEMPLATED_MEMBER_CALL(HasData, valueType) ) \
815 obj->addermethod(variantValue.wxTEMPLATED_MEMBER_CALL(Get , valueType)) ; \
817 obj->addermethod(*variantValue.wxTEMPLATED_MEMBER_CALL(Get , valueType*)) ; \
821 #define wxCOLLECTION_GETTER( property, Klass, valueType , gettermethod ) \
822 class wxCollectionGetter##property : public wxCollectionGetter \
825 wxINFUNC_CLASS_TYPE_FIX(Klass) \
826 wxCollectionGetter##property() : wxCollectionGetter( wxT(#gettermethod) ) {} \
827 virtual ~wxCollectionGetter##property() {} \
828 void Get( const wxObject *object , wxxVariantArray &result) const \
830 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
831 wxCollectionToVariantArray( obj->gettermethod() , result ) ; \
835 class WXDLLIMPEXP_BASE wxPropertyAccessor
838 wxPropertyAccessor( wxSetter
*setter
, wxGetter
*getter
, wxAdder
*adder
, wxCollectionGetter
*collectionGetter
)
839 { m_setter
= setter
; m_getter
= getter
; m_adder
= adder
; m_collectionGetter
= collectionGetter
;}
841 virtual ~wxPropertyAccessor() {}
843 // Setting a simple property (non-collection)
844 virtual void SetProperty(wxObject
*object
, const wxxVariant
&value
) const
845 { if ( m_setter
) m_setter
->Set( object
, value
) ; else wxLogError( wxGetTranslation(_T("SetProperty called w/o valid setter")) ) ;}
847 // Getting a simple property (non-collection)
848 virtual void GetProperty(const wxObject
*object
, wxxVariant
&result
) const
849 { if ( m_getter
) m_getter
->Get( object
, result
) ; else wxLogError( wxGetTranslation(_T("GetProperty called w/o valid getter")) ) ;}
851 // Adding an element to a collection property
852 virtual void AddToPropertyCollection(wxObject
*object
, const wxxVariant
&value
) const
853 { if ( m_adder
) m_adder
->Add( object
, value
) ; else wxLogError( wxGetTranslation(_T("AddToPropertyCollection called w/o valid adder")) ) ;}
855 // Getting a collection property
856 virtual void GetPropertyCollection( const wxObject
*obj
, wxxVariantArray
&result
) const
857 { if ( m_collectionGetter
) m_collectionGetter
->Get( obj
, result
) ; else wxLogError( wxGetTranslation(_T("GetPropertyCollection called w/o valid collection getter")) ) ;}
859 virtual bool HasSetter() const { return m_setter
!= NULL
; }
860 virtual bool HasCollectionGetter() const { return m_collectionGetter
!= NULL
; }
861 virtual bool HasGetter() const { return m_getter
!= NULL
; }
862 virtual bool HasAdder() const { return m_adder
!= NULL
; }
864 virtual const wxString
& GetCollectionGetterName() const
865 { return m_collectionGetter
->GetName() ; }
866 virtual const wxString
& GetGetterName() const
867 { return m_getter
->GetName() ; }
868 virtual const wxString
& GetSetterName() const
869 { return m_setter
->GetName() ; }
870 virtual const wxString
& GetAdderName() const
871 { return m_adder
->GetName() ; }
877 wxCollectionGetter
* m_collectionGetter
;
880 class WXDLLIMPEXP_BASE wxGenericPropertyAccessor
: public wxPropertyAccessor
883 wxGenericPropertyAccessor( const wxString
&propName
) ;
884 virtual ~wxGenericPropertyAccessor() ;
886 void RenameProperty( const wxString
& WXUNUSED_UNLESS_DEBUG(oldName
),
887 const wxString
& newName
)
889 wxASSERT( oldName
== m_propertyName
) ; m_propertyName
= newName
;
891 virtual bool HasSetter() const { return true ; }
892 virtual bool HasGetter() const { return true ; }
893 virtual bool HasAdder() const { return false ; }
894 virtual bool HasCollectionGetter() const { return false ; }
896 virtual const wxString
& GetGetterName() const
897 { return m_getterName
; }
898 virtual const wxString
& GetSetterName() const
899 { return m_setterName
; }
901 virtual void SetProperty(wxObject
*object
, const wxxVariant
&value
) const ;
902 virtual void GetProperty(const wxObject
*object
, wxxVariant
&value
) const ;
904 // Adding an element to a collection property
905 virtual void AddToPropertyCollection(wxObject
*WXUNUSED(object
), const wxxVariant
&WXUNUSED(value
)) const
906 { wxLogError( wxGetTranslation(_T("AddToPropertyCollection called on a generic accessor")) ) ;}
908 // Getting a collection property
909 virtual void GetPropertyCollection( const wxObject
*WXUNUSED(obj
), wxxVariantArray
&WXUNUSED(result
)) const
910 { wxLogError ( wxGetTranslation(_T("GetPropertyCollection called on a generic accessor")) ) ;}
912 struct wxGenericPropertyAccessorInternal
;
913 wxGenericPropertyAccessorInternal
* m_data
;
914 wxString m_propertyName
;
915 wxString m_setterName
;
916 wxString m_getterName
;
919 typedef long wxPropertyInfoFlags
;
921 // will be removed in future releases
922 wxPROP_DEPRECATED
= 0x00000001 ,
923 // object graph property, will be streamed with priority (after constructor properties)
924 wxPROP_OBJECT_GRAPH
= 0x00000002 ,
925 // this will only be streamed out and in as enum/set, the internal representation is still a long
926 wxPROP_ENUM_STORE_LONG
= 0x00000004 ,
927 // don't stream out this property, needed eg to avoid streaming out children that are always created by their parents
928 wxPROP_DONT_STREAM
= 0x00000008 ,
931 class WXDLLIMPEXP_BASE wxPropertyInfo
933 friend class WXDLLIMPEXP_BASE wxDynamicClassInfo
;
935 wxPropertyInfo(wxPropertyInfo
* &iter
,
936 wxClassInfo
* itsClass
,
937 const wxString
& name
,
938 const wxString
& typeName
,
939 wxPropertyAccessor
*accessor
,
941 wxPropertyInfoFlags flags
= 0,
942 const wxString
& helpString
= wxEmptyString
,
943 const wxString
& groupString
= wxEmptyString
) :
944 m_itsClass(itsClass
),
947 m_typeName(typeName
) ,
948 m_collectionElementTypeInfo(NULL
),
949 m_accessor(accessor
),
952 m_helpString(helpString
),
953 m_groupString(groupString
)
959 wxPropertyInfo(wxPropertyInfo
* &iter
,
960 wxClassInfo
* itsClass
,
961 const wxString
& name
,
962 const char* typeName
,
963 wxPropertyAccessor
*accessor
,
965 wxPropertyInfoFlags flags
= 0,
966 const wxString
& helpString
= wxEmptyString
,
967 const wxString
& groupString
= wxEmptyString
) :
968 m_itsClass(itsClass
),
971 m_typeName(wxString::FromAscii(typeName
)) ,
972 m_collectionElementTypeInfo(NULL
),
973 m_accessor(accessor
),
976 m_helpString(helpString
),
977 m_groupString(groupString
)
982 wxPropertyInfo(wxPropertyInfo
* &iter
,
983 wxClassInfo
* itsClass
,
984 const wxString
& name
,
985 wxDelegateTypeInfo
* type
,
986 wxPropertyAccessor
*accessor
,
988 wxPropertyInfoFlags flags
= 0,
989 const wxString
& helpString
= wxEmptyString
,
990 const wxString
& groupString
= wxEmptyString
) :
991 m_itsClass(itsClass
),
994 m_collectionElementTypeInfo(NULL
),
995 m_accessor(accessor
),
998 m_helpString(helpString
),
999 m_groupString(groupString
)
1004 wxPropertyInfo(wxPropertyInfo
* &iter
,
1005 wxClassInfo
* itsClass
, const wxString
& name
,
1006 const wxString
& collectionTypeName
,
1007 const wxString
& elementTypeName
,
1008 wxPropertyAccessor
*accessor
,
1009 wxPropertyInfoFlags flags
= 0,
1010 const wxString
& helpString
= wxEmptyString
,
1011 const wxString
& groupString
= wxEmptyString
) :
1012 m_itsClass(itsClass
),
1015 m_typeName(collectionTypeName
) ,
1016 m_collectionElementTypeInfo(NULL
),
1017 m_collectionElementTypeName(elementTypeName
),
1018 m_accessor(accessor
) ,
1020 m_helpString(helpString
),
1021 m_groupString(groupString
)
1027 wxPropertyInfo(wxPropertyInfo
* &iter
,
1028 wxClassInfo
* itsClass
, const wxString
& name
,
1029 const char* collectionTypeName
,
1030 const char* elementTypeName
,
1031 wxPropertyAccessor
*accessor
,
1032 wxPropertyInfoFlags flags
= 0,
1033 const wxString
& helpString
= wxEmptyString
,
1034 const wxString
& groupString
= wxEmptyString
) :
1035 m_itsClass(itsClass
),
1038 m_typeName(wxString::FromAscii(collectionTypeName
)) ,
1039 m_collectionElementTypeInfo(NULL
),
1040 m_collectionElementTypeName(wxString::FromAscii(elementTypeName
)),
1041 m_accessor(accessor
) ,
1043 m_helpString(helpString
),
1044 m_groupString(groupString
)
1051 // return the class this property is declared in
1052 const wxClassInfo
* GetDeclaringClass() const { return m_itsClass
; }
1054 // return the name of this property
1055 const wxString
& GetName() const { return m_name
; }
1057 // returns the flags of this property
1058 wxPropertyInfoFlags
GetFlags() const { return m_flags
;}
1060 // returns the short help string of this property
1061 const wxString
& GetHelpString() const { return m_helpString
; }
1063 // returns the group string of this property
1064 const wxString
& GetGroupString() const { return m_groupString
; }
1066 // return the element type info of this property (for collections, otherwise NULL)
1067 const wxTypeInfo
* GetCollectionElementTypeInfo() const
1069 if ( m_collectionElementTypeInfo
== NULL
)
1070 m_collectionElementTypeInfo
= wxTypeInfo::FindType(m_collectionElementTypeName
) ;
1071 return m_collectionElementTypeInfo
;
1074 // return the type info of this property
1075 const wxTypeInfo
* GetTypeInfo() const
1077 if ( m_typeInfo
== NULL
)
1078 m_typeInfo
= wxTypeInfo::FindType(m_typeName
) ;
1082 // return the accessor for this property
1083 wxPropertyAccessor
* GetAccessor() const { return m_accessor
; }
1085 // returns NULL if this is the last property of this class
1086 wxPropertyInfo
* GetNext() const { return m_next
; }
1088 // returns the default value of this property, its kind may be wxT_VOID if it is not valid
1089 wxxVariant
GetDefaultValue() const { return m_defaultValue
; }
1091 void Insert(wxPropertyInfo
* &iter
)
1098 wxPropertyInfo
* i
= iter
;
1106 wxClassInfo
* m_itsClass
;
1108 mutable wxTypeInfo
* m_typeInfo
;
1109 wxString m_typeName
;
1110 mutable wxTypeInfo
* m_collectionElementTypeInfo
;
1111 wxString m_collectionElementTypeName
;
1112 wxPropertyAccessor
* m_accessor
;
1113 wxxVariant m_defaultValue
;
1114 wxPropertyInfoFlags m_flags
;
1115 wxString m_helpString
;
1116 wxString m_groupString
;
1117 // string representation of the default value
1118 // to be assigned by the designer to the property
1119 // when the component is dropped on the container.
1120 wxPropertyInfo
* m_next
;
1123 WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxPropertyInfo
* , wxPropertyInfoMap
, class WXDLLIMPEXP_BASE
) ;
1125 #define wxBEGIN_PROPERTIES_TABLE(theClass) \
1126 wxPropertyInfo *theClass::GetPropertiesStatic() \
1128 typedef theClass class_t; \
1129 static wxPropertyInfo* first = NULL ;
1131 #define wxEND_PROPERTIES_TABLE() \
1134 #define wxHIDE_PROPERTY( pname ) \
1135 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(void).name() ,NULL , wxxVariant() , wxPROP_DONT_STREAM , wxEmptyString , wxEmptyString ) ;
1137 #define wxPROPERTY( pname , type , setter , getter , defaultValue , flags , 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(type).name() ,&_accessor##pname , wxxVariant(defaultValue) , flags , group , help ) ;
1145 #define wxPROPERTY_FLAGS( pname , flags , type , setter , getter ,defaultValue , pflags , help , group) \
1146 wxSETTER( pname , class_t , type , setter ) \
1147 static wxSetter##pname _setter##pname ; \
1148 wxGETTER( pname , class_t , type , getter ) \
1149 static wxGetter##pname _getter##pname ; \
1150 static wxPropertyAccessor _accessor##pname( &_setter##pname , &_getter##pname , NULL , NULL ) ; \
1151 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(flags).name() ,&_accessor##pname , wxxVariant(defaultValue), wxPROP_ENUM_STORE_LONG | pflags , help , group ) ;
1153 #define wxREADONLY_PROPERTY( pname , type , getter ,defaultValue , flags , help , group) \
1154 wxGETTER( pname , class_t , type , getter ) \
1155 static wxGetter##pname _getter##pname ; \
1156 static wxPropertyAccessor _accessor##pname( NULL , &_getter##pname , NULL , NULL ) ; \
1157 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(type).name() ,&_accessor##pname , wxxVariant(defaultValue), flags , help , group ) ;
1159 #define wxREADONLY_PROPERTY_FLAGS( pname , flags , type , getter ,defaultValue , pflags , help , group) \
1160 wxGETTER( pname , class_t , type , getter ) \
1161 static wxGetter##pname _getter##pname ; \
1162 static wxPropertyAccessor _accessor##pname( NULL , &_getter##pname , NULL , NULL ) ; \
1163 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(flags).name() ,&_accessor##pname , wxxVariant(defaultValue), wxPROP_ENUM_STORE_LONG | pflags , help , group ) ;
1165 #define wxPROPERTY_COLLECTION( pname , colltype , addelemtype , adder , getter , flags , help , group ) \
1166 wxADDER( pname , class_t , addelemtype , adder ) \
1167 static wxAdder##pname _adder##pname ; \
1168 wxCOLLECTION_GETTER( pname , class_t , colltype , getter ) \
1169 static wxCollectionGetter##pname _collectionGetter##pname ; \
1170 static wxPropertyAccessor _accessor##pname( NULL , NULL ,&_adder##pname , &_collectionGetter##pname ) ; \
1171 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(colltype).name() ,typeid(addelemtype).name() ,&_accessor##pname , flags , help , group ) ;
1173 #define wxREADONLY_PROPERTY_COLLECTION( pname , colltype , addelemtype , getter , flags , help , group) \
1174 wxCOLLECTION_GETTER( pname , class_t , colltype , getter ) \
1175 static wxCollectionGetter##pname _collectionGetter##pname ; \
1176 static wxPropertyAccessor _accessor##pname( NULL , NULL , NULL , &_collectionGetter##pname ) ; \
1177 static wxPropertyInfo _propertyInfo##pname( first ,class_t::GetClassInfoStatic() , wxT(#pname) , typeid(colltype).name() ,typeid(addelemtype).name() ,&_accessor##pname , flags , help , group ) ;
1180 #define wxEVENT_PROPERTY( name , eventType , eventClass ) \
1181 static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \
1182 static wxPropertyInfo _propertyInfo##name( first ,class_t::GetClassInfoStatic() , wxT(#name) , &_typeInfo##name , NULL , wxxVariant() ) ; \
1184 #define wxEVENT_RANGE_PROPERTY( name , eventType , lastEventType , eventClass ) \
1185 static wxDelegateTypeInfo _typeInfo##name( eventType , lastEventType , CLASSINFO( eventClass ) ) ; \
1186 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , wxT(#name) , &_typeInfo##name , NULL , wxxVariant() ) ; \
1188 // ----------------------------------------------------------------------------
1189 // Implementation Helper for Simple Properties
1190 // ----------------------------------------------------------------------------
1192 #define wxIMPLEMENT_PROPERTY(name, type) \
1196 void Set##name( type const & p) { m_##name = p; } \
1197 type const & Get##name() const { return m_##name; }
1199 // ----------------------------------------------------------------------------
1202 // this is describing an event sink
1203 // ----------------------------------------------------------------------------
1205 class WXDLLIMPEXP_BASE wxHandlerInfo
1207 friend class WXDLLIMPEXP_BASE wxDynamicClassInfo
;
1209 wxHandlerInfo(wxHandlerInfo
* &iter
,
1210 wxClassInfo
* itsClass
,
1211 const wxString
& name
,
1212 wxObjectEventFunction address
,
1213 const wxClassInfo
* eventClassInfo
) :
1214 m_eventFunction(address
),
1216 m_eventClassInfo(eventClassInfo
) ,
1217 m_itsClass(itsClass
)
1224 wxHandlerInfo
* i
= iter
;
1234 // return the name of this handler
1235 const wxString
& GetName() const { return m_name
; }
1237 // return the class info of the event
1238 const wxClassInfo
*GetEventClassInfo() const { return m_eventClassInfo
; }
1240 // get the handler function pointer
1241 wxObjectEventFunction
GetEventFunction() const { return m_eventFunction
; }
1243 // returns NULL if this is the last handler of this class
1244 wxHandlerInfo
* GetNext() const { return m_next
; }
1246 // return the class this property is declared in
1247 const wxClassInfo
* GetDeclaringClass() const { return m_itsClass
; }
1250 wxObjectEventFunction m_eventFunction
;
1252 const wxClassInfo
* m_eventClassInfo
;
1253 wxHandlerInfo
* m_next
;
1254 wxClassInfo
* m_itsClass
;
1257 #define wxHANDLER(name,eventClassType) \
1258 static wxHandlerInfo _handlerInfo##name( first , class_t::GetClassInfoStatic() , wxT(#name) , (wxObjectEventFunction) (wxEventFunction) &name , CLASSINFO( eventClassType ) ) ;
1260 #define wxBEGIN_HANDLERS_TABLE(theClass) \
1261 wxHandlerInfo *theClass::GetHandlersStatic() \
1263 typedef theClass class_t; \
1264 static wxHandlerInfo* first = NULL ;
1266 #define wxEND_HANDLERS_TABLE() \
1269 // ----------------------------------------------------------------------------
1270 // Constructor Bridges
1272 // allow to set up constructors with params during runtime
1273 // ----------------------------------------------------------------------------
1275 class WXDLLIMPEXP_BASE wxConstructorBridge
1278 virtual ~wxConstructorBridge() {};
1279 virtual void Create(wxObject
* &o
, wxxVariant
*args
) = 0;
1282 // a direct constructor bridge calls the operator new for this class and
1283 // passes all params to the constructor. needed for classes that cannot be
1284 // instantiated using alloc-create semantics
1285 class WXDLLIMPEXP_BASE wxDirectConstructorBrigde
: public wxConstructorBridge
1288 virtual void Create(wxObject
* &o
, wxxVariant
*args
) = 0;
1291 // Creator Bridges for all Numbers of Params
1295 template<typename Class
>
1296 struct wxConstructorBridge_0
: public wxConstructorBridge
1298 void Create(wxObject
* &o
, wxxVariant
*)
1300 Class
*obj
= dynamic_cast<Class
*>(o
);
1305 struct wxConstructorBridge_Dummy
: public wxConstructorBridge
1307 void Create(wxObject
*&, wxxVariant
*)
1312 #define wxCONSTRUCTOR_0(klass) \
1313 wxConstructorBridge_0<klass> constructor##klass ; \
1314 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1315 const wxChar *klass::ms_constructorProperties[] = { NULL } ; \
1316 const int klass::ms_constructorPropertiesCount = 0 ;
1318 #define wxCONSTRUCTOR_DUMMY(klass) \
1319 wxConstructorBridge_Dummy constructor##klass ; \
1320 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1321 const wxChar *klass::ms_constructorProperties[] = { NULL } ; \
1322 const int klass::ms_constructorPropertiesCount = 0 ;
1326 template<typename Class
, typename T0
>
1327 struct wxConstructorBridge_1
: public wxConstructorBridge
1329 void Create(wxObject
* &o
, wxxVariant
*args
)
1331 Class
*obj
= dynamic_cast<Class
*>(o
);
1333 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
)
1338 #define wxCONSTRUCTOR_1(klass,t0,v0) \
1339 wxConstructorBridge_1<klass,t0> constructor##klass ; \
1340 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1341 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) } ; \
1342 const int klass::ms_constructorPropertiesCount = 1 ;
1346 template<typename Class
,
1347 typename T0
, typename T1
>
1348 struct wxConstructorBridge_2
: public wxConstructorBridge
1350 void Create(wxObject
* &o
, wxxVariant
*args
)
1352 Class
*obj
= dynamic_cast<Class
*>(o
);
1354 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1355 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
)
1360 #define wxCONSTRUCTOR_2(klass,t0,v0,t1,v1) \
1361 wxConstructorBridge_2<klass,t0,t1> constructor##klass ; \
1362 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1363 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) } ; \
1364 const int klass::ms_constructorPropertiesCount = 2;
1366 // direct constructor version
1368 template<typename Class
,
1369 typename T0
, typename T1
>
1370 struct wxDirectConstructorBridge_2
: public wxDirectConstructorBrigde
1372 void Create(wxObject
* &o
, wxxVariant
*args
)
1375 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1376 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
)
1381 #define wxDIRECT_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
1382 wxDirectConstructorBridge_2<klass,t0,t1> constructor##klass ; \
1383 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1384 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) } ; \
1385 const int klass::ms_constructorPropertiesCount = 2;
1390 template<typename Class
,
1391 typename T0
, typename T1
, typename T2
>
1392 struct wxConstructorBridge_3
: public wxConstructorBridge
1394 void Create(wxObject
* &o
, wxxVariant
*args
)
1396 Class
*obj
= dynamic_cast<Class
*>(o
);
1398 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1399 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1400 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
)
1405 #define wxCONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
1406 wxConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \
1407 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1408 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) } ; \
1409 const int klass::ms_constructorPropertiesCount = 3 ;
1411 // direct constructor version
1413 template<typename Class
,
1414 typename T0
, typename T1
, typename T2
>
1415 struct wxDirectConstructorBridge_3
: public wxDirectConstructorBrigde
1417 void Create(wxObject
* &o
, wxxVariant
*args
)
1420 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1421 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1422 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
)
1427 #define wxDIRECT_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
1428 wxDirectConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \
1429 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1430 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) } ; \
1431 const int klass::ms_constructorPropertiesCount = 3;
1435 template<typename Class
,
1436 typename T0
, typename T1
, typename T2
, typename T3
>
1437 struct wxConstructorBridge_4
: public wxConstructorBridge
1439 void Create(wxObject
* &o
, wxxVariant
*args
)
1441 Class
*obj
= dynamic_cast<Class
*>(o
);
1443 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1444 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1445 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
) ,
1446 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
)
1451 #define wxCONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
1452 wxConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass ; \
1453 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1454 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) } ; \
1455 const int klass::ms_constructorPropertiesCount = 4 ;
1459 template<typename Class
,
1460 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
>
1461 struct wxConstructorBridge_5
: public wxConstructorBridge
1463 void Create(wxObject
* &o
, wxxVariant
*args
)
1465 Class
*obj
= dynamic_cast<Class
*>(o
);
1467 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1468 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1469 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
) ,
1470 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
) ,
1471 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
)
1476 #define wxCONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
1477 wxConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass ; \
1478 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1479 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) } ; \
1480 const int klass::ms_constructorPropertiesCount = 5;
1484 template<typename Class
,
1485 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
1486 struct wxConstructorBridge_6
: public wxConstructorBridge
1488 void Create(wxObject
* &o
, wxxVariant
*args
)
1490 Class
*obj
= dynamic_cast<Class
*>(o
);
1492 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1493 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1494 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
) ,
1495 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
) ,
1496 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
) ,
1497 args
[5].wxTEMPLATED_MEMBER_CALL(Get
, T5
)
1502 #define wxCONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1503 wxConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1504 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1505 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) } ; \
1506 const int klass::ms_constructorPropertiesCount = 6;
1508 // direct constructor version
1510 template<typename Class
,
1511 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
1512 struct wxDirectConstructorBridge_6
: public wxDirectConstructorBrigde
1514 void Create(wxObject
* &o
, wxxVariant
*args
)
1517 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1518 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1519 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
) ,
1520 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
) ,
1521 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
) ,
1522 args
[5].wxTEMPLATED_MEMBER_CALL(Get
, T5
)
1527 #define wxDIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1528 wxDirectConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1529 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1530 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) } ; \
1531 const int klass::ms_constructorPropertiesCount = 6;
1535 template<typename Class
,
1536 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
>
1537 struct wxConstructorBridge_7
: public wxConstructorBridge
1539 void Create(wxObject
* &o
, wxxVariant
*args
)
1541 Class
*obj
= dynamic_cast<Class
*>(o
);
1543 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1544 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1545 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
) ,
1546 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
) ,
1547 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
) ,
1548 args
[5].wxTEMPLATED_MEMBER_CALL(Get
, T5
) ,
1549 args
[6].wxTEMPLATED_MEMBER_CALL(Get
, T6
)
1554 #define wxCONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
1555 wxConstructorBridge_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass ; \
1556 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1557 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) , wxT(#v6) } ; \
1558 const int klass::ms_constructorPropertiesCount = 7;
1562 template<typename Class
,
1563 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
, typename T7
>
1564 struct wxConstructorBridge_8
: public wxConstructorBridge
1566 void Create(wxObject
* &o
, wxxVariant
*args
)
1568 Class
*obj
= dynamic_cast<Class
*>(o
);
1570 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1571 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1572 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
) ,
1573 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
) ,
1574 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
) ,
1575 args
[5].wxTEMPLATED_MEMBER_CALL(Get
, T5
) ,
1576 args
[6].wxTEMPLATED_MEMBER_CALL(Get
, T6
) ,
1577 args
[7].wxTEMPLATED_MEMBER_CALL(Get
, T7
)
1582 #define wxCONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
1583 wxConstructorBridge_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass ; \
1584 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1585 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) , wxT(#v6) , wxT(#v7) } ; \
1586 const int klass::ms_constructorPropertiesCount = 8;
1587 // ----------------------------------------------------------------------------
1589 // ----------------------------------------------------------------------------
1591 typedef wxObject
*(*wxObjectConstructorFn
)(void);
1592 typedef wxObject
* (*wxVariantToObjectConverter
)( wxxVariant
&data
) ;
1593 typedef wxxVariant (*wxObjectToVariantConverter
)( wxObject
* ) ;
1595 class WXDLLIMPEXP_BASE wxWriter
;
1596 class WXDLLIMPEXP_BASE wxPersister
;
1598 typedef bool (*wxObjectStreamingCallback
) ( const wxObject
*, wxWriter
* , wxPersister
* , wxxVariantArray
& ) ;
1600 class WXDLLIMPEXP_BASE wxClassInfo
1602 friend class WXDLLIMPEXP_BASE wxPropertyInfo
;
1603 friend class WXDLLIMPEXP_BASE wxHandlerInfo
;
1605 wxClassInfo(const wxClassInfo
**_Parents
,
1606 const wxChar
*_UnitName
,
1607 const wxChar
*_ClassName
,
1609 wxObjectConstructorFn ctor
,
1610 wxPropertyInfo
*_Props
,
1611 wxHandlerInfo
*_Handlers
,
1612 wxConstructorBridge
* _Constructor
,
1613 const wxChar
** _ConstructorProperties
,
1614 const int _ConstructorPropertiesCount
,
1615 wxVariantToObjectConverter _PtrConverter1
,
1616 wxVariantToObjectConverter _Converter2
,
1617 wxObjectToVariantConverter _Converter3
,
1618 wxObjectStreamingCallback _streamingCallback
= NULL
1621 m_className(_ClassName
),
1623 m_objectConstructor(ctor
),
1625 m_firstProperty(_Props
),
1626 m_firstHandler(_Handlers
),
1627 m_parents(_Parents
),
1628 m_unitName(_UnitName
),
1629 m_constructor(_Constructor
),
1630 m_constructorProperties(_ConstructorProperties
),
1631 m_constructorPropertiesCount(_ConstructorPropertiesCount
),
1632 m_variantOfPtrToObjectConverter(_PtrConverter1
),
1633 m_variantToObjectConverter(_Converter2
),
1634 m_objectToVariantConverter(_Converter3
),
1635 m_streamingCallback(_streamingCallback
)
1641 wxClassInfo(const wxChar
*_UnitName
, const wxChar
*_ClassName
,
1642 const wxClassInfo
**_Parents
) :
1643 m_className(_ClassName
),
1645 m_objectConstructor(NULL
),
1647 m_firstProperty(NULL
),
1648 m_firstHandler(NULL
),
1649 m_parents(_Parents
),
1650 m_unitName(_UnitName
),
1651 m_constructor(NULL
),
1652 m_constructorProperties(NULL
),
1653 m_constructorPropertiesCount(0),
1654 m_variantOfPtrToObjectConverter(NULL
),
1655 m_variantToObjectConverter(NULL
),
1656 m_objectToVariantConverter(NULL
),
1657 m_streamingCallback(NULL
)
1663 virtual ~wxClassInfo() ;
1665 // allocates an instance of this class, this object does not have to be initialized or fully constructed
1666 // as this call will be followed by a call to Create
1667 virtual wxObject
*AllocateObject() const { return m_objectConstructor
? (*m_objectConstructor
)() : 0; }
1669 // 'old naming' for AllocateObject staying here for backward compatibility
1670 wxObject
*CreateObject() const { return AllocateObject() ; }
1672 // direct construction call for classes that cannot construct instances via alloc/create
1673 wxObject
*ConstructObject(int ParamCount
, wxxVariant
*Params
) const
1675 if ( ParamCount
!= m_constructorPropertiesCount
)
1677 wxLogError( wxGetTranslation(_T("Illegal Parameter Count for ConstructObject Method")) ) ;
1680 wxObject
*object
= NULL
;
1681 m_constructor
->Create( object
, Params
) ;
1685 bool NeedsDirectConstruction() const { return dynamic_cast<wxDirectConstructorBrigde
*>( m_constructor
) != NULL
; }
1687 const wxChar
*GetClassName() const { return m_className
; }
1688 const wxChar
*GetBaseClassName1() const
1689 { return m_parents
[0] ? m_parents
[0]->GetClassName() : NULL
; }
1690 const wxChar
*GetBaseClassName2() const
1691 { return (m_parents
[0] && m_parents
[1]) ? m_parents
[1]->GetClassName() : NULL
; }
1692 const wxChar
*GetIncludeName() const { return m_unitName
; }
1693 const wxClassInfo
**GetParents() const { return m_parents
; }
1694 int GetSize() const { return m_objectSize
; }
1695 bool IsDynamic() const { return (NULL
!= m_objectConstructor
); }
1697 wxObjectConstructorFn
GetConstructor() const { return m_objectConstructor
; }
1698 static const wxClassInfo
*GetFirst() { return sm_first
; }
1699 const wxClassInfo
*GetNext() const { return m_next
; }
1700 static wxClassInfo
*FindClass(const wxChar
*className
);
1702 // Climb upwards through inheritance hierarchy.
1703 // Dual inheritance is catered for.
1705 bool IsKindOf(const wxClassInfo
*info
) const
1712 for ( int i
= 0 ; m_parents
[i
] ; ++ i
)
1714 if ( m_parents
[i
]->IsKindOf( info
) )
1721 // if there is a callback registered with that class it will be called
1722 // before this object will be written to disk, it can veto streaming out
1723 // this object by returning false, if this class has not registered a
1724 // callback, the search will go up the inheritance tree if no callback has
1725 // been registered true will be returned by default
1726 bool BeforeWriteObject( const wxObject
*obj
, wxWriter
*streamer
, wxPersister
*persister
, wxxVariantArray
&metadata
) const ;
1728 // gets the streaming callback from this class or any superclass
1729 wxObjectStreamingCallback
GetStreamingCallback() const ;
1731 static void CleanUp();
1733 // returns the first property
1734 const wxPropertyInfo
* GetFirstProperty() const { return m_firstProperty
; }
1736 // returns the first handler
1737 const wxHandlerInfo
* GetFirstHandler() const { return m_firstHandler
; }
1739 // Call the Create upon an instance of the class, in the end the object is fully
1741 virtual void Create (wxObject
*object
, int ParamCount
, wxxVariant
*Params
) const
1743 if ( ParamCount
!= m_constructorPropertiesCount
)
1745 wxLogError( wxGetTranslation(_T("Illegal Parameter Count for Create Method")) ) ;
1748 m_constructor
->Create( object
, Params
) ;
1751 // get number of parameters for constructor
1752 virtual int GetCreateParamCount() const { return m_constructorPropertiesCount
; }
1754 // get n-th constructor parameter
1755 virtual const wxChar
* GetCreateParamName(int n
) const { return m_constructorProperties
[n
] ; }
1757 // Runtime access to objects for simple properties (get/set) by property name, and variant data
1758 virtual void SetProperty (wxObject
*object
, const wxChar
*propertyName
, const wxxVariant
&value
) const ;
1759 virtual wxxVariant
GetProperty (wxObject
*object
, const wxChar
*propertyName
) const;
1761 // Runtime access to objects for collection properties by property name
1762 virtual wxxVariantArray
GetPropertyCollection(wxObject
*object
, const wxChar
*propertyName
) const ;
1763 virtual void AddToPropertyCollection(wxObject
*object
, const wxChar
*propertyName
, const wxxVariant
& value
) const ;
1765 // we must be able to cast variants to wxObject pointers, templates seem not to be suitable
1766 wxObject
* VariantToInstance( wxxVariant
&data
) const
1768 if ( data
.GetTypeInfo()->GetKind() == wxT_OBJECT
)
1769 return m_variantToObjectConverter( data
) ;
1771 return m_variantOfPtrToObjectConverter( data
) ;
1774 wxxVariant
InstanceToVariant( wxObject
*object
) const { return m_objectToVariantConverter( object
) ; }
1776 // find property by name
1777 virtual const wxPropertyInfo
*FindPropertyInfo (const wxChar
*PropertyName
) const ;
1779 // find handler by name
1780 virtual const wxHandlerInfo
*FindHandlerInfo (const wxChar
*PropertyName
) const ;
1782 // find property by name
1783 virtual wxPropertyInfo
*FindPropertyInfoInThisClass (const wxChar
*PropertyName
) const ;
1785 // find handler by name
1786 virtual wxHandlerInfo
*FindHandlerInfoInThisClass (const wxChar
*PropertyName
) const ;
1788 // puts all the properties of this class and its superclasses in the map, as long as there is not yet
1789 // an entry with the same name (overriding mechanism)
1790 void GetProperties( wxPropertyInfoMap
&map
) const ;
1792 const wxChar
*m_className
;
1794 wxObjectConstructorFn m_objectConstructor
;
1796 // class info object live in a linked list:
1797 // pointers to its head and the next element in it
1799 static wxClassInfo
*sm_first
;
1800 wxClassInfo
*m_next
;
1802 // FIXME: this should be private (currently used directly by way too
1804 static wxHashTable
*sm_classTable
;
1807 wxPropertyInfo
* m_firstProperty
;
1808 wxHandlerInfo
* m_firstHandler
;
1810 const wxClassInfo
** m_parents
;
1811 const wxChar
* m_unitName
;
1813 wxConstructorBridge
* m_constructor
;
1814 const wxChar
** m_constructorProperties
;
1815 const int m_constructorPropertiesCount
;
1816 wxVariantToObjectConverter m_variantOfPtrToObjectConverter
;
1817 wxVariantToObjectConverter m_variantToObjectConverter
;
1818 wxObjectToVariantConverter m_objectToVariantConverter
;
1819 wxObjectStreamingCallback m_streamingCallback
;
1820 const wxPropertyAccessor
*FindAccessor (const wxChar
*propertyName
) const ;
1823 // registers the class
1827 DECLARE_NO_COPY_CLASS(wxClassInfo
)
1831 WXDLLIMPEXP_BASE wxObject
*wxCreateDynamicObject(const wxChar
*name
);
1833 // ----------------------------------------------------------------------------
1835 // ----------------------------------------------------------------------------
1837 // this object leads to having a pure runtime-instantiation
1839 class WXDLLIMPEXP_BASE wxDynamicClassInfo
: public wxClassInfo
1841 friend class WXDLLIMPEXP_BASE wxDynamicObject
;
1843 wxDynamicClassInfo( const wxChar
*_UnitName
, const wxChar
*_ClassName
, const wxClassInfo
* superClass
) ;
1844 virtual ~wxDynamicClassInfo() ;
1846 // constructs a wxDynamicObject with an instance
1847 virtual wxObject
*AllocateObject() const ;
1849 // Call the Create method for a class
1850 virtual void Create (wxObject
*object
, int ParamCount
, wxxVariant
*Params
) const ;
1852 // get number of parameters for constructor
1853 virtual int GetCreateParamCount() const ;
1855 // get i-th constructor parameter
1856 virtual const wxChar
* GetCreateParamName(int i
) const ;
1858 // Runtime access to objects by property name, and variant data
1859 virtual void SetProperty (wxObject
*object
, const wxChar
*PropertyName
, const wxxVariant
&Value
) const ;
1860 virtual wxxVariant
GetProperty (wxObject
*object
, const wxChar
*PropertyName
) const ;
1862 // adds a property to this class at runtime
1863 void AddProperty( const wxChar
*propertyName
, const wxTypeInfo
* typeInfo
) ;
1865 // removes an existing runtime-property
1866 void RemoveProperty( const wxChar
*propertyName
) ;
1868 // renames an existing runtime-property
1869 void RenameProperty( const wxChar
*oldPropertyName
, const wxChar
*newPropertyName
) ;
1871 // as a handler to this class at runtime
1872 void AddHandler( const wxChar
*handlerName
, wxObjectEventFunction address
, const wxClassInfo
* eventClassInfo
) ;
1874 // removes an existing runtime-handler
1875 void RemoveHandler( const wxChar
*handlerName
) ;
1877 // renames an existing runtime-handler
1878 void RenameHandler( const wxChar
*oldHandlerName
, const wxChar
*newHandlerName
) ;
1880 struct wxDynamicClassInfoInternal
;
1881 wxDynamicClassInfoInternal
* m_data
;
1884 // ----------------------------------------------------------------------------
1885 // Dynamic class macros
1886 // ----------------------------------------------------------------------------
1888 #define _DECLARE_DYNAMIC_CLASS(name) \
1890 static wxClassInfo ms_classInfo; \
1891 static const wxClassInfo* ms_classParents[] ; \
1892 static wxPropertyInfo* GetPropertiesStatic() ; \
1893 static wxHandlerInfo* GetHandlersStatic() ; \
1894 static wxClassInfo *GetClassInfoStatic() \
1895 { return &name::ms_classInfo; } \
1896 virtual wxClassInfo *GetClassInfo() const \
1897 { return &name::ms_classInfo; }
1900 #define _DECLARE_DYNAMIC_CLASS(name) \
1902 static wxClassInfo ms_class##name; \
1903 static const wxClassInfo* ms_classParents##name[] ; \
1904 static wxPropertyInfo* GetPropertiesStatic() ; \
1905 static wxHandlerInfo* GetHandlersStatic() ; \
1906 static wxClassInfo *GetClassInfoStatic() \
1907 { return &name::ms_class##name; } \
1908 virtual wxClassInfo *GetClassInfo() const \
1909 { return &name::ms_class##name; }
1911 #define DECLARE_DYNAMIC_CLASS(name) \
1912 static wxConstructorBridge* ms_constructor ; \
1913 static const wxChar * ms_constructorProperties[] ; \
1914 static const int ms_constructorPropertiesCount ; \
1915 _DECLARE_DYNAMIC_CLASS(name)
1917 #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
1918 DECLARE_NO_ASSIGN_CLASS(name) \
1919 DECLARE_DYNAMIC_CLASS(name)
1921 #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \
1922 DECLARE_NO_COPY_CLASS(name) \
1923 DECLARE_DYNAMIC_CLASS(name)
1925 #define DECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name)
1926 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
1928 // -----------------------------------
1929 // for concrete classes
1930 // -----------------------------------
1932 // Single inheritance with one base class
1934 #define _TYPEINFO_CLASSES(n , toString , fromString ) \
1935 wxClassTypeInfo s_typeInfo##n(wxT_OBJECT , &n::ms_classInfo , toString , fromString , typeid(n).name()) ; \
1936 wxClassTypeInfo s_typeInfoPtr##n(wxT_OBJECT_PTR , &n::ms_classInfo , toString , fromString , typeid(n*).name()) ;
1938 #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit , callback) \
1939 wxObject* wxConstructorFor##name() \
1940 { return new name; } \
1941 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo ,NULL } ; \
1942 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.wxTEMPLATED_MEMBER_CALL(Get , name*) ; } \
1943 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1944 wxClassInfo name::ms_classInfo(name::ms_classParents , wxT(unit) , wxT(#name), \
1945 (int) sizeof(name), \
1946 (wxObjectConstructorFn) wxConstructorFor##name , \
1947 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::ms_constructor , name::ms_constructorProperties , \
1948 name::ms_constructorPropertiesCount , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name , callback);
1950 #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \
1951 wxObject* wxConstructorFor##name() \
1952 { return new name; } \
1953 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo ,NULL } ; \
1954 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return &data.wxTEMPLATED_MEMBER_CALL(Get , name) ; } \
1955 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.wxTEMPLATED_MEMBER_CALL(Get , name*) ; } \
1956 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1957 wxClassInfo name::ms_classInfo(name::ms_classParents , wxT(unit) , wxT(#name), \
1958 (int) sizeof(name), \
1959 (wxObjectConstructorFn) wxConstructorFor##name , \
1960 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::ms_constructor , name::ms_constructorProperties, \
1961 name::ms_constructorPropertiesCount , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name, callback);
1963 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \
1964 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" , NULL ) \
1965 _TYPEINFO_CLASSES(name, NULL , NULL) \
1966 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1967 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1968 wxCONSTRUCTOR_DUMMY( name )
1970 #define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \
1971 _IMPLEMENT_DYNAMIC_CLASS( name , basename , "" , NULL ) \
1972 _TYPEINFO_CLASSES(name, NULL , NULL) \
1973 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1974 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1975 wxCONSTRUCTOR_DUMMY( name )
1977 #define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \
1978 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , NULL ) \
1979 _TYPEINFO_CLASSES(name, NULL , NULL)
1981 #define IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name , basename , unit , callback ) \
1982 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , &callback ) \
1983 _TYPEINFO_CLASSES(name, NULL , NULL)
1985 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \
1986 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit , NULL ) \
1987 _TYPEINFO_CLASSES(name, NULL , NULL)
1989 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name , basename , unit , toString , fromString ) \
1990 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit , NULL ) \
1991 _TYPEINFO_CLASSES(name, toString , fromString)
1993 // this is for classes that do not derive from wxobject, there are no creators for these
1995 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name , unit ) \
1996 const wxClassInfo* name::ms_classParents[] = { NULL } ; \
1997 wxClassInfo name::ms_classInfo(name::ms_classParents , wxEmptyString , wxT(#name), \
1998 (int) sizeof(name), \
1999 (wxObjectConstructorFn) 0 , \
2000 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
2002 _TYPEINFO_CLASSES(name, NULL , NULL)
2004 // this is for subclasses that still do not derive from wxobject
2006 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name , basename, unit ) \
2007 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo ,NULL } ; \
2008 wxClassInfo name::ms_classInfo(name::ms_classParents , wxEmptyString , wxT(#name), \
2009 (int) sizeof(name), \
2010 (wxObjectConstructorFn) 0 , \
2011 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
2013 _TYPEINFO_CLASSES(name, NULL , NULL)
2016 // Multiple inheritance with two base classes
2018 #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit, callback) \
2019 wxObject* wxConstructorFor##name() \
2020 { return new name; } \
2021 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo ,&basename2::ms_classInfo , NULL } ; \
2022 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.wxTEMPLATED_MEMBER_CALL(Get , name*) ; } \
2023 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
2024 wxClassInfo name::ms_classInfo(name::ms_classParents , wxT(unit) , wxT(#name), \
2025 (int) sizeof(name), \
2026 (wxObjectConstructorFn) wxConstructorFor##name , \
2027 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::ms_constructor , name::ms_constructorProperties , \
2028 name::ms_constructorPropertiesCount , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name , callback);
2030 #define IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2) \
2031 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , "", NULL) \
2032 _TYPEINFO_CLASSES(name, NULL , NULL) \
2033 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
2034 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
2035 wxCONSTRUCTOR_DUMMY( name )
2037 #define IMPLEMENT_DYNAMIC_CLASS2_XTI( name , basename , basename2, unit) \
2038 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , unit, NULL) \
2039 _TYPEINFO_CLASSES(name, NULL , NULL)
2042 // -----------------------------------
2043 // for abstract classes
2044 // -----------------------------------
2046 // Single inheritance with one base class
2048 #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
2049 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo ,NULL } ; \
2050 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.wxTEMPLATED_MEMBER_CALL(Get , name*) ; } \
2051 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.wxTEMPLATED_MEMBER_CALL(Get , name*) ; } \
2052 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
2053 wxClassInfo name::ms_classInfo(name::ms_classParents , wxEmptyString , wxT(#name), \
2054 (int) sizeof(name), \
2055 (wxObjectConstructorFn) 0 , \
2056 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
2057 0 , wxVariantOfPtrToObjectConverter##name ,wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
2058 _TYPEINFO_CLASSES(name, NULL , NULL)
2060 #define IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
2061 _IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
2062 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
2063 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; }
2065 // Multiple inheritance with two base classes
2067 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
2068 wxClassInfo name::ms_classInfo(wxT(#name), wxT(#basename1), \
2069 wxT(#basename2), (int) sizeof(name), \
2070 (wxObjectConstructorFn) 0);
2072 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
2073 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
2075 #define wxBEGIN_EVENT_TABLE( a , b ) BEGIN_EVENT_TABLE( a , b )
2076 #define wxEND_EVENT_TABLE() END_EVENT_TABLE()
2078 // --------------------------------------------------------------------------
2079 // Collection Support
2080 // --------------------------------------------------------------------------
2082 template<typename iter
, typename collection_t
> void wxListCollectionToVariantArray( const collection_t
& coll
, wxxVariantArray
&value
)
2084 iter current
= coll
.GetFirst() ;
2087 value
.Add( new wxxVariant(current
->GetData()) ) ;
2088 current
= current
->GetNext();
2092 template<typename collection_t
> void wxArrayCollectionToVariantArray( const collection_t
& coll
, wxxVariantArray
&value
)
2094 for( size_t i
= 0 ; i
< coll
.GetCount() ; i
++ )
2096 value
.Add( new wxxVariant(coll
[i
]) ) ;
2101 #endif // _WX_XTIH__