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/serbase.h>
28 IMPLEMENT_SERIAL_CLASS(wxWindow
, wxObject
)
29 IMPLEMENT_SERIAL_CLASS(wxIndividualLayoutConstraint
, wxObject
)
30 IMPLEMENT_SERIAL_CLASS(wxLayoutConstraints
, wxObject
)
31 IMPLEMENT_SERIAL_CLASS(wxFrame
, wxWindow
)
32 IMPLEMENT_SERIAL_CLASS(wxPanel
, wxWindow
)
33 //IMPLEMENT_SERIAL_CLASS(wxDialog, wxWindow)
34 IMPLEMENT_SERIAL_CLASS(wxMenuBar
, wxWindow
)
35 IMPLEMENT_SERIAL_CLASS(wxMenuItem
, wxObject
)
36 IMPLEMENT_SERIAL_CLASS(wxMenu
, wxObject
)
38 void WXSERIAL(wxWindow
)::StoreObject(wxObjectOutputStream
& s
)
40 wxWindow
*win_object
= (wxWindow
*)Object();
41 wxNode
*node
= win_object
->GetChildren()->First();
44 s
.AddChild(win_object
->GetConstraints());
45 // s.AddChild(&(win_object->GetDefaultBackgroundColour()));
46 // s.AddChild(&(win_object->GetDefaultForegroundColour()));
47 s
.AddChild(win_object
->GetFont());
49 s
.AddChild(node
->Data());
55 wxDataOutputStream
data(s
);
58 data
.WriteString(win_object
->GetName());
59 data
.WriteString(win_object
->GetLabel());
60 data
.WriteString(win_object
->GetTitle());
62 data
.Write8(win_object
->GetAutoLayout());
63 data
.Write8(win_object
->IsShown());
64 data
.Write32( win_object
->GetWindowStyleFlag() );
65 data
.Write32(win_object
->GetId());
67 win_object
->GetSize(&w
, &h
);
68 win_object
->GetPosition(&x
, &y
);
75 void WXSERIAL(wxWindow
)::LoadObject(wxObjectInputStream
& s
)
77 wxDataInputStream
data_s(s
);
78 wxWindow
*win_object
= (wxWindow
*)Object();
80 m_parent
= (wxWindow
*)s
.GetParent();
82 m_name
= data_s
.ReadString();
83 m_label
= data_s
.ReadString();
84 m_title
= data_s
.ReadString();
86 m_auto_layout
= data_s
.Read8();
87 m_shown
= data_s
.Read8();
88 m_style
= data_s
.Read32();
89 m_id
= data_s
.Read32();
91 m_x
= data_s
.Read16();
92 m_y
= data_s
.Read16();
93 m_w
= data_s
.Read16();
94 m_h
= data_s
.Read16();
96 /* I assume we will never create raw wxWindow object */
98 // This will be done by wxLayoutConstraints, as we need an initialized object.
99 // win_object->SetConstraints((wxLayoutConstraints *)s.GetChild(0));
100 // win_object->SetDefaultBackgroundColour(*((wxColour *)s.GetChild(1)));
101 // win_object->SetDefaultForegroundColour(*((wxColour *)s.GetChild(2)));
102 win_object
->SetFont(*((wxFont
*)s
.GetChild(1)));
107 void WXSERIAL(wxIndividualLayoutConstraint
)::StoreObject
108 (wxObjectOutputStream
& s
)
110 wxIndividualLayoutConstraint
*lay_object
=
111 (wxIndividualLayoutConstraint
*)Object();
115 wxDataOutputStream
data_s(s
);
117 data_s
.WriteString(s
.GetObjectName(lay_object
->GetOtherWindow()));
118 data_s
.Write8(lay_object
->GetMyEdge());
119 data_s
.Write8(lay_object
->GetRelationship());
120 data_s
.Write16(lay_object
->GetMargin());
121 data_s
.Write16(lay_object
->GetValue());
122 data_s
.Write8(lay_object
->GetPercent());
123 data_s
.Write8(lay_object
->GetOtherEdge());
126 void WXSERIAL(wxIndividualLayoutConstraint
)::
127 LoadObject(wxObjectInputStream
& s
)
129 wxIndividualLayoutConstraint
*lay_object
=
130 (wxIndividualLayoutConstraint
*)Object();
131 wxDataInputStream
data_s(s
);
134 win_name
= data_s
.ReadString();
135 lay_object
->otherWin
= (wxWindow
*)s
.SolveName(win_name
);
136 lay_object
->myEdge
= (wxEdge
)data_s
.Read8();
137 lay_object
->relationship
= (wxRelationship
)data_s
.Read8();
138 lay_object
->margin
= data_s
.Read16();
139 lay_object
->value
= data_s
.Read16();
140 lay_object
->percent
= data_s
.Read8();
141 lay_object
->otherEdge
= (wxEdge
)data_s
.Read8();
144 void WXSERIAL(wxLayoutConstraints
)::StoreObject(wxObjectOutputStream
& s
)
146 wxLayoutConstraints
*lay_object
= (wxLayoutConstraints
*)Object();
147 WXSERIAL(wxIndividualLayoutConstraint
) c
;
149 #define STORE(obj) c.SetObject(&(lay_object->obj)); c.StoreObject(s);
151 // I simplify the process for this object
166 void WXSERIAL(wxLayoutConstraints
)::LoadObject(wxObjectInputStream
& s
)
168 wxLayoutConstraints
*lay_object
= (wxLayoutConstraints
*)Object();
169 WXSERIAL(wxIndividualLayoutConstraint
) c
;
171 #define LOAD(obj) c.SetObject(&(lay_object->obj)); c.LoadObject(s);
173 // I simplify the process for this object
187 // Initialize constraints
188 ((wxWindow
*)s
.GetParent())->SetConstraints(lay_object
);
191 void WXSERIAL(wxFrame
)::StoreObject(wxObjectOutputStream
& s
)
193 wxFrame
*frame
= (wxFrame
*)Object();
195 if (s
.FirstStage()) {
196 s
.AddChild(frame
->GetMenuBar());
197 WXSERIAL(wxWindow
)::StoreObject(s
);
201 WXSERIAL(wxWindow
)::StoreObject(s
);
203 wxDataOutputStream
data_s(s
);
204 wxStatusBar
*statbar
= frame
->GetStatusBar();
207 data_s
.Write8(statbar
->GetFieldsCount());
210 // HOW CAN I ACCESS TO THIS FIELD ?
211 // for (...) { data_s.Write8(statbar->m_statusWidths[i]); }
214 void WXSERIAL(wxFrame
)::LoadObject(wxObjectInputStream
& s
)
216 wxFrame
*frame
= (wxFrame
*)Object();
217 wxMenuBar
*mbar
= (wxMenuBar
*)s
.GetChild(0);
220 WXSERIAL(wxWindow
)::LoadObject(s
);
222 wxDataInputStream
data_s(s
);
224 frame
->SetMenuBar(mbar
);
225 frame
->Create(m_parent
, m_id
, m_title
, wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
228 frame
->CreateStatusBar(data_s
.Read8());
231 void WXSERIAL(wxMenuBar
)::StoreObject(wxObjectOutputStream
& s
)
233 wxMenuBar
*mbar
= (wxMenuBar
*)Object();
234 int i
, mcount
= mbar
->GetMenuCount();
236 if (s
.FirstStage()) {
237 for (i
=0;i
<mcount
;i
++)
238 s
.AddChild( mbar
->GetMenu(i
) );
239 WXSERIAL(wxWindow
)::StoreObject(s
);
243 wxDataOutputStream
data_s(s
);
244 data_s
.Write8( mcount
);
246 // It isn't necessary for this object.
247 // WXSERIAL(wxWindow)::StoreObject(s);
250 void WXSERIAL(wxMenuBar
)::LoadObject(wxObjectInputStream
& s
)
252 wxMenuBar
*mbar
= (wxMenuBar
*)Object();
254 wxDataInputStream
data_s(s
);
256 mcount
= data_s
.Read8();
257 for (i
=0;i
<mcount
;i
++) {
258 wxMenu
*menu
= (wxMenu
*)s
.GetChild(0);
259 mbar
->Append( menu
, menu
->GetTitle() );
262 // It isn't necessary for this object.
263 // WXSERIAL(wxWindow)::LoadObject(s);
266 void WXSERIAL(wxMenu
)::StoreObject(wxObjectOutputStream
& s
)
268 wxMenu
*menu
= (wxMenu
*)Object();
270 if (s
.FirstStage()) {
271 s
.AddChild( &menu
->GetItems() );
275 wxDataOutputStream
data_s(s
);
276 data_s
.WriteString( menu
->GetTitle() );
279 void WXSERIAL(wxMenu
)::LoadObject(wxObjectInputStream
& s
)
281 wxMenu
*menu
= (wxMenu
*)Object();
282 wxList
*items
= (wxList
*)s
.GetChild(0);
283 wxNode
*node
= items
->First();
285 wxDataInputStream
data_s(s
);
287 // menu->SetTitle( data_s.ReadString() );
290 // NOT IMPLEMENTED in wxGTK
291 // menu->Append( (wxMenuItem *)node->Data() );
296 void WXSERIAL(wxMenuItem
)::StoreObject(wxObjectOutputStream
& s
)
298 wxMenuItem
*item
= (wxMenuItem
*)Object();
300 if (s
.FirstStage()) {
301 s
.AddChild(item
->GetSubMenu());
305 wxDataOutputStream
data_s(s
);
307 data_s
.Write8( item
->GetId() );
308 data_s
.WriteString( item
->GetText() );
309 data_s
.Write8( item
->IsCheckable() );
310 data_s
.Write8( item
->IsEnabled() );
311 data_s
.Write8( item
->IsChecked() );
314 void WXSERIAL(wxMenuItem
)::LoadObject(wxObjectInputStream
& s
)
316 wxMenuItem
*item
= (wxMenuItem
*)Object();
317 wxDataInputStream
data_s(s
);
319 item
->SetId( data_s
.Read8() );
320 item
->SetText( data_s
.ReadString() );
321 item
->SetCheckable( data_s
.Read8() );
322 item
->Enable( data_s
.Read8() );
323 item
->Check( data_s
.Read8() );
324 item
->SetSubMenu( (wxMenu
*)s
.GetChild(0) );
327 void WXSERIAL(wxPanel
)::StoreObject(wxObjectOutputStream
& s
)
329 WXSERIAL(wxWindow
)::StoreObject(s
);
332 void WXSERIAL(wxPanel
)::LoadObject(wxObjectInputStream
& s
)
334 WXSERIAL(wxWindow
)::LoadObject(s
);
336 ((wxPanel
*)Object())->Create(m_parent
, m_id
, wxPoint(m_x
, m_y
),
337 wxSize(m_w
, m_h
), m_style
, m_name
);