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