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 IMPLEMENT_SERIAL_CLASS(wxMDIParentFrame
, wxFrame
)
44 IMPLEMENT_SERIAL_CLASS(wxMDIChildFrame
, wxFrame
)
45 IMPLEMENT_SERIAL_CLASS(wxMDIClientWindow
, wxWindow
)
47 /////////////////////////////////////////////////////////////////////////////
49 void WXSERIAL(wxWindow
)::StoreObject(wxObjectOutputStream
& s
)
51 wxWindow
*win_object
= (wxWindow
*)Object();
52 wxNode
*node
= win_object
->GetChildren()->First();
55 s
.AddChild(win_object
->GetConstraints());
56 s
.AddChild(win_object
->GetValidator());
58 // BAD HACK, but I don't have access to the internal variable of wxWindow.
59 m_bg_colour
= win_object
->GetDefaultBackgroundColour();
60 m_fg_colour
= win_object
->GetDefaultForegroundColour();
61 s
.AddChild(&m_bg_colour
);
62 s
.AddChild(&m_fg_colour
);
63 s
.AddChild(win_object
->GetFont());
65 s
.AddChild(node
->Data());
71 wxDataOutputStream
data(s
);
74 data
.WriteString(win_object
->GetName());
75 data
.WriteString(win_object
->GetLabel());
76 data
.WriteString(win_object
->GetTitle());
78 data
.Write8(win_object
->GetAutoLayout());
79 data
.Write8(win_object
->IsShown());
80 data
.Write32( win_object
->GetWindowStyleFlag() );
81 data
.Write32(win_object
->GetId());
83 win_object
->GetSize(&w
, &h
);
84 win_object
->GetPosition(&x
, &y
);
91 void WXSERIAL(wxWindow
)::LoadObject(wxObjectInputStream
& s
)
93 wxDataInputStream
data_s(s
);
94 wxWindow
*win_object
= (wxWindow
*)Object();
96 m_parent
= (wxWindow
*)s
.GetParent();
98 m_name
= data_s
.ReadString();
99 m_label
= data_s
.ReadString();
100 m_title
= data_s
.ReadString();
102 m_auto_layout
= data_s
.Read8();
103 m_shown
= data_s
.Read8();
104 m_style
= data_s
.Read32();
105 m_id
= data_s
.Read32();
107 m_x
= data_s
.Read16();
108 m_y
= data_s
.Read16();
109 m_w
= data_s
.Read16();
110 m_h
= data_s
.Read16();
112 /* I assume we will never create raw wxWindow object */
114 m_validator
= (wxValidator
*)s
.GetChild();
115 win_object
->SetDefaultBackgroundColour(*((wxColour
*)s
.GetChild()));
116 win_object
->SetDefaultForegroundColour(*((wxColour
*)s
.GetChild()));
117 win_object
->SetFont(*((wxFont
*)s
.GetChild()));
122 /////////////////////////////////////////////////////////////////////////////
124 void WXSERIAL(wxIndividualLayoutConstraint
)::StoreObject
125 (wxObjectOutputStream
& s
)
127 wxIndividualLayoutConstraint
*lay_object
=
128 (wxIndividualLayoutConstraint
*)Object();
132 wxDataOutputStream
data_s(s
);
134 data_s
.WriteString(s
.GetObjectName(lay_object
->GetOtherWindow()));
135 data_s
.Write8(lay_object
->GetMyEdge());
136 data_s
.Write8(lay_object
->GetRelationship());
137 data_s
.Write16(lay_object
->GetMargin());
138 data_s
.Write16(lay_object
->GetValue());
139 data_s
.Write8(lay_object
->GetPercent());
140 data_s
.Write8(lay_object
->GetOtherEdge());
143 void WXSERIAL(wxIndividualLayoutConstraint
)::
144 LoadObject(wxObjectInputStream
& s
)
146 wxIndividualLayoutConstraint
*lay_object
=
147 (wxIndividualLayoutConstraint
*)Object();
148 wxDataInputStream
data_s(s
);
151 win_name
= data_s
.ReadString();
152 lay_object
->otherWin
= (wxWindow
*)s
.SolveName(win_name
);
153 lay_object
->myEdge
= (wxEdge
)data_s
.Read8();
154 lay_object
->relationship
= (wxRelationship
)data_s
.Read8();
155 lay_object
->margin
= data_s
.Read16();
156 lay_object
->value
= data_s
.Read16();
157 lay_object
->percent
= data_s
.Read8();
158 lay_object
->otherEdge
= (wxEdge
)data_s
.Read8();
161 /////////////////////////////////////////////////////////////////////////////
163 void WXSERIAL(wxLayoutConstraints
)::StoreObject(wxObjectOutputStream
& s
)
165 wxLayoutConstraints
*lay_object
= (wxLayoutConstraints
*)Object();
166 WXSERIAL(wxIndividualLayoutConstraint
) c
;
168 #define STORE(obj) c.SetObject(&(lay_object->obj)); c.StoreObject(s);
170 // I simplify the process for this object
185 void WXSERIAL(wxLayoutConstraints
)::LoadObject(wxObjectInputStream
& s
)
187 wxLayoutConstraints
*lay_object
= (wxLayoutConstraints
*)Object();
188 WXSERIAL(wxIndividualLayoutConstraint
) c
;
190 #define LOAD(obj) c.SetObject(&(lay_object->obj)); c.LoadObject(s);
192 // I simplify the process for this object
206 // Initialize constraints
207 ((wxWindow
*)s
.GetParent())->SetConstraints(lay_object
);
210 /////////////////////////////////////////////////////////////////////////////
212 void WXSERIAL(wxFrame
)::StoreObject(wxObjectOutputStream
& s
)
214 wxFrame
*frame
= (wxFrame
*)Object();
216 if (s
.FirstStage()) {
217 s
.AddChild(frame
->GetMenuBar());
218 WXSERIAL(wxWindow
)::StoreObject(s
);
222 WXSERIAL(wxWindow
)::StoreObject(s
);
224 wxDataOutputStream
data_s(s
);
225 wxStatusBar
*statbar
= frame
->GetStatusBar();
227 // AAARGH !! I absolutely need to be able to modify internal fields of
228 // wxFrame (wxToolBar and wxStatusBar)
231 data_s
.Write8(statbar
->GetFieldsCount());
234 // HOW CAN I ACCESS TO THIS FIELD ?
235 // for (...) { data_s.Write8(statbar->m_statusWidths[i]); }
238 void WXSERIAL(wxFrame
)::LoadObject(wxObjectInputStream
& s
)
240 wxFrame
*frame
= (wxFrame
*)Object();
241 wxMenuBar
*mbar
= (wxMenuBar
*)s
.GetChild();
243 WXSERIAL(wxWindow
)::LoadObject(s
);
245 wxDataInputStream
data_s(s
);
247 frame
->SetMenuBar(mbar
);
248 if (frame
->GetClassInfo() == CLASSINFO(wxFrame
))
249 frame
->Create(m_parent
, m_id
, m_title
, wxPoint(m_x
, m_y
),
250 wxSize(m_w
, m_h
), m_style
, m_name
);
252 frame
->CreateStatusBar(data_s
.Read8());
255 /////////////////////////////////////////////////////////////////////////////
257 void WXSERIAL(wxMenuBar
)::StoreObject(wxObjectOutputStream
& s
)
259 wxMenuBar
*mbar
= (wxMenuBar
*)Object();
260 int i
, mcount
= mbar
->GetMenuCount();
262 if (s
.FirstStage()) {
263 for (i
=0;i
<mcount
;i
++)
264 s
.AddChild( mbar
->GetMenu(i
) );
265 WXSERIAL(wxWindow
)::StoreObject(s
);
269 wxDataOutputStream
data_s(s
);
270 data_s
.Write8( mcount
);
272 // It isn't necessary for this object.
273 // WXSERIAL(wxWindow)::StoreObject(s);
276 void WXSERIAL(wxMenuBar
)::LoadObject(wxObjectInputStream
& s
)
278 wxMenuBar
*mbar
= (wxMenuBar
*)Object();
280 wxDataInputStream
data_s(s
);
282 mcount
= data_s
.Read8();
283 for (i
=0;i
<mcount
;i
++) {
284 wxMenu
*menu
= (wxMenu
*)s
.GetChild();
285 mbar
->Append( menu
, menu
->GetTitle() );
288 // It isn't necessary for this object.
289 // WXSERIAL(wxWindow)::LoadObject(s);
292 /////////////////////////////////////////////////////////////////////////////
294 void WXSERIAL(wxMenu
)::StoreObject(wxObjectOutputStream
& s
)
296 wxMenu
*menu
= (wxMenu
*)Object();
298 if (s
.FirstStage()) {
299 s
.AddChild( &menu
->GetItems() );
303 wxDataOutputStream
data_s(s
);
304 data_s
.WriteString( menu
->GetTitle() );
307 void WXSERIAL(wxMenu
)::LoadObject(wxObjectInputStream
& s
)
309 wxMenu
*menu
= (wxMenu
*)Object();
310 wxList
*items
= (wxList
*)s
.GetChild();
311 wxNode
*node
= items
->First();
313 wxDataInputStream
data_s(s
);
315 menu
->SetTitle( data_s
.ReadString() );
318 // NOT IMPLEMENTED in wxGTK
319 // menu->Append( (wxMenuItem *)node->Data() );
324 /////////////////////////////////////////////////////////////////////////////
326 void WXSERIAL(wxMenuItem
)::StoreObject(wxObjectOutputStream
& s
)
328 wxMenuItem
*item
= (wxMenuItem
*)Object();
330 if (s
.FirstStage()) {
331 s
.AddChild(item
->GetSubMenu());
335 wxDataOutputStream
data_s(s
);
337 data_s
.Write8( item
->GetId() );
338 data_s
.WriteString( item
->GetText() );
339 data_s
.Write8( item
->IsCheckable() );
340 data_s
.Write8( item
->IsEnabled() );
341 data_s
.Write8( item
->IsChecked() );
344 void WXSERIAL(wxMenuItem
)::LoadObject(wxObjectInputStream
& s
)
346 wxMenuItem
*item
= (wxMenuItem
*)Object();
347 wxDataInputStream
data_s(s
);
349 item
->SetId( data_s
.Read8() );
350 item
->SetText( data_s
.ReadString() );
351 item
->SetCheckable( data_s
.Read8() );
352 item
->Enable( data_s
.Read8() );
353 item
->Check( data_s
.Read8() );
354 item
->SetSubMenu( (wxMenu
*)s
.GetChild() );
357 /////////////////////////////////////////////////////////////////////////////
359 void WXSERIAL(wxPanel
)::StoreObject(wxObjectOutputStream
& s
)
361 WXSERIAL(wxWindow
)::StoreObject(s
);
364 void WXSERIAL(wxPanel
)::LoadObject(wxObjectInputStream
& s
)
366 WXSERIAL(wxWindow
)::LoadObject(s
);
368 ((wxPanel
*)Object())->Create(m_parent
, m_id
, wxPoint(m_x
, m_y
),
369 wxSize(m_w
, m_h
), m_style
, m_name
);
372 /////////////////////////////////////////////////////////////////////////////
374 void WXSERIAL(wxDialog
)::StoreObject(wxObjectOutputStream
& s
)
376 WXSERIAL(wxWindow
)::StoreObject(s
);
379 void WXSERIAL(wxDialog
)::LoadObject(wxObjectInputStream
& s
)
381 WXSERIAL(wxWindow
)::LoadObject(s
);
383 ((wxDialog
*)Object())->Create(m_parent
, m_id
, m_title
, wxPoint(m_x
, m_y
),
384 wxSize(m_w
, m_h
), m_style
, m_name
);
387 /////////////////////////////////////////////////////////////////////////////
389 void WXSERIAL(wxMDIParentFrame
)::StoreObject(wxObjectOutputStream
& s
)
391 wxMDIParentFrame
*frame
= (wxMDIParentFrame
*)Object();
393 if (s
.FirstStage()) {
394 s
.AddChild(frame
->GetClientWindow());
395 WXSERIAL(wxMDIParentFrame
)::StoreObject(s
);
399 WXSERIAL(wxMDIParentFrame
)::StoreObject(s
);
402 void WXSERIAL(wxMDIParentFrame
)::LoadObject(wxObjectInputStream
& s
)
404 wxMDIParentFrame
*frame
= (wxMDIParentFrame
*)Object();
405 wxMDIClientWindow
*client
;
407 client
= (wxMDIClientWindow
*) s
.GetChild();
409 frame
->Create(m_parent
, m_id
, m_title
, wxPoint(m_x
, m_y
),
410 wxSize(m_w
, m_h
), m_style
, m_name
);
412 WXSERIAL(wxFrame
)::LoadObject(s
);
415 /////////////////////////////////////////////////////////////////////////////
417 void WXSERIAL(wxMDIChildFrame
)::StoreObject(wxObjectOutputStream
& s
)
419 WXSERIAL(wxFrame
)::StoreObject(s
);
422 void WXSERIAL(wxMDIChildFrame
)::LoadObject(wxObjectInputStream
& s
)
424 WXSERIAL(wxFrame
)::LoadObject(s
);
426 ((wxMDIChildFrame
*)Object())->Create((wxMDIParentFrame
*)m_parent
,
428 wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
432 /////////////////////////////////////////////////////////////////////////////
434 void WXSERIAL(wxMDIClientWindow
)::StoreObject(wxObjectOutputStream
& s
)
436 WXSERIAL(wxWindow
)::StoreObject(s
);
439 void WXSERIAL(wxMDIClientWindow
)::LoadObject(wxObjectInputStream
& s
)
441 WXSERIAL(wxWindow
)::LoadObject(s
);
443 ((wxMDIClientWindow
*)Object())->CreateClient((wxMDIParentFrame
*)m_parent
, m_style
);