]> git.saurik.com Git - wxWidgets.git/blame - utils/serialize/serwnd.cpp
added wxDialUpManager::IsAlwaysConnected() and GetISPNames(), also Dial()
[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.
856d2e52
GL
61 m_bg_colour = win_object->GetBackgroundColour();
62 m_fg_colour = win_object->GetForegroundColour();
c2dd8380
GL
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;
856d2e52
GL
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 }
9fdd8384
GL
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();
856d2e52 130 m_number = data_s.Read8();
9fdd8384
GL
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
1d44aaf8 137 (void)s.GetChild(); // We pass wxLayoutConstraints.
856d2e52 138
8d43638d 139 m_validator = (wxValidator *)s.GetChild();
1d44aaf8
GL
140 if (!m_validator)
141 m_validator = (wxValidator *)&wxDefaultValidator;
142
856d2e52 143 s.RemoveChildren(m_number+3);
1d44aaf8 144
856d2e52 145 s.Recall();
9fdd8384
GL
146
147 return;
148}
149
c2dd8380
GL
150/////////////////////////////////////////////////////////////////////////////
151
9fdd8384
GL
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
c2dd8380
GL
189/////////////////////////////////////////////////////////////////////////////
190
9fdd8384
GL
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
c2dd8380
GL
238/////////////////////////////////////////////////////////////////////////////
239
9fdd8384
GL
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();
8d43638d
GL
254
255 // AAARGH !! I absolutely need to be able to modify internal fields of
256 // wxFrame (wxToolBar and wxStatusBar)
9fdd8384
GL
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();
8d43638d 269 wxMenuBar *mbar = (wxMenuBar *)s.GetChild();
9fdd8384 270
9fdd8384
GL
271 WXSERIAL(wxWindow)::LoadObject(s);
272
856d2e52
GL
273 if (s.SecondCall())
274 return;
275
9fdd8384
GL
276 wxDataInputStream data_s(s);
277
c2dd8380
GL
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);
856d2e52 281 frame->SetMenuBar(mbar);
9fdd8384
GL
282
283 frame->CreateStatusBar(data_s.Read8());
284}
285
c2dd8380
GL
286/////////////////////////////////////////////////////////////////////////////
287
9fdd8384
GL
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++) {
8d43638d 315 wxMenu *menu = (wxMenu *)s.GetChild();
9fdd8384
GL
316 mbar->Append( menu, menu->GetTitle() );
317 }
318
319 // It isn't necessary for this object.
320 // WXSERIAL(wxWindow)::LoadObject(s);
321}
322
c2dd8380
GL
323/////////////////////////////////////////////////////////////////////////////
324
9fdd8384
GL
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();
8d43638d 341 wxList *items = (wxList *)s.GetChild();
9fdd8384
GL
342 wxNode *node = items->First();
343
344 wxDataInputStream data_s(s);
345
8d43638d 346 menu->SetTitle( data_s.ReadString() );
9fdd8384
GL
347
348 while (node) {
349// NOT IMPLEMENTED in wxGTK
350// menu->Append( (wxMenuItem *)node->Data() );
351 node = node->Next();
352 }
353}
354
c2dd8380
GL
355/////////////////////////////////////////////////////////////////////////////
356
9fdd8384
GL
357void WXSERIAL(wxMenuItem)::StoreObject(wxObjectOutputStream& s)
358{
359 wxMenuItem *item = (wxMenuItem *)Object();
360
361 if (s.FirstStage()) {
856d2e52 362#ifdef __WXGTK__
9fdd8384 363 s.AddChild(item->GetSubMenu());
856d2e52 364#endif
9fdd8384
GL
365 return;
366 }
367
368 wxDataOutputStream data_s(s);
369
856d2e52 370#ifdef __WXGTK__
9fdd8384
GL
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() );
856d2e52 376#endif
9fdd8384
GL
377}
378
379void WXSERIAL(wxMenuItem)::LoadObject(wxObjectInputStream& s)
380{
381 wxMenuItem *item = (wxMenuItem *)Object();
382 wxDataInputStream data_s(s);
383
856d2e52 384#ifdef __WXGTK__
9fdd8384
GL
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() );
8d43638d 390 item->SetSubMenu( (wxMenu *)s.GetChild() );
856d2e52 391#endif
9fdd8384 392}
123a7fdd 393
c2dd8380
GL
394/////////////////////////////////////////////////////////////////////////////
395
123a7fdd
GL
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
856d2e52
GL
405 if (s.SecondCall())
406 return;
407
123a7fdd
GL
408 ((wxPanel *)Object())->Create(m_parent, m_id, wxPoint(m_x, m_y),
409 wxSize(m_w, m_h), m_style, m_name);
410}
c2dd8380
GL
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
856d2e52
GL
423 if (s.SecondCall())
424 return;
425
c2dd8380
GL
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
856d2e52
GL
450 if (s.SecondCall()) {
451 WXSERIAL(wxFrame)::LoadObject(s);
452 return;
453 }
454
8d43638d 455 client = (wxMDIClientWindow *) s.GetChild();
c2dd8380
GL
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);
c2dd8380
GL
459
460 WXSERIAL(wxFrame)::LoadObject(s);
461}
8d43638d
GL
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
856d2e52
GL
474 if (s.SecondCall())
475 return;
476
8d43638d
GL
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
856d2e52
GL
494 if (s.SecondCall())
495 return;
496
8d43638d
GL
497 ((wxMDIClientWindow *)Object())->CreateClient((wxMDIParentFrame *)m_parent, m_style);
498}