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