]>
Commit | Line | Data |
---|---|---|
a095505c SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/common/xti.cpp | |
3 | // Purpose: runtime metadata information (extended class info | |
4 | // Author: Stefan Csomor | |
30fd71e6 | 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 | |
65571936 | 10 | // Licence: wxWindows licence |
a095505c SC |
11 | ///////////////////////////////////////////////////////////////////////////// |
12 | ||
a095505c SC |
13 | // For compilers that support precompilation, includes "wx.h". |
14 | #include "wx/wxprec.h" | |
15 | ||
16 | #ifdef __BORLANDC__ | |
8e3f3880 | 17 | #pragma hdrstop |
a095505c SC |
18 | #endif |
19 | ||
8e3f3880 WS |
20 | #if wxUSE_EXTENDED_RTTI |
21 | ||
a095505c | 22 | #ifndef WX_PRECOMP |
8e3f3880 | 23 | #include "wx/object.h" |
8ecff181 | 24 | #include "wx/list.h" |
8e3f3880 | 25 | #include "wx/hash.h" |
a095505c SC |
26 | #endif |
27 | ||
53b74313 | 28 | #include "wx/xti.h" |
a095505c SC |
29 | #include "wx/xml/xml.h" |
30 | #include "wx/tokenzr.h" | |
a095505c SC |
31 | #include <string.h> |
32 | ||
ab6e4913 | 33 | #include "wx/beforestd.h" |
2d51f067 SC |
34 | #include <map> |
35 | #include <string> | |
8f2b1cfd | 36 | #include <list> |
ab6e4913 | 37 | #include "wx/afterstd.h" |
2d51f067 SC |
38 | |
39 | using namespace std ; | |
40 | ||
a095505c SC |
41 | // ---------------------------------------------------------------------------- |
42 | // Enum Support | |
43 | // ---------------------------------------------------------------------------- | |
44 | ||
30fd71e6 | 45 | wxEnumData::wxEnumData( wxEnumMemberData* data ) |
a095505c | 46 | { |
2abce515 | 47 | m_members = data ; |
a095505c | 48 | for ( m_count = 0; m_members[m_count].m_name ; m_count++) |
2abce515 | 49 | {} ; |
a095505c SC |
50 | } |
51 | ||
9a75ecf6 | 52 | bool wxEnumData::HasEnumMemberValue(const wxChar *name, int *value) const |
a095505c SC |
53 | { |
54 | int i; | |
55 | for (i = 0; m_members[i].m_name ; i++ ) | |
2abce515 | 56 | { |
9dc6871e | 57 | if (!wxStrcmp(name, m_members[i].m_name)) |
2abce515 SC |
58 | { |
59 | if ( value ) | |
60 | *value = m_members[i].m_value; | |
61 | return true ; | |
62 | } | |
63 | } | |
64 | return false ; | |
a095505c SC |
65 | } |
66 | ||
9a75ecf6 | 67 | int wxEnumData::GetEnumMemberValue(const wxChar *name) const |
a095505c SC |
68 | { |
69 | int i; | |
70 | for (i = 0; m_members[i].m_name ; i++ ) | |
2abce515 | 71 | { |
9dc6871e | 72 | if (!wxStrcmp(name, m_members[i].m_name)) |
2abce515 SC |
73 | { |
74 | return m_members[i].m_value; | |
75 | } | |
76 | } | |
0c03c79e | 77 | return 0 ; |
a095505c SC |
78 | } |
79 | ||
9a75ecf6 | 80 | const wxChar *wxEnumData::GetEnumMemberName(int value) const |
a095505c SC |
81 | { |
82 | int i; | |
83 | for (i = 0; m_members[i].m_name ; i++) | |
2abce515 SC |
84 | if (value == m_members[i].m_value) |
85 | return m_members[i].m_name; | |
a095505c | 86 | |
525d8583 | 87 | return wxEmptyString ; |
a095505c SC |
88 | } |
89 | ||
9a75ecf6 | 90 | int wxEnumData::GetEnumMemberValueByIndex( int idx ) const |
a095505c | 91 | { |
2abce515 SC |
92 | // we should cache the count in order to avoid out-of-bounds errors |
93 | return m_members[idx].m_value ; | |
a095505c SC |
94 | } |
95 | ||
9a75ecf6 | 96 | const wxChar * wxEnumData::GetEnumMemberNameByIndex( int idx ) const |
a095505c | 97 | { |
2abce515 SC |
98 | // we should cache the count in order to avoid out-of-bounds errors |
99 | return m_members[idx].m_name ; | |
a095505c SC |
100 | } |
101 | ||
102 | // ---------------------------------------------------------------------------- | |
103 | // Type Information | |
104 | // ---------------------------------------------------------------------------- | |
a095505c | 105 | // ---------------------------------------------------------------------------- |
30fd71e6 | 106 | // value streaming |
a095505c SC |
107 | // ---------------------------------------------------------------------------- |
108 | ||
a095505c | 109 | // streamer specializations |
45212047 | 110 | // for all built-in types |
a095505c | 111 | |
45212047 | 112 | // bool |
a095505c | 113 | |
45212047 SC |
114 | template<> void wxStringReadValue(const wxString &s , bool &data ) |
115 | { | |
2abce515 SC |
116 | int intdata ; |
117 | wxSscanf(s, _T("%d"), &intdata ) ; | |
9a75ecf6 | 118 | data = (bool)intdata ; |
45212047 | 119 | } |
a095505c | 120 | |
45212047 | 121 | template<> void wxStringWriteValue(wxString &s , const bool &data ) |
a095505c | 122 | { |
9dc6871e | 123 | s = wxString::Format(_T("%d"), data ) ; |
a095505c SC |
124 | } |
125 | ||
45212047 SC |
126 | // char |
127 | ||
128 | template<> void wxStringReadValue(const wxString &s , char &data ) | |
a095505c | 129 | { |
2abce515 SC |
130 | int intdata ; |
131 | wxSscanf(s, _T("%d"), &intdata ) ; | |
132 | data = char(intdata) ; | |
45212047 SC |
133 | } |
134 | ||
135 | template<> void wxStringWriteValue(wxString &s , const char &data ) | |
136 | { | |
9dc6871e | 137 | s = wxString::Format(_T("%d"), data ) ; |
45212047 SC |
138 | } |
139 | ||
140 | // unsigned char | |
141 | ||
142 | template<> void wxStringReadValue(const wxString &s , unsigned char &data ) | |
143 | { | |
2abce515 SC |
144 | int intdata ; |
145 | wxSscanf(s, _T("%d"), &intdata ) ; | |
146 | data = (unsigned char)(intdata) ; | |
45212047 SC |
147 | } |
148 | ||
149 | template<> void wxStringWriteValue(wxString &s , const unsigned char &data ) | |
150 | { | |
9dc6871e | 151 | s = wxString::Format(_T("%d"), data ) ; |
a095505c SC |
152 | } |
153 | ||
30fd71e6 | 154 | // int |
a095505c | 155 | |
30fd71e6 | 156 | template<> void wxStringReadValue(const wxString &s , int &data ) |
a095505c | 157 | { |
2abce515 | 158 | wxSscanf(s, _T("%d"), &data ) ; |
a095505c SC |
159 | } |
160 | ||
30fd71e6 | 161 | template<> void wxStringWriteValue(wxString &s , const int &data ) |
a095505c | 162 | { |
9dc6871e | 163 | s = wxString::Format(_T("%d"), data ) ; |
a095505c SC |
164 | } |
165 | ||
45212047 SC |
166 | // unsigned int |
167 | ||
168 | template<> void wxStringReadValue(const wxString &s , unsigned int &data ) | |
169 | { | |
2abce515 | 170 | wxSscanf(s, _T("%d"), &data ) ; |
45212047 SC |
171 | } |
172 | ||
173 | template<> void wxStringWriteValue(wxString &s , const unsigned int &data ) | |
174 | { | |
9dc6871e | 175 | s = wxString::Format(_T("%d"), data ) ; |
45212047 SC |
176 | } |
177 | ||
178 | // long | |
179 | ||
180 | template<> void wxStringReadValue(const wxString &s , long &data ) | |
181 | { | |
2abce515 | 182 | wxSscanf(s, _T("%ld"), &data ) ; |
45212047 SC |
183 | } |
184 | ||
185 | template<> void wxStringWriteValue(wxString &s , const long &data ) | |
186 | { | |
9dc6871e | 187 | s = wxString::Format(_T("%ld"), data ) ; |
45212047 SC |
188 | } |
189 | ||
190 | // unsigned long | |
191 | ||
192 | template<> void wxStringReadValue(const wxString &s , unsigned long &data ) | |
193 | { | |
2abce515 | 194 | wxSscanf(s, _T("%ld"), &data ) ; |
45212047 SC |
195 | } |
196 | ||
197 | template<> void wxStringWriteValue(wxString &s , const unsigned long &data ) | |
198 | { | |
9dc6871e | 199 | s = wxString::Format(_T("%ld"), data ) ; |
45212047 SC |
200 | } |
201 | ||
202 | // float | |
203 | ||
204 | template<> void wxStringReadValue(const wxString &s , float &data ) | |
205 | { | |
2abce515 | 206 | wxSscanf(s, _T("%f"), &data ) ; |
45212047 SC |
207 | } |
208 | ||
209 | template<> void wxStringWriteValue(wxString &s , const float &data ) | |
210 | { | |
9dc6871e | 211 | s = wxString::Format(_T("%f"), data ) ; |
45212047 SC |
212 | } |
213 | ||
214 | // double | |
215 | ||
216 | template<> void wxStringReadValue(const wxString &s , double &data ) | |
217 | { | |
2abce515 | 218 | wxSscanf(s, _T("%lf"), &data ) ; |
45212047 SC |
219 | } |
220 | ||
221 | template<> void wxStringWriteValue(wxString &s , const double &data ) | |
222 | { | |
9dc6871e | 223 | s = wxString::Format(_T("%lf"), data ) ; |
45212047 SC |
224 | } |
225 | ||
a095505c SC |
226 | // wxString |
227 | ||
30fd71e6 | 228 | template<> void wxStringReadValue(const wxString &s , wxString &data ) |
a095505c | 229 | { |
2abce515 | 230 | data = s ; |
a095505c SC |
231 | } |
232 | ||
30fd71e6 | 233 | template<> void wxStringWriteValue(wxString &s , const wxString &data ) |
a095505c | 234 | { |
2abce515 | 235 | s = data ; |
a095505c SC |
236 | } |
237 | ||
c1d6d0f9 SC |
238 | // built-ins |
239 | // | |
b8d5be01 | 240 | |
af498247 VZ |
241 | #if wxUSE_FUNC_TEMPLATE_POINTER |
242 | #define wxBUILTIN_TYPE_INFO( element , type ) \ | |
243 | wxBuiltInTypeInfo s_typeInfo##type(element , &wxToStringConverter<type> , &wxFromStringConverter<type> , typeid(type).name()) ; | |
244 | #else | |
245 | #define wxBUILTIN_TYPE_INFO( element , type ) \ | |
246 | void _toString##element( const wxxVariant& data , wxString &result ) { wxToStringConverter<type>(data, result); } \ | |
247 | void _fromString##element( const wxString& data , wxxVariant &result ) { wxFromStringConverter<type>(data, result); } \ | |
248 | wxBuiltInTypeInfo s_typeInfo##type(element , &_toString##element , &_fromString##element , typeid(type).name()) ; | |
249 | #endif | |
250 | ||
251 | typedef unsigned char unsigned_char; | |
252 | typedef unsigned int unsigned_int; | |
253 | typedef unsigned long unsigned_long; | |
254 | ||
255 | wxBuiltInTypeInfo s_typeInfovoid( wxT_VOID , NULL , NULL , typeid(void).name()); | |
256 | wxBUILTIN_TYPE_INFO( wxT_BOOL , bool); | |
257 | wxBUILTIN_TYPE_INFO( wxT_CHAR , char); | |
258 | wxBUILTIN_TYPE_INFO( wxT_UCHAR , unsigned_char); | |
259 | wxBUILTIN_TYPE_INFO( wxT_INT , int); | |
260 | wxBUILTIN_TYPE_INFO( wxT_UINT , unsigned_int); | |
261 | wxBUILTIN_TYPE_INFO( wxT_LONG , long); | |
262 | wxBUILTIN_TYPE_INFO( wxT_ULONG , unsigned_long); | |
263 | wxBUILTIN_TYPE_INFO( wxT_FLOAT , float); | |
264 | wxBUILTIN_TYPE_INFO( wxT_DOUBLE , double); | |
265 | wxBUILTIN_TYPE_INFO( wxT_STRING , wxString); | |
266 | ||
b8d5be01 SC |
267 | |
268 | // this are compiler induced specialization which are never used anywhere | |
269 | ||
8805dbab SC |
270 | wxILLEGAL_TYPE_SPECIALIZATION( char const * ) |
271 | wxILLEGAL_TYPE_SPECIALIZATION( char * ) | |
272 | wxILLEGAL_TYPE_SPECIALIZATION( unsigned char * ) | |
273 | wxILLEGAL_TYPE_SPECIALIZATION( int * ) | |
274 | wxILLEGAL_TYPE_SPECIALIZATION( bool * ) | |
275 | wxILLEGAL_TYPE_SPECIALIZATION( long * ) | |
276 | wxILLEGAL_TYPE_SPECIALIZATION( wxString * ) | |
b8d5be01 | 277 | |
8805dbab | 278 | wxCOLLECTION_TYPE_INFO( wxString , wxArrayString ) ; |
b8d5be01 SC |
279 | |
280 | template<> void wxCollectionToVariantArray( wxArrayString const &theArray, wxxVariantArray &value) | |
281 | { | |
282 | wxArrayCollectionToVariantArray( theArray , value ) ; | |
283 | } | |
284 | ||
05fa251a | 285 | wxTypeInfoMap *wxTypeInfo::ms_typeTable = NULL ; |
b8d5be01 | 286 | |
cb73e600 SC |
287 | wxTypeInfo *wxTypeInfo::FindType(const wxChar *typeName) |
288 | { | |
05fa251a SC |
289 | wxTypeInfoMap::iterator iter = ms_typeTable->find(typeName) ; |
290 | wxASSERT_MSG( iter != ms_typeTable->end() , wxT("lookup for a non-existent type-info") ) ; | |
499a9a62 | 291 | return (wxTypeInfo *)iter->second; |
cb73e600 | 292 | } |
b8d5be01 | 293 | |
b1f6de83 | 294 | #if wxUSE_UNICODE |
9f6b8316 | 295 | wxClassTypeInfo::wxClassTypeInfo( wxTypeKind kind , wxClassInfo* classInfo , converterToString_t to , converterFromString_t from , const char *name) : |
b1f6de83 SC |
296 | wxTypeInfo( kind , to , from , name) |
297 | { wxASSERT_MSG( kind == wxT_OBJECT_PTR || kind == wxT_OBJECT , wxT("Illegal Kind for Enum Type")) ; m_classInfo = classInfo ;} | |
298 | #endif | |
299 | ||
499a9a62 SC |
300 | wxClassTypeInfo::wxClassTypeInfo( wxTypeKind kind , wxClassInfo* classInfo , converterToString_t to , converterFromString_t from , const wxString &name) : |
301 | wxTypeInfo( kind , to , from , name) | |
cb73e600 | 302 | { wxASSERT_MSG( kind == wxT_OBJECT_PTR || kind == wxT_OBJECT , wxT("Illegal Kind for Enum Type")) ; m_classInfo = classInfo ;} |
45212047 | 303 | |
cb73e600 | 304 | wxDelegateTypeInfo::wxDelegateTypeInfo( int eventType , wxClassInfo* eventClass , converterToString_t to , converterFromString_t from ) : |
2abce515 | 305 | wxTypeInfo ( wxT_DELEGATE , to , from , wxEmptyString ) |
8edb7cd5 SC |
306 | { m_eventClass = eventClass ; m_eventType = eventType ; m_lastEventType = -1 ;} |
307 | ||
308 | wxDelegateTypeInfo::wxDelegateTypeInfo( int eventType , int lastEventType , wxClassInfo* eventClass , converterToString_t to , converterFromString_t from ) : | |
309 | wxTypeInfo ( wxT_DELEGATE , to , from , wxEmptyString ) | |
310 | { m_eventClass = eventClass ; m_eventType = eventType ; m_lastEventType = lastEventType; } | |
45212047 | 311 | |
cb73e600 | 312 | void wxTypeInfo::Register() |
cab1a605 | 313 | { |
05fa251a SC |
314 | if ( ms_typeTable == NULL ) |
315 | ms_typeTable = new wxTypeInfoMap() ; | |
45212047 | 316 | |
525d8583 | 317 | if( !m_name.empty() ) |
05fa251a | 318 | (*ms_typeTable)[m_name] = this ; |
45212047 SC |
319 | } |
320 | ||
cb73e600 SC |
321 | void wxTypeInfo::Unregister() |
322 | { | |
525d8583 | 323 | if( !m_name.empty() ) |
05fa251a | 324 | ms_typeTable->erase(m_name); |
2abce515 | 325 | } |
45212047 | 326 | |
a095505c SC |
327 | // removing header dependancy on string tokenizer |
328 | ||
30fd71e6 | 329 | void wxSetStringToArray( const wxString &s , wxArrayString &array ) |
a095505c SC |
330 | { |
331 | wxStringTokenizer tokenizer(s, wxT("| \t\n"), wxTOKEN_STRTOK); | |
332 | wxString flag; | |
2abce515 | 333 | array.Clear() ; |
a095505c SC |
334 | while (tokenizer.HasMoreTokens()) |
335 | { | |
2abce515 SC |
336 | array.Add(tokenizer.GetNextToken()) ; |
337 | } | |
a095505c SC |
338 | } |
339 | ||
340 | // ---------------------------------------------------------------------------- | |
30fd71e6 | 341 | // wxClassInfo |
a095505c SC |
342 | // ---------------------------------------------------------------------------- |
343 | ||
499a9a62 SC |
344 | wxPropertyInfo::~wxPropertyInfo() |
345 | { | |
346 | if ( this == m_itsClass->m_firstProperty ) | |
347 | { | |
348 | m_itsClass->m_firstProperty = m_next; | |
349 | } | |
350 | else | |
351 | { | |
352 | wxPropertyInfo *info = m_itsClass->m_firstProperty; | |
353 | while (info) | |
354 | { | |
355 | if ( info->m_next == this ) | |
356 | { | |
357 | info->m_next = m_next; | |
358 | break; | |
359 | } | |
360 | ||
361 | info = info->m_next; | |
362 | } | |
363 | } | |
364 | } | |
365 | ||
366 | wxHandlerInfo::~wxHandlerInfo() | |
367 | { | |
368 | if ( this == m_itsClass->m_firstHandler ) | |
369 | { | |
370 | m_itsClass->m_firstHandler = m_next; | |
371 | } | |
372 | else | |
373 | { | |
374 | wxHandlerInfo *info = m_itsClass->m_firstHandler; | |
375 | while (info) | |
376 | { | |
377 | if ( info->m_next == this ) | |
378 | { | |
379 | info->m_next = m_next; | |
380 | break; | |
381 | } | |
382 | ||
383 | info = info->m_next; | |
384 | } | |
385 | } | |
386 | } | |
387 | ||
9dc6871e | 388 | const wxPropertyAccessor *wxClassInfo::FindAccessor(const wxChar *PropertyName) const |
a095505c | 389 | { |
fbbdc52c | 390 | const wxPropertyInfo* info = FindPropertyInfo( PropertyName ) ; |
30fd71e6 | 391 | |
2abce515 SC |
392 | if ( info ) |
393 | return info->GetAccessor() ; | |
a095505c | 394 | |
2abce515 | 395 | return NULL ; |
a095505c SC |
396 | } |
397 | ||
9dc6871e | 398 | wxPropertyInfo *wxClassInfo::FindPropertyInfoInThisClass (const wxChar *PropertyName) const |
a095505c | 399 | { |
499a9a62 | 400 | wxPropertyInfo* info = m_firstProperty ; |
a095505c | 401 | |
2abce515 SC |
402 | while( info ) |
403 | { | |
9dc6871e | 404 | if ( wxStrcmp( info->GetName() , PropertyName ) == 0 ) |
2abce515 SC |
405 | return info ; |
406 | info = info->GetNext() ; | |
407 | } | |
a095505c | 408 | |
2d51f067 SC |
409 | return 0; |
410 | } | |
411 | ||
9dc6871e | 412 | const wxPropertyInfo *wxClassInfo::FindPropertyInfo (const wxChar *PropertyName) const |
2d51f067 | 413 | { |
2abce515 | 414 | const wxPropertyInfo* info = FindPropertyInfoInThisClass( PropertyName ) ; |
2d51f067 SC |
415 | if ( info ) |
416 | return info ; | |
417 | ||
2abce515 SC |
418 | const wxClassInfo** parents = GetParents() ; |
419 | for ( int i = 0 ; parents[i] ; ++ i ) | |
420 | { | |
421 | if ( ( info = parents[i]->FindPropertyInfo( PropertyName ) ) != NULL ) | |
422 | return info ; | |
423 | } | |
a095505c SC |
424 | |
425 | return 0; | |
426 | } | |
427 | ||
9dc6871e | 428 | wxHandlerInfo *wxClassInfo::FindHandlerInfoInThisClass (const wxChar *PropertyName) const |
fbbdc52c | 429 | { |
499a9a62 | 430 | wxHandlerInfo* info = m_firstHandler ; |
fbbdc52c | 431 | |
2abce515 SC |
432 | while( info ) |
433 | { | |
9dc6871e | 434 | if ( wxStrcmp( info->GetName() , PropertyName ) == 0 ) |
2abce515 SC |
435 | return info ; |
436 | info = info->GetNext() ; | |
437 | } | |
fbbdc52c | 438 | |
2d51f067 SC |
439 | return 0; |
440 | } | |
441 | ||
9dc6871e | 442 | const wxHandlerInfo *wxClassInfo::FindHandlerInfo (const wxChar *PropertyName) const |
2d51f067 | 443 | { |
2abce515 | 444 | const wxHandlerInfo* info = FindHandlerInfoInThisClass( PropertyName ) ; |
2d51f067 SC |
445 | |
446 | if ( info ) | |
447 | return info ; | |
448 | ||
2abce515 SC |
449 | const wxClassInfo** parents = GetParents() ; |
450 | for ( int i = 0 ; parents[i] ; ++ i ) | |
451 | { | |
452 | if ( ( info = parents[i]->FindHandlerInfo( PropertyName ) ) != NULL ) | |
453 | return info ; | |
454 | } | |
fbbdc52c SC |
455 | |
456 | return 0; | |
457 | } | |
458 | ||
9c8046dd SC |
459 | wxObjectStreamingCallback wxClassInfo::GetStreamingCallback() const |
460 | { | |
461 | if ( m_streamingCallback ) | |
462 | return m_streamingCallback ; | |
463 | ||
464 | wxObjectStreamingCallback retval = NULL ; | |
2abce515 | 465 | const wxClassInfo** parents = GetParents() ; |
9c8046dd | 466 | for ( int i = 0 ; parents[i] && retval == NULL ; ++ i ) |
2abce515 | 467 | { |
9c8046dd | 468 | retval = parents[i]->GetStreamingCallback() ; |
2abce515 | 469 | } |
9c8046dd SC |
470 | return retval ; |
471 | } | |
472 | ||
cab1a605 | 473 | bool wxClassInfo::BeforeWriteObject( const wxObject *obj, wxWriter *streamer , wxPersister *persister , wxxVariantArray &metadata) const |
9c8046dd SC |
474 | { |
475 | wxObjectStreamingCallback sb = GetStreamingCallback() ; | |
476 | if ( sb ) | |
477 | return (*sb)(obj , streamer , persister , metadata ) ; | |
478 | ||
479 | return true ; | |
480 | } | |
fbbdc52c | 481 | |
9dc6871e | 482 | void wxClassInfo::SetProperty(wxObject *object, const wxChar *propertyName, const wxxVariant &value) const |
a095505c SC |
483 | { |
484 | const wxPropertyAccessor *accessor; | |
485 | ||
486 | accessor = FindAccessor(propertyName); | |
487 | wxASSERT(accessor->HasSetter()); | |
2abce515 | 488 | accessor->SetProperty( object , value ) ; |
a095505c SC |
489 | } |
490 | ||
9dc6871e | 491 | wxxVariant wxClassInfo::GetProperty(wxObject *object, const wxChar *propertyName) const |
a095505c SC |
492 | { |
493 | const wxPropertyAccessor *accessor; | |
494 | ||
495 | accessor = FindAccessor(propertyName); | |
496 | wxASSERT(accessor->HasGetter()); | |
b8d5be01 SC |
497 | wxxVariant result ; |
498 | accessor->GetProperty(object,result); | |
499 | return result ; | |
a095505c SC |
500 | } |
501 | ||
b8d5be01 | 502 | wxxVariantArray wxClassInfo::GetPropertyCollection(wxObject *object, const wxChar *propertyName) const |
ab6e4913 SC |
503 | { |
504 | const wxPropertyAccessor *accessor; | |
505 | ||
506 | accessor = FindAccessor(propertyName); | |
507 | wxASSERT(accessor->HasGetter()); | |
b8d5be01 SC |
508 | wxxVariantArray result ; |
509 | accessor->GetPropertyCollection(object,result); | |
510 | return result ; | |
ab6e4913 SC |
511 | } |
512 | ||
b8d5be01 | 513 | void wxClassInfo::AddToPropertyCollection(wxObject *object, const wxChar *propertyName , const wxxVariant& value) const |
ab6e4913 SC |
514 | { |
515 | const wxPropertyAccessor *accessor; | |
516 | ||
517 | accessor = FindAccessor(propertyName); | |
518 | wxASSERT(accessor->HasAdder()); | |
519 | accessor->AddToPropertyCollection( object , value ) ; | |
520 | } | |
521 | ||
cab1a605 | 522 | // void wxClassInfo::GetProperties( wxPropertyInfoMap &map ) const |
af498247 VZ |
523 | // The map parameter (the name map that is) seems something special |
524 | // to MSVC and so we use a other name. | |
cab1a605 | 525 | void wxClassInfo::GetProperties( wxPropertyInfoMap &infomap ) const |
cb73e600 SC |
526 | { |
527 | const wxPropertyInfo *pi = GetFirstProperty() ; | |
cab1a605 | 528 | while( pi ) |
cb73e600 | 529 | { |
af498247 VZ |
530 | if ( infomap.find( pi->GetName() ) == infomap.end() ) |
531 | infomap[pi->GetName()] = (wxPropertyInfo*) pi ; | |
cb73e600 SC |
532 | |
533 | pi = pi->GetNext() ; | |
534 | } | |
535 | ||
536 | const wxClassInfo** parents = GetParents() ; | |
537 | for ( int i = 0 ; parents[i] ; ++ i ) | |
538 | { | |
af498247 | 539 | parents[i]->GetProperties( infomap ) ; |
cb73e600 SC |
540 | } |
541 | } | |
542 | ||
a095505c SC |
543 | /* |
544 | VARIANT TO OBJECT | |
545 | */ | |
546 | ||
66c57129 | 547 | wxObject* wxxVariant::GetAsObject() |
a095505c | 548 | { |
2abce515 SC |
549 | const wxClassTypeInfo *ti = dynamic_cast<const wxClassTypeInfo*>( m_data->GetTypeInfo() ) ; |
550 | if ( ti ) | |
551 | return ti->GetClassInfo()->VariantToInstance(*this) ; | |
552 | else | |
553 | return NULL ; | |
a095505c SC |
554 | } |
555 | ||
2d51f067 SC |
556 | // ---------------------------------------------------------------------------- |
557 | // wxDynamicObject support | |
558 | // ---------------------------------------------------------------------------- | |
559 | // | |
560 | // Dynamic Objects are objects that have a real superclass instance and carry their | |
561 | // own attributes in a hash map. Like this it is possible to create the objects and | |
562 | // stream them, as if their class information was already available from compiled data | |
563 | ||
564 | struct wxDynamicObject::wxDynamicObjectInternal | |
565 | { | |
8f2b1cfd SC |
566 | wxDynamicObjectInternal() {} |
567 | ||
67b283a9 JS |
568 | #if wxUSE_UNICODE |
569 | map<wstring,wxxVariant> m_properties ; | |
570 | #else | |
2d51f067 | 571 | map<string,wxxVariant> m_properties ; |
67b283a9 | 572 | #endif |
8f2b1cfd SC |
573 | } ; |
574 | ||
575 | typedef list< wxDynamicObject* > wxDynamicObjectList ; | |
576 | ||
577 | struct wxDynamicClassInfo::wxDynamicClassInfoInternal | |
578 | { | |
579 | wxDynamicObjectList m_dynamicObjects ; | |
2d51f067 SC |
580 | } ; |
581 | ||
582 | // instantiates this object with an instance of its superclass | |
b8d5be01 | 583 | wxDynamicObject::wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info) |
2d51f067 SC |
584 | { |
585 | m_superClassInstance = superClassInstance ; | |
586 | m_classInfo = info ; | |
587 | m_data = new wxDynamicObjectInternal ; | |
588 | } | |
589 | ||
590 | wxDynamicObject::~wxDynamicObject() | |
591 | { | |
8f2b1cfd | 592 | dynamic_cast<const wxDynamicClassInfo*>(m_classInfo)->m_data->m_dynamicObjects.remove( this ) ; |
2d51f067 SC |
593 | delete m_data ; |
594 | delete m_superClassInstance ; | |
595 | } | |
596 | ||
597 | void wxDynamicObject::SetProperty (const wxChar *propertyName, const wxxVariant &value) | |
598 | { | |
599 | wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(propertyName),wxT("Accessing Unknown Property in a Dynamic Object") ) ; | |
8f2b1cfd | 600 | m_data->m_properties[propertyName] = value ; |
2d51f067 SC |
601 | } |
602 | ||
603 | wxxVariant wxDynamicObject::GetProperty (const wxChar *propertyName) const | |
604 | { | |
2abce515 | 605 | wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(propertyName),wxT("Accessing Unknown Property in a Dynamic Object") ) ; |
8f2b1cfd SC |
606 | return m_data->m_properties[propertyName] ; |
607 | } | |
608 | ||
cab1a605 | 609 | void wxDynamicObject::RemoveProperty( const wxChar *propertyName ) |
8f2b1cfd SC |
610 | { |
611 | wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(propertyName),wxT("Removing Unknown Property in a Dynamic Object") ) ; | |
612 | m_data->m_properties.erase( propertyName ) ; | |
2d51f067 SC |
613 | } |
614 | ||
cab1a605 | 615 | void wxDynamicObject::RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName ) |
8f2b1cfd SC |
616 | { |
617 | wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(oldPropertyName),wxT("Renaming Unknown Property in a Dynamic Object") ) ; | |
618 | wxxVariant value = m_data->m_properties[oldPropertyName] ; | |
619 | m_data->m_properties.erase( oldPropertyName ) ; | |
620 | m_data->m_properties[newPropertyName] = value ; | |
621 | } | |
622 | ||
623 | ||
2d51f067 SC |
624 | // ---------------------------------------------------------------------------- |
625 | // wxDynamiClassInfo | |
626 | // ---------------------------------------------------------------------------- | |
627 | ||
628 | wxDynamicClassInfo::wxDynamicClassInfo( const wxChar *unitName, const wxChar *className , const wxClassInfo* superClass ) : | |
2abce515 | 629 | wxClassInfo( unitName, className , new const wxClassInfo*[2]) |
2d51f067 SC |
630 | { |
631 | GetParents()[0] = superClass ; | |
632 | GetParents()[1] = NULL ; | |
8f2b1cfd | 633 | m_data = new wxDynamicClassInfoInternal ; |
2d51f067 SC |
634 | } |
635 | ||
636 | wxDynamicClassInfo::~wxDynamicClassInfo() | |
637 | { | |
638 | delete[] GetParents() ; | |
8f2b1cfd | 639 | delete m_data ; |
2d51f067 SC |
640 | } |
641 | ||
b8d5be01 | 642 | wxObject *wxDynamicClassInfo::AllocateObject() const |
2d51f067 | 643 | { |
ab6e4913 | 644 | wxObject* parent = GetParents()[0]->AllocateObject() ; |
8f2b1cfd SC |
645 | wxDynamicObject *obj = new wxDynamicObject( parent , this ) ; |
646 | m_data->m_dynamicObjects.push_back( obj ) ; | |
647 | return obj ; | |
2d51f067 SC |
648 | } |
649 | ||
b8d5be01 | 650 | void wxDynamicClassInfo::Create (wxObject *object, int paramCount, wxxVariant *params) const |
2d51f067 SC |
651 | { |
652 | wxDynamicObject *dynobj = dynamic_cast< wxDynamicObject *>( object ) ; | |
653 | wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::Create on an object other than wxDynamicObject") ) ; | |
654 | GetParents()[0]->Create( dynobj->GetSuperClassInstance() , paramCount , params ) ; | |
655 | } | |
656 | ||
657 | // get number of parameters for constructor | |
b8d5be01 | 658 | int wxDynamicClassInfo::GetCreateParamCount() const |
2d51f067 SC |
659 | { |
660 | return GetParents()[0]->GetCreateParamCount() ; | |
661 | } | |
662 | ||
663 | // get i-th constructor parameter | |
b8d5be01 | 664 | const wxChar* wxDynamicClassInfo::GetCreateParamName(int i) const |
2d51f067 SC |
665 | { |
666 | return GetParents()[0]->GetCreateParamName( i ) ; | |
667 | } | |
668 | ||
9dc6871e | 669 | void wxDynamicClassInfo::SetProperty(wxObject *object, const wxChar *propertyName, const wxxVariant &value) const |
2d51f067 SC |
670 | { |
671 | wxDynamicObject* dynobj = dynamic_cast< wxDynamicObject * >( object ) ; | |
672 | wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ; | |
673 | if ( FindPropertyInfoInThisClass(propertyName) ) | |
674 | dynobj->SetProperty( propertyName , value ) ; | |
675 | else | |
676 | GetParents()[0]->SetProperty( dynobj->GetSuperClassInstance() , propertyName , value ) ; | |
677 | } | |
678 | ||
9dc6871e | 679 | wxxVariant wxDynamicClassInfo::GetProperty(wxObject *object, const wxChar *propertyName) const |
2d51f067 SC |
680 | { |
681 | wxDynamicObject* dynobj = dynamic_cast< wxDynamicObject * >( object ) ; | |
682 | wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ; | |
683 | if ( FindPropertyInfoInThisClass(propertyName) ) | |
684 | return dynobj->GetProperty( propertyName ) ; | |
685 | else | |
686 | return GetParents()[0]->GetProperty( dynobj->GetSuperClassInstance() , propertyName ) ; | |
687 | } | |
688 | ||
b8d5be01 | 689 | void wxDynamicClassInfo::AddProperty( const wxChar *propertyName , const wxTypeInfo* typeInfo ) |
2d51f067 | 690 | { |
499a9a62 | 691 | new wxPropertyInfo( m_firstProperty , this , propertyName , typeInfo->GetTypeName() , new wxGenericPropertyAccessor( propertyName ) , wxxVariant() ) ; |
2d51f067 SC |
692 | } |
693 | ||
b8d5be01 | 694 | void wxDynamicClassInfo::AddHandler( const wxChar *handlerName , wxObjectEventFunction address , const wxClassInfo* eventClassInfo ) |
2d51f067 | 695 | { |
499a9a62 | 696 | new wxHandlerInfo( m_firstHandler , this , handlerName , address , eventClassInfo ) ; |
2d51f067 SC |
697 | } |
698 | ||
2abce515 | 699 | // removes an existing runtime-property |
cab1a605 | 700 | void wxDynamicClassInfo::RemoveProperty( const wxChar *propertyName ) |
2abce515 | 701 | { |
8f2b1cfd SC |
702 | for ( wxDynamicObjectList::iterator iter = m_data->m_dynamicObjects.begin() ; iter != m_data->m_dynamicObjects.end() ; ++iter ) |
703 | (*iter)->RemoveProperty( propertyName ) ; | |
499a9a62 | 704 | delete FindPropertyInfoInThisClass(propertyName) ; |
2abce515 SC |
705 | } |
706 | ||
707 | // removes an existing runtime-handler | |
cab1a605 | 708 | void wxDynamicClassInfo::RemoveHandler( const wxChar *handlerName ) |
2abce515 | 709 | { |
499a9a62 SC |
710 | delete FindHandlerInfoInThisClass(handlerName) ; |
711 | } | |
712 | ||
713 | // renames an existing runtime-property | |
cab1a605 | 714 | void wxDynamicClassInfo::RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName ) |
499a9a62 SC |
715 | { |
716 | wxPropertyInfo* pi = FindPropertyInfoInThisClass(oldPropertyName) ; | |
717 | wxASSERT_MSG( pi ,wxT("not existing property") ) ; | |
718 | pi->m_name = newPropertyName ; | |
719 | dynamic_cast<wxGenericPropertyAccessor*>(pi->GetAccessor())->RenameProperty( oldPropertyName , newPropertyName ) ; | |
8f2b1cfd SC |
720 | for ( wxDynamicObjectList::iterator iter = m_data->m_dynamicObjects.begin() ; iter != m_data->m_dynamicObjects.end() ; ++iter ) |
721 | (*iter)->RenameProperty( oldPropertyName , newPropertyName ) ; | |
499a9a62 SC |
722 | } |
723 | ||
724 | // renames an existing runtime-handler | |
cab1a605 | 725 | void wxDynamicClassInfo::RenameHandler( const wxChar *oldHandlerName , const wxChar *newHandlerName ) |
499a9a62 SC |
726 | { |
727 | wxASSERT_MSG(FindHandlerInfoInThisClass(oldHandlerName),wxT("not existing handler") ) ; | |
728 | FindHandlerInfoInThisClass(oldHandlerName)->m_name = newHandlerName ; | |
2abce515 SC |
729 | } |
730 | ||
2d51f067 SC |
731 | // ---------------------------------------------------------------------------- |
732 | // wxGenericPropertyAccessor | |
733 | // ---------------------------------------------------------------------------- | |
734 | ||
735 | struct wxGenericPropertyAccessor::wxGenericPropertyAccessorInternal | |
736 | { | |
b8d5be01 | 737 | char filler ; |
2d51f067 SC |
738 | } ; |
739 | ||
b8d5be01 SC |
740 | wxGenericPropertyAccessor::wxGenericPropertyAccessor( const wxString& propertyName ) |
741 | : wxPropertyAccessor( NULL , NULL , NULL , NULL ) | |
2d51f067 SC |
742 | { |
743 | m_data = new wxGenericPropertyAccessorInternal ; | |
b8d5be01 SC |
744 | m_propertyName = propertyName ; |
745 | m_getterName = wxT("Get")+propertyName ; | |
746 | m_setterName = wxT("Set")+propertyName ; | |
2d51f067 SC |
747 | } |
748 | ||
749 | wxGenericPropertyAccessor::~wxGenericPropertyAccessor() | |
750 | { | |
751 | delete m_data ; | |
752 | } | |
b8d5be01 | 753 | void wxGenericPropertyAccessor::SetProperty(wxObject *object, const wxxVariant &value) const |
2d51f067 SC |
754 | { |
755 | wxDynamicObject* dynobj = dynamic_cast< wxDynamicObject * >( object ) ; | |
756 | wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ; | |
b8d5be01 | 757 | dynobj->SetProperty(m_propertyName , value ) ; |
2d51f067 SC |
758 | } |
759 | ||
b8d5be01 | 760 | void wxGenericPropertyAccessor::GetProperty(const wxObject *object, wxxVariant& value) const |
2d51f067 SC |
761 | { |
762 | const wxDynamicObject* dynobj = dynamic_cast< const wxDynamicObject * >( object ) ; | |
763 | wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ; | |
b8d5be01 | 764 | value = dynobj->GetProperty( m_propertyName ) ; |
2d51f067 | 765 | } |
8e3f3880 WS |
766 | |
767 | #endif // wxUSE_EXTENDED_RTTI |