]> git.saurik.com Git - wxWidgets.git/blame - include/wx/xti.h
don't pass NULL pointer to printf(), this crashes Solaris printf
[wxWidgets.git] / include / wx / xti.h
CommitLineData
a095505c 1/////////////////////////////////////////////////////////////////////////////
bb7eff4c 2// Name: wx/xti.h
a095505c
SC
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
65571936 10// Licence: wxWindows licence
a095505c
SC
11/////////////////////////////////////////////////////////////////////////////
12
13#ifndef _WX_XTIH__
14#define _WX_XTIH__
15
12028905 16#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
a095505c
SC
17#pragma interface "xti.h"
18#endif
19
20// We want to support properties, event sources and events sinks through
21// explicit declarations, using templates and specialization to make the
4393b50c 22// effort as painless as possible.
a095505c
SC
23//
24// This means we have the following domains :
25//
26// - Type Information for categorizing built in types as well as custom types
27// this includes information about enums, their values and names
28// - Type safe value storage : a kind of wxVariant, called right now wxxVariant
4393b50c 29// which will be merged with wxVariant
a095505c
SC
30// - Property Information and Property Accessors providing access to a class'
31// values and exposed event delegates
32// - Information about event handlers
33// - extended Class Information for accessing all these
34
35// ----------------------------------------------------------------------------
36// headers
37// ----------------------------------------------------------------------------
38
39#include "wx/defs.h"
40#include "wx/memory.h"
ae820c69 41#include "wx/flags.h"
a095505c 42#include "wx/string.h"
aeec2045 43#include "wx/arrstr.h"
ae820c69 44#include "wx/hashmap.h"
8f2b1cfd
SC
45#include "wx/log.h"
46#include "wx/intl.h"
a095505c 47
1b23f6f7 48#include <typeinfo>
492f9a9e 49
2abce515
SC
50// we will move this later to defs.h
51
af498247 52#if defined(__GNUC__) && !wxCHECK_GCC_VERSION( 3 , 4 )
2abce515
SC
53# define wxUSE_MEMBER_TEMPLATES 0
54#endif
55
af498247
VZ
56#if defined(_MSC_VER) && _MSC_VER <= 1200
57# define wxUSE_MEMBER_TEMPLATES 0
58# define wxUSE_FUNC_TEMPLATE_POINTER 0
2abce515
SC
59#endif
60
61#ifndef wxUSE_MEMBER_TEMPLATES
af498247
VZ
62# define wxUSE_MEMBER_TEMPLATES 1
63#endif
64
65#ifndef wxUSE_FUNC_TEMPLATE_POINTER
66# define wxUSE_FUNC_TEMPLATE_POINTER 1
2abce515
SC
67#endif
68
69#if wxUSE_MEMBER_TEMPLATES
af498247
VZ
70# define wxTEMPLATED_MEMBER_CALL( method , type ) method<type>()
71# define wxTEMPLATED_MEMBER_FIX( type )
2abce515 72#else
af498247
VZ
73# define wxTEMPLATED_MEMBER_CALL( method , type ) method((type*)NULL)
74# define wxTEMPLATED_MEMBER_FIX( type ) type* =NULL
2abce515
SC
75#endif
76
af498247
VZ
77#if defined(_MSC_VER) && _MSC_VER <= 1200
78# define wxTEMPLATED_FUNCTION_FIX( type ) , wxTEMPLATED_MEMBER_FIX(type)
79# define wxINFUNC_CLASS_TYPE_FIX( type ) typedef type type;
80#else
81# define wxTEMPLATED_FUNCTION_FIX( type )
82# define wxINFUNC_CLASS_TYPE_FIX( type )
83#endif
84
85#define EMPTY_MACROVALUE /**/
86
a095505c
SC
87class WXDLLIMPEXP_BASE wxObject;
88class WXDLLIMPEXP_BASE wxClassInfo;
492f9a9e 89class WXDLLIMPEXP_BASE wxDynamicClassInfo;
a095505c
SC
90class WXDLLIMPEXP_BASE wxHashTable;
91class WXDLLIMPEXP_BASE wxObjectRefData;
92class WXDLLIMPEXP_BASE wxEvent;
432968bf 93class WXDLLIMPEXP_BASE wxEvtHandler;
a095505c 94
395b5a76 95typedef void (wxObject::*wxObjectEventFunction)(wxEvent&);
a095505c 96
af498247 97#if wxUSE_FUNC_TEMPLATE_POINTER
cab1a605 98# define wxTO_STRING(type) wxToStringConverter<type>
af498247
VZ
99# define wxTO_STRING_IMP(type)
100# define wxFROM_STRING(type) wxFromStringConverter<type>
101# define wxFROM_STRING_IMP(type)
102#else
103# define wxTO_STRING(type) ToString##type
104# define wxTO_STRING_IMP(type) inline void ToString##type( const wxxVariant& data , wxString &result ) { wxToStringConverter<type>(data, result); }
105# define wxFROM_STRING(type) FromString##type
106# define wxFROM_STRING_IMP(type) inline void FromString##type( const wxString& data , wxxVariant &result ) { wxFromStringConverter<type>(data, result); }
107#endif
108
a095505c
SC
109// ----------------------------------------------------------------------------
110// Enum Support
111//
4393b50c 112// In the header files there would no change from pure c++ code, in the
a095505c
SC
113// implementation, an enum would have
114// to be enumerated eg :
115//
9dabddc2
SC
116// wxBEGIN_ENUM( wxFlavor )
117// wxENUM_MEMBER( Vanilla )
118// wxENUM_MEMBER( Chocolate )
119// wxENUM_MEMBER( Strawberry )
120// wxEND_ENUM( wxFlavor )
a095505c
SC
121// ----------------------------------------------------------------------------
122
123struct WXDLLIMPEXP_BASE wxEnumMemberData
124{
517fb871
VS
125 const wxChar* m_name;
126 int m_value;
a095505c
SC
127};
128
129class WXDLLIMPEXP_BASE wxEnumData
130{
131public :
517fb871 132 wxEnumData( wxEnumMemberData* data ) ;
a095505c 133
517fb871
VS
134 // returns true if the member has been found and sets the int value
135 // pointed to accordingly (if ptr != null )
136 // if not found returns false, value left unchanged
25474dca 137 bool HasEnumMemberValue( const wxChar *name , int *value = NULL ) const ;
4393b50c 138
517fb871
VS
139 // returns the value of the member, if not found in debug mode an
140 // assert is issued, in release 0 is returned
25474dca 141 int GetEnumMemberValue(const wxChar *name ) const ;
4393b50c 142
517fb871
VS
143 // returns the name of the enum member having the passed in value
144 // returns an emtpy string if not found
25474dca 145 const wxChar *GetEnumMemberName(int value) const ;
4393b50c 146
517fb871 147 // returns the number of members in this enum
25474dca 148 int GetEnumCount() const { return m_count ; }
4393b50c 149
517fb871 150 // returns the value of the nth member
25474dca 151 int GetEnumMemberValueByIndex( int n ) const ;
4393b50c 152
517fb871 153 // returns the value of the nth member
25474dca 154 const wxChar *GetEnumMemberNameByIndex( int n ) const ;
a095505c
SC
155private :
156 wxEnumMemberData *m_members;
517fb871 157 int m_count ;
a095505c
SC
158};
159
9dabddc2 160#define wxBEGIN_ENUM( e ) \
517fb871 161 wxEnumMemberData s_enumDataMembers##e[] = {
a095505c 162
9dabddc2 163#define wxENUM_MEMBER( v ) { wxT(#v), v } ,
a095505c 164
9dabddc2 165#define wxEND_ENUM( e ) { NULL , 0 } } ; \
517fb871
VS
166 wxEnumData s_enumData##e( s_enumDataMembers##e ) ; \
167 wxEnumData *wxGetEnumData(e) { return &s_enumData##e ; } \
492f9a9e 168 template<> void wxStringReadValue(const wxString& s , e &data ) \
ae820c69
SC
169{ \
170 data = (e) s_enumData##e.GetEnumMemberValue(s) ; \
171} \
492f9a9e 172 template<> void wxStringWriteValue(wxString &s , const e &data ) \
ae820c69
SC
173{ \
174 s = s_enumData##e.GetEnumMemberName((int)data) ; \
175} \
176 void FromLong##e( long data , wxxVariant& result ) { result = wxxVariant((e)data) ;} \
2c4c3987 177 void ToLong##e( const wxxVariant& data , long &result ) { result = (long) data.wxTEMPLATED_MEMBER_CALL(Get , e) ;} \
af498247
VZ
178 wxTO_STRING_IMP( e ) \
179 wxFROM_STRING_IMP( e ) \
180 wxEnumTypeInfo s_typeInfo##e(wxT_ENUM , &s_enumData##e , &wxTO_STRING( e ) , &wxFROM_STRING( e ) , &ToLong##e , &FromLong##e , typeid(e).name() ) ;
a095505c
SC
181
182// ----------------------------------------------------------------------------
183// Set Support
4393b50c 184//
a095505c 185// in the header :
4393b50c 186//
a095505c 187// enum wxFlavor
4393b50c 188// {
517fb871
VS
189// Vanilla,
190// Chocolate,
191// Strawberry,
a095505c 192// };
4393b50c 193//
0886e254 194// typedef wxBitset<wxFlavor> wxCoupe ;
4393b50c 195//
a095505c 196// in the implementation file :
4393b50c 197//
9dabddc2
SC
198// wxBEGIN_ENUM( wxFlavor )
199// wxENUM_MEMBER( Vanilla )
200// wxENUM_MEMBER( Chocolate )
201// wxENUM_MEMBER( Strawberry )
202// wxEND_ENUM( wxFlavor )
a095505c 203//
9dabddc2 204// wxIMPLEMENT_SET_STREAMING( wxCoupe , wxFlavor )
4393b50c
SC
205//
206// implementation note : no partial specialization for streaming, but a delegation to a
a095505c
SC
207// different class
208//
209// ----------------------------------------------------------------------------
210
211// in order to remove dependancy on string tokenizer
1ab608ee 212void WXDLLIMPEXP_BASE wxSetStringToArray( const wxString &s , wxArrayString &array ) ;
a095505c
SC
213
214template<typename e>
0886e254 215void wxSetFromString(const wxString &s , wxBitset<e> &data )
a095505c 216{
517fb871 217 wxEnumData* edata = wxGetEnumData((e) 0) ;
9c8046dd 218 data.reset() ;
a095505c 219
517fb871
VS
220 wxArrayString array ;
221 wxSetStringToArray( s , array ) ;
a095505c
SC
222 wxString flag;
223 for ( int i = 0 ; i < array.Count() ; ++i )
224 {
225 flag = array[i] ;
517fb871
VS
226 int ivalue ;
227 if ( edata->HasEnumMemberValue( flag , &ivalue ) )
228 {
9c8046dd 229 data.set( (e) ivalue ) ;
517fb871 230 }
a095505c
SC
231 }
232}
233
234template<typename e>
0886e254 235void wxSetToString( wxString &s , const wxBitset<e> &data )
a095505c 236{
517fb871
VS
237 wxEnumData* edata = wxGetEnumData((e) 0) ;
238 int count = edata->GetEnumCount() ;
239 int i ;
240 s.Clear() ;
241 for ( i = 0 ; i < count ; i++ )
242 {
243 e value = (e) edata->GetEnumMemberValueByIndex(i) ;
9c8046dd 244 if ( data.test( value ) )
517fb871
VS
245 {
246 // this could also be done by the templated calls
432968bf 247 if ( !s.empty() )
583150e3 248 s +=wxT("|") ;
517fb871
VS
249 s += edata->GetEnumMemberNameByIndex(i) ;
250 }
251 }
a095505c
SC
252}
253
9dabddc2 254#define wxIMPLEMENT_SET_STREAMING(SetName,e) \
492f9a9e 255 template<> void wxStringReadValue(const wxString &s , wxBitset<e> &data ) \
ae820c69
SC
256{ \
257 wxSetFromString( s , data ) ; \
258} \
492f9a9e 259 template<> void wxStringWriteValue( wxString &s , const wxBitset<e> &data ) \
ae820c69
SC
260{ \
261 wxSetToString( s , data ) ; \
262} \
9c8046dd 263 void FromLong##SetName( long data , wxxVariant& result ) { result = wxxVariant(SetName((unsigned long)data)) ;} \
2c4c3987 264 void ToLong##SetName( const wxxVariant& data , long &result ) { result = (long) data.wxTEMPLATED_MEMBER_CALL(Get , SetName).to_ulong() ;} \
af498247
VZ
265 wxTO_STRING_IMP( SetName ) \
266 wxFROM_STRING_IMP( SetName ) \
267 wxEnumTypeInfo s_typeInfo##SetName(wxT_SET , &s_enumData##e , &wxTO_STRING( SetName ) , &wxFROM_STRING( SetName ) , &ToLong##SetName , &FromLong##SetName, typeid(SetName).name() ) ; \
2abce515 268}
a095505c 269
0886e254
SC
270template<typename e>
271void wxFlagsFromString(const wxString &s , e &data )
272{
273 wxEnumData* edata = wxGetEnumData((e*) 0) ;
274 data.m_data = 0 ;
275
276 wxArrayString array ;
277 wxSetStringToArray( s , array ) ;
278 wxString flag;
1c263d56 279 for ( size_t i = 0 ; i < array.Count() ; ++i )
0886e254
SC
280 {
281 flag = array[i] ;
282 int ivalue ;
283 if ( edata->HasEnumMemberValue( flag , &ivalue ) )
284 {
285 data.m_data |= ivalue ;
286 }
287 }
288}
289
290template<typename e>
291void wxFlagsToString( wxString &s , const e& data )
292{
293 wxEnumData* edata = wxGetEnumData((e*) 0) ;
294 int count = edata->GetEnumCount() ;
295 int i ;
296 s.Clear() ;
297 long dataValue = data.m_data ;
298 for ( i = 0 ; i < count ; i++ )
299 {
300 int value = edata->GetEnumMemberValueByIndex(i) ;
301 // make this to allow for multi-bit constants to work
302 if ( value && ( dataValue & value ) == value )
303 {
304 // clear the flags we just set
305 dataValue &= ~value ;
306 // this could also be done by the templated calls
432968bf 307 if ( !s.empty() )
583150e3 308 s +=wxT("|") ;
0886e254
SC
309 s += edata->GetEnumMemberNameByIndex(i) ;
310 }
311 }
312}
313
9dabddc2 314#define wxBEGIN_FLAGS( e ) \
0886e254
SC
315 wxEnumMemberData s_enumDataMembers##e[] = {
316
9dabddc2 317#define wxFLAGS_MEMBER( v ) { wxT(#v), v } ,
0886e254 318
9dabddc2 319#define wxEND_FLAGS( e ) { NULL , 0 } } ; \
0886e254
SC
320 wxEnumData s_enumData##e( s_enumDataMembers##e ) ; \
321 wxEnumData *wxGetEnumData(e*) { return &s_enumData##e ; } \
492f9a9e 322 template<> void wxStringReadValue(const wxString &s , e &data ) \
0886e254
SC
323{ \
324 wxFlagsFromString<e>( s , data ) ; \
325} \
492f9a9e 326 template<> void wxStringWriteValue( wxString &s , const e& data ) \
0886e254
SC
327{ \
328 wxFlagsToString<e>( s , data ) ; \
329} \
330 void FromLong##e( long data , wxxVariant& result ) { result = wxxVariant(e(data)) ;} \
2c4c3987 331 void ToLong##e( const wxxVariant& data , long &result ) { result = (long) data.wxTEMPLATED_MEMBER_CALL(Get , e).m_data ;} \
af498247
VZ
332 wxTO_STRING_IMP( e ) \
333 wxFROM_STRING_IMP( e ) \
334 wxEnumTypeInfo s_typeInfo##e(wxT_SET , &s_enumData##e , &wxTO_STRING( e ) , &wxFROM_STRING( e ) , &ToLong##e , &FromLong##e, typeid(e).name() ) ;
a095505c
SC
335// ----------------------------------------------------------------------------
336// Type Information
337// ----------------------------------------------------------------------------
ab6e4913
SC
338//
339//
340// All data exposed by the RTTI is characterized using the following classes.
341// The first characterization is done by wxTypeKind. All enums up to and including
342// wxT_CUSTOM represent so called simple types. These cannot be divided any further.
343// They can be converted to and from wxStrings, that's all.
344
a095505c
SC
345
346enum wxTypeKind
347{
348 wxT_VOID = 0, // unknown type
349 wxT_BOOL,
350 wxT_CHAR,
351 wxT_UCHAR,
352 wxT_INT,
353 wxT_UINT,
354 wxT_LONG,
355 wxT_ULONG,
356 wxT_FLOAT,
357 wxT_DOUBLE,
358 wxT_STRING, // must be wxString
0886e254 359 wxT_SET, // must be wxBitset<> template
a095505c 360 wxT_ENUM,
a095505c 361 wxT_CUSTOM, // user defined type (e.g. wxPoint)
75890a3f 362
ab6e4913
SC
363 wxT_LAST_SIMPLE_TYPE_KIND = wxT_CUSTOM ,
364
365 wxT_OBJECT_PTR, // object reference
ae820c69 366 wxT_OBJECT , // embedded object
ab6e4913
SC
367 wxT_COLLECTION , // collection
368
517fb871 369 wxT_DELEGATE , // for connecting against an event source
75890a3f 370
ab6e4913 371 wxT_LAST_TYPE_KIND = wxT_DELEGATE // sentinel for bad data, asserts, debugging
a095505c
SC
372};
373
492f9a9e
SC
374class WXDLLIMPEXP_BASE wxxVariant ;
375class WXDLLIMPEXP_BASE wxTypeInfo ;
ae820c69 376
492f9a9e 377WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxTypeInfo* , wxTypeInfoMap , class WXDLLIMPEXP_BASE ) ;
208fd16c 378
a095505c
SC
379class WXDLLIMPEXP_BASE wxTypeInfo
380{
381public :
2abce515
SC
382 typedef void (*converterToString_t)( const wxxVariant& data , wxString &result ) ;
383 typedef void (*converterFromString_t)( const wxString& data , wxxVariant &result ) ;
208fd16c 384
ab0881c7
VS
385 wxTypeInfo(wxTypeKind kind,
386 converterToString_t to = NULL, converterFromString_t from = NULL,
387 const wxString &name = wxEmptyString):
583150e3 388 m_toString(to), m_fromString(from), m_kind(kind), m_name(name)
2abce515 389 {
ab0881c7 390 Register();
2abce515 391 }
583150e3
SC
392#if wxUSE_UNICODE
393 wxTypeInfo(wxTypeKind kind,
12961861
WS
394 converterToString_t to, converterFromString_t from,
395 const char *name):
583150e3
SC
396 m_toString(to), m_fromString(from), m_kind(kind), m_name(wxString::FromAscii(name))
397 {
398 Register();
399 }
400#endif
ae820c69 401
2abce515
SC
402 virtual ~wxTypeInfo()
403 {
404 Unregister() ;
405 }
ae820c69 406
2abce515
SC
407 // return the kind of this type (wxT_... constants)
408 wxTypeKind GetKind() const { return m_kind ; }
ae820c69 409
2abce515
SC
410 // returns the unique name of this type
411 const wxString& GetTypeName() const { return m_name ; }
ae820c69 412
2abce515
SC
413 // is this type a delegate type
414 bool IsDelegateType() const { return m_kind == wxT_DELEGATE ; }
ae820c69 415
2abce515
SC
416 // is this type a custom type
417 bool IsCustomType() const { return m_kind == wxT_CUSTOM ; }
ae820c69 418
2abce515
SC
419 // is this type an object type
420 bool IsObjectType() const { return m_kind == wxT_OBJECT || m_kind == wxT_OBJECT_PTR ; }
ae820c69 421
2abce515
SC
422 // can the content of this type be converted to and from strings ?
423 bool HasStringConverters() const { return m_toString != NULL && m_fromString != NULL ; }
ae820c69 424
2abce515
SC
425 // convert a wxxVariant holding data of this type into a string
426 void ConvertToString( const wxxVariant& data , wxString &result ) const
ae820c69 427
8f2b1cfd 428 { if ( m_toString ) (*m_toString)( data , result ) ; else wxLogError( _("String conversions not supported") ) ; }
ae820c69 429
2abce515
SC
430 // convert a string into a wxxVariant holding the corresponding data in this type
431 void ConvertFromString( const wxString& data , wxxVariant &result ) const
8f2b1cfd 432 { if( m_fromString ) (*m_fromString)( data , result ) ; else wxLogError( _("String conversions not supported") ) ; }
ae820c69 433
583150e3
SC
434#if wxUSE_UNICODE
435 static wxTypeInfo *FindType(const char *typeName) { return FindType( wxString::FromAscii(typeName) ) ; }
436#endif
2abce515 437 static wxTypeInfo *FindType(const wxChar *typeName);
ae820c69
SC
438
439private :
440
441 void Register();
442 void Unregister();
208fd16c
SC
443
444 converterToString_t m_toString ;
445 converterFromString_t m_fromString ;
446
bb7eff4c 447 static wxTypeInfoMap* ms_typeTable ;
ae820c69 448
ab0881c7
VS
449 wxTypeKind m_kind;
450 wxString m_name;
a095505c
SC
451};
452
453class WXDLLIMPEXP_BASE wxBuiltInTypeInfo : public wxTypeInfo
454{
455public :
ae820c69
SC
456 wxBuiltInTypeInfo( wxTypeKind kind , converterToString_t to = NULL , converterFromString_t from = NULL , const wxString &name = wxEmptyString ) :
457 wxTypeInfo( kind , to , from , name )
458 { wxASSERT_MSG( GetKind() < wxT_SET , wxT("Illegal Kind for Base Type") ) ; }
583150e3
SC
459#if wxUSE_UNICODE
460 wxBuiltInTypeInfo( wxTypeKind kind , converterToString_t to , converterFromString_t from , const char *name ) :
461 wxTypeInfo( kind , to , from , name )
462 { wxASSERT_MSG( GetKind() < wxT_SET , wxT("Illegal Kind for Base Type") ) ; }
463#endif
a095505c
SC
464} ;
465
466class WXDLLIMPEXP_BASE wxCustomTypeInfo : public wxTypeInfo
467{
468public :
ae820c69
SC
469 wxCustomTypeInfo( const wxString &name , converterToString_t to , converterFromString_t from ) :
470 wxTypeInfo( wxT_CUSTOM , to , from , name )
471 {}
583150e3
SC
472#if wxUSE_UNICODE
473 wxCustomTypeInfo( const char *name , converterToString_t to , converterFromString_t from ) :
474 wxTypeInfo( wxT_CUSTOM , to , from , name )
475 {}
476#endif
a095505c
SC
477} ;
478
479class WXDLLIMPEXP_BASE wxEnumTypeInfo : public wxTypeInfo
480{
481public :
ae820c69
SC
482 typedef void (*converterToLong_t)( const wxxVariant& data , long &result ) ;
483 typedef void (*converterFromLong_t)( long data , wxxVariant &result ) ;
484
2abce515 485 wxEnumTypeInfo( wxTypeKind kind , wxEnumData* enumInfo , converterToString_t to , converterFromString_t from ,
ae820c69 486 converterToLong_t toLong , converterFromLong_t fromLong , const wxString &name ) :
2abce515
SC
487 wxTypeInfo( kind , to , from , name ) , m_toLong( toLong ) , m_fromLong( fromLong )
488 { wxASSERT_MSG( kind == wxT_ENUM || kind == wxT_SET , wxT("Illegal Kind for Enum Type")) ; m_enumInfo = enumInfo ;}
583150e3
SC
489
490#if wxUSE_UNICODE
491 wxEnumTypeInfo( wxTypeKind kind , wxEnumData* enumInfo , converterToString_t to , converterFromString_t from ,
492 converterToLong_t toLong , converterFromLong_t fromLong , const char * name ) :
493 wxTypeInfo( kind , to , from , name ) , m_toLong( toLong ) , m_fromLong( fromLong )
494 { wxASSERT_MSG( kind == wxT_ENUM || kind == wxT_SET , wxT("Illegal Kind for Enum Type")) ; m_enumInfo = enumInfo ;}
495#endif
2abce515 496 const wxEnumData* GetEnumData() const { return m_enumInfo ; }
ae820c69 497
2abce515
SC
498 // convert a wxxVariant holding data of this type into a long
499 void ConvertToLong( const wxxVariant& data , long &result ) const
ae820c69 500
8f2b1cfd 501 { if( m_toLong ) (*m_toLong)( data , result ) ; else wxLogError( _("Long Conversions not supported") ) ; }
ae820c69 502
2abce515
SC
503 // convert a long into a wxxVariant holding the corresponding data in this type
504 void ConvertFromLong( long data , wxxVariant &result ) const
8f2b1cfd 505 { if( m_fromLong ) (*m_fromLong)( data , result ) ; else wxLogError( _("Long Conversions not supported") ) ;}
ae820c69 506
a095505c 507private :
ae820c69
SC
508 converterToLong_t m_toLong ;
509 converterFromLong_t m_fromLong ;
510
517fb871 511 wxEnumData *m_enumInfo; // Kind == wxT_ENUM or Kind == wxT_SET
a095505c
SC
512} ;
513
514class WXDLLIMPEXP_BASE wxClassTypeInfo : public wxTypeInfo
515{
516public :
492f9a9e 517 wxClassTypeInfo( wxTypeKind kind , wxClassInfo* classInfo , converterToString_t to = NULL , converterFromString_t from = NULL , const wxString &name = wxEmptyString) ;
583150e3
SC
518#if wxUSE_UNICODE
519 wxClassTypeInfo( wxTypeKind kind , wxClassInfo* classInfo , converterToString_t to , converterFromString_t from , const char *name ) ;
520#endif
2abce515 521 const wxClassInfo *GetClassInfo() const { return m_classInfo ; }
a095505c 522private :
517fb871 523 wxClassInfo *m_classInfo; // Kind == wxT_OBJECT - could be NULL
a095505c
SC
524} ;
525
ab6e4913
SC
526class WXDLLIMPEXP_BASE wxCollectionTypeInfo : public wxTypeInfo
527{
528public :
c681bd24 529 wxCollectionTypeInfo( const wxString &elementName , converterToString_t to , converterFromString_t from , const wxString &name) :
ae820c69 530 wxTypeInfo( wxT_COLLECTION , to , from , name )
c681bd24 531 { m_elementTypeName = elementName ; m_elementType = NULL ;}
583150e3 532#if wxUSE_UNICODE
c681bd24 533 wxCollectionTypeInfo( const char *elementName , converterToString_t to , converterFromString_t from , const char *name ) :
583150e3 534 wxTypeInfo( wxT_COLLECTION , to , from , name )
c681bd24 535 { m_elementTypeName = wxString::FromAscii( elementName ) ; m_elementType = NULL ;}
583150e3 536#endif
cab1a605
WS
537 const wxTypeInfo* GetElementType() const
538 {
c681bd24
SC
539 if ( m_elementType == NULL )
540 m_elementType = wxTypeInfo::FindType( m_elementTypeName ) ;
541 return m_elementType ; }
ab6e4913 542private :
c681bd24
SC
543 mutable wxTypeInfo * m_elementType ;
544 wxString m_elementTypeName ;
ab6e4913
SC
545} ;
546
4393b50c 547// a delegate is an exposed event source
a095505c
SC
548
549class WXDLLIMPEXP_BASE wxDelegateTypeInfo : public wxTypeInfo
550{
551public :
ae820c69 552 wxDelegateTypeInfo( int eventType , wxClassInfo* eventClass , converterToString_t to = NULL , converterFromString_t from = NULL ) ;
4177a99c 553 wxDelegateTypeInfo( int eventType , int lastEventType, wxClassInfo* eventClass , converterToString_t to = NULL , converterFromString_t from = NULL ) ;
517fb871 554 int GetEventType() const { return m_eventType ; }
4177a99c 555 int GetLastEventType() const { return m_lastEventType ; }
25474dca 556 const wxClassInfo* GetEventClass() const { return m_eventClass ; }
a095505c 557private :
517fb871
VS
558 const wxClassInfo *m_eventClass; // (extended will merge into classinfo)
559 int m_eventType ;
4177a99c 560 int m_lastEventType ;
a095505c
SC
561} ;
562
492f9a9e 563template<typename T> const wxTypeInfo* wxGetTypeInfo( T * ) { return wxTypeInfo::FindType(typeid(T).name()) ; }
a095505c 564
a095505c
SC
565// this macro is for usage with custom, non-object derived classes and structs, wxPoint is such a custom type
566
af498247 567#if wxUSE_FUNC_TEMPLATE_POINTER
9dabddc2 568#define wxCUSTOM_TYPE_INFO( e , toString , fromString ) \
492f9a9e 569 wxCustomTypeInfo s_typeInfo##e(typeid(e).name() , &toString , &fromString) ;
af498247
VZ
570#else
571#define wxCUSTOM_TYPE_INFO( e , toString , fromString ) \
572 void ToString##e( const wxxVariant& data , wxString &result ) { toString(data, result); } \
573 void FromString##e( const wxString& data , wxxVariant &result ) { fromString(data, result); } \
574 wxCustomTypeInfo s_typeInfo##e(typeid(e).name() , &ToString##e , &FromString##e) ;
575#endif
a095505c 576
9dabddc2 577#define wxCOLLECTION_TYPE_INFO( element , collection ) \
c681bd24 578 wxCollectionTypeInfo s_typeInfo##collection( typeid(element).name() , NULL , NULL , typeid(collection).name() ) ;
ae820c69 579
8f2b1cfd
SC
580// sometimes a compiler invents specializations that are nowhere called, use this macro to satisfy the refs, currently
581// we don't have to play tricks, but if we will have to according to the compiler, we will use that macro for that
a095505c 582
9dabddc2 583#define wxILLEGAL_TYPE_SPECIALIZATION( a )
a095505c
SC
584
585// ----------------------------------------------------------------------------
586// wxxVariant as typesafe data holder
587// ----------------------------------------------------------------------------
588
589class WXDLLIMPEXP_BASE wxxVariantData
590{
591public:
517fb871 592 virtual ~wxxVariantData() {}
a095505c 593
517fb871
VS
594 // return a heap allocated duplicate
595 virtual wxxVariantData* Clone() const = 0 ;
a095505c 596
517fb871
VS
597 // returns the type info of the contentc
598 virtual const wxTypeInfo* GetTypeInfo() const = 0 ;
a095505c
SC
599} ;
600
df3a88af 601template<typename T> class wxxVariantDataT : public wxxVariantData
a095505c
SC
602{
603public:
fa08490f 604 wxxVariantDataT(const T& d) : m_data(d) {}
ae820c69 605 virtual ~wxxVariantDataT() {}
a095505c 606
ae820c69 607 // get a ref to the stored data
fa08490f 608 T & Get() { return m_data; }
a095505c 609
ae820c69 610 // get a const ref to the stored data
fa08490f
SC
611 const T & Get() const { return m_data; }
612
ae820c69 613 // set the data
fa08490f 614 void Set(const T& d) { m_data = d; }
a095505c 615
517fb871
VS
616 // return a heap allocated duplicate
617 virtual wxxVariantData* Clone() const { return new wxxVariantDataT<T>( Get() ) ; }
a095505c 618
517fb871
VS
619 // returns the type info of the contentc
620 virtual const wxTypeInfo* GetTypeInfo() const { return wxGetTypeInfo( (T*) NULL ) ; }
583150e3 621
a095505c
SC
622private:
623 T m_data;
624};
625
626class WXDLLIMPEXP_BASE wxxVariant
627{
628public :
ae820c69 629 wxxVariant() { m_data = NULL ; }
12961861 630 wxxVariant( wxxVariantData* data , const wxString& name = wxEmptyString ) : m_data(data) , m_name(name) {}
ae820c69
SC
631 wxxVariant( const wxxVariant &d ) { if ( d.m_data ) m_data = d.m_data->Clone() ; else m_data = NULL ; m_name = d.m_name ; }
632
12961861 633 template<typename T> wxxVariant( const T& data , const wxString& name = wxEmptyString ) :
ae820c69
SC
634 m_data(new wxxVariantDataT<T>(data) ), m_name(name) {}
635
636 ~wxxVariant() { delete m_data ; }
637
638 // get a ref to the stored data
9dabddc2 639 template<typename T> T& Get(wxTEMPLATED_MEMBER_FIX(T))
ae820c69
SC
640 {
641 wxxVariantDataT<T> *dataptr = dynamic_cast<wxxVariantDataT<T>*> (m_data) ;
af498247 642 wxASSERT_MSG( dataptr , wxString::Format(wxT("Cast to %s not possible"), typeid(T).name()) ) ;
ae820c69
SC
643 return dataptr->Get() ;
644 }
645
646 // get a ref to the stored data
9dabddc2 647 template<typename T> const T& Get(wxTEMPLATED_MEMBER_FIX(T)) const
ae820c69
SC
648 {
649 const wxxVariantDataT<T> *dataptr = dynamic_cast<const wxxVariantDataT<T>*> (m_data) ;
af498247 650 wxASSERT_MSG( dataptr , wxString::Format(wxT("Cast to %s not possible"), typeid(T).name()) ) ;
ae820c69
SC
651 return dataptr->Get() ;
652 }
fa08490f 653
583150e3
SC
654 bool IsEmpty() const { return m_data == NULL ; }
655
af498247 656 template<typename T> bool HasData(wxTEMPLATED_MEMBER_FIX(T)) const
208fd16c 657 {
ae820c69 658 const wxxVariantDataT<T> *dataptr = dynamic_cast<const wxxVariantDataT<T>*> (m_data) ;
208fd16c
SC
659 return dataptr != NULL ;
660 }
661
ae820c69
SC
662 // stores the data
663 template<typename T> void Set(const T& data) const
664 {
665 delete m_data ;
666 m_data = new wxxVariantDataT<T>(data) ;
667 }
668
669 wxxVariant& operator=(const wxxVariant &d)
670 {
8348e2cb
VZ
671 delete m_data;
672 m_data = d.m_data ? d.m_data->Clone() : NULL ;
ae820c69
SC
673 m_name = d.m_name ;
674 return *this ;
675 }
676
677 // gets the stored data casted to a wxObject* , returning NULL if cast is not possible
678 wxObject* GetAsObject() ;
679
680 // get the typeinfo of the stored object
681 const wxTypeInfo* GetTypeInfo() const { return m_data->GetTypeInfo() ; }
682
683 // returns this value as string
684 wxString GetAsString() const
685 {
686 wxString s ;
208fd16c 687 GetTypeInfo()->ConvertToString( *this , s ) ;
ae820c69
SC
688 return s ;
689 }
4f8ffae1 690 const wxString& GetName() const { return m_name ; }
a095505c 691private :
517fb871
VS
692 wxxVariantData* m_data ;
693 wxString m_name ;
a095505c
SC
694} ;
695
ab6e4913
SC
696#include <wx/dynarray.h>
697
698WX_DECLARE_OBJARRAY_WITH_DECL(wxxVariant, wxxVariantArray, class WXDLLIMPEXP_BASE);
699
2abce515
SC
700// templated streaming, every type must have their specialization for these methods
701
702template<typename T>
703void wxStringReadValue( const wxString &s , T &data );
704
705template<typename T>
706void wxStringWriteValue( wxString &s , const T &data);
707
708template<typename T>
af498247 709void wxToStringConverter( const wxxVariant &v, wxString &s wxTEMPLATED_FUNCTION_FIX(T)) { wxStringWriteValue( s , v.wxTEMPLATED_MEMBER_CALL(Get , T) ) ; }
2abce515
SC
710
711template<typename T>
cab1a605 712void wxFromStringConverter( const wxString &s, wxxVariant &v wxTEMPLATED_FUNCTION_FIX(T)) { T d ; wxStringReadValue( s , d ) ; v = wxxVariant(d) ; }
2abce515 713
a095505c
SC
714// ----------------------------------------------------------------------------
715// Property Support
716//
717// wxPropertyInfo is used to inquire of the property by name. It doesn't
718// provide access to the property, only information about it. If you
719// want access, look at wxPropertyAccessor.
720// ----------------------------------------------------------------------------
721
492f9a9e 722class WXDLLIMPEXP_BASE wxSetter
a095505c 723{
ab0881c7 724public:
208fd16c 725 wxSetter( const wxString name ) { m_name = name ; }
ab0881c7 726 virtual ~wxSetter() {}
208fd16c
SC
727 virtual void Set( wxObject *object, const wxxVariant &variantValue ) const = 0;
728 const wxString& GetName() const { return m_name ; }
ab0881c7
VS
729private:
730 wxString m_name;
731};
a095505c 732
492f9a9e 733class WXDLLIMPEXP_BASE wxGetter
2d51f067 734{
ab0881c7 735public:
208fd16c 736 wxGetter( const wxString name ) { m_name = name ; }
ab0881c7 737 virtual ~wxGetter() {}
208fd16c
SC
738 virtual void Get( const wxObject *object , wxxVariant& result) const = 0;
739 const wxString& GetName() const { return m_name ; }
ab0881c7
VS
740private:
741 wxString m_name;
742};
2d51f067 743
492f9a9e 744class WXDLLIMPEXP_BASE wxCollectionGetter
a095505c 745{
208fd16c
SC
746public :
747 wxCollectionGetter( const wxString name ) { m_name = name ; }
ab0881c7 748 virtual ~wxCollectionGetter() {}
208fd16c
SC
749 virtual void Get( const wxObject *object , wxxVariantArray& result) const = 0;
750 const wxString& GetName() const { return m_name ; }
751private :
752 wxString m_name ;
753} ;
fa08490f 754
1ab608ee 755template<typename coll_t> void WXDLLIMPEXP_BASE wxCollectionToVariantArray( const coll_t& coll , wxxVariantArray& result ) ;
a095505c 756
492f9a9e 757class WXDLLIMPEXP_BASE wxAdder
208fd16c
SC
758{
759public :
760 wxAdder( const wxString name ) { m_name = name ; }
ab0881c7 761 virtual ~wxAdder() {}
208fd16c
SC
762 virtual void Add( wxObject *object, const wxxVariant &variantValue ) const= 0;
763 const wxString& GetName() const { return m_name ; }
764private :
765 wxString m_name ;
766} ;
a095505c 767
517fb871 768
9dabddc2 769#define wxSETTER( property, Klass, valueType, setterMethod ) \
ae820c69
SC
770class wxSetter##property : public wxSetter \
771{ \
772public: \
af498247 773 wxINFUNC_CLASS_TYPE_FIX(Klass) \
583150e3 774 wxSetter##property() : wxSetter( wxT(#setterMethod) ) {} \
492f9a9e 775 ~wxSetter##property() {} \
ae820c69
SC
776 void Set( wxObject *object, const wxxVariant &variantValue ) const \
777{ \
778 Klass *obj = dynamic_cast<Klass*>(object) ; \
af498247 779 if ( variantValue.wxTEMPLATED_MEMBER_CALL(HasData, valueType) ) \
2c4c3987 780 obj->setterMethod(variantValue.wxTEMPLATED_MEMBER_CALL(Get , valueType)) ; \
a06bb527 781 else \
2c4c3987 782 obj->setterMethod(*variantValue.wxTEMPLATED_MEMBER_CALL(Get , valueType*)) ; \
ae820c69
SC
783} \
784} ;
208fd16c 785
9dabddc2 786#define wxGETTER( property, Klass, valueType , gettermethod ) \
ae820c69
SC
787class wxGetter##property : public wxGetter \
788{ \
789public : \
af498247 790 wxINFUNC_CLASS_TYPE_FIX(Klass) \
583150e3 791 wxGetter##property() : wxGetter( wxT(#gettermethod) ) {} \
492f9a9e 792 ~wxGetter##property() {} \
ae820c69
SC
793 void Get( const wxObject *object , wxxVariant &result) const \
794{ \
795 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
796 result = wxxVariant( obj->gettermethod() ) ; \
797} \
798} ;
208fd16c 799
9dabddc2 800#define wxADDER( property, Klass, valueType , addermethod ) \
ae820c69
SC
801class wxAdder##property : public wxAdder \
802{ \
803public: \
af498247 804 wxINFUNC_CLASS_TYPE_FIX(Klass) \
583150e3 805 wxAdder##property() : wxAdder( wxT(#addermethod) ) {} \
492f9a9e 806 ~wxAdder##property() {} \
ae820c69
SC
807 void Add( wxObject *object, const wxxVariant &variantValue ) const \
808{ \
809 Klass *obj = dynamic_cast<Klass*>(object) ; \
af498247 810 if ( variantValue.wxTEMPLATED_MEMBER_CALL(HasData, valueType) ) \
2c4c3987 811 obj->addermethod(variantValue.wxTEMPLATED_MEMBER_CALL(Get , valueType)) ; \
a06bb527 812 else \
2c4c3987 813 obj->addermethod(*variantValue.wxTEMPLATED_MEMBER_CALL(Get , valueType*)) ; \
ae820c69
SC
814} \
815} ;
208fd16c 816
9dabddc2 817#define wxCOLLECTION_GETTER( property, Klass, valueType , gettermethod ) \
ae820c69
SC
818class wxCollectionGetter##property : public wxCollectionGetter \
819{ \
820public : \
af498247 821 wxINFUNC_CLASS_TYPE_FIX(Klass) \
583150e3 822 wxCollectionGetter##property() : wxCollectionGetter( wxT(#gettermethod) ) {} \
492f9a9e 823 ~wxCollectionGetter##property() {} \
ae820c69
SC
824 void Get( const wxObject *object , wxxVariantArray &result) const \
825{ \
826 const Klass *obj = dynamic_cast<const Klass*>(object) ; \
827 wxCollectionToVariantArray( obj->gettermethod() , result ) ; \
828} \
829} ;
ab6e4913 830
208fd16c
SC
831class WXDLLIMPEXP_BASE wxPropertyAccessor
832{
833public :
834 wxPropertyAccessor( wxSetter *setter , wxGetter *getter , wxAdder *adder , wxCollectionGetter *collectionGetter )
835 { m_setter = setter ; m_getter = getter ; m_adder = adder ; m_collectionGetter = collectionGetter ;}
ab6e4913 836
208fd16c 837 virtual ~wxPropertyAccessor() {}
ab6e4913 838
208fd16c
SC
839 // Setting a simple property (non-collection)
840 virtual void SetProperty(wxObject *object, const wxxVariant &value) const
f7476b53 841 { if ( m_setter ) m_setter->Set( object , value ) ; else wxLogError( _("SetProperty called w/o valid setter") ) ;}
16a45a23 842
208fd16c
SC
843 // Getting a simple property (non-collection)
844 virtual void GetProperty(const wxObject *object, wxxVariant &result) const
8f2b1cfd 845 { if ( m_getter ) m_getter->Get( object , result ) ; else wxLogError( _("GetProperty called w/o valid getter") ) ;}
ab6e4913 846
208fd16c
SC
847 // Adding an element to a collection property
848 virtual void AddToPropertyCollection(wxObject *object, const wxxVariant &value) const
8f2b1cfd 849 { if ( m_adder ) m_adder->Add( object , value ) ; else wxLogError( _("AddToPropertyCollection called w/o valid adder") ) ;}
ab6e4913 850
208fd16c
SC
851 // Getting a collection property
852 virtual void GetPropertyCollection( const wxObject *obj, wxxVariantArray &result) const
8f2b1cfd 853 { if ( m_collectionGetter ) m_collectionGetter->Get( obj , result) ; else wxLogError( _("GetPropertyCollection called w/o valid collection getter") ) ;}
208fd16c
SC
854
855 virtual bool HasSetter() const { return m_setter != NULL ; }
856 virtual bool HasCollectionGetter() const { return m_collectionGetter != NULL ; }
857 virtual bool HasGetter() const { return m_getter != NULL ; }
858 virtual bool HasAdder() const { return m_adder != NULL ; }
859
860 virtual const wxString& GetCollectionGetterName() const
861 { return m_collectionGetter->GetName() ; }
862 virtual const wxString& GetGetterName() const
863 { return m_getter->GetName() ; }
864 virtual const wxString& GetSetterName() const
865 { return m_setter->GetName() ; }
866 virtual const wxString& GetAdderName() const
867 { return m_adder->GetName() ; }
492f9a9e 868
208fd16c
SC
869protected :
870 wxSetter *m_setter ;
871 wxAdder *m_adder ;
872 wxGetter *m_getter ;
873 wxCollectionGetter* m_collectionGetter ;
874};
ab6e4913 875
ae820c69
SC
876class WXDLLIMPEXP_BASE wxGenericPropertyAccessor : public wxPropertyAccessor
877{
878public :
879 wxGenericPropertyAccessor( const wxString &propName ) ;
880 ~wxGenericPropertyAccessor() ;
ab6e4913 881
53a26bf7
DS
882 void RenameProperty( const wxString& WXUNUSED_UNLESS_DEBUG(oldName),
883 const wxString& newName )
492f9a9e
SC
884 {
885 wxASSERT( oldName == m_propertyName ) ; m_propertyName = newName ;
886 }
ae820c69
SC
887 virtual bool HasSetter() const { return true ; }
888 virtual bool HasGetter() const { return true ; }
889 virtual bool HasAdder() const { return false ; }
890 virtual bool HasCollectionGetter() const { return false ; }
ab6e4913 891
ae820c69 892 virtual const wxString& GetGetterName() const
208fd16c
SC
893 { return m_getterName ; }
894 virtual const wxString& GetSetterName() const
895 { return m_setterName ; }
ab6e4913 896
208fd16c 897 virtual void SetProperty(wxObject *object, const wxxVariant &value) const ;
ae820c69 898 virtual void GetProperty(const wxObject *object, wxxVariant &value) const ;
208fd16c 899
ae820c69
SC
900 // Adding an element to a collection property
901 virtual void AddToPropertyCollection(wxObject *WXUNUSED(object), const wxxVariant &WXUNUSED(value)) const
8f2b1cfd 902 { wxLogError( _("AddToPropertyCollection called on a generic accessor") ) ;}
208fd16c 903
ae820c69
SC
904 // Getting a collection property
905 virtual void GetPropertyCollection( const wxObject *WXUNUSED(obj), wxxVariantArray &WXUNUSED(result)) const
8f2b1cfd 906 { wxLogError ( _("GetPropertyCollection called on a generic accessor") ) ;}
ae820c69
SC
907private :
908 struct wxGenericPropertyAccessorInternal ;
909 wxGenericPropertyAccessorInternal* m_data ;
910 wxString m_propertyName ;
911 wxString m_setterName ;
912 wxString m_getterName ;
208fd16c 913} ;
ab6e4913 914
ae820c69
SC
915typedef long wxPropertyInfoFlags ;
916enum {
917 // will be removed in future releases
918 wxPROP_DEPRECATED = 0x00000001 ,
919 // object graph property, will be streamed with priority (after constructor properties)
920 wxPROP_OBJECT_GRAPH = 0x00000002 ,
921 // this will only be streamed out and in as enum/set, the internal representation is still a long
922 wxPROP_ENUM_STORE_LONG = 0x00000004 ,
9c8046dd
SC
923 // don't stream out this property, needed eg to avoid streaming out children that are always created by their parents
924 wxPROP_DONT_STREAM = 0x00000008 ,
ae820c69
SC
925} ;
926
a095505c
SC
927class WXDLLIMPEXP_BASE wxPropertyInfo
928{
492f9a9e 929 friend class WXDLLIMPEXP_BASE wxDynamicClassInfo ;
a095505c 930public :
ab0881c7 931 wxPropertyInfo(wxPropertyInfo* &iter,
492f9a9e
SC
932 wxClassInfo* itsClass,
933 const wxString& name,
934 const wxString& typeName,
935 wxPropertyAccessor *accessor,
936 wxxVariant dv,
937 wxPropertyInfoFlags flags = 0,
938 const wxString& helpString = wxEmptyString,
939 const wxString& groupString = wxEmptyString) :
583150e3 940 m_itsClass(itsClass),
492f9a9e 941 m_name(name),
492f9a9e 942 m_typeInfo(NULL),
583150e3 943 m_typeName(typeName) ,
492f9a9e
SC
944 m_collectionElementTypeInfo(NULL),
945 m_accessor(accessor),
583150e3
SC
946 m_defaultValue(dv),
947 m_flags(flags),
948 m_helpString(helpString),
949 m_groupString(groupString)
492f9a9e
SC
950 {
951 Insert(iter);
952 }
953
583150e3 954#if wxUSE_UNICODE
492f9a9e
SC
955 wxPropertyInfo(wxPropertyInfo* &iter,
956 wxClassInfo* itsClass,
ab0881c7 957 const wxString& name,
583150e3 958 const char* typeName,
ab0881c7
VS
959 wxPropertyAccessor *accessor,
960 wxxVariant dv,
961 wxPropertyInfoFlags flags = 0,
962 const wxString& helpString = wxEmptyString,
963 const wxString& groupString = wxEmptyString) :
583150e3 964 m_itsClass(itsClass),
ab0881c7 965 m_name(name),
583150e3
SC
966 m_typeInfo(NULL),
967 m_typeName(wxString::FromAscii(typeName)) ,
968 m_collectionElementTypeInfo(NULL),
969 m_accessor(accessor),
970 m_defaultValue(dv),
971 m_flags(flags),
ab0881c7 972 m_helpString(helpString),
583150e3
SC
973 m_groupString(groupString)
974 {
975 Insert(iter);
976 }
977#endif
978 wxPropertyInfo(wxPropertyInfo* &iter,
979 wxClassInfo* itsClass,
980 const wxString& name,
981 wxDelegateTypeInfo* type,
982 wxPropertyAccessor *accessor,
983 wxxVariant dv,
984 wxPropertyInfoFlags flags = 0,
985 const wxString& helpString = wxEmptyString,
986 const wxString& groupString = wxEmptyString) :
ab0881c7 987 m_itsClass(itsClass),
583150e3 988 m_name(name),
492f9a9e 989 m_typeInfo(type),
ab0881c7
VS
990 m_collectionElementTypeInfo(NULL),
991 m_accessor(accessor),
583150e3
SC
992 m_defaultValue(dv),
993 m_flags(flags),
994 m_helpString(helpString),
995 m_groupString(groupString)
ae820c69 996 {
ab0881c7 997 Insert(iter);
ae820c69
SC
998 }
999
ab0881c7 1000 wxPropertyInfo(wxPropertyInfo* &iter,
492f9a9e
SC
1001 wxClassInfo* itsClass, const wxString& name,
1002 const wxString& collectionTypeName,
1003 const wxString& elementTypeName,
ab0881c7
VS
1004 wxPropertyAccessor *accessor,
1005 wxPropertyInfoFlags flags = 0,
1006 const wxString& helpString = wxEmptyString,
1007 const wxString& groupString = wxEmptyString) :
ab0881c7 1008 m_itsClass(itsClass),
583150e3 1009 m_name(name),
492f9a9e
SC
1010 m_typeInfo(NULL),
1011 m_typeName(collectionTypeName) ,
1012 m_collectionElementTypeInfo(NULL),
1013 m_collectionElementTypeName(elementTypeName),
583150e3
SC
1014 m_accessor(accessor) ,
1015 m_flags(flags),
1016 m_helpString(helpString),
1017 m_groupString(groupString)
ae820c69 1018 {
ab0881c7 1019 Insert(iter);
ae820c69
SC
1020 }
1021
583150e3
SC
1022#if wxUSE_UNICODE
1023 wxPropertyInfo(wxPropertyInfo* &iter,
1024 wxClassInfo* itsClass, const wxString& name,
1025 const char* collectionTypeName,
1026 const char* elementTypeName,
1027 wxPropertyAccessor *accessor,
1028 wxPropertyInfoFlags flags = 0,
1029 const wxString& helpString = wxEmptyString,
1030 const wxString& groupString = wxEmptyString) :
1031 m_itsClass(itsClass),
1032 m_name(name),
1033 m_typeInfo(NULL),
1034 m_typeName(wxString::FromAscii(collectionTypeName)) ,
1035 m_collectionElementTypeInfo(NULL),
1036 m_collectionElementTypeName(wxString::FromAscii(elementTypeName)),
1037 m_accessor(accessor) ,
1038 m_flags(flags),
1039 m_helpString(helpString),
1040 m_groupString(groupString)
1041 {
1042 Insert(iter);
1043 }
1044#endif
1c263d56
SC
1045 ~wxPropertyInfo() ;
1046
ae820c69 1047 // return the class this property is declared in
cab1a605 1048 const wxClassInfo* GetDeclaringClass() const { return m_itsClass ; }
fa08490f 1049
ae820c69 1050 // return the name of this property
cab1a605 1051 const wxString& GetName() const { return m_name ; }
ab6e4913 1052
ae820c69 1053 // returns the flags of this property
cab1a605 1054 wxPropertyInfoFlags GetFlags() const { return m_flags ;}
fa08490f 1055
ae820c69
SC
1056 // returns the short help string of this property
1057 const wxString& GetHelpString() const { return m_helpString ; }
fa08490f 1058
ae820c69
SC
1059 // returns the group string of this property
1060 const wxString& GetGroupString() const { return m_groupString ; }
fa08490f 1061
ae820c69 1062 // return the element type info of this property (for collections, otherwise NULL)
cab1a605 1063 const wxTypeInfo * GetCollectionElementTypeInfo() const
492f9a9e
SC
1064 {
1065 if ( m_collectionElementTypeInfo == NULL )
1066 m_collectionElementTypeInfo = wxTypeInfo::FindType(m_collectionElementTypeName) ;
583150e3 1067 return m_collectionElementTypeInfo ;
492f9a9e 1068 }
fa08490f 1069
ae820c69 1070 // return the type info of this property
cab1a605 1071 const wxTypeInfo * GetTypeInfo() const
492f9a9e
SC
1072 {
1073 if ( m_typeInfo == NULL )
1074 m_typeInfo = wxTypeInfo::FindType(m_typeName) ;
583150e3 1075 return m_typeInfo ;
492f9a9e 1076 }
fa08490f 1077
ae820c69
SC
1078 // return the accessor for this property
1079 wxPropertyAccessor* GetAccessor() const { return m_accessor ; }
1080
1081 // returns NULL if this is the last property of this class
1082 wxPropertyInfo* GetNext() const { return m_next ; }
1083
1084 // returns the default value of this property, its kind may be wxT_VOID if it is not valid
cab1a605 1085 wxxVariant GetDefaultValue() const { return m_defaultValue ; }
4393b50c 1086private :
ab6e4913
SC
1087 void Insert(wxPropertyInfo* &iter)
1088 {
ae820c69
SC
1089 m_next = NULL ;
1090 if ( iter == NULL )
1091 iter = this ;
1092 else
1093 {
1094 wxPropertyInfo* i = iter ;
1095 while( i->m_next )
1096 i = i->m_next ;
1097
1098 i->m_next = this ;
1099 }
ab6e4913 1100 }
583150e3 1101
492f9a9e 1102 wxClassInfo* m_itsClass ;
583150e3 1103 wxString m_name ;
492f9a9e 1104 mutable wxTypeInfo* m_typeInfo ;
583150e3 1105 wxString m_typeName ;
492f9a9e 1106 mutable wxTypeInfo* m_collectionElementTypeInfo ;
583150e3 1107 wxString m_collectionElementTypeName ;
517fb871 1108 wxPropertyAccessor* m_accessor ;
cab1a605 1109 wxxVariant m_defaultValue;
583150e3
SC
1110 wxPropertyInfoFlags m_flags ;
1111 wxString m_helpString ;
1112 wxString m_groupString ;
517fb871
VS
1113 // string representation of the default value
1114 // to be assigned by the designer to the property
1115 // when the component is dropped on the container.
1116 wxPropertyInfo* m_next ;
a095505c
SC
1117};
1118
492f9a9e 1119WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxPropertyInfo* , wxPropertyInfoMap , class WXDLLIMPEXP_BASE ) ;
ae820c69 1120
9dabddc2 1121#define wxBEGIN_PROPERTIES_TABLE(theClass) \
2d51f067 1122 wxPropertyInfo *theClass::GetPropertiesStatic() \
ae820c69
SC
1123{ \
1124 typedef theClass class_t; \
1125 static wxPropertyInfo* first = NULL ;
a095505c 1126
9dabddc2 1127#define wxEND_PROPERTIES_TABLE() \
ae820c69 1128 return first ; }
a095505c 1129
9dabddc2 1130#define wxHIDE_PROPERTY( pname ) \
583150e3 1131 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(void).name() ,NULL , wxxVariant() , wxPROP_DONT_STREAM , wxEmptyString , wxEmptyString ) ;
492f9a9e 1132
af498247 1133#define wxPROPERTY( pname , type , setter , getter , defaultValue , flags , help , group) \
9dabddc2 1134 wxSETTER( pname , class_t , type , setter ) \
492f9a9e 1135 static wxSetter##pname _setter##pname ; \
9dabddc2 1136 wxGETTER( pname , class_t , type , getter ) \
492f9a9e
SC
1137 static wxGetter##pname _getter##pname ; \
1138 static wxPropertyAccessor _accessor##pname( &_setter##pname , &_getter##pname , NULL , NULL ) ; \
583150e3 1139 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(type).name() ,&_accessor##pname , wxxVariant(defaultValue) , flags , group , help ) ;
492f9a9e 1140
9dabddc2
SC
1141#define wxPROPERTY_FLAGS( pname , flags , type , setter , getter ,defaultValue , pflags , help , group) \
1142 wxSETTER( pname , class_t , type , setter ) \
492f9a9e 1143 static wxSetter##pname _setter##pname ; \
9dabddc2 1144 wxGETTER( pname , class_t , type , getter ) \
492f9a9e
SC
1145 static wxGetter##pname _getter##pname ; \
1146 static wxPropertyAccessor _accessor##pname( &_setter##pname , &_getter##pname , NULL , NULL ) ; \
583150e3 1147 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(flags).name() ,&_accessor##pname , wxxVariant(defaultValue), wxPROP_ENUM_STORE_LONG | pflags , help , group ) ;
492f9a9e 1148
9dabddc2
SC
1149#define wxREADONLY_PROPERTY( pname , type , getter ,defaultValue , flags , help , group) \
1150 wxGETTER( pname , class_t , type , getter ) \
492f9a9e
SC
1151 static wxGetter##pname _getter##pname ; \
1152 static wxPropertyAccessor _accessor##pname( NULL , &_getter##pname , NULL , NULL ) ; \
583150e3
SC
1153 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(type).name() ,&_accessor##pname , wxxVariant(defaultValue), flags , help , group ) ;
1154
9dabddc2
SC
1155#define wxREADONLY_PROPERTY_FLAGS( pname , flags , type , getter ,defaultValue , pflags , help , group) \
1156 wxGETTER( pname , class_t , type , getter ) \
583150e3
SC
1157 static wxGetter##pname _getter##pname ; \
1158 static wxPropertyAccessor _accessor##pname( NULL , &_getter##pname , NULL , NULL ) ; \
1159 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(flags).name() ,&_accessor##pname , wxxVariant(defaultValue), wxPROP_ENUM_STORE_LONG | pflags , help , group ) ;
492f9a9e 1160
9dabddc2
SC
1161#define wxPROPERTY_COLLECTION( pname , colltype , addelemtype , adder , getter , flags , help , group ) \
1162 wxADDER( pname , class_t , addelemtype , adder ) \
492f9a9e 1163 static wxAdder##pname _adder##pname ; \
9dabddc2 1164 wxCOLLECTION_GETTER( pname , class_t , colltype , getter ) \
492f9a9e
SC
1165 static wxCollectionGetter##pname _collectionGetter##pname ; \
1166 static wxPropertyAccessor _accessor##pname( NULL , NULL ,&_adder##pname , &_collectionGetter##pname ) ; \
583150e3 1167 static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(colltype).name() ,typeid(addelemtype).name() ,&_accessor##pname , flags , help , group ) ;
492f9a9e 1168
9dabddc2
SC
1169#define wxREADONLY_PROPERTY_COLLECTION( pname , colltype , addelemtype , getter , flags , help , group) \
1170 wxCOLLECTION_GETTER( pname , class_t , colltype , getter ) \
492f9a9e
SC
1171 static wxCollectionGetter##pname _collectionGetter##pname ; \
1172 static wxPropertyAccessor _accessor##pname( NULL , NULL , NULL , &_collectionGetter##pname ) ; \
583150e3 1173 static wxPropertyInfo _propertyInfo##pname( first ,class_t::GetClassInfoStatic() , wxT(#pname) , typeid(colltype).name() ,typeid(addelemtype).name() ,&_accessor##pname , flags , help , group ) ;
16a45a23
SC
1174
1175
9dabddc2 1176#define wxEVENT_PROPERTY( name , eventType , eventClass ) \
517fb871 1177 static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \
583150e3 1178 static wxPropertyInfo _propertyInfo##name( first ,class_t::GetClassInfoStatic() , wxT(#name) , &_typeInfo##name , NULL , wxxVariant() ) ; \
a095505c 1179
9dabddc2 1180#define wxEVENT_RANGE_PROPERTY( name , eventType , lastEventType , eventClass ) \
4177a99c
SC
1181 static wxDelegateTypeInfo _typeInfo##name( eventType , lastEventType , CLASSINFO( eventClass ) ) ; \
1182 static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , wxT(#name) , &_typeInfo##name , NULL , wxxVariant() ) ; \
1183
584e6074
SC
1184// ----------------------------------------------------------------------------
1185// Implementation Helper for Simple Properties
1186// ----------------------------------------------------------------------------
1187
9dabddc2 1188#define wxIMPLEMENT_PROPERTY(name, type) \
584e6074
SC
1189private:\
1190 type m_##name; \
1191public: \
1192 void Set##name( type const & p) { m_##name = p; } \
1193 type const & Get##name() const { return m_##name; }
1194
a095505c
SC
1195// ----------------------------------------------------------------------------
1196// Handler Info
1197//
1198// this is describing an event sink
1199// ----------------------------------------------------------------------------
1200
492f9a9e 1201class WXDLLIMPEXP_BASE wxHandlerInfo
a095505c 1202{
492f9a9e 1203 friend class WXDLLIMPEXP_BASE wxDynamicClassInfo ;
a095505c 1204public :
ab0881c7 1205 wxHandlerInfo(wxHandlerInfo* &iter,
492f9a9e 1206 wxClassInfo* itsClass,
ab0881c7
VS
1207 const wxString& name,
1208 wxObjectEventFunction address,
1209 const wxClassInfo* eventClassInfo) :
1210 m_eventFunction(address),
1211 m_name(name),
492f9a9e
SC
1212 m_eventClassInfo(eventClassInfo) ,
1213 m_itsClass(itsClass)
ae820c69
SC
1214 {
1215 m_next = NULL ;
1216 if ( iter == NULL )
1217 iter = this ;
1218 else
1219 {
1220 wxHandlerInfo* i = iter ;
1221 while( i->m_next )
1222 i = i->m_next ;
1223
1224 i->m_next = this ;
1225 }
1226 }
1227
1c263d56
SC
1228 ~wxHandlerInfo() ;
1229
ae820c69 1230 // return the name of this handler
cab1a605 1231 const wxString& GetName() const { return m_name ; }
ae820c69
SC
1232
1233 // return the class info of the event
cab1a605 1234 const wxClassInfo *GetEventClassInfo() const { return m_eventClassInfo ; }
ae820c69
SC
1235
1236 // get the handler function pointer
cab1a605 1237 wxObjectEventFunction GetEventFunction() const { return m_eventFunction ; }
ae820c69
SC
1238
1239 // returns NULL if this is the last handler of this class
1240 wxHandlerInfo* GetNext() const { return m_next ; }
492f9a9e
SC
1241
1242 // return the class this property is declared in
1243 const wxClassInfo* GetDeclaringClass() const { return m_itsClass ; }
1244
4393b50c 1245private :
517fb871 1246 wxObjectEventFunction m_eventFunction ;
ae820c69 1247 wxString m_name;
517fb871
VS
1248 const wxClassInfo* m_eventClassInfo ;
1249 wxHandlerInfo* m_next ;
492f9a9e 1250 wxClassInfo* m_itsClass ;
a095505c
SC
1251};
1252
9dabddc2 1253#define wxHANDLER(name,eventClassType) \
f7476b53 1254 static wxHandlerInfo _handlerInfo##name( first , class_t::GetClassInfoStatic() , wxT(#name) , (wxObjectEventFunction) (wxEventFunction) &name , CLASSINFO( eventClassType ) ) ;
a095505c 1255
9dabddc2 1256#define wxBEGIN_HANDLERS_TABLE(theClass) \
2d51f067 1257 wxHandlerInfo *theClass::GetHandlersStatic() \
ae820c69
SC
1258{ \
1259 typedef theClass class_t; \
1260 static wxHandlerInfo* first = NULL ;
a095505c 1261
9dabddc2 1262#define wxEND_HANDLERS_TABLE() \
ae820c69 1263 return first ; }
a095505c
SC
1264
1265// ----------------------------------------------------------------------------
1266// Constructor Bridges
1267//
1268// allow to set up constructors with params during runtime
1269// ----------------------------------------------------------------------------
1270
1271class WXDLLIMPEXP_BASE wxConstructorBridge
1272{
1273public :
583150e3 1274 virtual void Create(wxObject * &o, wxxVariant *args) = 0;
a095505c
SC
1275};
1276
583150e3
SC
1277// a direct constructor bridge calls the operator new for this class and
1278// passes all params to the constructor. needed for classes that cannot be
1279// instantiated using alloc-create semantics
1280class WXDLLIMPEXP_BASE wxDirectConstructorBrigde : public wxConstructorBridge
1281{
1282public :
1283 virtual void Create(wxObject * &o, wxxVariant *args) = 0;
1284} ;
1285
a095505c
SC
1286// Creator Bridges for all Numbers of Params
1287
1288// no params
1289
1290template<typename Class>
1291struct wxConstructorBridge_0 : public wxConstructorBridge
1292{
583150e3 1293 void Create(wxObject * &o, wxxVariant *)
a095505c
SC
1294 {
1295 Class *obj = dynamic_cast<Class*>(o);
1296 obj->Create();
1297 }
1298};
1299
1300struct wxConstructorBridge_Dummy : public wxConstructorBridge
1301{
583150e3 1302 void Create(wxObject *&, wxxVariant *)
a095505c
SC
1303 {
1304 }
1305} ;
1306
9dabddc2 1307#define wxCONSTRUCTOR_0(klass) \
517fb871 1308 wxConstructorBridge_0<klass> constructor##klass ; \
bb7eff4c
SC
1309 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1310 const wxChar *klass::ms_constructorProperties[] = { NULL } ; \
1311 const int klass::ms_constructorPropertiesCount = 0 ;
a095505c 1312
9dabddc2 1313#define wxCONSTRUCTOR_DUMMY(klass) \
517fb871 1314 wxConstructorBridge_Dummy constructor##klass ; \
bb7eff4c
SC
1315 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1316 const wxChar *klass::ms_constructorProperties[] = { NULL } ; \
1317 const int klass::ms_constructorPropertiesCount = 0 ;
a095505c
SC
1318
1319// 1 param
1320
1321template<typename Class, typename T0>
1322struct wxConstructorBridge_1 : public wxConstructorBridge
1323{
583150e3 1324 void Create(wxObject * &o, wxxVariant *args)
a095505c
SC
1325 {
1326 Class *obj = dynamic_cast<Class*>(o);
1327 obj->Create(
9dabddc2 1328 args[0].wxTEMPLATED_MEMBER_CALL(Get , T0)
ae820c69 1329 );
a095505c
SC
1330 }
1331};
1332
9dabddc2 1333#define wxCONSTRUCTOR_1(klass,t0,v0) \
517fb871 1334 wxConstructorBridge_1<klass,t0> constructor##klass ; \
bb7eff4c
SC
1335 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1336 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) } ; \
1337 const int klass::ms_constructorPropertiesCount = 1 ;
a095505c
SC
1338
1339// 2 params
1340
1341template<typename Class,
ae820c69 1342typename T0, typename T1>
a095505c
SC
1343struct wxConstructorBridge_2 : public wxConstructorBridge
1344{
583150e3 1345 void Create(wxObject * &o, wxxVariant *args)
a095505c
SC
1346 {
1347 Class *obj = dynamic_cast<Class*>(o);
1348 obj->Create(
9dabddc2
SC
1349 args[0].wxTEMPLATED_MEMBER_CALL(Get , T0) ,
1350 args[1].wxTEMPLATED_MEMBER_CALL(Get , T1)
ae820c69 1351 );
a095505c
SC
1352 }
1353};
1354
9dabddc2 1355#define wxCONSTRUCTOR_2(klass,t0,v0,t1,v1) \
517fb871 1356 wxConstructorBridge_2<klass,t0,t1> constructor##klass ; \
bb7eff4c
SC
1357 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1358 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) } ; \
1359 const int klass::ms_constructorPropertiesCount = 2;
583150e3
SC
1360
1361// direct constructor version
1362
1363template<typename Class,
1364typename T0, typename T1>
1365struct wxDirectConstructorBridge_2 : public wxDirectConstructorBrigde
1366{
1367 void Create(wxObject * &o, wxxVariant *args)
1368 {
1369 o = new Class(
9dabddc2
SC
1370 args[0].wxTEMPLATED_MEMBER_CALL(Get , T0) ,
1371 args[1].wxTEMPLATED_MEMBER_CALL(Get , T1)
583150e3
SC
1372 );
1373 }
1374};
1375
9dabddc2 1376#define wxDIRECT_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
583150e3 1377 wxDirectConstructorBridge_2<klass,t0,t1> constructor##klass ; \
bb7eff4c
SC
1378 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1379 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) } ; \
1380 const int klass::ms_constructorPropertiesCount = 2;
a095505c 1381
583150e3 1382
a095505c
SC
1383// 3 params
1384
1385template<typename Class,
ae820c69 1386typename T0, typename T1, typename T2>
a095505c
SC
1387struct wxConstructorBridge_3 : public wxConstructorBridge
1388{
583150e3 1389 void Create(wxObject * &o, wxxVariant *args)
a095505c
SC
1390 {
1391 Class *obj = dynamic_cast<Class*>(o);
1392 obj->Create(
9dabddc2
SC
1393 args[0].wxTEMPLATED_MEMBER_CALL(Get , T0) ,
1394 args[1].wxTEMPLATED_MEMBER_CALL(Get , T1) ,
1395 args[2].wxTEMPLATED_MEMBER_CALL(Get , T2)
ae820c69 1396 );
a095505c
SC
1397 }
1398};
1399
9dabddc2 1400#define wxCONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
517fb871 1401 wxConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \
bb7eff4c
SC
1402 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1403 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) } ; \
1404 const int klass::ms_constructorPropertiesCount = 3 ;
a095505c
SC
1405
1406// 4 params
1407
1408template<typename Class,
ae820c69 1409typename T0, typename T1, typename T2, typename T3>
a095505c
SC
1410struct wxConstructorBridge_4 : public wxConstructorBridge
1411{
583150e3 1412 void Create(wxObject * &o, wxxVariant *args)
a095505c
SC
1413 {
1414 Class *obj = dynamic_cast<Class*>(o);
1415 obj->Create(
9dabddc2
SC
1416 args[0].wxTEMPLATED_MEMBER_CALL(Get , T0) ,
1417 args[1].wxTEMPLATED_MEMBER_CALL(Get , T1) ,
1418 args[2].wxTEMPLATED_MEMBER_CALL(Get , T2) ,
1419 args[3].wxTEMPLATED_MEMBER_CALL(Get , T3)
ae820c69 1420 );
a095505c
SC
1421 }
1422};
1423
9dabddc2 1424#define wxCONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
517fb871 1425 wxConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass ; \
bb7eff4c
SC
1426 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1427 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) } ; \
1428 const int klass::ms_constructorPropertiesCount = 4 ;
fbbdc52c
SC
1429
1430// 5 params
1431
1432template<typename Class,
ae820c69 1433typename T0, typename T1, typename T2, typename T3, typename T4>
fbbdc52c
SC
1434struct wxConstructorBridge_5 : public wxConstructorBridge
1435{
583150e3 1436 void Create(wxObject * &o, wxxVariant *args)
fbbdc52c
SC
1437 {
1438 Class *obj = dynamic_cast<Class*>(o);
1439 obj->Create(
9dabddc2
SC
1440 args[0].wxTEMPLATED_MEMBER_CALL(Get , T0) ,
1441 args[1].wxTEMPLATED_MEMBER_CALL(Get , T1) ,
1442 args[2].wxTEMPLATED_MEMBER_CALL(Get , T2) ,
1443 args[3].wxTEMPLATED_MEMBER_CALL(Get , T3) ,
1444 args[4].wxTEMPLATED_MEMBER_CALL(Get , T4)
ae820c69 1445 );
fbbdc52c
SC
1446 }
1447};
1448
9dabddc2 1449#define wxCONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
ae820c69 1450 wxConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass ; \
bb7eff4c
SC
1451 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1452 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) } ; \
1453 const int klass::ms_constructorPropertiesCount = 5;
fa08490f
SC
1454
1455// 6 params
1456
1457template<typename Class,
ae820c69 1458typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
fa08490f
SC
1459struct wxConstructorBridge_6 : public wxConstructorBridge
1460{
583150e3 1461 void Create(wxObject * &o, wxxVariant *args)
fa08490f
SC
1462 {
1463 Class *obj = dynamic_cast<Class*>(o);
1464 obj->Create(
9dabddc2
SC
1465 args[0].wxTEMPLATED_MEMBER_CALL(Get , T0) ,
1466 args[1].wxTEMPLATED_MEMBER_CALL(Get , T1) ,
1467 args[2].wxTEMPLATED_MEMBER_CALL(Get , T2) ,
1468 args[3].wxTEMPLATED_MEMBER_CALL(Get , T3) ,
1469 args[4].wxTEMPLATED_MEMBER_CALL(Get , T4) ,
1470 args[5].wxTEMPLATED_MEMBER_CALL(Get , T5)
ae820c69 1471 );
fa08490f
SC
1472 }
1473};
1474
9dabddc2 1475#define wxCONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
583150e3 1476 wxConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
bb7eff4c
SC
1477 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1478 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) } ; \
1479 const int klass::ms_constructorPropertiesCount = 6;
583150e3
SC
1480
1481// direct constructor version
1482
2abce515
SC
1483template<typename Class,
1484typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
583150e3 1485struct wxDirectConstructorBridge_6 : public wxDirectConstructorBrigde
2abce515 1486{
583150e3 1487 void Create(wxObject * &o, wxxVariant *args)
2abce515 1488 {
583150e3 1489 o = new Class(
9dabddc2
SC
1490 args[0].wxTEMPLATED_MEMBER_CALL(Get , T0) ,
1491 args[1].wxTEMPLATED_MEMBER_CALL(Get , T1) ,
1492 args[2].wxTEMPLATED_MEMBER_CALL(Get , T2) ,
1493 args[3].wxTEMPLATED_MEMBER_CALL(Get , T3) ,
1494 args[4].wxTEMPLATED_MEMBER_CALL(Get , T4) ,
1495 args[5].wxTEMPLATED_MEMBER_CALL(Get , T5)
2abce515
SC
1496 );
1497 }
1498};
1499
9dabddc2 1500#define wxDIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
2abce515 1501 wxDirectConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \
bb7eff4c
SC
1502 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1503 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) } ; \
1504 const int klass::ms_constructorPropertiesCount = 6;
fa08490f 1505
a06bb527
SC
1506// 7 params
1507
1508template<typename Class,
ae820c69 1509typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
a06bb527
SC
1510struct wxConstructorBridge_7 : public wxConstructorBridge
1511{
583150e3 1512 void Create(wxObject * &o, wxxVariant *args)
a06bb527
SC
1513 {
1514 Class *obj = dynamic_cast<Class*>(o);
1515 obj->Create(
9dabddc2
SC
1516 args[0].wxTEMPLATED_MEMBER_CALL(Get , T0) ,
1517 args[1].wxTEMPLATED_MEMBER_CALL(Get , T1) ,
1518 args[2].wxTEMPLATED_MEMBER_CALL(Get , T2) ,
1519 args[3].wxTEMPLATED_MEMBER_CALL(Get , T3) ,
1520 args[4].wxTEMPLATED_MEMBER_CALL(Get , T4) ,
1521 args[5].wxTEMPLATED_MEMBER_CALL(Get , T5) ,
1522 args[6].wxTEMPLATED_MEMBER_CALL(Get , T6)
ae820c69 1523 );
a06bb527
SC
1524 }
1525};
1526
9dabddc2 1527#define wxCONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
ae820c69 1528 wxConstructorBridge_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass ; \
bb7eff4c
SC
1529 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1530 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) , wxT(#v6) } ; \
1531 const int klass::ms_constructorPropertiesCount = 7;
a095505c 1532
a06bb527
SC
1533// 8 params
1534
1535template<typename Class,
ae820c69 1536typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
a06bb527
SC
1537struct wxConstructorBridge_8 : public wxConstructorBridge
1538{
583150e3 1539 void Create(wxObject * &o, wxxVariant *args)
a06bb527
SC
1540 {
1541 Class *obj = dynamic_cast<Class*>(o);
1542 obj->Create(
9dabddc2
SC
1543 args[0].wxTEMPLATED_MEMBER_CALL(Get , T0) ,
1544 args[1].wxTEMPLATED_MEMBER_CALL(Get , T1) ,
1545 args[2].wxTEMPLATED_MEMBER_CALL(Get , T2) ,
1546 args[3].wxTEMPLATED_MEMBER_CALL(Get , T3) ,
1547 args[4].wxTEMPLATED_MEMBER_CALL(Get , T4) ,
1548 args[5].wxTEMPLATED_MEMBER_CALL(Get , T5) ,
1549 args[6].wxTEMPLATED_MEMBER_CALL(Get , T6) ,
1550 args[7].wxTEMPLATED_MEMBER_CALL(Get , T7)
ae820c69 1551 );
a06bb527
SC
1552 }
1553};
1554
9dabddc2 1555#define wxCONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
ae820c69 1556 wxConstructorBridge_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass ; \
bb7eff4c
SC
1557 wxConstructorBridge* klass::ms_constructor = &constructor##klass ; \
1558 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) , wxT(#v6) , wxT(#v7) } ; \
1559 const int klass::ms_constructorPropertiesCount = 8;
a095505c
SC
1560// ----------------------------------------------------------------------------
1561// wxClassInfo
1562// ----------------------------------------------------------------------------
1563
1564typedef wxObject *(*wxObjectConstructorFn)(void);
fa08490f 1565typedef wxObject* (*wxVariantToObjectConverter)( wxxVariant &data ) ;
a095505c 1566typedef wxxVariant (*wxObjectToVariantConverter)( wxObject* ) ;
492f9a9e 1567
79902653
VS
1568class WXDLLIMPEXP_BASE wxWriter;
1569class WXDLLIMPEXP_BASE wxPersister;
492f9a9e 1570
9c8046dd 1571typedef bool (*wxObjectStreamingCallback) ( const wxObject *, wxWriter * , wxPersister * , wxxVariantArray & ) ;
a095505c
SC
1572
1573class WXDLLIMPEXP_BASE wxClassInfo
1574{
79902653
VS
1575 friend class WXDLLIMPEXP_BASE wxPropertyInfo ;
1576 friend class WXDLLIMPEXP_BASE wxHandlerInfo ;
a095505c
SC
1577public:
1578 wxClassInfo(const wxClassInfo **_Parents,
ae820c69
SC
1579 const wxChar *_UnitName,
1580 const wxChar *_ClassName,
1581 int size,
1582 wxObjectConstructorFn ctor ,
1583 wxPropertyInfo *_Props ,
1584 wxHandlerInfo *_Handlers ,
1585 wxConstructorBridge* _Constructor ,
1586 const wxChar ** _ConstructorProperties ,
1587 const int _ConstructorPropertiesCount ,
1588 wxVariantToObjectConverter _PtrConverter1 ,
1589 wxVariantToObjectConverter _Converter2 ,
9c8046dd
SC
1590 wxObjectToVariantConverter _Converter3 ,
1591 wxObjectStreamingCallback _streamingCallback = NULL
583150e3
SC
1592 ) :
1593
ab0881c7
VS
1594 m_className(_ClassName),
1595 m_objectSize(size),
1596 m_objectConstructor(ctor),
1597 m_next(sm_first),
1598 m_firstProperty(_Props),
1599 m_firstHandler(_Handlers),
1600 m_parents(_Parents),
583150e3 1601 m_unitName(_UnitName),
ab0881c7
VS
1602 m_constructor(_Constructor),
1603 m_constructorProperties(_ConstructorProperties),
1604 m_constructorPropertiesCount(_ConstructorPropertiesCount),
1605 m_variantOfPtrToObjectConverter(_PtrConverter1),
1606 m_variantToObjectConverter(_Converter2),
1607 m_objectToVariantConverter(_Converter3),
1608 m_streamingCallback(_streamingCallback)
ae820c69
SC
1609 {
1610 sm_first = this;
1611 Register() ;
1612 }
1613
ab0881c7 1614 wxClassInfo(const wxChar *_UnitName, const wxChar *_ClassName,
583150e3 1615 const wxClassInfo **_Parents) :
ab0881c7
VS
1616 m_className(_ClassName),
1617 m_objectSize(0),
1618 m_objectConstructor(NULL),
1619 m_next(sm_first),
1620 m_firstProperty(NULL),
1621 m_firstHandler(NULL),
1622 m_parents(_Parents),
1623 m_unitName(_UnitName),
1624 m_constructor(NULL),
1625 m_constructorProperties(NULL),
1626 m_constructorPropertiesCount(0),
1627 m_variantOfPtrToObjectConverter(NULL),
1628 m_variantToObjectConverter(NULL),
1629 m_objectToVariantConverter(NULL),
1630 m_streamingCallback(NULL)
ae820c69
SC
1631 {
1632 sm_first = this;
1633 Register() ;
1634 }
2d51f067 1635
aeec2045 1636 virtual ~wxClassInfo() ;
a095505c 1637
ab6e4913
SC
1638 // allocates an instance of this class, this object does not have to be initialized or fully constructed
1639 // as this call will be followed by a call to Create
1640 virtual wxObject *AllocateObject() const { return m_objectConstructor ? (*m_objectConstructor)() : 0; }
1641
1642 // 'old naming' for AllocateObject staying here for backward compatibility
1643 wxObject *CreateObject() const { return AllocateObject() ; }
a095505c 1644
583150e3
SC
1645 // direct construction call for classes that cannot construct instances via alloc/create
1646 wxObject *ConstructObject(int ParamCount, wxxVariant *Params) const
1647 {
8f2b1cfd
SC
1648 if ( ParamCount != m_constructorPropertiesCount )
1649 {
1650 wxLogError( _("Illegal Parameter Count for ConstructObject Method") ) ;
1651 return NULL ;
1652 }
583150e3
SC
1653 wxObject *object = NULL ;
1654 m_constructor->Create( object , Params ) ;
1655 return object ;
1656 }
1657
1658 bool NeedsDirectConstruction() const { return dynamic_cast<wxDirectConstructorBrigde*>( m_constructor) != NULL ; }
1659
a095505c 1660 const wxChar *GetClassName() const { return m_className; }
79fdfb35
SC
1661 const wxChar *GetBaseClassName1() const
1662 { return m_parents[0] ? m_parents[0]->GetClassName() : NULL; }
1663 const wxChar *GetBaseClassName2() const
1664 { return (m_parents[0] && m_parents[1]) ? m_parents[1]->GetClassName() : NULL; }
9c8046dd 1665 const wxChar *GetIncludeName() const { return m_unitName ; }
a095505c
SC
1666 const wxClassInfo **GetParents() const { return m_parents; }
1667 int GetSize() const { return m_objectSize; }
1668
1669 wxObjectConstructorFn GetConstructor() const { return m_objectConstructor; }
1670 static const wxClassInfo *GetFirst() { return sm_first; }
1671 const wxClassInfo *GetNext() const { return m_next; }
1672 static wxClassInfo *FindClass(const wxChar *className);
1673
ae820c69
SC
1674 // Climb upwards through inheritance hierarchy.
1675 // Dual inheritance is catered for.
a095505c
SC
1676
1677 bool IsKindOf(const wxClassInfo *info) const
1678 {
517fb871
VS
1679 if ( info != 0 )
1680 {
1681 if ( info == this )
1682 return true ;
1683
1684 for ( int i = 0 ; m_parents[i] ; ++ i )
1685 {
1686 if ( m_parents[i]->IsKindOf( info ) )
1687 return true ;
1688 }
1689 }
1690 return false ;
a095505c
SC
1691 }
1692
ab0881c7
VS
1693 // if there is a callback registered with that class it will be called
1694 // before this object will be written to disk, it can veto streaming out
1695 // this object by returning false, if this class has not registered a
1696 // callback, the search will go up the inheritance tree if no callback has
1697 // been registered true will be returned by default
9c8046dd
SC
1698 bool BeforeWriteObject( const wxObject *obj, wxWriter *streamer , wxPersister *persister , wxxVariantArray &metadata) const ;
1699
1700 // gets the streaming callback from this class or any superclass
1701 wxObjectStreamingCallback GetStreamingCallback() const ;
1702
45bbbc54 1703#if WXWIN_COMPATIBILITY_2_4
a095505c 1704 // Initializes parent pointers and hash table for fast searching.
45bbbc54 1705 wxDEPRECATED( static void InitializeClasses() );
a095505c 1706 // Cleans up hash table used for fast searching.
45bbbc54 1707 wxDEPRECATED( static void CleanUpClasses() );
aa8d7c2f 1708#endif
45bbbc54 1709 static void CleanUp();
75890a3f 1710
517fb871
VS
1711 // returns the first property
1712 const wxPropertyInfo* GetFirstProperty() const { return m_firstProperty ; }
a095505c 1713
517fb871
VS
1714 // returns the first handler
1715 const wxHandlerInfo* GetFirstHandler() const { return m_firstHandler ; }
a095505c 1716
ab6e4913
SC
1717 // Call the Create upon an instance of the class, in the end the object is fully
1718 // initialized
fa08490f 1719 virtual void Create (wxObject *object, int ParamCount, wxxVariant *Params) const
ae820c69 1720 {
8f2b1cfd
SC
1721 if ( ParamCount != m_constructorPropertiesCount )
1722 {
1723 wxLogError( _("Illegal Parameter Count for Create Method") ) ;
1724 return ;
1725 }
ae820c69
SC
1726 m_constructor->Create( object , Params ) ;
1727 }
a095505c 1728
517fb871
VS
1729 // get number of parameters for constructor
1730 virtual int GetCreateParamCount() const { return m_constructorPropertiesCount; }
a095505c 1731
ab6e4913
SC
1732 // get n-th constructor parameter
1733 virtual const wxChar* GetCreateParamName(int n) const { return m_constructorProperties[n] ; }
a095505c 1734
ab6e4913
SC
1735 // Runtime access to objects for simple properties (get/set) by property name, and variant data
1736 virtual void SetProperty (wxObject *object, const wxChar *propertyName, const wxxVariant &value) const ;
1737 virtual wxxVariant GetProperty (wxObject *object, const wxChar *propertyName) const;
1738
1739 // Runtime access to objects for collection properties by property name
1740 virtual wxxVariantArray GetPropertyCollection(wxObject *object, const wxChar *propertyName) const ;
16a45a23 1741 virtual void AddToPropertyCollection(wxObject *object, const wxChar *propertyName , const wxxVariant& value) const ;
a095505c 1742
ae820c69
SC
1743 // we must be able to cast variants to wxObject pointers, templates seem not to be suitable
1744 wxObject* VariantToInstance( wxxVariant &data ) const
cab1a605
WS
1745 {
1746 if ( data.GetTypeInfo()->GetKind() == wxT_OBJECT )
1747 return m_variantToObjectConverter( data ) ;
1748 else
1749 return m_variantOfPtrToObjectConverter( data ) ;
ae820c69 1750 }
fa08490f 1751
ae820c69 1752 wxxVariant InstanceToVariant( wxObject *object ) const { return m_objectToVariantConverter( object ) ; }
4393b50c 1753
517fb871 1754 // find property by name
fbbdc52c
SC
1755 virtual const wxPropertyInfo *FindPropertyInfo (const wxChar *PropertyName) const ;
1756
517fb871 1757 // find handler by name
fbbdc52c 1758 virtual const wxHandlerInfo *FindHandlerInfo (const wxChar *PropertyName) const ;
a095505c 1759
2d51f067 1760 // find property by name
492f9a9e 1761 virtual wxPropertyInfo *FindPropertyInfoInThisClass (const wxChar *PropertyName) const ;
2d51f067
SC
1762
1763 // find handler by name
492f9a9e 1764 virtual wxHandlerInfo *FindHandlerInfoInThisClass (const wxChar *PropertyName) const ;
ae820c69
SC
1765
1766 // puts all the properties of this class and its superclasses in the map, as long as there is not yet
1767 // an entry with the same name (overriding mechanism)
1768 void GetProperties( wxPropertyInfoMap &map ) const ;
a095505c
SC
1769public:
1770 const wxChar *m_className;
1771 int m_objectSize;
1772 wxObjectConstructorFn m_objectConstructor;
1773
1774 // class info object live in a linked list:
1775 // pointers to its head and the next element in it
1776
1777 static wxClassInfo *sm_first;
1778 wxClassInfo *m_next;
1779
517fb871 1780 // FIXME: this should be private (currently used directly by way too
a095505c
SC
1781 // many clients)
1782 static wxHashTable *sm_classTable;
1783
2d51f067 1784protected :
cab1a605
WS
1785 wxPropertyInfo * m_firstProperty ;
1786 wxHandlerInfo * m_firstHandler ;
a095505c 1787private:
cab1a605
WS
1788 const wxClassInfo** m_parents ;
1789 const wxChar* m_unitName;
fa08490f 1790
cab1a605
WS
1791 wxConstructorBridge* m_constructor ;
1792 const wxChar ** m_constructorProperties ;
1793 const int m_constructorPropertiesCount ;
ae820c69
SC
1794 wxVariantToObjectConverter m_variantOfPtrToObjectConverter ;
1795 wxVariantToObjectConverter m_variantToObjectConverter ;
1796 wxObjectToVariantConverter m_objectToVariantConverter ;
9c8046dd 1797 wxObjectStreamingCallback m_streamingCallback ;
2d51f067 1798 const wxPropertyAccessor *FindAccessor (const wxChar *propertyName) const ;
a095505c 1799
a095505c 1800
517fb871 1801 // InitializeClasses() helper
2d51f067 1802 static wxClassInfo *GetBaseByName(const wxChar *name) ;
75890a3f 1803
d1d738f1
VS
1804protected:
1805 // registers the class
1806 void Register();
1807 void Unregister();
a095505c
SC
1808
1809 DECLARE_NO_COPY_CLASS(wxClassInfo)
1810};
1811
2d51f067 1812
a095505c
SC
1813WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name);
1814
2d51f067
SC
1815// ----------------------------------------------------------------------------
1816// wxDynamicObject
1817// ----------------------------------------------------------------------------
1818//
1819// this object leads to having a pure runtime-instantiation
1820
492f9a9e 1821class WXDLLIMPEXP_BASE wxDynamicClassInfo : public wxClassInfo
2d51f067 1822{
8f2b1cfd 1823 friend class WXDLLIMPEXP_BASE wxDynamicObject ;
2d51f067
SC
1824public :
1825 wxDynamicClassInfo( const wxChar *_UnitName, const wxChar *_ClassName , const wxClassInfo* superClass ) ;
1826 virtual ~wxDynamicClassInfo() ;
1827
1828 // constructs a wxDynamicObject with an instance
ab6e4913 1829 virtual wxObject *AllocateObject() const ;
2d51f067
SC
1830
1831 // Call the Create method for a class
1832 virtual void Create (wxObject *object, int ParamCount, wxxVariant *Params) const ;
1833
1834 // get number of parameters for constructor
1835 virtual int GetCreateParamCount() const ;
1836
1837 // get i-th constructor parameter
1838 virtual const wxChar* GetCreateParamName(int i) const ;
1839
1840 // Runtime access to objects by property name, and variant data
1841 virtual void SetProperty (wxObject *object, const wxChar *PropertyName, const wxxVariant &Value) const ;
1842 virtual wxxVariant GetProperty (wxObject *object, const wxChar *PropertyName) const ;
1843
2abce515 1844 // adds a property to this class at runtime
2d51f067 1845 void AddProperty( const wxChar *propertyName , const wxTypeInfo* typeInfo ) ;
2abce515
SC
1846
1847 // removes an existing runtime-property
1848 void RemoveProperty( const wxChar *propertyName ) ;
1849
492f9a9e
SC
1850 // renames an existing runtime-property
1851 void RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName ) ;
1852
2abce515 1853 // as a handler to this class at runtime
2d51f067 1854 void AddHandler( const wxChar *handlerName , wxObjectEventFunction address , const wxClassInfo* eventClassInfo ) ;
2abce515
SC
1855
1856 // removes an existing runtime-handler
1857 void RemoveHandler( const wxChar *handlerName ) ;
492f9a9e
SC
1858
1859 // renames an existing runtime-handler
1860 void RenameHandler( const wxChar *oldHandlerName , const wxChar *newHandlerName ) ;
8f2b1cfd
SC
1861private :
1862 struct wxDynamicClassInfoInternal ;
1863 wxDynamicClassInfoInternal* m_data ;
2d51f067
SC
1864} ;
1865
a095505c
SC
1866// ----------------------------------------------------------------------------
1867// Dynamic class macros
1868// ----------------------------------------------------------------------------
1869
1870#define _DECLARE_DYNAMIC_CLASS(name) \
1871 public: \
bb7eff4c
SC
1872 static wxClassInfo ms_classInfo; \
1873 static const wxClassInfo* ms_classParents[] ; \
ae820c69
SC
1874 static wxPropertyInfo* GetPropertiesStatic() ; \
1875 static wxHandlerInfo* GetHandlersStatic() ; \
1876 static wxClassInfo *GetClassInfoStatic() \
bb7eff4c 1877{ return &name::ms_classInfo; } \
2abce515 1878 virtual wxClassInfo *GetClassInfo() const \
bb7eff4c 1879{ return &name::ms_classInfo; }
a095505c 1880
bb7eff4c
SC
1881/*
1882#define _DECLARE_DYNAMIC_CLASS(name) \
1883 public: \
1884 static wxClassInfo ms_class##name; \
1885 static const wxClassInfo* ms_classParents##name[] ; \
1886 static wxPropertyInfo* GetPropertiesStatic() ; \
1887 static wxHandlerInfo* GetHandlersStatic() ; \
1888 static wxClassInfo *GetClassInfoStatic() \
1889{ return &name::ms_class##name; } \
1890 virtual wxClassInfo *GetClassInfo() const \
1891{ return &name::ms_class##name; }
1892*/
a095505c 1893#define DECLARE_DYNAMIC_CLASS(name) \
bb7eff4c
SC
1894 static wxConstructorBridge* ms_constructor ; \
1895 static const wxChar * ms_constructorProperties[] ; \
1896 static const int ms_constructorPropertiesCount ; \
f0b7eadf 1897 _DECLARE_DYNAMIC_CLASS(name)
a095505c
SC
1898
1899#define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
1900 DECLARE_NO_ASSIGN_CLASS(name) \
1901 DECLARE_DYNAMIC_CLASS(name)
1902
1903#define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \
1904 DECLARE_NO_COPY_CLASS(name) \
1905 DECLARE_DYNAMIC_CLASS(name)
1906
1907#define DECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name)
1908#define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
1909
1910// -----------------------------------
1911// for concrete classes
1912// -----------------------------------
1913
ae820c69 1914// Single inheritance with one base class
a095505c 1915
583150e3 1916#define _TYPEINFO_CLASSES(n , toString , fromString ) \
bb7eff4c
SC
1917 wxClassTypeInfo s_typeInfo##n(wxT_OBJECT , &n::ms_classInfo , toString , fromString , typeid(n).name()) ; \
1918 wxClassTypeInfo s_typeInfoPtr##n(wxT_OBJECT_PTR , &n::ms_classInfo , toString , fromString , typeid(n*).name()) ;
492f9a9e 1919
9c8046dd 1920#define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit , callback) \
ae820c69
SC
1921 wxObject* wxConstructorFor##name() \
1922{ return new name; } \
bb7eff4c 1923 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo ,NULL } ; \
2c4c3987 1924 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.wxTEMPLATED_MEMBER_CALL(Get , name*) ; } \
ae820c69 1925 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
bb7eff4c 1926 wxClassInfo name::ms_classInfo(name::ms_classParents , wxT(unit) , wxT(#name), \
ae820c69
SC
1927 (int) sizeof(name), \
1928 (wxObjectConstructorFn) wxConstructorFor##name , \
bb7eff4c
SC
1929 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::ms_constructor , name::ms_constructorProperties , \
1930 name::ms_constructorPropertiesCount , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name , callback);
fa08490f 1931
9c8046dd 1932#define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \
ae820c69
SC
1933 wxObject* wxConstructorFor##name() \
1934{ return new name; } \
bb7eff4c 1935 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo ,NULL } ; \
2c4c3987
SC
1936 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return &data.wxTEMPLATED_MEMBER_CALL(Get , name) ; } \
1937 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.wxTEMPLATED_MEMBER_CALL(Get , name*) ; } \
ae820c69 1938 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
bb7eff4c 1939 wxClassInfo name::ms_classInfo(name::ms_classParents , wxT(unit) , wxT(#name), \
ae820c69
SC
1940 (int) sizeof(name), \
1941 (wxObjectConstructorFn) wxConstructorFor##name , \
bb7eff4c
SC
1942 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::ms_constructor , name::ms_constructorProperties, \
1943 name::ms_constructorPropertiesCount , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name, callback);
fa08490f
SC
1944
1945#define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \
9c8046dd 1946 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" , NULL ) \
583150e3 1947 _TYPEINFO_CLASSES(name, NULL , NULL) \
ae820c69
SC
1948 const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
1949 const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
9dabddc2 1950 wxCONSTRUCTOR_DUMMY( name )
a095505c
SC
1951
1952#define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \
9c8046dd 1953 _IMPLEMENT_DYNAMIC_CLASS( name , basename , "" , NULL ) \
583150e3
SC
1954 _TYPEINFO_CLASSES(name, NULL , NULL) \
1955 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
ae820c69 1956 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
9dabddc2 1957 wxCONSTRUCTOR_DUMMY( name )
a095505c
SC
1958
1959#define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \
583150e3
SC
1960 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , NULL ) \
1961 _TYPEINFO_CLASSES(name, NULL , NULL)
9c8046dd
SC
1962
1963#define IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name , basename , unit , callback ) \
583150e3
SC
1964 _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , &callback ) \
1965 _TYPEINFO_CLASSES(name, NULL , NULL)
a095505c 1966
fa08490f 1967#define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \
583150e3
SC
1968 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit , NULL ) \
1969 _TYPEINFO_CLASSES(name, NULL , NULL)
1970
1971#define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name , basename , unit , toString , fromString ) \
1972 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit , NULL ) \
1973 _TYPEINFO_CLASSES(name, toString , fromString)
fa08490f 1974
4393b50c 1975// this is for classes that do not derive from wxobject, there are no creators for these
a095505c
SC
1976
1977#define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name , unit ) \
bb7eff4c 1978 const wxClassInfo* name::ms_classParents[] = { NULL } ; \
432968bf 1979 wxClassInfo name::ms_classInfo(name::ms_classParents , wxEmptyString , wxT(#name), \
ae820c69
SC
1980 (int) sizeof(name), \
1981 (wxObjectConstructorFn) 0 , \
1982 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1983 0 , 0 , 0 ); \
583150e3 1984 _TYPEINFO_CLASSES(name, NULL , NULL)
a095505c
SC
1985
1986// this is for subclasses that still do not derive from wxobject
1987
1988#define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name , basename, unit ) \
bb7eff4c 1989 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo ,NULL } ; \
432968bf 1990 wxClassInfo name::ms_classInfo(name::ms_classParents , wxEmptyString , wxT(#name), \
ae820c69
SC
1991 (int) sizeof(name), \
1992 (wxObjectConstructorFn) 0 , \
1993 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
1994 0 , 0 , 0 ); \
583150e3 1995 _TYPEINFO_CLASSES(name, NULL , NULL)
ae820c69
SC
1996
1997
1998// Multiple inheritance with two base classes
a095505c
SC
1999
2000#define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit) \
ae820c69
SC
2001 wxObject* wxConstructorFor##name() \
2002{ return new name; } \
bb7eff4c 2003 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo ,&basename2::ms_classInfo , NULL } ; \
2c4c3987 2004 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.wxTEMPLATED_MEMBER_CALL(Get , name*) ; } \
ae820c69 2005 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
bb7eff4c 2006 wxClassInfo name::ms_classInfo(name::ms_classParents , wxT(unit) , wxT(#name), \
ae820c69
SC
2007 (int) sizeof(name), \
2008 (wxObjectConstructorFn) wxConstructorFor##name , \
bb7eff4c
SC
2009 name::GetPropertiesStatic(),name::GetHandlersStatic(),name::ms_constructor , name::ms_constructorProperties , \
2010 name::ms_constructorPropertiesCount , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
a095505c
SC
2011
2012#define IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2) \
ae820c69 2013 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , "") \
583150e3 2014 _TYPEINFO_CLASSES(name, NULL , NULL) \
ae820c69
SC
2015 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
2016 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
9dabddc2 2017 wxCONSTRUCTOR_DUMMY( name )
a095505c
SC
2018
2019#define IMPLEMENT_DYNAMIC_CLASS2_XTI( name , basename , basename2, unit) \
583150e3
SC
2020 _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , unit) \
2021 _TYPEINFO_CLASSES(name, NULL , NULL)
2022
a095505c
SC
2023
2024// -----------------------------------
2025// for abstract classes
2026// -----------------------------------
2027
ae820c69 2028// Single inheritance with one base class
a095505c
SC
2029
2030#define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
bb7eff4c 2031 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo ,NULL } ; \
2c4c3987
SC
2032 wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.wxTEMPLATED_MEMBER_CALL(Get , name*) ; } \
2033 wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.wxTEMPLATED_MEMBER_CALL(Get , name*) ; } \
ae820c69 2034 wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \
432968bf 2035 wxClassInfo name::ms_classInfo(name::ms_classParents , wxEmptyString , wxT(#name), \
ae820c69
SC
2036 (int) sizeof(name), \
2037 (wxObjectConstructorFn) 0 , \
2038 name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \
2039 0 , wxVariantOfPtrToObjectConverter##name ,wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
583150e3 2040 _TYPEINFO_CLASSES(name, NULL , NULL)
a095505c
SC
2041
2042#define IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
ae820c69
SC
2043 _IMPLEMENT_ABSTRACT_CLASS( name , basename ) \
2044 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
2045 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; }
a095505c 2046
ae820c69 2047// Multiple inheritance with two base classes
a095505c
SC
2048
2049#define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
bb7eff4c 2050 wxClassInfo name::ms_classInfo(wxT(#name), wxT(#basename1), \
ae820c69
SC
2051 wxT(#basename2), (int) sizeof(name), \
2052 (wxObjectConstructorFn) 0);
a095505c
SC
2053
2054#define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
2055#define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
2056
9dabddc2
SC
2057#define wxBEGIN_EVENT_TABLE( a , b ) BEGIN_EVENT_TABLE( a , b )
2058#define wxEND_EVENT_TABLE() END_EVENT_TABLE()
2059
208fd16c
SC
2060// --------------------------------------------------------------------------
2061// Collection Support
2062// --------------------------------------------------------------------------
2063
2abce515 2064template<typename iter , typename collection_t > void wxListCollectionToVariantArray( const collection_t& coll , wxxVariantArray &value )
208fd16c 2065{
2abce515 2066 iter current = coll.GetFirst() ;
208fd16c
SC
2067 while (current)
2068 {
2069 value.Add( new wxxVariant(current->GetData()) ) ;
2070 current = current->GetNext();
2071 }
2072}
2073
2074template<typename collection_t> void wxArrayCollectionToVariantArray( const collection_t& coll , wxxVariantArray &value )
2075{
ae820c69 2076 for( size_t i = 0 ; i < coll.GetCount() ; i++ )
208fd16c
SC
2077 {
2078 value.Add( new wxxVariant(coll[i]) ) ;
2079 }
2080}
2081
2082
aeec2045 2083#endif