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