]>
git.saurik.com Git - wxWidgets.git/blob - utils/serialize/sergdi.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Serialization: GDI classes
4 // Author: Guilhem Lavaux
8 // Copyright: (c) 1998 Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "sergdi.h"
15 #include <wx/objstrm.h>
16 #include <wx/datstrm.h>
17 #include <wx/gdicmn.h>
18 #include <wx/bitmap.h>
22 #include <wx/serbase.h>
23 #include <wx/imaglist.h>
24 #include <wx/region.h>
25 #include <wx/colour.h>
26 #include <wx/palette.h>
27 #include <wx/dcmemory.h>
31 IMPLEMENT_SERIAL_CLASS(wxBitmap
, wxObject
)
32 IMPLEMENT_SERIAL_CLASS(wxGDIObject
, wxObject
)
33 IMPLEMENT_SERIAL_CLASS(wxRegion
, wxGDIObject
)
34 IMPLEMENT_SERIAL_CLASS(wxColour
, wxObject
)
35 IMPLEMENT_SERIAL_CLASS(wxFont
, wxGDIObject
)
36 IMPLEMENT_SERIAL_CLASS(wxPen
, wxGDIObject
)
37 IMPLEMENT_SERIAL_CLASS(wxBrush
, wxGDIObject
)
38 IMPLEMENT_SERIAL_CLASS(wxImageList
, wxObject
)
40 IMPLEMENT_ALIAS_SERIAL_CLASS(wxPenList
, wxList
)
41 IMPLEMENT_ALIAS_SERIAL_CLASS(wxBrushList
, wxList
)
42 IMPLEMENT_ALIAS_SERIAL_CLASS(wxFontList
, wxList
)
43 IMPLEMENT_ALIAS_SERIAL_CLASS(wxColourDatabase
, wxList
)
44 IMPLEMENT_ALIAS_SERIAL_CLASS(wxBitmapList
, wxList
)
46 // ----------------------------------------------------------------------------
48 void WXSERIAL(wxBitmap
)::StoreObject(wxObjectOutputStream
& s
)
51 // I implemented a basic image saving (maybe I'll need to improve wxWin API).
54 wxDataOutputStream
data_s(s
);
55 wxBitmap
*bitmap
= (wxBitmap
*)Object();
59 w
= bitmap
->GetWidth();
60 h
= bitmap
->GetHeight();
63 s
.AddChild(bitmap
->GetMask());
66 dc
.SelectObject(*bitmap
);
72 dc
.GetPixel(x
, y
, &col
);
73 data_s
.Write8( col
.Red() );
74 data_s
.Write8( col
.Green() );
75 data_s
.Write8( col
.Blue() );
79 void WXSERIAL(wxBitmap
)::LoadObject(wxObjectInputStream
& s
)
82 // I implemented a basic image loading (maybe I'll need to improve wxWin API).
83 wxDataInputStream
data_s(s
);
84 wxBitmap
*bitmap
= (wxBitmap
*)Object();
95 dc
.SelectObject(*bitmap
);
102 pen
.SetColour(r
, g
, b
);
108 // ----------------------------------------------------------------------------
110 void WXSERIAL(wxGDIObject
)::StoreObject(wxObjectOutputStream
& s
)
115 bool visible
= ((wxGDIObject
*)Object())->GetVisible();
117 wxDataOutputStream
data_s(s
);
118 data_s
.Write8(visible
);
121 void WXSERIAL(wxGDIObject
)::LoadObject(wxObjectInputStream
& s
)
123 wxDataInputStream
data_s(s
);
125 ((wxGDIObject
*)Object())->SetVisible( data_s
.Read8() );
128 // ----------------------------------------------------------------------------
130 void WXSERIAL(wxRegion
)::StoreObject(wxObjectOutputStream
& s
)
132 WXSERIAL(wxGDIObject
)::StoreObject(s
);
137 wxDataOutputStream
data_s(s
);
138 wxRect rect
= ((wxRegion
*)Object())->GetBox();
140 data_s
.Write16( rect
.GetX() );
141 data_s
.Write16( rect
.GetY() );
142 data_s
.Write16( rect
.GetWidth() );
143 data_s
.Write16( rect
.GetHeight() );
146 void WXSERIAL(wxRegion
)::LoadObject(wxObjectInputStream
& s
)
148 WXSERIAL(wxGDIObject
)::LoadObject(s
);
150 wxDataInputStream
data_s(s
);
151 wxRegion
*region
= (wxRegion
*)Object();
154 rect
.SetX( data_s
.Read16() );
155 rect
.SetY( data_s
.Read16() );
156 rect
.SetWidth( data_s
.Read16() );
157 rect
.SetHeight( data_s
.Read16() );
159 *region
= wxRegion(rect
);
162 // ----------------------------------------------------------------------------
164 void WXSERIAL(wxColour
)::StoreObject(wxObjectOutputStream
& s
)
169 wxDataOutputStream
data_s(s
);
170 wxColour
*colour
= (wxColour
*)Object();
176 wxLogDebug("wxColour (0x%x) isn't ready.\n", colour
);
180 data_s
.Write8(colour
->Red());
181 data_s
.Write8(colour
->Green());
182 data_s
.Write8(colour
->Blue());
185 void WXSERIAL(wxColour
)::LoadObject(wxObjectInputStream
& s
)
187 wxDataInputStream
data_s(s
);
188 wxColour
*colour
= (wxColour
*)Object();
195 colour
->Set(r
, g
, b
);
198 // ----------------------------------------------------------------------------
200 void WXSERIAL(wxPen
)::StoreObject(wxObjectOutputStream
& s
)
202 wxPen
*pen
= (wxPen
*)Object();
203 WXSERIAL(wxGDIObject
)::StoreObject(s
);
205 if (s
.FirstStage()) {
206 s
.AddChild(& (pen
->GetColour()) );
210 wxDataOutputStream
data_s(s
);
212 data_s
.Write8( pen
->GetCap() );
213 data_s
.Write8( pen
->GetJoin() );
214 data_s
.Write8( pen
->GetStyle() );
215 data_s
.Write8( pen
->GetWidth() );
218 void WXSERIAL(wxPen
)::LoadObject(wxObjectInputStream
& s
)
220 wxPen
*pen
= (wxPen
*)Object();
221 wxColour
*col
= (wxColour
*) s
.GetChild();
223 WXSERIAL(wxGDIObject
)::LoadObject(s
);
225 wxDataInputStream
data_s(s
);
227 pen
->SetColour(*col
);
228 pen
->SetCap( data_s
.Read8() );
229 pen
->SetJoin( data_s
.Read8() );
230 pen
->SetStyle( data_s
.Read8() );
231 pen
->SetWidth( data_s
.Read8() );
234 // ----------------------------------------------------------------------------
235 void WXSERIAL(wxBrush
)::StoreObject(wxObjectOutputStream
& s
)
237 wxBrush
*brush
= (wxBrush
*)Object();
238 WXSERIAL(wxGDIObject
)::StoreObject(s
);
240 if (s
.FirstStage()) {
241 s
.AddChild( &(brush
->GetColour()) );
242 s
.AddChild( brush
->GetStipple() );
246 wxDataOutputStream
data_s(s
);
247 data_s
.Write8( brush
->GetStyle() );
250 void WXSERIAL(wxBrush
)::LoadObject(wxObjectInputStream
& s
)
252 wxBrush
*brush
= (wxBrush
*)Object();
253 wxColour
*col
= (wxColour
*)s
.GetChild();
254 wxBitmap
*bmap
= (wxBitmap
*)s
.GetChild();
256 WXSERIAL(wxGDIObject
)::LoadObject(s
);
258 wxDataInputStream
data_s(s
);
260 *brush
= wxBrush(*col
, data_s
.Read8());
262 *brush
= wxBrush(bmap
);
265 // ----------------------------------------------------------------------------
266 void WXSERIAL(wxFont
)::StoreObject(wxObjectOutputStream
& s
)
268 wxFont
*font
= (wxFont
*)Object();
270 WXSERIAL(wxGDIObject
)::StoreObject(s
);
275 wxDataOutputStream
data_s(s
);
277 data_s
.Write8( font
->GetPointSize() );
278 data_s
.WriteString( font
->GetFaceName() );
279 data_s
.Write8( font
->GetFamily() );
280 data_s
.Write8( font
->GetStyle() );
281 data_s
.Write8( font
->GetWeight() );
282 data_s
.Write8( font
->GetUnderlined() );
285 void WXSERIAL(wxFont
)::LoadObject(wxObjectInputStream
& s
)
287 wxFont
*font
= (wxFont
*)Object();
289 WXSERIAL(wxGDIObject
)::LoadObject(s
);
291 wxDataInputStream
data_s(s
);
292 int psize
, family
, style
, weight
;
296 psize
= data_s
.Read8();
297 face_name
= data_s
.ReadString();
298 family
= data_s
.Read8();
299 style
= data_s
.Read8();
300 weight
= data_s
.Read8();
301 underlined
= data_s
.Read8();
303 *font
= wxFont(psize
, face_name
, family
, style
, weight
, underlined
);
306 // ----------------------------------------------------------------------------
308 void WXSERIAL(wxImageList
)::StoreObject(wxObjectOutputStream
& s
)
310 wxImageList
*list
= (wxImageList
*)Object();
313 if (s
.FirstStage()) {
315 for (i
=0;i
<list
->GetImageCount();i
++)
316 s
.AddChild(list
->GetBitmap(i
));
320 wxDataOutputStream
data_s(s
);
322 data_s
.Write32(list
->GetImageCount());
325 void WXSERIAL(wxImageList
)::LoadObject(wxObjectInputStream
& s
)
328 wxImageList
*list
= (wxImageList
*)Object();
329 wxDataInputStream
data_s(s
);
331 count
= data_s
.Read32();
332 for (i
=0;i
<count
;i
++)
333 list
->Add(*((wxBitmap
*)s
.GetChild()));