]> git.saurik.com Git - wxWidgets.git/commitdiff
* New function wxObjectInputStream::Recall()
authorGuilhem Lavaux <lavaux@easynet.fr>
Sun, 23 Aug 1998 09:23:27 +0000 (09:23 +0000)
committerGuilhem Lavaux <lavaux@easynet.fr>
Sun, 23 Aug 1998 09:23:27 +0000 (09:23 +0000)
* Fixes in object serializer,dynlib,LoadObject/StoreObject
* Updates for serialization.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@625 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/objstrm.h
install/unix/configure.in
src/common/dynlib.cpp
src/common/object.cpp
src/common/objstrm.cpp
utils/serialize/serctrl.cpp
utils/serialize/serctrl.h
utils/serialize/sergdi.cpp
utils/serialize/sergdi.h
utils/serialize/sermain.cpp
utils/serialize/serwnd.cpp

index 9f419e38eca586899ea1771b0ca1a516284a98d3..699492671c183c6cb8369737e1b73ad322ad4feb 100644 (file)
@@ -27,7 +27,7 @@ class wxObjectStreamInfo : public wxObject {
   wxList children;
   wxObjectStreamInfo *parent;
   wxObject *object;
-  bool duplicate;
+  bool duplicate, recall;
 };
 
 class wxObjectOutputStream : public wxFilterOutputStream {
@@ -57,6 +57,9 @@ class wxObjectInputStream : public wxFilterInputStream {
  public:
   wxObjectInputStream(wxInputStream& s);
 
+  bool SecondCall() const { return m_secondcall; }
+  void Recall(bool on = TRUE) { m_current_info->recall = on; }
+
   wxObject *GetChild(int no) const;
   wxObject *GetChild();
   int NumberOfChildren() const { return m_current_info->n_children; }
@@ -72,6 +75,7 @@ class wxObjectInputStream : public wxFilterInputStream {
   void ProcessObjectData(wxObjectStreamInfo *info);
 
  protected:
+  bool m_secondcall;
   wxObjectStreamInfo *m_current_info;
   wxList m_solver;
 };
index 5fdad05b7a6c00901d7d4185c8fdbf1b8a1e748f..e37e5d894122c5892e2427f2e096a6fc3a435a37 100644 (file)
@@ -1286,27 +1286,32 @@ if test "$USE_THREADS" = "1"; then
   AC_CHECK_LIB(pthread-0.7, pthread_create, [
      UNIX_THREAD="gtk/threadpsx.cpp"
      THREADS_LINK="-lpthread-0.7"
-     AC_DEFINE(USE_THREADS)
   ],[
     AC_CHECK_HEADER(sys/prctl.h, [
         UNIX_THREAD="gtk/threadsgi.cpp"
-        AC_DEFINE(USE_THREADS)
     ])
-    AC_CHECK_LIB(pthread, pthread_create, [
+
+    dnl pthread_create is always available in pthread but it seems not to be
+    dnl the case for pthread_setcanceltype.
+
+    AC_CHECK_LIB(pthread, pthread_setcanceltype, [
        UNIX_THREAD="gtk/threadpsx.cpp"
        THREADS_LINK="-lpthread"
-       AC_DEFINE(USE_THREADS)
     ])
   ])
-  AC_CHECK_LIB(pthreads, pthread_create, [
+  AC_CHECK_LIB(pthreads, pthread_setcanceltype, [
      UNIX_THREAD="gtk/threadpsx.cpp"
      THREADS_LINK="-lpthreads"
-     AC_DEFINE(USE_THREADS)
   ])
 fi
 
+if test -z "$UNIX_THREAD"; then
+  USE_THREADS=0
+fi
+
 AC_SUBST(UNIX_THREAD)
 AC_SUBST(THREADS_LINK)
+AC_DEFINE(USE_THREADS)
 
 dnl   defines UNIX_THREAD it contains the source file to use for threads. (GL)
 dnl   defines THREADS_LINK it contains the thread library to link with. (GL)
index 906f7d83a35518df85c908a21d618bd042faed69..db17f823d469a2e09f154ea9960dea2f3c6957b7 100644 (file)
@@ -118,7 +118,7 @@ wxLibrary *wxLibraries::LoadLibrary(const wxString& name)
     return ((wxLibrary *)node->Data());
 
 #ifdef __UNIX__
-  lib_name.Prepend("lib");
+  lib_name.Prepend("./lib");
   lib_name += ".so";
 
   printf("lib_name = %s\n", WXSTRINGCAST lib_name);
index 5087cf190bbc174a1de9db3392daf009f374ed9d..b01cab153129266bc250274fe1f401b6957e7e11 100644 (file)
@@ -235,8 +235,13 @@ void wxObject::StoreObject( wxObjectOutputStream& stream )
 {
   wxString obj_name = wxString(GetClassInfo()->GetClassName()) + "_Serialize";
   wxLibrary *lib = wxTheLibraries.LoadLibrary("wxserial");
-  WXSERIAL(wxObject) *serial =
-                           (WXSERIAL(wxObject) *)lib->CreateObject( obj_name );
+  WXSERIAL(wxObject) *serial;
+
+  if (!lib) {
+    wxMessageBox("Can't load wxSerial dynamic library.", "Alert !");
+    return;
+  }
+  serial = (WXSERIAL(wxObject) *)lib->CreateObject( obj_name );
 
   if (!serial) {
     wxString message;
index 94200e50d8789feccdeeeceeb80b0574cce96f9e..824cd28fa666acbfbb802ab8b34e720221a0cf1a 100644 (file)
@@ -56,6 +56,7 @@ void wxObjectOutputStream::WriteObjectDef(wxObjectStreamInfo& info)
     data_s.WriteString(info.object->GetClassInfo()->GetClassName());
   } else {
     data_s.WriteString(TAG_EMPTY_OBJECT);
+    return;
   }
 
   data_s.WriteString(GetObjectName(info.object));
@@ -80,6 +81,9 @@ void wxObjectOutputStream::AddChild(wxObject *obj)
     info->duplicate = FALSE;
     m_saved_objs.Append(obj);
   }
+  if (!obj)
+    info->duplicate = FALSE;
+
   info->n_children = 0;
   info->object = obj;
   info->parent = m_current_info; // Not useful here.
@@ -135,6 +139,7 @@ bool wxObjectOutputStream::SaveObject(wxObject& obj)
   m_stage = 0;
   info.object = &obj;
   info.n_children = 0;
+  info.duplicate = FALSE;
   ProcessObjectDef(&info);
 
   m_stage = 1;
@@ -180,11 +185,25 @@ wxObject *wxObjectInputStream::GetParent() const
   return m_current_info->parent->object;
 }
 
+wxObject *wxObjectInputStream::GetChild()
+{
+  wxObject *obj = GetChild(0);
+
+  m_current_info->children_removed++;
+
+  return obj;
+}
+
 wxObject *wxObjectInputStream::GetChild(int no) const
 {
-  wxNode *node = m_current_info->children.Nth(m_current_info->children_removed+no);
+  wxNode *node;
   wxObjectStreamInfo *info;
 
+  if (m_current_info->children_removed >= m_current_info->n_children)
+    return NULL;
+
+  node = m_current_info->children.Nth(m_current_info->children_removed+no);
+
   if (!node)
     return (wxObject *) NULL;
 
@@ -210,17 +229,18 @@ bool wxObjectInputStream::ReadObjectDef(wxObjectStreamInfo *info)
     return FALSE;
 
   class_name = data_s.ReadString();
-  info->object_name = data_s.ReadString();
   info->children_removed = 0;
 
   if (class_name == TAG_EMPTY_OBJECT)
     info->object = (wxObject *) NULL;
   else if (class_name == TAG_DUPLICATE_OBJECT) {
+    info->object_name = data_s.ReadString();
     info->object = SolveName(info->object_name);
     info->n_children = 0;
   } else {
+    info->object_name = data_s.ReadString();
     info->object = wxCreateDynamicObject( WXSTRINGCAST class_name);
-    info->n_children = data_s.Read8();
+    info->n_children = data_s.Read32();
   }
   return TRUE;
 }
@@ -261,6 +281,14 @@ void wxObjectInputStream::ProcessObjectData(wxObjectStreamInfo *info)
     ProcessObjectData((wxObjectStreamInfo *)node->Data());
     node = node->Next();
   }
+
+  m_current_info = info;
+
+  if (info->recall) {
+    m_secondcall = TRUE;
+    info->object->LoadObject(*this);
+    m_secondcall = FALSE;
+  }
 }
 
 wxObject *wxObjectInputStream::LoadObject()
index 982dbc5440285e2d5cb9036785379adc3f92eccd..13e54517215e922b721b85f4ba313b9df68adcb0 100644 (file)
@@ -46,6 +46,7 @@ IMPLEMENT_SERIAL_CLASS(wxRadioBox, wxControl)
 IMPLEMENT_SERIAL_CLASS(wxRadioButton, wxControl)
 IMPLEMENT_SERIAL_CLASS(wxButton, wxControl)
 IMPLEMENT_SERIAL_CLASS(wxStaticText, wxControl)
+IMPLEMENT_SERIAL_CLASS(wxStaticBox, wxControl)
 
 //-----------------------------------------------------------------------------
 
@@ -244,40 +245,45 @@ void WXSERIAL(wxNotebook)::StoreObject(wxObjectOutputStream& s)
   wxImageList *imaglist = notebook->GetImageList();
   int i, pcount = notebook->GetPageCount();
 
+  WXSERIAL(wxControl)::StoreObject(s);
   if (s.FirstStage()) {
     s.AddChild(imaglist);
-    WXSERIAL(wxControl)::StoreObject(s);
     return;
   }
 
   wxDataOutputStream data_s(s);
 
   data_s.Write8( pcount );
-  WXSERIAL(wxControl)::StoreObject(s);
 
   for (i=0;i<pcount;i++)
     data_s.WriteString( notebook->GetPageText(i) );
-
 }
 
 void WXSERIAL(wxNotebook)::LoadObject(wxObjectInputStream& s)
 {
   wxNotebook *notebook = (wxNotebook *)Object();
-  int i, pcount;
+  int i;
   wxImageList *imaglist;
 
-  imaglist = (wxImageList *)s.GetChild();
+  if (s.SecondCall()) {
+    for (i=0;i<m_pcount;i++)
+      notebook->AddPage( (wxWindow *)s.GetChild(), m_stringlist[i] );
+    return;
+  }
 
   WXSERIAL(wxControl)::LoadObject(s);
 
+  imaglist = (wxImageList *)s.GetChild();
+
   notebook->Create(m_parent, m_id, wxPoint(m_x, m_y), wxSize(m_w, m_h),
                    m_style, m_name);
 
   wxDataInputStream data_s(s);
 
-  pcount = data_s.Read8();
-  for (i=0;i<pcount;i++)
-    notebook->SetPageText(i, data_s.ReadString() );
+  m_pcount = data_s.Read8();
+  for (i=0;i<m_pcount;i++)
+    m_stringlist.Add(data_s.ReadString());
+  s.Recall();
 }
 
 //-----------------------------------------------------------------------------
index a3b3ffc2798d2d4358c1fdec802ac3d3bf219732..a93a1b3c1aca3bbd04ef4ed7357bf196c4a5b75f 100644 (file)
@@ -27,10 +27,21 @@ DECLARE_SERIAL_CLASS(wxChoice, wxControl)
 DECLARE_SERIAL_CLASS(wxComboBox, wxControl)
 DECLARE_SERIAL_CLASS(wxGauge, wxControl)
 DECLARE_SERIAL_CLASS(wxListBox, wxControl)
-DECLARE_SERIAL_CLASS(wxNotebook, wxControl)
 DECLARE_SERIAL_CLASS(wxRadioBox, wxControl)
 DECLARE_SERIAL_CLASS(wxRadioButton, wxControl)
 DECLARE_SERIAL_CLASS(wxStaticText, wxControl)
 DECLARE_SERIAL_CLASS(wxStaticBox, wxControl)
 
+
+class WXSERIAL(wxNotebook) : public WXSERIAL(wxControl) {
+  DECLARE_DYNAMIC_CLASS( wxNotebook_Serialize )
+public:
+  void StoreObject(wxObjectOutputStream& s);
+  void LoadObject(wxObjectInputStream& s);
+
+protected:
+  int m_pcount;
+  wxArrayString m_stringlist;
+};
+
 #endif
index bedaddf300492f9765443a74c80d2fee541edf9f..8ab44d782c7df4a1943fd4af607b61a32a526d57 100644 (file)
 #include <wx/brush.h>
 #include <wx/serbase.h>
 #include <wx/imaglist.h>
+#include <wx/region.h>
+#include <wx/colour.h>
+#include <wx/palette.h>
+#include <wx/dcmemory.h>
 #include "sergdi.h"
 
 IMPLEMENT_SERIAL_CLASS(wxBitmap, wxObject)
 IMPLEMENT_SERIAL_CLASS(wxGDIObject, wxObject)
+IMPLEMENT_SERIAL_CLASS(wxRegion, wxGDIObject)
 IMPLEMENT_SERIAL_CLASS(wxColour, wxGDIObject)
 IMPLEMENT_SERIAL_CLASS(wxFont, wxGDIObject)
 IMPLEMENT_SERIAL_CLASS(wxPen, wxGDIObject)
@@ -37,16 +42,69 @@ IMPLEMENT_ALIAS_SERIAL_CLASS(wxFontList, wxList)
 IMPLEMENT_ALIAS_SERIAL_CLASS(wxColourDatabase, wxList)
 IMPLEMENT_ALIAS_SERIAL_CLASS(wxBitmapList, wxList)
 
+// ----------------------------------------------------------------------------
+
 void WXSERIAL(wxBitmap)::StoreObject(wxObjectOutputStream& s)
 {
   // TODO
+  // I implemented a basic image saving (maybe I'll need to improve wxWin API).
+
+  int x, y, w, h;
+  wxDataOutputStream data_s(s);
+  wxBitmap *bitmap = (wxBitmap *)Object();
+  wxColour col;
+  wxMemoryDC dc;
+
+  w = bitmap->GetWidth();
+  h = bitmap->GetHeight();
+
+  if (s.FirstStage()) {
+    s.AddChild(bitmap->GetMask());
+  }
+
+  dc.SelectObject(*bitmap);
+
+  data_s.Write16(w);
+  data_s.Write16(h);
+  for (y=0;y<h;y++)
+    for (x=0;x<w;x++) {
+      dc.GetPixel(x, y, &col);
+      data_s.Write8( col.Red() );
+      data_s.Write8( col.Green() );
+      data_s.Write8( col.Blue() );
+    }
 }
 
 void WXSERIAL(wxBitmap)::LoadObject(wxObjectInputStream& s)
 {
   // TODO
+  // I implemented a basic image loading (maybe I'll need to improve wxWin API).
+  wxDataInputStream data_s(s);
+  wxBitmap *bitmap = (wxBitmap *)Object();
+  wxMemoryDC dc;
+  wxPen pen;
+  int x, y, w, h;
+  int r, g, b;
+
+  w = data_s.Read16();
+  h = data_s.Read16();
+
+  bitmap->Resize(w, h);
+  dc.SelectObject(*bitmap);
+
+  for (y=0;y<h;y++)
+    for (x=0;x<w;x++) {
+      r = data_s.Read8();
+      g = data_s.Read8();
+      b = data_s.Read8();
+      pen.SetColour(r, g, b);
+      dc.SetPen(pen);
+      dc.DrawPoint(x,y); 
+    }
 }
 
+// ----------------------------------------------------------------------------
+
 void WXSERIAL(wxGDIObject)::StoreObject(wxObjectOutputStream& s)
 {
   if (s.FirstStage())
@@ -65,6 +123,42 @@ void WXSERIAL(wxGDIObject)::LoadObject(wxObjectInputStream& s)
   ((wxGDIObject *)Object())->SetVisible( data_s.Read8() );
 }
 
+// ----------------------------------------------------------------------------
+
+void WXSERIAL(wxRegion)::StoreObject(wxObjectOutputStream& s)
+{
+  WXSERIAL(wxGDIObject)::StoreObject(s);
+
+  if (s.FirstStage())
+    return;
+
+  wxDataOutputStream data_s(s);
+  wxRect rect = ((wxRegion *)Object())->GetBox();
+
+  data_s.Write16( rect.GetX() ); 
+  data_s.Write16( rect.GetY() ); 
+  data_s.Write16( rect.GetWidth() ); 
+  data_s.Write16( rect.GetHeight() ); 
+}
+
+void WXSERIAL(wxRegion)::LoadObject(wxObjectInputStream& s)
+{
+  WXSERIAL(wxGDIObject)::LoadObject(s);
+
+  wxDataInputStream data_s(s);
+  wxRegion *region = (wxRegion *)Object();
+  wxRect rect;
+
+  rect.SetX( data_s.Read16() );
+  rect.SetY( data_s.Read16() );
+  rect.SetWidth( data_s.Read16() );
+  rect.SetHeight( data_s.Read16() );
+
+  *region = wxRegion(rect);
+}
+
+// ----------------------------------------------------------------------------
+
 void WXSERIAL(wxColour)::StoreObject(wxObjectOutputStream& s)
 {
   WXSERIAL(wxGDIObject)::StoreObject(s);
@@ -95,6 +189,8 @@ void WXSERIAL(wxColour)::LoadObject(wxObjectInputStream& s)
   colour->Set(r, g, b);
 }
 
+// ----------------------------------------------------------------------------
+
 void WXSERIAL(wxPen)::StoreObject(wxObjectOutputStream& s)
 {
   wxPen *pen = (wxPen *)Object();
@@ -129,6 +225,7 @@ void WXSERIAL(wxPen)::LoadObject(wxObjectInputStream& s)
   pen->SetWidth( data_s.Read8() );
 }
 
+// ----------------------------------------------------------------------------
 void WXSERIAL(wxBrush)::StoreObject(wxObjectOutputStream& s)
 {
   wxBrush *brush = (wxBrush *)Object();
@@ -159,6 +256,7 @@ void WXSERIAL(wxBrush)::LoadObject(wxObjectInputStream& s)
     *brush = wxBrush(bmap);
 }
 
+// ----------------------------------------------------------------------------
 void WXSERIAL(wxFont)::StoreObject(wxObjectOutputStream& s)
 {
   wxFont *font = (wxFont *)Object();
@@ -199,6 +297,8 @@ void WXSERIAL(wxFont)::LoadObject(wxObjectInputStream& s)
   *font = wxFont(psize, face_name, family, style, weight, underlined);
 }
 
+// ----------------------------------------------------------------------------
+
 void WXSERIAL(wxImageList)::StoreObject(wxObjectOutputStream& s)
 {
   wxImageList *list = (wxImageList *)Object();
index bb746d3a6928bc80c263132d5a8c324a40ad0e9c..941586e077e2f1c9188a3fc970efecb8f099734e 100644 (file)
 
 DECLARE_SERIAL_CLASS(wxBitmap, wxObject)
 DECLARE_SERIAL_CLASS(wxGDIObject, wxObject)
+DECLARE_SERIAL_CLASS(wxRegion, wxGDIObject)
 DECLARE_SERIAL_CLASS(wxColour, wxGDIObject)
 DECLARE_SERIAL_CLASS(wxFont, wxGDIObject)
 DECLARE_SERIAL_CLASS(wxPen, wxGDIObject)
 DECLARE_SERIAL_CLASS(wxBrush, wxGDIObject)
 DECLARE_SERIAL_CLASS(wxImageList, wxObject)
 
-//DECLARE_SERIAL_CLASS(wxSize, wxObject)
-//DECLARE_SERIAL_CLASS(wxRealPoint, wxObject)
-//DECLARE_SERIAL_CLASS(wxRect, wxObject)
-
 DECLARE_ALIAS_SERIAL_CLASS(wxPenList, wxList)
 DECLARE_ALIAS_SERIAL_CLASS(wxBrushList, wxList)
 DECLARE_ALIAS_SERIAL_CLASS(wxFontList, wxList)
index 4ef76703dd253b9314afeb3ce79a9c86dadb6a06..e0c63aa0b4e59c372cae4a198061c62e14281feb 100644 (file)
@@ -20,6 +20,7 @@
 #include "serwnd.h"
 #include "sergdi.h"
 #include "serctrl.h"
+#include "serext.h"
 
 IMPLEMENT_DYNAMIC_CLASS(wxObject_Serialize, wxObject)
 
@@ -41,9 +42,13 @@ WXDLL_ENTRY_FUNCTION()
   REGISTER_CLASS(wxMenu);
   REGISTER_CLASS(wxMenuItem);
   REGISTER_CLASS(wxMenuBar);
+  REGISTER_CLASS(wxMDIParentFrame);
+  REGISTER_CLASS(wxMDIChildFrame);
+  REGISTER_CLASS(wxMDIClientWindow);
 
   REGISTER_CLASS(wxGDIObject);
   REGISTER_CLASS(wxBitmap);
+  REGISTER_CLASS(wxRegion);
   REGISTER_CLASS(wxColour);
   REGISTER_CLASS(wxFont);
   REGISTER_CLASS(wxPen);
@@ -54,6 +59,7 @@ WXDLL_ENTRY_FUNCTION()
   REGISTER_CLASS(wxFontList);
   REGISTER_CLASS(wxColourDatabase);
   REGISTER_CLASS(wxBitmapList);
+  REGISTER_CLASS(wxImageList);
 
   REGISTER_CLASS(wxControl);
   REGISTER_CLASS(wxSlider);
@@ -63,10 +69,15 @@ WXDLL_ENTRY_FUNCTION()
   REGISTER_CLASS(wxListBox);
   REGISTER_CLASS(wxButton);
   REGISTER_CLASS(wxStaticText);
+  REGISTER_CLASS(wxStaticBox);
   REGISTER_CLASS(wxRadioBox);
   REGISTER_CLASS(wxComboBox);
   REGISTER_CLASS(wxNotebook);
 
+  REGISTER_CLASS(wxSplitterWindow);
+  REGISTER_CLASS(wxGrid);
+  REGISTER_CLASS(wxGridCell);
+
   return lib;
 }
 
index 1efa161336765ba31d937aa659ae2cf48889361a..a52ef3f893fd601768419f848f40f50fba9333a5 100644 (file)
@@ -26,6 +26,7 @@
 #include <wx/serbase.h>
 #include <wx/statusbr.h>
 #include <wx/mdi.h>
+#include "wx/log.h"
 #include "serwnd.h"
 
 
@@ -49,9 +50,10 @@ 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->GetValidator());
 
@@ -71,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);
@@ -92,6 +96,9 @@ void WXSERIAL(wxWindow)::LoadObject(wxObjectInputStream& s)
 {
   wxDataInputStream data_s(s);
   wxWindow *win_object = (wxWindow *)Object();
+  wxColour *colour;
+  wxFont *font;
+  int number;
 
   m_parent = (wxWindow *)s.GetParent();
 
@@ -103,6 +110,7 @@ void WXSERIAL(wxWindow)::LoadObject(wxObjectInputStream& s)
   m_shown       = data_s.Read8();
   m_style       = data_s.Read32();
   m_id          = data_s.Read32();
+  number        = data_s.Read8();
 
   m_x = data_s.Read16();
   m_y = data_s.Read16();
@@ -110,11 +118,23 @@ void WXSERIAL(wxWindow)::LoadObject(wxObjectInputStream& s)
   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();
-  win_object->SetDefaultBackgroundColour(*((wxColour *)s.GetChild()));
-  win_object->SetDefaultForegroundColour(*((wxColour *)s.GetChild()));
-  win_object->SetFont(*((wxFont *)s.GetChild()));
+  if (!m_validator)
+    m_validator = (wxValidator *)&wxDefaultValidator;
+
+  colour = (wxColour *)s.GetChild();
+  if (colour)
+    win_object->SetDefaultBackgroundColour(*colour);
+  colour = (wxColour *)s.GetChild();
+  if (colour)
+    win_object->SetDefaultForegroundColour(*colour);
+  font = (wxFont *)s.GetChild();
+  if (font)
+    win_object->SetFont(*font);
+
+  s.RemoveChildren(number);
 
   return;
 }