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