]>
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 SC |
318 | |
319 | // ---------------------------------------------------------------------------- | |
4393b50c | 320 | // value streaming |
a095505c SC |
321 | // |
322 | // streaming is defined for xml constructs right now, the aim is to make this | |
323 | // pluggable in the future | |
324 | // ---------------------------------------------------------------------------- | |
325 | ||
326 | // convenience function (avoids including xml headers in users code) | |
327 | ||
328 | class wxXmlNode ; | |
329 | void wxXmlAddContentToNode( wxXmlNode* node , const wxString& data ) ; | |
330 | wxString wxXmlGetContentFromNode( wxXmlNode *node ) ; | |
331 | ||
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 SC |
339 | |
340 | // for simple types this default implementation is ok, composited structures will have to | |
4393b50c | 341 | // loop through their properties |
a095505c SC |
342 | |
343 | template<typename T> | |
4393b50c | 344 | void wxXmlReadValue( wxXmlNode *node , T &data ) |
a095505c | 345 | { |
517fb871 | 346 | wxStringReadValue<T>( wxXmlGetContentFromNode( node ) , data ) ; |
a095505c SC |
347 | } |
348 | ||
349 | template<typename T> | |
4393b50c | 350 | void wxXmlWriteValue( wxXmlNode *node , const T &data) |
a095505c | 351 | { |
517fb871 VS |
352 | wxString s ; |
353 | wxStringWriteValue<T>( s, data ) ; | |
354 | wxXmlAddContentToNode( node ,s ) ; | |
a095505c SC |
355 | } |
356 | ||
357 | // ---------------------------------------------------------------------------- | |
358 | // wxxVariant as typesafe data holder | |
359 | // ---------------------------------------------------------------------------- | |
360 | ||
361 | class WXDLLIMPEXP_BASE wxxVariantData | |
362 | { | |
363 | public: | |
517fb871 | 364 | virtual ~wxxVariantData() {} |
a095505c | 365 | |
517fb871 VS |
366 | // return a heap allocated duplicate |
367 | virtual wxxVariantData* Clone() const = 0 ; | |
a095505c | 368 | |
517fb871 VS |
369 | // returns the type info of the contentc |
370 | virtual const wxTypeInfo* GetTypeInfo() const = 0 ; | |
a095505c | 371 | |
517fb871 VS |
372 | // write the value into an xml node |
373 | virtual void Write( wxXmlNode* node ) const = 0 ; | |
a095505c | 374 | |
517fb871 VS |
375 | // read the value from the xml node |
376 | virtual void Read( wxXmlNode* node ) = 0 ; | |
a095505c | 377 | |
517fb871 VS |
378 | // write the value into a string |
379 | virtual void Write( wxString &s ) const = 0 ; | |
a095505c | 380 | |
517fb871 VS |
381 | // read the value from a string |
382 | virtual void Read( const wxString &s) = 0 ; | |
a095505c SC |
383 | } ; |
384 | ||
385 | template<typename T> class WXDLLIMPEXP_BASE wxxVariantDataT : public wxxVariantData | |
386 | { | |
387 | public: | |
fa08490f SC |
388 | wxxVariantDataT(const T& d) : m_data(d) {} |
389 | virtual ~wxxVariantDataT() {} | |
a095505c | 390 | |
fa08490f SC |
391 | // get a ref to the stored data |
392 | T & Get() { return m_data; } | |
a095505c | 393 | |
fa08490f SC |
394 | // get a const ref to the stored data |
395 | const T & Get() const { return m_data; } | |
396 | ||
397 | // set the data | |
398 | void Set(const T& d) { m_data = d; } | |
a095505c | 399 | |
517fb871 VS |
400 | // return a heap allocated duplicate |
401 | virtual wxxVariantData* Clone() const { return new wxxVariantDataT<T>( Get() ) ; } | |
a095505c | 402 | |
517fb871 VS |
403 | // returns the type info of the contentc |
404 | virtual const wxTypeInfo* GetTypeInfo() const { return wxGetTypeInfo( (T*) NULL ) ; } | |
a095505c | 405 | |
517fb871 VS |
406 | // write the value into an xml node |
407 | virtual void Write( wxXmlNode* node ) const { wxXmlWriteValue( node , m_data ) ; } | |
a095505c | 408 | |
517fb871 VS |
409 | // read the value from the xml node |
410 | virtual void Read( wxXmlNode* node ) { wxXmlReadValue( node , m_data ) ; } | |
a095505c | 411 | |
517fb871 VS |
412 | // write the value into a string |
413 | virtual void Write( wxString &s ) const { wxStringWriteValue( s , m_data ) ; } | |
a095505c | 414 | |
517fb871 VS |
415 | // read the value from a string |
416 | virtual void Read( const wxString &s) { wxStringReadValue( s , m_data ) ; } | |
a095505c SC |
417 | |
418 | private: | |
419 | T m_data; | |
420 | }; | |
421 | ||
422 | class WXDLLIMPEXP_BASE wxxVariant | |
423 | { | |
424 | public : | |
fa08490f SC |
425 | wxxVariant() { m_data = NULL ; } |
426 | wxxVariant( wxxVariantData* data , const wxString& name = wxT("") ) : m_data(data) , m_name(name) {} | |
427 | wxxVariant( const wxxVariant &d ) { if ( d.m_data ) m_data = d.m_data->Clone() ; else m_data = NULL ; m_name = d.m_name ; } | |
428 | ||
429 | template<typename T> wxxVariant( T data , const wxString& name = wxT("") ) : | |
430 | m_data(new wxxVariantDataT<T>(data) ), m_name(name) {} | |
431 | ~wxxVariant() { delete m_data ; } | |
432 | ||
433 | // get a ref to the stored data | |
434 | template<typename T> T& Get() | |
435 | { | |
436 | wxxVariantDataT<T> *dataptr = dynamic_cast<wxxVariantDataT<T>*> (m_data) ; | |
437 | wxASSERT_MSG( dataptr , "Cast not possible" ) ; | |
438 | return dataptr->Get() ; | |
439 | } | |
440 | ||
441 | // get a ref to the stored data | |
442 | template<typename T> const T& Get() const | |
443 | { | |
444 | const wxxVariantDataT<T> *dataptr = dynamic_cast<const wxxVariantDataT<T>*> (m_data) ; | |
445 | wxASSERT_MSG( dataptr , "Cast not possible" ) ; | |
446 | return dataptr->Get() ; | |
447 | } | |
448 | ||
449 | // stores the data | |
450 | template<typename T> void Set(const T& data) const | |
451 | { | |
452 | delete m_data ; | |
453 | m_data = new wxxVariantDataT<T>(data) ; | |
454 | } | |
455 | ||
456 | wxxVariant& operator=(const wxxVariant &d) | |
457 | { | |
458 | m_data = d.m_data->Clone() ; | |
459 | m_name = d.m_name ; | |
460 | return *this ; | |
461 | } | |
462 | ||
463 | // gets the stored data casted to a wxObject* , returning NULL if cast is not possible | |
464 | wxObject* GetAsObject() ; | |
465 | ||
466 | // get the typeinfo of the stored object | |
467 | const wxTypeInfo* GetTypeInfo() const { return m_data->GetTypeInfo() ; } | |
468 | ||
469 | // write the value into an xml node | |
470 | void Write( wxXmlNode* node ) const { m_data->Write( node ) ; } | |
471 | ||
472 | // read the value from the xml node | |
473 | void Read( wxXmlNode* node ) { m_data->Read( node ) ; } | |
474 | ||
475 | // write the value into a string | |
476 | void Write( wxString &s ) const { m_data->Write( s ) ; } | |
477 | ||
478 | // read the value from a string | |
479 | void Read( const wxString &s) { m_data->Read( s ) ; } | |
480 | ||
481 | // returns this value as string | |
482 | wxString GetAsString() const | |
483 | { | |
484 | wxString s ; | |
485 | Write( s ) ; | |
486 | return s ; | |
487 | } | |
488 | ||
489 | void SetFromString( const wxString &s) | |
490 | { | |
491 | Read( s ) ; | |
492 | } | |
a095505c | 493 | private : |
517fb871 VS |
494 | wxxVariantData* m_data ; |
495 | wxString m_name ; | |
a095505c SC |
496 | } ; |
497 | ||
498 | // ---------------------------------------------------------------------------- | |
499 | // Property Support | |
500 | // | |
501 | // wxPropertyInfo is used to inquire of the property by name. It doesn't | |
502 | // provide access to the property, only information about it. If you | |
503 | // want access, look at wxPropertyAccessor. | |
504 | // ---------------------------------------------------------------------------- | |
505 | ||
506 | class WXDLLIMPEXP_BASE wxPropertyAccessor | |
507 | { | |
508 | public : | |
4393b50c | 509 | class SetByRef ; |
fa08490f SC |
510 | class SetByRefRetBool ; |
511 | class SetRetBool ; | |
4393b50c | 512 | class SetAndGetByRef ; |
fa08490f | 513 | class SetAndGetByRefRetBool ; |
4393b50c | 514 | class GetByRef ; |
a095505c SC |
515 | virtual void SetProperty(wxObject *object, const wxxVariant &value) const = 0 ; |
516 | virtual wxxVariant GetProperty(wxObject *object) const = 0 ; | |
517 | virtual bool HasSetter() const = 0 ; | |
518 | virtual bool HasGetter() const = 0 ; | |
517fb871 VS |
519 | const wxChar * GetGetterName() const { return m_setterName ; } |
520 | const wxChar * GetSetterName() const { return m_getterName ; } | |
521 | virtual wxxVariant ReadValue( wxXmlNode* node ) const = 0 ; | |
522 | virtual void WriteValue( wxXmlNode* node , wxObject *o ) const = 0 ; | |
523 | virtual wxxVariant ReadValue( const wxString &value ) const = 0 ; | |
524 | virtual void WriteValue( wxString& value , wxObject *o ) const = 0 ; | |
a095505c | 525 | protected : |
517fb871 VS |
526 | const wxChar *m_setterName ; |
527 | const wxChar *m_getterName ; | |
a095505c SC |
528 | }; |
529 | ||
530 | template<typename T> | |
531 | void wxXmlReadValue( wxXmlNode *node , T &data ) ; | |
532 | ||
533 | template<typename T> | |
534 | void wxXmlWriteValue( wxXmlNode *node , const T &data) ; | |
535 | ||
536 | template<class Klass, typename T> | |
537 | class WXDLLIMPEXP_BASE wxPropertyAccessorT : public wxPropertyAccessor | |
538 | { | |
539 | public: | |
4393b50c | 540 | |
a095505c | 541 | typedef void (Klass::*setter_t)(T value); |
fa08490f | 542 | typedef bool (Klass::*setter_bool_t)(T value); |
fbbdc52c | 543 | typedef void (Klass::*setter_ref_t)(const T& value); |
fa08490f | 544 | typedef bool (Klass::*setter_ref_bool_t)(const T& value); |
a095505c SC |
545 | typedef T (Klass::*getter_t)() const; |
546 | typedef const T& (Klass::*getter_ref_t)() const; | |
547 | ||
fbbdc52c | 548 | wxPropertyAccessorT(setter_t setter, getter_t getter, const wxChar *g, const wxChar *s) |
fa08490f | 549 | : 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 |
550 | |
551 | wxPropertyAccessorT( getter_t getter, const wxChar *g) | |
fa08490f SC |
552 | : 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 ;} |
553 | ||
554 | wxPropertyAccessorT(SetRetBool*, setter_bool_t setter, getter_t getter, const wxChar *g, const wxChar *s) | |
555 | : 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 |
556 | |
557 | wxPropertyAccessorT(SetByRef*, setter_ref_t setter, getter_t getter, const wxChar *g, const wxChar *s) | |
fa08490f | 558 | : 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 | 559 | |
fa08490f SC |
560 | wxPropertyAccessorT(SetByRefRetBool*, setter_ref_bool_t setter, getter_t getter, const wxChar *g, const wxChar *s) |
561 | : 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 |
562 | // wxPropertyAccessorT(setter_ref_t setter, getter_t getter, const wxChar *g, const wxChar *s) |
563 | // : m_setter(NULL), m_setter_ref(setter), m_getter(getter) , m_getter_ref(NULL){m_setterName = s;m_getterName=g ;} | |
564 | ||
565 | wxPropertyAccessorT(SetAndGetByRef*, setter_ref_t setter, getter_ref_t getter, const wxChar *g, const wxChar *s) | |
fa08490f SC |
566 | : 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 ;} |
567 | ||
568 | wxPropertyAccessorT(SetAndGetByRefRetBool*, setter_ref_bool_t setter, getter_ref_t getter, const wxChar *g, const wxChar *s) | |
569 | : 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 |
570 | |
571 | // wxPropertyAccessorT(setter_ref_t setter, getter_ref_t getter, const wxChar *g, const wxChar *s) | |
572 | // : m_setter(NULL), m_setter_ref(setter), m_getter(NULL) , m_getter_ref(getter){m_setterName = s;m_getterName=g ;} | |
573 | ||
574 | // wxPropertyAccessorT(setter_t setter, getter_ref_t getter, const wxChar *g, const wxChar *s) | |
575 | // : m_setter(NULL), m_setter(setter), m_getter(NULL) , m_getter_ref(getter){m_setterName = s;m_getterName=g ;} | |
576 | ||
577 | wxPropertyAccessorT(GetByRef*, setter_t setter, getter_ref_t getter, const wxChar *g, const wxChar *s) | |
fa08490f | 578 | : 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 |
579 | |
580 | // wxPropertyAccessorT( getter_ref_t getter, const wxChar *g) | |
581 | // : m_setter(NULL), m_setter(NULL), m_getter(NULL) , m_getter_ref(getter){m_setterName = "";m_getterName=g ;} | |
a095505c | 582 | |
517fb871 VS |
583 | // returns true if this accessor has a setter |
584 | bool HasSetter() const { return m_setter != NULL || m_setter_ref != NULL ; } | |
a095505c | 585 | |
517fb871 VS |
586 | // return true if this accessor has a getter |
587 | bool HasGetter() const { return m_getter != NULL || m_getter_ref != NULL ; } | |
a095505c | 588 | |
517fb871 VS |
589 | // set the property this accessor is responsible for in an object |
590 | void SetProperty(wxObject *o, const wxxVariant &v) const | |
a095505c SC |
591 | { |
592 | Klass *obj = dynamic_cast<Klass*>(o); | |
fa08490f SC |
593 | T value ; |
594 | ||
595 | if ( wxGetTypeInfo((T*)NULL)->GetKind() == wxT_OBJECT && v.GetTypeInfo()->GetKind() == wxT_OBJECT_PTR ) | |
596 | value = *v.Get<T*>(); | |
597 | else | |
598 | value = v.Get<T>(); | |
a095505c SC |
599 | if (m_setter) |
600 | (obj->*(m_setter))(value); | |
fa08490f SC |
601 | else if ( m_setter_ref ) |
602 | (obj->*(m_setter_ref))(value); | |
603 | else if ( m_setter_ref_bool ) | |
604 | (obj->*(m_setter_ref_bool))(value); | |
605 | else if ( m_setter_bool ) | |
606 | (obj->*(m_setter_bool))(value); | |
607 | else | |
608 | { | |
609 | wxASSERT_MSG(0 , wxT("SetPropertyCalled without a valid Setter") ) ; | |
610 | } | |
611 | } | |
a095505c | 612 | |
517fb871 | 613 | // gets the property this accessor is responsible for from an object |
a095505c SC |
614 | wxxVariant GetProperty(wxObject *o) const |
615 | { | |
517fb871 | 616 | return wxxVariant( (wxxVariantData* ) DoGetProperty( o ) ) ; |
a095505c SC |
617 | } |
618 | ||
517fb871 VS |
619 | // write the property this accessor is responsible for from an object into |
620 | // a xml node | |
621 | void WriteValue( wxXmlNode* node , wxObject *o ) const | |
622 | { | |
623 | DoGetProperty( o )->Write( node ) ; | |
624 | } | |
625 | ||
626 | // write the property this accessor is responsible for from an object into | |
627 | // a string | |
628 | void WriteValue( wxString& s , wxObject *o ) const | |
629 | { | |
630 | DoGetProperty( o )->Write( s ) ; | |
631 | } | |
632 | ||
633 | // read a wxxVariant having the correct type for the property this accessor | |
634 | // is responsible for from an xml node | |
635 | wxxVariant ReadValue( wxXmlNode* node ) const | |
636 | { | |
637 | T data ; | |
638 | wxXmlReadValue( node , data ) ; | |
639 | return wxxVariant( data ) ; | |
640 | } | |
641 | ||
642 | // read a wxxVariant having the correct type for the property this accessor | |
643 | // is responsible for from a string | |
644 | wxxVariant ReadValue( const wxString &value ) const | |
645 | { | |
646 | T data ; | |
647 | wxStringReadValue( value , data ) ; | |
648 | return wxxVariant( data ) ; | |
649 | } | |
a095505c SC |
650 | |
651 | private : | |
652 | wxxVariantDataT<T>* DoGetProperty(wxObject *o) const | |
653 | { | |
654 | Klass *obj = dynamic_cast<Klass*>(o); | |
517fb871 VS |
655 | if ( m_getter ) |
656 | return new wxxVariantDataT<T>( (obj->*(m_getter))() ) ; | |
657 | else | |
658 | return new wxxVariantDataT<T>( (obj->*(m_getter_ref))() ) ; | |
a095505c SC |
659 | } |
660 | ||
661 | setter_t m_setter; | |
662 | setter_ref_t m_setter_ref; | |
fa08490f SC |
663 | setter_ref_bool_t m_setter_ref_bool ; |
664 | setter_bool_t m_setter_bool ; | |
a095505c | 665 | getter_t m_getter; |
517fb871 | 666 | getter_ref_t m_getter_ref ; |
a095505c SC |
667 | }; |
668 | ||
669 | class WXDLLIMPEXP_BASE wxPropertyInfo | |
670 | { | |
671 | public : | |
fa08490f SC |
672 | wxPropertyInfo( wxPropertyInfo* &iter , const wxChar *name , const wxChar *typeName , const wxTypeInfo* typeInfo , wxPropertyAccessor *accessor , wxxVariant dv ) : |
673 | m_name( name ) , m_typeName(typeName) , m_typeInfo( typeInfo ) , m_accessor( accessor ) , m_defaultValue( dv ) | |
674 | { | |
675 | m_next = NULL ; | |
676 | if ( iter == NULL ) | |
677 | iter = this ; | |
678 | else | |
679 | { | |
680 | wxPropertyInfo* i = iter ; | |
681 | while( i->m_next ) | |
682 | i = i->m_next ; | |
683 | ||
684 | i->m_next = this ; | |
685 | } | |
686 | } | |
687 | // return the name of this property | |
688 | const wxChar * GetName() const { return m_name ; } | |
689 | ||
690 | // return the typename of this property | |
691 | const wxChar * GetTypeName() const { return m_typeName ; } | |
692 | ||
693 | // return the type info of this property | |
694 | const wxTypeInfo * GetTypeInfo() const { return m_typeInfo ; } | |
695 | ||
696 | // return the accessor for this property | |
697 | wxPropertyAccessor* GetAccessor() const { return m_accessor ; } | |
698 | ||
699 | // returns NULL if this is the last property of this class | |
700 | wxPropertyInfo* GetNext() const { return m_next ; } | |
701 | ||
702 | // returns the default value of this property, its kind may be wxT_VOID if it is not valid | |
703 | wxxVariant GetDefaultValue() const { return m_defaultValue ; } | |
4393b50c | 704 | private : |
517fb871 VS |
705 | const wxChar * m_name; |
706 | const wxChar * m_typeName ; | |
707 | const wxTypeInfo* m_typeInfo ; | |
708 | wxPropertyAccessor* m_accessor ; | |
4393b50c | 709 | wxxVariant m_defaultValue; |
517fb871 VS |
710 | // string representation of the default value |
711 | // to be assigned by the designer to the property | |
712 | // when the component is dropped on the container. | |
713 | wxPropertyInfo* m_next ; | |
a095505c SC |
714 | }; |
715 | ||
716 | #define WX_BEGIN_PROPERTIES_TABLE(theClass) \ | |
717 | const wxPropertyInfo *theClass::GetPropertiesStatic() \ | |
718 | { \ | |
719 | typedef theClass class_t; \ | |
517fb871 | 720 | static wxPropertyInfo* first = NULL ; |
a095505c SC |
721 | |
722 | #define WX_END_PROPERTIES_TABLE() \ | |
517fb871 | 723 | return first ; } |
a095505c SC |
724 | |
725 | #define WX_PROPERTY( name , type , setter , getter ,defaultValue ) \ | |
fa08490f SC |
726 | static wxPropertyAccessorT<class_t , type> _accessor##name( &setter , &getter , #setter , #getter ) ; \ |
727 | static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ; | |
728 | ||
729 | #define WX_PROPERTY_SET_RET_BOOL( name , type , setter , getter ,defaultValue ) \ | |
730 | static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetRetBool*)NULL , &setter , &getter , #setter , #getter ) ; \ | |
731 | static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ; | |
4393b50c SC |
732 | |
733 | #define WX_PROPERTY_SET_BY_REF( name , type , setter , getter ,defaultValue ) \ | |
734 | static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetByRef*)NULL, &setter , &getter , #setter , #getter ) ; \ | |
735 | static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ; | |
736 | ||
fa08490f SC |
737 | #define WX_PROPERTY_SET_BY_REF_RET_BOOL( name , type , setter , getter ,defaultValue ) \ |
738 | static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetByRefRetBool*)NULL, &setter , &getter , #setter , #getter ) ; \ | |
739 | static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ; | |
740 | ||
741 | #define WX_PROPERTY_SET_AND_GET_BY_REF_RET_BOOL( name , type , setter , getter ,defaultValue ) \ | |
742 | static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetAndGetByRefRetBool*)NULL, &setter , &getter , #setter , #getter ) ; \ | |
743 | static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ; | |
744 | ||
4393b50c | 745 | #define WX_READONLY_PROPERTY( name , type , getter ,defaultValue ) \ |
517fb871 VS |
746 | static wxPropertyAccessorT<class_t , type> _accessor##name( &getter , #getter ) ; \ |
747 | static wxPropertyInfo _propertyInfo##name( first , #name , #type , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ; | |
a095505c SC |
748 | |
749 | #define WX_DELEGATE( name , eventType , eventClass ) \ | |
517fb871 VS |
750 | static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \ |
751 | static wxPropertyInfo _propertyInfo##name( first , #name , NULL , &_typeInfo##name , NULL , wxxVariant() ) ; \ | |
a095505c SC |
752 | |
753 | // ---------------------------------------------------------------------------- | |
754 | // Handler Info | |
755 | // | |
756 | // this is describing an event sink | |
757 | // ---------------------------------------------------------------------------- | |
758 | ||
759 | class wxHandlerInfo | |
760 | { | |
761 | public : | |
fa08490f SC |
762 | wxHandlerInfo( wxHandlerInfo* &iter , const wxChar *name , wxObjectEventFunction address , const wxClassInfo* eventClassInfo ) : |
763 | m_name( name ) , m_eventClassInfo( eventClassInfo ) , m_eventFunction( address ) | |
764 | { | |
765 | m_next = NULL ; | |
766 | if ( iter == NULL ) | |
767 | iter = this ; | |
768 | else | |
769 | { | |
770 | wxHandlerInfo* i = iter ; | |
771 | while( i->m_next ) | |
772 | i = i->m_next ; | |
773 | ||
774 | i->m_next = this ; | |
775 | } | |
776 | } | |
777 | ||
778 | // get the name of the handler method | |
779 | const wxChar * GetName() const { return m_name ; } | |
780 | ||
781 | // return the class info of the event | |
782 | const wxClassInfo * GetEventClassInfo() const { return m_eventClassInfo ; } | |
783 | ||
784 | // get the handler function pointer | |
785 | wxObjectEventFunction GetEventFunction() const { return m_eventFunction ; } | |
786 | ||
787 | // returns NULL if this is the last handler of this class | |
788 | wxHandlerInfo* GetNext() const { return m_next ; } | |
4393b50c | 789 | private : |
517fb871 VS |
790 | wxObjectEventFunction m_eventFunction ; |
791 | const wxChar * m_name; | |
792 | const wxClassInfo* m_eventClassInfo ; | |
793 | wxHandlerInfo* m_next ; | |
a095505c SC |
794 | }; |
795 | ||
796 | #define WX_HANDLER(name,eventClassType) \ | |
517fb871 | 797 | static wxHandlerInfo _handlerInfo##name( first , #name , (wxObjectEventFunction) (wxEventFunction) &name , CLASSINFO( eventClassType ) ) ; |
a095505c SC |
798 | |
799 | #define WX_BEGIN_HANDLERS_TABLE(theClass) \ | |
800 | const wxHandlerInfo *theClass::GetHandlersStatic() \ | |
801 | { \ | |
802 | typedef theClass class_t; \ | |
517fb871 | 803 | static wxHandlerInfo* first = NULL ; |
a095505c SC |
804 | |
805 | #define WX_END_HANDLERS_TABLE() \ | |
517fb871 | 806 | return first ; } |
a095505c SC |
807 | |
808 | // ---------------------------------------------------------------------------- | |
809 | // Constructor Bridges | |
810 | // | |
811 | // allow to set up constructors with params during runtime | |
812 | // ---------------------------------------------------------------------------- | |
813 | ||
814 | class WXDLLIMPEXP_BASE wxConstructorBridge | |
815 | { | |
816 | public : | |
817 | virtual void Create(wxObject *o, wxxVariant *args) = 0; | |
818 | }; | |
819 | ||
820 | // Creator Bridges for all Numbers of Params | |
821 | ||
822 | // no params | |
823 | ||
824 | template<typename Class> | |
825 | struct wxConstructorBridge_0 : public wxConstructorBridge | |
826 | { | |
827 | void Create(wxObject *o, wxxVariant *) | |
828 | { | |
829 | Class *obj = dynamic_cast<Class*>(o); | |
830 | obj->Create(); | |
831 | } | |
832 | }; | |
833 | ||
834 | struct wxConstructorBridge_Dummy : public wxConstructorBridge | |
835 | { | |
836 | void Create(wxObject *, wxxVariant *) | |
837 | { | |
838 | } | |
839 | } ; | |
840 | ||
841 | #define WX_CONSTRUCTOR_0(klass) \ | |
517fb871 VS |
842 | wxConstructorBridge_0<klass> constructor##klass ; \ |
843 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
844 | const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \ | |
845 | const int klass::sm_constructorPropertiesCount##klass = 0 ; | |
a095505c SC |
846 | |
847 | #define WX_CONSTRUCTOR_DUMMY(klass) \ | |
517fb871 VS |
848 | wxConstructorBridge_Dummy constructor##klass ; \ |
849 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
850 | const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \ | |
851 | const int klass::sm_constructorPropertiesCount##klass = 0 ; | |
a095505c SC |
852 | |
853 | // 1 param | |
854 | ||
855 | template<typename Class, typename T0> | |
856 | struct wxConstructorBridge_1 : public wxConstructorBridge | |
857 | { | |
858 | void Create(wxObject *o, wxxVariant *args) | |
859 | { | |
860 | Class *obj = dynamic_cast<Class*>(o); | |
861 | obj->Create( | |
862 | args[0].Get<T0>() | |
863 | ); | |
864 | } | |
865 | }; | |
866 | ||
867 | #define WX_CONSTRUCTOR_1(klass,t0,v0) \ | |
517fb871 VS |
868 | wxConstructorBridge_1<klass,t0> constructor##klass ; \ |
869 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
870 | const wxChar *klass::sm_constructorProperties##klass[] = { #v0 } ; \ | |
871 | const int klass::sm_constructorPropertiesCount##klass = 1 ; | |
a095505c SC |
872 | |
873 | // 2 params | |
874 | ||
875 | template<typename Class, | |
876 | typename T0, typename T1> | |
877 | struct wxConstructorBridge_2 : public wxConstructorBridge | |
878 | { | |
fbbdc52c | 879 | void Create(wxObject *o, wxxVariant *args) |
a095505c SC |
880 | { |
881 | Class *obj = dynamic_cast<Class*>(o); | |
882 | obj->Create( | |
883 | args[0].Get<T0>() , | |
4393b50c | 884 | args[1].Get<T1>() |
a095505c SC |
885 | ); |
886 | } | |
887 | }; | |
888 | ||
889 | #define WX_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \ | |
517fb871 VS |
890 | wxConstructorBridge_2<klass,t0,t1> constructor##klass ; \ |
891 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
892 | const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 } ; \ | |
893 | const int klass::sm_constructorPropertiesCount##klass = 2; | |
a095505c SC |
894 | |
895 | // 3 params | |
896 | ||
897 | template<typename Class, | |
898 | typename T0, typename T1, typename T2> | |
899 | struct wxConstructorBridge_3 : public wxConstructorBridge | |
900 | { | |
fbbdc52c | 901 | void Create(wxObject *o, wxxVariant *args) |
a095505c SC |
902 | { |
903 | Class *obj = dynamic_cast<Class*>(o); | |
904 | obj->Create( | |
905 | args[0].Get<T0>() , | |
906 | args[1].Get<T1>() , | |
4393b50c | 907 | args[2].Get<T2>() |
a095505c SC |
908 | ); |
909 | } | |
910 | }; | |
911 | ||
912 | #define WX_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \ | |
517fb871 VS |
913 | wxConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \ |
914 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
915 | const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 } ; \ | |
916 | const int klass::sm_constructorPropertiesCount##klass = 3 ; | |
a095505c SC |
917 | |
918 | // 4 params | |
919 | ||
920 | template<typename Class, | |
921 | typename T0, typename T1, typename T2, typename T3> | |
922 | struct wxConstructorBridge_4 : public wxConstructorBridge | |
923 | { | |
fbbdc52c | 924 | void Create(wxObject *o, wxxVariant *args) |
a095505c SC |
925 | { |
926 | Class *obj = dynamic_cast<Class*>(o); | |
927 | obj->Create( | |
928 | args[0].Get<T0>() , | |
929 | args[1].Get<T1>() , | |
930 | args[2].Get<T2>() , | |
4393b50c | 931 | args[3].Get<T3>() |
a095505c SC |
932 | ); |
933 | } | |
934 | }; | |
935 | ||
936 | #define WX_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \ | |
517fb871 VS |
937 | wxConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass ; \ |
938 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
939 | const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 } ; \ | |
940 | const int klass::sm_constructorPropertiesCount##klass = 4 ; | |
fbbdc52c SC |
941 | |
942 | // 5 params | |
943 | ||
944 | template<typename Class, | |
945 | typename T0, typename T1, typename T2, typename T3, typename T4> | |
946 | struct wxConstructorBridge_5 : public wxConstructorBridge | |
947 | { | |
948 | void Create(wxObject *o, wxxVariant *args) | |
949 | { | |
950 | Class *obj = dynamic_cast<Class*>(o); | |
951 | obj->Create( | |
952 | args[0].Get<T0>() , | |
953 | args[1].Get<T1>() , | |
954 | args[2].Get<T2>() , | |
955 | args[3].Get<T3>() , | |
4393b50c | 956 | args[4].Get<T4>() |
fbbdc52c SC |
957 | ); |
958 | } | |
959 | }; | |
960 | ||
961 | #define WX_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \ | |
fa08490f SC |
962 | wxConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass ; \ |
963 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
964 | const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 } ; \ | |
965 | const int klass::sm_constructorPropertiesCount##klass = 5; | |
966 | ||
967 | // 6 params | |
968 | ||
969 | template<typename Class, | |
970 | typename T0, typename T1, typename T2, typename T3, typename T4, typename T5> | |
971 | struct wxConstructorBridge_6 : public wxConstructorBridge | |
972 | { | |
973 | void Create(wxObject *o, wxxVariant *args) | |
974 | { | |
975 | Class *obj = dynamic_cast<Class*>(o); | |
976 | obj->Create( | |
977 | args[0].Get<T0>() , | |
978 | args[1].Get<T1>() , | |
979 | args[2].Get<T2>() , | |
980 | args[3].Get<T3>() , | |
981 | args[4].Get<T4>() , | |
982 | args[5].Get<T5>() | |
983 | ); | |
984 | } | |
985 | }; | |
986 | ||
987 | #define WX_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \ | |
988 | wxConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \ | |
989 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
990 | const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 } ; \ | |
991 | const int klass::sm_constructorPropertiesCount##klass = 6; | |
992 | ||
a095505c SC |
993 | |
994 | // ---------------------------------------------------------------------------- | |
995 | // wxClassInfo | |
996 | // ---------------------------------------------------------------------------- | |
997 | ||
998 | typedef wxObject *(*wxObjectConstructorFn)(void); | |
fa08490f | 999 | typedef wxObject* (*wxVariantToObjectConverter)( wxxVariant &data ) ; |
a095505c SC |
1000 | typedef wxxVariant (*wxObjectToVariantConverter)( wxObject* ) ; |
1001 | ||
1002 | class WXDLLIMPEXP_BASE wxClassInfo | |
1003 | { | |
1004 | public: | |
1005 | wxClassInfo(const wxClassInfo **_Parents, | |
517fb871 VS |
1006 | const wxChar *_UnitName, |
1007 | const wxChar *_ClassName, | |
a095505c SC |
1008 | int size, |
1009 | wxObjectConstructorFn ctor , | |
fa08490f SC |
1010 | const wxPropertyInfo *_Props , |
1011 | const wxHandlerInfo *_Handlers , | |
1012 | wxConstructorBridge* _Constructor , | |
1013 | const wxChar ** _ConstructorProperties , | |
1014 | const int _ConstructorPropertiesCount , | |
1015 | wxVariantToObjectConverter _PtrConverter1 , | |
1016 | wxVariantToObjectConverter _Converter2 , | |
1017 | wxObjectToVariantConverter _Converter3 | |
1018 | ) : m_parents(_Parents) , m_unitName(_UnitName) ,m_className(_ClassName), | |
1019 | m_objectSize(size), m_objectConstructor(ctor) , m_firstProperty(_Props ) , m_firstHandler(_Handlers ) , m_constructor( _Constructor ) , | |
1020 | m_constructorProperties(_ConstructorProperties) , m_constructorPropertiesCount(_ConstructorPropertiesCount), | |
1021 | m_variantOfPtrToObjectConverter( _PtrConverter1 ) , m_variantToObjectConverter( _Converter2 ) , m_objectToVariantConverter( _Converter3 ) , m_next(sm_first) | |
1022 | { | |
1023 | sm_first = this; | |
1024 | Register( m_className , this ) ; | |
1025 | } | |
a095505c | 1026 | |
aeec2045 | 1027 | virtual ~wxClassInfo() ; |
a095505c | 1028 | |
fa08490f | 1029 | wxObject *CreateObject() const { return m_objectConstructor ? (*m_objectConstructor)() : 0; } |
a095505c SC |
1030 | |
1031 | const wxChar *GetClassName() const { return m_className; } | |
1032 | const wxClassInfo **GetParents() const { return m_parents; } | |
1033 | int GetSize() const { return m_objectSize; } | |
1034 | ||
1035 | wxObjectConstructorFn GetConstructor() const { return m_objectConstructor; } | |
1036 | static const wxClassInfo *GetFirst() { return sm_first; } | |
1037 | const wxClassInfo *GetNext() const { return m_next; } | |
1038 | static wxClassInfo *FindClass(const wxChar *className); | |
1039 | ||
1040 | // Climb upwards through inheritance hierarchy. | |
1041 | // Dual inheritance is catered for. | |
1042 | ||
1043 | bool IsKindOf(const wxClassInfo *info) const | |
1044 | { | |
517fb871 VS |
1045 | if ( info != 0 ) |
1046 | { | |
1047 | if ( info == this ) | |
1048 | return true ; | |
1049 | ||
1050 | for ( int i = 0 ; m_parents[i] ; ++ i ) | |
1051 | { | |
1052 | if ( m_parents[i]->IsKindOf( info ) ) | |
1053 | return true ; | |
1054 | } | |
1055 | } | |
1056 | return false ; | |
a095505c SC |
1057 | } |
1058 | ||
1059 | // Initializes parent pointers and hash table for fast searching. | |
517fb871 VS |
1060 | // this is going to be removed by Register/Unregister calls |
1061 | // in Constructor / Destructor together with making the hash map private | |
a095505c SC |
1062 | |
1063 | static void InitializeClasses(); | |
1064 | ||
1065 | // Cleans up hash table used for fast searching. | |
1066 | ||
1067 | static void CleanUpClasses(); | |
1068 | ||
517fb871 VS |
1069 | // returns the first property |
1070 | const wxPropertyInfo* GetFirstProperty() const { return m_firstProperty ; } | |
a095505c | 1071 | |
517fb871 VS |
1072 | // returns the first handler |
1073 | const wxHandlerInfo* GetFirstHandler() const { return m_firstHandler ; } | |
a095505c SC |
1074 | |
1075 | // Call the Create method for a class | |
fa08490f SC |
1076 | virtual void Create (wxObject *object, int ParamCount, wxxVariant *Params) const |
1077 | { | |
1078 | wxASSERT_MSG( ParamCount == m_constructorPropertiesCount , wxT("Illegal Parameter Count for Create Method")) ; | |
1079 | m_constructor->Create( object , Params ) ; | |
1080 | } | |
a095505c | 1081 | |
517fb871 VS |
1082 | // get number of parameters for constructor |
1083 | virtual int GetCreateParamCount() const { return m_constructorPropertiesCount; } | |
a095505c | 1084 | |
517fb871 VS |
1085 | // get i-th constructor parameter |
1086 | virtual const wxChar* GetCreateParamName(int i) const { return m_constructorProperties[i] ; } | |
a095505c SC |
1087 | |
1088 | // Runtime access to objects by property name, and variant data | |
fbbdc52c SC |
1089 | virtual void SetProperty (wxObject *object, const wxChar *PropertyName, const wxxVariant &Value); |
1090 | virtual wxxVariant GetProperty (wxObject *object, const wxChar *PropertyName); | |
a095505c | 1091 | |
fa08490f | 1092 | // we must be able to cast variants to wxObject pointers, templates seem not to be suitable |
f0b7eadf | 1093 | wxObject* VariantToInstance( wxxVariant &data ) const |
fa08490f | 1094 | { if ( data.GetTypeInfo()->GetKind() == wxT_OBJECT ) |
f0b7eadf | 1095 | return m_variantToObjectConverter( data ) ; |
fa08490f SC |
1096 | else |
1097 | return m_variantOfPtrToObjectConverter( data ) ; | |
1098 | } | |
1099 | ||
1100 | wxxVariant InstanceToVariant( wxObject *object ) const { return m_objectToVariantConverter( object ) ; } | |
4393b50c | 1101 | |
517fb871 | 1102 | // find property by name |
fbbdc52c SC |
1103 | virtual const wxPropertyInfo *FindPropertyInfo (const wxChar *PropertyName) const ; |
1104 | ||
517fb871 | 1105 | // find handler by name |
fbbdc52c | 1106 | virtual const wxHandlerInfo *FindHandlerInfo (const wxChar *PropertyName) const ; |
a095505c SC |
1107 | |
1108 | public: | |
1109 | const wxChar *m_className; | |
1110 | int m_objectSize; | |
1111 | wxObjectConstructorFn m_objectConstructor; | |
1112 | ||
1113 | // class info object live in a linked list: | |
1114 | // pointers to its head and the next element in it | |
1115 | ||
1116 | static wxClassInfo *sm_first; | |
1117 | wxClassInfo *m_next; | |
1118 | ||
517fb871 | 1119 | // FIXME: this should be private (currently used directly by way too |
a095505c SC |
1120 | // many clients) |
1121 | static wxHashTable *sm_classTable; | |
1122 | ||
1123 | private: | |
fa08490f SC |
1124 | const wxClassInfo** m_parents ; |
1125 | const wxPropertyInfo * m_firstProperty ; | |
1126 | const wxHandlerInfo * m_firstHandler ; | |
1127 | const wxChar* m_unitName; | |
1128 | ||
1129 | wxConstructorBridge* m_constructor ; | |
1130 | const wxChar ** m_constructorProperties ; | |
1131 | const int m_constructorPropertiesCount ; | |
1132 | wxVariantToObjectConverter m_variantOfPtrToObjectConverter ; | |
1133 | wxVariantToObjectConverter m_variantToObjectConverter ; | |
1134 | wxObjectToVariantConverter m_objectToVariantConverter ; | |
a095505c | 1135 | |
fbbdc52c | 1136 | const wxPropertyAccessor *FindAccessor (const wxChar *propertyName); |
a095505c | 1137 | |
a095505c | 1138 | |
517fb871 | 1139 | // InitializeClasses() helper |
a095505c | 1140 | static wxClassInfo *GetBaseByName(const wxChar *name); |
d1d738f1 VS |
1141 | |
1142 | protected: | |
1143 | // registers the class | |
1144 | void Register(); | |
1145 | void Unregister(); | |
a095505c SC |
1146 | |
1147 | DECLARE_NO_COPY_CLASS(wxClassInfo) | |
1148 | }; | |
1149 | ||
1150 | WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name); | |
1151 | ||
1152 | // ---------------------------------------------------------------------------- | |
1153 | // Dynamic class macros | |
1154 | // ---------------------------------------------------------------------------- | |
1155 | ||
1156 | #define _DECLARE_DYNAMIC_CLASS(name) \ | |
1157 | public: \ | |
1158 | static wxClassInfo sm_class##name; \ | |
1159 | static const wxClassInfo* sm_classParents##name[] ; \ | |
1160 | static const wxPropertyInfo* GetPropertiesStatic() ; \ | |
1161 | static const wxHandlerInfo* GetHandlersStatic() ; \ | |
1162 | virtual wxClassInfo *GetClassInfo() const \ | |
1163 | { return &name::sm_class##name; } | |
1164 | ||
1165 | #define DECLARE_DYNAMIC_CLASS(name) \ | |
f0b7eadf SC |
1166 | static wxConstructorBridge* sm_constructor##name ; \ |
1167 | static const wxChar * sm_constructorProperties##name[] ; \ | |
1168 | static const int sm_constructorPropertiesCount##name ; \ | |
1169 | _DECLARE_DYNAMIC_CLASS(name) | |
a095505c SC |
1170 | |
1171 | #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \ | |
1172 | DECLARE_NO_ASSIGN_CLASS(name) \ | |
1173 | DECLARE_DYNAMIC_CLASS(name) | |
1174 | ||
1175 | #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \ | |
1176 | DECLARE_NO_COPY_CLASS(name) \ | |
1177 | DECLARE_DYNAMIC_CLASS(name) | |
1178 | ||
1179 | #define DECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name) | |
1180 | #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name) | |
1181 | ||
1182 | // ----------------------------------- | |
1183 | // for concrete classes | |
1184 | // ----------------------------------- | |
1185 | ||
1186 | // Single inheritance with one base class | |
1187 | ||
1188 | #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit) \ | |
1189 | wxObject* wxConstructorFor##name() \ | |
1190 | { return new name; } \ | |
1191 | const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \ | |
fa08490f SC |
1192 | wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \ |
1193 | wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \ | |
a095505c SC |
1194 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \ |
1195 | (int) sizeof(name), \ | |
1196 | (wxObjectConstructorFn) wxConstructorFor##name , \ | |
fa08490f SC |
1197 | name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \ |
1198 | name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name); \ | |
1199 | template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\ | |
1200 | template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
dadaeb69 SC |
1201 | template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\ |
1202 | template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
f0b7eadf SC |
1203 | template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1204 | template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1205 | template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \ | |
fa08490f SC |
1206 | template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \ |
1207 | template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } | |
1208 | ||
1209 | #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit) \ | |
1210 | wxObject* wxConstructorFor##name() \ | |
1211 | { return new name; } \ | |
1212 | const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \ | |
1213 | wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return &data.Get<name>() ; } \ | |
1214 | wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \ | |
1215 | wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \ | |
1216 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \ | |
1217 | (int) sizeof(name), \ | |
1218 | (wxObjectConstructorFn) wxConstructorFor##name , \ | |
1219 | name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \ | |
1220 | name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \ | |
1221 | template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\ | |
1222 | template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1223 | template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\ | |
1224 | template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
f0b7eadf SC |
1225 | template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1226 | template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1227 | template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \ | |
fa08490f SC |
1228 | template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \ |
1229 | template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } | |
1230 | ||
1231 | #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \ | |
1232 | _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" ) \ | |
1233 | const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \ | |
1234 | const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \ | |
1235 | WX_CONSTRUCTOR_DUMMY( name ) | |
a095505c SC |
1236 | |
1237 | #define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \ | |
1238 | _IMPLEMENT_DYNAMIC_CLASS( name , basename , "" ) \ | |
1239 | const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \ | |
fbbdc52c | 1240 | const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \ |
a095505c SC |
1241 | WX_CONSTRUCTOR_DUMMY( name ) |
1242 | ||
1243 | #define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \ | |
1244 | _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit ) | |
1245 | ||
fa08490f SC |
1246 | #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \ |
1247 | _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit ) | |
1248 | ||
4393b50c | 1249 | // this is for classes that do not derive from wxobject, there are no creators for these |
a095505c SC |
1250 | |
1251 | #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name , unit ) \ | |
1252 | const wxClassInfo* name::sm_classParents##name[] = { NULL } ; \ | |
1253 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \ | |
1254 | (int) sizeof(name), \ | |
1255 | (wxObjectConstructorFn) 0 , \ | |
517fb871 VS |
1256 | name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \ |
1257 | 0 , 0 , 0 ); \ | |
dadaeb69 SC |
1258 | template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1259 | template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
f0b7eadf SC |
1260 | template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1261 | template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1262 | template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \ | |
1263 | template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \ | |
fa08490f | 1264 | template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } |
a095505c SC |
1265 | |
1266 | // this is for subclasses that still do not derive from wxobject | |
1267 | ||
1268 | #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name , basename, unit ) \ | |
1269 | const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \ | |
1270 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \ | |
1271 | (int) sizeof(name), \ | |
1272 | (wxObjectConstructorFn) 0 , \ | |
517fb871 VS |
1273 | name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \ |
1274 | 0 , 0 , 0 ); \ | |
dadaeb69 SC |
1275 | template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1276 | template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
f0b7eadf SC |
1277 | template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1278 | template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1279 | template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \ | |
1280 | template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \ | |
fa08490f | 1281 | template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } |
a095505c | 1282 | |
f0b7eadf | 1283 | |
a095505c SC |
1284 | // Multiple inheritance with two base classes |
1285 | ||
1286 | #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit) \ | |
1287 | wxObject* wxConstructorFor##name() \ | |
1288 | { return new name; } \ | |
1289 | const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,&basename2::sm_class##basename2 , NULL } ; \ | |
fa08490f | 1290 | wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \ |
a095505c SC |
1291 | wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \ |
1292 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \ | |
1293 | (int) sizeof(name), \ | |
1294 | (wxObjectConstructorFn) wxConstructorFor##name , \ | |
517fb871 VS |
1295 | name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \ |
1296 | name::sm_constructorPropertiesCount##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \ | |
dadaeb69 SC |
1297 | template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1298 | template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
f0b7eadf SC |
1299 | template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1300 | template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1301 | template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \ | |
1302 | template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \ | |
fa08490f | 1303 | template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } |
a095505c SC |
1304 | |
1305 | #define IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2) \ | |
1306 | _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , "") \ | |
1307 | const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \ | |
fbbdc52c | 1308 | const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \ |
a095505c SC |
1309 | WX_CONSTRUCTOR_DUMMY( name ) |
1310 | ||
1311 | #define IMPLEMENT_DYNAMIC_CLASS2_XTI( name , basename , basename2, unit) \ | |
517fb871 | 1312 | _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , unit) |
a095505c SC |
1313 | |
1314 | // ----------------------------------- | |
1315 | // for abstract classes | |
1316 | // ----------------------------------- | |
1317 | ||
1318 | // Single inheritance with one base class | |
1319 | ||
1320 | #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \ | |
1321 | const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \ | |
fa08490f SC |
1322 | wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \ |
1323 | wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \ | |
1324 | wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \ | |
a095505c SC |
1325 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \ |
1326 | (int) sizeof(name), \ | |
1327 | (wxObjectConstructorFn) 0 , \ | |
fa08490f SC |
1328 | name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \ |
1329 | 0 , wxVariantOfPtrToObjectConverter##name ,wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \ | |
dadaeb69 SC |
1330 | template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1331 | template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
f0b7eadf SC |
1332 | template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1333 | template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1334 | template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \ | |
1335 | template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } \ | |
1336 | template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID) ; assert(0) ; return &s_typeInfo ; } | |
a095505c SC |
1337 | |
1338 | #define IMPLEMENT_ABSTRACT_CLASS( name , basename ) \ | |
1339 | _IMPLEMENT_ABSTRACT_CLASS( name , basename ) \ | |
fbbdc52c | 1340 | const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \ |
4393b50c | 1341 | const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } |
a095505c SC |
1342 | |
1343 | // Multiple inheritance with two base classes | |
1344 | ||
1345 | #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \ | |
1346 | wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \ | |
1347 | wxT(#basename2), (int) sizeof(name), \ | |
1348 | (wxObjectConstructorFn) 0); | |
1349 | ||
1350 | #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS | |
1351 | #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2 | |
1352 | ||
aeec2045 | 1353 | #endif |