]>
git.saurik.com Git - wxWidgets.git/blob - utils/serialize/serctrl.cpp
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/stattext.h>
27 #include <wx/combobox.h>
28 #include <wx/imaglist.h>
29 #include <wx/objstrm.h>
30 #include <wx/datstrm.h>
31 #include <wx/serbase.h>
35 IMPLEMENT_ALIAS_SERIAL_CLASS(wxControl
, wxWindow
)
36 IMPLEMENT_SERIAL_CLASS(wxSlider
, wxControl
)
37 IMPLEMENT_SERIAL_CLASS(wxCheckBox
, wxControl
)
38 IMPLEMENT_SERIAL_CLASS(wxChoice
, wxControl
)
39 IMPLEMENT_SERIAL_CLASS(wxComboBox
, wxControl
)
40 IMPLEMENT_SERIAL_CLASS(wxGauge
, wxControl
)
41 IMPLEMENT_SERIAL_CLASS(wxListBox
, wxControl
)
42 IMPLEMENT_SERIAL_CLASS(wxNotebook
, wxControl
)
43 IMPLEMENT_SERIAL_CLASS(wxRadioBox
, wxControl
)
45 IMPLEMENT_SERIAL_CLASS(wxButton
, wxControl
)
46 IMPLEMENT_SERIAL_CLASS(wxStaticText
, wxControl
)
48 void WXSERIAL(wxButton
)::StoreObject(wxObjectOutputStream
& s
)
50 WXSERIAL(wxControl
)::StoreObject(s
);
53 void WXSERIAL(wxButton
)::LoadObject(wxObjectInputStream
& s
)
55 WXSERIAL(wxControl
)::LoadObject(s
);
57 wxButton
*button
= (wxButton
*)Object();
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
),
61 m_style
, *m_validator
, m_name
);
64 void WXSERIAL(wxCheckBox
)::StoreObject(wxObjectOutputStream
& s
)
66 WXSERIAL(wxControl
)::StoreObject(s
);
71 wxDataOutputStream
data_s(s
);
72 data_s
.Write8( ((wxCheckBox
*)Object())->GetValue() );
75 void WXSERIAL(wxCheckBox
)::LoadObject(wxObjectInputStream
& s
)
77 WXSERIAL(wxControl
)::LoadObject(s
);
79 wxDataInputStream
data_s(s
);
80 wxCheckBox
*chkbox
= (wxCheckBox
*)Object();
82 chkbox
->Create(m_parent
, m_id
, m_label
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
83 m_style
, *m_validator
, m_name
);
85 chkbox
->SetValue(data_s
.Read8());
88 void WXSERIAL(wxSlider
)::StoreObject(wxObjectOutputStream
& s
)
90 WXSERIAL(wxControl
)::StoreObject(s
);
95 wxDataOutputStream
data_s(s
);
96 wxSlider
*slider
= (wxSlider
*)Object();
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() );
109 void WXSERIAL(wxSlider
)::LoadObject(wxObjectInputStream
& s
)
111 WXSERIAL(wxControl
)::LoadObject(s
);
113 wxDataInputStream
data_s(s
);
114 wxSlider
*slider
= (wxSlider
*)Object();
117 min
= data_s
.Read32();
118 max
= data_s
.Read32();
119 value
= data_s
.Read32();
121 slider
->Create(m_parent
, m_id
, value
, min
, max
, wxPoint(m_x
, m_y
),
122 wxSize(m_w
, m_h
), m_style
, *m_validator
, m_name
);
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() );
133 void WXSERIAL(wxGauge
)::StoreObject(wxObjectOutputStream
& s
)
135 WXSERIAL(wxControl
)::StoreObject(s
);
140 wxDataOutputStream
data_s(s
);
141 wxGauge
*gauge
= (wxGauge
*)Object();
143 data_s
.Write32( gauge
->GetRange() );
144 data_s
.Write8( gauge
->GetShadowWidth() );
145 data_s
.Write8( gauge
->GetBezelFace() );
146 data_s
.Write32( gauge
->GetValue() );
149 void WXSERIAL(wxGauge
)::LoadObject(wxObjectInputStream
& s
)
151 WXSERIAL(wxControl
)::LoadObject(s
);
153 wxDataInputStream
data_s(s
);
154 wxGauge
*gauge
= (wxGauge
*)Object();
157 range
= data_s
.Read32();
158 gauge
->Create(m_parent
, m_id
, range
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
159 m_style
, *m_validator
, m_name
);
161 gauge
->SetShadowWidth( data_s
.Read8() );
162 gauge
->SetBezelFace( data_s
.Read8() );
163 gauge
->SetValue( data_s
.Read32() );
166 void WXSERIAL(wxChoice
)::StoreObject(wxObjectOutputStream
& s
)
168 WXSERIAL(wxControl
)::StoreObject(s
);
173 wxDataOutputStream
data_s(s
);
174 wxChoice
*choice
= (wxChoice
*)Object();
175 int i
, num
= choice
->Number();
179 data_s
.WriteString( choice
->GetString(i
) );
182 void WXSERIAL(wxChoice
)::LoadObject(wxObjectInputStream
& s
)
184 WXSERIAL(wxControl
)::LoadObject(s
);
186 wxDataInputStream
data_s(s
);
187 wxChoice
*choice
= (wxChoice
*)Object();
188 int i
,num
= data_s
.Read32();
190 choice
->Create(m_parent
, m_id
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
), 0, NULL
,
191 m_style
, *m_validator
, m_name
);
194 choice
->Append( data_s
.ReadString() );
197 void WXSERIAL(wxListBox
)::StoreObject(wxObjectOutputStream
& s
)
199 WXSERIAL(wxControl
)::StoreObject(s
);
204 wxDataOutputStream
data_s(s
);
205 wxListBox
*listbox
= (wxListBox
*)Object();
206 int i
, num
= listbox
->Number();
210 data_s
.WriteString( listbox
->GetString(i
) );
213 void WXSERIAL(wxListBox
)::LoadObject(wxObjectInputStream
& s
)
215 WXSERIAL(wxListBox
)::LoadObject(s
);
217 wxDataInputStream
data_s(s
);
218 wxListBox
*listbox
= (wxListBox
*)Object();
219 int i
, num
= data_s
.Read32();
222 listbox
->Append( data_s
.ReadString() );
225 void WXSERIAL(wxNotebook
)::StoreObject(wxObjectOutputStream
& s
)
227 wxNotebook
*notebook
= (wxNotebook
*)Object();
228 wxImageList
*imaglist
= notebook
->GetImageList();
229 int i
, pcount
= notebook
->GetPageCount();
231 if (s
.FirstStage()) {
232 s
.AddChild(imaglist
);
233 WXSERIAL(wxControl
)::StoreObject(s
);
237 wxDataOutputStream
data_s(s
);
239 data_s
.Write8( pcount
);
240 WXSERIAL(wxControl
)::StoreObject(s
);
242 for (i
=0;i
<pcount
;i
++)
243 data_s
.WriteString( notebook
->GetPageText(i
) );
247 void WXSERIAL(wxNotebook
)::LoadObject(wxObjectInputStream
& s
)
249 wxNotebook
*notebook
= (wxNotebook
*)Object();
251 wxImageList
*imaglist
;
253 imaglist
= (wxImageList
*)s
.GetChild(0);
256 WXSERIAL(wxControl
)::LoadObject(s
);
258 notebook
->Create(m_parent
, m_id
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
261 wxDataInputStream
data_s(s
);
263 pcount
= data_s
.Read8();
264 for (i
=0;i
<pcount
;i
++)
265 notebook
->SetPageText(i
, data_s
.ReadString() );
268 void WXSERIAL(wxRadioBox
)::StoreObject(wxObjectOutputStream
& s
)
270 wxRadioBox
*box
= (wxRadioBox
*)Object();
271 WXSERIAL(wxControl
)::StoreObject(s
);
276 wxDataOutputStream
data_s(s
);
277 int i
, n_items
= box
->Number();
279 data_s
.Write8( n_items
);
280 data_s
.Write8( box
->GetNumberOfRowsOrCols() );
282 for (i
=0;i
<n_items
;i
++)
283 data_s
.WriteString( box
->GetString(i
) );
286 void WXSERIAL(wxRadioBox
)::LoadObject(wxObjectInputStream
& s
)
288 wxRadioBox
*box
= (wxRadioBox
*)Object();
290 WXSERIAL(wxControl
)::LoadObject(s
);
292 wxDataInputStream
data_s(s
);
293 int i
, n_rows_cols
, n_items
;
296 n_items
= data_s
.Read8();
297 n_rows_cols
= data_s
.Read8();
299 items
= new wxString
[n_items
];
300 for (i
=0;i
<n_items
;i
++)
301 items
[i
] = data_s
.ReadString();
303 box
->Create(m_parent
, m_id
, m_title
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
304 n_items
, items
, 0, m_style
, *m_validator
, m_name
);
307 void WXSERIAL(wxComboBox
)::StoreObject(wxObjectOutputStream
& s
)
309 WXSERIAL(wxControl
)::StoreObject(s
);
314 wxDataOutputStream
data_s(s
);
315 wxComboBox
*box
= (wxComboBox
*)Object();
316 int i
, num
= box
->Number();
318 data_s
.Write8( num
);
319 data_s
.Write8( box
->GetSelection() );
321 data_s
.WriteString( box
->GetString(i
) );
323 data_s
.WriteString( box
->GetValue() );
325 // TODO: Editable flag
328 void WXSERIAL(wxComboBox
)::LoadObject(wxObjectInputStream
& s
)
330 WXSERIAL(wxControl
)::LoadObject(s
);
332 wxDataInputStream
data_s(s
);
333 wxComboBox
*box
= (wxComboBox
*)Object();
334 int i
, num
, selection
;
336 box
->Create(m_parent
, m_id
, wxEmptyString
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
337 0, NULL
, m_style
, *m_validator
, m_name
);
339 num
= data_s
.Read8();
340 selection
= data_s
.Read8();
343 box
->Append( data_s
.ReadString() );
345 box
->SetSelection( selection
);
346 box
->SetValue( data_s
.ReadString() );
349 void WXSERIAL(wxStaticText
)::StoreObject(wxObjectOutputStream
& s
)
351 WXSERIAL(wxControl
)::StoreObject(s
);
354 void WXSERIAL(wxStaticText
)::LoadObject(wxObjectInputStream
& s
)
356 WXSERIAL(wxControl
)::LoadObject(s
);
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
);