1998-08-05 13:12:43 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: sergdi.cpp
|
|
|
|
// Purpose: Serialization: GDI classes
|
|
|
|
// Author: Guilhem Lavaux
|
|
|
|
// Modified by:
|
|
|
|
// Created: July 1998
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1998 Guilhem Lavaux
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-08-04 13:45:20 -04:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation "sergdi.h"
|
|
|
|
#endif
|
|
|
|
#include <wx/objstrm.h>
|
|
|
|
#include <wx/datstrm.h>
|
|
|
|
#include <wx/gdicmn.h>
|
|
|
|
#include <wx/bitmap.h>
|
|
|
|
#include <wx/font.h>
|
|
|
|
#include <wx/pen.h>
|
|
|
|
#include <wx/brush.h>
|
|
|
|
#include <wx/serbase.h>
|
1998-08-18 13:22:15 -04:00
|
|
|
#include <wx/imaglist.h>
|
1998-08-23 05:23:27 -04:00
|
|
|
#include <wx/region.h>
|
|
|
|
#include <wx/colour.h>
|
|
|
|
#include <wx/palette.h>
|
|
|
|
#include <wx/dcmemory.h>
|
1998-09-17 13:30:13 -04:00
|
|
|
#include <wx/log.h>
|
1998-08-04 13:45:20 -04:00
|
|
|
#include "sergdi.h"
|
|
|
|
|
|
|
|
IMPLEMENT_SERIAL_CLASS(wxBitmap, wxObject)
|
|
|
|
IMPLEMENT_SERIAL_CLASS(wxGDIObject, wxObject)
|
1998-08-23 05:23:27 -04:00
|
|
|
IMPLEMENT_SERIAL_CLASS(wxRegion, wxGDIObject)
|
1998-09-17 13:30:13 -04:00
|
|
|
IMPLEMENT_SERIAL_CLASS(wxColour, wxObject)
|
1998-08-04 13:45:20 -04:00
|
|
|
IMPLEMENT_SERIAL_CLASS(wxFont, wxGDIObject)
|
|
|
|
IMPLEMENT_SERIAL_CLASS(wxPen, wxGDIObject)
|
|
|
|
IMPLEMENT_SERIAL_CLASS(wxBrush, wxGDIObject)
|
1998-08-18 13:22:15 -04:00
|
|
|
IMPLEMENT_SERIAL_CLASS(wxImageList, wxObject)
|
1998-08-04 13:45:20 -04:00
|
|
|
|
|
|
|
IMPLEMENT_ALIAS_SERIAL_CLASS(wxPenList, wxList)
|
|
|
|
IMPLEMENT_ALIAS_SERIAL_CLASS(wxBrushList, wxList)
|
|
|
|
IMPLEMENT_ALIAS_SERIAL_CLASS(wxFontList, wxList)
|
|
|
|
IMPLEMENT_ALIAS_SERIAL_CLASS(wxColourDatabase, wxList)
|
|
|
|
IMPLEMENT_ALIAS_SERIAL_CLASS(wxBitmapList, wxList)
|
|
|
|
|
1998-08-23 05:23:27 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1998-08-04 13:45:20 -04:00
|
|
|
void WXSERIAL(wxBitmap)::StoreObject(wxObjectOutputStream& s)
|
|
|
|
{
|
|
|
|
// TODO
|
1998-08-23 05:23:27 -04:00
|
|
|
// 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() );
|
|
|
|
}
|
1998-08-04 13:45:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void WXSERIAL(wxBitmap)::LoadObject(wxObjectInputStream& s)
|
|
|
|
{
|
|
|
|
// TODO
|
1998-08-23 05:23:27 -04:00
|
|
|
// 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();
|
|
|
|
|
1998-11-11 13:06:28 -05:00
|
|
|
bitmap->SetWidth(w);
|
|
|
|
bitmap->SetHeight(h);
|
1998-08-23 05:23:27 -04:00
|
|
|
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);
|
|
|
|
}
|
1998-08-04 13:45:20 -04:00
|
|
|
}
|
|
|
|
|
1998-08-23 05:23:27 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1998-08-04 13:45:20 -04:00
|
|
|
void WXSERIAL(wxGDIObject)::StoreObject(wxObjectOutputStream& s)
|
|
|
|
{
|
|
|
|
if (s.FirstStage())
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool visible = ((wxGDIObject *)Object())->GetVisible();
|
|
|
|
|
|
|
|
wxDataOutputStream data_s(s);
|
|
|
|
data_s.Write8(visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WXSERIAL(wxGDIObject)::LoadObject(wxObjectInputStream& s)
|
|
|
|
{
|
|
|
|
wxDataInputStream data_s(s);
|
|
|
|
|
|
|
|
((wxGDIObject *)Object())->SetVisible( data_s.Read8() );
|
|
|
|
}
|
|
|
|
|
1998-08-23 05:23:27 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1998-08-04 13:45:20 -04:00
|
|
|
void WXSERIAL(wxColour)::StoreObject(wxObjectOutputStream& s)
|
|
|
|
{
|
|
|
|
if (s.FirstStage())
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxDataOutputStream data_s(s);
|
|
|
|
wxColour *colour = (wxColour *)Object();
|
|
|
|
|
1998-09-17 13:30:13 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1998-08-04 13:45:20 -04:00
|
|
|
data_s.Write8(colour->Red());
|
|
|
|
data_s.Write8(colour->Green());
|
|
|
|
data_s.Write8(colour->Blue());
|
|
|
|
}
|
|
|
|
|
|
|
|
void WXSERIAL(wxColour)::LoadObject(wxObjectInputStream& s)
|
|
|
|
{
|
|
|
|
wxDataInputStream data_s(s);
|
|
|
|
wxColour *colour = (wxColour *)Object();
|
|
|
|
int r, g, b;
|
|
|
|
|
|
|
|
r = data_s.Read8();
|
|
|
|
g = data_s.Read8();
|
|
|
|
b = data_s.Read8();
|
|
|
|
|
|
|
|
colour->Set(r, g, b);
|
|
|
|
}
|
|
|
|
|
1998-08-23 05:23:27 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1998-08-04 13:45:20 -04:00
|
|
|
void WXSERIAL(wxPen)::StoreObject(wxObjectOutputStream& s)
|
|
|
|
{
|
|
|
|
wxPen *pen = (wxPen *)Object();
|
|
|
|
WXSERIAL(wxGDIObject)::StoreObject(s);
|
|
|
|
|
|
|
|
if (s.FirstStage()) {
|
|
|
|
s.AddChild(& (pen->GetColour()) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxDataOutputStream data_s(s);
|
|
|
|
|
|
|
|
data_s.Write8( pen->GetCap() );
|
|
|
|
data_s.Write8( pen->GetJoin() );
|
|
|
|
data_s.Write8( pen->GetStyle() );
|
|
|
|
data_s.Write8( pen->GetWidth() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void WXSERIAL(wxPen)::LoadObject(wxObjectInputStream& s)
|
|
|
|
{
|
|
|
|
wxPen *pen = (wxPen *)Object();
|
1998-08-19 14:33:19 -04:00
|
|
|
wxColour *col = (wxColour *) s.GetChild();
|
1998-08-04 13:45:20 -04:00
|
|
|
|
|
|
|
WXSERIAL(wxGDIObject)::LoadObject(s);
|
|
|
|
|
|
|
|
wxDataInputStream data_s(s);
|
|
|
|
|
|
|
|
pen->SetColour(*col);
|
|
|
|
pen->SetCap( data_s.Read8() );
|
|
|
|
pen->SetJoin( data_s.Read8() );
|
|
|
|
pen->SetStyle( data_s.Read8() );
|
|
|
|
pen->SetWidth( data_s.Read8() );
|
|
|
|
}
|
|
|
|
|
1998-08-23 05:23:27 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-08-04 13:45:20 -04:00
|
|
|
void WXSERIAL(wxBrush)::StoreObject(wxObjectOutputStream& s)
|
|
|
|
{
|
|
|
|
wxBrush *brush = (wxBrush *)Object();
|
|
|
|
WXSERIAL(wxGDIObject)::StoreObject(s);
|
|
|
|
|
|
|
|
if (s.FirstStage()) {
|
|
|
|
s.AddChild( &(brush->GetColour()) );
|
|
|
|
s.AddChild( brush->GetStipple() );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxDataOutputStream data_s(s);
|
|
|
|
data_s.Write8( brush->GetStyle() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void WXSERIAL(wxBrush)::LoadObject(wxObjectInputStream& s)
|
|
|
|
{
|
|
|
|
wxBrush *brush = (wxBrush *)Object();
|
1998-08-19 14:33:19 -04:00
|
|
|
wxColour *col = (wxColour *)s.GetChild();
|
|
|
|
wxBitmap *bmap = (wxBitmap *)s.GetChild();
|
1998-08-04 13:45:20 -04:00
|
|
|
|
|
|
|
WXSERIAL(wxGDIObject)::LoadObject(s);
|
|
|
|
|
|
|
|
wxDataInputStream data_s(s);
|
|
|
|
if (bmap)
|
|
|
|
*brush = wxBrush(*col, data_s.Read8());
|
|
|
|
else
|
|
|
|
*brush = wxBrush(bmap);
|
|
|
|
}
|
|
|
|
|
1998-08-23 05:23:27 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-08-04 13:45:20 -04:00
|
|
|
void WXSERIAL(wxFont)::StoreObject(wxObjectOutputStream& s)
|
|
|
|
{
|
|
|
|
wxFont *font = (wxFont *)Object();
|
|
|
|
|
|
|
|
WXSERIAL(wxGDIObject)::StoreObject(s);
|
|
|
|
|
|
|
|
if (s.FirstStage())
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxDataOutputStream data_s(s);
|
|
|
|
|
|
|
|
data_s.Write8( font->GetPointSize() );
|
|
|
|
data_s.WriteString( font->GetFaceName() );
|
|
|
|
data_s.Write8( font->GetFamily() );
|
|
|
|
data_s.Write8( font->GetStyle() );
|
|
|
|
data_s.Write8( font->GetWeight() );
|
|
|
|
data_s.Write8( font->GetUnderlined() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void WXSERIAL(wxFont)::LoadObject(wxObjectInputStream& s)
|
|
|
|
{
|
|
|
|
wxFont *font = (wxFont *)Object();
|
|
|
|
|
|
|
|
WXSERIAL(wxGDIObject)::LoadObject(s);
|
|
|
|
|
|
|
|
wxDataInputStream data_s(s);
|
|
|
|
int psize, family, style, weight;
|
|
|
|
bool underlined;
|
|
|
|
wxString face_name;
|
|
|
|
|
|
|
|
psize = data_s.Read8();
|
|
|
|
face_name = data_s.ReadString();
|
|
|
|
family = data_s.Read8();
|
|
|
|
style = data_s.Read8();
|
|
|
|
weight = data_s.Read8();
|
|
|
|
underlined = data_s.Read8();
|
|
|
|
|
|
|
|
*font = wxFont(psize, face_name, family, style, weight, underlined);
|
|
|
|
}
|
1998-08-18 13:22:15 -04:00
|
|
|
|
1998-08-23 05:23:27 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1998-08-18 13:22:15 -04:00
|
|
|
void WXSERIAL(wxImageList)::StoreObject(wxObjectOutputStream& s)
|
|
|
|
{
|
|
|
|
wxImageList *list = (wxImageList *)Object();
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (s.FirstStage()) {
|
1998-09-17 13:30:13 -04:00
|
|
|
#ifdef __WXGTK__
|
1998-08-18 13:22:15 -04:00
|
|
|
for (i=0;i<list->GetImageCount();i++)
|
|
|
|
s.AddChild(list->GetBitmap(i));
|
1998-09-17 13:30:13 -04:00
|
|
|
#endif
|
1998-08-18 13:22:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
wxDataOutputStream data_s(s);
|
|
|
|
|
|
|
|
data_s.Write32(list->GetImageCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
void WXSERIAL(wxImageList)::LoadObject(wxObjectInputStream& s)
|
|
|
|
{
|
|
|
|
int i, count;
|
|
|
|
wxImageList *list = (wxImageList *)Object();
|
|
|
|
wxDataInputStream data_s(s);
|
|
|
|
|
|
|
|
count = data_s.Read32();
|
|
|
|
for (i=0;i<count;i++)
|
1998-08-19 14:33:19 -04:00
|
|
|
list->Add(*((wxBitmap *)s.GetChild()));
|
1998-08-18 13:22:15 -04:00
|
|
|
}
|