]> git.saurik.com Git - wxWidgets.git/blob - src/common/xti.cpp
blind compilation fix for wxUSE_STL==1 (bug 985662)
[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 #if wxUSE_FUNC_TEMPLATE_POINTER
246 #define wxBUILTIN_TYPE_INFO( element , type ) \
247 wxBuiltInTypeInfo s_typeInfo##type(element , &wxToStringConverter<type> , &wxFromStringConverter<type> , typeid(type).name()) ;
248 #else
249 #define wxBUILTIN_TYPE_INFO( element , type ) \
250 void _toString##element( const wxxVariant& data , wxString &result ) { wxToStringConverter<type>(data, result); } \
251 void _fromString##element( const wxString& data , wxxVariant &result ) { wxFromStringConverter<type>(data, result); } \
252 wxBuiltInTypeInfo s_typeInfo##type(element , &_toString##element , &_fromString##element , typeid(type).name()) ;
253 #endif
254
255 typedef unsigned char unsigned_char;
256 typedef unsigned int unsigned_int;
257 typedef unsigned long unsigned_long;
258
259 wxBuiltInTypeInfo s_typeInfovoid( wxT_VOID , NULL , NULL , typeid(void).name());
260 wxBUILTIN_TYPE_INFO( wxT_BOOL , bool);
261 wxBUILTIN_TYPE_INFO( wxT_CHAR , char);
262 wxBUILTIN_TYPE_INFO( wxT_UCHAR , unsigned_char);
263 wxBUILTIN_TYPE_INFO( wxT_INT , int);
264 wxBUILTIN_TYPE_INFO( wxT_UINT , unsigned_int);
265 wxBUILTIN_TYPE_INFO( wxT_LONG , long);
266 wxBUILTIN_TYPE_INFO( wxT_ULONG , unsigned_long);
267 wxBUILTIN_TYPE_INFO( wxT_FLOAT , float);
268 wxBUILTIN_TYPE_INFO( wxT_DOUBLE , double);
269 wxBUILTIN_TYPE_INFO( wxT_STRING , wxString);
270
271
272 // this are compiler induced specialization which are never used anywhere
273
274 wxILLEGAL_TYPE_SPECIALIZATION( char const * )
275 wxILLEGAL_TYPE_SPECIALIZATION( char * )
276 wxILLEGAL_TYPE_SPECIALIZATION( unsigned char * )
277 wxILLEGAL_TYPE_SPECIALIZATION( int * )
278 wxILLEGAL_TYPE_SPECIALIZATION( bool * )
279 wxILLEGAL_TYPE_SPECIALIZATION( long * )
280 wxILLEGAL_TYPE_SPECIALIZATION( wxString * )
281
282 wxCOLLECTION_TYPE_INFO( wxString , wxArrayString ) ;
283
284 template<> void wxCollectionToVariantArray( wxArrayString const &theArray, wxxVariantArray &value)
285 {
286 wxArrayCollectionToVariantArray( theArray , value ) ;
287 }
288
289 wxTypeInfoMap *wxTypeInfo::ms_typeTable = NULL ;
290
291 wxTypeInfo *wxTypeInfo::FindType(const wxChar *typeName)
292 {
293 wxTypeInfoMap::iterator iter = ms_typeTable->find(typeName) ;
294 wxASSERT_MSG( iter != ms_typeTable->end() , wxT("lookup for a non-existent type-info") ) ;
295 return (wxTypeInfo *)iter->second;
296 }
297
298 #if wxUSE_UNICODE
299 wxClassTypeInfo::wxClassTypeInfo( wxTypeKind kind , wxClassInfo* classInfo , converterToString_t to , converterFromString_t from , const char *name) :
300 wxTypeInfo( kind , to , from , name)
301 { wxASSERT_MSG( kind == wxT_OBJECT_PTR || kind == wxT_OBJECT , wxT("Illegal Kind for Enum Type")) ; m_classInfo = classInfo ;}
302 #endif
303
304 wxClassTypeInfo::wxClassTypeInfo( wxTypeKind kind , wxClassInfo* classInfo , converterToString_t to , converterFromString_t from , const wxString &name) :
305 wxTypeInfo( kind , to , from , name)
306 { wxASSERT_MSG( kind == wxT_OBJECT_PTR || kind == wxT_OBJECT , wxT("Illegal Kind for Enum Type")) ; m_classInfo = classInfo ;}
307
308 wxDelegateTypeInfo::wxDelegateTypeInfo( int eventType , wxClassInfo* eventClass , converterToString_t to , converterFromString_t from ) :
309 wxTypeInfo ( wxT_DELEGATE , to , from , wxEmptyString )
310 { m_eventClass = eventClass ; m_eventType = eventType ; m_lastEventType = -1 ;}
311
312 wxDelegateTypeInfo::wxDelegateTypeInfo( int eventType , int lastEventType , wxClassInfo* eventClass , converterToString_t to , converterFromString_t from ) :
313 wxTypeInfo ( wxT_DELEGATE , to , from , wxEmptyString )
314 { m_eventClass = eventClass ; m_eventType = eventType ; m_lastEventType = lastEventType; }
315
316 void wxTypeInfo::Register()
317 {
318 if ( ms_typeTable == NULL )
319 ms_typeTable = new wxTypeInfoMap() ;
320
321 if( !m_name.IsEmpty() )
322 (*ms_typeTable)[m_name] = this ;
323 }
324
325 void wxTypeInfo::Unregister()
326 {
327 if( !m_name.IsEmpty() )
328 ms_typeTable->erase(m_name);
329 }
330
331 // removing header dependancy on string tokenizer
332
333 void wxSetStringToArray( const wxString &s , wxArrayString &array )
334 {
335 wxStringTokenizer tokenizer(s, wxT("| \t\n"), wxTOKEN_STRTOK);
336 wxString flag;
337 array.Clear() ;
338 while (tokenizer.HasMoreTokens())
339 {
340 array.Add(tokenizer.GetNextToken()) ;
341 }
342 }
343
344 // ----------------------------------------------------------------------------
345 // wxClassInfo
346 // ----------------------------------------------------------------------------
347
348 wxPropertyInfo::~wxPropertyInfo()
349 {
350 if ( this == m_itsClass->m_firstProperty )
351 {
352 m_itsClass->m_firstProperty = m_next;
353 }
354 else
355 {
356 wxPropertyInfo *info = m_itsClass->m_firstProperty;
357 while (info)
358 {
359 if ( info->m_next == this )
360 {
361 info->m_next = m_next;
362 break;
363 }
364
365 info = info->m_next;
366 }
367 }
368 }
369
370 wxHandlerInfo::~wxHandlerInfo()
371 {
372 if ( this == m_itsClass->m_firstHandler )
373 {
374 m_itsClass->m_firstHandler = m_next;
375 }
376 else
377 {
378 wxHandlerInfo *info = m_itsClass->m_firstHandler;
379 while (info)
380 {
381 if ( info->m_next == this )
382 {
383 info->m_next = m_next;
384 break;
385 }
386
387 info = info->m_next;
388 }
389 }
390 }
391
392 const wxPropertyAccessor *wxClassInfo::FindAccessor(const wxChar *PropertyName) const
393 {
394 const wxPropertyInfo* info = FindPropertyInfo( PropertyName ) ;
395
396 if ( info )
397 return info->GetAccessor() ;
398
399 return NULL ;
400 }
401
402 wxPropertyInfo *wxClassInfo::FindPropertyInfoInThisClass (const wxChar *PropertyName) const
403 {
404 wxPropertyInfo* info = m_firstProperty ;
405
406 while( info )
407 {
408 if ( wxStrcmp( info->GetName() , PropertyName ) == 0 )
409 return info ;
410 info = info->GetNext() ;
411 }
412
413 return 0;
414 }
415
416 const wxPropertyInfo *wxClassInfo::FindPropertyInfo (const wxChar *PropertyName) const
417 {
418 const wxPropertyInfo* info = FindPropertyInfoInThisClass( PropertyName ) ;
419 if ( info )
420 return info ;
421
422 const wxClassInfo** parents = GetParents() ;
423 for ( int i = 0 ; parents[i] ; ++ i )
424 {
425 if ( ( info = parents[i]->FindPropertyInfo( PropertyName ) ) != NULL )
426 return info ;
427 }
428
429 return 0;
430 }
431
432 wxHandlerInfo *wxClassInfo::FindHandlerInfoInThisClass (const wxChar *PropertyName) const
433 {
434 wxHandlerInfo* info = m_firstHandler ;
435
436 while( info )
437 {
438 if ( wxStrcmp( info->GetName() , PropertyName ) == 0 )
439 return info ;
440 info = info->GetNext() ;
441 }
442
443 return 0;
444 }
445
446 const wxHandlerInfo *wxClassInfo::FindHandlerInfo (const wxChar *PropertyName) const
447 {
448 const wxHandlerInfo* info = FindHandlerInfoInThisClass( PropertyName ) ;
449
450 if ( info )
451 return info ;
452
453 const wxClassInfo** parents = GetParents() ;
454 for ( int i = 0 ; parents[i] ; ++ i )
455 {
456 if ( ( info = parents[i]->FindHandlerInfo( PropertyName ) ) != NULL )
457 return info ;
458 }
459
460 return 0;
461 }
462
463 wxObjectStreamingCallback wxClassInfo::GetStreamingCallback() const
464 {
465 if ( m_streamingCallback )
466 return m_streamingCallback ;
467
468 wxObjectStreamingCallback retval = NULL ;
469 const wxClassInfo** parents = GetParents() ;
470 for ( int i = 0 ; parents[i] && retval == NULL ; ++ i )
471 {
472 retval = parents[i]->GetStreamingCallback() ;
473 }
474 return retval ;
475 }
476
477 bool wxClassInfo::BeforeWriteObject( const wxObject *obj, wxWriter *streamer , wxPersister *persister , wxxVariantArray &metadata) const
478 {
479 wxObjectStreamingCallback sb = GetStreamingCallback() ;
480 if ( sb )
481 return (*sb)(obj , streamer , persister , metadata ) ;
482
483 return true ;
484 }
485
486 void wxClassInfo::SetProperty(wxObject *object, const wxChar *propertyName, const wxxVariant &value) const
487 {
488 const wxPropertyAccessor *accessor;
489
490 accessor = FindAccessor(propertyName);
491 wxASSERT(accessor->HasSetter());
492 accessor->SetProperty( object , value ) ;
493 }
494
495 wxxVariant wxClassInfo::GetProperty(wxObject *object, const wxChar *propertyName) const
496 {
497 const wxPropertyAccessor *accessor;
498
499 accessor = FindAccessor(propertyName);
500 wxASSERT(accessor->HasGetter());
501 wxxVariant result ;
502 accessor->GetProperty(object,result);
503 return result ;
504 }
505
506 wxxVariantArray wxClassInfo::GetPropertyCollection(wxObject *object, const wxChar *propertyName) const
507 {
508 const wxPropertyAccessor *accessor;
509
510 accessor = FindAccessor(propertyName);
511 wxASSERT(accessor->HasGetter());
512 wxxVariantArray result ;
513 accessor->GetPropertyCollection(object,result);
514 return result ;
515 }
516
517 void wxClassInfo::AddToPropertyCollection(wxObject *object, const wxChar *propertyName , const wxxVariant& value) const
518 {
519 const wxPropertyAccessor *accessor;
520
521 accessor = FindAccessor(propertyName);
522 wxASSERT(accessor->HasAdder());
523 accessor->AddToPropertyCollection( object , value ) ;
524 }
525
526 // void wxClassInfo::GetProperties( wxPropertyInfoMap &map ) const
527 // The map parameter (the name map that is) seems something special
528 // to MSVC and so we use a other name.
529 void wxClassInfo::GetProperties( wxPropertyInfoMap &infomap ) const
530 {
531 const wxPropertyInfo *pi = GetFirstProperty() ;
532 while( pi )
533 {
534 if ( infomap.find( pi->GetName() ) == infomap.end() )
535 infomap[pi->GetName()] = (wxPropertyInfo*) pi ;
536
537 pi = pi->GetNext() ;
538 }
539
540 const wxClassInfo** parents = GetParents() ;
541 for ( int i = 0 ; parents[i] ; ++ i )
542 {
543 parents[i]->GetProperties( infomap ) ;
544 }
545 }
546
547 /*
548 VARIANT TO OBJECT
549 */
550
551 wxObject* wxxVariant::GetAsObject()
552 {
553 const wxClassTypeInfo *ti = dynamic_cast<const wxClassTypeInfo*>( m_data->GetTypeInfo() ) ;
554 if ( ti )
555 return ti->GetClassInfo()->VariantToInstance(*this) ;
556 else
557 return NULL ;
558 }
559
560 // ----------------------------------------------------------------------------
561 // wxDynamicObject support
562 // ----------------------------------------------------------------------------
563 //
564 // Dynamic Objects are objects that have a real superclass instance and carry their
565 // own attributes in a hash map. Like this it is possible to create the objects and
566 // stream them, as if their class information was already available from compiled data
567
568 struct wxDynamicObject::wxDynamicObjectInternal
569 {
570 wxDynamicObjectInternal() {}
571
572 #if wxUSE_UNICODE
573 map<wstring,wxxVariant> m_properties ;
574 #else
575 map<string,wxxVariant> m_properties ;
576 #endif
577 } ;
578
579 typedef list< wxDynamicObject* > wxDynamicObjectList ;
580
581 struct wxDynamicClassInfo::wxDynamicClassInfoInternal
582 {
583 wxDynamicObjectList m_dynamicObjects ;
584 } ;
585
586 // instantiates this object with an instance of its superclass
587 wxDynamicObject::wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info)
588 {
589 m_superClassInstance = superClassInstance ;
590 m_classInfo = info ;
591 m_data = new wxDynamicObjectInternal ;
592 }
593
594 wxDynamicObject::~wxDynamicObject()
595 {
596 dynamic_cast<const wxDynamicClassInfo*>(m_classInfo)->m_data->m_dynamicObjects.remove( this ) ;
597 delete m_data ;
598 delete m_superClassInstance ;
599 }
600
601 void wxDynamicObject::SetProperty (const wxChar *propertyName, const wxxVariant &value)
602 {
603 wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(propertyName),wxT("Accessing Unknown Property in a Dynamic Object") ) ;
604 m_data->m_properties[propertyName] = value ;
605 }
606
607 wxxVariant wxDynamicObject::GetProperty (const wxChar *propertyName) const
608 {
609 wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(propertyName),wxT("Accessing Unknown Property in a Dynamic Object") ) ;
610 return m_data->m_properties[propertyName] ;
611 }
612
613 void wxDynamicObject::RemoveProperty( const wxChar *propertyName )
614 {
615 wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(propertyName),wxT("Removing Unknown Property in a Dynamic Object") ) ;
616 m_data->m_properties.erase( propertyName ) ;
617 }
618
619 void wxDynamicObject::RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName )
620 {
621 wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(oldPropertyName),wxT("Renaming Unknown Property in a Dynamic Object") ) ;
622 wxxVariant value = m_data->m_properties[oldPropertyName] ;
623 m_data->m_properties.erase( oldPropertyName ) ;
624 m_data->m_properties[newPropertyName] = value ;
625 }
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 m_data = new wxDynamicClassInfoInternal ;
638 }
639
640 wxDynamicClassInfo::~wxDynamicClassInfo()
641 {
642 delete[] GetParents() ;
643 delete m_data ;
644 }
645
646 wxObject *wxDynamicClassInfo::AllocateObject() const
647 {
648 wxObject* parent = GetParents()[0]->AllocateObject() ;
649 wxDynamicObject *obj = new wxDynamicObject( parent , this ) ;
650 m_data->m_dynamicObjects.push_back( obj ) ;
651 return obj ;
652 }
653
654 void wxDynamicClassInfo::Create (wxObject *object, int paramCount, wxxVariant *params) const
655 {
656 wxDynamicObject *dynobj = dynamic_cast< wxDynamicObject *>( object ) ;
657 wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::Create on an object other than wxDynamicObject") ) ;
658 GetParents()[0]->Create( dynobj->GetSuperClassInstance() , paramCount , params ) ;
659 }
660
661 // get number of parameters for constructor
662 int wxDynamicClassInfo::GetCreateParamCount() const
663 {
664 return GetParents()[0]->GetCreateParamCount() ;
665 }
666
667 // get i-th constructor parameter
668 const wxChar* wxDynamicClassInfo::GetCreateParamName(int i) const
669 {
670 return GetParents()[0]->GetCreateParamName( i ) ;
671 }
672
673 void wxDynamicClassInfo::SetProperty(wxObject *object, const wxChar *propertyName, 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 if ( FindPropertyInfoInThisClass(propertyName) )
678 dynobj->SetProperty( propertyName , value ) ;
679 else
680 GetParents()[0]->SetProperty( dynobj->GetSuperClassInstance() , propertyName , value ) ;
681 }
682
683 wxxVariant wxDynamicClassInfo::GetProperty(wxObject *object, const wxChar *propertyName) const
684 {
685 wxDynamicObject* dynobj = dynamic_cast< wxDynamicObject * >( object ) ;
686 wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ;
687 if ( FindPropertyInfoInThisClass(propertyName) )
688 return dynobj->GetProperty( propertyName ) ;
689 else
690 return GetParents()[0]->GetProperty( dynobj->GetSuperClassInstance() , propertyName ) ;
691 }
692
693 void wxDynamicClassInfo::AddProperty( const wxChar *propertyName , const wxTypeInfo* typeInfo )
694 {
695 new wxPropertyInfo( m_firstProperty , this , propertyName , typeInfo->GetTypeName() , new wxGenericPropertyAccessor( propertyName ) , wxxVariant() ) ;
696 }
697
698 void wxDynamicClassInfo::AddHandler( const wxChar *handlerName , wxObjectEventFunction address , const wxClassInfo* eventClassInfo )
699 {
700 new wxHandlerInfo( m_firstHandler , this , handlerName , address , eventClassInfo ) ;
701 }
702
703 // removes an existing runtime-property
704 void wxDynamicClassInfo::RemoveProperty( const wxChar *propertyName )
705 {
706 for ( wxDynamicObjectList::iterator iter = m_data->m_dynamicObjects.begin() ; iter != m_data->m_dynamicObjects.end() ; ++iter )
707 (*iter)->RemoveProperty( propertyName ) ;
708 delete FindPropertyInfoInThisClass(propertyName) ;
709 }
710
711 // removes an existing runtime-handler
712 void wxDynamicClassInfo::RemoveHandler( const wxChar *handlerName )
713 {
714 delete FindHandlerInfoInThisClass(handlerName) ;
715 }
716
717 // renames an existing runtime-property
718 void wxDynamicClassInfo::RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName )
719 {
720 wxPropertyInfo* pi = FindPropertyInfoInThisClass(oldPropertyName) ;
721 wxASSERT_MSG( pi ,wxT("not existing property") ) ;
722 pi->m_name = newPropertyName ;
723 dynamic_cast<wxGenericPropertyAccessor*>(pi->GetAccessor())->RenameProperty( oldPropertyName , newPropertyName ) ;
724 for ( wxDynamicObjectList::iterator iter = m_data->m_dynamicObjects.begin() ; iter != m_data->m_dynamicObjects.end() ; ++iter )
725 (*iter)->RenameProperty( oldPropertyName , newPropertyName ) ;
726 }
727
728 // renames an existing runtime-handler
729 void wxDynamicClassInfo::RenameHandler( const wxChar *oldHandlerName , const wxChar *newHandlerName )
730 {
731 wxASSERT_MSG(FindHandlerInfoInThisClass(oldHandlerName),wxT("not existing handler") ) ;
732 FindHandlerInfoInThisClass(oldHandlerName)->m_name = newHandlerName ;
733 }
734
735 // ----------------------------------------------------------------------------
736 // wxGenericPropertyAccessor
737 // ----------------------------------------------------------------------------
738
739 struct wxGenericPropertyAccessor::wxGenericPropertyAccessorInternal
740 {
741 char filler ;
742 } ;
743
744 wxGenericPropertyAccessor::wxGenericPropertyAccessor( const wxString& propertyName )
745 : wxPropertyAccessor( NULL , NULL , NULL , NULL )
746 {
747 m_data = new wxGenericPropertyAccessorInternal ;
748 m_propertyName = propertyName ;
749 m_getterName = wxT("Get")+propertyName ;
750 m_setterName = wxT("Set")+propertyName ;
751 }
752
753 wxGenericPropertyAccessor::~wxGenericPropertyAccessor()
754 {
755 delete m_data ;
756 }
757 void wxGenericPropertyAccessor::SetProperty(wxObject *object, const wxxVariant &value) const
758 {
759 wxDynamicObject* dynobj = dynamic_cast< wxDynamicObject * >( object ) ;
760 wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ;
761 dynobj->SetProperty(m_propertyName , value ) ;
762 }
763
764 void wxGenericPropertyAccessor::GetProperty(const wxObject *object, wxxVariant& value) const
765 {
766 const wxDynamicObject* dynobj = dynamic_cast< const wxDynamicObject * >( object ) ;
767 wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ;
768 value = dynobj->GetProperty( m_propertyName ) ;
769 }
770 #endif