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