]> git.saurik.com Git - wxWidgets.git/blame_incremental - utils/serialize/serwnd.cpp
added new text event macros description
[wxWidgets.git] / utils / serialize / serwnd.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: serwnd.cpp
3// Purpose: Serialization: wxWindow classes
4// Author: Guilhem Lavaux
5// Modified by:
6// Created: July 1998
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Guilhem Lavaux
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "serwnd.h"
14#endif
15
16#include <wx/window.h>
17#include <wx/layout.h>
18#include <wx/stream.h>
19#include <wx/datstrm.h>
20#include <wx/objstrm.h>
21#include <wx/utils.h>
22#include <wx/frame.h>
23#include <wx/panel.h>
24#include <wx/menu.h>
25#include <wx/dialog.h>
26#include <wx/serbase.h>
27#include <wx/statusbr.h>
28#include <wx/mdi.h>
29#include "wx/log.h"
30#include "serwnd.h"
31
32
33IMPLEMENT_SERIAL_CLASS(wxWindow, wxObject)
34IMPLEMENT_SERIAL_CLASS(wxIndividualLayoutConstraint, wxObject)
35IMPLEMENT_SERIAL_CLASS(wxLayoutConstraints, wxObject)
36IMPLEMENT_ALIAS_SERIAL_CLASS(wxValidator, wxObject)
37IMPLEMENT_SERIAL_CLASS(wxFrame, wxWindow)
38IMPLEMENT_SERIAL_CLASS(wxPanel, wxWindow)
39IMPLEMENT_SERIAL_CLASS(wxDialog, wxWindow)
40IMPLEMENT_SERIAL_CLASS(wxMenuBar, wxWindow)
41IMPLEMENT_SERIAL_CLASS(wxMenuItem, wxObject)
42IMPLEMENT_SERIAL_CLASS(wxMenu, wxObject)
43
44IMPLEMENT_SERIAL_CLASS(wxMDIParentFrame, wxFrame)
45IMPLEMENT_SERIAL_CLASS(wxMDIChildFrame, wxFrame)
46IMPLEMENT_SERIAL_CLASS(wxMDIClientWindow, wxWindow)
47
48/////////////////////////////////////////////////////////////////////////////
49
50void WXSERIAL(wxWindow)::StoreObject(wxObjectOutputStream& s)
51{
52 wxWindow *win_object = (wxWindow *)Object();
53
54 if (s.FirstStage()) {
55 wxNode *node = win_object->GetChildren()->First();
56
57 s.AddChild(win_object->GetConstraints());
58 s.AddChild(win_object->GetValidator());
59
60 // BAD HACK, but I don't have access to the internal variable of wxWindow.
61 m_bg_colour = win_object->GetBackgroundColour();
62 m_fg_colour = win_object->GetForegroundColour();
63 s.AddChild(&m_bg_colour);
64 s.AddChild(&m_fg_colour);
65 s.AddChild(win_object->GetFont());
66 while (node) {
67 s.AddChild(node->Data());
68 node = node->Next();
69 }
70 return;
71 }
72
73 wxDataOutputStream data(s);
74 int x,y,w,h;
75
76 data.WriteString( win_object->GetName() );
77 data.WriteString( win_object->GetLabel() );
78 data.WriteString( win_object->GetTitle() );
79
80 data.Write8( win_object->GetAutoLayout() );
81 data.Write8( win_object->IsShown() );
82 data.Write32( win_object->GetWindowStyleFlag() );
83 data.Write32( win_object->GetId() );
84 wxLogDebug( "Number = %d", win_object->GetChildren()->Number() );
85 data.Write8( win_object->GetChildren()->Number() );
86
87 win_object->GetSize(&w, &h);
88 win_object->GetPosition(&x, &y);
89 data.Write16(x);
90 data.Write16(y);
91 data.Write16(w);
92 data.Write16(h);
93}
94
95void WXSERIAL(wxWindow)::LoadObject(wxObjectInputStream& s)
96{
97 wxDataInputStream data_s(s);
98 wxWindow *win_object = (wxWindow *)Object();
99 wxColour *colour;
100 wxFont *font;
101
102 if (s.SecondCall()) {
103 /* I assume we will never create raw wxWindow object */
104 (void)s.GetChild(); // We pass wxLayoutConstraints.
105 (void)s.GetChild(); // We pass wxValidator.
106
107 colour = (wxColour *)s.GetChild();
108 if (colour)
109 win_object->SetBackgroundColour(*colour);
110 colour = (wxColour *)s.GetChild();
111 if (colour)
112 win_object->SetForegroundColour(*colour);
113 font = (wxFont *)s.GetChild();
114 if (font)
115 win_object->SetFont(*font);
116 s.RemoveChildren(m_number);
117 return;
118 }
119
120 m_parent = (wxWindow *)s.GetParent();
121
122 m_name = data_s.ReadString();
123 m_label = data_s.ReadString();
124 m_title = data_s.ReadString();
125
126 m_auto_layout = data_s.Read8();
127 m_shown = data_s.Read8();
128 m_style = data_s.Read32();
129 m_id = data_s.Read32();
130 m_number = data_s.Read8();
131
132 m_x = data_s.Read16();
133 m_y = data_s.Read16();
134 m_w = data_s.Read16();
135 m_h = data_s.Read16();
136
137 (void)s.GetChild(); // We pass wxLayoutConstraints.
138
139 m_validator = (wxValidator *)s.GetChild();
140 if (!m_validator)
141 m_validator = (wxValidator *)&wxDefaultValidator;
142
143 s.RemoveChildren(m_number+3);
144
145 s.Recall();
146
147 return;
148}
149
150/////////////////////////////////////////////////////////////////////////////
151
152void WXSERIAL(wxIndividualLayoutConstraint)::StoreObject
153 (wxObjectOutputStream& s)
154{
155 wxIndividualLayoutConstraint *lay_object =
156 (wxIndividualLayoutConstraint *)Object();
157 if (s.FirstStage())
158 return;
159
160 wxDataOutputStream data_s(s);
161
162 data_s.WriteString(s.GetObjectName(lay_object->GetOtherWindow()));
163 data_s.Write8(lay_object->GetMyEdge());
164 data_s.Write8(lay_object->GetRelationship());
165 data_s.Write16(lay_object->GetMargin());
166 data_s.Write16(lay_object->GetValue());
167 data_s.Write8(lay_object->GetPercent());
168 data_s.Write8(lay_object->GetOtherEdge());
169}
170
171void WXSERIAL(wxIndividualLayoutConstraint)::
172 LoadObject(wxObjectInputStream& s)
173{
174 wxIndividualLayoutConstraint *lay_object =
175 (wxIndividualLayoutConstraint *)Object();
176 wxDataInputStream data_s(s);
177 wxString win_name;
178
179 win_name = data_s.ReadString();
180 lay_object->otherWin = (wxWindow *)s.SolveName(win_name);
181 lay_object->myEdge = (wxEdge)data_s.Read8();
182 lay_object->relationship = (wxRelationship)data_s.Read8();
183 lay_object->margin = data_s.Read16();
184 lay_object->value = data_s.Read16();
185 lay_object->percent = data_s.Read8();
186 lay_object->otherEdge = (wxEdge)data_s.Read8();
187}
188
189/////////////////////////////////////////////////////////////////////////////
190
191void WXSERIAL(wxLayoutConstraints)::StoreObject(wxObjectOutputStream& s)
192{
193 wxLayoutConstraints *lay_object = (wxLayoutConstraints *)Object();
194 WXSERIAL(wxIndividualLayoutConstraint) c;
195
196#define STORE(obj) c.SetObject(&(lay_object->obj)); c.StoreObject(s);
197
198 // I simplify the process for this object
199 STORE(left);
200 STORE(right);
201 STORE(bottom);
202 STORE(top);
203
204 STORE(width);
205 STORE(height);
206
207 STORE(centreX);
208 STORE(centreY);
209
210#undef STORE
211}
212
213void WXSERIAL(wxLayoutConstraints)::LoadObject(wxObjectInputStream& s)
214{
215 wxLayoutConstraints *lay_object = (wxLayoutConstraints *)Object();
216 WXSERIAL(wxIndividualLayoutConstraint) c;
217
218#define LOAD(obj) c.SetObject(&(lay_object->obj)); c.LoadObject(s);
219
220 // I simplify the process for this object
221 LOAD(left);
222 LOAD(right);
223 LOAD(bottom);
224 LOAD(top);
225
226 LOAD(width);
227 LOAD(height);
228
229 LOAD(centreX);
230 LOAD(centreY);
231
232#undef LOAD
233
234 // Initialize constraints
235 ((wxWindow *)s.GetParent())->SetConstraints(lay_object);
236}
237
238/////////////////////////////////////////////////////////////////////////////
239
240void WXSERIAL(wxFrame)::StoreObject(wxObjectOutputStream& s)
241{
242 wxFrame *frame = (wxFrame *)Object();
243
244 if (s.FirstStage()) {
245 s.AddChild(frame->GetMenuBar());
246 WXSERIAL(wxWindow)::StoreObject(s);
247 return;
248 }
249
250 WXSERIAL(wxWindow)::StoreObject(s);
251
252 wxDataOutputStream data_s(s);
253 wxStatusBar *statbar = frame->GetStatusBar();
254
255 // AAARGH !! I absolutely need to be able to modify internal fields of
256 // wxFrame (wxToolBar and wxStatusBar)
257
258 if (statbar)
259 data_s.Write8(statbar->GetFieldsCount());
260 else
261 data_s.Write8(0);
262 // HOW CAN I ACCESS TO THIS FIELD ?
263 // for (...) { data_s.Write8(statbar->m_statusWidths[i]); }
264}
265
266void WXSERIAL(wxFrame)::LoadObject(wxObjectInputStream& s)
267{
268 wxFrame *frame = (wxFrame *)Object();
269 wxMenuBar *mbar = (wxMenuBar *)s.GetChild();
270
271 WXSERIAL(wxWindow)::LoadObject(s);
272
273 if (s.SecondCall())
274 return;
275
276 wxDataInputStream data_s(s);
277
278 if (frame->GetClassInfo() == CLASSINFO(wxFrame))
279 frame->Create(m_parent, m_id, m_title, wxPoint(m_x, m_y),
280 wxSize(m_w, m_h), m_style, m_name);
281 frame->SetMenuBar(mbar);
282
283 frame->CreateStatusBar(data_s.Read8());
284}
285
286/////////////////////////////////////////////////////////////////////////////
287
288void WXSERIAL(wxMenuBar)::StoreObject(wxObjectOutputStream& s)
289{
290 wxMenuBar *mbar = (wxMenuBar *)Object();
291 int i, mcount = mbar->GetMenuCount();
292
293 if (s.FirstStage()) {
294 for (i=0;i<mcount;i++)
295 s.AddChild( mbar->GetMenu(i) );
296 WXSERIAL(wxWindow)::StoreObject(s);
297 return;
298 }
299
300 wxDataOutputStream data_s(s);
301 data_s.Write8( mcount );
302
303 // It isn't necessary for this object.
304 // WXSERIAL(wxWindow)::StoreObject(s);
305}
306
307void WXSERIAL(wxMenuBar)::LoadObject(wxObjectInputStream& s)
308{
309 wxMenuBar *mbar = (wxMenuBar *)Object();
310 int i, mcount;
311 wxDataInputStream data_s(s);
312
313 mcount = data_s.Read8();
314 for (i=0;i<mcount;i++) {
315 wxMenu *menu = (wxMenu *)s.GetChild();
316 mbar->Append( menu, menu->GetTitle() );
317 }
318
319 // It isn't necessary for this object.
320 // WXSERIAL(wxWindow)::LoadObject(s);
321}
322
323/////////////////////////////////////////////////////////////////////////////
324
325void WXSERIAL(wxMenu)::StoreObject(wxObjectOutputStream& s)
326{
327 wxMenu *menu = (wxMenu *)Object();
328
329 if (s.FirstStage()) {
330 s.AddChild( &menu->GetItems() );
331 return;
332 }
333
334 wxDataOutputStream data_s(s);
335 data_s.WriteString( menu->GetTitle() );
336}
337
338void WXSERIAL(wxMenu)::LoadObject(wxObjectInputStream& s)
339{
340 wxMenu *menu = (wxMenu *)Object();
341 wxList *items = (wxList *)s.GetChild();
342 wxNode *node = items->First();
343
344 wxDataInputStream data_s(s);
345
346 menu->SetTitle( data_s.ReadString() );
347
348 while (node) {
349// NOT IMPLEMENTED in wxGTK
350// menu->Append( (wxMenuItem *)node->Data() );
351 node = node->Next();
352 }
353}
354
355/////////////////////////////////////////////////////////////////////////////
356
357void WXSERIAL(wxMenuItem)::StoreObject(wxObjectOutputStream& s)
358{
359 wxMenuItem *item = (wxMenuItem *)Object();
360
361 if (s.FirstStage()) {
362#ifdef __WXGTK__
363 s.AddChild(item->GetSubMenu());
364#endif
365 return;
366 }
367
368 wxDataOutputStream data_s(s);
369
370#ifdef __WXGTK__
371 data_s.Write8( item->GetId() );
372 data_s.WriteString( item->GetText() );
373 data_s.Write8( item->IsCheckable() );
374 data_s.Write8( item->IsEnabled() );
375 data_s.Write8( item->IsChecked() );
376#endif
377}
378
379void WXSERIAL(wxMenuItem)::LoadObject(wxObjectInputStream& s)
380{
381 wxMenuItem *item = (wxMenuItem *)Object();
382 wxDataInputStream data_s(s);
383
384#ifdef __WXGTK__
385 item->SetId( data_s.Read8() );
386 item->SetText( data_s.ReadString() );
387 item->SetCheckable( data_s.Read8() );
388 item->Enable( data_s.Read8() );
389 item->Check( data_s.Read8() );
390 item->SetSubMenu( (wxMenu *)s.GetChild() );
391#endif
392}
393
394/////////////////////////////////////////////////////////////////////////////
395
396void WXSERIAL(wxPanel)::StoreObject(wxObjectOutputStream& s)
397{
398 WXSERIAL(wxWindow)::StoreObject(s);
399}
400
401void WXSERIAL(wxPanel)::LoadObject(wxObjectInputStream& s)
402{
403 WXSERIAL(wxWindow)::LoadObject(s);
404
405 if (s.SecondCall())
406 return;
407
408 ((wxPanel *)Object())->Create(m_parent, m_id, wxPoint(m_x, m_y),
409 wxSize(m_w, m_h), m_style, m_name);
410}
411
412/////////////////////////////////////////////////////////////////////////////
413
414void WXSERIAL(wxDialog)::StoreObject(wxObjectOutputStream& s)
415{
416 WXSERIAL(wxWindow)::StoreObject(s);
417}
418
419void WXSERIAL(wxDialog)::LoadObject(wxObjectInputStream& s)
420{
421 WXSERIAL(wxWindow)::LoadObject(s);
422
423 if (s.SecondCall())
424 return;
425
426 ((wxDialog *)Object())->Create(m_parent, m_id, m_title, wxPoint(m_x, m_y),
427 wxSize(m_w, m_h), m_style, m_name);
428}
429
430/////////////////////////////////////////////////////////////////////////////
431
432void WXSERIAL(wxMDIParentFrame)::StoreObject(wxObjectOutputStream& s)
433{
434 wxMDIParentFrame *frame = (wxMDIParentFrame *)Object();
435
436 if (s.FirstStage()) {
437 s.AddChild(frame->GetClientWindow());
438 WXSERIAL(wxMDIParentFrame)::StoreObject(s);
439 return;
440 }
441
442 WXSERIAL(wxMDIParentFrame)::StoreObject(s);
443}
444
445void WXSERIAL(wxMDIParentFrame)::LoadObject(wxObjectInputStream& s)
446{
447 wxMDIParentFrame *frame = (wxMDIParentFrame *)Object();
448 wxMDIClientWindow *client;
449
450 if (s.SecondCall()) {
451 WXSERIAL(wxFrame)::LoadObject(s);
452 return;
453 }
454
455 client = (wxMDIClientWindow *) s.GetChild();
456
457 frame->Create(m_parent, m_id, m_title, wxPoint(m_x, m_y),
458 wxSize(m_w, m_h), m_style, m_name);
459
460 WXSERIAL(wxFrame)::LoadObject(s);
461}
462
463/////////////////////////////////////////////////////////////////////////////
464
465void WXSERIAL(wxMDIChildFrame)::StoreObject(wxObjectOutputStream& s)
466{
467 WXSERIAL(wxFrame)::StoreObject(s);
468}
469
470void WXSERIAL(wxMDIChildFrame)::LoadObject(wxObjectInputStream& s)
471{
472 WXSERIAL(wxFrame)::LoadObject(s);
473
474 if (s.SecondCall())
475 return;
476
477 ((wxMDIChildFrame *)Object())->Create((wxMDIParentFrame *)m_parent,
478 m_id, m_title,
479 wxPoint(m_x, m_y), wxSize(m_w, m_h),
480 m_style, m_name);
481}
482
483/////////////////////////////////////////////////////////////////////////////
484
485void WXSERIAL(wxMDIClientWindow)::StoreObject(wxObjectOutputStream& s)
486{
487 WXSERIAL(wxWindow)::StoreObject(s);
488}
489
490void WXSERIAL(wxMDIClientWindow)::LoadObject(wxObjectInputStream& s)
491{
492 WXSERIAL(wxWindow)::LoadObject(s);
493
494 if (s.SecondCall())
495 return;
496
497 ((wxMDIClientWindow *)Object())->CreateClient((wxMDIParentFrame *)m_parent, m_style);
498}