]> git.saurik.com Git - wxWidgets.git/blob - contrib/utils/convertrc/wxr2xml.cpp
added newline
[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 #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
31 // ////////////////////////////////////////////////////////////////////
32 // Construction/Destruction
33 // ////////////////////////////////////////////////////////////////////
34
35 wxr2xml::wxr2xml()
36 {
37
38 }
39
40 wxr2xml::~wxr2xml()
41 {
42
43 }
44
45 bool wxr2xml::Convert(wxString wxrfile, wxString xmlfile)
46 {
47 bool result;
48 result = m_xmlfile.Open(xmlfile.c_str(), _T("w+t"));
49 wxASSERT_MSG(result, _T("Couldn't create XML file"));
50 if (!result)
51 return FALSE;
52
53 result = m_table.ParseResourceFile(wxrfile);
54 wxASSERT_MSG(result, _T("Couldn't Load WXR file"));
55 if (!result)
56 return FALSE;
57 // Write basic xml header
58 m_xmlfile.Write(_T("<?xml version=\"1.0\" ?>\n"));
59 m_xmlfile.Write(_T("<resource>\n"));
60 result = ParseResources();
61 m_xmlfile.Write(_T("</resource>\n"));
62
63 m_xmlfile.Close();
64
65 return result;
66 }
67
68 bool wxr2xml::ParseResources()
69 {
70 m_table.BeginFind();
71 wxNode *node;
72
73 node = m_table.Next();
74 while (node)
75 {
76 wxItemResource *res = (wxItemResource *) node->GetData();
77 wxString resType(res->GetType());
78 if (resType == _T("wxDialog"))
79 ParseDialog(res);
80 else if (resType == _T("wxPanel"))
81 ParsePanel(res);
82 else if (resType == _T("wxPanel"))
83 ParsePanel(res);
84 else if (resType == _T("wxMenu"))
85 ParseMenuBar(res);
86 else if (resType == _T("wxBitmap"))
87 ParseBitmap(res);
88 else
89 wxLogError(_T("Found unsupported resource ") + resType);
90 node = m_table.Next();
91 }
92 return TRUE;
93 }
94
95 void wxr2xml::ParsePanel(wxItemResource * res)
96 {
97 m_xmlfile.Write(_T("\t<object class=\"wxPanel\""));
98 PanelStuff(res);
99 WriteControlInfo(res);
100 m_xmlfile.Write(_T("\n"));
101 ParseControls(res);
102 m_xmlfile.Write(_T("\t</object>\n\n"));
103 }
104
105 void wxr2xml::ParseDialog(wxItemResource * res)
106 {
107 PanelStuff(res);
108 m_xmlfile.Write(_T("\t<object class=\"wxDialog\""));
109 WriteControlInfo(res);
110 m_xmlfile.Write(GetTitle(res));
111
112 m_xmlfile.Write(_T("\n"));
113 ParseControls(res);
114 m_xmlfile.Write(_T("\t</object>\n\n"));
115 }
116
117 void wxr2xml::ParseControls(wxItemResource * res)
118 {
119 wxNode *node = res->GetChildren().GetFirst();
120 while (node)
121 {
122 wxItemResource *res = (wxItemResource *) node->GetData();
123 wxString resType(res->GetType());
124 if (resType == _T("wxButton"))
125 ParseButton(res);
126 else if ((resType == _T("wxTextCtrl")) | (resType == _T("wxText"))
127 | (resType == _T("wxMultiText")))
128 ParseTextCtrl(res);
129 else if (resType == _T("wxCheckBox"))
130 ParseCheckBox(res);
131 else if (resType == _T("wxRadioBox"))
132 ParseRadioBox(res);
133 else if (resType == _T("wxListBox"))
134 ParseListBox(res);
135 else if ((resType == _T("wxStaticText")) | (resType == _T("wxMessage")))
136 ParseStaticText(res);
137 else if (resType == _T("wxChoice"))
138 ParseChoice(res);
139 else if (resType == _T("wxGauge"))
140 ParseGauge(res);
141 else if (resType == _T("wxSlider"))
142 ParseSlider(res);
143 else if (resType == _T("wxComboBox"))
144 ParseComboBox(res);
145 else if (resType == _T("wxRadioButton"))
146 ParseRadioButton(res);
147 else if (resType == _T("wxStaticBitmap"))
148 ParseStaticBitmap(res);
149 else if (resType == _T("wxScrollBar"))
150 ParseScrollBar(res);
151 else if ((resType == _T("wxStaticBox")) | (resType == _T("wxGroupBox")))
152 ParseStaticBox(res);
153 else if (resType == _T("wxBitmapButton"))
154 ParseBitmapButton(res);
155 else
156 wxLogError(_T("Found unsupported resource ") + resType);
157 node = node->GetNext();
158 }
159 }
160
161 // Write out basic stuff every control has
162 // name,position,size,bg,fg
163 void wxr2xml::WriteControlInfo(wxItemResource * res)
164 {
165 m_xmlfile.Write(GenerateName(res));
166 m_xmlfile.Write(_T(">\n"));
167 m_xmlfile.Write(GetPosition(res));
168 m_xmlfile.Write(GetSize(res));
169 m_xmlfile.Write(GetStyles(res));
170 WriteFontInfo(res);
171 }
172
173 wxString wxr2xml::GetSize(wxItemResource * res)
174 {
175 wxString msg;
176 if (m_dlgunits)
177 msg << _T("\t\t\t\t<size>") << res->GetWidth() << _T(",") << res->GetHeight() << _T("d</size>\n");
178 else
179 msg << _T("\t\t\t\t<size>") << res->GetWidth() << _T(",") << res->GetHeight() << _T("</size>\n");
180 return msg;
181 }
182
183 wxString wxr2xml::GetPosition(wxItemResource * res)
184 {
185 wxString msg;
186 if (m_dlgunits)
187 msg << _T("\t\t\t\t<pos>") << res->GetX() << _T(",") << res->GetY() << _T("d</pos>\n");
188 else
189 msg << _T("\t\t\t\t<pos>") << res->GetX() << _T(",") << res->GetY() << _T("</pos>\n");
190 return msg;
191 }
192
193 void wxr2xml::ParseButton(wxItemResource * res)
194 {
195 m_xmlfile.Write(_T("\t\t\t<object class=\"wxButton\""));
196 WriteControlInfo(res);
197 m_xmlfile.Write(GetLabel(res));
198 m_xmlfile.Write(_T("\t\t\t</object>\n"));
199 }
200
201 void wxr2xml::ParseTextCtrl(wxItemResource * res)
202 {
203 m_xmlfile.Write(_T("\t\t\t<object class=\"wxTextCtrl\""));
204 WriteControlInfo(res);
205 m_xmlfile.Write(GetValue4(res));
206 m_xmlfile.Write(_T("\t\t\t</object>\n"));
207
208 }
209
210 wxString wxr2xml::GetTitle(wxItemResource * res)
211 {
212 wxString msg;
213 msg = _T("\t\t\t\t<title>") + res->GetTitle() + _T("</title>");
214 return msg;
215 }
216
217 wxString wxr2xml::GetValue4(wxItemResource * res)
218 {
219 wxString msg;
220 msg = _T("\t\t\t\t<value>") + res->GetValue4() + _T("</value>\n");
221 return msg;
222 }
223
224 void wxr2xml::ParseCheckBox(wxItemResource * res)
225 {
226 m_xmlfile.Write(_T("\t\t\t<object class=\"wxCheckBox\""));
227 WriteControlInfo(res);
228 m_xmlfile.Write(GetLabel(res));
229 m_xmlfile.Write(GetCheckStatus(res));
230 m_xmlfile.Write(_T("\t\t\t</object>\n"));
231 }
232
233 wxString wxr2xml::GetLabel(wxItemResource * res)
234 {
235 return _T("\t\t\t\t<label>") + res->GetTitle() + _T("</label>\n");
236 }
237
238 void wxr2xml::ParseRadioBox(wxItemResource * res)
239 {
240 m_xmlfile.Write(_T("\t\t\t<object class=\"wxRadioBox\""));
241 WriteControlInfo(res);
242 m_xmlfile.Write(GetLabel(res));
243 // Add radio box items
244 WriteStringList(res);
245 // Value1
246 m_xmlfile.Write(GetDimension(res));
247 m_xmlfile.Write(_T("\t\t\t</object>\n"));
248 }
249
250 void wxr2xml::ParseListBox(wxItemResource * res)
251 {
252 m_xmlfile.Write(_T("\t\t\t<object class=\"wxListBox\""));
253 WriteControlInfo(res);
254 WriteStringList(res);
255 m_xmlfile.Write(_T("\t\t\t</object>\n"));
256 }
257
258 void wxr2xml::ParseStaticText(wxItemResource * res)
259 {
260 m_xmlfile.Write(_T("\t\t\t<object class=\"wxStaticText\""));
261 WriteControlInfo(res);
262 m_xmlfile.Write(GetLabel(res));
263 m_xmlfile.Write(_T("\t\t\t</object>\n"));
264 }
265
266 void wxr2xml::ParseStaticBox(wxItemResource * res)
267 {
268 m_xmlfile.Write(_T("\t\t\t<object class=\"wxStaticBox\""));
269 WriteControlInfo(res);
270 m_xmlfile.Write(GetLabel(res));
271 m_xmlfile.Write(_T("\t\t\t</object>\n"));
272 }
273
274 void wxr2xml::WriteStringList(wxItemResource * res)
275 {
276 m_xmlfile.Write(_T("\t\t\t\t<content>\n"));
277 for (wxStringListNode * node = res->GetStringValues().GetFirst();
278 node;node = node->GetNext()) {
279 const wxString s1 = node->GetData();
280 m_xmlfile.Write(_T("\t\t\t\t\t<item>") + s1 + _T("</item>\n"));
281 }
282 m_xmlfile.Write(_T("\t\t\t\t</content>\n"));
283 }
284
285 void wxr2xml::ParseChoice(wxItemResource * res)
286 {
287 m_xmlfile.Write(_T("\t\t\t<object class=\"wxChoice\""));
288 WriteControlInfo(res);
289 // Add choice items
290 WriteStringList(res);
291 m_xmlfile.Write(_T("\t\t\t</object>\n"));
292 }
293
294 void wxr2xml::ParseGauge(wxItemResource * res)
295 {
296 m_xmlfile.Write(_T("\t\t\t<object class=\"wxGauge\""));
297 WriteControlInfo(res);
298 m_xmlfile.Write(GetValue1(res));
299 m_xmlfile.Write(GetRange(res));
300 m_xmlfile.Write(_T("\n\t\t\t</object>\n"));
301 }
302
303 wxString wxr2xml::GetValue1(wxItemResource * res)
304 {
305 wxString msg;
306 msg << _T("\t\t\t\t<value>") << res->GetValue1() << _T("</value>\n");
307 return msg;
308 }
309
310 wxString wxr2xml::GetRange(wxItemResource * res)
311 {
312 wxString msg;
313 msg << _T("\t\t\t\t<range>") << res->GetValue2() << _T("</range>");
314 return msg;
315 }
316
317 void wxr2xml::ParseSlider(wxItemResource * res)
318 {
319 m_xmlfile.Write(_T("\t\t\t<object class=\"wxSlider\""));
320 WriteControlInfo(res);
321 m_xmlfile.Write(GetValue1(res));
322 m_xmlfile.Write(GetMax(res));
323 m_xmlfile.Write(GetMin(res));
324 m_xmlfile.Write(_T("\n\t\t\t</object>\n"));
325 }
326
327 wxString wxr2xml::GetMax(wxItemResource * res)
328 {
329 wxString msg;
330 msg << _T("\t\t\t\t<max>") << res->GetValue3() << _T("</max>\n");
331 return msg;
332 }
333
334 wxString wxr2xml::GetMin(wxItemResource * res)
335 {
336 wxString msg;
337 msg << _T("\t\t\t\t<min>") << res->GetValue2() << _T("</min>");
338 return msg;
339 }
340
341 void wxr2xml::ParseComboBox(wxItemResource * res)
342 {
343 m_xmlfile.Write(_T("\t\t\t<object class=\"wxComboBox\""));
344 WriteControlInfo(res);
345 // Add combo items
346 WriteStringList(res);
347 m_xmlfile.Write(_T("\n\t\t\t</object>\n"));
348 }
349
350 void wxr2xml::ParseRadioButton(wxItemResource * res)
351 {
352 m_xmlfile.Write(_T("\t\t\t<object class=\"wxRadioButton\""));
353 WriteControlInfo(res);
354 m_xmlfile.Write(GetLabel(res));
355
356 wxString msg;
357 m_xmlfile.Write(GetValue1(res));
358 m_xmlfile.Write(GetCheckStatus(res));
359 m_xmlfile.Write(_T("\t\t\t</object>\n"));
360 }
361
362 void wxr2xml::ParseScrollBar(wxItemResource * res)
363 {
364 m_xmlfile.Write(_T("\t\t\t<object class=\"wxScrollBar\""));
365 WriteControlInfo(res);
366 m_xmlfile.Write(GetValue1(res));
367 m_xmlfile.Write(_T("\t\t\t\t<thumbsize>")+GetValue2(res)+_T("</thumbsize>\n"));
368 m_xmlfile.Write(_T("\t\t\t\t<range>")+GetValue3(res)+_T("</range>\n"));
369 m_xmlfile.Write(_T("\t\t\t\t<pagesize>")+GetValue5(res)+_T("</pagesize>\n"));
370 m_xmlfile.Write(_T("\t\t\t</object>\n"));
371 }
372
373 wxString wxr2xml::GetCheckStatus(wxItemResource * res)
374 {
375 wxString msg;
376 msg << _T("\t\t\t\t<checked>") << res->GetValue1() << _T("</checked>\n");
377 return msg;
378 }
379
380 wxString wxr2xml::GetStyles(wxItemResource * res)
381 {
382 // Very crude way to get styles
383 long style;
384 wxString s, restype;
385 restype = res->GetType();
386 style = res->GetStyle();
387
388 s = _T("\t\t\t\t<style>");
389
390 // Common styles for all controls
391 if (style & wxSIMPLE_BORDER)
392 s += _T("wxSIMPLE_BORDER|");
393 if (style & wxSUNKEN_BORDER)
394 s += _T("wxSUNKEN_BORDER|");
395 if (style & wxSIMPLE_BORDER)
396 s += _T("wxSIMPLE_BORDER|");
397 if (style & wxDOUBLE_BORDER)
398 s += _T("wxDOUBLE_BORDER|");
399 if (style & wxRAISED_BORDER)
400 s += _T("wxRAISED_BORDER|");
401 if (style & wxTRANSPARENT_WINDOW)
402 s += _T("wxTRANSPARENT_WINDOW|");
403 if (style & wxWANTS_CHARS)
404 s += _T("wxWANTS_CHARS|");
405 if (style & wxNO_FULL_REPAINT_ON_RESIZE)
406 s += _T("wxNO_FULL_REPAINT_ON_RESIZE|");
407
408 if (restype == _T("wxDialog"))
409 {
410 if (style & wxDIALOG_MODAL)
411 s += _T("wxDIALOG_MODAL|");
412 if (style & wxDEFAULT_DIALOG_STYLE)
413 s += _T("wxDEFAULT_DIALOG_STYLE|");
414 if (style & wxDIALOG_MODELESS)
415 s += _T("wxDIALOG_MODELESS|");
416 if (style & wxNO_3D)
417 s += _T("wxNO_3D|");
418 if (style & wxTAB_TRAVERSAL)
419 s += _T("wxTAB_TRAVERSAL|");
420 if (style & wxWS_EX_VALIDATE_RECURSIVELY)
421 s += _T("wxWS_EX_VALIDATE_RECURSIVELY|");
422 if (style & wxSTAY_ON_TOP)
423 s += _T("wxSTAY_ON_TOP|");
424 if (style & wxCAPTION)
425 s += _T("wxCAPTION|");
426 if (style & wxTHICK_FRAME)
427 s += _T("wxTHICK_FRAME|");
428 if (style & wxRESIZE_BOX)
429 s += _T("wxRESIZE_BOX|");
430 if (style & wxRESIZE_BORDER)
431 s += _T("wxRESIZE_BORDER|");
432 if (style & wxSYSTEM_MENU)
433 s += _T("wxSYSTEM_MENU|");
434 if (style & wxCLIP_CHILDREN)
435 s += _T("wxCLIP_CHILDREN|");
436 }
437
438 if (restype == _T("wxPanel"))
439 {
440 if (style & wxCLIP_CHILDREN)
441 s += _T("wxCLIP_CHILDREN|");
442 if (style & wxNO_3D)
443 s += _T("wxNO_3D|");
444 if (style & wxTAB_TRAVERSAL)
445 s += _T("wxTAB_TRAVERSAL|");
446 if (style & wxWS_EX_VALIDATE_RECURSIVELY)
447 s += _T("wxWS_EX_VALIDATE_RECURSIVELY|");
448 }
449
450 if (restype == _T("wxComboBox"))
451 {
452 if (style & wxCB_SORT)
453 s += _T("wxCB_SORT|");
454 if (style & wxCB_SIMPLE)
455 s += _T("wxCB_SIMPLE|");
456 if (style & wxCB_READONLY)
457 s += _T("wxCB_READONLY|");
458 if (style & wxCB_DROPDOWN)
459 s += _T("wxCB_DROPDOWN|");
460 }
461
462 if (restype == _T("wxGauge"))
463 {
464 if (style & wxGA_HORIZONTAL)
465 s += _T("wxGA_HORIZONTAL|");
466 if (style & wxGA_VERTICAL)
467 s += _T("wxGA_VERTICAL|");
468 if (style & wxGA_PROGRESSBAR)
469 s += _T("wxGA_PROGRESSBAR|");
470 // windows only
471 if (style & wxGA_SMOOTH)
472 s += _T("wxGA_SMOOTH|");
473 }
474
475 if (restype == _T("wxRadioButton"))
476 {
477 if (style & wxRB_GROUP)
478 s += _T("wxRB_GROUP|");
479 }
480
481 if (restype == _T("wxStaticText"))
482 {
483 if (style & wxST_NO_AUTORESIZE)
484 s += _T("wxST_NO_AUTORESIZEL|");
485 }
486
487 if (restype == _T("wxRadioBox"))
488 {
489 if (style & wxRA_HORIZONTAL)
490 s += _T("wxRA_HORIZONTAL|");
491 if (style & wxRA_SPECIFY_COLS)
492 s += _T("wxRA_SPECIFY_COLS|");
493 if (style & wxRA_SPECIFY_ROWS)
494 s += _T("wxRA_SPECIFY_ROWS|");
495 if (style & wxRA_VERTICAL)
496 s += _T("wxRA_VERTICAL|");
497 }
498
499 if (restype == _T("wxListBox"))
500 {
501 if (style & wxLB_SINGLE)
502 s += _T("wxLB_SINGLE|");
503 if (style & wxLB_MULTIPLE)
504 s += _T("wxLB_MULTIPLE|");
505 if (style & wxLB_EXTENDED)
506 s += _T("wxLB_EXTENDED|");
507 if (style & wxLB_HSCROLL)
508 s += _T("wxLB_HSCROLL|");
509 if (style & wxLB_ALWAYS_SB)
510 s += _T("wxLB_ALWAYS_SB|");
511 if (style & wxLB_NEEDED_SB)
512 s += _T("wxLB_NEEDED_SB|");
513 if (style & wxLB_SORT)
514 s += _T("wxLB_SORT|");
515 }
516
517 if (restype == _T("wxTextCtrl"))
518 {
519 if (style & wxTE_PROCESS_ENTER)
520 s += _T("wxTE_PROCESS_ENTER|");
521 if (style & wxTE_PROCESS_TAB)
522 s += _T("wxTE_PROCESS_TAB|");
523 if (style & wxTE_MULTILINE)
524 s += _T("wxTE_MULTILINE|");
525 if (style & wxTE_PASSWORD)
526 s += _T("wxTE_PASSWORD|");
527 if (style & wxTE_READONLY)
528 s += _T("wxTE_READONLY|");
529 if (style & wxHSCROLL)
530 s += _T("wxHSCROLL|");
531 }
532
533
534 if (restype == _T("wxScrollBar"))
535 {
536 if (style & wxSB_HORIZONTAL)
537 s += _T("wxSB_HORIZONTAL|");
538 if (style & wxSB_VERTICAL)
539 s += _T("wxSB_VERTICAL|");
540 }
541
542 int l;
543 l = s.Length();
544 // No styles defined
545 if (l == 11)
546 return _T("");
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() != _T(""))
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() == _T("")) {
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(" <label>")
636 + FixMenuString(res->GetTitle()) + _T("</label>\n"));
637 if (res->GetValue4() != _T(""))
638 m_xmlfile.Write(_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 }