1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: runtime metadata information (extended class info)
4 // Author: Stefan Csomor
8 // Copyright: (c) 1997 Julian Smart
9 // (c) 2003 Stefan Csomor
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
16 #if defined(__GNUG__) && !defined(__APPLE__)
17 #pragma interface "xti.h"
20 // We want to support properties, event sources and events sinks through
21 // explicit declarations, using templates and specialization to make the
22 // effort as painless as possible.
24 // This means we have the following domains :
26 // - Type Information for categorizing built in types as well as custom types
27 // this includes information about enums, their values and names
28 // - Type safe value storage : a kind of wxVariant, called right now wxxVariant
29 // which will be merged with wxVariant
30 // - Property Information and Property Accessors providing access to a class'
31 // values and exposed event delegates
32 // - Information about event handlers
33 // - extended Class Information for accessing all these
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
40 #include "wx/memory.h"
42 #include "wx/string.h"
43 #include "wx/arrstr.h"
45 class WXDLLIMPEXP_BASE wxObject
;
46 class WXDLLIMPEXP_BASE wxClassInfo
;
47 class WXDLLIMPEXP_BASE wxHashTable
;
48 class WXDLLIMPEXP_BASE wxObjectRefData
;
49 class WXDLLIMPEXP_BASE wxEvent
;
51 typedef void (wxObject::*wxObjectEventFunction
)(wxEvent
&);
53 // ----------------------------------------------------------------------------
56 // In the header files there would no change from pure c++ code, in the
57 // implementation, an enum would have
58 // to be enumerated eg :
60 // WX_BEGIN_ENUM( wxFlavor )
61 // WX_ENUM_MEMBER( Vanilla )
62 // WX_ENUM_MEMBER( Chocolate )
63 // WX_ENUM_MEMBER( Strawberry )
64 // WX_END_ENUM( wxFlavor )
65 // ----------------------------------------------------------------------------
67 struct WXDLLIMPEXP_BASE wxEnumMemberData
73 class WXDLLIMPEXP_BASE wxEnumData
76 wxEnumData( wxEnumMemberData
* data
) ;
78 // returns true if the member has been found and sets the int value
79 // pointed to accordingly (if ptr != null )
80 // if not found returns false, value left unchanged
81 bool HasEnumMemberValue( const wxChar
*name
, int *value
= NULL
) ;
83 // returns the value of the member, if not found in debug mode an
84 // assert is issued, in release 0 is returned
85 int GetEnumMemberValue(const wxChar
*name
);
87 // returns the name of the enum member having the passed in value
88 // returns an emtpy string if not found
89 const wxChar
*GetEnumMemberName(int value
);
91 // returns the number of members in this enum
92 int GetEnumCount() { return m_count
; }
94 // returns the value of the nth member
95 int GetEnumMemberValueByIndex( int n
) ;
97 // returns the value of the nth member
98 const wxChar
*GetEnumMemberNameByIndex( int n
) ;
100 wxEnumMemberData
*m_members
;
104 #define WX_BEGIN_ENUM( e ) \
105 wxEnumMemberData s_enumDataMembers##e[] = {
107 #define WX_ENUM_MEMBER( v ) { #v, v } ,
109 #define WX_END_ENUM( e ) { NULL , 0 } } ; \
110 wxEnumData s_enumData##e( s_enumDataMembers##e ) ; \
111 wxEnumData *wxGetEnumData(e) { return &s_enumData##e ; } \
112 template<> const wxTypeInfo* wxGetTypeInfo( e * ){ static wxEnumTypeInfo s_typeInfo(wxT_ENUM , &s_enumData##e) ; return &s_typeInfo ; } \
113 template<> void wxStringReadValue(const wxString& s , e &data ) \
115 data = (e) s_enumData##e.GetEnumMemberValue(s) ; \
117 template<> void wxStringWriteValue(wxString &s , const e &data ) \
119 s = s_enumData##e.GetEnumMemberName((int)data) ; \
122 // ----------------------------------------------------------------------------
134 // typedef wxSet<wxFlavor> wxCoupe ;
136 // in the implementation file :
138 // WX_BEGIN_ENUM( wxFlavor )
139 // WX_ENUM_MEMBER( Vanilla )
140 // WX_ENUM_MEMBER( Chocolate )
141 // WX_ENUM_MEMBER( Strawberry )
142 // WX_END_ENUM( wxFlavor )
144 // WX_IMPLEMENT_SET_STREAMING( wxCoupe , wxFlavor )
146 // implementation note : no partial specialization for streaming, but a delegation to a
149 // ----------------------------------------------------------------------------
151 // in order to remove dependancy on string tokenizer
152 void wxSetStringToArray( const wxString
&s
, wxArrayString
&array
) ;
155 void wxSetFromString(const wxString
&s
, wxSet
<e
> &data
)
157 wxEnumData
* edata
= wxGetEnumData((e
) 0) ;
160 wxArrayString array
;
161 wxSetStringToArray( s
, array
) ;
163 for ( int i
= 0 ; i
< array
.Count() ; ++i
)
167 if ( edata
->HasEnumMemberValue( flag
, &ivalue
) )
169 data
.Set( (e
) ivalue
) ;
175 void wxSetToString( wxString
&s
, const wxSet
<e
> &data
)
177 wxEnumData
* edata
= wxGetEnumData((e
) 0) ;
178 int count
= edata
->GetEnumCount() ;
181 for ( i
= 0 ; i
< count
; i
++ )
183 e value
= (e
) edata
->GetEnumMemberValueByIndex(i
) ;
184 if ( data
.Contains( value
) )
186 // this could also be done by the templated calls
189 s
+= edata
->GetEnumMemberNameByIndex(i
) ;
194 // if the wxSet specialization above does not work for all compilers, add this to the WX_IMPLEMENT_SET_STREAMING macro
195 // template<> const wxTypeInfo* wxGetTypeInfo( SetName * ){ static wxEnumTypeInfo s_typeInfo(wxT_SET , &s_enumData##e) ; return &s_typeInfo ; }
197 #define WX_IMPLEMENT_SET_STREAMING(SetName,e) \
198 template<> void wxStringReadValue(const wxString &s , wxSet<e> &data ) \
200 wxSetFromString( s , data ) ; \
202 template<> void wxStringWriteValue( wxString &s , const wxSet<e> &data ) \
204 wxSetToString( s , data ) ; \
208 // ----------------------------------------------------------------------------
210 // ----------------------------------------------------------------------------
214 wxT_VOID
= 0, // unknown type
224 wxT_STRING
, // must be wxString
225 wxT_SET
, // must be wxSet<> template
227 wxT_OBJECT_PTR
, // pointer to wxObject
228 wxT_OBJECT
, // wxObject
229 wxT_CUSTOM
, // user defined type (e.g. wxPoint)
230 wxT_DELEGATE
, // for connecting against an event source
231 wxT_LAST_TYPE_KIND
// sentinel for bad data, asserts, debugging
234 class WXDLLIMPEXP_BASE wxTypeInfo
237 wxTypeInfo() : m_kind( wxT_VOID
) {}
238 virtual ~wxTypeInfo() {}
239 wxTypeKind
GetKind() const { return m_kind
; }
240 bool IsDelegateType() const { return m_kind
== wxT_DELEGATE
; }
241 bool IsCustomType() const { return m_kind
== wxT_CUSTOM
; }
242 bool IsObjectType() const { return m_kind
== wxT_OBJECT
|| m_kind
== wxT_OBJECT_PTR
; }
247 class WXDLLIMPEXP_BASE wxBuiltInTypeInfo
: public wxTypeInfo
250 wxBuiltInTypeInfo( wxTypeKind kind
) { wxASSERT_MSG( kind
< wxT_SET
, wxT("Illegal Kind for Base Type") ) ; m_kind
= kind
;}
253 class WXDLLIMPEXP_BASE wxCustomTypeInfo
: public wxTypeInfo
256 wxCustomTypeInfo( const wxChar
*typeName
)
257 { m_kind
= wxT_CUSTOM
; m_typeName
= typeName
;}
258 const wxChar
*GetTypeName() const { return m_typeName
; }
260 const wxChar
*m_typeName
; // Kind == wxT_CUSTOM
263 class WXDLLIMPEXP_BASE wxEnumTypeInfo
: public wxTypeInfo
266 wxEnumTypeInfo( wxTypeKind kind
, wxEnumData
* enumInfo
)
267 { wxASSERT_MSG( kind
== wxT_ENUM
|| kind
== wxT_SET
, wxT("Illegal Kind for Enum Type")) ; m_kind
= kind
; m_enumInfo
= enumInfo
;}
268 const wxEnumData
* GetEnumData() const { return m_enumInfo
; }
270 wxEnumData
*m_enumInfo
; // Kind == wxT_ENUM or Kind == wxT_SET
273 class WXDLLIMPEXP_BASE wxClassTypeInfo
: public wxTypeInfo
276 wxClassTypeInfo( wxTypeKind kind
, wxClassInfo
* classInfo
)
277 { wxASSERT_MSG( kind
== wxT_OBJECT_PTR
|| kind
== wxT_OBJECT
, wxT("Illegal Kind for Enum Type")) ; m_kind
= kind
; m_classInfo
= classInfo
;}
278 const wxClassInfo
*GetClassInfo() const { return m_classInfo
; }
280 wxClassInfo
*m_classInfo
; // Kind == wxT_OBJECT - could be NULL
283 // a delegate is an exposed event source
285 class WXDLLIMPEXP_BASE wxDelegateTypeInfo
: public wxTypeInfo
288 wxDelegateTypeInfo( int eventType
, wxClassInfo
* eventClass
)
289 { m_kind
= wxT_DELEGATE
; m_eventClass
= eventClass
; m_eventType
= eventType
;}
290 const wxClassInfo
*GetEventClass() const { assert( m_kind
== wxT_DELEGATE
) ; return m_eventClass
; }
291 int GetEventType() const { return m_eventType
; }
293 const wxClassInfo
*m_eventClass
; // (extended will merge into classinfo)
297 template<typename T
> const wxTypeInfo
* wxGetTypeInfo( T
* ) ;
299 template<typename T
> const wxTypeInfo
* wxGetTypeInfo( wxSet
<T
> * )
301 static wxEnumTypeInfo
s_typeInfo(wxT_SET
, wxGetEnumData((T
) 0) ) ; return &s_typeInfo
;
304 // this macro is for usage with custom, non-object derived classes and structs, wxPoint is such a custom type
306 #define WX_CUSTOM_TYPE_INFO( e ) \
307 template<> const wxTypeInfo* wxGetTypeInfo( e * ){ static wxCustomTypeInfo s_typeInfo(#e) ; return &s_typeInfo ; } \
309 // ----------------------------------------------------------------------------
312 // streaming is defined for xml constructs right now, the aim is to make this
313 // pluggable in the future
314 // ----------------------------------------------------------------------------
316 // convenience function (avoids including xml headers in users code)
319 void wxXmlAddContentToNode( wxXmlNode
* node
, const wxString
& data
) ;
320 wxString
wxXmlGetContentFromNode( wxXmlNode
*node
) ;
322 // templated streaming, every type must have their specialization for these methods
325 void wxStringReadValue( const wxString
&s
, T
&data
) ;
328 void wxStringWriteValue( wxString
&s
, const T
&data
) ;
330 // for simple types this default implementation is ok, composited structures will have to
331 // loop through their properties
334 void wxXmlReadValue( wxXmlNode
*node
, T
&data
)
336 wxStringReadValue
<T
>( wxXmlGetContentFromNode( node
) , data
) ;
340 void wxXmlWriteValue( wxXmlNode
*node
, const T
&data
)
343 wxStringWriteValue
<T
>( s
, data
) ;
344 wxXmlAddContentToNode( node
,s
) ;
347 // ----------------------------------------------------------------------------
348 // wxxVariant as typesafe data holder
349 // ----------------------------------------------------------------------------
351 class WXDLLIMPEXP_BASE wxxVariantData
354 virtual ~wxxVariantData() {}
356 // return a heap allocated duplicate
357 virtual wxxVariantData
* Clone() const = 0 ;
359 // returns the type info of the contentc
360 virtual const wxTypeInfo
* GetTypeInfo() const = 0 ;
362 // write the value into an xml node
363 virtual void Write( wxXmlNode
* node
) const = 0 ;
365 // read the value from the xml node
366 virtual void Read( wxXmlNode
* node
) = 0 ;
368 // write the value into a string
369 virtual void Write( wxString
&s
) const = 0 ;
371 // read the value from a string
372 virtual void Read( const wxString
&s
) = 0 ;
375 template<typename T
> class WXDLLIMPEXP_BASE wxxVariantDataT
: public wxxVariantData
378 wxxVariantDataT(const T
& d
) : m_data(d
) {}
379 virtual ~wxxVariantDataT() {}
381 // get a ref to the stored data
382 T
& Get() { return m_data
; }
384 // get a const ref to the stored data
385 const T
& Get() const { return m_data
; }
388 void Set(const T
& d
) { m_data
= d
; }
390 // return a heap allocated duplicate
391 virtual wxxVariantData
* Clone() const { return new wxxVariantDataT
<T
>( Get() ) ; }
393 // returns the type info of the contentc
394 virtual const wxTypeInfo
* GetTypeInfo() const { return wxGetTypeInfo( (T
*) NULL
) ; }
396 // write the value into an xml node
397 virtual void Write( wxXmlNode
* node
) const { wxXmlWriteValue( node
, m_data
) ; }
399 // read the value from the xml node
400 virtual void Read( wxXmlNode
* node
) { wxXmlReadValue( node
, m_data
) ; }
402 // write the value into a string
403 virtual void Write( wxString
&s
) const { wxStringWriteValue( s
, m_data
) ; }
405 // read the value from a string
406 virtual void Read( const wxString
&s
) { wxStringReadValue( s
, m_data
) ; }
412 class WXDLLIMPEXP_BASE wxxVariant
415 wxxVariant() { m_data
= NULL
; }
416 wxxVariant( wxxVariantData
* data
, const wxString
& name
= wxT("") ) : m_data(data
) , m_name(name
) {}
417 wxxVariant( const wxxVariant
&d
) { if ( d
.m_data
) m_data
= d
.m_data
->Clone() ; else m_data
= NULL
; m_name
= d
.m_name
; }
419 template<typename T
> wxxVariant( T data
, const wxString
& name
= wxT("") ) :
420 m_data(new wxxVariantDataT
<T
>(data
) ), m_name(name
) {}
421 ~wxxVariant() { delete m_data
; }
423 // get a ref to the stored data
424 template<typename T
> T
& Get()
426 wxxVariantDataT
<T
> *dataptr
= dynamic_cast<wxxVariantDataT
<T
>*> (m_data
) ;
427 wxASSERT_MSG( dataptr
, "Cast not possible" ) ;
428 return dataptr
->Get() ;
431 // get a ref to the stored data
432 template<typename T
> const T
& Get() const
434 const wxxVariantDataT
<T
> *dataptr
= dynamic_cast<const wxxVariantDataT
<T
>*> (m_data
) ;
435 wxASSERT_MSG( dataptr
, "Cast not possible" ) ;
436 return dataptr
->Get() ;
440 template<typename T
> void Set(const T
& data
) const
443 m_data
= new wxxVariantDataT
<T
>(data
) ;
446 wxxVariant
& operator=(const wxxVariant
&d
)
448 m_data
= d
.m_data
->Clone() ;
453 // gets the stored data casted to a wxObject* , returning NULL if cast is not possible
454 wxObject
* GetAsObject() ;
456 // get the typeinfo of the stored object
457 const wxTypeInfo
* GetTypeInfo() const { return m_data
->GetTypeInfo() ; }
459 // write the value into an xml node
460 void Write( wxXmlNode
* node
) const { m_data
->Write( node
) ; }
462 // read the value from the xml node
463 void Read( wxXmlNode
* node
) { m_data
->Read( node
) ; }
465 // write the value into a string
466 void Write( wxString
&s
) const { m_data
->Write( s
) ; }
468 // read the value from a string
469 void Read( const wxString
&s
) { m_data
->Read( s
) ; }
471 // returns this value as string
472 wxString
GetAsString() const
479 void SetFromString( const wxString
&s
)
484 wxxVariantData
* m_data
;
488 // ----------------------------------------------------------------------------
491 // wxPropertyInfo is used to inquire of the property by name. It doesn't
492 // provide access to the property, only information about it. If you
493 // want access, look at wxPropertyAccessor.
494 // ----------------------------------------------------------------------------
496 class WXDLLIMPEXP_BASE wxPropertyAccessor
500 class SetByRefRetBool
;
502 class SetAndGetByRef
;
503 class SetAndGetByRefRetBool
;
505 virtual void SetProperty(wxObject
*object
, const wxxVariant
&value
) const = 0 ;
506 virtual wxxVariant
GetProperty(wxObject
*object
) const = 0 ;
507 virtual bool HasSetter() const = 0 ;
508 virtual bool HasGetter() const = 0 ;
509 const wxChar
* GetGetterName() const { return m_setterName
; }
510 const wxChar
* GetSetterName() const { return m_getterName
; }
511 virtual wxxVariant
ReadValue( wxXmlNode
* node
) const = 0 ;
512 virtual void WriteValue( wxXmlNode
* node
, wxObject
*o
) const = 0 ;
513 virtual wxxVariant
ReadValue( const wxString
&value
) const = 0 ;
514 virtual void WriteValue( wxString
& value
, wxObject
*o
) const = 0 ;
516 const wxChar
*m_setterName
;
517 const wxChar
*m_getterName
;
521 void wxXmlReadValue( wxXmlNode
*node
, T
&data
) ;
524 void wxXmlWriteValue( wxXmlNode
*node
, const T
&data
) ;
526 template<class Klass
, typename T
>
527 class WXDLLIMPEXP_BASE wxPropertyAccessorT
: public wxPropertyAccessor
531 typedef void (Klass::*setter_t
)(T value
);
532 typedef bool (Klass::*setter_bool_t
)(T value
);
533 typedef void (Klass::*setter_ref_t
)(const T
& value
);
534 typedef bool (Klass::*setter_ref_bool_t
)(const T
& value
);
535 typedef T (Klass::*getter_t
)() const;
536 typedef const T
& (Klass::*getter_ref_t
)() const;
538 wxPropertyAccessorT(setter_t setter
, getter_t getter
, const wxChar
*g
, const wxChar
*s
)
539 : m_setter_bool( NULL
) , m_setter_ref_bool( NULL
) , m_setter(setter
), m_setter_ref(NULL
), m_getter(getter
) ,m_getter_ref(NULL
) {m_setterName
= s
;m_getterName
=g
;}
541 wxPropertyAccessorT( getter_t getter
, const wxChar
*g
)
542 : m_setter_bool( NULL
) , m_setter_ref_bool( NULL
) , m_setter(NULL
), m_setter_ref(NULL
), m_getter(getter
) ,m_getter_ref(NULL
) {m_setterName
= "";m_getterName
=g
;}
544 wxPropertyAccessorT(SetRetBool
*, setter_bool_t setter
, getter_t getter
, const wxChar
*g
, const wxChar
*s
)
545 : m_setter_bool( setter
) , m_setter_ref_bool( NULL
) , m_setter(NULL
), m_setter_ref(NULL
), m_getter(getter
) , m_getter_ref(NULL
){m_setterName
= s
;m_getterName
=g
;}
547 wxPropertyAccessorT(SetByRef
*, setter_ref_t setter
, getter_t getter
, const wxChar
*g
, const wxChar
*s
)
548 : m_setter_bool( NULL
) , m_setter_ref_bool( NULL
) , m_setter(NULL
), m_setter_ref(setter
), m_getter(getter
) , m_getter_ref(NULL
){m_setterName
= s
;m_getterName
=g
;}
550 wxPropertyAccessorT(SetByRefRetBool
*, setter_ref_bool_t setter
, getter_t getter
, const wxChar
*g
, const wxChar
*s
)
551 : m_setter_bool( NULL
) , m_setter_ref_bool( setter
) , m_setter(NULL
), m_setter_ref(NULL
), m_getter(getter
) , m_getter_ref(NULL
){m_setterName
= s
;m_getterName
=g
;}
552 // wxPropertyAccessorT(setter_ref_t setter, getter_t getter, const wxChar *g, const wxChar *s)
553 // : m_setter(NULL), m_setter_ref(setter), m_getter(getter) , m_getter_ref(NULL){m_setterName = s;m_getterName=g ;}
555 wxPropertyAccessorT(SetAndGetByRef
*, setter_ref_t setter
, getter_ref_t getter
, const wxChar
*g
, const wxChar
*s
)
556 : m_setter_bool( NULL
) , m_setter_ref_bool( NULL
) , m_setter(NULL
), m_setter_ref(setter
), m_getter(NULL
) , m_getter_ref(getter
){m_setterName
= s
;m_getterName
=g
;}
558 wxPropertyAccessorT(SetAndGetByRefRetBool
*, setter_ref_bool_t setter
, getter_ref_t getter
, const wxChar
*g
, const wxChar
*s
)
559 : m_setter_bool( NULL
) , m_setter_ref_bool( setter
) , m_setter(NULL
), m_setter_ref(NULL
), m_getter(NULL
) , m_getter_ref(getter
){m_setterName
= s
;m_getterName
=g
;}
561 // wxPropertyAccessorT(setter_ref_t setter, getter_ref_t getter, const wxChar *g, const wxChar *s)
562 // : m_setter(NULL), m_setter_ref(setter), m_getter(NULL) , m_getter_ref(getter){m_setterName = s;m_getterName=g ;}
564 // wxPropertyAccessorT(setter_t setter, getter_ref_t getter, const wxChar *g, const wxChar *s)
565 // : m_setter(NULL), m_setter(setter), m_getter(NULL) , m_getter_ref(getter){m_setterName = s;m_getterName=g ;}
567 wxPropertyAccessorT(GetByRef
*, setter_t setter
, getter_ref_t getter
, const wxChar
*g
, const wxChar
*s
)
568 : m_setter_bool( NULL
) , m_setter_ref_bool( NULL
) , m_setter(NULL
), m_setter(setter
), m_getter(NULL
) , m_getter_ref(getter
){m_setterName
= s
;m_getterName
=g
;}
570 // wxPropertyAccessorT( getter_ref_t getter, const wxChar *g)
571 // : m_setter(NULL), m_setter(NULL), m_getter(NULL) , m_getter_ref(getter){m_setterName = "";m_getterName=g ;}
573 // returns true if this accessor has a setter
574 bool HasSetter() const { return m_setter
!= NULL
|| m_setter_ref
!= NULL
; }
576 // return true if this accessor has a getter
577 bool HasGetter() const { return m_getter
!= NULL
|| m_getter_ref
!= NULL
; }
579 // set the property this accessor is responsible for in an object
580 void SetProperty(wxObject
*o
, const wxxVariant
&v
) const
582 Klass
*obj
= dynamic_cast<Klass
*>(o
);
585 if ( wxGetTypeInfo((T
*)NULL
)->GetKind() == wxT_OBJECT
&& v
.GetTypeInfo()->GetKind() == wxT_OBJECT_PTR
)
586 value
= *v
.Get
<T
*>();
590 (obj
->*(m_setter
))(value
);
591 else if ( m_setter_ref
)
592 (obj
->*(m_setter_ref
))(value
);
593 else if ( m_setter_ref_bool
)
594 (obj
->*(m_setter_ref_bool
))(value
);
595 else if ( m_setter_bool
)
596 (obj
->*(m_setter_bool
))(value
);
599 wxASSERT_MSG(0 , wxT("SetPropertyCalled without a valid Setter") ) ;
603 // gets the property this accessor is responsible for from an object
604 wxxVariant
GetProperty(wxObject
*o
) const
606 return wxxVariant( (wxxVariantData
* ) DoGetProperty( o
) ) ;
609 // write the property this accessor is responsible for from an object into
611 void WriteValue( wxXmlNode
* node
, wxObject
*o
) const
613 DoGetProperty( o
)->Write( node
) ;
616 // write the property this accessor is responsible for from an object into
618 void WriteValue( wxString
& s
, wxObject
*o
) const
620 DoGetProperty( o
)->Write( s
) ;
623 // read a wxxVariant having the correct type for the property this accessor
624 // is responsible for from an xml node
625 wxxVariant
ReadValue( wxXmlNode
* node
) const
628 wxXmlReadValue( node
, data
) ;
629 return wxxVariant( data
) ;
632 // read a wxxVariant having the correct type for the property this accessor
633 // is responsible for from a string
634 wxxVariant
ReadValue( const wxString
&value
) const
637 wxStringReadValue( value
, data
) ;
638 return wxxVariant( data
) ;
642 wxxVariantDataT
<T
>* DoGetProperty(wxObject
*o
) const
644 Klass
*obj
= dynamic_cast<Klass
*>(o
);
646 return new wxxVariantDataT
<T
>( (obj
->*(m_getter
))() ) ;
648 return new wxxVariantDataT
<T
>( (obj
->*(m_getter_ref
))() ) ;
652 setter_ref_t m_setter_ref
;
653 setter_ref_bool_t m_setter_ref_bool
;
654 setter_bool_t m_setter_bool
;
656 getter_ref_t m_getter_ref
;
659 class WXDLLIMPEXP_BASE wxPropertyInfo
662 wxPropertyInfo( wxPropertyInfo
* &iter
, const wxChar
*name
, const wxChar
*typeName
, const wxTypeInfo
* typeInfo
, wxPropertyAccessor
*accessor
, wxxVariant dv
) :
663 m_name( name
) , m_typeName(typeName
) , m_typeInfo( typeInfo
) , m_accessor( accessor
) , m_defaultValue( dv
)
670 wxPropertyInfo
* i
= iter
;
677 // return the name of this property
678 const wxChar
* GetName() const { return m_name
; }
680 // return the typename of this property
681 const wxChar
* GetTypeName() const { return m_typeName
; }
683 // return the type info of this property
684 const wxTypeInfo
* GetTypeInfo() const { return m_typeInfo
; }
686 // return the accessor for this property
687 wxPropertyAccessor
* GetAccessor() const { return m_accessor
; }
689 // returns NULL if this is the last property of this class
690 wxPropertyInfo
* GetNext() const { return m_next
; }
692 // returns the default value of this property, its kind may be wxT_VOID if it is not valid
693 wxxVariant
GetDefaultValue() const { return m_defaultValue
; }
695 const wxChar
* m_name
;
696 const wxChar
* m_typeName
;
697 const wxTypeInfo
* m_typeInfo
;
698 wxPropertyAccessor
* m_accessor
;
699 wxxVariant m_defaultValue
;
700 // string representation of the default value
701 // to be assigned by the designer to the property
702 // when the component is dropped on the container.
703 wxPropertyInfo
* m_next
;
706 #define WX_BEGIN_PROPERTIES_TABLE(theClass) \
707 const wxPropertyInfo *theClass::GetPropertiesStatic() \
709 typedef theClass class_t; \
710 static wxPropertyInfo* first = NULL ;
712 #define WX_END_PROPERTIES_TABLE() \
715 #define WX_PROPERTY( name , type , setter , getter ,defaultValue ) \
716 static wxPropertyAccessorT<class_t , type> _accessor##name( &setter , &getter , #setter , #getter ) ; \
717 static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
719 #define WX_PROPERTY_SET_RET_BOOL( name , type , setter , getter ,defaultValue ) \
720 static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetRetBool*)NULL , &setter , &getter , #setter , #getter ) ; \
721 static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
723 #define WX_PROPERTY_SET_BY_REF( name , type , setter , getter ,defaultValue ) \
724 static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetByRef*)NULL, &setter , &getter , #setter , #getter ) ; \
725 static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
727 #define WX_PROPERTY_SET_BY_REF_RET_BOOL( name , type , setter , getter ,defaultValue ) \
728 static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetByRefRetBool*)NULL, &setter , &getter , #setter , #getter ) ; \
729 static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
731 #define WX_PROPERTY_SET_AND_GET_BY_REF_RET_BOOL( name , type , setter , getter ,defaultValue ) \
732 static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetAndGetByRefRetBool*)NULL, &setter , &getter , #setter , #getter ) ; \
733 static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
735 #define WX_READONLY_PROPERTY( name , type , getter ,defaultValue ) \
736 static wxPropertyAccessorT<class_t , type> _accessor##name( &getter , #getter ) ; \
737 static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
739 #define WX_DELEGATE( name , eventType , eventClass ) \
740 static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \
741 static wxPropertyInfo _propertyInfo##name( first , #name , NULL , &_typeInfo##name , NULL , wxxVariant() ) ; \
743 // ----------------------------------------------------------------------------
746 // this is describing an event sink
747 // ----------------------------------------------------------------------------
752 wxHandlerInfo( wxHandlerInfo
* &iter
, const wxChar
*name
, wxObjectEventFunction address
, const wxClassInfo
* eventClassInfo
) :
753 m_name( name
) , m_eventClassInfo( eventClassInfo
) , m_eventFunction( address
)
760 wxHandlerInfo
* i
= iter
;
768 // get the name of the handler method
769 const wxChar
* GetName() const { return m_name
; }
771 // return the class info of the event
772 const wxClassInfo
* GetEventClassInfo() const { return m_eventClassInfo
; }
774 // get the handler function pointer
775 wxObjectEventFunction
GetEventFunction() const { return m_eventFunction
; }
777 // returns NULL if this is the last handler of this class
778 wxHandlerInfo
* GetNext() const { return m_next
; }
780 wxObjectEventFunction m_eventFunction
;
781 const wxChar
* m_name
;
782 const wxClassInfo
* m_eventClassInfo
;
783 wxHandlerInfo
* m_next
;
786 #define WX_HANDLER(name,eventClassType) \
787 static wxHandlerInfo _handlerInfo##name( first , #name , (wxObjectEventFunction) (wxEventFunction) &name , CLASSINFO( eventClassType ) ) ;
789 #define WX_BEGIN_HANDLERS_TABLE(theClass) \
790 const wxHandlerInfo *theClass::GetHandlersStatic() \
792 typedef theClass class_t; \
793 static wxHandlerInfo* first = NULL ;
795 #define WX_END_HANDLERS_TABLE() \
798 // ----------------------------------------------------------------------------
799 // Constructor Bridges
801 // allow to set up constructors with params during runtime
802 // ----------------------------------------------------------------------------
804 class WXDLLIMPEXP_BASE wxConstructorBridge
807 virtual void Create(wxObject
*o
, wxxVariant
*args
) = 0;
810 // Creator Bridges for all Numbers of Params
814 template<typename Class
>
815 struct wxConstructorBridge_0
: public wxConstructorBridge
817 void Create(wxObject
*o
, wxxVariant
*)
819 Class
*obj
= dynamic_cast<Class
*>(o
);
824 struct wxConstructorBridge_Dummy
: public wxConstructorBridge
826 void Create(wxObject
*, wxxVariant
*)
831 #define WX_CONSTRUCTOR_0(klass) \
832 wxConstructorBridge_0<klass> constructor##klass ; \
833 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
834 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
835 const int klass::sm_constructorPropertiesCount##klass = 0 ;
837 #define WX_CONSTRUCTOR_DUMMY(klass) \
838 wxConstructorBridge_Dummy constructor##klass ; \
839 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
840 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
841 const int klass::sm_constructorPropertiesCount##klass = 0 ;
845 template<typename Class
, typename T0
>
846 struct wxConstructorBridge_1
: public wxConstructorBridge
848 void Create(wxObject
*o
, wxxVariant
*args
)
850 Class
*obj
= dynamic_cast<Class
*>(o
);
857 #define WX_CONSTRUCTOR_1(klass,t0,v0) \
858 wxConstructorBridge_1<klass,t0> constructor##klass ; \
859 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
860 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 } ; \
861 const int klass::sm_constructorPropertiesCount##klass = 1 ;
865 template<typename Class
,
866 typename T0
, typename T1
>
867 struct wxConstructorBridge_2
: public wxConstructorBridge
869 void Create(wxObject
*o
, wxxVariant
*args
)
871 Class
*obj
= dynamic_cast<Class
*>(o
);
879 #define WX_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
880 wxConstructorBridge_2<klass,t0,t1> constructor##klass ; \
881 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
882 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 } ; \
883 const int klass::sm_constructorPropertiesCount##klass = 2;
887 template<typename Class
,
888 typename T0
, typename T1
, typename T2
>
889 struct wxConstructorBridge_3
: public wxConstructorBridge
891 void Create(wxObject
*o
, wxxVariant
*args
)
893 Class
*obj
= dynamic_cast<Class
*>(o
);
902 #define WX_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
903 wxConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \
904 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
905 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 } ; \
906 const int klass::sm_constructorPropertiesCount##klass = 3 ;
910 template<typename Class
,
911 typename T0
, typename T1
, typename T2
, typename T3
>
912 struct wxConstructorBridge_4
: public wxConstructorBridge
914 void Create(wxObject
*o
, wxxVariant
*args
)
916 Class
*obj
= dynamic_cast<Class
*>(o
);
926 #define WX_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
927 wxConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass ; \
928 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
929 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 } ; \
930 const int klass::sm_constructorPropertiesCount##klass = 4 ;
934 template<typename Class
,
935 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
>
936 struct wxConstructorBridge_5
: public wxConstructorBridge
938 void Create(wxObject
*o
, wxxVariant
*args
)
940 Class
*obj
= dynamic_cast<Class
*>(o
);
951 #define WX_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
952 wxConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass ; \
953 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
954 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 } ; \
955 const int klass::sm_constructorPropertiesCount##klass = 5;
959 template<typename Class
,
960 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
961 struct wxConstructorBridge_6
: public wxConstructorBridge
963 void Create(wxObject
*o
, wxxVariant
*args
)
965 Class
*obj
= dynamic_cast<Class
*>(o
);
977 #define WX_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
978 wxConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
979 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
980 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 } ; \
981 const int klass::sm_constructorPropertiesCount##klass = 6;
984 // ----------------------------------------------------------------------------
986 // ----------------------------------------------------------------------------
988 typedef wxObject
*(*wxObjectConstructorFn
)(void);
989 typedef wxObject
* (*wxVariantToObjectConverter
)( wxxVariant
&data
) ;
990 typedef wxxVariant (*wxObjectToVariantConverter
)( wxObject
* ) ;
992 class WXDLLIMPEXP_BASE wxClassInfo
995 wxClassInfo(const wxClassInfo
**_Parents
,
996 const wxChar
*_UnitName
,
997 const wxChar
*_ClassName
,
999 wxObjectConstructorFn ctor
,
1000 const wxPropertyInfo
*_Props
,
1001 const wxHandlerInfo
*_Handlers
,
1002 wxConstructorBridge
* _Constructor
,
1003 const wxChar
** _ConstructorProperties
,
1004 const int _ConstructorPropertiesCount
,
1005 wxVariantToObjectConverter _PtrConverter1
,
1006 wxVariantToObjectConverter _Converter2
,
1007 wxObjectToVariantConverter _Converter3
1008 ) : m_parents(_Parents
) , m_unitName(_UnitName
) ,m_className(_ClassName
),
1009 m_objectSize(size
), m_objectConstructor(ctor
) , m_firstProperty(_Props
) , m_firstHandler(_Handlers
) , m_constructor( _Constructor
) ,
1010 m_constructorProperties(_ConstructorProperties
) , m_constructorPropertiesCount(_ConstructorPropertiesCount
),
1011 m_variantOfPtrToObjectConverter( _PtrConverter1
) , m_variantToObjectConverter( _Converter2
) , m_objectToVariantConverter( _Converter3
) , m_next(sm_first
)
1014 Register( m_className
, this ) ;
1017 virtual ~wxClassInfo() ;
1019 wxObject
*CreateObject() const { return m_objectConstructor
? (*m_objectConstructor
)() : 0; }
1021 const wxChar
*GetClassName() const { return m_className
; }
1022 const wxClassInfo
**GetParents() const { return m_parents
; }
1023 int GetSize() const { return m_objectSize
; }
1025 wxObjectConstructorFn
GetConstructor() const { return m_objectConstructor
; }
1026 static const wxClassInfo
*GetFirst() { return sm_first
; }
1027 const wxClassInfo
*GetNext() const { return m_next
; }
1028 static wxClassInfo
*FindClass(const wxChar
*className
);
1030 // Climb upwards through inheritance hierarchy.
1031 // Dual inheritance is catered for.
1033 bool IsKindOf(const wxClassInfo
*info
) const
1040 for ( int i
= 0 ; m_parents
[i
] ; ++ i
)
1042 if ( m_parents
[i
]->IsKindOf( info
) )
1049 // Initializes parent pointers and hash table for fast searching.
1050 // this is going to be removed by Register/Unregister calls
1051 // in Constructor / Destructor together with making the hash map private
1053 static void InitializeClasses();
1055 // Cleans up hash table used for fast searching.
1057 static void CleanUpClasses();
1059 // returns the first property
1060 const wxPropertyInfo
* GetFirstProperty() const { return m_firstProperty
; }
1062 // returns the first handler
1063 const wxHandlerInfo
* GetFirstHandler() const { return m_firstHandler
; }
1065 // Call the Create method for a class
1066 virtual void Create (wxObject
*object
, int ParamCount
, wxxVariant
*Params
) const
1068 wxASSERT_MSG( ParamCount
== m_constructorPropertiesCount
, wxT("Illegal Parameter Count for Create Method")) ;
1069 m_constructor
->Create( object
, Params
) ;
1072 // get number of parameters for constructor
1073 virtual int GetCreateParamCount() const { return m_constructorPropertiesCount
; }
1075 // get i-th constructor parameter
1076 virtual const wxChar
* GetCreateParamName(int i
) const { return m_constructorProperties
[i
] ; }
1078 // Runtime access to objects by property name, and variant data
1079 virtual void SetProperty (wxObject
*object
, const wxChar
*PropertyName
, const wxxVariant
&Value
);
1080 virtual wxxVariant
GetProperty (wxObject
*object
, const wxChar
*PropertyName
);
1082 // we must be able to cast variants to wxObject pointers, templates seem not to be suitable
1083 wxObject
* VariantToInstance( wxxVariant
&data
) const
1084 { if ( data
.GetTypeInfo()->GetKind() == wxT_OBJECT
)
1085 return m_variantToObjectConverter( data
) ;
1087 return m_variantOfPtrToObjectConverter( data
) ;
1090 wxxVariant
InstanceToVariant( wxObject
*object
) const { return m_objectToVariantConverter( object
) ; }
1092 // find property by name
1093 virtual const wxPropertyInfo
*FindPropertyInfo (const wxChar
*PropertyName
) const ;
1095 // find handler by name
1096 virtual const wxHandlerInfo
*FindHandlerInfo (const wxChar
*PropertyName
) const ;
1099 const wxChar
*m_className
;
1101 wxObjectConstructorFn m_objectConstructor
;
1103 // class info object live in a linked list:
1104 // pointers to its head and the next element in it
1106 static wxClassInfo
*sm_first
;
1107 wxClassInfo
*m_next
;
1109 // FIXME: this should be private (currently used directly by way too
1111 static wxHashTable
*sm_classTable
;
1114 const wxClassInfo
** m_parents
;
1115 const wxPropertyInfo
* m_firstProperty
;
1116 const wxHandlerInfo
* m_firstHandler
;
1117 const wxChar
* m_unitName
;
1119 wxConstructorBridge
* m_constructor
;
1120 const wxChar
** m_constructorProperties
;
1121 const int m_constructorPropertiesCount
;
1122 wxVariantToObjectConverter m_variantOfPtrToObjectConverter
;
1123 wxVariantToObjectConverter m_variantToObjectConverter
;
1124 wxObjectToVariantConverter m_objectToVariantConverter
;
1126 const wxPropertyAccessor
*FindAccessor (const wxChar
*propertyName
);
1128 // registers the class
1129 static void Register(const wxChar
*name
, wxClassInfo
*info
);
1131 static void Unregister(const wxChar
*name
);
1133 // InitializeClasses() helper
1134 static wxClassInfo
*GetBaseByName(const wxChar
*name
);
1136 DECLARE_NO_COPY_CLASS(wxClassInfo
)
1139 WXDLLIMPEXP_BASE wxObject
*wxCreateDynamicObject(const wxChar
*name
);
1141 // ----------------------------------------------------------------------------
1142 // Dynamic class macros
1143 // ----------------------------------------------------------------------------
1145 #define _DECLARE_DYNAMIC_CLASS(name) \
1147 static wxClassInfo sm_class##name; \
1148 static const wxClassInfo* sm_classParents##name[] ; \
1149 static const wxPropertyInfo* GetPropertiesStatic() ; \
1150 static const wxHandlerInfo* GetHandlersStatic() ; \
1151 virtual wxClassInfo *GetClassInfo() const \
1152 { return &name::sm_class##name; }
1154 #define DECLARE_DYNAMIC_CLASS(name) \
1155 _DECLARE_DYNAMIC_CLASS(name) \
1156 static wxConstructorBridge* sm_constructor##name ; \
1157 static const wxChar * sm_constructorProperties##name[] ; \
1158 static const int sm_constructorPropertiesCount##name ;
1160 #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
1161 DECLARE_NO_ASSIGN_CLASS(name) \
1162 DECLARE_DYNAMIC_CLASS(name)
1164 #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \
1165 DECLARE_NO_COPY_CLASS(name) \
1166 DECLARE_DYNAMIC_CLASS(name)
1168 #define DECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name)
1169 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
1171 // -----------------------------------
1172 // for concrete classes
1173 // -----------------------------------
1175 // Single inheritance with one base class
1177 #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit) \
1178 wxObject* wxConstructorFor##name() \
1179 { return new name; } \
1180 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1181 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1182 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1183 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1184 (int) sizeof(name), \
1185 (wxObjectConstructorFn) wxConstructorFor##name , \
1186 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1187 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name); \
1188 template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1189 template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1190 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1191 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1192 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1193 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1195 #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit) \
1196 wxObject* wxConstructorFor##name() \
1197 { return new name; } \
1198 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1199 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return &data.Get<name>() ; } \
1200 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1201 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1202 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1203 (int) sizeof(name), \
1204 (wxObjectConstructorFn) wxConstructorFor##name , \
1205 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1206 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1207 template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1208 template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1209 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1210 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1211 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1212 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1214 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \
1215 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" ) \
1216 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1217 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1218 WX_CONSTRUCTOR_DUMMY( name )
1220 #define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \
1221 _IMPLEMENT_DYNAMIC_CLASS( name , basename , "" ) \
1222 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1223 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1224 WX_CONSTRUCTOR_DUMMY( name )
1226 #define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \
1227 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit )
1229 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \
1230 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit )
1232 // this is for classes that do not derive from wxobject, there are no creators for these
1234 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name , unit ) \
1235 const wxClassInfo* name::sm_classParents##name[] = { NULL } ; \
1236 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1237 (int) sizeof(name), \
1238 (wxObjectConstructorFn) 0 , \
1239 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1241 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1242 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1243 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1245 // this is for subclasses that still do not derive from wxobject
1247 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name , basename, unit ) \
1248 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1249 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1250 (int) sizeof(name), \
1251 (wxObjectConstructorFn) 0 , \
1252 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1254 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1255 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1256 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1258 // Multiple inheritance with two base classes
1260 #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit) \
1261 wxObject* wxConstructorFor##name() \
1262 { return new name; } \
1263 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,&basename2::sm_class##basename2 , NULL } ; \
1264 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1265 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1266 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1267 (int) sizeof(name), \
1268 (wxObjectConstructorFn) wxConstructorFor##name , \
1269 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1270 name::sm_constructorPropertiesCount##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1271 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1272 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1273 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1275 #define IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2) \
1276 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , "") \
1277 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1278 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1279 WX_CONSTRUCTOR_DUMMY( name )
1281 #define IMPLEMENT_DYNAMIC_CLASS2_XTI( name , basename , basename2, unit) \
1282 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , unit)
1284 // -----------------------------------
1285 // for abstract classes
1286 // -----------------------------------
1288 // Single inheritance with one base class
1290 #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
1291 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1292 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1293 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1294 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1295 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1296 (int) sizeof(name), \
1297 (wxObjectConstructorFn) 0 , \
1298 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1299 0 , wxVariantOfPtrToObjectConverter##name ,wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1300 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1301 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1302 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1304 #define IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1305 _IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1306 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1307 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; }
1309 // Multiple inheritance with two base classes
1311 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
1312 wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \
1313 wxT(#basename2), (int) sizeof(name), \
1314 (wxObjectConstructorFn) 0);
1316 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
1317 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2