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