]>
Commit | Line | Data |
---|---|---|
a095505c SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/xti.h | |
3 | // Purpose: runtime metadata information (extended class info) | |
4 | // Author: Stefan Csomor | |
4393b50c | 5 | // Modified by: |
a095505c SC |
6 | // Created: 27/07/03 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1997 Julian Smart | |
9 | // (c) 2003 Stefan Csomor | |
10 | // Licence: wxWindows licence | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | #ifndef _WX_XTIH__ | |
14 | #define _WX_XTIH__ | |
15 | ||
12028905 | 16 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
a095505c SC |
17 | #pragma interface "xti.h" |
18 | #endif | |
19 | ||
20 | // We want to support properties, event sources and events sinks through | |
21 | // explicit declarations, using templates and specialization to make the | |
4393b50c | 22 | // effort as painless as possible. |
a095505c SC |
23 | // |
24 | // This means we have the following domains : | |
25 | // | |
26 | // - Type Information for categorizing built in types as well as custom types | |
27 | // this includes information about enums, their values and names | |
28 | // - Type safe value storage : a kind of wxVariant, called right now wxxVariant | |
4393b50c | 29 | // which will be merged with wxVariant |
a095505c SC |
30 | // - Property Information and Property Accessors providing access to a class' |
31 | // values and exposed event delegates | |
32 | // - Information about event handlers | |
33 | // - extended Class Information for accessing all these | |
34 | ||
35 | // ---------------------------------------------------------------------------- | |
36 | // headers | |
37 | // ---------------------------------------------------------------------------- | |
38 | ||
39 | #include "wx/defs.h" | |
40 | #include "wx/memory.h" | |
41 | #include "wx/set.h" | |
42 | #include "wx/string.h" | |
aeec2045 | 43 | #include "wx/arrstr.h" |
a095505c 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 ; } \ | |
517fb871 VS |
112 | template<> void wxStringReadValue(const wxString& s , e &data ) \ |
113 | { \ | |
114 | data = (e) s_enumData##e.GetEnumMemberValue(s) ; \ | |
115 | } \ | |
116 | template<> void wxStringWriteValue(wxString &s , const e &data ) \ | |
117 | { \ | |
118 | s = s_enumData##e.GetEnumMemberName((int)data) ; \ | |
f0b7eadf | 119 | } \ |
208fd16c | 120 | template<> const wxTypeInfo* wxGetTypeInfo( e * ){ static wxEnumTypeInfo s_typeInfo(wxT_ENUM , &s_enumData##e , &wxToStringConverter<e> , &wxFromStringConverter<e>) ; return &s_typeInfo ; } \ |
f0b7eadf SC |
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 ) ; \ | |
208fd16c | 214 | } |
a095505c SC |
215 | |
216 | ||
217 | // ---------------------------------------------------------------------------- | |
218 | // Type Information | |
219 | // ---------------------------------------------------------------------------- | |
ab6e4913 SC |
220 | // |
221 | // | |
222 | // All data exposed by the RTTI is characterized using the following classes. | |
223 | // The first characterization is done by wxTypeKind. All enums up to and including | |
224 | // wxT_CUSTOM represent so called simple types. These cannot be divided any further. | |
225 | // They can be converted to and from wxStrings, that's all. | |
226 | ||
a095505c SC |
227 | |
228 | enum wxTypeKind | |
229 | { | |
230 | wxT_VOID = 0, // unknown type | |
231 | wxT_BOOL, | |
232 | wxT_CHAR, | |
233 | wxT_UCHAR, | |
234 | wxT_INT, | |
235 | wxT_UINT, | |
236 | wxT_LONG, | |
237 | wxT_ULONG, | |
238 | wxT_FLOAT, | |
239 | wxT_DOUBLE, | |
240 | wxT_STRING, // must be wxString | |
241 | wxT_SET, // must be wxSet<> template | |
242 | wxT_ENUM, | |
a095505c | 243 | wxT_CUSTOM, // user defined type (e.g. wxPoint) |
75890a3f | 244 | |
ab6e4913 SC |
245 | wxT_LAST_SIMPLE_TYPE_KIND = wxT_CUSTOM , |
246 | ||
247 | wxT_OBJECT_PTR, // object reference | |
248 | wxT_OBJECT , // embedded object | |
249 | wxT_COLLECTION , // collection | |
250 | ||
517fb871 | 251 | wxT_DELEGATE , // for connecting against an event source |
75890a3f | 252 | |
ab6e4913 | 253 | wxT_LAST_TYPE_KIND = wxT_DELEGATE // sentinel for bad data, asserts, debugging |
a095505c SC |
254 | }; |
255 | ||
208fd16c SC |
256 | class wxxVariant ; |
257 | ||
a095505c SC |
258 | class WXDLLIMPEXP_BASE wxTypeInfo |
259 | { | |
260 | public : | |
208fd16c | 261 | wxTypeInfo() : m_kind( wxT_VOID) , m_toString(NULL) , m_fromString(NULL) {} |
fa08490f SC |
262 | virtual ~wxTypeInfo() {} |
263 | wxTypeKind GetKind() const { return m_kind ; } | |
264 | bool IsDelegateType() const { return m_kind == wxT_DELEGATE ; } | |
265 | bool IsCustomType() const { return m_kind == wxT_CUSTOM ; } | |
266 | bool IsObjectType() const { return m_kind == wxT_OBJECT || m_kind == wxT_OBJECT_PTR ; } | |
208fd16c SC |
267 | bool HasStringConverters() const { return m_toString != NULL && m_fromString != NULL ; } |
268 | void ConvertToString( const wxxVariant& data , wxString &result ) const | |
269 | { wxASSERT_MSG( m_toString , wxT("String conversions not supported") ) ; (*m_toString)( data , result ) ; } | |
270 | void ConvertFromString( const wxString& data , wxxVariant &result ) const | |
271 | { wxASSERT_MSG( m_fromString , wxT("String conversions not supported") ) ; (*m_fromString)( data , result ) ; } | |
272 | ||
a095505c | 273 | protected : |
208fd16c SC |
274 | typedef void (*converterToString_t)( const wxxVariant& data , wxString &result ) ; |
275 | typedef void (*converterFromString_t)( const wxString& data , wxxVariant &result ) ; | |
276 | ||
277 | converterToString_t m_toString ; | |
278 | converterFromString_t m_fromString ; | |
279 | ||
280 | wxTypeKind m_kind ; | |
a095505c SC |
281 | }; |
282 | ||
283 | class WXDLLIMPEXP_BASE wxBuiltInTypeInfo : public wxTypeInfo | |
284 | { | |
285 | public : | |
208fd16c SC |
286 | wxBuiltInTypeInfo( wxTypeKind kind , converterToString_t to = NULL , converterFromString_t from= NULL ) |
287 | { wxASSERT_MSG( kind < wxT_SET , wxT("Illegal Kind for Base Type") ) ; m_kind = kind ; m_toString = to ; m_fromString = from ;} | |
a095505c SC |
288 | } ; |
289 | ||
290 | class WXDLLIMPEXP_BASE wxCustomTypeInfo : public wxTypeInfo | |
291 | { | |
292 | public : | |
208fd16c SC |
293 | wxCustomTypeInfo( const wxChar *typeName , converterToString_t to= NULL , converterFromString_t from= NULL ) |
294 | { m_kind = wxT_CUSTOM ; m_typeName = typeName ;m_toString = to ; m_fromString = from ;} | |
517fb871 | 295 | const wxChar *GetTypeName() const { return m_typeName ; } |
a095505c | 296 | private : |
517fb871 | 297 | const wxChar *m_typeName; // Kind == wxT_CUSTOM |
a095505c SC |
298 | } ; |
299 | ||
300 | class WXDLLIMPEXP_BASE wxEnumTypeInfo : public wxTypeInfo | |
301 | { | |
302 | public : | |
208fd16c SC |
303 | wxEnumTypeInfo( wxTypeKind kind , wxEnumData* enumInfo , converterToString_t to = NULL , converterFromString_t from= NULL ) |
304 | { wxASSERT_MSG( kind == wxT_ENUM || kind == wxT_SET , wxT("Illegal Kind for Enum Type")) ; m_kind = kind ; m_enumInfo = enumInfo ;m_toString = to ; m_fromString = from ;} | |
517fb871 | 305 | const wxEnumData* GetEnumData() const { return m_enumInfo ; } |
a095505c | 306 | private : |
517fb871 | 307 | wxEnumData *m_enumInfo; // Kind == wxT_ENUM or Kind == wxT_SET |
a095505c SC |
308 | } ; |
309 | ||
310 | class WXDLLIMPEXP_BASE wxClassTypeInfo : public wxTypeInfo | |
311 | { | |
312 | public : | |
208fd16c | 313 | wxClassTypeInfo( wxTypeKind kind , wxClassInfo* classInfo , converterToString_t to = NULL , converterFromString_t from = NULL ) |
fa08490f SC |
314 | { wxASSERT_MSG( kind == wxT_OBJECT_PTR || kind == wxT_OBJECT , wxT("Illegal Kind for Enum Type")) ; m_kind = kind ; m_classInfo = classInfo ;} |
315 | const wxClassInfo *GetClassInfo() const { return m_classInfo ; } | |
a095505c | 316 | private : |
517fb871 | 317 | wxClassInfo *m_classInfo; // Kind == wxT_OBJECT - could be NULL |
a095505c SC |
318 | } ; |
319 | ||
ab6e4913 SC |
320 | class WXDLLIMPEXP_BASE wxCollectionTypeInfo : public wxTypeInfo |
321 | { | |
322 | public : | |
208fd16c SC |
323 | wxCollectionTypeInfo( wxTypeInfo *elementType , converterToString_t to = NULL , converterFromString_t from = NULL ) |
324 | { m_kind = wxT_COLLECTION , m_elementType = elementType ; m_toString = to ; m_fromString = from ;} | |
ab6e4913 SC |
325 | |
326 | const wxTypeInfo* GetElementType() const { return m_elementType ; } | |
327 | private : | |
328 | wxTypeInfo * m_elementType ; | |
329 | } ; | |
330 | ||
4393b50c | 331 | // a delegate is an exposed event source |
a095505c SC |
332 | |
333 | class WXDLLIMPEXP_BASE wxDelegateTypeInfo : public wxTypeInfo | |
334 | { | |
335 | public : | |
208fd16c SC |
336 | wxDelegateTypeInfo( int eventType , wxClassInfo* eventClass , converterToString_t to = NULL , converterFromString_t from = NULL ) |
337 | { m_kind = wxT_DELEGATE ; m_eventClass = eventClass ; m_eventType = eventType ;m_toString = to ; m_fromString = from ;} | |
517fb871 VS |
338 | const wxClassInfo *GetEventClass() const { assert( m_kind == wxT_DELEGATE ) ; return m_eventClass ; } |
339 | int GetEventType() const { return m_eventType ; } | |
a095505c | 340 | private : |
517fb871 VS |
341 | const wxClassInfo *m_eventClass; // (extended will merge into classinfo) |
342 | int m_eventType ; | |
a095505c SC |
343 | } ; |
344 | ||
345 | template<typename T> const wxTypeInfo* wxGetTypeInfo( T * ) ; | |
346 | ||
4393b50c | 347 | template<typename T> const wxTypeInfo* wxGetTypeInfo( wxSet<T> * ) |
a095505c | 348 | { |
517fb871 | 349 | static wxEnumTypeInfo s_typeInfo(wxT_SET , wxGetEnumData((T) 0) ) ; return &s_typeInfo ; |
a095505c SC |
350 | } |
351 | ||
352 | // this macro is for usage with custom, non-object derived classes and structs, wxPoint is such a custom type | |
353 | ||
354 | #define WX_CUSTOM_TYPE_INFO( e ) \ | |
f0b7eadf | 355 | template<> const wxTypeInfo* wxGetTypeInfo( e ** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID) ; assert(0) ; return &s_typeInfo ; } \ |
208fd16c | 356 | template<> const wxTypeInfo* wxGetTypeInfo( e * ){ static wxCustomTypeInfo s_typeInfo(#e, &wxToStringConverter<e> , &wxFromStringConverter<e>) ; return &s_typeInfo ; } |
a095505c | 357 | |
a095505c SC |
358 | // templated streaming, every type must have their specialization for these methods |
359 | ||
360 | template<typename T> | |
f0b7eadf | 361 | void wxStringReadValue( const wxString &s , T &data ); |
a095505c SC |
362 | |
363 | template<typename T> | |
f0b7eadf | 364 | void wxStringWriteValue( wxString &s , const T &data); |
a095505c | 365 | |
208fd16c SC |
366 | template<typename T> |
367 | void wxToStringConverter( const wxxVariant &v, wxString &s) { wxStringWriteValue( s , v.Get<T>() ) ; } | |
368 | ||
369 | template<typename T> | |
370 | void wxFromStringConverter( const wxString &s, wxxVariant &v) { T d ; wxStringReadValue( s , d ) ; v = wxxVariant(d) ; } \ | |
371 | ||
aa8d7c2f | 372 | // sometimes a compiler invents specializations that are nowhere called, use this macro to satisfy the refs |
a095505c | 373 | |
aa8d7c2f SC |
374 | #define WX_ILLEGAL_TYPE_SPECIALIZATION( a ) \ |
375 | template<> const wxTypeInfo* wxGetTypeInfo( a * ) { assert(0) ; \ | |
376 | static wxBuiltInTypeInfo s_typeInfo( wxT_VOID ) ; return &s_typeInfo ; } \ | |
377 | template<> void wxStringReadValue(const wxString & , a & ) { assert(0) ; }\ | |
378 | template<> void wxStringWriteValue(wxString & , a const & ) { assert(0) ; } | |
a095505c SC |
379 | |
380 | // ---------------------------------------------------------------------------- | |
381 | // wxxVariant as typesafe data holder | |
382 | // ---------------------------------------------------------------------------- | |
383 | ||
384 | class WXDLLIMPEXP_BASE wxxVariantData | |
385 | { | |
386 | public: | |
517fb871 | 387 | virtual ~wxxVariantData() {} |
a095505c | 388 | |
517fb871 VS |
389 | // return a heap allocated duplicate |
390 | virtual wxxVariantData* Clone() const = 0 ; | |
a095505c | 391 | |
517fb871 VS |
392 | // returns the type info of the contentc |
393 | virtual const wxTypeInfo* GetTypeInfo() const = 0 ; | |
a095505c SC |
394 | } ; |
395 | ||
396 | template<typename T> class WXDLLIMPEXP_BASE wxxVariantDataT : public wxxVariantData | |
397 | { | |
398 | public: | |
fa08490f SC |
399 | wxxVariantDataT(const T& d) : m_data(d) {} |
400 | virtual ~wxxVariantDataT() {} | |
a095505c | 401 | |
fa08490f SC |
402 | // get a ref to the stored data |
403 | T & Get() { return m_data; } | |
a095505c | 404 | |
fa08490f SC |
405 | // get a const ref to the stored data |
406 | const T & Get() const { return m_data; } | |
407 | ||
408 | // set the data | |
409 | void Set(const T& d) { m_data = d; } | |
a095505c | 410 | |
517fb871 VS |
411 | // return a heap allocated duplicate |
412 | virtual wxxVariantData* Clone() const { return new wxxVariantDataT<T>( Get() ) ; } | |
a095505c | 413 | |
517fb871 VS |
414 | // returns the type info of the contentc |
415 | virtual const wxTypeInfo* GetTypeInfo() const { return wxGetTypeInfo( (T*) NULL ) ; } | |
a095505c SC |
416 | private: |
417 | T m_data; | |
418 | }; | |
419 | ||
420 | class WXDLLIMPEXP_BASE wxxVariant | |
421 | { | |
422 | public : | |
fa08490f SC |
423 | wxxVariant() { m_data = NULL ; } |
424 | wxxVariant( wxxVariantData* data , const wxString& name = wxT("") ) : m_data(data) , m_name(name) {} | |
425 | wxxVariant( const wxxVariant &d ) { if ( d.m_data ) m_data = d.m_data->Clone() ; else m_data = NULL ; m_name = d.m_name ; } | |
426 | ||
427 | template<typename T> wxxVariant( T data , const wxString& name = wxT("") ) : | |
428 | m_data(new wxxVariantDataT<T>(data) ), m_name(name) {} | |
208fd16c | 429 | |
fa08490f SC |
430 | ~wxxVariant() { delete m_data ; } |
431 | ||
432 | // get a ref to the stored data | |
433 | template<typename T> T& Get() | |
434 | { | |
435 | wxxVariantDataT<T> *dataptr = dynamic_cast<wxxVariantDataT<T>*> (m_data) ; | |
436 | wxASSERT_MSG( dataptr , "Cast not possible" ) ; | |
437 | return dataptr->Get() ; | |
438 | } | |
439 | ||
440 | // get a ref to the stored data | |
441 | template<typename T> const T& Get() const | |
442 | { | |
443 | const wxxVariantDataT<T> *dataptr = dynamic_cast<const wxxVariantDataT<T>*> (m_data) ; | |
444 | wxASSERT_MSG( dataptr , "Cast not possible" ) ; | |
445 | return dataptr->Get() ; | |
446 | } | |
447 | ||
208fd16c SC |
448 | template<typename T> bool HasData() const |
449 | { | |
450 | const wxxVariantDataT<T> *dataptr = dynamic_cast<const wxxVariantDataT<T>*> (m_data) ; | |
451 | return dataptr != NULL ; | |
452 | } | |
453 | ||
fa08490f SC |
454 | // stores the data |
455 | template<typename T> void Set(const T& data) const | |
456 | { | |
457 | delete m_data ; | |
458 | m_data = new wxxVariantDataT<T>(data) ; | |
459 | } | |
460 | ||
461 | wxxVariant& operator=(const wxxVariant &d) | |
462 | { | |
463 | m_data = d.m_data->Clone() ; | |
464 | m_name = d.m_name ; | |
465 | return *this ; | |
466 | } | |
467 | ||
468 | // gets the stored data casted to a wxObject* , returning NULL if cast is not possible | |
469 | wxObject* GetAsObject() ; | |
470 | ||
471 | // get the typeinfo of the stored object | |
472 | const wxTypeInfo* GetTypeInfo() const { return m_data->GetTypeInfo() ; } | |
473 | ||
fa08490f SC |
474 | // returns this value as string |
475 | wxString GetAsString() const | |
476 | { | |
477 | wxString s ; | |
208fd16c | 478 | GetTypeInfo()->ConvertToString( *this , s ) ; |
fa08490f SC |
479 | return s ; |
480 | } | |
a095505c | 481 | private : |
517fb871 VS |
482 | wxxVariantData* m_data ; |
483 | wxString m_name ; | |
a095505c SC |
484 | } ; |
485 | ||
ab6e4913 SC |
486 | #include <wx/dynarray.h> |
487 | ||
488 | WX_DECLARE_OBJARRAY_WITH_DECL(wxxVariant, wxxVariantArray, class WXDLLIMPEXP_BASE); | |
489 | ||
a095505c SC |
490 | // ---------------------------------------------------------------------------- |
491 | // Property Support | |
492 | // | |
493 | // wxPropertyInfo is used to inquire of the property by name. It doesn't | |
494 | // provide access to the property, only information about it. If you | |
495 | // want access, look at wxPropertyAccessor. | |
496 | // ---------------------------------------------------------------------------- | |
497 | ||
208fd16c | 498 | class wxSetter |
a095505c SC |
499 | { |
500 | public : | |
208fd16c SC |
501 | wxSetter( const wxString name ) { m_name = name ; } |
502 | virtual void Set( wxObject *object, const wxxVariant &variantValue ) const = 0; | |
503 | const wxString& GetName() const { return m_name ; } | |
504 | private : | |
505 | wxString m_name ; | |
506 | } ; | |
a095505c | 507 | |
208fd16c | 508 | class wxGetter |
2d51f067 SC |
509 | { |
510 | public : | |
208fd16c SC |
511 | wxGetter( const wxString name ) { m_name = name ; } |
512 | virtual void Get( const wxObject *object , wxxVariant& result) const = 0; | |
513 | const wxString& GetName() const { return m_name ; } | |
2d51f067 | 514 | private : |
208fd16c | 515 | wxString m_name ; |
2d51f067 SC |
516 | } ; |
517 | ||
208fd16c | 518 | class wxCollectionGetter |
a095505c | 519 | { |
208fd16c SC |
520 | public : |
521 | wxCollectionGetter( const wxString name ) { m_name = name ; } | |
522 | virtual void Get( const wxObject *object , wxxVariantArray& result) const = 0; | |
523 | const wxString& GetName() const { return m_name ; } | |
524 | private : | |
525 | wxString m_name ; | |
526 | } ; | |
fa08490f | 527 | |
208fd16c | 528 | template<typename coll_t> void wxCollectionToVariantArray( const coll_t& coll , wxxVariantArray& result ) ; |
a095505c | 529 | |
208fd16c SC |
530 | class wxAdder |
531 | { | |
532 | public : | |
533 | wxAdder( const wxString name ) { m_name = name ; } | |
534 | virtual void Add( wxObject *object, const wxxVariant &variantValue ) const= 0; | |
535 | const wxString& GetName() const { return m_name ; } | |
536 | private : | |
537 | wxString m_name ; | |
538 | } ; | |
a095505c | 539 | |
517fb871 | 540 | |
208fd16c SC |
541 | template <class Klass, typename valueType, typename retType> void wxSetterFunc( wxObject *object , const wxxVariant &variantValue , retType(Klass::*setter)( valueType ) ) |
542 | { | |
543 | Klass *obj = dynamic_cast<Klass*>(object); | |
544 | if ( variantValue.HasData<valueType>() ) | |
545 | (obj->*(setter))(variantValue.Get<valueType>()) ; | |
546 | else | |
547 | (obj->*(setter))(*variantValue.Get<valueType*>()) ; | |
548 | } | |
a095505c | 549 | |
208fd16c SC |
550 | template <class Klass, typename valueType, typename retType> void wxSetterFunc( wxObject *object , const wxxVariant &variantValue , retType(Klass::*setter)( valueType& ) ) |
551 | { | |
552 | Klass *obj = dynamic_cast<Klass*>(object); | |
553 | if ( variantValue.HasData<valueType>() ) | |
554 | (obj->*(setter))(variantValue.Get<valueType>()) ; | |
555 | else | |
556 | (obj->*(setter))(*variantValue.Get<valueType*>()) ; | |
557 | } | |
a095505c | 558 | |
208fd16c SC |
559 | template <class Klass, typename valueType, typename retType> void wxSetterFunc( wxObject *object , const wxxVariant &variantValue , retType(Klass::*setter)( const valueType& ) ) |
560 | { | |
561 | Klass *obj = dynamic_cast<Klass*>(object); | |
562 | if ( variantValue.HasData<valueType>() ) | |
563 | (obj->*(setter))(variantValue.Get<valueType>()) ; | |
564 | else | |
565 | (obj->*(setter))(*variantValue.Get<valueType*>()) ; | |
566 | } | |
a095505c | 567 | |
208fd16c | 568 | template <class Klass, typename valueType, typename retType> void wxAdderFunc( wxObject *object , const wxxVariant &variantValue , retType(Klass::*adder)( valueType ) ) |
ab6e4913 | 569 | { |
208fd16c SC |
570 | Klass *obj = dynamic_cast<Klass*>(object); |
571 | (obj->*(adder))(variantValue.Get<valueType>()) ; | |
572 | } | |
ab6e4913 | 573 | |
208fd16c SC |
574 | template <class Klass, typename valueType, typename retType> void wxAdderFunc( wxObject *object , const wxxVariant &variantValue , retType(Klass::*adder)( valueType& ) ) |
575 | { | |
576 | Klass *obj = dynamic_cast<Klass*>(object); | |
577 | (obj->*(adder))(variantValue.Get<valueType>()) ; | |
578 | } | |
ab6e4913 | 579 | |
208fd16c SC |
580 | template <class Klass, typename valueType, typename retType> void wxAdderFunc( wxObject *object , const wxxVariant &variantValue , retType(Klass::*adder)( const valueType& ) ) |
581 | { | |
582 | Klass *obj = dynamic_cast<Klass*>(object); | |
583 | (obj->*(adder))(variantValue.Get<valueType>()) ; | |
584 | } | |
16a45a23 | 585 | |
208fd16c SC |
586 | /* |
587 | template <class Klass, typename valueType> void wxxGetterFunc( const wxObject *object , wxxVariant &result, valueType& (Klass::*getter)() const ) | |
588 | { | |
589 | const Klass *obj = dynamic_cast<const Klass*>(object); | |
590 | result = wxxVariant((obj->*(getter))()) ; | |
591 | } | |
592 | */ | |
ab6e4913 | 593 | |
208fd16c SC |
594 | template <class Klass, typename valueType> void wxGetterFunc( const wxObject *object , wxxVariant &result, valueType(Klass::*getter)() const ) |
595 | { | |
596 | const Klass *obj = dynamic_cast<const Klass*>(object); | |
597 | result = wxxVariant((obj->*(getter))()) ; | |
598 | } | |
ab6e4913 | 599 | |
208fd16c SC |
600 | template <class Klass, typename valueType> void wxGetterFunc( const wxObject *object , wxxVariant &result, const valueType&(Klass::*getter)() const) |
601 | { | |
602 | const Klass *obj = dynamic_cast<const Klass*>(object); | |
603 | result = wxxVariant((obj->*(getter))()) ; | |
604 | } | |
ab6e4913 | 605 | |
208fd16c SC |
606 | template <class Klass, typename valueType> void wxCollectionGetterFunc( const wxObject *object , wxxVariantArray &result, valueType& (Klass::*getter)() const ) |
607 | { | |
608 | const Klass *obj = dynamic_cast<const Klass*>(object); | |
609 | wxCollectionToVariantArray( (obj->*(getter))() , result ) ; | |
610 | } | |
ab6e4913 | 611 | |
208fd16c SC |
612 | template <class Klass, typename valueType> void wxCollectionGetterFunc( const wxObject *object , wxxVariantArray &result, valueType(Klass::*getter)() const ) |
613 | { | |
614 | const Klass *obj = dynamic_cast<const Klass*>(object); | |
615 | wxCollectionToVariantArray( (obj->*(getter))() , result ) ; | |
616 | } | |
ab6e4913 | 617 | |
208fd16c SC |
618 | template <class Klass, typename valueType> void wxCollectionGetterFunc( const wxObject *object , wxxVariantArray &result, const valueType&(Klass::*getter)() const) |
619 | { | |
620 | const Klass *obj = dynamic_cast<const Klass*>(object); | |
621 | wxCollectionToVariantArray( (obj->*(getter))() , result ) ; | |
622 | } | |
ab6e4913 | 623 | |
208fd16c SC |
624 | #define WX_SETTER( property , settermethod ) \ |
625 | class wxSetter##property : public wxSetter \ | |
626 | { \ | |
627 | public: \ | |
628 | wxSetter##property() : wxSetter( #settermethod ) {} \ | |
629 | void Set( wxObject *object, const wxxVariant &variantValue ) const \ | |
630 | { \ | |
631 | wxSetterFunc( object , variantValue , &class_t::settermethod ) ; \ | |
632 | } \ | |
633 | } ; | |
634 | ||
635 | #define WX_GETTER( property , gettermethod ) \ | |
636 | class wxGetter##property : public wxGetter \ | |
637 | { \ | |
638 | public : \ | |
639 | wxGetter##property() : wxGetter( #gettermethod ) {} \ | |
640 | void Get( const wxObject *object , wxxVariant &result) const \ | |
641 | { \ | |
642 | wxGetterFunc( object , result , &class_t::gettermethod ) ; \ | |
643 | } \ | |
644 | } ; | |
645 | ||
646 | #define WX_ADDER( property , addermethod ) \ | |
647 | class wxAdder##property : public wxAdder \ | |
648 | { \ | |
649 | public: \ | |
650 | wxAdder##property() : wxAdder( #addermethod ) {} \ | |
651 | void Add( wxObject *object, const wxxVariant &variantValue ) const \ | |
652 | { \ | |
653 | wxAdderFunc( object , variantValue , &class_t::addermethod ) ; \ | |
654 | } \ | |
655 | } ; | |
656 | ||
657 | #define WX_COLLECTION_GETTER( property , gettermethod ) \ | |
658 | class wxCollectionGetter##property : public wxCollectionGetter \ | |
659 | { \ | |
660 | public : \ | |
661 | wxCollectionGetter##property() : wxCollectionGetter( #gettermethod ) {} \ | |
662 | void Get( const wxObject *object , wxxVariantArray &result) const \ | |
663 | { \ | |
664 | wxCollectionGetterFunc( object , result , &class_t::gettermethod ) ; \ | |
665 | } \ | |
666 | } ; | |
ab6e4913 | 667 | |
208fd16c SC |
668 | class WXDLLIMPEXP_BASE wxPropertyAccessor |
669 | { | |
670 | public : | |
671 | wxPropertyAccessor( wxSetter *setter , wxGetter *getter , wxAdder *adder , wxCollectionGetter *collectionGetter ) | |
672 | { m_setter = setter ; m_getter = getter ; m_adder = adder ; m_collectionGetter = collectionGetter ;} | |
ab6e4913 | 673 | |
208fd16c | 674 | virtual ~wxPropertyAccessor() {} |
ab6e4913 | 675 | |
208fd16c SC |
676 | // Setting a simple property (non-collection) |
677 | virtual void SetProperty(wxObject *object, const wxxVariant &value) const | |
678 | { wxASSERT_MSG(m_setter,wxT("SetProperty called w/o valid setter") ) ; m_setter->Set( object , value ) ;} | |
16a45a23 | 679 | |
208fd16c SC |
680 | // Getting a simple property (non-collection) |
681 | virtual void GetProperty(const wxObject *object, wxxVariant &result) const | |
682 | { wxASSERT_MSG(m_getter,wxT("GetProperty called w/o valid getter") ) ; return m_getter->Get( object , result ) ;} | |
ab6e4913 | 683 | |
208fd16c SC |
684 | // Adding an element to a collection property |
685 | virtual void AddToPropertyCollection(wxObject *object, const wxxVariant &value) const | |
686 | { wxASSERT_MSG(m_adder,wxT("AddToPropertyCollection called w/o valid adder") ) ; m_adder->Add( object , value ) ;} | |
ab6e4913 | 687 | |
208fd16c SC |
688 | // Getting a collection property |
689 | virtual void GetPropertyCollection( const wxObject *obj, wxxVariantArray &result) const | |
690 | { wxASSERT_MSG(m_collectionGetter,wxT("GetPropertyCollection called w/o valid collection getter") ) ; return m_collectionGetter->Get( obj , result) ;} | |
691 | ||
692 | virtual bool HasSetter() const { return m_setter != NULL ; } | |
693 | virtual bool HasCollectionGetter() const { return m_collectionGetter != NULL ; } | |
694 | virtual bool HasGetter() const { return m_getter != NULL ; } | |
695 | virtual bool HasAdder() const { return m_adder != NULL ; } | |
696 | ||
697 | virtual const wxString& GetCollectionGetterName() const | |
698 | { return m_collectionGetter->GetName() ; } | |
699 | virtual const wxString& GetGetterName() const | |
700 | { return m_getter->GetName() ; } | |
701 | virtual const wxString& GetSetterName() const | |
702 | { return m_setter->GetName() ; } | |
703 | virtual const wxString& GetAdderName() const | |
704 | { return m_adder->GetName() ; } | |
705 | /* | |
706 | virtual wxxVariant ReadValue( const wxString &value ) const ; | |
707 | virtual void WriteValue( wxString& value , const wxObject *o ) const ; | |
708 | */ | |
709 | protected : | |
710 | wxSetter *m_setter ; | |
711 | wxAdder *m_adder ; | |
712 | wxGetter *m_getter ; | |
713 | wxCollectionGetter* m_collectionGetter ; | |
714 | }; | |
ab6e4913 | 715 | |
208fd16c SC |
716 | class WXDLLIMPEXP_BASE wxGenericPropertyAccessor : public wxPropertyAccessor |
717 | { | |
718 | public : | |
719 | wxGenericPropertyAccessor( const wxString &propName ) ; | |
720 | ~wxGenericPropertyAccessor() ; | |
ab6e4913 | 721 | |
208fd16c SC |
722 | virtual bool HasSetter() const { return true ; } |
723 | virtual bool HasGetter() const { return true ; } | |
724 | virtual bool HasAdder() const { return false ; } | |
725 | virtual bool HasCollectionGetter() const { return false ; } | |
ab6e4913 | 726 | |
208fd16c SC |
727 | virtual const wxString& GetGetterName() const |
728 | { return m_getterName ; } | |
729 | virtual const wxString& GetSetterName() const | |
730 | { return m_setterName ; } | |
ab6e4913 | 731 | |
208fd16c SC |
732 | virtual void SetProperty(wxObject *object, const wxxVariant &value) const ; |
733 | virtual void GetProperty(const wxObject *object, wxxVariant &value) const ; | |
734 | ||
735 | // Adding an element to a collection property | |
736 | virtual void AddToPropertyCollection(wxObject *object, const wxxVariant &value) const | |
737 | { wxASSERT_MSG(0,wxT("AddToPropertyCollection called on a generic accessor") ) ;} | |
738 | ||
739 | // Getting a collection property | |
740 | virtual void GetPropertyCollection( const wxObject *obj, wxxVariantArray &result) const | |
741 | { wxASSERT_MSG(0,wxT("GetPropertyCollection called on a generic accessor") ) ;} | |
742 | private : | |
743 | struct wxGenericPropertyAccessorInternal ; | |
744 | wxGenericPropertyAccessorInternal* m_data ; | |
745 | wxString m_propertyName ; | |
746 | wxString m_setterName ; | |
747 | wxString m_getterName ; | |
748 | } ; | |
ab6e4913 | 749 | |
a095505c SC |
750 | class WXDLLIMPEXP_BASE wxPropertyInfo |
751 | { | |
752 | public : | |
ab6e4913 SC |
753 | wxPropertyInfo( wxPropertyInfo* &iter , const wxChar *name , const wxTypeInfo* typeInfo , wxPropertyAccessor *accessor , wxxVariant dv ) : |
754 | m_name( name ) , m_typeInfo( typeInfo ) , m_accessor( accessor ) , m_defaultValue( dv ) , m_collectionElementTypeInfo(NULL) | |
fa08490f | 755 | { |
ab6e4913 SC |
756 | Insert(iter) ; |
757 | } | |
fa08490f | 758 | |
ab6e4913 SC |
759 | wxPropertyInfo( wxPropertyInfo* &iter , const wxChar *name , const wxTypeInfo* collTypeInfo , const wxTypeInfo* elemTypeInfo , wxPropertyAccessor *accessor ) : |
760 | m_name( name ) , m_typeInfo( collTypeInfo ) , m_accessor( accessor ) , m_collectionElementTypeInfo(elemTypeInfo) | |
761 | { | |
762 | Insert(iter) ; | |
fa08490f | 763 | } |
ab6e4913 | 764 | |
fa08490f SC |
765 | // return the name of this property |
766 | const wxChar * GetName() const { return m_name ; } | |
767 | ||
ab6e4913 SC |
768 | // return the element type info of this property (for collections, otherwise NULL) |
769 | const wxTypeInfo * GetCollectionElementTypeInfo() const { return m_collectionElementTypeInfo ; } | |
fa08490f | 770 | |
ab6e4913 | 771 | // return the type info of this property |
fa08490f SC |
772 | const wxTypeInfo * GetTypeInfo() const { return m_typeInfo ; } |
773 | ||
774 | // return the accessor for this property | |
775 | wxPropertyAccessor* GetAccessor() const { return m_accessor ; } | |
776 | ||
777 | // returns NULL if this is the last property of this class | |
778 | wxPropertyInfo* GetNext() const { return m_next ; } | |
779 | ||
780 | // returns the default value of this property, its kind may be wxT_VOID if it is not valid | |
781 | wxxVariant GetDefaultValue() const { return m_defaultValue ; } | |
4393b50c | 782 | private : |
ab6e4913 SC |
783 | void Insert(wxPropertyInfo* &iter) |
784 | { | |
785 | m_next = NULL ; | |
786 | if ( iter == NULL ) | |
787 | iter = this ; | |
788 | else | |
789 | { | |
790 | wxPropertyInfo* i = iter ; | |
791 | while( i->m_next ) | |
792 | i = i->m_next ; | |
793 | ||
794 | i->m_next = this ; | |
795 | } | |
796 | } | |
797 | ||
517fb871 VS |
798 | const wxChar * m_name; |
799 | const wxChar * m_typeName ; | |
800 | const wxTypeInfo* m_typeInfo ; | |
ab6e4913 | 801 | const wxTypeInfo* m_collectionElementTypeInfo ; |
517fb871 | 802 | wxPropertyAccessor* m_accessor ; |
4393b50c | 803 | wxxVariant m_defaultValue; |
517fb871 VS |
804 | // string representation of the default value |
805 | // to be assigned by the designer to the property | |
806 | // when the component is dropped on the container. | |
807 | wxPropertyInfo* m_next ; | |
a095505c SC |
808 | }; |
809 | ||
810 | #define WX_BEGIN_PROPERTIES_TABLE(theClass) \ | |
2d51f067 | 811 | wxPropertyInfo *theClass::GetPropertiesStatic() \ |
a095505c SC |
812 | { \ |
813 | typedef theClass class_t; \ | |
517fb871 | 814 | static wxPropertyInfo* first = NULL ; |
a095505c SC |
815 | |
816 | #define WX_END_PROPERTIES_TABLE() \ | |
517fb871 | 817 | return first ; } |
a095505c | 818 | |
438edbc0 | 819 | |
438edbc0 | 820 | |
a095505c | 821 | #define WX_PROPERTY( name , type , setter , getter ,defaultValue ) \ |
208fd16c SC |
822 | WX_SETTER( name , setter ) \ |
823 | static wxSetter##name _setter##name ; \ | |
824 | WX_GETTER( name , getter ) \ | |
825 | static wxGetter##name _getter##name ; \ | |
826 | static wxPropertyAccessor _accessor##name( &_setter##name , &_getter##name , NULL , NULL ) ; \ | |
ab6e4913 | 827 | static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ; |
4393b50c | 828 | |
16a45a23 | 829 | #define WX_READONLY_PROPERTY( name , type , getter ,defaultValue ) \ |
208fd16c SC |
830 | WX_GETTER( name , getter ) \ |
831 | static wxGetter##name _getter##name ; \ | |
832 | static wxPropertyAccessor _accessor##name( NULL , &_getter##name , NULL , NULL ) ; \ | |
ab6e4913 SC |
833 | static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ; |
834 | ||
835 | #define WX_PROPERTY_COLLECTION( name , colltype , addelemtype , adder , getter ) \ | |
208fd16c SC |
836 | WX_ADDER( name , adder ) \ |
837 | static wxAdder##name _adder##name ; \ | |
838 | WX_COLLECTION_GETTER( name , getter ) \ | |
839 | static wxCollectionGetter##name _collectionGetter##name ; \ | |
840 | static wxPropertyAccessor _accessor##name( NULL , NULL ,&_adder##name , &_collectionGetter##name ) ; \ | |
841 | static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name ) ; | |
438edbc0 | 842 | |
16a45a23 | 843 | #define WX_READONLY_PROPERTY_COLLECTION( name , colltype , addelemtype , getter ) \ |
208fd16c SC |
844 | WX_COLLECTION_GETTER( name , getter ) \ |
845 | static wxCollectionGetter##name _collectionGetter##name ; \ | |
846 | static wxPropertyAccessor _accessor##name( NULL , NULL , NULL , &_collectionGetter##name ) ; \ | |
847 | static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name ) ; | |
848 | /* | |
849 | #define WX_PROPERTY_COLLECTION( name , colltype , addelemtype , adder , getter ) \ | |
850 | static wxPropertyCollectionAccessorT<class_t , colltype , addelemtype > _accessor##name( &adder , &getter , #adder , #getter ) ; \ | |
16a45a23 SC |
851 | static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name ) ; |
852 | ||
208fd16c SC |
853 | #define WX_READONLY_PROPERTY_COLLECTION( name , colltype , addelemtype , getter ) \ |
854 | static wxPropertyCollectionAccessorT<class_t , colltype , addelemtype > _accessor##name( &getter , #getter ) ; \ | |
855 | static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name ) ; | |
856 | */ | |
16a45a23 | 857 | |
16a45a23 SC |
858 | |
859 | ||
a095505c | 860 | #define WX_DELEGATE( name , eventType , eventClass ) \ |
517fb871 | 861 | static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \ |
ab6e4913 | 862 | static wxPropertyInfo _propertyInfo##name( first , #name , &_typeInfo##name , NULL , wxxVariant() ) ; \ |
a095505c SC |
863 | |
864 | // ---------------------------------------------------------------------------- | |
865 | // Handler Info | |
866 | // | |
867 | // this is describing an event sink | |
868 | // ---------------------------------------------------------------------------- | |
869 | ||
870 | class wxHandlerInfo | |
871 | { | |
872 | public : | |
fa08490f SC |
873 | wxHandlerInfo( wxHandlerInfo* &iter , const wxChar *name , wxObjectEventFunction address , const wxClassInfo* eventClassInfo ) : |
874 | m_name( name ) , m_eventClassInfo( eventClassInfo ) , m_eventFunction( address ) | |
875 | { | |
876 | m_next = NULL ; | |
877 | if ( iter == NULL ) | |
878 | iter = this ; | |
879 | else | |
880 | { | |
881 | wxHandlerInfo* i = iter ; | |
882 | while( i->m_next ) | |
883 | i = i->m_next ; | |
884 | ||
885 | i->m_next = this ; | |
886 | } | |
887 | } | |
888 | ||
889 | // get the name of the handler method | |
890 | const wxChar * GetName() const { return m_name ; } | |
891 | ||
892 | // return the class info of the event | |
893 | const wxClassInfo * GetEventClassInfo() const { return m_eventClassInfo ; } | |
894 | ||
895 | // get the handler function pointer | |
896 | wxObjectEventFunction GetEventFunction() const { return m_eventFunction ; } | |
897 | ||
898 | // returns NULL if this is the last handler of this class | |
899 | wxHandlerInfo* GetNext() const { return m_next ; } | |
4393b50c | 900 | private : |
517fb871 VS |
901 | wxObjectEventFunction m_eventFunction ; |
902 | const wxChar * m_name; | |
903 | const wxClassInfo* m_eventClassInfo ; | |
904 | wxHandlerInfo* m_next ; | |
a095505c SC |
905 | }; |
906 | ||
907 | #define WX_HANDLER(name,eventClassType) \ | |
517fb871 | 908 | static wxHandlerInfo _handlerInfo##name( first , #name , (wxObjectEventFunction) (wxEventFunction) &name , CLASSINFO( eventClassType ) ) ; |
a095505c SC |
909 | |
910 | #define WX_BEGIN_HANDLERS_TABLE(theClass) \ | |
2d51f067 | 911 | wxHandlerInfo *theClass::GetHandlersStatic() \ |
a095505c SC |
912 | { \ |
913 | typedef theClass class_t; \ | |
517fb871 | 914 | static wxHandlerInfo* first = NULL ; |
a095505c SC |
915 | |
916 | #define WX_END_HANDLERS_TABLE() \ | |
517fb871 | 917 | return first ; } |
a095505c SC |
918 | |
919 | // ---------------------------------------------------------------------------- | |
920 | // Constructor Bridges | |
921 | // | |
922 | // allow to set up constructors with params during runtime | |
923 | // ---------------------------------------------------------------------------- | |
924 | ||
925 | class WXDLLIMPEXP_BASE wxConstructorBridge | |
926 | { | |
927 | public : | |
928 | virtual void Create(wxObject *o, wxxVariant *args) = 0; | |
929 | }; | |
930 | ||
931 | // Creator Bridges for all Numbers of Params | |
932 | ||
933 | // no params | |
934 | ||
935 | template<typename Class> | |
936 | struct wxConstructorBridge_0 : public wxConstructorBridge | |
937 | { | |
938 | void Create(wxObject *o, wxxVariant *) | |
939 | { | |
940 | Class *obj = dynamic_cast<Class*>(o); | |
941 | obj->Create(); | |
942 | } | |
943 | }; | |
944 | ||
945 | struct wxConstructorBridge_Dummy : public wxConstructorBridge | |
946 | { | |
947 | void Create(wxObject *, wxxVariant *) | |
948 | { | |
949 | } | |
950 | } ; | |
951 | ||
952 | #define WX_CONSTRUCTOR_0(klass) \ | |
517fb871 VS |
953 | wxConstructorBridge_0<klass> constructor##klass ; \ |
954 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
955 | const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \ | |
956 | const int klass::sm_constructorPropertiesCount##klass = 0 ; | |
a095505c SC |
957 | |
958 | #define WX_CONSTRUCTOR_DUMMY(klass) \ | |
517fb871 VS |
959 | wxConstructorBridge_Dummy constructor##klass ; \ |
960 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
961 | const wxChar *klass::sm_constructorProperties##klass[] = { NULL } ; \ | |
962 | const int klass::sm_constructorPropertiesCount##klass = 0 ; | |
a095505c SC |
963 | |
964 | // 1 param | |
965 | ||
966 | template<typename Class, typename T0> | |
967 | struct wxConstructorBridge_1 : public wxConstructorBridge | |
968 | { | |
969 | void Create(wxObject *o, wxxVariant *args) | |
970 | { | |
971 | Class *obj = dynamic_cast<Class*>(o); | |
972 | obj->Create( | |
973 | args[0].Get<T0>() | |
974 | ); | |
975 | } | |
976 | }; | |
977 | ||
978 | #define WX_CONSTRUCTOR_1(klass,t0,v0) \ | |
517fb871 VS |
979 | wxConstructorBridge_1<klass,t0> constructor##klass ; \ |
980 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
981 | const wxChar *klass::sm_constructorProperties##klass[] = { #v0 } ; \ | |
982 | const int klass::sm_constructorPropertiesCount##klass = 1 ; | |
a095505c SC |
983 | |
984 | // 2 params | |
985 | ||
986 | template<typename Class, | |
987 | typename T0, typename T1> | |
988 | struct wxConstructorBridge_2 : public wxConstructorBridge | |
989 | { | |
fbbdc52c | 990 | void Create(wxObject *o, wxxVariant *args) |
a095505c SC |
991 | { |
992 | Class *obj = dynamic_cast<Class*>(o); | |
993 | obj->Create( | |
994 | args[0].Get<T0>() , | |
4393b50c | 995 | args[1].Get<T1>() |
a095505c SC |
996 | ); |
997 | } | |
998 | }; | |
999 | ||
1000 | #define WX_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \ | |
517fb871 VS |
1001 | wxConstructorBridge_2<klass,t0,t1> constructor##klass ; \ |
1002 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
1003 | const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 } ; \ | |
1004 | const int klass::sm_constructorPropertiesCount##klass = 2; | |
a095505c SC |
1005 | |
1006 | // 3 params | |
1007 | ||
1008 | template<typename Class, | |
1009 | typename T0, typename T1, typename T2> | |
1010 | struct wxConstructorBridge_3 : public wxConstructorBridge | |
1011 | { | |
fbbdc52c | 1012 | void Create(wxObject *o, wxxVariant *args) |
a095505c SC |
1013 | { |
1014 | Class *obj = dynamic_cast<Class*>(o); | |
1015 | obj->Create( | |
1016 | args[0].Get<T0>() , | |
1017 | args[1].Get<T1>() , | |
4393b50c | 1018 | args[2].Get<T2>() |
a095505c SC |
1019 | ); |
1020 | } | |
1021 | }; | |
1022 | ||
1023 | #define WX_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \ | |
517fb871 VS |
1024 | wxConstructorBridge_3<klass,t0,t1,t2> constructor##klass ; \ |
1025 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
1026 | const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 } ; \ | |
1027 | const int klass::sm_constructorPropertiesCount##klass = 3 ; | |
a095505c SC |
1028 | |
1029 | // 4 params | |
1030 | ||
1031 | template<typename Class, | |
1032 | typename T0, typename T1, typename T2, typename T3> | |
1033 | struct wxConstructorBridge_4 : public wxConstructorBridge | |
1034 | { | |
fbbdc52c | 1035 | void Create(wxObject *o, wxxVariant *args) |
a095505c SC |
1036 | { |
1037 | Class *obj = dynamic_cast<Class*>(o); | |
1038 | obj->Create( | |
1039 | args[0].Get<T0>() , | |
1040 | args[1].Get<T1>() , | |
1041 | args[2].Get<T2>() , | |
4393b50c | 1042 | args[3].Get<T3>() |
a095505c SC |
1043 | ); |
1044 | } | |
1045 | }; | |
1046 | ||
1047 | #define WX_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \ | |
517fb871 VS |
1048 | wxConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass ; \ |
1049 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
1050 | const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 } ; \ | |
1051 | const int klass::sm_constructorPropertiesCount##klass = 4 ; | |
fbbdc52c SC |
1052 | |
1053 | // 5 params | |
1054 | ||
1055 | template<typename Class, | |
1056 | typename T0, typename T1, typename T2, typename T3, typename T4> | |
1057 | struct wxConstructorBridge_5 : public wxConstructorBridge | |
1058 | { | |
1059 | void Create(wxObject *o, wxxVariant *args) | |
1060 | { | |
1061 | Class *obj = dynamic_cast<Class*>(o); | |
1062 | obj->Create( | |
1063 | args[0].Get<T0>() , | |
1064 | args[1].Get<T1>() , | |
1065 | args[2].Get<T2>() , | |
1066 | args[3].Get<T3>() , | |
4393b50c | 1067 | args[4].Get<T4>() |
fbbdc52c SC |
1068 | ); |
1069 | } | |
1070 | }; | |
1071 | ||
1072 | #define WX_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \ | |
fa08490f SC |
1073 | wxConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass ; \ |
1074 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
1075 | const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 } ; \ | |
1076 | const int klass::sm_constructorPropertiesCount##klass = 5; | |
1077 | ||
1078 | // 6 params | |
1079 | ||
1080 | template<typename Class, | |
1081 | typename T0, typename T1, typename T2, typename T3, typename T4, typename T5> | |
1082 | struct wxConstructorBridge_6 : public wxConstructorBridge | |
1083 | { | |
1084 | void Create(wxObject *o, wxxVariant *args) | |
1085 | { | |
1086 | Class *obj = dynamic_cast<Class*>(o); | |
1087 | obj->Create( | |
1088 | args[0].Get<T0>() , | |
1089 | args[1].Get<T1>() , | |
1090 | args[2].Get<T2>() , | |
1091 | args[3].Get<T3>() , | |
1092 | args[4].Get<T4>() , | |
1093 | args[5].Get<T5>() | |
1094 | ); | |
1095 | } | |
1096 | }; | |
1097 | ||
1098 | #define WX_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \ | |
1099 | wxConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass ; \ | |
1100 | wxConstructorBridge* klass::sm_constructor##klass = &constructor##klass ; \ | |
1101 | const wxChar *klass::sm_constructorProperties##klass[] = { #v0 , #v1 , #v2 , #v3 , #v4 , #v5 } ; \ | |
1102 | const int klass::sm_constructorPropertiesCount##klass = 6; | |
1103 | ||
a095505c SC |
1104 | |
1105 | // ---------------------------------------------------------------------------- | |
1106 | // wxClassInfo | |
1107 | // ---------------------------------------------------------------------------- | |
1108 | ||
1109 | typedef wxObject *(*wxObjectConstructorFn)(void); | |
fa08490f | 1110 | typedef wxObject* (*wxVariantToObjectConverter)( wxxVariant &data ) ; |
a095505c SC |
1111 | typedef wxxVariant (*wxObjectToVariantConverter)( wxObject* ) ; |
1112 | ||
1113 | class WXDLLIMPEXP_BASE wxClassInfo | |
1114 | { | |
1115 | public: | |
1116 | wxClassInfo(const wxClassInfo **_Parents, | |
517fb871 VS |
1117 | const wxChar *_UnitName, |
1118 | const wxChar *_ClassName, | |
a095505c SC |
1119 | int size, |
1120 | wxObjectConstructorFn ctor , | |
2d51f067 SC |
1121 | wxPropertyInfo *_Props , |
1122 | wxHandlerInfo *_Handlers , | |
fa08490f SC |
1123 | wxConstructorBridge* _Constructor , |
1124 | const wxChar ** _ConstructorProperties , | |
1125 | const int _ConstructorPropertiesCount , | |
1126 | wxVariantToObjectConverter _PtrConverter1 , | |
1127 | wxVariantToObjectConverter _Converter2 , | |
1128 | wxObjectToVariantConverter _Converter3 | |
1129 | ) : m_parents(_Parents) , m_unitName(_UnitName) ,m_className(_ClassName), | |
1130 | m_objectSize(size), m_objectConstructor(ctor) , m_firstProperty(_Props ) , m_firstHandler(_Handlers ) , m_constructor( _Constructor ) , | |
1131 | m_constructorProperties(_ConstructorProperties) , m_constructorPropertiesCount(_ConstructorPropertiesCount), | |
1132 | m_variantOfPtrToObjectConverter( _PtrConverter1 ) , m_variantToObjectConverter( _Converter2 ) , m_objectToVariantConverter( _Converter3 ) , m_next(sm_first) | |
1133 | { | |
1134 | sm_first = this; | |
aa8d7c2f | 1135 | Register() ; |
fa08490f | 1136 | } |
a095505c | 1137 | |
2d51f067 SC |
1138 | wxClassInfo(const wxChar *_UnitName, const wxChar *_ClassName, const wxClassInfo **_Parents) : m_parents(_Parents) , m_unitName(_UnitName) ,m_className(_ClassName), |
1139 | m_objectSize(0), m_objectConstructor(NULL) , m_firstProperty(NULL ) , m_firstHandler(NULL ) , m_constructor( NULL ) , | |
1140 | m_constructorProperties(NULL) , m_constructorPropertiesCount(NULL), | |
1141 | m_variantOfPtrToObjectConverter( NULL ) , m_variantToObjectConverter( NULL ) , m_objectToVariantConverter( NULL ) , m_next(sm_first) | |
1142 | { | |
1143 | sm_first = this; | |
1144 | Register() ; | |
1145 | } | |
1146 | ||
aeec2045 | 1147 | virtual ~wxClassInfo() ; |
a095505c | 1148 | |
ab6e4913 SC |
1149 | // allocates an instance of this class, this object does not have to be initialized or fully constructed |
1150 | // as this call will be followed by a call to Create | |
1151 | virtual wxObject *AllocateObject() const { return m_objectConstructor ? (*m_objectConstructor)() : 0; } | |
1152 | ||
1153 | // 'old naming' for AllocateObject staying here for backward compatibility | |
1154 | wxObject *CreateObject() const { return AllocateObject() ; } | |
a095505c SC |
1155 | |
1156 | const wxChar *GetClassName() const { return m_className; } | |
1157 | const wxClassInfo **GetParents() const { return m_parents; } | |
1158 | int GetSize() const { return m_objectSize; } | |
1159 | ||
1160 | wxObjectConstructorFn GetConstructor() const { return m_objectConstructor; } | |
1161 | static const wxClassInfo *GetFirst() { return sm_first; } | |
1162 | const wxClassInfo *GetNext() const { return m_next; } | |
1163 | static wxClassInfo *FindClass(const wxChar *className); | |
1164 | ||
1165 | // Climb upwards through inheritance hierarchy. | |
1166 | // Dual inheritance is catered for. | |
1167 | ||
1168 | bool IsKindOf(const wxClassInfo *info) const | |
1169 | { | |
517fb871 VS |
1170 | if ( info != 0 ) |
1171 | { | |
1172 | if ( info == this ) | |
1173 | return true ; | |
1174 | ||
1175 | for ( int i = 0 ; m_parents[i] ; ++ i ) | |
1176 | { | |
1177 | if ( m_parents[i]->IsKindOf( info ) ) | |
1178 | return true ; | |
1179 | } | |
1180 | } | |
1181 | return false ; | |
a095505c SC |
1182 | } |
1183 | ||
aa8d7c2f | 1184 | #ifdef WXWIN_COMPATIBILITY_2_4 |
a095505c | 1185 | // Initializes parent pointers and hash table for fast searching. |
aa8d7c2f | 1186 | wxDEPRECATED( static void InitializeClasses() ); |
a095505c | 1187 | // Cleans up hash table used for fast searching. |
aa8d7c2f SC |
1188 | wxDEPRECATED( static void CleanUpClasses() ); |
1189 | #endif | |
1190 | static void CleanUp(); | |
75890a3f | 1191 | |
517fb871 VS |
1192 | // returns the first property |
1193 | const wxPropertyInfo* GetFirstProperty() const { return m_firstProperty ; } | |
a095505c | 1194 | |
517fb871 VS |
1195 | // returns the first handler |
1196 | const wxHandlerInfo* GetFirstHandler() const { return m_firstHandler ; } | |
a095505c | 1197 | |
ab6e4913 SC |
1198 | // Call the Create upon an instance of the class, in the end the object is fully |
1199 | // initialized | |
fa08490f SC |
1200 | virtual void Create (wxObject *object, int ParamCount, wxxVariant *Params) const |
1201 | { | |
1202 | wxASSERT_MSG( ParamCount == m_constructorPropertiesCount , wxT("Illegal Parameter Count for Create Method")) ; | |
1203 | m_constructor->Create( object , Params ) ; | |
1204 | } | |
a095505c | 1205 | |
517fb871 VS |
1206 | // get number of parameters for constructor |
1207 | virtual int GetCreateParamCount() const { return m_constructorPropertiesCount; } | |
a095505c | 1208 | |
ab6e4913 SC |
1209 | // get n-th constructor parameter |
1210 | virtual const wxChar* GetCreateParamName(int n) const { return m_constructorProperties[n] ; } | |
a095505c | 1211 | |
ab6e4913 SC |
1212 | // Runtime access to objects for simple properties (get/set) by property name, and variant data |
1213 | virtual void SetProperty (wxObject *object, const wxChar *propertyName, const wxxVariant &value) const ; | |
1214 | virtual wxxVariant GetProperty (wxObject *object, const wxChar *propertyName) const; | |
1215 | ||
1216 | // Runtime access to objects for collection properties by property name | |
1217 | virtual wxxVariantArray GetPropertyCollection(wxObject *object, const wxChar *propertyName) const ; | |
16a45a23 | 1218 | virtual void AddToPropertyCollection(wxObject *object, const wxChar *propertyName , const wxxVariant& value) const ; |
a095505c | 1219 | |
fa08490f | 1220 | // we must be able to cast variants to wxObject pointers, templates seem not to be suitable |
f0b7eadf | 1221 | wxObject* VariantToInstance( wxxVariant &data ) const |
fa08490f | 1222 | { if ( data.GetTypeInfo()->GetKind() == wxT_OBJECT ) |
f0b7eadf | 1223 | return m_variantToObjectConverter( data ) ; |
fa08490f SC |
1224 | else |
1225 | return m_variantOfPtrToObjectConverter( data ) ; | |
1226 | } | |
1227 | ||
1228 | wxxVariant InstanceToVariant( wxObject *object ) const { return m_objectToVariantConverter( object ) ; } | |
4393b50c | 1229 | |
517fb871 | 1230 | // find property by name |
fbbdc52c SC |
1231 | virtual const wxPropertyInfo *FindPropertyInfo (const wxChar *PropertyName) const ; |
1232 | ||
517fb871 | 1233 | // find handler by name |
fbbdc52c | 1234 | virtual const wxHandlerInfo *FindHandlerInfo (const wxChar *PropertyName) const ; |
a095505c | 1235 | |
2d51f067 SC |
1236 | // find property by name |
1237 | virtual const wxPropertyInfo *FindPropertyInfoInThisClass (const wxChar *PropertyName) const ; | |
1238 | ||
1239 | // find handler by name | |
1240 | virtual const wxHandlerInfo *FindHandlerInfoInThisClass (const wxChar *PropertyName) const ; | |
a095505c SC |
1241 | public: |
1242 | const wxChar *m_className; | |
1243 | int m_objectSize; | |
1244 | wxObjectConstructorFn m_objectConstructor; | |
1245 | ||
1246 | // class info object live in a linked list: | |
1247 | // pointers to its head and the next element in it | |
1248 | ||
1249 | static wxClassInfo *sm_first; | |
1250 | wxClassInfo *m_next; | |
1251 | ||
517fb871 | 1252 | // FIXME: this should be private (currently used directly by way too |
a095505c SC |
1253 | // many clients) |
1254 | static wxHashTable *sm_classTable; | |
1255 | ||
2d51f067 SC |
1256 | protected : |
1257 | wxPropertyInfo * m_firstProperty ; | |
1258 | wxHandlerInfo * m_firstHandler ; | |
a095505c | 1259 | private: |
fa08490f | 1260 | const wxClassInfo** m_parents ; |
fa08490f SC |
1261 | const wxChar* m_unitName; |
1262 | ||
1263 | wxConstructorBridge* m_constructor ; | |
1264 | const wxChar ** m_constructorProperties ; | |
1265 | const int m_constructorPropertiesCount ; | |
1266 | wxVariantToObjectConverter m_variantOfPtrToObjectConverter ; | |
1267 | wxVariantToObjectConverter m_variantToObjectConverter ; | |
1268 | wxObjectToVariantConverter m_objectToVariantConverter ; | |
a095505c | 1269 | |
2d51f067 | 1270 | const wxPropertyAccessor *FindAccessor (const wxChar *propertyName) const ; |
a095505c | 1271 | |
a095505c | 1272 | |
517fb871 | 1273 | // InitializeClasses() helper |
2d51f067 | 1274 | static wxClassInfo *GetBaseByName(const wxChar *name) ; |
75890a3f | 1275 | |
d1d738f1 VS |
1276 | protected: |
1277 | // registers the class | |
1278 | void Register(); | |
1279 | void Unregister(); | |
a095505c SC |
1280 | |
1281 | DECLARE_NO_COPY_CLASS(wxClassInfo) | |
1282 | }; | |
1283 | ||
2d51f067 | 1284 | |
a095505c SC |
1285 | WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name); |
1286 | ||
2d51f067 SC |
1287 | // ---------------------------------------------------------------------------- |
1288 | // wxDynamicObject | |
1289 | // ---------------------------------------------------------------------------- | |
1290 | // | |
1291 | // this object leads to having a pure runtime-instantiation | |
1292 | ||
1293 | class wxDynamicClassInfo : public wxClassInfo | |
1294 | { | |
1295 | public : | |
1296 | wxDynamicClassInfo( const wxChar *_UnitName, const wxChar *_ClassName , const wxClassInfo* superClass ) ; | |
1297 | virtual ~wxDynamicClassInfo() ; | |
1298 | ||
1299 | // constructs a wxDynamicObject with an instance | |
ab6e4913 | 1300 | virtual wxObject *AllocateObject() const ; |
2d51f067 SC |
1301 | |
1302 | // Call the Create method for a class | |
1303 | virtual void Create (wxObject *object, int ParamCount, wxxVariant *Params) const ; | |
1304 | ||
1305 | // get number of parameters for constructor | |
1306 | virtual int GetCreateParamCount() const ; | |
1307 | ||
1308 | // get i-th constructor parameter | |
1309 | virtual const wxChar* GetCreateParamName(int i) const ; | |
1310 | ||
1311 | // Runtime access to objects by property name, and variant data | |
1312 | virtual void SetProperty (wxObject *object, const wxChar *PropertyName, const wxxVariant &Value) const ; | |
1313 | virtual wxxVariant GetProperty (wxObject *object, const wxChar *PropertyName) const ; | |
1314 | ||
1315 | void AddProperty( const wxChar *propertyName , const wxTypeInfo* typeInfo ) ; | |
1316 | void AddHandler( const wxChar *handlerName , wxObjectEventFunction address , const wxClassInfo* eventClassInfo ) ; | |
1317 | } ; | |
1318 | ||
a095505c SC |
1319 | // ---------------------------------------------------------------------------- |
1320 | // Dynamic class macros | |
1321 | // ---------------------------------------------------------------------------- | |
1322 | ||
1323 | #define _DECLARE_DYNAMIC_CLASS(name) \ | |
1324 | public: \ | |
1325 | static wxClassInfo sm_class##name; \ | |
1326 | static const wxClassInfo* sm_classParents##name[] ; \ | |
2d51f067 SC |
1327 | static wxPropertyInfo* GetPropertiesStatic() ; \ |
1328 | static wxHandlerInfo* GetHandlersStatic() ; \ | |
a095505c SC |
1329 | virtual wxClassInfo *GetClassInfo() const \ |
1330 | { return &name::sm_class##name; } | |
1331 | ||
1332 | #define DECLARE_DYNAMIC_CLASS(name) \ | |
f0b7eadf SC |
1333 | static wxConstructorBridge* sm_constructor##name ; \ |
1334 | static const wxChar * sm_constructorProperties##name[] ; \ | |
1335 | static const int sm_constructorPropertiesCount##name ; \ | |
1336 | _DECLARE_DYNAMIC_CLASS(name) | |
a095505c SC |
1337 | |
1338 | #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \ | |
1339 | DECLARE_NO_ASSIGN_CLASS(name) \ | |
1340 | DECLARE_DYNAMIC_CLASS(name) | |
1341 | ||
1342 | #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \ | |
1343 | DECLARE_NO_COPY_CLASS(name) \ | |
1344 | DECLARE_DYNAMIC_CLASS(name) | |
1345 | ||
1346 | #define DECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name) | |
1347 | #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name) | |
1348 | ||
1349 | // ----------------------------------- | |
1350 | // for concrete classes | |
1351 | // ----------------------------------- | |
1352 | ||
1353 | // Single inheritance with one base class | |
1354 | ||
1355 | #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit) \ | |
1356 | wxObject* wxConstructorFor##name() \ | |
1357 | { return new name; } \ | |
1358 | const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \ | |
fa08490f SC |
1359 | wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \ |
1360 | wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \ | |
a095505c SC |
1361 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \ |
1362 | (int) sizeof(name), \ | |
1363 | (wxObjectConstructorFn) wxConstructorFor##name , \ | |
fa08490f SC |
1364 | name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \ |
1365 | name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name); \ | |
1366 | template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\ | |
1367 | template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
dadaeb69 SC |
1368 | template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\ |
1369 | template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
f0b7eadf SC |
1370 | template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1371 | template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1372 | template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \ | |
fa08490f SC |
1373 | template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \ |
1374 | template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } | |
1375 | ||
1376 | #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit) \ | |
1377 | wxObject* wxConstructorFor##name() \ | |
1378 | { return new name; } \ | |
1379 | const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \ | |
1380 | wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return &data.Get<name>() ; } \ | |
1381 | wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \ | |
1382 | wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \ | |
1383 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \ | |
1384 | (int) sizeof(name), \ | |
1385 | (wxObjectConstructorFn) wxConstructorFor##name , \ | |
1386 | name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \ | |
1387 | name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \ | |
1388 | template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\ | |
1389 | template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1390 | template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\ | |
1391 | template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
f0b7eadf SC |
1392 | template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1393 | template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1394 | template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \ | |
fa08490f SC |
1395 | template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \ |
1396 | template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } | |
1397 | ||
1398 | #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \ | |
1399 | _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" ) \ | |
1400 | const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \ | |
1401 | const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \ | |
1402 | WX_CONSTRUCTOR_DUMMY( name ) | |
a095505c SC |
1403 | |
1404 | #define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \ | |
1405 | _IMPLEMENT_DYNAMIC_CLASS( name , basename , "" ) \ | |
2d51f067 SC |
1406 | wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \ |
1407 | wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \ | |
a095505c SC |
1408 | WX_CONSTRUCTOR_DUMMY( name ) |
1409 | ||
1410 | #define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \ | |
1411 | _IMPLEMENT_DYNAMIC_CLASS( name , basename , unit ) | |
1412 | ||
fa08490f SC |
1413 | #define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \ |
1414 | _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit ) | |
1415 | ||
4393b50c | 1416 | // this is for classes that do not derive from wxobject, there are no creators for these |
a095505c SC |
1417 | |
1418 | #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name , unit ) \ | |
1419 | const wxClassInfo* name::sm_classParents##name[] = { NULL } ; \ | |
1420 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \ | |
1421 | (int) sizeof(name), \ | |
1422 | (wxObjectConstructorFn) 0 , \ | |
517fb871 VS |
1423 | name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \ |
1424 | 0 , 0 , 0 ); \ | |
dadaeb69 SC |
1425 | template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1426 | template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
f0b7eadf SC |
1427 | template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1428 | template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1429 | template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \ | |
1430 | template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \ | |
fa08490f | 1431 | template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } |
a095505c SC |
1432 | |
1433 | // this is for subclasses that still do not derive from wxobject | |
1434 | ||
1435 | #define IMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name , basename, unit ) \ | |
1436 | const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \ | |
1437 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \ | |
1438 | (int) sizeof(name), \ | |
1439 | (wxObjectConstructorFn) 0 , \ | |
517fb871 VS |
1440 | name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \ |
1441 | 0 , 0 , 0 ); \ | |
dadaeb69 SC |
1442 | template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1443 | template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
f0b7eadf SC |
1444 | template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1445 | template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1446 | template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \ | |
1447 | template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \ | |
fa08490f | 1448 | template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } |
a095505c | 1449 | |
f0b7eadf | 1450 | |
a095505c SC |
1451 | // Multiple inheritance with two base classes |
1452 | ||
1453 | #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit) \ | |
1454 | wxObject* wxConstructorFor##name() \ | |
1455 | { return new name; } \ | |
1456 | const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,&basename2::sm_class##basename2 , NULL } ; \ | |
fa08490f | 1457 | wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \ |
a095505c SC |
1458 | wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \ |
1459 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT(unit) , wxT(#name), \ | |
1460 | (int) sizeof(name), \ | |
1461 | (wxObjectConstructorFn) wxConstructorFor##name , \ | |
517fb871 VS |
1462 | name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \ |
1463 | name::sm_constructorPropertiesCount##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \ | |
dadaeb69 SC |
1464 | template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1465 | template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
f0b7eadf SC |
1466 | template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1467 | template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1468 | template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID ) ; wxASSERT_MSG(0 , wxT("illegal specialization called") ) ; return &s_typeInfo ; } \ | |
1469 | template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \ | |
fa08490f | 1470 | template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } |
a095505c SC |
1471 | |
1472 | #define IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2) \ | |
1473 | _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , "") \ | |
2d51f067 SC |
1474 | wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \ |
1475 | wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \ | |
a095505c SC |
1476 | WX_CONSTRUCTOR_DUMMY( name ) |
1477 | ||
1478 | #define IMPLEMENT_DYNAMIC_CLASS2_XTI( name , basename , basename2, unit) \ | |
517fb871 | 1479 | _IMPLEMENT_DYNAMIC_CLASS2( name , basename , basename2 , unit) |
a095505c SC |
1480 | |
1481 | // ----------------------------------- | |
1482 | // for abstract classes | |
1483 | // ----------------------------------- | |
1484 | ||
1485 | // Single inheritance with one base class | |
1486 | ||
1487 | #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \ | |
1488 | const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \ | |
fa08490f SC |
1489 | wxObject* wxVariantToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \ |
1490 | wxObject* wxVariantOfPtrToObjectConverter##name ( wxxVariant &data ) { return data.Get<name*>() ; } \ | |
1491 | wxxVariant wxObjectToVariantConverter##name ( wxObject *data ) { return wxxVariant( dynamic_cast<name*> (data) ) ; } \ | |
a095505c SC |
1492 | wxClassInfo name::sm_class##name(sm_classParents##name , wxT("") , wxT(#name), \ |
1493 | (int) sizeof(name), \ | |
1494 | (wxObjectConstructorFn) 0 , \ | |
fa08490f SC |
1495 | name::GetPropertiesStatic(),name::GetHandlersStatic(),0 , 0 , \ |
1496 | 0 , wxVariantOfPtrToObjectConverter##name ,wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \ | |
dadaeb69 SC |
1497 | template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1498 | template<> void wxStringWriteValue(wxString & , name* const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
f0b7eadf SC |
1499 | template<> void wxStringReadValue(const wxString & , name ** & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ |
1500 | template<> void wxStringWriteValue(wxString & , name** const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\ | |
1501 | template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \ | |
1502 | template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; } \ | |
1503 | template<> const wxTypeInfo* wxGetTypeInfo( name *** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID) ; assert(0) ; return &s_typeInfo ; } | |
a095505c SC |
1504 | |
1505 | #define IMPLEMENT_ABSTRACT_CLASS( name , basename ) \ | |
1506 | _IMPLEMENT_ABSTRACT_CLASS( name , basename ) \ | |
2d51f067 SC |
1507 | wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \ |
1508 | wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } | |
a095505c SC |
1509 | |
1510 | // Multiple inheritance with two base classes | |
1511 | ||
1512 | #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \ | |
1513 | wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \ | |
1514 | wxT(#basename2), (int) sizeof(name), \ | |
1515 | (wxObjectConstructorFn) 0); | |
1516 | ||
1517 | #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS | |
1518 | #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2 | |
1519 | ||
208fd16c SC |
1520 | // -------------------------------------------------------------------------- |
1521 | // Collection Support | |
1522 | // -------------------------------------------------------------------------- | |
1523 | ||
1524 | template<typename collection_t> void wxListCollectionToVariantArray( const collection_t& coll , wxxVariantArray &value ) | |
1525 | { | |
1526 | collection_t::compatibility_iterator current = coll.GetFirst() ; | |
1527 | while (current) | |
1528 | { | |
1529 | value.Add( new wxxVariant(current->GetData()) ) ; | |
1530 | current = current->GetNext(); | |
1531 | } | |
1532 | } | |
1533 | ||
1534 | template<typename collection_t> void wxArrayCollectionToVariantArray( const collection_t& coll , wxxVariantArray &value ) | |
1535 | { | |
1536 | for( int i = 0 ; i < coll.GetCount() ; i++ ) | |
1537 | { | |
1538 | value.Add( new wxxVariant(coll[i]) ) ; | |
1539 | } | |
1540 | } | |
1541 | ||
1542 | ||
aeec2045 | 1543 | #endif |