]> git.saurik.com Git - wxWidgets.git/blame - utils/serialize/serctrl.cpp
change in XRC format
[wxWidgets.git] / utils / serialize / serctrl.cpp
CommitLineData
123a7fdd
GL
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
9fdd8384
GL
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>
8d43638d 26#include <wx/radiobut.h>
9fdd8384 27#include <wx/stattext.h>
8d43638d 28#include <wx/statbox.h>
9fdd8384 29#include <wx/combobox.h>
c2dd8380 30#include <wx/imaglist.h>
9fdd8384
GL
31#include <wx/objstrm.h>
32#include <wx/datstrm.h>
33#include <wx/serbase.h>
34#include "serwnd.h"
35#include "serctrl.h"
36
37IMPLEMENT_ALIAS_SERIAL_CLASS(wxControl, wxWindow)
856d2e52
GL
38#ifdef __WINDOWS__
39IMPLEMENT_SERIAL_CLASS(wxSlider95, wxControl)
40IMPLEMENT_SERIAL_CLASS(wxGauge95, wxControl)
41#else
9fdd8384 42IMPLEMENT_SERIAL_CLASS(wxSlider, wxControl)
856d2e52
GL
43IMPLEMENT_SERIAL_CLASS(wxGauge, wxControl)
44#endif
9fdd8384
GL
45IMPLEMENT_SERIAL_CLASS(wxCheckBox, wxControl)
46IMPLEMENT_SERIAL_CLASS(wxChoice, wxControl)
47IMPLEMENT_SERIAL_CLASS(wxComboBox, wxControl)
9fdd8384
GL
48IMPLEMENT_SERIAL_CLASS(wxListBox, wxControl)
49IMPLEMENT_SERIAL_CLASS(wxNotebook, wxControl)
50IMPLEMENT_SERIAL_CLASS(wxRadioBox, wxControl)
8d43638d 51IMPLEMENT_SERIAL_CLASS(wxRadioButton, wxControl)
9fdd8384
GL
52IMPLEMENT_SERIAL_CLASS(wxButton, wxControl)
53IMPLEMENT_SERIAL_CLASS(wxStaticText, wxControl)
1d44aaf8 54IMPLEMENT_SERIAL_CLASS(wxStaticBox, wxControl)
9fdd8384 55
8d43638d
GL
56//-----------------------------------------------------------------------------
57
9fdd8384
GL
58void WXSERIAL(wxButton)::StoreObject(wxObjectOutputStream& s)
59{
60 WXSERIAL(wxControl)::StoreObject(s);
61}
62
63void WXSERIAL(wxButton)::LoadObject(wxObjectInputStream& s)
64{
65 WXSERIAL(wxControl)::LoadObject(s);
66
856d2e52
GL
67 if (s.SecondCall())
68 return;
69
9fdd8384
GL
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),
c2dd8380 74 m_style, *m_validator, m_name);
9fdd8384
GL
75}
76
8d43638d
GL
77//-----------------------------------------------------------------------------
78
9fdd8384
GL
79void 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
90void WXSERIAL(wxCheckBox)::LoadObject(wxObjectInputStream& s)
91{
92 WXSERIAL(wxControl)::LoadObject(s);
93
856d2e52
GL
94 if (s.SecondCall())
95 return;
96
9fdd8384
GL
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),
c2dd8380 101 m_style, *m_validator, m_name);
9fdd8384
GL
102
103 chkbox->SetValue(data_s.Read8());
104}
105
8d43638d
GL
106//-----------------------------------------------------------------------------
107
856d2e52
GL
108#ifdef __WXMSW__
109void WXSERIAL(wxSlider95)::StoreObject(wxObjectOutputStream& s)
110#else
9fdd8384 111void WXSERIAL(wxSlider)::StoreObject(wxObjectOutputStream& s)
856d2e52 112#endif
9fdd8384
GL
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
856d2e52
GL
133#ifdef __WXMSW__
134void WXSERIAL(wxSlider95)::LoadObject(wxObjectInputStream& s)
135#else
9fdd8384 136void WXSERIAL(wxSlider)::LoadObject(wxObjectInputStream& s)
856d2e52 137#endif
9fdd8384
GL
138{
139 WXSERIAL(wxControl)::LoadObject(s);
140
856d2e52
GL
141 if (s.SecondCall())
142 return;
143
9fdd8384
GL
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),
c2dd8380 153 wxSize(m_w, m_h), m_style, *m_validator, m_name);
9fdd8384
GL
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
8d43638d
GL
164//-----------------------------------------------------------------------------
165
856d2e52
GL
166#ifdef __WXMSW__
167void WXSERIAL(wxGauge95)::StoreObject(wxObjectOutputStream& s)
168#else
9fdd8384 169void WXSERIAL(wxGauge)::StoreObject(wxObjectOutputStream& s)
856d2e52 170#endif
9fdd8384
GL
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
856d2e52
GL
186#ifdef __WXMSW__
187void WXSERIAL(wxGauge95)::LoadObject(wxObjectInputStream& s)
188#else
9fdd8384 189void WXSERIAL(wxGauge)::LoadObject(wxObjectInputStream& s)
856d2e52 190#endif
9fdd8384
GL
191{
192 WXSERIAL(wxControl)::LoadObject(s);
193
856d2e52
GL
194 if (s.SecondCall())
195 return;
196
9fdd8384
GL
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),
c2dd8380 203 m_style, *m_validator, m_name);
9fdd8384
GL
204
205 gauge->SetShadowWidth( data_s.Read8() );
206 gauge->SetBezelFace( data_s.Read8() );
207 gauge->SetValue( data_s.Read32() );
208}
209
8d43638d
GL
210//-----------------------------------------------------------------------------
211
9fdd8384
GL
212void 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
228void WXSERIAL(wxChoice)::LoadObject(wxObjectInputStream& s)
229{
230 WXSERIAL(wxControl)::LoadObject(s);
231
856d2e52
GL
232 if (s.SecondCall())
233 return;
234
9fdd8384
GL
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,
c2dd8380 240 m_style, *m_validator, m_name);
9fdd8384
GL
241
242 for (i=0;i<num;i++)
243 choice->Append( data_s.ReadString() );
244}
245
8d43638d
GL
246//-----------------------------------------------------------------------------
247
9fdd8384
GL
248void 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
264void WXSERIAL(wxListBox)::LoadObject(wxObjectInputStream& s)
265{
266 WXSERIAL(wxListBox)::LoadObject(s);
267
856d2e52
GL
268 if (s.SecondCall())
269 return;
270
9fdd8384
GL
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
8d43638d
GL
279//-----------------------------------------------------------------------------
280
9fdd8384
GL
281void WXSERIAL(wxNotebook)::StoreObject(wxObjectOutputStream& s)
282{
283 wxNotebook *notebook = (wxNotebook *)Object();
c2dd8380 284 wxImageList *imaglist = notebook->GetImageList();
9fdd8384
GL
285 int i, pcount = notebook->GetPageCount();
286
1d44aaf8 287 WXSERIAL(wxControl)::StoreObject(s);
9fdd8384 288 if (s.FirstStage()) {
c2dd8380 289 s.AddChild(imaglist);
9fdd8384
GL
290 return;
291 }
292
293 wxDataOutputStream data_s(s);
294
295 data_s.Write8( pcount );
c2dd8380 296
9fdd8384
GL
297 for (i=0;i<pcount;i++)
298 data_s.WriteString( notebook->GetPageText(i) );
299}
300
301void WXSERIAL(wxNotebook)::LoadObject(wxObjectInputStream& s)
302{
303 wxNotebook *notebook = (wxNotebook *)Object();
1d44aaf8 304 int i;
c2dd8380
GL
305 wxImageList *imaglist;
306
856d2e52
GL
307 WXSERIAL(wxControl)::LoadObject(s);
308
1d44aaf8
GL
309 if (s.SecondCall()) {
310 for (i=0;i<m_pcount;i++)
311 notebook->AddPage( (wxWindow *)s.GetChild(), m_stringlist[i] );
312 return;
313 }
9fdd8384 314
1d44aaf8
GL
315 imaglist = (wxImageList *)s.GetChild();
316
9fdd8384
GL
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
1d44aaf8
GL
322 m_pcount = data_s.Read8();
323 for (i=0;i<m_pcount;i++)
324 m_stringlist.Add(data_s.ReadString());
325 s.Recall();
9fdd8384
GL
326}
327
8d43638d
GL
328//-----------------------------------------------------------------------------
329
9fdd8384
GL
330void 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
348void WXSERIAL(wxRadioBox)::LoadObject(wxObjectInputStream& s)
349{
350 wxRadioBox *box = (wxRadioBox *)Object();
351
352 WXSERIAL(wxControl)::LoadObject(s);
353
856d2e52
GL
354 if (s.SecondCall())
355 return;
356
9fdd8384
GL
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),
c2dd8380 369 n_items, items, 0, m_style, *m_validator, m_name);
9fdd8384
GL
370}
371
8d43638d
GL
372//-----------------------------------------------------------------------------
373
374void 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
385void WXSERIAL(wxRadioButton)::LoadObject(wxObjectInputStream& s)
386{
387 wxDataInputStream data_s(s);
388
389 WXSERIAL(wxControl)::LoadObject(s);
856d2e52
GL
390
391 if (s.SecondCall())
392 return;
393
8d43638d
GL
394 ((wxRadioButton *)Object())->SetValue( (bool)data_s.Read8() );
395}
396
397//-----------------------------------------------------------------------------
398
9fdd8384
GL
399void 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
420void WXSERIAL(wxComboBox)::LoadObject(wxObjectInputStream& s)
421{
422 WXSERIAL(wxControl)::LoadObject(s);
423
856d2e52
GL
424 if (s.SecondCall())
425 return;
426
9fdd8384
GL
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),
c2dd8380 432 0, NULL, m_style, *m_validator, m_name);
9fdd8384
GL
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
8d43638d
GL
444//-----------------------------------------------------------------------------
445
9fdd8384
GL
446void WXSERIAL(wxStaticText)::StoreObject(wxObjectOutputStream& s)
447{
448 WXSERIAL(wxControl)::StoreObject(s);
449}
450
451void WXSERIAL(wxStaticText)::LoadObject(wxObjectInputStream& s)
452{
453 WXSERIAL(wxControl)::LoadObject(s);
454
856d2e52
GL
455 if (s.SecondCall())
456 return;
457
9fdd8384
GL
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}
8d43638d
GL
461
462//-----------------------------------------------------------------------------
463
464void WXSERIAL(wxStaticBox)::StoreObject(wxObjectOutputStream& s)
465{
466 WXSERIAL(wxControl)::StoreObject(s);
467}
468
469void WXSERIAL(wxStaticBox)::LoadObject(wxObjectInputStream& s)
470{
471 WXSERIAL(wxControl)::LoadObject(s);
856d2e52
GL
472
473 if (s.SecondCall())
474 return;
8d43638d
GL
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}