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