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>
33 IMPLEMENT_SERIAL_CLASS(wxWindow
, wxObject
)
34 IMPLEMENT_SERIAL_CLASS(wxIndividualLayoutConstraint
, wxObject
)
35 IMPLEMENT_SERIAL_CLASS(wxLayoutConstraints
, wxObject
)
36 IMPLEMENT_ALIAS_SERIAL_CLASS(wxValidator
, wxObject
)
37 IMPLEMENT_SERIAL_CLASS(wxFrame
, wxWindow
)
38 IMPLEMENT_SERIAL_CLASS(wxPanel
, wxWindow
)
39 IMPLEMENT_SERIAL_CLASS(wxDialog
, wxWindow
)
40 IMPLEMENT_SERIAL_CLASS(wxMenuBar
, wxWindow
)
41 IMPLEMENT_SERIAL_CLASS(wxMenuItem
, wxObject
)
42 IMPLEMENT_SERIAL_CLASS(wxMenu
, wxObject
)
44 IMPLEMENT_SERIAL_CLASS(wxMDIParentFrame
, wxFrame
)
45 IMPLEMENT_SERIAL_CLASS(wxMDIChildFrame
, wxFrame
)
46 IMPLEMENT_SERIAL_CLASS(wxMDIClientWindow
, wxWindow
)
48 /////////////////////////////////////////////////////////////////////////////
50 void WXSERIAL(wxWindow
)::StoreObject(wxObjectOutputStream
& s
)
52 wxWindow
*win_object
= (wxWindow
*)Object();
55 wxNode
*node
= win_object
->GetChildren()->First();
57 s
.AddChild(win_object
->GetConstraints());
58 s
.AddChild(win_object
->GetValidator());
60 // BAD HACK, but I don't have access to the internal variable of wxWindow.
61 m_bg_colour
= win_object
->GetDefaultBackgroundColour();
62 m_fg_colour
= win_object
->GetDefaultForegroundColour();
63 s
.AddChild(&m_bg_colour
);
64 s
.AddChild(&m_fg_colour
);
65 s
.AddChild(win_object
->GetFont());
67 s
.AddChild(node
->Data());
73 wxDataOutputStream
data(s
);
76 data
.WriteString( win_object
->GetName() );
77 data
.WriteString( win_object
->GetLabel() );
78 data
.WriteString( win_object
->GetTitle() );
80 data
.Write8( win_object
->GetAutoLayout() );
81 data
.Write8( win_object
->IsShown() );
82 data
.Write32( win_object
->GetWindowStyleFlag() );
83 data
.Write32( win_object
->GetId() );
84 wxLogDebug( "Number = %d", win_object
->GetChildren()->Number() );
85 data
.Write8( win_object
->GetChildren()->Number() );
87 win_object
->GetSize(&w
, &h
);
88 win_object
->GetPosition(&x
, &y
);
95 void WXSERIAL(wxWindow
)::LoadObject(wxObjectInputStream
& s
)
97 wxDataInputStream
data_s(s
);
98 wxWindow
*win_object
= (wxWindow
*)Object();
103 m_parent
= (wxWindow
*)s
.GetParent();
105 m_name
= data_s
.ReadString();
106 m_label
= data_s
.ReadString();
107 m_title
= data_s
.ReadString();
109 m_auto_layout
= data_s
.Read8();
110 m_shown
= data_s
.Read8();
111 m_style
= data_s
.Read32();
112 m_id
= data_s
.Read32();
113 number
= data_s
.Read8();
115 m_x
= data_s
.Read16();
116 m_y
= data_s
.Read16();
117 m_w
= data_s
.Read16();
118 m_h
= data_s
.Read16();
120 /* I assume we will never create raw wxWindow object */
121 (void)s
.GetChild(); // We pass wxLayoutConstraints.
123 m_validator
= (wxValidator
*)s
.GetChild();
125 m_validator
= (wxValidator
*)&wxDefaultValidator
;
127 colour
= (wxColour
*)s
.GetChild();
129 win_object
->SetDefaultBackgroundColour(*colour
);
130 colour
= (wxColour
*)s
.GetChild();
132 win_object
->SetDefaultForegroundColour(*colour
);
133 font
= (wxFont
*)s
.GetChild();
135 win_object
->SetFont(*font
);
137 s
.RemoveChildren(number
);
142 /////////////////////////////////////////////////////////////////////////////
144 void WXSERIAL(wxIndividualLayoutConstraint
)::StoreObject
145 (wxObjectOutputStream
& s
)
147 wxIndividualLayoutConstraint
*lay_object
=
148 (wxIndividualLayoutConstraint
*)Object();
152 wxDataOutputStream
data_s(s
);
154 data_s
.WriteString(s
.GetObjectName(lay_object
->GetOtherWindow()));
155 data_s
.Write8(lay_object
->GetMyEdge());
156 data_s
.Write8(lay_object
->GetRelationship());
157 data_s
.Write16(lay_object
->GetMargin());
158 data_s
.Write16(lay_object
->GetValue());
159 data_s
.Write8(lay_object
->GetPercent());
160 data_s
.Write8(lay_object
->GetOtherEdge());
163 void WXSERIAL(wxIndividualLayoutConstraint
)::
164 LoadObject(wxObjectInputStream
& s
)
166 wxIndividualLayoutConstraint
*lay_object
=
167 (wxIndividualLayoutConstraint
*)Object();
168 wxDataInputStream
data_s(s
);
171 win_name
= data_s
.ReadString();
172 lay_object
->otherWin
= (wxWindow
*)s
.SolveName(win_name
);
173 lay_object
->myEdge
= (wxEdge
)data_s
.Read8();
174 lay_object
->relationship
= (wxRelationship
)data_s
.Read8();
175 lay_object
->margin
= data_s
.Read16();
176 lay_object
->value
= data_s
.Read16();
177 lay_object
->percent
= data_s
.Read8();
178 lay_object
->otherEdge
= (wxEdge
)data_s
.Read8();
181 /////////////////////////////////////////////////////////////////////////////
183 void WXSERIAL(wxLayoutConstraints
)::StoreObject(wxObjectOutputStream
& s
)
185 wxLayoutConstraints
*lay_object
= (wxLayoutConstraints
*)Object();
186 WXSERIAL(wxIndividualLayoutConstraint
) c
;
188 #define STORE(obj) c.SetObject(&(lay_object->obj)); c.StoreObject(s);
190 // I simplify the process for this object
205 void WXSERIAL(wxLayoutConstraints
)::LoadObject(wxObjectInputStream
& s
)
207 wxLayoutConstraints
*lay_object
= (wxLayoutConstraints
*)Object();
208 WXSERIAL(wxIndividualLayoutConstraint
) c
;
210 #define LOAD(obj) c.SetObject(&(lay_object->obj)); c.LoadObject(s);
212 // I simplify the process for this object
226 // Initialize constraints
227 ((wxWindow
*)s
.GetParent())->SetConstraints(lay_object
);
230 /////////////////////////////////////////////////////////////////////////////
232 void WXSERIAL(wxFrame
)::StoreObject(wxObjectOutputStream
& s
)
234 wxFrame
*frame
= (wxFrame
*)Object();
236 if (s
.FirstStage()) {
237 s
.AddChild(frame
->GetMenuBar());
238 WXSERIAL(wxWindow
)::StoreObject(s
);
242 WXSERIAL(wxWindow
)::StoreObject(s
);
244 wxDataOutputStream
data_s(s
);
245 wxStatusBar
*statbar
= frame
->GetStatusBar();
247 // AAARGH !! I absolutely need to be able to modify internal fields of
248 // wxFrame (wxToolBar and wxStatusBar)
251 data_s
.Write8(statbar
->GetFieldsCount());
254 // HOW CAN I ACCESS TO THIS FIELD ?
255 // for (...) { data_s.Write8(statbar->m_statusWidths[i]); }
258 void WXSERIAL(wxFrame
)::LoadObject(wxObjectInputStream
& s
)
260 wxFrame
*frame
= (wxFrame
*)Object();
261 wxMenuBar
*mbar
= (wxMenuBar
*)s
.GetChild();
263 WXSERIAL(wxWindow
)::LoadObject(s
);
265 wxDataInputStream
data_s(s
);
267 frame
->SetMenuBar(mbar
);
268 if (frame
->GetClassInfo() == CLASSINFO(wxFrame
))
269 frame
->Create(m_parent
, m_id
, m_title
, wxPoint(m_x
, m_y
),
270 wxSize(m_w
, m_h
), m_style
, m_name
);
272 frame
->CreateStatusBar(data_s
.Read8());
275 /////////////////////////////////////////////////////////////////////////////
277 void WXSERIAL(wxMenuBar
)::StoreObject(wxObjectOutputStream
& s
)
279 wxMenuBar
*mbar
= (wxMenuBar
*)Object();
280 int i
, mcount
= mbar
->GetMenuCount();
282 if (s
.FirstStage()) {
283 for (i
=0;i
<mcount
;i
++)
284 s
.AddChild( mbar
->GetMenu(i
) );
285 WXSERIAL(wxWindow
)::StoreObject(s
);
289 wxDataOutputStream
data_s(s
);
290 data_s
.Write8( mcount
);
292 // It isn't necessary for this object.
293 // WXSERIAL(wxWindow)::StoreObject(s);
296 void WXSERIAL(wxMenuBar
)::LoadObject(wxObjectInputStream
& s
)
298 wxMenuBar
*mbar
= (wxMenuBar
*)Object();
300 wxDataInputStream
data_s(s
);
302 mcount
= data_s
.Read8();
303 for (i
=0;i
<mcount
;i
++) {
304 wxMenu
*menu
= (wxMenu
*)s
.GetChild();
305 mbar
->Append( menu
, menu
->GetTitle() );
308 // It isn't necessary for this object.
309 // WXSERIAL(wxWindow)::LoadObject(s);
312 /////////////////////////////////////////////////////////////////////////////
314 void WXSERIAL(wxMenu
)::StoreObject(wxObjectOutputStream
& s
)
316 wxMenu
*menu
= (wxMenu
*)Object();
318 if (s
.FirstStage()) {
319 s
.AddChild( &menu
->GetItems() );
323 wxDataOutputStream
data_s(s
);
324 data_s
.WriteString( menu
->GetTitle() );
327 void WXSERIAL(wxMenu
)::LoadObject(wxObjectInputStream
& s
)
329 wxMenu
*menu
= (wxMenu
*)Object();
330 wxList
*items
= (wxList
*)s
.GetChild();
331 wxNode
*node
= items
->First();
333 wxDataInputStream
data_s(s
);
335 menu
->SetTitle( data_s
.ReadString() );
338 // NOT IMPLEMENTED in wxGTK
339 // menu->Append( (wxMenuItem *)node->Data() );
344 /////////////////////////////////////////////////////////////////////////////
346 void WXSERIAL(wxMenuItem
)::StoreObject(wxObjectOutputStream
& s
)
348 wxMenuItem
*item
= (wxMenuItem
*)Object();
350 if (s
.FirstStage()) {
351 s
.AddChild(item
->GetSubMenu());
355 wxDataOutputStream
data_s(s
);
357 data_s
.Write8( item
->GetId() );
358 data_s
.WriteString( item
->GetText() );
359 data_s
.Write8( item
->IsCheckable() );
360 data_s
.Write8( item
->IsEnabled() );
361 data_s
.Write8( item
->IsChecked() );
364 void WXSERIAL(wxMenuItem
)::LoadObject(wxObjectInputStream
& s
)
366 wxMenuItem
*item
= (wxMenuItem
*)Object();
367 wxDataInputStream
data_s(s
);
369 item
->SetId( data_s
.Read8() );
370 item
->SetText( data_s
.ReadString() );
371 item
->SetCheckable( data_s
.Read8() );
372 item
->Enable( data_s
.Read8() );
373 item
->Check( data_s
.Read8() );
374 item
->SetSubMenu( (wxMenu
*)s
.GetChild() );
377 /////////////////////////////////////////////////////////////////////////////
379 void WXSERIAL(wxPanel
)::StoreObject(wxObjectOutputStream
& s
)
381 WXSERIAL(wxWindow
)::StoreObject(s
);
384 void WXSERIAL(wxPanel
)::LoadObject(wxObjectInputStream
& s
)
386 WXSERIAL(wxWindow
)::LoadObject(s
);
388 ((wxPanel
*)Object())->Create(m_parent
, m_id
, wxPoint(m_x
, m_y
),
389 wxSize(m_w
, m_h
), m_style
, m_name
);
392 /////////////////////////////////////////////////////////////////////////////
394 void WXSERIAL(wxDialog
)::StoreObject(wxObjectOutputStream
& s
)
396 WXSERIAL(wxWindow
)::StoreObject(s
);
399 void WXSERIAL(wxDialog
)::LoadObject(wxObjectInputStream
& s
)
401 WXSERIAL(wxWindow
)::LoadObject(s
);
403 ((wxDialog
*)Object())->Create(m_parent
, m_id
, m_title
, wxPoint(m_x
, m_y
),
404 wxSize(m_w
, m_h
), m_style
, m_name
);
407 /////////////////////////////////////////////////////////////////////////////
409 void WXSERIAL(wxMDIParentFrame
)::StoreObject(wxObjectOutputStream
& s
)
411 wxMDIParentFrame
*frame
= (wxMDIParentFrame
*)Object();
413 if (s
.FirstStage()) {
414 s
.AddChild(frame
->GetClientWindow());
415 WXSERIAL(wxMDIParentFrame
)::StoreObject(s
);
419 WXSERIAL(wxMDIParentFrame
)::StoreObject(s
);
422 void WXSERIAL(wxMDIParentFrame
)::LoadObject(wxObjectInputStream
& s
)
424 wxMDIParentFrame
*frame
= (wxMDIParentFrame
*)Object();
425 wxMDIClientWindow
*client
;
427 client
= (wxMDIClientWindow
*) s
.GetChild();
429 frame
->Create(m_parent
, m_id
, m_title
, wxPoint(m_x
, m_y
),
430 wxSize(m_w
, m_h
), m_style
, m_name
);
432 WXSERIAL(wxFrame
)::LoadObject(s
);
435 /////////////////////////////////////////////////////////////////////////////
437 void WXSERIAL(wxMDIChildFrame
)::StoreObject(wxObjectOutputStream
& s
)
439 WXSERIAL(wxFrame
)::StoreObject(s
);
442 void WXSERIAL(wxMDIChildFrame
)::LoadObject(wxObjectInputStream
& s
)
444 WXSERIAL(wxFrame
)::LoadObject(s
);
446 ((wxMDIChildFrame
*)Object())->Create((wxMDIParentFrame
*)m_parent
,
448 wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
452 /////////////////////////////////////////////////////////////////////////////
454 void WXSERIAL(wxMDIClientWindow
)::StoreObject(wxObjectOutputStream
& s
)
456 WXSERIAL(wxWindow
)::StoreObject(s
);
459 void WXSERIAL(wxMDIClientWindow
)::LoadObject(wxObjectInputStream
& s
)
461 WXSERIAL(wxWindow
)::LoadObject(s
);
463 ((wxMDIClientWindow
*)Object())->CreateClient((wxMDIParentFrame
*)m_parent
, m_style
);