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