]>
Commit | Line | Data |
---|---|---|
2193517f VS |
1 | // wxr2xml.cpp: implementation of the wxr2xml class. |
2 | // 8/30/00 Brian Gavin | |
88d42654 | 3 | // only tested on wxMSW so far |
2193517f VS |
4 | //License: wxWindows Liscense |
5 | // //////////////////////////////////////////////////////////////////// | |
6 | ||
7 | /* | |
8 | How to use class: | |
9 | #include "wxr2xml.h" | |
10 | ... | |
11 | wxr2xml trans; | |
12 | trans->Convert("Myfile.wxr","Myfile.xml"); | |
88d42654 | 13 | */ |
88d42654 VS |
14 | |
15 | // For compilers that support precompilation, includes "wx/wx.h". | |
16 | #include "wx/wxprec.h" | |
17 | ||
18 | #ifdef __BORLANDC__ | |
19 | #pragma hdrstop | |
20 | #endif | |
21 | ||
22 | #ifndef WX_PRECOMP | |
23 | #include "wx/wx.h" | |
24 | #endif | |
25 | ||
26 | #include "wxr2xml.h" | |
27 | ||
2193517f | 28 | // //////////////////////////////////////////////////////////////////// |
88d42654 | 29 | // Construction/Destruction |
2193517f | 30 | // //////////////////////////////////////////////////////////////////// |
88d42654 | 31 | |
2193517f | 32 | wxr2xml::wxr2xml() |
88d42654 VS |
33 | { |
34 | ||
35 | } | |
36 | ||
2193517f | 37 | wxr2xml::~wxr2xml() |
88d42654 VS |
38 | { |
39 | ||
40 | } | |
41 | ||
2193517f | 42 | bool wxr2xml::Convert(wxString wxrfile, wxString xmlfile) |
88d42654 | 43 | { |
2193517f | 44 | bool result; |
19d0f58d JS |
45 | result = m_xmlfile.Open(xmlfile.c_str(), _T("w+t")); |
46 | wxASSERT_MSG(result, _T("Couldn't create XML file")); | |
2193517f | 47 | if (!result) |
f80ea77b | 48 | return false; |
88d42654 | 49 | |
2193517f | 50 | result = m_table.ParseResourceFile(wxrfile); |
19d0f58d | 51 | wxASSERT_MSG(result, _T("Couldn't Load WXR file")); |
2193517f | 52 | if (!result) |
f80ea77b | 53 | return false; |
2193517f | 54 | // Write basic xml header |
19d0f58d JS |
55 | m_xmlfile.Write(_T("<?xml version=\"1.0\" ?>\n")); |
56 | m_xmlfile.Write(_T("<resource>\n")); | |
2193517f | 57 | result = ParseResources(); |
19d0f58d | 58 | m_xmlfile.Write(_T("</resource>\n")); |
88d42654 | 59 | |
2193517f | 60 | m_xmlfile.Close(); |
88d42654 | 61 | |
2193517f | 62 | return result; |
88d42654 VS |
63 | } |
64 | ||
2193517f | 65 | bool wxr2xml::ParseResources() |
88d42654 | 66 | { |
2193517f | 67 | m_table.BeginFind(); |
99940d1b | 68 | wxHashTable::Node *node; |
2193517f | 69 | |
19d0f58d | 70 | node = m_table.Next(); |
f80ea77b | 71 | while (node) |
2193517f | 72 | { |
19d0f58d | 73 | wxItemResource *res = (wxItemResource *) node->GetData(); |
88d42654 | 74 | wxString resType(res->GetType()); |
19d0f58d | 75 | if (resType == _T("wxDialog")) |
2193517f | 76 | ParseDialog(res); |
19d0f58d | 77 | else if (resType == _T("wxPanel")) |
2193517f | 78 | ParsePanel(res); |
19d0f58d | 79 | else if (resType == _T("wxPanel")) |
2193517f | 80 | ParsePanel(res); |
19d0f58d | 81 | else if (resType == _T("wxMenu")) |
2193517f | 82 | ParseMenuBar(res); |
19d0f58d | 83 | else if (resType == _T("wxBitmap")) |
2193517f VS |
84 | ParseBitmap(res); |
85 | else | |
19d0f58d JS |
86 | wxLogError(_T("Found unsupported resource ") + resType); |
87 | node = m_table.Next(); | |
88d42654 | 88 | } |
f80ea77b | 89 | return true; |
88d42654 VS |
90 | } |
91 | ||
2193517f | 92 | void wxr2xml::ParsePanel(wxItemResource * res) |
88d42654 | 93 | { |
19d0f58d | 94 | m_xmlfile.Write(_T("\t<object class=\"wxPanel\"")); |
2193517f VS |
95 | PanelStuff(res); |
96 | WriteControlInfo(res); | |
19d0f58d | 97 | m_xmlfile.Write(_T("\n")); |
2193517f | 98 | ParseControls(res); |
19d0f58d | 99 | m_xmlfile.Write(_T("\t</object>\n\n")); |
88d42654 VS |
100 | } |
101 | ||
2193517f | 102 | void wxr2xml::ParseDialog(wxItemResource * res) |
88d42654 | 103 | { |
2193517f | 104 | PanelStuff(res); |
19d0f58d | 105 | m_xmlfile.Write(_T("\t<object class=\"wxDialog\"")); |
2193517f VS |
106 | WriteControlInfo(res); |
107 | m_xmlfile.Write(GetTitle(res)); | |
88d42654 | 108 | |
19d0f58d | 109 | m_xmlfile.Write(_T("\n")); |
2193517f | 110 | ParseControls(res); |
19d0f58d | 111 | m_xmlfile.Write(_T("\t</object>\n\n")); |
88d42654 VS |
112 | } |
113 | ||
2193517f | 114 | void wxr2xml::ParseControls(wxItemResource * res) |
88d42654 | 115 | { |
19d0f58d | 116 | wxNode *node = res->GetChildren().GetFirst(); |
f80ea77b | 117 | while (node) |
88d42654 | 118 | { |
19d0f58d | 119 | wxItemResource *res = (wxItemResource *) node->GetData(); |
2193517f | 120 | wxString resType(res->GetType()); |
19d0f58d | 121 | if (resType == _T("wxButton")) |
2193517f | 122 | ParseButton(res); |
19d0f58d JS |
123 | else if ((resType == _T("wxTextCtrl")) | (resType == _T("wxText")) |
124 | | (resType == _T("wxMultiText"))) | |
2193517f | 125 | ParseTextCtrl(res); |
19d0f58d | 126 | else if (resType == _T("wxCheckBox")) |
2193517f | 127 | ParseCheckBox(res); |
19d0f58d | 128 | else if (resType == _T("wxRadioBox")) |
2193517f | 129 | ParseRadioBox(res); |
19d0f58d | 130 | else if (resType == _T("wxListBox")) |
2193517f | 131 | ParseListBox(res); |
19d0f58d | 132 | else if ((resType == _T("wxStaticText")) | (resType == _T("wxMessage"))) |
2193517f | 133 | ParseStaticText(res); |
19d0f58d | 134 | else if (resType == _T("wxChoice")) |
2193517f | 135 | ParseChoice(res); |
19d0f58d | 136 | else if (resType == _T("wxGauge")) |
2193517f | 137 | ParseGauge(res); |
19d0f58d | 138 | else if (resType == _T("wxSlider")) |
2193517f | 139 | ParseSlider(res); |
19d0f58d | 140 | else if (resType == _T("wxComboBox")) |
2193517f | 141 | ParseComboBox(res); |
19d0f58d | 142 | else if (resType == _T("wxRadioButton")) |
2193517f | 143 | ParseRadioButton(res); |
19d0f58d | 144 | else if (resType == _T("wxStaticBitmap")) |
2193517f | 145 | ParseStaticBitmap(res); |
19d0f58d | 146 | else if (resType == _T("wxScrollBar")) |
2193517f | 147 | ParseScrollBar(res); |
19d0f58d | 148 | else if ((resType == _T("wxStaticBox")) | (resType == _T("wxGroupBox"))) |
2193517f | 149 | ParseStaticBox(res); |
19d0f58d | 150 | else if (resType == _T("wxBitmapButton")) |
2193517f VS |
151 | ParseBitmapButton(res); |
152 | else | |
19d0f58d JS |
153 | wxLogError(_T("Found unsupported resource ") + resType); |
154 | node = node->GetNext(); | |
88d42654 VS |
155 | } |
156 | } | |
157 | ||
2193517f | 158 | // Write out basic stuff every control has |
88d42654 | 159 | // name,position,size,bg,fg |
2193517f | 160 | void wxr2xml::WriteControlInfo(wxItemResource * res) |
88d42654 | 161 | { |
2193517f | 162 | m_xmlfile.Write(GenerateName(res)); |
19d0f58d | 163 | m_xmlfile.Write(_T(">\n")); |
2193517f VS |
164 | m_xmlfile.Write(GetPosition(res)); |
165 | m_xmlfile.Write(GetSize(res)); | |
166 | m_xmlfile.Write(GetStyles(res)); | |
167 | WriteFontInfo(res); | |
88d42654 VS |
168 | } |
169 | ||
2193517f | 170 | wxString wxr2xml::GetSize(wxItemResource * res) |
88d42654 | 171 | { |
2193517f VS |
172 | wxString msg; |
173 | if (m_dlgunits) | |
19d0f58d | 174 | msg << _T("\t\t\t\t<size>") << res->GetWidth() << _T(",") << res->GetHeight() << _T("d</size>\n"); |
2193517f | 175 | else |
19d0f58d | 176 | msg << _T("\t\t\t\t<size>") << res->GetWidth() << _T(",") << res->GetHeight() << _T("</size>\n"); |
2193517f | 177 | return msg; |
88d42654 VS |
178 | } |
179 | ||
2193517f | 180 | wxString wxr2xml::GetPosition(wxItemResource * res) |
88d42654 | 181 | { |
2193517f VS |
182 | wxString msg; |
183 | if (m_dlgunits) | |
19d0f58d | 184 | msg << _T("\t\t\t\t<pos>") << res->GetX() << _T(",") << res->GetY() << _T("d</pos>\n"); |
2193517f | 185 | else |
19d0f58d | 186 | msg << _T("\t\t\t\t<pos>") << res->GetX() << _T(",") << res->GetY() << _T("</pos>\n"); |
2193517f | 187 | return msg; |
88d42654 VS |
188 | } |
189 | ||
2193517f | 190 | void wxr2xml::ParseButton(wxItemResource * res) |
88d42654 | 191 | { |
19d0f58d | 192 | m_xmlfile.Write(_T("\t\t\t<object class=\"wxButton\"")); |
2193517f VS |
193 | WriteControlInfo(res); |
194 | m_xmlfile.Write(GetLabel(res)); | |
19d0f58d | 195 | m_xmlfile.Write(_T("\t\t\t</object>\n")); |
88d42654 VS |
196 | } |
197 | ||
2193517f | 198 | void wxr2xml::ParseTextCtrl(wxItemResource * res) |
88d42654 | 199 | { |
19d0f58d | 200 | m_xmlfile.Write(_T("\t\t\t<object class=\"wxTextCtrl\"")); |
2193517f VS |
201 | WriteControlInfo(res); |
202 | m_xmlfile.Write(GetValue4(res)); | |
19d0f58d | 203 | m_xmlfile.Write(_T("\t\t\t</object>\n")); |
88d42654 VS |
204 | |
205 | } | |
206 | ||
2193517f | 207 | wxString wxr2xml::GetTitle(wxItemResource * res) |
88d42654 | 208 | { |
2193517f | 209 | wxString msg; |
19d0f58d | 210 | msg = _T("\t\t\t\t<title>") + res->GetTitle() + _T("</title>"); |
2193517f | 211 | return msg; |
88d42654 VS |
212 | } |
213 | ||
2193517f | 214 | wxString wxr2xml::GetValue4(wxItemResource * res) |
88d42654 | 215 | { |
2193517f | 216 | wxString msg; |
19d0f58d | 217 | msg = _T("\t\t\t\t<value>") + res->GetValue4() + _T("</value>\n"); |
2193517f | 218 | return msg; |
88d42654 VS |
219 | } |
220 | ||
2193517f | 221 | void wxr2xml::ParseCheckBox(wxItemResource * res) |
88d42654 | 222 | { |
19d0f58d | 223 | m_xmlfile.Write(_T("\t\t\t<object class=\"wxCheckBox\"")); |
2193517f VS |
224 | WriteControlInfo(res); |
225 | m_xmlfile.Write(GetLabel(res)); | |
226 | m_xmlfile.Write(GetCheckStatus(res)); | |
19d0f58d | 227 | m_xmlfile.Write(_T("\t\t\t</object>\n")); |
88d42654 VS |
228 | } |
229 | ||
2193517f | 230 | wxString wxr2xml::GetLabel(wxItemResource * res) |
88d42654 | 231 | { |
19d0f58d | 232 | return _T("\t\t\t\t<label>") + res->GetTitle() + _T("</label>\n"); |
88d42654 VS |
233 | } |
234 | ||
2193517f | 235 | void wxr2xml::ParseRadioBox(wxItemResource * res) |
88d42654 | 236 | { |
19d0f58d | 237 | m_xmlfile.Write(_T("\t\t\t<object class=\"wxRadioBox\"")); |
2193517f VS |
238 | WriteControlInfo(res); |
239 | m_xmlfile.Write(GetLabel(res)); | |
240 | // Add radio box items | |
241 | WriteStringList(res); | |
242 | // Value1 | |
243 | m_xmlfile.Write(GetDimension(res)); | |
19d0f58d | 244 | m_xmlfile.Write(_T("\t\t\t</object>\n")); |
88d42654 VS |
245 | } |
246 | ||
2193517f | 247 | void wxr2xml::ParseListBox(wxItemResource * res) |
88d42654 | 248 | { |
19d0f58d | 249 | m_xmlfile.Write(_T("\t\t\t<object class=\"wxListBox\"")); |
2193517f VS |
250 | WriteControlInfo(res); |
251 | WriteStringList(res); | |
19d0f58d | 252 | m_xmlfile.Write(_T("\t\t\t</object>\n")); |
88d42654 VS |
253 | } |
254 | ||
2193517f | 255 | void wxr2xml::ParseStaticText(wxItemResource * res) |
88d42654 | 256 | { |
19d0f58d | 257 | m_xmlfile.Write(_T("\t\t\t<object class=\"wxStaticText\"")); |
2193517f VS |
258 | WriteControlInfo(res); |
259 | m_xmlfile.Write(GetLabel(res)); | |
19d0f58d | 260 | m_xmlfile.Write(_T("\t\t\t</object>\n")); |
88d42654 VS |
261 | } |
262 | ||
2193517f | 263 | void wxr2xml::ParseStaticBox(wxItemResource * res) |
88d42654 | 264 | { |
19d0f58d | 265 | m_xmlfile.Write(_T("\t\t\t<object class=\"wxStaticBox\"")); |
2193517f VS |
266 | WriteControlInfo(res); |
267 | m_xmlfile.Write(GetLabel(res)); | |
19d0f58d | 268 | m_xmlfile.Write(_T("\t\t\t</object>\n")); |
88d42654 VS |
269 | } |
270 | ||
2193517f | 271 | void wxr2xml::WriteStringList(wxItemResource * res) |
88d42654 | 272 | { |
19d0f58d | 273 | m_xmlfile.Write(_T("\t\t\t\t<content>\n")); |
2193517f VS |
274 | for (wxStringListNode * node = res->GetStringValues().GetFirst(); |
275 | node;node = node->GetNext()) { | |
88d42654 | 276 | const wxString s1 = node->GetData(); |
19d0f58d | 277 | m_xmlfile.Write(_T("\t\t\t\t\t<item>") + s1 + _T("</item>\n")); |
88d42654 | 278 | } |
19d0f58d | 279 | m_xmlfile.Write(_T("\t\t\t\t</content>\n")); |
88d42654 VS |
280 | } |
281 | ||
2193517f | 282 | void wxr2xml::ParseChoice(wxItemResource * res) |
88d42654 | 283 | { |
19d0f58d | 284 | m_xmlfile.Write(_T("\t\t\t<object class=\"wxChoice\"")); |
2193517f VS |
285 | WriteControlInfo(res); |
286 | // Add choice items | |
287 | WriteStringList(res); | |
19d0f58d | 288 | m_xmlfile.Write(_T("\t\t\t</object>\n")); |
88d42654 VS |
289 | } |
290 | ||
2193517f | 291 | void wxr2xml::ParseGauge(wxItemResource * res) |
88d42654 | 292 | { |
19d0f58d | 293 | m_xmlfile.Write(_T("\t\t\t<object class=\"wxGauge\"")); |
2193517f VS |
294 | WriteControlInfo(res); |
295 | m_xmlfile.Write(GetValue1(res)); | |
296 | m_xmlfile.Write(GetRange(res)); | |
19d0f58d | 297 | m_xmlfile.Write(_T("\n\t\t\t</object>\n")); |
88d42654 VS |
298 | } |
299 | ||
2193517f | 300 | wxString wxr2xml::GetValue1(wxItemResource * res) |
88d42654 | 301 | { |
2193517f | 302 | wxString msg; |
19d0f58d | 303 | msg << _T("\t\t\t\t<value>") << res->GetValue1() << _T("</value>\n"); |
2193517f | 304 | return msg; |
88d42654 VS |
305 | } |
306 | ||
2193517f | 307 | wxString wxr2xml::GetRange(wxItemResource * res) |
88d42654 | 308 | { |
2193517f | 309 | wxString msg; |
19d0f58d | 310 | msg << _T("\t\t\t\t<range>") << res->GetValue2() << _T("</range>"); |
2193517f | 311 | return msg; |
88d42654 VS |
312 | } |
313 | ||
2193517f | 314 | void wxr2xml::ParseSlider(wxItemResource * res) |
88d42654 | 315 | { |
19d0f58d | 316 | m_xmlfile.Write(_T("\t\t\t<object class=\"wxSlider\"")); |
2193517f VS |
317 | WriteControlInfo(res); |
318 | m_xmlfile.Write(GetValue1(res)); | |
319 | m_xmlfile.Write(GetMax(res)); | |
320 | m_xmlfile.Write(GetMin(res)); | |
19d0f58d | 321 | m_xmlfile.Write(_T("\n\t\t\t</object>\n")); |
88d42654 VS |
322 | } |
323 | ||
2193517f | 324 | wxString wxr2xml::GetMax(wxItemResource * res) |
88d42654 | 325 | { |
2193517f | 326 | wxString msg; |
19d0f58d | 327 | msg << _T("\t\t\t\t<max>") << res->GetValue3() << _T("</max>\n"); |
2193517f | 328 | return msg; |
88d42654 VS |
329 | } |
330 | ||
2193517f | 331 | wxString wxr2xml::GetMin(wxItemResource * res) |
88d42654 | 332 | { |
2193517f | 333 | wxString msg; |
19d0f58d | 334 | msg << _T("\t\t\t\t<min>") << res->GetValue2() << _T("</min>"); |
2193517f | 335 | return msg; |
88d42654 VS |
336 | } |
337 | ||
2193517f | 338 | void wxr2xml::ParseComboBox(wxItemResource * res) |
88d42654 | 339 | { |
19d0f58d | 340 | m_xmlfile.Write(_T("\t\t\t<object class=\"wxComboBox\"")); |
2193517f VS |
341 | WriteControlInfo(res); |
342 | // Add combo items | |
343 | WriteStringList(res); | |
19d0f58d | 344 | m_xmlfile.Write(_T("\n\t\t\t</object>\n")); |
88d42654 VS |
345 | } |
346 | ||
2193517f | 347 | void wxr2xml::ParseRadioButton(wxItemResource * res) |
88d42654 | 348 | { |
19d0f58d | 349 | m_xmlfile.Write(_T("\t\t\t<object class=\"wxRadioButton\"")); |
2193517f VS |
350 | WriteControlInfo(res); |
351 | m_xmlfile.Write(GetLabel(res)); | |
352 | ||
353 | wxString msg; | |
354 | m_xmlfile.Write(GetValue1(res)); | |
355 | m_xmlfile.Write(GetCheckStatus(res)); | |
19d0f58d | 356 | m_xmlfile.Write(_T("\t\t\t</object>\n")); |
2193517f | 357 | } |
88d42654 | 358 | |
2193517f VS |
359 | void wxr2xml::ParseScrollBar(wxItemResource * res) |
360 | { | |
19d0f58d | 361 | m_xmlfile.Write(_T("\t\t\t<object class=\"wxScrollBar\"")); |
2193517f VS |
362 | WriteControlInfo(res); |
363 | m_xmlfile.Write(GetValue1(res)); | |
19d0f58d JS |
364 | m_xmlfile.Write(_T("\t\t\t\t<thumbsize>")+GetValue2(res)+_T("</thumbsize>\n")); |
365 | m_xmlfile.Write(_T("\t\t\t\t<range>")+GetValue3(res)+_T("</range>\n")); | |
366 | m_xmlfile.Write(_T("\t\t\t\t<pagesize>")+GetValue5(res)+_T("</pagesize>\n")); | |
367 | m_xmlfile.Write(_T("\t\t\t</object>\n")); | |
88d42654 VS |
368 | } |
369 | ||
2193517f | 370 | wxString wxr2xml::GetCheckStatus(wxItemResource * res) |
88d42654 | 371 | { |
2193517f | 372 | wxString msg; |
19d0f58d | 373 | msg << _T("\t\t\t\t<checked>") << res->GetValue1() << _T("</checked>\n"); |
2193517f VS |
374 | return msg; |
375 | } | |
88d42654 | 376 | |
2193517f | 377 | wxString wxr2xml::GetStyles(wxItemResource * res) |
88d42654 | 378 | { |
2193517f VS |
379 | // Very crude way to get styles |
380 | long style; | |
381 | wxString s, restype; | |
382 | restype = res->GetType(); | |
383 | style = res->GetStyle(); | |
384 | ||
19d0f58d | 385 | s = _T("\t\t\t\t<style>"); |
2193517f VS |
386 | |
387 | // Common styles for all controls | |
388 | if (style & wxSIMPLE_BORDER) | |
19d0f58d | 389 | s += _T("wxSIMPLE_BORDER|"); |
2193517f | 390 | if (style & wxSUNKEN_BORDER) |
19d0f58d | 391 | s += _T("wxSUNKEN_BORDER|"); |
2193517f | 392 | if (style & wxSIMPLE_BORDER) |
19d0f58d | 393 | s += _T("wxSIMPLE_BORDER|"); |
2193517f | 394 | if (style & wxDOUBLE_BORDER) |
19d0f58d | 395 | s += _T("wxDOUBLE_BORDER|"); |
2193517f | 396 | if (style & wxRAISED_BORDER) |
19d0f58d | 397 | s += _T("wxRAISED_BORDER|"); |
2193517f | 398 | if (style & wxTRANSPARENT_WINDOW) |
19d0f58d | 399 | s += _T("wxTRANSPARENT_WINDOW|"); |
2193517f | 400 | if (style & wxWANTS_CHARS) |
19d0f58d | 401 | s += _T("wxWANTS_CHARS|"); |
2193517f | 402 | if (style & wxNO_FULL_REPAINT_ON_RESIZE) |
19d0f58d | 403 | s += _T("wxNO_FULL_REPAINT_ON_RESIZE|"); |
2193517f | 404 | |
f80ea77b | 405 | if (restype == _T("wxDialog")) |
2193517f VS |
406 | { |
407 | if (style & wxDIALOG_MODAL) | |
19d0f58d | 408 | s += _T("wxDIALOG_MODAL|"); |
2193517f | 409 | if (style & wxDEFAULT_DIALOG_STYLE) |
19d0f58d | 410 | s += _T("wxDEFAULT_DIALOG_STYLE|"); |
2193517f | 411 | if (style & wxDIALOG_MODELESS) |
19d0f58d | 412 | s += _T("wxDIALOG_MODELESS|"); |
2193517f | 413 | if (style & wxNO_3D) |
19d0f58d | 414 | s += _T("wxNO_3D|"); |
2193517f | 415 | if (style & wxTAB_TRAVERSAL) |
19d0f58d | 416 | s += _T("wxTAB_TRAVERSAL|"); |
2193517f | 417 | if (style & wxWS_EX_VALIDATE_RECURSIVELY) |
19d0f58d | 418 | s += _T("wxWS_EX_VALIDATE_RECURSIVELY|"); |
2193517f | 419 | if (style & wxSTAY_ON_TOP) |
19d0f58d | 420 | s += _T("wxSTAY_ON_TOP|"); |
2193517f | 421 | if (style & wxCAPTION) |
19d0f58d | 422 | s += _T("wxCAPTION|"); |
2193517f | 423 | if (style & wxTHICK_FRAME) |
19d0f58d | 424 | s += _T("wxTHICK_FRAME|"); |
2193517f | 425 | if (style & wxRESIZE_BOX) |
19d0f58d | 426 | s += _T("wxRESIZE_BOX|"); |
2193517f | 427 | if (style & wxRESIZE_BORDER) |
19d0f58d | 428 | s += _T("wxRESIZE_BORDER|"); |
2193517f | 429 | if (style & wxSYSTEM_MENU) |
19d0f58d | 430 | s += _T("wxSYSTEM_MENU|"); |
2193517f | 431 | if (style & wxCLIP_CHILDREN) |
19d0f58d | 432 | s += _T("wxCLIP_CHILDREN|"); |
2193517f VS |
433 | } |
434 | ||
f80ea77b | 435 | if (restype == _T("wxPanel")) |
2193517f VS |
436 | { |
437 | if (style & wxCLIP_CHILDREN) | |
19d0f58d | 438 | s += _T("wxCLIP_CHILDREN|"); |
2193517f | 439 | if (style & wxNO_3D) |
19d0f58d | 440 | s += _T("wxNO_3D|"); |
2193517f | 441 | if (style & wxTAB_TRAVERSAL) |
19d0f58d | 442 | s += _T("wxTAB_TRAVERSAL|"); |
2193517f | 443 | if (style & wxWS_EX_VALIDATE_RECURSIVELY) |
19d0f58d | 444 | s += _T("wxWS_EX_VALIDATE_RECURSIVELY|"); |
2193517f VS |
445 | } |
446 | ||
f80ea77b | 447 | if (restype == _T("wxComboBox")) |
2193517f VS |
448 | { |
449 | if (style & wxCB_SORT) | |
19d0f58d | 450 | s += _T("wxCB_SORT|"); |
2193517f | 451 | if (style & wxCB_SIMPLE) |
19d0f58d | 452 | s += _T("wxCB_SIMPLE|"); |
2193517f | 453 | if (style & wxCB_READONLY) |
19d0f58d | 454 | s += _T("wxCB_READONLY|"); |
2193517f | 455 | if (style & wxCB_DROPDOWN) |
19d0f58d | 456 | s += _T("wxCB_DROPDOWN|"); |
2193517f VS |
457 | } |
458 | ||
f80ea77b | 459 | if (restype == _T("wxGauge")) |
2193517f VS |
460 | { |
461 | if (style & wxGA_HORIZONTAL) | |
19d0f58d | 462 | s += _T("wxGA_HORIZONTAL|"); |
2193517f | 463 | if (style & wxGA_VERTICAL) |
19d0f58d | 464 | s += _T("wxGA_VERTICAL|"); |
2193517f | 465 | if (style & wxGA_PROGRESSBAR) |
19d0f58d | 466 | s += _T("wxGA_PROGRESSBAR|"); |
2193517f VS |
467 | // windows only |
468 | if (style & wxGA_SMOOTH) | |
19d0f58d | 469 | s += _T("wxGA_SMOOTH|"); |
2193517f VS |
470 | } |
471 | ||
f80ea77b | 472 | if (restype == _T("wxRadioButton")) |
2193517f VS |
473 | { |
474 | if (style & wxRB_GROUP) | |
19d0f58d | 475 | s += _T("wxRB_GROUP|"); |
2193517f VS |
476 | } |
477 | ||
f80ea77b | 478 | if (restype == _T("wxStaticText")) |
2193517f VS |
479 | { |
480 | if (style & wxST_NO_AUTORESIZE) | |
19d0f58d | 481 | s += _T("wxST_NO_AUTORESIZEL|"); |
2193517f VS |
482 | } |
483 | ||
f80ea77b | 484 | if (restype == _T("wxRadioBox")) |
2193517f VS |
485 | { |
486 | if (style & wxRA_HORIZONTAL) | |
19d0f58d | 487 | s += _T("wxRA_HORIZONTAL|"); |
2193517f | 488 | if (style & wxRA_SPECIFY_COLS) |
19d0f58d | 489 | s += _T("wxRA_SPECIFY_COLS|"); |
2193517f | 490 | if (style & wxRA_SPECIFY_ROWS) |
19d0f58d | 491 | s += _T("wxRA_SPECIFY_ROWS|"); |
2193517f | 492 | if (style & wxRA_VERTICAL) |
19d0f58d | 493 | s += _T("wxRA_VERTICAL|"); |
2193517f VS |
494 | } |
495 | ||
f80ea77b | 496 | if (restype == _T("wxListBox")) |
2193517f VS |
497 | { |
498 | if (style & wxLB_SINGLE) | |
19d0f58d | 499 | s += _T("wxLB_SINGLE|"); |
2193517f | 500 | if (style & wxLB_MULTIPLE) |
19d0f58d | 501 | s += _T("wxLB_MULTIPLE|"); |
2193517f | 502 | if (style & wxLB_EXTENDED) |
19d0f58d | 503 | s += _T("wxLB_EXTENDED|"); |
2193517f | 504 | if (style & wxLB_HSCROLL) |
19d0f58d | 505 | s += _T("wxLB_HSCROLL|"); |
2193517f | 506 | if (style & wxLB_ALWAYS_SB) |
19d0f58d | 507 | s += _T("wxLB_ALWAYS_SB|"); |
2193517f | 508 | if (style & wxLB_NEEDED_SB) |
19d0f58d | 509 | s += _T("wxLB_NEEDED_SB|"); |
2193517f | 510 | if (style & wxLB_SORT) |
19d0f58d | 511 | s += _T("wxLB_SORT|"); |
2193517f VS |
512 | } |
513 | ||
f80ea77b | 514 | if (restype == _T("wxTextCtrl")) |
2193517f VS |
515 | { |
516 | if (style & wxTE_PROCESS_ENTER) | |
19d0f58d | 517 | s += _T("wxTE_PROCESS_ENTER|"); |
2193517f | 518 | if (style & wxTE_PROCESS_TAB) |
19d0f58d | 519 | s += _T("wxTE_PROCESS_TAB|"); |
2193517f | 520 | if (style & wxTE_MULTILINE) |
19d0f58d | 521 | s += _T("wxTE_MULTILINE|"); |
2193517f | 522 | if (style & wxTE_PASSWORD) |
19d0f58d | 523 | s += _T("wxTE_PASSWORD|"); |
2193517f | 524 | if (style & wxTE_READONLY) |
19d0f58d | 525 | s += _T("wxTE_READONLY|"); |
2193517f | 526 | if (style & wxHSCROLL) |
19d0f58d | 527 | s += _T("wxHSCROLL|"); |
2193517f VS |
528 | } |
529 | ||
530 | ||
19d0f58d | 531 | if (restype == _T("wxScrollBar")) |
2193517f VS |
532 | { |
533 | if (style & wxSB_HORIZONTAL) | |
19d0f58d | 534 | s += _T("wxSB_HORIZONTAL|"); |
f80ea77b | 535 | if (style & wxSB_VERTICAL) |
19d0f58d | 536 | s += _T("wxSB_VERTICAL|"); |
2193517f VS |
537 | } |
538 | ||
539 | int l; | |
540 | l = s.Length(); | |
541 | // No styles defined | |
542 | if (l == 11) | |
543 | return _T(""); | |
544 | // Trim off last | | |
545 | s = s.Truncate(l - 1); | |
546 | ||
19d0f58d | 547 | s += _T("</style>\n"); |
2193517f | 548 | return s; |
88d42654 VS |
549 | } |
550 | ||
2193517f | 551 | wxString wxr2xml::GetDimension(wxItemResource * res) |
88d42654 | 552 | { |
2193517f | 553 | wxString msg; |
19d0f58d | 554 | msg << _T("\t\t\t\t<dimension>") << res->GetValue1() << _T("</dimension>\n"); |
2193517f VS |
555 | return msg; |
556 | } | |
88d42654 | 557 | |
2193517f VS |
558 | wxString wxr2xml::GenerateName(wxItemResource * res) |
559 | { | |
560 | wxString name; | |
561 | name = _T(" name=\""); | |
562 | switch (res->GetId()) { | |
563 | case wxID_OK: | |
564 | name += _T("wxID_OK"); | |
565 | break; | |
566 | case wxID_CANCEL: | |
567 | name += _T("wxID_CANCEL"); | |
568 | break; | |
569 | default: | |
570 | name += res->GetName(); | |
571 | } | |
88d42654 | 572 | |
19d0f58d | 573 | name += _T("\""); |
2193517f | 574 | return name; |
88d42654 | 575 | } |
88d42654 | 576 | |
2193517f VS |
577 | void wxr2xml::ParseMenuBar(wxItemResource * res) |
578 | { | |
579 | wxItemResource *child; | |
19d0f58d | 580 | wxNode *node = res->GetChildren().GetFirst(); |
2193517f | 581 | // Get Menu Bar Name |
19d0f58d | 582 | m_xmlfile.Write(_T("\t<object class=\"wxMenuBar\" ")); |
2193517f | 583 | m_xmlfile.Write(GenerateName(res)); |
19d0f58d | 584 | m_xmlfile.Write(_T(">\n")); |
2193517f | 585 | while (node) { |
19d0f58d | 586 | child = (wxItemResource *) node->GetData(); |
2193517f | 587 | ParseMenu(child); |
19d0f58d | 588 | node = node->GetNext(); |
2193517f | 589 | } |
88d42654 | 590 | |
19d0f58d | 591 | m_xmlfile.Write(_T("\t</object> \n\n")); |
2193517f VS |
592 | } |
593 | ||
594 | void wxr2xml::ParseMenu(wxItemResource * res) | |
595 | { | |
596 | wxItemResource *child; | |
19d0f58d | 597 | wxNode *node = res->GetChildren().GetFirst(); |
f80ea77b | 598 | // Get Menu |
19d0f58d | 599 | m_xmlfile.Write(_T("\t\t\t<object class=\"wxMenu\" ")); |
2193517f | 600 | wxString menuname; |
19d0f58d | 601 | menuname << _T("name = \"menu_") << res->GetValue1() << _T("\""); |
2193517f | 602 | m_xmlfile.Write(menuname); |
19d0f58d JS |
603 | m_xmlfile.Write(_T(">\n")); |
604 | m_xmlfile.Write(_T("\t\t\t\t<label>") | |
605 | + FixMenuString(res->GetTitle()) + _T("</label>\n")); | |
606 | if (res->GetValue4() != _T("")) | |
607 | m_xmlfile.Write(_T("\t\t\t\t<help>") + res->GetValue4() + | |
608 | _T("</help>\n")); | |
2193517f VS |
609 | // Read in menu items and additional menus |
610 | while (node) { | |
19d0f58d JS |
611 | child = (wxItemResource *) node->GetData(); |
612 | if (!child->GetChildren().GetFirst()) | |
2193517f VS |
613 | ParseMenuItem(child); |
614 | else | |
615 | ParseMenu(child); | |
19d0f58d | 616 | node = node->GetNext(); |
2193517f | 617 | } |
19d0f58d | 618 | m_xmlfile.Write(_T("\t\t\t</object> \n")); |
2193517f VS |
619 | } |
620 | ||
621 | void wxr2xml::ParseMenuItem(wxItemResource * res) | |
622 | { | |
623 | // Get Menu Item or Separator | |
19d0f58d JS |
624 | if (res->GetTitle() == _T("")) { |
625 | m_xmlfile.Write(_T("\t\t\t<object class=\"separator\"/>\n")); | |
2193517f | 626 | } else { |
19d0f58d | 627 | m_xmlfile.Write(_T("\t\t\t\t<object class=\"wxMenuItem\" ")); |
2193517f | 628 | wxString menuname; |
19d0f58d | 629 | menuname << _T("name = \"menuitem_") << res->GetValue1() << _T("\""); |
2193517f | 630 | m_xmlfile.Write(menuname); |
19d0f58d | 631 | m_xmlfile.Write(_T(">\n")); |
f80ea77b | 632 | m_xmlfile.Write(_T("\t\t\t<label>") |
19d0f58d JS |
633 | + FixMenuString(res->GetTitle()) + _T("</label>\n")); |
634 | if (res->GetValue4() != _T("")) | |
f80ea77b | 635 | m_xmlfile.Write(_T("\t\t\t<help>") + |
19d0f58d | 636 | res->GetValue4() + _T("</help>\n")); |
2193517f | 637 | if (res->GetValue2()) |
19d0f58d JS |
638 | m_xmlfile.Write(_T("\t\t\t\t<checkable>1</checkable>\n")); |
639 | m_xmlfile.Write(_T("\t\t\t</object> \n")); | |
2193517f VS |
640 | } |
641 | } | |
642 | ||
643 | wxString wxr2xml::FixMenuString(wxString phrase) | |
644 | { | |
19d0f58d | 645 | phrase.Replace(_T("&"), _T("$")); |
2193517f VS |
646 | return phrase; |
647 | } | |
648 | ||
649 | void wxr2xml::ParseStaticBitmap(wxItemResource * res) | |
650 | { | |
19d0f58d | 651 | m_xmlfile.Write(_T("\t\t\t<object class=\"wxStaticBitmap\"")); |
2193517f VS |
652 | WriteControlInfo(res); |
653 | // value4 holds bitmap name | |
654 | wxString bitmapname; | |
655 | bitmapname = res->GetValue4(); | |
656 | wxBitmap bitmap; | |
657 | bitmap = wxResourceCreateBitmap(bitmapname, &m_table); | |
658 | bitmapname += _T(".bmp"); | |
659 | bitmap.SaveFile(bitmapname, wxBITMAP_TYPE_BMP); | |
19d0f58d JS |
660 | m_xmlfile.Write(_T("\n\t\t\t\t<bitmap>") + bitmapname + _T("</bitmap>")); |
661 | m_xmlfile.Write(_T("\t\t\t</object>\n")); | |
2193517f VS |
662 | // bitmap5 |
663 | } | |
664 | //Parse a bitmap resource | |
665 | void wxr2xml::ParseBitmap(wxItemResource * res) | |
666 | { | |
19d0f58d JS |
667 | m_xmlfile.Write(_T("\t<object class=\"wxBitmap\" ")); |
668 | m_xmlfile.Write(GenerateName(res)+_T(">")); | |
2193517f VS |
669 | wxString bitmapname; |
670 | bitmapname = res->GetName(); | |
671 | wxBitmap bitmap; | |
672 | bitmap = wxResourceCreateBitmap(bitmapname, &m_table); | |
673 | bitmapname += _T(".bmp"); | |
674 | bitmap.SaveFile(bitmapname, wxBITMAP_TYPE_BMP); | |
675 | m_xmlfile.Write(bitmapname); | |
19d0f58d | 676 | m_xmlfile.Write(_T("</object>\n\n")); |
88d42654 VS |
677 | } |
678 | ||
2193517f | 679 | void wxr2xml::PanelStuff(wxItemResource * res) |
88d42654 | 680 | { |
2193517f | 681 | if ((res->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0) |
f80ea77b | 682 | m_dlgunits = true; |
2193517f | 683 | else |
f80ea77b | 684 | m_dlgunits = false; |
2193517f VS |
685 | |
686 | // If this is true ignore fonts, background color and use system | |
687 | // defaults instead | |
688 | if ((res->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS) != 0) | |
f80ea77b | 689 | m_systemdefaults = true; |
2193517f | 690 | else |
f80ea77b | 691 | m_systemdefaults = false; |
2193517f VS |
692 | |
693 | } | |
694 | ||
695 | wxString wxr2xml::GetValue2(wxItemResource *res) | |
696 | { | |
697 | wxString msg; | |
698 | msg << res->GetValue2(); | |
699 | return msg; | |
88d42654 VS |
700 | } |
701 | ||
2193517f | 702 | wxString wxr2xml::GetValue3(wxItemResource *res) |
88d42654 | 703 | { |
2193517f VS |
704 | wxString msg; |
705 | msg << res->GetValue3(); | |
706 | return msg; | |
707 | ||
88d42654 VS |
708 | } |
709 | ||
2193517f | 710 | wxString wxr2xml::GetValue5(wxItemResource *res) |
88d42654 | 711 | { |
2193517f VS |
712 | wxString msg; |
713 | msg << res->GetValue5(); | |
714 | return msg; | |
715 | ||
88d42654 VS |
716 | } |
717 | ||
2193517f | 718 | void wxr2xml::ParseBitmapButton(wxItemResource *res) |
88d42654 | 719 | { |
f80ea77b | 720 | |
19d0f58d | 721 | m_xmlfile.Write(_T("\t\t\t<object class=\"wxBitmapButton\"")); |
2193517f VS |
722 | WriteControlInfo(res); |
723 | // value4 holds bitmap name | |
724 | wxString bitmapname; | |
725 | bitmapname = res->GetValue4(); | |
726 | wxBitmap bitmap; | |
727 | bitmap = wxResourceCreateBitmap(bitmapname, &m_table); | |
728 | bitmapname += _T(".bmp"); | |
729 | bitmap.SaveFile(bitmapname, wxBITMAP_TYPE_BMP); | |
19d0f58d | 730 | m_xmlfile.Write(_T("\t\t\t\t<bitmap>") + bitmapname + _T("</bitmap>\n")); |
f80ea77b | 731 | |
19d0f58d | 732 | m_xmlfile.Write(_T("\t\t\t</object>\n")); |
2193517f VS |
733 | } |
734 | ||
735 | void wxr2xml::WriteFontInfo(wxItemResource *res) | |
736 | { | |
737 | //if systems_defaults true just ignore the fonts | |
738 | if (m_systemdefaults) | |
739 | return; | |
740 | wxFont font; | |
741 | font=res->GetFont(); | |
742 | if (!font.GetRefData()) | |
743 | return; | |
744 | ||
19d0f58d | 745 | m_xmlfile.Write(_T("\t\t\t<font>\n")); |
2193517f VS |
746 | //Get font point size,font family,weight,font style,underline |
747 | int pt; | |
748 | wxString msg; | |
749 | pt=font.GetPointSize(); | |
19d0f58d | 750 | msg<<_T("\t\t\t\t<size>")<<pt<<_T("</size>\n"); |
2193517f VS |
751 | m_xmlfile.Write(msg); |
752 | GetFontFace(font); | |
753 | GetFontStyle(font); | |
754 | GetFontWeight(font); | |
f80ea77b | 755 | |
2193517f | 756 | if (font.GetUnderlined()) |
19d0f58d | 757 | m_xmlfile.Write(_T("\t\t\t\t<underlined>1</underlined>\n")); |
f80ea77b | 758 | |
19d0f58d | 759 | m_xmlfile.Write(_T("\t\t\t</font>\n")); |
2193517f | 760 | } |
88d42654 | 761 | |
2193517f VS |
762 | //WARNING possible make here |
763 | //I wasn't really sure the right way to do this. | |
764 | void wxr2xml::GetFontFace(wxFont font) | |
765 | { | |
766 | int family=font.GetFamily(); | |
f80ea77b | 767 | |
2193517f VS |
768 | switch (family) |
769 | { | |
770 | case wxDEFAULT: | |
771 | break; | |
772 | case wxDECORATIVE: | |
19d0f58d | 773 | m_xmlfile.Write(_T("\t\t\t\t<face>decorative</face>\n")); |
2193517f VS |
774 | break; |
775 | case wxROMAN: | |
19d0f58d | 776 | m_xmlfile.Write(_T("\t\t\t\t<face>roman</face>\n")); |
2193517f VS |
777 | break; |
778 | case wxSCRIPT: | |
19d0f58d | 779 | m_xmlfile.Write(_T("\t\t\t\t<face>script</face>\n")); |
2193517f VS |
780 | break; |
781 | case wxSWISS: | |
19d0f58d | 782 | m_xmlfile.Write(_T("\t\t\t\t<face>swiss</face>\n")); |
2193517f VS |
783 | break; |
784 | case wxMODERN: | |
19d0f58d | 785 | m_xmlfile.Write(_T("\t\t\t\t<face>modern</face>\n")); |
2193517f VS |
786 | break; |
787 | default: | |
19d0f58d | 788 | wxLogError(_T("Unknown font face")); |
2193517f | 789 | } |
88d42654 VS |
790 | } |
791 | ||
2193517f | 792 | void wxr2xml::GetFontStyle(wxFont font) |
88d42654 | 793 | { |
88d42654 | 794 | |
2193517f VS |
795 | int style=font.GetStyle(); |
796 | ||
797 | switch (style) | |
798 | { | |
799 | //since this is default no point in making file any larger | |
800 | case wxNORMAL: | |
801 | break; | |
802 | case wxITALIC: | |
19d0f58d | 803 | m_xmlfile.Write(_T("<style>italic</style>\n")); |
2193517f VS |
804 | break; |
805 | case wxSLANT: | |
19d0f58d | 806 | m_xmlfile.Write(_T("<style>slant</style>\n")); |
2193517f VS |
807 | break; |
808 | default: | |
19d0f58d | 809 | wxLogError(_T("Unknown font style")); |
2193517f VS |
810 | } |
811 | } | |
812 | ||
813 | void wxr2xml::GetFontWeight(wxFont font) | |
814 | { | |
815 | int weight=font.GetWeight(); | |
88d42654 | 816 | |
2193517f VS |
817 | switch (weight) |
818 | { | |
819 | //since this is default no point in making file any larger | |
820 | case wxNORMAL: | |
821 | break; | |
822 | case wxLIGHT: | |
19d0f58d | 823 | m_xmlfile.Write(_T("\t\t\t\t<weight>light</weight>\n")); |
2193517f VS |
824 | break; |
825 | case wxBOLD: | |
19d0f58d | 826 | m_xmlfile.Write(_T("\t\t\t\t<weight>bold</weight>\n")); |
2193517f VS |
827 | break; |
828 | default: | |
19d0f58d | 829 | wxLogError(_T("Unknown font weight")); |
2193517f | 830 | } |
88d42654 | 831 | } |