]> git.saurik.com Git - wxWidgets.git/blame - include/wx/xtistrm.h
Add support for auto-orientable toolbars to AUI.
[wxWidgets.git] / include / wx / xtistrm.h
CommitLineData
70e88103
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/xtistrm.h
3// Purpose: streaming runtime metadata information (extended class info)
4// Author: Stefan Csomor
cab1a605 5// Modified by:
70e88103
SC
6// Created: 27/07/03
7// RCS-ID: $Id$
8// Copyright: (c) 2003 Stefan Csomor
65571936 9// Licence: wxWindows licence
70e88103
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_XTISTRMH__
13#define _WX_XTISTRMH__
14
70e88103
SC
15#include "wx/wx.h"
16
17#if wxUSE_EXTENDED_RTTI
18
8ec1974e 19const int wxInvalidObjectID = -2 ;
8f2b1cfd 20const int wxNullObjectID = -3 ;
8ec1974e 21
70e88103
SC
22// Filer contains the interfaces for streaming objects in and out of XML,
23// rendering them either to objects in memory, or to code. Note: We
24// consider the process of generating code to be one of *depersisting* the
25// object from xml, *not* of persisting the object to code from an object
26// in memory. This distincation can be confusing, and should be kept
27// in mind when looking at the property streamers and callback interfaces
28// listed below.
29
30/*
aa8d7c2f 31Main interfaces for streaming out objects.
70e88103
SC
32*/
33
ab6e4913
SC
34// ----------------------------------------------------------------------------
35// wxPersister
36//
37// This class will be asked during the streaming-out process about every single
38// property or object instance. It can veto streaming out by returning false
39// or modify the value before it is streamed-out.
40// ----------------------------------------------------------------------------
41
b5dbe15d
VS
42class WXDLLIMPEXP_FWD_BASE wxWriter ;
43class WXDLLIMPEXP_FWD_BASE wxReader ;
ab6e4913 44
1c263d56 45class WXDLLIMPEXP_BASE wxPersister
aa8d7c2f
SC
46{
47public :
afc89ff4
MB
48 virtual ~wxPersister() {}
49
ab6e4913 50 // will be called before an object is written, may veto by returning false
cab1a605 51 virtual bool BeforeWriteObject( wxWriter *WXUNUSED(writer) , const wxObject *WXUNUSED(object) , const wxClassInfo *WXUNUSED(classInfo) , wxxVariantArray &WXUNUSED(metadata)) { return true ; }
ab6e4913
SC
52
53 // will be called after this object has been written, may be needed for adjusting stacks
54 virtual void AfterWriteObject( wxWriter *WXUNUSED(writer) , const wxObject *WXUNUSED(object) , const wxClassInfo *WXUNUSED(classInfo) ) {}
aa8d7c2f 55
cab1a605 56 // will be called before a property gets written, may change the value , eg replace a concrete wxSize by wxSize( wxDefaultCoord , wxDefaultCoord ) or veto
aa8d7c2f 57 // writing that property at all by returning false
cab1a605 58 virtual bool BeforeWriteProperty( wxWriter *WXUNUSED(writer) , const wxObject *WXUNUSED(object), const wxPropertyInfo *WXUNUSED(propInfo) , wxxVariant &WXUNUSED(value) ) { return true ; }
aa8d7c2f 59
cab1a605 60 // will be called before a property gets written, may change the value , eg replace a concrete wxSize by wxSize( wxDefaultCoord , wxDefaultCoord ) or veto
aa8d7c2f 61 // writing that property at all by returning false
cab1a605 62 virtual bool BeforeWriteProperty( wxWriter *WXUNUSED(writer) , const wxObject *WXUNUSED(object), const wxPropertyInfo *WXUNUSED(propInfo) , wxxVariantArray &WXUNUSED(value) ) { return true ; }
ab6e4913
SC
63
64 // will be called after a property has been written out, may be needed for adjusting stacks
65 virtual void AfterWriteProperty( wxWriter *WXUNUSED(writer) , const wxPropertyInfo *WXUNUSED(propInfo) ) {}
66
67 // will be called before this delegate gets written
cab1a605
WS
68 virtual bool BeforeWriteDelegate( wxWriter *WXUNUSED(writer) , const wxObject *WXUNUSED(object), const wxClassInfo* WXUNUSED(classInfo) , const wxPropertyInfo *WXUNUSED(propInfo) ,
69 const wxObject *&WXUNUSED(eventSink) , const wxHandlerInfo* &WXUNUSED(handlerInfo) ) { return true ; }
aa8d7c2f 70
cab1a605
WS
71 virtual void AfterWriteDelegate( wxWriter *WXUNUSED(writer) , const wxObject *WXUNUSED(object), const wxClassInfo* WXUNUSED(classInfo) , const wxPropertyInfo *WXUNUSED(propInfo) ,
72 const wxObject *&WXUNUSED(eventSink) , const wxHandlerInfo* &WXUNUSED(handlerInfo) ) { }
aa8d7c2f
SC
73} ;
74
1c263d56 75class WXDLLIMPEXP_BASE wxWriter : public wxObject
aa8d7c2f
SC
76{
77public :
78 wxWriter() ;
d3c7fc99 79 virtual ~wxWriter() ;
aa8d7c2f
SC
80
81 // with this call you start writing out a new top-level object
4f8ffae1 82 void WriteObject(const wxObject *object, const wxClassInfo *classInfo , wxPersister *persister , const wxString &name , wxxVariantArray &WXUNUSED(metadata)) ;
aa8d7c2f 83
ab6e4913
SC
84 //
85 // Managing the object identity table a.k.a context
86 //
cab1a605 87 // these methods make sure that no object gets written twice, because sometimes multiple calls to the WriteObject will be
ab6e4913
SC
88 // made without wanting to have duplicate objects written, the object identity table will be reset manually
89
90 virtual void ClearObjectContext() ;
2abce515 91
ab6e4913 92 // gets the object Id for a passed in object in the context
aa8d7c2f 93 int GetObjectID(const wxObject *obj) ;
aa8d7c2f 94
ab6e4913
SC
95 // returns true if this object has already been written in this context
96 bool IsObjectKnown( const wxObject *obj ) ;
aa8d7c2f
SC
97
98 //
99 // streaming callbacks
100 //
101 // these callbacks really write out the values in the stream format
aa8d7c2f 102
ab6e4913
SC
103 // begins writing out a new toplevel entry which has the indicated unique name
104 virtual void DoBeginWriteTopLevelEntry( const wxString &name ) = 0 ;
105
106 // ends writing out a new toplevel entry which has the indicated unique name
107 virtual void DoEndWriteTopLevelEntry( const wxString &name ) = 0 ;
108
109 // start of writing an object having the passed in ID
4f8ffae1 110 virtual void DoBeginWriteObject(const wxObject *object, const wxClassInfo *classInfo, int objectID , wxxVariantArray &metadata ) = 0 ;
aa8d7c2f
SC
111
112 // end of writing an toplevel object name param is used for unique identification within the container
ab6e4913
SC
113 virtual void DoEndWriteObject(const wxObject *object, const wxClassInfo *classInfo, int objectID ) = 0 ;
114
115 // writes a simple property in the stream format
116 virtual void DoWriteSimpleType( wxxVariant &value ) = 0 ;
aa8d7c2f 117
ab6e4913
SC
118 // start of writing a complex property into the stream (
119 virtual void DoBeginWriteProperty( const wxPropertyInfo *propInfo ) = 0 ;
aa8d7c2f 120
ab6e4913
SC
121 // end of writing a complex property into the stream
122 virtual void DoEndWriteProperty( const wxPropertyInfo *propInfo ) = 0;
aa8d7c2f 123
ab6e4913
SC
124 virtual void DoBeginWriteElement() = 0 ;
125 virtual void DoEndWriteElement() = 0 ;
cab1a605 126 // insert an object reference to an already written object
ab6e4913 127 virtual void DoWriteRepeatedObject( int objectID ) = 0 ;
aa8d7c2f 128
ab6e4913
SC
129 // insert a null reference
130 virtual void DoWriteNullObject() = 0 ;
aa8d7c2f
SC
131
132 // writes a delegate in the stream format
cab1a605 133 virtual void DoWriteDelegate( const wxObject *object, const wxClassInfo* classInfo , const wxPropertyInfo *propInfo ,
aa8d7c2f
SC
134 const wxObject *eventSink , int sinkObjectID , const wxClassInfo* eventSinkClassInfo , const wxHandlerInfo* handlerIndo ) = 0;
135private :
136
137 struct wxWriterInternal ;
138 wxWriterInternal* m_data ;
139
140 struct wxWriterInternalPropertiesData ;
141
142 void WriteAllProperties( const wxObject * obj , const wxClassInfo* ci , wxPersister *persister, wxWriterInternalPropertiesData * data ) ;
ae820c69 143 void WriteOneProperty( const wxObject *obj , const wxClassInfo* ci , const wxPropertyInfo* pi , wxPersister *persister , wxWriterInternalPropertiesData *data ) ;
4f8ffae1 144 void WriteObject(const wxObject *object, const wxClassInfo *classInfo , wxPersister *persister , bool isEmbedded, wxxVariantArray &metadata ) ;
9c8046dd 145 void FindConnectEntry(const wxEvtHandler * evSource,const wxDelegateTypeInfo* dti, const wxObject* &sink , const wxHandlerInfo *&handler) ;
aa8d7c2f
SC
146} ;
147
70e88103 148
70e88103 149/*
8ec1974e 150Streaming callbacks for depersisting XML to code, or running objects
70e88103
SC
151*/
152
b5dbe15d 153class WXDLLIMPEXP_FWD_BASE wxDepersister ;
70e88103
SC
154
155/*
8ec1974e
SC
156wxReader handles streaming in a class from a arbitrary format. While walking through
157it issues calls out to interfaces to depersist the guts from the underlying storage format.
70e88103 158*/
8ec1974e 159
1c263d56 160class WXDLLIMPEXP_BASE wxReader : public wxObject
70e88103 161{
8ec1974e
SC
162public :
163 wxReader() ;
d3c7fc99 164 virtual ~wxReader() ;
aa8d7c2f 165
8ec1974e
SC
166 // the only thing wxReader knows about is the class info by object ID
167 wxClassInfo *GetObjectClassInfo(int objectID) ;
168 bool HasObjectClassInfo( int objectID ) ;
169 void SetObjectClassInfo(int objectID, wxClassInfo* classInfo);
170
cab1a605 171 // Reads the component the reader is pointed at from the underlying format.
8ec1974e
SC
172 // The return value is the root object ID, which can
173 // then be used to ask the depersister about that object
8f2b1cfd
SC
174 // if there was a problem you will get back wxInvalidObjectID and the current
175 // error log will carry the problems encoutered
ab6e4913 176 virtual int ReadObject( const wxString &name , wxDepersister *depersist ) = 0 ;
8ec1974e
SC
177
178private :
70e88103 179 struct wxReaderInternal;
8ec1974e
SC
180 wxReaderInternal *m_data;
181} ;
182
8ec1974e
SC
183// This abstract class matches the allocate-init/create model of creation of objects.
184// At runtime, these will create actual instances, and manipulate them.
185// When generating code, these will just create statements of C++
186// code to create the objects.
187
1c263d56 188class WXDLLIMPEXP_BASE wxDepersister
70e88103 189{
8ec1974e 190public :
afc89ff4
MB
191 virtual ~wxDepersister() {}
192
8ec1974e 193 // allocate the new object on the heap, that object will have the passed in ID
4f8ffae1 194 virtual void AllocateObject(int objectID, wxClassInfo *classInfo, wxxVariantArray &metadata) = 0;
8ec1974e 195
16a45a23 196 // initialize the already allocated object having the ID objectID with the Create method
8ec1974e
SC
197 // creation parameters which are objects are having their Ids passed in objectIDValues
198 // having objectId <> wxInvalidObjectID
199
16a45a23
SC
200 virtual void CreateObject(int objectID,
201 const wxClassInfo *classInfo,
202 int paramCount,
8ec1974e
SC
203 wxxVariant *VariantValues ,
204 int *objectIDValues ,
4f8ffae1
SC
205 const wxClassInfo **objectClassInfos ,
206 wxxVariantArray &metadata) = 0;
8ec1974e 207
583150e3
SC
208 // construct the new object on the heap, that object will have the passed in ID (for objects that
209 // don't support allocate-create type of creation)
210 // creation parameters which are objects are having their Ids passed in objectIDValues
211 // having objectId <> wxInvalidObjectID
212
213 virtual void ConstructObject(int objectID,
214 const wxClassInfo *classInfo,
215 int paramCount,
216 wxxVariant *VariantValues ,
217 int *objectIDValues ,
218 const wxClassInfo **objectClassInfos ,
219 wxxVariantArray &metadata) = 0;
220
16a45a23 221 // destroy the heap-allocated object having the ID objectID, this may be used if an object
8ec1974e
SC
222 // is embedded in another object and set via value semantics, so the intermediate
223 // object can be destroyed after safely
16a45a23 224 virtual void DestroyObject(int objectID, wxClassInfo *classInfo) = 0;
8ec1974e
SC
225
226 // set the corresponding property
16a45a23
SC
227 virtual void SetProperty(int objectID,
228 const wxClassInfo *classInfo,
229 const wxPropertyInfo* propertyInfo ,
8ec1974e
SC
230 const wxxVariant &VariantValue) = 0;
231
232 // sets the corresponding property (value is an object)
16a45a23
SC
233 virtual void SetPropertyAsObject(int objectID,
234 const wxClassInfo *classInfo,
235 const wxPropertyInfo* propertyInfo ,
8ec1974e
SC
236 int valueObjectId) = 0;
237
16a45a23
SC
238 // adds an element to a property collection
239 virtual void AddToPropertyCollection( int objectID ,
240 const wxClassInfo *classInfo,
241 const wxPropertyInfo* propertyInfo ,
242 const wxxVariant &VariantValue) = 0;
243
244 // sets the corresponding property (value is an object)
245 virtual void AddToPropertyCollectionAsObject(int objectID,
246 const wxClassInfo *classInfo,
247 const wxPropertyInfo* propertyInfo ,
248 int valueObjectId) = 0;
8ec1974e
SC
249
250 // sets the corresponding event handler
70e88103 251 virtual void SetConnect(int EventSourceObjectID,
8ec1974e 252 const wxClassInfo *EventSourceClassInfo,
9dabddc2 253 const wxPropertyInfo *delegateInfo ,
8ec1974e
SC
254 const wxClassInfo *EventSinkClassInfo ,
255 const wxHandlerInfo* handlerInfo ,
256 int EventSinkObjectID ) = 0;
70e88103
SC
257};
258
259/*
8ec1974e
SC
260wxRuntimeDepersister implements the callbacks that will depersist
261an object into a running memory image, as opposed to writing
262C++ initialization code to bring the object to life.
70e88103 263*/
1c263d56
SC
264
265class WXDLLIMPEXP_BASE wxRuntimeDepersister : public wxDepersister
70e88103 266{
8ec1974e
SC
267 struct wxRuntimeDepersisterInternal ;
268 wxRuntimeDepersisterInternal * m_data ;
269public :
1b5ff3a3
VS
270 wxRuntimeDepersister();
271 virtual ~wxRuntimeDepersister();
8ec1974e 272
cab1a605 273 // returns the object having the corresponding ID fully constructed
8ec1974e
SC
274 wxObject *GetObject(int objectID) ;
275
276 // allocate the new object on the heap, that object will have the passed in ID
4f8ffae1
SC
277 virtual void AllocateObject(int objectID, wxClassInfo *classInfo ,
278 wxxVariantArray &metadata) ;
8ec1974e 279
16a45a23 280 // initialize the already allocated object having the ID objectID with the Create method
8ec1974e
SC
281 // creation parameters which are objects are having their Ids passed in objectIDValues
282 // having objectId <> wxInvalidObjectID
283
16a45a23
SC
284 virtual void CreateObject(int objectID,
285 const wxClassInfo *classInfo,
286 int paramCount,
8ec1974e
SC
287 wxxVariant *VariantValues ,
288 int *objectIDValues,
4f8ffae1
SC
289 const wxClassInfo **objectClassInfos ,
290 wxxVariantArray &metadata
8ec1974e
SC
291 ) ;
292
583150e3
SC
293 // construct the new object on the heap, that object will have the passed in ID (for objects that
294 // don't support allocate-create type of creation)
295 // creation parameters which are objects are having their Ids passed in objectIDValues
296 // having objectId <> wxInvalidObjectID
297
298 virtual void ConstructObject(int objectID,
299 const wxClassInfo *classInfo,
300 int paramCount,
301 wxxVariant *VariantValues ,
302 int *objectIDValues ,
303 const wxClassInfo **objectClassInfos ,
304 wxxVariantArray &metadata) ;
305
16a45a23 306 // destroy the heap-allocated object having the ID objectID, this may be used if an object
8ec1974e
SC
307 // is embedded in another object and set via value semantics, so the intermediate
308 // object can be destroyed after safely
309 virtual void DestroyObject(int objectID, wxClassInfo *classInfo) ;
310
311 // set the corresponding property
312 virtual void SetProperty(int objectID,
313 const wxClassInfo *classInfo,
314 const wxPropertyInfo* propertyInfo ,
315 const wxxVariant &variantValue);
316
317 // sets the corresponding property (value is an object)
318 virtual void SetPropertyAsObject(int objectId,
319 const wxClassInfo *classInfo,
320 const wxPropertyInfo* propertyInfo ,
321 int valueObjectId) ;
322
16a45a23
SC
323 // adds an element to a property collection
324 virtual void AddToPropertyCollection( int objectID ,
325 const wxClassInfo *classInfo,
326 const wxPropertyInfo* propertyInfo ,
327 const wxxVariant &VariantValue) ;
328
329 // sets the corresponding property (value is an object)
330 virtual void AddToPropertyCollectionAsObject(int objectID,
331 const wxClassInfo *classInfo,
332 const wxPropertyInfo* propertyInfo ,
333 int valueObjectId) ;
8ec1974e
SC
334
335 // sets the corresponding event handler
336 virtual void SetConnect(int eventSourceObjectID,
337 const wxClassInfo *eventSourceClassInfo,
9dabddc2 338 const wxPropertyInfo *delegateInfo ,
8ec1974e
SC
339 const wxClassInfo *eventSinkClassInfo ,
340 const wxHandlerInfo* handlerInfo ,
341 int eventSinkObjectID ) ;
70e88103
SC
342};
343
344/*
8ec1974e 345wxDepersisterCode implements the callbacks that will depersist
cab1a605 346an object into a C++ initialization function. this will move to
1c263d56 347a utility lib soon
70e88103
SC
348*/
349
b5dbe15d 350class WXDLLIMPEXP_FWD_BASE wxTextOutputStream ;
70e88103 351
1c263d56 352class WXDLLIMPEXP_BASE wxCodeDepersister : public wxDepersister
70e88103 353{
8ec1974e
SC
354private :
355 struct wxCodeDepersisterInternal ;
356 wxCodeDepersisterInternal * m_data ;
357 wxTextOutputStream *m_fp;
358 wxString ValueAsCode( const wxxVariant &param ) ;
70e88103 359public:
1b5ff3a3
VS
360 wxCodeDepersister(wxTextOutputStream *out);
361 virtual ~wxCodeDepersister();
8ec1974e
SC
362
363 // allocate the new object on the heap, that object will have the passed in ID
4f8ffae1
SC
364 virtual void AllocateObject(int objectID, wxClassInfo *classInfo ,
365 wxxVariantArray &metadata) ;
8ec1974e 366
16a45a23 367 // initialize the already allocated object having the ID objectID with the Create method
8ec1974e
SC
368 // creation parameters which are objects are having their Ids passed in objectIDValues
369 // having objectId <> wxInvalidObjectID
370
371 virtual void CreateObject(int objectID,
372 const wxClassInfo *classInfo,
373 int paramCount,
374 wxxVariant *variantValues ,
375 int *objectIDValues,
4f8ffae1
SC
376 const wxClassInfo **objectClassInfos ,
377 wxxVariantArray &metadata
8ec1974e
SC
378 ) ;
379
583150e3
SC
380 // construct the new object on the heap, that object will have the passed in ID (for objects that
381 // don't support allocate-create type of creation)
382 // creation parameters which are objects are having their Ids passed in objectIDValues
383 // having objectId <> wxInvalidObjectID
384
385 virtual void ConstructObject(int objectID,
386 const wxClassInfo *classInfo,
387 int paramCount,
388 wxxVariant *VariantValues ,
389 int *objectIDValues ,
390 const wxClassInfo **objectClassInfos ,
391 wxxVariantArray &metadata) ;
392
16a45a23 393 // destroy the heap-allocated object having the ID objectID, this may be used if an object
8ec1974e
SC
394 // is embedded in another object and set via value semantics, so the intermediate
395 // object can be destroyed after safely
396 virtual void DestroyObject(int objectID, wxClassInfo *classInfo) ;
397
398 // set the corresponding property
399 virtual void SetProperty(int objectID,
400 const wxClassInfo *classInfo,
401 const wxPropertyInfo* propertyInfo ,
402 const wxxVariant &variantValue);
403
404 // sets the corresponding property (value is an object)
405 virtual void SetPropertyAsObject(int objectId,
406 const wxClassInfo *classInfo,
407 const wxPropertyInfo* propertyInfo ,
408 int valueObjectId) ;
409
16a45a23
SC
410 // adds an element to a property collection
411 virtual void AddToPropertyCollection( int objectID ,
412 const wxClassInfo *classInfo,
413 const wxPropertyInfo* propertyInfo ,
414 const wxxVariant &VariantValue) ;
415
416 // sets the corresponding property (value is an object)
417 virtual void AddToPropertyCollectionAsObject(int objectID,
418 const wxClassInfo *classInfo,
419 const wxPropertyInfo* propertyInfo ,
420 int valueObjectId) ;
8ec1974e
SC
421
422 // sets the corresponding event handler
423 virtual void SetConnect(int eventSourceObjectID,
424 const wxClassInfo *eventSourceClassInfo,
9dabddc2 425 const wxPropertyInfo *delegateInfo ,
8ec1974e
SC
426 const wxClassInfo *eventSinkClassInfo ,
427 const wxHandlerInfo* handlerInfo ,
428 int eventSinkObjectID ) ;
70e88103
SC
429};
430
431#endif // wxUSE_EXTENDED_RTTI
432
12028905 433#endif