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