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