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