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