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