]> git.saurik.com Git - wxWidgets.git/blame_incremental - contrib/utils/convertrc/wxr2xml.cpp
renamed resource.xml to resource.xrc
[wxWidgets.git] / contrib / utils / convertrc / wxr2xml.cpp
... / ...
CommitLineData
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/*
8How to use class:
9#include "wxr2xml.h"
10...
11wxr2xml trans;
12trans->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
35wxr2xml::wxr2xml()
36{
37
38}
39
40wxr2xml::~wxr2xml()
41{
42
43}
44
45bool wxr2xml::Convert(wxString wxrfile, wxString xmlfile)
46{
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;
52
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");
62
63 m_xmlfile.Close();
64
65 return result;
66}
67
68bool wxr2xml::ParseResources()
69{
70 m_table.BeginFind();
71 wxNode *node;
72
73 while ((node = m_table.Next()))
74 {
75 wxItemResource *res = (wxItemResource *) node->Data();
76 wxString resType(res->GetType());
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);
89 }
90 return TRUE;
91}
92
93void wxr2xml::ParsePanel(wxItemResource * res)
94{
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");
103}
104
105void wxr2xml::ParseDialog(wxItemResource * res)
106{
107 PanelStuff(res);
108 m_xmlfile.Write("\t<dialog");
109 WriteControlInfo(res);
110 m_xmlfile.Write(GetTitle(res));
111
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");
117}
118
119void wxr2xml::ParseControls(wxItemResource * res)
120{
121 wxNode *node = res->GetChildren().First();
122 while (node)
123 {
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();
160 }
161}
162
163// Write out basic stuff every control has
164// name,position,size,bg,fg
165void wxr2xml::WriteControlInfo(wxItemResource * res)
166{
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);
173}
174
175wxString wxr2xml::GetSize(wxItemResource * res)
176{
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;
183}
184
185wxString wxr2xml::GetPosition(wxItemResource * res)
186{
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;
193}
194
195void wxr2xml::ParseButton(wxItemResource * res)
196{
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");
201}
202
203void wxr2xml::ParseTextCtrl(wxItemResource * res)
204{
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");
209
210}
211
212wxString wxr2xml::GetTitle(wxItemResource * res)
213{
214 wxString msg;
215 msg = _T("\t\t\t\t<title>" + res->GetTitle() + "</title>");
216 return msg;
217}
218
219wxString wxr2xml::GetValue4(wxItemResource * res)
220{
221 wxString msg;
222 msg = _T("\t\t\t\t<value>" + res->GetValue4() + "</value>\n");
223 return msg;
224}
225
226void wxr2xml::ParseCheckBox(wxItemResource * res)
227{
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");
233}
234
235wxString wxr2xml::GetLabel(wxItemResource * res)
236{
237 return _T("\t\t\t\t<label>" + res->GetTitle() + "</label>\n");
238}
239
240void wxr2xml::ParseRadioBox(wxItemResource * res)
241{
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");
250}
251
252void wxr2xml::ParseListBox(wxItemResource * res)
253{
254 m_xmlfile.Write("\t\t\t<listbox");
255 WriteControlInfo(res);
256 WriteStringList(res);
257 m_xmlfile.Write("\t\t\t</listbox>\n");
258}
259
260void wxr2xml::ParseStaticText(wxItemResource * res)
261{
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");
266}
267
268void wxr2xml::ParseStaticBox(wxItemResource * res)
269{
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");
274}
275
276void wxr2xml::WriteStringList(wxItemResource * res)
277{
278 m_xmlfile.Write("\t\t\t\t<content>\n");
279 for (wxStringListNode * node = res->GetStringValues().GetFirst();
280 node;node = node->GetNext()) {
281 const wxString s1 = node->GetData();
282 m_xmlfile.Write("\t\t\t\t\t<item>" + s1 + "</item>\n");
283 }
284 m_xmlfile.Write("\t\t\t\t</content>\n");
285}
286
287void wxr2xml::ParseChoice(wxItemResource * res)
288{
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");
294}
295
296void wxr2xml::ParseGauge(wxItemResource * res)
297{
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");
303}
304
305wxString wxr2xml::GetValue1(wxItemResource * res)
306{
307 wxString msg;
308 msg << "\t\t\t\t<value>" << res->GetValue1() << "</value>\n";
309 return msg;
310}
311
312wxString wxr2xml::GetRange(wxItemResource * res)
313{
314 wxString msg;
315 msg << "\t\t\t\t<range>" << res->GetValue2() << "</range>";
316 return msg;
317}
318
319void wxr2xml::ParseSlider(wxItemResource * res)
320{
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");
327}
328
329wxString wxr2xml::GetMax(wxItemResource * res)
330{
331 wxString msg;
332 msg << "\t\t\t\t<max>" << res->GetValue3() << "</max>\n";
333 return msg;
334}
335
336wxString wxr2xml::GetMin(wxItemResource * res)
337{
338 wxString msg;
339 msg << "\t\t\t\t<min>" << res->GetValue2() << "</min>";
340 return msg;
341}
342
343void wxr2xml::ParseComboBox(wxItemResource * res)
344{
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");
350}
351
352void wxr2xml::ParseRadioButton(wxItemResource * res)
353{
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}
363
364void 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");
373}
374
375wxString wxr2xml::GetCheckStatus(wxItemResource * res)
376{
377 wxString msg;
378 msg << "\t\t\t\t<checked>" << res->GetValue1() << "</checked>\n";
379 return msg;
380}
381
382wxString wxr2xml::GetStyles(wxItemResource * res)
383{
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;
554}
555
556wxString wxr2xml::GetDimension(wxItemResource * res)
557{
558 wxString msg;
559 msg << "\t\t\t\t<dimension>" << res->GetValue1() << "</dimension>\n";
560 return msg;
561}
562
563wxString 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 }
577
578 name += "\"";
579 return name;
580}
581
582void 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);
594 node = node->Next();
595 }
596
597 m_xmlfile.Write("\t\t</children>\n");
598 m_xmlfile.Write("\t</menubar> \n\n");
599}
600
601void 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
630void 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
652wxString wxr2xml::FixMenuString(wxString phrase)
653{
654 phrase.Replace("&", "$");
655 return phrase;
656}
657
658void 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
674void 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");
686}
687
688void wxr2xml::PanelStuff(wxItemResource * res)
689{
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
704wxString wxr2xml::GetValue2(wxItemResource *res)
705{
706 wxString msg;
707 msg << res->GetValue2();
708 return msg;
709}
710
711wxString wxr2xml::GetValue3(wxItemResource *res)
712{
713 wxString msg;
714 msg << res->GetValue3();
715 return msg;
716
717}
718
719wxString wxr2xml::GetValue5(wxItemResource *res)
720{
721 wxString msg;
722 msg << res->GetValue5();
723 return msg;
724
725}
726
727void wxr2xml::ParseBitmapButton(wxItemResource *res)
728{
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
744void 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}
770
771//WARNING possible make here
772//I wasn't really sure the right way to do this.
773void 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 }
799}
800
801void wxr2xml::GetFontStyle(wxFont font)
802{
803
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
822void wxr2xml::GetFontWeight(wxFont font)
823{
824 int weight=font.GetWeight();
825
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 }
840}