]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: serctrl.cpp | |
3 | // Purpose: Serialization: control 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 "serctrl.h" | |
14 | #endif | |
15 | ||
16 | #include <wx/window.h> | |
17 | #include <wx/control.h> | |
18 | #include <wx/button.h> | |
19 | #include <wx/checkbox.h> | |
20 | #include <wx/slider.h> | |
21 | #include <wx/gauge.h> | |
22 | #include <wx/choice.h> | |
23 | #include <wx/listbox.h> | |
24 | #include <wx/notebook.h> | |
25 | #include <wx/radiobox.h> | |
26 | #include <wx/radiobut.h> | |
27 | #include <wx/stattext.h> | |
28 | #include <wx/statbox.h> | |
29 | #include <wx/combobox.h> | |
30 | #include <wx/imaglist.h> | |
31 | #include <wx/objstrm.h> | |
32 | #include <wx/datstrm.h> | |
33 | #include <wx/serbase.h> | |
34 | #include "serwnd.h" | |
35 | #include "serctrl.h" | |
36 | ||
37 | IMPLEMENT_ALIAS_SERIAL_CLASS(wxControl, wxWindow) | |
38 | IMPLEMENT_SERIAL_CLASS(wxSlider, wxControl) | |
39 | IMPLEMENT_SERIAL_CLASS(wxCheckBox, wxControl) | |
40 | IMPLEMENT_SERIAL_CLASS(wxChoice, wxControl) | |
41 | IMPLEMENT_SERIAL_CLASS(wxComboBox, wxControl) | |
42 | IMPLEMENT_SERIAL_CLASS(wxGauge, wxControl) | |
43 | IMPLEMENT_SERIAL_CLASS(wxListBox, wxControl) | |
44 | IMPLEMENT_SERIAL_CLASS(wxNotebook, wxControl) | |
45 | IMPLEMENT_SERIAL_CLASS(wxRadioBox, wxControl) | |
46 | IMPLEMENT_SERIAL_CLASS(wxRadioButton, wxControl) | |
47 | IMPLEMENT_SERIAL_CLASS(wxButton, wxControl) | |
48 | IMPLEMENT_SERIAL_CLASS(wxStaticText, wxControl) | |
49 | IMPLEMENT_SERIAL_CLASS(wxStaticBox, wxControl) | |
50 | ||
51 | //----------------------------------------------------------------------------- | |
52 | ||
53 | void WXSERIAL(wxButton)::StoreObject(wxObjectOutputStream& s) | |
54 | { | |
55 | WXSERIAL(wxControl)::StoreObject(s); | |
56 | } | |
57 | ||
58 | void WXSERIAL(wxButton)::LoadObject(wxObjectInputStream& s) | |
59 | { | |
60 | WXSERIAL(wxControl)::LoadObject(s); | |
61 | ||
62 | wxButton *button = (wxButton *)Object(); | |
63 | ||
64 | printf("label = %s\n", WXSTRINGCAST m_label); | |
65 | button->Create(m_parent, m_id, m_label, wxPoint(m_x, m_y), wxSize(m_w, m_h), | |
66 | m_style, *m_validator, m_name); | |
67 | } | |
68 | ||
69 | //----------------------------------------------------------------------------- | |
70 | ||
71 | void WXSERIAL(wxCheckBox)::StoreObject(wxObjectOutputStream& s) | |
72 | { | |
73 | WXSERIAL(wxControl)::StoreObject(s); | |
74 | ||
75 | if (s.FirstStage()) | |
76 | return; | |
77 | ||
78 | wxDataOutputStream data_s(s); | |
79 | data_s.Write8( ((wxCheckBox *)Object())->GetValue() ); | |
80 | } | |
81 | ||
82 | void WXSERIAL(wxCheckBox)::LoadObject(wxObjectInputStream& s) | |
83 | { | |
84 | WXSERIAL(wxControl)::LoadObject(s); | |
85 | ||
86 | wxDataInputStream data_s(s); | |
87 | wxCheckBox *chkbox = (wxCheckBox *)Object(); | |
88 | ||
89 | chkbox->Create(m_parent, m_id, m_label, wxPoint(m_x, m_y), wxSize(m_w, m_h), | |
90 | m_style, *m_validator, m_name); | |
91 | ||
92 | chkbox->SetValue(data_s.Read8()); | |
93 | } | |
94 | ||
95 | //----------------------------------------------------------------------------- | |
96 | ||
97 | void WXSERIAL(wxSlider)::StoreObject(wxObjectOutputStream& s) | |
98 | { | |
99 | WXSERIAL(wxControl)::StoreObject(s); | |
100 | ||
101 | if (s.FirstStage()) | |
102 | return; | |
103 | ||
104 | wxDataOutputStream data_s(s); | |
105 | wxSlider *slider = (wxSlider *)Object(); | |
106 | ||
107 | data_s.Write32( slider->GetMin() ); | |
108 | data_s.Write32( slider->GetMax() ); | |
109 | data_s.Write32( slider->GetValue() ); | |
110 | data_s.Write32( slider->GetTickFreq() ); | |
111 | data_s.Write32( slider->GetPageSize() ); | |
112 | data_s.Write32( slider->GetLineSize() ); | |
113 | data_s.Write32( slider->GetSelStart() ); | |
114 | data_s.Write32( slider->GetSelEnd() ); | |
115 | data_s.Write32( slider->GetThumbLength() ); | |
116 | } | |
117 | ||
118 | void WXSERIAL(wxSlider)::LoadObject(wxObjectInputStream& s) | |
119 | { | |
120 | WXSERIAL(wxControl)::LoadObject(s); | |
121 | ||
122 | wxDataInputStream data_s(s); | |
123 | wxSlider *slider = (wxSlider *)Object(); | |
124 | int value, min, max; | |
125 | ||
126 | min = data_s.Read32(); | |
127 | max = data_s.Read32(); | |
128 | value = data_s.Read32(); | |
129 | ||
130 | slider->Create(m_parent, m_id, value, min, max, wxPoint(m_x, m_y), | |
131 | wxSize(m_w, m_h), m_style, *m_validator, m_name); | |
132 | ||
133 | slider->SetTickFreq( 0, data_s.Read32() ); | |
134 | slider->SetPageSize( data_s.Read32() ); | |
135 | slider->SetLineSize( data_s.Read32() ); | |
136 | min = data_s.Read32(); | |
137 | max = data_s.Read32(); | |
138 | slider->SetSelection(min, max); | |
139 | slider->SetThumbLength( data_s.Read32() ); | |
140 | } | |
141 | ||
142 | //----------------------------------------------------------------------------- | |
143 | ||
144 | void WXSERIAL(wxGauge)::StoreObject(wxObjectOutputStream& s) | |
145 | { | |
146 | WXSERIAL(wxControl)::StoreObject(s); | |
147 | ||
148 | if (s.FirstStage()) | |
149 | return; | |
150 | ||
151 | wxDataOutputStream data_s(s); | |
152 | wxGauge *gauge = (wxGauge *)Object(); | |
153 | ||
154 | data_s.Write32( gauge->GetRange() ); | |
155 | data_s.Write8( gauge->GetShadowWidth() ); | |
156 | data_s.Write8( gauge->GetBezelFace() ); | |
157 | data_s.Write32( gauge->GetValue() ); | |
158 | } | |
159 | ||
160 | void WXSERIAL(wxGauge)::LoadObject(wxObjectInputStream& s) | |
161 | { | |
162 | WXSERIAL(wxControl)::LoadObject(s); | |
163 | ||
164 | wxDataInputStream data_s(s); | |
165 | wxGauge *gauge = (wxGauge *)Object(); | |
166 | int range; | |
167 | ||
168 | range = data_s.Read32(); | |
169 | gauge->Create(m_parent, m_id, range, wxPoint(m_x, m_y), wxSize(m_w, m_h), | |
170 | m_style, *m_validator, m_name); | |
171 | ||
172 | gauge->SetShadowWidth( data_s.Read8() ); | |
173 | gauge->SetBezelFace( data_s.Read8() ); | |
174 | gauge->SetValue( data_s.Read32() ); | |
175 | } | |
176 | ||
177 | //----------------------------------------------------------------------------- | |
178 | ||
179 | void WXSERIAL(wxChoice)::StoreObject(wxObjectOutputStream& s) | |
180 | { | |
181 | WXSERIAL(wxControl)::StoreObject(s); | |
182 | ||
183 | if (s.FirstStage()) | |
184 | return; | |
185 | ||
186 | wxDataOutputStream data_s(s); | |
187 | wxChoice *choice = (wxChoice *)Object(); | |
188 | int i, num = choice->Number(); | |
189 | ||
190 | data_s.Write32(num); | |
191 | for (i=0;i<num;i++) | |
192 | data_s.WriteString( choice->GetString(i) ); | |
193 | } | |
194 | ||
195 | void WXSERIAL(wxChoice)::LoadObject(wxObjectInputStream& s) | |
196 | { | |
197 | WXSERIAL(wxControl)::LoadObject(s); | |
198 | ||
199 | wxDataInputStream data_s(s); | |
200 | wxChoice *choice = (wxChoice *)Object(); | |
201 | int i,num = data_s.Read32(); | |
202 | ||
203 | choice->Create(m_parent, m_id, wxPoint(m_x, m_y), wxSize(m_w, m_h), 0, NULL, | |
204 | m_style, *m_validator, m_name); | |
205 | ||
206 | for (i=0;i<num;i++) | |
207 | choice->Append( data_s.ReadString() ); | |
208 | } | |
209 | ||
210 | //----------------------------------------------------------------------------- | |
211 | ||
212 | void WXSERIAL(wxListBox)::StoreObject(wxObjectOutputStream& s) | |
213 | { | |
214 | WXSERIAL(wxControl)::StoreObject(s); | |
215 | ||
216 | if (s.FirstStage()) | |
217 | return; | |
218 | ||
219 | wxDataOutputStream data_s(s); | |
220 | wxListBox *listbox = (wxListBox *)Object(); | |
221 | int i, num = listbox->Number(); | |
222 | ||
223 | data_s.Write32(num); | |
224 | for (i=0;i<num;i++) | |
225 | data_s.WriteString( listbox->GetString(i) ); | |
226 | } | |
227 | ||
228 | void WXSERIAL(wxListBox)::LoadObject(wxObjectInputStream& s) | |
229 | { | |
230 | WXSERIAL(wxListBox)::LoadObject(s); | |
231 | ||
232 | wxDataInputStream data_s(s); | |
233 | wxListBox *listbox = (wxListBox *)Object(); | |
234 | int i, num = data_s.Read32(); | |
235 | ||
236 | for (i=0;i<num;i++) | |
237 | listbox->Append( data_s.ReadString() ); | |
238 | } | |
239 | ||
240 | //----------------------------------------------------------------------------- | |
241 | ||
242 | void WXSERIAL(wxNotebook)::StoreObject(wxObjectOutputStream& s) | |
243 | { | |
244 | wxNotebook *notebook = (wxNotebook *)Object(); | |
245 | wxImageList *imaglist = notebook->GetImageList(); | |
246 | int i, pcount = notebook->GetPageCount(); | |
247 | ||
248 | WXSERIAL(wxControl)::StoreObject(s); | |
249 | if (s.FirstStage()) { | |
250 | s.AddChild(imaglist); | |
251 | return; | |
252 | } | |
253 | ||
254 | wxDataOutputStream data_s(s); | |
255 | ||
256 | data_s.Write8( pcount ); | |
257 | ||
258 | for (i=0;i<pcount;i++) | |
259 | data_s.WriteString( notebook->GetPageText(i) ); | |
260 | } | |
261 | ||
262 | void WXSERIAL(wxNotebook)::LoadObject(wxObjectInputStream& s) | |
263 | { | |
264 | wxNotebook *notebook = (wxNotebook *)Object(); | |
265 | int i; | |
266 | wxImageList *imaglist; | |
267 | ||
268 | if (s.SecondCall()) { | |
269 | for (i=0;i<m_pcount;i++) | |
270 | notebook->AddPage( (wxWindow *)s.GetChild(), m_stringlist[i] ); | |
271 | return; | |
272 | } | |
273 | ||
274 | WXSERIAL(wxControl)::LoadObject(s); | |
275 | ||
276 | imaglist = (wxImageList *)s.GetChild(); | |
277 | ||
278 | notebook->Create(m_parent, m_id, wxPoint(m_x, m_y), wxSize(m_w, m_h), | |
279 | m_style, m_name); | |
280 | ||
281 | wxDataInputStream data_s(s); | |
282 | ||
283 | m_pcount = data_s.Read8(); | |
284 | for (i=0;i<m_pcount;i++) | |
285 | m_stringlist.Add(data_s.ReadString()); | |
286 | s.Recall(); | |
287 | } | |
288 | ||
289 | //----------------------------------------------------------------------------- | |
290 | ||
291 | void WXSERIAL(wxRadioBox)::StoreObject(wxObjectOutputStream& s) | |
292 | { | |
293 | wxRadioBox *box = (wxRadioBox *)Object(); | |
294 | WXSERIAL(wxControl)::StoreObject(s); | |
295 | ||
296 | if (s.FirstStage()) | |
297 | return; | |
298 | ||
299 | wxDataOutputStream data_s(s); | |
300 | int i, n_items = box->Number(); | |
301 | ||
302 | data_s.Write8( n_items ); | |
303 | data_s.Write8( box->GetNumberOfRowsOrCols() ); | |
304 | ||
305 | for (i=0;i<n_items;i++) | |
306 | data_s.WriteString( box->GetString(i) ); | |
307 | } | |
308 | ||
309 | void WXSERIAL(wxRadioBox)::LoadObject(wxObjectInputStream& s) | |
310 | { | |
311 | wxRadioBox *box = (wxRadioBox *)Object(); | |
312 | ||
313 | WXSERIAL(wxControl)::LoadObject(s); | |
314 | ||
315 | wxDataInputStream data_s(s); | |
316 | int i, n_rows_cols, n_items; | |
317 | wxString *items; | |
318 | ||
319 | n_items = data_s.Read8(); | |
320 | n_rows_cols = data_s.Read8(); | |
321 | ||
322 | items = new wxString[n_items]; | |
323 | for (i=0;i<n_items;i++) | |
324 | items[i] = data_s.ReadString(); | |
325 | ||
326 | box->Create(m_parent, m_id, m_title, wxPoint(m_x, m_y), wxSize(m_w, m_h), | |
327 | n_items, items, 0, m_style, *m_validator, m_name); | |
328 | } | |
329 | ||
330 | //----------------------------------------------------------------------------- | |
331 | ||
332 | void WXSERIAL(wxRadioButton)::StoreObject(wxObjectOutputStream& s) | |
333 | { | |
334 | WXSERIAL(wxControl)::StoreObject(s); | |
335 | ||
336 | if (s.FirstStage()) | |
337 | return; | |
338 | ||
339 | wxDataOutputStream data_s(s); | |
340 | data_s.Write8( (char) ((wxRadioButton *)Object())->GetValue() ); | |
341 | } | |
342 | ||
343 | void WXSERIAL(wxRadioButton)::LoadObject(wxObjectInputStream& s) | |
344 | { | |
345 | wxDataInputStream data_s(s); | |
346 | ||
347 | WXSERIAL(wxControl)::LoadObject(s); | |
348 | ((wxRadioButton *)Object())->SetValue( (bool)data_s.Read8() ); | |
349 | } | |
350 | ||
351 | //----------------------------------------------------------------------------- | |
352 | ||
353 | void WXSERIAL(wxComboBox)::StoreObject(wxObjectOutputStream& s) | |
354 | { | |
355 | WXSERIAL(wxControl)::StoreObject(s); | |
356 | ||
357 | if (s.FirstStage()) | |
358 | return; | |
359 | ||
360 | wxDataOutputStream data_s(s); | |
361 | wxComboBox *box = (wxComboBox *)Object(); | |
362 | int i, num = box->Number(); | |
363 | ||
364 | data_s.Write8( num ); | |
365 | data_s.Write8( box->GetSelection() ); | |
366 | for (i=0;i<num;i++) | |
367 | data_s.WriteString( box->GetString(i) ); | |
368 | ||
369 | data_s.WriteString( box->GetValue() ); | |
370 | ||
371 | // TODO: Editable flag | |
372 | } | |
373 | ||
374 | void WXSERIAL(wxComboBox)::LoadObject(wxObjectInputStream& s) | |
375 | { | |
376 | WXSERIAL(wxControl)::LoadObject(s); | |
377 | ||
378 | wxDataInputStream data_s(s); | |
379 | wxComboBox *box = (wxComboBox *)Object(); | |
380 | int i, num, selection; | |
381 | ||
382 | box->Create(m_parent, m_id, wxEmptyString, wxPoint(m_x, m_y), wxSize(m_w, m_h), | |
383 | 0, NULL, m_style, *m_validator, m_name); | |
384 | ||
385 | num = data_s.Read8(); | |
386 | selection = data_s.Read8(); | |
387 | ||
388 | for (i=0;i<num;i++) | |
389 | box->Append( data_s.ReadString() ); | |
390 | ||
391 | box->SetSelection( selection ); | |
392 | box->SetValue( data_s.ReadString() ); | |
393 | } | |
394 | ||
395 | //----------------------------------------------------------------------------- | |
396 | ||
397 | void WXSERIAL(wxStaticText)::StoreObject(wxObjectOutputStream& s) | |
398 | { | |
399 | WXSERIAL(wxControl)::StoreObject(s); | |
400 | } | |
401 | ||
402 | void WXSERIAL(wxStaticText)::LoadObject(wxObjectInputStream& s) | |
403 | { | |
404 | WXSERIAL(wxControl)::LoadObject(s); | |
405 | ||
406 | ((wxStaticText *)Object())->Create(m_parent, m_id, m_label, wxPoint(m_x, m_y), | |
407 | wxSize(m_w, m_h), m_style, m_name); | |
408 | } | |
409 | ||
410 | //----------------------------------------------------------------------------- | |
411 | ||
412 | void WXSERIAL(wxStaticBox)::StoreObject(wxObjectOutputStream& s) | |
413 | { | |
414 | WXSERIAL(wxControl)::StoreObject(s); | |
415 | } | |
416 | ||
417 | void WXSERIAL(wxStaticBox)::LoadObject(wxObjectInputStream& s) | |
418 | { | |
419 | WXSERIAL(wxControl)::LoadObject(s); | |
420 | ||
421 | ((wxStaticBox *)Object())->Create(m_parent, m_id, m_label, wxPoint(m_x, m_y), | |
422 | wxSize(m_w, m_h), m_style, m_name); | |
423 | } |