]>
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
)
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
)
49 IMPLEMENT_SERIAL_CLASS(wxStaticBox
, wxControl
)
51 //-----------------------------------------------------------------------------
53 void WXSERIAL(wxButton
)::StoreObject(wxObjectOutputStream
& s
)
55 WXSERIAL(wxControl
)::StoreObject(s
);
58 void WXSERIAL(wxButton
)::LoadObject(wxObjectInputStream
& s
)
60 WXSERIAL(wxControl
)::LoadObject(s
);
62 wxButton
*button
= (wxButton
*)Object();
64 printf("label = %s\n", WXSTRINGCAST m_label
);
65 button
->Create(m_parent
, m_id
, m_label
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
66 m_style
, *m_validator
, m_name
);
69 //-----------------------------------------------------------------------------
71 void WXSERIAL(wxCheckBox
)::StoreObject(wxObjectOutputStream
& s
)
73 WXSERIAL(wxControl
)::StoreObject(s
);
78 wxDataOutputStream
data_s(s
);
79 data_s
.Write8( ((wxCheckBox
*)Object())->GetValue() );
82 void WXSERIAL(wxCheckBox
)::LoadObject(wxObjectInputStream
& s
)
84 WXSERIAL(wxControl
)::LoadObject(s
);
86 wxDataInputStream
data_s(s
);
87 wxCheckBox
*chkbox
= (wxCheckBox
*)Object();
89 chkbox
->Create(m_parent
, m_id
, m_label
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
90 m_style
, *m_validator
, m_name
);
92 chkbox
->SetValue(data_s
.Read8());
95 //-----------------------------------------------------------------------------
97 void WXSERIAL(wxSlider
)::StoreObject(wxObjectOutputStream
& s
)
99 WXSERIAL(wxControl
)::StoreObject(s
);
104 wxDataOutputStream
data_s(s
);
105 wxSlider
*slider
= (wxSlider
*)Object();
107 data_s
.Write32( slider
->GetMin() );
108 data_s
.Write32( slider
->GetMax() );
109 data_s
.Write32( slider
->GetValue() );
110 data_s
.Write32( slider
->GetTickFreq() );
111 data_s
.Write32( slider
->GetPageSize() );
112 data_s
.Write32( slider
->GetLineSize() );
113 data_s
.Write32( slider
->GetSelStart() );
114 data_s
.Write32( slider
->GetSelEnd() );
115 data_s
.Write32( slider
->GetThumbLength() );
118 void WXSERIAL(wxSlider
)::LoadObject(wxObjectInputStream
& s
)
120 WXSERIAL(wxControl
)::LoadObject(s
);
122 wxDataInputStream
data_s(s
);
123 wxSlider
*slider
= (wxSlider
*)Object();
126 min
= data_s
.Read32();
127 max
= data_s
.Read32();
128 value
= data_s
.Read32();
130 slider
->Create(m_parent
, m_id
, value
, min
, max
, wxPoint(m_x
, m_y
),
131 wxSize(m_w
, m_h
), m_style
, *m_validator
, m_name
);
133 slider
->SetTickFreq( 0, data_s
.Read32() );
134 slider
->SetPageSize( data_s
.Read32() );
135 slider
->SetLineSize( data_s
.Read32() );
136 min
= data_s
.Read32();
137 max
= data_s
.Read32();
138 slider
->SetSelection(min
, max
);
139 slider
->SetThumbLength( data_s
.Read32() );
142 //-----------------------------------------------------------------------------
144 void WXSERIAL(wxGauge
)::StoreObject(wxObjectOutputStream
& s
)
146 WXSERIAL(wxControl
)::StoreObject(s
);
151 wxDataOutputStream
data_s(s
);
152 wxGauge
*gauge
= (wxGauge
*)Object();
154 data_s
.Write32( gauge
->GetRange() );
155 data_s
.Write8( gauge
->GetShadowWidth() );
156 data_s
.Write8( gauge
->GetBezelFace() );
157 data_s
.Write32( gauge
->GetValue() );
160 void WXSERIAL(wxGauge
)::LoadObject(wxObjectInputStream
& s
)
162 WXSERIAL(wxControl
)::LoadObject(s
);
164 wxDataInputStream
data_s(s
);
165 wxGauge
*gauge
= (wxGauge
*)Object();
168 range
= data_s
.Read32();
169 gauge
->Create(m_parent
, m_id
, range
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
170 m_style
, *m_validator
, m_name
);
172 gauge
->SetShadowWidth( data_s
.Read8() );
173 gauge
->SetBezelFace( data_s
.Read8() );
174 gauge
->SetValue( data_s
.Read32() );
177 //-----------------------------------------------------------------------------
179 void WXSERIAL(wxChoice
)::StoreObject(wxObjectOutputStream
& s
)
181 WXSERIAL(wxControl
)::StoreObject(s
);
186 wxDataOutputStream
data_s(s
);
187 wxChoice
*choice
= (wxChoice
*)Object();
188 int i
, num
= choice
->Number();
192 data_s
.WriteString( choice
->GetString(i
) );
195 void WXSERIAL(wxChoice
)::LoadObject(wxObjectInputStream
& s
)
197 WXSERIAL(wxControl
)::LoadObject(s
);
199 wxDataInputStream
data_s(s
);
200 wxChoice
*choice
= (wxChoice
*)Object();
201 int i
,num
= data_s
.Read32();
203 choice
->Create(m_parent
, m_id
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
), 0, NULL
,
204 m_style
, *m_validator
, m_name
);
207 choice
->Append( data_s
.ReadString() );
210 //-----------------------------------------------------------------------------
212 void WXSERIAL(wxListBox
)::StoreObject(wxObjectOutputStream
& s
)
214 WXSERIAL(wxControl
)::StoreObject(s
);
219 wxDataOutputStream
data_s(s
);
220 wxListBox
*listbox
= (wxListBox
*)Object();
221 int i
, num
= listbox
->Number();
225 data_s
.WriteString( listbox
->GetString(i
) );
228 void WXSERIAL(wxListBox
)::LoadObject(wxObjectInputStream
& s
)
230 WXSERIAL(wxListBox
)::LoadObject(s
);
232 wxDataInputStream
data_s(s
);
233 wxListBox
*listbox
= (wxListBox
*)Object();
234 int i
, num
= data_s
.Read32();
237 listbox
->Append( data_s
.ReadString() );
240 //-----------------------------------------------------------------------------
242 void WXSERIAL(wxNotebook
)::StoreObject(wxObjectOutputStream
& s
)
244 wxNotebook
*notebook
= (wxNotebook
*)Object();
245 wxImageList
*imaglist
= notebook
->GetImageList();
246 int i
, pcount
= notebook
->GetPageCount();
248 WXSERIAL(wxControl
)::StoreObject(s
);
249 if (s
.FirstStage()) {
250 s
.AddChild(imaglist
);
254 wxDataOutputStream
data_s(s
);
256 data_s
.Write8( pcount
);
258 for (i
=0;i
<pcount
;i
++)
259 data_s
.WriteString( notebook
->GetPageText(i
) );
262 void WXSERIAL(wxNotebook
)::LoadObject(wxObjectInputStream
& s
)
264 wxNotebook
*notebook
= (wxNotebook
*)Object();
266 wxImageList
*imaglist
;
268 if (s
.SecondCall()) {
269 for (i
=0;i
<m_pcount
;i
++)
270 notebook
->AddPage( (wxWindow
*)s
.GetChild(), m_stringlist
[i
] );
274 WXSERIAL(wxControl
)::LoadObject(s
);
276 imaglist
= (wxImageList
*)s
.GetChild();
278 notebook
->Create(m_parent
, m_id
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
281 wxDataInputStream
data_s(s
);
283 m_pcount
= data_s
.Read8();
284 for (i
=0;i
<m_pcount
;i
++)
285 m_stringlist
.Add(data_s
.ReadString());
289 //-----------------------------------------------------------------------------
291 void WXSERIAL(wxRadioBox
)::StoreObject(wxObjectOutputStream
& s
)
293 wxRadioBox
*box
= (wxRadioBox
*)Object();
294 WXSERIAL(wxControl
)::StoreObject(s
);
299 wxDataOutputStream
data_s(s
);
300 int i
, n_items
= box
->Number();
302 data_s
.Write8( n_items
);
303 data_s
.Write8( box
->GetNumberOfRowsOrCols() );
305 for (i
=0;i
<n_items
;i
++)
306 data_s
.WriteString( box
->GetString(i
) );
309 void WXSERIAL(wxRadioBox
)::LoadObject(wxObjectInputStream
& s
)
311 wxRadioBox
*box
= (wxRadioBox
*)Object();
313 WXSERIAL(wxControl
)::LoadObject(s
);
315 wxDataInputStream
data_s(s
);
316 int i
, n_rows_cols
, n_items
;
319 n_items
= data_s
.Read8();
320 n_rows_cols
= data_s
.Read8();
322 items
= new wxString
[n_items
];
323 for (i
=0;i
<n_items
;i
++)
324 items
[i
] = data_s
.ReadString();
326 box
->Create(m_parent
, m_id
, m_title
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
327 n_items
, items
, 0, m_style
, *m_validator
, m_name
);
330 //-----------------------------------------------------------------------------
332 void WXSERIAL(wxRadioButton
)::StoreObject(wxObjectOutputStream
& s
)
334 WXSERIAL(wxControl
)::StoreObject(s
);
339 wxDataOutputStream
data_s(s
);
340 data_s
.Write8( (char) ((wxRadioButton
*)Object())->GetValue() );
343 void WXSERIAL(wxRadioButton
)::LoadObject(wxObjectInputStream
& s
)
345 wxDataInputStream
data_s(s
);
347 WXSERIAL(wxControl
)::LoadObject(s
);
348 ((wxRadioButton
*)Object())->SetValue( (bool)data_s
.Read8() );
351 //-----------------------------------------------------------------------------
353 void WXSERIAL(wxComboBox
)::StoreObject(wxObjectOutputStream
& s
)
355 WXSERIAL(wxControl
)::StoreObject(s
);
360 wxDataOutputStream
data_s(s
);
361 wxComboBox
*box
= (wxComboBox
*)Object();
362 int i
, num
= box
->Number();
364 data_s
.Write8( num
);
365 data_s
.Write8( box
->GetSelection() );
367 data_s
.WriteString( box
->GetString(i
) );
369 data_s
.WriteString( box
->GetValue() );
371 // TODO: Editable flag
374 void WXSERIAL(wxComboBox
)::LoadObject(wxObjectInputStream
& s
)
376 WXSERIAL(wxControl
)::LoadObject(s
);
378 wxDataInputStream
data_s(s
);
379 wxComboBox
*box
= (wxComboBox
*)Object();
380 int i
, num
, selection
;
382 box
->Create(m_parent
, m_id
, wxEmptyString
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
383 0, NULL
, m_style
, *m_validator
, m_name
);
385 num
= data_s
.Read8();
386 selection
= data_s
.Read8();
389 box
->Append( data_s
.ReadString() );
391 box
->SetSelection( selection
);
392 box
->SetValue( data_s
.ReadString() );
395 //-----------------------------------------------------------------------------
397 void WXSERIAL(wxStaticText
)::StoreObject(wxObjectOutputStream
& s
)
399 WXSERIAL(wxControl
)::StoreObject(s
);
402 void WXSERIAL(wxStaticText
)::LoadObject(wxObjectInputStream
& s
)
404 WXSERIAL(wxControl
)::LoadObject(s
);
406 ((wxStaticText
*)Object())->Create(m_parent
, m_id
, m_label
, wxPoint(m_x
, m_y
),
407 wxSize(m_w
, m_h
), m_style
, m_name
);
410 //-----------------------------------------------------------------------------
412 void WXSERIAL(wxStaticBox
)::StoreObject(wxObjectOutputStream
& s
)
414 WXSERIAL(wxControl
)::StoreObject(s
);
417 void WXSERIAL(wxStaticBox
)::LoadObject(wxObjectInputStream
& s
)
419 WXSERIAL(wxControl
)::LoadObject(s
);
421 ((wxStaticBox
*)Object())->Create(m_parent
, m_id
, m_label
, wxPoint(m_x
, m_y
),
422 wxSize(m_w
, m_h
), m_style
, m_name
);