]> git.saurik.com Git - wxWidgets.git/blob - src/common/xtistrm.cpp
unicode fixes
[wxWidgets.git] / src / common / xtistrm.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/xtistrm.cpp
3 // Purpose: streaming runtime metadata information
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 27/07/03
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "xtistrm.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/hash.h"
25 #include "wx/object.h"
26 #endif
27
28 #include "wx/tokenzr.h"
29 #include "wx/txtstrm.h"
30 #include "wx/event.h"
31
32 #if wxUSE_EXTENDED_RTTI
33
34 #include "wx/xtistrm.h"
35
36 #include "wx/beforestd.h"
37 #include <map>
38 #include <vector>
39 #include <string>
40 #include "wx/afterstd.h"
41
42 using namespace std ;
43
44 struct wxWriter::wxWriterInternal
45 {
46 map< const wxObject* , int > m_writtenObjects ;
47 int m_nextId ;
48 } ;
49
50 wxWriter::wxWriter()
51 {
52 m_data = new wxWriterInternal ;
53 m_data->m_nextId = 0 ;
54 }
55
56 wxWriter::~wxWriter()
57 {
58 delete m_data ;
59 }
60
61 struct wxWriter::wxWriterInternalPropertiesData
62 {
63 char nothing ;
64 } ;
65
66 void wxWriter::ClearObjectContext()
67 {
68 delete m_data ;
69 m_data = new wxWriterInternal() ;
70 m_data->m_nextId = 0 ;
71 }
72
73 void wxWriter::WriteObject(const wxObject *object, const wxClassInfo *classInfo , wxPersister *persister , const wxString &name , wxxVariantArray &metadata )
74 {
75 DoBeginWriteTopLevelEntry( name ) ;
76 WriteObject( object , classInfo , persister , false , metadata) ;
77 DoEndWriteTopLevelEntry( name ) ;
78 }
79
80 void wxWriter::WriteObject(const wxObject *object, const wxClassInfo *classInfo , wxPersister *persister , bool isEmbedded, wxxVariantArray &metadata )
81 {
82 if ( !classInfo->BeforeWriteObject( object , this , persister , metadata) )
83 return ;
84
85 if ( persister->BeforeWriteObject( this , object , classInfo , metadata) )
86 {
87 if ( object == NULL )
88 DoWriteNullObject() ;
89 else if ( IsObjectKnown( object ) )
90 DoWriteRepeatedObject( GetObjectID(object) ) ;
91 else
92 {
93 int oid = m_data->m_nextId++ ;
94 if ( !isEmbedded )
95 m_data->m_writtenObjects[object] = oid ;
96
97 // in case this object is a wxDynamicObject we also have to insert is superclass
98 // instance with the same id, so that object relations are streamed out correctly
99 const wxDynamicObject* dynobj = dynamic_cast<const wxDynamicObject *>( object ) ;
100 if ( !isEmbedded && dynobj )
101 m_data->m_writtenObjects[dynobj->GetSuperClassInstance()] = oid ;
102
103 DoBeginWriteObject( object , classInfo , oid , metadata ) ;
104 wxWriterInternalPropertiesData data ;
105 WriteAllProperties( object , classInfo , persister , &data ) ;
106 DoEndWriteObject( object , classInfo , oid ) ;
107 }
108 persister->AfterWriteObject( this ,object , classInfo ) ;
109 }
110 }
111
112 void wxWriter::FindConnectEntry(const wxEvtHandler * evSource,const wxDelegateTypeInfo* dti, const wxObject* &sink , const wxHandlerInfo *&handler)
113 {
114 wxList *dynamicEvents = evSource->GetDynamicEventTable() ;
115
116 if ( dynamicEvents )
117 {
118 wxList::compatibility_iterator node = dynamicEvents->GetFirst();
119 while (node)
120 {
121 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
122
123 // find the match
124 if ( entry->m_fn &&
125 (dti->GetEventType() == entry->m_eventType) &&
126 (entry->m_id == -1 ) &&
127 (entry->m_eventSink != NULL ) )
128 {
129 sink = entry->m_eventSink ;
130 const wxClassInfo* sinkClassInfo = sink->GetClassInfo() ;
131 const wxHandlerInfo* sinkHandler = sinkClassInfo->GetFirstHandler() ;
132 while ( sinkHandler )
133 {
134 if ( sinkHandler->GetEventFunction() == entry->m_fn )
135 {
136 handler = sinkHandler ;
137 break ;
138 }
139 sinkHandler = sinkHandler->GetNext() ;
140 }
141 break ;
142 }
143 node = node->GetNext();
144 }
145 }
146 }
147 void wxWriter::WriteAllProperties( const wxObject * obj , const wxClassInfo* ci , wxPersister *persister, wxWriterInternalPropertiesData * data )
148 {
149 wxPropertyInfoMap map ;
150 ci->GetProperties( map ) ;
151 for ( int i = 0 ; i < ci->GetCreateParamCount() ; ++i )
152 {
153 wxString name = ci->GetCreateParamName(i) ;
154 const wxPropertyInfo* prop = map.find(name)->second ;
155 wxASSERT_MSG( prop , wxT("Create Parameter not found in declared RTTI Parameters") ) ;
156 WriteOneProperty( obj , prop->GetDeclaringClass() , prop , persister , data ) ;
157 map.erase( name ) ;
158 }
159
160 for( wxPropertyInfoMap::iterator iter = map.begin() ; iter != map.end() ; ++iter )
161 {
162 const wxPropertyInfo* prop = iter->second ;
163 if ( prop->GetFlags() & wxPROP_OBJECT_GRAPH )
164 {
165 WriteOneProperty( obj , prop->GetDeclaringClass() , prop , persister , data ) ;
166 }
167 }
168
169 for( wxPropertyInfoMap::iterator iter = map.begin() ; iter != map.end() ; ++iter )
170 {
171 const wxPropertyInfo* prop = iter->second ;
172 if ( !(prop->GetFlags() & wxPROP_OBJECT_GRAPH) )
173 {
174 WriteOneProperty( obj , prop->GetDeclaringClass() , prop , persister , data ) ;
175 }
176 }
177 }
178
179 void wxWriter::WriteOneProperty( const wxObject *obj , const wxClassInfo* ci , const wxPropertyInfo* pi , wxPersister *persister , wxWriterInternalPropertiesData *WXUNUSED(data) )
180 {
181 if ( pi->GetFlags() & wxPROP_DONT_STREAM )
182 return ;
183
184 // make sure that we are picking the correct object for accessing the property
185 const wxDynamicObject* dynobj = dynamic_cast< const wxDynamicObject* > (obj ) ;
186 if ( dynobj && (dynamic_cast<const wxDynamicClassInfo*>(ci) == NULL) )
187 obj = dynobj->GetSuperClassInstance() ;
188
189 if ( pi->GetTypeInfo()->GetKind() == wxT_COLLECTION )
190 {
191 wxxVariantArray data ;
192 pi->GetAccessor()->GetPropertyCollection(obj, data) ;
193 const wxTypeInfo * elementType = dynamic_cast< const wxCollectionTypeInfo* >( pi->GetTypeInfo() )->GetElementType() ;
194 for ( size_t i = 0 ; i < data.GetCount() ; ++i )
195 {
196 if ( i == 0 )
197 DoBeginWriteProperty( pi ) ;
198
199 DoBeginWriteElement() ;
200 wxxVariant value = data[i] ;
201 if ( persister->BeforeWriteProperty( this , pi , value ) )
202 {
203 const wxClassTypeInfo* cti = dynamic_cast< const wxClassTypeInfo* > ( elementType ) ;
204 if ( cti )
205 {
206 const wxClassInfo* pci = cti->GetClassInfo() ;
207 wxObject *vobj = pci->VariantToInstance( value ) ;
208 wxxVariantArray md ;
209 WriteObject( vobj , (vobj ? vobj->GetClassInfo() : pci ) , persister , cti->GetKind()== wxT_OBJECT , md ) ;
210 }
211 else
212 {
213 DoWriteSimpleType( value ) ;
214 }
215 }
216 DoEndWriteElement() ;
217 if ( i == data.GetCount() - 1 )
218 DoEndWriteProperty( pi ) ;
219 }
220 }
221 else
222 {
223 const wxDelegateTypeInfo* dti = dynamic_cast< const wxDelegateTypeInfo* > ( pi->GetTypeInfo() ) ;
224 if ( dti )
225 {
226 const wxObject* sink = NULL ;
227 const wxHandlerInfo *handler = NULL ;
228
229 const wxEvtHandler * evSource = dynamic_cast<const wxEvtHandler *>(obj) ;
230 wxASSERT_MSG( evSource , wxT("Illegal Object Class (Non-wxEvtHandler) as Event Source") ) ;
231
232 FindConnectEntry( evSource , dti , sink , handler ) ;
233 if ( persister->BeforeWriteDelegate( this , obj , ci , pi , sink , handler ) )
234 {
235 if ( sink != NULL && handler != NULL )
236 {
237 DoBeginWriteProperty( pi ) ;
238 wxASSERT_MSG( IsObjectKnown( sink ) , wxT("Streaming delegates for not already streamed objects not yet supported") ) ;
239 DoWriteDelegate( obj , ci , pi , sink , GetObjectID( sink ) , sink->GetClassInfo() , handler ) ;
240 DoEndWriteProperty( pi ) ;
241 }
242 }
243 }
244 else
245 {
246 wxxVariant value ;
247 pi->GetAccessor()->GetProperty(obj, value) ;
248
249 // avoid streaming out void objects
250 if( value.IsEmpty() )
251 return ;
252
253 if ( pi->GetFlags() & wxPROP_ENUM_STORE_LONG )
254 {
255 const wxEnumTypeInfo *eti = dynamic_cast<const wxEnumTypeInfo*>( pi->GetTypeInfo() ) ;
256 wxASSERT_MSG( eti , wxT("Type must have enum - long conversion") ) ;
257 eti->ConvertFromLong( value.Get<long>() , value ) ;
258 }
259
260 // avoid streaming out default values
261 if ( pi->GetTypeInfo()->HasStringConverters() && !pi->GetDefaultValue().IsEmpty() )
262 {
263 if ( value.GetAsString() == pi->GetDefaultValue().GetAsString() )
264 return ;
265 }
266
267 // avoid streaming out null objects
268 const wxClassTypeInfo* cti = dynamic_cast< const wxClassTypeInfo* > ( pi->GetTypeInfo() ) ;
269
270 if ( cti && value.GetAsObject() == NULL )
271 return ;
272
273 if ( persister->BeforeWriteProperty( this , pi , value ) )
274 {
275 DoBeginWriteProperty( pi ) ;
276 if ( cti )
277 {
278 const wxClassInfo* pci = cti->GetClassInfo() ;
279 wxObject *vobj = pci->VariantToInstance( value ) ;
280 if ( vobj && pi->GetTypeInfo()->HasStringConverters() )
281 {
282 wxString stringValue ;
283 cti->ConvertToString( value , stringValue ) ;
284 wxxVariant convertedValue(stringValue) ;
285 DoWriteSimpleType( convertedValue ) ;
286 }
287 else
288 {
289 wxxVariantArray md ;
290 WriteObject( vobj , (vobj ? vobj->GetClassInfo() : pci ) , persister , cti->GetKind()== wxT_OBJECT , md) ;
291 }
292 }
293 else
294 {
295 DoWriteSimpleType( value ) ;
296 }
297 DoEndWriteProperty( pi ) ;
298 }
299 }
300 }
301 }
302
303 int wxWriter::GetObjectID(const wxObject *obj)
304 {
305 if ( !IsObjectKnown( obj ) )
306 return wxInvalidObjectID ;
307
308 return m_data->m_writtenObjects[obj] ;
309 }
310
311 bool wxWriter::IsObjectKnown( const wxObject *obj )
312 {
313 return m_data->m_writtenObjects.find( obj ) != m_data->m_writtenObjects.end() ;
314 }
315
316
317 // ----------------------------------------------------------------------------
318 // reading objects in
319 // ----------------------------------------------------------------------------
320
321 struct wxReader::wxReaderInternal
322 {
323 map<int,wxClassInfo*> m_classInfos;
324 };
325
326 wxReader::wxReader()
327 {
328 m_data = new wxReaderInternal;
329 }
330
331 wxReader::~wxReader()
332 {
333 delete m_data;
334 }
335
336 wxClassInfo* wxReader::GetObjectClassInfo(int objectID)
337 {
338 assert( m_data->m_classInfos.find(objectID) != m_data->m_classInfos.end() );
339 return m_data->m_classInfos[objectID] ;
340 }
341
342 void wxReader::SetObjectClassInfo(int objectID, wxClassInfo *classInfo )
343 {
344 assert( m_data->m_classInfos.find(objectID) == m_data->m_classInfos.end() ) ;
345 m_data->m_classInfos[objectID] = classInfo ;
346 }
347
348 bool wxReader::HasObjectClassInfo( int objectID )
349 {
350 return m_data->m_classInfos.find(objectID) != m_data->m_classInfos.end() ;
351 }
352
353
354 // ----------------------------------------------------------------------------
355 // reading xml in
356 // ----------------------------------------------------------------------------
357
358 /*
359 Reading components has not to be extended for components
360 as properties are always sought by typeinfo over all levels
361 and create params are always toplevel class only
362 */
363
364
365 // ----------------------------------------------------------------------------
366 // depersisting to memory
367 // ----------------------------------------------------------------------------
368
369 struct wxRuntimeDepersister::wxRuntimeDepersisterInternal
370 {
371 map<int,wxObject *> m_objects;
372
373 void SetObject(int objectID, wxObject *obj )
374 {
375 assert( m_objects.find(objectID) == m_objects.end() ) ;
376 m_objects[objectID] = obj ;
377 }
378 wxObject* GetObject( int objectID )
379 {
380 if ( objectID == wxNullObjectID )
381 return NULL ;
382
383 assert( m_objects.find(objectID) != m_objects.end() ) ;
384 return m_objects[objectID] ;
385 }
386 } ;
387
388 wxRuntimeDepersister::wxRuntimeDepersister()
389 {
390 m_data = new wxRuntimeDepersisterInternal() ;
391 }
392
393 wxRuntimeDepersister::~wxRuntimeDepersister()
394 {
395 delete m_data ;
396 }
397
398 void wxRuntimeDepersister::AllocateObject(int objectID, wxClassInfo *classInfo ,
399 wxxVariantArray &WXUNUSED(metadata))
400 {
401 wxObject *O;
402 O = classInfo->CreateObject();
403 m_data->SetObject(objectID, O);
404 }
405
406 void wxRuntimeDepersister::CreateObject(int objectID,
407 const wxClassInfo *classInfo,
408 int paramCount,
409 wxxVariant *params,
410 int *objectIdValues,
411 const wxClassInfo **objectClassInfos ,
412 wxxVariantArray &WXUNUSED(metadata))
413 {
414 wxObject *o;
415 o = m_data->GetObject(objectID);
416 for ( int i = 0 ; i < paramCount ; ++i )
417 {
418 if ( objectIdValues[i] != wxInvalidObjectID )
419 {
420 wxObject *o;
421 o = m_data->GetObject(objectIdValues[i]);
422 // if this is a dynamic object and we are asked for another class
423 // than wxDynamicObject we cast it down manually.
424 wxDynamicObject *dyno = dynamic_cast< wxDynamicObject * > (o) ;
425 if ( dyno!=NULL && (objectClassInfos[i] != dyno->GetClassInfo()) )
426 {
427 o = dyno->GetSuperClassInstance() ;
428 }
429 params[i] = objectClassInfos[i]->InstanceToVariant(o) ;
430 }
431 }
432 classInfo->Create(o, paramCount, params);
433 }
434
435 void wxRuntimeDepersister::ConstructObject(int objectID,
436 const wxClassInfo *classInfo,
437 int paramCount,
438 wxxVariant *params,
439 int *objectIdValues,
440 const wxClassInfo **objectClassInfos ,
441 wxxVariantArray &WXUNUSED(metadata))
442 {
443 wxObject *o;
444 for ( int i = 0 ; i < paramCount ; ++i )
445 {
446 if ( objectIdValues[i] != wxInvalidObjectID )
447 {
448 wxObject *o;
449 o = m_data->GetObject(objectIdValues[i]);
450 // if this is a dynamic object and we are asked for another class
451 // than wxDynamicObject we cast it down manually.
452 wxDynamicObject *dyno = dynamic_cast< wxDynamicObject * > (o) ;
453 if ( dyno!=NULL && (objectClassInfos[i] != dyno->GetClassInfo()) )
454 {
455 o = dyno->GetSuperClassInstance() ;
456 }
457 params[i] = objectClassInfos[i]->InstanceToVariant(o) ;
458 }
459 }
460 o = classInfo->ConstructObject(paramCount, params);
461 m_data->SetObject(objectID, o);
462 }
463
464
465 void wxRuntimeDepersister::DestroyObject(int objectID, wxClassInfo *WXUNUSED(classInfo))
466 {
467 wxObject *o;
468 o = m_data->GetObject(objectID);
469 delete o ;
470 }
471
472 void wxRuntimeDepersister::SetProperty(int objectID,
473 const wxClassInfo *classInfo,
474 const wxPropertyInfo* propertyInfo,
475 const wxxVariant &value)
476 {
477 wxObject *o;
478 o = m_data->GetObject(objectID);
479 classInfo->SetProperty( o , propertyInfo->GetName() , value ) ;
480 }
481
482 void wxRuntimeDepersister::SetPropertyAsObject(int objectID,
483 const wxClassInfo *classInfo,
484 const wxPropertyInfo* propertyInfo,
485 int valueObjectId)
486 {
487 wxObject *o, *valo;
488 o = m_data->GetObject(objectID);
489 valo = m_data->GetObject(valueObjectId);
490 const wxClassInfo* valClassInfo = (dynamic_cast<const wxClassTypeInfo*>(propertyInfo->GetTypeInfo()))->GetClassInfo() ;
491 // if this is a dynamic object and we are asked for another class
492 // than wxDynamicObject we cast it down manually.
493 wxDynamicObject *dynvalo = dynamic_cast< wxDynamicObject * > (valo) ;
494 if ( dynvalo!=NULL && (valClassInfo != dynvalo->GetClassInfo()) )
495 {
496 valo = dynvalo->GetSuperClassInstance() ;
497 }
498
499 classInfo->SetProperty( o , propertyInfo->GetName() , valClassInfo->InstanceToVariant(valo) ) ;
500 }
501
502 void wxRuntimeDepersister::SetConnect(int eventSourceObjectID,
503 const wxClassInfo *WXUNUSED(eventSourceClassInfo),
504 const wxDelegateTypeInfo *delegateInfo ,
505 const wxClassInfo *WXUNUSED(eventSinkClassInfo) ,
506 const wxHandlerInfo* handlerInfo ,
507 int eventSinkObjectID )
508 {
509 wxEvtHandler *ehsource = dynamic_cast< wxEvtHandler* >( m_data->GetObject( eventSourceObjectID ) ) ;
510 wxEvtHandler *ehsink = dynamic_cast< wxEvtHandler *>(m_data->GetObject(eventSinkObjectID) ) ;
511
512 if ( ehsource && ehsink )
513 {
514 ehsource->Connect( -1 , delegateInfo->GetEventType() ,
515 handlerInfo->GetEventFunction() , NULL /*user data*/ ,
516 ehsink ) ;
517 }
518 }
519
520 wxObject *wxRuntimeDepersister::GetObject(int objectID)
521 {
522 return m_data->GetObject( objectID ) ;
523 }
524
525 // adds an element to a property collection
526 void wxRuntimeDepersister::AddToPropertyCollection( int objectID ,
527 const wxClassInfo *classInfo,
528 const wxPropertyInfo* propertyInfo ,
529 const wxxVariant &value)
530 {
531 wxObject *o;
532 o = m_data->GetObject(objectID);
533 classInfo->AddToPropertyCollection( o , propertyInfo->GetName() , value ) ;
534 }
535
536 // sets the corresponding property (value is an object)
537 void wxRuntimeDepersister::AddToPropertyCollectionAsObject(int objectID,
538 const wxClassInfo *classInfo,
539 const wxPropertyInfo* propertyInfo ,
540 int valueObjectId)
541 {
542 wxObject *o, *valo;
543 o = m_data->GetObject(objectID);
544 valo = m_data->GetObject(valueObjectId);
545 const wxCollectionTypeInfo * collectionTypeInfo = dynamic_cast< const wxCollectionTypeInfo * >(propertyInfo->GetTypeInfo() ) ;
546 const wxClassInfo* valClassInfo = (dynamic_cast<const wxClassTypeInfo*>(collectionTypeInfo->GetElementType()))->GetClassInfo() ;
547 // if this is a dynamic object and we are asked for another class
548 // than wxDynamicObject we cast it down manually.
549 wxDynamicObject *dynvalo = dynamic_cast< wxDynamicObject * > (valo) ;
550 if ( dynvalo!=NULL && (valClassInfo != dynvalo->GetClassInfo()) )
551 {
552 valo = dynvalo->GetSuperClassInstance() ;
553 }
554
555 classInfo->AddToPropertyCollection( o , propertyInfo->GetName() , valClassInfo->InstanceToVariant(valo) ) ;
556 }
557
558 // ----------------------------------------------------------------------------
559 // depersisting to code
560 // ----------------------------------------------------------------------------
561
562 struct wxCodeDepersister::wxCodeDepersisterInternal
563 {
564 map<int,string> m_objectNames ;
565
566 void SetObjectName(int objectID, const wxString &name )
567 {
568 assert( m_objectNames.find(objectID) == m_objectNames.end() ) ;
569 m_objectNames[objectID] = (const char *)name;
570 }
571 wxString GetObjectName( int objectID )
572 {
573 if ( objectID == wxNullObjectID )
574 return "NULL" ;
575
576 assert( m_objectNames.find(objectID) != m_objectNames.end() ) ;
577 return wxString( m_objectNames[objectID].c_str() ) ;
578 }
579 } ;
580
581 wxCodeDepersister::wxCodeDepersister(wxTextOutputStream *out)
582 : m_fp(out)
583 {
584 m_data = new wxCodeDepersisterInternal ;
585 }
586
587 wxCodeDepersister::~wxCodeDepersister()
588 {
589 delete m_data ;
590 }
591
592 void wxCodeDepersister::AllocateObject(int objectID, wxClassInfo *classInfo ,
593 wxxVariantArray &WXUNUSED(metadata))
594 {
595 wxString objectName = wxString::Format( "LocalObject_%d" , objectID ) ;
596 m_fp->WriteString( wxString::Format( "\t%s *%s = new %s;\n",
597 classInfo->GetClassName(),
598 objectName.c_str(),
599 classInfo->GetClassName()) );
600 m_data->SetObjectName( objectID , objectName ) ;
601 }
602
603 void wxCodeDepersister::DestroyObject(int objectID, wxClassInfo *WXUNUSED(classInfo))
604 {
605 m_fp->WriteString( wxString::Format( "\tdelete %s;\n",
606 m_data->GetObjectName( objectID).c_str() ) );
607 }
608
609 wxString wxCodeDepersister::ValueAsCode( const wxxVariant &param )
610 {
611 wxString value ;
612 const wxTypeInfo* type = param.GetTypeInfo() ;
613 if ( type->GetKind() == wxT_CUSTOM )
614 {
615 const wxCustomTypeInfo* cti = dynamic_cast<const wxCustomTypeInfo*>(type) ;
616 wxASSERT_MSG( cti , wxT("Internal error, illegal wxCustomTypeInfo") ) ;
617 value.Printf( "%s(%s)",cti->GetTypeName().c_str(),param.GetAsString().c_str() );
618 }
619 else if ( type->GetKind() == wxT_STRING )
620 {
621 value.Printf( "\"%s\"",param.GetAsString().c_str() );
622 }
623 else
624 {
625 value.Printf( "%s", param.GetAsString().c_str() );
626 }
627 return value ;
628 }
629
630 void wxCodeDepersister::CreateObject(int objectID,
631 const wxClassInfo *WXUNUSED(classInfo),
632 int paramCount,
633 wxxVariant *params,
634 int *objectIDValues,
635 const wxClassInfo **WXUNUSED(objectClassInfos) ,
636 wxxVariantArray &WXUNUSED(metadata)
637 )
638 {
639 int i;
640 m_fp->WriteString( wxString::Format( "\t%s->Create(", m_data->GetObjectName(objectID).c_str() ) );
641 for (i = 0; i < paramCount; i++)
642 {
643 if ( objectIDValues[i] != wxInvalidObjectID )
644 m_fp->WriteString( wxString::Format( "%s", m_data->GetObjectName( objectIDValues[i] ).c_str() ) );
645 else
646 {
647 m_fp->WriteString( wxString::Format( "%s", ValueAsCode(params[i]).c_str() ) );
648 }
649 if (i < paramCount - 1)
650 m_fp->WriteString( ", ");
651 }
652 m_fp->WriteString( ");\n");
653 }
654
655 void wxCodeDepersister::ConstructObject(int objectID,
656 const wxClassInfo *classInfo,
657 int paramCount,
658 wxxVariant *params,
659 int *objectIDValues,
660 const wxClassInfo **WXUNUSED(objectClassInfos) ,
661 wxxVariantArray &WXUNUSED(metadata)
662 )
663 {
664 wxString objectName = wxString::Format( "LocalObject_%d" , objectID ) ;
665 m_fp->WriteString( wxString::Format( "\t%s *%s = new %s(",
666 classInfo->GetClassName(),
667 objectName.c_str(),
668 classInfo->GetClassName()) );
669 m_data->SetObjectName( objectID , objectName ) ;
670
671 int i;
672 for (i = 0; i < paramCount; i++)
673 {
674 if ( objectIDValues[i] != wxInvalidObjectID )
675 m_fp->WriteString( wxString::Format( "%s", m_data->GetObjectName( objectIDValues[i] ).c_str() ) );
676 else
677 {
678 m_fp->WriteString( wxString::Format( "%s", ValueAsCode(params[i]).c_str() ) );
679 }
680 if (i < paramCount - 1)
681 m_fp->WriteString( ", ");
682 }
683 m_fp->WriteString( ");\n");
684 }
685
686 void wxCodeDepersister::SetProperty(int objectID,
687 const wxClassInfo *WXUNUSED(classInfo),
688 const wxPropertyInfo* propertyInfo,
689 const wxxVariant &value)
690 {
691 m_fp->WriteString( wxString::Format( "\t%s->%s(%s);\n",
692 m_data->GetObjectName(objectID).c_str(),
693 propertyInfo->GetAccessor()->GetSetterName().c_str(),
694 ValueAsCode(value).c_str()) );
695 }
696
697 void wxCodeDepersister::SetPropertyAsObject(int objectID,
698 const wxClassInfo *WXUNUSED(classInfo),
699 const wxPropertyInfo* propertyInfo,
700 int valueObjectId)
701 {
702 if ( propertyInfo->GetTypeInfo()->GetKind() == wxT_OBJECT )
703 m_fp->WriteString( wxString::Format( "\t%s->%s(*%s);\n",
704 m_data->GetObjectName(objectID).c_str(),
705 propertyInfo->GetAccessor()->GetSetterName().c_str(),
706 m_data->GetObjectName( valueObjectId).c_str() ) );
707 else
708 m_fp->WriteString( wxString::Format( "\t%s->%s(%s);\n",
709 m_data->GetObjectName(objectID).c_str(),
710 propertyInfo->GetAccessor()->GetSetterName().c_str(),
711 m_data->GetObjectName( valueObjectId).c_str() ) );
712 }
713
714 void wxCodeDepersister::AddToPropertyCollection( int objectID ,
715 const wxClassInfo *WXUNUSED(classInfo),
716 const wxPropertyInfo* propertyInfo ,
717 const wxxVariant &value)
718 {
719 m_fp->WriteString( wxString::Format( "\t%s->%s(%s);\n",
720 m_data->GetObjectName(objectID).c_str(),
721 propertyInfo->GetAccessor()->GetAdderName().c_str(),
722 ValueAsCode(value).c_str()) );
723 }
724
725 // sets the corresponding property (value is an object)
726 void wxCodeDepersister::AddToPropertyCollectionAsObject(int WXUNUSED(objectID),
727 const wxClassInfo *WXUNUSED(classInfo),
728 const wxPropertyInfo* WXUNUSED(propertyInfo) ,
729 int WXUNUSED(valueObjectId))
730 {
731 // TODO
732 }
733
734 void wxCodeDepersister::SetConnect(int eventSourceObjectID,
735 const wxClassInfo *WXUNUSED(eventSourceClassInfo),
736 const wxDelegateTypeInfo *delegateInfo ,
737 const wxClassInfo *eventSinkClassInfo ,
738 const wxHandlerInfo* handlerInfo ,
739 int eventSinkObjectID )
740 {
741 wxString ehsource = m_data->GetObjectName( eventSourceObjectID ) ;
742 wxString ehsink = m_data->GetObjectName(eventSinkObjectID) ;
743 wxString ehsinkClass = eventSinkClassInfo->GetClassName() ;
744 int eventType = delegateInfo->GetEventType() ;
745 wxString handlerName = handlerInfo->GetName() ;
746
747 m_fp->WriteString( wxString::Format( "\t%s->Connect( %s->GetId() , %d , (wxObjectEventFunction)(wxEventFunction) & %s::%s , NULL , %s ) ;" ,
748 ehsource.c_str() , ehsource.c_str() , eventType , ehsinkClass.c_str() , handlerName.c_str() , ehsink.c_str() ) );
749 }
750
751 #include <wx/arrimpl.cpp>
752
753 WX_DEFINE_OBJARRAY(wxxVariantArray);
754
755 #endif