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