* wxThread: new functions: wxThread::Pause/Resume, wxThread::GetThreadFromID
[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(0);
120
121 s.RemoveChildren(1);
122
123 WXSERIAL(wxGDIObject)::LoadObject(s);
124
125 wxDataInputStream data_s(s);
126
127 pen->SetColour(*col);
128 pen->SetCap( data_s.Read8() );
129 pen->SetJoin( data_s.Read8() );
130 pen->SetStyle( data_s.Read8() );
131 pen->SetWidth( data_s.Read8() );
132 }
133
134 void WXSERIAL(wxBrush)::StoreObject(wxObjectOutputStream& s)
135 {
136 wxBrush *brush = (wxBrush *)Object();
137 WXSERIAL(wxGDIObject)::StoreObject(s);
138
139 if (s.FirstStage()) {
140 s.AddChild( &(brush->GetColour()) );
141 s.AddChild( brush->GetStipple() );
142 return;
143 }
144
145 wxDataOutputStream data_s(s);
146 data_s.Write8( brush->GetStyle() );
147 }
148
149 void WXSERIAL(wxBrush)::LoadObject(wxObjectInputStream& s)
150 {
151 wxBrush *brush = (wxBrush *)Object();
152 wxColour *col = (wxColour *)s.GetChild(0);
153 wxBitmap *bmap = (wxBitmap *)s.GetChild(1);
154
155 s.RemoveChildren(2);
156
157 WXSERIAL(wxGDIObject)::LoadObject(s);
158
159 wxDataInputStream data_s(s);
160 if (bmap)
161 *brush = wxBrush(*col, data_s.Read8());
162 else
163 *brush = wxBrush(bmap);
164 }
165
166 void WXSERIAL(wxFont)::StoreObject(wxObjectOutputStream& s)
167 {
168 wxFont *font = (wxFont *)Object();
169
170 WXSERIAL(wxGDIObject)::StoreObject(s);
171
172 if (s.FirstStage())
173 return;
174
175 wxDataOutputStream data_s(s);
176
177 data_s.Write8( font->GetPointSize() );
178 data_s.WriteString( font->GetFaceName() );
179 data_s.Write8( font->GetFamily() );
180 data_s.Write8( font->GetStyle() );
181 data_s.Write8( font->GetWeight() );
182 data_s.Write8( font->GetUnderlined() );
183 }
184
185 void WXSERIAL(wxFont)::LoadObject(wxObjectInputStream& s)
186 {
187 wxFont *font = (wxFont *)Object();
188
189 WXSERIAL(wxGDIObject)::LoadObject(s);
190
191 wxDataInputStream data_s(s);
192 int psize, family, style, weight;
193 bool underlined;
194 wxString face_name;
195
196 psize = data_s.Read8();
197 face_name = data_s.ReadString();
198 family = data_s.Read8();
199 style = data_s.Read8();
200 weight = data_s.Read8();
201 underlined = data_s.Read8();
202
203 *font = wxFont(psize, face_name, family, style, weight, underlined);
204 }
205
206 void WXSERIAL(wxImageList)::StoreObject(wxObjectOutputStream& s)
207 {
208 wxImageList *list = (wxImageList *)Object();
209 int i;
210
211 if (s.FirstStage()) {
212 for (i=0;i<list->GetImageCount();i++)
213 s.AddChild(list->GetBitmap(i));
214 }
215
216 wxDataOutputStream data_s(s);
217
218 data_s.Write32(list->GetImageCount());
219 }
220
221 void WXSERIAL(wxImageList)::LoadObject(wxObjectInputStream& s)
222 {
223 int i, count;
224 wxImageList *list = (wxImageList *)Object();
225 wxDataInputStream data_s(s);
226
227 count = data_s.Read32();
228 for (i=0;i<count;i++)
229 list->Add(*((wxBitmap *)s.GetChild(i)));
230 }