]>
git.saurik.com Git - wxWidgets.git/blob - contrib/utils/convertrc/rc2xml.cpp
1 // rc2xml.cpp: implementation of the rc2xml class.
2 //Author: Brian Gavin 9/24/00
3 //License: wxWindows License
9 trans->Convert("Myfile.rc","Myfile.xml");
12 1. Figure how to fix memory leaks in all wxLists in this class
13 2. Find a way to rename MS Windows fonts so that they work
14 cross platform (wxGTK,etc)
15 3. Be able to abort incorrectly formated files without crashing
19 #pragma implementation "rc2xml.cpp"
20 #pragma interface "rc2xml.cpp"
23 // For compilers that support precompilation, includes "wx/wx.h".
24 #include "wx/wxprec.h"
30 // for all others, include the necessary headers (this file is usually all you
31 // need because it includes almost all "standard" wxWindows headers
39 #include "wx/resource.h"
40 #include <wx/textfile.h>
41 #include <wx/tokenzr.h>
45 //////////////////////////////////////////////////////////////////////
46 // Construction/Destruction
47 //////////////////////////////////////////////////////////////////////
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
);
63 delete m_resourcelist
;
66 bool rc2xml::Convert(wxString rcfile
, wxString xmlfile
)
68 m_rc
.Open(rcfile
.c_str());
69 m_filesize
=m_rc
.Length();
72 m_workingpath
=wxPathOnly(rcfile
);
74 m_targetpath
=wxPathOnly(xmlfile
)+"\\";
78 wxSetWorkingDirectory(m_workingpath
);
82 result
=m_xmlfile
.Open(xmlfile
.c_str(),"w+t");
83 wxASSERT_MSG(result
,"Couldn't create XML file");
88 /* Write Basic header for XML file */
89 m_xmlfile
.Write("<?xml version=\"1.0\" ?>\n");
90 m_xmlfile
.Write("<resource>\n");
93 ParseResourceHeader();
94 //Gather all the resource we need for toolbars,menus, and etc
98 //Read in dialogs, toolbars,menus
101 m_xmlfile
.Write("</resource>\n");
109 void rc2xml::ParseDialog(wxString dlgname
)
112 static int dlgid
=999;
114 /* Make sure that this really is a dialog
115 microsoft reuses the keyword DIALOG for other things
118 //Microsoft notation?
119 if (token
=="DISCARDABLE")
124 //Error isn't a Dialog resource eject eject
125 if (!token
.IsNumber())
128 //Record x,y,width,height
129 int x
,y
,width
,height
;
130 ReadRect(x
,y
,width
,height
);
134 wxString ptsize
,face
;
136 m_xmlfile
.Write("\t<object class=\"wxDialog\"");
137 //Avoid duplicate names this way
138 dlgname
.Replace("IDD_","DLG_");
139 WriteBasicInfo(x
,y
,width
,height
,dlgname
);
143 while ((token
!="BEGIN")&(token
!="{"))
145 if (token
=="CAPTION")
147 title
=GetQuoteField();
150 //TODO fix face name so that it is cross platform name
151 // FONT 8, "MS Sans Serif"
155 face
=GetQuoteField();
156 m_xmlfile
.Write("\t\t<font>\n");
157 m_xmlfile
.Write("\t\t\t<size>"+ptsize
+"</size>\n");
158 m_xmlfile
.Write("\t\t\t<face>"+face
+"</face>\n");
159 m_xmlfile
.Write("\t\t</font>\n");
166 m_xmlfile
.Write("\t</object>\n");
171 EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT
173 LTEXT "Bands",IDC_STATIC,11,86,21,8
174 EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL
177 void rc2xml::ParseControls()
182 while ((token
!="END")&(token
!="}"))
184 if (token
=="AUTOCHECKBOX")
187 if (token
=="AUTORADIOBUTTON")
192 else if (token
=="EDITTEXT")
194 else if (token
=="PUSHBUTTON")
196 else if (token
=="DEFPUSHBUTTON")
198 else if (token
=="GROUPBOX")
200 else if (token
=="COMBOBOX")
202 else if (token
=="CONTROL")
204 else if (token
=="LISTBOX")
206 else if (token
=="ICON")
208 else if (token
=="SCROLLBAR")
214 //LTEXT "Radius",IDC_STATIC,9,67,23,8
215 void rc2xml::ParseStaticText()
218 wxString phrase
,varname
;
219 phrase
=GetQuoteField();
221 int x
,y
,width
,height
;
222 ReadRect(x
,y
,width
,height
);
224 m_xmlfile
.Write("\t\t<object class=\"wxStaticText\"");
225 WriteBasicInfo(x
,y
,width
,height
,varname
);WriteLabel(phrase
);
226 m_xmlfile
.Write("\t\t</object>\n");
229 //EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
230 void rc2xml::ParseTextCtrl()
233 wxString varname
,style
;
235 int x
,y
,width
,height
;
236 ReadRect(x
,y
,width
,height
);
239 m_xmlfile
.Write("\t\t<object class=\"wxTextCtrl\"");
240 WriteBasicInfo(x
,y
,width
,height
,varname
);
241 m_xmlfile
.Write("\t\t</object>\n");
244 //AUTOCHECKBOX "&log.", ID_XLOG, 25, 24, 21, 12
245 void rc2xml::ParseCheckBox()
248 wxString phrase
,varname
;
249 phrase
=GetQuoteField();
252 int x
,y
,width
,height
;
253 ReadRect(x
,y
,width
,height
);
255 m_xmlfile
.Write("\t\t<object class=\"wxCheckBox\"");
256 WriteBasicInfo(x
,y
,width
,height
,varname
);
258 m_xmlfile
.Write("\t\t</object>\n");
261 //AUTORADIOBUTTON "&text", ID_SW10, 13, 12, 68, 10, BS_AUTORADIOBUTTON | WS_GROUP
262 void rc2xml::ParseRadioButton()
264 wxString token
,style
;
265 wxString phrase
,varname
;
266 phrase
=GetQuoteField();
269 int x
,y
,width
,height
;
270 if (ReadRect(x
,y
,width
,height
))
272 if (token
.Find("WS_GROUP") != -1)
273 style
+= "wxRB_GROUP";
275 m_xmlfile
.Write("\t\t<object class=\"wxRadioButton\"");
276 WriteBasicInfo(x
,y
,width
,height
,varname
);
279 m_xmlfile
.Write("\t\t</object>\n");
283 //PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
284 void rc2xml::ParsePushButton()
287 wxString phrase
,varname
;
288 phrase
=GetQuoteField();
291 int x
,y
,width
,height
;
292 ReadRect(x
,y
,width
,height
);
294 m_xmlfile
.Write("\t\t<object class=\"wxButton\"");
295 WriteBasicInfo(x
,y
,width
,height
,varname
);
297 m_xmlfile
.Write("\t\t</object>\n");
302 bool rc2xml::Seperator(int ch
)
304 //if ((ch==' ')|(ch==',')|(ch==13)|(ch==10)|(ch=='|')|(ch=='\t'))
305 if ((ch
==' ')|(ch
==',')|(ch
==13)|(ch
==10)|(ch
=='\t'))
317 void rc2xml::ParseGroupBox()
319 // GROUPBOX "Rotate",IDC_STATIC,1,1,71,79
321 wxString phrase
,varname
;
322 phrase
=GetQuoteField();
324 int x
,y
,width
,height
;
325 ReadRect(x
,y
,width
,height
);
327 m_xmlfile
.Write("\t\t<object class=\"wxStaticBox\"");
328 WriteBasicInfo(x
,y
,width
,height
,varname
);
330 m_xmlfile
.Write("\t\t</object>\n");
333 bool rc2xml::ReadRect(int & x
, int & y
, int & width
, int & height
)
337 width
=atoi(GetToken());
339 wxString tmp
= GetToken(&ret
);
341 return ret
; // check for more parameters
344 wxString
rc2xml::GetToken(bool *listseperator
)
362 while (Seperator(ch
))
375 while (!Seperator(ch
))
385 *listseperator
= (ch
== ',');
389 wxString
rc2xml::GetQuoteField()
409 void rc2xml::ReadChar(int &ch
)
414 if((result
>=m_filesize
))
417 result
=m_rc
.Read(&ch
,1);
426 void rc2xml::ParseComboBox()
428 /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
429 WS_VSCROLL | WS_TABSTOP */
430 wxString token
,style
;
433 int x
,y
,width
,height
;
434 if (ReadRect(x
,y
,width
,height
))
437 m_xmlfile
.Write("\t\t<object class=\"wxComboBox\"");
438 WriteBasicInfo(x
,y
,width
,height
,varname
);
439 if (token
.Find("CBS_SIMPLE") != -1)
440 WriteStyle("wxCB_SIMPLE");
441 if (token
.Find("CBS_SORT") != -1)
442 WriteStyle("wxCB_SORT");
443 if (token
.Find("CBS_DISABLENOSCROLL") != -1)
444 WriteStyle("wxLB_ALWAYS_SB");
445 m_xmlfile
.Write("\n\t\t</object>\n");
449 void rc2xml::ParseMenu(wxString varname
)
453 //Write menubar to xml file
454 m_xmlfile
.Write("\t<object class=\"wxMenuBar\"");
455 //Avoid duplicate names this way
456 varname
.Replace("IDR_","MB_");
458 m_xmlfile
.Write(">\n");
460 while ((token
!="BEGIN")&(token
!="{"))
463 while ((token
!="END")&(token
!="}"))
471 m_xmlfile
.Write("\t</object>\n");
474 void rc2xml::ParsePopupMenu()
476 static int menucount
=0;
478 wxString token
,name
,msg
,longhelp
,tip
;
479 token
=GetQuoteField();
481 //Remove \t because it causes problems
483 //spot=token.First("\\t");
484 //token=token.Left(spot);
487 //Generate a fake name since RC menus don't have one
488 name
<<"Menu_"<<menucount
;
489 m_xmlfile
.Write("\t\t<object class=\"wxMenu\"");
491 m_xmlfile
.Write(">\n");
494 while ((token
!="BEGIN")&(token
!="{"))
497 while ((token
!="END")&(token
!="}"))
503 if (token
=="MENUITEM")
506 m_xmlfile
.Write("\t\t\t</object>\n");
509 wxString
rc2xml::PeekToken()
519 //MS Windows pain in the butt CONTROL
520 void rc2xml::ParseControlMS()
522 wxString label
,varname
,kindctrl
,token
;
525 if (token
.Contains("\""))
526 ParseNormalMSControl();
528 ParseWeirdMSControl();
532 /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
533 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
536 void rc2xml::ParseSlider(wxString label
, wxString varname
)
538 wxString token
,style
;
540 if (token
.Find("TBS_VERT")!=-1)
541 style
+="wxSL_VERTICAL";
542 //MFC RC Default is horizontal
544 style
+="wxSL_HORIZONTAL";
546 int x
,y
,width
,height
;
547 ReadRect(x
,y
,width
,height
);
548 m_xmlfile
.Write("\t\t<object class=\"wxSlider\"");
549 WriteBasicInfo(x
,y
,width
,height
,varname
);
551 m_xmlfile
.Write("\n\t\t</object>\n");
555 CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
556 WS_BORDER,15,52,154,13
558 void rc2xml::ParseProgressBar(wxString label
, wxString varname
)
560 wxString token
,style
;
563 int x
,y
,width
,height
;
564 ReadRect(x
,y
,width
,height
);
566 //Always horizontal in MFC
567 m_xmlfile
.Write("\t\t<object class=\"wxGauge\"");
568 WriteBasicInfo(x
,y
,width
,height
,varname
);
570 m_xmlfile
.Write("\t\t</object>\n");
573 bool rc2xml::ReadOrs(wxString
& orstring
)
578 if (token
.IsNumber())
582 while(PeekToken()==_T("|"))
585 orstring
+=GetToken();
587 orstring
+=GetToken();
592 //Is it a check button or a radio button
593 void rc2xml::ParseCtrlButton(wxString label
, wxString varname
)
597 int x
,y
,width
,height
;
599 if (token
.Find("BS_AUTOCHECKBOX")!=-1)
601 ReadRect(x
,y
,width
,height
);
602 m_xmlfile
.Write("\t\t<object class=\"wxCheckBox\"");
603 WriteBasicInfo(x
,y
,width
,height
,varname
);
605 m_xmlfile
.Write("\t\t</object>\n");
608 if (token
.Find("BS_AUTORADIOBUTTON")!=-1)
610 ReadRect(x
,y
,width
,height
);
611 m_xmlfile
.Write("\t\t<object class=\"wxRadioButton\"");
612 WriteBasicInfo(x
,y
,width
,height
,varname
);
614 m_xmlfile
.Write("\t\t</object>\n");
620 void rc2xml::WriteSize(int width
, int height
)
623 msg
<<" <size>"<<width
<<","<<height
<<"d</size>";
624 m_xmlfile
.Write(msg
);
627 void rc2xml::WritePosition(int x
, int y
)
630 msg
<<" <pos>"<<x
<<","<<y
<<"d</pos>";
631 m_xmlfile
.Write(msg
);
634 void rc2xml::WriteTitle(wxString title
)
637 msg
=_T("\t\t<title>"+title
+"</title>\n");
638 m_xmlfile
.Write(msg
);
641 void rc2xml::WriteName(wxString name
)
644 //Try to convert any number ids into names
646 //Replace common MS ids with wxWindows ids
647 //I didn't do everyone of them
650 else if (name
=="IDCANCEL")
652 else if (name
=="IDAPPLY")
654 else if (name
=="ID_FILE_OPEN")
656 else if (name
=="ID_FILE_CLOSE")
658 else if (name
=="ID_FILE_SAVE")
660 else if (name
=="ID_FILE_SAVE_AS")
662 else if (name
=="ID_APP_EXIT")
664 else if (name
=="ID_FILE_PRINT")
666 else if (name
=="ID_FILE_PRINT_PREVIEW")
668 else if (name
=="ID_FILE_PRINT_SETUP")
669 name
="wxID_PRINT_SETUP";
670 else if (name
=="ID_APP_ABOUT")
672 else if (name
=="ID_EDIT_UNDO")
674 else if (name
=="ID_EDIT_CUT")
676 else if (name
=="ID_EDIT_COPY")
678 else if (name
=="ID_EDIT_PASTE")
680 else if (name
=="IDYES")
682 else if (name
=="IDNO")
684 else if (name
=="IDHELP")
687 m_xmlfile
.Write(" name= \""+name
+"\"");
690 void rc2xml::WriteLabel(wxString label
)
692 label
.Replace("&","$");
693 m_xmlfile
.Write("\t\t\t<label>"+label
+"</label>\n");
696 void rc2xml::WriteBasicInfo(int x
, int y
, int width
, int height
, wxString name
)
699 m_xmlfile
.Write(">\n");
700 m_xmlfile
.Write("\t\t\t");
702 WriteSize(width
,height
);
703 m_xmlfile
.Write("\n");
706 void rc2xml::WriteStyle(wxString style
)
708 if (style
.Length()==0)
710 m_xmlfile
.Write("\t\t\t<style>"+style
+"</style>\n");
713 LISTBOX IDC_LIST1,16,89,48,40,LBS_SORT | LBS_MULTIPLESEL |
714 LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
716 void rc2xml::ParseListBox()
721 int x
,y
,width
,height
;
722 ReadRect(x
,y
,width
,height
);
724 m_xmlfile
.Write("\t\t<object class=\"wxListBox\"");
725 WriteBasicInfo(x
,y
,width
,height
,varname
);
726 m_xmlfile
.Write("\n\t\t</object>\n");
730 CONTROL "",IDC_RICHEDIT1,"RICHEDIT",ES_AUTOHSCROLL | WS_BORDER |
731 WS_TABSTOP,103,110,40,14
733 void rc2xml::ParseRichEdit(wxString label
, wxString varname
)
736 //while (ReadOrs(token));
738 int x
,y
,width
,height
;
739 ReadRect(x
,y
,width
,height
);
741 //Make it a rich text control
742 style
+="wxTE_MULTILINE ";
743 m_xmlfile
.Write("\t\t<object class=\"wxTextCtrl\"");
744 WriteBasicInfo(x
,y
,width
,height
,varname
);
746 m_xmlfile
.Write("\t\t</object>\n");
750 CONTROL "Spin1",IDC_SPIN1,"msctls_updown32",UDS_ARROWKEYS,209,72,
753 void rc2xml::ParseSpinCtrl(wxString label
, wxString varname
)
755 wxString token
,style
;
758 if (token
.Find("UDS_HORZ")!=-1)
759 style
="wxSP_HORIZONTAL";
762 style
="wxSP_VERTICAL";
764 int x
,y
,width
,height
;
765 ReadRect(x
,y
,width
,height
);
766 m_xmlfile
.Write("\t\t<object class=\"wxSpinButton\"");
767 WriteBasicInfo(x
,y
,width
,height
,varname
);
769 m_xmlfile
.Write("\n\t\t</object>\n");
773 void rc2xml::FirstPass()
775 wxString token
,prevtok
;
780 ParseBitmap(prevtok
);
781 else if (token
=="STRINGTABLE")
782 ParseStringTable(prevtok
);
783 else if (token
=="ICON")
790 void rc2xml::ParseBitmap(wxString varname
)
792 wxString token
,*bitmapfile
;
795 //Microsoft notation?
796 if (token
=="DISCARDABLE")
801 bitmapfile
=new wxString
;
802 *bitmapfile
=GetQuoteField();
803 m_bitmaplist
->Append(varname
,bitmapfile
);
808 void rc2xml::SecondPass()
810 wxString token
,prevtok
;
815 ParseDialog(prevtok
);
816 else if (token
=="MENU")
818 else if (token
=="TOOLBAR")
819 ParseToolBar(prevtok
);
826 void rc2xml::ParseToolBar(wxString varname
)
830 wxASSERT_MSG(token
=="DISCARDABLE","Error in toolbar parsing");
831 //Look up bitmap for toolbar and load
832 wxNode
*node
=m_bitmaplist
->Find(LookUpId(varname
));
833 wxString
*bitmappath
;
834 bitmappath
=(wxString
*)node
->Data();
836 if (!bitmap
.LoadFile(*bitmappath
,wxBITMAP_TYPE_BMP
))
837 wxLogError("Unable to load bitmap:"+*bitmappath
);
839 //Write toolbar to xml file
840 m_xmlfile
.Write(" <object class=\"wxToolBar\"");
841 //Avoid duplicate names this way
842 varname
.Replace("IDR_","TB_");
844 m_xmlfile
.Write(">\n");
850 //Grab width and height
852 width
=atoi(GetToken());
853 height
=atoi(GetToken());
856 wxString buttonname
,msg
,tip
,longhelp
;
858 while ((token
!="BEGIN"))
861 while ((token
!="END")&(token
!="}"))
865 buttonname
=GetToken();
866 m_xmlfile
.Write("\t\t\t<object class=\"tool\"");
867 WriteName(buttonname
);
868 m_xmlfile
.Write(">\n");
869 //Write tool tip if any
870 if (LookUpString(buttonname
,msg
))
872 SplitHelp(msg
,tip
,longhelp
);
873 m_xmlfile
.Write("\t\t\t\t<tooltip>"+tip
+"</tooltip>\n");
874 m_xmlfile
.Write(" <longhelp>"+longhelp
+"</longhelp>\n");
876 //Make a bitmap file name
877 buttonname
=CleanName(buttonname
);
879 m_xmlfile
.Write("\t\t\t\t<bitmap>"+buttonname
+"</bitmap>\n");
880 WriteToolButton(buttonname
,c
,width
,height
,bitmap
);
881 m_xmlfile
.Write("\t\t\t</object>\n");
884 else if (token
=="SEPARATOR")
886 m_xmlfile
.Write("\t\t\t<object class=\"separator\"/>\n");
890 m_xmlfile
.Write("\t</object>\n");
893 //Extract bitmaps from larger toolbar bitmap
894 void rc2xml::WriteToolButton(wxString name
,int index
, int width
, int height
, wxBitmap bitmap
)
898 wxRect
r(x
,0,width
,height
);
900 little
=bitmap
.GetSubBitmap(r
);
901 little
.SaveFile(m_targetpath
+name
,wxBITMAP_TYPE_BMP
);
904 void rc2xml::ParseStringTable(wxString varname
)
908 while ((token
!="BEGIN"))
913 while ((token
!="END")&(token
!="}"))
916 *msg
=GetQuoteField();
917 m_stringtable
->Append(token
,msg
);
923 bool rc2xml::LookUpString(wxString strid
,wxString
& st
)
925 wxNode
*node
=m_stringtable
->Find(strid
);
930 s
=(wxString
*)node
->Data();
936 bool rc2xml::SplitHelp(wxString msg
, wxString
&shorthelp
, wxString
&longhelp
)
939 spot
=msg
.Find("\\n");
946 longhelp
=msg
.Left(spot
);
947 spot
=msg
.Length()-spot
-2;
948 shorthelp
=msg
.Right(spot
);
952 void rc2xml::ParseMenuItem()
954 wxString token
,name
,msg
,tip
,longhelp
;
956 if (PeekToken()=="SEPARATOR")
958 m_xmlfile
.Write("\t\t\t<object class=\"separator\"/>\n");
962 token
=GetQuoteField();
964 //Remove \t because it causes problems
965 //spot=token.First("\\t");
966 //token=token.Left(spot);
967 m_xmlfile
.Write("\t\t\t<object class=\"wxMenuItem\"");
969 m_xmlfile
.Write(">\n");
971 //Look up help if any listed in stringtable
972 if (LookUpString(name
,msg
))
974 SplitHelp(msg
,tip
,longhelp
);
975 m_xmlfile
.Write("\t\t\t<help>"
976 +longhelp
+"</help>\n");
978 //look for extra attributes like checked and break
981 while ((ptoken
!="MENUITEM")&(ptoken
!="POPUP")&(ptoken
!="END"))
984 if (token
=="CHECKED")
985 m_xmlfile
.Write("\t\t\t<checkable>1</checkable>\n");
986 else if (token
=="MENUBREAK");
987 //m_xmlfile.Write("\t\t\t</break>\n");
988 else if (token
=="GRAYED");
990 wxLogError("Unknown Menu Item token:"+token
);
994 m_xmlfile
.Write("\t\t\t</object>\n");
998 //ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
999 void rc2xml::ParseIconStatic()
1002 wxString varname
,iconname
;
1003 iconname
=GetToken();
1007 int x
,y
,width
,height
;
1008 ReadRect(x
,y
,width
,height
);
1010 m_xmlfile
.Write("\t\t<object class=\"wxStaticBitmap\"");
1011 WriteBasicInfo(x
,y
,width
,height
,varname
);
1012 //Save icon as a bitmap
1013 WriteIcon(iconname
);
1014 m_xmlfile
.Write("\t\t</object>\n");
1017 //IDR_MAINFRAME ICON DISCARDABLE "res\\mfcexample.ico"
1018 void rc2xml::ParseIcon(wxString varname
)
1020 wxString token
,*iconfile
;
1021 iconfile
=new wxString
;
1024 *iconfile
=GetQuoteField();
1025 m_iconlist
->Append(varname
,iconfile
);
1030 wxString
rc2xml::CleanName(wxString name
)
1033 name
.Replace("id_","");
1034 name
.Replace("idr_","");
1035 name
.Replace("idb_","");
1036 name
.Replace("idc_","");
1038 name
.Replace(".ico","");
1040 name
.Replace(".bmp","");
1043 // And the award for most messed up control goes to...
1044 // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
1045 void rc2xml::ParseStaticBitmap(wxString bitmapname
, wxString varname
)
1053 int x
,y
,width
,height
;
1054 ReadRect(x
,y
,width
,height
);
1056 m_xmlfile
.Write("\t\t<object class=\"wxStaticBitmap\"");
1057 WriteBasicInfo(x
,y
,width
,height
,varname
);
1058 WriteBitmap(bitmapname
);
1059 m_xmlfile
.Write("\t\t</object>\n");
1063 void rc2xml::ParseNormalMSControl()
1065 wxString label
,varname
,kindctrl
;
1067 label
=GetQuoteField();
1069 kindctrl
=GetQuoteField();
1070 kindctrl
.MakeUpper();
1072 if (kindctrl
=="MSCTLS_UPDOWN32")
1073 ParseSpinCtrl(label
,varname
);
1074 if (kindctrl
=="MSCTLS_TRACKBAR32")
1075 ParseSlider(label
,varname
);
1076 if (kindctrl
=="MSCTLS_PROGRESS32")
1077 ParseProgressBar(label
,varname
);
1078 if (kindctrl
=="SYSTREEVIEW32")
1079 ParseTreeCtrl(label
,varname
);
1080 if (kindctrl
=="SYSMONTHCAL32")
1081 ParseCalendar(label
,varname
);
1082 if (kindctrl
=="SYSLISTVIEW32")
1083 ParseListCtrl(label
,varname
);
1084 if (kindctrl
=="BUTTON")
1085 ParseCtrlButton(label
,varname
);
1086 if (kindctrl
=="RICHEDIT")
1087 ParseRichEdit(label
,varname
);
1091 void rc2xml::ParseWeirdMSControl()
1098 kindctrl
=GetQuoteField();
1099 kindctrl
.MakeUpper();
1100 // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
1101 if (kindctrl
=="STATIC")
1103 if (PeekToken()=="SS_BITMAP")
1104 ParseStaticBitmap(id
,varname
);
1106 wxLogError("Unknown MS Control Static token");
1110 //SCROLLBAR IDC_SCROLLBAR1,219,56,10,40,SBS_VERT
1112 void rc2xml::ParseScrollBar()
1118 int x
,y
,width
,height
;
1119 ReadRect(x
,y
,width
,height
);
1124 if (token
.Find("SBS_VERT")!=-1)
1125 style
=_T("wxSB_VERTICAL");
1126 //Default MFC style is horizontal
1128 style
=_T("wxSB_HORIZONTAL");
1130 m_xmlfile
.Write("\t\t<object class=\"wxScrollBar\"");
1131 WriteBasicInfo(x
,y
,width
,height
,varname
);
1133 m_xmlfile
.Write("\n\t\t</object>\n");
1136 // CONTROL "Tree1",IDC_TREE1,"SysTreeView32",WS_BORDER | WS_TABSTOP,
1139 void rc2xml::ParseTreeCtrl(wxString label
, wxString varname
)
1142 //while (ReadOrs(token));
1144 int x
,y
,width
,height
;
1145 ReadRect(x
,y
,width
,height
);
1146 m_xmlfile
.Write("\t\t<object class=\"wxTreeCtrl\"");
1147 WriteBasicInfo(x
,y
,width
,height
,varname
);
1148 m_xmlfile
.Write("\t\t</object>\n");
1151 // CONTROL "MonthCalendar1",IDC_MONTHCALENDAR1,"SysMonthCal32",
1152 //MCS_NOTODAY | WS_TABSTOP,105,71,129,89
1154 void rc2xml::ParseCalendar(wxString label
, wxString varname
)
1157 //while (ReadOrs(token));
1159 int x
,y
,width
,height
;
1160 ReadRect(x
,y
,width
,height
);
1161 m_xmlfile
.Write("\t\t<object class=\"wxCalendarCtrl\"");
1162 WriteBasicInfo(x
,y
,width
,height
,varname
);
1163 m_xmlfile
.Write("\t\t</object>\n");
1165 // CONTROL "List1",IDC_LIST1,"SysListView32",WS_BORDER | WS_TABSTOP,
1168 void rc2xml::ParseListCtrl(wxString label
, wxString varname
)
1171 //while (ReadOrs(token));
1173 int x
,y
,width
,height
;
1174 ReadRect(x
,y
,width
,height
);
1175 m_xmlfile
.Write("\t\t<object class=\"wxListCtrl\"");
1176 WriteBasicInfo(x
,y
,width
,height
,varname
);
1177 m_xmlfile
.Write("\t\t</object>\n");
1181 void rc2xml::WriteBitmap(wxString bitmapname
)
1184 wxNode
*node
=m_bitmaplist
->Find(LookUpId(bitmapname
));
1187 m_xmlfile
.Write("\t\t\t<bitmap>missingfile</bitmap>\n");
1188 wxLogError("Unable to find bitmap:"+bitmapname
);
1192 wxString
*bitmappath
;
1193 bitmappath
=(wxString
*)node
->Data();
1195 bitmapname
=wxFileNameFromPath(*bitmappath
);
1197 if (!bitmap
.LoadFile(*bitmappath
,wxBITMAP_TYPE_BMP
))
1198 wxLogError("Unable to load bitmap:"+*bitmappath
);
1200 //Make a bitmap file name
1201 bitmapname
=CleanName(bitmapname
);
1203 m_xmlfile
.Write("\t\t\t<bitmap>"+bitmapname
+"</bitmap>\n");
1204 bitmap
.SaveFile(m_targetpath
+bitmapname
,wxBITMAP_TYPE_BMP
);
1207 void rc2xml::WriteIcon(wxString iconname
)
1209 wxNode
*node
=m_iconlist
->Find(iconname
);
1212 m_xmlfile
.Write("\t\t\t<bitmap>missing_file</bitmap>\n");
1213 wxLogError("Unable to find icon:"+iconname
);
1216 iconpath
=(wxString
*)node
->Data();
1219 if (!icon
.LoadFile(*iconpath
,wxBITMAP_TYPE_ICO
))
1220 wxLogError("Unable to load icon:"+*iconpath
);
1222 bitmap
.CopyFromIcon(icon
);
1226 iconname
=wxFileNameFromPath(*iconpath
);
1227 //Make a bitmap file name
1228 iconname
=CleanName(iconname
);
1230 m_xmlfile
.Write("\t\t\t<bitmap>"+iconname
+"</bitmap>\n");
1231 bitmap
.SaveFile(m_targetpath
+iconname
,wxBITMAP_TYPE_BMP
);
1235 /*Unfortunately sometimes the great MSVC Resource editor decides
1236 to use numbers instead of the word id. I have no idea why they
1237 do this, but that is the way it is.
1239 /* this is a quick and dirty way to parse the resource.h file
1240 it will not recognize #ifdef so it can be easily fooled
1242 void rc2xml::ParseResourceHeader()
1245 //Attempt to load resource.h in current path
1246 if (!r
.Open("resource.h"))
1248 wxLogError("Warining Unable to load resource.h file");
1254 wxStringTokenizer tok
;
1260 //Read through entire file
1261 for ( str
= r
.GetFirstLine(); !r
.Eof(); str
= r
.GetNextLine() )
1263 if (str
.Find("#define")!=-1)
1266 //Just ignore #define token
1268 v
=tok
.GetNextToken();
1269 id
=tok
.GetNextToken();
1272 varname
=new wxString
;
1275 m_resourcelist
->Append(n
,varname
);
1285 wxString
rc2xml::LookUpId(wxString id
)
1293 wxNode
*node
=m_resourcelist
->Find(n
);
1298 s
=(wxString
*)node
->Data();