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