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