1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Serialization: wxWindow classes
4 // Author: Guilhem Lavaux
8 // Copyright: (c) 1998 Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "serwnd.h"
16 #include <wx/window.h>
17 #include <wx/layout.h>
18 #include <wx/stream.h>
19 #include <wx/datstrm.h>
20 #include <wx/objstrm.h>
25 #include <wx/dialog.h>
26 #include <wx/serbase.h>
27 #include <wx/statusbr.h>
32 IMPLEMENT_SERIAL_CLASS(wxWindow
, wxObject
)
33 IMPLEMENT_SERIAL_CLASS(wxIndividualLayoutConstraint
, wxObject
)
34 IMPLEMENT_SERIAL_CLASS(wxLayoutConstraints
, wxObject
)
35 IMPLEMENT_ALIAS_SERIAL_CLASS(wxValidator
, wxObject
)
36 IMPLEMENT_SERIAL_CLASS(wxFrame
, wxWindow
)
37 IMPLEMENT_SERIAL_CLASS(wxPanel
, wxWindow
)
38 IMPLEMENT_SERIAL_CLASS(wxDialog
, wxWindow
)
39 IMPLEMENT_SERIAL_CLASS(wxMenuBar
, wxWindow
)
40 IMPLEMENT_SERIAL_CLASS(wxMenuItem
, wxObject
)
41 IMPLEMENT_SERIAL_CLASS(wxMenu
, wxObject
)
43 /////////////////////////////////////////////////////////////////////////////
45 void WXSERIAL(wxWindow
)::StoreObject(wxObjectOutputStream
& s
)
47 wxWindow
*win_object
= (wxWindow
*)Object();
48 wxNode
*node
= win_object
->GetChildren()->First();
51 s
.AddChild(win_object
->GetConstraints());
52 s
.AddChild(win_object
->GetValidator());
54 // BAD HACK, but I don't have access to the internal variable of wxWindow.
55 m_bg_colour
= win_object
->GetDefaultBackgroundColour();
56 m_fg_colour
= win_object
->GetDefaultForegroundColour();
57 s
.AddChild(&m_bg_colour
);
58 s
.AddChild(&m_fg_colour
);
59 s
.AddChild(win_object
->GetFont());
61 s
.AddChild(node
->Data());
67 wxDataOutputStream
data(s
);
70 data
.WriteString(win_object
->GetName());
71 data
.WriteString(win_object
->GetLabel());
72 data
.WriteString(win_object
->GetTitle());
74 data
.Write8(win_object
->GetAutoLayout());
75 data
.Write8(win_object
->IsShown());
76 data
.Write32( win_object
->GetWindowStyleFlag() );
77 data
.Write32(win_object
->GetId());
79 win_object
->GetSize(&w
, &h
);
80 win_object
->GetPosition(&x
, &y
);
87 void WXSERIAL(wxWindow
)::LoadObject(wxObjectInputStream
& s
)
89 wxDataInputStream
data_s(s
);
90 wxWindow
*win_object
= (wxWindow
*)Object();
92 m_parent
= (wxWindow
*)s
.GetParent();
94 m_name
= data_s
.ReadString();
95 m_label
= data_s
.ReadString();
96 m_title
= data_s
.ReadString();
98 m_auto_layout
= data_s
.Read8();
99 m_shown
= data_s
.Read8();
100 m_style
= data_s
.Read32();
101 m_id
= data_s
.Read32();
103 m_x
= data_s
.Read16();
104 m_y
= data_s
.Read16();
105 m_w
= data_s
.Read16();
106 m_h
= data_s
.Read16();
108 /* I assume we will never create raw wxWindow object */
110 m_validator
= (wxValidator
*)s
.GetChild(1);
111 win_object
->SetDefaultBackgroundColour(*((wxColour
*)s
.GetChild(2)));
112 win_object
->SetDefaultForegroundColour(*((wxColour
*)s
.GetChild(3)));
113 win_object
->SetFont(*((wxFont
*)s
.GetChild(4)));
118 /////////////////////////////////////////////////////////////////////////////
120 void WXSERIAL(wxIndividualLayoutConstraint
)::StoreObject
121 (wxObjectOutputStream
& s
)
123 wxIndividualLayoutConstraint
*lay_object
=
124 (wxIndividualLayoutConstraint
*)Object();
128 wxDataOutputStream
data_s(s
);
130 data_s
.WriteString(s
.GetObjectName(lay_object
->GetOtherWindow()));
131 data_s
.Write8(lay_object
->GetMyEdge());
132 data_s
.Write8(lay_object
->GetRelationship());
133 data_s
.Write16(lay_object
->GetMargin());
134 data_s
.Write16(lay_object
->GetValue());
135 data_s
.Write8(lay_object
->GetPercent());
136 data_s
.Write8(lay_object
->GetOtherEdge());
139 void WXSERIAL(wxIndividualLayoutConstraint
)::
140 LoadObject(wxObjectInputStream
& s
)
142 wxIndividualLayoutConstraint
*lay_object
=
143 (wxIndividualLayoutConstraint
*)Object();
144 wxDataInputStream
data_s(s
);
147 win_name
= data_s
.ReadString();
148 lay_object
->otherWin
= (wxWindow
*)s
.SolveName(win_name
);
149 lay_object
->myEdge
= (wxEdge
)data_s
.Read8();
150 lay_object
->relationship
= (wxRelationship
)data_s
.Read8();
151 lay_object
->margin
= data_s
.Read16();
152 lay_object
->value
= data_s
.Read16();
153 lay_object
->percent
= data_s
.Read8();
154 lay_object
->otherEdge
= (wxEdge
)data_s
.Read8();
157 /////////////////////////////////////////////////////////////////////////////
159 void WXSERIAL(wxLayoutConstraints
)::StoreObject(wxObjectOutputStream
& s
)
161 wxLayoutConstraints
*lay_object
= (wxLayoutConstraints
*)Object();
162 WXSERIAL(wxIndividualLayoutConstraint
) c
;
164 #define STORE(obj) c.SetObject(&(lay_object->obj)); c.StoreObject(s);
166 // I simplify the process for this object
181 void WXSERIAL(wxLayoutConstraints
)::LoadObject(wxObjectInputStream
& s
)
183 wxLayoutConstraints
*lay_object
= (wxLayoutConstraints
*)Object();
184 WXSERIAL(wxIndividualLayoutConstraint
) c
;
186 #define LOAD(obj) c.SetObject(&(lay_object->obj)); c.LoadObject(s);
188 // I simplify the process for this object
202 // Initialize constraints
203 ((wxWindow
*)s
.GetParent())->SetConstraints(lay_object
);
206 /////////////////////////////////////////////////////////////////////////////
208 void WXSERIAL(wxFrame
)::StoreObject(wxObjectOutputStream
& s
)
210 wxFrame
*frame
= (wxFrame
*)Object();
212 if (s
.FirstStage()) {
213 s
.AddChild(frame
->GetMenuBar());
214 WXSERIAL(wxWindow
)::StoreObject(s
);
218 WXSERIAL(wxWindow
)::StoreObject(s
);
220 wxDataOutputStream
data_s(s
);
221 wxStatusBar
*statbar
= frame
->GetStatusBar();
224 data_s
.Write8(statbar
->GetFieldsCount());
227 // HOW CAN I ACCESS TO THIS FIELD ?
228 // for (...) { data_s.Write8(statbar->m_statusWidths[i]); }
231 void WXSERIAL(wxFrame
)::LoadObject(wxObjectInputStream
& s
)
233 wxFrame
*frame
= (wxFrame
*)Object();
234 wxMenuBar
*mbar
= (wxMenuBar
*)s
.GetChild(0);
237 WXSERIAL(wxWindow
)::LoadObject(s
);
239 wxDataInputStream
data_s(s
);
241 frame
->SetMenuBar(mbar
);
242 if (frame
->GetClassInfo() == CLASSINFO(wxFrame
))
243 frame
->Create(m_parent
, m_id
, m_title
, wxPoint(m_x
, m_y
),
244 wxSize(m_w
, m_h
), m_style
, m_name
);
246 frame
->CreateStatusBar(data_s
.Read8());
249 /////////////////////////////////////////////////////////////////////////////
251 void WXSERIAL(wxMenuBar
)::StoreObject(wxObjectOutputStream
& s
)
253 wxMenuBar
*mbar
= (wxMenuBar
*)Object();
254 int i
, mcount
= mbar
->GetMenuCount();
256 if (s
.FirstStage()) {
257 for (i
=0;i
<mcount
;i
++)
258 s
.AddChild( mbar
->GetMenu(i
) );
259 WXSERIAL(wxWindow
)::StoreObject(s
);
263 wxDataOutputStream
data_s(s
);
264 data_s
.Write8( mcount
);
266 // It isn't necessary for this object.
267 // WXSERIAL(wxWindow)::StoreObject(s);
270 void WXSERIAL(wxMenuBar
)::LoadObject(wxObjectInputStream
& s
)
272 wxMenuBar
*mbar
= (wxMenuBar
*)Object();
274 wxDataInputStream
data_s(s
);
276 mcount
= data_s
.Read8();
277 for (i
=0;i
<mcount
;i
++) {
278 wxMenu
*menu
= (wxMenu
*)s
.GetChild(0);
279 mbar
->Append( menu
, menu
->GetTitle() );
282 // It isn't necessary for this object.
283 // WXSERIAL(wxWindow)::LoadObject(s);
286 /////////////////////////////////////////////////////////////////////////////
288 void WXSERIAL(wxMenu
)::StoreObject(wxObjectOutputStream
& s
)
290 wxMenu
*menu
= (wxMenu
*)Object();
292 if (s
.FirstStage()) {
293 s
.AddChild( &menu
->GetItems() );
297 wxDataOutputStream
data_s(s
);
298 data_s
.WriteString( menu
->GetTitle() );
301 void WXSERIAL(wxMenu
)::LoadObject(wxObjectInputStream
& s
)
303 wxMenu
*menu
= (wxMenu
*)Object();
304 wxList
*items
= (wxList
*)s
.GetChild(0);
305 wxNode
*node
= items
->First();
307 wxDataInputStream
data_s(s
);
309 // menu->SetTitle( data_s.ReadString() );
312 // NOT IMPLEMENTED in wxGTK
313 // menu->Append( (wxMenuItem *)node->Data() );
318 /////////////////////////////////////////////////////////////////////////////
320 void WXSERIAL(wxMenuItem
)::StoreObject(wxObjectOutputStream
& s
)
322 wxMenuItem
*item
= (wxMenuItem
*)Object();
324 if (s
.FirstStage()) {
325 s
.AddChild(item
->GetSubMenu());
329 wxDataOutputStream
data_s(s
);
331 data_s
.Write8( item
->GetId() );
332 data_s
.WriteString( item
->GetText() );
333 data_s
.Write8( item
->IsCheckable() );
334 data_s
.Write8( item
->IsEnabled() );
335 data_s
.Write8( item
->IsChecked() );
338 void WXSERIAL(wxMenuItem
)::LoadObject(wxObjectInputStream
& s
)
340 wxMenuItem
*item
= (wxMenuItem
*)Object();
341 wxDataInputStream
data_s(s
);
343 item
->SetId( data_s
.Read8() );
344 item
->SetText( data_s
.ReadString() );
345 item
->SetCheckable( data_s
.Read8() );
346 item
->Enable( data_s
.Read8() );
347 item
->Check( data_s
.Read8() );
348 item
->SetSubMenu( (wxMenu
*)s
.GetChild(0) );
351 /////////////////////////////////////////////////////////////////////////////
353 void WXSERIAL(wxPanel
)::StoreObject(wxObjectOutputStream
& s
)
355 WXSERIAL(wxWindow
)::StoreObject(s
);
358 void WXSERIAL(wxPanel
)::LoadObject(wxObjectInputStream
& s
)
360 WXSERIAL(wxWindow
)::LoadObject(s
);
362 ((wxPanel
*)Object())->Create(m_parent
, m_id
, wxPoint(m_x
, m_y
),
363 wxSize(m_w
, m_h
), m_style
, m_name
);
366 /////////////////////////////////////////////////////////////////////////////
368 void WXSERIAL(wxDialog
)::StoreObject(wxObjectOutputStream
& s
)
370 WXSERIAL(wxWindow
)::StoreObject(s
);
373 void WXSERIAL(wxDialog
)::LoadObject(wxObjectInputStream
& s
)
375 WXSERIAL(wxWindow
)::LoadObject(s
);
377 ((wxDialog
*)Object())->Create(m_parent
, m_id
, m_title
, wxPoint(m_x
, m_y
),
378 wxSize(m_w
, m_h
), m_style
, m_name
);
381 /////////////////////////////////////////////////////////////////////////////
383 void WXSERIAL(wxMDIParentFrame
)::StoreObject(wxObjectOutputStream
& s
)
385 wxMDIParentFrame
*frame
= (wxMDIParentFrame
*)Object();
387 if (s
.FirstStage()) {
388 s
.AddChild(frame
->GetClientWindow());
389 WXSERIAL(wxMDIParentFrame
)::StoreObject(s
);
393 WXSERIAL(wxMDIParentFrame
)::StoreObject(s
);
396 void WXSERIAL(wxMDIParentFrame
)::LoadObject(wxObjectInputStream
& s
)
398 wxMDIParentFrame
*frame
= (wxMDIParentFrame
*)Object();
399 wxMDIClientWindow
*client
;
401 client
= (wxMDIClientWindow
*) s
.GetChild(0);
404 frame
->Create(m_parent
, m_id
, m_title
, wxPoint(m_x
, m_y
),
405 wxSize(m_w
, m_h
), m_style
, m_name
);
406 // client->CreateClient(this, style_client);
408 WXSERIAL(wxFrame
)::LoadObject(s
);