linkage corrections, destructors added
[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 ( size_t 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 ~wxSetter() {} \
709 void Set( wxObject *object, const wxxVariant &variantValue ) const \
710 { \
711 Klass *obj = dynamic_cast<Klass*>(object) ; \
712 if ( variantValue.HasData<valueType>() ) \
713 obj->setterMethod(variantValue.Get<valueType>()) ; \
714 else \
715 obj->setterMethod(*variantValue.Get<valueType*>()) ; \
716 } \
717 } ;
718
719 #define WX_GETTER( property, Klass, valueType , gettermethod ) \
720 class wxGetter##property : public wxGetter \
721 { \
722 public : \
723 wxGetter##property() : wxGetter( #gettermethod ) {} \
724 ~wxGetter() {} \
725 void Get( const wxObject *object , wxxVariant &result) const \
726 { \
727 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
728 result = wxxVariant( obj->gettermethod() ) ; \
729 } \
730 } ;
731
732 #define WX_ADDER( property, Klass, valueType , addermethod ) \
733 class wxAdder##property : public wxAdder \
734 { \
735 public: \
736 wxAdder##property() : wxAdder( #addermethod ) {} \
737 ~wxAdder() {} \
738 void Add( wxObject *object, const wxxVariant &variantValue ) const \
739 { \
740 Klass *obj = dynamic_cast<Klass*>(object) ; \
741 if ( variantValue.HasData<valueType>() ) \
742 obj->addermethod(variantValue.Get<valueType>()) ; \
743 else \
744 obj->addermethod(*variantValue.Get<valueType*>()) ; \
745 } \
746 } ;
747
748 #define WX_COLLECTION_GETTER( property, Klass, valueType , gettermethod ) \
749 class wxCollectionGetter##property : public wxCollectionGetter \
750 { \
751 public : \
752 wxCollectionGetter##property() : wxCollectionGetter( #gettermethod ) {} \
753 ~wxCollectionGetter() {} \
754 void Get( const wxObject *object , wxxVariantArray &result) const \
755 { \
756 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
757 wxCollectionToVariantArray( obj->gettermethod() , result ) ; \
758 } \
759 } ;
760
761 class WXDLLIMPEXP_BASE wxPropertyAccessor
762 {
763 public :
764 wxPropertyAccessor( wxSetter *setter , wxGetter *getter , wxAdder *adder , wxCollectionGetter *collectionGetter )
765 { m_setter = setter ; m_getter = getter ; m_adder = adder ; m_collectionGetter = collectionGetter ;}
766
767 virtual ~wxPropertyAccessor() {}
768
769 // Setting a simple property (non-collection)
770 virtual void SetProperty(wxObject *object, const wxxVariant &value) const
771 { wxASSERT_MSG(m_setter,wxT("SetProperty called w/o valid setter") ) ; m_setter->Set( object , value ) ;}
772
773 // Getting a simple property (non-collection)
774 virtual void GetProperty(const wxObject *object, wxxVariant &result) const
775 { wxASSERT_MSG(m_getter,wxT("GetProperty called w/o valid getter") ) ; m_getter->Get( object , result ) ;}
776
777 // Adding an element to a collection property
778 virtual void AddToPropertyCollection(wxObject *object, const wxxVariant &value) const
779 { wxASSERT_MSG(m_adder,wxT("AddToPropertyCollection called w/o valid adder") ) ; m_adder->Add( object , value ) ;}
780
781 // Getting a collection property
782 virtual void GetPropertyCollection( const wxObject *obj, wxxVariantArray &result) const
783 { wxASSERT_MSG(m_collectionGetter,wxT("GetPropertyCollection called w/o valid collection getter") ) ; m_collectionGetter->Get( obj , result) ;}
784
785 virtual bool HasSetter() const { return m_setter != NULL ; }
786 virtual bool HasCollectionGetter() const { return m_collectionGetter != NULL ; }
787 virtual bool HasGetter() const { return m_getter != NULL ; }
788 virtual bool HasAdder() const { return m_adder != NULL ; }
789
790 virtual const wxString& GetCollectionGetterName() const
791 { return m_collectionGetter->GetName() ; }
792 virtual const wxString& GetGetterName() const
793 { return m_getter->GetName() ; }
794 virtual const wxString& GetSetterName() const
795 { return m_setter->GetName() ; }
796 virtual const wxString& GetAdderName() const
797 { return m_adder->GetName() ; }
798 /*
799 virtual wxxVariant ReadValue( const wxString &value ) const ;
800 virtual void WriteValue( wxString& value , const wxObject *o ) const ;
801 */
802 protected :
803 wxSetter *m_setter ;
804 wxAdder *m_adder ;
805 wxGetter *m_getter ;
806 wxCollectionGetter* m_collectionGetter ;
807 };
808
809 class WXDLLIMPEXP_BASE wxGenericPropertyAccessor : public wxPropertyAccessor
810 {
811 public :
812 wxGenericPropertyAccessor( const wxString &propName ) ;
813 ~wxGenericPropertyAccessor() ;
814
815 virtual bool HasSetter() const { return true ; }
816 virtual bool HasGetter() const { return true ; }
817 virtual bool HasAdder() const { return false ; }
818 virtual bool HasCollectionGetter() const { return false ; }
819
820 virtual const wxString& GetGetterName() const
821 { return m_getterName ; }
822 virtual const wxString& GetSetterName() const
823 { return m_setterName ; }
824
825 virtual void SetProperty(wxObject *object, const wxxVariant &value) const ;
826 virtual void GetProperty(const wxObject *object, wxxVariant &value) const ;
827
828 // Adding an element to a collection property
829 virtual void AddToPropertyCollection(wxObject *WXUNUSED(object), const wxxVariant &WXUNUSED(value)) const
830 { wxASSERT_MSG(0,wxT("AddToPropertyCollection called on a generic accessor") ) ;}
831
832 // Getting a collection property
833 virtual void GetPropertyCollection( const wxObject *WXUNUSED(obj), wxxVariantArray &WXUNUSED(result)) const
834 { wxASSERT_MSG(0,wxT("GetPropertyCollection called on a generic accessor") ) ;}
835 private :
836 struct wxGenericPropertyAccessorInternal ;
837 wxGenericPropertyAccessorInternal* m_data ;
838 wxString m_propertyName ;
839 wxString m_setterName ;
840 wxString m_getterName ;
841 } ;
842
843 typedef long wxPropertyInfoFlags ;
844 enum {
845 // will be removed in future releases
846 wxPROP_DEPRECATED = 0x00000001 ,
847 // object graph property, will be streamed with priority (after constructor properties)
848 wxPROP_OBJECT_GRAPH = 0x00000002 ,
849 // this will only be streamed out and in as enum/set, the internal representation is still a long
850 wxPROP_ENUM_STORE_LONG = 0x00000004 ,
851 // don't stream out this property, needed eg to avoid streaming out children that are always created by their parents
852 wxPROP_DONT_STREAM = 0x00000008 ,
853 } ;
854
855 class WXDLLIMPEXP_BASE wxPropertyInfo
856 {
857 public :
858 wxPropertyInfo(wxPropertyInfo* &iter,
859 const wxClassInfo* itsClass,
860 const wxString& name,
861 const wxTypeInfo* typeInfo,
862 wxPropertyAccessor *accessor,
863 wxxVariant dv,
864 wxPropertyInfoFlags flags = 0,
865 const wxString& helpString = wxEmptyString,
866 const wxString& groupString = wxEmptyString) :
867 m_name(name),
868 m_groupString(groupString),
869 m_helpString(helpString),
870 m_itsClass(itsClass),
871 m_flags(flags),
872 m_typeInfo(typeInfo),
873 m_collectionElementTypeInfo(NULL),
874 m_accessor(accessor),
875 m_defaultValue(dv)
876 {
877 Insert(iter);
878 }
879
880 wxPropertyInfo(wxPropertyInfo* &iter,
881 const wxClassInfo* itsClass, const wxString& name,
882 const wxTypeInfo* collTypeInfo,
883 const wxTypeInfo* elemTypeInfo,
884 wxPropertyAccessor *accessor,
885 wxPropertyInfoFlags flags = 0,
886 const wxString& helpString = wxEmptyString,
887 const wxString& groupString = wxEmptyString) :
888 m_name(name),
889 m_groupString(groupString),
890 m_helpString(helpString),
891 m_itsClass(itsClass),
892 m_flags(flags),
893 m_typeInfo(collTypeInfo),
894 m_collectionElementTypeInfo(elemTypeInfo),
895 m_accessor(accessor)
896 {
897 Insert(iter);
898 }
899
900 ~wxPropertyInfo() ;
901
902 // return the class this property is declared in
903 const wxClassInfo* GetDeclaringClass() const { return m_itsClass ; }
904
905 // return the name of this property
906 const wxString& GetName() const { return m_name ; }
907
908 // returns the flags of this property
909 wxPropertyInfoFlags GetFlags() const { return m_flags ;}
910
911 // returns the short help string of this property
912 const wxString& GetHelpString() const { return m_helpString ; }
913
914 // returns the group string of this property
915 const wxString& GetGroupString() const { return m_groupString ; }
916
917 // return the element type info of this property (for collections, otherwise NULL)
918 const wxTypeInfo * GetCollectionElementTypeInfo() const { return m_collectionElementTypeInfo ; }
919
920 // return the type info of this property
921 const wxTypeInfo * GetTypeInfo() const { return m_typeInfo ; }
922
923 // return the accessor for this property
924 wxPropertyAccessor* GetAccessor() const { return m_accessor ; }
925
926 // returns NULL if this is the last property of this class
927 wxPropertyInfo* GetNext() const { return m_next ; }
928
929 // returns the default value of this property, its kind may be wxT_VOID if it is not valid
930 wxxVariant GetDefaultValue() const { return m_defaultValue ; }
931 private :
932 void Insert(wxPropertyInfo* &iter)
933 {
934 m_next = NULL ;
935 if ( iter == NULL )
936 iter = this ;
937 else
938 {
939 wxPropertyInfo* i = iter ;
940 while( i->m_next )
941 i = i->m_next ;
942
943 i->m_next = this ;
944 }
945 }
946
947 wxString m_name ;
948 wxString m_typeName ;
949 wxString m_groupString ;
950 wxString m_helpString ;
951 const wxClassInfo* m_itsClass ;
952 wxPropertyInfoFlags m_flags ;
953 const wxTypeInfo* m_typeInfo ;
954 const wxTypeInfo* m_collectionElementTypeInfo ;
955 wxPropertyAccessor* m_accessor ;
956 wxxVariant m_defaultValue;
957 // string representation of the default value
958 // to be assigned by the designer to the property
959 // when the component is dropped on the container.
960 wxPropertyInfo* m_next ;
961 };
962
963 WX_DECLARE_EXPORTED_STRING_HASH_MAP( wxPropertyInfo* , wxPropertyInfoMap ) ;
964
965 #define WX_BEGIN_PROPERTIES_TABLE(theClass) \
966 wxPropertyInfo *theClass::GetPropertiesStatic() \
967 { \
968 typedef theClass class_t; \
969 static wxPropertyInfo* first = NULL ;
970
971 #define WX_END_PROPERTIES_TABLE() \
972 return first ; }
973
974 #define WX_HIDE_PROPERTY( name ) \
975 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (void*) NULL ) ,NULL , wxxVariant() , wxPROP_DONT_STREAM , wxEmptyString , wxEmptyString ) ;
976
977 #define WX_PROPERTY( name , type , setter , getter ,defaultValue , flags , help , group) \
978 WX_SETTER( name , class_t , type , setter ) \
979 static wxSetter##name _setter##name ; \
980 WX_GETTER( name , class_t , type , getter ) \
981 static wxGetter##name _getter##name ; \
982 static wxPropertyAccessor _accessor##name( &_setter##name , &_getter##name , NULL , NULL ) ; \
983 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) , flags , group , help ) ;
984
985 #define WX_PROPERTY_FLAGS( name , flags , type , setter , getter ,defaultValue , pflags , help , group) \
986 WX_SETTER( name , class_t , type , setter ) \
987 static wxSetter##name _setter##name ; \
988 WX_GETTER( name , class_t , type , getter ) \
989 static wxGetter##name _getter##name ; \
990 static wxPropertyAccessor _accessor##name( &_setter##name , &_getter##name , NULL , NULL ) ; \
991 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (flags*) NULL ) ,&_accessor##name , wxxVariant(defaultValue), wxPROP_ENUM_STORE_LONG | pflags , help , group ) ;
992
993 #define WX_READONLY_PROPERTY( name , type , getter ,defaultValue , flags , help , group) \
994 WX_GETTER( name , class_t , type , getter ) \
995 static wxGetter##name _getter##name ; \
996 static wxPropertyAccessor _accessor##name( NULL , &_getter##name , NULL , NULL ) ; \
997 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue), flags , help , group ) ;
998
999 #define WX_PROPERTY_COLLECTION( name , colltype , addelemtype , adder , getter , flags , help , group ) \
1000 WX_ADDER( name , class_t , addelemtype , adder ) \
1001 static wxAdder##name _adder##name ; \
1002 WX_COLLECTION_GETTER( name , class_t , colltype , getter ) \
1003 static wxCollectionGetter##name _collectionGetter##name ; \
1004 static wxPropertyAccessor _accessor##name( NULL , NULL ,&_adder##name , &_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_READONLY_PROPERTY_COLLECTION( name , colltype , addelemtype , getter , flags , help , group) \
1008 WX_COLLECTION_GETTER( name , class_t , colltype , getter ) \
1009 static wxCollectionGetter##name _collectionGetter##name ; \
1010 static wxPropertyAccessor _accessor##name( NULL , NULL , NULL , &_collectionGetter##name ) ; \
1011 static wxPropertyInfo _propertyInfo##name( first ,class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name , flags , help , group ) ;
1012 /*
1013 #define WX_PROPERTY_COLLECTION( name , colltype , addelemtype , adder , getter ) \
1014 static wxPropertyCollectionAccessorT<class_t , colltype , addelemtype > _accessor##name( &adder , &getter , #adder , #getter ) ; \
1015 static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name ) ;
1016
1017 #define WX_READONLY_PROPERTY_COLLECTION( name , colltype , addelemtype , getter ) \
1018 static wxPropertyCollectionAccessorT<class_t , colltype , addelemtype > _accessor##name( &getter , #getter ) ; \
1019 static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name ) ;
1020 */
1021
1022
1023
1024 #define WX_DELEGATE( name , eventType , eventClass ) \
1025 static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \
1026 static wxPropertyInfo _propertyInfo##name( first ,class_t::GetClassInfoStatic() , #name , &_typeInfo##name , NULL , wxxVariant() ) ; \
1027
1028 // ----------------------------------------------------------------------------
1029 // Handler Info
1030 //
1031 // this is describing an event sink
1032 // ----------------------------------------------------------------------------
1033
1034 class wxHandlerInfo
1035 {
1036 public :
1037 wxHandlerInfo(wxHandlerInfo* &iter,
1038 const wxString& name,
1039 wxObjectEventFunction address,
1040 const wxClassInfo* eventClassInfo) :
1041 m_eventFunction(address),
1042 m_name(name),
1043 m_eventClassInfo(eventClassInfo)
1044 {
1045 m_next = NULL ;
1046 if ( iter == NULL )
1047 iter = this ;
1048 else
1049 {
1050 wxHandlerInfo* i = iter ;
1051 while( i->m_next )
1052 i = i->m_next ;
1053
1054 i->m_next = this ;
1055 }
1056 }
1057
1058 ~wxHandlerInfo() ;
1059
1060 // return the name of this handler
1061 const wxString& GetName() const { return m_name ; }
1062
1063 // return the class info of the event
1064 const wxClassInfo * GetEventClassInfo() const { return m_eventClassInfo ; }
1065
1066 // get the handler function pointer
1067 wxObjectEventFunction GetEventFunction() const { return m_eventFunction ; }
1068
1069 // returns NULL if this is the last handler of this class
1070 wxHandlerInfo* GetNext() const { return m_next ; }
1071 private :
1072 wxObjectEventFunction m_eventFunction ;
1073 wxString m_name;
1074 const wxClassInfo* m_eventClassInfo ;
1075 wxHandlerInfo* m_next ;
1076 };
1077
1078 #define WX_HANDLER(name,eventClassType) \
1079 static wxHandlerInfo _handlerInfo##name( first , #name , (wxObjectEventFunction) (wxEventFunction) &name , CLASSINFO( eventClassType ) ) ;
1080
1081 #define WX_BEGIN_HANDLERS_TABLE(theClass) \
1082 wxHandlerInfo *theClass::GetHandlersStatic() \
1083 { \
1084 typedef theClass class_t; \
1085 static wxHandlerInfo* first = NULL ;
1086
1087 #define WX_END_HANDLERS_TABLE() \
1088 return first ; }
1089
1090 // ----------------------------------------------------------------------------
1091 // Constructor Bridges
1092 //
1093 // allow to set up constructors with params during runtime
1094 // ----------------------------------------------------------------------------
1095
1096 class WXDLLIMPEXP_BASE wxConstructorBridge
1097 {
1098 public :
1099 virtual void Create(wxObject *o, wxxVariant *args) = 0;
1100 };
1101
1102 // Creator Bridges for all Numbers of Params
1103
1104 // no params
1105
1106 template<typename Class>
1107 struct wxConstructorBridge_0 : public wxConstructorBridge
1108 {
1109 void Create(wxObject *o, wxxVariant *)
1110 {
1111 Class *obj = dynamic_cast<Class*>(o);
1112 obj->Create();
1113 }
1114 };
1115
1116 struct wxConstructorBridge_Dummy : public wxConstructorBridge
1117 {
1118 void Create(wxObject *, wxxVariant *)
1119 {
1120 }
1121 } ;
1122
1123 #define WX_CONSTRUCTOR_0(klass) \
1124 wxConstructorBridge_0<klass> constructor##klass ; \
1125 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1126 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
1127 const int klass::sm_constructorPropertiesCount##klass = 0 ;
1128
1129 #define WX_CONSTRUCTOR_DUMMY(klass) \
1130 wxConstructorBridge_Dummy constructor##klass ; \
1131 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1132 const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \
1133 const int klass::sm_constructorPropertiesCount##klass = 0 ;
1134
1135 // 1 param
1136
1137 template<typename Class, typename T0>
1138 struct wxConstructorBridge_1 : public wxConstructorBridge
1139 {
1140 void Create(wxObject *o, wxxVariant *args)
1141 {
1142 Class *obj = dynamic_cast<Class*>(o);
1143 obj->Create(
1144 args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0)
1145 );
1146 }
1147 };
1148
1149 #define WX_CONSTRUCTOR_1(klass,t0,v0) \
1150 wxConstructorBridge_1<klass,t0> constructor##klass ; \
1151 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1152 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 } ; \
1153 const int klass::sm_constructorPropertiesCount##klass = 1 ;
1154
1155 // 2 params
1156
1157 template<typename Class,
1158 typename T0, typename T1>
1159 struct wxConstructorBridge_2 : public wxConstructorBridge
1160 {
1161 void Create(wxObject *o, wxxVariant *args)
1162 {
1163 Class *obj = dynamic_cast<Class*>(o);
1164 obj->Create(
1165 args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) ,
1166 args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1)
1167 );
1168 }
1169 };
1170
1171 #define WX_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
1172 wxConstructorBridge_2<klass,t0,t1> constructor##klass ; \
1173 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1174 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 } ; \
1175 const int klass::sm_constructorPropertiesCount##klass = 2;
1176
1177 // 3 params
1178
1179 template<typename Class,
1180 typename T0, typename T1, typename T2>
1181 struct wxConstructorBridge_3 : public wxConstructorBridge
1182 {
1183 void Create(wxObject *o, wxxVariant *args)
1184 {
1185 Class *obj = dynamic_cast<Class*>(o);
1186 obj->Create(
1187 args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) ,
1188 args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) ,
1189 args[2].WX_TEMPLATED_MEMBER_CALL(Get , T2)
1190 );
1191 }
1192 };
1193
1194 #define WX_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
1195 wxConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \
1196 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1197 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 } ; \
1198 const int klass::sm_constructorPropertiesCount##klass = 3 ;
1199
1200 // 4 params
1201
1202 template<typename Class,
1203 typename T0, typename T1, typename T2, typename T3>
1204 struct wxConstructorBridge_4 : public wxConstructorBridge
1205 {
1206 void Create(wxObject *o, wxxVariant *args)
1207 {
1208 Class *obj = dynamic_cast<Class*>(o);
1209 obj->Create(
1210 args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) ,
1211 args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) ,
1212 args[2].WX_TEMPLATED_MEMBER_CALL(Get , T2) ,
1213 args[3].WX_TEMPLATED_MEMBER_CALL(Get , T3)
1214 );
1215 }
1216 };
1217
1218 #define WX_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
1219 wxConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass ; \
1220 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1221 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 } ; \
1222 const int klass::sm_constructorPropertiesCount##klass = 4 ;
1223
1224 // 5 params
1225
1226 template<typename Class,
1227 typename T0, typename T1, typename T2, typename T3, typename T4>
1228 struct wxConstructorBridge_5 : public wxConstructorBridge
1229 {
1230 void Create(wxObject *o, wxxVariant *args)
1231 {
1232 Class *obj = dynamic_cast<Class*>(o);
1233 obj->Create(
1234 args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) ,
1235 args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) ,
1236 args[2].WX_TEMPLATED_MEMBER_CALL(Get , T2) ,
1237 args[3].WX_TEMPLATED_MEMBER_CALL(Get , T3) ,
1238 args[4].WX_TEMPLATED_MEMBER_CALL(Get , T4)
1239 );
1240 }
1241 };
1242
1243 #define WX_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
1244 wxConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass ; \
1245 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1246 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 } ; \
1247 const int klass::sm_constructorPropertiesCount##klass = 5;
1248
1249 // 6 params
1250
1251 template<typename Class,
1252 typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
1253 struct wxConstructorBridge_6 : public wxConstructorBridge
1254 {
1255 void Create(wxObject *o, wxxVariant *args)
1256 {
1257 Class *obj = dynamic_cast<Class*>(o);
1258 obj->Create(
1259 args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) ,
1260 args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) ,
1261 args[2].WX_TEMPLATED_MEMBER_CALL(Get , T2) ,
1262 args[3].WX_TEMPLATED_MEMBER_CALL(Get , T3) ,
1263 args[4].WX_TEMPLATED_MEMBER_CALL(Get , T4) ,
1264 args[5].WX_TEMPLATED_MEMBER_CALL(Get , T5)
1265 );
1266 }
1267 };
1268
1269 template<typename Class,
1270 typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
1271 struct wxDirectConstructorBridge_6 : public wxConstructorBridge
1272 {
1273 void Create(wxObject *o, wxxVariant *args)
1274 {
1275 Class *obj = new Class(
1276 args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) ,
1277 args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) ,
1278 args[2].WX_TEMPLATED_MEMBER_CALL(Get , T2) ,
1279 args[3].WX_TEMPLATED_MEMBER_CALL(Get , T3) ,
1280 args[4].WX_TEMPLATED_MEMBER_CALL(Get , T4) ,
1281 args[5].WX_TEMPLATED_MEMBER_CALL(Get , T5)
1282 );
1283 }
1284 };
1285
1286 #define WX_DIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1287 wxDirectConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1288 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1289 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 } ; \
1290 const int klass::sm_constructorPropertiesCount##klass = 6;
1291
1292 #define WX_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
1293 wxConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
1294 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1295 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 } ; \
1296 const int klass::sm_constructorPropertiesCount##klass = 6;
1297
1298 // 7 params
1299
1300 template<typename Class,
1301 typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
1302 struct wxConstructorBridge_7 : public wxConstructorBridge
1303 {
1304 void Create(wxObject *o, wxxVariant *args)
1305 {
1306 Class *obj = dynamic_cast<Class*>(o);
1307 obj->Create(
1308 args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) ,
1309 args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) ,
1310 args[2].WX_TEMPLATED_MEMBER_CALL(Get , T2) ,
1311 args[3].WX_TEMPLATED_MEMBER_CALL(Get , T3) ,
1312 args[4].WX_TEMPLATED_MEMBER_CALL(Get , T4) ,
1313 args[5].WX_TEMPLATED_MEMBER_CALL(Get , T5) ,
1314 args[6].WX_TEMPLATED_MEMBER_CALL(Get , T6)
1315 );
1316 }
1317 };
1318
1319 #define WX_CONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
1320 wxConstructorBridge_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass ; \
1321 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1322 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 , #v6} ; \
1323 const int klass::sm_constructorPropertiesCount##klass = 7;
1324
1325 // 8 params
1326
1327 template<typename Class,
1328 typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
1329 struct wxConstructorBridge_8 : public wxConstructorBridge
1330 {
1331 void Create(wxObject *o, wxxVariant *args)
1332 {
1333 Class *obj = dynamic_cast<Class*>(o);
1334 obj->Create(
1335 args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) ,
1336 args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) ,
1337 args[2].WX_TEMPLATED_MEMBER_CALL(Get , T2) ,
1338 args[3].WX_TEMPLATED_MEMBER_CALL(Get , T3) ,
1339 args[4].WX_TEMPLATED_MEMBER_CALL(Get , T4) ,
1340 args[5].WX_TEMPLATED_MEMBER_CALL(Get , T5) ,
1341 args[6].WX_TEMPLATED_MEMBER_CALL(Get , T6) ,
1342 args[7].WX_TEMPLATED_MEMBER_CALL(Get , T7)
1343 );
1344 }
1345 };
1346
1347 #define WX_CONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
1348 wxConstructorBridge_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass ; \
1349 wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \
1350 const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 , #v6 , #v7} ; \
1351 const int klass::sm_constructorPropertiesCount##klass = 8;
1352 // ----------------------------------------------------------------------------
1353 // wxClassInfo
1354 // ----------------------------------------------------------------------------
1355
1356 typedef wxObject *(*wxObjectConstructorFn)(void);
1357 typedef wxObject* (*wxVariantToObjectConverter)( wxxVariant &data ) ;
1358 typedef wxxVariant (*wxObjectToVariantConverter)( wxObject* ) ;
1359 class wxWriter ;
1360 class wxPersister ;
1361 typedef bool (*wxObjectStreamingCallback) ( const wxObject *, wxWriter * , wxPersister * , wxxVariantArray & ) ;
1362
1363 class WXDLLIMPEXP_BASE wxClassInfo
1364 {
1365 friend class WXDLLEXPORT wxPropertyInfo ;
1366 friend class WXDLLEXPORT wxHandlerInfo ;
1367 public:
1368 wxClassInfo(const wxClassInfo **_Parents,
1369 const wxChar *_UnitName,
1370 const wxChar *_ClassName,
1371 int size,
1372 wxObjectConstructorFn ctor ,
1373 wxPropertyInfo *_Props ,
1374 wxHandlerInfo *_Handlers ,
1375 wxConstructorBridge* _Constructor ,
1376 const wxChar ** _ConstructorProperties ,
1377 const int _ConstructorPropertiesCount ,
1378 wxVariantToObjectConverter _PtrConverter1 ,
1379 wxVariantToObjectConverter _Converter2 ,
1380 wxObjectToVariantConverter _Converter3 ,
1381 wxObjectStreamingCallback _streamingCallback = NULL
1382 ) :
1383
1384 m_className(_ClassName),
1385 m_objectSize(size),
1386 m_objectConstructor(ctor),
1387 m_next(sm_first),
1388 m_firstProperty(_Props),
1389 m_firstHandler(_Handlers),
1390 m_parents(_Parents),
1391 m_unitName(_UnitName),
1392 m_constructor(_Constructor),
1393 m_constructorProperties(_ConstructorProperties),
1394 m_constructorPropertiesCount(_ConstructorPropertiesCount),
1395 m_variantOfPtrToObjectConverter(_PtrConverter1),
1396 m_variantToObjectConverter(_Converter2),
1397 m_objectToVariantConverter(_Converter3),
1398 m_streamingCallback(_streamingCallback)
1399 {
1400 sm_first = this;
1401 Register() ;
1402 }
1403
1404 wxClassInfo(const wxChar *_UnitName, const wxChar *_ClassName,
1405 const wxClassInfo **_Parents) :
1406 m_className(_ClassName),
1407 m_objectSize(0),
1408 m_objectConstructor(NULL),
1409 m_next(sm_first),
1410 m_firstProperty(NULL),
1411 m_firstHandler(NULL),
1412 m_parents(_Parents),
1413 m_unitName(_UnitName),
1414 m_constructor(NULL),
1415 m_constructorProperties(NULL),
1416 m_constructorPropertiesCount(0),
1417 m_variantOfPtrToObjectConverter(NULL),
1418 m_variantToObjectConverter(NULL),
1419 m_objectToVariantConverter(NULL),
1420 m_streamingCallback(NULL)
1421 {
1422 sm_first = this;
1423 Register() ;
1424 }
1425
1426 virtual ~wxClassInfo() ;
1427
1428 // allocates an instance of this class, this object does not have to be initialized or fully constructed
1429 // as this call will be followed by a call to Create
1430 virtual wxObject *AllocateObject() const { return m_objectConstructor ? (*m_objectConstructor)() : 0; }
1431
1432 // 'old naming' for AllocateObject staying here for backward compatibility
1433 wxObject *CreateObject() const { return AllocateObject() ; }
1434
1435 const wxChar *GetClassName() const { return m_className; }
1436 const wxChar *GetIncludeName() const { return m_unitName ; }
1437 const wxClassInfo **GetParents() const { return m_parents; }
1438 int GetSize() const { return m_objectSize; }
1439
1440 wxObjectConstructorFn GetConstructor() const { return m_objectConstructor; }
1441 static const wxClassInfo *GetFirst() { return sm_first; }
1442 const wxClassInfo *GetNext() const { return m_next; }
1443 static wxClassInfo *FindClass(const wxChar *className);
1444
1445 // Climb upwards through inheritance hierarchy.
1446 // Dual inheritance is catered for.
1447
1448 bool IsKindOf(const wxClassInfo *info) const
1449 {
1450 if ( info != 0 )
1451 {
1452 if ( info == this )
1453 return true ;
1454
1455 for ( int i = 0 ; m_parents[i] ; ++ i )
1456 {
1457 if ( m_parents[i]->IsKindOf( info ) )
1458 return true ;
1459 }
1460 }
1461 return false ;
1462 }
1463
1464 // if there is a callback registered with that class it will be called
1465 // before this object will be written to disk, it can veto streaming out
1466 // this object by returning false, if this class has not registered a
1467 // callback, the search will go up the inheritance tree if no callback has
1468 // been registered true will be returned by default
1469 bool BeforeWriteObject( const wxObject *obj, wxWriter *streamer , wxPersister *persister , wxxVariantArray &metadata) const ;
1470
1471 // gets the streaming callback from this class or any superclass
1472 wxObjectStreamingCallback GetStreamingCallback() const ;
1473
1474 #ifdef WXWIN_COMPATIBILITY_2_4
1475 // Initializes parent pointers and hash table for fast searching.
1476 wxDEPRECATED( static void InitializeClasses() );
1477 // Cleans up hash table used for fast searching.
1478 wxDEPRECATED( static void CleanUpClasses() );
1479 #endif
1480 static void CleanUp();
1481
1482 // returns the first property
1483 const wxPropertyInfo* GetFirstProperty() const { return m_firstProperty ; }
1484
1485 // returns the first handler
1486 const wxHandlerInfo* GetFirstHandler() const { return m_firstHandler ; }
1487
1488 // Call the Create upon an instance of the class, in the end the object is fully
1489 // initialized
1490 virtual void Create (wxObject *object, int ParamCount, wxxVariant *Params) const
1491 {
1492 wxASSERT_MSG( ParamCount == m_constructorPropertiesCount , wxT("Illegal Parameter Count for Create Method")) ;
1493 m_constructor->Create( object , Params ) ;
1494 }
1495
1496 // get number of parameters for constructor
1497 virtual int GetCreateParamCount() const { return m_constructorPropertiesCount; }
1498
1499 // get n-th constructor parameter
1500 virtual const wxChar* GetCreateParamName(int n) const { return m_constructorProperties[n] ; }
1501
1502 // Runtime access to objects for simple properties (get/set) by property name, and variant data
1503 virtual void SetProperty (wxObject *object, const wxChar *propertyName, const wxxVariant &value) const ;
1504 virtual wxxVariant GetProperty (wxObject *object, const wxChar *propertyName) const;
1505
1506 // Runtime access to objects for collection properties by property name
1507 virtual wxxVariantArray GetPropertyCollection(wxObject *object, const wxChar *propertyName) const ;
1508 virtual void AddToPropertyCollection(wxObject *object, const wxChar *propertyName , const wxxVariant& value) const ;
1509
1510 // we must be able to cast variants to wxObject pointers, templates seem not to be suitable
1511 wxObject* VariantToInstance( wxxVariant &data ) const
1512 { if ( data.GetTypeInfo()->GetKind() == wxT_OBJECT )
1513 return m_variantToObjectConverter( data ) ;
1514 else
1515 return m_variantOfPtrToObjectConverter( data ) ;
1516 }
1517
1518 wxxVariant InstanceToVariant( wxObject *object ) const { return m_objectToVariantConverter( object ) ; }
1519
1520 // find property by name
1521 virtual const wxPropertyInfo *FindPropertyInfo (const wxChar *PropertyName) const ;
1522
1523 // find handler by name
1524 virtual const wxHandlerInfo *FindHandlerInfo (const wxChar *PropertyName) const ;
1525
1526 // find property by name
1527 virtual const wxPropertyInfo *FindPropertyInfoInThisClass (const wxChar *PropertyName) const ;
1528
1529 // find handler by name
1530 virtual const wxHandlerInfo *FindHandlerInfoInThisClass (const wxChar *PropertyName) const ;
1531
1532 // puts all the properties of this class and its superclasses in the map, as long as there is not yet
1533 // an entry with the same name (overriding mechanism)
1534 void GetProperties( wxPropertyInfoMap &map ) const ;
1535 public:
1536 const wxChar *m_className;
1537 int m_objectSize;
1538 wxObjectConstructorFn m_objectConstructor;
1539
1540 // class info object live in a linked list:
1541 // pointers to its head and the next element in it
1542
1543 static wxClassInfo *sm_first;
1544 wxClassInfo *m_next;
1545
1546 // FIXME: this should be private (currently used directly by way too
1547 // many clients)
1548 static wxHashTable *sm_classTable;
1549
1550 protected :
1551 wxPropertyInfo * m_firstProperty ;
1552 wxHandlerInfo * m_firstHandler ;
1553 private:
1554 const wxClassInfo** m_parents ;
1555 const wxChar* m_unitName;
1556
1557 wxConstructorBridge* m_constructor ;
1558 const wxChar ** m_constructorProperties ;
1559 const int m_constructorPropertiesCount ;
1560 wxVariantToObjectConverter m_variantOfPtrToObjectConverter ;
1561 wxVariantToObjectConverter m_variantToObjectConverter ;
1562 wxObjectToVariantConverter m_objectToVariantConverter ;
1563 wxObjectStreamingCallback m_streamingCallback ;
1564 const wxPropertyAccessor *FindAccessor (const wxChar *propertyName) const ;
1565
1566
1567 // InitializeClasses() helper
1568 static wxClassInfo *GetBaseByName(const wxChar *name) ;
1569
1570 protected:
1571 // registers the class
1572 void Register();
1573 void Unregister();
1574
1575 DECLARE_NO_COPY_CLASS(wxClassInfo)
1576 };
1577
1578
1579 WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name);
1580
1581 // ----------------------------------------------------------------------------
1582 // wxDynamicObject
1583 // ----------------------------------------------------------------------------
1584 //
1585 // this object leads to having a pure runtime-instantiation
1586
1587 class wxDynamicClassInfo : public wxClassInfo
1588 {
1589 public :
1590 wxDynamicClassInfo( const wxChar *_UnitName, const wxChar *_ClassName , const wxClassInfo* superClass ) ;
1591 virtual ~wxDynamicClassInfo() ;
1592
1593 // constructs a wxDynamicObject with an instance
1594 virtual wxObject *AllocateObject() const ;
1595
1596 // Call the Create method for a class
1597 virtual void Create (wxObject *object, int ParamCount, wxxVariant *Params) const ;
1598
1599 // get number of parameters for constructor
1600 virtual int GetCreateParamCount() const ;
1601
1602 // get i-th constructor parameter
1603 virtual const wxChar* GetCreateParamName(int i) const ;
1604
1605 // Runtime access to objects by property name, and variant data
1606 virtual void SetProperty (wxObject *object, const wxChar *PropertyName, const wxxVariant &Value) const ;
1607 virtual wxxVariant GetProperty (wxObject *object, const wxChar *PropertyName) const ;
1608
1609 // adds a property to this class at runtime
1610 void AddProperty( const wxChar *propertyName , const wxTypeInfo* typeInfo ) ;
1611
1612 // removes an existing runtime-property
1613 void RemoveProperty( const wxChar *propertyName ) ;
1614
1615 // as a handler to this class at runtime
1616 void AddHandler( const wxChar *handlerName , wxObjectEventFunction address , const wxClassInfo* eventClassInfo ) ;
1617
1618 // removes an existing runtime-handler
1619 void RemoveHandler( const wxChar *handlerName ) ;
1620 } ;
1621
1622 // ----------------------------------------------------------------------------
1623 // Dynamic class macros
1624 // ----------------------------------------------------------------------------
1625
1626 #define _DECLARE_DYNAMIC_CLASS(name) \
1627 public: \
1628 static wxClassInfo sm_class##name; \
1629 static const wxClassInfo* sm_classParents##name[] ; \
1630 static wxPropertyInfo* GetPropertiesStatic() ; \
1631 static wxHandlerInfo* GetHandlersStatic() ; \
1632 static wxClassInfo *GetClassInfoStatic() \
1633 { return &name::sm_class##name; } \
1634 virtual wxClassInfo *GetClassInfo() const \
1635 { return &name::sm_class##name; }
1636
1637 #define DECLARE_DYNAMIC_CLASS(name) \
1638 static wxConstructorBridge* sm_constructor##name ; \
1639 static const wxChar * sm_constructorProperties##name[] ; \
1640 static const int sm_constructorPropertiesCount##name ; \
1641 _DECLARE_DYNAMIC_CLASS(name)
1642
1643 #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
1644 DECLARE_NO_ASSIGN_CLASS(name) \
1645 DECLARE_DYNAMIC_CLASS(name)
1646
1647 #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \
1648 DECLARE_NO_COPY_CLASS(name) \
1649 DECLARE_DYNAMIC_CLASS(name)
1650
1651 #define DECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name)
1652 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
1653
1654 // -----------------------------------
1655 // for concrete classes
1656 // -----------------------------------
1657
1658 // Single inheritance with one base class
1659
1660 #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit , callback) \
1661 wxObject* wxConstructorFor##name() \
1662 { return new name; } \
1663 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1664 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1665 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1666 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1667 (int) sizeof(name), \
1668 (wxObjectConstructorFn) wxConstructorFor##name , \
1669 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1670 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name , callback); \
1671 template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1672 template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1673 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1674 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1675 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1676 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1677 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
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
1681 #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \
1682 wxObject* wxConstructorFor##name() \
1683 { return new name; } \
1684 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1685 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return &data.Get<name>() ; } \
1686 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1687 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1688 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1689 (int) sizeof(name), \
1690 (wxObjectConstructorFn) wxConstructorFor##name , \
1691 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1692 name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name, callback); \
1693 template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1694 template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1695 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
1696 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1697 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1698 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1699 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1700 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1701 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1702
1703 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \
1704 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" , NULL ) \
1705 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1706 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1707 WX_CONSTRUCTOR_DUMMY( name )
1708
1709 #define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \
1710 _IMPLEMENT_DYNAMIC_CLASS( name , basename , "" , NULL ) \
1711 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1712 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1713 WX_CONSTRUCTOR_DUMMY( name )
1714
1715 #define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \
1716 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , NULL )
1717
1718 #define IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name , basename , unit , callback ) \
1719 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , &callback )
1720
1721 #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \
1722 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit , NULL )
1723
1724 // this is for classes that do not derive from wxobject, there are no creators for these
1725
1726 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name , unit ) \
1727 const wxClassInfo* name::sm_classParents##name[] = { NULL } ; \
1728 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1729 (int) sizeof(name), \
1730 (wxObjectConstructorFn) 0 , \
1731 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1732 0 , 0 , 0 ); \
1733 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1734 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1735 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1736 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1737 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1738 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1739 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1740
1741 // this is for subclasses that still do not derive from wxobject
1742
1743 #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name , basename, unit ) \
1744 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1745 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1746 (int) sizeof(name), \
1747 (wxObjectConstructorFn) 0 , \
1748 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1749 0 , 0 , 0 ); \
1750 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1751 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1752 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1753 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1754 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1755 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1756 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1757
1758
1759 // Multiple inheritance with two base classes
1760
1761 #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit) \
1762 wxObject* wxConstructorFor##name() \
1763 { return new name; } \
1764 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,&basename2::sm_class##basename2 , NULL } ; \
1765 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1766 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1767 wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \
1768 (int) sizeof(name), \
1769 (wxObjectConstructorFn) wxConstructorFor##name , \
1770 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
1771 name::sm_constructorPropertiesCount##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1772 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1773 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1774 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1775 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1776 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \
1777 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1778 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
1779
1780 #define IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2) \
1781 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , "") \
1782 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1783 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1784 WX_CONSTRUCTOR_DUMMY( name )
1785
1786 #define IMPLEMENT_DYNAMIC_CLASS2_XTI( name , basename , basename2, unit) \
1787 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , unit)
1788
1789 // -----------------------------------
1790 // for abstract classes
1791 // -----------------------------------
1792
1793 // Single inheritance with one base class
1794
1795 #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
1796 const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
1797 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1798 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \
1799 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
1800 wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \
1801 (int) sizeof(name), \
1802 (wxObjectConstructorFn) 0 , \
1803 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1804 0 , wxVariantOfPtrToObjectConverter##name ,wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
1805 template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1806 template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1807 template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1808 template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
1809 template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
1810 template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } \
1811 template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID) ; assert(0) ; return &s_typeInfo ; }
1812
1813 #define IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1814 _IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
1815 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
1816 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; }
1817
1818 // Multiple inheritance with two base classes
1819
1820 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
1821 wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \
1822 wxT(#basename2), (int) sizeof(name), \
1823 (wxObjectConstructorFn) 0);
1824
1825 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
1826 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
1827
1828 // --------------------------------------------------------------------------
1829 // Collection Support
1830 // --------------------------------------------------------------------------
1831
1832 template<typename iter , typename collection_t > void wxListCollectionToVariantArray( const collection_t& coll , wxxVariantArray &value )
1833 {
1834 iter current = coll.GetFirst() ;
1835 while (current)
1836 {
1837 value.Add( new wxxVariant(current->GetData()) ) ;
1838 current = current->GetNext();
1839 }
1840 }
1841
1842 template<typename collection_t> void wxArrayCollectionToVariantArray( const collection_t& coll , wxxVariantArray &value )
1843 {
1844 for( size_t i = 0 ; i < coll.GetCount() ; i++ )
1845 {
1846 value.Add( new wxxVariant(coll[i]) ) ;
1847 }
1848 }
1849
1850
1851 #endif