]> git.saurik.com Git - wxWidgets.git/blob - include/wx/xti.h
avoid a bug in Carbon headers
[wxWidgets.git] / include / wx / xti.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/xti.hG
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/flags.h"
42 #include "wx/string.h"
43 #include "wx/arrstr.h"
44 #include "wx/hashmap.h"
45
46 #include <typeinfo>
47
48 // we will move this later to defs.h
49
50 #if !wxCHECK_GCC_VERSION( 3 , 4 )
51 # define wxUSE_MEMBER_TEMPLATES 0
52 #endif
53
54 #ifdef _MSC_VER
55 # if _MSC_VER <= 1200
56 # define wxUSE_MEMBER_TEMPLATES 0
57 # endif
58 #endif
59
60 #ifndef wxUSE_MEMBER_TEMPLATES
61 #define wxUSE_MEMBER_TEMPLATES 1
62 #endif
63
64 #if wxUSE_MEMBER_TEMPLATES
65 #define WX_TEMPLATED_MEMBER_CALL( method , type ) method<type>()
66 #define WX_TEMPLATED_MEMBER_FIX( type )
67 #else
68 #define WX_TEMPLATED_MEMBER_CALL( method , type ) method((type*)NULL)
69 #define WX_TEMPLATED_MEMBER_FIX( type ) type* =NULL
70 #endif
71
72 class WXDLLIMPEXP_BASE wxObject;
73 class WXDLLIMPEXP_BASE wxClassInfo;
74 class WXDLLIMPEXP_BASE wxDynamicClassInfo;
75 class WXDLLIMPEXP_BASE wxHashTable;
76 class WXDLLIMPEXP_BASE wxObjectRefData;
77 class WXDLLIMPEXP_BASE wxEvent;
78
79 typedef void (wxObject::*wxObjectEventFunction)(wxEvent&);
80
81 // ----------------------------------------------------------------------------
82 // Enum Support
83 //
84 // In the header files there would no change from pure c++ code, in the
85 // implementation, an enum would have
86 // to be enumerated eg :
87 //
88 // WX_BEGIN_ENUM( wxFlavor )
89 // WX_ENUM_MEMBER( Vanilla )
90 // WX_ENUM_MEMBER( Chocolate )
91 // WX_ENUM_MEMBER( Strawberry )
92 // WX_END_ENUM( wxFlavor )
93 // ----------------------------------------------------------------------------
94
95 struct WXDLLIMPEXP_BASE wxEnumMemberData
96 {
97 const wxChar* m_name;
98 int m_value;
99 };
100
101 class WXDLLIMPEXP_BASE wxEnumData
102 {
103 public :
104 wxEnumData( wxEnumMemberData* data ) ;
105
106 // returns true if the member has been found and sets the int value
107 // pointed to accordingly (if ptr != null )
108 // if not found returns false, value left unchanged
109 bool HasEnumMemberValue( const wxChar *name , int *value = NULL ) ;
110
111 // returns the value of the member, if not found in debug mode an
112 // assert is issued, in release 0 is returned
113 int GetEnumMemberValue(const wxChar *name );
114
115 // returns the name of the enum member having the passed in value
116 // returns an emtpy string if not found
117 const wxChar *GetEnumMemberName(int value);
118
119 // returns the number of members in this enum
120 int GetEnumCount() { return m_count ; }
121
122 // returns the value of the nth member
123 int GetEnumMemberValueByIndex( int n ) ;
124
125 // returns the value of the nth member
126 const wxChar *GetEnumMemberNameByIndex( int n ) ;
127 private :
128 wxEnumMemberData *m_members;
129 int m_count ;
130 };
131
132 #define WX_BEGIN_ENUM( e ) \
133 wxEnumMemberData s_enumDataMembers##e[] = {
134
135 #define WX_ENUM_MEMBER( v ) { #v, v } ,
136
137 #define WX_END_ENUM( e ) { NULL , 0 } } ; \
138 wxEnumData s_enumData##e( s_enumDataMembers##e ) ; \
139 wxEnumData *wxGetEnumData(e) { return &s_enumData##e ; } \
140 template<> void wxStringReadValue(const wxString& s , e &data ) \
141 { \
142 data = (e) s_enumData##e.GetEnumMemberValue(s) ; \
143 } \
144 template<> void wxStringWriteValue(wxString &s , const e &data ) \
145 { \
146 s = s_enumData##e.GetEnumMemberName((int)data) ; \
147 } \
148 void FromLong##e( long data , wxxVariant& result ) { result = wxxVariant((e)data) ;} \
149 void ToLong##e( const wxxVariant& data , long &result ) { result = (long) data.Get<e>() ;} \
150 wxEnumTypeInfo s_typeInfo##e(wxT_ENUM , &s_enumData##e , &wxToStringConverter<e> , &wxFromStringConverter<e> , &ToLong##e , &FromLong##e , typeid(e).name() ) ;
151
152 // ----------------------------------------------------------------------------
153 // Set Support
154 //
155 // in the header :
156 //
157 // enum wxFlavor
158 // {
159 // Vanilla,
160 // Chocolate,
161 // Strawberry,
162 // };
163 //
164 // typedef wxBitset<wxFlavor> wxCoupe ;
165 //
166 // in the implementation file :
167 //
168 // WX_BEGIN_ENUM( wxFlavor )
169 // WX_ENUM_MEMBER( Vanilla )
170 // WX_ENUM_MEMBER( Chocolate )
171 // WX_ENUM_MEMBER( Strawberry )
172 // WX_END_ENUM( wxFlavor )
173 //
174 // WX_IMPLEMENT_SET_STREAMING( wxCoupe , wxFlavor )
175 //
176 // implementation note : no partial specialization for streaming, but a delegation to a
177 // different class
178 //
179 // ----------------------------------------------------------------------------
180
181 // in order to remove dependancy on string tokenizer
182 void wxSetStringToArray( const wxString &s , wxArrayString &array ) ;
183
184 template<typename e>
185 void wxSetFromString(const wxString &s , wxBitset<e> &data )
186 {
187 wxEnumData* edata = wxGetEnumData((e) 0) ;
188 data.reset() ;
189
190 wxArrayString array ;
191 wxSetStringToArray( s , array ) ;
192 wxString flag;
193 for ( int i = 0 ; i < array.Count() ; ++i )
194 {
195 flag = array[i] ;
196 int ivalue ;
197 if ( edata->HasEnumMemberValue( flag , &ivalue ) )
198 {
199 data.set( (e) ivalue ) ;
200 }
201 }
202 }
203
204 template<typename e>
205 void wxSetToString( wxString &s , const wxBitset<e> &data )
206 {
207 wxEnumData* edata = wxGetEnumData((e) 0) ;
208 int count = edata->GetEnumCount() ;
209 int i ;
210 s.Clear() ;
211 for ( i = 0 ; i < count ; i++ )
212 {
213 e value = (e) edata->GetEnumMemberValueByIndex(i) ;
214 if ( data.test( value ) )
215 {
216 // this could also be done by the templated calls
217 if ( !s.IsEmpty() )
218 s +="|" ;
219 s += edata->GetEnumMemberNameByIndex(i) ;
220 }
221 }
222 }
223
224 #define WX_IMPLEMENT_SET_STREAMING(SetName,e) \
225 template<> void wxStringReadValue(const wxString &s , wxBitset<e> &data ) \
226 { \
227 wxSetFromString( s , data ) ; \
228 } \
229 template<> void wxStringWriteValue( wxString &s , const wxBitset<e> &data ) \
230 { \
231 wxSetToString( s , data ) ; \
232 } \
233 void FromLong##SetName( long data , wxxVariant& result ) { result = wxxVariant(SetName((unsigned long)data)) ;} \
234 void ToLong##SetName( const wxxVariant& data , long &result ) { result = (long) data.Get<SetName>().to_ulong() ;} \
235 wxEnumTypeInfo s_typeInfo##SetName(wxT_SET , &s_enumData##e , &wxToStringConverter<SetName> , &wxFromStringConverter<SetName> , &ToLong##SetName , &FromLong##SetName, typeid(SetName).name() ) ; \
236 }
237
238 template<typename e>
239 void wxFlagsFromString(const wxString &s , e &data )
240 {
241 wxEnumData* edata = wxGetEnumData((e*) 0) ;
242 data.m_data = 0 ;
243
244 wxArrayString array ;
245 wxSetStringToArray( s , array ) ;
246 wxString flag;
247 for ( size_t i = 0 ; i < array.Count() ; ++i )
248 {
249 flag = array[i] ;
250 int ivalue ;
251 if ( edata->HasEnumMemberValue( flag , &ivalue ) )
252 {
253 data.m_data |= ivalue ;
254 }
255 }
256 }
257
258 template<typename e>
259 void wxFlagsToString( wxString &s , const e& data )
260 {
261 wxEnumData* edata = wxGetEnumData((e*) 0) ;
262 int count = edata->GetEnumCount() ;
263 int i ;
264 s.Clear() ;
265 long dataValue = data.m_data ;
266 for ( i = 0 ; i < count ; i++ )
267 {
268 int value = edata->GetEnumMemberValueByIndex(i) ;
269 // make this to allow for multi-bit constants to work
270 if ( value && ( dataValue & value ) == value )
271 {
272 // clear the flags we just set
273 dataValue &= ~value ;
274 // this could also be done by the templated calls
275 if ( !s.IsEmpty() )
276 s +="|" ;
277 s += edata->GetEnumMemberNameByIndex(i) ;
278 }
279 }
280 }
281
282 #define WX_BEGIN_FLAGS( e ) \
283 wxEnumMemberData s_enumDataMembers##e[] = {
284
285 #define WX_FLAGS_MEMBER( v ) { #v, v } ,
286
287 #define WX_END_FLAGS( e ) { NULL , 0 } } ; \
288 wxEnumData s_enumData##e( s_enumDataMembers##e ) ; \
289 wxEnumData *wxGetEnumData(e*) { return &s_enumData##e ; } \
290 template<> void wxStringReadValue(const wxString &s , e &data ) \
291 { \
292 wxFlagsFromString<e>( s , data ) ; \
293 } \
294 template<> void wxStringWriteValue( wxString &s , const e& data ) \
295 { \
296 wxFlagsToString<e>( s , data ) ; \
297 } \
298 void FromLong##e( long data , wxxVariant& result ) { result = wxxVariant(e(data)) ;} \
299 void ToLong##e( const wxxVariant& data , long &result ) { result = (long) data.Get<e>().m_data ;} \
300 wxEnumTypeInfo s_typeInfo##e(wxT_SET , &s_enumData##e , &wxToStringConverter<e> , &wxFromStringConverter<e> , &ToLong##e , &FromLong##e, typeid(e).name() ) ;
301 // ----------------------------------------------------------------------------
302 // Type Information
303 // ----------------------------------------------------------------------------
304 //
305 //
306 // All data exposed by the RTTI is characterized using the following classes.
307 // The first characterization is done by wxTypeKind. All enums up to and including
308 // wxT_CUSTOM represent so called simple types. These cannot be divided any further.
309 // They can be converted to and from wxStrings, that's all.
310
311
312 enum wxTypeKind
313 {
314 wxT_VOID = 0, // unknown type
315 wxT_BOOL,
316 wxT_CHAR,
317 wxT_UCHAR,
318 wxT_INT,
319 wxT_UINT,
320 wxT_LONG,
321 wxT_ULONG,
322 wxT_FLOAT,
323 wxT_DOUBLE,
324 wxT_STRING, // must be wxString
325 wxT_SET, // must be wxBitset<> template
326 wxT_ENUM,
327 wxT_CUSTOM, // user defined type (e.g. wxPoint)
328
329 wxT_LAST_SIMPLE_TYPE_KIND = wxT_CUSTOM ,
330
331 wxT_OBJECT_PTR, // object reference
332 wxT_OBJECT , // embedded object
333 wxT_COLLECTION , // collection
334
335 wxT_DELEGATE , // for connecting against an event source
336
337 wxT_LAST_TYPE_KIND = wxT_DELEGATE // sentinel for bad data, asserts, debugging
338 };
339
340 class WXDLLIMPEXP_BASE wxxVariant ;
341 class WXDLLIMPEXP_BASE wxTypeInfo ;
342
343 WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxTypeInfo* , wxTypeInfoMap , class WXDLLIMPEXP_BASE ) ;
344
345 class WXDLLIMPEXP_BASE wxTypeInfo
346 {
347 public :
348 typedef void (*converterToString_t)( const wxxVariant& data , wxString &result ) ;
349 typedef void (*converterFromString_t)( const wxString& data , wxxVariant &result ) ;
350
351 wxTypeInfo(wxTypeKind kind,
352 converterToString_t to = NULL, converterFromString_t from = NULL,
353 const wxString &name = wxEmptyString):
354 m_toString(to), m_fromString(from), m_kind(kind), m_name(name)
355 {
356 Register();
357 }
358
359 virtual ~wxTypeInfo()
360 {
361 Unregister() ;
362 }
363
364 // return the kind of this type (wxT_... constants)
365 wxTypeKind GetKind() const { return m_kind ; }
366
367 // returns the unique name of this type
368 const wxString& GetTypeName() const { return m_name ; }
369
370 // is this type a delegate type
371 bool IsDelegateType() const { return m_kind == wxT_DELEGATE ; }
372
373 // is this type a custom type
374 bool IsCustomType() const { return m_kind == wxT_CUSTOM ; }
375
376 // is this type an object type
377 bool IsObjectType() const { return m_kind == wxT_OBJECT || m_kind == wxT_OBJECT_PTR ; }
378
379 // can the content of this type be converted to and from strings ?
380 bool HasStringConverters() const { return m_toString != NULL && m_fromString != NULL ; }
381
382 // convert a wxxVariant holding data of this type into a string
383 void ConvertToString( const wxxVariant& data , wxString &result ) const
384
385 { wxASSERT_MSG( m_toString , wxT("String conversions not supported") ) ; (*m_toString)( data , result ) ; }
386
387 // convert a string into a wxxVariant holding the corresponding data in this type
388 void ConvertFromString( const wxString& data , wxxVariant &result ) const
389 { wxASSERT_MSG( m_fromString , wxT("String conversions not supported") ) ; (*m_fromString)( data , result ) ; }
390
391 static wxTypeInfo *FindType(const wxChar *typeName);
392
393 private :
394
395 void Register();
396 void Unregister();
397
398 converterToString_t m_toString ;
399 converterFromString_t m_fromString ;
400
401 static wxTypeInfoMap* sm_typeTable ;
402
403 wxTypeKind m_kind;
404 wxString m_name;
405 };
406
407 class WXDLLIMPEXP_BASE wxBuiltInTypeInfo : public wxTypeInfo
408 {
409 public :
410 wxBuiltInTypeInfo( wxTypeKind kind , converterToString_t to = NULL , converterFromString_t from = NULL , const wxString &name = wxEmptyString ) :
411 wxTypeInfo( kind , to , from , name )
412 { wxASSERT_MSG( GetKind() < wxT_SET , wxT("Illegal Kind for Base Type") ) ; }
413 } ;
414
415 class WXDLLIMPEXP_BASE wxCustomTypeInfo : public wxTypeInfo
416 {
417 public :
418 wxCustomTypeInfo( const wxString &name , converterToString_t to , converterFromString_t from ) :
419 wxTypeInfo( wxT_CUSTOM , to , from , name )
420 {}
421 } ;
422
423 class WXDLLIMPEXP_BASE wxEnumTypeInfo : public wxTypeInfo
424 {
425 public :
426 typedef void (*converterToLong_t)( const wxxVariant& data , long &result ) ;
427 typedef void (*converterFromLong_t)( long data , wxxVariant &result ) ;
428
429 wxEnumTypeInfo( wxTypeKind kind , wxEnumData* enumInfo , converterToString_t to , converterFromString_t from ,
430 converterToLong_t toLong , converterFromLong_t fromLong , const wxString &name ) :
431 wxTypeInfo( kind , to , from , name ) , m_toLong( toLong ) , m_fromLong( fromLong )
432 { wxASSERT_MSG( kind == wxT_ENUM || kind == wxT_SET , wxT("Illegal Kind for Enum Type")) ; m_enumInfo = enumInfo ;}
433 const wxEnumData* GetEnumData() const { return m_enumInfo ; }
434
435 // convert a wxxVariant holding data of this type into a long
436 void ConvertToLong( const wxxVariant& data , long &result ) const
437
438 { wxASSERT_MSG( m_toLong , wxT("Long conversions not supported") ) ; (*m_toLong)( data , result ) ; }
439
440 // convert a long into a wxxVariant holding the corresponding data in this type
441 void ConvertFromLong( long data , wxxVariant &result ) const
442 { wxASSERT_MSG( m_fromLong , wxT("Long conversions not supported") ) ; (*m_fromLong)( data , result ) ; }
443
444 private :
445 converterToLong_t m_toLong ;
446 converterFromLong_t m_fromLong ;
447
448 wxEnumData *m_enumInfo; // Kind == wxT_ENUM or Kind == wxT_SET
449 } ;
450
451 class WXDLLIMPEXP_BASE wxClassTypeInfo : public wxTypeInfo
452 {
453 public :
454 wxClassTypeInfo( wxTypeKind kind , wxClassInfo* classInfo , converterToString_t to = NULL , converterFromString_t from = NULL , const wxString &name = wxEmptyString) ;
455 const wxClassInfo *GetClassInfo() const { return m_classInfo ; }
456 private :
457 wxClassInfo *m_classInfo; // Kind == wxT_OBJECT - could be NULL
458 } ;
459
460 class WXDLLIMPEXP_BASE wxCollectionTypeInfo : public wxTypeInfo
461 {
462 public :
463 wxCollectionTypeInfo( wxTypeInfo *elementType , converterToString_t to , converterFromString_t from , const wxString &name) :
464 wxTypeInfo( wxT_COLLECTION , to , from , name )
465 { m_elementType = elementType ;}
466
467 const wxTypeInfo* GetElementType() const { return m_elementType ; }
468 private :
469 wxTypeInfo * m_elementType ;
470 } ;
471
472 // a delegate is an exposed event source
473
474 class WXDLLIMPEXP_BASE wxDelegateTypeInfo : public wxTypeInfo
475 {
476 public :
477 wxDelegateTypeInfo( int eventType , wxClassInfo* eventClass , converterToString_t to = NULL , converterFromString_t from = NULL ) ;
478 int GetEventType() const { return m_eventType ; }
479 private :
480 const wxClassInfo *m_eventClass; // (extended will merge into classinfo)
481 int m_eventType ;
482 } ;
483
484 template<typename T> const wxTypeInfo* wxGetTypeInfo( T * ) { return wxTypeInfo::FindType(typeid(T).name()) ; }
485
486 // this macro is for usage with custom, non-object derived classes and structs, wxPoint is such a custom type
487
488 #define WX_CUSTOM_TYPE_INFO( e , toString , fromString ) \
489 wxCustomTypeInfo s_typeInfo##e(typeid(e).name() , &toString , &fromString) ;
490
491 #define WX_COLLECTION_TYPE_INFO( element , collection ) \
492 wxCollectionTypeInfo s_typeInfo##collection( (wxTypeInfo*) wxGetTypeInfo( (element *) NULL) , NULL , NULL , typeid(collection).name() ) ;
493
494 // sometimes a compiler invents specializations that are nowhere called, use this macro to satisfy the refs
495
496 #define WX_ILLEGAL_TYPE_SPECIALIZATION( a )
497 /*
498 template<> const wxTypeInfo* wxGetTypeInfo( a * ) { assert(0) ; \
499 static wxBuiltInTypeInfo s_typeInfo( wxT_VOID ) ; return &s_typeInfo ; } \
500 template<> void wxStringReadValue(const wxString & , a & ) { assert(0) ; }\
501 template<> void wxStringWriteValue(wxString & , a const & ) { assert(0) ; }
502 */
503
504 // ----------------------------------------------------------------------------
505 // wxxVariant as typesafe data holder
506 // ----------------------------------------------------------------------------
507
508 class WXDLLIMPEXP_BASE wxxVariantData
509 {
510 public:
511 virtual ~wxxVariantData() {}
512
513 // return a heap allocated duplicate
514 virtual wxxVariantData* Clone() const = 0 ;
515
516 // returns the type info of the contentc
517 virtual const wxTypeInfo* GetTypeInfo() const = 0 ;
518 } ;
519
520 template<typename T> class wxxVariantDataT : public wxxVariantData
521 {
522 public:
523 wxxVariantDataT(const T& d) : m_data(d) {}
524 virtual ~wxxVariantDataT() {}
525
526 // get a ref to the stored data
527 T & Get() { return m_data; }
528
529 // get a const ref to the stored data
530 const T & Get() const { return m_data; }
531
532 // set the data
533 void Set(const T& d) { m_data = d; }
534
535 // return a heap allocated duplicate
536 virtual wxxVariantData* Clone() const { return new wxxVariantDataT<T>( Get() ) ; }
537
538 // returns the type info of the contentc
539 virtual const wxTypeInfo* GetTypeInfo() const { return wxGetTypeInfo( (T*) NULL ) ; }
540 private:
541 T m_data;
542 };
543
544 class WXDLLIMPEXP_BASE wxxVariant
545 {
546 public :
547 wxxVariant() { m_data = NULL ; }
548 wxxVariant( wxxVariantData* data , const wxString& name = wxT("") ) : m_data(data) , m_name(name) {}
549 wxxVariant( const wxxVariant &d ) { if ( d.m_data ) m_data = d.m_data->Clone() ; else m_data = NULL ; m_name = d.m_name ; }
550
551 template<typename T> wxxVariant( const T& data , const wxString& name = wxT("") ) :
552 m_data(new wxxVariantDataT<T>(data) ), m_name(name) {}
553
554 ~wxxVariant() { delete m_data ; }
555
556 // get a ref to the stored data
557 template<typename T> T& Get(WX_TEMPLATED_MEMBER_FIX(T))
558 {
559 wxxVariantDataT<T> *dataptr = dynamic_cast<wxxVariantDataT<T>*> (m_data) ;
560 wxASSERT_MSG( dataptr , wxT("Cast not possible") ) ;
561 return dataptr->Get() ;
562 }
563
564 // get a ref to the stored data
565 template<typename T> const T& Get(WX_TEMPLATED_MEMBER_FIX(T)) const
566 {
567 const wxxVariantDataT<T> *dataptr = dynamic_cast<const wxxVariantDataT<T>*> (m_data) ;
568 wxASSERT_MSG( dataptr , wxT("Cast not possible") ) ;
569 return dataptr->Get() ;
570 }
571
572 template<typename T> bool HasData() const
573 {
574 const wxxVariantDataT<T> *dataptr = dynamic_cast<const wxxVariantDataT<T>*> (m_data) ;
575 return dataptr != NULL ;
576 }
577
578 // stores the data
579 template<typename T> void Set(const T& data) const
580 {
581 delete m_data ;
582 m_data = new wxxVariantDataT<T>(data) ;
583 }
584
585 wxxVariant& operator=(const wxxVariant &d)
586 {
587 m_data = d.m_data->Clone() ;
588 m_name = d.m_name ;
589 return *this ;
590 }
591
592 // gets the stored data casted to a wxObject* , returning NULL if cast is not possible
593 wxObject* GetAsObject() ;
594
595 // get the typeinfo of the stored object
596 const wxTypeInfo* GetTypeInfo() const { return m_data->GetTypeInfo() ; }
597
598 // returns this value as string
599 wxString GetAsString() const
600 {
601 wxString s ;
602 GetTypeInfo()->ConvertToString( *this , s ) ;
603 return s ;
604 }
605 const wxString& GetName() const { return m_name ; }
606 private :
607 wxxVariantData* m_data ;
608 wxString m_name ;
609 } ;
610
611 #include <wx/dynarray.h>
612
613 WX_DECLARE_OBJARRAY_WITH_DECL(wxxVariant, wxxVariantArray, class WXDLLIMPEXP_BASE);
614
615 // templated streaming, every type must have their specialization for these methods
616
617 template<typename T>
618 void wxStringReadValue( const wxString &s , T &data );
619
620 template<typename T>
621 void wxStringWriteValue( wxString &s , const T &data);
622
623 template<typename T>
624 void wxToStringConverter( const wxxVariant &v, wxString &s) { wxStringWriteValue( s , v.WX_TEMPLATED_MEMBER_CALL(Get , T) ) ; }
625
626 template<typename T>
627 void wxFromStringConverter( const wxString &s, wxxVariant &v) { T d ; wxStringReadValue( s , d ) ; v = wxxVariant(d) ; } \
628
629 // ----------------------------------------------------------------------------
630 // Property Support
631 //
632 // wxPropertyInfo is used to inquire of the property by name. It doesn't
633 // provide access to the property, only information about it. If you
634 // want access, look at wxPropertyAccessor.
635 // ----------------------------------------------------------------------------
636
637 class WXDLLIMPEXP_BASE wxSetter
638 {
639 public:
640 wxSetter( const wxString name ) { m_name = name ; }
641 virtual ~wxSetter() {}
642 virtual void Set( wxObject *object, const wxxVariant &variantValue ) const = 0;
643 const wxString& GetName() const { return m_name ; }
644 private:
645 wxString m_name;
646 };
647
648 class WXDLLIMPEXP_BASE wxGetter
649 {
650 public:
651 wxGetter( const wxString name ) { m_name = name ; }
652 virtual ~wxGetter() {}
653 virtual void Get( const wxObject *object , wxxVariant& result) const = 0;
654 const wxString& GetName() const { return m_name ; }
655 private:
656 wxString m_name;
657 };
658
659 class WXDLLIMPEXP_BASE wxCollectionGetter
660 {
661 public :
662 wxCollectionGetter( const wxString name ) { m_name = name ; }
663 virtual ~wxCollectionGetter() {}
664 virtual void Get( const wxObject *object , wxxVariantArray& result) const = 0;
665 const wxString& GetName() const { return m_name ; }
666 private :
667 wxString m_name ;
668 } ;
669
670 template<typename coll_t> void wxCollectionToVariantArray( const coll_t& coll , wxxVariantArray& result ) ;
671
672 class WXDLLIMPEXP_BASE wxAdder
673 {
674 public :
675 wxAdder( const wxString name ) { m_name = name ; }
676 virtual ~wxAdder() {}
677 virtual void Add( wxObject *object, const wxxVariant &variantValue ) const= 0;
678 const wxString& GetName() const { return m_name ; }
679 private :
680 wxString m_name ;
681 } ;
682
683
684
685 #define WX_SETTER( property, Klass, valueType, setterMethod ) \
686 class wxSetter##property : public wxSetter \
687 { \
688 public: \
689 wxSetter##property() : wxSetter( #setterMethod ) {} \
690 ~wxSetter##property() {} \
691 void Set( wxObject *object, const wxxVariant &variantValue ) const \
692 { \
693 Klass *obj = dynamic_cast<Klass*>(object) ; \
694 if ( variantValue.HasData<valueType>() ) \
695 obj->setterMethod(variantValue.Get<valueType>()) ; \
696 else \
697 obj->setterMethod(*variantValue.Get<valueType*>()) ; \
698 } \
699 } ;
700
701 #define WX_GETTER( property, Klass, valueType , gettermethod ) \
702 class wxGetter##property : public wxGetter \
703 { \
704 public : \
705 wxGetter##property() : wxGetter( #gettermethod ) {} \
706 ~wxGetter##property() {} \
707 void Get( const wxObject *object , wxxVariant &result) const \
708 { \
709 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
710 result = wxxVariant( obj->gettermethod() ) ; \
711 } \
712 } ;
713
714 #define WX_ADDER( property, Klass, valueType , addermethod ) \
715 class wxAdder##property : public wxAdder \
716 { \
717 public: \
718 wxAdder##property() : wxAdder( #addermethod ) {} \
719 ~wxAdder##property() {} \
720 void Add( wxObject *object, const wxxVariant &variantValue ) const \
721 { \
722 Klass *obj = dynamic_cast<Klass*>(object) ; \
723 if ( variantValue.HasData<valueType>() ) \
724 obj->addermethod(variantValue.Get<valueType>()) ; \
725 else \
726 obj->addermethod(*variantValue.Get<valueType*>()) ; \
727 } \
728 } ;
729
730 #define WX_COLLECTION_GETTER( property, Klass, valueType , gettermethod ) \
731 class wxCollectionGetter##property : public wxCollectionGetter \
732 { \
733 public : \
734 wxCollectionGetter##property() : wxCollectionGetter( #gettermethod ) {} \
735 ~wxCollectionGetter##property() {} \
736 void Get( const wxObject *object , wxxVariantArray &result) const \
737 { \
738 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
739 wxCollectionToVariantArray( obj->gettermethod() , result ) ; \
740 } \
741 } ;
742
743 class WXDLLIMPEXP_BASE wxPropertyAccessor
744 {
745 public :
746 wxPropertyAccessor( wxSetter *setter , wxGetter *getter , wxAdder *adder , wxCollectionGetter *collectionGetter )
747 { m_setter = setter ; m_getter = getter ; m_adder = adder ; m_collectionGetter = collectionGetter ;}
748
749 virtual ~wxPropertyAccessor() {}
750
751 // Setting a simple property (non-collection)
752 virtual void SetProperty(wxObject *object, const wxxVariant &value) const
753 { wxASSERT_MSG(m_setter,wxT("SetProperty called w/o valid setter") ) ; m_setter->Set( object , value ) ;}
754
755 // Getting a simple property (non-collection)
756 virtual void GetProperty(const wxObject *object, wxxVariant &result) const
757 { wxASSERT_MSG(m_getter,wxT("GetProperty called w/o valid getter") ) ; m_getter->Get( object , result ) ;}
758
759 // Adding an element to a collection property
760 virtual void AddToPropertyCollection(wxObject *object, const wxxVariant &value) const
761 { wxASSERT_MSG(m_adder,wxT("AddToPropertyCollection called w/o valid adder") ) ; m_adder->Add( object , value ) ;}
762
763 // Getting a collection property
764 virtual void GetPropertyCollection( const wxObject *obj, wxxVariantArray &result) const
765 { wxASSERT_MSG(m_collectionGetter,wxT("GetPropertyCollection called w/o valid collection getter") ) ; m_collectionGetter->Get( obj , result) ;}
766
767 virtual bool HasSetter() const { return m_setter != NULL ; }
768 virtual bool HasCollectionGetter() const { return m_collectionGetter != NULL ; }
769 virtual bool HasGetter() const { return m_getter != NULL ; }
770 virtual bool HasAdder() const { return m_adder != NULL ; }
771
772 virtual const wxString& GetCollectionGetterName() const
773 { return m_collectionGetter->GetName() ; }
774 virtual const wxString& GetGetterName() const
775 { return m_getter->GetName() ; }
776 virtual const wxString& GetSetterName() const
777 { return m_setter->GetName() ; }
778 virtual const wxString& GetAdderName() const
779 { return m_adder->GetName() ; }
780
781 protected :
782 wxSetter *m_setter ;
783 wxAdder *m_adder ;
784 wxGetter *m_getter ;
785 wxCollectionGetter* m_collectionGetter ;
786 };
787
788 class WXDLLIMPEXP_BASE wxGenericPropertyAccessor : public wxPropertyAccessor
789 {
790 public :
791 wxGenericPropertyAccessor( const wxString &propName ) ;
792 ~wxGenericPropertyAccessor() ;
793
794 void RenameProperty( const wxString &oldName , const wxString &newName )
795 {
796 wxASSERT( oldName == m_propertyName ) ; m_propertyName = newName ;
797 }
798 virtual bool HasSetter() const { return true ; }
799 virtual bool HasGetter() const { return true ; }
800 virtual bool HasAdder() const { return false ; }
801 virtual bool HasCollectionGetter() const { return false ; }
802
803 virtual const wxString& GetGetterName() const
804 { return m_getterName ; }
805 virtual const wxString& GetSetterName() const
806 { return m_setterName ; }
807
808 virtual void SetProperty(wxObject *object, const wxxVariant &value) const ;
809 virtual void GetProperty(const wxObject *object, wxxVariant &value) const ;
810
811 // Adding an element to a collection property
812 virtual void AddToPropertyCollection(wxObject *WXUNUSED(object), const wxxVariant &WXUNUSED(value)) const
813 { wxASSERT_MSG(0,wxT("AddToPropertyCollection called on a generic accessor") ) ;}
814
815 // Getting a collection property
816 virtual void GetPropertyCollection( const wxObject *WXUNUSED(obj), wxxVariantArray &WXUNUSED(result)) const
817 { wxASSERT_MSG(0,wxT("GetPropertyCollection called on a generic accessor") ) ;}
818 private :
819 struct wxGenericPropertyAccessorInternal ;
820 wxGenericPropertyAccessorInternal* m_data ;
821 wxString m_propertyName ;
822 wxString m_setterName ;
823 wxString m_getterName ;
824 } ;
825
826 typedef long wxPropertyInfoFlags ;
827 enum {
828 // will be removed in future releases
829 wxPROP_DEPRECATED = 0x00000001 ,
830 // object graph property, will be streamed with priority (after constructor properties)
831 wxPROP_OBJECT_GRAPH = 0x00000002 ,
832 // this will only be streamed out and in as enum/set, the internal representation is still a long
833 wxPROP_ENUM_STORE_LONG = 0x00000004 ,
834 // don't stream out this property, needed eg to avoid streaming out children that are always created by their parents
835 wxPROP_DONT_STREAM = 0x00000008 ,
836 } ;
837
838 class WXDLLIMPEXP_BASE wxPropertyInfo
839 {
840 friend class WXDLLIMPEXP_BASE wxDynamicClassInfo ;
841 public :
842 wxPropertyInfo(wxPropertyInfo* &iter,
843 wxClassInfo* itsClass,
844 const wxString& name,
845 const wxString& typeName,
846 wxPropertyAccessor *accessor,
847 wxxVariant dv,
848 wxPropertyInfoFlags flags = 0,
849 const wxString& helpString = wxEmptyString,
850 const wxString& groupString = wxEmptyString) :
851 m_name(name),
852 m_groupString(groupString),
853 m_helpString(helpString),
854 m_itsClass(itsClass),
855 m_flags(flags),
856 m_typeName(typeName) ,
857 m_typeInfo(NULL),
858 m_collectionElementTypeInfo(NULL),
859 m_accessor(accessor),
860 m_defaultValue(dv)
861 {
862 Insert(iter);
863 }
864
865 wxPropertyInfo(wxPropertyInfo* &iter,
866 wxClassInfo* itsClass,
867 const wxString& name,
868 wxDelegateTypeInfo* type,
869 wxPropertyAccessor *accessor,
870 wxxVariant dv,
871 wxPropertyInfoFlags flags = 0,
872 const wxString& helpString = wxEmptyString,
873 const wxString& groupString = wxEmptyString) :
874 m_name(name),
875 m_groupString(groupString),
876 m_helpString(helpString),
877 m_itsClass(itsClass),
878 m_flags(flags),
879 m_typeInfo(type),
880 m_collectionElementTypeInfo(NULL),
881 m_accessor(accessor),
882 m_defaultValue(dv)
883 {
884 Insert(iter);
885 }
886
887 wxPropertyInfo(wxPropertyInfo* &iter,
888 wxClassInfo* itsClass, const wxString& name,
889 const wxString& collectionTypeName,
890 const wxString& elementTypeName,
891 wxPropertyAccessor *accessor,
892 wxPropertyInfoFlags flags = 0,
893 const wxString& helpString = wxEmptyString,
894 const wxString& groupString = wxEmptyString) :
895 m_name(name),
896 m_groupString(groupString),
897 m_helpString(helpString),
898 m_itsClass(itsClass),
899 m_flags(flags),
900 m_typeInfo(NULL),
901 m_typeName(collectionTypeName) ,
902 m_collectionElementTypeInfo(NULL),
903 m_collectionElementTypeName(elementTypeName),
904 m_accessor(accessor)
905 {
906 Insert(iter);
907 }
908
909 ~wxPropertyInfo() ;
910
911 // return the class this property is declared in
912 const wxClassInfo* GetDeclaringClass() const { return m_itsClass ; }
913
914 // return the name of this property
915 const wxString& GetName() const { return m_name ; }
916
917 // returns the flags of this property
918 wxPropertyInfoFlags GetFlags() const { return m_flags ;}
919
920 // returns the short help string of this property
921 const wxString& GetHelpString() const { return m_helpString ; }
922
923 // returns the group string of this property
924 const wxString& GetGroupString() const { return m_groupString ; }
925
926 // return the element type info of this property (for collections, otherwise NULL)
927 const wxTypeInfo * GetCollectionElementTypeInfo() const
928 {
929 if ( m_collectionElementTypeInfo == NULL )
930 m_collectionElementTypeInfo = wxTypeInfo::FindType(m_collectionElementTypeName) ;
931 return m_collectionElementTypeInfo ;
932 }
933
934 // return the type info of this property
935 const wxTypeInfo * GetTypeInfo() const
936 {
937 if ( m_typeInfo == NULL )
938 m_typeInfo = wxTypeInfo::FindType(m_typeName) ;
939 return m_typeInfo ;
940 }
941
942 // return the accessor for this property
943 wxPropertyAccessor* GetAccessor() const { return m_accessor ; }
944
945 // returns NULL if this is the last property of this class
946 wxPropertyInfo* GetNext() const { return m_next ; }
947
948 // returns the default value of this property, its kind may be wxT_VOID if it is not valid
949 wxxVariant GetDefaultValue() const { return m_defaultValue ; }
950 private :
951 void Insert(wxPropertyInfo* &iter)
952 {
953 m_next = NULL ;
954 if ( iter == NULL )
955 iter = this ;
956 else
957 {
958 wxPropertyInfo* i = iter ;
959 while( i->m_next )
960 i = i->m_next ;
961
962 i->m_next = this ;
963 }
964 }
965
966 wxString m_name ;
967 wxString m_typeName ;
968 wxString m_collectionElementTypeName ;
969 wxString m_groupString ;
970 wxString m_helpString ;
971 wxClassInfo* m_itsClass ;
972 wxPropertyInfoFlags m_flags ;
973 mutable wxTypeInfo* m_typeInfo ;
974 mutable wxTypeInfo* m_collectionElementTypeInfo ;
975 wxPropertyAccessor* m_accessor ;
976 wxxVariant m_defaultValue;
977 // string representation of the default value
978 // to be assigned by the designer to the property
979 // when the component is dropped on the container.
980 wxPropertyInfo* m_next ;
981 };
982
983 WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxPropertyInfo* , wxPropertyInfoMap , class WXDLLIMPEXP_BASE ) ;
984
985 #define WX_BEGIN_PROPERTIES_TABLE(theClass) \
986 wxPropertyInfo *theClass::GetPropertiesStatic() \
987 { \
988 typedef theClass class_t; \
989 static wxPropertyInfo* first = NULL ;
990
991 #define WX_END_PROPERTIES_TABLE() \
992 return first ; }
993
994 #define WX_HIDE_PROPERTY( pname ) \
995 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , #pname , typeid(void).name() ,NULL , wxxVariant() , wxPROP_DONT_STREAM , wxEmptyString , wxEmptyString ) ;
996
997 #define WX_PROPERTY( pname , type , setter , getter ,defaultValue , flags , help , group) \
998 WX_SETTER( pname , class_t , type , setter ) \
999 static wxSetter##pname _setter##pname ; \
1000 WX_GETTER( pname , class_t , type , getter ) \
1001 static wxGetter##pname _getter##pname ; \
1002 static wxPropertyAccessor _accessor##pname( &_setter##pname , &_getter##pname , NULL , NULL ) ; \
1003 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , #pname , typeid(type).name() ,&_accessor##pname , wxxVariant(defaultValue) , flags , group , help ) ;
1004
1005 #define WX_PROPERTY_FLAGS( pname , flags , type , setter , getter ,defaultValue , pflags , help , group) \
1006 WX_SETTER( pname , class_t , type , setter ) \
1007 static wxSetter##pname _setter##pname ; \
1008 WX_GETTER( pname , class_t , type , getter ) \
1009 static wxGetter##pname _getter##pname ; \
1010 static wxPropertyAccessor _accessor##pname( &_setter##pname , &_getter##pname , NULL , NULL ) ; \
1011 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , #pname , typeid(flags).name() ,&_accessor##pname , wxxVariant(defaultValue), wxPROP_ENUM_STORE_LONG | pflags , help , group ) ;
1012
1013 #define WX_READONLY_PROPERTY( pname , type , getter ,defaultValue , flags , help , group) \
1014 WX_GETTER( pname , class_t , type , getter ) \
1015 static wxGetter##pname _getter##pname ; \
1016 static wxPropertyAccessor _accessor##pname( NULL , &_getter##pname , NULL , NULL ) ; \
1017 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , #pname , typeid(type).name() ,&_accessor##pname , wxxVariant(defaultValue), flags , help , group ) ;
1018
1019 #define WX_PROPERTY_COLLECTION( pname , colltype , addelemtype , adder , getter , flags , help , group ) \
1020 WX_ADDER( pname , class_t , addelemtype , adder ) \
1021 static wxAdder##pname _adder##pname ; \
1022 WX_COLLECTION_GETTER( pname , class_t , colltype , getter ) \
1023 static wxCollectionGetter##pname _collectionGetter##pname ; \
1024 static wxPropertyAccessor _accessor##pname( NULL , NULL ,&_adder##pname , &_collectionGetter##pname ) ; \
1025 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , #pname , typeid(colltype).name() ,typeid(addelemtype).name() ,&_accessor##pname , flags , help , group ) ;
1026
1027 #define WX_READONLY_PROPERTY_COLLECTION( pname , colltype , addelemtype , getter , flags , help , group) \
1028 WX_COLLECTION_GETTER( pname , class_t , colltype , getter ) \
1029 static wxCollectionGetter##pname _collectionGetter##pname ; \
1030 static wxPropertyAccessor _accessor##pname( NULL , NULL , NULL , &_collectionGetter##pname ) ; \
1031 static wxPropertyInfo _propertyInfo##pname( first ,class_t::GetClassInfoStatic() , #pname , typeid(colltype).name() ,typeid(addelemtype).name() ,&_accessor##pname , flags , help , group ) ;
1032
1033
1034 #define WX_DELEGATE( name , eventType , eventClass ) \
1035 static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \
1036 static wxPropertyInfo _propertyInfo##name( first ,class_t::GetClassInfoStatic() , #name , &_typeInfo##name , NULL , wxxVariant() ) ; \
1037
1038 // ----------------------------------------------------------------------------
1039 // Handler Info
1040 //
1041 // this is describing an event sink
1042 // ----------------------------------------------------------------------------
1043
1044 class WXDLLIMPEXP_BASE wxHandlerInfo
1045 {
1046 friend class WXDLLIMPEXP_BASE wxDynamicClassInfo ;
1047 public :
1048 wxHandlerInfo(wxHandlerInfo* &iter,
1049 wxClassInfo* itsClass,
1050 const wxString& name,
1051 wxObjectEventFunction address,
1052 const wxClassInfo* eventClassInfo) :
1053 m_eventFunction(address),
1054 m_name(name),
1055 m_eventClassInfo(eventClassInfo) ,
1056 m_itsClass(itsClass)
1057 {
1058 m_next = NULL ;
1059 if ( iter == NULL )
1060 iter = this ;
1061 else
1062 {
1063 wxHandlerInfo* i = iter ;
1064 while( i->m_next )
1065 i = i->m_next ;
1066
1067 i->m_next = this ;
1068 }
1069 }
1070
1071 ~wxHandlerInfo() ;
1072
1073 // return the name of this handler
1074 const wxString& GetName() const { return m_name ; }
1075
1076 // return the class info of the event
1077 const wxClassInfo * GetEventClassInfo() const { return m_eventClassInfo ; }
1078
1079 // get the handler function pointer
1080 wxObjectEventFunction GetEventFunction() const { return m_eventFunction ; }
1081
1082 // returns NULL if this is the last handler of this class
1083 wxHandlerInfo* GetNext() const { return m_next ; }
1084
1085 // return the class this property is declared in
1086 const wxClassInfo* GetDeclaringClass() const { return m_itsClass ; }
1087
1088 private :
1089 wxObjectEventFunction m_eventFunction ;
1090 wxString m_name;
1091 const wxClassInfo* m_eventClassInfo ;
1092 wxHandlerInfo* m_next ;
1093 wxClassInfo* m_itsClass ;
1094 };
1095
1096 #define WX_HANDLER(name,eventClassType) \
1097 static wxHandlerInfo _handlerInfo##name( first , class_t::GetClassInfoStatic() , #name , (wxObjectEventFunction) (wxEventFunction) &name , CLASSINFO( eventClassType ) ) ;
1098
1099 #define WX_BEGIN_HANDLERS_TABLE(theClass) \
1100 wxHandlerInfo *theClass::GetHandlersStatic() \
1101 { \
1102 typedef theClass class_t; \
1103 static wxHandlerInfo* first = NULL ;
1104
1105 #define WX_END_HANDLERS_TABLE() \
1106 return first ; }
1107
1108 // ----------------------------------------------------------------------------
1109 // Constructor Bridges
1110 //
1111 // allow to set up constructors with params during runtime
1112 // ----------------------------------------------------------------------------
1113
1114 class WXDLLIMPEXP_BASE wxConstructorBridge
1115 {
1116 public :
1117 virtual void Create(wxObject *o, wxxVariant *args) = 0;
1118 };
1119
1120 // Creator Bridges for all Numbers of Params
1121
1122 // no params
1123
1124 template<typename Class>
1125 struct wxConstructorBridge_0 : public wxConstructorBridge
1126 {
1127 void Create(wxObject *o, wxxVariant *)
1128 {
1129 Class *obj = dynamic_cast<Class*>(o);
1130 obj->Create();
1131 }
1132 };
1133
1134 struct wxConstructorBridge_Dummy : public wxConstructorBridge
1135 {
1136 void Create(wxObject *, wxxVariant *)
1137 {
1138 }
1139 } ;
1140
1141 #define WX_CONSTRUCTOR_0(klass) \
1142 wxConstructorBridge_0<klass> constructor##klass ; \
1143 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1144 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
1145 const int klass::sm_constructorPropertiesCount##klass = 0 ;
1146
1147 #define WX_CONSTRUCTOR_DUMMY(klass) \
1148 wxConstructorBridge_Dummy constructor##klass ; \
1149 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1150 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
1151 const int klass::sm_constructorPropertiesCount##klass = 0 ;
1152
1153 // 1 param
1154
1155 template<typename Class, typename T0>
1156 struct wxConstructorBridge_1 : public wxConstructorBridge
1157 {
1158 void Create(wxObject *o, wxxVariant *args)
1159 {
1160 Class *obj = dynamic_cast<Class*>(o);
1161 obj->Create(
1162 args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0)
1163 );
1164 }
1165 };
1166
1167 #define WX_CONSTRUCTOR_1(klass,t0,v0) \
1168 wxConstructorBridge_1<klass,t0> constructor##klass ; \
1169 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1170 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 } ; \
1171 const int klass::sm_constructorPropertiesCount##klass = 1 ;
1172
1173 // 2 params
1174
1175 template<typename Class,
1176 typename T0, typename T1>
1177 struct wxConstructorBridge_2 : public wxConstructorBridge
1178 {
1179 void Create(wxObject *o, wxxVariant *args)
1180 {
1181 Class *obj = dynamic_cast<Class*>(o);
1182 obj->Create(
1183 args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) ,
1184 args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1)
1185 );
1186 }
1187 };
1188
1189 #define WX_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
1190 wxConstructorBridge_2<klass,t0,t1> constructor##klass ; \
1191 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1192 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 } ; \
1193 const int klass::sm_constructorPropertiesCount##klass = 2;
1194
1195 // 3 params
1196
1197 template<typename Class,
1198 typename T0, typename T1, typename T2>
1199 struct wxConstructorBridge_3 : public wxConstructorBridge
1200 {
1201 void Create(wxObject *o, wxxVariant *args)
1202 {
1203 Class *obj = dynamic_cast<Class*>(o);
1204 obj->Create(
1205 args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) ,
1206 args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) ,
1207 args[2].WX_TEMPLATED_MEMBER_CALL(Get , T2)
1208 );
1209 }
1210 };
1211
1212 #define WX_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
1213 wxConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \
1214 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1215 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 } ; \
1216 const int klass::sm_constructorPropertiesCount##klass = 3 ;
1217
1218 // 4 params
1219
1220 template<typename Class,
1221 typename T0, typename T1, typename T2, typename T3>
1222 struct wxConstructorBridge_4 : public wxConstructorBridge
1223 {
1224 void Create(wxObject *o, wxxVariant *args)
1225 {
1226 Class *obj = dynamic_cast<Class*>(o);
1227 obj->Create(
1228 args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) ,
1229 args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) ,
1230 args[2].WX_TEMPLATED_MEMBER_CALL(Get , T2) ,
1231 args[3].WX_TEMPLATED_MEMBER_CALL(Get , T3)
1232 );
1233 }
1234 };
1235
1236 #define WX_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
1237 wxConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass ; \
1238 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1239 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 } ; \
1240 const int klass::sm_constructorPropertiesCount##klass = 4 ;
1241
1242 // 5 params
1243
1244 template<typename Class,
1245 typename T0, typename T1, typename T2, typename T3, typename T4>
1246 struct wxConstructorBridge_5 : public wxConstructorBridge
1247 {
1248 void Create(wxObject *o, wxxVariant *args)
1249 {
1250 Class *obj = dynamic_cast<Class*>(o);
1251 obj->Create(
1252 args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) ,
1253 args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) ,
1254 args[2].WX_TEMPLATED_MEMBER_CALL(Get , T2) ,
1255 args[3].WX_TEMPLATED_MEMBER_CALL(Get , T3) ,
1256 args[4].WX_TEMPLATED_MEMBER_CALL(Get , T4)
1257 );
1258 }
1259 };
1260
1261 #define WX_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
1262 wxConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass ; \
1263 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1264 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 } ; \
1265 const int klass::sm_constructorPropertiesCount##klass = 5;
1266
1267 // 6 params
1268
1269 template<typename Class,
1270 typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
1271 struct wxConstructorBridge_6 : public wxConstructorBridge
1272 {
1273 void Create(wxObject *o, wxxVariant *args)
1274 {
1275 Class *obj = dynamic_cast<Class*>(o);
1276 obj->Create(
1277 args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) ,
1278 args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) ,
1279 args[2].WX_TEMPLATED_MEMBER_CALL(Get , T2) ,
1280 args[3].WX_TEMPLATED_MEMBER_CALL(Get , T3) ,
1281 args[4].WX_TEMPLATED_MEMBER_CALL(Get , T4) ,
1282 args[5].WX_TEMPLATED_MEMBER_CALL(Get , T5)
1283 );
1284 }
1285 };
1286
1287 template<typename Class,
1288 typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
1289 struct wxDirectConstructorBridge_6 : public wxConstructorBridge
1290 {
1291 void Create(wxObject *o, wxxVariant *args)
1292 {
1293 Class *obj = new Class(
1294 args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) ,
1295 args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) ,
1296 args[2].WX_TEMPLATED_MEMBER_CALL(Get , T2) ,
1297 args[3].WX_TEMPLATED_MEMBER_CALL(Get , T3) ,
1298 args[4].WX_TEMPLATED_MEMBER_CALL(Get , T4) ,
1299 args[5].WX_TEMPLATED_MEMBER_CALL(Get , T5)
1300 );
1301 }
1302 };
1303
1304 #define WX_DIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1305 wxDirectConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1306 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1307 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 } ; \
1308 const int klass::sm_constructorPropertiesCount##klass = 6;
1309
1310 #define WX_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1311 wxConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1312 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1313 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 } ; \
1314 const int klass::sm_constructorPropertiesCount##klass = 6;
1315
1316 // 7 params
1317
1318 template<typename Class,
1319 typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
1320 struct wxConstructorBridge_7 : public wxConstructorBridge
1321 {
1322 void Create(wxObject *o, wxxVariant *args)
1323 {
1324 Class *obj = dynamic_cast<Class*>(o);
1325 obj->Create(
1326 args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) ,
1327 args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) ,
1328 args[2].WX_TEMPLATED_MEMBER_CALL(Get , T2) ,
1329 args[3].WX_TEMPLATED_MEMBER_CALL(Get , T3) ,
1330 args[4].WX_TEMPLATED_MEMBER_CALL(Get , T4) ,
1331 args[5].WX_TEMPLATED_MEMBER_CALL(Get , T5) ,
1332 args[6].WX_TEMPLATED_MEMBER_CALL(Get , T6)
1333 );
1334 }
1335 };
1336
1337 #define WX_CONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
1338 wxConstructorBridge_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass ; \
1339 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1340 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 , #v6} ; \
1341 const int klass::sm_constructorPropertiesCount##klass = 7;
1342
1343 // 8 params
1344
1345 template<typename Class,
1346 typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
1347 struct wxConstructorBridge_8 : public wxConstructorBridge
1348 {
1349 void Create(wxObject *o, wxxVariant *args)
1350 {
1351 Class *obj = dynamic_cast<Class*>(o);
1352 obj->Create(
1353 args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) ,
1354 args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) ,
1355 args[2].WX_TEMPLATED_MEMBER_CALL(Get , T2) ,
1356 args[3].WX_TEMPLATED_MEMBER_CALL(Get , T3) ,
1357 args[4].WX_TEMPLATED_MEMBER_CALL(Get , T4) ,
1358 args[5].WX_TEMPLATED_MEMBER_CALL(Get , T5) ,
1359 args[6].WX_TEMPLATED_MEMBER_CALL(Get , T6) ,
1360 args[7].WX_TEMPLATED_MEMBER_CALL(Get , T7)
1361 );
1362 }
1363 };
1364
1365 #define WX_CONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
1366 wxConstructorBridge_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass ; \
1367 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1368 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 , #v6 , #v7} ; \
1369 const int klass::sm_constructorPropertiesCount##klass = 8;
1370 // ----------------------------------------------------------------------------
1371 // wxClassInfo
1372 // ----------------------------------------------------------------------------
1373
1374 typedef wxObject *(*wxObjectConstructorFn)(void);
1375 typedef wxObject* (*wxVariantToObjectConverter)( wxxVariant &data ) ;
1376 typedef wxxVariant (*wxObjectToVariantConverter)( wxObject* ) ;
1377
1378 class WXDLLIMPEXP_BASE wxWriter;
1379 class WXDLLIMPEXP_BASE wxPersister;
1380
1381 typedef bool (*wxObjectStreamingCallback) ( const wxObject *, wxWriter * , wxPersister * , wxxVariantArray & ) ;
1382
1383 class WXDLLIMPEXP_BASE wxClassInfo
1384 {
1385 friend class WXDLLIMPEXP_BASE wxPropertyInfo ;
1386 friend class WXDLLIMPEXP_BASE wxHandlerInfo ;
1387 public:
1388 wxClassInfo(const wxClassInfo **_Parents,
1389 const wxChar *_UnitName,
1390 const wxChar *_ClassName,
1391 int size,
1392 wxObjectConstructorFn ctor ,
1393 wxPropertyInfo *_Props ,
1394 wxHandlerInfo *_Handlers ,
1395 wxConstructorBridge* _Constructor ,
1396 const wxChar ** _ConstructorProperties ,
1397 const int _ConstructorPropertiesCount ,
1398 wxVariantToObjectConverter _PtrConverter1 ,
1399 wxVariantToObjectConverter _Converter2 ,
1400 wxObjectToVariantConverter _Converter3 ,
1401 wxObjectStreamingCallback _streamingCallback = NULL
1402 ) :
1403
1404 m_className(_ClassName),
1405 m_objectSize(size),
1406 m_objectConstructor(ctor),
1407 m_next(sm_first),
1408 m_firstProperty(_Props),
1409 m_firstHandler(_Handlers),
1410 m_parents(_Parents),
1411 m_unitName(_UnitName),
1412 m_constructor(_Constructor),
1413 m_constructorProperties(_ConstructorProperties),
1414 m_constructorPropertiesCount(_ConstructorPropertiesCount),
1415 m_variantOfPtrToObjectConverter(_PtrConverter1),
1416 m_variantToObjectConverter(_Converter2),
1417 m_objectToVariantConverter(_Converter3),
1418 m_streamingCallback(_streamingCallback)
1419 {
1420 sm_first = this;
1421 Register() ;
1422 }
1423
1424 wxClassInfo(const wxChar *_UnitName, const wxChar *_ClassName,
1425 const wxClassInfo **_Parents) :
1426 m_className(_ClassName),
1427 m_objectSize(0),
1428 m_objectConstructor(NULL),
1429 m_next(sm_first),
1430 m_firstProperty(NULL),
1431 m_firstHandler(NULL),
1432 m_parents(_Parents),
1433 m_unitName(_UnitName),
1434 m_constructor(NULL),
1435 m_constructorProperties(NULL),
1436 m_constructorPropertiesCount(0),
1437 m_variantOfPtrToObjectConverter(NULL),
1438 m_variantToObjectConverter(NULL),
1439 m_objectToVariantConverter(NULL),
1440 m_streamingCallback(NULL)
1441 {
1442 sm_first = this;
1443 Register() ;
1444 }
1445
1446 virtual ~wxClassInfo() ;
1447
1448 // allocates an instance of this class, this object does not have to be initialized or fully constructed
1449 // as this call will be followed by a call to Create
1450 virtual wxObject *AllocateObject() const { return m_objectConstructor ? (*m_objectConstructor)() : 0; }
1451
1452 // 'old naming' for AllocateObject staying here for backward compatibility
1453 wxObject *CreateObject() const { return AllocateObject() ; }
1454
1455 const wxChar *GetClassName() const { return m_className; }
1456 const wxChar *GetIncludeName() const { return m_unitName ; }
1457 const wxClassInfo **GetParents() const { return m_parents; }
1458 int GetSize() const { return m_objectSize; }
1459
1460 wxObjectConstructorFn GetConstructor() const { return m_objectConstructor; }
1461 static const wxClassInfo *GetFirst() { return sm_first; }
1462 const wxClassInfo *GetNext() const { return m_next; }
1463 static wxClassInfo *FindClass(const wxChar *className);
1464
1465 // Climb upwards through inheritance hierarchy.
1466 // Dual inheritance is catered for.
1467
1468 bool IsKindOf(const wxClassInfo *info) const
1469 {
1470 if ( info != 0 )
1471 {
1472 if ( info == this )
1473 return true ;
1474
1475 for ( int i = 0 ; m_parents[i] ; ++ i )
1476 {
1477 if ( m_parents[i]->IsKindOf( info ) )
1478 return true ;
1479 }
1480 }
1481 return false ;
1482 }
1483
1484 // if there is a callback registered with that class it will be called
1485 // before this object will be written to disk, it can veto streaming out
1486 // this object by returning false, if this class has not registered a
1487 // callback, the search will go up the inheritance tree if no callback has
1488 // been registered true will be returned by default
1489 bool BeforeWriteObject( const wxObject *obj, wxWriter *streamer , wxPersister *persister , wxxVariantArray &metadata) const ;
1490
1491 // gets the streaming callback from this class or any superclass
1492 wxObjectStreamingCallback GetStreamingCallback() const ;
1493
1494 #ifdef WXWIN_COMPATIBILITY_2_4
1495 // Initializes parent pointers and hash table for fast searching.
1496 wxDEPRECATED( static void InitializeClasses() );
1497 // Cleans up hash table used for fast searching.
1498 wxDEPRECATED( static void CleanUpClasses() );
1499 #endif
1500 static void CleanUp();
1501
1502 // returns the first property
1503 const wxPropertyInfo* GetFirstProperty() const { return m_firstProperty ; }
1504
1505 // returns the first handler
1506 const wxHandlerInfo* GetFirstHandler() const { return m_firstHandler ; }
1507
1508 // Call the Create upon an instance of the class, in the end the object is fully
1509 // initialized
1510 virtual void Create (wxObject *object, int ParamCount, wxxVariant *Params) const
1511 {
1512 wxASSERT_MSG( ParamCount == m_constructorPropertiesCount , wxT("Illegal Parameter Count for Create Method")) ;
1513 m_constructor->Create( object , Params ) ;
1514 }
1515
1516 // get number of parameters for constructor
1517 virtual int GetCreateParamCount() const { return m_constructorPropertiesCount; }
1518
1519 // get n-th constructor parameter
1520 virtual const wxChar* GetCreateParamName(int n) const { return m_constructorProperties[n] ; }
1521
1522 // Runtime access to objects for simple properties (get/set) by property name, and variant data
1523 virtual void SetProperty (wxObject *object, const wxChar *propertyName, const wxxVariant &value) const ;
1524 virtual wxxVariant GetProperty (wxObject *object, const wxChar *propertyName) const;
1525
1526 // Runtime access to objects for collection properties by property name
1527 virtual wxxVariantArray GetPropertyCollection(wxObject *object, const wxChar *propertyName) const ;
1528 virtual void AddToPropertyCollection(wxObject *object, const wxChar *propertyName , const wxxVariant& value) const ;
1529
1530 // we must be able to cast variants to wxObject pointers, templates seem not to be suitable
1531 wxObject* VariantToInstance( wxxVariant &data ) const
1532 { if ( data.GetTypeInfo()->GetKind() == wxT_OBJECT )
1533 return m_variantToObjectConverter( data ) ;
1534 else
1535 return m_variantOfPtrToObjectConverter( data ) ;
1536 }
1537
1538 wxxVariant InstanceToVariant( wxObject *object ) const { return m_objectToVariantConverter( object ) ; }
1539
1540 // find property by name
1541 virtual const wxPropertyInfo *FindPropertyInfo (const wxChar *PropertyName) const ;
1542
1543 // find handler by name
1544 virtual const wxHandlerInfo *FindHandlerInfo (const wxChar *PropertyName) const ;
1545
1546 // find property by name
1547 virtual wxPropertyInfo *FindPropertyInfoInThisClass (const wxChar *PropertyName) const ;
1548
1549 // find handler by name
1550 virtual wxHandlerInfo *FindHandlerInfoInThisClass (const wxChar *PropertyName) const ;
1551
1552 // puts all the properties of this class and its superclasses in the map, as long as there is not yet
1553 // an entry with the same name (overriding mechanism)
1554 void GetProperties( wxPropertyInfoMap &map ) const ;
1555 public:
1556 const wxChar *m_className;
1557 int m_objectSize;
1558 wxObjectConstructorFn m_objectConstructor;
1559
1560 // class info object live in a linked list:
1561 // pointers to its head and the next element in it
1562
1563 static wxClassInfo *sm_first;
1564 wxClassInfo *m_next;
1565
1566 // FIXME: this should be private (currently used directly by way too
1567 // many clients)
1568 static wxHashTable *sm_classTable;
1569
1570 protected :
1571 wxPropertyInfo * m_firstProperty ;
1572 wxHandlerInfo * m_firstHandler ;
1573 private:
1574 const wxClassInfo** m_parents ;
1575 const wxChar* m_unitName;
1576
1577 wxConstructorBridge* m_constructor ;
1578 const wxChar ** m_constructorProperties ;
1579 const int m_constructorPropertiesCount ;
1580 wxVariantToObjectConverter m_variantOfPtrToObjectConverter ;
1581 wxVariantToObjectConverter m_variantToObjectConverter ;
1582 wxObjectToVariantConverter m_objectToVariantConverter ;
1583 wxObjectStreamingCallback m_streamingCallback ;
1584 const wxPropertyAccessor *FindAccessor (const wxChar *propertyName) const ;
1585
1586
1587 // InitializeClasses() helper
1588 static wxClassInfo *GetBaseByName(const wxChar *name) ;
1589
1590 protected:
1591 // registers the class
1592 void Register();
1593 void Unregister();
1594
1595 DECLARE_NO_COPY_CLASS(wxClassInfo)
1596 };
1597
1598
1599 WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name);
1600
1601 // ----------------------------------------------------------------------------
1602 // wxDynamicObject
1603 // ----------------------------------------------------------------------------
1604 //
1605 // this object leads to having a pure runtime-instantiation
1606
1607 class WXDLLIMPEXP_BASE wxDynamicClassInfo : public wxClassInfo
1608 {
1609 public :
1610 wxDynamicClassInfo( const wxChar *_UnitName, const wxChar *_ClassName , const wxClassInfo* superClass ) ;
1611 virtual ~wxDynamicClassInfo() ;
1612
1613 // constructs a wxDynamicObject with an instance
1614 virtual wxObject *AllocateObject() const ;
1615
1616 // Call the Create method for a class
1617 virtual void Create (wxObject *object, int ParamCount, wxxVariant *Params) const ;
1618
1619 // get number of parameters for constructor
1620 virtual int GetCreateParamCount() const ;
1621
1622 // get i-th constructor parameter
1623 virtual const wxChar* GetCreateParamName(int i) const ;
1624
1625 // Runtime access to objects by property name, and variant data
1626 virtual void SetProperty (wxObject *object, const wxChar *PropertyName, const wxxVariant &Value) const ;
1627 virtual wxxVariant GetProperty (wxObject *object, const wxChar *PropertyName) const ;
1628
1629 // adds a property to this class at runtime
1630 void AddProperty( const wxChar *propertyName , const wxTypeInfo* typeInfo ) ;
1631
1632 // removes an existing runtime-property
1633 void RemoveProperty( const wxChar *propertyName ) ;
1634
1635 // renames an existing runtime-property
1636 void RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName ) ;
1637
1638 // as a handler to this class at runtime
1639 void AddHandler( const wxChar *handlerName , wxObjectEventFunction address , const wxClassInfo* eventClassInfo ) ;
1640
1641 // removes an existing runtime-handler
1642 void RemoveHandler( const wxChar *handlerName ) ;
1643
1644 // renames an existing runtime-handler
1645 void RenameHandler( const wxChar *oldHandlerName , const wxChar *newHandlerName ) ;
1646 } ;
1647
1648 // ----------------------------------------------------------------------------
1649 // Dynamic class macros
1650 // ----------------------------------------------------------------------------
1651
1652 #define _DECLARE_DYNAMIC_CLASS(name) \
1653 public: \
1654 static wxClassInfo sm_class##name; \
1655 static const wxClassInfo* sm_classParents##name[] ; \
1656 static wxPropertyInfo* GetPropertiesStatic() ; \
1657 static wxHandlerInfo* GetHandlersStatic() ; \
1658 static wxClassInfo *GetClassInfoStatic() \
1659 { return &name::sm_class##name; } \
1660 virtual wxClassInfo *GetClassInfo() const \
1661 { return &name::sm_class##name; }
1662
1663 #define DECLARE_DYNAMIC_CLASS(name) \
1664 static wxConstructorBridge* sm_constructor##name ; \
1665 static const wxChar * sm_constructorProperties##name[] ; \
1666 static const int sm_constructorPropertiesCount##name ; \
1667 _DECLARE_DYNAMIC_CLASS(name)
1668
1669 #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
1670 DECLARE_NO_ASSIGN_CLASS(name) \
1671 DECLARE_DYNAMIC_CLASS(name)
1672
1673 #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \
1674 DECLARE_NO_COPY_CLASS(name) \
1675 DECLARE_DYNAMIC_CLASS(name)
1676
1677 #define DECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name)
1678 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
1679
1680 // -----------------------------------
1681 // for concrete classes
1682 // -----------------------------------
1683
1684 // Single inheritance with one base class
1685
1686 #define _TYPEINFO_CLASSES(n) \
1687 wxClassTypeInfo s_typeInfo##n(wxT_OBJECT , &n::sm_class##n , NULL , NULL , typeid(n).name()) ; \
1688 wxClassTypeInfo s_typeInfoPtr##n(wxT_OBJECT_PTR , &n::sm_class##n , NULL , NULL , typeid(n*).name()) ;
1689
1690 #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit , callback) \
1691 wxObject* wxConstructorFor##name() \
1692 { return new name; } \
1693 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1694 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1695 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1696 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1697 (int) sizeof(name), \
1698 (wxObjectConstructorFn) wxConstructorFor##name , \
1699 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1700 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name , callback); \
1701 _TYPEINFO_CLASSES(name)
1702
1703 #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \
1704 wxObject* wxConstructorFor##name() \
1705 { return new name; } \
1706 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1707 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return &data.Get<name>() ; } \
1708 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1709 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1710 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1711 (int) sizeof(name), \
1712 (wxObjectConstructorFn) wxConstructorFor##name , \
1713 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1714 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name, callback); \
1715 _TYPEINFO_CLASSES(name)
1716
1717 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \
1718 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" , NULL ) \
1719 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1720 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1721 WX_CONSTRUCTOR_DUMMY( name )
1722
1723 #define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \
1724 _IMPLEMENT_DYNAMIC_CLASS( name , basename , "" , NULL ) \
1725 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1726 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1727 WX_CONSTRUCTOR_DUMMY( name )
1728
1729 #define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \
1730 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , NULL )
1731
1732 #define IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name , basename , unit , callback ) \
1733 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , &callback )
1734
1735 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \
1736 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit , NULL )
1737
1738 // this is for classes that do not derive from wxobject, there are no creators for these
1739
1740 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name , unit ) \
1741 const wxClassInfo* name::sm_classParents##name[] = { NULL } ; \
1742 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1743 (int) sizeof(name), \
1744 (wxObjectConstructorFn) 0 , \
1745 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1746 0 , 0 , 0 ); \
1747 _TYPEINFO_CLASSES(name)
1748
1749 // this is for subclasses that still do not derive from wxobject
1750
1751 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name , basename, unit ) \
1752 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1753 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1754 (int) sizeof(name), \
1755 (wxObjectConstructorFn) 0 , \
1756 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1757 0 , 0 , 0 ); \
1758 _TYPEINFO_CLASSES(name)
1759
1760
1761 // Multiple inheritance with two base classes
1762
1763 #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit) \
1764 wxObject* wxConstructorFor##name() \
1765 { return new name; } \
1766 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,&basename2::sm_class##basename2 , NULL } ; \
1767 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1768 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1769 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1770 (int) sizeof(name), \
1771 (wxObjectConstructorFn) wxConstructorFor##name , \
1772 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1773 name::sm_constructorPropertiesCount##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1774 _TYPEINFO_CLASSES(name)
1775
1776 #define IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2) \
1777 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , "") \
1778 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1779 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1780 WX_CONSTRUCTOR_DUMMY( name )
1781
1782 #define IMPLEMENT_DYNAMIC_CLASS2_XTI( name , basename , basename2, unit) \
1783 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , unit)
1784
1785 // -----------------------------------
1786 // for abstract classes
1787 // -----------------------------------
1788
1789 // Single inheritance with one base class
1790
1791 #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
1792 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1793 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1794 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1795 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1796 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1797 (int) sizeof(name), \
1798 (wxObjectConstructorFn) 0 , \
1799 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1800 0 , wxVariantOfPtrToObjectConverter##name ,wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1801 _TYPEINFO_CLASSES(name)
1802
1803 #define IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1804 _IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1805 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1806 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; }
1807
1808 // Multiple inheritance with two base classes
1809
1810 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
1811 wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \
1812 wxT(#basename2), (int) sizeof(name), \
1813 (wxObjectConstructorFn) 0);
1814
1815 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
1816 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
1817
1818 // --------------------------------------------------------------------------
1819 // Collection Support
1820 // --------------------------------------------------------------------------
1821
1822 template<typename iter , typename collection_t > void wxListCollectionToVariantArray( const collection_t& coll , wxxVariantArray &value )
1823 {
1824 iter current = coll.GetFirst() ;
1825 while (current)
1826 {
1827 value.Add( new wxxVariant(current->GetData()) ) ;
1828 current = current->GetNext();
1829 }
1830 }
1831
1832 template<typename collection_t> void wxArrayCollectionToVariantArray( const collection_t& coll , wxxVariantArray &value )
1833 {
1834 for( size_t i = 0 ; i < coll.GetCount() ; i++ )
1835 {
1836 value.Add( new wxxVariant(coll[i]) ) ;
1837 }
1838 }
1839
1840
1841 #endif