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