* Some new feature in wxObject*Stream (objects aren't duplicated)
[wxWidgets.git] / utils / serialize / sergdi.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: sergdi.cpp
3 // Purpose: Serialization: GDI classes
4 // Author: Guilhem Lavaux
5 // Modified by:
6 // Created: July 1998
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "sergdi.h"
14 #endif
15 #include <wx/objstrm.h>
16 #include <wx/datstrm.h>
17 #include <wx/gdicmn.h>
18 #include <wx/bitmap.h>
19 #include <wx/font.h>
20 #include <wx/pen.h>
21 #include <wx/brush.h>
22 #include <wx/serbase.h>
23 #include <wx/imaglist.h>
24 #include "sergdi.h"
25
26 IMPLEMENT_SERIAL_CLASS(wxBitmap, wxObject)
27 IMPLEMENT_SERIAL_CLASS(wxGDIObject, wxObject)
28 IMPLEMENT_SERIAL_CLASS(wxColour, wxGDIObject)
29 IMPLEMENT_SERIAL_CLASS(wxFont, wxGDIObject)
30 IMPLEMENT_SERIAL_CLASS(wxPen, wxGDIObject)
31 IMPLEMENT_SERIAL_CLASS(wxBrush, wxGDIObject)
32 IMPLEMENT_SERIAL_CLASS(wxImageList, wxObject)
33
34 IMPLEMENT_ALIAS_SERIAL_CLASS(wxPenList, wxList)
35 IMPLEMENT_ALIAS_SERIAL_CLASS(wxBrushList, wxList)
36 IMPLEMENT_ALIAS_SERIAL_CLASS(wxFontList, wxList)
37 IMPLEMENT_ALIAS_SERIAL_CLASS(wxColourDatabase, wxList)
38 IMPLEMENT_ALIAS_SERIAL_CLASS(wxBitmapList, wxList)
39
40 void WXSERIAL(wxBitmap)::StoreObject(wxObjectOutputStream& s)
41 {
42 // TODO
43 }
44
45 void WXSERIAL(wxBitmap)::LoadObject(wxObjectInputStream& s)
46 {
47 // TODO
48 }
49
50 void WXSERIAL(wxGDIObject)::StoreObject(wxObjectOutputStream& s)
51 {
52 if (s.FirstStage())
53 return;
54
55 bool visible = ((wxGDIObject *)Object())->GetVisible();
56
57 wxDataOutputStream data_s(s);
58 data_s.Write8(visible);
59 }
60
61 void WXSERIAL(wxGDIObject)::LoadObject(wxObjectInputStream& s)
62 {
63 wxDataInputStream data_s(s);
64
65 ((wxGDIObject *)Object())->SetVisible( data_s.Read8() );
66 }
67
68 void WXSERIAL(wxColour)::StoreObject(wxObjectOutputStream& s)
69 {
70 WXSERIAL(wxGDIObject)::StoreObject(s);
71
72 if (s.FirstStage())
73 return;
74
75 wxDataOutputStream data_s(s);
76 wxColour *colour = (wxColour *)Object();
77
78 data_s.Write8(colour->Red());
79 data_s.Write8(colour->Green());
80 data_s.Write8(colour->Blue());
81 }
82
83 void WXSERIAL(wxColour)::LoadObject(wxObjectInputStream& s)
84 {
85 WXSERIAL(wxGDIObject)::LoadObject(s);
86
87 wxDataInputStream data_s(s);
88 wxColour *colour = (wxColour *)Object();
89 int r, g, b;
90
91 r = data_s.Read8();
92 g = data_s.Read8();
93 b = data_s.Read8();
94
95 colour->Set(r, g, b);
96 }
97
98 void WXSERIAL(wxPen)::StoreObject(wxObjectOutputStream& s)
99 {
100 wxPen *pen = (wxPen *)Object();
101 WXSERIAL(wxGDIObject)::StoreObject(s);
102
103 if (s.FirstStage()) {
104 s.AddChild(& (pen->GetColour()) );
105 return;
106 }
107
108 wxDataOutputStream data_s(s);
109
110 data_s.Write8( pen->GetCap() );
111 data_s.Write8( pen->GetJoin() );
112 data_s.Write8( pen->GetStyle() );
113 data_s.Write8( pen->GetWidth() );
114 }
115
116 void WXSERIAL(wxPen)::LoadObject(wxObjectInputStream& s)
117 {
118 wxPen *pen = (wxPen *)Object();
119 wxColour *col = (wxColour *) s.GetChild();
120
121 WXSERIAL(wxGDIObject)::LoadObject(s);
122
123 wxDataInputStream data_s(s);
124
125 pen->SetColour(*col);
126 pen->SetCap( data_s.Read8() );
127 pen->SetJoin( data_s.Read8() );
128 pen->SetStyle( data_s.Read8() );
129 pen->SetWidth( data_s.Read8() );
130 }
131
132 void WXSERIAL(wxBrush)::StoreObject(wxObjectOutputStream& s)
133 {
134 wxBrush *brush = (wxBrush *)Object();
135 WXSERIAL(wxGDIObject)::StoreObject(s);
136
137 if (s.FirstStage()) {
138 s.AddChild( &(brush->GetColour()) );
139 s.AddChild( brush->GetStipple() );
140 return;
141 }
142
143 wxDataOutputStream data_s(s);
144 data_s.Write8( brush->GetStyle() );
145 }
146
147 void WXSERIAL(wxBrush)::LoadObject(wxObjectInputStream& s)
148 {
149 wxBrush *brush = (wxBrush *)Object();
150 wxColour *col = (wxColour *)s.GetChild();
151 wxBitmap *bmap = (wxBitmap *)s.GetChild();
152
153 WXSERIAL(wxGDIObject)::LoadObject(s);
154
155 wxDataInputStream data_s(s);
156 if (bmap)
157 *brush = wxBrush(*col, data_s.Read8());
158 else
159 *brush = wxBrush(bmap);
160 }
161
162 void WXSERIAL(wxFont)::StoreObject(wxObjectOutputStream& s)
163 {
164 wxFont *font = (wxFont *)Object();
165
166 WXSERIAL(wxGDIObject)::StoreObject(s);
167
168 if (s.FirstStage())
169 return;
170
171 wxDataOutputStream data_s(s);
172
173 data_s.Write8( font->GetPointSize() );
174 data_s.WriteString( font->GetFaceName() );
175 data_s.Write8( font->GetFamily() );
176 data_s.Write8( font->GetStyle() );
177 data_s.Write8( font->GetWeight() );
178 data_s.Write8( font->GetUnderlined() );
179 }
180
181 void WXSERIAL(wxFont)::LoadObject(wxObjectInputStream& s)
182 {
183 wxFont *font = (wxFont *)Object();
184
185 WXSERIAL(wxGDIObject)::LoadObject(s);
186
187 wxDataInputStream data_s(s);
188 int psize, family, style, weight;
189 bool underlined;
190 wxString face_name;
191
192 psize = data_s.Read8();
193 face_name = data_s.ReadString();
194 family = data_s.Read8();
195 style = data_s.Read8();
196 weight = data_s.Read8();
197 underlined = data_s.Read8();
198
199 *font = wxFont(psize, face_name, family, style, weight, underlined);
200 }
201
202 void WXSERIAL(wxImageList)::StoreObject(wxObjectOutputStream& s)
203 {
204 wxImageList *list = (wxImageList *)Object();
205 int i;
206
207 if (s.FirstStage()) {
208 for (i=0;i<list->GetImageCount();i++)
209 s.AddChild(list->GetBitmap(i));
210 }
211
212 wxDataOutputStream data_s(s);
213
214 data_s.Write32(list->GetImageCount());
215 }
216
217 void WXSERIAL(wxImageList)::LoadObject(wxObjectInputStream& s)
218 {
219 int i, count;
220 wxImageList *list = (wxImageList *)Object();
221 wxDataInputStream data_s(s);
222
223 count = data_s.Read32();
224 for (i=0;i<count;i++)
225 list->Add(*((wxBitmap *)s.GetChild()));
226 }