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