]>
Commit | Line | Data |
---|---|---|
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 "sergdi.h" | |
24 | ||
25 | IMPLEMENT_SERIAL_CLASS(wxBitmap, wxObject) | |
26 | IMPLEMENT_SERIAL_CLASS(wxGDIObject, wxObject) | |
27 | IMPLEMENT_SERIAL_CLASS(wxColour, wxGDIObject) | |
28 | IMPLEMENT_SERIAL_CLASS(wxFont, wxGDIObject) | |
29 | IMPLEMENT_SERIAL_CLASS(wxPen, wxGDIObject) | |
30 | IMPLEMENT_SERIAL_CLASS(wxBrush, wxGDIObject) | |
31 | ||
32 | IMPLEMENT_ALIAS_SERIAL_CLASS(wxPenList, wxList) | |
33 | IMPLEMENT_ALIAS_SERIAL_CLASS(wxBrushList, wxList) | |
34 | IMPLEMENT_ALIAS_SERIAL_CLASS(wxFontList, wxList) | |
35 | IMPLEMENT_ALIAS_SERIAL_CLASS(wxColourDatabase, wxList) | |
36 | IMPLEMENT_ALIAS_SERIAL_CLASS(wxBitmapList, wxList) | |
37 | ||
38 | void WXSERIAL(wxBitmap)::StoreObject(wxObjectOutputStream& s) | |
39 | { | |
40 | // TODO | |
41 | } | |
42 | ||
43 | void WXSERIAL(wxBitmap)::LoadObject(wxObjectInputStream& s) | |
44 | { | |
45 | // TODO | |
46 | } | |
47 | ||
48 | void WXSERIAL(wxGDIObject)::StoreObject(wxObjectOutputStream& s) | |
49 | { | |
50 | if (s.FirstStage()) | |
51 | return; | |
52 | ||
53 | bool visible = ((wxGDIObject *)Object())->GetVisible(); | |
54 | ||
55 | wxDataOutputStream data_s(s); | |
56 | data_s.Write8(visible); | |
57 | } | |
58 | ||
59 | void WXSERIAL(wxGDIObject)::LoadObject(wxObjectInputStream& s) | |
60 | { | |
61 | wxDataInputStream data_s(s); | |
62 | ||
63 | ((wxGDIObject *)Object())->SetVisible( data_s.Read8() ); | |
64 | } | |
65 | ||
66 | void WXSERIAL(wxColour)::StoreObject(wxObjectOutputStream& s) | |
67 | { | |
68 | WXSERIAL(wxGDIObject)::StoreObject(s); | |
69 | ||
70 | if (s.FirstStage()) | |
71 | return; | |
72 | ||
73 | wxDataOutputStream data_s(s); | |
74 | wxColour *colour = (wxColour *)Object(); | |
75 | ||
76 | data_s.Write8(colour->Red()); | |
77 | data_s.Write8(colour->Green()); | |
78 | data_s.Write8(colour->Blue()); | |
79 | } | |
80 | ||
81 | void WXSERIAL(wxColour)::LoadObject(wxObjectInputStream& s) | |
82 | { | |
83 | WXSERIAL(wxGDIObject)::LoadObject(s); | |
84 | ||
85 | wxDataInputStream data_s(s); | |
86 | wxColour *colour = (wxColour *)Object(); | |
87 | int r, g, b; | |
88 | ||
89 | r = data_s.Read8(); | |
90 | g = data_s.Read8(); | |
91 | b = data_s.Read8(); | |
92 | ||
93 | colour->Set(r, g, b); | |
94 | } | |
95 | ||
96 | void WXSERIAL(wxPen)::StoreObject(wxObjectOutputStream& s) | |
97 | { | |
98 | wxPen *pen = (wxPen *)Object(); | |
99 | WXSERIAL(wxGDIObject)::StoreObject(s); | |
100 | ||
101 | if (s.FirstStage()) { | |
102 | s.AddChild(& (pen->GetColour()) ); | |
103 | return; | |
104 | } | |
105 | ||
106 | wxDataOutputStream data_s(s); | |
107 | ||
108 | data_s.Write8( pen->GetCap() ); | |
109 | data_s.Write8( pen->GetJoin() ); | |
110 | data_s.Write8( pen->GetStyle() ); | |
111 | data_s.Write8( pen->GetWidth() ); | |
112 | } | |
113 | ||
114 | void WXSERIAL(wxPen)::LoadObject(wxObjectInputStream& s) | |
115 | { | |
116 | wxPen *pen = (wxPen *)Object(); | |
117 | wxColour *col = (wxColour *) s.GetChild(0); | |
118 | ||
119 | s.RemoveChildren(1); | |
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(0); | |
151 | wxBitmap *bmap = (wxBitmap *)s.GetChild(1); | |
152 | ||
153 | s.RemoveChildren(2); | |
154 | ||
155 | WXSERIAL(wxGDIObject)::LoadObject(s); | |
156 | ||
157 | wxDataInputStream data_s(s); | |
158 | if (bmap) | |
159 | *brush = wxBrush(*col, data_s.Read8()); | |
160 | else | |
161 | *brush = wxBrush(bmap); | |
162 | } | |
163 | ||
164 | void WXSERIAL(wxFont)::StoreObject(wxObjectOutputStream& s) | |
165 | { | |
166 | wxFont *font = (wxFont *)Object(); | |
167 | ||
168 | WXSERIAL(wxGDIObject)::StoreObject(s); | |
169 | ||
170 | if (s.FirstStage()) | |
171 | return; | |
172 | ||
173 | wxDataOutputStream data_s(s); | |
174 | ||
175 | data_s.Write8( font->GetPointSize() ); | |
176 | data_s.WriteString( font->GetFaceName() ); | |
177 | data_s.Write8( font->GetFamily() ); | |
178 | data_s.Write8( font->GetStyle() ); | |
179 | data_s.Write8( font->GetWeight() ); | |
180 | data_s.Write8( font->GetUnderlined() ); | |
181 | } | |
182 | ||
183 | void WXSERIAL(wxFont)::LoadObject(wxObjectInputStream& s) | |
184 | { | |
185 | wxFont *font = (wxFont *)Object(); | |
186 | ||
187 | WXSERIAL(wxGDIObject)::LoadObject(s); | |
188 | ||
189 | wxDataInputStream data_s(s); | |
190 | int psize, family, style, weight; | |
191 | bool underlined; | |
192 | wxString face_name; | |
193 | ||
194 | psize = data_s.Read8(); | |
195 | face_name = data_s.ReadString(); | |
196 | family = data_s.Read8(); | |
197 | style = data_s.Read8(); | |
198 | weight = data_s.Read8(); | |
199 | underlined = data_s.Read8(); | |
200 | ||
201 | *font = wxFont(psize, face_name, family, style, weight, underlined); | |
202 | } |