]>
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>
30 IMPLEMENT_SERIAL_CLASS(wxBitmap
, wxObject
)
31 IMPLEMENT_SERIAL_CLASS(wxGDIObject
, wxObject
)
32 IMPLEMENT_SERIAL_CLASS(wxRegion
, wxGDIObject
)
33 IMPLEMENT_SERIAL_CLASS(wxColour
, wxGDIObject
)
34 IMPLEMENT_SERIAL_CLASS(wxFont
, wxGDIObject
)
35 IMPLEMENT_SERIAL_CLASS(wxPen
, wxGDIObject
)
36 IMPLEMENT_SERIAL_CLASS(wxBrush
, wxGDIObject
)
37 IMPLEMENT_SERIAL_CLASS(wxImageList
, wxObject
)
39 IMPLEMENT_ALIAS_SERIAL_CLASS(wxPenList
, wxList
)
40 IMPLEMENT_ALIAS_SERIAL_CLASS(wxBrushList
, wxList
)
41 IMPLEMENT_ALIAS_SERIAL_CLASS(wxFontList
, wxList
)
42 IMPLEMENT_ALIAS_SERIAL_CLASS(wxColourDatabase
, wxList
)
43 IMPLEMENT_ALIAS_SERIAL_CLASS(wxBitmapList
, wxList
)
45 // ----------------------------------------------------------------------------
47 void WXSERIAL(wxBitmap
)::StoreObject(wxObjectOutputStream
& s
)
50 // I implemented a basic image saving (maybe I'll need to improve wxWin API).
53 wxDataOutputStream
data_s(s
);
54 wxBitmap
*bitmap
= (wxBitmap
*)Object();
58 w
= bitmap
->GetWidth();
59 h
= bitmap
->GetHeight();
62 s
.AddChild(bitmap
->GetMask());
65 dc
.SelectObject(*bitmap
);
71 dc
.GetPixel(x
, y
, &col
);
72 data_s
.Write8( col
.Red() );
73 data_s
.Write8( col
.Green() );
74 data_s
.Write8( col
.Blue() );
78 void WXSERIAL(wxBitmap
)::LoadObject(wxObjectInputStream
& s
)
81 // I implemented a basic image loading (maybe I'll need to improve wxWin API).
82 wxDataInputStream
data_s(s
);
83 wxBitmap
*bitmap
= (wxBitmap
*)Object();
93 dc
.SelectObject(*bitmap
);
100 pen
.SetColour(r
, g
, b
);
106 // ----------------------------------------------------------------------------
108 void WXSERIAL(wxGDIObject
)::StoreObject(wxObjectOutputStream
& s
)
113 bool visible
= ((wxGDIObject
*)Object())->GetVisible();
115 wxDataOutputStream
data_s(s
);
116 data_s
.Write8(visible
);
119 void WXSERIAL(wxGDIObject
)::LoadObject(wxObjectInputStream
& s
)
121 wxDataInputStream
data_s(s
);
123 ((wxGDIObject
*)Object())->SetVisible( data_s
.Read8() );
126 // ----------------------------------------------------------------------------
128 void WXSERIAL(wxRegion
)::StoreObject(wxObjectOutputStream
& s
)
130 WXSERIAL(wxGDIObject
)::StoreObject(s
);
135 wxDataOutputStream
data_s(s
);
136 wxRect rect
= ((wxRegion
*)Object())->GetBox();
138 data_s
.Write16( rect
.GetX() );
139 data_s
.Write16( rect
.GetY() );
140 data_s
.Write16( rect
.GetWidth() );
141 data_s
.Write16( rect
.GetHeight() );
144 void WXSERIAL(wxRegion
)::LoadObject(wxObjectInputStream
& s
)
146 WXSERIAL(wxGDIObject
)::LoadObject(s
);
148 wxDataInputStream
data_s(s
);
149 wxRegion
*region
= (wxRegion
*)Object();
152 rect
.SetX( data_s
.Read16() );
153 rect
.SetY( data_s
.Read16() );
154 rect
.SetWidth( data_s
.Read16() );
155 rect
.SetHeight( data_s
.Read16() );
157 *region
= wxRegion(rect
);
160 // ----------------------------------------------------------------------------
162 void WXSERIAL(wxColour
)::StoreObject(wxObjectOutputStream
& s
)
164 WXSERIAL(wxGDIObject
)::StoreObject(s
);
169 wxDataOutputStream
data_s(s
);
170 wxColour
*colour
= (wxColour
*)Object();
172 data_s
.Write8(colour
->Red());
173 data_s
.Write8(colour
->Green());
174 data_s
.Write8(colour
->Blue());
177 void WXSERIAL(wxColour
)::LoadObject(wxObjectInputStream
& s
)
179 WXSERIAL(wxGDIObject
)::LoadObject(s
);
181 wxDataInputStream
data_s(s
);
182 wxColour
*colour
= (wxColour
*)Object();
189 colour
->Set(r
, g
, b
);
192 // ----------------------------------------------------------------------------
194 void WXSERIAL(wxPen
)::StoreObject(wxObjectOutputStream
& s
)
196 wxPen
*pen
= (wxPen
*)Object();
197 WXSERIAL(wxGDIObject
)::StoreObject(s
);
199 if (s
.FirstStage()) {
200 s
.AddChild(& (pen
->GetColour()) );
204 wxDataOutputStream
data_s(s
);
206 data_s
.Write8( pen
->GetCap() );
207 data_s
.Write8( pen
->GetJoin() );
208 data_s
.Write8( pen
->GetStyle() );
209 data_s
.Write8( pen
->GetWidth() );
212 void WXSERIAL(wxPen
)::LoadObject(wxObjectInputStream
& s
)
214 wxPen
*pen
= (wxPen
*)Object();
215 wxColour
*col
= (wxColour
*) s
.GetChild();
217 WXSERIAL(wxGDIObject
)::LoadObject(s
);
219 wxDataInputStream
data_s(s
);
221 pen
->SetColour(*col
);
222 pen
->SetCap( data_s
.Read8() );
223 pen
->SetJoin( data_s
.Read8() );
224 pen
->SetStyle( data_s
.Read8() );
225 pen
->SetWidth( data_s
.Read8() );
228 // ----------------------------------------------------------------------------
229 void WXSERIAL(wxBrush
)::StoreObject(wxObjectOutputStream
& s
)
231 wxBrush
*brush
= (wxBrush
*)Object();
232 WXSERIAL(wxGDIObject
)::StoreObject(s
);
234 if (s
.FirstStage()) {
235 s
.AddChild( &(brush
->GetColour()) );
236 s
.AddChild( brush
->GetStipple() );
240 wxDataOutputStream
data_s(s
);
241 data_s
.Write8( brush
->GetStyle() );
244 void WXSERIAL(wxBrush
)::LoadObject(wxObjectInputStream
& s
)
246 wxBrush
*brush
= (wxBrush
*)Object();
247 wxColour
*col
= (wxColour
*)s
.GetChild();
248 wxBitmap
*bmap
= (wxBitmap
*)s
.GetChild();
250 WXSERIAL(wxGDIObject
)::LoadObject(s
);
252 wxDataInputStream
data_s(s
);
254 *brush
= wxBrush(*col
, data_s
.Read8());
256 *brush
= wxBrush(bmap
);
259 // ----------------------------------------------------------------------------
260 void WXSERIAL(wxFont
)::StoreObject(wxObjectOutputStream
& s
)
262 wxFont
*font
= (wxFont
*)Object();
264 WXSERIAL(wxGDIObject
)::StoreObject(s
);
269 wxDataOutputStream
data_s(s
);
271 data_s
.Write8( font
->GetPointSize() );
272 data_s
.WriteString( font
->GetFaceName() );
273 data_s
.Write8( font
->GetFamily() );
274 data_s
.Write8( font
->GetStyle() );
275 data_s
.Write8( font
->GetWeight() );
276 data_s
.Write8( font
->GetUnderlined() );
279 void WXSERIAL(wxFont
)::LoadObject(wxObjectInputStream
& s
)
281 wxFont
*font
= (wxFont
*)Object();
283 WXSERIAL(wxGDIObject
)::LoadObject(s
);
285 wxDataInputStream
data_s(s
);
286 int psize
, family
, style
, weight
;
290 psize
= data_s
.Read8();
291 face_name
= data_s
.ReadString();
292 family
= data_s
.Read8();
293 style
= data_s
.Read8();
294 weight
= data_s
.Read8();
295 underlined
= data_s
.Read8();
297 *font
= wxFont(psize
, face_name
, family
, style
, weight
, underlined
);
300 // ----------------------------------------------------------------------------
302 void WXSERIAL(wxImageList
)::StoreObject(wxObjectOutputStream
& s
)
304 wxImageList
*list
= (wxImageList
*)Object();
307 if (s
.FirstStage()) {
308 for (i
=0;i
<list
->GetImageCount();i
++)
309 s
.AddChild(list
->GetBitmap(i
));
312 wxDataOutputStream
data_s(s
);
314 data_s
.Write32(list
->GetImageCount());
317 void WXSERIAL(wxImageList
)::LoadObject(wxObjectInputStream
& s
)
320 wxImageList
*list
= (wxImageList
*)Object();
321 wxDataInputStream
data_s(s
);
323 count
= data_s
.Read32();
324 for (i
=0;i
<count
;i
++)
325 list
->Add(*((wxBitmap
*)s
.GetChild()));