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 wxHashTable_Node
;
88 class WXDLLIMPEXP_BASE wxObjectRefData
;
89 class WXDLLIMPEXP_BASE wxEvent
;
90 class WXDLLIMPEXP_BASE wxEvtHandler
;
92 typedef void (wxObject::*wxObjectEventFunction
)(wxEvent
&);
94 #if wxUSE_FUNC_TEMPLATE_POINTER
95 # define wxTO_STRING(type) wxToStringConverter<type>
96 # define wxTO_STRING_IMP(type)
97 # define wxFROM_STRING(type) wxFromStringConverter<type>
98 # define wxFROM_STRING_IMP(type)
100 # define wxTO_STRING(type) ToString##type
101 # define wxTO_STRING_IMP(type) inline void ToString##type( const wxxVariant& data , wxString &result ) { wxToStringConverter<type>(data, result); }
102 # define wxFROM_STRING(type) FromString##type
103 # define wxFROM_STRING_IMP(type) inline void FromString##type( const wxString& data , wxxVariant &result ) { wxFromStringConverter<type>(data, result); }
106 // ----------------------------------------------------------------------------
109 // In the header files there would no change from pure c++ code, in the
110 // implementation, an enum would have
111 // to be enumerated eg :
113 // wxBEGIN_ENUM( wxFlavor )
114 // wxENUM_MEMBER( Vanilla )
115 // wxENUM_MEMBER( Chocolate )
116 // wxENUM_MEMBER( Strawberry )
117 // wxEND_ENUM( wxFlavor )
118 // ----------------------------------------------------------------------------
120 struct WXDLLIMPEXP_BASE wxEnumMemberData
122 const wxChar
* m_name
;
126 class WXDLLIMPEXP_BASE wxEnumData
129 wxEnumData( wxEnumMemberData
* data
) ;
131 // returns true if the member has been found and sets the int value
132 // pointed to accordingly (if ptr != null )
133 // if not found returns false, value left unchanged
134 bool HasEnumMemberValue( const wxChar
*name
, int *value
= NULL
) const ;
136 // returns the value of the member, if not found in debug mode an
137 // assert is issued, in release 0 is returned
138 int GetEnumMemberValue(const wxChar
*name
) const ;
140 // returns the name of the enum member having the passed in value
141 // returns an emtpy string if not found
142 const wxChar
*GetEnumMemberName(int value
) const ;
144 // returns the number of members in this enum
145 int GetEnumCount() const { return m_count
; }
147 // returns the value of the nth member
148 int GetEnumMemberValueByIndex( int n
) const ;
150 // returns the value of the nth member
151 const wxChar
*GetEnumMemberNameByIndex( int n
) const ;
153 wxEnumMemberData
*m_members
;
157 #define wxBEGIN_ENUM( e ) \
158 wxEnumMemberData s_enumDataMembers##e[] = {
160 #define wxENUM_MEMBER( v ) { wxT(#v), v } ,
162 #define wxEND_ENUM( e ) { NULL , 0 } } ; \
163 wxEnumData s_enumData##e( s_enumDataMembers##e ) ; \
164 wxEnumData *wxGetEnumData(e) { return &s_enumData##e ; } \
165 template<> void wxStringReadValue(const wxString& s , e &data ) \
167 data = (e) s_enumData##e.GetEnumMemberValue(s) ; \
169 template<> void wxStringWriteValue(wxString &s , const e &data ) \
171 s = s_enumData##e.GetEnumMemberName((int)data) ; \
173 void FromLong##e( long data , wxxVariant& result ) { result = wxxVariant((e)data) ;} \
174 void ToLong##e( const wxxVariant& data , long &result ) { result = (long) data.wxTEMPLATED_MEMBER_CALL(Get , e) ;} \
175 wxTO_STRING_IMP( e ) \
176 wxFROM_STRING_IMP( e ) \
177 wxEnumTypeInfo s_typeInfo##e(wxT_ENUM , &s_enumData##e , &wxTO_STRING( e ) , &wxFROM_STRING( e ) , &ToLong##e , &FromLong##e , typeid(e).name() ) ;
179 // ----------------------------------------------------------------------------
191 // typedef wxBitset<wxFlavor> wxCoupe ;
193 // in the implementation file :
195 // wxBEGIN_ENUM( wxFlavor )
196 // wxENUM_MEMBER( Vanilla )
197 // wxENUM_MEMBER( Chocolate )
198 // wxENUM_MEMBER( Strawberry )
199 // wxEND_ENUM( wxFlavor )
201 // wxIMPLEMENT_SET_STREAMING( wxCoupe , wxFlavor )
203 // implementation note : no partial specialization for streaming, but a delegation to a
206 // ----------------------------------------------------------------------------
208 // in order to remove dependancy on string tokenizer
209 void WXDLLIMPEXP_BASE
wxSetStringToArray( const wxString
&s
, wxArrayString
&array
) ;
212 void wxSetFromString(const wxString
&s
, wxBitset
<e
> &data
)
214 wxEnumData
* edata
= wxGetEnumData((e
) 0) ;
217 wxArrayString array
;
218 wxSetStringToArray( s
, array
) ;
220 for ( int i
= 0 ; i
< array
.Count() ; ++i
)
224 if ( edata
->HasEnumMemberValue( flag
, &ivalue
) )
226 data
.set( (e
) ivalue
) ;
232 void wxSetToString( wxString
&s
, const wxBitset
<e
> &data
)
234 wxEnumData
* edata
= wxGetEnumData((e
) 0) ;
235 int count
= edata
->GetEnumCount() ;
238 for ( i
= 0 ; i
< count
; i
++ )
240 e value
= (e
) edata
->GetEnumMemberValueByIndex(i
) ;
241 if ( data
.test( value
) )
243 // this could also be done by the templated calls
246 s
+= edata
->GetEnumMemberNameByIndex(i
) ;
251 #define wxIMPLEMENT_SET_STREAMING(SetName,e) \
252 template<> void wxStringReadValue(const wxString &s , wxBitset<e> &data ) \
254 wxSetFromString( s , data ) ; \
256 template<> void wxStringWriteValue( wxString &s , const wxBitset<e> &data ) \
258 wxSetToString( s , data ) ; \
260 void FromLong##SetName( long data , wxxVariant& result ) { result = wxxVariant(SetName((unsigned long)data)) ;} \
261 void ToLong##SetName( const wxxVariant& data , long &result ) { result = (long) data.wxTEMPLATED_MEMBER_CALL(Get , SetName).to_ulong() ;} \
262 wxTO_STRING_IMP( SetName ) \
263 wxFROM_STRING_IMP( SetName ) \
264 wxEnumTypeInfo s_typeInfo##SetName(wxT_SET , &s_enumData##e , &wxTO_STRING( SetName ) , &wxFROM_STRING( SetName ) , &ToLong##SetName , &FromLong##SetName, typeid(SetName).name() ) ; \
268 void wxFlagsFromString(const wxString
&s
, e
&data
)
270 wxEnumData
* edata
= wxGetEnumData((e
*) 0) ;
273 wxArrayString array
;
274 wxSetStringToArray( s
, array
) ;
276 for ( size_t i
= 0 ; i
< array
.Count() ; ++i
)
280 if ( edata
->HasEnumMemberValue( flag
, &ivalue
) )
282 data
.m_data
|= ivalue
;
288 void wxFlagsToString( wxString
&s
, const e
& data
)
290 wxEnumData
* edata
= wxGetEnumData((e
*) 0) ;
291 int count
= edata
->GetEnumCount() ;
294 long dataValue
= data
.m_data
;
295 for ( i
= 0 ; i
< count
; i
++ )
297 int value
= edata
->GetEnumMemberValueByIndex(i
) ;
298 // make this to allow for multi-bit constants to work
299 if ( value
&& ( dataValue
& value
) == value
)
301 // clear the flags we just set
302 dataValue
&= ~value
;
303 // this could also be done by the templated calls
306 s
+= edata
->GetEnumMemberNameByIndex(i
) ;
311 #define wxBEGIN_FLAGS( e ) \
312 wxEnumMemberData s_enumDataMembers##e[] = {
314 #define wxFLAGS_MEMBER( v ) { wxT(#v), v } ,
316 #define wxEND_FLAGS( e ) { NULL , 0 } } ; \
317 wxEnumData s_enumData##e( s_enumDataMembers##e ) ; \
318 wxEnumData *wxGetEnumData(e*) { return &s_enumData##e ; } \
319 template<> void wxStringReadValue(const wxString &s , e &data ) \
321 wxFlagsFromString<e>( s , data ) ; \
323 template<> void wxStringWriteValue( wxString &s , const e& data ) \
325 wxFlagsToString<e>( s , data ) ; \
327 void FromLong##e( long data , wxxVariant& result ) { result = wxxVariant(e(data)) ;} \
328 void ToLong##e( const wxxVariant& data , long &result ) { result = (long) data.wxTEMPLATED_MEMBER_CALL(Get , e).m_data ;} \
329 wxTO_STRING_IMP( e ) \
330 wxFROM_STRING_IMP( e ) \
331 wxEnumTypeInfo s_typeInfo##e(wxT_SET , &s_enumData##e , &wxTO_STRING( e ) , &wxFROM_STRING( e ) , &ToLong##e , &FromLong##e, typeid(e).name() ) ;
332 // ----------------------------------------------------------------------------
334 // ----------------------------------------------------------------------------
337 // All data exposed by the RTTI is characterized using the following classes.
338 // The first characterization is done by wxTypeKind. All enums up to and including
339 // wxT_CUSTOM represent so called simple types. These cannot be divided any further.
340 // They can be converted to and from wxStrings, that's all.
345 wxT_VOID
= 0, // unknown type
355 wxT_STRING
, // must be wxString
356 wxT_SET
, // must be wxBitset<> template
358 wxT_CUSTOM
, // user defined type (e.g. wxPoint)
360 wxT_LAST_SIMPLE_TYPE_KIND
= wxT_CUSTOM
,
362 wxT_OBJECT_PTR
, // object reference
363 wxT_OBJECT
, // embedded object
364 wxT_COLLECTION
, // collection
366 wxT_DELEGATE
, // for connecting against an event source
368 wxT_LAST_TYPE_KIND
= wxT_DELEGATE
// sentinel for bad data, asserts, debugging
371 class WXDLLIMPEXP_BASE wxxVariant
;
372 class WXDLLIMPEXP_BASE wxTypeInfo
;
374 WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxTypeInfo
* , wxTypeInfoMap
, class WXDLLIMPEXP_BASE
) ;
376 class WXDLLIMPEXP_BASE wxTypeInfo
379 typedef void (*converterToString_t
)( const wxxVariant
& data
, wxString
&result
) ;
380 typedef void (*converterFromString_t
)( const wxString
& data
, wxxVariant
&result
) ;
382 wxTypeInfo(wxTypeKind kind
,
383 converterToString_t to
= NULL
, converterFromString_t from
= NULL
,
384 const wxString
&name
= wxEmptyString
):
385 m_toString(to
), m_fromString(from
), m_kind(kind
), m_name(name
)
390 wxTypeInfo(wxTypeKind kind
,
391 converterToString_t to
, converterFromString_t from
,
393 m_toString(to
), m_fromString(from
), m_kind(kind
), m_name(wxString::FromAscii(name
))
399 virtual ~wxTypeInfo()
404 // return the kind of this type (wxT_... constants)
405 wxTypeKind
GetKind() const { return m_kind
; }
407 // returns the unique name of this type
408 const wxString
& GetTypeName() const { return m_name
; }
410 // is this type a delegate type
411 bool IsDelegateType() const { return m_kind
== wxT_DELEGATE
; }
413 // is this type a custom type
414 bool IsCustomType() const { return m_kind
== wxT_CUSTOM
; }
416 // is this type an object type
417 bool IsObjectType() const { return m_kind
== wxT_OBJECT
|| m_kind
== wxT_OBJECT_PTR
; }
419 // can the content of this type be converted to and from strings ?
420 bool HasStringConverters() const { return m_toString
!= NULL
&& m_fromString
!= NULL
; }
422 // convert a wxxVariant holding data of this type into a string
423 void ConvertToString( const wxxVariant
& data
, wxString
&result
) const
425 { if ( m_toString
) (*m_toString
)( data
, result
) ; else wxLogError( wxGetTranslation(_T("String conversions not supported")) ) ; }
427 // convert a string into a wxxVariant holding the corresponding data in this type
428 void ConvertFromString( const wxString
& data
, wxxVariant
&result
) const
429 { if( m_fromString
) (*m_fromString
)( data
, result
) ; else wxLogError( wxGetTranslation(_T("String conversions not supported")) ) ; }
432 static wxTypeInfo
*FindType(const char *typeName
) { return FindType( wxString::FromAscii(typeName
) ) ; }
434 static wxTypeInfo
*FindType(const wxChar
*typeName
);
435 static wxTypeInfo
*FindType(const wxString typeName
)
438 return FindType( typeName
.wchar_str() );
440 return FindType( typeName
.char_str() );
449 converterToString_t m_toString
;
450 converterFromString_t m_fromString
;
452 static wxTypeInfoMap
* ms_typeTable
;
458 class WXDLLIMPEXP_BASE wxBuiltInTypeInfo
: public wxTypeInfo
461 wxBuiltInTypeInfo( wxTypeKind kind
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
, const wxString
&name
= wxEmptyString
) :
462 wxTypeInfo( kind
, to
, from
, name
)
463 { wxASSERT_MSG( GetKind() < wxT_SET
, wxT("Illegal Kind for Base Type") ) ; }
465 wxBuiltInTypeInfo( wxTypeKind kind
, converterToString_t to
, converterFromString_t from
, const char *name
) :
466 wxTypeInfo( kind
, to
, from
, name
)
467 { wxASSERT_MSG( GetKind() < wxT_SET
, wxT("Illegal Kind for Base Type") ) ; }
471 class WXDLLIMPEXP_BASE wxCustomTypeInfo
: public wxTypeInfo
474 wxCustomTypeInfo( const wxString
&name
, converterToString_t to
, converterFromString_t from
) :
475 wxTypeInfo( wxT_CUSTOM
, to
, from
, name
)
478 wxCustomTypeInfo( const char *name
, converterToString_t to
, converterFromString_t from
) :
479 wxTypeInfo( wxT_CUSTOM
, to
, from
, name
)
484 class WXDLLIMPEXP_BASE wxEnumTypeInfo
: public wxTypeInfo
487 typedef void (*converterToLong_t
)( const wxxVariant
& data
, long &result
) ;
488 typedef void (*converterFromLong_t
)( long data
, wxxVariant
&result
) ;
490 wxEnumTypeInfo( wxTypeKind kind
, wxEnumData
* enumInfo
, converterToString_t to
, converterFromString_t from
,
491 converterToLong_t toLong
, converterFromLong_t fromLong
, const wxString
&name
) :
492 wxTypeInfo( kind
, to
, from
, name
) , m_toLong( toLong
) , m_fromLong( fromLong
)
493 { wxASSERT_MSG( kind
== wxT_ENUM
|| kind
== wxT_SET
, wxT("Illegal Kind for Enum Type")) ; m_enumInfo
= enumInfo
;}
496 wxEnumTypeInfo( wxTypeKind kind
, wxEnumData
* enumInfo
, converterToString_t to
, converterFromString_t from
,
497 converterToLong_t toLong
, converterFromLong_t fromLong
, const char * name
) :
498 wxTypeInfo( kind
, to
, from
, name
) , m_toLong( toLong
) , m_fromLong( fromLong
)
499 { wxASSERT_MSG( kind
== wxT_ENUM
|| kind
== wxT_SET
, wxT("Illegal Kind for Enum Type")) ; m_enumInfo
= enumInfo
;}
501 const wxEnumData
* GetEnumData() const { return m_enumInfo
; }
503 // convert a wxxVariant holding data of this type into a long
504 void ConvertToLong( const wxxVariant
& data
, long &result
) const
506 { if( m_toLong
) (*m_toLong
)( data
, result
) ; else wxLogError( wxGetTranslation(_T("Long Conversions not supported")) ) ; }
508 // convert a long into a wxxVariant holding the corresponding data in this type
509 void ConvertFromLong( long data
, wxxVariant
&result
) const
510 { if( m_fromLong
) (*m_fromLong
)( data
, result
) ; else wxLogError( wxGetTranslation(_T("Long Conversions not supported")) ) ;}
513 converterToLong_t m_toLong
;
514 converterFromLong_t m_fromLong
;
516 wxEnumData
*m_enumInfo
; // Kind == wxT_ENUM or Kind == wxT_SET
519 class WXDLLIMPEXP_BASE wxClassTypeInfo
: public wxTypeInfo
522 wxClassTypeInfo( wxTypeKind kind
, wxClassInfo
* classInfo
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
, const wxString
&name
= wxEmptyString
) ;
524 wxClassTypeInfo( wxTypeKind kind
, wxClassInfo
* classInfo
, converterToString_t to
, converterFromString_t from
, const char *name
) ;
526 const wxClassInfo
*GetClassInfo() const { return m_classInfo
; }
528 wxClassInfo
*m_classInfo
; // Kind == wxT_OBJECT - could be NULL
531 class WXDLLIMPEXP_BASE wxCollectionTypeInfo
: public wxTypeInfo
534 wxCollectionTypeInfo( const wxString
&elementName
, converterToString_t to
, converterFromString_t from
, const wxString
&name
) :
535 wxTypeInfo( wxT_COLLECTION
, to
, from
, name
)
536 { m_elementTypeName
= elementName
; m_elementType
= NULL
;}
538 wxCollectionTypeInfo( const char *elementName
, converterToString_t to
, converterFromString_t from
, const char *name
) :
539 wxTypeInfo( wxT_COLLECTION
, to
, from
, name
)
540 { m_elementTypeName
= wxString::FromAscii( elementName
) ; m_elementType
= NULL
;}
542 const wxTypeInfo
* GetElementType() const
544 if ( m_elementType
== NULL
)
545 m_elementType
= wxTypeInfo::FindType( m_elementTypeName
) ;
546 return m_elementType
; }
548 mutable wxTypeInfo
* m_elementType
;
549 wxString m_elementTypeName
;
552 // a delegate is an exposed event source
554 class WXDLLIMPEXP_BASE wxDelegateTypeInfo
: public wxTypeInfo
557 wxDelegateTypeInfo( int eventType
, wxClassInfo
* eventClass
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
) ;
558 wxDelegateTypeInfo( int eventType
, int lastEventType
, wxClassInfo
* eventClass
, converterToString_t to
= NULL
, converterFromString_t from
= NULL
) ;
559 int GetEventType() const { return m_eventType
; }
560 int GetLastEventType() const { return m_lastEventType
; }
561 const wxClassInfo
* GetEventClass() const { return m_eventClass
; }
563 const wxClassInfo
*m_eventClass
; // (extended will merge into classinfo)
565 int m_lastEventType
;
568 template<typename T
> const wxTypeInfo
* wxGetTypeInfo( T
* ) { return wxTypeInfo::FindType(typeid(T
).name()) ; }
570 // this macro is for usage with custom, non-object derived classes and structs, wxPoint is such a custom type
572 #if wxUSE_FUNC_TEMPLATE_POINTER
573 #define wxCUSTOM_TYPE_INFO( e , toString , fromString ) \
574 wxCustomTypeInfo s_typeInfo##e(typeid(e).name() , &toString , &fromString) ;
576 #define wxCUSTOM_TYPE_INFO( e , toString , fromString ) \
577 void ToString##e( const wxxVariant& data , wxString &result ) { toString(data, result); } \
578 void FromString##e( const wxString& data , wxxVariant &result ) { fromString(data, result); } \
579 wxCustomTypeInfo s_typeInfo##e(typeid(e).name() , &ToString##e , &FromString##e) ;
582 #define wxCOLLECTION_TYPE_INFO( element , collection ) \
583 wxCollectionTypeInfo s_typeInfo##collection( typeid(element).name() , NULL , NULL , typeid(collection).name() ) ;
585 // sometimes a compiler invents specializations that are nowhere called, use this macro to satisfy the refs, currently
586 // we don't have to play tricks, but if we will have to according to the compiler, we will use that macro for that
588 #define wxILLEGAL_TYPE_SPECIALIZATION( a )
590 // ----------------------------------------------------------------------------
591 // wxxVariant as typesafe data holder
592 // ----------------------------------------------------------------------------
594 class WXDLLIMPEXP_BASE wxxVariantData
597 virtual ~wxxVariantData() {}
599 // return a heap allocated duplicate
600 virtual wxxVariantData
* Clone() const = 0 ;
602 // returns the type info of the contentc
603 virtual const wxTypeInfo
* GetTypeInfo() const = 0 ;
606 template<typename T
> class wxxVariantDataT
: public wxxVariantData
609 wxxVariantDataT(const T
& d
) : m_data(d
) {}
610 virtual ~wxxVariantDataT() {}
612 // get a ref to the stored data
613 T
& Get() { return m_data
; }
615 // get a const ref to the stored data
616 const T
& Get() const { return m_data
; }
619 void Set(const T
& d
) { m_data
= d
; }
621 // return a heap allocated duplicate
622 virtual wxxVariantData
* Clone() const { return new wxxVariantDataT
<T
>( Get() ) ; }
624 // returns the type info of the contentc
625 virtual const wxTypeInfo
* GetTypeInfo() const { return wxGetTypeInfo( (T
*) NULL
) ; }
631 class WXDLLIMPEXP_BASE wxxVariant
634 wxxVariant() { m_data
= NULL
; }
635 wxxVariant( wxxVariantData
* data
, const wxString
& name
= wxEmptyString
) : m_data(data
) , m_name(name
) {}
636 wxxVariant( const wxxVariant
&d
) { if ( d
.m_data
) m_data
= d
.m_data
->Clone() ; else m_data
= NULL
; m_name
= d
.m_name
; }
638 template<typename T
> wxxVariant( const T
& data
, const wxString
& name
= wxEmptyString
) :
639 m_data(new wxxVariantDataT
<T
>(data
) ), m_name(name
) {}
641 ~wxxVariant() { delete m_data
; }
643 // get a ref to the stored data
644 template<typename T
> T
& Get(wxTEMPLATED_MEMBER_FIX(T
))
646 wxxVariantDataT
<T
> *dataptr
= dynamic_cast<wxxVariantDataT
<T
>*> (m_data
) ;
647 wxASSERT_MSG( dataptr
, wxString::Format(wxT("Cast to %s not possible"), typeid(T
).name()) ) ;
648 return dataptr
->Get() ;
651 // get a ref to the stored data
652 template<typename T
> const T
& Get(wxTEMPLATED_MEMBER_FIX(T
)) const
654 const wxxVariantDataT
<T
> *dataptr
= dynamic_cast<const wxxVariantDataT
<T
>*> (m_data
) ;
655 wxASSERT_MSG( dataptr
, wxString::Format(wxT("Cast to %s not possible"), typeid(T
).name()) ) ;
656 return dataptr
->Get() ;
659 bool IsEmpty() const { return m_data
== NULL
; }
661 template<typename T
> bool HasData(wxTEMPLATED_MEMBER_FIX(T
)) const
663 const wxxVariantDataT
<T
> *dataptr
= dynamic_cast<const wxxVariantDataT
<T
>*> (m_data
) ;
664 return dataptr
!= NULL
;
668 template<typename T
> void Set(const T
& data
) const
671 m_data
= new wxxVariantDataT
<T
>(data
) ;
674 wxxVariant
& operator=(const wxxVariant
&d
)
677 m_data
= d
.m_data
? d
.m_data
->Clone() : NULL
;
682 // gets the stored data casted to a wxObject* , returning NULL if cast is not possible
683 wxObject
* GetAsObject() ;
685 // get the typeinfo of the stored object
686 const wxTypeInfo
* GetTypeInfo() const { return m_data
->GetTypeInfo() ; }
688 // returns this value as string
689 wxString
GetAsString() const
692 GetTypeInfo()->ConvertToString( *this , s
) ;
695 const wxString
& GetName() const { return m_name
; }
697 wxxVariantData
* m_data
;
701 #include "wx/dynarray.h"
703 WX_DECLARE_OBJARRAY_WITH_DECL(wxxVariant
, wxxVariantArray
, class WXDLLIMPEXP_BASE
);
705 // templated streaming, every type must have their specialization for these methods
708 void wxStringReadValue( const wxString
&s
, T
&data
);
711 void wxStringWriteValue( wxString
&s
, const T
&data
);
714 void wxToStringConverter( const wxxVariant
&v
, wxString
&s
wxTEMPLATED_FUNCTION_FIX(T
)) { wxStringWriteValue( s
, v
.wxTEMPLATED_MEMBER_CALL(Get
, T
) ) ; }
717 void wxFromStringConverter( const wxString
&s
, wxxVariant
&v
wxTEMPLATED_FUNCTION_FIX(T
)) { T d
; wxStringReadValue( s
, d
) ; v
= wxxVariant(d
) ; }
719 // ----------------------------------------------------------------------------
722 // wxPropertyInfo is used to inquire of the property by name. It doesn't
723 // provide access to the property, only information about it. If you
724 // want access, look at wxPropertyAccessor.
725 // ----------------------------------------------------------------------------
727 class WXDLLIMPEXP_BASE wxSetter
730 wxSetter( const wxString name
) { m_name
= name
; }
731 virtual ~wxSetter() {}
732 virtual void Set( wxObject
*object
, const wxxVariant
&variantValue
) const = 0;
733 const wxString
& GetName() const { return m_name
; }
738 class WXDLLIMPEXP_BASE wxGetter
741 wxGetter( const wxString name
) { m_name
= name
; }
742 virtual ~wxGetter() {}
743 virtual void Get( const wxObject
*object
, wxxVariant
& result
) const = 0;
744 const wxString
& GetName() const { return m_name
; }
749 class WXDLLIMPEXP_BASE wxCollectionGetter
752 wxCollectionGetter( const wxString name
) { m_name
= name
; }
753 virtual ~wxCollectionGetter() {}
754 virtual void Get( const wxObject
*object
, wxxVariantArray
& result
) const = 0;
755 const wxString
& GetName() const { return m_name
; }
760 template<typename coll_t
> void WXDLLIMPEXP_BASE
wxCollectionToVariantArray( const coll_t
& coll
, wxxVariantArray
& result
) ;
762 class WXDLLIMPEXP_BASE wxAdder
765 wxAdder( const wxString name
) { m_name
= name
; }
766 virtual ~wxAdder() {}
767 virtual void Add( wxObject
*object
, const wxxVariant
&variantValue
) const= 0;
768 const wxString
& GetName() const { return m_name
; }
774 #define wxSETTER( property, Klass, valueType, setterMethod ) \
775 class wxSetter##property : public wxSetter \
778 wxINFUNC_CLASS_TYPE_FIX(Klass) \
779 wxSetter##property() : wxSetter( wxT(#setterMethod) ) {} \
780 virtual ~wxSetter##property() {} \
781 void Set( wxObject *object, const wxxVariant &variantValue ) const \
783 Klass *obj = dynamic_cast<Klass*>(object) ; \
784 if ( variantValue.wxTEMPLATED_MEMBER_CALL(HasData, valueType) ) \
785 obj->setterMethod(variantValue.wxTEMPLATED_MEMBER_CALL(Get , valueType)) ; \
787 obj->setterMethod(*variantValue.wxTEMPLATED_MEMBER_CALL(Get , valueType*)) ; \
791 #define wxGETTER( property, Klass, valueType , gettermethod ) \
792 class wxGetter##property : public wxGetter \
795 wxINFUNC_CLASS_TYPE_FIX(Klass) \
796 wxGetter##property() : wxGetter( wxT(#gettermethod) ) {} \
797 virtual ~wxGetter##property() {} \
798 void Get( const wxObject *object , wxxVariant &result) const \
800 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
801 result = wxxVariant( obj->gettermethod() ) ; \
805 #define wxADDER( property, Klass, valueType , addermethod ) \
806 class wxAdder##property : public wxAdder \
809 wxINFUNC_CLASS_TYPE_FIX(Klass) \
810 wxAdder##property() : wxAdder( wxT(#addermethod) ) {} \
811 virtual ~wxAdder##property() {} \
812 void Add( wxObject *object, const wxxVariant &variantValue ) const \
814 Klass *obj = dynamic_cast<Klass*>(object) ; \
815 if ( variantValue.wxTEMPLATED_MEMBER_CALL(HasData, valueType) ) \
816 obj->addermethod(variantValue.wxTEMPLATED_MEMBER_CALL(Get , valueType)) ; \
818 obj->addermethod(*variantValue.wxTEMPLATED_MEMBER_CALL(Get , valueType*)) ; \
822 #define wxCOLLECTION_GETTER( property, Klass, valueType , gettermethod ) \
823 class wxCollectionGetter##property : public wxCollectionGetter \
826 wxINFUNC_CLASS_TYPE_FIX(Klass) \
827 wxCollectionGetter##property() : wxCollectionGetter( wxT(#gettermethod) ) {} \
828 virtual ~wxCollectionGetter##property() {} \
829 void Get( const wxObject *object , wxxVariantArray &result) const \
831 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
832 wxCollectionToVariantArray( obj->gettermethod() , result ) ; \
836 class WXDLLIMPEXP_BASE wxPropertyAccessor
839 wxPropertyAccessor( wxSetter
*setter
, wxGetter
*getter
, wxAdder
*adder
, wxCollectionGetter
*collectionGetter
)
840 { m_setter
= setter
; m_getter
= getter
; m_adder
= adder
; m_collectionGetter
= collectionGetter
;}
842 virtual ~wxPropertyAccessor() {}
844 // Setting a simple property (non-collection)
845 virtual void SetProperty(wxObject
*object
, const wxxVariant
&value
) const
846 { if ( m_setter
) m_setter
->Set( object
, value
) ; else wxLogError( wxGetTranslation(_T("SetProperty called w/o valid setter")) ) ;}
848 // Getting a simple property (non-collection)
849 virtual void GetProperty(const wxObject
*object
, wxxVariant
&result
) const
850 { if ( m_getter
) m_getter
->Get( object
, result
) ; else wxLogError( wxGetTranslation(_T("GetProperty called w/o valid getter")) ) ;}
852 // Adding an element to a collection property
853 virtual void AddToPropertyCollection(wxObject
*object
, const wxxVariant
&value
) const
854 { if ( m_adder
) m_adder
->Add( object
, value
) ; else wxLogError( wxGetTranslation(_T("AddToPropertyCollection called w/o valid adder")) ) ;}
856 // Getting a collection property
857 virtual void GetPropertyCollection( const wxObject
*obj
, wxxVariantArray
&result
) const
858 { if ( m_collectionGetter
) m_collectionGetter
->Get( obj
, result
) ; else wxLogError( wxGetTranslation(_T("GetPropertyCollection called w/o valid collection getter")) ) ;}
860 virtual bool HasSetter() const { return m_setter
!= NULL
; }
861 virtual bool HasCollectionGetter() const { return m_collectionGetter
!= NULL
; }
862 virtual bool HasGetter() const { return m_getter
!= NULL
; }
863 virtual bool HasAdder() const { return m_adder
!= NULL
; }
865 virtual const wxString
& GetCollectionGetterName() const
866 { return m_collectionGetter
->GetName() ; }
867 virtual const wxString
& GetGetterName() const
868 { return m_getter
->GetName() ; }
869 virtual const wxString
& GetSetterName() const
870 { return m_setter
->GetName() ; }
871 virtual const wxString
& GetAdderName() const
872 { return m_adder
->GetName() ; }
878 wxCollectionGetter
* m_collectionGetter
;
881 class WXDLLIMPEXP_BASE wxGenericPropertyAccessor
: public wxPropertyAccessor
884 wxGenericPropertyAccessor( const wxString
&propName
) ;
885 virtual ~wxGenericPropertyAccessor() ;
887 void RenameProperty( const wxString
& WXUNUSED_UNLESS_DEBUG(oldName
),
888 const wxString
& newName
)
890 wxASSERT( oldName
== m_propertyName
) ; m_propertyName
= newName
;
892 virtual bool HasSetter() const { return true ; }
893 virtual bool HasGetter() const { return true ; }
894 virtual bool HasAdder() const { return false ; }
895 virtual bool HasCollectionGetter() const { return false ; }
897 virtual const wxString
& GetGetterName() const
898 { return m_getterName
; }
899 virtual const wxString
& GetSetterName() const
900 { return m_setterName
; }
902 virtual void SetProperty(wxObject
*object
, const wxxVariant
&value
) const ;
903 virtual void GetProperty(const wxObject
*object
, wxxVariant
&value
) const ;
905 // Adding an element to a collection property
906 virtual void AddToPropertyCollection(wxObject
*WXUNUSED(object
), const wxxVariant
&WXUNUSED(value
)) const
907 { wxLogError( wxGetTranslation(_T("AddToPropertyCollection called on a generic accessor")) ) ;}
909 // Getting a collection property
910 virtual void GetPropertyCollection( const wxObject
*WXUNUSED(obj
), wxxVariantArray
&WXUNUSED(result
)) const
911 { wxLogError ( wxGetTranslation(_T("GetPropertyCollection called on a generic accessor")) ) ;}
913 struct wxGenericPropertyAccessorInternal
;
914 wxGenericPropertyAccessorInternal
* m_data
;
915 wxString m_propertyName
;
916 wxString m_setterName
;
917 wxString m_getterName
;
920 typedef long wxPropertyInfoFlags
;
922 // will be removed in future releases
923 wxPROP_DEPRECATED
= 0x00000001 ,
924 // object graph property, will be streamed with priority (after constructor properties)
925 wxPROP_OBJECT_GRAPH
= 0x00000002 ,
926 // this will only be streamed out and in as enum/set, the internal representation is still a long
927 wxPROP_ENUM_STORE_LONG
= 0x00000004 ,
928 // don't stream out this property, needed eg to avoid streaming out children that are always created by their parents
929 wxPROP_DONT_STREAM
= 0x00000008 ,
932 class WXDLLIMPEXP_BASE wxPropertyInfo
934 friend class WXDLLIMPEXP_BASE wxDynamicClassInfo
;
936 wxPropertyInfo(wxPropertyInfo
* &iter
,
937 wxClassInfo
* itsClass
,
938 const wxString
& name
,
939 const wxString
& typeName
,
940 wxPropertyAccessor
*accessor
,
942 wxPropertyInfoFlags flags
= 0,
943 const wxString
& helpString
= wxEmptyString
,
944 const wxString
& groupString
= wxEmptyString
) :
945 m_itsClass(itsClass
),
948 m_typeName(typeName
) ,
949 m_collectionElementTypeInfo(NULL
),
950 m_accessor(accessor
),
953 m_helpString(helpString
),
954 m_groupString(groupString
)
960 wxPropertyInfo(wxPropertyInfo
* &iter
,
961 wxClassInfo
* itsClass
,
962 const wxString
& name
,
963 const char* typeName
,
964 wxPropertyAccessor
*accessor
,
966 wxPropertyInfoFlags flags
= 0,
967 const wxString
& helpString
= wxEmptyString
,
968 const wxString
& groupString
= wxEmptyString
) :
969 m_itsClass(itsClass
),
972 m_typeName(wxString::FromAscii(typeName
)) ,
973 m_collectionElementTypeInfo(NULL
),
974 m_accessor(accessor
),
977 m_helpString(helpString
),
978 m_groupString(groupString
)
983 wxPropertyInfo(wxPropertyInfo
* &iter
,
984 wxClassInfo
* itsClass
,
985 const wxString
& name
,
986 wxDelegateTypeInfo
* type
,
987 wxPropertyAccessor
*accessor
,
989 wxPropertyInfoFlags flags
= 0,
990 const wxString
& helpString
= wxEmptyString
,
991 const wxString
& groupString
= wxEmptyString
) :
992 m_itsClass(itsClass
),
995 m_collectionElementTypeInfo(NULL
),
996 m_accessor(accessor
),
999 m_helpString(helpString
),
1000 m_groupString(groupString
)
1005 wxPropertyInfo(wxPropertyInfo
* &iter
,
1006 wxClassInfo
* itsClass
, const wxString
& name
,
1007 const wxString
& collectionTypeName
,
1008 const wxString
& elementTypeName
,
1009 wxPropertyAccessor
*accessor
,
1010 wxPropertyInfoFlags flags
= 0,
1011 const wxString
& helpString
= wxEmptyString
,
1012 const wxString
& groupString
= wxEmptyString
) :
1013 m_itsClass(itsClass
),
1016 m_typeName(collectionTypeName
) ,
1017 m_collectionElementTypeInfo(NULL
),
1018 m_collectionElementTypeName(elementTypeName
),
1019 m_accessor(accessor
) ,
1021 m_helpString(helpString
),
1022 m_groupString(groupString
)
1028 wxPropertyInfo(wxPropertyInfo
* &iter
,
1029 wxClassInfo
* itsClass
, const wxString
& name
,
1030 const char* collectionTypeName
,
1031 const char* elementTypeName
,
1032 wxPropertyAccessor
*accessor
,
1033 wxPropertyInfoFlags flags
= 0,
1034 const wxString
& helpString
= wxEmptyString
,
1035 const wxString
& groupString
= wxEmptyString
) :
1036 m_itsClass(itsClass
),
1039 m_typeName(wxString::FromAscii(collectionTypeName
)) ,
1040 m_collectionElementTypeInfo(NULL
),
1041 m_collectionElementTypeName(wxString::FromAscii(elementTypeName
)),
1042 m_accessor(accessor
) ,
1044 m_helpString(helpString
),
1045 m_groupString(groupString
)
1052 // return the class this property is declared in
1053 const wxClassInfo
* GetDeclaringClass() const { return m_itsClass
; }
1055 // return the name of this property
1056 const wxString
& GetName() const { return m_name
; }
1058 // returns the flags of this property
1059 wxPropertyInfoFlags
GetFlags() const { return m_flags
;}
1061 // returns the short help string of this property
1062 const wxString
& GetHelpString() const { return m_helpString
; }
1064 // returns the group string of this property
1065 const wxString
& GetGroupString() const { return m_groupString
; }
1067 // return the element type info of this property (for collections, otherwise NULL)
1068 const wxTypeInfo
* GetCollectionElementTypeInfo() const
1070 if ( m_collectionElementTypeInfo
== NULL
)
1071 m_collectionElementTypeInfo
= wxTypeInfo::FindType(m_collectionElementTypeName
) ;
1072 return m_collectionElementTypeInfo
;
1075 // return the type info of this property
1076 const wxTypeInfo
* GetTypeInfo() const
1078 if ( m_typeInfo
== NULL
)
1079 m_typeInfo
= wxTypeInfo::FindType(m_typeName
) ;
1083 // return the accessor for this property
1084 wxPropertyAccessor
* GetAccessor() const { return m_accessor
; }
1086 // returns NULL if this is the last property of this class
1087 wxPropertyInfo
* GetNext() const { return m_next
; }
1089 // returns the default value of this property, its kind may be wxT_VOID if it is not valid
1090 wxxVariant
GetDefaultValue() const { return m_defaultValue
; }
1092 void Insert(wxPropertyInfo
* &iter
)
1099 wxPropertyInfo
* i
= iter
;
1107 wxClassInfo
* m_itsClass
;
1109 mutable wxTypeInfo
* m_typeInfo
;
1110 wxString m_typeName
;
1111 mutable wxTypeInfo
* m_collectionElementTypeInfo
;
1112 wxString m_collectionElementTypeName
;
1113 wxPropertyAccessor
* m_accessor
;
1114 wxxVariant m_defaultValue
;
1115 wxPropertyInfoFlags m_flags
;
1116 wxString m_helpString
;
1117 wxString m_groupString
;
1118 // string representation of the default value
1119 // to be assigned by the designer to the property
1120 // when the component is dropped on the container.
1121 wxPropertyInfo
* m_next
;
1124 WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxPropertyInfo
* , wxPropertyInfoMap
, class WXDLLIMPEXP_BASE
) ;
1126 #define wxBEGIN_PROPERTIES_TABLE(theClass) \
1127 wxPropertyInfo *theClass::GetPropertiesStatic() \
1129 typedef theClass class_t; \
1130 static wxPropertyInfo* first = NULL ;
1132 #define wxEND_PROPERTIES_TABLE() \
1135 #define wxHIDE_PROPERTY( pname ) \
1136 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(void).name() ,NULL , wxxVariant() , wxPROP_DONT_STREAM , wxEmptyString , wxEmptyString ) ;
1138 #define wxPROPERTY( pname , type , setter , getter , defaultValue , flags , help , group) \
1139 wxSETTER( pname , class_t , type , setter ) \
1140 static wxSetter##pname _setter##pname ; \
1141 wxGETTER( pname , class_t , type , getter ) \
1142 static wxGetter##pname _getter##pname ; \
1143 static wxPropertyAccessor _accessor##pname( &_setter##pname , &_getter##pname , NULL , NULL ) ; \
1144 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(type).name() ,&_accessor##pname , wxxVariant(defaultValue) , flags , group , help ) ;
1146 #define wxPROPERTY_FLAGS( pname , flags , type , setter , getter ,defaultValue , pflags , help , group) \
1147 wxSETTER( pname , class_t , type , setter ) \
1148 static wxSetter##pname _setter##pname ; \
1149 wxGETTER( pname , class_t , type , getter ) \
1150 static wxGetter##pname _getter##pname ; \
1151 static wxPropertyAccessor _accessor##pname( &_setter##pname , &_getter##pname , NULL , NULL ) ; \
1152 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(flags).name() ,&_accessor##pname , wxxVariant(defaultValue), wxPROP_ENUM_STORE_LONG | pflags , help , group ) ;
1154 #define wxREADONLY_PROPERTY( pname , type , getter ,defaultValue , flags , help , group) \
1155 wxGETTER( pname , class_t , type , getter ) \
1156 static wxGetter##pname _getter##pname ; \
1157 static wxPropertyAccessor _accessor##pname( NULL , &_getter##pname , NULL , NULL ) ; \
1158 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(type).name() ,&_accessor##pname , wxxVariant(defaultValue), flags , help , group ) ;
1160 #define wxREADONLY_PROPERTY_FLAGS( pname , flags , type , getter ,defaultValue , pflags , help , group) \
1161 wxGETTER( pname , class_t , type , getter ) \
1162 static wxGetter##pname _getter##pname ; \
1163 static wxPropertyAccessor _accessor##pname( NULL , &_getter##pname , NULL , NULL ) ; \
1164 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(flags).name() ,&_accessor##pname , wxxVariant(defaultValue), wxPROP_ENUM_STORE_LONG | pflags , help , group ) ;
1166 #define wxPROPERTY_COLLECTION( pname , colltype , addelemtype , adder , getter , flags , help , group ) \
1167 wxADDER( pname , class_t , addelemtype , adder ) \
1168 static wxAdder##pname _adder##pname ; \
1169 wxCOLLECTION_GETTER( pname , class_t , colltype , getter ) \
1170 static wxCollectionGetter##pname _collectionGetter##pname ; \
1171 static wxPropertyAccessor _accessor##pname( NULL , NULL ,&_adder##pname , &_collectionGetter##pname ) ; \
1172 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(colltype).name() ,typeid(addelemtype).name() ,&_accessor##pname , flags , help , group ) ;
1174 #define wxREADONLY_PROPERTY_COLLECTION( pname , colltype , addelemtype , getter , flags , help , group) \
1175 wxCOLLECTION_GETTER( pname , class_t , colltype , getter ) \
1176 static wxCollectionGetter##pname _collectionGetter##pname ; \
1177 static wxPropertyAccessor _accessor##pname( NULL , NULL , NULL , &_collectionGetter##pname ) ; \
1178 static wxPropertyInfo _propertyInfo##pname( first ,class_t::GetClassInfoStatic() , wxT(#pname) , typeid(colltype).name() ,typeid(addelemtype).name() ,&_accessor##pname , flags , help , group ) ;
1181 #define wxEVENT_PROPERTY( name , eventType , eventClass ) \
1182 static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \
1183 static wxPropertyInfo _propertyInfo##name( first ,class_t::GetClassInfoStatic() , wxT(#name) , &_typeInfo##name , NULL , wxxVariant() ) ; \
1185 #define wxEVENT_RANGE_PROPERTY( name , eventType , lastEventType , eventClass ) \
1186 static wxDelegateTypeInfo _typeInfo##name( eventType , lastEventType , CLASSINFO( eventClass ) ) ; \
1187 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , wxT(#name) , &_typeInfo##name , NULL , wxxVariant() ) ; \
1189 // ----------------------------------------------------------------------------
1190 // Implementation Helper for Simple Properties
1191 // ----------------------------------------------------------------------------
1193 #define wxIMPLEMENT_PROPERTY(name, type) \
1197 void Set##name( type const & p) { m_##name = p; } \
1198 type const & Get##name() const { return m_##name; }
1200 // ----------------------------------------------------------------------------
1203 // this is describing an event sink
1204 // ----------------------------------------------------------------------------
1206 class WXDLLIMPEXP_BASE wxHandlerInfo
1208 friend class WXDLLIMPEXP_BASE wxDynamicClassInfo
;
1210 wxHandlerInfo(wxHandlerInfo
* &iter
,
1211 wxClassInfo
* itsClass
,
1212 const wxString
& name
,
1213 wxObjectEventFunction address
,
1214 const wxClassInfo
* eventClassInfo
) :
1215 m_eventFunction(address
),
1217 m_eventClassInfo(eventClassInfo
) ,
1218 m_itsClass(itsClass
)
1225 wxHandlerInfo
* i
= iter
;
1235 // return the name of this handler
1236 const wxString
& GetName() const { return m_name
; }
1238 // return the class info of the event
1239 const wxClassInfo
*GetEventClassInfo() const { return m_eventClassInfo
; }
1241 // get the handler function pointer
1242 wxObjectEventFunction
GetEventFunction() const { return m_eventFunction
; }
1244 // returns NULL if this is the last handler of this class
1245 wxHandlerInfo
* GetNext() const { return m_next
; }
1247 // return the class this property is declared in
1248 const wxClassInfo
* GetDeclaringClass() const { return m_itsClass
; }
1251 wxObjectEventFunction m_eventFunction
;
1253 const wxClassInfo
* m_eventClassInfo
;
1254 wxHandlerInfo
* m_next
;
1255 wxClassInfo
* m_itsClass
;
1258 #define wxHANDLER(name,eventClassType) \
1259 static wxHandlerInfo _handlerInfo##name( first , class_t::GetClassInfoStatic() , wxT(#name) , (wxObjectEventFunction) (wxEventFunction) &name , CLASSINFO( eventClassType ) ) ;
1261 #define wxBEGIN_HANDLERS_TABLE(theClass) \
1262 wxHandlerInfo *theClass::GetHandlersStatic() \
1264 typedef theClass class_t; \
1265 static wxHandlerInfo* first = NULL ;
1267 #define wxEND_HANDLERS_TABLE() \
1270 // ----------------------------------------------------------------------------
1271 // Constructor Bridges
1273 // allow to set up constructors with params during runtime
1274 // ----------------------------------------------------------------------------
1276 class WXDLLIMPEXP_BASE wxConstructorBridge
1279 virtual ~wxConstructorBridge() {};
1280 virtual void Create(wxObject
* &o
, wxxVariant
*args
) = 0;
1283 // a direct constructor bridge calls the operator new for this class and
1284 // passes all params to the constructor. needed for classes that cannot be
1285 // instantiated using alloc-create semantics
1286 class WXDLLIMPEXP_BASE wxDirectConstructorBrigde
: public wxConstructorBridge
1289 virtual void Create(wxObject
* &o
, wxxVariant
*args
) = 0;
1292 // Creator Bridges for all Numbers of Params
1296 template<typename Class
>
1297 struct wxConstructorBridge_0
: public wxConstructorBridge
1299 void Create(wxObject
* &o
, wxxVariant
*)
1301 Class
*obj
= dynamic_cast<Class
*>(o
);
1306 struct wxConstructorBridge_Dummy
: public wxConstructorBridge
1308 void Create(wxObject
*&, wxxVariant
*)
1313 #define wxCONSTRUCTOR_0(klass) \
1314 wxConstructorBridge_0<klass> constructor##klass ; \
1315 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1316 const wxChar *klass::ms_constructorProperties[] = { NULL } ; \
1317 const int klass::ms_constructorPropertiesCount = 0 ;
1319 #define wxCONSTRUCTOR_DUMMY(klass) \
1320 wxConstructorBridge_Dummy constructor##klass ; \
1321 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1322 const wxChar *klass::ms_constructorProperties[] = { NULL } ; \
1323 const int klass::ms_constructorPropertiesCount = 0 ;
1327 template<typename Class
, typename T0
>
1328 struct wxConstructorBridge_1
: public wxConstructorBridge
1330 void Create(wxObject
* &o
, wxxVariant
*args
)
1332 Class
*obj
= dynamic_cast<Class
*>(o
);
1334 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
)
1339 #define wxCONSTRUCTOR_1(klass,t0,v0) \
1340 wxConstructorBridge_1<klass,t0> constructor##klass ; \
1341 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1342 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) } ; \
1343 const int klass::ms_constructorPropertiesCount = 1 ;
1347 template<typename Class
,
1348 typename T0
, typename T1
>
1349 struct wxConstructorBridge_2
: public wxConstructorBridge
1351 void Create(wxObject
* &o
, wxxVariant
*args
)
1353 Class
*obj
= dynamic_cast<Class
*>(o
);
1355 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1356 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
)
1361 #define wxCONSTRUCTOR_2(klass,t0,v0,t1,v1) \
1362 wxConstructorBridge_2<klass,t0,t1> constructor##klass ; \
1363 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1364 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) } ; \
1365 const int klass::ms_constructorPropertiesCount = 2;
1367 // direct constructor version
1369 template<typename Class
,
1370 typename T0
, typename T1
>
1371 struct wxDirectConstructorBridge_2
: public wxDirectConstructorBrigde
1373 void Create(wxObject
* &o
, wxxVariant
*args
)
1376 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1377 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
)
1382 #define wxDIRECT_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
1383 wxDirectConstructorBridge_2<klass,t0,t1> constructor##klass ; \
1384 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1385 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) } ; \
1386 const int klass::ms_constructorPropertiesCount = 2;
1391 template<typename Class
,
1392 typename T0
, typename T1
, typename T2
>
1393 struct wxConstructorBridge_3
: public wxConstructorBridge
1395 void Create(wxObject
* &o
, wxxVariant
*args
)
1397 Class
*obj
= dynamic_cast<Class
*>(o
);
1399 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1400 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1401 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
)
1406 #define wxCONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
1407 wxConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \
1408 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1409 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) } ; \
1410 const int klass::ms_constructorPropertiesCount = 3 ;
1412 // direct constructor version
1414 template<typename Class
,
1415 typename T0
, typename T1
, typename T2
>
1416 struct wxDirectConstructorBridge_3
: public wxDirectConstructorBrigde
1418 void Create(wxObject
* &o
, wxxVariant
*args
)
1421 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1422 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1423 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
)
1428 #define wxDIRECT_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
1429 wxDirectConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \
1430 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1431 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) } ; \
1432 const int klass::ms_constructorPropertiesCount = 3;
1436 template<typename Class
,
1437 typename T0
, typename T1
, typename T2
, typename T3
>
1438 struct wxConstructorBridge_4
: public wxConstructorBridge
1440 void Create(wxObject
* &o
, wxxVariant
*args
)
1442 Class
*obj
= dynamic_cast<Class
*>(o
);
1444 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1445 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1446 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
) ,
1447 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
)
1452 #define wxCONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
1453 wxConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass ; \
1454 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1455 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) } ; \
1456 const int klass::ms_constructorPropertiesCount = 4 ;
1460 template<typename Class
,
1461 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
>
1462 struct wxConstructorBridge_5
: public wxConstructorBridge
1464 void Create(wxObject
* &o
, wxxVariant
*args
)
1466 Class
*obj
= dynamic_cast<Class
*>(o
);
1468 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1469 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1470 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
) ,
1471 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
) ,
1472 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
)
1477 #define wxCONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
1478 wxConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass ; \
1479 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1480 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) } ; \
1481 const int klass::ms_constructorPropertiesCount = 5;
1485 template<typename Class
,
1486 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
1487 struct wxConstructorBridge_6
: public wxConstructorBridge
1489 void Create(wxObject
* &o
, wxxVariant
*args
)
1491 Class
*obj
= dynamic_cast<Class
*>(o
);
1493 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1494 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1495 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
) ,
1496 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
) ,
1497 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
) ,
1498 args
[5].wxTEMPLATED_MEMBER_CALL(Get
, T5
)
1503 #define wxCONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1504 wxConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1505 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1506 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) } ; \
1507 const int klass::ms_constructorPropertiesCount = 6;
1509 // direct constructor version
1511 template<typename Class
,
1512 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
1513 struct wxDirectConstructorBridge_6
: public wxDirectConstructorBrigde
1515 void Create(wxObject
* &o
, wxxVariant
*args
)
1518 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1519 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1520 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
) ,
1521 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
) ,
1522 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
) ,
1523 args
[5].wxTEMPLATED_MEMBER_CALL(Get
, T5
)
1528 #define wxDIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1529 wxDirectConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1530 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1531 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) } ; \
1532 const int klass::ms_constructorPropertiesCount = 6;
1536 template<typename Class
,
1537 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
>
1538 struct wxConstructorBridge_7
: public wxConstructorBridge
1540 void Create(wxObject
* &o
, wxxVariant
*args
)
1542 Class
*obj
= dynamic_cast<Class
*>(o
);
1544 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1545 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1546 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
) ,
1547 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
) ,
1548 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
) ,
1549 args
[5].wxTEMPLATED_MEMBER_CALL(Get
, T5
) ,
1550 args
[6].wxTEMPLATED_MEMBER_CALL(Get
, T6
)
1555 #define wxCONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
1556 wxConstructorBridge_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass ; \
1557 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1558 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) , wxT(#v6) } ; \
1559 const int klass::ms_constructorPropertiesCount = 7;
1563 template<typename Class
,
1564 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
, typename T7
>
1565 struct wxConstructorBridge_8
: public wxConstructorBridge
1567 void Create(wxObject
* &o
, wxxVariant
*args
)
1569 Class
*obj
= dynamic_cast<Class
*>(o
);
1571 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
) ,
1572 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
) ,
1573 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
) ,
1574 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
) ,
1575 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
) ,
1576 args
[5].wxTEMPLATED_MEMBER_CALL(Get
, T5
) ,
1577 args
[6].wxTEMPLATED_MEMBER_CALL(Get
, T6
) ,
1578 args
[7].wxTEMPLATED_MEMBER_CALL(Get
, T7
)
1583 #define wxCONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
1584 wxConstructorBridge_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass ; \
1585 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1586 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) , wxT(#v6) , wxT(#v7) } ; \
1587 const int klass::ms_constructorPropertiesCount = 8;
1588 // ----------------------------------------------------------------------------
1590 // ----------------------------------------------------------------------------
1592 typedef wxObject
*(*wxObjectConstructorFn
)(void);
1593 typedef wxObject
* (*wxVariantToObjectConverter
)( wxxVariant
&data
) ;
1594 typedef wxxVariant (*wxObjectToVariantConverter
)( wxObject
* ) ;
1596 class WXDLLIMPEXP_BASE wxWriter
;
1597 class WXDLLIMPEXP_BASE wxPersister
;
1599 typedef bool (*wxObjectStreamingCallback
) ( const wxObject
*, wxWriter
* , wxPersister
* , wxxVariantArray
& ) ;
1601 class WXDLLIMPEXP_BASE wxClassInfo
1603 friend class WXDLLIMPEXP_BASE wxPropertyInfo
;
1604 friend class WXDLLIMPEXP_BASE wxHandlerInfo
;
1605 friend wxObject
*wxCreateDynamicObject(const wxString
& name
);
1607 wxClassInfo(const wxClassInfo
**_Parents
,
1608 const wxChar
*_UnitName
,
1609 const wxChar
*_ClassName
,
1611 wxObjectConstructorFn ctor
,
1612 wxPropertyInfo
*_Props
,
1613 wxHandlerInfo
*_Handlers
,
1614 wxConstructorBridge
* _Constructor
,
1615 const wxChar
** _ConstructorProperties
,
1616 const int _ConstructorPropertiesCount
,
1617 wxVariantToObjectConverter _PtrConverter1
,
1618 wxVariantToObjectConverter _Converter2
,
1619 wxObjectToVariantConverter _Converter3
,
1620 wxObjectStreamingCallback _streamingCallback
= NULL
1623 m_className(_ClassName
),
1625 m_objectConstructor(ctor
),
1627 m_firstProperty(_Props
),
1628 m_firstHandler(_Handlers
),
1629 m_parents(_Parents
),
1630 m_unitName(_UnitName
),
1631 m_constructor(_Constructor
),
1632 m_constructorProperties(_ConstructorProperties
),
1633 m_constructorPropertiesCount(_ConstructorPropertiesCount
),
1634 m_variantOfPtrToObjectConverter(_PtrConverter1
),
1635 m_variantToObjectConverter(_Converter2
),
1636 m_objectToVariantConverter(_Converter3
),
1637 m_streamingCallback(_streamingCallback
)
1643 wxClassInfo(const wxChar
*_UnitName
, const wxChar
*_ClassName
,
1644 const wxClassInfo
**_Parents
) :
1645 m_className(_ClassName
),
1647 m_objectConstructor(NULL
),
1649 m_firstProperty(NULL
),
1650 m_firstHandler(NULL
),
1651 m_parents(_Parents
),
1652 m_unitName(_UnitName
),
1653 m_constructor(NULL
),
1654 m_constructorProperties(NULL
),
1655 m_constructorPropertiesCount(0),
1656 m_variantOfPtrToObjectConverter(NULL
),
1657 m_variantToObjectConverter(NULL
),
1658 m_objectToVariantConverter(NULL
),
1659 m_streamingCallback(NULL
)
1665 virtual ~wxClassInfo() ;
1667 // allocates an instance of this class, this object does not have to be initialized or fully constructed
1668 // as this call will be followed by a call to Create
1669 virtual wxObject
*AllocateObject() const { return m_objectConstructor
? (*m_objectConstructor
)() : 0; }
1671 // 'old naming' for AllocateObject staying here for backward compatibility
1672 wxObject
*CreateObject() const { return AllocateObject() ; }
1674 // direct construction call for classes that cannot construct instances via alloc/create
1675 wxObject
*ConstructObject(int ParamCount
, wxxVariant
*Params
) const
1677 if ( ParamCount
!= m_constructorPropertiesCount
)
1679 wxLogError( wxGetTranslation(_T("Illegal Parameter Count for ConstructObject Method")) ) ;
1682 wxObject
*object
= NULL
;
1683 m_constructor
->Create( object
, Params
) ;
1687 bool NeedsDirectConstruction() const { return dynamic_cast<wxDirectConstructorBrigde
*>( m_constructor
) != NULL
; }
1689 const wxChar
*GetClassName() const { return m_className
; }
1690 const wxChar
*GetBaseClassName1() const
1691 { return m_parents
[0] ? m_parents
[0]->GetClassName() : NULL
; }
1692 const wxChar
*GetBaseClassName2() const
1693 { return (m_parents
[0] && m_parents
[1]) ? m_parents
[1]->GetClassName() : NULL
; }
1694 const wxChar
*GetIncludeName() const { return m_unitName
; }
1695 const wxClassInfo
**GetParents() const { return m_parents
; }
1696 int GetSize() const { return m_objectSize
; }
1697 bool IsDynamic() const { return (NULL
!= m_objectConstructor
); }
1699 wxObjectConstructorFn
GetConstructor() const { return m_objectConstructor
; }
1700 static const wxClassInfo
*GetFirst() { return sm_first
; }
1701 const wxClassInfo
*GetNext() const { return m_next
; }
1702 static wxClassInfo
*FindClass(const wxString
& className
);
1704 // Climb upwards through inheritance hierarchy.
1705 // Dual inheritance is catered for.
1707 bool IsKindOf(const wxClassInfo
*info
) const
1714 for ( int i
= 0 ; m_parents
[i
] ; ++ i
)
1716 if ( m_parents
[i
]->IsKindOf( info
) )
1723 DECLARE_CLASS_INFO_ITERATORS()
1725 // if there is a callback registered with that class it will be called
1726 // before this object will be written to disk, it can veto streaming out
1727 // this object by returning false, if this class has not registered a
1728 // callback, the search will go up the inheritance tree if no callback has
1729 // been registered true will be returned by default
1730 bool BeforeWriteObject( const wxObject
*obj
, wxWriter
*streamer
, wxPersister
*persister
, wxxVariantArray
&metadata
) const ;
1732 // gets the streaming callback from this class or any superclass
1733 wxObjectStreamingCallback
GetStreamingCallback() const ;
1735 static void CleanUp();
1737 // returns the first property
1738 const wxPropertyInfo
* GetFirstProperty() const { return m_firstProperty
; }
1740 // returns the first handler
1741 const wxHandlerInfo
* GetFirstHandler() const { return m_firstHandler
; }
1743 // Call the Create upon an instance of the class, in the end the object is fully
1745 virtual void Create (wxObject
*object
, int ParamCount
, wxxVariant
*Params
) const
1747 if ( ParamCount
!= m_constructorPropertiesCount
)
1749 wxLogError( wxGetTranslation(_T("Illegal Parameter Count for Create Method")) ) ;
1752 m_constructor
->Create( object
, Params
) ;
1755 // get number of parameters for constructor
1756 virtual int GetCreateParamCount() const { return m_constructorPropertiesCount
; }
1758 // get n-th constructor parameter
1759 virtual const wxChar
* GetCreateParamName(int n
) const { return m_constructorProperties
[n
] ; }
1761 // Runtime access to objects for simple properties (get/set) by property name, and variant data
1762 virtual void SetProperty (wxObject
*object
, const wxChar
*propertyName
, const wxxVariant
&value
) const ;
1763 virtual wxxVariant
GetProperty (wxObject
*object
, const wxChar
*propertyName
) const;
1765 // Runtime access to objects for collection properties by property name
1766 virtual wxxVariantArray
GetPropertyCollection(wxObject
*object
, const wxChar
*propertyName
) const ;
1767 virtual void AddToPropertyCollection(wxObject
*object
, const wxChar
*propertyName
, const wxxVariant
& value
) const ;
1769 // we must be able to cast variants to wxObject pointers, templates seem not to be suitable
1770 wxObject
* VariantToInstance( wxxVariant
&data
) const
1772 if ( data
.GetTypeInfo()->GetKind() == wxT_OBJECT
)
1773 return m_variantToObjectConverter( data
) ;
1775 return m_variantOfPtrToObjectConverter( data
) ;
1778 wxxVariant
InstanceToVariant( wxObject
*object
) const { return m_objectToVariantConverter( object
) ; }
1780 // find property by name
1781 virtual const wxPropertyInfo
*FindPropertyInfo (const wxChar
*PropertyName
) const ;
1783 // find handler by name
1784 virtual const wxHandlerInfo
*FindHandlerInfo (const wxChar
*PropertyName
) const ;
1786 // find property by name
1787 virtual wxPropertyInfo
*FindPropertyInfoInThisClass (const wxChar
*PropertyName
) const ;
1789 // find handler by name
1790 virtual wxHandlerInfo
*FindHandlerInfoInThisClass (const wxChar
*PropertyName
) const ;
1792 // puts all the properties of this class and its superclasses in the map, as long as there is not yet
1793 // an entry with the same name (overriding mechanism)
1794 void GetProperties( wxPropertyInfoMap
&map
) const ;
1796 const wxChar
*m_className
;
1798 wxObjectConstructorFn m_objectConstructor
;
1800 // class info object live in a linked list:
1801 // pointers to its head and the next element in it
1803 static wxClassInfo
*sm_first
;
1804 wxClassInfo
*m_next
;
1806 static wxHashTable
*sm_classTable
;
1809 wxPropertyInfo
* m_firstProperty
;
1810 wxHandlerInfo
* m_firstHandler
;
1812 const wxClassInfo
** m_parents
;
1813 const wxChar
* m_unitName
;
1815 wxConstructorBridge
* m_constructor
;
1816 const wxChar
** m_constructorProperties
;
1817 const int m_constructorPropertiesCount
;
1818 wxVariantToObjectConverter m_variantOfPtrToObjectConverter
;
1819 wxVariantToObjectConverter m_variantToObjectConverter
;
1820 wxObjectToVariantConverter m_objectToVariantConverter
;
1821 wxObjectStreamingCallback m_streamingCallback
;
1822 const wxPropertyAccessor
*FindAccessor (const wxChar
*propertyName
) const ;
1825 // registers the class
1829 DECLARE_NO_COPY_CLASS(wxClassInfo
)
1833 WXDLLIMPEXP_BASE wxObject
*wxCreateDynamicObject(const wxString
& name
);
1835 // ----------------------------------------------------------------------------
1837 // ----------------------------------------------------------------------------
1839 // this object leads to having a pure runtime-instantiation
1841 class WXDLLIMPEXP_BASE wxDynamicClassInfo
: public wxClassInfo
1843 friend class WXDLLIMPEXP_BASE wxDynamicObject
;
1845 wxDynamicClassInfo( const wxChar
*_UnitName
, const wxChar
*_ClassName
, const wxClassInfo
* superClass
) ;
1846 virtual ~wxDynamicClassInfo() ;
1848 // constructs a wxDynamicObject with an instance
1849 virtual wxObject
*AllocateObject() const ;
1851 // Call the Create method for a class
1852 virtual void Create (wxObject
*object
, int ParamCount
, wxxVariant
*Params
) const ;
1854 // get number of parameters for constructor
1855 virtual int GetCreateParamCount() const ;
1857 // get i-th constructor parameter
1858 virtual const wxChar
* GetCreateParamName(int i
) const ;
1860 // Runtime access to objects by property name, and variant data
1861 virtual void SetProperty (wxObject
*object
, const wxChar
*PropertyName
, const wxxVariant
&Value
) const ;
1862 virtual wxxVariant
GetProperty (wxObject
*object
, const wxChar
*PropertyName
) const ;
1864 // adds a property to this class at runtime
1865 void AddProperty( const wxChar
*propertyName
, const wxTypeInfo
* typeInfo
) ;
1867 // removes an existing runtime-property
1868 void RemoveProperty( const wxChar
*propertyName
) ;
1870 // renames an existing runtime-property
1871 void RenameProperty( const wxChar
*oldPropertyName
, const wxChar
*newPropertyName
) ;
1873 // as a handler to this class at runtime
1874 void AddHandler( const wxChar
*handlerName
, wxObjectEventFunction address
, const wxClassInfo
* eventClassInfo
) ;
1876 // removes an existing runtime-handler
1877 void RemoveHandler( const wxChar
*handlerName
) ;
1879 // renames an existing runtime-handler
1880 void RenameHandler( const wxChar
*oldHandlerName
, const wxChar
*newHandlerName
) ;
1882 struct wxDynamicClassInfoInternal
;
1883 wxDynamicClassInfoInternal
* m_data
;
1886 // ----------------------------------------------------------------------------
1887 // Dynamic class macros
1888 // ----------------------------------------------------------------------------
1890 #define _DECLARE_DYNAMIC_CLASS(name) \
1892 static wxClassInfo ms_classInfo; \
1893 static const wxClassInfo* ms_classParents[] ; \
1894 static wxPropertyInfo* GetPropertiesStatic() ; \
1895 static wxHandlerInfo* GetHandlersStatic() ; \
1896 static wxClassInfo *GetClassInfoStatic() \
1897 { return &name::ms_classInfo; } \
1898 virtual wxClassInfo *GetClassInfo() const \
1899 { return &name::ms_classInfo; }
1902 #define _DECLARE_DYNAMIC_CLASS(name) \
1904 static wxClassInfo ms_class##name; \
1905 static const wxClassInfo* ms_classParents##name[] ; \
1906 static wxPropertyInfo* GetPropertiesStatic() ; \
1907 static wxHandlerInfo* GetHandlersStatic() ; \
1908 static wxClassInfo *GetClassInfoStatic() \
1909 { return &name::ms_class##name; } \
1910 virtual wxClassInfo *GetClassInfo() const \
1911 { return &name::ms_class##name; }
1913 #define DECLARE_DYNAMIC_CLASS(name) \
1914 static wxConstructorBridge* ms_constructor ; \
1915 static const wxChar * ms_constructorProperties[] ; \
1916 static const int ms_constructorPropertiesCount ; \
1917 _DECLARE_DYNAMIC_CLASS(name)
1919 #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
1920 DECLARE_NO_ASSIGN_CLASS(name) \
1921 DECLARE_DYNAMIC_CLASS(name)
1923 #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \
1924 DECLARE_NO_COPY_CLASS(name) \
1925 DECLARE_DYNAMIC_CLASS(name)
1927 #define DECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name)
1928 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
1930 // -----------------------------------
1931 // for concrete classes
1932 // -----------------------------------
1934 // Single inheritance with one base class
1936 #define _TYPEINFO_CLASSES(n , toString , fromString ) \
1937 wxClassTypeInfo s_typeInfo##n(wxT_OBJECT , &n::ms_classInfo , toString , fromString , typeid(n).name()) ; \
1938 wxClassTypeInfo s_typeInfoPtr##n(wxT_OBJECT_PTR , &n::ms_classInfo , toString , fromString , typeid(n*).name()) ;
1940 #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit , callback) \
1941 wxObject* wxConstructorFor##name() \
1942 { return new name; } \
1943 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo ,NULL } ; \
1944 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.wxTEMPLATED_MEMBER_CALL(Get , name*) ; } \
1945 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1946 wxClassInfo name::ms_classInfo(name::ms_classParents , wxT(unit) , wxT(#name), \
1947 (int) sizeof(name), \
1948 (wxObjectConstructorFn) wxConstructorFor##name , \
1949 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::ms_constructor , name::ms_constructorProperties , \
1950 name::ms_constructorPropertiesCount , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name , callback);
1952 #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \
1953 wxObject* wxConstructorFor##name() \
1954 { return new name; } \
1955 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo ,NULL } ; \
1956 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return &data.wxTEMPLATED_MEMBER_CALL(Get , name) ; } \
1957 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.wxTEMPLATED_MEMBER_CALL(Get , name*) ; } \
1958 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1959 wxClassInfo name::ms_classInfo(name::ms_classParents , wxT(unit) , wxT(#name), \
1960 (int) sizeof(name), \
1961 (wxObjectConstructorFn) wxConstructorFor##name , \
1962 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::ms_constructor , name::ms_constructorProperties, \
1963 name::ms_constructorPropertiesCount , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name, callback);
1965 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \
1966 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" , NULL ) \
1967 _TYPEINFO_CLASSES(name, NULL , NULL) \
1968 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1969 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1970 wxCONSTRUCTOR_DUMMY( name )
1972 #define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \
1973 _IMPLEMENT_DYNAMIC_CLASS( name , basename , "" , NULL ) \
1974 _TYPEINFO_CLASSES(name, NULL , NULL) \
1975 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1976 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1977 wxCONSTRUCTOR_DUMMY( name )
1979 #define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \
1980 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , NULL ) \
1981 _TYPEINFO_CLASSES(name, NULL , NULL)
1983 #define IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name , basename , unit , callback ) \
1984 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , &callback ) \
1985 _TYPEINFO_CLASSES(name, NULL , NULL)
1987 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \
1988 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit , NULL ) \
1989 _TYPEINFO_CLASSES(name, NULL , NULL)
1991 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name , basename , unit , toString , fromString ) \
1992 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit , NULL ) \
1993 _TYPEINFO_CLASSES(name, toString , fromString)
1995 // this is for classes that do not derive from wxobject, there are no creators for these
1997 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name , unit ) \
1998 const wxClassInfo* name::ms_classParents[] = { NULL } ; \
1999 wxClassInfo name::ms_classInfo(name::ms_classParents , wxEmptyString , wxT(#name), \
2000 (int) sizeof(name), \
2001 (wxObjectConstructorFn) 0 , \
2002 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
2004 _TYPEINFO_CLASSES(name, NULL , NULL)
2006 // this is for subclasses that still do not derive from wxobject
2008 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name , basename, unit ) \
2009 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo ,NULL } ; \
2010 wxClassInfo name::ms_classInfo(name::ms_classParents , wxEmptyString , wxT(#name), \
2011 (int) sizeof(name), \
2012 (wxObjectConstructorFn) 0 , \
2013 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
2015 _TYPEINFO_CLASSES(name, NULL , NULL)
2018 // Multiple inheritance with two base classes
2020 #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit, callback) \
2021 wxObject* wxConstructorFor##name() \
2022 { return new name; } \
2023 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo ,&basename2::ms_classInfo , NULL } ; \
2024 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.wxTEMPLATED_MEMBER_CALL(Get , name*) ; } \
2025 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
2026 wxClassInfo name::ms_classInfo(name::ms_classParents , wxT(unit) , wxT(#name), \
2027 (int) sizeof(name), \
2028 (wxObjectConstructorFn) wxConstructorFor##name , \
2029 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::ms_constructor , name::ms_constructorProperties , \
2030 name::ms_constructorPropertiesCount , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name , callback);
2032 #define IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2) \
2033 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , "", NULL) \
2034 _TYPEINFO_CLASSES(name, NULL , NULL) \
2035 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
2036 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
2037 wxCONSTRUCTOR_DUMMY( name )
2039 #define IMPLEMENT_DYNAMIC_CLASS2_XTI( name , basename , basename2, unit) \
2040 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , unit, NULL) \
2041 _TYPEINFO_CLASSES(name, NULL , NULL)
2044 // -----------------------------------
2045 // for abstract classes
2046 // -----------------------------------
2048 // Single inheritance with one base class
2050 #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
2051 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo ,NULL } ; \
2052 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.wxTEMPLATED_MEMBER_CALL(Get , name*) ; } \
2053 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.wxTEMPLATED_MEMBER_CALL(Get , name*) ; } \
2054 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
2055 wxClassInfo name::ms_classInfo(name::ms_classParents , wxEmptyString , wxT(#name), \
2056 (int) sizeof(name), \
2057 (wxObjectConstructorFn) 0 , \
2058 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
2059 0 , wxVariantOfPtrToObjectConverter##name ,wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
2060 _TYPEINFO_CLASSES(name, NULL , NULL)
2062 #define IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
2063 _IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
2064 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
2065 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; }
2067 // Multiple inheritance with two base classes
2069 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
2070 wxClassInfo name::ms_classInfo(wxT(#name), wxT(#basename1), \
2071 wxT(#basename2), (int) sizeof(name), \
2072 (wxObjectConstructorFn) 0);
2074 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
2075 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
2077 #define wxBEGIN_EVENT_TABLE( a , b ) BEGIN_EVENT_TABLE( a , b )
2078 #define wxEND_EVENT_TABLE() END_EVENT_TABLE()
2080 // --------------------------------------------------------------------------
2081 // Collection Support
2082 // --------------------------------------------------------------------------
2084 template<typename iter
, typename collection_t
> void wxListCollectionToVariantArray( const collection_t
& coll
, wxxVariantArray
&value
)
2086 iter current
= coll
.GetFirst() ;
2089 value
.Add( new wxxVariant(current
->GetData()) ) ;
2090 current
= current
->GetNext();
2094 template<typename collection_t
> void wxArrayCollectionToVariantArray( const collection_t
& coll
, wxxVariantArray
&value
)
2096 for( size_t i
= 0 ; i
< coll
.GetCount() ; i
++ )
2098 value
.Add( new wxxVariant(coll
[i
]) ) ;
2103 #endif // _WX_XTIH__