]>
git.saurik.com Git - wxWidgets.git/blob - utils/serialize/serctrl.cpp
982dbc5440285e2d5cb9036785379adc3f92eccd
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Serialization: control classes
4 // Author: Guilhem Lavaux
8 // Copyright: (c) 1998 Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "serctrl.h"
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>
22 #include <wx/choice.h>
23 #include <wx/listbox.h>
24 #include <wx/notebook.h>
25 #include <wx/radiobox.h>
26 #include <wx/radiobut.h>
27 #include <wx/stattext.h>
28 #include <wx/statbox.h>
29 #include <wx/combobox.h>
30 #include <wx/imaglist.h>
31 #include <wx/objstrm.h>
32 #include <wx/datstrm.h>
33 #include <wx/serbase.h>
37 IMPLEMENT_ALIAS_SERIAL_CLASS(wxControl
, wxWindow
)
38 IMPLEMENT_SERIAL_CLASS(wxSlider
, wxControl
)
39 IMPLEMENT_SERIAL_CLASS(wxCheckBox
, wxControl
)
40 IMPLEMENT_SERIAL_CLASS(wxChoice
, wxControl
)
41 IMPLEMENT_SERIAL_CLASS(wxComboBox
, wxControl
)
42 IMPLEMENT_SERIAL_CLASS(wxGauge
, wxControl
)
43 IMPLEMENT_SERIAL_CLASS(wxListBox
, wxControl
)
44 IMPLEMENT_SERIAL_CLASS(wxNotebook
, wxControl
)
45 IMPLEMENT_SERIAL_CLASS(wxRadioBox
, wxControl
)
46 IMPLEMENT_SERIAL_CLASS(wxRadioButton
, wxControl
)
47 IMPLEMENT_SERIAL_CLASS(wxButton
, wxControl
)
48 IMPLEMENT_SERIAL_CLASS(wxStaticText
, wxControl
)
50 //-----------------------------------------------------------------------------
52 void WXSERIAL(wxButton
)::StoreObject(wxObjectOutputStream
& s
)
54 WXSERIAL(wxControl
)::StoreObject(s
);
57 void WXSERIAL(wxButton
)::LoadObject(wxObjectInputStream
& s
)
59 WXSERIAL(wxControl
)::LoadObject(s
);
61 wxButton
*button
= (wxButton
*)Object();
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
),
65 m_style
, *m_validator
, m_name
);
68 //-----------------------------------------------------------------------------
70 void WXSERIAL(wxCheckBox
)::StoreObject(wxObjectOutputStream
& s
)
72 WXSERIAL(wxControl
)::StoreObject(s
);
77 wxDataOutputStream
data_s(s
);
78 data_s
.Write8( ((wxCheckBox
*)Object())->GetValue() );
81 void WXSERIAL(wxCheckBox
)::LoadObject(wxObjectInputStream
& s
)
83 WXSERIAL(wxControl
)::LoadObject(s
);
85 wxDataInputStream
data_s(s
);
86 wxCheckBox
*chkbox
= (wxCheckBox
*)Object();
88 chkbox
->Create(m_parent
, m_id
, m_label
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
89 m_style
, *m_validator
, m_name
);
91 chkbox
->SetValue(data_s
.Read8());
94 //-----------------------------------------------------------------------------
96 void WXSERIAL(wxSlider
)::StoreObject(wxObjectOutputStream
& s
)
98 WXSERIAL(wxControl
)::StoreObject(s
);
103 wxDataOutputStream
data_s(s
);
104 wxSlider
*slider
= (wxSlider
*)Object();
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() );
117 void WXSERIAL(wxSlider
)::LoadObject(wxObjectInputStream
& s
)
119 WXSERIAL(wxControl
)::LoadObject(s
);
121 wxDataInputStream
data_s(s
);
122 wxSlider
*slider
= (wxSlider
*)Object();
125 min
= data_s
.Read32();
126 max
= data_s
.Read32();
127 value
= data_s
.Read32();
129 slider
->Create(m_parent
, m_id
, value
, min
, max
, wxPoint(m_x
, m_y
),
130 wxSize(m_w
, m_h
), m_style
, *m_validator
, m_name
);
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() );
141 //-----------------------------------------------------------------------------
143 void WXSERIAL(wxGauge
)::StoreObject(wxObjectOutputStream
& s
)
145 WXSERIAL(wxControl
)::StoreObject(s
);
150 wxDataOutputStream
data_s(s
);
151 wxGauge
*gauge
= (wxGauge
*)Object();
153 data_s
.Write32( gauge
->GetRange() );
154 data_s
.Write8( gauge
->GetShadowWidth() );
155 data_s
.Write8( gauge
->GetBezelFace() );
156 data_s
.Write32( gauge
->GetValue() );
159 void WXSERIAL(wxGauge
)::LoadObject(wxObjectInputStream
& s
)
161 WXSERIAL(wxControl
)::LoadObject(s
);
163 wxDataInputStream
data_s(s
);
164 wxGauge
*gauge
= (wxGauge
*)Object();
167 range
= data_s
.Read32();
168 gauge
->Create(m_parent
, m_id
, range
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
169 m_style
, *m_validator
, m_name
);
171 gauge
->SetShadowWidth( data_s
.Read8() );
172 gauge
->SetBezelFace( data_s
.Read8() );
173 gauge
->SetValue( data_s
.Read32() );
176 //-----------------------------------------------------------------------------
178 void WXSERIAL(wxChoice
)::StoreObject(wxObjectOutputStream
& s
)
180 WXSERIAL(wxControl
)::StoreObject(s
);
185 wxDataOutputStream
data_s(s
);
186 wxChoice
*choice
= (wxChoice
*)Object();
187 int i
, num
= choice
->Number();
191 data_s
.WriteString( choice
->GetString(i
) );
194 void WXSERIAL(wxChoice
)::LoadObject(wxObjectInputStream
& s
)
196 WXSERIAL(wxControl
)::LoadObject(s
);
198 wxDataInputStream
data_s(s
);
199 wxChoice
*choice
= (wxChoice
*)Object();
200 int i
,num
= data_s
.Read32();
202 choice
->Create(m_parent
, m_id
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
), 0, NULL
,
203 m_style
, *m_validator
, m_name
);
206 choice
->Append( data_s
.ReadString() );
209 //-----------------------------------------------------------------------------
211 void WXSERIAL(wxListBox
)::StoreObject(wxObjectOutputStream
& s
)
213 WXSERIAL(wxControl
)::StoreObject(s
);
218 wxDataOutputStream
data_s(s
);
219 wxListBox
*listbox
= (wxListBox
*)Object();
220 int i
, num
= listbox
->Number();
224 data_s
.WriteString( listbox
->GetString(i
) );
227 void WXSERIAL(wxListBox
)::LoadObject(wxObjectInputStream
& s
)
229 WXSERIAL(wxListBox
)::LoadObject(s
);
231 wxDataInputStream
data_s(s
);
232 wxListBox
*listbox
= (wxListBox
*)Object();
233 int i
, num
= data_s
.Read32();
236 listbox
->Append( data_s
.ReadString() );
239 //-----------------------------------------------------------------------------
241 void WXSERIAL(wxNotebook
)::StoreObject(wxObjectOutputStream
& s
)
243 wxNotebook
*notebook
= (wxNotebook
*)Object();
244 wxImageList
*imaglist
= notebook
->GetImageList();
245 int i
, pcount
= notebook
->GetPageCount();
247 if (s
.FirstStage()) {
248 s
.AddChild(imaglist
);
249 WXSERIAL(wxControl
)::StoreObject(s
);
253 wxDataOutputStream
data_s(s
);
255 data_s
.Write8( pcount
);
256 WXSERIAL(wxControl
)::StoreObject(s
);
258 for (i
=0;i
<pcount
;i
++)
259 data_s
.WriteString( notebook
->GetPageText(i
) );
263 void WXSERIAL(wxNotebook
)::LoadObject(wxObjectInputStream
& s
)
265 wxNotebook
*notebook
= (wxNotebook
*)Object();
267 wxImageList
*imaglist
;
269 imaglist
= (wxImageList
*)s
.GetChild();
271 WXSERIAL(wxControl
)::LoadObject(s
);
273 notebook
->Create(m_parent
, m_id
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
276 wxDataInputStream
data_s(s
);
278 pcount
= data_s
.Read8();
279 for (i
=0;i
<pcount
;i
++)
280 notebook
->SetPageText(i
, data_s
.ReadString() );
283 //-----------------------------------------------------------------------------
285 void WXSERIAL(wxRadioBox
)::StoreObject(wxObjectOutputStream
& s
)
287 wxRadioBox
*box
= (wxRadioBox
*)Object();
288 WXSERIAL(wxControl
)::StoreObject(s
);
293 wxDataOutputStream
data_s(s
);
294 int i
, n_items
= box
->Number();
296 data_s
.Write8( n_items
);
297 data_s
.Write8( box
->GetNumberOfRowsOrCols() );
299 for (i
=0;i
<n_items
;i
++)
300 data_s
.WriteString( box
->GetString(i
) );
303 void WXSERIAL(wxRadioBox
)::LoadObject(wxObjectInputStream
& s
)
305 wxRadioBox
*box
= (wxRadioBox
*)Object();
307 WXSERIAL(wxControl
)::LoadObject(s
);
309 wxDataInputStream
data_s(s
);
310 int i
, n_rows_cols
, n_items
;
313 n_items
= data_s
.Read8();
314 n_rows_cols
= data_s
.Read8();
316 items
= new wxString
[n_items
];
317 for (i
=0;i
<n_items
;i
++)
318 items
[i
] = data_s
.ReadString();
320 box
->Create(m_parent
, m_id
, m_title
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
321 n_items
, items
, 0, m_style
, *m_validator
, m_name
);
324 //-----------------------------------------------------------------------------
326 void WXSERIAL(wxRadioButton
)::StoreObject(wxObjectOutputStream
& s
)
328 WXSERIAL(wxControl
)::StoreObject(s
);
333 wxDataOutputStream
data_s(s
);
334 data_s
.Write8( (char) ((wxRadioButton
*)Object())->GetValue() );
337 void WXSERIAL(wxRadioButton
)::LoadObject(wxObjectInputStream
& s
)
339 wxDataInputStream
data_s(s
);
341 WXSERIAL(wxControl
)::LoadObject(s
);
342 ((wxRadioButton
*)Object())->SetValue( (bool)data_s
.Read8() );
345 //-----------------------------------------------------------------------------
347 void WXSERIAL(wxComboBox
)::StoreObject(wxObjectOutputStream
& s
)
349 WXSERIAL(wxControl
)::StoreObject(s
);
354 wxDataOutputStream
data_s(s
);
355 wxComboBox
*box
= (wxComboBox
*)Object();
356 int i
, num
= box
->Number();
358 data_s
.Write8( num
);
359 data_s
.Write8( box
->GetSelection() );
361 data_s
.WriteString( box
->GetString(i
) );
363 data_s
.WriteString( box
->GetValue() );
365 // TODO: Editable flag
368 void WXSERIAL(wxComboBox
)::LoadObject(wxObjectInputStream
& s
)
370 WXSERIAL(wxControl
)::LoadObject(s
);
372 wxDataInputStream
data_s(s
);
373 wxComboBox
*box
= (wxComboBox
*)Object();
374 int i
, num
, selection
;
376 box
->Create(m_parent
, m_id
, wxEmptyString
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
377 0, NULL
, m_style
, *m_validator
, m_name
);
379 num
= data_s
.Read8();
380 selection
= data_s
.Read8();
383 box
->Append( data_s
.ReadString() );
385 box
->SetSelection( selection
);
386 box
->SetValue( data_s
.ReadString() );
389 //-----------------------------------------------------------------------------
391 void WXSERIAL(wxStaticText
)::StoreObject(wxObjectOutputStream
& s
)
393 WXSERIAL(wxControl
)::StoreObject(s
);
396 void WXSERIAL(wxStaticText
)::LoadObject(wxObjectInputStream
& s
)
398 WXSERIAL(wxControl
)::LoadObject(s
);
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
);
404 //-----------------------------------------------------------------------------
406 void WXSERIAL(wxStaticBox
)::StoreObject(wxObjectOutputStream
& s
)
408 WXSERIAL(wxControl
)::StoreObject(s
);
411 void WXSERIAL(wxStaticBox
)::LoadObject(wxObjectInputStream
& s
)
413 WXSERIAL(wxControl
)::LoadObject(s
);
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
);