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