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