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