]> git.saurik.com Git - wxWidgets.git/blob - contrib/utils/convertrc/wxr2xml.cpp
remove extraneous semicolons
[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 WXWIN_COMPATIBILITY_2_6
426 if (style & wxRESIZE_BOX)
427 s += _T("wxRESIZE_BOX|");
428 #endif // WXWIN_COMPATIBILITY_2_6
429 if (style & wxRESIZE_BORDER)
430 s += _T("wxRESIZE_BORDER|");
431 if (style & wxSYSTEM_MENU)
432 s += _T("wxSYSTEM_MENU|");
433 if (style & wxCLIP_CHILDREN)
434 s += _T("wxCLIP_CHILDREN|");
435 }
436
437 if (restype == _T("wxPanel"))
438 {
439 if (style & wxCLIP_CHILDREN)
440 s += _T("wxCLIP_CHILDREN|");
441 #if WXWIN_COMPATIBILITY_2_6
442 if (style & wxNO_3D)
443 s += _T("wxNO_3D|");
444 #endif // WXWIN_COMPATIBILITY_2_6
445 if (style & wxTAB_TRAVERSAL)
446 s += _T("wxTAB_TRAVERSAL|");
447 if (style & wxWS_EX_VALIDATE_RECURSIVELY)
448 s += _T("wxWS_EX_VALIDATE_RECURSIVELY|");
449 }
450
451 if (restype == _T("wxComboBox"))
452 {
453 if (style & wxCB_SORT)
454 s += _T("wxCB_SORT|");
455 if (style & wxCB_SIMPLE)
456 s += _T("wxCB_SIMPLE|");
457 if (style & wxCB_READONLY)
458 s += _T("wxCB_READONLY|");
459 if (style & wxCB_DROPDOWN)
460 s += _T("wxCB_DROPDOWN|");
461 }
462
463 if (restype == _T("wxGauge"))
464 {
465 if (style & wxGA_HORIZONTAL)
466 s += _T("wxGA_HORIZONTAL|");
467 if (style & wxGA_VERTICAL)
468 s += _T("wxGA_VERTICAL|");
469 // windows only
470 if (style & wxGA_SMOOTH)
471 s += _T("wxGA_SMOOTH|");
472 }
473
474 if (restype == _T("wxRadioButton"))
475 {
476 if (style & wxRB_GROUP)
477 s += _T("wxRB_GROUP|");
478 }
479
480 if (restype == _T("wxStaticText"))
481 {
482 if (style & wxST_NO_AUTORESIZE)
483 s += _T("wxST_NO_AUTORESIZEL|");
484 }
485
486 if (restype == _T("wxRadioBox"))
487 {
488 if (style & wxRA_HORIZONTAL)
489 s += _T("wxRA_HORIZONTAL|");
490 if (style & wxRA_SPECIFY_COLS)
491 s += _T("wxRA_SPECIFY_COLS|");
492 if (style & wxRA_SPECIFY_ROWS)
493 s += _T("wxRA_SPECIFY_ROWS|");
494 if (style & wxRA_VERTICAL)
495 s += _T("wxRA_VERTICAL|");
496 }
497
498 if (restype == _T("wxListBox"))
499 {
500 if (style & wxLB_SINGLE)
501 s += _T("wxLB_SINGLE|");
502 if (style & wxLB_MULTIPLE)
503 s += _T("wxLB_MULTIPLE|");
504 if (style & wxLB_EXTENDED)
505 s += _T("wxLB_EXTENDED|");
506 if (style & wxLB_HSCROLL)
507 s += _T("wxLB_HSCROLL|");
508 if (style & wxLB_ALWAYS_SB)
509 s += _T("wxLB_ALWAYS_SB|");
510 if (style & wxLB_NEEDED_SB)
511 s += _T("wxLB_NEEDED_SB|");
512 if (style & wxLB_SORT)
513 s += _T("wxLB_SORT|");
514 }
515
516 if (restype == _T("wxTextCtrl"))
517 {
518 if (style & wxTE_PROCESS_ENTER)
519 s += _T("wxTE_PROCESS_ENTER|");
520 if (style & wxTE_PROCESS_TAB)
521 s += _T("wxTE_PROCESS_TAB|");
522 if (style & wxTE_MULTILINE)
523 s += _T("wxTE_MULTILINE|");
524 if (style & wxTE_PASSWORD)
525 s += _T("wxTE_PASSWORD|");
526 if (style & wxTE_READONLY)
527 s += _T("wxTE_READONLY|");
528 if (style & wxHSCROLL)
529 s += _T("wxHSCROLL|");
530 }
531
532
533 if (restype == _T("wxScrollBar"))
534 {
535 if (style & wxSB_HORIZONTAL)
536 s += _T("wxSB_HORIZONTAL|");
537 if (style & wxSB_VERTICAL)
538 s += _T("wxSB_VERTICAL|");
539 }
540
541 int l = s.length();
542 // No styles defined
543 if (l == 11)
544 return wxEmptyString;
545 // Trim off last |
546 s = s.Truncate(l - 1);
547
548 s += _T("</style>\n");
549 return s;
550 }
551
552 wxString wxr2xml::GetDimension(wxItemResource * res)
553 {
554 wxString msg;
555 msg << _T("\t\t\t\t<dimension>") << res->GetValue1() << _T("</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 += _T("\"");
575 return name;
576 }
577
578 void wxr2xml::ParseMenuBar(wxItemResource * res)
579 {
580 wxItemResource *child;
581 wxNode *node = res->GetChildren().GetFirst();
582 // Get Menu Bar Name
583 m_xmlfile.Write(_T("\t<object class=\"wxMenuBar\" "));
584 m_xmlfile.Write(GenerateName(res));
585 m_xmlfile.Write(_T(">\n"));
586 while (node) {
587 child = (wxItemResource *) node->GetData();
588 ParseMenu(child);
589 node = node->GetNext();
590 }
591
592 m_xmlfile.Write(_T("\t</object> \n\n"));
593 }
594
595 void wxr2xml::ParseMenu(wxItemResource * res)
596 {
597 wxItemResource *child;
598 wxNode *node = res->GetChildren().GetFirst();
599 // Get Menu
600 m_xmlfile.Write(_T("\t\t\t<object class=\"wxMenu\" "));
601 wxString menuname;
602 menuname << _T("name = \"menu_") << res->GetValue1() << _T("\"");
603 m_xmlfile.Write(menuname);
604 m_xmlfile.Write(_T(">\n"));
605 m_xmlfile.Write(_T("\t\t\t\t<label>")
606 + FixMenuString(res->GetTitle()) + _T("</label>\n"));
607 if (!res->GetValue4().empty())
608 m_xmlfile.Write(_T("\t\t\t\t<help>") + res->GetValue4() +
609 _T("</help>\n"));
610 // Read in menu items and additional menus
611 while (node) {
612 child = (wxItemResource *) node->GetData();
613 if (!child->GetChildren().GetFirst())
614 ParseMenuItem(child);
615 else
616 ParseMenu(child);
617 node = node->GetNext();
618 }
619 m_xmlfile.Write(_T("\t\t\t</object> \n"));
620 }
621
622 void wxr2xml::ParseMenuItem(wxItemResource * res)
623 {
624 // Get Menu Item or Separator
625 if (res->GetTitle().empty()) {
626 m_xmlfile.Write(_T("\t\t\t<object class=\"separator\"/>\n"));
627 } else {
628 m_xmlfile.Write(_T("\t\t\t\t<object class=\"wxMenuItem\" "));
629 wxString menuname;
630 menuname << _T("name = \"menuitem_") << res->GetValue1() << _T("\"");
631 m_xmlfile.Write(menuname);
632 m_xmlfile.Write(_T(">\n"));
633 m_xmlfile.Write(_T("\t\t\t<label>")
634 + FixMenuString(res->GetTitle()) + _T("</label>\n"));
635 if (!res->GetValue4().empty())
636 m_xmlfile.Write(_T("\t\t\t<help>") +
637 res->GetValue4() + _T("</help>\n"));
638 if (res->GetValue2())
639 m_xmlfile.Write(_T("\t\t\t\t<checkable>1</checkable>\n"));
640 m_xmlfile.Write(_T("\t\t\t</object> \n"));
641 }
642 }
643
644 wxString wxr2xml::FixMenuString(wxString phrase)
645 {
646 phrase.Replace(_T("&"), _T("$"));
647 return phrase;
648 }
649
650 void wxr2xml::ParseStaticBitmap(wxItemResource * res)
651 {
652 m_xmlfile.Write(_T("\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(_T("\n\t\t\t\t<bitmap>") + bitmapname + _T("</bitmap>"));
662 m_xmlfile.Write(_T("\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("\t<object class=\"wxBitmap\" "));
669 m_xmlfile.Write(GenerateName(res)+_T(">"));
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(_T("</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\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\t<bitmap>") + bitmapname + _T("</bitmap>\n"));
732
733 m_xmlfile.Write(_T("\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\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\t<size>")<<pt<<_T("</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\t<underlined>1</underlined>\n"));
759
760 m_xmlfile.Write(_T("\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\t<face>decorative</face>\n"));
775 break;
776 case wxROMAN:
777 m_xmlfile.Write(_T("\t\t\t\t<face>roman</face>\n"));
778 break;
779 case wxSCRIPT:
780 m_xmlfile.Write(_T("\t\t\t\t<face>script</face>\n"));
781 break;
782 case wxSWISS:
783 m_xmlfile.Write(_T("\t\t\t\t<face>swiss</face>\n"));
784 break;
785 case wxMODERN:
786 m_xmlfile.Write(_T("\t\t\t\t<face>modern</face>\n"));
787 break;
788 default:
789 wxLogError(_T("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(_T("<style>italic</style>\n"));
805 break;
806 case wxSLANT:
807 m_xmlfile.Write(_T("<style>slant</style>\n"));
808 break;
809 default:
810 wxLogError(_T("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\t<weight>light</weight>\n"));
825 break;
826 case wxBOLD:
827 m_xmlfile.Write(_T("\t\t\t\t<weight>bold</weight>\n"));
828 break;
829 default:
830 wxLogError(_T("Unknown font weight"));
831 }
832 }