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