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