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