]> git.saurik.com Git - wxWidgets.git/blob - include/wx/xti.h
added wxDynamicObject (kind of delegate, docs to come once this has calmed down)
[wxWidgets.git] / include / wx / xti.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/xti.h
3 // Purpose: runtime metadata information (extended class info)
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 27/07/03
7 // RCS-ID: $Id$
8 // Copyright: (c) 1997 Julian Smart
9 // (c) 2003 Stefan Csomor
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef _WX_XTIH__
14 #define _WX_XTIH__
15
16 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
17 #pragma interface "xti.h"
18 #endif
19
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.
23 //
24 // This means we have the following domains :
25 //
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
34
35 // ----------------------------------------------------------------------------
36 // headers
37 // ----------------------------------------------------------------------------
38
39 #include "wx/defs.h"
40 #include "wx/memory.h"
41 #include "wx/set.h"
42 #include "wx/string.h"
43 #include "wx/arrstr.h"
44
45 // some compilers have troubles getting the correct wxPropertyAccessorT constructor
46 // set this to 1 to make things work for these, too
47
48 #ifndef WX_XTI_TEMPLATE_FIX
49 #define WX_XTI_TEMPLATE_FIX 0
50 #endif
51
52 #if WX_XTI_TEMPLATE_FIX
53 #define WX_XTI_PARAM_FIX(a,b) a,b
54 #else
55 #define WX_XTI_PARAM_FIX(a,b)
56 #endif
57
58 class WXDLLIMPEXP_BASE wxObject;
59 class WXDLLIMPEXP_BASE wxClassInfo;
60 class WXDLLIMPEXP_BASE wxHashTable;
61 class WXDLLIMPEXP_BASE wxObjectRefData;
62 class WXDLLIMPEXP_BASE wxEvent;
63
64 typedef void (wxObject::*wxObjectEventFunction)(wxEvent&);
65
66 // ----------------------------------------------------------------------------
67 // Enum Support
68 //
69 // In the header files there would no change from pure c++ code, in the
70 // implementation, an enum would have
71 // to be enumerated eg :
72 //
73 // WX_BEGIN_ENUM( wxFlavor )
74 // WX_ENUM_MEMBER( Vanilla )
75 // WX_ENUM_MEMBER( Chocolate )
76 // WX_ENUM_MEMBER( Strawberry )
77 // WX_END_ENUM( wxFlavor )
78 // ----------------------------------------------------------------------------
79
80 struct WXDLLIMPEXP_BASE wxEnumMemberData
81 {
82 const wxChar* m_name;
83 int m_value;
84 };
85
86 class WXDLLIMPEXP_BASE wxEnumData
87 {
88 public :
89 wxEnumData( wxEnumMemberData* data ) ;
90
91 // returns true if the member has been found and sets the int value
92 // pointed to accordingly (if ptr != null )
93 // if not found returns false, value left unchanged
94 bool HasEnumMemberValue( const wxChar *name , int *value = NULL ) ;
95
96 // returns the value of the member, if not found in debug mode an
97 // assert is issued, in release 0 is returned
98 int GetEnumMemberValue(const wxChar *name );
99
100 // returns the name of the enum member having the passed in value
101 // returns an emtpy string if not found
102 const wxChar *GetEnumMemberName(int value);
103
104 // returns the number of members in this enum
105 int GetEnumCount() { return m_count ; }
106
107 // returns the value of the nth member
108 int GetEnumMemberValueByIndex( int n ) ;
109
110 // returns the value of the nth member
111 const wxChar *GetEnumMemberNameByIndex( int n ) ;
112 private :
113 wxEnumMemberData *m_members;
114 int m_count ;
115 };
116
117 #define WX_BEGIN_ENUM( e ) \
118 wxEnumMemberData s_enumDataMembers##e[] = {
119
120 #define WX_ENUM_MEMBER( v ) { #v, v } ,
121
122 #define WX_END_ENUM( e ) { NULL , 0 } } ; \
123 wxEnumData s_enumData##e( s_enumDataMembers##e ) ; \
124 wxEnumData *wxGetEnumData(e) { return &s_enumData##e ; } \
125 template<> const wxTypeInfo* wxGetTypeInfo( e * ){ static wxEnumTypeInfo s_typeInfo(wxT_ENUM , &s_enumData##e) ; return &s_typeInfo ; } \
126 template<> void wxStringReadValue(const wxString& s , e &data ) \
127 { \
128 data = (e) s_enumData##e.GetEnumMemberValue(s) ; \
129 } \
130 template<> void wxStringWriteValue(wxString &s , const e &data ) \
131 { \
132 s = s_enumData##e.GetEnumMemberName((int)data) ; \
133 } \
134 template<> const wxTypeInfo* wxGetTypeInfo( e ** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; assert(0) ; return &s_typeInfo ; } \
135 template<> void wxStringReadValue(const wxString& , e* & ) \
136 { \
137 assert(0) ; \
138 } \
139 template<> void wxStringWriteValue(wxString &s , e* const & ) \
140 { \
141 assert(0) ; \
142 }
143
144 // ----------------------------------------------------------------------------
145 // Set Support
146 //
147 // in the header :
148 //
149 // enum wxFlavor
150 // {
151 // Vanilla,
152 // Chocolate,
153 // Strawberry,
154 // };
155 //
156 // typedef wxSet<wxFlavor> wxCoupe ;
157 //
158 // in the implementation file :
159 //
160 // WX_BEGIN_ENUM( wxFlavor )
161 // WX_ENUM_MEMBER( Vanilla )
162 // WX_ENUM_MEMBER( Chocolate )
163 // WX_ENUM_MEMBER( Strawberry )
164 // WX_END_ENUM( wxFlavor )
165 //
166 // WX_IMPLEMENT_SET_STREAMING( wxCoupe , wxFlavor )
167 //
168 // implementation note : no partial specialization for streaming, but a delegation to a
169 // different class
170 //
171 // ----------------------------------------------------------------------------
172
173 // in order to remove dependancy on string tokenizer
174 void wxSetStringToArray( const wxString &s , wxArrayString &array ) ;
175
176 template<typename e>
177 void wxSetFromString(const wxString &s , wxSet<e> &data )
178 {
179 wxEnumData* edata = wxGetEnumData((e) 0) ;
180 data.Clear() ;
181
182 wxArrayString array ;
183 wxSetStringToArray( s , array ) ;
184 wxString flag;
185 for ( int i = 0 ; i < array.Count() ; ++i )
186 {
187 flag = array[i] ;
188 int ivalue ;
189 if ( edata->HasEnumMemberValue( flag , &ivalue ) )
190 {
191 data.Set( (e) ivalue ) ;
192 }
193 }
194 }
195
196 template<typename e>
197 void wxSetToString( wxString &s , const wxSet<e> &data )
198 {
199 wxEnumData* edata = wxGetEnumData((e) 0) ;
200 int count = edata->GetEnumCount() ;
201 int i ;
202 s.Clear() ;
203 for ( i = 0 ; i < count ; i++ )
204 {
205 e value = (e) edata->GetEnumMemberValueByIndex(i) ;
206 if ( data.Contains( value ) )
207 {
208 // this could also be done by the templated calls
209 if ( !s.IsEmpty() )
210 s +="|" ;
211 s += edata->GetEnumMemberNameByIndex(i) ;
212 }
213 }
214 }
215
216 // if the wxSet specialization above does not work for all compilers, add this to the WX_IMPLEMENT_SET_STREAMING macro
217 // template<> const wxTypeInfo* wxGetTypeInfo( SetName * ){ static wxEnumTypeInfo s_typeInfo(wxT_SET , &s_enumData##e) ; return &s_typeInfo ; }
218
219 #define WX_IMPLEMENT_SET_STREAMING(SetName,e) \
220 template<> void wxStringReadValue(const wxString &s , wxSet<e> &data ) \
221 { \
222 wxSetFromString( s , data ) ; \
223 } \
224 template<> void wxStringWriteValue( wxString &s , const wxSet<e> &data ) \
225 { \
226 wxSetToString( s , data ) ; \
227 } \
228
229
230 // ----------------------------------------------------------------------------
231 // Type Information
232 // ----------------------------------------------------------------------------
233
234 enum wxTypeKind
235 {
236 wxT_VOID = 0, // unknown type
237 wxT_BOOL,
238 wxT_CHAR,
239 wxT_UCHAR,
240 wxT_INT,
241 wxT_UINT,
242 wxT_LONG,
243 wxT_ULONG,
244 wxT_FLOAT,
245 wxT_DOUBLE,
246 wxT_STRING, // must be wxString
247 wxT_SET, // must be wxSet<> template
248 wxT_ENUM,
249 wxT_OBJECT_PTR, // pointer to wxObject
250 wxT_OBJECT , // wxObject
251 wxT_CUSTOM, // user defined type (e.g. wxPoint)
252 wxT_DELEGATE , // for connecting against an event source
253 wxT_LAST_TYPE_KIND // sentinel for bad data, asserts, debugging
254 };
255
256 class WXDLLIMPEXP_BASE wxTypeInfo
257 {
258 public :
259 wxTypeInfo() : m_kind( wxT_VOID) {}
260 virtual ~wxTypeInfo() {}
261 wxTypeKind GetKind() const { return m_kind ; }
262 bool IsDelegateType() const { return m_kind == wxT_DELEGATE ; }
263 bool IsCustomType() const { return m_kind == wxT_CUSTOM ; }
264 bool IsObjectType() const { return m_kind == wxT_OBJECT || m_kind == wxT_OBJECT_PTR ; }
265 protected :
266 wxTypeKind m_kind ;
267 };
268
269 class WXDLLIMPEXP_BASE wxBuiltInTypeInfo : public wxTypeInfo
270 {
271 public :
272 wxBuiltInTypeInfo( wxTypeKind kind ) { wxASSERT_MSG( kind < wxT_SET , wxT("Illegal Kind for Base Type") ) ; m_kind = kind ;}
273 } ;
274
275 class WXDLLIMPEXP_BASE wxCustomTypeInfo : public wxTypeInfo
276 {
277 public :
278 wxCustomTypeInfo( const wxChar *typeName )
279 { m_kind = wxT_CUSTOM ; m_typeName = typeName ;}
280 const wxChar *GetTypeName() const { return m_typeName ; }
281 private :
282 const wxChar *m_typeName; // Kind == wxT_CUSTOM
283 } ;
284
285 class WXDLLIMPEXP_BASE wxEnumTypeInfo : public wxTypeInfo
286 {
287 public :
288 wxEnumTypeInfo( wxTypeKind kind , wxEnumData* enumInfo )
289 { wxASSERT_MSG( kind == wxT_ENUM || kind == wxT_SET , wxT("Illegal Kind for Enum Type")) ; m_kind = kind ; m_enumInfo = enumInfo ;}
290 const wxEnumData* GetEnumData() const { return m_enumInfo ; }
291 private :
292 wxEnumData *m_enumInfo; // Kind == wxT_ENUM or Kind == wxT_SET
293 } ;
294
295 class WXDLLIMPEXP_BASE wxClassTypeInfo : public wxTypeInfo
296 {
297 public :
298 wxClassTypeInfo( wxTypeKind kind , wxClassInfo* classInfo )
299 { wxASSERT_MSG( kind == wxT_OBJECT_PTR || kind == wxT_OBJECT , wxT("Illegal Kind for Enum Type")) ; m_kind = kind ; m_classInfo = classInfo ;}
300 const wxClassInfo *GetClassInfo() const { return m_classInfo ; }
301 private :
302 wxClassInfo *m_classInfo; // Kind == wxT_OBJECT - could be NULL
303 } ;
304
305 // a delegate is an exposed event source
306
307 class WXDLLIMPEXP_BASE wxDelegateTypeInfo : public wxTypeInfo
308 {
309 public :
310 wxDelegateTypeInfo( int eventType , wxClassInfo* eventClass )
311 { m_kind = wxT_DELEGATE ; m_eventClass = eventClass ; m_eventType = eventType ;}
312 const wxClassInfo *GetEventClass() const { assert( m_kind == wxT_DELEGATE ) ; return m_eventClass ; }
313 int GetEventType() const { return m_eventType ; }
314 private :
315 const wxClassInfo *m_eventClass; // (extended will merge into classinfo)
316 int m_eventType ;
317 } ;
318
319 template<typename T> const wxTypeInfo* wxGetTypeInfo( T * ) ;
320
321 template<typename T> const wxTypeInfo* wxGetTypeInfo( wxSet<T> * )
322 {
323 static wxEnumTypeInfo s_typeInfo(wxT_SET , wxGetEnumData((T) 0) ) ; return &s_typeInfo ;
324 }
325
326 // this macro is for usage with custom, non-object derived classes and structs, wxPoint is such a custom type
327
328 #define WX_CUSTOM_TYPE_INFO( e ) \
329 template<> const wxTypeInfo* wxGetTypeInfo( e ** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID) ; assert(0) ; return &s_typeInfo ; } \
330 template<> const wxTypeInfo* wxGetTypeInfo( e * ){ static wxCustomTypeInfo s_typeInfo(#e) ; return &s_typeInfo ; }
331
332 // templated streaming, every type must have their specialization for these methods
333
334 template<typename T>
335 void wxStringReadValue( const wxString &s , T &data );
336
337 template<typename T>
338 void wxStringWriteValue( wxString &s , const T &data);
339
340 // sometimes a compiler invents specializations that are nowhere called, use this macro to satisfy the refs
341
342 #define WX_ILLEGAL_TYPE_SPECIALIZATION( a ) \
343 template<> const wxTypeInfo* wxGetTypeInfo( a * ) { assert(0) ; \
344 static wxBuiltInTypeInfo s_typeInfo( wxT_VOID ) ; return &s_typeInfo ; } \
345 template<> void wxStringReadValue(const wxString & , a & ) { assert(0) ; }\
346 template<> void wxStringWriteValue(wxString & , a const & ) { assert(0) ; }
347
348 // ----------------------------------------------------------------------------
349 // wxxVariant as typesafe data holder
350 // ----------------------------------------------------------------------------
351
352 class WXDLLIMPEXP_BASE wxxVariantData
353 {
354 public:
355 virtual ~wxxVariantData() {}
356
357 // return a heap allocated duplicate
358 virtual wxxVariantData* Clone() const = 0 ;
359
360 // returns the type info of the contentc
361 virtual const wxTypeInfo* GetTypeInfo() const = 0 ;
362
363 // write the value into a string
364 virtual void Write( wxString &s ) const = 0 ;
365
366 // read the value from a string
367 virtual void Read( const wxString &s) = 0 ;
368 } ;
369
370 template<typename T> class WXDLLIMPEXP_BASE wxxVariantDataT : public wxxVariantData
371 {
372 public:
373 wxxVariantDataT(const T& d) : m_data(d) {}
374 virtual ~wxxVariantDataT() {}
375
376 // get a ref to the stored data
377 T & Get() { return m_data; }
378
379 // get a const ref to the stored data
380 const T & Get() const { return m_data; }
381
382 // set the data
383 void Set(const T& d) { m_data = d; }
384
385 // return a heap allocated duplicate
386 virtual wxxVariantData* Clone() const { return new wxxVariantDataT<T>( Get() ) ; }
387
388 // returns the type info of the contentc
389 virtual const wxTypeInfo* GetTypeInfo() const { return wxGetTypeInfo( (T*) NULL ) ; }
390
391 // write the value into a string
392 virtual void Write( wxString &s ) const { wxStringWriteValue( s , m_data ) ; }
393
394 // read the value from a string
395 virtual void Read( const wxString &s) { wxStringReadValue( s , m_data ) ; }
396
397 private:
398 T m_data;
399 };
400
401 class WXDLLIMPEXP_BASE wxxVariant
402 {
403 public :
404 wxxVariant() { m_data = NULL ; }
405 wxxVariant( wxxVariantData* data , const wxString& name = wxT("") ) : m_data(data) , m_name(name) {}
406 wxxVariant( const wxxVariant &d ) { if ( d.m_data ) m_data = d.m_data->Clone() ; else m_data = NULL ; m_name = d.m_name ; }
407
408 template<typename T> wxxVariant( T data , const wxString& name = wxT("") ) :
409 m_data(new wxxVariantDataT<T>(data) ), m_name(name) {}
410 ~wxxVariant() { delete m_data ; }
411
412 // get a ref to the stored data
413 template<typename T> T& Get()
414 {
415 wxxVariantDataT<T> *dataptr = dynamic_cast<wxxVariantDataT<T>*> (m_data) ;
416 wxASSERT_MSG( dataptr , "Cast not possible" ) ;
417 return dataptr->Get() ;
418 }
419
420 // get a ref to the stored data
421 template<typename T> const T& Get() const
422 {
423 const wxxVariantDataT<T> *dataptr = dynamic_cast<const wxxVariantDataT<T>*> (m_data) ;
424 wxASSERT_MSG( dataptr , "Cast not possible" ) ;
425 return dataptr->Get() ;
426 }
427
428 // stores the data
429 template<typename T> void Set(const T& data) const
430 {
431 delete m_data ;
432 m_data = new wxxVariantDataT<T>(data) ;
433 }
434
435 wxxVariant& operator=(const wxxVariant &d)
436 {
437 m_data = d.m_data->Clone() ;
438 m_name = d.m_name ;
439 return *this ;
440 }
441
442 // gets the stored data casted to a wxObject* , returning NULL if cast is not possible
443 wxObject* GetAsObject() ;
444
445 // get the typeinfo of the stored object
446 const wxTypeInfo* GetTypeInfo() const { return m_data->GetTypeInfo() ; }
447
448 // write the value into a string
449 void Write( wxString &s ) const { m_data->Write( s ) ; }
450
451 // read the value from a string
452 void Read( const wxString &s) { m_data->Read( s ) ; }
453
454 // returns this value as string
455 wxString GetAsString() const
456 {
457 wxString s ;
458 Write( s ) ;
459 return s ;
460 }
461
462 void SetFromString( const wxString &s)
463 {
464 Read( s ) ;
465 }
466 private :
467 wxxVariantData* m_data ;
468 wxString m_name ;
469 } ;
470
471 // ----------------------------------------------------------------------------
472 // Property Support
473 //
474 // wxPropertyInfo is used to inquire of the property by name. It doesn't
475 // provide access to the property, only information about it. If you
476 // want access, look at wxPropertyAccessor.
477 // ----------------------------------------------------------------------------
478
479 class WXDLLIMPEXP_BASE wxPropertyAccessor
480 {
481 public :
482 #if WX_XTI_TEMPLATE_FIX
483 class SetByRef ;
484 class SetByRefRetBool ;
485 class SetRetBool ;
486 class SetAndGetByRef ;
487 class SetAndGetByRefRetBool ;
488 class GetByRef ;
489 #endif
490 wxPropertyAccessor() { m_setterName = NULL ; m_getterName = NULL ; }
491 virtual ~wxPropertyAccessor() {}
492 virtual void SetProperty(wxObject *object, const wxxVariant &value) const = 0 ;
493 virtual wxxVariant GetProperty(const wxObject *object) const = 0 ;
494 virtual bool HasSetter() const = 0 ;
495 virtual bool HasGetter() const = 0 ;
496 const wxChar * GetGetterName() const { return m_setterName ; }
497 const wxChar * GetSetterName() const { return m_getterName ; }
498 virtual wxxVariant ReadValue( const wxString &value ) const = 0 ;
499 virtual void WriteValue( wxString& value , const wxObject *o ) const = 0 ;
500 protected :
501 const wxChar *m_setterName ;
502 const wxChar *m_getterName ;
503 };
504
505 class WXDLLIMPEXP_BASE wxGenericPropertyAccessor : public wxPropertyAccessor
506 {
507 public :
508 wxGenericPropertyAccessor( const wxChar* propertyName ) ;
509 ~wxGenericPropertyAccessor() ;
510 virtual void SetProperty(wxObject *object, const wxxVariant &value) const ;
511 virtual wxxVariant GetProperty(const wxObject *object) const ;
512 virtual bool HasSetter() const { return true ; }
513 virtual bool HasGetter() const { return true ; }
514 virtual wxxVariant ReadValue( const wxString &value ) const ;
515 virtual void WriteValue( wxString& value , const wxObject *o ) const ;
516 private :
517 struct wxGenericPropertyAccessorInternal ;
518 wxGenericPropertyAccessorInternal* m_data ;
519 } ;
520
521 template<class Klass, typename T>
522 class WXDLLIMPEXP_BASE wxPropertyAccessorT : public wxPropertyAccessor
523 {
524 public:
525
526 typedef void (Klass::*setter_t)(T value);
527 typedef bool (Klass::*setter_bool_t)(T value);
528 typedef void (Klass::*setter_ref_t)(const T& value);
529 typedef bool (Klass::*setter_ref_bool_t)(const T& value);
530 typedef T (Klass::*getter_t)() const;
531 typedef const T& (Klass::*getter_ref_t)() const;
532
533 wxPropertyAccessorT(setter_t setter, getter_t getter, const wxChar *g, const wxChar *s)
534 : 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 ;}
535
536 wxPropertyAccessorT( getter_t getter, const wxChar *g)
537 : 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 ;}
538
539 wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetRetBool*,) setter_bool_t setter, getter_t getter, const wxChar *g, const wxChar *s)
540 : 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 ;}
541
542 wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetByRef*,) setter_ref_t setter, getter_t getter, const wxChar *g, const wxChar *s)
543 : 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 ;}
544
545 wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetByRefRetBool*,) setter_ref_bool_t setter, getter_t getter, const wxChar *g, const wxChar *s)
546 : 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 ;}
547
548 wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetAndGetByRef*,) setter_ref_t setter, getter_ref_t getter, const wxChar *g, const wxChar *s)
549 : 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 ;}
550
551 wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetAndGetByRefRetBool*,) setter_ref_bool_t setter, getter_ref_t getter, const wxChar *g, const wxChar *s)
552 : 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 ;}
553
554 wxPropertyAccessorT(WX_XTI_PARAM_FIX(GetByRef*,) setter_t setter, getter_ref_t getter, const wxChar *g, const wxChar *s)
555 : 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 ;}
556
557 // returns true if this accessor has a setter
558 bool HasSetter() const { return m_setter != NULL || m_setter_ref != NULL || m_setter_ref_bool != NULL || m_setter_bool ; }
559
560 // return true if this accessor has a getter
561 bool HasGetter() const { return m_getter != NULL || m_getter_ref != NULL ; }
562
563 // set the property this accessor is responsible for in an object
564 void SetProperty(wxObject *o, const wxxVariant &v) const
565 {
566 Klass *obj = dynamic_cast<Klass*>(o);
567 T value ;
568
569 if ( wxGetTypeInfo((T*)NULL)->GetKind() == wxT_OBJECT && v.GetTypeInfo()->GetKind() == wxT_OBJECT_PTR )
570 value = *v.Get<T*>();
571 else
572 value = v.Get<T>();
573 if (m_setter)
574 (obj->*(m_setter))(value);
575 else if ( m_setter_ref )
576 (obj->*(m_setter_ref))(value);
577 else if ( m_setter_ref_bool )
578 (obj->*(m_setter_ref_bool))(value);
579 else if ( m_setter_bool )
580 (obj->*(m_setter_bool))(value);
581 else
582 {
583 wxASSERT_MSG(0 , wxT("SetPropertyCalled without a valid Setter") ) ;
584 }
585 }
586
587 // gets the property this accessor is responsible for from an object
588 wxxVariant GetProperty(const wxObject *o) const
589 {
590 return wxxVariant( (wxxVariantData* ) DoGetProperty( o ) ) ;
591 }
592
593 // write the property this accessor is responsible for from an object into
594 // a string
595 void WriteValue( wxString& s , const wxObject *o ) const
596 {
597 DoGetProperty( o )->Write( s ) ;
598 }
599
600 // read a wxxVariant having the correct type for the property this accessor
601 // is responsible for from a string
602 wxxVariant ReadValue( const wxString &value ) const
603 {
604 T data ;
605 wxStringReadValue( value , data ) ;
606 return wxxVariant( data ) ;
607 }
608
609 private :
610 wxxVariantDataT<T>* DoGetProperty(const wxObject *o) const
611 {
612 const Klass *obj = dynamic_cast<const Klass*>(o);
613 if ( m_getter )
614 return new wxxVariantDataT<T>( (obj->*(m_getter))() ) ;
615 else
616 return new wxxVariantDataT<T>( (obj->*(m_getter_ref))() ) ;
617 }
618
619 setter_t m_setter;
620 setter_ref_t m_setter_ref;
621 setter_ref_bool_t m_setter_ref_bool ;
622 setter_bool_t m_setter_bool ;
623 getter_t m_getter;
624 getter_ref_t m_getter_ref ;
625 };
626
627 class WXDLLIMPEXP_BASE wxPropertyInfo
628 {
629 public :
630 wxPropertyInfo( wxPropertyInfo* &iter , const wxChar *name , const wxChar *typeName , const wxTypeInfo* typeInfo , wxPropertyAccessor *accessor , wxxVariant dv ) :
631 m_name( name ) , m_typeName(typeName) , m_typeInfo( typeInfo ) , m_accessor( accessor ) , m_defaultValue( dv )
632 {
633 m_next = NULL ;
634 if ( iter == NULL )
635 iter = this ;
636 else
637 {
638 wxPropertyInfo* i = iter ;
639 while( i->m_next )
640 i = i->m_next ;
641
642 i->m_next = this ;
643 }
644 }
645 // return the name of this property
646 const wxChar * GetName() const { return m_name ; }
647
648 // return the typename of this property
649 const wxChar * GetTypeName() const { return m_typeName ; }
650
651 // return the type info of this property
652 const wxTypeInfo * GetTypeInfo() const { return m_typeInfo ; }
653
654 // return the accessor for this property
655 wxPropertyAccessor* GetAccessor() const { return m_accessor ; }
656
657 // returns NULL if this is the last property of this class
658 wxPropertyInfo* GetNext() const { return m_next ; }
659
660 // returns the default value of this property, its kind may be wxT_VOID if it is not valid
661 wxxVariant GetDefaultValue() const { return m_defaultValue ; }
662 private :
663 const wxChar * m_name;
664 const wxChar * m_typeName ;
665 const wxTypeInfo* m_typeInfo ;
666 wxPropertyAccessor* m_accessor ;
667 wxxVariant m_defaultValue;
668 // string representation of the default value
669 // to be assigned by the designer to the property
670 // when the component is dropped on the container.
671 wxPropertyInfo* m_next ;
672 };
673
674 #define WX_BEGIN_PROPERTIES_TABLE(theClass) \
675 wxPropertyInfo *theClass::GetPropertiesStatic() \
676 { \
677 typedef theClass class_t; \
678 static wxPropertyInfo* first = NULL ;
679
680 #define WX_END_PROPERTIES_TABLE() \
681 return first ; }
682
683
684 #if WX_XTI_TEMPLATE_FIX
685
686 #define WX_PROPERTY( name , type , setter , getter ,defaultValue ) \
687 static wxPropertyAccessorT<class_t , type> _accessor##name( &setter , &getter , #setter , #getter ) ; \
688 static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
689
690 #define WX_PROPERTY_SET_RET_BOOL( name , type , setter , getter ,defaultValue ) \
691 static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetRetBool*)NULL , &setter , &getter , #setter , #getter ) ; \
692 static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
693
694 #define WX_PROPERTY_SET_BY_REF( name , type , setter , getter ,defaultValue ) \
695 static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetByRef*)NULL, &setter , &getter , #setter , #getter ) ; \
696 static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
697
698 #define WX_PROPERTY_SET_BY_REF_RET_BOOL( name , type , setter , getter ,defaultValue ) \
699 static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetByRefRetBool*)NULL, &setter , &getter , #setter , #getter ) ; \
700 static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
701
702 #define WX_PROPERTY_SET_AND_GET_BY_REF_RET_BOOL( name , type , setter , getter ,defaultValue ) \
703 static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetAndGetByRefRetBool*)NULL, &setter , &getter , #setter , #getter ) ; \
704 static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
705
706 #else
707
708 #define WX_PROPERTY( name , type , setter , getter ,defaultValue ) \
709 static wxPropertyAccessorT<class_t , type> _accessor##name( &setter , &getter , #setter , #getter ) ; \
710 static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
711
712 #define WX_PROPERTY_SET_RET_BOOL( name , type , setter , getter ,defaultValue ) \
713 WX_PROPERTY( name , type , setter , getter , defaultValue )
714
715 #define WX_PROPERTY_SET_BY_REF( name , type , setter , getter ,defaultValue ) \
716 WX_PROPERTY( name , type , setter , getter , defaultValue )
717
718 #define WX_PROPERTY_SET_BY_REF_RET_BOOL( name , type , setter , getter ,defaultValue ) \
719 WX_PROPERTY( name , type , setter , getter , defaultValue )
720
721 #define WX_PROPERTY_SET_AND_GET_BY_REF_RET_BOOL( name , type , setter , getter ,defaultValue ) \
722 WX_PROPERTY( name , type , setter , getter , defaultValue )
723
724 #endif
725
726 #define WX_READONLY_PROPERTY( name , type , getter ,defaultValue ) \
727 static wxPropertyAccessorT<class_t , type> _accessor##name( &getter , #getter ) ; \
728 static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
729
730 #define WX_DELEGATE( name , eventType , eventClass ) \
731 static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \
732 static wxPropertyInfo _propertyInfo##name( first , #name , NULL , &_typeInfo##name , NULL , wxxVariant() ) ; \
733
734 // ----------------------------------------------------------------------------
735 // Handler Info
736 //
737 // this is describing an event sink
738 // ----------------------------------------------------------------------------
739
740 class wxHandlerInfo
741 {
742 public :
743 wxHandlerInfo( wxHandlerInfo* &iter , const wxChar *name , wxObjectEventFunction address , const wxClassInfo* eventClassInfo ) :
744 m_name( name ) , m_eventClassInfo( eventClassInfo ) , m_eventFunction( address )
745 {
746 m_next = NULL ;
747 if ( iter == NULL )
748 iter = this ;
749 else
750 {
751 wxHandlerInfo* i = iter ;
752 while( i->m_next )
753 i = i->m_next ;
754
755 i->m_next = this ;
756 }
757 }
758
759 // get the name of the handler method
760 const wxChar * GetName() const { return m_name ; }
761
762 // return the class info of the event
763 const wxClassInfo * GetEventClassInfo() const { return m_eventClassInfo ; }
764
765 // get the handler function pointer
766 wxObjectEventFunction GetEventFunction() const { return m_eventFunction ; }
767
768 // returns NULL if this is the last handler of this class
769 wxHandlerInfo* GetNext() const { return m_next ; }
770 private :
771 wxObjectEventFunction m_eventFunction ;
772 const wxChar * m_name;
773 const wxClassInfo* m_eventClassInfo ;
774 wxHandlerInfo* m_next ;
775 };
776
777 #define WX_HANDLER(name,eventClassType) \
778 static wxHandlerInfo _handlerInfo##name( first , #name , (wxObjectEventFunction) (wxEventFunction) &name , CLASSINFO( eventClassType ) ) ;
779
780 #define WX_BEGIN_HANDLERS_TABLE(theClass) \
781 wxHandlerInfo *theClass::GetHandlersStatic() \
782 { \
783 typedef theClass class_t; \
784 static wxHandlerInfo* first = NULL ;
785
786 #define WX_END_HANDLERS_TABLE() \
787 return first ; }
788
789 // ----------------------------------------------------------------------------
790 // Constructor Bridges
791 //
792 // allow to set up constructors with params during runtime
793 // ----------------------------------------------------------------------------
794
795 class WXDLLIMPEXP_BASE wxConstructorBridge
796 {
797 public :
798 virtual void Create(wxObject *o, wxxVariant *args) = 0;
799 };
800
801 // Creator Bridges for all Numbers of Params
802
803 // no params
804
805 template<typename Class>
806 struct wxConstructorBridge_0 : public wxConstructorBridge
807 {
808 void Create(wxObject *o, wxxVariant *)
809 {
810 Class *obj = dynamic_cast<Class*>(o);
811 obj->Create();
812 }
813 };
814
815 struct wxConstructorBridge_Dummy : public wxConstructorBridge
816 {
817 void Create(wxObject *, wxxVariant *)
818 {
819 }
820 } ;
821
822 #define WX_CONSTRUCTOR_0(klass) \
823 wxConstructorBridge_0<klass> constructor##klass ; \
824 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
825 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
826 const int klass::sm_constructorPropertiesCount##klass = 0 ;
827
828 #define WX_CONSTRUCTOR_DUMMY(klass) \
829 wxConstructorBridge_Dummy constructor##klass ; \
830 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
831 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
832 const int klass::sm_constructorPropertiesCount##klass = 0 ;
833
834 // 1 param
835
836 template<typename Class, typename T0>
837 struct wxConstructorBridge_1 : public wxConstructorBridge
838 {
839 void Create(wxObject *o, wxxVariant *args)
840 {
841 Class *obj = dynamic_cast<Class*>(o);
842 obj->Create(
843 args[0].Get<T0>()
844 );
845 }
846 };
847
848 #define WX_CONSTRUCTOR_1(klass,t0,v0) \
849 wxConstructorBridge_1<klass,t0> constructor##klass ; \
850 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
851 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 } ; \
852 const int klass::sm_constructorPropertiesCount##klass = 1 ;
853
854 // 2 params
855
856 template<typename Class,
857 typename T0, typename T1>
858 struct wxConstructorBridge_2 : public wxConstructorBridge
859 {
860 void Create(wxObject *o, wxxVariant *args)
861 {
862 Class *obj = dynamic_cast<Class*>(o);
863 obj->Create(
864 args[0].Get<T0>() ,
865 args[1].Get<T1>()
866 );
867 }
868 };
869
870 #define WX_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
871 wxConstructorBridge_2<klass,t0,t1> constructor##klass ; \
872 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
873 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 } ; \
874 const int klass::sm_constructorPropertiesCount##klass = 2;
875
876 // 3 params
877
878 template<typename Class,
879 typename T0, typename T1, typename T2>
880 struct wxConstructorBridge_3 : public wxConstructorBridge
881 {
882 void Create(wxObject *o, wxxVariant *args)
883 {
884 Class *obj = dynamic_cast<Class*>(o);
885 obj->Create(
886 args[0].Get<T0>() ,
887 args[1].Get<T1>() ,
888 args[2].Get<T2>()
889 );
890 }
891 };
892
893 #define WX_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
894 wxConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \
895 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
896 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 } ; \
897 const int klass::sm_constructorPropertiesCount##klass = 3 ;
898
899 // 4 params
900
901 template<typename Class,
902 typename T0, typename T1, typename T2, typename T3>
903 struct wxConstructorBridge_4 : public wxConstructorBridge
904 {
905 void Create(wxObject *o, wxxVariant *args)
906 {
907 Class *obj = dynamic_cast<Class*>(o);
908 obj->Create(
909 args[0].Get<T0>() ,
910 args[1].Get<T1>() ,
911 args[2].Get<T2>() ,
912 args[3].Get<T3>()
913 );
914 }
915 };
916
917 #define WX_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
918 wxConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass ; \
919 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
920 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 } ; \
921 const int klass::sm_constructorPropertiesCount##klass = 4 ;
922
923 // 5 params
924
925 template<typename Class,
926 typename T0, typename T1, typename T2, typename T3, typename T4>
927 struct wxConstructorBridge_5 : public wxConstructorBridge
928 {
929 void Create(wxObject *o, wxxVariant *args)
930 {
931 Class *obj = dynamic_cast<Class*>(o);
932 obj->Create(
933 args[0].Get<T0>() ,
934 args[1].Get<T1>() ,
935 args[2].Get<T2>() ,
936 args[3].Get<T3>() ,
937 args[4].Get<T4>()
938 );
939 }
940 };
941
942 #define WX_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
943 wxConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass ; \
944 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
945 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 } ; \
946 const int klass::sm_constructorPropertiesCount##klass = 5;
947
948 // 6 params
949
950 template<typename Class,
951 typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
952 struct wxConstructorBridge_6 : public wxConstructorBridge
953 {
954 void Create(wxObject *o, wxxVariant *args)
955 {
956 Class *obj = dynamic_cast<Class*>(o);
957 obj->Create(
958 args[0].Get<T0>() ,
959 args[1].Get<T1>() ,
960 args[2].Get<T2>() ,
961 args[3].Get<T3>() ,
962 args[4].Get<T4>() ,
963 args[5].Get<T5>()
964 );
965 }
966 };
967
968 #define WX_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
969 wxConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
970 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
971 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 } ; \
972 const int klass::sm_constructorPropertiesCount##klass = 6;
973
974
975 // ----------------------------------------------------------------------------
976 // wxClassInfo
977 // ----------------------------------------------------------------------------
978
979 typedef wxObject *(*wxObjectConstructorFn)(void);
980 typedef wxObject* (*wxVariantToObjectConverter)( wxxVariant &data ) ;
981 typedef wxxVariant (*wxObjectToVariantConverter)( wxObject* ) ;
982
983 class WXDLLIMPEXP_BASE wxClassInfo
984 {
985 public:
986 wxClassInfo(const wxClassInfo **_Parents,
987 const wxChar *_UnitName,
988 const wxChar *_ClassName,
989 int size,
990 wxObjectConstructorFn ctor ,
991 wxPropertyInfo *_Props ,
992 wxHandlerInfo *_Handlers ,
993 wxConstructorBridge* _Constructor ,
994 const wxChar ** _ConstructorProperties ,
995 const int _ConstructorPropertiesCount ,
996 wxVariantToObjectConverter _PtrConverter1 ,
997 wxVariantToObjectConverter _Converter2 ,
998 wxObjectToVariantConverter _Converter3
999 ) : m_parents(_Parents) , m_unitName(_UnitName) ,m_className(_ClassName),
1000 m_objectSize(size), m_objectConstructor(ctor) , m_firstProperty(_Props ) , m_firstHandler(_Handlers ) , m_constructor( _Constructor ) ,
1001 m_constructorProperties(_ConstructorProperties) , m_constructorPropertiesCount(_ConstructorPropertiesCount),
1002 m_variantOfPtrToObjectConverter( _PtrConverter1 ) , m_variantToObjectConverter( _Converter2 ) , m_objectToVariantConverter( _Converter3 ) , m_next(sm_first)
1003 {
1004 sm_first = this;
1005 Register() ;
1006 }
1007
1008 wxClassInfo(const wxChar *_UnitName, const wxChar *_ClassName, const wxClassInfo **_Parents) : m_parents(_Parents) , m_unitName(_UnitName) ,m_className(_ClassName),
1009 m_objectSize(0), m_objectConstructor(NULL) , m_firstProperty(NULL ) , m_firstHandler(NULL ) , m_constructor( NULL ) ,
1010 m_constructorProperties(NULL) , m_constructorPropertiesCount(NULL),
1011 m_variantOfPtrToObjectConverter( NULL ) , m_variantToObjectConverter( NULL ) , m_objectToVariantConverter( NULL ) , m_next(sm_first)
1012 {
1013 sm_first = this;
1014 Register() ;
1015 }
1016
1017 virtual ~wxClassInfo() ;
1018
1019 virtual wxObject *CreateObject() const { return m_objectConstructor ? (*m_objectConstructor)() : 0; }
1020
1021 const wxChar *GetClassName() const { return m_className; }
1022 const wxClassInfo **GetParents() const { return m_parents; }
1023 int GetSize() const { return m_objectSize; }
1024
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);
1029
1030 // Climb upwards through inheritance hierarchy.
1031 // Dual inheritance is catered for.
1032
1033 bool IsKindOf(const wxClassInfo *info) const
1034 {
1035 if ( info != 0 )
1036 {
1037 if ( info == this )
1038 return true ;
1039
1040 for ( int i = 0 ; m_parents[i] ; ++ i )
1041 {
1042 if ( m_parents[i]->IsKindOf( info ) )
1043 return true ;
1044 }
1045 }
1046 return false ;
1047 }
1048
1049 #ifdef WXWIN_COMPATIBILITY_2_4
1050 // Initializes parent pointers and hash table for fast searching.
1051 wxDEPRECATED( static void InitializeClasses() );
1052 // Cleans up hash table used for fast searching.
1053 wxDEPRECATED( static void CleanUpClasses() );
1054 #endif
1055 static void CleanUp();
1056
1057 // returns the first property
1058 const wxPropertyInfo* GetFirstProperty() const { return m_firstProperty ; }
1059
1060 // returns the first handler
1061 const wxHandlerInfo* GetFirstHandler() const { return m_firstHandler ; }
1062
1063 // Call the Create method for a class
1064 virtual void Create (wxObject *object, int ParamCount, wxxVariant *Params) const
1065 {
1066 wxASSERT_MSG( ParamCount == m_constructorPropertiesCount , wxT("Illegal Parameter Count for Create Method")) ;
1067 m_constructor->Create( object , Params ) ;
1068 }
1069
1070 // get number of parameters for constructor
1071 virtual int GetCreateParamCount() const { return m_constructorPropertiesCount; }
1072
1073 // get i-th constructor parameter
1074 virtual const wxChar* GetCreateParamName(int i) const { return m_constructorProperties[i] ; }
1075
1076 // Runtime access to objects by property name, and variant data
1077 virtual void SetProperty (wxObject *object, const wxChar *PropertyName, const wxxVariant &Value) const ;
1078 virtual wxxVariant GetProperty (wxObject *object, const wxChar *PropertyName) const;
1079
1080 // we must be able to cast variants to wxObject pointers, templates seem not to be suitable
1081 wxObject* VariantToInstance( wxxVariant &data ) const
1082 { if ( data.GetTypeInfo()->GetKind() == wxT_OBJECT )
1083 return m_variantToObjectConverter( data ) ;
1084 else
1085 return m_variantOfPtrToObjectConverter( data ) ;
1086 }
1087
1088 wxxVariant InstanceToVariant( wxObject *object ) const { return m_objectToVariantConverter( object ) ; }
1089
1090 // find property by name
1091 virtual const wxPropertyInfo *FindPropertyInfo (const wxChar *PropertyName) const ;
1092
1093 // find handler by name
1094 virtual const wxHandlerInfo *FindHandlerInfo (const wxChar *PropertyName) const ;
1095
1096 // find property by name
1097 virtual const wxPropertyInfo *FindPropertyInfoInThisClass (const wxChar *PropertyName) const ;
1098
1099 // find handler by name
1100 virtual const wxHandlerInfo *FindHandlerInfoInThisClass (const wxChar *PropertyName) const ;
1101 public:
1102 const wxChar *m_className;
1103 int m_objectSize;
1104 wxObjectConstructorFn m_objectConstructor;
1105
1106 // class info object live in a linked list:
1107 // pointers to its head and the next element in it
1108
1109 static wxClassInfo *sm_first;
1110 wxClassInfo *m_next;
1111
1112 // FIXME: this should be private (currently used directly by way too
1113 // many clients)
1114 static wxHashTable *sm_classTable;
1115
1116 protected :
1117 wxPropertyInfo * m_firstProperty ;
1118 wxHandlerInfo * m_firstHandler ;
1119 private:
1120 const wxClassInfo** m_parents ;
1121 const wxChar* m_unitName;
1122
1123 wxConstructorBridge* m_constructor ;
1124 const wxChar ** m_constructorProperties ;
1125 const int m_constructorPropertiesCount ;
1126 wxVariantToObjectConverter m_variantOfPtrToObjectConverter ;
1127 wxVariantToObjectConverter m_variantToObjectConverter ;
1128 wxObjectToVariantConverter m_objectToVariantConverter ;
1129
1130 const wxPropertyAccessor *FindAccessor (const wxChar *propertyName) const ;
1131
1132
1133 // InitializeClasses() helper
1134 static wxClassInfo *GetBaseByName(const wxChar *name) ;
1135
1136 protected:
1137 // registers the class
1138 void Register();
1139 void Unregister();
1140
1141 DECLARE_NO_COPY_CLASS(wxClassInfo)
1142 };
1143
1144
1145 WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name);
1146
1147 // ----------------------------------------------------------------------------
1148 // wxDynamicObject
1149 // ----------------------------------------------------------------------------
1150 //
1151 // this object leads to having a pure runtime-instantiation
1152
1153 class wxDynamicClassInfo : public wxClassInfo
1154 {
1155 public :
1156 wxDynamicClassInfo( const wxChar *_UnitName, const wxChar *_ClassName , const wxClassInfo* superClass ) ;
1157 virtual ~wxDynamicClassInfo() ;
1158
1159 // constructs a wxDynamicObject with an instance
1160 virtual wxObject *CreateObject() const ;
1161
1162 // Call the Create method for a class
1163 virtual void Create (wxObject *object, int ParamCount, wxxVariant *Params) const ;
1164
1165 // get number of parameters for constructor
1166 virtual int GetCreateParamCount() const ;
1167
1168 // get i-th constructor parameter
1169 virtual const wxChar* GetCreateParamName(int i) const ;
1170
1171 // Runtime access to objects by property name, and variant data
1172 virtual void SetProperty (wxObject *object, const wxChar *PropertyName, const wxxVariant &Value) const ;
1173 virtual wxxVariant GetProperty (wxObject *object, const wxChar *PropertyName) const ;
1174
1175 void AddProperty( const wxChar *propertyName , const wxTypeInfo* typeInfo ) ;
1176 void AddHandler( const wxChar *handlerName , wxObjectEventFunction address , const wxClassInfo* eventClassInfo ) ;
1177 } ;
1178
1179 // ----------------------------------------------------------------------------
1180 // Dynamic class macros
1181 // ----------------------------------------------------------------------------
1182
1183 #define _DECLARE_DYNAMIC_CLASS(name) \
1184 public: \
1185 static wxClassInfo sm_class##name; \
1186 static const wxClassInfo* sm_classParents##name[] ; \
1187 static wxPropertyInfo* GetPropertiesStatic() ; \
1188 static wxHandlerInfo* GetHandlersStatic() ; \
1189 virtual wxClassInfo *GetClassInfo() const \
1190 { return &name::sm_class##name; }
1191
1192 #define DECLARE_DYNAMIC_CLASS(name) \
1193 static wxConstructorBridge* sm_constructor##name ; \
1194 static const wxChar * sm_constructorProperties##name[] ; \
1195 static const int sm_constructorPropertiesCount##name ; \
1196 _DECLARE_DYNAMIC_CLASS(name)
1197
1198 #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
1199 DECLARE_NO_ASSIGN_CLASS(name) \
1200 DECLARE_DYNAMIC_CLASS(name)
1201
1202 #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \
1203 DECLARE_NO_COPY_CLASS(name) \
1204 DECLARE_DYNAMIC_CLASS(name)
1205
1206 #define DECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name)
1207 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
1208
1209 // -----------------------------------
1210 // for concrete classes
1211 // -----------------------------------
1212
1213 // Single inheritance with one base class
1214
1215 #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit) \
1216 wxObject* wxConstructorFor##name() \
1217 { return new name; } \
1218 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1219 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1220 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1221 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1222 (int) sizeof(name), \
1223 (wxObjectConstructorFn) wxConstructorFor##name , \
1224 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1225 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name); \
1226 template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1227 template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1228 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1229 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1230 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1231 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1232 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1233 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1234 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1235
1236 #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit) \
1237 wxObject* wxConstructorFor##name() \
1238 { return new name; } \
1239 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1240 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return &data.Get<name>() ; } \
1241 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1242 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1243 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1244 (int) sizeof(name), \
1245 (wxObjectConstructorFn) wxConstructorFor##name , \
1246 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1247 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1248 template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1249 template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1250 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1251 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1252 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1253 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1254 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1255 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1256 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1257
1258 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \
1259 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" ) \
1260 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1261 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1262 WX_CONSTRUCTOR_DUMMY( name )
1263
1264 #define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \
1265 _IMPLEMENT_DYNAMIC_CLASS( name , basename , "" ) \
1266 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1267 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1268 WX_CONSTRUCTOR_DUMMY( name )
1269
1270 #define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \
1271 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit )
1272
1273 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \
1274 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit )
1275
1276 // this is for classes that do not derive from wxobject, there are no creators for these
1277
1278 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name , unit ) \
1279 const wxClassInfo* name::sm_classParents##name[] = { NULL } ; \
1280 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1281 (int) sizeof(name), \
1282 (wxObjectConstructorFn) 0 , \
1283 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1284 0 , 0 , 0 ); \
1285 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1286 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1287 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1288 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1289 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1290 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1291 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1292
1293 // this is for subclasses that still do not derive from wxobject
1294
1295 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name , basename, unit ) \
1296 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1297 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1298 (int) sizeof(name), \
1299 (wxObjectConstructorFn) 0 , \
1300 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1301 0 , 0 , 0 ); \
1302 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1303 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1304 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1305 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1306 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1307 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1308 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1309
1310
1311 // Multiple inheritance with two base classes
1312
1313 #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit) \
1314 wxObject* wxConstructorFor##name() \
1315 { return new name; } \
1316 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,&basename2::sm_class##basename2 , NULL } ; \
1317 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1318 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1319 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1320 (int) sizeof(name), \
1321 (wxObjectConstructorFn) wxConstructorFor##name , \
1322 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1323 name::sm_constructorPropertiesCount##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1324 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1325 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1326 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1327 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1328 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1329 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1330 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1331
1332 #define IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2) \
1333 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , "") \
1334 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1335 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1336 WX_CONSTRUCTOR_DUMMY( name )
1337
1338 #define IMPLEMENT_DYNAMIC_CLASS2_XTI( name , basename , basename2, unit) \
1339 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , unit)
1340
1341 // -----------------------------------
1342 // for abstract classes
1343 // -----------------------------------
1344
1345 // Single inheritance with one base class
1346
1347 #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
1348 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1349 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1350 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1351 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1352 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1353 (int) sizeof(name), \
1354 (wxObjectConstructorFn) 0 , \
1355 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1356 0 , wxVariantOfPtrToObjectConverter##name ,wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1357 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1358 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1359 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1360 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1361 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1362 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } \
1363 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID) ; assert(0) ; return &s_typeInfo ; }
1364
1365 #define IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1366 _IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1367 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1368 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; }
1369
1370 // Multiple inheritance with two base classes
1371
1372 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
1373 wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \
1374 wxT(#basename2), (int) sizeof(name), \
1375 (wxObjectConstructorFn) 0);
1376
1377 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
1378 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
1379
1380 #endif