]> git.saurik.com Git - wxWidgets.git/blame - src/common/xti.cpp
fixed rounding errors in variable status bar panes widths computation (patch 1030021)
[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
65571936 10// Licence: wxWindows licence
a095505c
SC
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
af498247
VZ
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
255typedef unsigned char unsigned_char;
256typedef unsigned int unsigned_int;
257typedef unsigned long unsigned_long;
258
259wxBuiltInTypeInfo s_typeInfovoid( wxT_VOID , NULL , NULL , typeid(void).name());
260wxBUILTIN_TYPE_INFO( wxT_BOOL , bool);
261wxBUILTIN_TYPE_INFO( wxT_CHAR , char);
262wxBUILTIN_TYPE_INFO( wxT_UCHAR , unsigned_char);
263wxBUILTIN_TYPE_INFO( wxT_INT , int);
264wxBUILTIN_TYPE_INFO( wxT_UINT , unsigned_int);
265wxBUILTIN_TYPE_INFO( wxT_LONG , long);
266wxBUILTIN_TYPE_INFO( wxT_ULONG , unsigned_long);
267wxBUILTIN_TYPE_INFO( wxT_FLOAT , float);
268wxBUILTIN_TYPE_INFO( wxT_DOUBLE , double);
269wxBUILTIN_TYPE_INFO( wxT_STRING , wxString);
270
b8d5be01
SC
271
272// this are compiler induced specialization which are never used anywhere
273
8805dbab
SC
274wxILLEGAL_TYPE_SPECIALIZATION( char const * )
275wxILLEGAL_TYPE_SPECIALIZATION( char * )
276wxILLEGAL_TYPE_SPECIALIZATION( unsigned char * )
277wxILLEGAL_TYPE_SPECIALIZATION( int * )
278wxILLEGAL_TYPE_SPECIALIZATION( bool * )
279wxILLEGAL_TYPE_SPECIALIZATION( long * )
280wxILLEGAL_TYPE_SPECIALIZATION( wxString * )
b8d5be01 281
8805dbab 282wxCOLLECTION_TYPE_INFO( wxString , wxArrayString ) ;
b8d5be01
SC
283
284template<> void wxCollectionToVariantArray( wxArrayString const &theArray, wxxVariantArray &value)
285{
286 wxArrayCollectionToVariantArray( theArray , value ) ;
287}
288
05fa251a 289wxTypeInfoMap *wxTypeInfo::ms_typeTable = NULL ;
b8d5be01 290
cb73e600
SC
291wxTypeInfo *wxTypeInfo::FindType(const wxChar *typeName)
292{
05fa251a
SC
293 wxTypeInfoMap::iterator iter = ms_typeTable->find(typeName) ;
294 wxASSERT_MSG( iter != ms_typeTable->end() , wxT("lookup for a non-existent type-info") ) ;
499a9a62 295 return (wxTypeInfo *)iter->second;
cb73e600 296}
b8d5be01 297
b1f6de83 298#if wxUSE_UNICODE
9f6b8316 299wxClassTypeInfo::wxClassTypeInfo( wxTypeKind kind , wxClassInfo* classInfo , converterToString_t to , converterFromString_t from , const char *name) :
b1f6de83
SC
300wxTypeInfo( 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
499a9a62
SC
304wxClassTypeInfo::wxClassTypeInfo( wxTypeKind kind , wxClassInfo* classInfo , converterToString_t to , converterFromString_t from , const wxString &name) :
305wxTypeInfo( kind , to , from , name)
cb73e600 306{ wxASSERT_MSG( kind == wxT_OBJECT_PTR || kind == wxT_OBJECT , wxT("Illegal Kind for Enum Type")) ; m_classInfo = classInfo ;}
45212047 307
cb73e600 308wxDelegateTypeInfo::wxDelegateTypeInfo( int eventType , wxClassInfo* eventClass , converterToString_t to , converterFromString_t from ) :
2abce515 309wxTypeInfo ( wxT_DELEGATE , to , from , wxEmptyString )
8edb7cd5
SC
310{ m_eventClass = eventClass ; m_eventType = eventType ; m_lastEventType = -1 ;}
311
312wxDelegateTypeInfo::wxDelegateTypeInfo( int eventType , int lastEventType , wxClassInfo* eventClass , converterToString_t to , converterFromString_t from ) :
313wxTypeInfo ( wxT_DELEGATE , to , from , wxEmptyString )
314{ m_eventClass = eventClass ; m_eventType = eventType ; m_lastEventType = lastEventType; }
45212047 315
cb73e600
SC
316void wxTypeInfo::Register()
317{
05fa251a
SC
318 if ( ms_typeTable == NULL )
319 ms_typeTable = new wxTypeInfoMap() ;
45212047 320
cb73e600 321 if( !m_name.IsEmpty() )
05fa251a 322 (*ms_typeTable)[m_name] = this ;
45212047
SC
323}
324
cb73e600
SC
325void wxTypeInfo::Unregister()
326{
327 if( !m_name.IsEmpty() )
05fa251a 328 ms_typeTable->erase(m_name);
2abce515 329}
45212047 330
a095505c
SC
331// removing header dependancy on string tokenizer
332
30fd71e6 333void wxSetStringToArray( const wxString &s , wxArrayString &array )
a095505c
SC
334{
335 wxStringTokenizer tokenizer(s, wxT("| \t\n"), wxTOKEN_STRTOK);
336 wxString flag;
2abce515 337 array.Clear() ;
a095505c
SC
338 while (tokenizer.HasMoreTokens())
339 {
2abce515
SC
340 array.Add(tokenizer.GetNextToken()) ;
341 }
a095505c
SC
342}
343
344// ----------------------------------------------------------------------------
30fd71e6 345// wxClassInfo
a095505c
SC
346// ----------------------------------------------------------------------------
347
499a9a62
SC
348wxPropertyInfo::~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
370wxHandlerInfo::~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
9dc6871e 392const wxPropertyAccessor *wxClassInfo::FindAccessor(const wxChar *PropertyName) const
a095505c 393{
fbbdc52c 394 const wxPropertyInfo* info = FindPropertyInfo( PropertyName ) ;
30fd71e6 395
2abce515
SC
396 if ( info )
397 return info->GetAccessor() ;
a095505c 398
2abce515 399 return NULL ;
a095505c
SC
400}
401
9dc6871e 402wxPropertyInfo *wxClassInfo::FindPropertyInfoInThisClass (const wxChar *PropertyName) const
a095505c 403{
499a9a62 404 wxPropertyInfo* info = m_firstProperty ;
a095505c 405
2abce515
SC
406 while( info )
407 {
9dc6871e 408 if ( wxStrcmp( info->GetName() , PropertyName ) == 0 )
2abce515
SC
409 return info ;
410 info = info->GetNext() ;
411 }
a095505c 412
2d51f067
SC
413 return 0;
414}
415
9dc6871e 416const wxPropertyInfo *wxClassInfo::FindPropertyInfo (const wxChar *PropertyName) const
2d51f067 417{
2abce515 418 const wxPropertyInfo* info = FindPropertyInfoInThisClass( PropertyName ) ;
2d51f067
SC
419 if ( info )
420 return info ;
421
2abce515
SC
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 }
a095505c
SC
428
429 return 0;
430}
431
9dc6871e 432wxHandlerInfo *wxClassInfo::FindHandlerInfoInThisClass (const wxChar *PropertyName) const
fbbdc52c 433{
499a9a62 434 wxHandlerInfo* info = m_firstHandler ;
fbbdc52c 435
2abce515
SC
436 while( info )
437 {
9dc6871e 438 if ( wxStrcmp( info->GetName() , PropertyName ) == 0 )
2abce515
SC
439 return info ;
440 info = info->GetNext() ;
441 }
fbbdc52c 442
2d51f067
SC
443 return 0;
444}
445
9dc6871e 446const wxHandlerInfo *wxClassInfo::FindHandlerInfo (const wxChar *PropertyName) const
2d51f067 447{
2abce515 448 const wxHandlerInfo* info = FindHandlerInfoInThisClass( PropertyName ) ;
2d51f067
SC
449
450 if ( info )
451 return info ;
452
2abce515
SC
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 }
fbbdc52c
SC
459
460 return 0;
461}
462
9c8046dd
SC
463wxObjectStreamingCallback wxClassInfo::GetStreamingCallback() const
464{
465 if ( m_streamingCallback )
466 return m_streamingCallback ;
467
468 wxObjectStreamingCallback retval = NULL ;
2abce515 469 const wxClassInfo** parents = GetParents() ;
9c8046dd 470 for ( int i = 0 ; parents[i] && retval == NULL ; ++ i )
2abce515 471 {
9c8046dd 472 retval = parents[i]->GetStreamingCallback() ;
2abce515 473 }
9c8046dd
SC
474 return retval ;
475}
476
477bool 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}
fbbdc52c 485
9dc6871e 486void wxClassInfo::SetProperty(wxObject *object, const wxChar *propertyName, const wxxVariant &value) const
a095505c
SC
487{
488 const wxPropertyAccessor *accessor;
489
490 accessor = FindAccessor(propertyName);
491 wxASSERT(accessor->HasSetter());
2abce515 492 accessor->SetProperty( object , value ) ;
a095505c
SC
493}
494
9dc6871e 495wxxVariant wxClassInfo::GetProperty(wxObject *object, const wxChar *propertyName) const
a095505c
SC
496{
497 const wxPropertyAccessor *accessor;
498
499 accessor = FindAccessor(propertyName);
500 wxASSERT(accessor->HasGetter());
b8d5be01
SC
501 wxxVariant result ;
502 accessor->GetProperty(object,result);
503 return result ;
a095505c
SC
504}
505
b8d5be01 506wxxVariantArray wxClassInfo::GetPropertyCollection(wxObject *object, const wxChar *propertyName) const
ab6e4913
SC
507{
508 const wxPropertyAccessor *accessor;
509
510 accessor = FindAccessor(propertyName);
511 wxASSERT(accessor->HasGetter());
b8d5be01
SC
512 wxxVariantArray result ;
513 accessor->GetPropertyCollection(object,result);
514 return result ;
ab6e4913
SC
515}
516
b8d5be01 517void wxClassInfo::AddToPropertyCollection(wxObject *object, const wxChar *propertyName , const wxxVariant& value) const
ab6e4913
SC
518{
519 const wxPropertyAccessor *accessor;
520
521 accessor = FindAccessor(propertyName);
522 wxASSERT(accessor->HasAdder());
523 accessor->AddToPropertyCollection( object , value ) ;
524}
525
af498247
VZ
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.
529void wxClassInfo::GetProperties( wxPropertyInfoMap &infomap ) const
cb73e600
SC
530{
531 const wxPropertyInfo *pi = GetFirstProperty() ;
532 while( pi )
533 {
af498247
VZ
534 if ( infomap.find( pi->GetName() ) == infomap.end() )
535 infomap[pi->GetName()] = (wxPropertyInfo*) pi ;
cb73e600
SC
536
537 pi = pi->GetNext() ;
538 }
539
540 const wxClassInfo** parents = GetParents() ;
541 for ( int i = 0 ; parents[i] ; ++ i )
542 {
af498247 543 parents[i]->GetProperties( infomap ) ;
cb73e600
SC
544 }
545}
546
a095505c
SC
547/*
548VARIANT TO OBJECT
549*/
550
66c57129 551wxObject* wxxVariant::GetAsObject()
a095505c 552{
2abce515
SC
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 ;
a095505c
SC
558}
559
2d51f067
SC
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
568struct wxDynamicObject::wxDynamicObjectInternal
569{
8f2b1cfd
SC
570 wxDynamicObjectInternal() {}
571
67b283a9
JS
572#if wxUSE_UNICODE
573 map<wstring,wxxVariant> m_properties ;
574#else
2d51f067 575 map<string,wxxVariant> m_properties ;
67b283a9 576#endif
8f2b1cfd
SC
577} ;
578
579typedef list< wxDynamicObject* > wxDynamicObjectList ;
580
581struct wxDynamicClassInfo::wxDynamicClassInfoInternal
582{
583 wxDynamicObjectList m_dynamicObjects ;
2d51f067
SC
584} ;
585
586// instantiates this object with an instance of its superclass
b8d5be01 587wxDynamicObject::wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info)
2d51f067
SC
588{
589 m_superClassInstance = superClassInstance ;
590 m_classInfo = info ;
591 m_data = new wxDynamicObjectInternal ;
592}
593
594wxDynamicObject::~wxDynamicObject()
595{
8f2b1cfd 596 dynamic_cast<const wxDynamicClassInfo*>(m_classInfo)->m_data->m_dynamicObjects.remove( this ) ;
2d51f067
SC
597 delete m_data ;
598 delete m_superClassInstance ;
599}
600
601void wxDynamicObject::SetProperty (const wxChar *propertyName, const wxxVariant &value)
602{
603 wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(propertyName),wxT("Accessing Unknown Property in a Dynamic Object") ) ;
8f2b1cfd 604 m_data->m_properties[propertyName] = value ;
2d51f067
SC
605}
606
607wxxVariant wxDynamicObject::GetProperty (const wxChar *propertyName) const
608{
2abce515 609 wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(propertyName),wxT("Accessing Unknown Property in a Dynamic Object") ) ;
8f2b1cfd
SC
610 return m_data->m_properties[propertyName] ;
611}
612
613void 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 ) ;
2d51f067
SC
617}
618
8f2b1cfd
SC
619void 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
2d51f067
SC
628// ----------------------------------------------------------------------------
629// wxDynamiClassInfo
630// ----------------------------------------------------------------------------
631
632wxDynamicClassInfo::wxDynamicClassInfo( const wxChar *unitName, const wxChar *className , const wxClassInfo* superClass ) :
2abce515 633wxClassInfo( unitName, className , new const wxClassInfo*[2])
2d51f067
SC
634{
635 GetParents()[0] = superClass ;
636 GetParents()[1] = NULL ;
8f2b1cfd 637 m_data = new wxDynamicClassInfoInternal ;
2d51f067
SC
638}
639
640wxDynamicClassInfo::~wxDynamicClassInfo()
641{
642 delete[] GetParents() ;
8f2b1cfd 643 delete m_data ;
2d51f067
SC
644}
645
b8d5be01 646wxObject *wxDynamicClassInfo::AllocateObject() const
2d51f067 647{
ab6e4913 648 wxObject* parent = GetParents()[0]->AllocateObject() ;
8f2b1cfd
SC
649 wxDynamicObject *obj = new wxDynamicObject( parent , this ) ;
650 m_data->m_dynamicObjects.push_back( obj ) ;
651 return obj ;
2d51f067
SC
652}
653
b8d5be01 654void wxDynamicClassInfo::Create (wxObject *object, int paramCount, wxxVariant *params) const
2d51f067
SC
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
b8d5be01 662int wxDynamicClassInfo::GetCreateParamCount() const
2d51f067
SC
663{
664 return GetParents()[0]->GetCreateParamCount() ;
665}
666
667// get i-th constructor parameter
b8d5be01 668const wxChar* wxDynamicClassInfo::GetCreateParamName(int i) const
2d51f067
SC
669{
670 return GetParents()[0]->GetCreateParamName( i ) ;
671}
672
9dc6871e 673void wxDynamicClassInfo::SetProperty(wxObject *object, const wxChar *propertyName, const wxxVariant &value) const
2d51f067
SC
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
9dc6871e 683wxxVariant wxDynamicClassInfo::GetProperty(wxObject *object, const wxChar *propertyName) const
2d51f067
SC
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
b8d5be01 693void wxDynamicClassInfo::AddProperty( const wxChar *propertyName , const wxTypeInfo* typeInfo )
2d51f067 694{
499a9a62 695 new wxPropertyInfo( m_firstProperty , this , propertyName , typeInfo->GetTypeName() , new wxGenericPropertyAccessor( propertyName ) , wxxVariant() ) ;
2d51f067
SC
696}
697
b8d5be01 698void wxDynamicClassInfo::AddHandler( const wxChar *handlerName , wxObjectEventFunction address , const wxClassInfo* eventClassInfo )
2d51f067 699{
499a9a62 700 new wxHandlerInfo( m_firstHandler , this , handlerName , address , eventClassInfo ) ;
2d51f067
SC
701}
702
2abce515
SC
703// removes an existing runtime-property
704void wxDynamicClassInfo::RemoveProperty( const wxChar *propertyName )
705{
8f2b1cfd
SC
706 for ( wxDynamicObjectList::iterator iter = m_data->m_dynamicObjects.begin() ; iter != m_data->m_dynamicObjects.end() ; ++iter )
707 (*iter)->RemoveProperty( propertyName ) ;
499a9a62 708 delete FindPropertyInfoInThisClass(propertyName) ;
2abce515
SC
709}
710
711// removes an existing runtime-handler
712void wxDynamicClassInfo::RemoveHandler( const wxChar *handlerName )
713{
499a9a62
SC
714 delete FindHandlerInfoInThisClass(handlerName) ;
715}
716
717// renames an existing runtime-property
718void 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 ) ;
8f2b1cfd
SC
724 for ( wxDynamicObjectList::iterator iter = m_data->m_dynamicObjects.begin() ; iter != m_data->m_dynamicObjects.end() ; ++iter )
725 (*iter)->RenameProperty( oldPropertyName , newPropertyName ) ;
499a9a62
SC
726}
727
728// renames an existing runtime-handler
729void wxDynamicClassInfo::RenameHandler( const wxChar *oldHandlerName , const wxChar *newHandlerName )
730{
731 wxASSERT_MSG(FindHandlerInfoInThisClass(oldHandlerName),wxT("not existing handler") ) ;
732 FindHandlerInfoInThisClass(oldHandlerName)->m_name = newHandlerName ;
2abce515
SC
733}
734
2d51f067
SC
735// ----------------------------------------------------------------------------
736// wxGenericPropertyAccessor
737// ----------------------------------------------------------------------------
738
739struct wxGenericPropertyAccessor::wxGenericPropertyAccessorInternal
740{
b8d5be01 741 char filler ;
2d51f067
SC
742} ;
743
b8d5be01
SC
744wxGenericPropertyAccessor::wxGenericPropertyAccessor( const wxString& propertyName )
745: wxPropertyAccessor( NULL , NULL , NULL , NULL )
2d51f067
SC
746{
747 m_data = new wxGenericPropertyAccessorInternal ;
b8d5be01
SC
748 m_propertyName = propertyName ;
749 m_getterName = wxT("Get")+propertyName ;
750 m_setterName = wxT("Set")+propertyName ;
2d51f067
SC
751}
752
753wxGenericPropertyAccessor::~wxGenericPropertyAccessor()
754{
755 delete m_data ;
756}
b8d5be01 757void wxGenericPropertyAccessor::SetProperty(wxObject *object, const wxxVariant &value) const
2d51f067
SC
758{
759 wxDynamicObject* dynobj = dynamic_cast< wxDynamicObject * >( object ) ;
760 wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ;
b8d5be01 761 dynobj->SetProperty(m_propertyName , value ) ;
2d51f067
SC
762}
763
b8d5be01 764void wxGenericPropertyAccessor::GetProperty(const wxObject *object, wxxVariant& value) const
2d51f067
SC
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") ) ;
b8d5be01 768 value = dynobj->GetProperty( m_propertyName ) ;
2d51f067 769}
a095505c 770#endif