]>
Commit | Line | Data |
---|---|---|
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 | ||
33 | IMPLEMENT_SERIAL_CLASS(wxWindow, wxObject) | |
34 | IMPLEMENT_SERIAL_CLASS(wxIndividualLayoutConstraint, wxObject) | |
35 | IMPLEMENT_SERIAL_CLASS(wxLayoutConstraints, wxObject) | |
36 | IMPLEMENT_ALIAS_SERIAL_CLASS(wxValidator, wxObject) | |
37 | IMPLEMENT_SERIAL_CLASS(wxFrame, wxWindow) | |
38 | IMPLEMENT_SERIAL_CLASS(wxPanel, wxWindow) | |
39 | IMPLEMENT_SERIAL_CLASS(wxDialog, wxWindow) | |
40 | IMPLEMENT_SERIAL_CLASS(wxMenuBar, wxWindow) | |
41 | IMPLEMENT_SERIAL_CLASS(wxMenuItem, wxObject) | |
42 | IMPLEMENT_SERIAL_CLASS(wxMenu, wxObject) | |
43 | ||
44 | IMPLEMENT_SERIAL_CLASS(wxMDIParentFrame, wxFrame) | |
45 | IMPLEMENT_SERIAL_CLASS(wxMDIChildFrame, wxFrame) | |
46 | IMPLEMENT_SERIAL_CLASS(wxMDIClientWindow, wxWindow) | |
47 | ||
48 | ///////////////////////////////////////////////////////////////////////////// | |
49 | ||
50 | void 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->GetDefaultBackgroundColour(); | |
62 | m_fg_colour = win_object->GetDefaultForegroundColour(); | |
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 | ||
95 | void WXSERIAL(wxWindow)::LoadObject(wxObjectInputStream& s) | |
96 | { | |
97 | wxDataInputStream data_s(s); | |
98 | wxWindow *win_object = (wxWindow *)Object(); | |
99 | wxColour *colour; | |
100 | wxFont *font; | |
101 | int number; | |
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(); | |
113 | number = data_s.Read8(); | |
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 */ | |
121 | (void)s.GetChild(); // We pass wxLayoutConstraints. | |
122 | ||
123 | m_validator = (wxValidator *)s.GetChild(); | |
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); | |
138 | ||
139 | return; | |
140 | } | |
141 | ||
142 | ///////////////////////////////////////////////////////////////////////////// | |
143 | ||
144 | void 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 | ||
163 | void 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 | ||
181 | ///////////////////////////////////////////////////////////////////////////// | |
182 | ||
183 | void 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 | ||
205 | void 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 | ||
230 | ///////////////////////////////////////////////////////////////////////////// | |
231 | ||
232 | void 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(); | |
246 | ||
247 | // AAARGH !! I absolutely need to be able to modify internal fields of | |
248 | // wxFrame (wxToolBar and wxStatusBar) | |
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 | ||
258 | void WXSERIAL(wxFrame)::LoadObject(wxObjectInputStream& s) | |
259 | { | |
260 | wxFrame *frame = (wxFrame *)Object(); | |
261 | wxMenuBar *mbar = (wxMenuBar *)s.GetChild(); | |
262 | ||
263 | WXSERIAL(wxWindow)::LoadObject(s); | |
264 | ||
265 | wxDataInputStream data_s(s); | |
266 | ||
267 | frame->SetMenuBar(mbar); | |
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); | |
271 | ||
272 | frame->CreateStatusBar(data_s.Read8()); | |
273 | } | |
274 | ||
275 | ///////////////////////////////////////////////////////////////////////////// | |
276 | ||
277 | void 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 | ||
296 | void 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++) { | |
304 | wxMenu *menu = (wxMenu *)s.GetChild(); | |
305 | mbar->Append( menu, menu->GetTitle() ); | |
306 | } | |
307 | ||
308 | // It isn't necessary for this object. | |
309 | // WXSERIAL(wxWindow)::LoadObject(s); | |
310 | } | |
311 | ||
312 | ///////////////////////////////////////////////////////////////////////////// | |
313 | ||
314 | void 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 | ||
327 | void WXSERIAL(wxMenu)::LoadObject(wxObjectInputStream& s) | |
328 | { | |
329 | wxMenu *menu = (wxMenu *)Object(); | |
330 | wxList *items = (wxList *)s.GetChild(); | |
331 | wxNode *node = items->First(); | |
332 | ||
333 | wxDataInputStream data_s(s); | |
334 | ||
335 | menu->SetTitle( data_s.ReadString() ); | |
336 | ||
337 | while (node) { | |
338 | // NOT IMPLEMENTED in wxGTK | |
339 | // menu->Append( (wxMenuItem *)node->Data() ); | |
340 | node = node->Next(); | |
341 | } | |
342 | } | |
343 | ||
344 | ///////////////////////////////////////////////////////////////////////////// | |
345 | ||
346 | void 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 | ||
364 | void 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() ); | |
374 | item->SetSubMenu( (wxMenu *)s.GetChild() ); | |
375 | } | |
376 | ||
377 | ///////////////////////////////////////////////////////////////////////////// | |
378 | ||
379 | void WXSERIAL(wxPanel)::StoreObject(wxObjectOutputStream& s) | |
380 | { | |
381 | WXSERIAL(wxWindow)::StoreObject(s); | |
382 | } | |
383 | ||
384 | void 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 | } | |
391 | ||
392 | ///////////////////////////////////////////////////////////////////////////// | |
393 | ||
394 | void WXSERIAL(wxDialog)::StoreObject(wxObjectOutputStream& s) | |
395 | { | |
396 | WXSERIAL(wxWindow)::StoreObject(s); | |
397 | } | |
398 | ||
399 | void 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 | ||
409 | void 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 | ||
422 | void WXSERIAL(wxMDIParentFrame)::LoadObject(wxObjectInputStream& s) | |
423 | { | |
424 | wxMDIParentFrame *frame = (wxMDIParentFrame *)Object(); | |
425 | wxMDIClientWindow *client; | |
426 | ||
427 | client = (wxMDIClientWindow *) s.GetChild(); | |
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); | |
431 | ||
432 | WXSERIAL(wxFrame)::LoadObject(s); | |
433 | } | |
434 | ||
435 | ///////////////////////////////////////////////////////////////////////////// | |
436 | ||
437 | void WXSERIAL(wxMDIChildFrame)::StoreObject(wxObjectOutputStream& s) | |
438 | { | |
439 | WXSERIAL(wxFrame)::StoreObject(s); | |
440 | } | |
441 | ||
442 | void 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 | ||
454 | void WXSERIAL(wxMDIClientWindow)::StoreObject(wxObjectOutputStream& s) | |
455 | { | |
456 | WXSERIAL(wxWindow)::StoreObject(s); | |
457 | } | |
458 | ||
459 | void WXSERIAL(wxMDIClientWindow)::LoadObject(wxObjectInputStream& s) | |
460 | { | |
461 | WXSERIAL(wxWindow)::LoadObject(s); | |
462 | ||
463 | ((wxMDIClientWindow *)Object())->CreateClient((wxMDIParentFrame *)m_parent, m_style); | |
464 | } |