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