]> git.saurik.com Git - wxWidgets.git/blob - contrib/utils/convertrc/wxr2xml.cpp
fixed bakefile so that in-tree headers take precedence over system-installed ones
[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(), "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
68 bool 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
93 void wxr2xml::ParsePanel(wxItemResource * res)
94 {
95 m_xmlfile.Write("\t<object class=\"wxPanel\"");
96 PanelStuff(res);
97 WriteControlInfo(res);
98 m_xmlfile.Write("\n");
99 ParseControls(res);
100 m_xmlfile.Write("\t</object>\n\n");
101 }
102
103 void wxr2xml::ParseDialog(wxItemResource * res)
104 {
105 PanelStuff(res);
106 m_xmlfile.Write("\t<object class=\"wxDialog\"");
107 WriteControlInfo(res);
108 m_xmlfile.Write(GetTitle(res));
109
110 m_xmlfile.Write("\n");
111 ParseControls(res);
112 m_xmlfile.Write("\t</object>\n\n");
113 }
114
115 void wxr2xml::ParseControls(wxItemResource * res)
116 {
117 wxNode *node = res->GetChildren().First();
118 while (node)
119 {
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();
156 }
157 }
158
159 // Write out basic stuff every control has
160 // name,position,size,bg,fg
161 void wxr2xml::WriteControlInfo(wxItemResource * res)
162 {
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);
169 }
170
171 wxString wxr2xml::GetSize(wxItemResource * res)
172 {
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;
179 }
180
181 wxString wxr2xml::GetPosition(wxItemResource * res)
182 {
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;
189 }
190
191 void wxr2xml::ParseButton(wxItemResource * res)
192 {
193 m_xmlfile.Write("\t\t\t<object class=\"wxButton\"");
194 WriteControlInfo(res);
195 m_xmlfile.Write(GetLabel(res));
196 m_xmlfile.Write("\t\t\t</object>\n");
197 }
198
199 void wxr2xml::ParseTextCtrl(wxItemResource * res)
200 {
201 m_xmlfile.Write("\t\t\t<object class=\"wxTextCtrl\"");
202 WriteControlInfo(res);
203 m_xmlfile.Write(GetValue4(res));
204 m_xmlfile.Write("\t\t\t</object>\n");
205
206 }
207
208 wxString wxr2xml::GetTitle(wxItemResource * res)
209 {
210 wxString msg;
211 msg = _T("\t\t\t\t<title>" + res->GetTitle() + "</title>");
212 return msg;
213 }
214
215 wxString wxr2xml::GetValue4(wxItemResource * res)
216 {
217 wxString msg;
218 msg = _T("\t\t\t\t<value>" + res->GetValue4() + "</value>\n");
219 return msg;
220 }
221
222 void wxr2xml::ParseCheckBox(wxItemResource * res)
223 {
224 m_xmlfile.Write("\t\t\t<object class=\"wxCheckBox\"");
225 WriteControlInfo(res);
226 m_xmlfile.Write(GetLabel(res));
227 m_xmlfile.Write(GetCheckStatus(res));
228 m_xmlfile.Write("\t\t\t</object>\n");
229 }
230
231 wxString wxr2xml::GetLabel(wxItemResource * res)
232 {
233 return _T("\t\t\t\t<label>" + res->GetTitle() + "</label>\n");
234 }
235
236 void wxr2xml::ParseRadioBox(wxItemResource * res)
237 {
238 m_xmlfile.Write("\t\t\t<object class=\"wxRadioBox\"");
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));
245 m_xmlfile.Write("\t\t\t</object>\n");
246 }
247
248 void wxr2xml::ParseListBox(wxItemResource * res)
249 {
250 m_xmlfile.Write("\t\t\t<object class=\"wxListBox\"");
251 WriteControlInfo(res);
252 WriteStringList(res);
253 m_xmlfile.Write("\t\t\t</object>\n");
254 }
255
256 void wxr2xml::ParseStaticText(wxItemResource * res)
257 {
258 m_xmlfile.Write("\t\t\t<object class=\"wxStaticText\"");
259 WriteControlInfo(res);
260 m_xmlfile.Write(GetLabel(res));
261 m_xmlfile.Write("\t\t\t</object>\n");
262 }
263
264 void wxr2xml::ParseStaticBox(wxItemResource * res)
265 {
266 m_xmlfile.Write("\t\t\t<object class=\"wxStaticBox\"");
267 WriteControlInfo(res);
268 m_xmlfile.Write(GetLabel(res));
269 m_xmlfile.Write("\t\t\t</object>\n");
270 }
271
272 void wxr2xml::WriteStringList(wxItemResource * res)
273 {
274 m_xmlfile.Write("\t\t\t\t<content>\n");
275 for (wxStringListNode * node = res->GetStringValues().GetFirst();
276 node;node = node->GetNext()) {
277 const wxString s1 = node->GetData();
278 m_xmlfile.Write("\t\t\t\t\t<item>" + s1 + "</item>\n");
279 }
280 m_xmlfile.Write("\t\t\t\t</content>\n");
281 }
282
283 void wxr2xml::ParseChoice(wxItemResource * res)
284 {
285 m_xmlfile.Write("\t\t\t<object class=\"wxChoice\"");
286 WriteControlInfo(res);
287 // Add choice items
288 WriteStringList(res);
289 m_xmlfile.Write("\t\t\t</object>\n");
290 }
291
292 void wxr2xml::ParseGauge(wxItemResource * res)
293 {
294 m_xmlfile.Write("\t\t\t<object class=\"wxGauge\"");
295 WriteControlInfo(res);
296 m_xmlfile.Write(GetValue1(res));
297 m_xmlfile.Write(GetRange(res));
298 m_xmlfile.Write("\n\t\t\t</object>\n");
299 }
300
301 wxString wxr2xml::GetValue1(wxItemResource * res)
302 {
303 wxString msg;
304 msg << "\t\t\t\t<value>" << res->GetValue1() << "</value>\n";
305 return msg;
306 }
307
308 wxString wxr2xml::GetRange(wxItemResource * res)
309 {
310 wxString msg;
311 msg << "\t\t\t\t<range>" << res->GetValue2() << "</range>";
312 return msg;
313 }
314
315 void wxr2xml::ParseSlider(wxItemResource * res)
316 {
317 m_xmlfile.Write("\t\t\t<object class=\"wxSlider\"");
318 WriteControlInfo(res);
319 m_xmlfile.Write(GetValue1(res));
320 m_xmlfile.Write(GetMax(res));
321 m_xmlfile.Write(GetMin(res));
322 m_xmlfile.Write("\n\t\t\t</object>\n");
323 }
324
325 wxString wxr2xml::GetMax(wxItemResource * res)
326 {
327 wxString msg;
328 msg << "\t\t\t\t<max>" << res->GetValue3() << "</max>\n";
329 return msg;
330 }
331
332 wxString wxr2xml::GetMin(wxItemResource * res)
333 {
334 wxString msg;
335 msg << "\t\t\t\t<min>" << res->GetValue2() << "</min>";
336 return msg;
337 }
338
339 void wxr2xml::ParseComboBox(wxItemResource * res)
340 {
341 m_xmlfile.Write("\t\t\t<object class=\"wxComboBox\"");
342 WriteControlInfo(res);
343 // Add combo items
344 WriteStringList(res);
345 m_xmlfile.Write("\n\t\t\t</object>\n");
346 }
347
348 void wxr2xml::ParseRadioButton(wxItemResource * res)
349 {
350 m_xmlfile.Write("\t\t\t<object class=\"wxRadioButton\"");
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));
357 m_xmlfile.Write("\t\t\t</object>\n");
358 }
359
360 void wxr2xml::ParseScrollBar(wxItemResource * res)
361 {
362 m_xmlfile.Write("\t\t\t<object class=\"wxScrollBar\"");
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");
368 m_xmlfile.Write("\t\t\t</object>\n");
369 }
370
371 wxString wxr2xml::GetCheckStatus(wxItemResource * res)
372 {
373 wxString msg;
374 msg << "\t\t\t\t<checked>" << res->GetValue1() << "</checked>\n";
375 return msg;
376 }
377
378 wxString wxr2xml::GetStyles(wxItemResource * res)
379 {
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;
550 }
551
552 wxString wxr2xml::GetDimension(wxItemResource * res)
553 {
554 wxString msg;
555 msg << "\t\t\t\t<dimension>" << res->GetValue1() << "</dimension>\n";
556 return msg;
557 }
558
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 }
573
574 name += "\"";
575 return name;
576 }
577
578 void wxr2xml::ParseMenuBar(wxItemResource * res)
579 {
580 wxItemResource *child;
581 wxNode *node = res->GetChildren().First();
582 // Get Menu Bar Name
583 m_xmlfile.Write("\t<object class=\"wxMenuBar\" ");
584 m_xmlfile.Write(GenerateName(res));
585 m_xmlfile.Write(">\n");
586 while (node) {
587 child = (wxItemResource *) node->Data();
588 ParseMenu(child);
589 node = node->Next();
590 }
591
592 m_xmlfile.Write("\t</object> \n\n");
593 }
594
595 void wxr2xml::ParseMenu(wxItemResource * res)
596 {
597 wxItemResource *child;
598 wxNode *node = res->GetChildren().First();
599 // Get Menu
600 m_xmlfile.Write("\t\t\t<object class=\"wxMenu\" ");
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");
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 }
619 m_xmlfile.Write("\t\t\t</object> \n");
620 }
621
622 void wxr2xml::ParseMenuItem(wxItemResource * res)
623 {
624 // Get Menu Item or Separator
625 if (res->GetTitle() == "") {
626 m_xmlfile.Write("\t\t\t<object class=\"separator\"/>\n");
627 } else {
628 m_xmlfile.Write("\t\t\t\t<object class=\"wxMenuItem\" ");
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");
640 m_xmlfile.Write("\t\t\t</object> \n");
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 {
652 m_xmlfile.Write("\t\t\t<object class=\"wxStaticBitmap\"");
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>");
662 m_xmlfile.Write("\t\t\t</object>\n");
663 // bitmap5
664 }
665 //Parse a bitmap resource
666 void wxr2xml::ParseBitmap(wxItemResource * res)
667 {
668 m_xmlfile.Write("\t<object class=\"wxBitmap\" ");
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);
677 m_xmlfile.Write("</object>\n\n");
678 }
679
680 void wxr2xml::PanelStuff(wxItemResource * res)
681 {
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;
701 }
702
703 wxString wxr2xml::GetValue3(wxItemResource *res)
704 {
705 wxString msg;
706 msg << res->GetValue3();
707 return msg;
708
709 }
710
711 wxString wxr2xml::GetValue5(wxItemResource *res)
712 {
713 wxString msg;
714 msg << res->GetValue5();
715 return msg;
716
717 }
718
719 void wxr2xml::ParseBitmapButton(wxItemResource *res)
720 {
721
722 m_xmlfile.Write("\t\t\t<object class=\"wxBitmapButton\"");
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
733 m_xmlfile.Write("\t\t\t</object>\n");
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 }
762
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:
774 m_xmlfile.Write("\t\t\t\t<face>decorative</face>\n");
775 break;
776 case wxROMAN:
777 m_xmlfile.Write("\t\t\t\t<face>roman</face>\n");
778 break;
779 case wxSCRIPT:
780 m_xmlfile.Write("\t\t\t\t<face>script</face>\n");
781 break;
782 case wxSWISS:
783 m_xmlfile.Write("\t\t\t\t<face>swiss</face>\n");
784 break;
785 case wxMODERN:
786 m_xmlfile.Write("\t\t\t\t<face>modern</face>\n");
787 break;
788 default:
789 wxLogError("Unknown font face");
790 }
791 }
792
793 void wxr2xml::GetFontStyle(wxFont font)
794 {
795
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();
817
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 }
832 }