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