]> git.saurik.com Git - wxWidgets.git/blame - contrib/utils/convertrc/rc2xml.cpp
final part of SF patch #904166 (DMC fix)
[wxWidgets.git] / contrib / utils / convertrc / rc2xml.cpp
CommitLineData
2193517f
VS
1// rc2xml.cpp: implementation of the rc2xml class.
2//Author: Brian Gavin 9/24/00
3//License: wxWindows License
4/*
5How to use:
6#include "rc2xml.h"
7...
8rc2xml trans;
9trans->Convert("Myfile.rc","Myfile.xml");
10*/
11/* TODO
121. Figure how to fix memory leaks in all wxLists in this class
132. Find a way to rename MS Windows fonts so that they work
14cross platform (wxGTK,etc)
153. Be able to abort incorrectly formated files without crashing
16*/
17
18#ifdef __GNUG__
19#pragma implementation "rc2xml.cpp"
20#pragma interface "rc2xml.cpp"
21#endif
22
88d42654 23// For compilers that support precompilation, includes "wx/wx.h".
92a19c2e 24#include "wx/wxprec.h"
2193517f
VS
25
26#ifdef __BORLANDC__
27#pragma hdrstop
28#endif
29
30// for all others, include the necessary headers (this file is usually all you
31// need because it includes almost all "standard" wxWindows headers
32#ifndef WX_PRECOMP
33#include <wx/wx.h>
34#endif
35
88d42654
VS
36
37#include "rc2xml.h"
38#include "wx/image.h"
7c9955d1
JS
39#include "wx/deprecated/setup.h"
40#include "wx/deprecated/resource.h"
2193517f
VS
41#include <wx/textfile.h>
42#include <wx/tokenzr.h>
43
44
45
88d42654
VS
46//////////////////////////////////////////////////////////////////////
47// Construction/Destruction
48//////////////////////////////////////////////////////////////////////
49
2193517f 50rc2xml::rc2xml()
88d42654 51{
2193517f
VS
52 m_done=FALSE;
53 m_bitmaplist=new wxList(wxKEY_STRING);
54 m_stringtable=new wxList(wxKEY_STRING);
55 m_iconlist = new wxList(wxKEY_STRING);
56 m_resourcelist =new wxList(wxKEY_INTEGER);
88d42654
VS
57}
58
2193517f 59rc2xml::~rc2xml()
88d42654 60{
2193517f
VS
61 delete m_bitmaplist;
62 delete m_stringtable;
63 delete m_iconlist;
64 delete m_resourcelist;
88d42654
VS
65}
66
2193517f 67bool rc2xml::Convert(wxString rcfile, wxString xmlfile)
88d42654 68{
2193517f
VS
69 m_rc.Open(rcfile.c_str());
70 m_filesize=m_rc.Length();
7c9955d1 71
92a19c2e 72
2c99715a 73 m_workingpath=wxPathOnly(rcfile);
92a19c2e 74
19d0f58d 75 m_targetpath=wxPathOnly(xmlfile) + _T("\\");
2c99715a 76
92a19c2e
GT
77
78
2c99715a
VS
79 wxSetWorkingDirectory(m_workingpath);
80
92a19c2e 81
2193517f 82 bool result;
19d0f58d
JS
83 result=m_xmlfile.Open(xmlfile.c_str(),_T("w+t"));
84 wxASSERT_MSG(result,_T("Couldn't create XML file"));
2193517f
VS
85 if (!result)
86 return FALSE;
88d42654 87
7c9955d1 88
88d42654 89/* Write Basic header for XML file */
19d0f58d
JS
90 m_xmlfile.Write(_T("<?xml version=\"1.0\" ?>\n"));
91 m_xmlfile.Write(_T("<resource>\n"));
7c9955d1 92
2193517f
VS
93//Read resource.h
94 ParseResourceHeader();
88d42654 95//Gather all the resource we need for toolbars,menus, and etc
2193517f
VS
96 FirstPass();
97 m_done=FALSE;
98 m_rc.Seek(0);
88d42654 99//Read in dialogs, toolbars,menus
2193517f 100 SecondPass();
88d42654 101
19d0f58d 102 m_xmlfile.Write(_T("</resource>\n"));
2193517f
VS
103 m_xmlfile.Close();
104 m_rc.Close();
7c9955d1 105 wxMessageBox(_("Conversion complete."), _("Done"),
5c8756b0 106 wxOK | wxICON_INFORMATION);
88d42654
VS
107
108return TRUE;
109}
110
111
2193517f 112void rc2xml::ParseDialog(wxString dlgname)
88d42654 113{
2193517f
VS
114 wxString token;
115 static int dlgid=999;
116 dlgid++;
7c9955d1 117/* Make sure that this really is a dialog
2193517f
VS
118microsoft reuses the keyword DIALOG for other things
119*/
120 token=PeekToken();
121//Microsoft notation?
19d0f58d
JS
122 while ((token==_T("DISCARDABLE"))
123 ||(token==_T("LOADONCALL"))||(token==_T("MOVEABLE")))
2193517f
VS
124 {
125 token=GetToken();
126 token=PeekToken();
127 }
128//Error isn't a Dialog resource eject eject
129 if (!token.IsNumber())
130 return;
88d42654
VS
131
132//Record x,y,width,height
2193517f
VS
133 int x,y,width,height;
134 ReadRect(x,y,width,height);
88d42654 135//Get Title
2193517f
VS
136 token=GetToken();
137 wxString title;
138 wxString ptsize,face;
7c9955d1 139
19d0f58d 140 m_xmlfile.Write(_T("\t<object class=\"wxDialog\""));
2193517f 141 //Avoid duplicate names this way
19d0f58d 142 dlgname.Replace(_T("IDD_"),_T("DLG_"));
2193517f
VS
143 WriteBasicInfo(x,y,width,height,dlgname);
144 WriteTitle(title);
7c9955d1 145
2193517f 146
19d0f58d 147 while ((token!=_T("BEGIN"))&(token!=_T("{")))
2193517f 148 {
19d0f58d 149 if (token==_T("CAPTION"))
2193517f
VS
150 {
151 title=GetQuoteField();
152 }
153
154//TODO fix face name so that it is cross platform name
155// FONT 8, "MS Sans Serif"
19d0f58d 156 if (token==_T("FONT"))
2193517f
VS
157 {
158 ptsize=GetToken();
159 face=GetQuoteField();
19d0f58d
JS
160 m_xmlfile.Write(_T("\t\t<font>\n"));
161 m_xmlfile.Write(_T("\t\t\t<size>")+ptsize+_T("</size>\n"));
162 m_xmlfile.Write(_T("\t\t\t<face>")+face+_T("</face>\n"));
163 m_xmlfile.Write(_T("\t\t</font>\n"));
2193517f
VS
164 }
165
166 token=GetToken();
167 }
88d42654 168
2193517f 169 ParseControls();
19d0f58d 170 m_xmlfile.Write(_T("\t</object>\n"));
88d42654
VS
171}
172
173/*
174BEGIN
7c9955d1 175 EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT
88d42654
VS
176 WS_TABSTOP
177 LTEXT "Bands",IDC_STATIC,11,86,21,8
178 EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL
179END
180*/
2193517f 181void rc2xml::ParseControls()
88d42654 182{
2193517f 183 wxString token;
5c8756b0 184 wxString label,varname;
2193517f
VS
185
186 token=GetToken();
19d0f58d 187 while ((token!=_T("END"))&(token!=_T("}")))
2193517f 188 {
19d0f58d 189 if (token==_T("AUTOCHECKBOX"))
5c8756b0
JS
190 {
191 label=GetQuoteField();
192 varname=GetToken();
193 ParseCheckBox(label,varname);
194 }
11ad1132 195 else
19d0f58d 196 if (token==_T("AUTORADIOBUTTON"))
5c8756b0
JS
197 {
198 label=GetQuoteField();
199 varname=GetToken();
200 ParseRadioButton(label,varname);
201 }
11ad1132 202 else
19d0f58d 203 if (token==_T("LTEXT"))
5c8756b0
JS
204 {
205 label=GetQuoteField();
206 varname=GetToken();
207 ParseStaticText(label,varname);
208 }
19d0f58d 209 else if (token==_T("EDITTEXT"))
5c8756b0
JS
210 {
211 varname=GetToken();
212 ParseTextCtrl(varname);
213 }
19d0f58d 214 else if ((token==_T("PUSHBUTTON"))||(token==_T("DEFPUSHBUTTON")))
5c8756b0
JS
215 {
216 label=GetQuoteField();
217 varname=GetToken();
218 ParsePushButton(label,varname);
219 }
19d0f58d 220 else if (token==_T("GROUPBOX"))
5c8756b0
JS
221 {
222 label=GetQuoteField();
223 varname=GetToken();
224 ParseGroupBox(label,varname);
225 }
19d0f58d 226 else if (token==_T("COMBOBOX"))
5c8756b0
JS
227 {
228 varname=GetToken();
229 ParseComboBox(varname);
230 }
19d0f58d 231 else if (token==_T("CONTROL"))
2193517f 232 ParseControlMS();
19d0f58d 233 else if (token==_T("LISTBOX"))
5c8756b0
JS
234 {
235 varname=GetToken();
236 ParseListBox(varname);
237 }
19d0f58d 238 else if (token==_T("ICON"))
2193517f 239 ParseIconStatic();
19d0f58d 240 else if (token==_T("SCROLLBAR"))
2193517f
VS
241 ParseScrollBar();
242 token=GetToken();
243 }
88d42654
VS
244
245}
246//LTEXT "Radius",IDC_STATIC,9,67,23,8
5c8756b0 247void rc2xml::ParseStaticText(wxString phrase, wxString varname)
88d42654 248{
2193517f 249 wxString token;
5c8756b0
JS
250 token=PeekToken();
251 while (!token.IsNumber())
252 {
253 token=GetToken();
254 token=PeekToken();
255 }
2193517f
VS
256 int x,y,width,height;
257 ReadRect(x,y,width,height);
88d42654 258
19d0f58d 259 m_xmlfile.Write(_T("\t\t<object class=\"wxStaticText\""));
2193517f 260 WriteBasicInfo(x,y,width,height,varname);WriteLabel(phrase);
19d0f58d 261 m_xmlfile.Write(_T("\t\t</object>\n"));
88d42654
VS
262
263}
264//EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
5c8756b0 265void rc2xml::ParseTextCtrl(wxString varname)
88d42654 266{
2193517f 267 wxString token;
5c8756b0
JS
268 wxString style;
269 token=PeekToken();
270 while (!token.IsNumber())
271 {
272 token=GetToken();
273 token=PeekToken();
274 }
2193517f
VS
275 int x,y,width,height;
276 ReadRect(x,y,width,height);
88d42654
VS
277//TODO
278//style=GetToken();
19d0f58d 279 m_xmlfile.Write(_T("\t\t<object class=\"wxTextCtrl\""));
2193517f 280 WriteBasicInfo(x,y,width,height,varname);
19d0f58d 281 m_xmlfile.Write(_T("\t\t</object>\n"));
88d42654
VS
282
283}
11ad1132 284//AUTOCHECKBOX "&log.", ID_XLOG, 25, 24, 21, 12
5c8756b0 285void rc2xml::ParseCheckBox(wxString phrase, wxString varname)
11ad1132
VS
286{
287 wxString token;
5c8756b0
JS
288 token=PeekToken();
289 while (!token.IsNumber())
290 {
291 token=GetToken();
292 token=PeekToken();
293 }
11ad1132
VS
294 int x,y,width,height;
295 ReadRect(x,y,width,height);
296
19d0f58d 297 m_xmlfile.Write(_T("\t\t<object class=\"wxCheckBox\""));
11ad1132
VS
298 WriteBasicInfo(x,y,width,height,varname);
299 WriteLabel(phrase);
19d0f58d 300 m_xmlfile.Write(_T("\t\t</object>\n"));
11ad1132
VS
301
302}
303//AUTORADIOBUTTON "&text", ID_SW10, 13, 12, 68, 10, BS_AUTORADIOBUTTON | WS_GROUP
5c8756b0 304void rc2xml::ParseRadioButton(wxString phrase, wxString varname)
11ad1132
VS
305{
306 wxString token,style;
11ad1132 307 int x,y,width,height;
5c8756b0
JS
308 bool GotOrs;
309 GotOrs = ReadOrs(token);
11ad1132 310 if (ReadRect(x,y,width,height))
5c8756b0 311 if (GotOrs==FALSE)
11ad1132 312 ReadOrs(token);
19d0f58d
JS
313 if (token.Find(_T("WS_GROUP")) != -1)
314 style += _T("wxRB_GROUP");
11ad1132 315
19d0f58d 316 m_xmlfile.Write(_T("\t\t<object class=\"wxRadioButton\""));
11ad1132
VS
317 WriteBasicInfo(x,y,width,height,varname);
318 WriteLabel(phrase);
319 WriteStyle(style);
19d0f58d 320 m_xmlfile.Write(_T("\t\t</object>\n"));
11ad1132
VS
321
322}
323
88d42654 324//PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
5c8756b0 325void rc2xml::ParsePushButton(wxString phrase, wxString varname)
88d42654 326{
2193517f 327 wxString token;
88d42654 328
5c8756b0
JS
329 token=PeekToken();
330 while (!token.IsNumber())
331 {
332 token=GetToken();
333 token=PeekToken();
334 }
2193517f
VS
335 int x,y,width,height;
336 ReadRect(x,y,width,height);
88d42654 337
19d0f58d 338 m_xmlfile.Write(_T("\t\t<object class=\"wxButton\""));
2193517f
VS
339 WriteBasicInfo(x,y,width,height,varname);
340 WriteLabel(phrase);
19d0f58d 341 m_xmlfile.Write(_T("\t\t</object>\n"));
88d42654
VS
342
343}
344
345
2193517f 346bool rc2xml::Seperator(int ch)
88d42654
VS
347{
348//if ((ch==' ')|(ch==',')|(ch==13)|(ch==10)|(ch=='|')|(ch=='\t'))
2193517f
VS
349 if ((ch==' ')|(ch==',')|(ch==13)|(ch==10)|(ch=='\t'))
350 return TRUE;
351
352 if (ch==EOF)
353 {
354 m_done=TRUE;
355 return TRUE;
356 }
7c9955d1 357
2193517f 358 return FALSE;
88d42654
VS
359}
360
5c8756b0 361void rc2xml::ParseGroupBox(wxString phrase, wxString varname)
88d42654
VS
362{
363// GROUPBOX "Rotate",IDC_STATIC,1,1,71,79
2193517f 364 wxString token;
5c8756b0
JS
365 token=PeekToken();
366 while (!token.IsNumber())
367 {
368 token=GetToken();
369 token=PeekToken();
370 }
2193517f
VS
371 int x,y,width,height;
372 ReadRect(x,y,width,height);
373
19d0f58d 374 m_xmlfile.Write(_T("\t\t<object class=\"wxStaticBox\""));
2193517f
VS
375 WriteBasicInfo(x,y,width,height,varname);
376 WriteLabel(phrase);
19d0f58d 377 m_xmlfile.Write(_T("\t\t</object>\n"));
88d42654
VS
378}
379
11ad1132 380bool rc2xml::ReadRect(int & x, int & y, int & width, int & height)
88d42654 381{
19d0f58d
JS
382 x=wxAtoi(GetToken());
383 y=wxAtoi(GetToken());
384 width=wxAtoi(GetToken());
11ad1132
VS
385 bool ret;
386 wxString tmp = GetToken(&ret);
19d0f58d 387 height=wxAtoi(tmp);
11ad1132 388 return ret; // check for more parameters
88d42654
VS
389}
390
11ad1132 391wxString rc2xml::GetToken(bool *listseperator)
88d42654 392{
19d0f58d 393 wxString token=wxEmptyString;
88d42654 394
2193517f
VS
395 if (m_rc.Eof())
396 {
397 m_done=TRUE;
398 return token;
88d42654
VS
399}
400
2193517f
VS
401 int ch=0;
402 ReadChar(ch);
403 if (ch==EOF)
404 {
405 m_done=TRUE;
406 return token;
407 }
88d42654 408
2193517f
VS
409 while (Seperator(ch))
410 {
411 ReadChar(ch);
412 if (m_done)
413 return token;
414 }
88d42654 415
2193517f
VS
416 if (ch==EOF)
417 {
418 m_done=TRUE;
419 }
7c9955d1 420
88d42654 421
2193517f
VS
422 while (!Seperator(ch))
423 {
11ad1132 424 token += (char)ch;
2193517f
VS
425 ReadChar(ch);
426 }
88d42654 427
11ad1132
VS
428 if (ch == EOF)
429 m_done = TRUE;
88d42654 430
11ad1132
VS
431 if (listseperator)
432 *listseperator = (ch == ',');
2193517f 433 return token;
88d42654
VS
434}
435
2193517f 436wxString rc2xml::GetQuoteField()
88d42654 437{
2193517f
VS
438 wxString phrase;
439 //ASCII code 34 "
440 int ch=0;
441 ReadChar(ch);
88d42654 442
2193517f
VS
443 while (ch!=34)
444 ReadChar(ch);
5c8756b0 445 ReadChar(ch);
7c9955d1 446
5c8756b0
JS
447 while (ch!=34)
448 {
449 phrase+=(char)ch;
450 ReadChar(ch);
451 }
452 return phrase;
453}
454
455// string in stringtable may contain embedded quotes
456// escape characters retained to allow strings to be rewritten
457wxString rc2xml::GetStringQuote()
458{
459 wxString phrase;
460 //ASCII code 34 "
461 bool done=FALSE;
462 int p,ch=0,lastch=0;
2193517f 463 ReadChar(ch);
88d42654 464
2193517f 465 while (ch!=34)
5c8756b0
JS
466 ReadChar(ch);
467 ReadChar(ch);
468 while (done==FALSE)
469 {
470 if ((ch==34)&&(lastch!='\\'))
471 {
472 p=m_rc.Tell();
473 ReadChar(ch);
474// RC supports "", for embedded quote, as well as \"
7c9955d1
JS
475 if (ch==34)
476 phrase+='\\';
5c8756b0 477 else
2193517f 478 {
5c8756b0
JS
479 m_rc.Seek(p);
480 done = TRUE;
481 }
482 }
483 if (done==TRUE)
484 break;
485 if (ch=='\r')
486 ReadChar(ch); // skip
487 if ((ch=='\n')&&(lastch=='\\')) // lastch <should> be this
488 phrase+='n'; // escape
489 else
2193517f 490 phrase+=(char)ch;
5c8756b0 491 lastch=ch;
2193517f
VS
492 ReadChar(ch);
493 }
5c8756b0 494
2193517f 495 return phrase;
88d42654
VS
496}
497
2193517f 498void rc2xml::ReadChar(int &ch)
88d42654 499{
2193517f
VS
500 int result;
501 result=m_rc.Tell();
88d42654 502
2193517f
VS
503 if((result>=m_filesize))
504 m_done=TRUE;
88d42654 505
2193517f 506 result=m_rc.Read(&ch,1);
88d42654 507
2193517f
VS
508 if((result==-1))
509 m_done=TRUE;
88d42654 510
2193517f
VS
511 if(ch==EOF)
512 m_done=TRUE;
88d42654
VS
513}
514
5c8756b0 515void rc2xml::ParseComboBox(wxString varname)
88d42654 516{
7c9955d1 517/* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
88d42654 518 WS_VSCROLL | WS_TABSTOP */
11ad1132 519 wxString token,style;
2193517f 520 int x,y,width,height;
5c8756b0
JS
521 bool GotOrs;
522 GotOrs = ReadOrs(token);
11ad1132 523 if (ReadRect(x,y,width,height))
5c8756b0 524 if (GotOrs==FALSE)
11ad1132 525 ReadOrs(token);
88d42654 526
19d0f58d 527 m_xmlfile.Write(_T("\t\t<object class=\"wxComboBox\""));
2193517f 528 WriteBasicInfo(x,y,width,height,varname);
19d0f58d
JS
529 if (token.Find(_T("CBS_SIMPLE")) != -1)
530 WriteStyle(_T("wxCB_SIMPLE"));
531 if (token.Find(_T("CBS_SORT")) != -1)
532 WriteStyle(_T("wxCB_SORT"));
533 if (token.Find(_T("CBS_DISABLENOSCROLL")) != -1)
534 WriteStyle(_T("wxLB_ALWAYS_SB"));
535 m_xmlfile.Write(_T("\n\t\t</object>\n"));
88d42654
VS
536
537}
538
2193517f 539void rc2xml::ParseMenu(wxString varname)
88d42654 540{
19d0f58d 541 wxString token=wxEmptyString;
2193517f
VS
542
543 //Write menubar to xml file
19d0f58d 544 m_xmlfile.Write(_T("\t<object class=\"wxMenuBar\""));
2193517f 545 //Avoid duplicate names this way
19d0f58d 546 varname.Replace(_T("IDR_"),_T("MB_"));
2193517f 547 WriteName(varname);
19d0f58d 548 m_xmlfile.Write(_T(">\n"));
2193517f 549
19d0f58d 550 while ((token!=_T("BEGIN"))&(token!=_T("{")))
2193517f
VS
551 token=GetToken();
552
19d0f58d 553 while ((token!=_T("END"))&(token!=_T("}")))
2193517f
VS
554 {
555 token=GetToken();
5c8756b0
JS
556 token.MakeUpper();
557
19d0f58d 558 if (token==_T("POPUP"))
2193517f
VS
559 {
560 ParsePopupMenu();
561 }
562 }
19d0f58d 563 m_xmlfile.Write(_T("\t</object>\n"));
88d42654
VS
564}
565
2193517f 566void rc2xml::ParsePopupMenu()
88d42654 567{
2193517f
VS
568 static int menucount=0;
569 menucount++;
570 wxString token,name,msg,longhelp,tip;
571 token=GetQuoteField();
572
573//Remove \t because it causes problems
88d42654 574
2193517f
VS
575//spot=token.First("\\t");
576//token=token.Left(spot);
88d42654
VS
577
578//Write Menu item
579//Generate a fake name since RC menus don't have one
19d0f58d
JS
580 name << _T("Menu_") << menucount;
581 m_xmlfile.Write(_T("\t\t<object class=\"wxMenu\""));
2193517f 582 WriteName(name);
19d0f58d 583 m_xmlfile.Write(_T(">\n"));
2193517f 584 WriteLabel(token);
2193517f 585
19d0f58d 586 while ((token!=_T("BEGIN"))&(token!=_T("{")))
2193517f
VS
587 token=GetToken();
588
19d0f58d 589 while ((token!=_T("END"))&(token!=_T("}")))
2193517f
VS
590 {
591 token=GetToken();
5c8756b0
JS
592 token.MakeUpper();
593
19d0f58d 594 if (token==_T("POPUP"))
2193517f 595 ParsePopupMenu();
7c9955d1 596
19d0f58d 597 if (token==_T("MENUITEM"))
2193517f
VS
598 ParseMenuItem();
599 }
19d0f58d 600 m_xmlfile.Write(_T("\t\t\t</object>\n"));
88d42654
VS
601}
602
2193517f 603wxString rc2xml::PeekToken()
88d42654 604{
2193517f
VS
605 wxString token;
606 int p;
607 p=m_rc.Tell();
608 token=GetToken();
88d42654 609
2193517f
VS
610 m_rc.Seek(p);
611 return token;
88d42654
VS
612}
613//MS Windows pain in the butt CONTROL
2193517f 614void rc2xml::ParseControlMS()
88d42654 615{
2193517f
VS
616 wxString label,varname,kindctrl,token;
617 token=PeekToken();
88d42654 618
19d0f58d 619 if (token.Contains(_T("\"")))
2193517f
VS
620 ParseNormalMSControl();
621 else
622 ParseWeirdMSControl();
88d42654
VS
623
624}
625
7c9955d1 626/* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
88d42654
VS
627 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
628*/
629
19d0f58d 630void rc2xml::ParseSlider(wxString WXUNUSED(label), wxString varname)
88d42654 631{
2193517f
VS
632 wxString token,style;
633 ReadOrs(token);
19d0f58d
JS
634 if (token.Find(_T("TBS_VERT"))!=-1)
635 style+=_T("wxSL_VERTICAL");
2193517f
VS
636 //MFC RC Default is horizontal
637 else
19d0f58d 638 style+=_T("wxSL_HORIZONTAL");
2193517f
VS
639
640 int x,y,width,height;
641 ReadRect(x,y,width,height);
19d0f58d 642 m_xmlfile.Write(_T("\t\t<object class=\"wxSlider\""));
2193517f
VS
643 WriteBasicInfo(x,y,width,height,varname);
644 WriteStyle(style);
19d0f58d 645 m_xmlfile.Write(_T("\n\t\t</object>\n"));
88d42654
VS
646
647}
7c9955d1 648/*
88d42654
VS
649CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
650 WS_BORDER,15,52,154,13
651*/
19d0f58d 652void rc2xml::ParseProgressBar(wxString WXUNUSED(label), wxString varname)
88d42654 653{
2193517f
VS
654 wxString token,style;
655 ReadOrs(token);
7c9955d1 656
2193517f
VS
657 int x,y,width,height;
658 ReadRect(x,y,width,height);
659
88d42654 660//Always horizontal in MFC
19d0f58d 661 m_xmlfile.Write(_T("\t\t<object class=\"wxGauge\""));
2193517f
VS
662 WriteBasicInfo(x,y,width,height,varname);
663 WriteStyle(style);
19d0f58d 664 m_xmlfile.Write(_T("\t\t</object>\n"));
88d42654
VS
665}
666
2193517f 667bool rc2xml::ReadOrs(wxString & orstring)
88d42654 668{
2193517f
VS
669 wxString token;
670
671 token=PeekToken();
672 if (token.IsNumber())
673 return FALSE;
674 orstring=GetToken();
675
676 while(PeekToken()==_T("|"))
677 {
7c9955d1 678 //Grab |
2193517f
VS
679 orstring+=GetToken();
680 //Grab next token
681 orstring+=GetToken();
682 }
683 return TRUE;
88d42654
VS
684}
685
5c8756b0 686//Is it a checkbutton or a radiobutton or a pushbutton or a groupbox
2193517f 687void rc2xml::ParseCtrlButton(wxString label, wxString varname)
88d42654 688{
2193517f 689 wxString token;
5c8756b0
JS
690 int p;
691 p=m_rc.Tell();
2193517f 692 ReadOrs(token);
5c8756b0 693 m_rc.Seek(p);
2193517f 694
19d0f58d 695 if (token.Find(_T("BS_AUTOCHECKBOX"))!=-1)
5c8756b0 696 ParseCheckBox(label, varname);
19d0f58d
JS
697 else if ((token.Find(_T("BS_AUTORADIOBUTTON"))!=-1)||
698 (token.Find(_T("BS_RADIOBUTTON"))!=-1))
5c8756b0 699 ParseRadioButton(label, varname);
19d0f58d 700 else if (token.Find(_T("BS_GROUPBOX"))!=-1)
7c9955d1 701 ParseGroupBox(label, varname);
5c8756b0
JS
702 else // if ((token.Find("BS_PUSHBUTTON")!=-1)||
703// (token.Find("BS_DEFPUSHBUTTON")!=-1))
704 ParsePushButton(label, varname); // make default case
88d42654
VS
705}
706
2193517f 707void rc2xml::WriteSize(int width, int height)
88d42654 708{
2193517f 709 wxString msg;
19d0f58d 710 msg << _T(" <size>") << width << _T(",") << height << _T("d</size>");
2193517f 711 m_xmlfile.Write(msg);
88d42654
VS
712}
713
2193517f 714void rc2xml::WritePosition(int x, int y)
88d42654 715{
2193517f 716 wxString msg;
19d0f58d 717 msg << _T(" <pos>") << x << _T(",") << y << _T("d</pos>");
2193517f 718 m_xmlfile.Write(msg);
88d42654
VS
719}
720
2193517f 721void rc2xml::WriteTitle(wxString title)
88d42654 722{
2193517f 723 wxString msg;
19d0f58d 724 msg=_T("\t\t<title>")+title+_T("</title>\n");
2193517f 725 m_xmlfile.Write(msg);
88d42654
VS
726}
727
2193517f 728void rc2xml::WriteName(wxString name)
88d42654 729{
7c9955d1 730
2193517f
VS
731//Try to convert any number ids into names
732name=LookUpId(name);
88d42654
VS
733//Replace common MS ids with wxWindows ids
734//I didn't do everyone of them
19d0f58d
JS
735 if (name==_T("IDOK"))
736 name=_T("wxID_OK");
737 else if (name==_T("IDCANCEL"))
738 name=_T("wxID_CANCEL");
739 else if (name==_T("IDAPPLY"))
740 name=_T("wxID_APPLY");
741 else if (name==_T("ID_FILE_OPEN"))
742 name=_T("wxID_OPEN");
743 else if (name==_T("ID_FILE_CLOSE"))
744 name=_T("wxID_CLOSE");
745 else if (name==_T("ID_FILE_SAVE"))
746 name=_T("wxID_SAVE");
747 else if (name==_T("ID_FILE_SAVE_AS"))
748 name=_T("wxID_SAVEAS");
749 else if (name==_T("ID_APP_EXIT"))
750 name=_T("wxID_EXIT");
751 else if (name==_T("ID_FILE_PRINT"))
752 name=_T("wxID_PRINT");
753 else if (name==_T("ID_FILE_PRINT_PREVIEW"))
754 name=_T("wxID_PREVIEW");
755 else if (name==_T("ID_FILE_PRINT_SETUP"))
756 name=_T("wxID_PRINT_SETUP");
757 else if (name==_T("ID_APP_ABOUT"))
758 name=_T("wxID_ABOUT");
759 else if (name==_T("ID_EDIT_UNDO"))
760 name=_T("wxID_UNDO");
761 else if (name==_T("ID_EDIT_CUT"))
762 name=_T("wxID_CUT");
763 else if (name==_T("ID_EDIT_COPY"))
764 name=_T("wxID_COPY");
765 else if (name==_T("ID_EDIT_PASTE"))
766 name=_T("wxID_PASTE");
767 else if (name==_T("IDYES"))
768 name=_T("wxID_YES");
769 else if (name==_T("IDNO"))
770 name=_T("wxID_NO");
771 else if (name==_T("IDHELP"))
772 name=_T("wxID_HELP");
773
774 m_xmlfile.Write(_T(" name= \"")+name+_T("\""));
88d42654
VS
775}
776
2193517f 777void rc2xml::WriteLabel(wxString label)
88d42654 778{
19d0f58d
JS
779 label.Replace(_T("&"),_T("$"));
780 m_xmlfile.Write(_T("\t\t\t<label>")+label+_T("</label>\n"));
88d42654
VS
781}
782
2193517f 783void rc2xml::WriteBasicInfo(int x, int y, int width, int height, wxString name)
88d42654 784{
2193517f 785 WriteName(name);
19d0f58d
JS
786 m_xmlfile.Write(_T(">\n"));
787 m_xmlfile.Write(_T("\t\t\t"));
2193517f
VS
788 WritePosition(x,y);
789 WriteSize(width,height);
19d0f58d 790 m_xmlfile.Write(_T("\n"));
88d42654
VS
791}
792
2193517f 793void rc2xml::WriteStyle(wxString style)
88d42654 794{
2193517f
VS
795 if (style.Length()==0)
796 return;
19d0f58d 797 m_xmlfile.Write(_T("\t\t\t<style>")+style+_T("</style>\n"));
88d42654
VS
798}
799/*
7c9955d1 800 LISTBOX IDC_LIST1,16,89,48,40,LBS_SORT | LBS_MULTIPLESEL |
88d42654
VS
801 LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
802*/
5c8756b0 803void rc2xml::ParseListBox(wxString varname)
88d42654 804{
2193517f 805 wxString token;
5c8756b0
JS
806 token=PeekToken();
807 while (!token.IsNumber())
808 {
809 token=GetToken();
810 token=PeekToken();
811 }
2193517f
VS
812 int x,y,width,height;
813 ReadRect(x,y,width,height);
88d42654 814
19d0f58d 815 m_xmlfile.Write(_T("\t\t<object class=\"wxListBox\""));
2193517f 816 WriteBasicInfo(x,y,width,height,varname);
19d0f58d 817 m_xmlfile.Write(_T("\n\t\t</object>\n"));
88d42654
VS
818
819}
820/*
7c9955d1 821 CONTROL "",IDC_RICHEDIT1,"RICHEDIT",ES_AUTOHSCROLL | WS_BORDER |
88d42654
VS
822 WS_TABSTOP,103,110,40,14
823*/
2193517f 824void rc2xml::ParseRichEdit(wxString label, wxString varname)
88d42654 825{
2193517f
VS
826 wxString token;
827 //while (ReadOrs(token));
828 ReadOrs(token);
829 int x,y,width,height;
830 ReadRect(x,y,width,height);
831 wxString style;
88d42654 832//Make it a rich text control
19d0f58d
JS
833 style+=_T("wxTE_MULTILINE ");
834 m_xmlfile.Write(_T("\t\t<object class=\"wxTextCtrl\""));
2193517f
VS
835 WriteBasicInfo(x,y,width,height,varname);
836 WriteStyle(style);
19d0f58d 837 m_xmlfile.Write(_T("\t\t</object>\n"));
88d42654
VS
838
839}
840/*
841CONTROL "Spin1",IDC_SPIN1,"msctls_updown32",UDS_ARROWKEYS,209,72,
842 19,26
843*/
19d0f58d 844void rc2xml::ParseSpinCtrl(wxString WXUNUSED(label), wxString varname)
88d42654 845{
2193517f 846 wxString token,style;
7c9955d1 847
2193517f 848 ReadOrs(token);
19d0f58d
JS
849 if (token.Find(_T("UDS_HORZ"))!=-1)
850 style=_T("wxSP_HORIZONTAL");
2193517f
VS
851 //MFC default
852 else
19d0f58d 853 style=_T("wxSP_VERTICAL");
2193517f
VS
854
855 int x,y,width,height;
856 ReadRect(x,y,width,height);
19d0f58d 857 m_xmlfile.Write(_T("\t\t<object class=\"wxSpinButton\""));
2193517f
VS
858 WriteBasicInfo(x,y,width,height,varname);
859 WriteStyle(style);
19d0f58d 860 m_xmlfile.Write(_T("\n\t\t</object>\n"));
88d42654
VS
861
862}
863
2193517f 864void rc2xml::FirstPass()
88d42654 865{
2193517f
VS
866 wxString token,prevtok;
867 while (!m_done)
868 {
869 token=GetToken();
19d0f58d 870 if (token==_T("BITMAP"))
2193517f 871 ParseBitmap(prevtok);
19d0f58d 872 else if (token==_T("STRINGTABLE"))
2193517f 873 ParseStringTable(prevtok);
19d0f58d 874 else if (token==_T("ICON"))
2193517f 875 ParseIcon(prevtok);
7c9955d1 876
2193517f
VS
877 prevtok=token;
878 }
88d42654
VS
879}
880
2193517f 881void rc2xml::ParseBitmap(wxString varname)
88d42654 882{
2193517f 883 wxString token,*bitmapfile;
7c9955d1 884
2193517f
VS
885 token=PeekToken();
886 //Microsoft notation?
19d0f58d 887 if (token==_T("DISCARDABLE"))
2193517f
VS
888 {
889 token=GetToken();
890 token=PeekToken();
891 }
892 bitmapfile=new wxString;
893 *bitmapfile=GetQuoteField();
894 m_bitmaplist->Append(varname,bitmapfile);
88d42654
VS
895
896}
897
898
2193517f 899void rc2xml::SecondPass()
88d42654 900{
2193517f
VS
901 wxString token,prevtok;
902 while (!m_done)
903 {
904 token=GetToken();
19d0f58d 905 if ((token==_T("DIALOG"))||(token==_T("DIALOGEX")))
2193517f 906 ParseDialog(prevtok);
19d0f58d 907 else if (token==_T("MENU"))
2193517f 908 ParseMenu(prevtok);
19d0f58d 909 else if (token==_T("TOOLBAR"))
2193517f 910 ParseToolBar(prevtok);
7c9955d1 911
2193517f
VS
912 prevtok=token;
913 }
88d42654
VS
914
915}
916
2193517f 917void rc2xml::ParseToolBar(wxString varname)
88d42654 918{
7c9955d1 919 wxString token;
2193517f 920 token=GetToken();
19d0f58d 921 wxASSERT_MSG(token==_T("DISCARDABLE"),_T("Error in toolbar parsing"));
88d42654 922//Look up bitmap for toolbar and load
2193517f
VS
923 wxNode *node=m_bitmaplist->Find(LookUpId(varname));
924 wxString *bitmappath;
19d0f58d 925 bitmappath=(wxString *)node->GetData();
2193517f
VS
926 wxBitmap bitmap;
927 if (!bitmap.LoadFile(*bitmappath,wxBITMAP_TYPE_BMP ))
19d0f58d 928 wxLogError(_T("Unable to load bitmap:")+*bitmappath);
88d42654
VS
929
930//Write toolbar to xml file
19d0f58d 931 m_xmlfile.Write(_T(" <object class=\"wxToolBar\""));
88d42654 932//Avoid duplicate names this way
19d0f58d 933 varname.Replace(_T("IDR_"),_T("TB_"));
2193517f 934 WriteName(varname);
19d0f58d 935 m_xmlfile.Write(_T(">\n"));
2193517f 936 wxString style;
19d0f58d 937 style+=_T("wxTB_FLAT");
2193517f 938 WriteStyle(style);
88d42654 939
88d42654
VS
940
941//Grab width and height
2193517f 942 int width,height;
19d0f58d
JS
943 width=wxAtoi(GetToken());
944 height=wxAtoi(GetToken());
2193517f 945
7c9955d1 946 int c=0;
2193517f
VS
947 wxString buttonname,msg,tip,longhelp;
948 token=GetToken();
19d0f58d 949 while ((token!=_T("BEGIN"))&(token!=_T("{")))
2193517f
VS
950 token=GetToken();
951
19d0f58d 952 while ((token!=_T("END"))&(token!=_T("}")))
2193517f 953 {
19d0f58d 954 if (token==_T("BUTTON"))
2193517f
VS
955 {
956 buttonname=GetToken();
19d0f58d 957 m_xmlfile.Write(_T("\t\t\t<object class=\"tool\""));
2193517f 958 WriteName(buttonname);
19d0f58d 959 m_xmlfile.Write(_T(">\n"));
2193517f
VS
960 //Write tool tip if any
961 if (LookUpString(buttonname,msg))
962 {
963 SplitHelp(msg,tip,longhelp);
19d0f58d
JS
964 m_xmlfile.Write(_T("\t\t\t\t<tooltip>")+tip+_T("</tooltip>\n"));
965 m_xmlfile.Write(_T(" <longhelp>")+longhelp+_T("</longhelp>\n"));
2193517f
VS
966 }
967 //Make a bitmap file name
968 buttonname=CleanName(buttonname);
19d0f58d
JS
969 buttonname+=_T(".bmp");
970 m_xmlfile.Write(_T("\t\t\t\t<bitmap>")+buttonname+_T("</bitmap>\n"));
2193517f 971 WriteToolButton(buttonname,c,width,height,bitmap);
19d0f58d 972 m_xmlfile.Write(_T("\t\t\t</object>\n"));
2193517f
VS
973 c++;
974 }
19d0f58d 975 else if (token==_T("SEPARATOR"))
2193517f 976 {
19d0f58d 977 m_xmlfile.Write(_T("\t\t\t<object class=\"separator\"/>\n"));
2193517f
VS
978 }
979 token=GetToken();
980 }
19d0f58d 981 m_xmlfile.Write(_T("\t</object>\n"));
88d42654
VS
982}
983
984//Extract bitmaps from larger toolbar bitmap
2193517f 985void rc2xml::WriteToolButton(wxString name,int index, int width, int height, wxBitmap bitmap)
88d42654 986{
2193517f
VS
987 int x;
988 x=index*width;
989 wxRect r(x,0,width,height);
990 wxBitmap little;
991 little=bitmap.GetSubBitmap(r);
2c99715a 992 little.SaveFile(m_targetpath+name,wxBITMAP_TYPE_BMP);
88d42654
VS
993}
994
2193517f 995void rc2xml::ParseStringTable(wxString varname)
88d42654 996{
2193517f
VS
997 wxString token;
998 token=GetToken();
19d0f58d 999 while ((token!=_T("BEGIN"))&(token!=_T("{")))
2193517f
VS
1000 token=GetToken();
1001 token=GetToken();
1002 wxString *msg;
1003
19d0f58d 1004 while ((token!=_T("END"))&(token!=_T("}")))
2193517f
VS
1005 {
1006 msg=new wxString;
5c8756b0 1007 *msg=GetStringQuote();
2193517f
VS
1008 m_stringtable->Append(token,msg);
1009 token=GetToken();
1010 }
88d42654
VS
1011
1012}
1013
2193517f 1014bool rc2xml::LookUpString(wxString strid,wxString & st)
88d42654 1015{
2193517f
VS
1016 wxNode *node=m_stringtable->Find(strid);
1017 wxString *s;
1018 if (node==NULL)
1019 return FALSE;
88d42654 1020
19d0f58d 1021 s=(wxString *)node->GetData();
2193517f 1022 st=*s;
88d42654 1023
2193517f 1024 return TRUE;
88d42654
VS
1025}
1026
2193517f 1027bool rc2xml::SplitHelp(wxString msg, wxString &shorthelp, wxString &longhelp)
88d42654 1028{
2193517f 1029 int spot;
19d0f58d 1030 spot=msg.Find(_T("\\n"));
2193517f
VS
1031 if (spot==-1)
1032 {
1033 shorthelp=msg;
1034 longhelp=msg;
1035 }
1036
1037 longhelp=msg.Left(spot);
1038 spot=msg.Length()-spot-2;
1039 shorthelp=msg.Right(spot);
1040 return TRUE;
88d42654
VS
1041}
1042
2193517f 1043void rc2xml::ParseMenuItem()
88d42654 1044{
2193517f
VS
1045 wxString token,name,msg,tip,longhelp;
1046//int spot;
19d0f58d 1047 if (PeekToken()==_T("SEPARATOR"))
2193517f 1048 {
19d0f58d 1049 m_xmlfile.Write(_T("\t\t\t<object class=\"separator\"/>\n"));
2193517f
VS
1050 return;
1051 }
1052
1053 token=GetQuoteField();
1054 name=GetToken();
1055//Remove \t because it causes problems
1056//spot=token.First("\\t");
1057//token=token.Left(spot);
19d0f58d 1058 m_xmlfile.Write(_T("\t\t\t<object class=\"wxMenuItem\""));
2193517f 1059 WriteName(name);
19d0f58d 1060 m_xmlfile.Write(_T(">\n"));
2193517f 1061 WriteLabel(token);
88d42654 1062//Look up help if any listed in stringtable
5c8756b0 1063//can't assume numbers correlate, restrict to string identifiers
7c9955d1 1064 if ((!name.IsNumber())&&(LookUpString(name,msg)))
2193517f
VS
1065 {
1066 SplitHelp(msg,tip,longhelp);
19d0f58d
JS
1067 m_xmlfile.Write(_T("\t\t\t<help>")
1068 +longhelp+_T("</help>\n"));
2193517f 1069 }
88d42654 1070//look for extra attributes like checked and break
2193517f
VS
1071 wxString ptoken;
1072 ptoken=PeekToken();
5c8756b0 1073 ptoken.MakeUpper();
19d0f58d 1074 while ((ptoken!=_T("MENUITEM"))&(ptoken!=_T("POPUP"))&(ptoken!=_T("END")))
2193517f
VS
1075 {
1076 token=GetToken();
5c8756b0 1077 ptoken.MakeUpper();
19d0f58d
JS
1078 if (token==_T("CHECKED"))
1079 m_xmlfile.Write(_T("\t\t\t<checkable>1</checkable>\n"));
b2247ee9
CE
1080 else if (token==_T("MENUBREAK"))
1081 ;
2193517f 1082//m_xmlfile.Write("\t\t\t</break>\n");
b2247ee9
CE
1083 else if (token==_T("GRAYED"))
1084 ;
2193517f 1085 else
19d0f58d 1086 wxLogError(_T("Unknown Menu Item token:")+token);
7c9955d1 1087
2193517f 1088 ptoken=PeekToken();
5c8756b0 1089 ptoken.MakeUpper();
2193517f 1090 }
19d0f58d 1091 m_xmlfile.Write(_T("\t\t\t</object>\n"));
88d42654
VS
1092
1093}
1094
1095//ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
2193517f 1096void rc2xml::ParseIconStatic()
88d42654 1097{
2193517f
VS
1098 wxString token;
1099 wxString varname,iconname;
5c8756b0 1100 token = PeekToken();
19d0f58d 1101 if (token.Contains(_T("\"")))
5c8756b0
JS
1102 iconname = GetQuoteField();
1103 else
2193517f 1104 iconname=GetToken();
88d42654 1105//Look up icon
2193517f 1106 varname=GetToken();
88d42654 1107
2193517f
VS
1108 int x,y,width,height;
1109 ReadRect(x,y,width,height);
88d42654 1110
19d0f58d 1111 m_xmlfile.Write(_T("\t\t<object class=\"wxStaticBitmap\""));
2193517f 1112 WriteBasicInfo(x,y,width,height,varname);
88d42654 1113//Save icon as a bitmap
2193517f 1114 WriteIcon(iconname);
19d0f58d 1115 m_xmlfile.Write(_T("\t\t</object>\n"));
88d42654
VS
1116
1117}
1118//IDR_MAINFRAME ICON DISCARDABLE "res\\mfcexample.ico"
2193517f 1119void rc2xml::ParseIcon(wxString varname)
88d42654 1120{
2193517f
VS
1121 wxString token,*iconfile;
1122 iconfile=new wxString;
1123 token=PeekToken();
88d42654 1124
2193517f
VS
1125 *iconfile=GetQuoteField();
1126 m_iconlist->Append(varname,iconfile);
7c9955d1 1127
88d42654
VS
1128
1129}
1130
2193517f 1131wxString rc2xml::CleanName(wxString name)
88d42654 1132{
2193517f 1133 name.MakeLower();
19d0f58d
JS
1134 name.Replace(_T("id_"),wxEmptyString);
1135 name.Replace(_T("idr_"),wxEmptyString);
1136 name.Replace(_T("idb_"),wxEmptyString);
1137 name.Replace(_T("idc_"),wxEmptyString);
92a19c2e 1138
19d0f58d 1139 name.Replace(_T(".ico"),wxEmptyString);
92a19c2e 1140
19d0f58d 1141 name.Replace(_T(".bmp"),wxEmptyString);
2193517f 1142 return name;
88d42654
VS
1143}
1144// And the award for most messed up control goes to...
1145// CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
2193517f 1146void rc2xml::ParseStaticBitmap(wxString bitmapname, wxString varname)
88d42654 1147{
2193517f
VS
1148 wxString token;
1149 //Grab SS_BITMAP
5c8756b0 1150 ReadOrs(token);
88d42654 1151
88d42654 1152
2193517f
VS
1153 int x,y,width,height;
1154 ReadRect(x,y,width,height);
1155
19d0f58d 1156 m_xmlfile.Write(_T("\t\t<object class=\"wxStaticBitmap\""));
2193517f
VS
1157 WriteBasicInfo(x,y,width,height,varname);
1158 WriteBitmap(bitmapname);
19d0f58d 1159 m_xmlfile.Write(_T("\t\t</object>\n"));
88d42654
VS
1160
1161}
1162
2193517f 1163void rc2xml::ParseNormalMSControl()
88d42654
VS
1164{
1165wxString label,varname,kindctrl;
1166
1167label=GetQuoteField();
1168varname=GetToken();
1169kindctrl=GetQuoteField();
1170kindctrl.MakeUpper();
1171
19d0f58d 1172 if (kindctrl==_T("MSCTLS_UPDOWN32"))
2193517f 1173 ParseSpinCtrl(label,varname);
19d0f58d 1174 if (kindctrl==_T("MSCTLS_TRACKBAR32"))
2193517f 1175 ParseSlider(label,varname);
19d0f58d 1176 if (kindctrl==_T("MSCTLS_PROGRESS32"))
2193517f 1177 ParseProgressBar(label,varname);
19d0f58d 1178 if (kindctrl==_T("SYSTREEVIEW32"))
2193517f 1179 ParseTreeCtrl(label,varname);
19d0f58d 1180 if (kindctrl==_T("SYSMONTHCAL32"))
2193517f 1181 ParseCalendar(label,varname);
19d0f58d 1182 if (kindctrl==_T("SYSLISTVIEW32"))
2193517f 1183 ParseListCtrl(label,varname);
19d0f58d 1184 if (kindctrl==_T("BUTTON"))
2193517f 1185 ParseCtrlButton(label,varname);
19d0f58d 1186 if (kindctrl==_T("RICHEDIT"))
2193517f 1187 ParseRichEdit(label,varname);
19d0f58d 1188 if (kindctrl==_T("STATIC"))
5c8756b0
JS
1189 {
1190 wxString token;
1191 int p=m_rc.Tell();
1192 ReadOrs(token);
1193 m_rc.Seek(p);
19d0f58d 1194 if (token.Find(_T("SS_BITMAP"))!=-1)
5c8756b0
JS
1195 ParseStaticBitmap(label,varname);
1196 else
1197 ParseStaticText(label,varname);
1198 }
19d0f58d 1199 if (kindctrl==_T("EDIT"))
5c8756b0 1200 ParseTextCtrl(varname);
19d0f58d 1201 if (kindctrl==_T("LISTBOX"))
5c8756b0 1202 ParseListBox(varname);
19d0f58d 1203 if (kindctrl==_T("COMBOBOX"))
5c8756b0 1204 ParseComboBox(varname);
88d42654
VS
1205
1206}
1207
2193517f 1208void rc2xml::ParseWeirdMSControl()
88d42654 1209{
2193517f
VS
1210 wxString kindctrl;
1211 wxString varname;
1212 wxString id;
1213 id=GetToken();
1214 varname=GetToken();
1215 kindctrl=GetQuoteField();
1216 kindctrl.MakeUpper();
88d42654 1217// CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
19d0f58d 1218 if (kindctrl==_T("STATIC"))
2193517f 1219 {
19d0f58d 1220 if (PeekToken()==_T("SS_BITMAP"))
2193517f
VS
1221 ParseStaticBitmap(id,varname);
1222 else
19d0f58d 1223 wxLogError(_T("Unknown MS Control Static token"));
2193517f 1224 }
88d42654
VS
1225
1226}
1227//SCROLLBAR IDC_SCROLLBAR1,219,56,10,40,SBS_VERT
1228
2193517f 1229void rc2xml::ParseScrollBar()
88d42654 1230{
2193517f
VS
1231 wxString token;
1232 wxString varname;
1233
1234 varname=GetToken();
1235 int x,y,width,height;
1236 ReadRect(x,y,width,height);
1237 wxString style;
1238
1239 ReadOrs(token);
7c9955d1 1240
19d0f58d 1241if (token.Find(_T("SBS_VERT"))!=-1)
2193517f 1242 style=_T("wxSB_VERTICAL");
88d42654 1243//Default MFC style is horizontal
2193517f
VS
1244 else
1245 style=_T("wxSB_HORIZONTAL");
88d42654 1246
19d0f58d 1247 m_xmlfile.Write(_T("\t\t<object class=\"wxScrollBar\""));
2193517f
VS
1248 WriteBasicInfo(x,y,width,height,varname);
1249 WriteStyle(style);
19d0f58d 1250 m_xmlfile.Write(_T("\n\t\t</object>\n"));
88d42654
VS
1251
1252}
1253// CONTROL "Tree1",IDC_TREE1,"SysTreeView32",WS_BORDER | WS_TABSTOP,
1254// 7,7,66,61
1255
19d0f58d 1256void rc2xml::ParseTreeCtrl(wxString WXUNUSED(label), wxString varname)
88d42654 1257{
2193517f
VS
1258 wxString token;
1259//while (ReadOrs(token));
1260 ReadOrs(token);
1261 int x,y,width,height;
1262 ReadRect(x,y,width,height);
19d0f58d 1263 m_xmlfile.Write(_T("\t\t<object class=\"wxTreeCtrl\""));
2193517f 1264 WriteBasicInfo(x,y,width,height,varname);
19d0f58d 1265 m_xmlfile.Write(_T("\t\t</object>\n"));
88d42654
VS
1266
1267}
1268// CONTROL "MonthCalendar1",IDC_MONTHCALENDAR1,"SysMonthCal32",
1269 //MCS_NOTODAY | WS_TABSTOP,105,71,129,89
1270
19d0f58d 1271void rc2xml::ParseCalendar(wxString WXUNUSED(label), wxString varname)
88d42654 1272{
2193517f
VS
1273 wxString token;
1274//while (ReadOrs(token));
1275 ReadOrs(token);
1276 int x,y,width,height;
1277 ReadRect(x,y,width,height);
19d0f58d 1278 m_xmlfile.Write(_T("\t\t<object class=\"wxCalendarCtrl\""));
2193517f 1279 WriteBasicInfo(x,y,width,height,varname);
19d0f58d 1280 m_xmlfile.Write(_T("\t\t</object>\n"));
88d42654
VS
1281}
1282// CONTROL "List1",IDC_LIST1,"SysListView32",WS_BORDER | WS_TABSTOP,
1283 // 7,89,68,71
1284
19d0f58d 1285void rc2xml::ParseListCtrl(wxString WXUNUSED(label), wxString varname)
88d42654 1286{
2193517f
VS
1287 wxString token;
1288 //while (ReadOrs(token));
1289 ReadOrs(token);
1290 int x,y,width,height;
1291 ReadRect(x,y,width,height);
19d0f58d 1292 m_xmlfile.Write(_T("\t\t<object class=\"wxListCtrl\""));
2193517f 1293 WriteBasicInfo(x,y,width,height,varname);
19d0f58d 1294 m_xmlfile.Write(_T("\t\t</object>\n"));
88d42654
VS
1295
1296}
2193517f
VS
1297
1298void rc2xml::WriteBitmap(wxString bitmapname)
1299{
1300//Look up bitmap
1301 wxNode *node=m_bitmaplist->Find(LookUpId(bitmapname));
1302 if (node==NULL)
1303 {
19d0f58d
JS
1304 m_xmlfile.Write(_T("\t\t\t<bitmap>missingfile</bitmap>\n"));
1305 wxLogError(_T("Unable to find bitmap:")+bitmapname);
2193517f
VS
1306 return;
1307 }
7c9955d1 1308
2193517f 1309 wxString *bitmappath;
19d0f58d 1310 bitmappath=(wxString *)node->GetData();
92a19c2e 1311
2c99715a 1312 bitmapname=wxFileNameFromPath(*bitmappath);
2193517f
VS
1313 wxBitmap bitmap;
1314 if (!bitmap.LoadFile(*bitmappath,wxBITMAP_TYPE_BMP ))
19d0f58d 1315 wxLogError(_T("Unable to load bitmap:")+*bitmappath);
2193517f
VS
1316
1317 //Make a bitmap file name
1318 bitmapname=CleanName(bitmapname);
19d0f58d
JS
1319 bitmapname+=_T(".bmp");
1320 m_xmlfile.Write(_T("\t\t\t<bitmap>")+bitmapname+_T("</bitmap>\n"));
2c99715a 1321 bitmap.SaveFile(m_targetpath+bitmapname,wxBITMAP_TYPE_BMP);
2193517f
VS
1322}
1323
1324void rc2xml::WriteIcon(wxString iconname)
1325{
1326wxNode *node=m_iconlist->Find(iconname);
1327 if (node==NULL)
1328 {
19d0f58d
JS
1329 m_xmlfile.Write(_T("\t\t\t<bitmap>missing_file</bitmap>\n"));
1330 wxLogError(_T("Unable to find icon:")+iconname);
2193517f
VS
1331 }
1332 wxString *iconpath;
19d0f58d 1333 iconpath=(wxString *)node->GetData();
2193517f
VS
1334 wxIcon icon;
1335 wxBitmap bitmap;
1336 if (!icon.LoadFile(*iconpath,wxBITMAP_TYPE_ICO ))
19d0f58d 1337 wxLogError(_T("Unable to load icon:")+*iconpath);
2193517f
VS
1338#ifdef __WXMSW__
1339 bitmap.CopyFromIcon(icon);
1340#else
1341 bitmap = icon;
1342#endif
2c99715a 1343 iconname=wxFileNameFromPath(*iconpath);
2193517f
VS
1344 //Make a bitmap file name
1345 iconname=CleanName(iconname);
19d0f58d
JS
1346 iconname+=_T(".bmp");
1347 m_xmlfile.Write(_T("\t\t\t<bitmap>")+iconname+_T("</bitmap>\n"));
2c99715a 1348 bitmap.SaveFile(m_targetpath+iconname,wxBITMAP_TYPE_BMP);
2193517f 1349
7c9955d1 1350
2193517f
VS
1351}
1352/*Unfortunately sometimes the great MSVC Resource editor decides
1353to use numbers instead of the word id. I have no idea why they
1354do this, but that is the way it is.
1355*/
1356/* this is a quick and dirty way to parse the resource.h file
1357it will not recognize #ifdef so it can be easily fooled
1358*/
1359void rc2xml::ParseResourceHeader()
1360{
1361wxTextFile r;
1362//Attempt to load resource.h in current path
19d0f58d 1363 if (!r.Open(_T("resource.h")))
2193517f 1364 {
19d0f58d 1365 wxLogError(_T("Warining Unable to load resource.h file"));
2193517f
VS
1366 return;
1367 }
7c9955d1 1368
2193517f
VS
1369 wxString str;
1370 wxString id,v;
1371 wxStringTokenizer tok;
1372 wxString *varname;
7c9955d1
JS
1373
1374
2193517f
VS
1375 long n;
1376
1377//Read through entire file
1378 for ( str = r.GetFirstLine(); !r.Eof(); str = r.GetNextLine() )
1379 {
19d0f58d 1380 if (str.Find(_T("#define"))!=-1)
2193517f
VS
1381 {
1382 tok.SetString(str);
1383 //Just ignore #define token
1384 tok.GetNextToken();
1385 v=tok.GetNextToken();
1386 id=tok.GetNextToken();
1387 if (id.IsNumber())
1388 {
1389 varname=new wxString;
1390 id.ToLong(&n);
1391 *varname=v;
1392 m_resourcelist->Append(n,varname);
1393 }
1394 }
1395 }
1396
7c9955d1
JS
1397
1398
2193517f
VS
1399}
1400
1401
1402wxString rc2xml::LookUpId(wxString id)
1403{
1404wxString st;
1405
1406if (!id.IsNumber())
1407 return id;
1408long n;
1409id.ToLong(&n);
1410wxNode *node=m_resourcelist->Find(n);
1411 wxString *s;
1412 if (node==NULL)
1413 return id;
1414
19d0f58d 1415 s=(wxString *)node->GetData();
2193517f
VS
1416 st=*s;
1417return st;
1418}