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