]>
Commit | Line | Data |
---|---|---|
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 |
72 | class WXDLLIMPEXP_BASE wxObject; |
73 | class WXDLLIMPEXP_BASE wxClassInfo; | |
492f9a9e | 74 | class WXDLLIMPEXP_BASE wxDynamicClassInfo; |
a095505c SC |
75 | class WXDLLIMPEXP_BASE wxHashTable; |
76 | class WXDLLIMPEXP_BASE wxObjectRefData; | |
77 | class WXDLLIMPEXP_BASE wxEvent; | |
78 | ||
79 | typedef 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 | ||
95 | struct WXDLLIMPEXP_BASE wxEnumMemberData | |
96 | { | |
517fb871 VS |
97 | const wxChar* m_name; |
98 | int m_value; | |
a095505c SC |
99 | }; |
100 | ||
101 | class WXDLLIMPEXP_BASE wxEnumData | |
102 | { | |
103 | public : | |
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 | |
109 | bool HasEnumMemberValue( const wxChar *name , int *value = NULL ) ; | |
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 | |
113 | int GetEnumMemberValue(const wxChar *name ); | |
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 | |
a095505c | 117 | const wxChar *GetEnumMemberName(int value); |
4393b50c | 118 | |
517fb871 VS |
119 | // returns the number of members in this enum |
120 | int GetEnumCount() { return m_count ; } | |
4393b50c | 121 | |
517fb871 VS |
122 | // returns the value of the nth member |
123 | int GetEnumMemberValueByIndex( int n ) ; | |
4393b50c | 124 | |
517fb871 VS |
125 | // returns the value of the nth member |
126 | const wxChar *GetEnumMemberNameByIndex( int n ) ; | |
a095505c SC |
127 | private : |
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 | |
182 | void wxSetStringToArray( const wxString &s , wxArrayString &array ) ; | |
183 | ||
184 | template<typename e> | |
0886e254 | 185 | void 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 | ||
204 | template<typename e> | |
0886e254 | 205 | void 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 |
238 | template<typename e> |
239 | void 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 | ||
258 | template<typename e> | |
259 | void 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 | |
312 | enum 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 |
340 | class WXDLLIMPEXP_BASE wxxVariant ; |
341 | class WXDLLIMPEXP_BASE wxTypeInfo ; | |
ae820c69 | 342 | |
492f9a9e | 343 | WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxTypeInfo* , wxTypeInfoMap , class WXDLLIMPEXP_BASE ) ; |
208fd16c | 344 | |
a095505c SC |
345 | class WXDLLIMPEXP_BASE wxTypeInfo |
346 | { | |
347 | public : | |
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 | |
405 | private : | |
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 | ||
419 | class WXDLLIMPEXP_BASE wxBuiltInTypeInfo : public wxTypeInfo | |
420 | { | |
421 | public : | |
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 | ||
432 | class WXDLLIMPEXP_BASE wxCustomTypeInfo : public wxTypeInfo | |
433 | { | |
434 | public : | |
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 | ||
445 | class WXDLLIMPEXP_BASE wxEnumTypeInfo : public wxTypeInfo | |
446 | { | |
447 | public : | |
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 | 473 | private : |
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 | ||
480 | class WXDLLIMPEXP_BASE wxClassTypeInfo : public wxTypeInfo | |
481 | { | |
482 | public : | |
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 | 488 | private : |
517fb871 | 489 | wxClassInfo *m_classInfo; // Kind == wxT_OBJECT - could be NULL |
a095505c SC |
490 | } ; |
491 | ||
ab6e4913 SC |
492 | class WXDLLIMPEXP_BASE wxCollectionTypeInfo : public wxTypeInfo |
493 | { | |
494 | public : | |
ae820c69 SC |
495 | wxCollectionTypeInfo( wxTypeInfo *elementType , converterToString_t to , converterFromString_t from , const wxString &name) : |
496 | wxTypeInfo( wxT_COLLECTION , to , from , name ) | |
497 | { m_elementType = elementType ;} | |
583150e3 SC |
498 | #if wxUSE_UNICODE |
499 | wxCollectionTypeInfo( wxTypeInfo *elementType , converterToString_t to , converterFromString_t from , const char *name ) : | |
500 | wxTypeInfo( wxT_COLLECTION , to , from , name ) | |
501 | { m_elementType = elementType ;} | |
502 | #endif | |
ae820c69 | 503 | const wxTypeInfo* GetElementType() const { return m_elementType ; } |
ab6e4913 SC |
504 | private : |
505 | wxTypeInfo * m_elementType ; | |
506 | } ; | |
507 | ||
4393b50c | 508 | // a delegate is an exposed event source |
a095505c SC |
509 | |
510 | class WXDLLIMPEXP_BASE wxDelegateTypeInfo : public wxTypeInfo | |
511 | { | |
512 | public : | |
ae820c69 | 513 | wxDelegateTypeInfo( int eventType , wxClassInfo* eventClass , converterToString_t to = NULL , converterFromString_t from = NULL ) ; |
517fb871 | 514 | int GetEventType() const { return m_eventType ; } |
a095505c | 515 | private : |
517fb871 VS |
516 | const wxClassInfo *m_eventClass; // (extended will merge into classinfo) |
517 | int m_eventType ; | |
a095505c SC |
518 | } ; |
519 | ||
492f9a9e | 520 | template<typename T> const wxTypeInfo* wxGetTypeInfo( T * ) { return wxTypeInfo::FindType(typeid(T).name()) ; } |
a095505c | 521 | |
a095505c SC |
522 | // this macro is for usage with custom, non-object derived classes and structs, wxPoint is such a custom type |
523 | ||
492f9a9e SC |
524 | #define WX_CUSTOM_TYPE_INFO( e , toString , fromString ) \ |
525 | wxCustomTypeInfo s_typeInfo##e(typeid(e).name() , &toString , &fromString) ; | |
a095505c | 526 | |
ae820c69 | 527 | #define WX_COLLECTION_TYPE_INFO( element , collection ) \ |
583150e3 | 528 | wxCollectionTypeInfo s_typeInfo##collection( (wxTypeInfo*) wxGetTypeInfo( (element *) NULL) , NULL , NULL , typeid(collection).name() ) ; |
ae820c69 | 529 | |
aa8d7c2f | 530 | // sometimes a compiler invents specializations that are nowhere called, use this macro to satisfy the refs |
a095505c | 531 | |
583150e3 | 532 | #define WX_ILLEGAL_TYPE_SPECIALIZATION( a ) |
492f9a9e SC |
533 | /* |
534 | template<> const wxTypeInfo* wxGetTypeInfo( a * ) { assert(0) ; \ | |
aa8d7c2f | 535 | static wxBuiltInTypeInfo s_typeInfo( wxT_VOID ) ; return &s_typeInfo ; } \ |
492f9a9e SC |
536 | template<> void wxStringReadValue(const wxString & , a & ) { assert(0) ; }\ |
537 | template<> void wxStringWriteValue(wxString & , a const & ) { assert(0) ; } | |
538 | */ | |
a095505c SC |
539 | |
540 | // ---------------------------------------------------------------------------- | |
541 | // wxxVariant as typesafe data holder | |
542 | // ---------------------------------------------------------------------------- | |
543 | ||
544 | class WXDLLIMPEXP_BASE wxxVariantData | |
545 | { | |
546 | public: | |
517fb871 | 547 | virtual ~wxxVariantData() {} |
a095505c | 548 | |
517fb871 VS |
549 | // return a heap allocated duplicate |
550 | virtual wxxVariantData* Clone() const = 0 ; | |
a095505c | 551 | |
517fb871 VS |
552 | // returns the type info of the contentc |
553 | virtual const wxTypeInfo* GetTypeInfo() const = 0 ; | |
a095505c SC |
554 | } ; |
555 | ||
df3a88af | 556 | template<typename T> class wxxVariantDataT : public wxxVariantData |
a095505c SC |
557 | { |
558 | public: | |
fa08490f | 559 | wxxVariantDataT(const T& d) : m_data(d) {} |
ae820c69 | 560 | virtual ~wxxVariantDataT() {} |
a095505c | 561 | |
ae820c69 | 562 | // get a ref to the stored data |
fa08490f | 563 | T & Get() { return m_data; } |
a095505c | 564 | |
ae820c69 | 565 | // get a const ref to the stored data |
fa08490f SC |
566 | const T & Get() const { return m_data; } |
567 | ||
ae820c69 | 568 | // set the data |
fa08490f | 569 | void Set(const T& d) { m_data = d; } |
a095505c | 570 | |
517fb871 VS |
571 | // return a heap allocated duplicate |
572 | virtual wxxVariantData* Clone() const { return new wxxVariantDataT<T>( Get() ) ; } | |
a095505c | 573 | |
517fb871 VS |
574 | // returns the type info of the contentc |
575 | virtual const wxTypeInfo* GetTypeInfo() const { return wxGetTypeInfo( (T*) NULL ) ; } | |
583150e3 | 576 | |
a095505c SC |
577 | private: |
578 | T m_data; | |
579 | }; | |
580 | ||
581 | class WXDLLIMPEXP_BASE wxxVariant | |
582 | { | |
583 | public : | |
ae820c69 SC |
584 | wxxVariant() { m_data = NULL ; } |
585 | wxxVariant( wxxVariantData* data , const wxString& name = wxT("") ) : m_data(data) , m_name(name) {} | |
586 | wxxVariant( const wxxVariant &d ) { if ( d.m_data ) m_data = d.m_data->Clone() ; else m_data = NULL ; m_name = d.m_name ; } | |
587 | ||
588 | template<typename T> wxxVariant( const T& data , const wxString& name = wxT("") ) : | |
589 | m_data(new wxxVariantDataT<T>(data) ), m_name(name) {} | |
590 | ||
591 | ~wxxVariant() { delete m_data ; } | |
592 | ||
593 | // get a ref to the stored data | |
2abce515 | 594 | template<typename T> T& Get(WX_TEMPLATED_MEMBER_FIX(T)) |
ae820c69 SC |
595 | { |
596 | wxxVariantDataT<T> *dataptr = dynamic_cast<wxxVariantDataT<T>*> (m_data) ; | |
0a206469 | 597 | wxASSERT_MSG( dataptr , wxT("Cast not possible") ) ; |
ae820c69 SC |
598 | return dataptr->Get() ; |
599 | } | |
600 | ||
601 | // get a ref to the stored data | |
2abce515 | 602 | template<typename T> const T& Get(WX_TEMPLATED_MEMBER_FIX(T)) const |
ae820c69 SC |
603 | { |
604 | const wxxVariantDataT<T> *dataptr = dynamic_cast<const wxxVariantDataT<T>*> (m_data) ; | |
0a206469 | 605 | wxASSERT_MSG( dataptr , wxT("Cast not possible") ) ; |
ae820c69 SC |
606 | return dataptr->Get() ; |
607 | } | |
fa08490f | 608 | |
583150e3 SC |
609 | bool IsEmpty() const { return m_data == NULL ; } |
610 | ||
208fd16c SC |
611 | template<typename T> bool HasData() const |
612 | { | |
ae820c69 | 613 | const wxxVariantDataT<T> *dataptr = dynamic_cast<const wxxVariantDataT<T>*> (m_data) ; |
208fd16c SC |
614 | return dataptr != NULL ; |
615 | } | |
616 | ||
ae820c69 SC |
617 | // stores the data |
618 | template<typename T> void Set(const T& data) const | |
619 | { | |
620 | delete m_data ; | |
621 | m_data = new wxxVariantDataT<T>(data) ; | |
622 | } | |
623 | ||
624 | wxxVariant& operator=(const wxxVariant &d) | |
625 | { | |
626 | m_data = d.m_data->Clone() ; | |
627 | m_name = d.m_name ; | |
628 | return *this ; | |
629 | } | |
630 | ||
631 | // gets the stored data casted to a wxObject* , returning NULL if cast is not possible | |
632 | wxObject* GetAsObject() ; | |
633 | ||
634 | // get the typeinfo of the stored object | |
635 | const wxTypeInfo* GetTypeInfo() const { return m_data->GetTypeInfo() ; } | |
636 | ||
637 | // returns this value as string | |
638 | wxString GetAsString() const | |
639 | { | |
640 | wxString s ; | |
208fd16c | 641 | GetTypeInfo()->ConvertToString( *this , s ) ; |
ae820c69 SC |
642 | return s ; |
643 | } | |
4f8ffae1 | 644 | const wxString& GetName() const { return m_name ; } |
a095505c | 645 | private : |
517fb871 VS |
646 | wxxVariantData* m_data ; |
647 | wxString m_name ; | |
a095505c SC |
648 | } ; |
649 | ||
ab6e4913 SC |
650 | #include <wx/dynarray.h> |
651 | ||
652 | WX_DECLARE_OBJARRAY_WITH_DECL(wxxVariant, wxxVariantArray, class WXDLLIMPEXP_BASE); | |
653 | ||
2abce515 SC |
654 | // templated streaming, every type must have their specialization for these methods |
655 | ||
656 | template<typename T> | |
657 | void wxStringReadValue( const wxString &s , T &data ); | |
658 | ||
659 | template<typename T> | |
660 | void wxStringWriteValue( wxString &s , const T &data); | |
661 | ||
662 | template<typename T> | |
663 | void wxToStringConverter( const wxxVariant &v, wxString &s) { wxStringWriteValue( s , v.WX_TEMPLATED_MEMBER_CALL(Get , T) ) ; } | |
664 | ||
665 | template<typename T> | |
666 | void wxFromStringConverter( const wxString &s, wxxVariant &v) { T d ; wxStringReadValue( s , d ) ; v = wxxVariant(d) ; } \ | |
667 | ||
a095505c SC |
668 | // ---------------------------------------------------------------------------- |
669 | // Property Support | |
670 | // | |
671 | // wxPropertyInfo is used to inquire of the property by name. It doesn't | |
672 | // provide access to the property, only information about it. If you | |
673 | // want access, look at wxPropertyAccessor. | |
674 | // ---------------------------------------------------------------------------- | |
675 | ||
492f9a9e | 676 | class WXDLLIMPEXP_BASE wxSetter |
a095505c | 677 | { |
ab0881c7 | 678 | public: |
208fd16c | 679 | wxSetter( const wxString name ) { m_name = name ; } |
ab0881c7 | 680 | virtual ~wxSetter() {} |
208fd16c SC |
681 | virtual void Set( wxObject *object, const wxxVariant &variantValue ) const = 0; |
682 | const wxString& GetName() const { return m_name ; } | |
ab0881c7 VS |
683 | private: |
684 | wxString m_name; | |
685 | }; | |
a095505c | 686 | |
492f9a9e | 687 | class WXDLLIMPEXP_BASE wxGetter |
2d51f067 | 688 | { |
ab0881c7 | 689 | public: |
208fd16c | 690 | wxGetter( const wxString name ) { m_name = name ; } |
ab0881c7 | 691 | virtual ~wxGetter() {} |
208fd16c SC |
692 | virtual void Get( const wxObject *object , wxxVariant& result) const = 0; |
693 | const wxString& GetName() const { return m_name ; } | |
ab0881c7 VS |
694 | private: |
695 | wxString m_name; | |
696 | }; | |
2d51f067 | 697 | |
492f9a9e | 698 | class WXDLLIMPEXP_BASE wxCollectionGetter |
a095505c | 699 | { |
208fd16c SC |
700 | public : |
701 | wxCollectionGetter( const wxString name ) { m_name = name ; } | |
ab0881c7 | 702 | virtual ~wxCollectionGetter() {} |
208fd16c SC |
703 | virtual void Get( const wxObject *object , wxxVariantArray& result) const = 0; |
704 | const wxString& GetName() const { return m_name ; } | |
705 | private : | |
706 | wxString m_name ; | |
707 | } ; | |
fa08490f | 708 | |
208fd16c | 709 | template<typename coll_t> void wxCollectionToVariantArray( const coll_t& coll , wxxVariantArray& result ) ; |
a095505c | 710 | |
492f9a9e | 711 | class WXDLLIMPEXP_BASE wxAdder |
208fd16c SC |
712 | { |
713 | public : | |
714 | wxAdder( const wxString name ) { m_name = name ; } | |
ab0881c7 | 715 | virtual ~wxAdder() {} |
208fd16c SC |
716 | virtual void Add( wxObject *object, const wxxVariant &variantValue ) const= 0; |
717 | const wxString& GetName() const { return m_name ; } | |
718 | private : | |
719 | wxString m_name ; | |
720 | } ; | |
a095505c | 721 | |
517fb871 | 722 | |
ab6e4913 | 723 | |
a06bb527 | 724 | #define WX_SETTER( property, Klass, valueType, setterMethod ) \ |
ae820c69 SC |
725 | class wxSetter##property : public wxSetter \ |
726 | { \ | |
727 | public: \ | |
583150e3 | 728 | wxSetter##property() : wxSetter( wxT(#setterMethod) ) {} \ |
492f9a9e | 729 | ~wxSetter##property() {} \ |
ae820c69 SC |
730 | void Set( wxObject *object, const wxxVariant &variantValue ) const \ |
731 | { \ | |
732 | Klass *obj = dynamic_cast<Klass*>(object) ; \ | |
733 | if ( variantValue.HasData<valueType>() ) \ | |
734 | obj->setterMethod(variantValue.Get<valueType>()) ; \ | |
a06bb527 | 735 | else \ |
ae820c69 SC |
736 | obj->setterMethod(*variantValue.Get<valueType*>()) ; \ |
737 | } \ | |
738 | } ; | |
208fd16c | 739 | |
a06bb527 | 740 | #define WX_GETTER( property, Klass, valueType , gettermethod ) \ |
ae820c69 SC |
741 | class wxGetter##property : public wxGetter \ |
742 | { \ | |
743 | public : \ | |
583150e3 | 744 | wxGetter##property() : wxGetter( wxT(#gettermethod) ) {} \ |
492f9a9e | 745 | ~wxGetter##property() {} \ |
ae820c69 SC |
746 | void Get( const wxObject *object , wxxVariant &result) const \ |
747 | { \ | |
748 | const Klass *obj = dynamic_cast<const Klass*>(object) ; \ | |
749 | result = wxxVariant( obj->gettermethod() ) ; \ | |
750 | } \ | |
751 | } ; | |
208fd16c | 752 | |
a06bb527 | 753 | #define WX_ADDER( property, Klass, valueType , addermethod ) \ |
ae820c69 SC |
754 | class wxAdder##property : public wxAdder \ |
755 | { \ | |
756 | public: \ | |
583150e3 | 757 | wxAdder##property() : wxAdder( wxT(#addermethod) ) {} \ |
492f9a9e | 758 | ~wxAdder##property() {} \ |
ae820c69 SC |
759 | void Add( wxObject *object, const wxxVariant &variantValue ) const \ |
760 | { \ | |
761 | Klass *obj = dynamic_cast<Klass*>(object) ; \ | |
762 | if ( variantValue.HasData<valueType>() ) \ | |
763 | obj->addermethod(variantValue.Get<valueType>()) ; \ | |
a06bb527 | 764 | else \ |
ae820c69 SC |
765 | obj->addermethod(*variantValue.Get<valueType*>()) ; \ |
766 | } \ | |
767 | } ; | |
208fd16c | 768 | |
a06bb527 | 769 | #define WX_COLLECTION_GETTER( property, Klass, valueType , gettermethod ) \ |
ae820c69 SC |
770 | class wxCollectionGetter##property : public wxCollectionGetter \ |
771 | { \ | |
772 | public : \ | |
583150e3 | 773 | wxCollectionGetter##property() : wxCollectionGetter( wxT(#gettermethod) ) {} \ |
492f9a9e | 774 | ~wxCollectionGetter##property() {} \ |
ae820c69 SC |
775 | void Get( const wxObject *object , wxxVariantArray &result) const \ |
776 | { \ | |
777 | const Klass *obj = dynamic_cast<const Klass*>(object) ; \ | |
778 | wxCollectionToVariantArray( obj->gettermethod() , result ) ; \ | |
779 | } \ | |
780 | } ; | |
ab6e4913 | 781 | |
208fd16c SC |
782 | class WXDLLIMPEXP_BASE wxPropertyAccessor |
783 | { | |
784 | public : | |
785 | wxPropertyAccessor( wxSetter *setter , wxGetter *getter , wxAdder *adder , wxCollectionGetter *collectionGetter ) | |
786 | { m_setter = setter ; m_getter = getter ; m_adder = adder ; m_collectionGetter = collectionGetter ;} | |
ab6e4913 | 787 | |
208fd16c | 788 | virtual ~wxPropertyAccessor() {} |
ab6e4913 | 789 | |
208fd16c SC |
790 | // Setting a simple property (non-collection) |
791 | virtual void SetProperty(wxObject *object, const wxxVariant &value) const | |
792 | { wxASSERT_MSG(m_setter,wxT("SetProperty called w/o valid setter") ) ; m_setter->Set( object , value ) ;} | |
16a45a23 | 793 | |
208fd16c SC |
794 | // Getting a simple property (non-collection) |
795 | virtual void GetProperty(const wxObject *object, wxxVariant &result) const | |
16d0c403 | 796 | { wxASSERT_MSG(m_getter,wxT("GetProperty called w/o valid getter") ) ; m_getter->Get( object , result ) ;} |
ab6e4913 | 797 | |
208fd16c SC |
798 | // Adding an element to a collection property |
799 | virtual void AddToPropertyCollection(wxObject *object, const wxxVariant &value) const | |
800 | { wxASSERT_MSG(m_adder,wxT("AddToPropertyCollection called w/o valid adder") ) ; m_adder->Add( object , value ) ;} | |
ab6e4913 | 801 | |
208fd16c SC |
802 | // Getting a collection property |
803 | virtual void GetPropertyCollection( const wxObject *obj, wxxVariantArray &result) const | |
16d0c403 | 804 | { wxASSERT_MSG(m_collectionGetter,wxT("GetPropertyCollection called w/o valid collection getter") ) ; m_collectionGetter->Get( obj , result) ;} |
208fd16c SC |
805 | |
806 | virtual bool HasSetter() const { return m_setter != NULL ; } | |
807 | virtual bool HasCollectionGetter() const { return m_collectionGetter != NULL ; } | |
808 | virtual bool HasGetter() const { return m_getter != NULL ; } | |
809 | virtual bool HasAdder() const { return m_adder != NULL ; } | |
810 | ||
811 | virtual const wxString& GetCollectionGetterName() const | |
812 | { return m_collectionGetter->GetName() ; } | |
813 | virtual const wxString& GetGetterName() const | |
814 | { return m_getter->GetName() ; } | |
815 | virtual const wxString& GetSetterName() const | |
816 | { return m_setter->GetName() ; } | |
817 | virtual const wxString& GetAdderName() const | |
818 | { return m_adder->GetName() ; } | |
492f9a9e | 819 | |
208fd16c SC |
820 | protected : |
821 | wxSetter *m_setter ; | |
822 | wxAdder *m_adder ; | |
823 | wxGetter *m_getter ; | |
824 | wxCollectionGetter* m_collectionGetter ; | |
825 | }; | |
ab6e4913 | 826 | |
ae820c69 SC |
827 | class WXDLLIMPEXP_BASE wxGenericPropertyAccessor : public wxPropertyAccessor |
828 | { | |
829 | public : | |
830 | wxGenericPropertyAccessor( const wxString &propName ) ; | |
831 | ~wxGenericPropertyAccessor() ; | |
ab6e4913 | 832 | |
492f9a9e SC |
833 | void RenameProperty( const wxString &oldName , const wxString &newName ) |
834 | { | |
835 | wxASSERT( oldName == m_propertyName ) ; m_propertyName = newName ; | |
836 | } | |
ae820c69 SC |
837 | virtual bool HasSetter() const { return true ; } |
838 | virtual bool HasGetter() const { return true ; } | |
839 | virtual bool HasAdder() const { return false ; } | |
840 | virtual bool HasCollectionGetter() const { return false ; } | |
ab6e4913 | 841 | |
ae820c69 | 842 | virtual const wxString& GetGetterName() const |
208fd16c SC |
843 | { return m_getterName ; } |
844 | virtual const wxString& GetSetterName() const | |
845 | { return m_setterName ; } | |
ab6e4913 | 846 | |
208fd16c | 847 | virtual void SetProperty(wxObject *object, const wxxVariant &value) const ; |
ae820c69 | 848 | virtual void GetProperty(const wxObject *object, wxxVariant &value) const ; |
208fd16c | 849 | |
ae820c69 SC |
850 | // Adding an element to a collection property |
851 | virtual void AddToPropertyCollection(wxObject *WXUNUSED(object), const wxxVariant &WXUNUSED(value)) const | |
852 | { wxASSERT_MSG(0,wxT("AddToPropertyCollection called on a generic accessor") ) ;} | |
208fd16c | 853 | |
ae820c69 SC |
854 | // Getting a collection property |
855 | virtual void GetPropertyCollection( const wxObject *WXUNUSED(obj), wxxVariantArray &WXUNUSED(result)) const | |
208fd16c | 856 | { wxASSERT_MSG(0,wxT("GetPropertyCollection called on a generic accessor") ) ;} |
ae820c69 SC |
857 | private : |
858 | struct wxGenericPropertyAccessorInternal ; | |
859 | wxGenericPropertyAccessorInternal* m_data ; | |
860 | wxString m_propertyName ; | |
861 | wxString m_setterName ; | |
862 | wxString m_getterName ; | |
208fd16c | 863 | } ; |
ab6e4913 | 864 | |
ae820c69 SC |
865 | typedef long wxPropertyInfoFlags ; |
866 | enum { | |
867 | // will be removed in future releases | |
868 | wxPROP_DEPRECATED = 0x00000001 , | |
869 | // object graph property, will be streamed with priority (after constructor properties) | |
870 | wxPROP_OBJECT_GRAPH = 0x00000002 , | |
871 | // this will only be streamed out and in as enum/set, the internal representation is still a long | |
872 | wxPROP_ENUM_STORE_LONG = 0x00000004 , | |
9c8046dd SC |
873 | // don't stream out this property, needed eg to avoid streaming out children that are always created by their parents |
874 | wxPROP_DONT_STREAM = 0x00000008 , | |
ae820c69 SC |
875 | } ; |
876 | ||
a095505c SC |
877 | class WXDLLIMPEXP_BASE wxPropertyInfo |
878 | { | |
492f9a9e | 879 | friend class WXDLLIMPEXP_BASE wxDynamicClassInfo ; |
a095505c | 880 | public : |
ab0881c7 | 881 | wxPropertyInfo(wxPropertyInfo* &iter, |
492f9a9e SC |
882 | wxClassInfo* itsClass, |
883 | const wxString& name, | |
884 | const wxString& typeName, | |
885 | wxPropertyAccessor *accessor, | |
886 | wxxVariant dv, | |
887 | wxPropertyInfoFlags flags = 0, | |
888 | const wxString& helpString = wxEmptyString, | |
889 | const wxString& groupString = wxEmptyString) : | |
583150e3 | 890 | m_itsClass(itsClass), |
492f9a9e | 891 | m_name(name), |
492f9a9e | 892 | m_typeInfo(NULL), |
583150e3 | 893 | m_typeName(typeName) , |
492f9a9e SC |
894 | m_collectionElementTypeInfo(NULL), |
895 | m_accessor(accessor), | |
583150e3 SC |
896 | m_defaultValue(dv), |
897 | m_flags(flags), | |
898 | m_helpString(helpString), | |
899 | m_groupString(groupString) | |
492f9a9e SC |
900 | { |
901 | Insert(iter); | |
902 | } | |
903 | ||
583150e3 | 904 | #if wxUSE_UNICODE |
492f9a9e SC |
905 | wxPropertyInfo(wxPropertyInfo* &iter, |
906 | wxClassInfo* itsClass, | |
ab0881c7 | 907 | const wxString& name, |
583150e3 | 908 | const char* typeName, |
ab0881c7 VS |
909 | wxPropertyAccessor *accessor, |
910 | wxxVariant dv, | |
911 | wxPropertyInfoFlags flags = 0, | |
912 | const wxString& helpString = wxEmptyString, | |
913 | const wxString& groupString = wxEmptyString) : | |
583150e3 | 914 | m_itsClass(itsClass), |
ab0881c7 | 915 | m_name(name), |
583150e3 SC |
916 | m_typeInfo(NULL), |
917 | m_typeName(wxString::FromAscii(typeName)) , | |
918 | m_collectionElementTypeInfo(NULL), | |
919 | m_accessor(accessor), | |
920 | m_defaultValue(dv), | |
921 | m_flags(flags), | |
ab0881c7 | 922 | m_helpString(helpString), |
583150e3 SC |
923 | m_groupString(groupString) |
924 | { | |
925 | Insert(iter); | |
926 | } | |
927 | #endif | |
928 | wxPropertyInfo(wxPropertyInfo* &iter, | |
929 | wxClassInfo* itsClass, | |
930 | const wxString& name, | |
931 | wxDelegateTypeInfo* type, | |
932 | wxPropertyAccessor *accessor, | |
933 | wxxVariant dv, | |
934 | wxPropertyInfoFlags flags = 0, | |
935 | const wxString& helpString = wxEmptyString, | |
936 | const wxString& groupString = wxEmptyString) : | |
ab0881c7 | 937 | m_itsClass(itsClass), |
583150e3 | 938 | m_name(name), |
492f9a9e | 939 | m_typeInfo(type), |
ab0881c7 VS |
940 | m_collectionElementTypeInfo(NULL), |
941 | m_accessor(accessor), | |
583150e3 SC |
942 | m_defaultValue(dv), |
943 | m_flags(flags), | |
944 | m_helpString(helpString), | |
945 | m_groupString(groupString) | |
ae820c69 | 946 | { |
ab0881c7 | 947 | Insert(iter); |
ae820c69 SC |
948 | } |
949 | ||
ab0881c7 | 950 | wxPropertyInfo(wxPropertyInfo* &iter, |
492f9a9e SC |
951 | wxClassInfo* itsClass, const wxString& name, |
952 | const wxString& collectionTypeName, | |
953 | const wxString& elementTypeName, | |
ab0881c7 VS |
954 | wxPropertyAccessor *accessor, |
955 | wxPropertyInfoFlags flags = 0, | |
956 | const wxString& helpString = wxEmptyString, | |
957 | const wxString& groupString = wxEmptyString) : | |
ab0881c7 | 958 | m_itsClass(itsClass), |
583150e3 | 959 | m_name(name), |
492f9a9e SC |
960 | m_typeInfo(NULL), |
961 | m_typeName(collectionTypeName) , | |
962 | m_collectionElementTypeInfo(NULL), | |
963 | m_collectionElementTypeName(elementTypeName), | |
583150e3 SC |
964 | m_accessor(accessor) , |
965 | m_flags(flags), | |
966 | m_helpString(helpString), | |
967 | m_groupString(groupString) | |
ae820c69 | 968 | { |
ab0881c7 | 969 | Insert(iter); |
ae820c69 SC |
970 | } |
971 | ||
583150e3 SC |
972 | #if wxUSE_UNICODE |
973 | wxPropertyInfo(wxPropertyInfo* &iter, | |
974 | wxClassInfo* itsClass, const wxString& name, | |
975 | const char* collectionTypeName, | |
976 | const char* elementTypeName, | |
977 | wxPropertyAccessor *accessor, | |
978 | wxPropertyInfoFlags flags = 0, | |
979 | const wxString& helpString = wxEmptyString, | |
980 | const wxString& groupString = wxEmptyString) : | |
981 | m_itsClass(itsClass), | |
982 | m_name(name), | |
983 | m_typeInfo(NULL), | |
984 | m_typeName(wxString::FromAscii(collectionTypeName)) , | |
985 | m_collectionElementTypeInfo(NULL), | |
986 | m_collectionElementTypeName(wxString::FromAscii(elementTypeName)), | |
987 | m_accessor(accessor) , | |
988 | m_flags(flags), | |
989 | m_helpString(helpString), | |
990 | m_groupString(groupString) | |
991 | { | |
992 | Insert(iter); | |
993 | } | |
994 | #endif | |
1c263d56 SC |
995 | ~wxPropertyInfo() ; |
996 | ||
ae820c69 SC |
997 | // return the class this property is declared in |
998 | const wxClassInfo* GetDeclaringClass() const { return m_itsClass ; } | |
fa08490f | 999 | |
ae820c69 SC |
1000 | // return the name of this property |
1001 | const wxString& GetName() const { return m_name ; } | |
ab6e4913 | 1002 | |
ae820c69 SC |
1003 | // returns the flags of this property |
1004 | wxPropertyInfoFlags GetFlags() const { return m_flags ;} | |
fa08490f | 1005 | |
ae820c69 SC |
1006 | // returns the short help string of this property |
1007 | const wxString& GetHelpString() const { return m_helpString ; } | |
fa08490f | 1008 | |
ae820c69 SC |
1009 | // returns the group string of this property |
1010 | const wxString& GetGroupString() const { return m_groupString ; } | |
fa08490f | 1011 | |
ae820c69 | 1012 | // return the element type info of this property (for collections, otherwise NULL) |
583150e3 | 1013 | const wxTypeInfo * GetCollectionElementTypeInfo() const |
492f9a9e SC |
1014 | { |
1015 | if ( m_collectionElementTypeInfo == NULL ) | |
1016 | m_collectionElementTypeInfo = wxTypeInfo::FindType(m_collectionElementTypeName) ; | |
583150e3 | 1017 | return m_collectionElementTypeInfo ; |
492f9a9e | 1018 | } |
fa08490f | 1019 | |
ae820c69 | 1020 | // return the type info of this property |
583150e3 | 1021 | const wxTypeInfo * GetTypeInfo() const |
492f9a9e SC |
1022 | { |
1023 | if ( m_typeInfo == NULL ) | |
1024 | m_typeInfo = wxTypeInfo::FindType(m_typeName) ; | |
583150e3 | 1025 | return m_typeInfo ; |
492f9a9e | 1026 | } |
fa08490f | 1027 | |
ae820c69 SC |
1028 | // return the accessor for this property |
1029 | wxPropertyAccessor* GetAccessor() const { return m_accessor ; } | |
1030 | ||
1031 | // returns NULL if this is the last property of this class | |
1032 | wxPropertyInfo* GetNext() const { return m_next ; } | |
1033 | ||
1034 | // returns the default value of this property, its kind may be wxT_VOID if it is not valid | |
1035 | wxxVariant GetDefaultValue() const { return m_defaultValue ; } | |
4393b50c | 1036 | private : |
ab6e4913 SC |
1037 | void Insert(wxPropertyInfo* &iter) |
1038 | { | |
ae820c69 SC |
1039 | m_next = NULL ; |
1040 | if ( iter == NULL ) | |
1041 | iter = this ; | |
1042 | else | |
1043 | { | |
1044 | wxPropertyInfo* i = iter ; | |
1045 | while( i->m_next ) | |
1046 | i = i->m_next ; | |
1047 | ||
1048 | i->m_next = this ; | |
1049 | } | |
ab6e4913 | 1050 | } |
583150e3 | 1051 | |
492f9a9e | 1052 | wxClassInfo* m_itsClass ; |
583150e3 | 1053 | wxString m_name ; |
492f9a9e | 1054 | mutable wxTypeInfo* m_typeInfo ; |
583150e3 | 1055 | wxString m_typeName ; |
492f9a9e | 1056 | mutable wxTypeInfo* m_collectionElementTypeInfo ; |
583150e3 | 1057 | wxString m_collectionElementTypeName ; |
517fb871 | 1058 | wxPropertyAccessor* m_accessor ; |
583150e3 SC |
1059 | wxxVariant m_defaultValue; |
1060 | wxPropertyInfoFlags m_flags ; | |
1061 | wxString m_helpString ; | |
1062 | wxString m_groupString ; | |
517fb871 VS |
1063 | // string representation of the default value |
1064 | // to be assigned by the designer to the property | |
1065 | // when the component is dropped on the container. | |
1066 | wxPropertyInfo* m_next ; | |
a095505c SC |
1067 | }; |
1068 | ||
492f9a9e | 1069 | WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxPropertyInfo* , wxPropertyInfoMap , class WXDLLIMPEXP_BASE ) ; |
ae820c69 | 1070 | |
a095505c | 1071 | #define WX_BEGIN_PROPERTIES_TABLE(theClass) \ |
2d51f067 | 1072 | wxPropertyInfo *theClass::GetPropertiesStatic() \ |
ae820c69 SC |
1073 | { \ |
1074 | typedef theClass class_t; \ | |
1075 | static wxPropertyInfo* first = NULL ; | |
a095505c SC |
1076 | |
1077 | #define WX_END_PROPERTIES_TABLE() \ | |
ae820c69 | 1078 | return first ; } |
a095505c | 1079 | |
492f9a9e | 1080 | #define WX_HIDE_PROPERTY( pname ) \ |
583150e3 | 1081 | static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(void).name() ,NULL , wxxVariant() , wxPROP_DONT_STREAM , wxEmptyString , wxEmptyString ) ; |
492f9a9e SC |
1082 | |
1083 | #define WX_PROPERTY( pname , type , setter , getter ,defaultValue , flags , help , group) \ | |
1084 | WX_SETTER( pname , class_t , type , setter ) \ | |
1085 | static wxSetter##pname _setter##pname ; \ | |
1086 | WX_GETTER( pname , class_t , type , getter ) \ | |
1087 | static wxGetter##pname _getter##pname ; \ | |
1088 | static wxPropertyAccessor _accessor##pname( &_setter##pname , &_getter##pname , NULL , NULL ) ; \ | |
583150e3 | 1089 | static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(type).name() ,&_accessor##pname , wxxVariant(defaultValue) , flags , group , help ) ; |
492f9a9e SC |
1090 | |
1091 | #define WX_PROPERTY_FLAGS( pname , flags , type , setter , getter ,defaultValue , pflags , help , group) \ | |
1092 | WX_SETTER( pname , class_t , type , setter ) \ | |
1093 | static wxSetter##pname _setter##pname ; \ | |
1094 | WX_GETTER( pname , class_t , type , getter ) \ | |
1095 | static wxGetter##pname _getter##pname ; \ | |
1096 | static wxPropertyAccessor _accessor##pname( &_setter##pname , &_getter##pname , NULL , NULL ) ; \ | |
583150e3 | 1097 | 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 |
1098 | |
1099 | #define WX_READONLY_PROPERTY( pname , type , getter ,defaultValue , flags , help , group) \ | |
1100 | WX_GETTER( pname , class_t , type , getter ) \ | |
1101 | static wxGetter##pname _getter##pname ; \ | |
1102 | static wxPropertyAccessor _accessor##pname( NULL , &_getter##pname , NULL , NULL ) ; \ | |
583150e3 SC |
1103 | static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(type).name() ,&_accessor##pname , wxxVariant(defaultValue), flags , help , group ) ; |
1104 | ||
1105 | #define WX_READONLY_PROPERTY_FLAGS( pname , flags , type , getter ,defaultValue , pflags , help , group) \ | |
1106 | WX_GETTER( pname , class_t , type , getter ) \ | |
1107 | static wxGetter##pname _getter##pname ; \ | |
1108 | static wxPropertyAccessor _accessor##pname( NULL , &_getter##pname , NULL , NULL ) ; \ | |
1109 | 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 |
1110 | |
1111 | #define WX_PROPERTY_COLLECTION( pname , colltype , addelemtype , adder , getter , flags , help , group ) \ | |
1112 | WX_ADDER( pname , class_t , addelemtype , adder ) \ | |
1113 | static wxAdder##pname _adder##pname ; \ | |
1114 | WX_COLLECTION_GETTER( pname , class_t , colltype , getter ) \ | |
1115 | static wxCollectionGetter##pname _collectionGetter##pname ; \ | |
1116 | static wxPropertyAccessor _accessor##pname( NULL , NULL ,&_adder##pname , &_collectionGetter##pname ) ; \ | |
583150e3 | 1117 | static wxPropertyInfo _propertyInfo##pname( first , class_t::GetClassInfoStatic() , wxT(#pname) , typeid(colltype).name() ,typeid(addelemtype).name() ,&_accessor##pname , flags , help , group ) ; |
492f9a9e SC |
1118 | |
1119 | #define WX_READONLY_PROPERTY_COLLECTION( pname , colltype , addelemtype , getter , flags , help , group) \ | |
1120 | WX_COLLECTION_GETTER( pname , class_t , colltype , getter ) \ | |
1121 | static wxCollectionGetter##pname _collectionGetter##pname ; \ | |
1122 | static wxPropertyAccessor _accessor##pname( NULL , NULL , NULL , &_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 ) ; |
16a45a23 SC |
1124 | |
1125 | ||
a095505c | 1126 | #define WX_DELEGATE( name , eventType , eventClass ) \ |
517fb871 | 1127 | static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \ |
583150e3 | 1128 | static wxPropertyInfo _propertyInfo##name( first ,class_t::GetClassInfoStatic() , wxT(#name) , &_typeInfo##name , NULL , wxxVariant() ) ; \ |
a095505c SC |
1129 | |
1130 | // ---------------------------------------------------------------------------- | |
1131 | // Handler Info | |
1132 | // | |
1133 | // this is describing an event sink | |
1134 | // ---------------------------------------------------------------------------- | |
1135 | ||
492f9a9e | 1136 | class WXDLLIMPEXP_BASE wxHandlerInfo |
a095505c | 1137 | { |
492f9a9e | 1138 | friend class WXDLLIMPEXP_BASE wxDynamicClassInfo ; |
a095505c | 1139 | public : |
ab0881c7 | 1140 | wxHandlerInfo(wxHandlerInfo* &iter, |
492f9a9e | 1141 | wxClassInfo* itsClass, |
ab0881c7 VS |
1142 | const wxString& name, |
1143 | wxObjectEventFunction address, | |
1144 | const wxClassInfo* eventClassInfo) : | |
1145 | m_eventFunction(address), | |
1146 | m_name(name), | |
492f9a9e SC |
1147 | m_eventClassInfo(eventClassInfo) , |
1148 | m_itsClass(itsClass) | |
ae820c69 SC |
1149 | { |
1150 | m_next = NULL ; | |
1151 | if ( iter == NULL ) | |
1152 | iter = this ; | |
1153 | else | |
1154 | { | |
1155 | wxHandlerInfo* i = iter ; | |
1156 | while( i->m_next ) | |
1157 | i = i->m_next ; | |
1158 | ||
1159 | i->m_next = this ; | |
1160 | } | |
1161 | } | |
1162 | ||
1c263d56 SC |
1163 | ~wxHandlerInfo() ; |
1164 | ||
ae820c69 SC |
1165 | // return the name of this handler |
1166 | const wxString& GetName() const { return m_name ; } | |
1167 | ||
1168 | // return the class info of the event | |
1169 | const wxClassInfo * GetEventClassInfo() const { return m_eventClassInfo ; } | |
1170 | ||
1171 | // get the handler function pointer | |
1172 | wxObjectEventFunction GetEventFunction() const { return m_eventFunction ; } | |
1173 | ||
1174 | // returns NULL if this is the last handler of this class | |
1175 | wxHandlerInfo* GetNext() const { return m_next ; } | |
492f9a9e SC |
1176 | |
1177 | // return the class this property is declared in | |
1178 | const wxClassInfo* GetDeclaringClass() const { return m_itsClass ; } | |
1179 | ||
4393b50c | 1180 | private : |
517fb871 | 1181 | wxObjectEventFunction m_eventFunction ; |
ae820c69 | 1182 | wxString m_name; |
517fb871 VS |
1183 | const wxClassInfo* m_eventClassInfo ; |
1184 | wxHandlerInfo* m_next ; | |
492f9a9e | 1185 | wxClassInfo* m_itsClass ; |
a095505c SC |
1186 | }; |
1187 | ||
1188 | #define WX_HANDLER(name,eventClassType) \ | |
492f9a9e | 1189 | static wxHandlerInfo _handlerInfo##name( first , class_t::GetClassInfoStatic() , #name , (wxObjectEventFunction) (wxEventFunction) &name , CLASSINFO( eventClassType ) ) ; |
a095505c SC |
1190 | |
1191 | #define WX_BEGIN_HANDLERS_TABLE(theClass) \ | |
2d51f067 | 1192 | wxHandlerInfo *theClass::GetHandlersStatic() \ |
ae820c69 SC |
1193 | { \ |
1194 | typedef theClass class_t; \ | |
1195 | static wxHandlerInfo* first = NULL ; | |
a095505c SC |
1196 | |
1197 | #define WX_END_HANDLERS_TABLE() \ | |
ae820c69 | 1198 | return first ; } |
a095505c SC |
1199 | |
1200 | // ---------------------------------------------------------------------------- | |
1201 | // Constructor Bridges | |
1202 | // | |
1203 | // allow to set up constructors with params during runtime | |
1204 | // ---------------------------------------------------------------------------- | |
1205 | ||
1206 | class WXDLLIMPEXP_BASE wxConstructorBridge | |
1207 | { | |
1208 | public : | |
583150e3 | 1209 | virtual void Create(wxObject * &o, wxxVariant *args) = 0; |
a095505c SC |
1210 | }; |
1211 | ||
583150e3 SC |
1212 | // a direct constructor bridge calls the operator new for this class and |
1213 | // passes all params to the constructor. needed for classes that cannot be | |
1214 | // instantiated using alloc-create semantics | |
1215 | class WXDLLIMPEXP_BASE wxDirectConstructorBrigde : public wxConstructorBridge | |
1216 | { | |
1217 | public : | |
1218 | virtual void Create(wxObject * &o, wxxVariant *args) = 0; | |
1219 | } ; | |
1220 | ||
a095505c SC |
1221 | // Creator Bridges for all Numbers of Params |
1222 | ||
1223 | // no params | |
1224 | ||
1225 | template<typename Class> | |
1226 | struct wxConstructorBridge_0 : public wxConstructorBridge | |
1227 | { | |
583150e3 | 1228 | void Create(wxObject * &o, wxxVariant *) |
a095505c SC |
1229 | { |
1230 | Class *obj = dynamic_cast<Class*>(o); | |
1231 | obj->Create(); | |
1232 | } | |
1233 | }; | |
1234 | ||
1235 | struct wxConstructorBridge_Dummy : public wxConstructorBridge | |
1236 | { | |
583150e3 | 1237 | void Create(wxObject *&, wxxVariant *) |
a095505c SC |
1238 | { |
1239 | } | |
1240 | } ; | |
1241 | ||
1242 | #define WX_CONSTRUCTOR_0(klass) \ | |
517fb871 VS |
1243 | wxConstructorBridge_0<klass> constructor##klass ; \ |
1244 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
1245 | const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \ | |
1246 | const int klass::sm_constructorPropertiesCount##klass = 0 ; | |
a095505c SC |
1247 | |
1248 | #define WX_CONSTRUCTOR_DUMMY(klass) \ | |
517fb871 VS |
1249 | wxConstructorBridge_Dummy constructor##klass ; \ |
1250 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
1251 | const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \ | |
1252 | const int klass::sm_constructorPropertiesCount##klass = 0 ; | |
a095505c SC |
1253 | |
1254 | // 1 param | |
1255 | ||
1256 | template<typename Class, typename T0> | |
1257 | struct wxConstructorBridge_1 : public wxConstructorBridge | |
1258 | { | |
583150e3 | 1259 | void Create(wxObject * &o, wxxVariant *args) |
a095505c SC |
1260 | { |
1261 | Class *obj = dynamic_cast<Class*>(o); | |
1262 | obj->Create( | |
2abce515 | 1263 | args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) |
ae820c69 | 1264 | ); |
a095505c SC |
1265 | } |
1266 | }; | |
1267 | ||
1268 | #define WX_CONSTRUCTOR_1(klass,t0,v0) \ | |
517fb871 VS |
1269 | wxConstructorBridge_1<klass,t0> constructor##klass ; \ |
1270 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
583150e3 | 1271 | const wxChar *klass::sm_constructorProperties##klass[] = { wxT(#v0) } ; \ |
517fb871 | 1272 | const int klass::sm_constructorPropertiesCount##klass = 1 ; |
a095505c SC |
1273 | |
1274 | // 2 params | |
1275 | ||
1276 | template<typename Class, | |
ae820c69 | 1277 | typename T0, typename T1> |
a095505c SC |
1278 | struct wxConstructorBridge_2 : public wxConstructorBridge |
1279 | { | |
583150e3 | 1280 | void Create(wxObject * &o, wxxVariant *args) |
a095505c SC |
1281 | { |
1282 | Class *obj = dynamic_cast<Class*>(o); | |
1283 | obj->Create( | |
2abce515 SC |
1284 | args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) , |
1285 | args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) | |
ae820c69 | 1286 | ); |
a095505c SC |
1287 | } |
1288 | }; | |
1289 | ||
1290 | #define WX_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \ | |
517fb871 VS |
1291 | wxConstructorBridge_2<klass,t0,t1> constructor##klass ; \ |
1292 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
583150e3 SC |
1293 | const wxChar *klass::sm_constructorProperties##klass[] = { wxT(#v0) , wxT(#v1) } ; \ |
1294 | const int klass::sm_constructorPropertiesCount##klass = 2; | |
1295 | ||
1296 | // direct constructor version | |
1297 | ||
1298 | template<typename Class, | |
1299 | typename T0, typename T1> | |
1300 | struct wxDirectConstructorBridge_2 : public wxDirectConstructorBrigde | |
1301 | { | |
1302 | void Create(wxObject * &o, wxxVariant *args) | |
1303 | { | |
1304 | o = new Class( | |
1305 | args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) , | |
1306 | args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) | |
1307 | ); | |
1308 | } | |
1309 | }; | |
1310 | ||
1311 | #define WX_DIRECT_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \ | |
1312 | wxDirectConstructorBridge_2<klass,t0,t1> constructor##klass ; \ | |
1313 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
1314 | const wxChar *klass::sm_constructorProperties##klass[] = { wxT(#v0) , wxT(#v1) } ; \ | |
517fb871 | 1315 | const int klass::sm_constructorPropertiesCount##klass = 2; |
a095505c | 1316 | |
583150e3 | 1317 | |
a095505c SC |
1318 | // 3 params |
1319 | ||
1320 | template<typename Class, | |
ae820c69 | 1321 | typename T0, typename T1, typename T2> |
a095505c SC |
1322 | struct wxConstructorBridge_3 : public wxConstructorBridge |
1323 | { | |
583150e3 | 1324 | void Create(wxObject * &o, wxxVariant *args) |
a095505c SC |
1325 | { |
1326 | Class *obj = dynamic_cast<Class*>(o); | |
1327 | obj->Create( | |
2abce515 SC |
1328 | args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) , |
1329 | args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) , | |
1330 | args[2].WX_TEMPLATED_MEMBER_CALL(Get , T2) | |
ae820c69 | 1331 | ); |
a095505c SC |
1332 | } |
1333 | }; | |
1334 | ||
1335 | #define WX_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \ | |
517fb871 VS |
1336 | wxConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \ |
1337 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
583150e3 | 1338 | const wxChar *klass::sm_constructorProperties##klass[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) } ; \ |
517fb871 | 1339 | const int klass::sm_constructorPropertiesCount##klass = 3 ; |
a095505c SC |
1340 | |
1341 | // 4 params | |
1342 | ||
1343 | template<typename Class, | |
ae820c69 | 1344 | typename T0, typename T1, typename T2, typename T3> |
a095505c SC |
1345 | struct wxConstructorBridge_4 : public wxConstructorBridge |
1346 | { | |
583150e3 | 1347 | void Create(wxObject * &o, wxxVariant *args) |
a095505c SC |
1348 | { |
1349 | Class *obj = dynamic_cast<Class*>(o); | |
1350 | obj->Create( | |
2abce515 SC |
1351 | args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) , |
1352 | args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) , | |
1353 | args[2].WX_TEMPLATED_MEMBER_CALL(Get , T2) , | |
1354 | args[3].WX_TEMPLATED_MEMBER_CALL(Get , T3) | |
ae820c69 | 1355 | ); |
a095505c SC |
1356 | } |
1357 | }; | |
1358 | ||
1359 | #define WX_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \ | |
517fb871 VS |
1360 | wxConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass ; \ |
1361 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
583150e3 | 1362 | const wxChar *klass::sm_constructorProperties##klass[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) } ; \ |
517fb871 | 1363 | const int klass::sm_constructorPropertiesCount##klass = 4 ; |
fbbdc52c SC |
1364 | |
1365 | // 5 params | |
1366 | ||
1367 | template<typename Class, | |
ae820c69 | 1368 | typename T0, typename T1, typename T2, typename T3, typename T4> |
fbbdc52c SC |
1369 | struct wxConstructorBridge_5 : public wxConstructorBridge |
1370 | { | |
583150e3 | 1371 | void Create(wxObject * &o, wxxVariant *args) |
fbbdc52c 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) , | |
1379 | args[4].WX_TEMPLATED_MEMBER_CALL(Get , T4) | |
ae820c69 | 1380 | ); |
fbbdc52c SC |
1381 | } |
1382 | }; | |
1383 | ||
1384 | #define WX_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \ | |
ae820c69 SC |
1385 | wxConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass ; \ |
1386 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
583150e3 | 1387 | const wxChar *klass::sm_constructorProperties##klass[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) } ; \ |
ae820c69 | 1388 | const int klass::sm_constructorPropertiesCount##klass = 5; |
fa08490f SC |
1389 | |
1390 | // 6 params | |
1391 | ||
1392 | template<typename Class, | |
ae820c69 | 1393 | typename T0, typename T1, typename T2, typename T3, typename T4, typename T5> |
fa08490f SC |
1394 | struct wxConstructorBridge_6 : public wxConstructorBridge |
1395 | { | |
583150e3 | 1396 | void Create(wxObject * &o, wxxVariant *args) |
fa08490f SC |
1397 | { |
1398 | Class *obj = dynamic_cast<Class*>(o); | |
1399 | obj->Create( | |
2abce515 SC |
1400 | args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) , |
1401 | args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) , | |
1402 | args[2].WX_TEMPLATED_MEMBER_CALL(Get , T2) , | |
1403 | args[3].WX_TEMPLATED_MEMBER_CALL(Get , T3) , | |
1404 | args[4].WX_TEMPLATED_MEMBER_CALL(Get , T4) , | |
1405 | args[5].WX_TEMPLATED_MEMBER_CALL(Get , T5) | |
ae820c69 | 1406 | ); |
fa08490f SC |
1407 | } |
1408 | }; | |
1409 | ||
583150e3 SC |
1410 | #define WX_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \ |
1411 | wxConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \ | |
1412 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
1413 | const wxChar *klass::sm_constructorProperties##klass[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) } ; \ | |
1414 | const int klass::sm_constructorPropertiesCount##klass = 6; | |
1415 | ||
1416 | // direct constructor version | |
1417 | ||
2abce515 SC |
1418 | template<typename Class, |
1419 | typename T0, typename T1, typename T2, typename T3, typename T4, typename T5> | |
583150e3 | 1420 | struct wxDirectConstructorBridge_6 : public wxDirectConstructorBrigde |
2abce515 | 1421 | { |
583150e3 | 1422 | void Create(wxObject * &o, wxxVariant *args) |
2abce515 | 1423 | { |
583150e3 | 1424 | o = new Class( |
2abce515 SC |
1425 | args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) , |
1426 | args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) , | |
1427 | args[2].WX_TEMPLATED_MEMBER_CALL(Get , T2) , | |
1428 | args[3].WX_TEMPLATED_MEMBER_CALL(Get , T3) , | |
1429 | args[4].WX_TEMPLATED_MEMBER_CALL(Get , T4) , | |
1430 | args[5].WX_TEMPLATED_MEMBER_CALL(Get , T5) | |
1431 | ); | |
1432 | } | |
1433 | }; | |
1434 | ||
1435 | #define WX_DIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \ | |
1436 | wxDirectConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \ | |
1437 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
583150e3 | 1438 | const wxChar *klass::sm_constructorProperties##klass[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) } ; \ |
ae820c69 | 1439 | const int klass::sm_constructorPropertiesCount##klass = 6; |
fa08490f | 1440 | |
a06bb527 SC |
1441 | // 7 params |
1442 | ||
1443 | template<typename Class, | |
ae820c69 | 1444 | typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6> |
a06bb527 SC |
1445 | struct wxConstructorBridge_7 : public wxConstructorBridge |
1446 | { | |
583150e3 | 1447 | void Create(wxObject * &o, wxxVariant *args) |
a06bb527 SC |
1448 | { |
1449 | Class *obj = dynamic_cast<Class*>(o); | |
1450 | obj->Create( | |
2abce515 SC |
1451 | args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) , |
1452 | args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) , | |
1453 | args[2].WX_TEMPLATED_MEMBER_CALL(Get , T2) , | |
1454 | args[3].WX_TEMPLATED_MEMBER_CALL(Get , T3) , | |
1455 | args[4].WX_TEMPLATED_MEMBER_CALL(Get , T4) , | |
1456 | args[5].WX_TEMPLATED_MEMBER_CALL(Get , T5) , | |
1457 | args[6].WX_TEMPLATED_MEMBER_CALL(Get , T6) | |
ae820c69 | 1458 | ); |
a06bb527 SC |
1459 | } |
1460 | }; | |
1461 | ||
1462 | #define WX_CONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \ | |
ae820c69 SC |
1463 | wxConstructorBridge_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass ; \ |
1464 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
583150e3 | 1465 | const wxChar *klass::sm_constructorProperties##klass[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) , wxT(#v6) } ; \ |
ae820c69 | 1466 | const int klass::sm_constructorPropertiesCount##klass = 7; |
a095505c | 1467 | |
a06bb527 SC |
1468 | // 8 params |
1469 | ||
1470 | template<typename Class, | |
ae820c69 | 1471 | typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> |
a06bb527 SC |
1472 | struct wxConstructorBridge_8 : public wxConstructorBridge |
1473 | { | |
583150e3 | 1474 | void Create(wxObject * &o, wxxVariant *args) |
a06bb527 SC |
1475 | { |
1476 | Class *obj = dynamic_cast<Class*>(o); | |
1477 | obj->Create( | |
2abce515 SC |
1478 | args[0].WX_TEMPLATED_MEMBER_CALL(Get , T0) , |
1479 | args[1].WX_TEMPLATED_MEMBER_CALL(Get , T1) , | |
1480 | args[2].WX_TEMPLATED_MEMBER_CALL(Get , T2) , | |
1481 | args[3].WX_TEMPLATED_MEMBER_CALL(Get , T3) , | |
1482 | args[4].WX_TEMPLATED_MEMBER_CALL(Get , T4) , | |
1483 | args[5].WX_TEMPLATED_MEMBER_CALL(Get , T5) , | |
1484 | args[6].WX_TEMPLATED_MEMBER_CALL(Get , T6) , | |
1485 | args[7].WX_TEMPLATED_MEMBER_CALL(Get , T7) | |
ae820c69 | 1486 | ); |
a06bb527 SC |
1487 | } |
1488 | }; | |
1489 | ||
1490 | #define WX_CONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \ | |
ae820c69 SC |
1491 | wxConstructorBridge_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass ; \ |
1492 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
583150e3 | 1493 | const wxChar *klass::sm_constructorProperties##klass[] = { wxT(#v0) , wxT(#v1) , wxT(#v2) , wxT(#v3) , wxT(#v4) , wxT(#v5) , wxT(#v6) , wxT(#v7) } ; \ |
ae820c69 | 1494 | const int klass::sm_constructorPropertiesCount##klass = 8; |
a095505c SC |
1495 | // ---------------------------------------------------------------------------- |
1496 | // wxClassInfo | |
1497 | // ---------------------------------------------------------------------------- | |
1498 | ||
1499 | typedef wxObject *(*wxObjectConstructorFn)(void); | |
fa08490f | 1500 | typedef wxObject* (*wxVariantToObjectConverter)( wxxVariant &data ) ; |
a095505c | 1501 | typedef wxxVariant (*wxObjectToVariantConverter)( wxObject* ) ; |
492f9a9e | 1502 | |
79902653 VS |
1503 | class WXDLLIMPEXP_BASE wxWriter; |
1504 | class WXDLLIMPEXP_BASE wxPersister; | |
492f9a9e | 1505 | |
9c8046dd | 1506 | typedef bool (*wxObjectStreamingCallback) ( const wxObject *, wxWriter * , wxPersister * , wxxVariantArray & ) ; |
a095505c SC |
1507 | |
1508 | class WXDLLIMPEXP_BASE wxClassInfo | |
1509 | { | |
79902653 VS |
1510 | friend class WXDLLIMPEXP_BASE wxPropertyInfo ; |
1511 | friend class WXDLLIMPEXP_BASE wxHandlerInfo ; | |
a095505c SC |
1512 | public: |
1513 | wxClassInfo(const wxClassInfo **_Parents, | |
ae820c69 SC |
1514 | const wxChar *_UnitName, |
1515 | const wxChar *_ClassName, | |
1516 | int size, | |
1517 | wxObjectConstructorFn ctor , | |
1518 | wxPropertyInfo *_Props , | |
1519 | wxHandlerInfo *_Handlers , | |
1520 | wxConstructorBridge* _Constructor , | |
1521 | const wxChar ** _ConstructorProperties , | |
1522 | const int _ConstructorPropertiesCount , | |
1523 | wxVariantToObjectConverter _PtrConverter1 , | |
1524 | wxVariantToObjectConverter _Converter2 , | |
9c8046dd SC |
1525 | wxObjectToVariantConverter _Converter3 , |
1526 | wxObjectStreamingCallback _streamingCallback = NULL | |
583150e3 SC |
1527 | ) : |
1528 | ||
ab0881c7 VS |
1529 | m_className(_ClassName), |
1530 | m_objectSize(size), | |
1531 | m_objectConstructor(ctor), | |
1532 | m_next(sm_first), | |
1533 | m_firstProperty(_Props), | |
1534 | m_firstHandler(_Handlers), | |
1535 | m_parents(_Parents), | |
583150e3 | 1536 | m_unitName(_UnitName), |
ab0881c7 VS |
1537 | m_constructor(_Constructor), |
1538 | m_constructorProperties(_ConstructorProperties), | |
1539 | m_constructorPropertiesCount(_ConstructorPropertiesCount), | |
1540 | m_variantOfPtrToObjectConverter(_PtrConverter1), | |
1541 | m_variantToObjectConverter(_Converter2), | |
1542 | m_objectToVariantConverter(_Converter3), | |
1543 | m_streamingCallback(_streamingCallback) | |
ae820c69 SC |
1544 | { |
1545 | sm_first = this; | |
1546 | Register() ; | |
1547 | } | |
1548 | ||
ab0881c7 | 1549 | wxClassInfo(const wxChar *_UnitName, const wxChar *_ClassName, |
583150e3 | 1550 | const wxClassInfo **_Parents) : |
ab0881c7 VS |
1551 | m_className(_ClassName), |
1552 | m_objectSize(0), | |
1553 | m_objectConstructor(NULL), | |
1554 | m_next(sm_first), | |
1555 | m_firstProperty(NULL), | |
1556 | m_firstHandler(NULL), | |
1557 | m_parents(_Parents), | |
1558 | m_unitName(_UnitName), | |
1559 | m_constructor(NULL), | |
1560 | m_constructorProperties(NULL), | |
1561 | m_constructorPropertiesCount(0), | |
1562 | m_variantOfPtrToObjectConverter(NULL), | |
1563 | m_variantToObjectConverter(NULL), | |
1564 | m_objectToVariantConverter(NULL), | |
1565 | m_streamingCallback(NULL) | |
ae820c69 SC |
1566 | { |
1567 | sm_first = this; | |
1568 | Register() ; | |
1569 | } | |
2d51f067 | 1570 | |
aeec2045 | 1571 | virtual ~wxClassInfo() ; |
a095505c | 1572 | |
ab6e4913 SC |
1573 | // allocates an instance of this class, this object does not have to be initialized or fully constructed |
1574 | // as this call will be followed by a call to Create | |
1575 | virtual wxObject *AllocateObject() const { return m_objectConstructor ? (*m_objectConstructor)() : 0; } | |
1576 | ||
1577 | // 'old naming' for AllocateObject staying here for backward compatibility | |
1578 | wxObject *CreateObject() const { return AllocateObject() ; } | |
a095505c | 1579 | |
583150e3 SC |
1580 | // direct construction call for classes that cannot construct instances via alloc/create |
1581 | wxObject *ConstructObject(int ParamCount, wxxVariant *Params) const | |
1582 | { | |
1583 | wxASSERT_MSG( ParamCount == m_constructorPropertiesCount , wxT("Illegal Parameter Count for ConstructObject Method")) ; | |
1584 | wxObject *object = NULL ; | |
1585 | m_constructor->Create( object , Params ) ; | |
1586 | return object ; | |
1587 | } | |
1588 | ||
1589 | bool NeedsDirectConstruction() const { return dynamic_cast<wxDirectConstructorBrigde*>( m_constructor) != NULL ; } | |
1590 | ||
a095505c | 1591 | const wxChar *GetClassName() const { return m_className; } |
9c8046dd | 1592 | const wxChar *GetIncludeName() const { return m_unitName ; } |
a095505c SC |
1593 | const wxClassInfo **GetParents() const { return m_parents; } |
1594 | int GetSize() const { return m_objectSize; } | |
1595 | ||
1596 | wxObjectConstructorFn GetConstructor() const { return m_objectConstructor; } | |
1597 | static const wxClassInfo *GetFirst() { return sm_first; } | |
1598 | const wxClassInfo *GetNext() const { return m_next; } | |
1599 | static wxClassInfo *FindClass(const wxChar *className); | |
1600 | ||
ae820c69 SC |
1601 | // Climb upwards through inheritance hierarchy. |
1602 | // Dual inheritance is catered for. | |
a095505c SC |
1603 | |
1604 | bool IsKindOf(const wxClassInfo *info) const | |
1605 | { | |
517fb871 VS |
1606 | if ( info != 0 ) |
1607 | { | |
1608 | if ( info == this ) | |
1609 | return true ; | |
1610 | ||
1611 | for ( int i = 0 ; m_parents[i] ; ++ i ) | |
1612 | { | |
1613 | if ( m_parents[i]->IsKindOf( info ) ) | |
1614 | return true ; | |
1615 | } | |
1616 | } | |
1617 | return false ; | |
a095505c SC |
1618 | } |
1619 | ||
ab0881c7 VS |
1620 | // if there is a callback registered with that class it will be called |
1621 | // before this object will be written to disk, it can veto streaming out | |
1622 | // this object by returning false, if this class has not registered a | |
1623 | // callback, the search will go up the inheritance tree if no callback has | |
1624 | // been registered true will be returned by default | |
9c8046dd SC |
1625 | bool BeforeWriteObject( const wxObject *obj, wxWriter *streamer , wxPersister *persister , wxxVariantArray &metadata) const ; |
1626 | ||
1627 | // gets the streaming callback from this class or any superclass | |
1628 | wxObjectStreamingCallback GetStreamingCallback() const ; | |
1629 | ||
aa8d7c2f | 1630 | #ifdef WXWIN_COMPATIBILITY_2_4 |
a095505c | 1631 | // Initializes parent pointers and hash table for fast searching. |
aa8d7c2f | 1632 | wxDEPRECATED( static void InitializeClasses() ); |
a095505c | 1633 | // Cleans up hash table used for fast searching. |
aa8d7c2f SC |
1634 | wxDEPRECATED( static void CleanUpClasses() ); |
1635 | #endif | |
1636 | static void CleanUp(); | |
75890a3f | 1637 | |
517fb871 VS |
1638 | // returns the first property |
1639 | const wxPropertyInfo* GetFirstProperty() const { return m_firstProperty ; } | |
a095505c | 1640 | |
517fb871 VS |
1641 | // returns the first handler |
1642 | const wxHandlerInfo* GetFirstHandler() const { return m_firstHandler ; } | |
a095505c | 1643 | |
ab6e4913 SC |
1644 | // Call the Create upon an instance of the class, in the end the object is fully |
1645 | // initialized | |
fa08490f | 1646 | virtual void Create (wxObject *object, int ParamCount, wxxVariant *Params) const |
ae820c69 SC |
1647 | { |
1648 | wxASSERT_MSG( ParamCount == m_constructorPropertiesCount , wxT("Illegal Parameter Count for Create Method")) ; | |
1649 | m_constructor->Create( object , Params ) ; | |
1650 | } | |
a095505c | 1651 | |
517fb871 VS |
1652 | // get number of parameters for constructor |
1653 | virtual int GetCreateParamCount() const { return m_constructorPropertiesCount; } | |
a095505c | 1654 | |
ab6e4913 SC |
1655 | // get n-th constructor parameter |
1656 | virtual const wxChar* GetCreateParamName(int n) const { return m_constructorProperties[n] ; } | |
a095505c | 1657 | |
ab6e4913 SC |
1658 | // Runtime access to objects for simple properties (get/set) by property name, and variant data |
1659 | virtual void SetProperty (wxObject *object, const wxChar *propertyName, const wxxVariant &value) const ; | |
1660 | virtual wxxVariant GetProperty (wxObject *object, const wxChar *propertyName) const; | |
1661 | ||
1662 | // Runtime access to objects for collection properties by property name | |
1663 | virtual wxxVariantArray GetPropertyCollection(wxObject *object, const wxChar *propertyName) const ; | |
16a45a23 | 1664 | virtual void AddToPropertyCollection(wxObject *object, const wxChar *propertyName , const wxxVariant& value) const ; |
a095505c | 1665 | |
ae820c69 SC |
1666 | // we must be able to cast variants to wxObject pointers, templates seem not to be suitable |
1667 | wxObject* VariantToInstance( wxxVariant &data ) const | |
1668 | { if ( data.GetTypeInfo()->GetKind() == wxT_OBJECT ) | |
1669 | return m_variantToObjectConverter( data ) ; | |
1670 | else | |
1671 | return m_variantOfPtrToObjectConverter( data ) ; | |
1672 | } | |
fa08490f | 1673 | |
ae820c69 | 1674 | wxxVariant InstanceToVariant( wxObject *object ) const { return m_objectToVariantConverter( object ) ; } |
4393b50c | 1675 | |
517fb871 | 1676 | // find property by name |
fbbdc52c SC |
1677 | virtual const wxPropertyInfo *FindPropertyInfo (const wxChar *PropertyName) const ; |
1678 | ||
517fb871 | 1679 | // find handler by name |
fbbdc52c | 1680 | virtual const wxHandlerInfo *FindHandlerInfo (const wxChar *PropertyName) const ; |
a095505c | 1681 | |
2d51f067 | 1682 | // find property by name |
492f9a9e | 1683 | virtual wxPropertyInfo *FindPropertyInfoInThisClass (const wxChar *PropertyName) const ; |
2d51f067 SC |
1684 | |
1685 | // find handler by name | |
492f9a9e | 1686 | virtual wxHandlerInfo *FindHandlerInfoInThisClass (const wxChar *PropertyName) const ; |
ae820c69 SC |
1687 | |
1688 | // puts all the properties of this class and its superclasses in the map, as long as there is not yet | |
1689 | // an entry with the same name (overriding mechanism) | |
1690 | void GetProperties( wxPropertyInfoMap &map ) const ; | |
a095505c SC |
1691 | public: |
1692 | const wxChar *m_className; | |
1693 | int m_objectSize; | |
1694 | wxObjectConstructorFn m_objectConstructor; | |
1695 | ||
1696 | // class info object live in a linked list: | |
1697 | // pointers to its head and the next element in it | |
1698 | ||
1699 | static wxClassInfo *sm_first; | |
1700 | wxClassInfo *m_next; | |
1701 | ||
517fb871 | 1702 | // FIXME: this should be private (currently used directly by way too |
a095505c SC |
1703 | // many clients) |
1704 | static wxHashTable *sm_classTable; | |
1705 | ||
2d51f067 | 1706 | protected : |
ae820c69 SC |
1707 | wxPropertyInfo * m_firstProperty ; |
1708 | wxHandlerInfo * m_firstHandler ; | |
a095505c | 1709 | private: |
ae820c69 | 1710 | const wxClassInfo** m_parents ; |
fa08490f SC |
1711 | const wxChar* m_unitName; |
1712 | ||
ae820c69 SC |
1713 | wxConstructorBridge* m_constructor ; |
1714 | const wxChar ** m_constructorProperties ; | |
1715 | const int m_constructorPropertiesCount ; | |
1716 | wxVariantToObjectConverter m_variantOfPtrToObjectConverter ; | |
1717 | wxVariantToObjectConverter m_variantToObjectConverter ; | |
1718 | wxObjectToVariantConverter m_objectToVariantConverter ; | |
9c8046dd | 1719 | wxObjectStreamingCallback m_streamingCallback ; |
2d51f067 | 1720 | const wxPropertyAccessor *FindAccessor (const wxChar *propertyName) const ; |
a095505c | 1721 | |
a095505c | 1722 | |
517fb871 | 1723 | // InitializeClasses() helper |
2d51f067 | 1724 | static wxClassInfo *GetBaseByName(const wxChar *name) ; |
75890a3f | 1725 | |
d1d738f1 VS |
1726 | protected: |
1727 | // registers the class | |
1728 | void Register(); | |
1729 | void Unregister(); | |
a095505c SC |
1730 | |
1731 | DECLARE_NO_COPY_CLASS(wxClassInfo) | |
1732 | }; | |
1733 | ||
2d51f067 | 1734 | |
a095505c SC |
1735 | WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name); |
1736 | ||
2d51f067 SC |
1737 | // ---------------------------------------------------------------------------- |
1738 | // wxDynamicObject | |
1739 | // ---------------------------------------------------------------------------- | |
1740 | // | |
1741 | // this object leads to having a pure runtime-instantiation | |
1742 | ||
492f9a9e | 1743 | class WXDLLIMPEXP_BASE wxDynamicClassInfo : public wxClassInfo |
2d51f067 SC |
1744 | { |
1745 | public : | |
1746 | wxDynamicClassInfo( const wxChar *_UnitName, const wxChar *_ClassName , const wxClassInfo* superClass ) ; | |
1747 | virtual ~wxDynamicClassInfo() ; | |
1748 | ||
1749 | // constructs a wxDynamicObject with an instance | |
ab6e4913 | 1750 | virtual wxObject *AllocateObject() const ; |
2d51f067 SC |
1751 | |
1752 | // Call the Create method for a class | |
1753 | virtual void Create (wxObject *object, int ParamCount, wxxVariant *Params) const ; | |
1754 | ||
1755 | // get number of parameters for constructor | |
1756 | virtual int GetCreateParamCount() const ; | |
1757 | ||
1758 | // get i-th constructor parameter | |
1759 | virtual const wxChar* GetCreateParamName(int i) const ; | |
1760 | ||
1761 | // Runtime access to objects by property name, and variant data | |
1762 | virtual void SetProperty (wxObject *object, const wxChar *PropertyName, const wxxVariant &Value) const ; | |
1763 | virtual wxxVariant GetProperty (wxObject *object, const wxChar *PropertyName) const ; | |
1764 | ||
2abce515 | 1765 | // adds a property to this class at runtime |
2d51f067 | 1766 | void AddProperty( const wxChar *propertyName , const wxTypeInfo* typeInfo ) ; |
2abce515 SC |
1767 | |
1768 | // removes an existing runtime-property | |
1769 | void RemoveProperty( const wxChar *propertyName ) ; | |
1770 | ||
492f9a9e SC |
1771 | // renames an existing runtime-property |
1772 | void RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName ) ; | |
1773 | ||
2abce515 | 1774 | // as a handler to this class at runtime |
2d51f067 | 1775 | void AddHandler( const wxChar *handlerName , wxObjectEventFunction address , const wxClassInfo* eventClassInfo ) ; |
2abce515 SC |
1776 | |
1777 | // removes an existing runtime-handler | |
1778 | void RemoveHandler( const wxChar *handlerName ) ; | |
492f9a9e SC |
1779 | |
1780 | // renames an existing runtime-handler | |
1781 | void RenameHandler( const wxChar *oldHandlerName , const wxChar *newHandlerName ) ; | |
2d51f067 SC |
1782 | } ; |
1783 | ||
a095505c SC |
1784 | // ---------------------------------------------------------------------------- |
1785 | // Dynamic class macros | |
1786 | // ---------------------------------------------------------------------------- | |
1787 | ||
1788 | #define _DECLARE_DYNAMIC_CLASS(name) \ | |
1789 | public: \ | |
ae820c69 SC |
1790 | static wxClassInfo sm_class##name; \ |
1791 | static const wxClassInfo* sm_classParents##name[] ; \ | |
1792 | static wxPropertyInfo* GetPropertiesStatic() ; \ | |
1793 | static wxHandlerInfo* GetHandlersStatic() ; \ | |
1794 | static wxClassInfo *GetClassInfoStatic() \ | |
1795 | { return &name::sm_class##name; } \ | |
2abce515 | 1796 | virtual wxClassInfo *GetClassInfo() const \ |
ae820c69 | 1797 | { return &name::sm_class##name; } |
a095505c SC |
1798 | |
1799 | #define DECLARE_DYNAMIC_CLASS(name) \ | |
ae820c69 SC |
1800 | static wxConstructorBridge* sm_constructor##name ; \ |
1801 | static const wxChar * sm_constructorProperties##name[] ; \ | |
1802 | static const int sm_constructorPropertiesCount##name ; \ | |
f0b7eadf | 1803 | _DECLARE_DYNAMIC_CLASS(name) |
a095505c SC |
1804 | |
1805 | #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \ | |
1806 | DECLARE_NO_ASSIGN_CLASS(name) \ | |
1807 | DECLARE_DYNAMIC_CLASS(name) | |
1808 | ||
1809 | #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \ | |
1810 | DECLARE_NO_COPY_CLASS(name) \ | |
1811 | DECLARE_DYNAMIC_CLASS(name) | |
1812 | ||
1813 | #define DECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name) | |
1814 | #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name) | |
1815 | ||
1816 | // ----------------------------------- | |
1817 | // for concrete classes | |
1818 | // ----------------------------------- | |
1819 | ||
ae820c69 | 1820 | // Single inheritance with one base class |
a095505c | 1821 | |
583150e3 SC |
1822 | #define _TYPEINFO_CLASSES(n , toString , fromString ) \ |
1823 | wxClassTypeInfo s_typeInfo##n(wxT_OBJECT , &n::sm_class##n , toString , fromString , typeid(n).name()) ; \ | |
1824 | wxClassTypeInfo s_typeInfoPtr##n(wxT_OBJECT_PTR , &n::sm_class##n , toString , fromString , typeid(n*).name()) ; | |
492f9a9e | 1825 | |
9c8046dd | 1826 | #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit , callback) \ |
ae820c69 SC |
1827 | wxObject* wxConstructorFor##name() \ |
1828 | { return new name; } \ | |
1829 | const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \ | |
1830 | wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \ | |
1831 | wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \ | |
1832 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \ | |
1833 | (int) sizeof(name), \ | |
1834 | (wxObjectConstructorFn) wxConstructorFor##name , \ | |
1835 | name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \ | |
583150e3 | 1836 | name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name , callback); |
fa08490f | 1837 | |
9c8046dd | 1838 | #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \ |
ae820c69 SC |
1839 | wxObject* wxConstructorFor##name() \ |
1840 | { return new name; } \ | |
1841 | const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \ | |
1842 | wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return &data.Get<name>() ; } \ | |
1843 | wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \ | |
1844 | wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \ | |
1845 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \ | |
1846 | (int) sizeof(name), \ | |
1847 | (wxObjectConstructorFn) wxConstructorFor##name , \ | |
1848 | name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \ | |
583150e3 | 1849 | name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name, callback); |
fa08490f SC |
1850 | |
1851 | #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \ | |
9c8046dd | 1852 | _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" , NULL ) \ |
583150e3 | 1853 | _TYPEINFO_CLASSES(name, NULL , NULL) \ |
ae820c69 SC |
1854 | const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \ |
1855 | const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \ | |
1856 | WX_CONSTRUCTOR_DUMMY( name ) | |
a095505c SC |
1857 | |
1858 | #define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \ | |
9c8046dd | 1859 | _IMPLEMENT_DYNAMIC_CLASS( name , basename , "" , NULL ) \ |
583150e3 SC |
1860 | _TYPEINFO_CLASSES(name, NULL , NULL) \ |
1861 | wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \ | |
ae820c69 SC |
1862 | wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \ |
1863 | WX_CONSTRUCTOR_DUMMY( name ) | |
a095505c SC |
1864 | |
1865 | #define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \ | |
583150e3 SC |
1866 | _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , NULL ) \ |
1867 | _TYPEINFO_CLASSES(name, NULL , NULL) | |
9c8046dd SC |
1868 | |
1869 | #define IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name , basename , unit , callback ) \ | |
583150e3 SC |
1870 | _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , &callback ) \ |
1871 | _TYPEINFO_CLASSES(name, NULL , NULL) | |
a095505c | 1872 | |
fa08490f | 1873 | #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \ |
583150e3 SC |
1874 | _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit , NULL ) \ |
1875 | _TYPEINFO_CLASSES(name, NULL , NULL) | |
1876 | ||
1877 | #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name , basename , unit , toString , fromString ) \ | |
1878 | _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit , NULL ) \ | |
1879 | _TYPEINFO_CLASSES(name, toString , fromString) | |
fa08490f | 1880 | |
4393b50c | 1881 | // this is for classes that do not derive from wxobject, there are no creators for these |
a095505c SC |
1882 | |
1883 | #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name , unit ) \ | |
ae820c69 SC |
1884 | const wxClassInfo* name::sm_classParents##name[] = { NULL } ; \ |
1885 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \ | |
1886 | (int) sizeof(name), \ | |
1887 | (wxObjectConstructorFn) 0 , \ | |
1888 | name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \ | |
1889 | 0 , 0 , 0 ); \ | |
583150e3 | 1890 | _TYPEINFO_CLASSES(name, NULL , NULL) |
a095505c SC |
1891 | |
1892 | // this is for subclasses that still do not derive from wxobject | |
1893 | ||
1894 | #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name , basename, unit ) \ | |
ae820c69 SC |
1895 | const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \ |
1896 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \ | |
1897 | (int) sizeof(name), \ | |
1898 | (wxObjectConstructorFn) 0 , \ | |
1899 | name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \ | |
1900 | 0 , 0 , 0 ); \ | |
583150e3 | 1901 | _TYPEINFO_CLASSES(name, NULL , NULL) |
ae820c69 SC |
1902 | |
1903 | ||
1904 | // Multiple inheritance with two base classes | |
a095505c SC |
1905 | |
1906 | #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit) \ | |
ae820c69 SC |
1907 | wxObject* wxConstructorFor##name() \ |
1908 | { return new name; } \ | |
1909 | const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,&basename2::sm_class##basename2 , NULL } ; \ | |
1910 | wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \ | |
1911 | wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \ | |
1912 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \ | |
1913 | (int) sizeof(name), \ | |
1914 | (wxObjectConstructorFn) wxConstructorFor##name , \ | |
1915 | name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \ | |
1916 | name::sm_constructorPropertiesCount##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \ | |
a095505c SC |
1917 | |
1918 | #define IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2) \ | |
ae820c69 | 1919 | _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , "") \ |
583150e3 | 1920 | _TYPEINFO_CLASSES(name, NULL , NULL) \ |
ae820c69 SC |
1921 | wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \ |
1922 | wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \ | |
1923 | WX_CONSTRUCTOR_DUMMY( name ) | |
a095505c SC |
1924 | |
1925 | #define IMPLEMENT_DYNAMIC_CLASS2_XTI( name , basename , basename2, unit) \ | |
583150e3 SC |
1926 | _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , unit) \ |
1927 | _TYPEINFO_CLASSES(name, NULL , NULL) | |
1928 | ||
a095505c SC |
1929 | |
1930 | // ----------------------------------- | |
1931 | // for abstract classes | |
1932 | // ----------------------------------- | |
1933 | ||
ae820c69 | 1934 | // Single inheritance with one base class |
a095505c SC |
1935 | |
1936 | #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \ | |
ae820c69 SC |
1937 | const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \ |
1938 | wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \ | |
1939 | wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \ | |
1940 | wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \ | |
1941 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \ | |
1942 | (int) sizeof(name), \ | |
1943 | (wxObjectConstructorFn) 0 , \ | |
1944 | name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \ | |
1945 | 0 , wxVariantOfPtrToObjectConverter##name ,wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \ | |
583150e3 | 1946 | _TYPEINFO_CLASSES(name, NULL , NULL) |
a095505c SC |
1947 | |
1948 | #define IMPLEMENT_ABSTRACT_CLASS( name , basename ) \ | |
ae820c69 SC |
1949 | _IMPLEMENT_ABSTRACT_CLASS( name , basename ) \ |
1950 | wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \ | |
1951 | wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } | |
a095505c | 1952 | |
ae820c69 | 1953 | // Multiple inheritance with two base classes |
a095505c SC |
1954 | |
1955 | #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \ | |
ae820c69 SC |
1956 | wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \ |
1957 | wxT(#basename2), (int) sizeof(name), \ | |
1958 | (wxObjectConstructorFn) 0); | |
a095505c SC |
1959 | |
1960 | #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS | |
1961 | #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2 | |
1962 | ||
208fd16c SC |
1963 | // -------------------------------------------------------------------------- |
1964 | // Collection Support | |
1965 | // -------------------------------------------------------------------------- | |
1966 | ||
2abce515 | 1967 | template<typename iter , typename collection_t > void wxListCollectionToVariantArray( const collection_t& coll , wxxVariantArray &value ) |
208fd16c | 1968 | { |
2abce515 | 1969 | iter current = coll.GetFirst() ; |
208fd16c SC |
1970 | while (current) |
1971 | { | |
1972 | value.Add( new wxxVariant(current->GetData()) ) ; | |
1973 | current = current->GetNext(); | |
1974 | } | |
1975 | } | |
1976 | ||
1977 | template<typename collection_t> void wxArrayCollectionToVariantArray( const collection_t& coll , wxxVariantArray &value ) | |
1978 | { | |
ae820c69 | 1979 | for( size_t i = 0 ; i < coll.GetCount() ; i++ ) |
208fd16c SC |
1980 | { |
1981 | value.Add( new wxxVariant(coll[i]) ) ; | |
1982 | } | |
1983 | } | |
1984 | ||
1985 | ||
aeec2045 | 1986 | #endif |