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