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