]>
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/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
)
39 IMPLEMENT_SERIAL_CLASS(wxSlider95
, wxControl
)
40 IMPLEMENT_SERIAL_CLASS(wxGauge95
, wxControl
)
42 IMPLEMENT_SERIAL_CLASS(wxSlider
, wxControl
)
43 IMPLEMENT_SERIAL_CLASS(wxGauge
, wxControl
)
45 IMPLEMENT_SERIAL_CLASS(wxCheckBox
, wxControl
)
46 IMPLEMENT_SERIAL_CLASS(wxChoice
, wxControl
)
47 IMPLEMENT_SERIAL_CLASS(wxComboBox
, wxControl
)
48 IMPLEMENT_SERIAL_CLASS(wxListBox
, wxControl
)
49 IMPLEMENT_SERIAL_CLASS(wxNotebook
, wxControl
)
50 IMPLEMENT_SERIAL_CLASS(wxRadioBox
, wxControl
)
51 IMPLEMENT_SERIAL_CLASS(wxRadioButton
, wxControl
)
52 IMPLEMENT_SERIAL_CLASS(wxButton
, wxControl
)
53 IMPLEMENT_SERIAL_CLASS(wxStaticText
, wxControl
)
54 IMPLEMENT_SERIAL_CLASS(wxStaticBox
, wxControl
)
56 //-----------------------------------------------------------------------------
58 void WXSERIAL(wxButton
)::StoreObject(wxObjectOutputStream
& s
)
60 WXSERIAL(wxControl
)::StoreObject(s
);
63 void WXSERIAL(wxButton
)::LoadObject(wxObjectInputStream
& s
)
65 WXSERIAL(wxControl
)::LoadObject(s
);
70 wxButton
*button
= (wxButton
*)Object();
72 printf("label = %s\n", WXSTRINGCAST m_label
);
73 button
->Create(m_parent
, m_id
, m_label
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
74 m_style
, *m_validator
, m_name
);
77 //-----------------------------------------------------------------------------
79 void WXSERIAL(wxCheckBox
)::StoreObject(wxObjectOutputStream
& s
)
81 WXSERIAL(wxControl
)::StoreObject(s
);
86 wxDataOutputStream
data_s(s
);
87 data_s
.Write8( ((wxCheckBox
*)Object())->GetValue() );
90 void WXSERIAL(wxCheckBox
)::LoadObject(wxObjectInputStream
& s
)
92 WXSERIAL(wxControl
)::LoadObject(s
);
97 wxDataInputStream
data_s(s
);
98 wxCheckBox
*chkbox
= (wxCheckBox
*)Object();
100 chkbox
->Create(m_parent
, m_id
, m_label
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
101 m_style
, *m_validator
, m_name
);
103 chkbox
->SetValue(data_s
.Read8());
106 //-----------------------------------------------------------------------------
109 void WXSERIAL(wxSlider95
)::StoreObject(wxObjectOutputStream
& s
)
111 void WXSERIAL(wxSlider
)::StoreObject(wxObjectOutputStream
& s
)
114 WXSERIAL(wxControl
)::StoreObject(s
);
119 wxDataOutputStream
data_s(s
);
120 wxSlider
*slider
= (wxSlider
*)Object();
122 data_s
.Write32( slider
->GetMin() );
123 data_s
.Write32( slider
->GetMax() );
124 data_s
.Write32( slider
->GetValue() );
125 data_s
.Write32( slider
->GetTickFreq() );
126 data_s
.Write32( slider
->GetPageSize() );
127 data_s
.Write32( slider
->GetLineSize() );
128 data_s
.Write32( slider
->GetSelStart() );
129 data_s
.Write32( slider
->GetSelEnd() );
130 data_s
.Write32( slider
->GetThumbLength() );
134 void WXSERIAL(wxSlider95
)::LoadObject(wxObjectInputStream
& s
)
136 void WXSERIAL(wxSlider
)::LoadObject(wxObjectInputStream
& s
)
139 WXSERIAL(wxControl
)::LoadObject(s
);
144 wxDataInputStream
data_s(s
);
145 wxSlider
*slider
= (wxSlider
*)Object();
148 min
= data_s
.Read32();
149 max
= data_s
.Read32();
150 value
= data_s
.Read32();
152 slider
->Create(m_parent
, m_id
, value
, min
, max
, wxPoint(m_x
, m_y
),
153 wxSize(m_w
, m_h
), m_style
, *m_validator
, m_name
);
155 slider
->SetTickFreq( 0, data_s
.Read32() );
156 slider
->SetPageSize( data_s
.Read32() );
157 slider
->SetLineSize( data_s
.Read32() );
158 min
= data_s
.Read32();
159 max
= data_s
.Read32();
160 slider
->SetSelection(min
, max
);
161 slider
->SetThumbLength( data_s
.Read32() );
164 //-----------------------------------------------------------------------------
167 void WXSERIAL(wxGauge95
)::StoreObject(wxObjectOutputStream
& s
)
169 void WXSERIAL(wxGauge
)::StoreObject(wxObjectOutputStream
& s
)
172 WXSERIAL(wxControl
)::StoreObject(s
);
177 wxDataOutputStream
data_s(s
);
178 wxGauge
*gauge
= (wxGauge
*)Object();
180 data_s
.Write32( gauge
->GetRange() );
181 data_s
.Write8( gauge
->GetShadowWidth() );
182 data_s
.Write8( gauge
->GetBezelFace() );
183 data_s
.Write32( gauge
->GetValue() );
187 void WXSERIAL(wxGauge95
)::LoadObject(wxObjectInputStream
& s
)
189 void WXSERIAL(wxGauge
)::LoadObject(wxObjectInputStream
& s
)
192 WXSERIAL(wxControl
)::LoadObject(s
);
197 wxDataInputStream
data_s(s
);
198 wxGauge
*gauge
= (wxGauge
*)Object();
201 range
= data_s
.Read32();
202 gauge
->Create(m_parent
, m_id
, range
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
203 m_style
, *m_validator
, m_name
);
205 gauge
->SetShadowWidth( data_s
.Read8() );
206 gauge
->SetBezelFace( data_s
.Read8() );
207 gauge
->SetValue( data_s
.Read32() );
210 //-----------------------------------------------------------------------------
212 void WXSERIAL(wxChoice
)::StoreObject(wxObjectOutputStream
& s
)
214 WXSERIAL(wxControl
)::StoreObject(s
);
219 wxDataOutputStream
data_s(s
);
220 wxChoice
*choice
= (wxChoice
*)Object();
221 int i
, num
= choice
->Number();
225 data_s
.WriteString( choice
->GetString(i
) );
228 void WXSERIAL(wxChoice
)::LoadObject(wxObjectInputStream
& s
)
230 WXSERIAL(wxControl
)::LoadObject(s
);
235 wxDataInputStream
data_s(s
);
236 wxChoice
*choice
= (wxChoice
*)Object();
237 int i
,num
= data_s
.Read32();
239 choice
->Create(m_parent
, m_id
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
), 0, NULL
,
240 m_style
, *m_validator
, m_name
);
243 choice
->Append( data_s
.ReadString() );
246 //-----------------------------------------------------------------------------
248 void WXSERIAL(wxListBox
)::StoreObject(wxObjectOutputStream
& s
)
250 WXSERIAL(wxControl
)::StoreObject(s
);
255 wxDataOutputStream
data_s(s
);
256 wxListBox
*listbox
= (wxListBox
*)Object();
257 int i
, num
= listbox
->Number();
261 data_s
.WriteString( listbox
->GetString(i
) );
264 void WXSERIAL(wxListBox
)::LoadObject(wxObjectInputStream
& s
)
266 WXSERIAL(wxListBox
)::LoadObject(s
);
271 wxDataInputStream
data_s(s
);
272 wxListBox
*listbox
= (wxListBox
*)Object();
273 int i
, num
= data_s
.Read32();
276 listbox
->Append( data_s
.ReadString() );
279 //-----------------------------------------------------------------------------
281 void WXSERIAL(wxNotebook
)::StoreObject(wxObjectOutputStream
& s
)
283 wxNotebook
*notebook
= (wxNotebook
*)Object();
284 wxImageList
*imaglist
= notebook
->GetImageList();
285 int i
, pcount
= notebook
->GetPageCount();
287 WXSERIAL(wxControl
)::StoreObject(s
);
288 if (s
.FirstStage()) {
289 s
.AddChild(imaglist
);
293 wxDataOutputStream
data_s(s
);
295 data_s
.Write8( pcount
);
297 for (i
=0;i
<pcount
;i
++)
298 data_s
.WriteString( notebook
->GetPageText(i
) );
301 void WXSERIAL(wxNotebook
)::LoadObject(wxObjectInputStream
& s
)
303 wxNotebook
*notebook
= (wxNotebook
*)Object();
305 wxImageList
*imaglist
;
307 WXSERIAL(wxControl
)::LoadObject(s
);
309 if (s
.SecondCall()) {
310 for (i
=0;i
<m_pcount
;i
++)
311 notebook
->AddPage( (wxWindow
*)s
.GetChild(), m_stringlist
[i
] );
315 imaglist
= (wxImageList
*)s
.GetChild();
317 notebook
->Create(m_parent
, m_id
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
320 wxDataInputStream
data_s(s
);
322 m_pcount
= data_s
.Read8();
323 for (i
=0;i
<m_pcount
;i
++)
324 m_stringlist
.Add(data_s
.ReadString());
328 //-----------------------------------------------------------------------------
330 void WXSERIAL(wxRadioBox
)::StoreObject(wxObjectOutputStream
& s
)
332 wxRadioBox
*box
= (wxRadioBox
*)Object();
333 WXSERIAL(wxControl
)::StoreObject(s
);
338 wxDataOutputStream
data_s(s
);
339 int i
, n_items
= box
->Number();
341 data_s
.Write8( n_items
);
342 data_s
.Write8( box
->GetNumberOfRowsOrCols() );
344 for (i
=0;i
<n_items
;i
++)
345 data_s
.WriteString( box
->GetString(i
) );
348 void WXSERIAL(wxRadioBox
)::LoadObject(wxObjectInputStream
& s
)
350 wxRadioBox
*box
= (wxRadioBox
*)Object();
352 WXSERIAL(wxControl
)::LoadObject(s
);
357 wxDataInputStream
data_s(s
);
358 int i
, n_rows_cols
, n_items
;
361 n_items
= data_s
.Read8();
362 n_rows_cols
= data_s
.Read8();
364 items
= new wxString
[n_items
];
365 for (i
=0;i
<n_items
;i
++)
366 items
[i
] = data_s
.ReadString();
368 box
->Create(m_parent
, m_id
, m_title
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
369 n_items
, items
, 0, m_style
, *m_validator
, m_name
);
372 //-----------------------------------------------------------------------------
374 void WXSERIAL(wxRadioButton
)::StoreObject(wxObjectOutputStream
& s
)
376 WXSERIAL(wxControl
)::StoreObject(s
);
381 wxDataOutputStream
data_s(s
);
382 data_s
.Write8( (char) ((wxRadioButton
*)Object())->GetValue() );
385 void WXSERIAL(wxRadioButton
)::LoadObject(wxObjectInputStream
& s
)
387 wxDataInputStream
data_s(s
);
389 WXSERIAL(wxControl
)::LoadObject(s
);
394 ((wxRadioButton
*)Object())->SetValue( (bool)data_s
.Read8() );
397 //-----------------------------------------------------------------------------
399 void WXSERIAL(wxComboBox
)::StoreObject(wxObjectOutputStream
& s
)
401 WXSERIAL(wxControl
)::StoreObject(s
);
406 wxDataOutputStream
data_s(s
);
407 wxComboBox
*box
= (wxComboBox
*)Object();
408 int i
, num
= box
->Number();
410 data_s
.Write8( num
);
411 data_s
.Write8( box
->GetSelection() );
413 data_s
.WriteString( box
->GetString(i
) );
415 data_s
.WriteString( box
->GetValue() );
417 // TODO: Editable flag
420 void WXSERIAL(wxComboBox
)::LoadObject(wxObjectInputStream
& s
)
422 WXSERIAL(wxControl
)::LoadObject(s
);
427 wxDataInputStream
data_s(s
);
428 wxComboBox
*box
= (wxComboBox
*)Object();
429 int i
, num
, selection
;
431 box
->Create(m_parent
, m_id
, wxEmptyString
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
432 0, NULL
, m_style
, *m_validator
, m_name
);
434 num
= data_s
.Read8();
435 selection
= data_s
.Read8();
438 box
->Append( data_s
.ReadString() );
440 box
->SetSelection( selection
);
441 box
->SetValue( data_s
.ReadString() );
444 //-----------------------------------------------------------------------------
446 void WXSERIAL(wxStaticText
)::StoreObject(wxObjectOutputStream
& s
)
448 WXSERIAL(wxControl
)::StoreObject(s
);
451 void WXSERIAL(wxStaticText
)::LoadObject(wxObjectInputStream
& s
)
453 WXSERIAL(wxControl
)::LoadObject(s
);
458 ((wxStaticText
*)Object())->Create(m_parent
, m_id
, m_label
, wxPoint(m_x
, m_y
),
459 wxSize(m_w
, m_h
), m_style
, m_name
);
462 //-----------------------------------------------------------------------------
464 void WXSERIAL(wxStaticBox
)::StoreObject(wxObjectOutputStream
& s
)
466 WXSERIAL(wxControl
)::StoreObject(s
);
469 void WXSERIAL(wxStaticBox
)::LoadObject(wxObjectInputStream
& s
)
471 WXSERIAL(wxControl
)::LoadObject(s
);
476 ((wxStaticBox
*)Object())->Create(m_parent
, m_id
, m_label
, wxPoint(m_x
, m_y
),
477 wxSize(m_w
, m_h
), m_style
, m_name
);