]> git.saurik.com Git - wxWidgets.git/blame - src/common/xti.cpp
mac encodings support
[wxWidgets.git] / src / common / xti.cpp
CommitLineData
a095505c
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/common/xti.cpp
3// Purpose: runtime metadata information (extended class info
4// Author: Stefan Csomor
30fd71e6 5// Modified by:
a095505c
SC
6// Created: 27/07/03
7// RCS-ID: $Id$
8// Copyright: (c) 1997 Julian Smart
9// (c) 2003 Stefan Csomor
10// Licence: wxWindows licence
11/////////////////////////////////////////////////////////////////////////////
12
14f355c2 13#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
a095505c
SC
14#pragma implementation "xti.h"
15#endif
16
17// For compilers that support precompilation, includes "wx.h".
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
21#pragma hdrstop
22#endif
23
24#ifndef WX_PRECOMP
2abce515
SC
25#include "wx/hash.h"
26#include "wx/object.h"
a095505c
SC
27#endif
28
53b74313
JS
29#if wxUSE_EXTENDED_RTTI
30
31#include "wx/xti.h"
a095505c
SC
32#include "wx/xml/xml.h"
33#include "wx/tokenzr.h"
b8d5be01 34#include "wx/list.h"
a095505c
SC
35#include <string.h>
36
ab6e4913 37#include "wx/beforestd.h"
2d51f067
SC
38#include <map>
39#include <string>
8f2b1cfd 40#include <list>
ab6e4913 41#include "wx/afterstd.h"
2d51f067
SC
42
43using namespace std ;
44
a095505c
SC
45// ----------------------------------------------------------------------------
46// Enum Support
47// ----------------------------------------------------------------------------
48
30fd71e6 49wxEnumData::wxEnumData( wxEnumMemberData* data )
a095505c 50{
2abce515 51 m_members = data ;
a095505c 52 for ( m_count = 0; m_members[m_count].m_name ; m_count++)
2abce515 53 {} ;
a095505c
SC
54}
55
9a75ecf6 56bool wxEnumData::HasEnumMemberValue(const wxChar *name, int *value) const
a095505c
SC
57{
58 int i;
59 for (i = 0; m_members[i].m_name ; i++ )
2abce515 60 {
9dc6871e 61 if (!wxStrcmp(name, m_members[i].m_name))
2abce515
SC
62 {
63 if ( value )
64 *value = m_members[i].m_value;
65 return true ;
66 }
67 }
68 return false ;
a095505c
SC
69}
70
9a75ecf6 71int wxEnumData::GetEnumMemberValue(const wxChar *name) const
a095505c
SC
72{
73 int i;
74 for (i = 0; m_members[i].m_name ; i++ )
2abce515 75 {
9dc6871e 76 if (!wxStrcmp(name, m_members[i].m_name))
2abce515
SC
77 {
78 return m_members[i].m_value;
79 }
80 }
0c03c79e 81 return 0 ;
a095505c
SC
82}
83
9a75ecf6 84const wxChar *wxEnumData::GetEnumMemberName(int value) const
a095505c
SC
85{
86 int i;
87 for (i = 0; m_members[i].m_name ; i++)
2abce515
SC
88 if (value == m_members[i].m_value)
89 return m_members[i].m_name;
a095505c 90
2abce515 91 return wxT("") ;
a095505c
SC
92}
93
9a75ecf6 94int wxEnumData::GetEnumMemberValueByIndex( int idx ) const
a095505c 95{
2abce515
SC
96 // we should cache the count in order to avoid out-of-bounds errors
97 return m_members[idx].m_value ;
a095505c
SC
98}
99
9a75ecf6 100const wxChar * wxEnumData::GetEnumMemberNameByIndex( int idx ) const
a095505c 101{
2abce515
SC
102 // we should cache the count in order to avoid out-of-bounds errors
103 return m_members[idx].m_name ;
a095505c
SC
104}
105
106// ----------------------------------------------------------------------------
107// Type Information
108// ----------------------------------------------------------------------------
a095505c 109// ----------------------------------------------------------------------------
30fd71e6 110// value streaming
a095505c
SC
111// ----------------------------------------------------------------------------
112
a095505c 113// streamer specializations
45212047 114// for all built-in types
a095505c 115
45212047 116// bool
a095505c 117
45212047
SC
118template<> void wxStringReadValue(const wxString &s , bool &data )
119{
2abce515
SC
120 int intdata ;
121 wxSscanf(s, _T("%d"), &intdata ) ;
9a75ecf6 122 data = (bool)intdata ;
45212047 123}
a095505c 124
45212047 125template<> void wxStringWriteValue(wxString &s , const bool &data )
a095505c 126{
9dc6871e 127 s = wxString::Format(_T("%d"), data ) ;
a095505c
SC
128}
129
45212047
SC
130// char
131
132template<> void wxStringReadValue(const wxString &s , char &data )
a095505c 133{
2abce515
SC
134 int intdata ;
135 wxSscanf(s, _T("%d"), &intdata ) ;
136 data = char(intdata) ;
45212047
SC
137}
138
139template<> void wxStringWriteValue(wxString &s , const char &data )
140{
9dc6871e 141 s = wxString::Format(_T("%d"), data ) ;
45212047
SC
142}
143
144// unsigned char
145
146template<> void wxStringReadValue(const wxString &s , unsigned char &data )
147{
2abce515
SC
148 int intdata ;
149 wxSscanf(s, _T("%d"), &intdata ) ;
150 data = (unsigned char)(intdata) ;
45212047
SC
151}
152
153template<> void wxStringWriteValue(wxString &s , const unsigned char &data )
154{
9dc6871e 155 s = wxString::Format(_T("%d"), data ) ;
a095505c
SC
156}
157
30fd71e6 158// int
a095505c 159
30fd71e6 160template<> void wxStringReadValue(const wxString &s , int &data )
a095505c 161{
2abce515 162 wxSscanf(s, _T("%d"), &data ) ;
a095505c
SC
163}
164
30fd71e6 165template<> void wxStringWriteValue(wxString &s , const int &data )
a095505c 166{
9dc6871e 167 s = wxString::Format(_T("%d"), data ) ;
a095505c
SC
168}
169
45212047
SC
170// unsigned int
171
172template<> void wxStringReadValue(const wxString &s , unsigned int &data )
173{
2abce515 174 wxSscanf(s, _T("%d"), &data ) ;
45212047
SC
175}
176
177template<> void wxStringWriteValue(wxString &s , const unsigned int &data )
178{
9dc6871e 179 s = wxString::Format(_T("%d"), data ) ;
45212047
SC
180}
181
182// long
183
184template<> void wxStringReadValue(const wxString &s , long &data )
185{
2abce515 186 wxSscanf(s, _T("%ld"), &data ) ;
45212047
SC
187}
188
189template<> void wxStringWriteValue(wxString &s , const long &data )
190{
9dc6871e 191 s = wxString::Format(_T("%ld"), data ) ;
45212047
SC
192}
193
194// unsigned long
195
196template<> void wxStringReadValue(const wxString &s , unsigned long &data )
197{
2abce515 198 wxSscanf(s, _T("%ld"), &data ) ;
45212047
SC
199}
200
201template<> void wxStringWriteValue(wxString &s , const unsigned long &data )
202{
9dc6871e 203 s = wxString::Format(_T("%ld"), data ) ;
45212047
SC
204}
205
206// float
207
208template<> void wxStringReadValue(const wxString &s , float &data )
209{
2abce515 210 wxSscanf(s, _T("%f"), &data ) ;
45212047
SC
211}
212
213template<> void wxStringWriteValue(wxString &s , const float &data )
214{
9dc6871e 215 s = wxString::Format(_T("%f"), data ) ;
45212047
SC
216}
217
218// double
219
220template<> void wxStringReadValue(const wxString &s , double &data )
221{
2abce515 222 wxSscanf(s, _T("%lf"), &data ) ;
45212047
SC
223}
224
225template<> void wxStringWriteValue(wxString &s , const double &data )
226{
9dc6871e 227 s = wxString::Format(_T("%lf"), data ) ;
45212047
SC
228}
229
a095505c
SC
230// wxString
231
30fd71e6 232template<> void wxStringReadValue(const wxString &s , wxString &data )
a095505c 233{
2abce515 234 data = s ;
a095505c
SC
235}
236
30fd71e6 237template<> void wxStringWriteValue(wxString &s , const wxString &data )
a095505c 238{
2abce515 239 s = data ;
a095505c
SC
240}
241
c1d6d0f9
SC
242// built-ins
243//
b8d5be01 244
499a9a62
SC
245wxBuiltInTypeInfo s_typeInfovoid( wxT_VOID , NULL , NULL , typeid(void).name() ) ;
246wxBuiltInTypeInfo s_typeInfobool( wxT_BOOL , &wxToStringConverter<bool> , &wxFromStringConverter<bool>, typeid(bool).name()) ;
247wxBuiltInTypeInfo s_typeInfochar( wxT_CHAR , &wxToStringConverter<char> , &wxFromStringConverter<char>, typeid(char).name()) ;
248wxBuiltInTypeInfo s_typeInfounsignedchar( wxT_UCHAR , &wxToStringConverter< unsigned char > , &wxFromStringConverter<unsigned char>, typeid(unsigned char).name()) ;
249wxBuiltInTypeInfo s_typeInfoint( wxT_INT , &wxToStringConverter<int> , &wxFromStringConverter<int>, typeid(int).name()) ;
250wxBuiltInTypeInfo s_typeInfounsignedint( wxT_UINT , &wxToStringConverter<unsigned int> , &wxFromStringConverter<unsigned int>, typeid(unsigned int).name()) ;
251wxBuiltInTypeInfo s_typeInfolong( wxT_LONG , &wxToStringConverter<long> , &wxFromStringConverter<long>, typeid(long).name()) ;
252wxBuiltInTypeInfo s_typeInfounsignedlong( wxT_ULONG , &wxToStringConverter<unsigned long> , &wxFromStringConverter<unsigned long>, typeid(unsigned long).name()) ;
253wxBuiltInTypeInfo s_typeInfofloat( wxT_FLOAT , &wxToStringConverter<float> , &wxFromStringConverter<float>, typeid(float).name()) ;
254wxBuiltInTypeInfo s_typeInfodouble( wxT_DOUBLE , &wxToStringConverter<double> , &wxFromStringConverter<double>, typeid(double).name()) ;
255wxBuiltInTypeInfo s_typeInfowxString( wxT_STRING , &wxToStringConverter<wxString> , &wxFromStringConverter<wxString>, typeid(wxString).name()) ;
b8d5be01
SC
256
257// this are compiler induced specialization which are never used anywhere
258
8805dbab
SC
259wxILLEGAL_TYPE_SPECIALIZATION( char const * )
260wxILLEGAL_TYPE_SPECIALIZATION( char * )
261wxILLEGAL_TYPE_SPECIALIZATION( unsigned char * )
262wxILLEGAL_TYPE_SPECIALIZATION( int * )
263wxILLEGAL_TYPE_SPECIALIZATION( bool * )
264wxILLEGAL_TYPE_SPECIALIZATION( long * )
265wxILLEGAL_TYPE_SPECIALIZATION( wxString * )
b8d5be01 266
8805dbab 267wxCOLLECTION_TYPE_INFO( wxString , wxArrayString ) ;
b8d5be01
SC
268
269template<> void wxCollectionToVariantArray( wxArrayString const &theArray, wxxVariantArray &value)
270{
271 wxArrayCollectionToVariantArray( theArray , value ) ;
272}
273
05fa251a 274wxTypeInfoMap *wxTypeInfo::ms_typeTable = NULL ;
b8d5be01 275
cb73e600
SC
276wxTypeInfo *wxTypeInfo::FindType(const wxChar *typeName)
277{
05fa251a
SC
278 wxTypeInfoMap::iterator iter = ms_typeTable->find(typeName) ;
279 wxASSERT_MSG( iter != ms_typeTable->end() , wxT("lookup for a non-existent type-info") ) ;
499a9a62 280 return (wxTypeInfo *)iter->second;
cb73e600 281}
b8d5be01 282
b1f6de83 283#if wxUSE_UNICODE
9f6b8316 284wxClassTypeInfo::wxClassTypeInfo( wxTypeKind kind , wxClassInfo* classInfo , converterToString_t to , converterFromString_t from , const char *name) :
b1f6de83
SC
285wxTypeInfo( 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
499a9a62
SC
289wxClassTypeInfo::wxClassTypeInfo( wxTypeKind kind , wxClassInfo* classInfo , converterToString_t to , converterFromString_t from , const wxString &name) :
290wxTypeInfo( kind , to , from , name)
cb73e600 291{ wxASSERT_MSG( kind == wxT_OBJECT_PTR || kind == wxT_OBJECT , wxT("Illegal Kind for Enum Type")) ; m_classInfo = classInfo ;}
45212047 292
cb73e600 293wxDelegateTypeInfo::wxDelegateTypeInfo( int eventType , wxClassInfo* eventClass , converterToString_t to , converterFromString_t from ) :
2abce515 294wxTypeInfo ( wxT_DELEGATE , to , from , wxEmptyString )
8edb7cd5
SC
295{ m_eventClass = eventClass ; m_eventType = eventType ; m_lastEventType = -1 ;}
296
297wxDelegateTypeInfo::wxDelegateTypeInfo( int eventType , int lastEventType , wxClassInfo* eventClass , converterToString_t to , converterFromString_t from ) :
298wxTypeInfo ( wxT_DELEGATE , to , from , wxEmptyString )
299{ m_eventClass = eventClass ; m_eventType = eventType ; m_lastEventType = lastEventType; }
45212047 300
cb73e600
SC
301void wxTypeInfo::Register()
302{
05fa251a
SC
303 if ( ms_typeTable == NULL )
304 ms_typeTable = new wxTypeInfoMap() ;
45212047 305
cb73e600 306 if( !m_name.IsEmpty() )
05fa251a 307 (*ms_typeTable)[m_name] = this ;
45212047
SC
308}
309
cb73e600
SC
310void wxTypeInfo::Unregister()
311{
312 if( !m_name.IsEmpty() )
05fa251a 313 ms_typeTable->erase(m_name);
2abce515 314}
45212047 315
a095505c
SC
316// removing header dependancy on string tokenizer
317
30fd71e6 318void wxSetStringToArray( const wxString &s , wxArrayString &array )
a095505c
SC
319{
320 wxStringTokenizer tokenizer(s, wxT("| \t\n"), wxTOKEN_STRTOK);
321 wxString flag;
2abce515 322 array.Clear() ;
a095505c
SC
323 while (tokenizer.HasMoreTokens())
324 {
2abce515
SC
325 array.Add(tokenizer.GetNextToken()) ;
326 }
a095505c
SC
327}
328
329// ----------------------------------------------------------------------------
30fd71e6 330// wxClassInfo
a095505c
SC
331// ----------------------------------------------------------------------------
332
499a9a62
SC
333wxPropertyInfo::~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
355wxHandlerInfo::~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
9dc6871e 377const wxPropertyAccessor *wxClassInfo::FindAccessor(const wxChar *PropertyName) const
a095505c 378{
fbbdc52c 379 const wxPropertyInfo* info = FindPropertyInfo( PropertyName ) ;
30fd71e6 380
2abce515
SC
381 if ( info )
382 return info->GetAccessor() ;
a095505c 383
2abce515 384 return NULL ;
a095505c
SC
385}
386
9dc6871e 387wxPropertyInfo *wxClassInfo::FindPropertyInfoInThisClass (const wxChar *PropertyName) const
a095505c 388{
499a9a62 389 wxPropertyInfo* info = m_firstProperty ;
a095505c 390
2abce515
SC
391 while( info )
392 {
9dc6871e 393 if ( wxStrcmp( info->GetName() , PropertyName ) == 0 )
2abce515
SC
394 return info ;
395 info = info->GetNext() ;
396 }
a095505c 397
2d51f067
SC
398 return 0;
399}
400
9dc6871e 401const wxPropertyInfo *wxClassInfo::FindPropertyInfo (const wxChar *PropertyName) const
2d51f067 402{
2abce515 403 const wxPropertyInfo* info = FindPropertyInfoInThisClass( PropertyName ) ;
2d51f067
SC
404 if ( info )
405 return info ;
406
2abce515
SC
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 }
a095505c
SC
413
414 return 0;
415}
416
9dc6871e 417wxHandlerInfo *wxClassInfo::FindHandlerInfoInThisClass (const wxChar *PropertyName) const
fbbdc52c 418{
499a9a62 419 wxHandlerInfo* info = m_firstHandler ;
fbbdc52c 420
2abce515
SC
421 while( info )
422 {
9dc6871e 423 if ( wxStrcmp( info->GetName() , PropertyName ) == 0 )
2abce515
SC
424 return info ;
425 info = info->GetNext() ;
426 }
fbbdc52c 427
2d51f067
SC
428 return 0;
429}
430
9dc6871e 431const wxHandlerInfo *wxClassInfo::FindHandlerInfo (const wxChar *PropertyName) const
2d51f067 432{
2abce515 433 const wxHandlerInfo* info = FindHandlerInfoInThisClass( PropertyName ) ;
2d51f067
SC
434
435 if ( info )
436 return info ;
437
2abce515
SC
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 }
fbbdc52c
SC
444
445 return 0;
446}
447
9c8046dd
SC
448wxObjectStreamingCallback wxClassInfo::GetStreamingCallback() const
449{
450 if ( m_streamingCallback )
451 return m_streamingCallback ;
452
453 wxObjectStreamingCallback retval = NULL ;
2abce515 454 const wxClassInfo** parents = GetParents() ;
9c8046dd 455 for ( int i = 0 ; parents[i] && retval == NULL ; ++ i )
2abce515 456 {
9c8046dd 457 retval = parents[i]->GetStreamingCallback() ;
2abce515 458 }
9c8046dd
SC
459 return retval ;
460}
461
462bool 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}
fbbdc52c 470
9dc6871e 471void wxClassInfo::SetProperty(wxObject *object, const wxChar *propertyName, const wxxVariant &value) const
a095505c
SC
472{
473 const wxPropertyAccessor *accessor;
474
475 accessor = FindAccessor(propertyName);
476 wxASSERT(accessor->HasSetter());
2abce515 477 accessor->SetProperty( object , value ) ;
a095505c
SC
478}
479
9dc6871e 480wxxVariant wxClassInfo::GetProperty(wxObject *object, const wxChar *propertyName) const
a095505c
SC
481{
482 const wxPropertyAccessor *accessor;
483
484 accessor = FindAccessor(propertyName);
485 wxASSERT(accessor->HasGetter());
b8d5be01
SC
486 wxxVariant result ;
487 accessor->GetProperty(object,result);
488 return result ;
a095505c
SC
489}
490
b8d5be01 491wxxVariantArray wxClassInfo::GetPropertyCollection(wxObject *object, const wxChar *propertyName) const
ab6e4913
SC
492{
493 const wxPropertyAccessor *accessor;
494
495 accessor = FindAccessor(propertyName);
496 wxASSERT(accessor->HasGetter());
b8d5be01
SC
497 wxxVariantArray result ;
498 accessor->GetPropertyCollection(object,result);
499 return result ;
ab6e4913
SC
500}
501
b8d5be01 502void wxClassInfo::AddToPropertyCollection(wxObject *object, const wxChar *propertyName , const wxxVariant& value) const
ab6e4913
SC
503{
504 const wxPropertyAccessor *accessor;
505
506 accessor = FindAccessor(propertyName);
507 wxASSERT(accessor->HasAdder());
508 accessor->AddToPropertyCollection( object , value ) ;
509}
510
cb73e600
SC
511void 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
a095505c
SC
529/*
530VARIANT TO OBJECT
531*/
532
66c57129 533wxObject* wxxVariant::GetAsObject()
a095505c 534{
2abce515
SC
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 ;
a095505c
SC
540}
541
2d51f067
SC
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
550struct wxDynamicObject::wxDynamicObjectInternal
551{
8f2b1cfd
SC
552 wxDynamicObjectInternal() {}
553
67b283a9
JS
554#if wxUSE_UNICODE
555 map<wstring,wxxVariant> m_properties ;
556#else
2d51f067 557 map<string,wxxVariant> m_properties ;
67b283a9 558#endif
8f2b1cfd
SC
559} ;
560
561typedef list< wxDynamicObject* > wxDynamicObjectList ;
562
563struct wxDynamicClassInfo::wxDynamicClassInfoInternal
564{
565 wxDynamicObjectList m_dynamicObjects ;
2d51f067
SC
566} ;
567
568// instantiates this object with an instance of its superclass
b8d5be01 569wxDynamicObject::wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info)
2d51f067
SC
570{
571 m_superClassInstance = superClassInstance ;
572 m_classInfo = info ;
573 m_data = new wxDynamicObjectInternal ;
574}
575
576wxDynamicObject::~wxDynamicObject()
577{
8f2b1cfd 578 dynamic_cast<const wxDynamicClassInfo*>(m_classInfo)->m_data->m_dynamicObjects.remove( this ) ;
2d51f067
SC
579 delete m_data ;
580 delete m_superClassInstance ;
581}
582
583void wxDynamicObject::SetProperty (const wxChar *propertyName, const wxxVariant &value)
584{
585 wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(propertyName),wxT("Accessing Unknown Property in a Dynamic Object") ) ;
8f2b1cfd 586 m_data->m_properties[propertyName] = value ;
2d51f067
SC
587}
588
589wxxVariant wxDynamicObject::GetProperty (const wxChar *propertyName) const
590{
2abce515 591 wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(propertyName),wxT("Accessing Unknown Property in a Dynamic Object") ) ;
8f2b1cfd
SC
592 return m_data->m_properties[propertyName] ;
593}
594
595void 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 ) ;
2d51f067
SC
599}
600
8f2b1cfd
SC
601void 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
2d51f067
SC
610// ----------------------------------------------------------------------------
611// wxDynamiClassInfo
612// ----------------------------------------------------------------------------
613
614wxDynamicClassInfo::wxDynamicClassInfo( const wxChar *unitName, const wxChar *className , const wxClassInfo* superClass ) :
2abce515 615wxClassInfo( unitName, className , new const wxClassInfo*[2])
2d51f067
SC
616{
617 GetParents()[0] = superClass ;
618 GetParents()[1] = NULL ;
8f2b1cfd 619 m_data = new wxDynamicClassInfoInternal ;
2d51f067
SC
620}
621
622wxDynamicClassInfo::~wxDynamicClassInfo()
623{
624 delete[] GetParents() ;
8f2b1cfd 625 delete m_data ;
2d51f067
SC
626}
627
b8d5be01 628wxObject *wxDynamicClassInfo::AllocateObject() const
2d51f067 629{
ab6e4913 630 wxObject* parent = GetParents()[0]->AllocateObject() ;
8f2b1cfd
SC
631 wxDynamicObject *obj = new wxDynamicObject( parent , this ) ;
632 m_data->m_dynamicObjects.push_back( obj ) ;
633 return obj ;
2d51f067
SC
634}
635
b8d5be01 636void wxDynamicClassInfo::Create (wxObject *object, int paramCount, wxxVariant *params) const
2d51f067
SC
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
b8d5be01 644int wxDynamicClassInfo::GetCreateParamCount() const
2d51f067
SC
645{
646 return GetParents()[0]->GetCreateParamCount() ;
647}
648
649// get i-th constructor parameter
b8d5be01 650const wxChar* wxDynamicClassInfo::GetCreateParamName(int i) const
2d51f067
SC
651{
652 return GetParents()[0]->GetCreateParamName( i ) ;
653}
654
9dc6871e 655void wxDynamicClassInfo::SetProperty(wxObject *object, const wxChar *propertyName, const wxxVariant &value) const
2d51f067
SC
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
9dc6871e 665wxxVariant wxDynamicClassInfo::GetProperty(wxObject *object, const wxChar *propertyName) const
2d51f067
SC
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
b8d5be01 675void wxDynamicClassInfo::AddProperty( const wxChar *propertyName , const wxTypeInfo* typeInfo )
2d51f067 676{
499a9a62 677 new wxPropertyInfo( m_firstProperty , this , propertyName , typeInfo->GetTypeName() , new wxGenericPropertyAccessor( propertyName ) , wxxVariant() ) ;
2d51f067
SC
678}
679
b8d5be01 680void wxDynamicClassInfo::AddHandler( const wxChar *handlerName , wxObjectEventFunction address , const wxClassInfo* eventClassInfo )
2d51f067 681{
499a9a62 682 new wxHandlerInfo( m_firstHandler , this , handlerName , address , eventClassInfo ) ;
2d51f067
SC
683}
684
2abce515
SC
685// removes an existing runtime-property
686void wxDynamicClassInfo::RemoveProperty( const wxChar *propertyName )
687{
8f2b1cfd
SC
688 for ( wxDynamicObjectList::iterator iter = m_data->m_dynamicObjects.begin() ; iter != m_data->m_dynamicObjects.end() ; ++iter )
689 (*iter)->RemoveProperty( propertyName ) ;
499a9a62 690 delete FindPropertyInfoInThisClass(propertyName) ;
2abce515
SC
691}
692
693// removes an existing runtime-handler
694void wxDynamicClassInfo::RemoveHandler( const wxChar *handlerName )
695{
499a9a62
SC
696 delete FindHandlerInfoInThisClass(handlerName) ;
697}
698
699// renames an existing runtime-property
700void 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 ) ;
8f2b1cfd
SC
706 for ( wxDynamicObjectList::iterator iter = m_data->m_dynamicObjects.begin() ; iter != m_data->m_dynamicObjects.end() ; ++iter )
707 (*iter)->RenameProperty( oldPropertyName , newPropertyName ) ;
499a9a62
SC
708}
709
710// renames an existing runtime-handler
711void wxDynamicClassInfo::RenameHandler( const wxChar *oldHandlerName , const wxChar *newHandlerName )
712{
713 wxASSERT_MSG(FindHandlerInfoInThisClass(oldHandlerName),wxT("not existing handler") ) ;
714 FindHandlerInfoInThisClass(oldHandlerName)->m_name = newHandlerName ;
2abce515
SC
715}
716
2d51f067
SC
717// ----------------------------------------------------------------------------
718// wxGenericPropertyAccessor
719// ----------------------------------------------------------------------------
720
721struct wxGenericPropertyAccessor::wxGenericPropertyAccessorInternal
722{
b8d5be01 723 char filler ;
2d51f067
SC
724} ;
725
b8d5be01
SC
726wxGenericPropertyAccessor::wxGenericPropertyAccessor( const wxString& propertyName )
727: wxPropertyAccessor( NULL , NULL , NULL , NULL )
2d51f067
SC
728{
729 m_data = new wxGenericPropertyAccessorInternal ;
b8d5be01
SC
730 m_propertyName = propertyName ;
731 m_getterName = wxT("Get")+propertyName ;
732 m_setterName = wxT("Set")+propertyName ;
2d51f067
SC
733}
734
735wxGenericPropertyAccessor::~wxGenericPropertyAccessor()
736{
737 delete m_data ;
738}
b8d5be01 739void wxGenericPropertyAccessor::SetProperty(wxObject *object, const wxxVariant &value) const
2d51f067
SC
740{
741 wxDynamicObject* dynobj = dynamic_cast< wxDynamicObject * >( object ) ;
742 wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ;
b8d5be01 743 dynobj->SetProperty(m_propertyName , value ) ;
2d51f067
SC
744}
745
b8d5be01 746void wxGenericPropertyAccessor::GetProperty(const wxObject *object, wxxVariant& value) const
2d51f067
SC
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") ) ;
b8d5be01 750 value = dynobj->GetProperty( m_propertyName ) ;
2d51f067 751}
a095505c 752#endif