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