]>
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();
98 dc
.SelectObject(*bitmap
);
105 pen
.SetColour(r
, g
, b
);
111 // ----------------------------------------------------------------------------
113 void WXSERIAL(wxGDIObject
)::StoreObject(wxObjectOutputStream
& s
)
118 bool visible
= ((wxGDIObject
*)Object())->GetVisible();
120 wxDataOutputStream
data_s(s
);
121 data_s
.Write8(visible
);
124 void WXSERIAL(wxGDIObject
)::LoadObject(wxObjectInputStream
& s
)
126 wxDataInputStream
data_s(s
);
128 ((wxGDIObject
*)Object())->SetVisible( data_s
.Read8() );
131 // ----------------------------------------------------------------------------
133 void WXSERIAL(wxRegion
)::StoreObject(wxObjectOutputStream
& s
)
135 WXSERIAL(wxGDIObject
)::StoreObject(s
);
140 wxDataOutputStream
data_s(s
);
141 wxRect rect
= ((wxRegion
*)Object())->GetBox();
143 data_s
.Write16( rect
.GetX() );
144 data_s
.Write16( rect
.GetY() );
145 data_s
.Write16( rect
.GetWidth() );
146 data_s
.Write16( rect
.GetHeight() );
149 void WXSERIAL(wxRegion
)::LoadObject(wxObjectInputStream
& s
)
151 WXSERIAL(wxGDIObject
)::LoadObject(s
);
153 wxDataInputStream
data_s(s
);
154 wxRegion
*region
= (wxRegion
*)Object();
157 rect
.SetX( data_s
.Read16() );
158 rect
.SetY( data_s
.Read16() );
159 rect
.SetWidth( data_s
.Read16() );
160 rect
.SetHeight( data_s
.Read16() );
162 *region
= wxRegion(rect
);
165 // ----------------------------------------------------------------------------
167 void WXSERIAL(wxColour
)::StoreObject(wxObjectOutputStream
& s
)
172 wxDataOutputStream
data_s(s
);
173 wxColour
*colour
= (wxColour
*)Object();
179 wxLogDebug("wxColour (0x%x) isn't ready.\n", colour
);
183 data_s
.Write8(colour
->Red());
184 data_s
.Write8(colour
->Green());
185 data_s
.Write8(colour
->Blue());
188 void WXSERIAL(wxColour
)::LoadObject(wxObjectInputStream
& s
)
190 wxDataInputStream
data_s(s
);
191 wxColour
*colour
= (wxColour
*)Object();
198 colour
->Set(r
, g
, b
);
201 // ----------------------------------------------------------------------------
203 void WXSERIAL(wxPen
)::StoreObject(wxObjectOutputStream
& s
)
205 wxPen
*pen
= (wxPen
*)Object();
206 WXSERIAL(wxGDIObject
)::StoreObject(s
);
208 if (s
.FirstStage()) {
209 s
.AddChild(& (pen
->GetColour()) );
213 wxDataOutputStream
data_s(s
);
215 data_s
.Write8( pen
->GetCap() );
216 data_s
.Write8( pen
->GetJoin() );
217 data_s
.Write8( pen
->GetStyle() );
218 data_s
.Write8( pen
->GetWidth() );
221 void WXSERIAL(wxPen
)::LoadObject(wxObjectInputStream
& s
)
223 wxPen
*pen
= (wxPen
*)Object();
224 wxColour
*col
= (wxColour
*) s
.GetChild();
226 WXSERIAL(wxGDIObject
)::LoadObject(s
);
228 wxDataInputStream
data_s(s
);
230 pen
->SetColour(*col
);
231 pen
->SetCap( data_s
.Read8() );
232 pen
->SetJoin( data_s
.Read8() );
233 pen
->SetStyle( data_s
.Read8() );
234 pen
->SetWidth( data_s
.Read8() );
237 // ----------------------------------------------------------------------------
238 void WXSERIAL(wxBrush
)::StoreObject(wxObjectOutputStream
& s
)
240 wxBrush
*brush
= (wxBrush
*)Object();
241 WXSERIAL(wxGDIObject
)::StoreObject(s
);
243 if (s
.FirstStage()) {
244 s
.AddChild( &(brush
->GetColour()) );
245 s
.AddChild( brush
->GetStipple() );
249 wxDataOutputStream
data_s(s
);
250 data_s
.Write8( brush
->GetStyle() );
253 void WXSERIAL(wxBrush
)::LoadObject(wxObjectInputStream
& s
)
255 wxBrush
*brush
= (wxBrush
*)Object();
256 wxColour
*col
= (wxColour
*)s
.GetChild();
257 wxBitmap
*bmap
= (wxBitmap
*)s
.GetChild();
259 WXSERIAL(wxGDIObject
)::LoadObject(s
);
261 wxDataInputStream
data_s(s
);
263 *brush
= wxBrush(*col
, data_s
.Read8());
265 *brush
= wxBrush(bmap
);
268 // ----------------------------------------------------------------------------
269 void WXSERIAL(wxFont
)::StoreObject(wxObjectOutputStream
& s
)
271 wxFont
*font
= (wxFont
*)Object();
273 WXSERIAL(wxGDIObject
)::StoreObject(s
);
278 wxDataOutputStream
data_s(s
);
280 data_s
.Write8( font
->GetPointSize() );
281 data_s
.WriteString( font
->GetFaceName() );
282 data_s
.Write8( font
->GetFamily() );
283 data_s
.Write8( font
->GetStyle() );
284 data_s
.Write8( font
->GetWeight() );
285 data_s
.Write8( font
->GetUnderlined() );
288 void WXSERIAL(wxFont
)::LoadObject(wxObjectInputStream
& s
)
290 wxFont
*font
= (wxFont
*)Object();
292 WXSERIAL(wxGDIObject
)::LoadObject(s
);
294 wxDataInputStream
data_s(s
);
295 int psize
, family
, style
, weight
;
299 psize
= data_s
.Read8();
300 face_name
= data_s
.ReadString();
301 family
= data_s
.Read8();
302 style
= data_s
.Read8();
303 weight
= data_s
.Read8();
304 underlined
= data_s
.Read8();
306 *font
= wxFont(psize
, face_name
, family
, style
, weight
, underlined
);
309 // ----------------------------------------------------------------------------
311 void WXSERIAL(wxImageList
)::StoreObject(wxObjectOutputStream
& s
)
313 wxImageList
*list
= (wxImageList
*)Object();
316 if (s
.FirstStage()) {
318 for (i
=0;i
<list
->GetImageCount();i
++)
319 s
.AddChild(list
->GetBitmap(i
));
323 wxDataOutputStream
data_s(s
);
325 data_s
.Write32(list
->GetImageCount());
328 void WXSERIAL(wxImageList
)::LoadObject(wxObjectInputStream
& s
)
331 wxImageList
*list
= (wxImageList
*)Object();
332 wxDataInputStream
data_s(s
);
334 count
= data_s
.Read32();
335 for (i
=0;i
<count
;i
++)
336 list
->Add(*((wxBitmap
*)s
.GetChild()));