From 1d44aaf824396d1029bab018f4613e3952daa9ee Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Sun, 23 Aug 1998 09:23:27 +0000 Subject: [PATCH] * New function wxObjectInputStream::Recall() * 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 | 6 ++- install/unix/configure.in | 17 +++--- src/common/dynlib.cpp | 2 +- src/common/object.cpp | 9 +++- src/common/objstrm.cpp | 34 ++++++++++-- utils/serialize/serctrl.cpp | 22 +++++--- utils/serialize/serctrl.h | 13 ++++- utils/serialize/sergdi.cpp | 100 ++++++++++++++++++++++++++++++++++++ utils/serialize/sergdi.h | 5 +- utils/serialize/sermain.cpp | 11 ++++ utils/serialize/serwnd.cpp | 42 +++++++++++---- 11 files changed, 224 insertions(+), 37 deletions(-) diff --git a/include/wx/objstrm.h b/include/wx/objstrm.h index 9f419e38ec..699492671c 100644 --- a/include/wx/objstrm.h +++ b/include/wx/objstrm.h @@ -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; }; diff --git a/install/unix/configure.in b/install/unix/configure.in index 5fdad05b7a..e37e5d8941 100644 --- a/install/unix/configure.in +++ b/install/unix/configure.in @@ -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) diff --git a/src/common/dynlib.cpp b/src/common/dynlib.cpp index 906f7d83a3..db17f823d4 100644 --- a/src/common/dynlib.cpp +++ b/src/common/dynlib.cpp @@ -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); diff --git a/src/common/object.cpp b/src/common/object.cpp index 5087cf190b..b01cab1531 100644 --- a/src/common/object.cpp +++ b/src/common/object.cpp @@ -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; diff --git a/src/common/objstrm.cpp b/src/common/objstrm.cpp index 94200e50d8..824cd28fa6 100644 --- a/src/common/objstrm.cpp +++ b/src/common/objstrm.cpp @@ -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() diff --git a/utils/serialize/serctrl.cpp b/utils/serialize/serctrl.cpp index 982dbc5440..13e5451721 100644 --- a/utils/serialize/serctrl.cpp +++ b/utils/serialize/serctrl.cpp @@ -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;iGetPageText(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;iAddPage( (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;iSetPageText(i, data_s.ReadString() ); + m_pcount = data_s.Read8(); + for (i=0;i #include #include +#include +#include +#include +#include #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;yResize(w, h); + dc.SelectObject(*bitmap); + + for (y=0;ySetVisible( 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(); diff --git a/utils/serialize/sergdi.h b/utils/serialize/sergdi.h index bb746d3a69..941586e077 100644 --- a/utils/serialize/sergdi.h +++ b/utils/serialize/sergdi.h @@ -21,16 +21,13 @@ 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) diff --git a/utils/serialize/sermain.cpp b/utils/serialize/sermain.cpp index 4ef76703dd..e0c63aa0b4 100644 --- a/utils/serialize/sermain.cpp +++ b/utils/serialize/sermain.cpp @@ -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; } diff --git a/utils/serialize/serwnd.cpp b/utils/serialize/serwnd.cpp index 1efa161336..a52ef3f893 100644 --- a/utils/serialize/serwnd.cpp +++ b/utils/serialize/serwnd.cpp @@ -26,6 +26,7 @@ #include #include #include +#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; }