]>
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 | |
10 | // Licence: wxWindows licence | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
14f355c2 | 13 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
a095505c SC |
14 | #pragma implementation "xti.h" |
15 | #endif | |
16 | ||
17 | // For compilers that support precompilation, includes "wx.h". | |
18 | #include "wx/wxprec.h" | |
19 | ||
20 | #ifdef __BORLANDC__ | |
21 | #pragma hdrstop | |
22 | #endif | |
23 | ||
24 | #ifndef WX_PRECOMP | |
25 | #include "wx/hash.h" | |
26 | #include "wx/object.h" | |
27 | #endif | |
28 | ||
29 | #include "wx/xml/xml.h" | |
30 | #include "wx/tokenzr.h" | |
31 | ||
32 | #include <string.h> | |
33 | ||
30bfc425 | 34 | #if wxUSE_EXTENDED_RTTI |
a095505c | 35 | |
ab6e4913 | 36 | #include "wx/beforestd.h" |
2d51f067 SC |
37 | #include <map> |
38 | #include <string> | |
ab6e4913 | 39 | #include "wx/afterstd.h" |
2d51f067 SC |
40 | |
41 | using namespace std ; | |
42 | ||
a095505c SC |
43 | // ---------------------------------------------------------------------------- |
44 | // Enum Support | |
45 | // ---------------------------------------------------------------------------- | |
46 | ||
30fd71e6 | 47 | wxEnumData::wxEnumData( wxEnumMemberData* data ) |
a095505c | 48 | { |
30fd71e6 | 49 | m_members = data ; |
a095505c SC |
50 | for ( m_count = 0; m_members[m_count].m_name ; m_count++) |
51 | {} ; | |
52 | } | |
53 | ||
54 | bool wxEnumData::HasEnumMemberValue(const wxChar *name, int *value) | |
55 | { | |
56 | int i; | |
57 | for (i = 0; m_members[i].m_name ; i++ ) | |
58 | { | |
59 | if (!strcmp(name, m_members[i].m_name)) | |
60 | { | |
61 | if ( value ) | |
62 | *value = m_members[i].m_value; | |
63 | return true ; | |
64 | } | |
65 | } | |
66 | return false ; | |
67 | } | |
68 | ||
69 | int wxEnumData::GetEnumMemberValue(const wxChar *name) | |
70 | { | |
71 | int i; | |
72 | for (i = 0; m_members[i].m_name ; i++ ) | |
73 | { | |
74 | if (!strcmp(name, m_members[i].m_name)) | |
75 | { | |
76 | return m_members[i].m_value; | |
77 | } | |
78 | } | |
0c03c79e | 79 | return 0 ; |
a095505c SC |
80 | } |
81 | ||
82 | const wxChar *wxEnumData::GetEnumMemberName(int value) | |
83 | { | |
84 | int i; | |
85 | for (i = 0; m_members[i].m_name ; i++) | |
86 | if (value == m_members[i].m_value) | |
87 | return m_members[i].m_name; | |
88 | ||
89 | return wxT("") ; | |
90 | } | |
91 | ||
30fd71e6 | 92 | int wxEnumData::GetEnumMemberValueByIndex( int idx ) |
a095505c SC |
93 | { |
94 | // we should cache the count in order to avoid out-of-bounds errors | |
95 | return m_members[idx].m_value ; | |
96 | } | |
97 | ||
30fd71e6 | 98 | const char * wxEnumData::GetEnumMemberNameByIndex( int idx ) |
a095505c SC |
99 | { |
100 | // we should cache the count in order to avoid out-of-bounds errors | |
101 | return m_members[idx].m_name ; | |
102 | } | |
103 | ||
104 | // ---------------------------------------------------------------------------- | |
105 | // Type Information | |
106 | // ---------------------------------------------------------------------------- | |
107 | ||
0c03c79e | 108 | template<> const wxTypeInfo* wxGetTypeInfo( void * ) |
a095505c SC |
109 | { |
110 | static wxBuiltInTypeInfo s_typeInfo( wxT_VOID ) ; | |
111 | return &s_typeInfo ; | |
112 | } | |
113 | ||
0c03c79e | 114 | template<> const wxTypeInfo* wxGetTypeInfo( bool * ) |
a095505c SC |
115 | { |
116 | static wxBuiltInTypeInfo s_typeInfo( wxT_BOOL ) ; | |
117 | return &s_typeInfo ; | |
118 | } | |
119 | ||
0c03c79e | 120 | template<> const wxTypeInfo* wxGetTypeInfo( char * ) |
a095505c SC |
121 | { |
122 | static wxBuiltInTypeInfo s_typeInfo( wxT_CHAR ) ; | |
123 | return &s_typeInfo ; | |
124 | } | |
125 | ||
0c03c79e | 126 | template<> const wxTypeInfo* wxGetTypeInfo( unsigned char * ) |
a095505c SC |
127 | { |
128 | static wxBuiltInTypeInfo s_typeInfo( wxT_UCHAR ) ; | |
129 | return &s_typeInfo ; | |
130 | } | |
131 | ||
0c03c79e | 132 | template<> const wxTypeInfo* wxGetTypeInfo( int * ) |
a095505c SC |
133 | { |
134 | static wxBuiltInTypeInfo s_typeInfo( wxT_CHAR ) ; | |
135 | return &s_typeInfo ; | |
136 | } | |
137 | ||
0c03c79e | 138 | template<> const wxTypeInfo* wxGetTypeInfo( unsigned int * ) |
a095505c SC |
139 | { |
140 | static wxBuiltInTypeInfo s_typeInfo( wxT_UCHAR ) ; | |
141 | return &s_typeInfo ; | |
142 | } | |
143 | ||
0c03c79e | 144 | template<> const wxTypeInfo* wxGetTypeInfo( long * ) |
a095505c SC |
145 | { |
146 | static wxBuiltInTypeInfo s_typeInfo( wxT_CHAR ) ; | |
147 | return &s_typeInfo ; | |
148 | } | |
149 | ||
0c03c79e | 150 | template<> const wxTypeInfo* wxGetTypeInfo( unsigned long * ) |
a095505c SC |
151 | { |
152 | static wxBuiltInTypeInfo s_typeInfo( wxT_UCHAR ) ; | |
153 | return &s_typeInfo ; | |
154 | } | |
155 | ||
0c03c79e | 156 | template<> const wxTypeInfo* wxGetTypeInfo( float * ) |
a095505c SC |
157 | { |
158 | static wxBuiltInTypeInfo s_typeInfo( wxT_FLOAT ) ; | |
159 | return &s_typeInfo ; | |
160 | } | |
161 | ||
0c03c79e | 162 | template<> const wxTypeInfo* wxGetTypeInfo( double * ) |
a095505c SC |
163 | { |
164 | static wxBuiltInTypeInfo s_typeInfo( wxT_DOUBLE ) ; | |
165 | return &s_typeInfo ; | |
166 | } | |
167 | ||
0c03c79e | 168 | template<> const wxTypeInfo* wxGetTypeInfo( wxString * ) |
a095505c SC |
169 | { |
170 | static wxBuiltInTypeInfo s_typeInfo( wxT_STRING ) ; | |
171 | return &s_typeInfo ; | |
172 | } | |
173 | ||
ab6e4913 SC |
174 | template<> const wxTypeInfo* wxGetTypeInfo( wxWindowList * ) |
175 | { | |
176 | static wxCollectionTypeInfo s_typeInfo( (wxTypeInfo*) wxGetTypeInfo( (wxWindow **) NULL) ) ; | |
177 | return &s_typeInfo ; | |
178 | } | |
179 | ||
0c03c79e | 180 | // this are compiler induced specialization which are never used anywhere |
a095505c | 181 | |
16776ad9 SC |
182 | WX_ILLEGAL_TYPE_SPECIALIZATION( char const * ) |
183 | WX_ILLEGAL_TYPE_SPECIALIZATION( char * ) | |
184 | WX_ILLEGAL_TYPE_SPECIALIZATION( unsigned char * ) | |
185 | WX_ILLEGAL_TYPE_SPECIALIZATION( int * ) | |
186 | WX_ILLEGAL_TYPE_SPECIALIZATION( bool * ) | |
187 | WX_ILLEGAL_TYPE_SPECIALIZATION( long * ) | |
188 | WX_ILLEGAL_TYPE_SPECIALIZATION( wxString * ) | |
f0b7eadf | 189 | |
a095505c | 190 | // ---------------------------------------------------------------------------- |
30fd71e6 | 191 | // value streaming |
a095505c SC |
192 | // ---------------------------------------------------------------------------- |
193 | ||
a095505c | 194 | // streamer specializations |
45212047 | 195 | // for all built-in types |
a095505c | 196 | |
45212047 | 197 | // bool |
a095505c | 198 | |
45212047 SC |
199 | template<> void wxStringReadValue(const wxString &s , bool &data ) |
200 | { | |
201 | int intdata ; | |
202 | wxSscanf(s, _T("%d"), &intdata ) ; | |
203 | data = bool(intdata) ; | |
204 | } | |
a095505c | 205 | |
45212047 | 206 | template<> void wxStringWriteValue(wxString &s , const bool &data ) |
a095505c | 207 | { |
45212047 | 208 | s = wxString::Format("%d", data ) ; |
a095505c SC |
209 | } |
210 | ||
45212047 SC |
211 | // char |
212 | ||
213 | template<> void wxStringReadValue(const wxString &s , char &data ) | |
a095505c | 214 | { |
45212047 SC |
215 | int intdata ; |
216 | wxSscanf(s, _T("%d"), &intdata ) ; | |
217 | data = char(intdata) ; | |
218 | } | |
219 | ||
220 | template<> void wxStringWriteValue(wxString &s , const char &data ) | |
221 | { | |
222 | s = wxString::Format("%d", data ) ; | |
223 | } | |
224 | ||
225 | // unsigned char | |
226 | ||
227 | template<> void wxStringReadValue(const wxString &s , unsigned char &data ) | |
228 | { | |
229 | int intdata ; | |
230 | wxSscanf(s, _T("%d"), &intdata ) ; | |
66c57129 | 231 | data = (unsigned char)(intdata) ; |
45212047 SC |
232 | } |
233 | ||
234 | template<> void wxStringWriteValue(wxString &s , const unsigned char &data ) | |
235 | { | |
236 | s = wxString::Format("%d", data ) ; | |
a095505c SC |
237 | } |
238 | ||
30fd71e6 | 239 | // int |
a095505c | 240 | |
30fd71e6 | 241 | template<> void wxStringReadValue(const wxString &s , int &data ) |
a095505c SC |
242 | { |
243 | wxSscanf(s, _T("%d"), &data ) ; | |
244 | } | |
245 | ||
30fd71e6 | 246 | template<> void wxStringWriteValue(wxString &s , const int &data ) |
a095505c SC |
247 | { |
248 | s = wxString::Format("%d", data ) ; | |
249 | } | |
250 | ||
45212047 SC |
251 | // unsigned int |
252 | ||
253 | template<> void wxStringReadValue(const wxString &s , unsigned int &data ) | |
254 | { | |
255 | wxSscanf(s, _T("%d"), &data ) ; | |
256 | } | |
257 | ||
258 | template<> void wxStringWriteValue(wxString &s , const unsigned int &data ) | |
259 | { | |
260 | s = wxString::Format("%d", data ) ; | |
261 | } | |
262 | ||
263 | // long | |
264 | ||
265 | template<> void wxStringReadValue(const wxString &s , long &data ) | |
266 | { | |
267 | wxSscanf(s, _T("%ld"), &data ) ; | |
268 | } | |
269 | ||
270 | template<> void wxStringWriteValue(wxString &s , const long &data ) | |
271 | { | |
272 | s = wxString::Format("%ld", data ) ; | |
273 | } | |
274 | ||
275 | // unsigned long | |
276 | ||
277 | template<> void wxStringReadValue(const wxString &s , unsigned long &data ) | |
278 | { | |
279 | wxSscanf(s, _T("%ld"), &data ) ; | |
280 | } | |
281 | ||
282 | template<> void wxStringWriteValue(wxString &s , const unsigned long &data ) | |
283 | { | |
284 | s = wxString::Format("%ld", data ) ; | |
285 | } | |
286 | ||
287 | // float | |
288 | ||
289 | template<> void wxStringReadValue(const wxString &s , float &data ) | |
290 | { | |
291 | wxSscanf(s, _T("%f"), &data ) ; | |
292 | } | |
293 | ||
294 | template<> void wxStringWriteValue(wxString &s , const float &data ) | |
295 | { | |
296 | s = wxString::Format("%f", data ) ; | |
297 | } | |
298 | ||
299 | // double | |
300 | ||
301 | template<> void wxStringReadValue(const wxString &s , double &data ) | |
302 | { | |
303 | wxSscanf(s, _T("%lf"), &data ) ; | |
304 | } | |
305 | ||
306 | template<> void wxStringWriteValue(wxString &s , const double &data ) | |
307 | { | |
308 | s = wxString::Format("%lf", data ) ; | |
309 | } | |
310 | ||
a095505c SC |
311 | // wxString |
312 | ||
30fd71e6 | 313 | template<> void wxStringReadValue(const wxString &s , wxString &data ) |
a095505c SC |
314 | { |
315 | data = s ; | |
316 | } | |
317 | ||
30fd71e6 | 318 | template<> void wxStringWriteValue(wxString &s , const wxString &data ) |
a095505c SC |
319 | { |
320 | s = data ; | |
321 | } | |
322 | ||
323 | /* | |
324 | Custom Data Streaming / Type Infos | |
325 | we will have to add this for all wx non object types, but it is also an example | |
326 | for custom data structures | |
327 | */ | |
328 | ||
329 | // wxPoint | |
330 | ||
30fd71e6 | 331 | template<> void wxStringReadValue(const wxString &s , wxPoint &data ) |
a095505c SC |
332 | { |
333 | wxSscanf(s, _T("%d,%d"), &data.x , &data.y ) ; | |
334 | } | |
335 | ||
30fd71e6 | 336 | template<> void wxStringWriteValue(wxString &s , const wxPoint &data ) |
a095505c SC |
337 | { |
338 | s = wxString::Format("%d,%d", data.x , data.y ) ; | |
339 | } | |
340 | ||
f0b7eadf SC |
341 | template<> void wxStringReadValue(const wxString & , wxPoint* & ) |
342 | { | |
343 | assert(0) ; | |
344 | } | |
345 | ||
346 | template<> void wxStringWriteValue(wxString & , wxPoint* const & ) | |
347 | { | |
348 | assert(0) ; | |
349 | } | |
350 | ||
a095505c SC |
351 | WX_CUSTOM_TYPE_INFO(wxPoint) |
352 | ||
30fd71e6 | 353 | template<> void wxStringReadValue(const wxString &s , wxSize &data ) |
fbbdc52c SC |
354 | { |
355 | wxSscanf(s, _T("%d,%d"), &data.x , &data.y ) ; | |
356 | } | |
357 | ||
30fd71e6 | 358 | template<> void wxStringWriteValue(wxString &s , const wxSize &data ) |
fbbdc52c SC |
359 | { |
360 | s = wxString::Format("%d,%d", data.x , data.y ) ; | |
361 | } | |
362 | ||
f0b7eadf SC |
363 | template<> void wxStringReadValue(const wxString & , wxSize* & ) |
364 | { | |
365 | assert(0) ; | |
366 | } | |
367 | ||
368 | template<> void wxStringWriteValue(wxString & , wxSize * const & ) | |
369 | { | |
370 | assert(0) ; | |
371 | } | |
372 | ||
fbbdc52c SC |
373 | WX_CUSTOM_TYPE_INFO(wxSize) |
374 | ||
45212047 SC |
375 | /* |
376 | ||
377 | template<> void wxStringReadValue(const wxString &s , wxColour &data ) | |
378 | { | |
379 | // copied from VS xrc | |
380 | unsigned long tmp = 0; | |
381 | ||
382 | if (s.Length() != 7 || s[0u] != wxT('#') || | |
383 | wxSscanf(s.c_str(), wxT("#%lX"), &tmp) != 1) | |
384 | { | |
385 | wxLogError(_("String To Colour : Incorrect colour specification : %s"), | |
386 | s.c_str() ); | |
387 | data = wxNullColour; | |
388 | } | |
389 | else | |
390 | { | |
391 | data = wxColour((unsigned char) ((tmp & 0xFF0000) >> 16) , | |
392 | (unsigned char) ((tmp & 0x00FF00) >> 8), | |
393 | (unsigned char) ((tmp & 0x0000FF))); | |
394 | } | |
395 | } | |
396 | ||
397 | template<> void wxStringWriteValue(wxString &s , const wxColour &data ) | |
398 | { | |
399 | s = wxString::Format("#%2X%2X%2X", data.Red() , data.Green() , data.Blue() ) ; | |
400 | } | |
401 | ||
402 | WX_CUSTOM_TYPE_INFO(wxColour) | |
403 | ||
404 | */ | |
405 | ||
a095505c SC |
406 | // removing header dependancy on string tokenizer |
407 | ||
30fd71e6 | 408 | void wxSetStringToArray( const wxString &s , wxArrayString &array ) |
a095505c SC |
409 | { |
410 | wxStringTokenizer tokenizer(s, wxT("| \t\n"), wxTOKEN_STRTOK); | |
411 | wxString flag; | |
412 | array.Clear() ; | |
413 | while (tokenizer.HasMoreTokens()) | |
414 | { | |
415 | array.Add(tokenizer.GetNextToken()) ; | |
416 | } | |
417 | } | |
418 | ||
419 | // ---------------------------------------------------------------------------- | |
30fd71e6 | 420 | // wxClassInfo |
a095505c SC |
421 | // ---------------------------------------------------------------------------- |
422 | ||
2d51f067 | 423 | const wxPropertyAccessor *wxClassInfo::FindAccessor(const char *PropertyName) const |
a095505c | 424 | { |
fbbdc52c | 425 | const wxPropertyInfo* info = FindPropertyInfo( PropertyName ) ; |
30fd71e6 | 426 | |
a095505c SC |
427 | if ( info ) |
428 | return info->GetAccessor() ; | |
429 | ||
430 | return NULL ; | |
431 | } | |
432 | ||
2d51f067 | 433 | const wxPropertyInfo *wxClassInfo::FindPropertyInfoInThisClass (const char *PropertyName) const |
a095505c SC |
434 | { |
435 | const wxPropertyInfo* info = GetFirstProperty() ; | |
436 | ||
437 | while( info ) | |
438 | { | |
439 | if ( strcmp( info->GetName() , PropertyName ) == 0 ) | |
440 | return info ; | |
441 | info = info->GetNext() ; | |
442 | } | |
443 | ||
2d51f067 SC |
444 | return 0; |
445 | } | |
446 | ||
447 | const wxPropertyInfo *wxClassInfo::FindPropertyInfo (const char *PropertyName) const | |
448 | { | |
449 | const wxPropertyInfo* info = FindPropertyInfoInThisClass( PropertyName ) ; | |
450 | if ( info ) | |
451 | return info ; | |
452 | ||
a095505c SC |
453 | const wxClassInfo** parents = GetParents() ; |
454 | for ( int i = 0 ; parents[i] ; ++ i ) | |
455 | { | |
fbbdc52c | 456 | if ( ( info = parents[i]->FindPropertyInfo( PropertyName ) ) != NULL ) |
a095505c SC |
457 | return info ; |
458 | } | |
459 | ||
460 | return 0; | |
461 | } | |
462 | ||
2d51f067 | 463 | const wxHandlerInfo *wxClassInfo::FindHandlerInfoInThisClass (const char *PropertyName) const |
fbbdc52c SC |
464 | { |
465 | const wxHandlerInfo* info = GetFirstHandler() ; | |
466 | ||
467 | while( info ) | |
468 | { | |
469 | if ( strcmp( info->GetName() , PropertyName ) == 0 ) | |
470 | return info ; | |
471 | info = info->GetNext() ; | |
472 | } | |
473 | ||
2d51f067 SC |
474 | return 0; |
475 | } | |
476 | ||
477 | const wxHandlerInfo *wxClassInfo::FindHandlerInfo (const char *PropertyName) const | |
478 | { | |
479 | const wxHandlerInfo* info = FindHandlerInfoInThisClass( PropertyName ) ; | |
480 | ||
481 | if ( info ) | |
482 | return info ; | |
483 | ||
fbbdc52c SC |
484 | const wxClassInfo** parents = GetParents() ; |
485 | for ( int i = 0 ; parents[i] ; ++ i ) | |
486 | { | |
487 | if ( ( info = parents[i]->FindHandlerInfo( PropertyName ) ) != NULL ) | |
488 | return info ; | |
489 | } | |
490 | ||
491 | return 0; | |
492 | } | |
493 | ||
494 | ||
2d51f067 | 495 | void wxClassInfo::SetProperty(wxObject *object, const char *propertyName, const wxxVariant &value) const |
a095505c SC |
496 | { |
497 | const wxPropertyAccessor *accessor; | |
498 | ||
499 | accessor = FindAccessor(propertyName); | |
500 | wxASSERT(accessor->HasSetter()); | |
501 | accessor->SetProperty( object , value ) ; | |
502 | } | |
503 | ||
2d51f067 | 504 | wxxVariant wxClassInfo::GetProperty(wxObject *object, const char *propertyName) const |
a095505c SC |
505 | { |
506 | const wxPropertyAccessor *accessor; | |
507 | ||
508 | accessor = FindAccessor(propertyName); | |
509 | wxASSERT(accessor->HasGetter()); | |
510 | return accessor->GetProperty(object); | |
511 | } | |
512 | ||
ab6e4913 SC |
513 | wxxVariantArray wxClassInfo::GetPropertyCollection(wxObject *object, const wxChar *propertyName) const |
514 | { | |
515 | const wxPropertyAccessor *accessor; | |
516 | ||
517 | accessor = FindAccessor(propertyName); | |
518 | wxASSERT(accessor->HasGetter()); | |
519 | return accessor->GetPropertyCollection(object); | |
520 | } | |
521 | ||
16a45a23 | 522 | void wxClassInfo::AddToPropertyCollection(wxObject *object, const wxChar *propertyName , const wxxVariant& value) const |
ab6e4913 SC |
523 | { |
524 | const wxPropertyAccessor *accessor; | |
525 | ||
526 | accessor = FindAccessor(propertyName); | |
527 | wxASSERT(accessor->HasAdder()); | |
528 | accessor->AddToPropertyCollection( object , value ) ; | |
529 | } | |
530 | ||
a095505c SC |
531 | /* |
532 | VARIANT TO OBJECT | |
533 | */ | |
534 | ||
66c57129 | 535 | wxObject* wxxVariant::GetAsObject() |
a095505c SC |
536 | { |
537 | const wxClassTypeInfo *ti = dynamic_cast<const wxClassTypeInfo*>( m_data->GetTypeInfo() ) ; | |
538 | if ( ti ) | |
539 | return ti->GetClassInfo()->VariantToInstance(*this) ; | |
540 | else | |
541 | return NULL ; | |
542 | } | |
543 | ||
2d51f067 SC |
544 | // ---------------------------------------------------------------------------- |
545 | // wxDynamicObject support | |
546 | // ---------------------------------------------------------------------------- | |
547 | // | |
548 | // Dynamic Objects are objects that have a real superclass instance and carry their | |
549 | // own attributes in a hash map. Like this it is possible to create the objects and | |
550 | // stream them, as if their class information was already available from compiled data | |
551 | ||
552 | struct wxDynamicObject::wxDynamicObjectInternal | |
553 | { | |
554 | map<string,wxxVariant> m_properties ; | |
555 | } ; | |
556 | ||
557 | // instantiates this object with an instance of its superclass | |
558 | wxDynamicObject::wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info) | |
559 | { | |
560 | m_superClassInstance = superClassInstance ; | |
561 | m_classInfo = info ; | |
562 | m_data = new wxDynamicObjectInternal ; | |
563 | } | |
564 | ||
565 | wxDynamicObject::~wxDynamicObject() | |
566 | { | |
567 | delete m_data ; | |
568 | delete m_superClassInstance ; | |
569 | } | |
570 | ||
571 | void wxDynamicObject::SetProperty (const wxChar *propertyName, const wxxVariant &value) | |
572 | { | |
573 | wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(propertyName),wxT("Accessing Unknown Property in a Dynamic Object") ) ; | |
574 | m_data->m_properties[propertyName] = value ; | |
575 | } | |
576 | ||
577 | wxxVariant wxDynamicObject::GetProperty (const wxChar *propertyName) const | |
578 | { | |
579 | wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(propertyName),wxT("Accessing Unknown Property in a Dynamic Object") ) ; | |
580 | return m_data->m_properties[propertyName] ; | |
581 | } | |
582 | ||
583 | // ---------------------------------------------------------------------------- | |
584 | // wxDynamiClassInfo | |
585 | // ---------------------------------------------------------------------------- | |
586 | ||
587 | wxDynamicClassInfo::wxDynamicClassInfo( const wxChar *unitName, const wxChar *className , const wxClassInfo* superClass ) : | |
588 | wxClassInfo( unitName, className , new const wxClassInfo*[2]) | |
589 | { | |
590 | GetParents()[0] = superClass ; | |
591 | GetParents()[1] = NULL ; | |
592 | } | |
593 | ||
594 | wxDynamicClassInfo::~wxDynamicClassInfo() | |
595 | { | |
596 | delete[] GetParents() ; | |
597 | } | |
598 | ||
ab6e4913 | 599 | wxObject *wxDynamicClassInfo::AllocateObject() const |
2d51f067 | 600 | { |
ab6e4913 | 601 | wxObject* parent = GetParents()[0]->AllocateObject() ; |
2d51f067 SC |
602 | return new wxDynamicObject( parent , this ) ; |
603 | } | |
604 | ||
605 | void wxDynamicClassInfo::Create (wxObject *object, int paramCount, wxxVariant *params) const | |
606 | { | |
607 | wxDynamicObject *dynobj = dynamic_cast< wxDynamicObject *>( object ) ; | |
608 | wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::Create on an object other than wxDynamicObject") ) ; | |
609 | GetParents()[0]->Create( dynobj->GetSuperClassInstance() , paramCount , params ) ; | |
610 | } | |
611 | ||
612 | // get number of parameters for constructor | |
613 | int wxDynamicClassInfo::GetCreateParamCount() const | |
614 | { | |
615 | return GetParents()[0]->GetCreateParamCount() ; | |
616 | } | |
617 | ||
618 | // get i-th constructor parameter | |
619 | const wxChar* wxDynamicClassInfo::GetCreateParamName(int i) const | |
620 | { | |
621 | return GetParents()[0]->GetCreateParamName( i ) ; | |
622 | } | |
623 | ||
624 | void wxDynamicClassInfo::SetProperty(wxObject *object, const char *propertyName, const wxxVariant &value) const | |
625 | { | |
626 | wxDynamicObject* dynobj = dynamic_cast< wxDynamicObject * >( object ) ; | |
627 | wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ; | |
628 | if ( FindPropertyInfoInThisClass(propertyName) ) | |
629 | dynobj->SetProperty( propertyName , value ) ; | |
630 | else | |
631 | GetParents()[0]->SetProperty( dynobj->GetSuperClassInstance() , propertyName , value ) ; | |
632 | } | |
633 | ||
634 | wxxVariant wxDynamicClassInfo::GetProperty(wxObject *object, const char *propertyName) const | |
635 | { | |
636 | wxDynamicObject* dynobj = dynamic_cast< wxDynamicObject * >( object ) ; | |
637 | wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ; | |
638 | if ( FindPropertyInfoInThisClass(propertyName) ) | |
639 | return dynobj->GetProperty( propertyName ) ; | |
640 | else | |
641 | return GetParents()[0]->GetProperty( dynobj->GetSuperClassInstance() , propertyName ) ; | |
642 | } | |
643 | ||
644 | void wxDynamicClassInfo::AddProperty( const wxChar *propertyName , const wxTypeInfo* typeInfo ) | |
645 | { | |
ab6e4913 | 646 | new wxPropertyInfo( m_firstProperty , propertyName , typeInfo , new wxGenericPropertyAccessor( propertyName ) , wxxVariant() ) ; |
2d51f067 SC |
647 | } |
648 | ||
649 | void wxDynamicClassInfo::AddHandler( const wxChar *handlerName , wxObjectEventFunction address , const wxClassInfo* eventClassInfo ) | |
650 | { | |
651 | new wxHandlerInfo( m_firstHandler , handlerName , address , eventClassInfo ) ; | |
652 | } | |
653 | ||
654 | // ---------------------------------------------------------------------------- | |
655 | // wxGenericPropertyAccessor | |
656 | // ---------------------------------------------------------------------------- | |
657 | ||
658 | struct wxGenericPropertyAccessor::wxGenericPropertyAccessorInternal | |
659 | { | |
660 | wxString m_propertyName ; | |
661 | } ; | |
662 | ||
663 | wxGenericPropertyAccessor::wxGenericPropertyAccessor( const wxChar* propertyName ) | |
664 | { | |
665 | m_data = new wxGenericPropertyAccessorInternal ; | |
666 | m_data->m_propertyName = propertyName ; | |
667 | } | |
668 | ||
669 | wxGenericPropertyAccessor::~wxGenericPropertyAccessor() | |
670 | { | |
671 | delete m_data ; | |
672 | } | |
673 | void wxGenericPropertyAccessor::SetProperty(wxObject *object, const wxxVariant &value) const | |
674 | { | |
675 | wxDynamicObject* dynobj = dynamic_cast< wxDynamicObject * >( object ) ; | |
676 | wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ; | |
677 | dynobj->SetProperty(m_data->m_propertyName , value ) ; | |
678 | } | |
679 | ||
680 | wxxVariant wxGenericPropertyAccessor::GetProperty(const wxObject *object) const | |
681 | { | |
682 | const wxDynamicObject* dynobj = dynamic_cast< const wxDynamicObject * >( object ) ; | |
683 | wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ; | |
684 | return dynobj->GetProperty( m_data->m_propertyName ) ; | |
685 | } | |
686 | ||
687 | wxxVariant wxGenericPropertyAccessor::ReadValue( const wxString &value ) const | |
688 | { | |
689 | return wxxVariant(value) ; | |
690 | } | |
691 | ||
692 | void wxGenericPropertyAccessor::WriteValue( wxString& value , const wxObject *object ) const | |
693 | { | |
694 | const wxDynamicObject* dynobj = dynamic_cast< const wxDynamicObject * >( object ) ; | |
695 | wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ; | |
696 | wxxVariant val = dynobj->GetProperty( m_data->m_propertyName ) ; | |
697 | value = val.GetAsString() ; | |
698 | } | |
a095505c SC |
699 | |
700 | #endif |