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