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