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