X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9fdd83842f5ead4ef45852b9943df36c38b4d7d7..94e2ed3b8db0220160c0b939782cd46914ec073a:/utils/serialize/serwnd.cpp diff --git a/utils/serialize/serwnd.cpp b/utils/serialize/serwnd.cpp index 52914a0d89..a7790942cc 100644 --- a/utils/serialize/serwnd.cpp +++ b/utils/serialize/serwnd.cpp @@ -3,9 +3,9 @@ // Purpose: Serialization: wxWindow classes // Author: Guilhem Lavaux // Modified by: -// Created: 11/07/98 +// Created: July 1998 // RCS-ID: $Id$ -// Copyright: (c) Guilhem Lavaux +// Copyright: (c) 1998 Guilhem Lavaux // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// @@ -20,29 +20,48 @@ #include #include #include +#include +#include +#include #include +#include +#include +#include "wx/log.h" #include "serwnd.h" + IMPLEMENT_SERIAL_CLASS(wxWindow, wxObject) IMPLEMENT_SERIAL_CLASS(wxIndividualLayoutConstraint, wxObject) IMPLEMENT_SERIAL_CLASS(wxLayoutConstraints, wxObject) +IMPLEMENT_ALIAS_SERIAL_CLASS(wxValidator, wxObject) IMPLEMENT_SERIAL_CLASS(wxFrame, wxWindow) -//IMPLEMENT_SERIAL_CLASS(wxDialog, wxWindow) +IMPLEMENT_SERIAL_CLASS(wxPanel, wxWindow) +IMPLEMENT_SERIAL_CLASS(wxDialog, wxWindow) IMPLEMENT_SERIAL_CLASS(wxMenuBar, wxWindow) IMPLEMENT_SERIAL_CLASS(wxMenuItem, wxObject) IMPLEMENT_SERIAL_CLASS(wxMenu, wxObject) -// IMPLEMENT_ALIAS_SERIAL_CLASS(wxPanel, wxWindow) +IMPLEMENT_SERIAL_CLASS(wxMDIParentFrame, wxFrame) +IMPLEMENT_SERIAL_CLASS(wxMDIChildFrame, wxFrame) +IMPLEMENT_SERIAL_CLASS(wxMDIClientWindow, wxWindow) + +///////////////////////////////////////////////////////////////////////////// void WXSERIAL(wxWindow)::StoreObject(wxObjectOutputStream& s) { wxWindow *win_object = (wxWindow *)Object(); - wxNode *node = win_object->GetChildren()->First(); if (s.FirstStage()) { + wxNode *node = win_object->GetChildren()->First(); + s.AddChild(win_object->GetConstraints()); -// s.AddChild(&(win_object->GetDefaultBackgroundColour())); -// s.AddChild(&(win_object->GetDefaultForegroundColour())); + s.AddChild(win_object->GetValidator()); + + // BAD HACK, but I don't have access to the internal variable of wxWindow. + m_bg_colour = win_object->GetBackgroundColour(); + m_fg_colour = win_object->GetForegroundColour(); + s.AddChild(&m_bg_colour); + s.AddChild(&m_fg_colour); s.AddChild(win_object->GetFont()); while (node) { s.AddChild(node->Data()); @@ -54,14 +73,16 @@ void WXSERIAL(wxWindow)::StoreObject(wxObjectOutputStream& s) wxDataOutputStream data(s); int x,y,w,h; - data.WriteString(win_object->GetName()); - data.WriteString(win_object->GetLabel()); - data.WriteString(win_object->GetTitle()); + data.WriteString( win_object->GetName() ); + data.WriteString( win_object->GetLabel() ); + data.WriteString( win_object->GetTitle() ); - data.Write8(win_object->GetAutoLayout()); - data.Write8(win_object->IsShown()); + data.Write8( win_object->GetAutoLayout() ); + data.Write8( win_object->IsShown() ); data.Write32( win_object->GetWindowStyleFlag() ); - data.Write32(win_object->GetId()); + data.Write32( win_object->GetId() ); + wxLogDebug( "Number = %d", win_object->GetChildren()->Number() ); + data.Write8( win_object->GetChildren()->Number() ); win_object->GetSize(&w, &h); win_object->GetPosition(&x, &y); @@ -75,6 +96,26 @@ void WXSERIAL(wxWindow)::LoadObject(wxObjectInputStream& s) { wxDataInputStream data_s(s); wxWindow *win_object = (wxWindow *)Object(); + wxColour *colour; + wxFont *font; + + if (s.SecondCall()) { + /* I assume we will never create raw wxWindow object */ + (void)s.GetChild(); // We pass wxLayoutConstraints. + (void)s.GetChild(); // We pass wxValidator. + + colour = (wxColour *)s.GetChild(); + if (colour) + win_object->SetBackgroundColour(*colour); + colour = (wxColour *)s.GetChild(); + if (colour) + win_object->SetForegroundColour(*colour); + font = (wxFont *)s.GetChild(); + if (font) + win_object->SetFont(*font); + s.RemoveChildren(m_number); + return; + } m_parent = (wxWindow *)s.GetParent(); @@ -86,23 +127,28 @@ void WXSERIAL(wxWindow)::LoadObject(wxObjectInputStream& s) m_shown = data_s.Read8(); m_style = data_s.Read32(); m_id = data_s.Read32(); + m_number = data_s.Read8(); m_x = data_s.Read16(); m_y = data_s.Read16(); m_w = data_s.Read16(); m_h = data_s.Read16(); - /* I assume we will never create raw wxWindow object */ + (void)s.GetChild(); // We pass wxLayoutConstraints. + + m_validator = (wxValidator *)s.GetChild(); + if (!m_validator) + m_validator = (wxValidator *)&wxDefaultValidator; + + s.RemoveChildren(m_number+3); - // This will be done by wxLayoutConstraints, as we need an initialized object. -// win_object->SetConstraints((wxLayoutConstraints *)s.GetChild(0)); -// win_object->SetDefaultBackgroundColour(*((wxColour *)s.GetChild(1))); -// win_object->SetDefaultForegroundColour(*((wxColour *)s.GetChild(2))); - win_object->SetFont(*((wxFont *)s.GetChild(1))); + s.Recall(); return; } +///////////////////////////////////////////////////////////////////////////// + void WXSERIAL(wxIndividualLayoutConstraint)::StoreObject (wxObjectOutputStream& s) { @@ -140,6 +186,8 @@ void WXSERIAL(wxIndividualLayoutConstraint):: lay_object->otherEdge = (wxEdge)data_s.Read8(); } +///////////////////////////////////////////////////////////////////////////// + void WXSERIAL(wxLayoutConstraints)::StoreObject(wxObjectOutputStream& s) { wxLayoutConstraints *lay_object = (wxLayoutConstraints *)Object(); @@ -187,6 +235,8 @@ void WXSERIAL(wxLayoutConstraints)::LoadObject(wxObjectInputStream& s) ((wxWindow *)s.GetParent())->SetConstraints(lay_object); } +///////////////////////////////////////////////////////////////////////////// + void WXSERIAL(wxFrame)::StoreObject(wxObjectOutputStream& s) { wxFrame *frame = (wxFrame *)Object(); @@ -201,6 +251,9 @@ void WXSERIAL(wxFrame)::StoreObject(wxObjectOutputStream& s) wxDataOutputStream data_s(s); wxStatusBar *statbar = frame->GetStatusBar(); + + // AAARGH !! I absolutely need to be able to modify internal fields of + // wxFrame (wxToolBar and wxStatusBar) if (statbar) data_s.Write8(statbar->GetFieldsCount()); @@ -213,20 +266,25 @@ void WXSERIAL(wxFrame)::StoreObject(wxObjectOutputStream& s) void WXSERIAL(wxFrame)::LoadObject(wxObjectInputStream& s) { wxFrame *frame = (wxFrame *)Object(); - wxMenuBar *mbar = (wxMenuBar *)s.GetChild(0); + wxMenuBar *mbar = (wxMenuBar *)s.GetChild(); - s.RemoveChildren(1); WXSERIAL(wxWindow)::LoadObject(s); + if (s.SecondCall()) + return; + wxDataInputStream data_s(s); + if (frame->GetClassInfo() == CLASSINFO(wxFrame)) + frame->Create(m_parent, m_id, m_title, wxPoint(m_x, m_y), + wxSize(m_w, m_h), m_style, m_name); frame->SetMenuBar(mbar); - frame->Create(m_parent, m_id, m_title, wxPoint(m_x, m_y), wxSize(m_w, m_h), - m_style, m_name); frame->CreateStatusBar(data_s.Read8()); } +///////////////////////////////////////////////////////////////////////////// + void WXSERIAL(wxMenuBar)::StoreObject(wxObjectOutputStream& s) { wxMenuBar *mbar = (wxMenuBar *)Object(); @@ -254,7 +312,7 @@ void WXSERIAL(wxMenuBar)::LoadObject(wxObjectInputStream& s) mcount = data_s.Read8(); for (i=0;iAppend( menu, menu->GetTitle() ); } @@ -262,6 +320,8 @@ void WXSERIAL(wxMenuBar)::LoadObject(wxObjectInputStream& s) // WXSERIAL(wxWindow)::LoadObject(s); } +///////////////////////////////////////////////////////////////////////////// + void WXSERIAL(wxMenu)::StoreObject(wxObjectOutputStream& s) { wxMenu *menu = (wxMenu *)Object(); @@ -278,12 +338,12 @@ void WXSERIAL(wxMenu)::StoreObject(wxObjectOutputStream& s) void WXSERIAL(wxMenu)::LoadObject(wxObjectInputStream& s) { wxMenu *menu = (wxMenu *)Object(); - wxList *items = (wxList *)s.GetChild(0); + wxList *items = (wxList *)s.GetChild(); wxNode *node = items->First(); wxDataInputStream data_s(s); -// menu->SetTitle( data_s.ReadString() ); + menu->SetTitle( data_s.ReadString() ); while (node) { // NOT IMPLEMENTED in wxGTK @@ -292,22 +352,28 @@ void WXSERIAL(wxMenu)::LoadObject(wxObjectInputStream& s) } } +///////////////////////////////////////////////////////////////////////////// + void WXSERIAL(wxMenuItem)::StoreObject(wxObjectOutputStream& s) { wxMenuItem *item = (wxMenuItem *)Object(); if (s.FirstStage()) { +#ifdef __WXGTK__ s.AddChild(item->GetSubMenu()); +#endif return; } wxDataOutputStream data_s(s); +#ifdef __WXGTK__ data_s.Write8( item->GetId() ); data_s.WriteString( item->GetText() ); data_s.Write8( item->IsCheckable() ); data_s.Write8( item->IsEnabled() ); data_s.Write8( item->IsChecked() ); +#endif } void WXSERIAL(wxMenuItem)::LoadObject(wxObjectInputStream& s) @@ -315,10 +381,118 @@ void WXSERIAL(wxMenuItem)::LoadObject(wxObjectInputStream& s) wxMenuItem *item = (wxMenuItem *)Object(); wxDataInputStream data_s(s); +#ifdef __WXGTK__ item->SetId( data_s.Read8() ); item->SetText( data_s.ReadString() ); item->SetCheckable( data_s.Read8() ); item->Enable( data_s.Read8() ); item->Check( data_s.Read8() ); - item->SetSubMenu( (wxMenu *)s.GetChild(0) ); + item->SetSubMenu( (wxMenu *)s.GetChild() ); +#endif +} + +///////////////////////////////////////////////////////////////////////////// + +void WXSERIAL(wxPanel)::StoreObject(wxObjectOutputStream& s) +{ + WXSERIAL(wxWindow)::StoreObject(s); +} + +void WXSERIAL(wxPanel)::LoadObject(wxObjectInputStream& s) +{ + WXSERIAL(wxWindow)::LoadObject(s); + + if (s.SecondCall()) + return; + + ((wxPanel *)Object())->Create(m_parent, m_id, wxPoint(m_x, m_y), + wxSize(m_w, m_h), m_style, m_name); +} + +///////////////////////////////////////////////////////////////////////////// + +void WXSERIAL(wxDialog)::StoreObject(wxObjectOutputStream& s) +{ + WXSERIAL(wxWindow)::StoreObject(s); +} + +void WXSERIAL(wxDialog)::LoadObject(wxObjectInputStream& s) +{ + WXSERIAL(wxWindow)::LoadObject(s); + + if (s.SecondCall()) + return; + + ((wxDialog *)Object())->Create(m_parent, m_id, m_title, wxPoint(m_x, m_y), + wxSize(m_w, m_h), m_style, m_name); +} + +///////////////////////////////////////////////////////////////////////////// + +void WXSERIAL(wxMDIParentFrame)::StoreObject(wxObjectOutputStream& s) +{ + wxMDIParentFrame *frame = (wxMDIParentFrame *)Object(); + + if (s.FirstStage()) { + s.AddChild(frame->GetClientWindow()); + WXSERIAL(wxMDIParentFrame)::StoreObject(s); + return; + } + + WXSERIAL(wxMDIParentFrame)::StoreObject(s); +} + +void WXSERIAL(wxMDIParentFrame)::LoadObject(wxObjectInputStream& s) +{ + wxMDIParentFrame *frame = (wxMDIParentFrame *)Object(); + wxMDIClientWindow *client; + + if (s.SecondCall()) { + WXSERIAL(wxFrame)::LoadObject(s); + return; + } + + client = (wxMDIClientWindow *) s.GetChild(); + + frame->Create(m_parent, m_id, m_title, wxPoint(m_x, m_y), + wxSize(m_w, m_h), m_style, m_name); + + WXSERIAL(wxFrame)::LoadObject(s); +} + +///////////////////////////////////////////////////////////////////////////// + +void WXSERIAL(wxMDIChildFrame)::StoreObject(wxObjectOutputStream& s) +{ + WXSERIAL(wxFrame)::StoreObject(s); +} + +void WXSERIAL(wxMDIChildFrame)::LoadObject(wxObjectInputStream& s) +{ + WXSERIAL(wxFrame)::LoadObject(s); + + if (s.SecondCall()) + return; + + ((wxMDIChildFrame *)Object())->Create((wxMDIParentFrame *)m_parent, + m_id, m_title, + wxPoint(m_x, m_y), wxSize(m_w, m_h), + m_style, m_name); +} + +///////////////////////////////////////////////////////////////////////////// + +void WXSERIAL(wxMDIClientWindow)::StoreObject(wxObjectOutputStream& s) +{ + WXSERIAL(wxWindow)::StoreObject(s); +} + +void WXSERIAL(wxMDIClientWindow)::LoadObject(wxObjectInputStream& s) +{ + WXSERIAL(wxWindow)::LoadObject(s); + + if (s.SecondCall()) + return; + + ((wxMDIClientWindow *)Object())->CreateClient((wxMDIParentFrame *)m_parent, m_style); }