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