]> git.saurik.com Git - wxWidgets.git/blame_incremental - contrib/utils/convertrc/wxr2xml.cpp
define _HPUX_SOURCE under HP-UX, otherwise many things are not defined in standard...
[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
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
32wxr2xml::wxr2xml()
33{
34
35}
36
37wxr2xml::~wxr2xml()
38{
39
40}
41
42bool 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
65bool 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
92void 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
102void 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
114void 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
160void 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
170wxString 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
180wxString 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
190void 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
198void 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
207wxString 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
214wxString 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
221void 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
230wxString wxr2xml::GetLabel(wxItemResource * res)
231{
232 return _T("\t\t\t\t<label>") + res->GetTitle() + _T("</label>\n");
233}
234
235void 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
247void 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
255void 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
263void 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
271void 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
282void 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
291void 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
300wxString 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
307wxString 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
314void 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
324wxString 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
331wxString 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
338void 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
347void 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
359void 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
370wxString 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
377wxString 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 & wxDIALOG_MODAL)
408 s += _T("wxDIALOG_MODAL|");
409 if (style & wxDEFAULT_DIALOG_STYLE)
410 s += _T("wxDEFAULT_DIALOG_STYLE|");
411 if (style & wxDIALOG_MODELESS)
412 s += _T("wxDIALOG_MODELESS|");
413 if (style & wxNO_3D)
414 s += _T("wxNO_3D|");
415 if (style & wxTAB_TRAVERSAL)
416 s += _T("wxTAB_TRAVERSAL|");
417 if (style & wxWS_EX_VALIDATE_RECURSIVELY)
418 s += _T("wxWS_EX_VALIDATE_RECURSIVELY|");
419 if (style & wxSTAY_ON_TOP)
420 s += _T("wxSTAY_ON_TOP|");
421 if (style & wxCAPTION)
422 s += _T("wxCAPTION|");
423 if (style & wxTHICK_FRAME)
424 s += _T("wxTHICK_FRAME|");
425 if (style & wxRESIZE_BOX)
426 s += _T("wxRESIZE_BOX|");
427 if (style & wxRESIZE_BORDER)
428 s += _T("wxRESIZE_BORDER|");
429 if (style & wxSYSTEM_MENU)
430 s += _T("wxSYSTEM_MENU|");
431 if (style & wxCLIP_CHILDREN)
432 s += _T("wxCLIP_CHILDREN|");
433 }
434
435 if (restype == _T("wxPanel"))
436 {
437 if (style & wxCLIP_CHILDREN)
438 s += _T("wxCLIP_CHILDREN|");
439 if (style & wxNO_3D)
440 s += _T("wxNO_3D|");
441 if (style & wxTAB_TRAVERSAL)
442 s += _T("wxTAB_TRAVERSAL|");
443 if (style & wxWS_EX_VALIDATE_RECURSIVELY)
444 s += _T("wxWS_EX_VALIDATE_RECURSIVELY|");
445 }
446
447 if (restype == _T("wxComboBox"))
448 {
449 if (style & wxCB_SORT)
450 s += _T("wxCB_SORT|");
451 if (style & wxCB_SIMPLE)
452 s += _T("wxCB_SIMPLE|");
453 if (style & wxCB_READONLY)
454 s += _T("wxCB_READONLY|");
455 if (style & wxCB_DROPDOWN)
456 s += _T("wxCB_DROPDOWN|");
457 }
458
459 if (restype == _T("wxGauge"))
460 {
461 if (style & wxGA_HORIZONTAL)
462 s += _T("wxGA_HORIZONTAL|");
463 if (style & wxGA_VERTICAL)
464 s += _T("wxGA_VERTICAL|");
465 if (style & wxGA_PROGRESSBAR)
466 s += _T("wxGA_PROGRESSBAR|");
467 // windows only
468 if (style & wxGA_SMOOTH)
469 s += _T("wxGA_SMOOTH|");
470 }
471
472 if (restype == _T("wxRadioButton"))
473 {
474 if (style & wxRB_GROUP)
475 s += _T("wxRB_GROUP|");
476 }
477
478 if (restype == _T("wxStaticText"))
479 {
480 if (style & wxST_NO_AUTORESIZE)
481 s += _T("wxST_NO_AUTORESIZEL|");
482 }
483
484 if (restype == _T("wxRadioBox"))
485 {
486 if (style & wxRA_HORIZONTAL)
487 s += _T("wxRA_HORIZONTAL|");
488 if (style & wxRA_SPECIFY_COLS)
489 s += _T("wxRA_SPECIFY_COLS|");
490 if (style & wxRA_SPECIFY_ROWS)
491 s += _T("wxRA_SPECIFY_ROWS|");
492 if (style & wxRA_VERTICAL)
493 s += _T("wxRA_VERTICAL|");
494 }
495
496 if (restype == _T("wxListBox"))
497 {
498 if (style & wxLB_SINGLE)
499 s += _T("wxLB_SINGLE|");
500 if (style & wxLB_MULTIPLE)
501 s += _T("wxLB_MULTIPLE|");
502 if (style & wxLB_EXTENDED)
503 s += _T("wxLB_EXTENDED|");
504 if (style & wxLB_HSCROLL)
505 s += _T("wxLB_HSCROLL|");
506 if (style & wxLB_ALWAYS_SB)
507 s += _T("wxLB_ALWAYS_SB|");
508 if (style & wxLB_NEEDED_SB)
509 s += _T("wxLB_NEEDED_SB|");
510 if (style & wxLB_SORT)
511 s += _T("wxLB_SORT|");
512 }
513
514 if (restype == _T("wxTextCtrl"))
515 {
516 if (style & wxTE_PROCESS_ENTER)
517 s += _T("wxTE_PROCESS_ENTER|");
518 if (style & wxTE_PROCESS_TAB)
519 s += _T("wxTE_PROCESS_TAB|");
520 if (style & wxTE_MULTILINE)
521 s += _T("wxTE_MULTILINE|");
522 if (style & wxTE_PASSWORD)
523 s += _T("wxTE_PASSWORD|");
524 if (style & wxTE_READONLY)
525 s += _T("wxTE_READONLY|");
526 if (style & wxHSCROLL)
527 s += _T("wxHSCROLL|");
528 }
529
530
531 if (restype == _T("wxScrollBar"))
532 {
533 if (style & wxSB_HORIZONTAL)
534 s += _T("wxSB_HORIZONTAL|");
535 if (style & wxSB_VERTICAL)
536 s += _T("wxSB_VERTICAL|");
537 }
538
539 int l;
540 l = s.Length();
541 // No styles defined
542 if (l == 11)
543 return _T("");
544 // Trim off last |
545 s = s.Truncate(l - 1);
546
547 s += _T("</style>\n");
548 return s;
549}
550
551wxString wxr2xml::GetDimension(wxItemResource * res)
552{
553 wxString msg;
554 msg << _T("\t\t\t\t<dimension>") << res->GetValue1() << _T("</dimension>\n");
555 return msg;
556}
557
558wxString wxr2xml::GenerateName(wxItemResource * res)
559{
560 wxString name;
561 name = _T(" name=\"");
562 switch (res->GetId()) {
563 case wxID_OK:
564 name += _T("wxID_OK");
565 break;
566 case wxID_CANCEL:
567 name += _T("wxID_CANCEL");
568 break;
569 default:
570 name += res->GetName();
571 }
572
573 name += _T("\"");
574 return name;
575}
576
577void wxr2xml::ParseMenuBar(wxItemResource * res)
578{
579 wxItemResource *child;
580 wxNode *node = res->GetChildren().GetFirst();
581 // Get Menu Bar Name
582 m_xmlfile.Write(_T("\t<object class=\"wxMenuBar\" "));
583 m_xmlfile.Write(GenerateName(res));
584 m_xmlfile.Write(_T(">\n"));
585 while (node) {
586 child = (wxItemResource *) node->GetData();
587 ParseMenu(child);
588 node = node->GetNext();
589 }
590
591 m_xmlfile.Write(_T("\t</object> \n\n"));
592}
593
594void wxr2xml::ParseMenu(wxItemResource * res)
595{
596 wxItemResource *child;
597 wxNode *node = res->GetChildren().GetFirst();
598 // Get Menu
599 m_xmlfile.Write(_T("\t\t\t<object class=\"wxMenu\" "));
600 wxString menuname;
601 menuname << _T("name = \"menu_") << res->GetValue1() << _T("\"");
602 m_xmlfile.Write(menuname);
603 m_xmlfile.Write(_T(">\n"));
604 m_xmlfile.Write(_T("\t\t\t\t<label>")
605 + FixMenuString(res->GetTitle()) + _T("</label>\n"));
606 if (res->GetValue4() != _T(""))
607 m_xmlfile.Write(_T("\t\t\t\t<help>") + res->GetValue4() +
608 _T("</help>\n"));
609 // Read in menu items and additional menus
610 while (node) {
611 child = (wxItemResource *) node->GetData();
612 if (!child->GetChildren().GetFirst())
613 ParseMenuItem(child);
614 else
615 ParseMenu(child);
616 node = node->GetNext();
617 }
618 m_xmlfile.Write(_T("\t\t\t</object> \n"));
619}
620
621void wxr2xml::ParseMenuItem(wxItemResource * res)
622{
623 // Get Menu Item or Separator
624 if (res->GetTitle() == _T("")) {
625 m_xmlfile.Write(_T("\t\t\t<object class=\"separator\"/>\n"));
626 } else {
627 m_xmlfile.Write(_T("\t\t\t\t<object class=\"wxMenuItem\" "));
628 wxString menuname;
629 menuname << _T("name = \"menuitem_") << res->GetValue1() << _T("\"");
630 m_xmlfile.Write(menuname);
631 m_xmlfile.Write(_T(">\n"));
632 m_xmlfile.Write(_T("\t\t\t<label>")
633 + FixMenuString(res->GetTitle()) + _T("</label>\n"));
634 if (res->GetValue4() != _T(""))
635 m_xmlfile.Write(_T("\t\t\t<help>") +
636 res->GetValue4() + _T("</help>\n"));
637 if (res->GetValue2())
638 m_xmlfile.Write(_T("\t\t\t\t<checkable>1</checkable>\n"));
639 m_xmlfile.Write(_T("\t\t\t</object> \n"));
640 }
641}
642
643wxString wxr2xml::FixMenuString(wxString phrase)
644{
645 phrase.Replace(_T("&"), _T("$"));
646 return phrase;
647}
648
649void wxr2xml::ParseStaticBitmap(wxItemResource * res)
650{
651 m_xmlfile.Write(_T("\t\t\t<object class=\"wxStaticBitmap\""));
652 WriteControlInfo(res);
653 // value4 holds bitmap name
654 wxString bitmapname;
655 bitmapname = res->GetValue4();
656 wxBitmap bitmap;
657 bitmap = wxResourceCreateBitmap(bitmapname, &m_table);
658 bitmapname += _T(".bmp");
659 bitmap.SaveFile(bitmapname, wxBITMAP_TYPE_BMP);
660 m_xmlfile.Write(_T("\n\t\t\t\t<bitmap>") + bitmapname + _T("</bitmap>"));
661 m_xmlfile.Write(_T("\t\t\t</object>\n"));
662 // bitmap5
663}
664//Parse a bitmap resource
665void wxr2xml::ParseBitmap(wxItemResource * res)
666{
667 m_xmlfile.Write(_T("\t<object class=\"wxBitmap\" "));
668 m_xmlfile.Write(GenerateName(res)+_T(">"));
669 wxString bitmapname;
670 bitmapname = res->GetName();
671 wxBitmap bitmap;
672 bitmap = wxResourceCreateBitmap(bitmapname, &m_table);
673 bitmapname += _T(".bmp");
674 bitmap.SaveFile(bitmapname, wxBITMAP_TYPE_BMP);
675 m_xmlfile.Write(bitmapname);
676 m_xmlfile.Write(_T("</object>\n\n"));
677}
678
679void wxr2xml::PanelStuff(wxItemResource * res)
680{
681 if ((res->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0)
682 m_dlgunits = true;
683 else
684 m_dlgunits = false;
685
686 // If this is true ignore fonts, background color and use system
687 // defaults instead
688 if ((res->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS) != 0)
689 m_systemdefaults = true;
690 else
691 m_systemdefaults = false;
692
693}
694
695wxString wxr2xml::GetValue2(wxItemResource *res)
696{
697 wxString msg;
698 msg << res->GetValue2();
699 return msg;
700}
701
702wxString wxr2xml::GetValue3(wxItemResource *res)
703{
704 wxString msg;
705 msg << res->GetValue3();
706 return msg;
707
708}
709
710wxString wxr2xml::GetValue5(wxItemResource *res)
711{
712 wxString msg;
713 msg << res->GetValue5();
714 return msg;
715
716}
717
718void wxr2xml::ParseBitmapButton(wxItemResource *res)
719{
720
721 m_xmlfile.Write(_T("\t\t\t<object class=\"wxBitmapButton\""));
722 WriteControlInfo(res);
723 // value4 holds bitmap name
724 wxString bitmapname;
725 bitmapname = res->GetValue4();
726 wxBitmap bitmap;
727 bitmap = wxResourceCreateBitmap(bitmapname, &m_table);
728 bitmapname += _T(".bmp");
729 bitmap.SaveFile(bitmapname, wxBITMAP_TYPE_BMP);
730 m_xmlfile.Write(_T("\t\t\t\t<bitmap>") + bitmapname + _T("</bitmap>\n"));
731
732 m_xmlfile.Write(_T("\t\t\t</object>\n"));
733}
734
735void wxr2xml::WriteFontInfo(wxItemResource *res)
736{
737//if systems_defaults true just ignore the fonts
738 if (m_systemdefaults)
739 return;
740 wxFont font;
741 font=res->GetFont();
742 if (!font.GetRefData())
743 return;
744
745 m_xmlfile.Write(_T("\t\t\t<font>\n"));
746 //Get font point size,font family,weight,font style,underline
747 int pt;
748 wxString msg;
749 pt=font.GetPointSize();
750 msg<<_T("\t\t\t\t<size>")<<pt<<_T("</size>\n");
751 m_xmlfile.Write(msg);
752 GetFontFace(font);
753 GetFontStyle(font);
754 GetFontWeight(font);
755
756 if (font.GetUnderlined())
757 m_xmlfile.Write(_T("\t\t\t\t<underlined>1</underlined>\n"));
758
759 m_xmlfile.Write(_T("\t\t\t</font>\n"));
760}
761
762//WARNING possible make here
763//I wasn't really sure the right way to do this.
764void wxr2xml::GetFontFace(wxFont font)
765{
766 int family=font.GetFamily();
767
768 switch (family)
769 {
770 case wxDEFAULT:
771 break;
772 case wxDECORATIVE:
773 m_xmlfile.Write(_T("\t\t\t\t<face>decorative</face>\n"));
774 break;
775 case wxROMAN:
776 m_xmlfile.Write(_T("\t\t\t\t<face>roman</face>\n"));
777 break;
778 case wxSCRIPT:
779 m_xmlfile.Write(_T("\t\t\t\t<face>script</face>\n"));
780 break;
781 case wxSWISS:
782 m_xmlfile.Write(_T("\t\t\t\t<face>swiss</face>\n"));
783 break;
784 case wxMODERN:
785 m_xmlfile.Write(_T("\t\t\t\t<face>modern</face>\n"));
786 break;
787 default:
788 wxLogError(_T("Unknown font face"));
789 }
790}
791
792void wxr2xml::GetFontStyle(wxFont font)
793{
794
795 int style=font.GetStyle();
796
797 switch (style)
798 {
799//since this is default no point in making file any larger
800 case wxNORMAL:
801 break;
802 case wxITALIC:
803 m_xmlfile.Write(_T("<style>italic</style>\n"));
804 break;
805 case wxSLANT:
806 m_xmlfile.Write(_T("<style>slant</style>\n"));
807 break;
808 default:
809 wxLogError(_T("Unknown font style"));
810 }
811}
812
813void wxr2xml::GetFontWeight(wxFont font)
814{
815 int weight=font.GetWeight();
816
817 switch (weight)
818 {
819//since this is default no point in making file any larger
820 case wxNORMAL:
821 break;
822 case wxLIGHT:
823 m_xmlfile.Write(_T("\t\t\t\t<weight>light</weight>\n"));
824 break;
825 case wxBOLD:
826 m_xmlfile.Write(_T("\t\t\t\t<weight>bold</weight>\n"));
827 break;
828 default:
829 wxLogError(_T("Unknown font weight"));
830 }
831}