]>
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/objstrm.h>
29 #include <wx/datstrm.h>
30 #include <wx/serbase.h>
34 IMPLEMENT_ALIAS_SERIAL_CLASS(wxControl
, wxWindow
)
35 IMPLEMENT_SERIAL_CLASS(wxSlider
, wxControl
)
36 IMPLEMENT_SERIAL_CLASS(wxCheckBox
, wxControl
)
37 IMPLEMENT_SERIAL_CLASS(wxChoice
, wxControl
)
38 IMPLEMENT_SERIAL_CLASS(wxComboBox
, wxControl
)
39 IMPLEMENT_SERIAL_CLASS(wxGauge
, wxControl
)
40 IMPLEMENT_SERIAL_CLASS(wxListBox
, wxControl
)
41 IMPLEMENT_SERIAL_CLASS(wxNotebook
, wxControl
)
42 IMPLEMENT_SERIAL_CLASS(wxRadioBox
, wxControl
)
44 IMPLEMENT_SERIAL_CLASS(wxButton
, wxControl
)
45 IMPLEMENT_SERIAL_CLASS(wxStaticText
, wxControl
)
47 void WXSERIAL(wxButton
)::StoreObject(wxObjectOutputStream
& s
)
49 WXSERIAL(wxControl
)::StoreObject(s
);
52 void WXSERIAL(wxButton
)::LoadObject(wxObjectInputStream
& s
)
54 WXSERIAL(wxControl
)::LoadObject(s
);
56 wxButton
*button
= (wxButton
*)Object();
58 printf("label = %s\n", WXSTRINGCAST m_label
);
59 button
->Create(m_parent
, m_id
, m_label
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
63 void WXSERIAL(wxCheckBox
)::StoreObject(wxObjectOutputStream
& s
)
65 WXSERIAL(wxControl
)::StoreObject(s
);
70 wxDataOutputStream
data_s(s
);
71 data_s
.Write8( ((wxCheckBox
*)Object())->GetValue() );
74 void WXSERIAL(wxCheckBox
)::LoadObject(wxObjectInputStream
& s
)
76 WXSERIAL(wxControl
)::LoadObject(s
);
78 wxDataInputStream
data_s(s
);
79 wxCheckBox
*chkbox
= (wxCheckBox
*)Object();
81 chkbox
->Create(m_parent
, m_id
, m_label
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
84 chkbox
->SetValue(data_s
.Read8());
87 void WXSERIAL(wxSlider
)::StoreObject(wxObjectOutputStream
& s
)
89 WXSERIAL(wxControl
)::StoreObject(s
);
94 wxDataOutputStream
data_s(s
);
95 wxSlider
*slider
= (wxSlider
*)Object();
97 data_s
.Write32( slider
->GetMin() );
98 data_s
.Write32( slider
->GetMax() );
99 data_s
.Write32( slider
->GetValue() );
100 data_s
.Write32( slider
->GetTickFreq() );
101 data_s
.Write32( slider
->GetPageSize() );
102 data_s
.Write32( slider
->GetLineSize() );
103 data_s
.Write32( slider
->GetSelStart() );
104 data_s
.Write32( slider
->GetSelEnd() );
105 data_s
.Write32( slider
->GetThumbLength() );
108 void WXSERIAL(wxSlider
)::LoadObject(wxObjectInputStream
& s
)
110 WXSERIAL(wxControl
)::LoadObject(s
);
112 wxDataInputStream
data_s(s
);
113 wxSlider
*slider
= (wxSlider
*)Object();
116 min
= data_s
.Read32();
117 max
= data_s
.Read32();
118 value
= data_s
.Read32();
120 slider
->Create(m_parent
, m_id
, value
, min
, max
, wxPoint(m_x
, m_y
),
121 wxSize(m_w
, m_h
), m_style
, m_name
);
123 slider
->SetTickFreq( 0, data_s
.Read32() );
124 slider
->SetPageSize( data_s
.Read32() );
125 slider
->SetLineSize( data_s
.Read32() );
126 min
= data_s
.Read32();
127 max
= data_s
.Read32();
128 slider
->SetSelection(min
, max
);
129 slider
->SetThumbLength( data_s
.Read32() );
132 void WXSERIAL(wxGauge
)::StoreObject(wxObjectOutputStream
& s
)
134 WXSERIAL(wxControl
)::StoreObject(s
);
139 wxDataOutputStream
data_s(s
);
140 wxGauge
*gauge
= (wxGauge
*)Object();
142 data_s
.Write32( gauge
->GetRange() );
143 data_s
.Write8( gauge
->GetShadowWidth() );
144 data_s
.Write8( gauge
->GetBezelFace() );
145 data_s
.Write32( gauge
->GetValue() );
148 void WXSERIAL(wxGauge
)::LoadObject(wxObjectInputStream
& s
)
150 WXSERIAL(wxControl
)::LoadObject(s
);
152 wxDataInputStream
data_s(s
);
153 wxGauge
*gauge
= (wxGauge
*)Object();
156 range
= data_s
.Read32();
157 gauge
->Create(m_parent
, m_id
, range
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
160 gauge
->SetShadowWidth( data_s
.Read8() );
161 gauge
->SetBezelFace( data_s
.Read8() );
162 gauge
->SetValue( data_s
.Read32() );
165 void WXSERIAL(wxChoice
)::StoreObject(wxObjectOutputStream
& s
)
167 WXSERIAL(wxControl
)::StoreObject(s
);
172 wxDataOutputStream
data_s(s
);
173 wxChoice
*choice
= (wxChoice
*)Object();
174 int i
, num
= choice
->Number();
178 data_s
.WriteString( choice
->GetString(i
) );
181 void WXSERIAL(wxChoice
)::LoadObject(wxObjectInputStream
& s
)
183 WXSERIAL(wxControl
)::LoadObject(s
);
185 wxDataInputStream
data_s(s
);
186 wxChoice
*choice
= (wxChoice
*)Object();
187 int i
,num
= data_s
.Read32();
189 choice
->Create(m_parent
, m_id
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
), 0, NULL
,
193 choice
->Append( data_s
.ReadString() );
196 void WXSERIAL(wxListBox
)::StoreObject(wxObjectOutputStream
& s
)
198 WXSERIAL(wxControl
)::StoreObject(s
);
203 wxDataOutputStream
data_s(s
);
204 wxListBox
*listbox
= (wxListBox
*)Object();
205 int i
, num
= listbox
->Number();
209 data_s
.WriteString( listbox
->GetString(i
) );
212 void WXSERIAL(wxListBox
)::LoadObject(wxObjectInputStream
& s
)
214 WXSERIAL(wxListBox
)::LoadObject(s
);
216 wxDataInputStream
data_s(s
);
217 wxListBox
*listbox
= (wxListBox
*)Object();
218 int i
, num
= data_s
.Read32();
221 listbox
->Append( data_s
.ReadString() );
224 void WXSERIAL(wxNotebook
)::StoreObject(wxObjectOutputStream
& s
)
226 wxNotebook
*notebook
= (wxNotebook
*)Object();
227 int i
, pcount
= notebook
->GetPageCount();
229 WXSERIAL(wxControl
)::StoreObject(s
);
231 if (s
.FirstStage()) {
232 // Don't know how to retrieve images from wxImageList (copy to a DC ?)
236 wxDataOutputStream
data_s(s
);
238 data_s
.Write8( pcount
);
239 for (i
=0;i
<pcount
;i
++)
240 data_s
.WriteString( notebook
->GetPageText(i
) );
243 void WXSERIAL(wxNotebook
)::LoadObject(wxObjectInputStream
& s
)
245 wxNotebook
*notebook
= (wxNotebook
*)Object();
248 WXSERIAL(wxControl
)::LoadObject(s
);
250 notebook
->Create(m_parent
, m_id
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
253 wxDataInputStream
data_s(s
);
255 pcount
= data_s
.Read8();
256 for (i
=0;i
<pcount
;i
++)
257 notebook
->SetPageText(i
, data_s
.ReadString() );
260 void WXSERIAL(wxRadioBox
)::StoreObject(wxObjectOutputStream
& s
)
262 wxRadioBox
*box
= (wxRadioBox
*)Object();
263 WXSERIAL(wxControl
)::StoreObject(s
);
268 wxDataOutputStream
data_s(s
);
269 int i
, n_items
= box
->Number();
271 data_s
.Write8( n_items
);
272 data_s
.Write8( box
->GetNumberOfRowsOrCols() );
274 for (i
=0;i
<n_items
;i
++)
275 data_s
.WriteString( box
->GetString(i
) );
278 void WXSERIAL(wxRadioBox
)::LoadObject(wxObjectInputStream
& s
)
280 wxRadioBox
*box
= (wxRadioBox
*)Object();
282 WXSERIAL(wxControl
)::LoadObject(s
);
284 wxDataInputStream
data_s(s
);
285 int i
, n_rows_cols
, n_items
;
288 n_items
= data_s
.Read8();
289 n_rows_cols
= data_s
.Read8();
291 items
= new wxString
[n_items
];
292 for (i
=0;i
<n_items
;i
++)
293 items
[i
] = data_s
.ReadString();
295 box
->Create(m_parent
, m_id
, m_title
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
296 n_items
, items
, 0, m_style
, m_name
);
299 void WXSERIAL(wxComboBox
)::StoreObject(wxObjectOutputStream
& s
)
301 WXSERIAL(wxControl
)::StoreObject(s
);
306 wxDataOutputStream
data_s(s
);
307 wxComboBox
*box
= (wxComboBox
*)Object();
308 int i
, num
= box
->Number();
310 data_s
.Write8( num
);
311 data_s
.Write8( box
->GetSelection() );
313 data_s
.WriteString( box
->GetString(i
) );
315 data_s
.WriteString( box
->GetValue() );
317 // TODO: Editable flag
320 void WXSERIAL(wxComboBox
)::LoadObject(wxObjectInputStream
& s
)
322 WXSERIAL(wxControl
)::LoadObject(s
);
324 wxDataInputStream
data_s(s
);
325 wxComboBox
*box
= (wxComboBox
*)Object();
326 int i
, num
, selection
;
328 box
->Create(m_parent
, m_id
, wxEmptyString
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
329 0, NULL
, m_style
, m_name
);
331 num
= data_s
.Read8();
332 selection
= data_s
.Read8();
335 box
->Append( data_s
.ReadString() );
337 box
->SetSelection( selection
);
338 box
->SetValue( data_s
.ReadString() );
341 void WXSERIAL(wxStaticText
)::StoreObject(wxObjectOutputStream
& s
)
343 WXSERIAL(wxControl
)::StoreObject(s
);
346 void WXSERIAL(wxStaticText
)::LoadObject(wxObjectInputStream
& s
)
348 WXSERIAL(wxControl
)::LoadObject(s
);
350 ((wxStaticText
*)Object())->Create(m_parent
, m_id
, m_label
, wxPoint(m_x
, m_y
),
351 wxSize(m_w
, m_h
), m_style
, m_name
);