unicode fixes
[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)
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)
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)
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 )
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 )
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 WX_ILLEGAL_TYPE_SPECIALIZATION( char const * )
259 WX_ILLEGAL_TYPE_SPECIALIZATION( char * )
260 WX_ILLEGAL_TYPE_SPECIALIZATION( unsigned char * )
261 WX_ILLEGAL_TYPE_SPECIALIZATION( int * )
262 WX_ILLEGAL_TYPE_SPECIALIZATION( bool * )
263 WX_ILLEGAL_TYPE_SPECIALIZATION( long * )
264 WX_ILLEGAL_TYPE_SPECIALIZATION( wxString * )
265
266 WX_COLLECTION_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 ;}
295
296 void wxTypeInfo::Register()
297 {
298 if ( sm_typeTable == NULL )
299 sm_typeTable = new wxTypeInfoMap() ;
300
301 if( !m_name.IsEmpty() )
302 (*sm_typeTable)[m_name] = this ;
303 }
304
305 void wxTypeInfo::Unregister()
306 {
307 if( !m_name.IsEmpty() )
308 sm_typeTable->erase(m_name);
309 }
310
311 // removing header dependancy on string tokenizer
312
313 void wxSetStringToArray( const wxString &s , wxArrayString &array )
314 {
315 wxStringTokenizer tokenizer(s, wxT("| \t\n"), wxTOKEN_STRTOK);
316 wxString flag;
317 array.Clear() ;
318 while (tokenizer.HasMoreTokens())
319 {
320 array.Add(tokenizer.GetNextToken()) ;
321 }
322 }
323
324 // ----------------------------------------------------------------------------
325 // wxClassInfo
326 // ----------------------------------------------------------------------------
327
328 wxPropertyInfo::~wxPropertyInfo()
329 {
330 if ( this == m_itsClass->m_firstProperty )
331 {
332 m_itsClass->m_firstProperty = m_next;
333 }
334 else
335 {
336 wxPropertyInfo *info = m_itsClass->m_firstProperty;
337 while (info)
338 {
339 if ( info->m_next == this )
340 {
341 info->m_next = m_next;
342 break;
343 }
344
345 info = info->m_next;
346 }
347 }
348 }
349
350 wxHandlerInfo::~wxHandlerInfo()
351 {
352 if ( this == m_itsClass->m_firstHandler )
353 {
354 m_itsClass->m_firstHandler = m_next;
355 }
356 else
357 {
358 wxHandlerInfo *info = m_itsClass->m_firstHandler;
359 while (info)
360 {
361 if ( info->m_next == this )
362 {
363 info->m_next = m_next;
364 break;
365 }
366
367 info = info->m_next;
368 }
369 }
370 }
371
372 const wxPropertyAccessor *wxClassInfo::FindAccessor(const wxChar *PropertyName) const
373 {
374 const wxPropertyInfo* info = FindPropertyInfo( PropertyName ) ;
375
376 if ( info )
377 return info->GetAccessor() ;
378
379 return NULL ;
380 }
381
382 wxPropertyInfo *wxClassInfo::FindPropertyInfoInThisClass (const wxChar *PropertyName) const
383 {
384 wxPropertyInfo* info = m_firstProperty ;
385
386 while( info )
387 {
388 if ( wxStrcmp( info->GetName() , PropertyName ) == 0 )
389 return info ;
390 info = info->GetNext() ;
391 }
392
393 return 0;
394 }
395
396 const wxPropertyInfo *wxClassInfo::FindPropertyInfo (const wxChar *PropertyName) const
397 {
398 const wxPropertyInfo* info = FindPropertyInfoInThisClass( PropertyName ) ;
399 if ( info )
400 return info ;
401
402 const wxClassInfo** parents = GetParents() ;
403 for ( int i = 0 ; parents[i] ; ++ i )
404 {
405 if ( ( info = parents[i]->FindPropertyInfo( PropertyName ) ) != NULL )
406 return info ;
407 }
408
409 return 0;
410 }
411
412 wxHandlerInfo *wxClassInfo::FindHandlerInfoInThisClass (const wxChar *PropertyName) const
413 {
414 wxHandlerInfo* info = m_firstHandler ;
415
416 while( info )
417 {
418 if ( wxStrcmp( info->GetName() , PropertyName ) == 0 )
419 return info ;
420 info = info->GetNext() ;
421 }
422
423 return 0;
424 }
425
426 const wxHandlerInfo *wxClassInfo::FindHandlerInfo (const wxChar *PropertyName) const
427 {
428 const wxHandlerInfo* info = FindHandlerInfoInThisClass( PropertyName ) ;
429
430 if ( info )
431 return info ;
432
433 const wxClassInfo** parents = GetParents() ;
434 for ( int i = 0 ; parents[i] ; ++ i )
435 {
436 if ( ( info = parents[i]->FindHandlerInfo( PropertyName ) ) != NULL )
437 return info ;
438 }
439
440 return 0;
441 }
442
443 wxObjectStreamingCallback wxClassInfo::GetStreamingCallback() const
444 {
445 if ( m_streamingCallback )
446 return m_streamingCallback ;
447
448 wxObjectStreamingCallback retval = NULL ;
449 const wxClassInfo** parents = GetParents() ;
450 for ( int i = 0 ; parents[i] && retval == NULL ; ++ i )
451 {
452 retval = parents[i]->GetStreamingCallback() ;
453 }
454 return retval ;
455 }
456
457 bool wxClassInfo::BeforeWriteObject( const wxObject *obj, wxWriter *streamer , wxPersister *persister , wxxVariantArray &metadata) const
458 {
459 wxObjectStreamingCallback sb = GetStreamingCallback() ;
460 if ( sb )
461 return (*sb)(obj , streamer , persister , metadata ) ;
462
463 return true ;
464 }
465
466 void wxClassInfo::SetProperty(wxObject *object, const wxChar *propertyName, const wxxVariant &value) const
467 {
468 const wxPropertyAccessor *accessor;
469
470 accessor = FindAccessor(propertyName);
471 wxASSERT(accessor->HasSetter());
472 accessor->SetProperty( object , value ) ;
473 }
474
475 wxxVariant wxClassInfo::GetProperty(wxObject *object, const wxChar *propertyName) const
476 {
477 const wxPropertyAccessor *accessor;
478
479 accessor = FindAccessor(propertyName);
480 wxASSERT(accessor->HasGetter());
481 wxxVariant result ;
482 accessor->GetProperty(object,result);
483 return result ;
484 }
485
486 wxxVariantArray wxClassInfo::GetPropertyCollection(wxObject *object, const wxChar *propertyName) const
487 {
488 const wxPropertyAccessor *accessor;
489
490 accessor = FindAccessor(propertyName);
491 wxASSERT(accessor->HasGetter());
492 wxxVariantArray result ;
493 accessor->GetPropertyCollection(object,result);
494 return result ;
495 }
496
497 void wxClassInfo::AddToPropertyCollection(wxObject *object, const wxChar *propertyName , const wxxVariant& value) const
498 {
499 const wxPropertyAccessor *accessor;
500
501 accessor = FindAccessor(propertyName);
502 wxASSERT(accessor->HasAdder());
503 accessor->AddToPropertyCollection( object , value ) ;
504 }
505
506 void wxClassInfo::GetProperties( wxPropertyInfoMap &map ) const
507 {
508 const wxPropertyInfo *pi = GetFirstProperty() ;
509 while( pi )
510 {
511 if ( map.find( pi->GetName() ) == map.end() )
512 map[pi->GetName()] = (wxPropertyInfo*) pi ;
513
514 pi = pi->GetNext() ;
515 }
516
517 const wxClassInfo** parents = GetParents() ;
518 for ( int i = 0 ; parents[i] ; ++ i )
519 {
520 parents[i]->GetProperties( map ) ;
521 }
522 }
523
524 /*
525 VARIANT TO OBJECT
526 */
527
528 wxObject* wxxVariant::GetAsObject()
529 {
530 const wxClassTypeInfo *ti = dynamic_cast<const wxClassTypeInfo*>( m_data->GetTypeInfo() ) ;
531 if ( ti )
532 return ti->GetClassInfo()->VariantToInstance(*this) ;
533 else
534 return NULL ;
535 }
536
537 // ----------------------------------------------------------------------------
538 // wxDynamicObject support
539 // ----------------------------------------------------------------------------
540 //
541 // Dynamic Objects are objects that have a real superclass instance and carry their
542 // own attributes in a hash map. Like this it is possible to create the objects and
543 // stream them, as if their class information was already available from compiled data
544
545 struct wxDynamicObject::wxDynamicObjectInternal
546 {
547 #if wxUSE_UNICODE
548 map<wstring,wxxVariant> m_properties ;
549 #else
550 map<string,wxxVariant> m_properties ;
551 #endif
552 } ;
553
554 // instantiates this object with an instance of its superclass
555 wxDynamicObject::wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info)
556 {
557 m_superClassInstance = superClassInstance ;
558 m_classInfo = info ;
559 m_data = new wxDynamicObjectInternal ;
560 }
561
562 wxDynamicObject::~wxDynamicObject()
563 {
564 delete m_data ;
565 delete m_superClassInstance ;
566 }
567
568 void wxDynamicObject::SetProperty (const wxChar *propertyName, const wxxVariant &value)
569 {
570 wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(propertyName),wxT("Accessing Unknown Property in a Dynamic Object") ) ;
571 m_data->m_properties[propertyName] = value ;
572 }
573
574 wxxVariant wxDynamicObject::GetProperty (const wxChar *propertyName) const
575 {
576 wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(propertyName),wxT("Accessing Unknown Property in a Dynamic Object") ) ;
577 return m_data->m_properties[propertyName] ;
578 }
579
580 // ----------------------------------------------------------------------------
581 // wxDynamiClassInfo
582 // ----------------------------------------------------------------------------
583
584 wxDynamicClassInfo::wxDynamicClassInfo( const wxChar *unitName, const wxChar *className , const wxClassInfo* superClass ) :
585 wxClassInfo( unitName, className , new const wxClassInfo*[2])
586 {
587 GetParents()[0] = superClass ;
588 GetParents()[1] = NULL ;
589 }
590
591 wxDynamicClassInfo::~wxDynamicClassInfo()
592 {
593 delete[] GetParents() ;
594 }
595
596 wxObject *wxDynamicClassInfo::AllocateObject() const
597 {
598 wxObject* parent = GetParents()[0]->AllocateObject() ;
599 return new wxDynamicObject( parent , this ) ;
600 }
601
602 void wxDynamicClassInfo::Create (wxObject *object, int paramCount, wxxVariant *params) const
603 {
604 wxDynamicObject *dynobj = dynamic_cast< wxDynamicObject *>( object ) ;
605 wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::Create on an object other than wxDynamicObject") ) ;
606 GetParents()[0]->Create( dynobj->GetSuperClassInstance() , paramCount , params ) ;
607 }
608
609 // get number of parameters for constructor
610 int wxDynamicClassInfo::GetCreateParamCount() const
611 {
612 return GetParents()[0]->GetCreateParamCount() ;
613 }
614
615 // get i-th constructor parameter
616 const wxChar* wxDynamicClassInfo::GetCreateParamName(int i) const
617 {
618 return GetParents()[0]->GetCreateParamName( i ) ;
619 }
620
621 void wxDynamicClassInfo::SetProperty(wxObject *object, const wxChar *propertyName, const wxxVariant &value) const
622 {
623 wxDynamicObject* dynobj = dynamic_cast< wxDynamicObject * >( object ) ;
624 wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ;
625 if ( FindPropertyInfoInThisClass(propertyName) )
626 dynobj->SetProperty( propertyName , value ) ;
627 else
628 GetParents()[0]->SetProperty( dynobj->GetSuperClassInstance() , propertyName , value ) ;
629 }
630
631 wxxVariant wxDynamicClassInfo::GetProperty(wxObject *object, const wxChar *propertyName) const
632 {
633 wxDynamicObject* dynobj = dynamic_cast< wxDynamicObject * >( object ) ;
634 wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ;
635 if ( FindPropertyInfoInThisClass(propertyName) )
636 return dynobj->GetProperty( propertyName ) ;
637 else
638 return GetParents()[0]->GetProperty( dynobj->GetSuperClassInstance() , propertyName ) ;
639 }
640
641 void wxDynamicClassInfo::AddProperty( const wxChar *propertyName , const wxTypeInfo* typeInfo )
642 {
643 new wxPropertyInfo( m_firstProperty , this , propertyName , typeInfo->GetTypeName() , new wxGenericPropertyAccessor( propertyName ) , wxxVariant() ) ;
644 }
645
646 void wxDynamicClassInfo::AddHandler( const wxChar *handlerName , wxObjectEventFunction address , const wxClassInfo* eventClassInfo )
647 {
648 new wxHandlerInfo( m_firstHandler , this , handlerName , address , eventClassInfo ) ;
649 }
650
651 // removes an existing runtime-property
652 void wxDynamicClassInfo::RemoveProperty( const wxChar *propertyName )
653 {
654 delete FindPropertyInfoInThisClass(propertyName) ;
655 }
656
657 // removes an existing runtime-handler
658 void wxDynamicClassInfo::RemoveHandler( const wxChar *handlerName )
659 {
660 delete FindHandlerInfoInThisClass(handlerName) ;
661 }
662
663 // renames an existing runtime-property
664 void wxDynamicClassInfo::RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName )
665 {
666 wxPropertyInfo* pi = FindPropertyInfoInThisClass(oldPropertyName) ;
667 wxASSERT_MSG( pi ,wxT("not existing property") ) ;
668 pi->m_name = newPropertyName ;
669 dynamic_cast<wxGenericPropertyAccessor*>(pi->GetAccessor())->RenameProperty( oldPropertyName , newPropertyName ) ;
670 }
671
672 // renames an existing runtime-handler
673 void wxDynamicClassInfo::RenameHandler( const wxChar *oldHandlerName , const wxChar *newHandlerName )
674 {
675 wxASSERT_MSG(FindHandlerInfoInThisClass(oldHandlerName),wxT("not existing handler") ) ;
676 FindHandlerInfoInThisClass(oldHandlerName)->m_name = newHandlerName ;
677 }
678
679 // ----------------------------------------------------------------------------
680 // wxGenericPropertyAccessor
681 // ----------------------------------------------------------------------------
682
683 struct wxGenericPropertyAccessor::wxGenericPropertyAccessorInternal
684 {
685 char filler ;
686 } ;
687
688 wxGenericPropertyAccessor::wxGenericPropertyAccessor( const wxString& propertyName )
689 : wxPropertyAccessor( NULL , NULL , NULL , NULL )
690 {
691 m_data = new wxGenericPropertyAccessorInternal ;
692 m_propertyName = propertyName ;
693 m_getterName = wxT("Get")+propertyName ;
694 m_setterName = wxT("Set")+propertyName ;
695 }
696
697 wxGenericPropertyAccessor::~wxGenericPropertyAccessor()
698 {
699 delete m_data ;
700 }
701 void wxGenericPropertyAccessor::SetProperty(wxObject *object, const wxxVariant &value) const
702 {
703 wxDynamicObject* dynobj = dynamic_cast< wxDynamicObject * >( object ) ;
704 wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ;
705 dynobj->SetProperty(m_propertyName , value ) ;
706 }
707
708 void wxGenericPropertyAccessor::GetProperty(const wxObject *object, wxxVariant& value) const
709 {
710 const wxDynamicObject* dynobj = dynamic_cast< const wxDynamicObject * >( object ) ;
711 wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ;
712 value = dynobj->GetProperty( m_propertyName ) ;
713 }
714 #endif