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