X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8d43638db10823193952af62215f4c9e900f312a..f35719ef1d3b34fb42ebfab33944ea9cdc4413eb:/utils/serialize/sergdi.cpp diff --git a/utils/serialize/sergdi.cpp b/utils/serialize/sergdi.cpp index bedaddf300..e413a4627b 100644 --- a/utils/serialize/sergdi.cpp +++ b/utils/serialize/sergdi.cpp @@ -21,11 +21,17 @@ #include #include #include +#include +#include +#include +#include +#include #include "sergdi.h" IMPLEMENT_SERIAL_CLASS(wxBitmap, wxObject) IMPLEMENT_SERIAL_CLASS(wxGDIObject, wxObject) -IMPLEMENT_SERIAL_CLASS(wxColour, wxGDIObject) +IMPLEMENT_SERIAL_CLASS(wxRegion, wxGDIObject) +IMPLEMENT_SERIAL_CLASS(wxColour, wxObject) IMPLEMENT_SERIAL_CLASS(wxFont, wxGDIObject) IMPLEMENT_SERIAL_CLASS(wxPen, wxGDIObject) IMPLEMENT_SERIAL_CLASS(wxBrush, wxGDIObject) @@ -37,16 +43,70 @@ 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;ySetWidth(w); + bitmap->SetHeight(h); + dc.SelectObject(*bitmap); + + for (y=0;ySetVisible( data_s.Read8() ); } -void WXSERIAL(wxColour)::StoreObject(wxObjectOutputStream& s) +// ---------------------------------------------------------------------------- + +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) +{ if (s.FirstStage()) return; wxDataOutputStream data_s(s); wxColour *colour = (wxColour *)Object(); + if (!colour->Ok()) { + data_s.Write8(0); + data_s.Write8(0); + data_s.Write8(0); + wxLogDebug("wxColour (0x%x) isn't ready.\n", colour); + return; + } + data_s.Write8(colour->Red()); data_s.Write8(colour->Green()); data_s.Write8(colour->Blue()); @@ -82,8 +184,6 @@ void WXSERIAL(wxColour)::StoreObject(wxObjectOutputStream& s) void WXSERIAL(wxColour)::LoadObject(wxObjectInputStream& s) { - WXSERIAL(wxGDIObject)::LoadObject(s); - wxDataInputStream data_s(s); wxColour *colour = (wxColour *)Object(); int r, g, b; @@ -95,6 +195,8 @@ void WXSERIAL(wxColour)::LoadObject(wxObjectInputStream& s) colour->Set(r, g, b); } +// ---------------------------------------------------------------------------- + void WXSERIAL(wxPen)::StoreObject(wxObjectOutputStream& s) { wxPen *pen = (wxPen *)Object(); @@ -129,6 +231,7 @@ void WXSERIAL(wxPen)::LoadObject(wxObjectInputStream& s) pen->SetWidth( data_s.Read8() ); } +// ---------------------------------------------------------------------------- void WXSERIAL(wxBrush)::StoreObject(wxObjectOutputStream& s) { wxBrush *brush = (wxBrush *)Object(); @@ -159,6 +262,7 @@ void WXSERIAL(wxBrush)::LoadObject(wxObjectInputStream& s) *brush = wxBrush(bmap); } +// ---------------------------------------------------------------------------- void WXSERIAL(wxFont)::StoreObject(wxObjectOutputStream& s) { wxFont *font = (wxFont *)Object(); @@ -199,14 +303,18 @@ 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(); int i; if (s.FirstStage()) { +#ifdef __WXGTK__ for (i=0;iGetImageCount();i++) s.AddChild(list->GetBitmap(i)); +#endif } wxDataOutputStream data_s(s);