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