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