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
->GetBackgroundColour();
62 m_fg_colour
= win_object
->GetForegroundColour();
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();
102 if (s
.SecondCall()) {
103 /* I assume we will never create raw wxWindow object */
104 (void)s
.GetChild(); // We pass wxLayoutConstraints.
105 (void)s
.GetChild(); // We pass wxValidator.
107 colour
= (wxColour
*)s
.GetChild();
109 win_object
->SetBackgroundColour(*colour
);
110 colour
= (wxColour
*)s
.GetChild();
112 win_object
->SetForegroundColour(*colour
);
113 font
= (wxFont
*)s
.GetChild();
115 win_object
->SetFont(*font
);
116 s
.RemoveChildren(m_number
);
120 m_parent
= (wxWindow
*)s
.GetParent();
122 m_name
= data_s
.ReadString();
123 m_label
= data_s
.ReadString();
124 m_title
= data_s
.ReadString();
126 m_auto_layout
= data_s
.Read8();
127 m_shown
= data_s
.Read8();
128 m_style
= data_s
.Read32();
129 m_id
= data_s
.Read32();
130 m_number
= data_s
.Read8();
132 m_x
= data_s
.Read16();
133 m_y
= data_s
.Read16();
134 m_w
= data_s
.Read16();
135 m_h
= data_s
.Read16();
137 (void)s
.GetChild(); // We pass wxLayoutConstraints.
139 m_validator
= (wxValidator
*)s
.GetChild();
141 m_validator
= (wxValidator
*)&wxDefaultValidator
;
143 s
.RemoveChildren(m_number
+3);
150 /////////////////////////////////////////////////////////////////////////////
152 void WXSERIAL(wxIndividualLayoutConstraint
)::StoreObject
153 (wxObjectOutputStream
& s
)
155 wxIndividualLayoutConstraint
*lay_object
=
156 (wxIndividualLayoutConstraint
*)Object();
160 wxDataOutputStream
data_s(s
);
162 data_s
.WriteString(s
.GetObjectName(lay_object
->GetOtherWindow()));
163 data_s
.Write8(lay_object
->GetMyEdge());
164 data_s
.Write8(lay_object
->GetRelationship());
165 data_s
.Write16(lay_object
->GetMargin());
166 data_s
.Write16(lay_object
->GetValue());
167 data_s
.Write8(lay_object
->GetPercent());
168 data_s
.Write8(lay_object
->GetOtherEdge());
171 void WXSERIAL(wxIndividualLayoutConstraint
)::
172 LoadObject(wxObjectInputStream
& s
)
174 wxIndividualLayoutConstraint
*lay_object
=
175 (wxIndividualLayoutConstraint
*)Object();
176 wxDataInputStream
data_s(s
);
179 win_name
= data_s
.ReadString();
180 lay_object
->otherWin
= (wxWindow
*)s
.SolveName(win_name
);
181 lay_object
->myEdge
= (wxEdge
)data_s
.Read8();
182 lay_object
->relationship
= (wxRelationship
)data_s
.Read8();
183 lay_object
->margin
= data_s
.Read16();
184 lay_object
->value
= data_s
.Read16();
185 lay_object
->percent
= data_s
.Read8();
186 lay_object
->otherEdge
= (wxEdge
)data_s
.Read8();
189 /////////////////////////////////////////////////////////////////////////////
191 void WXSERIAL(wxLayoutConstraints
)::StoreObject(wxObjectOutputStream
& s
)
193 wxLayoutConstraints
*lay_object
= (wxLayoutConstraints
*)Object();
194 WXSERIAL(wxIndividualLayoutConstraint
) c
;
196 #define STORE(obj) c.SetObject(&(lay_object->obj)); c.StoreObject(s);
198 // I simplify the process for this object
213 void WXSERIAL(wxLayoutConstraints
)::LoadObject(wxObjectInputStream
& s
)
215 wxLayoutConstraints
*lay_object
= (wxLayoutConstraints
*)Object();
216 WXSERIAL(wxIndividualLayoutConstraint
) c
;
218 #define LOAD(obj) c.SetObject(&(lay_object->obj)); c.LoadObject(s);
220 // I simplify the process for this object
234 // Initialize constraints
235 ((wxWindow
*)s
.GetParent())->SetConstraints(lay_object
);
238 /////////////////////////////////////////////////////////////////////////////
240 void WXSERIAL(wxFrame
)::StoreObject(wxObjectOutputStream
& s
)
242 wxFrame
*frame
= (wxFrame
*)Object();
244 if (s
.FirstStage()) {
245 s
.AddChild(frame
->GetMenuBar());
246 WXSERIAL(wxWindow
)::StoreObject(s
);
250 WXSERIAL(wxWindow
)::StoreObject(s
);
252 wxDataOutputStream
data_s(s
);
253 wxStatusBar
*statbar
= frame
->GetStatusBar();
255 // AAARGH !! I absolutely need to be able to modify internal fields of
256 // wxFrame (wxToolBar and wxStatusBar)
259 data_s
.Write8(statbar
->GetFieldsCount());
262 // HOW CAN I ACCESS TO THIS FIELD ?
263 // for (...) { data_s.Write8(statbar->m_statusWidths[i]); }
266 void WXSERIAL(wxFrame
)::LoadObject(wxObjectInputStream
& s
)
268 wxFrame
*frame
= (wxFrame
*)Object();
269 wxMenuBar
*mbar
= (wxMenuBar
*)s
.GetChild();
271 WXSERIAL(wxWindow
)::LoadObject(s
);
276 wxDataInputStream
data_s(s
);
278 if (frame
->GetClassInfo() == CLASSINFO(wxFrame
))
279 frame
->Create(m_parent
, m_id
, m_title
, wxPoint(m_x
, m_y
),
280 wxSize(m_w
, m_h
), m_style
, m_name
);
281 frame
->SetMenuBar(mbar
);
283 frame
->CreateStatusBar(data_s
.Read8());
286 /////////////////////////////////////////////////////////////////////////////
288 void WXSERIAL(wxMenuBar
)::StoreObject(wxObjectOutputStream
& s
)
290 wxMenuBar
*mbar
= (wxMenuBar
*)Object();
291 int i
, mcount
= mbar
->GetMenuCount();
293 if (s
.FirstStage()) {
294 for (i
=0;i
<mcount
;i
++)
295 s
.AddChild( mbar
->GetMenu(i
) );
296 WXSERIAL(wxWindow
)::StoreObject(s
);
300 wxDataOutputStream
data_s(s
);
301 data_s
.Write8( mcount
);
303 // It isn't necessary for this object.
304 // WXSERIAL(wxWindow)::StoreObject(s);
307 void WXSERIAL(wxMenuBar
)::LoadObject(wxObjectInputStream
& s
)
309 wxMenuBar
*mbar
= (wxMenuBar
*)Object();
311 wxDataInputStream
data_s(s
);
313 mcount
= data_s
.Read8();
314 for (i
=0;i
<mcount
;i
++) {
315 wxMenu
*menu
= (wxMenu
*)s
.GetChild();
316 mbar
->Append( menu
, menu
->GetTitle() );
319 // It isn't necessary for this object.
320 // WXSERIAL(wxWindow)::LoadObject(s);
323 /////////////////////////////////////////////////////////////////////////////
325 void WXSERIAL(wxMenu
)::StoreObject(wxObjectOutputStream
& s
)
327 wxMenu
*menu
= (wxMenu
*)Object();
329 if (s
.FirstStage()) {
330 s
.AddChild( &menu
->GetItems() );
334 wxDataOutputStream
data_s(s
);
335 data_s
.WriteString( menu
->GetTitle() );
338 void WXSERIAL(wxMenu
)::LoadObject(wxObjectInputStream
& s
)
340 wxMenu
*menu
= (wxMenu
*)Object();
341 wxList
*items
= (wxList
*)s
.GetChild();
342 wxNode
*node
= items
->First();
344 wxDataInputStream
data_s(s
);
346 menu
->SetTitle( data_s
.ReadString() );
349 // NOT IMPLEMENTED in wxGTK
350 // menu->Append( (wxMenuItem *)node->Data() );
355 /////////////////////////////////////////////////////////////////////////////
357 void WXSERIAL(wxMenuItem
)::StoreObject(wxObjectOutputStream
& s
)
359 wxMenuItem
*item
= (wxMenuItem
*)Object();
361 if (s
.FirstStage()) {
363 s
.AddChild(item
->GetSubMenu());
368 wxDataOutputStream
data_s(s
);
371 data_s
.Write8( item
->GetId() );
372 data_s
.WriteString( item
->GetText() );
373 data_s
.Write8( item
->IsCheckable() );
374 data_s
.Write8( item
->IsEnabled() );
375 data_s
.Write8( item
->IsChecked() );
379 void WXSERIAL(wxMenuItem
)::LoadObject(wxObjectInputStream
& s
)
381 wxMenuItem
*item
= (wxMenuItem
*)Object();
382 wxDataInputStream
data_s(s
);
385 item
->SetId( data_s
.Read8() );
386 item
->SetText( data_s
.ReadString() );
387 item
->SetCheckable( data_s
.Read8() );
388 item
->Enable( data_s
.Read8() );
389 item
->Check( data_s
.Read8() );
390 item
->SetSubMenu( (wxMenu
*)s
.GetChild() );
394 /////////////////////////////////////////////////////////////////////////////
396 void WXSERIAL(wxPanel
)::StoreObject(wxObjectOutputStream
& s
)
398 WXSERIAL(wxWindow
)::StoreObject(s
);
401 void WXSERIAL(wxPanel
)::LoadObject(wxObjectInputStream
& s
)
403 WXSERIAL(wxWindow
)::LoadObject(s
);
408 ((wxPanel
*)Object())->Create(m_parent
, m_id
, wxPoint(m_x
, m_y
),
409 wxSize(m_w
, m_h
), m_style
, m_name
);
412 /////////////////////////////////////////////////////////////////////////////
414 void WXSERIAL(wxDialog
)::StoreObject(wxObjectOutputStream
& s
)
416 WXSERIAL(wxWindow
)::StoreObject(s
);
419 void WXSERIAL(wxDialog
)::LoadObject(wxObjectInputStream
& s
)
421 WXSERIAL(wxWindow
)::LoadObject(s
);
426 ((wxDialog
*)Object())->Create(m_parent
, m_id
, m_title
, wxPoint(m_x
, m_y
),
427 wxSize(m_w
, m_h
), m_style
, m_name
);
430 /////////////////////////////////////////////////////////////////////////////
432 void WXSERIAL(wxMDIParentFrame
)::StoreObject(wxObjectOutputStream
& s
)
434 wxMDIParentFrame
*frame
= (wxMDIParentFrame
*)Object();
436 if (s
.FirstStage()) {
437 s
.AddChild(frame
->GetClientWindow());
438 WXSERIAL(wxMDIParentFrame
)::StoreObject(s
);
442 WXSERIAL(wxMDIParentFrame
)::StoreObject(s
);
445 void WXSERIAL(wxMDIParentFrame
)::LoadObject(wxObjectInputStream
& s
)
447 wxMDIParentFrame
*frame
= (wxMDIParentFrame
*)Object();
448 wxMDIClientWindow
*client
;
450 if (s
.SecondCall()) {
451 WXSERIAL(wxFrame
)::LoadObject(s
);
455 client
= (wxMDIClientWindow
*) s
.GetChild();
457 frame
->Create(m_parent
, m_id
, m_title
, wxPoint(m_x
, m_y
),
458 wxSize(m_w
, m_h
), m_style
, m_name
);
460 WXSERIAL(wxFrame
)::LoadObject(s
);
463 /////////////////////////////////////////////////////////////////////////////
465 void WXSERIAL(wxMDIChildFrame
)::StoreObject(wxObjectOutputStream
& s
)
467 WXSERIAL(wxFrame
)::StoreObject(s
);
470 void WXSERIAL(wxMDIChildFrame
)::LoadObject(wxObjectInputStream
& s
)
472 WXSERIAL(wxFrame
)::LoadObject(s
);
477 ((wxMDIChildFrame
*)Object())->Create((wxMDIParentFrame
*)m_parent
,
479 wxPoint(m_x
, m_y
), wxSize(m_w
, m_h
),
483 /////////////////////////////////////////////////////////////////////////////
485 void WXSERIAL(wxMDIClientWindow
)::StoreObject(wxObjectOutputStream
& s
)
487 WXSERIAL(wxWindow
)::StoreObject(s
);
490 void WXSERIAL(wxMDIClientWindow
)::LoadObject(wxObjectInputStream
& s
)
492 WXSERIAL(wxWindow
)::LoadObject(s
);
497 ((wxMDIClientWindow
*)Object())->CreateClient((wxMDIParentFrame
*)m_parent
, m_style
);