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