]>
Commit | Line | Data |
---|---|---|
a095505c SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/xti.h | |
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" | |
41 | #include "wx/set.h" | |
42 | #include "wx/string.h" | |
aeec2045 | 43 | #include "wx/arrstr.h" |
a095505c | 44 | |
438edbc0 SC |
45 | // some compilers have troubles getting the correct wxPropertyAccessorT constructor |
46 | // set this to 1 to make things work for these, too | |
47 | ||
31478355 | 48 | #ifndef WX_XTI_TEMPLATE_FIX |
438edbc0 | 49 | #define WX_XTI_TEMPLATE_FIX 0 |
31478355 | 50 | #endif |
438edbc0 SC |
51 | |
52 | #if WX_XTI_TEMPLATE_FIX | |
53 | #define WX_XTI_PARAM_FIX(a,b) a,b | |
54 | #else | |
55 | #define WX_XTI_PARAM_FIX(a,b) | |
56 | #endif | |
57 | ||
a095505c SC |
58 | class WXDLLIMPEXP_BASE wxObject; |
59 | class WXDLLIMPEXP_BASE wxClassInfo; | |
60 | class WXDLLIMPEXP_BASE wxHashTable; | |
61 | class WXDLLIMPEXP_BASE wxObjectRefData; | |
62 | class WXDLLIMPEXP_BASE wxEvent; | |
63 | ||
64 | typedef void (wxObject::*wxObjectEventFunction)(wxEvent&); | |
65 | ||
66 | // ---------------------------------------------------------------------------- | |
67 | // Enum Support | |
68 | // | |
4393b50c | 69 | // In the header files there would no change from pure c++ code, in the |
a095505c SC |
70 | // implementation, an enum would have |
71 | // to be enumerated eg : | |
72 | // | |
73 | // WX_BEGIN_ENUM( wxFlavor ) | |
74 | // WX_ENUM_MEMBER( Vanilla ) | |
75 | // WX_ENUM_MEMBER( Chocolate ) | |
76 | // WX_ENUM_MEMBER( Strawberry ) | |
77 | // WX_END_ENUM( wxFlavor ) | |
78 | // ---------------------------------------------------------------------------- | |
79 | ||
80 | struct WXDLLIMPEXP_BASE wxEnumMemberData | |
81 | { | |
517fb871 VS |
82 | const wxChar* m_name; |
83 | int m_value; | |
a095505c SC |
84 | }; |
85 | ||
86 | class WXDLLIMPEXP_BASE wxEnumData | |
87 | { | |
88 | public : | |
517fb871 | 89 | wxEnumData( wxEnumMemberData* data ) ; |
a095505c | 90 | |
517fb871 VS |
91 | // returns true if the member has been found and sets the int value |
92 | // pointed to accordingly (if ptr != null ) | |
93 | // if not found returns false, value left unchanged | |
94 | bool HasEnumMemberValue( const wxChar *name , int *value = NULL ) ; | |
4393b50c | 95 | |
517fb871 VS |
96 | // returns the value of the member, if not found in debug mode an |
97 | // assert is issued, in release 0 is returned | |
98 | int GetEnumMemberValue(const wxChar *name ); | |
4393b50c | 99 | |
517fb871 VS |
100 | // returns the name of the enum member having the passed in value |
101 | // returns an emtpy string if not found | |
a095505c | 102 | const wxChar *GetEnumMemberName(int value); |
4393b50c | 103 | |
517fb871 VS |
104 | // returns the number of members in this enum |
105 | int GetEnumCount() { return m_count ; } | |
4393b50c | 106 | |
517fb871 VS |
107 | // returns the value of the nth member |
108 | int GetEnumMemberValueByIndex( int n ) ; | |
4393b50c | 109 | |
517fb871 VS |
110 | // returns the value of the nth member |
111 | const wxChar *GetEnumMemberNameByIndex( int n ) ; | |
a095505c SC |
112 | private : |
113 | wxEnumMemberData *m_members; | |
517fb871 | 114 | int m_count ; |
a095505c SC |
115 | }; |
116 | ||
117 | #define WX_BEGIN_ENUM( e ) \ | |
517fb871 | 118 | wxEnumMemberData s_enumDataMembers##e[] = { |
a095505c SC |
119 | |
120 | #define WX_ENUM_MEMBER( v ) { #v, v } , | |
121 | ||
122 | #define WX_END_ENUM( e ) { NULL , 0 } } ; \ | |
517fb871 VS |
123 | wxEnumData s_enumData##e( s_enumDataMembers##e ) ; \ |
124 | wxEnumData *wxGetEnumData(e) { return &s_enumData##e ; } \ | |
125 | template<> const wxTypeInfo* wxGetTypeInfo( e * ){ static wxEnumTypeInfo s_typeInfo(wxT_ENUM , &s_enumData##e) ; return &s_typeInfo ; } \ | |
126 | template<> void wxStringReadValue(const wxString& s , e &data ) \ | |
127 | { \ | |
128 | data = (e) s_enumData##e.GetEnumMemberValue(s) ; \ | |
129 | } \ | |
130 | template<> void wxStringWriteValue(wxString &s , const e &data ) \ | |
131 | { \ | |
132 | s = s_enumData##e.GetEnumMemberName((int)data) ; \ | |
f0b7eadf SC |
133 | } \ |
134 | template<> const wxTypeInfo* wxGetTypeInfo( e ** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; assert(0) ; return &s_typeInfo ; } \ | |
135 | template<> void wxStringReadValue(const wxString& , e* & ) \ | |
136 | { \ | |
137 | assert(0) ; \ | |
138 | } \ | |
139 | template<> void wxStringWriteValue(wxString &s , e* const & ) \ | |
140 | { \ | |
141 | assert(0) ; \ | |
517fb871 | 142 | } |
a095505c SC |
143 | |
144 | // ---------------------------------------------------------------------------- | |
145 | // Set Support | |
4393b50c | 146 | // |
a095505c | 147 | // in the header : |
4393b50c | 148 | // |
a095505c | 149 | // enum wxFlavor |
4393b50c | 150 | // { |
517fb871 VS |
151 | // Vanilla, |
152 | // Chocolate, | |
153 | // Strawberry, | |
a095505c | 154 | // }; |
4393b50c | 155 | // |
a095505c | 156 | // typedef wxSet<wxFlavor> wxCoupe ; |
4393b50c | 157 | // |
a095505c | 158 | // in the implementation file : |
4393b50c | 159 | // |
a095505c | 160 | // WX_BEGIN_ENUM( wxFlavor ) |
517fb871 VS |
161 | // WX_ENUM_MEMBER( Vanilla ) |
162 | // WX_ENUM_MEMBER( Chocolate ) | |
163 | // WX_ENUM_MEMBER( Strawberry ) | |
a095505c | 164 | // WX_END_ENUM( wxFlavor ) |
a095505c | 165 | // |
4393b50c SC |
166 | // WX_IMPLEMENT_SET_STREAMING( wxCoupe , wxFlavor ) |
167 | // | |
168 | // implementation note : no partial specialization for streaming, but a delegation to a | |
a095505c SC |
169 | // different class |
170 | // | |
171 | // ---------------------------------------------------------------------------- | |
172 | ||
173 | // in order to remove dependancy on string tokenizer | |
174 | void wxSetStringToArray( const wxString &s , wxArrayString &array ) ; | |
175 | ||
176 | template<typename e> | |
4393b50c | 177 | void wxSetFromString(const wxString &s , wxSet<e> &data ) |
a095505c | 178 | { |
517fb871 VS |
179 | wxEnumData* edata = wxGetEnumData((e) 0) ; |
180 | data.Clear() ; | |
a095505c | 181 | |
517fb871 VS |
182 | wxArrayString array ; |
183 | wxSetStringToArray( s , array ) ; | |
a095505c SC |
184 | wxString flag; |
185 | for ( int i = 0 ; i < array.Count() ; ++i ) | |
186 | { | |
187 | flag = array[i] ; | |
517fb871 VS |
188 | int ivalue ; |
189 | if ( edata->HasEnumMemberValue( flag , &ivalue ) ) | |
190 | { | |
191 | data.Set( (e) ivalue ) ; | |
192 | } | |
a095505c SC |
193 | } |
194 | } | |
195 | ||
196 | template<typename e> | |
197 | void wxSetToString( wxString &s , const wxSet<e> &data ) | |
198 | { | |
517fb871 VS |
199 | wxEnumData* edata = wxGetEnumData((e) 0) ; |
200 | int count = edata->GetEnumCount() ; | |
201 | int i ; | |
202 | s.Clear() ; | |
203 | for ( i = 0 ; i < count ; i++ ) | |
204 | { | |
205 | e value = (e) edata->GetEnumMemberValueByIndex(i) ; | |
206 | if ( data.Contains( value ) ) | |
207 | { | |
208 | // this could also be done by the templated calls | |
209 | if ( !s.IsEmpty() ) | |
210 | s +="|" ; | |
211 | s += edata->GetEnumMemberNameByIndex(i) ; | |
212 | } | |
213 | } | |
a095505c SC |
214 | } |
215 | ||
216 | // if the wxSet specialization above does not work for all compilers, add this to the WX_IMPLEMENT_SET_STREAMING macro | |
517fb871 | 217 | // template<> const wxTypeInfo* wxGetTypeInfo( SetName * ){ static wxEnumTypeInfo s_typeInfo(wxT_SET , &s_enumData##e) ; return &s_typeInfo ; } |
a095505c SC |
218 | |
219 | #define WX_IMPLEMENT_SET_STREAMING(SetName,e) \ | |
517fb871 VS |
220 | template<> void wxStringReadValue(const wxString &s , wxSet<e> &data ) \ |
221 | { \ | |
222 | wxSetFromString( s , data ) ; \ | |
223 | } \ | |
224 | template<> void wxStringWriteValue( wxString &s , const wxSet<e> &data ) \ | |
225 | { \ | |
226 | wxSetToString( s , data ) ; \ | |
227 | } \ | |
a095505c SC |
228 | |
229 | ||
230 | // ---------------------------------------------------------------------------- | |
231 | // Type Information | |
232 | // ---------------------------------------------------------------------------- | |
233 | ||
234 | enum wxTypeKind | |
235 | { | |
236 | wxT_VOID = 0, // unknown type | |
237 | wxT_BOOL, | |
238 | wxT_CHAR, | |
239 | wxT_UCHAR, | |
240 | wxT_INT, | |
241 | wxT_UINT, | |
242 | wxT_LONG, | |
243 | wxT_ULONG, | |
244 | wxT_FLOAT, | |
245 | wxT_DOUBLE, | |
246 | wxT_STRING, // must be wxString | |
247 | wxT_SET, // must be wxSet<> template | |
248 | wxT_ENUM, | |
fa08490f SC |
249 | wxT_OBJECT_PTR, // pointer to wxObject |
250 | wxT_OBJECT , // wxObject | |
a095505c | 251 | wxT_CUSTOM, // user defined type (e.g. wxPoint) |
517fb871 | 252 | wxT_DELEGATE , // for connecting against an event source |
a095505c SC |
253 | wxT_LAST_TYPE_KIND // sentinel for bad data, asserts, debugging |
254 | }; | |
255 | ||
256 | class WXDLLIMPEXP_BASE wxTypeInfo | |
257 | { | |
258 | public : | |
fa08490f SC |
259 | wxTypeInfo() : m_kind( wxT_VOID) {} |
260 | virtual ~wxTypeInfo() {} | |
261 | wxTypeKind GetKind() const { return m_kind ; } | |
262 | bool IsDelegateType() const { return m_kind == wxT_DELEGATE ; } | |
263 | bool IsCustomType() const { return m_kind == wxT_CUSTOM ; } | |
264 | bool IsObjectType() const { return m_kind == wxT_OBJECT || m_kind == wxT_OBJECT_PTR ; } | |
a095505c | 265 | protected : |
fa08490f | 266 | wxTypeKind m_kind ; |
a095505c SC |
267 | }; |
268 | ||
269 | class WXDLLIMPEXP_BASE wxBuiltInTypeInfo : public wxTypeInfo | |
270 | { | |
271 | public : | |
517fb871 | 272 | wxBuiltInTypeInfo( wxTypeKind kind ) { wxASSERT_MSG( kind < wxT_SET , wxT("Illegal Kind for Base Type") ) ; m_kind = kind ;} |
a095505c SC |
273 | } ; |
274 | ||
275 | class WXDLLIMPEXP_BASE wxCustomTypeInfo : public wxTypeInfo | |
276 | { | |
277 | public : | |
517fb871 VS |
278 | wxCustomTypeInfo( const wxChar *typeName ) |
279 | { m_kind = wxT_CUSTOM ; m_typeName = typeName ;} | |
280 | const wxChar *GetTypeName() const { return m_typeName ; } | |
a095505c | 281 | private : |
517fb871 | 282 | const wxChar *m_typeName; // Kind == wxT_CUSTOM |
a095505c SC |
283 | } ; |
284 | ||
285 | class WXDLLIMPEXP_BASE wxEnumTypeInfo : public wxTypeInfo | |
286 | { | |
287 | public : | |
517fb871 VS |
288 | wxEnumTypeInfo( wxTypeKind kind , wxEnumData* enumInfo ) |
289 | { wxASSERT_MSG( kind == wxT_ENUM || kind == wxT_SET , wxT("Illegal Kind for Enum Type")) ; m_kind = kind ; m_enumInfo = enumInfo ;} | |
290 | const wxEnumData* GetEnumData() const { return m_enumInfo ; } | |
a095505c | 291 | private : |
517fb871 | 292 | wxEnumData *m_enumInfo; // Kind == wxT_ENUM or Kind == wxT_SET |
a095505c SC |
293 | } ; |
294 | ||
295 | class WXDLLIMPEXP_BASE wxClassTypeInfo : public wxTypeInfo | |
296 | { | |
297 | public : | |
fa08490f SC |
298 | wxClassTypeInfo( wxTypeKind kind , wxClassInfo* classInfo ) |
299 | { wxASSERT_MSG( kind == wxT_OBJECT_PTR || kind == wxT_OBJECT , wxT("Illegal Kind for Enum Type")) ; m_kind = kind ; m_classInfo = classInfo ;} | |
300 | const wxClassInfo *GetClassInfo() const { return m_classInfo ; } | |
a095505c | 301 | private : |
517fb871 | 302 | wxClassInfo *m_classInfo; // Kind == wxT_OBJECT - could be NULL |
a095505c SC |
303 | } ; |
304 | ||
4393b50c | 305 | // a delegate is an exposed event source |
a095505c SC |
306 | |
307 | class WXDLLIMPEXP_BASE wxDelegateTypeInfo : public wxTypeInfo | |
308 | { | |
309 | public : | |
517fb871 VS |
310 | wxDelegateTypeInfo( int eventType , wxClassInfo* eventClass ) |
311 | { m_kind = wxT_DELEGATE ; m_eventClass = eventClass ; m_eventType = eventType ;} | |
312 | const wxClassInfo *GetEventClass() const { assert( m_kind == wxT_DELEGATE ) ; return m_eventClass ; } | |
313 | int GetEventType() const { return m_eventType ; } | |
a095505c | 314 | private : |
517fb871 VS |
315 | const wxClassInfo *m_eventClass; // (extended will merge into classinfo) |
316 | int m_eventType ; | |
a095505c SC |
317 | } ; |
318 | ||
319 | template<typename T> const wxTypeInfo* wxGetTypeInfo( T * ) ; | |
320 | ||
4393b50c | 321 | template<typename T> const wxTypeInfo* wxGetTypeInfo( wxSet<T> * ) |
a095505c | 322 | { |
517fb871 | 323 | static wxEnumTypeInfo s_typeInfo(wxT_SET , wxGetEnumData((T) 0) ) ; return &s_typeInfo ; |
a095505c SC |
324 | } |
325 | ||
326 | // this macro is for usage with custom, non-object derived classes and structs, wxPoint is such a custom type | |
327 | ||
328 | #define WX_CUSTOM_TYPE_INFO( e ) \ | |
f0b7eadf SC |
329 | template<> const wxTypeInfo* wxGetTypeInfo( e ** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID) ; assert(0) ; return &s_typeInfo ; } \ |
330 | template<> const wxTypeInfo* wxGetTypeInfo( e * ){ static wxCustomTypeInfo s_typeInfo(#e) ; return &s_typeInfo ; } | |
a095505c | 331 | |
a095505c SC |
332 | // templated streaming, every type must have their specialization for these methods |
333 | ||
334 | template<typename T> | |
f0b7eadf | 335 | void wxStringReadValue( const wxString &s , T &data ); |
a095505c SC |
336 | |
337 | template<typename T> | |
f0b7eadf | 338 | void wxStringWriteValue( wxString &s , const T &data); |
a095505c | 339 | |
aa8d7c2f | 340 | // sometimes a compiler invents specializations that are nowhere called, use this macro to satisfy the refs |
a095505c | 341 | |
aa8d7c2f SC |
342 | #define WX_ILLEGAL_TYPE_SPECIALIZATION( a ) \ |
343 | template<> const wxTypeInfo* wxGetTypeInfo( a * ) { assert(0) ; \ | |
344 | static wxBuiltInTypeInfo s_typeInfo( wxT_VOID ) ; return &s_typeInfo ; } \ | |
345 | template<> void wxStringReadValue(const wxString & , a & ) { assert(0) ; }\ | |
346 | template<> void wxStringWriteValue(wxString & , a const & ) { assert(0) ; } | |
a095505c SC |
347 | |
348 | // ---------------------------------------------------------------------------- | |
349 | // wxxVariant as typesafe data holder | |
350 | // ---------------------------------------------------------------------------- | |
351 | ||
352 | class WXDLLIMPEXP_BASE wxxVariantData | |
353 | { | |
354 | public: | |
517fb871 | 355 | virtual ~wxxVariantData() {} |
a095505c | 356 | |
517fb871 VS |
357 | // return a heap allocated duplicate |
358 | virtual wxxVariantData* Clone() const = 0 ; | |
a095505c | 359 | |
517fb871 VS |
360 | // returns the type info of the contentc |
361 | virtual const wxTypeInfo* GetTypeInfo() const = 0 ; | |
a095505c | 362 | |
517fb871 VS |
363 | // write the value into a string |
364 | virtual void Write( wxString &s ) const = 0 ; | |
a095505c | 365 | |
517fb871 VS |
366 | // read the value from a string |
367 | virtual void Read( const wxString &s) = 0 ; | |
a095505c SC |
368 | } ; |
369 | ||
370 | template<typename T> class WXDLLIMPEXP_BASE wxxVariantDataT : public wxxVariantData | |
371 | { | |
372 | public: | |
fa08490f SC |
373 | wxxVariantDataT(const T& d) : m_data(d) {} |
374 | virtual ~wxxVariantDataT() {} | |
a095505c | 375 | |
fa08490f SC |
376 | // get a ref to the stored data |
377 | T & Get() { return m_data; } | |
a095505c | 378 | |
fa08490f SC |
379 | // get a const ref to the stored data |
380 | const T & Get() const { return m_data; } | |
381 | ||
382 | // set the data | |
383 | void Set(const T& d) { m_data = d; } | |
a095505c | 384 | |
517fb871 VS |
385 | // return a heap allocated duplicate |
386 | virtual wxxVariantData* Clone() const { return new wxxVariantDataT<T>( Get() ) ; } | |
a095505c | 387 | |
517fb871 VS |
388 | // returns the type info of the contentc |
389 | virtual const wxTypeInfo* GetTypeInfo() const { return wxGetTypeInfo( (T*) NULL ) ; } | |
a095505c | 390 | |
517fb871 VS |
391 | // write the value into a string |
392 | virtual void Write( wxString &s ) const { wxStringWriteValue( s , m_data ) ; } | |
a095505c | 393 | |
517fb871 VS |
394 | // read the value from a string |
395 | virtual void Read( const wxString &s) { wxStringReadValue( s , m_data ) ; } | |
a095505c SC |
396 | |
397 | private: | |
398 | T m_data; | |
399 | }; | |
400 | ||
401 | class WXDLLIMPEXP_BASE wxxVariant | |
402 | { | |
403 | public : | |
fa08490f SC |
404 | wxxVariant() { m_data = NULL ; } |
405 | wxxVariant( wxxVariantData* data , const wxString& name = wxT("") ) : m_data(data) , m_name(name) {} | |
406 | wxxVariant( const wxxVariant &d ) { if ( d.m_data ) m_data = d.m_data->Clone() ; else m_data = NULL ; m_name = d.m_name ; } | |
407 | ||
408 | template<typename T> wxxVariant( T data , const wxString& name = wxT("") ) : | |
409 | m_data(new wxxVariantDataT<T>(data) ), m_name(name) {} | |
410 | ~wxxVariant() { delete m_data ; } | |
411 | ||
412 | // get a ref to the stored data | |
413 | template<typename T> T& Get() | |
414 | { | |
415 | wxxVariantDataT<T> *dataptr = dynamic_cast<wxxVariantDataT<T>*> (m_data) ; | |
416 | wxASSERT_MSG( dataptr , "Cast not possible" ) ; | |
417 | return dataptr->Get() ; | |
418 | } | |
419 | ||
420 | // get a ref to the stored data | |
421 | template<typename T> const T& Get() const | |
422 | { | |
423 | const wxxVariantDataT<T> *dataptr = dynamic_cast<const wxxVariantDataT<T>*> (m_data) ; | |
424 | wxASSERT_MSG( dataptr , "Cast not possible" ) ; | |
425 | return dataptr->Get() ; | |
426 | } | |
427 | ||
428 | // stores the data | |
429 | template<typename T> void Set(const T& data) const | |
430 | { | |
431 | delete m_data ; | |
432 | m_data = new wxxVariantDataT<T>(data) ; | |
433 | } | |
434 | ||
435 | wxxVariant& operator=(const wxxVariant &d) | |
436 | { | |
437 | m_data = d.m_data->Clone() ; | |
438 | m_name = d.m_name ; | |
439 | return *this ; | |
440 | } | |
441 | ||
442 | // gets the stored data casted to a wxObject* , returning NULL if cast is not possible | |
443 | wxObject* GetAsObject() ; | |
444 | ||
445 | // get the typeinfo of the stored object | |
446 | const wxTypeInfo* GetTypeInfo() const { return m_data->GetTypeInfo() ; } | |
447 | ||
aa8d7c2f | 448 | // write the value into a string |
fa08490f SC |
449 | void Write( wxString &s ) const { m_data->Write( s ) ; } |
450 | ||
451 | // read the value from a string | |
452 | void Read( const wxString &s) { m_data->Read( s ) ; } | |
453 | ||
454 | // returns this value as string | |
455 | wxString GetAsString() const | |
456 | { | |
457 | wxString s ; | |
458 | Write( s ) ; | |
459 | return s ; | |
460 | } | |
461 | ||
462 | void SetFromString( const wxString &s) | |
463 | { | |
464 | Read( s ) ; | |
465 | } | |
a095505c | 466 | private : |
517fb871 VS |
467 | wxxVariantData* m_data ; |
468 | wxString m_name ; | |
a095505c SC |
469 | } ; |
470 | ||
471 | // ---------------------------------------------------------------------------- | |
472 | // Property Support | |
473 | // | |
474 | // wxPropertyInfo is used to inquire of the property by name. It doesn't | |
475 | // provide access to the property, only information about it. If you | |
476 | // want access, look at wxPropertyAccessor. | |
477 | // ---------------------------------------------------------------------------- | |
478 | ||
479 | class WXDLLIMPEXP_BASE wxPropertyAccessor | |
480 | { | |
481 | public : | |
438edbc0 | 482 | #if WX_XTI_TEMPLATE_FIX |
4393b50c | 483 | class SetByRef ; |
fa08490f SC |
484 | class SetByRefRetBool ; |
485 | class SetRetBool ; | |
4393b50c | 486 | class SetAndGetByRef ; |
fa08490f | 487 | class SetAndGetByRefRetBool ; |
4393b50c | 488 | class GetByRef ; |
438edbc0 | 489 | #endif |
2d51f067 SC |
490 | wxPropertyAccessor() { m_setterName = NULL ; m_getterName = NULL ; } |
491 | virtual ~wxPropertyAccessor() {} | |
a095505c | 492 | virtual void SetProperty(wxObject *object, const wxxVariant &value) const = 0 ; |
aa8d7c2f | 493 | virtual wxxVariant GetProperty(const wxObject *object) const = 0 ; |
a095505c SC |
494 | virtual bool HasSetter() const = 0 ; |
495 | virtual bool HasGetter() const = 0 ; | |
517fb871 VS |
496 | const wxChar * GetGetterName() const { return m_setterName ; } |
497 | const wxChar * GetSetterName() const { return m_getterName ; } | |
517fb871 | 498 | virtual wxxVariant ReadValue( const wxString &value ) const = 0 ; |
aa8d7c2f | 499 | virtual void WriteValue( wxString& value , const wxObject *o ) const = 0 ; |
a095505c | 500 | protected : |
517fb871 VS |
501 | const wxChar *m_setterName ; |
502 | const wxChar *m_getterName ; | |
a095505c SC |
503 | }; |
504 | ||
2d51f067 SC |
505 | class WXDLLIMPEXP_BASE wxGenericPropertyAccessor : public wxPropertyAccessor |
506 | { | |
507 | public : | |
508 | wxGenericPropertyAccessor( const wxChar* propertyName ) ; | |
509 | ~wxGenericPropertyAccessor() ; | |
510 | virtual void SetProperty(wxObject *object, const wxxVariant &value) const ; | |
511 | virtual wxxVariant GetProperty(const wxObject *object) const ; | |
512 | virtual bool HasSetter() const { return true ; } | |
513 | virtual bool HasGetter() const { return true ; } | |
514 | virtual wxxVariant ReadValue( const wxString &value ) const ; | |
515 | virtual void WriteValue( wxString& value , const wxObject *o ) const ; | |
516 | private : | |
517 | struct wxGenericPropertyAccessorInternal ; | |
518 | wxGenericPropertyAccessorInternal* m_data ; | |
519 | } ; | |
520 | ||
a095505c SC |
521 | template<class Klass, typename T> |
522 | class WXDLLIMPEXP_BASE wxPropertyAccessorT : public wxPropertyAccessor | |
523 | { | |
524 | public: | |
4393b50c | 525 | |
a095505c | 526 | typedef void (Klass::*setter_t)(T value); |
fa08490f | 527 | typedef bool (Klass::*setter_bool_t)(T value); |
fbbdc52c | 528 | typedef void (Klass::*setter_ref_t)(const T& value); |
fa08490f | 529 | typedef bool (Klass::*setter_ref_bool_t)(const T& value); |
a095505c SC |
530 | typedef T (Klass::*getter_t)() const; |
531 | typedef const T& (Klass::*getter_ref_t)() const; | |
532 | ||
fbbdc52c | 533 | wxPropertyAccessorT(setter_t setter, getter_t getter, const wxChar *g, const wxChar *s) |
fa08490f | 534 | : m_setter_bool( NULL ) , m_setter_ref_bool( NULL ) , m_setter(setter), m_setter_ref(NULL), m_getter(getter) ,m_getter_ref(NULL) {m_setterName = s;m_getterName=g ;} |
4393b50c SC |
535 | |
536 | wxPropertyAccessorT( getter_t getter, const wxChar *g) | |
fa08490f SC |
537 | : m_setter_bool( NULL ) , m_setter_ref_bool( NULL ) , m_setter(NULL), m_setter_ref(NULL), m_getter(getter) ,m_getter_ref(NULL) {m_setterName = "";m_getterName=g ;} |
538 | ||
438edbc0 | 539 | wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetRetBool*,) setter_bool_t setter, getter_t getter, const wxChar *g, const wxChar *s) |
fa08490f | 540 | : m_setter_bool( setter ) , m_setter_ref_bool( NULL ) , m_setter(NULL), m_setter_ref(NULL), m_getter(getter) , m_getter_ref(NULL){m_setterName = s;m_getterName=g ;} |
4393b50c | 541 | |
438edbc0 | 542 | wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetByRef*,) setter_ref_t setter, getter_t getter, const wxChar *g, const wxChar *s) |
fa08490f | 543 | : m_setter_bool( NULL ) , m_setter_ref_bool( NULL ) , m_setter(NULL), m_setter_ref(setter), m_getter(getter) , m_getter_ref(NULL){m_setterName = s;m_getterName=g ;} |
4393b50c | 544 | |
438edbc0 | 545 | wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetByRefRetBool*,) setter_ref_bool_t setter, getter_t getter, const wxChar *g, const wxChar *s) |
fa08490f | 546 | : m_setter_bool( NULL ) , m_setter_ref_bool( setter ) , m_setter(NULL), m_setter_ref(NULL), m_getter(getter) , m_getter_ref(NULL){m_setterName = s;m_getterName=g ;} |
4393b50c | 547 | |
438edbc0 | 548 | wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetAndGetByRef*,) setter_ref_t setter, getter_ref_t getter, const wxChar *g, const wxChar *s) |
fa08490f SC |
549 | : m_setter_bool( NULL ) , m_setter_ref_bool( NULL ) , m_setter(NULL), m_setter_ref(setter), m_getter(NULL) , m_getter_ref(getter){m_setterName = s;m_getterName=g ;} |
550 | ||
438edbc0 | 551 | wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetAndGetByRefRetBool*,) setter_ref_bool_t setter, getter_ref_t getter, const wxChar *g, const wxChar *s) |
fa08490f | 552 | : m_setter_bool( NULL ) , m_setter_ref_bool( setter ) , m_setter(NULL), m_setter_ref(NULL), m_getter(NULL) , m_getter_ref(getter){m_setterName = s;m_getterName=g ;} |
4393b50c | 553 | |
438edbc0 | 554 | wxPropertyAccessorT(WX_XTI_PARAM_FIX(GetByRef*,) setter_t setter, getter_ref_t getter, const wxChar *g, const wxChar *s) |
fa08490f | 555 | : m_setter_bool( NULL ) , m_setter_ref_bool( NULL ) , m_setter(NULL), m_setter(setter), m_getter(NULL) , m_getter_ref(getter){m_setterName = s;m_getterName=g ;} |
4393b50c | 556 | |
517fb871 | 557 | // returns true if this accessor has a setter |
2d51f067 | 558 | bool HasSetter() const { return m_setter != NULL || m_setter_ref != NULL || m_setter_ref_bool != NULL || m_setter_bool ; } |
a095505c | 559 | |
517fb871 VS |
560 | // return true if this accessor has a getter |
561 | bool HasGetter() const { return m_getter != NULL || m_getter_ref != NULL ; } | |
a095505c | 562 | |
517fb871 VS |
563 | // set the property this accessor is responsible for in an object |
564 | void SetProperty(wxObject *o, const wxxVariant &v) const | |
a095505c SC |
565 | { |
566 | Klass *obj = dynamic_cast<Klass*>(o); | |
fa08490f SC |
567 | T value ; |
568 | ||
569 | if ( wxGetTypeInfo((T*)NULL)->GetKind() == wxT_OBJECT && v.GetTypeInfo()->GetKind() == wxT_OBJECT_PTR ) | |
570 | value = *v.Get<T*>(); | |
571 | else | |
572 | value = v.Get<T>(); | |
a095505c SC |
573 | if (m_setter) |
574 | (obj->*(m_setter))(value); | |
fa08490f SC |
575 | else if ( m_setter_ref ) |
576 | (obj->*(m_setter_ref))(value); | |
577 | else if ( m_setter_ref_bool ) | |
578 | (obj->*(m_setter_ref_bool))(value); | |
579 | else if ( m_setter_bool ) | |
580 | (obj->*(m_setter_bool))(value); | |
581 | else | |
582 | { | |
583 | wxASSERT_MSG(0 , wxT("SetPropertyCalled without a valid Setter") ) ; | |
584 | } | |
585 | } | |
a095505c | 586 | |
517fb871 | 587 | // gets the property this accessor is responsible for from an object |
aa8d7c2f | 588 | wxxVariant GetProperty(const wxObject *o) const |
a095505c | 589 | { |
517fb871 | 590 | return wxxVariant( (wxxVariantData* ) DoGetProperty( o ) ) ; |
a095505c SC |
591 | } |
592 | ||
517fb871 VS |
593 | // write the property this accessor is responsible for from an object into |
594 | // a string | |
aa8d7c2f | 595 | void WriteValue( wxString& s , const wxObject *o ) const |
517fb871 VS |
596 | { |
597 | DoGetProperty( o )->Write( s ) ; | |
598 | } | |
599 | ||
517fb871 VS |
600 | // read a wxxVariant having the correct type for the property this accessor |
601 | // is responsible for from a string | |
602 | wxxVariant ReadValue( const wxString &value ) const | |
603 | { | |
604 | T data ; | |
605 | wxStringReadValue( value , data ) ; | |
606 | return wxxVariant( data ) ; | |
607 | } | |
a095505c SC |
608 | |
609 | private : | |
aa8d7c2f | 610 | wxxVariantDataT<T>* DoGetProperty(const wxObject *o) const |
a095505c | 611 | { |
aa8d7c2f | 612 | const Klass *obj = dynamic_cast<const Klass*>(o); |
517fb871 VS |
613 | if ( m_getter ) |
614 | return new wxxVariantDataT<T>( (obj->*(m_getter))() ) ; | |
615 | else | |
616 | return new wxxVariantDataT<T>( (obj->*(m_getter_ref))() ) ; | |
a095505c SC |
617 | } |
618 | ||
619 | setter_t m_setter; | |
620 | setter_ref_t m_setter_ref; | |
fa08490f SC |
621 | setter_ref_bool_t m_setter_ref_bool ; |
622 | setter_bool_t m_setter_bool ; | |
a095505c | 623 | getter_t m_getter; |
517fb871 | 624 | getter_ref_t m_getter_ref ; |
a095505c SC |
625 | }; |
626 | ||
627 | class WXDLLIMPEXP_BASE wxPropertyInfo | |
628 | { | |
629 | public : | |
fa08490f SC |
630 | wxPropertyInfo( wxPropertyInfo* &iter , const wxChar *name , const wxChar *typeName , const wxTypeInfo* typeInfo , wxPropertyAccessor *accessor , wxxVariant dv ) : |
631 | m_name( name ) , m_typeName(typeName) , m_typeInfo( typeInfo ) , m_accessor( accessor ) , m_defaultValue( dv ) | |
632 | { | |
633 | m_next = NULL ; | |
634 | if ( iter == NULL ) | |
635 | iter = this ; | |
636 | else | |
637 | { | |
638 | wxPropertyInfo* i = iter ; | |
639 | while( i->m_next ) | |
640 | i = i->m_next ; | |
641 | ||
642 | i->m_next = this ; | |
643 | } | |
644 | } | |
645 | // return the name of this property | |
646 | const wxChar * GetName() const { return m_name ; } | |
647 | ||
648 | // return the typename of this property | |
649 | const wxChar * GetTypeName() const { return m_typeName ; } | |
650 | ||
651 | // return the type info of this property | |
652 | const wxTypeInfo * GetTypeInfo() const { return m_typeInfo ; } | |
653 | ||
654 | // return the accessor for this property | |
655 | wxPropertyAccessor* GetAccessor() const { return m_accessor ; } | |
656 | ||
657 | // returns NULL if this is the last property of this class | |
658 | wxPropertyInfo* GetNext() const { return m_next ; } | |
659 | ||
660 | // returns the default value of this property, its kind may be wxT_VOID if it is not valid | |
661 | wxxVariant GetDefaultValue() const { return m_defaultValue ; } | |
4393b50c | 662 | private : |
517fb871 VS |
663 | const wxChar * m_name; |
664 | const wxChar * m_typeName ; | |
665 | const wxTypeInfo* m_typeInfo ; | |
666 | wxPropertyAccessor* m_accessor ; | |
4393b50c | 667 | wxxVariant m_defaultValue; |
517fb871 VS |
668 | // string representation of the default value |
669 | // to be assigned by the designer to the property | |
670 | // when the component is dropped on the container. | |
671 | wxPropertyInfo* m_next ; | |
a095505c SC |
672 | }; |
673 | ||
674 | #define WX_BEGIN_PROPERTIES_TABLE(theClass) \ | |
2d51f067 | 675 | wxPropertyInfo *theClass::GetPropertiesStatic() \ |
a095505c SC |
676 | { \ |
677 | typedef theClass class_t; \ | |
517fb871 | 678 | static wxPropertyInfo* first = NULL ; |
a095505c SC |
679 | |
680 | #define WX_END_PROPERTIES_TABLE() \ | |
517fb871 | 681 | return first ; } |
a095505c | 682 | |
438edbc0 SC |
683 | |
684 | #if WX_XTI_TEMPLATE_FIX | |
685 | ||
a095505c | 686 | #define WX_PROPERTY( name , type , setter , getter ,defaultValue ) \ |
fa08490f SC |
687 | static wxPropertyAccessorT<class_t , type> _accessor##name( &setter , &getter , #setter , #getter ) ; \ |
688 | static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ; | |
689 | ||
690 | #define WX_PROPERTY_SET_RET_BOOL( name , type , setter , getter ,defaultValue ) \ | |
691 | static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetRetBool*)NULL , &setter , &getter , #setter , #getter ) ; \ | |
692 | static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ; | |
4393b50c SC |
693 | |
694 | #define WX_PROPERTY_SET_BY_REF( name , type , setter , getter ,defaultValue ) \ | |
695 | static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetByRef*)NULL, &setter , &getter , #setter , #getter ) ; \ | |
696 | static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ; | |
697 | ||
fa08490f SC |
698 | #define WX_PROPERTY_SET_BY_REF_RET_BOOL( name , type , setter , getter ,defaultValue ) \ |
699 | static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetByRefRetBool*)NULL, &setter , &getter , #setter , #getter ) ; \ | |
700 | static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ; | |
701 | ||
702 | #define WX_PROPERTY_SET_AND_GET_BY_REF_RET_BOOL( name , type , setter , getter ,defaultValue ) \ | |
703 | static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetAndGetByRefRetBool*)NULL, &setter , &getter , #setter , #getter ) ; \ | |
704 | static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ; | |
705 | ||
438edbc0 SC |
706 | #else |
707 | ||
708 | #define WX_PROPERTY( name , type , setter , getter ,defaultValue ) \ | |
709 | static wxPropertyAccessorT<class_t , type> _accessor##name( &setter , &getter , #setter , #getter ) ; \ | |
710 | static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ; | |
711 | ||
712 | #define WX_PROPERTY_SET_RET_BOOL( name , type , setter , getter ,defaultValue ) \ | |
713 | WX_PROPERTY( name , type , setter , getter , defaultValue ) | |
714 | ||
715 | #define WX_PROPERTY_SET_BY_REF( name , type , setter , getter ,defaultValue ) \ | |
716 | WX_PROPERTY( name , type , setter , getter , defaultValue ) | |
717 | ||
718 | #define WX_PROPERTY_SET_BY_REF_RET_BOOL( name , type , setter , getter ,defaultValue ) \ | |
719 | WX_PROPERTY( name , type , setter , getter , defaultValue ) | |
720 | ||
721 | #define WX_PROPERTY_SET_AND_GET_BY_REF_RET_BOOL( name , type , setter , getter ,defaultValue ) \ | |
722 | WX_PROPERTY( name , type , setter , getter , defaultValue ) | |
723 | ||
724 | #endif | |
725 | ||
4393b50c | 726 | #define WX_READONLY_PROPERTY( name , type , getter ,defaultValue ) \ |
517fb871 VS |
727 | static wxPropertyAccessorT<class_t , type> _accessor##name( &getter , #getter ) ; \ |
728 | static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ; | |
a095505c SC |
729 | |
730 | #define WX_DELEGATE( name , eventType , eventClass ) \ | |
517fb871 VS |
731 | static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \ |
732 | static wxPropertyInfo _propertyInfo##name( first , #name , NULL , &_typeInfo##name , NULL , wxxVariant() ) ; \ | |
a095505c SC |
733 | |
734 | // ---------------------------------------------------------------------------- | |
735 | // Handler Info | |
736 | // | |
737 | // this is describing an event sink | |
738 | // ---------------------------------------------------------------------------- | |
739 | ||
740 | class wxHandlerInfo | |
741 | { | |
742 | public : | |
fa08490f SC |
743 | wxHandlerInfo( wxHandlerInfo* &iter , const wxChar *name , wxObjectEventFunction address , const wxClassInfo* eventClassInfo ) : |
744 | m_name( name ) , m_eventClassInfo( eventClassInfo ) , m_eventFunction( address ) | |
745 | { | |
746 | m_next = NULL ; | |
747 | if ( iter == NULL ) | |
748 | iter = this ; | |
749 | else | |
750 | { | |
751 | wxHandlerInfo* i = iter ; | |
752 | while( i->m_next ) | |
753 | i = i->m_next ; | |
754 | ||
755 | i->m_next = this ; | |
756 | } | |
757 | } | |
758 | ||
759 | // get the name of the handler method | |
760 | const wxChar * GetName() const { return m_name ; } | |
761 | ||
762 | // return the class info of the event | |
763 | const wxClassInfo * GetEventClassInfo() const { return m_eventClassInfo ; } | |
764 | ||
765 | // get the handler function pointer | |
766 | wxObjectEventFunction GetEventFunction() const { return m_eventFunction ; } | |
767 | ||
768 | // returns NULL if this is the last handler of this class | |
769 | wxHandlerInfo* GetNext() const { return m_next ; } | |
4393b50c | 770 | private : |
517fb871 VS |
771 | wxObjectEventFunction m_eventFunction ; |
772 | const wxChar * m_name; | |
773 | const wxClassInfo* m_eventClassInfo ; | |
774 | wxHandlerInfo* m_next ; | |
a095505c SC |
775 | }; |
776 | ||
777 | #define WX_HANDLER(name,eventClassType) \ | |
517fb871 | 778 | static wxHandlerInfo _handlerInfo##name( first , #name , (wxObjectEventFunction) (wxEventFunction) &name , CLASSINFO( eventClassType ) ) ; |
a095505c SC |
779 | |
780 | #define WX_BEGIN_HANDLERS_TABLE(theClass) \ | |
2d51f067 | 781 | wxHandlerInfo *theClass::GetHandlersStatic() \ |
a095505c SC |
782 | { \ |
783 | typedef theClass class_t; \ | |
517fb871 | 784 | static wxHandlerInfo* first = NULL ; |
a095505c SC |
785 | |
786 | #define WX_END_HANDLERS_TABLE() \ | |
517fb871 | 787 | return first ; } |
a095505c SC |
788 | |
789 | // ---------------------------------------------------------------------------- | |
790 | // Constructor Bridges | |
791 | // | |
792 | // allow to set up constructors with params during runtime | |
793 | // ---------------------------------------------------------------------------- | |
794 | ||
795 | class WXDLLIMPEXP_BASE wxConstructorBridge | |
796 | { | |
797 | public : | |
798 | virtual void Create(wxObject *o, wxxVariant *args) = 0; | |
799 | }; | |
800 | ||
801 | // Creator Bridges for all Numbers of Params | |
802 | ||
803 | // no params | |
804 | ||
805 | template<typename Class> | |
806 | struct wxConstructorBridge_0 : public wxConstructorBridge | |
807 | { | |
808 | void Create(wxObject *o, wxxVariant *) | |
809 | { | |
810 | Class *obj = dynamic_cast<Class*>(o); | |
811 | obj->Create(); | |
812 | } | |
813 | }; | |
814 | ||
815 | struct wxConstructorBridge_Dummy : public wxConstructorBridge | |
816 | { | |
817 | void Create(wxObject *, wxxVariant *) | |
818 | { | |
819 | } | |
820 | } ; | |
821 | ||
822 | #define WX_CONSTRUCTOR_0(klass) \ | |
517fb871 VS |
823 | wxConstructorBridge_0<klass> constructor##klass ; \ |
824 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
825 | const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \ | |
826 | const int klass::sm_constructorPropertiesCount##klass = 0 ; | |
a095505c SC |
827 | |
828 | #define WX_CONSTRUCTOR_DUMMY(klass) \ | |
517fb871 VS |
829 | wxConstructorBridge_Dummy constructor##klass ; \ |
830 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
831 | const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \ | |
832 | const int klass::sm_constructorPropertiesCount##klass = 0 ; | |
a095505c SC |
833 | |
834 | // 1 param | |
835 | ||
836 | template<typename Class, typename T0> | |
837 | struct wxConstructorBridge_1 : public wxConstructorBridge | |
838 | { | |
839 | void Create(wxObject *o, wxxVariant *args) | |
840 | { | |
841 | Class *obj = dynamic_cast<Class*>(o); | |
842 | obj->Create( | |
843 | args[0].Get<T0>() | |
844 | ); | |
845 | } | |
846 | }; | |
847 | ||
848 | #define WX_CONSTRUCTOR_1(klass,t0,v0) \ | |
517fb871 VS |
849 | wxConstructorBridge_1<klass,t0> constructor##klass ; \ |
850 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
851 | const wxChar *klass::sm_constructorProperties##klass[] = { #v0 } ; \ | |
852 | const int klass::sm_constructorPropertiesCount##klass = 1 ; | |
a095505c SC |
853 | |
854 | // 2 params | |
855 | ||
856 | template<typename Class, | |
857 | typename T0, typename T1> | |
858 | struct wxConstructorBridge_2 : public wxConstructorBridge | |
859 | { | |
fbbdc52c | 860 | void Create(wxObject *o, wxxVariant *args) |
a095505c SC |
861 | { |
862 | Class *obj = dynamic_cast<Class*>(o); | |
863 | obj->Create( | |
864 | args[0].Get<T0>() , | |
4393b50c | 865 | args[1].Get<T1>() |
a095505c SC |
866 | ); |
867 | } | |
868 | }; | |
869 | ||
870 | #define WX_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \ | |
517fb871 VS |
871 | wxConstructorBridge_2<klass,t0,t1> constructor##klass ; \ |
872 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
873 | const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 } ; \ | |
874 | const int klass::sm_constructorPropertiesCount##klass = 2; | |
a095505c SC |
875 | |
876 | // 3 params | |
877 | ||
878 | template<typename Class, | |
879 | typename T0, typename T1, typename T2> | |
880 | struct wxConstructorBridge_3 : public wxConstructorBridge | |
881 | { | |
fbbdc52c | 882 | void Create(wxObject *o, wxxVariant *args) |
a095505c SC |
883 | { |
884 | Class *obj = dynamic_cast<Class*>(o); | |
885 | obj->Create( | |
886 | args[0].Get<T0>() , | |
887 | args[1].Get<T1>() , | |
4393b50c | 888 | args[2].Get<T2>() |
a095505c SC |
889 | ); |
890 | } | |
891 | }; | |
892 | ||
893 | #define WX_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \ | |
517fb871 VS |
894 | wxConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \ |
895 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
896 | const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 } ; \ | |
897 | const int klass::sm_constructorPropertiesCount##klass = 3 ; | |
a095505c SC |
898 | |
899 | // 4 params | |
900 | ||
901 | template<typename Class, | |
902 | typename T0, typename T1, typename T2, typename T3> | |
903 | struct wxConstructorBridge_4 : public wxConstructorBridge | |
904 | { | |
fbbdc52c | 905 | void Create(wxObject *o, wxxVariant *args) |
a095505c SC |
906 | { |
907 | Class *obj = dynamic_cast<Class*>(o); | |
908 | obj->Create( | |
909 | args[0].Get<T0>() , | |
910 | args[1].Get<T1>() , | |
911 | args[2].Get<T2>() , | |
4393b50c | 912 | args[3].Get<T3>() |
a095505c SC |
913 | ); |
914 | } | |
915 | }; | |
916 | ||
917 | #define WX_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \ | |
517fb871 VS |
918 | wxConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass ; \ |
919 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
920 | const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 } ; \ | |
921 | const int klass::sm_constructorPropertiesCount##klass = 4 ; | |
fbbdc52c SC |
922 | |
923 | // 5 params | |
924 | ||
925 | template<typename Class, | |
926 | typename T0, typename T1, typename T2, typename T3, typename T4> | |
927 | struct wxConstructorBridge_5 : public wxConstructorBridge | |
928 | { | |
929 | void Create(wxObject *o, wxxVariant *args) | |
930 | { | |
931 | Class *obj = dynamic_cast<Class*>(o); | |
932 | obj->Create( | |
933 | args[0].Get<T0>() , | |
934 | args[1].Get<T1>() , | |
935 | args[2].Get<T2>() , | |
936 | args[3].Get<T3>() , | |
4393b50c | 937 | args[4].Get<T4>() |
fbbdc52c SC |
938 | ); |
939 | } | |
940 | }; | |
941 | ||
942 | #define WX_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \ | |
fa08490f SC |
943 | wxConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass ; \ |
944 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
945 | const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 } ; \ | |
946 | const int klass::sm_constructorPropertiesCount##klass = 5; | |
947 | ||
948 | // 6 params | |
949 | ||
950 | template<typename Class, | |
951 | typename T0, typename T1, typename T2, typename T3, typename T4, typename T5> | |
952 | struct wxConstructorBridge_6 : public wxConstructorBridge | |
953 | { | |
954 | void Create(wxObject *o, wxxVariant *args) | |
955 | { | |
956 | Class *obj = dynamic_cast<Class*>(o); | |
957 | obj->Create( | |
958 | args[0].Get<T0>() , | |
959 | args[1].Get<T1>() , | |
960 | args[2].Get<T2>() , | |
961 | args[3].Get<T3>() , | |
962 | args[4].Get<T4>() , | |
963 | args[5].Get<T5>() | |
964 | ); | |
965 | } | |
966 | }; | |
967 | ||
968 | #define WX_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \ | |
969 | wxConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \ | |
970 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
971 | const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 } ; \ | |
972 | const int klass::sm_constructorPropertiesCount##klass = 6; | |
973 | ||
a095505c SC |
974 | |
975 | // ---------------------------------------------------------------------------- | |
976 | // wxClassInfo | |
977 | // ---------------------------------------------------------------------------- | |
978 | ||
979 | typedef wxObject *(*wxObjectConstructorFn)(void); | |
fa08490f | 980 | typedef wxObject* (*wxVariantToObjectConverter)( wxxVariant &data ) ; |
a095505c SC |
981 | typedef wxxVariant (*wxObjectToVariantConverter)( wxObject* ) ; |
982 | ||
983 | class WXDLLIMPEXP_BASE wxClassInfo | |
984 | { | |
985 | public: | |
986 | wxClassInfo(const wxClassInfo **_Parents, | |
517fb871 VS |
987 | const wxChar *_UnitName, |
988 | const wxChar *_ClassName, | |
a095505c SC |
989 | int size, |
990 | wxObjectConstructorFn ctor , | |
2d51f067 SC |
991 | wxPropertyInfo *_Props , |
992 | wxHandlerInfo *_Handlers , | |
fa08490f SC |
993 | wxConstructorBridge* _Constructor , |
994 | const wxChar ** _ConstructorProperties , | |
995 | const int _ConstructorPropertiesCount , | |
996 | wxVariantToObjectConverter _PtrConverter1 , | |
997 | wxVariantToObjectConverter _Converter2 , | |
998 | wxObjectToVariantConverter _Converter3 | |
999 | ) : m_parents(_Parents) , m_unitName(_UnitName) ,m_className(_ClassName), | |
1000 | m_objectSize(size), m_objectConstructor(ctor) , m_firstProperty(_Props ) , m_firstHandler(_Handlers ) , m_constructor( _Constructor ) , | |
1001 | m_constructorProperties(_ConstructorProperties) , m_constructorPropertiesCount(_ConstructorPropertiesCount), | |
1002 | m_variantOfPtrToObjectConverter( _PtrConverter1 ) , m_variantToObjectConverter( _Converter2 ) , m_objectToVariantConverter( _Converter3 ) , m_next(sm_first) | |
1003 | { | |
1004 | sm_first = this; | |
aa8d7c2f | 1005 | Register() ; |
fa08490f | 1006 | } |
a095505c | 1007 | |
2d51f067 SC |
1008 | wxClassInfo(const wxChar *_UnitName, const wxChar *_ClassName, const wxClassInfo **_Parents) : m_parents(_Parents) , m_unitName(_UnitName) ,m_className(_ClassName), |
1009 | m_objectSize(0), m_objectConstructor(NULL) , m_firstProperty(NULL ) , m_firstHandler(NULL ) , m_constructor( NULL ) , | |
1010 | m_constructorProperties(NULL) , m_constructorPropertiesCount(NULL), | |
1011 | m_variantOfPtrToObjectConverter( NULL ) , m_variantToObjectConverter( NULL ) , m_objectToVariantConverter( NULL ) , m_next(sm_first) | |
1012 | { | |
1013 | sm_first = this; | |
1014 | Register() ; | |
1015 | } | |
1016 | ||
aeec2045 | 1017 | virtual ~wxClassInfo() ; |
a095505c | 1018 | |
2d51f067 | 1019 | virtual wxObject *CreateObject() const { return m_objectConstructor ? (*m_objectConstructor)() : 0; } |
a095505c SC |
1020 | |
1021 | const wxChar *GetClassName() const { return m_className; } | |
1022 | const wxClassInfo **GetParents() const { return m_parents; } | |
1023 | int GetSize() const { return m_objectSize; } | |
1024 | ||
1025 | wxObjectConstructorFn GetConstructor() const { return m_objectConstructor; } | |
1026 | static const wxClassInfo *GetFirst() { return sm_first; } | |
1027 | const wxClassInfo *GetNext() const { return m_next; } | |
1028 | static wxClassInfo *FindClass(const wxChar *className); | |
1029 | ||
1030 | // Climb upwards through inheritance hierarchy. | |
1031 | // Dual inheritance is catered for. | |
1032 | ||
1033 | bool IsKindOf(const wxClassInfo *info) const | |
1034 | { | |
517fb871 VS |
1035 | if ( info != 0 ) |
1036 | { | |
1037 | if ( info == this ) | |
1038 | return true ; | |
1039 | ||
1040 | for ( int i = 0 ; m_parents[i] ; ++ i ) | |
1041 | { | |
1042 | if ( m_parents[i]->IsKindOf( info ) ) | |
1043 | return true ; | |
1044 | } | |
1045 | } | |
1046 | return false ; | |
a095505c SC |
1047 | } |
1048 | ||
aa8d7c2f | 1049 | #ifdef WXWIN_COMPATIBILITY_2_4 |
a095505c | 1050 | // Initializes parent pointers and hash table for fast searching. |
aa8d7c2f | 1051 | wxDEPRECATED( static void InitializeClasses() ); |
a095505c | 1052 | // Cleans up hash table used for fast searching. |
aa8d7c2f SC |
1053 | wxDEPRECATED( static void CleanUpClasses() ); |
1054 | #endif | |
1055 | static void CleanUp(); | |
1056 | ||
517fb871 VS |
1057 | // returns the first property |
1058 | const wxPropertyInfo* GetFirstProperty() const { return m_firstProperty ; } | |
a095505c | 1059 | |
517fb871 VS |
1060 | // returns the first handler |
1061 | const wxHandlerInfo* GetFirstHandler() const { return m_firstHandler ; } | |
a095505c SC |
1062 | |
1063 | // Call the Create method for a class | |
fa08490f SC |
1064 | virtual void Create (wxObject *object, int ParamCount, wxxVariant *Params) const |
1065 | { | |
1066 | wxASSERT_MSG( ParamCount == m_constructorPropertiesCount , wxT("Illegal Parameter Count for Create Method")) ; | |
1067 | m_constructor->Create( object , Params ) ; | |
1068 | } | |
a095505c | 1069 | |
517fb871 VS |
1070 | // get number of parameters for constructor |
1071 | virtual int GetCreateParamCount() const { return m_constructorPropertiesCount; } | |
a095505c | 1072 | |
517fb871 VS |
1073 | // get i-th constructor parameter |
1074 | virtual const wxChar* GetCreateParamName(int i) const { return m_constructorProperties[i] ; } | |
a095505c SC |
1075 | |
1076 | // Runtime access to objects by property name, and variant data | |
2d51f067 SC |
1077 | virtual void SetProperty (wxObject *object, const wxChar *PropertyName, const wxxVariant &Value) const ; |
1078 | virtual wxxVariant GetProperty (wxObject *object, const wxChar *PropertyName) const; | |
a095505c | 1079 | |
fa08490f | 1080 | // we must be able to cast variants to wxObject pointers, templates seem not to be suitable |
f0b7eadf | 1081 | wxObject* VariantToInstance( wxxVariant &data ) const |
fa08490f | 1082 | { if ( data.GetTypeInfo()->GetKind() == wxT_OBJECT ) |
f0b7eadf | 1083 | return m_variantToObjectConverter( data ) ; |
fa08490f SC |
1084 | else |
1085 | return m_variantOfPtrToObjectConverter( data ) ; | |
1086 | } | |
1087 | ||
1088 | wxxVariant InstanceToVariant( wxObject *object ) const { return m_objectToVariantConverter( object ) ; } | |
4393b50c | 1089 | |
517fb871 | 1090 | // find property by name |
fbbdc52c SC |
1091 | virtual const wxPropertyInfo *FindPropertyInfo (const wxChar *PropertyName) const ; |
1092 | ||
517fb871 | 1093 | // find handler by name |
fbbdc52c | 1094 | virtual const wxHandlerInfo *FindHandlerInfo (const wxChar *PropertyName) const ; |
a095505c | 1095 | |
2d51f067 SC |
1096 | // find property by name |
1097 | virtual const wxPropertyInfo *FindPropertyInfoInThisClass (const wxChar *PropertyName) const ; | |
1098 | ||
1099 | // find handler by name | |
1100 | virtual const wxHandlerInfo *FindHandlerInfoInThisClass (const wxChar *PropertyName) const ; | |
a095505c SC |
1101 | public: |
1102 | const wxChar *m_className; | |
1103 | int m_objectSize; | |
1104 | wxObjectConstructorFn m_objectConstructor; | |
1105 | ||
1106 | // class info object live in a linked list: | |
1107 | // pointers to its head and the next element in it | |
1108 | ||
1109 | static wxClassInfo *sm_first; | |
1110 | wxClassInfo *m_next; | |
1111 | ||
517fb871 | 1112 | // FIXME: this should be private (currently used directly by way too |
a095505c SC |
1113 | // many clients) |
1114 | static wxHashTable *sm_classTable; | |
1115 | ||
2d51f067 SC |
1116 | protected : |
1117 | wxPropertyInfo * m_firstProperty ; | |
1118 | wxHandlerInfo * m_firstHandler ; | |
a095505c | 1119 | private: |
fa08490f | 1120 | const wxClassInfo** m_parents ; |
fa08490f SC |
1121 | const wxChar* m_unitName; |
1122 | ||
1123 | wxConstructorBridge* m_constructor ; | |
1124 | const wxChar ** m_constructorProperties ; | |
1125 | const int m_constructorPropertiesCount ; | |
1126 | wxVariantToObjectConverter m_variantOfPtrToObjectConverter ; | |
1127 | wxVariantToObjectConverter m_variantToObjectConverter ; | |
1128 | wxObjectToVariantConverter m_objectToVariantConverter ; | |
a095505c | 1129 | |
2d51f067 | 1130 | const wxPropertyAccessor *FindAccessor (const wxChar *propertyName) const ; |
a095505c | 1131 | |
a095505c | 1132 | |
517fb871 | 1133 | // InitializeClasses() helper |
2d51f067 | 1134 | static wxClassInfo *GetBaseByName(const wxChar *name) ; |
d1d738f1 VS |
1135 | |
1136 | protected: | |
1137 | // registers the class | |
1138 | void Register(); | |
1139 | void Unregister(); | |
a095505c SC |
1140 | |
1141 | DECLARE_NO_COPY_CLASS(wxClassInfo) | |
1142 | }; | |
1143 | ||
2d51f067 | 1144 | |
a095505c SC |
1145 | WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name); |
1146 | ||
2d51f067 SC |
1147 | // ---------------------------------------------------------------------------- |
1148 | // wxDynamicObject | |
1149 | // ---------------------------------------------------------------------------- | |
1150 | // | |
1151 | // this object leads to having a pure runtime-instantiation | |
1152 | ||
1153 | class wxDynamicClassInfo : public wxClassInfo | |
1154 | { | |
1155 | public : | |
1156 | wxDynamicClassInfo( const wxChar *_UnitName, const wxChar *_ClassName , const wxClassInfo* superClass ) ; | |
1157 | virtual ~wxDynamicClassInfo() ; | |
1158 | ||
1159 | // constructs a wxDynamicObject with an instance | |
1160 | virtual wxObject *CreateObject() const ; | |
1161 | ||
1162 | // Call the Create method for a class | |
1163 | virtual void Create (wxObject *object, int ParamCount, wxxVariant *Params) const ; | |
1164 | ||
1165 | // get number of parameters for constructor | |
1166 | virtual int GetCreateParamCount() const ; | |
1167 | ||
1168 | // get i-th constructor parameter | |
1169 | virtual const wxChar* GetCreateParamName(int i) const ; | |
1170 | ||
1171 | // Runtime access to objects by property name, and variant data | |
1172 | virtual void SetProperty (wxObject *object, const wxChar *PropertyName, const wxxVariant &Value) const ; | |
1173 | virtual wxxVariant GetProperty (wxObject *object, const wxChar *PropertyName) const ; | |
1174 | ||
1175 | void AddProperty( const wxChar *propertyName , const wxTypeInfo* typeInfo ) ; | |
1176 | void AddHandler( const wxChar *handlerName , wxObjectEventFunction address , const wxClassInfo* eventClassInfo ) ; | |
1177 | } ; | |
1178 | ||
a095505c SC |
1179 | // ---------------------------------------------------------------------------- |
1180 | // Dynamic class macros | |
1181 | // ---------------------------------------------------------------------------- | |
1182 | ||
1183 | #define _DECLARE_DYNAMIC_CLASS(name) \ | |
1184 | public: \ | |
1185 | static wxClassInfo sm_class##name; \ | |
1186 | static const wxClassInfo* sm_classParents##name[] ; \ | |
2d51f067 SC |
1187 | static wxPropertyInfo* GetPropertiesStatic() ; \ |
1188 | static wxHandlerInfo* GetHandlersStatic() ; \ | |
a095505c SC |
1189 | virtual wxClassInfo *GetClassInfo() const \ |
1190 | { return &name::sm_class##name; } | |
1191 | ||
1192 | #define DECLARE_DYNAMIC_CLASS(name) \ | |
f0b7eadf SC |
1193 | static wxConstructorBridge* sm_constructor##name ; \ |
1194 | static const wxChar * sm_constructorProperties##name[] ; \ | |
1195 | static const int sm_constructorPropertiesCount##name ; \ | |
1196 | _DECLARE_DYNAMIC_CLASS(name) | |
a095505c SC |
1197 | |
1198 | #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \ | |
1199 | DECLARE_NO_ASSIGN_CLASS(name) \ | |
1200 | DECLARE_DYNAMIC_CLASS(name) | |
1201 | ||
1202 | #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \ | |
1203 | DECLARE_NO_COPY_CLASS(name) \ | |
1204 | DECLARE_DYNAMIC_CLASS(name) | |
1205 | ||
1206 | #define DECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name) | |
1207 | #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name) | |
1208 | ||
1209 | // ----------------------------------- | |
1210 | // for concrete classes | |
1211 | // ----------------------------------- | |
1212 | ||
1213 | // Single inheritance with one base class | |
1214 | ||
1215 | #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit) \ | |
1216 | wxObject* wxConstructorFor##name() \ | |
1217 | { return new name; } \ | |
1218 | const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \ | |
fa08490f SC |
1219 | wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \ |
1220 | wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \ | |
a095505c SC |
1221 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \ |
1222 | (int) sizeof(name), \ | |
1223 | (wxObjectConstructorFn) wxConstructorFor##name , \ | |
fa08490f SC |
1224 | name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \ |
1225 | name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name); \ | |
1226 | template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\ | |
1227 | template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
dadaeb69 SC |
1228 | template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\ |
1229 | template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
f0b7eadf SC |
1230 | template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1231 | template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1232 | template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \ | |
fa08490f SC |
1233 | template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \ |
1234 | template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } | |
1235 | ||
1236 | #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit) \ | |
1237 | wxObject* wxConstructorFor##name() \ | |
1238 | { return new name; } \ | |
1239 | const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \ | |
1240 | wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return &data.Get<name>() ; } \ | |
1241 | wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \ | |
1242 | wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \ | |
1243 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \ | |
1244 | (int) sizeof(name), \ | |
1245 | (wxObjectConstructorFn) wxConstructorFor##name , \ | |
1246 | name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \ | |
1247 | name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \ | |
1248 | template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\ | |
1249 | template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1250 | template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\ | |
1251 | template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
f0b7eadf SC |
1252 | template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1253 | template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1254 | template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \ | |
fa08490f SC |
1255 | template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \ |
1256 | template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } | |
1257 | ||
1258 | #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \ | |
1259 | _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" ) \ | |
1260 | const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \ | |
1261 | const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \ | |
1262 | WX_CONSTRUCTOR_DUMMY( name ) | |
a095505c SC |
1263 | |
1264 | #define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \ | |
1265 | _IMPLEMENT_DYNAMIC_CLASS( name , basename , "" ) \ | |
2d51f067 SC |
1266 | wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \ |
1267 | wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \ | |
a095505c SC |
1268 | WX_CONSTRUCTOR_DUMMY( name ) |
1269 | ||
1270 | #define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \ | |
1271 | _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit ) | |
1272 | ||
fa08490f SC |
1273 | #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \ |
1274 | _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit ) | |
1275 | ||
4393b50c | 1276 | // this is for classes that do not derive from wxobject, there are no creators for these |
a095505c SC |
1277 | |
1278 | #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name , unit ) \ | |
1279 | const wxClassInfo* name::sm_classParents##name[] = { NULL } ; \ | |
1280 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \ | |
1281 | (int) sizeof(name), \ | |
1282 | (wxObjectConstructorFn) 0 , \ | |
517fb871 VS |
1283 | name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \ |
1284 | 0 , 0 , 0 ); \ | |
dadaeb69 SC |
1285 | template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1286 | template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
f0b7eadf SC |
1287 | template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1288 | template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1289 | template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \ | |
1290 | template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \ | |
fa08490f | 1291 | template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } |
a095505c SC |
1292 | |
1293 | // this is for subclasses that still do not derive from wxobject | |
1294 | ||
1295 | #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name , basename, unit ) \ | |
1296 | const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \ | |
1297 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \ | |
1298 | (int) sizeof(name), \ | |
1299 | (wxObjectConstructorFn) 0 , \ | |
517fb871 VS |
1300 | name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \ |
1301 | 0 , 0 , 0 ); \ | |
dadaeb69 SC |
1302 | template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1303 | template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
f0b7eadf SC |
1304 | template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1305 | template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1306 | template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \ | |
1307 | template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \ | |
fa08490f | 1308 | template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } |
a095505c | 1309 | |
f0b7eadf | 1310 | |
a095505c SC |
1311 | // Multiple inheritance with two base classes |
1312 | ||
1313 | #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit) \ | |
1314 | wxObject* wxConstructorFor##name() \ | |
1315 | { return new name; } \ | |
1316 | const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,&basename2::sm_class##basename2 , NULL } ; \ | |
fa08490f | 1317 | wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \ |
a095505c SC |
1318 | wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \ |
1319 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \ | |
1320 | (int) sizeof(name), \ | |
1321 | (wxObjectConstructorFn) wxConstructorFor##name , \ | |
517fb871 VS |
1322 | name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \ |
1323 | name::sm_constructorPropertiesCount##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \ | |
dadaeb69 SC |
1324 | template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1325 | template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
f0b7eadf SC |
1326 | template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1327 | template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1328 | template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \ | |
1329 | template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \ | |
fa08490f | 1330 | template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } |
a095505c SC |
1331 | |
1332 | #define IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2) \ | |
1333 | _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , "") \ | |
2d51f067 SC |
1334 | wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \ |
1335 | wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \ | |
a095505c SC |
1336 | WX_CONSTRUCTOR_DUMMY( name ) |
1337 | ||
1338 | #define IMPLEMENT_DYNAMIC_CLASS2_XTI( name , basename , basename2, unit) \ | |
517fb871 | 1339 | _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , unit) |
a095505c SC |
1340 | |
1341 | // ----------------------------------- | |
1342 | // for abstract classes | |
1343 | // ----------------------------------- | |
1344 | ||
1345 | // Single inheritance with one base class | |
1346 | ||
1347 | #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \ | |
1348 | const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \ | |
fa08490f SC |
1349 | wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \ |
1350 | wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \ | |
1351 | wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \ | |
a095505c SC |
1352 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \ |
1353 | (int) sizeof(name), \ | |
1354 | (wxObjectConstructorFn) 0 , \ | |
fa08490f SC |
1355 | name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \ |
1356 | 0 , wxVariantOfPtrToObjectConverter##name ,wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \ | |
dadaeb69 SC |
1357 | template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1358 | template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
f0b7eadf SC |
1359 | template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1360 | template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1361 | template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \ | |
1362 | template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } \ | |
1363 | template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID) ; assert(0) ; return &s_typeInfo ; } | |
a095505c SC |
1364 | |
1365 | #define IMPLEMENT_ABSTRACT_CLASS( name , basename ) \ | |
1366 | _IMPLEMENT_ABSTRACT_CLASS( name , basename ) \ | |
2d51f067 SC |
1367 | wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \ |
1368 | wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } | |
a095505c SC |
1369 | |
1370 | // Multiple inheritance with two base classes | |
1371 | ||
1372 | #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \ | |
1373 | wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \ | |
1374 | wxT(#basename2), (int) sizeof(name), \ | |
1375 | (wxObjectConstructorFn) 0); | |
1376 | ||
1377 | #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS | |
1378 | #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2 | |
1379 | ||
aeec2045 | 1380 | #endif |