]> git.saurik.com Git - wxWidgets.git/blame - utils/serialize/serctrl.cpp
wxFileConfig ctor now (again) uses the files in the correct locations if the
[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)
38IMPLEMENT_SERIAL_CLASS(wxSlider, wxControl)
39IMPLEMENT_SERIAL_CLASS(wxCheckBox, wxControl)
40IMPLEMENT_SERIAL_CLASS(wxChoice, wxControl)
41IMPLEMENT_SERIAL_CLASS(wxComboBox, wxControl)
42IMPLEMENT_SERIAL_CLASS(wxGauge, wxControl)
43IMPLEMENT_SERIAL_CLASS(wxListBox, wxControl)
44IMPLEMENT_SERIAL_CLASS(wxNotebook, wxControl)
45IMPLEMENT_SERIAL_CLASS(wxRadioBox, wxControl)
8d43638d 46IMPLEMENT_SERIAL_CLASS(wxRadioButton, wxControl)
9fdd8384
GL
47IMPLEMENT_SERIAL_CLASS(wxButton, wxControl)
48IMPLEMENT_SERIAL_CLASS(wxStaticText, wxControl)
1d44aaf8 49IMPLEMENT_SERIAL_CLASS(wxStaticBox, wxControl)
9fdd8384 50
8d43638d
GL
51//-----------------------------------------------------------------------------
52
9fdd8384
GL
53void WXSERIAL(wxButton)::StoreObject(wxObjectOutputStream& s)
54{
55 WXSERIAL(wxControl)::StoreObject(s);
56}
57
58void 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),
c2dd8380 66 m_style, *m_validator, m_name);
9fdd8384
GL
67}
68
8d43638d
GL
69//-----------------------------------------------------------------------------
70
9fdd8384
GL
71void 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
82void 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),
c2dd8380 90 m_style, *m_validator, m_name);
9fdd8384
GL
91
92 chkbox->SetValue(data_s.Read8());
93}
94
8d43638d
GL
95//-----------------------------------------------------------------------------
96
9fdd8384
GL
97void 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
118void 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),
c2dd8380 131 wxSize(m_w, m_h), m_style, *m_validator, m_name);
9fdd8384
GL
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
8d43638d
GL
142//-----------------------------------------------------------------------------
143
9fdd8384
GL
144void 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
160void 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),
c2dd8380 170 m_style, *m_validator, m_name);
9fdd8384
GL
171
172 gauge->SetShadowWidth( data_s.Read8() );
173 gauge->SetBezelFace( data_s.Read8() );
174 gauge->SetValue( data_s.Read32() );
175}
176
8d43638d
GL
177//-----------------------------------------------------------------------------
178
9fdd8384
GL
179void 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
195void 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,
c2dd8380 204 m_style, *m_validator, m_name);
9fdd8384
GL
205
206 for (i=0;i<num;i++)
207 choice->Append( data_s.ReadString() );
208}
209
8d43638d
GL
210//-----------------------------------------------------------------------------
211
9fdd8384
GL
212void 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
228void 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
8d43638d
GL
240//-----------------------------------------------------------------------------
241
9fdd8384
GL
242void WXSERIAL(wxNotebook)::StoreObject(wxObjectOutputStream& s)
243{
244 wxNotebook *notebook = (wxNotebook *)Object();
c2dd8380 245 wxImageList *imaglist = notebook->GetImageList();
9fdd8384
GL
246 int i, pcount = notebook->GetPageCount();
247
1d44aaf8 248 WXSERIAL(wxControl)::StoreObject(s);
9fdd8384 249 if (s.FirstStage()) {
c2dd8380 250 s.AddChild(imaglist);
9fdd8384
GL
251 return;
252 }
253
254 wxDataOutputStream data_s(s);
255
256 data_s.Write8( pcount );
c2dd8380 257
9fdd8384
GL
258 for (i=0;i<pcount;i++)
259 data_s.WriteString( notebook->GetPageText(i) );
260}
261
262void WXSERIAL(wxNotebook)::LoadObject(wxObjectInputStream& s)
263{
264 wxNotebook *notebook = (wxNotebook *)Object();
1d44aaf8 265 int i;
c2dd8380
GL
266 wxImageList *imaglist;
267
1d44aaf8
GL
268 if (s.SecondCall()) {
269 for (i=0;i<m_pcount;i++)
270 notebook->AddPage( (wxWindow *)s.GetChild(), m_stringlist[i] );
271 return;
272 }
9fdd8384
GL
273
274 WXSERIAL(wxControl)::LoadObject(s);
275
1d44aaf8
GL
276 imaglist = (wxImageList *)s.GetChild();
277
9fdd8384
GL
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
1d44aaf8
GL
283 m_pcount = data_s.Read8();
284 for (i=0;i<m_pcount;i++)
285 m_stringlist.Add(data_s.ReadString());
286 s.Recall();
9fdd8384
GL
287}
288
8d43638d
GL
289//-----------------------------------------------------------------------------
290
9fdd8384
GL
291void 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
309void 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),
c2dd8380 327 n_items, items, 0, m_style, *m_validator, m_name);
9fdd8384
GL
328}
329
8d43638d
GL
330//-----------------------------------------------------------------------------
331
332void 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
343void 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
9fdd8384
GL
353void 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
374void 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),
c2dd8380 383 0, NULL, m_style, *m_validator, m_name);
9fdd8384
GL
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
8d43638d
GL
395//-----------------------------------------------------------------------------
396
9fdd8384
GL
397void WXSERIAL(wxStaticText)::StoreObject(wxObjectOutputStream& s)
398{
399 WXSERIAL(wxControl)::StoreObject(s);
400}
401
402void 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}
8d43638d
GL
409
410//-----------------------------------------------------------------------------
411
412void WXSERIAL(wxStaticBox)::StoreObject(wxObjectOutputStream& s)
413{
414 WXSERIAL(wxControl)::StoreObject(s);
415}
416
417void 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}