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