]>
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");
104 wxMessageBox(_("Conversion complete."), _("Done"),
105 wxOK
| wxICON_INFORMATION
);
111 void rc2xml::ParseDialog(wxString dlgname
)
114 static int dlgid
=999;
116 /* Make sure that this really is a dialog
117 microsoft reuses the keyword DIALOG for other things
120 //Microsoft notation?
121 while ((token
=="DISCARDABLE")
122 ||(token
=="LOADONCALL")||(token
=="MOVEABLE"))
127 //Error isn't a Dialog resource eject eject
128 if (!token
.IsNumber())
131 //Record x,y,width,height
132 int x
,y
,width
,height
;
133 ReadRect(x
,y
,width
,height
);
137 wxString ptsize
,face
;
139 m_xmlfile
.Write("\t<object class=\"wxDialog\"");
140 //Avoid duplicate names this way
141 dlgname
.Replace("IDD_","DLG_");
142 WriteBasicInfo(x
,y
,width
,height
,dlgname
);
146 while ((token
!="BEGIN")&(token
!="{"))
148 if (token
=="CAPTION")
150 title
=GetQuoteField();
153 //TODO fix face name so that it is cross platform name
154 // FONT 8, "MS Sans Serif"
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");
169 m_xmlfile
.Write("\t</object>\n");
174 EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT
176 LTEXT "Bands",IDC_STATIC,11,86,21,8
177 EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL
180 void rc2xml::ParseControls()
183 wxString label
,varname
;
186 while ((token
!="END")&(token
!="}"))
188 if (token
=="AUTOCHECKBOX")
190 label
=GetQuoteField();
192 ParseCheckBox(label
,varname
);
195 if (token
=="AUTORADIOBUTTON")
197 label
=GetQuoteField();
199 ParseRadioButton(label
,varname
);
204 label
=GetQuoteField();
206 ParseStaticText(label
,varname
);
208 else if (token
=="EDITTEXT")
211 ParseTextCtrl(varname
);
213 else if ((token
=="PUSHBUTTON")||(token
=="DEFPUSHBUTTON"))
215 label
=GetQuoteField();
217 ParsePushButton(label
,varname
);
219 else if (token
=="GROUPBOX")
221 label
=GetQuoteField();
223 ParseGroupBox(label
,varname
);
225 else if (token
=="COMBOBOX")
228 ParseComboBox(varname
);
230 else if (token
=="CONTROL")
232 else if (token
=="LISTBOX")
235 ParseListBox(varname
);
237 else if (token
=="ICON")
239 else if (token
=="SCROLLBAR")
245 //LTEXT "Radius",IDC_STATIC,9,67,23,8
246 void rc2xml::ParseStaticText(wxString phrase
, wxString varname
)
250 while (!token
.IsNumber())
255 int x
,y
,width
,height
;
256 ReadRect(x
,y
,width
,height
);
258 m_xmlfile
.Write("\t\t<object class=\"wxStaticText\"");
259 WriteBasicInfo(x
,y
,width
,height
,varname
);WriteLabel(phrase
);
260 m_xmlfile
.Write("\t\t</object>\n");
263 //EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
264 void rc2xml::ParseTextCtrl(wxString varname
)
269 while (!token
.IsNumber())
274 int x
,y
,width
,height
;
275 ReadRect(x
,y
,width
,height
);
278 m_xmlfile
.Write("\t\t<object class=\"wxTextCtrl\"");
279 WriteBasicInfo(x
,y
,width
,height
,varname
);
280 m_xmlfile
.Write("\t\t</object>\n");
283 //AUTOCHECKBOX "&log.", ID_XLOG, 25, 24, 21, 12
284 void rc2xml::ParseCheckBox(wxString phrase
, wxString varname
)
288 while (!token
.IsNumber())
293 int x
,y
,width
,height
;
294 ReadRect(x
,y
,width
,height
);
296 m_xmlfile
.Write("\t\t<object class=\"wxCheckBox\"");
297 WriteBasicInfo(x
,y
,width
,height
,varname
);
299 m_xmlfile
.Write("\t\t</object>\n");
302 //AUTORADIOBUTTON "&text", ID_SW10, 13, 12, 68, 10, BS_AUTORADIOBUTTON | WS_GROUP
303 void rc2xml::ParseRadioButton(wxString phrase
, wxString varname
)
305 wxString token
,style
;
306 int x
,y
,width
,height
;
308 GotOrs
= ReadOrs(token
);
309 if (ReadRect(x
,y
,width
,height
))
312 if (token
.Find("WS_GROUP") != -1)
313 style
+= "wxRB_GROUP";
315 m_xmlfile
.Write("\t\t<object class=\"wxRadioButton\"");
316 WriteBasicInfo(x
,y
,width
,height
,varname
);
319 m_xmlfile
.Write("\t\t</object>\n");
323 //PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
324 void rc2xml::ParsePushButton(wxString phrase
, wxString varname
)
329 while (!token
.IsNumber())
334 int x
,y
,width
,height
;
335 ReadRect(x
,y
,width
,height
);
337 m_xmlfile
.Write("\t\t<object class=\"wxButton\"");
338 WriteBasicInfo(x
,y
,width
,height
,varname
);
340 m_xmlfile
.Write("\t\t</object>\n");
345 bool rc2xml::Seperator(int ch
)
347 //if ((ch==' ')|(ch==',')|(ch==13)|(ch==10)|(ch=='|')|(ch=='\t'))
348 if ((ch
==' ')|(ch
==',')|(ch
==13)|(ch
==10)|(ch
=='\t'))
360 void rc2xml::ParseGroupBox(wxString phrase
, wxString varname
)
362 // GROUPBOX "Rotate",IDC_STATIC,1,1,71,79
365 while (!token
.IsNumber())
370 int x
,y
,width
,height
;
371 ReadRect(x
,y
,width
,height
);
373 m_xmlfile
.Write("\t\t<object class=\"wxStaticBox\"");
374 WriteBasicInfo(x
,y
,width
,height
,varname
);
376 m_xmlfile
.Write("\t\t</object>\n");
379 bool rc2xml::ReadRect(int & x
, int & y
, int & width
, int & height
)
383 width
=atoi(GetToken());
385 wxString tmp
= GetToken(&ret
);
387 return ret
; // check for more parameters
390 wxString
rc2xml::GetToken(bool *listseperator
)
408 while (Seperator(ch
))
421 while (!Seperator(ch
))
431 *listseperator
= (ch
== ',');
435 wxString
rc2xml::GetQuoteField()
454 // string in stringtable may contain embedded quotes
455 // escape characters retained to allow strings to be rewritten
456 wxString
rc2xml::GetStringQuote()
469 if ((ch
==34)&&(lastch
!='\\'))
473 // RC supports "", for embedded quote, as well as \"
485 ReadChar(ch
); // skip
486 if ((ch
=='\n')&&(lastch
=='\\')) // lastch <should> be this
487 phrase
+='n'; // escape
497 void rc2xml::ReadChar(int &ch
)
502 if((result
>=m_filesize
))
505 result
=m_rc
.Read(&ch
,1);
514 void rc2xml::ParseComboBox(wxString varname
)
516 /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
517 WS_VSCROLL | WS_TABSTOP */
518 wxString token
,style
;
519 int x
,y
,width
,height
;
521 GotOrs
= ReadOrs(token
);
522 if (ReadRect(x
,y
,width
,height
))
526 m_xmlfile
.Write("\t\t<object class=\"wxComboBox\"");
527 WriteBasicInfo(x
,y
,width
,height
,varname
);
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");
534 m_xmlfile
.Write("\n\t\t</object>\n");
538 void rc2xml::ParseMenu(wxString varname
)
542 //Write menubar to xml file
543 m_xmlfile
.Write("\t<object class=\"wxMenuBar\"");
544 //Avoid duplicate names this way
545 varname
.Replace("IDR_","MB_");
547 m_xmlfile
.Write(">\n");
549 while ((token
!="BEGIN")&(token
!="{"))
552 while ((token
!="END")&(token
!="}"))
562 m_xmlfile
.Write("\t</object>\n");
565 void rc2xml::ParsePopupMenu()
567 static int menucount
=0;
569 wxString token
,name
,msg
,longhelp
,tip
;
570 token
=GetQuoteField();
572 //Remove \t because it causes problems
574 //spot=token.First("\\t");
575 //token=token.Left(spot);
578 //Generate a fake name since RC menus don't have one
579 name
<<"Menu_"<<menucount
;
580 m_xmlfile
.Write("\t\t<object class=\"wxMenu\"");
582 m_xmlfile
.Write(">\n");
585 while ((token
!="BEGIN")&(token
!="{"))
588 while ((token
!="END")&(token
!="}"))
596 if (token
=="MENUITEM")
599 m_xmlfile
.Write("\t\t\t</object>\n");
602 wxString
rc2xml::PeekToken()
612 //MS Windows pain in the butt CONTROL
613 void rc2xml::ParseControlMS()
615 wxString label
,varname
,kindctrl
,token
;
618 if (token
.Contains("\""))
619 ParseNormalMSControl();
621 ParseWeirdMSControl();
625 /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
626 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
629 void rc2xml::ParseSlider(wxString label
, wxString varname
)
631 wxString token
,style
;
633 if (token
.Find("TBS_VERT")!=-1)
634 style
+="wxSL_VERTICAL";
635 //MFC RC Default is horizontal
637 style
+="wxSL_HORIZONTAL";
639 int x
,y
,width
,height
;
640 ReadRect(x
,y
,width
,height
);
641 m_xmlfile
.Write("\t\t<object class=\"wxSlider\"");
642 WriteBasicInfo(x
,y
,width
,height
,varname
);
644 m_xmlfile
.Write("\n\t\t</object>\n");
648 CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
649 WS_BORDER,15,52,154,13
651 void rc2xml::ParseProgressBar(wxString label
, wxString varname
)
653 wxString token
,style
;
656 int x
,y
,width
,height
;
657 ReadRect(x
,y
,width
,height
);
659 //Always horizontal in MFC
660 m_xmlfile
.Write("\t\t<object class=\"wxGauge\"");
661 WriteBasicInfo(x
,y
,width
,height
,varname
);
663 m_xmlfile
.Write("\t\t</object>\n");
666 bool rc2xml::ReadOrs(wxString
& orstring
)
671 if (token
.IsNumber())
675 while(PeekToken()==_T("|"))
678 orstring
+=GetToken();
680 orstring
+=GetToken();
685 //Is it a checkbutton or a radiobutton or a pushbutton or a groupbox
686 void rc2xml::ParseCtrlButton(wxString label
, wxString varname
)
694 if (token
.Find("BS_AUTOCHECKBOX")!=-1)
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
706 void rc2xml::WriteSize(int width
, int height
)
709 msg
<<" <size>"<<width
<<","<<height
<<"d</size>";
710 m_xmlfile
.Write(msg
);
713 void rc2xml::WritePosition(int x
, int y
)
716 msg
<<" <pos>"<<x
<<","<<y
<<"d</pos>";
717 m_xmlfile
.Write(msg
);
720 void rc2xml::WriteTitle(wxString title
)
723 msg
=_T("\t\t<title>"+title
+"</title>\n");
724 m_xmlfile
.Write(msg
);
727 void rc2xml::WriteName(wxString name
)
730 //Try to convert any number ids into names
732 //Replace common MS ids with wxWindows ids
733 //I didn't do everyone of them
736 else if (name
=="IDCANCEL")
738 else if (name
=="IDAPPLY")
740 else if (name
=="ID_FILE_OPEN")
742 else if (name
=="ID_FILE_CLOSE")
744 else if (name
=="ID_FILE_SAVE")
746 else if (name
=="ID_FILE_SAVE_AS")
748 else if (name
=="ID_APP_EXIT")
750 else if (name
=="ID_FILE_PRINT")
752 else if (name
=="ID_FILE_PRINT_PREVIEW")
754 else if (name
=="ID_FILE_PRINT_SETUP")
755 name
="wxID_PRINT_SETUP";
756 else if (name
=="ID_APP_ABOUT")
758 else if (name
=="ID_EDIT_UNDO")
760 else if (name
=="ID_EDIT_CUT")
762 else if (name
=="ID_EDIT_COPY")
764 else if (name
=="ID_EDIT_PASTE")
766 else if (name
=="IDYES")
768 else if (name
=="IDNO")
770 else if (name
=="IDHELP")
773 m_xmlfile
.Write(" name= \""+name
+"\"");
776 void rc2xml::WriteLabel(wxString label
)
778 label
.Replace("&","$");
779 m_xmlfile
.Write("\t\t\t<label>"+label
+"</label>\n");
782 void rc2xml::WriteBasicInfo(int x
, int y
, int width
, int height
, wxString name
)
785 m_xmlfile
.Write(">\n");
786 m_xmlfile
.Write("\t\t\t");
788 WriteSize(width
,height
);
789 m_xmlfile
.Write("\n");
792 void rc2xml::WriteStyle(wxString style
)
794 if (style
.Length()==0)
796 m_xmlfile
.Write("\t\t\t<style>"+style
+"</style>\n");
799 LISTBOX IDC_LIST1,16,89,48,40,LBS_SORT | LBS_MULTIPLESEL |
800 LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
802 void rc2xml::ParseListBox(wxString varname
)
806 while (!token
.IsNumber())
811 int x
,y
,width
,height
;
812 ReadRect(x
,y
,width
,height
);
814 m_xmlfile
.Write("\t\t<object class=\"wxListBox\"");
815 WriteBasicInfo(x
,y
,width
,height
,varname
);
816 m_xmlfile
.Write("\n\t\t</object>\n");
820 CONTROL "",IDC_RICHEDIT1,"RICHEDIT",ES_AUTOHSCROLL | WS_BORDER |
821 WS_TABSTOP,103,110,40,14
823 void rc2xml::ParseRichEdit(wxString label
, wxString varname
)
826 //while (ReadOrs(token));
828 int x
,y
,width
,height
;
829 ReadRect(x
,y
,width
,height
);
831 //Make it a rich text control
832 style
+="wxTE_MULTILINE ";
833 m_xmlfile
.Write("\t\t<object class=\"wxTextCtrl\"");
834 WriteBasicInfo(x
,y
,width
,height
,varname
);
836 m_xmlfile
.Write("\t\t</object>\n");
840 CONTROL "Spin1",IDC_SPIN1,"msctls_updown32",UDS_ARROWKEYS,209,72,
843 void rc2xml::ParseSpinCtrl(wxString label
, wxString varname
)
845 wxString token
,style
;
848 if (token
.Find("UDS_HORZ")!=-1)
849 style
="wxSP_HORIZONTAL";
852 style
="wxSP_VERTICAL";
854 int x
,y
,width
,height
;
855 ReadRect(x
,y
,width
,height
);
856 m_xmlfile
.Write("\t\t<object class=\"wxSpinButton\"");
857 WriteBasicInfo(x
,y
,width
,height
,varname
);
859 m_xmlfile
.Write("\n\t\t</object>\n");
863 void rc2xml::FirstPass()
865 wxString token
,prevtok
;
870 ParseBitmap(prevtok
);
871 else if (token
=="STRINGTABLE")
872 ParseStringTable(prevtok
);
873 else if (token
=="ICON")
880 void rc2xml::ParseBitmap(wxString varname
)
882 wxString token
,*bitmapfile
;
885 //Microsoft notation?
886 if (token
=="DISCARDABLE")
891 bitmapfile
=new wxString
;
892 *bitmapfile
=GetQuoteField();
893 m_bitmaplist
->Append(varname
,bitmapfile
);
898 void rc2xml::SecondPass()
900 wxString token
,prevtok
;
904 if ((token
=="DIALOG")||(token
=="DIALOGEX"))
905 ParseDialog(prevtok
);
906 else if (token
=="MENU")
908 else if (token
=="TOOLBAR")
909 ParseToolBar(prevtok
);
916 void rc2xml::ParseToolBar(wxString varname
)
920 wxASSERT_MSG(token
=="DISCARDABLE","Error in toolbar parsing");
921 //Look up bitmap for toolbar and load
922 wxNode
*node
=m_bitmaplist
->Find(LookUpId(varname
));
923 wxString
*bitmappath
;
924 bitmappath
=(wxString
*)node
->Data();
926 if (!bitmap
.LoadFile(*bitmappath
,wxBITMAP_TYPE_BMP
))
927 wxLogError("Unable to load bitmap:"+*bitmappath
);
929 //Write toolbar to xml file
930 m_xmlfile
.Write(" <object class=\"wxToolBar\"");
931 //Avoid duplicate names this way
932 varname
.Replace("IDR_","TB_");
934 m_xmlfile
.Write(">\n");
940 //Grab width and height
942 width
=atoi(GetToken());
943 height
=atoi(GetToken());
946 wxString buttonname
,msg
,tip
,longhelp
;
948 while ((token
!="BEGIN")&(token
!="{"))
951 while ((token
!="END")&(token
!="}"))
955 buttonname
=GetToken();
956 m_xmlfile
.Write("\t\t\t<object class=\"tool\"");
957 WriteName(buttonname
);
958 m_xmlfile
.Write(">\n");
959 //Write tool tip if any
960 if (LookUpString(buttonname
,msg
))
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");
966 //Make a bitmap file name
967 buttonname
=CleanName(buttonname
);
969 m_xmlfile
.Write("\t\t\t\t<bitmap>"+buttonname
+"</bitmap>\n");
970 WriteToolButton(buttonname
,c
,width
,height
,bitmap
);
971 m_xmlfile
.Write("\t\t\t</object>\n");
974 else if (token
=="SEPARATOR")
976 m_xmlfile
.Write("\t\t\t<object class=\"separator\"/>\n");
980 m_xmlfile
.Write("\t</object>\n");
983 //Extract bitmaps from larger toolbar bitmap
984 void rc2xml::WriteToolButton(wxString name
,int index
, int width
, int height
, wxBitmap bitmap
)
988 wxRect
r(x
,0,width
,height
);
990 little
=bitmap
.GetSubBitmap(r
);
991 little
.SaveFile(m_targetpath
+name
,wxBITMAP_TYPE_BMP
);
994 void rc2xml::ParseStringTable(wxString varname
)
998 while ((token
!="BEGIN")&(token
!="{"))
1003 while ((token
!="END")&(token
!="}"))
1006 *msg
=GetStringQuote();
1007 m_stringtable
->Append(token
,msg
);
1013 bool rc2xml::LookUpString(wxString strid
,wxString
& st
)
1015 wxNode
*node
=m_stringtable
->Find(strid
);
1020 s
=(wxString
*)node
->Data();
1026 bool rc2xml::SplitHelp(wxString msg
, wxString
&shorthelp
, wxString
&longhelp
)
1029 spot
=msg
.Find("\\n");
1036 longhelp
=msg
.Left(spot
);
1037 spot
=msg
.Length()-spot
-2;
1038 shorthelp
=msg
.Right(spot
);
1042 void rc2xml::ParseMenuItem()
1044 wxString token
,name
,msg
,tip
,longhelp
;
1046 if (PeekToken()=="SEPARATOR")
1048 m_xmlfile
.Write("\t\t\t<object class=\"separator\"/>\n");
1052 token
=GetQuoteField();
1054 //Remove \t because it causes problems
1055 //spot=token.First("\\t");
1056 //token=token.Left(spot);
1057 m_xmlfile
.Write("\t\t\t<object class=\"wxMenuItem\"");
1059 m_xmlfile
.Write(">\n");
1061 //Look up help if any listed in stringtable
1062 //can't assume numbers correlate, restrict to string identifiers
1063 if ((!name
.IsNumber())&&(LookUpString(name
,msg
)))
1065 SplitHelp(msg
,tip
,longhelp
);
1066 m_xmlfile
.Write("\t\t\t<help>"
1067 +longhelp
+"</help>\n");
1069 //look for extra attributes like checked and break
1073 while ((ptoken
!="MENUITEM")&(ptoken
!="POPUP")&(ptoken
!="END"))
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");
1083 wxLogError("Unknown Menu Item token:"+token
);
1088 m_xmlfile
.Write("\t\t\t</object>\n");
1092 //ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
1093 void rc2xml::ParseIconStatic()
1096 wxString varname
,iconname
;
1097 token
= PeekToken();
1098 if (token
.Contains("\""))
1099 iconname
= GetQuoteField();
1101 iconname
=GetToken();
1105 int x
,y
,width
,height
;
1106 ReadRect(x
,y
,width
,height
);
1108 m_xmlfile
.Write("\t\t<object class=\"wxStaticBitmap\"");
1109 WriteBasicInfo(x
,y
,width
,height
,varname
);
1110 //Save icon as a bitmap
1111 WriteIcon(iconname
);
1112 m_xmlfile
.Write("\t\t</object>\n");
1115 //IDR_MAINFRAME ICON DISCARDABLE "res\\mfcexample.ico"
1116 void rc2xml::ParseIcon(wxString varname
)
1118 wxString token
,*iconfile
;
1119 iconfile
=new wxString
;
1122 *iconfile
=GetQuoteField();
1123 m_iconlist
->Append(varname
,iconfile
);
1128 wxString
rc2xml::CleanName(wxString name
)
1131 name
.Replace("id_","");
1132 name
.Replace("idr_","");
1133 name
.Replace("idb_","");
1134 name
.Replace("idc_","");
1136 name
.Replace(".ico","");
1138 name
.Replace(".bmp","");
1141 // And the award for most messed up control goes to...
1142 // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
1143 void rc2xml::ParseStaticBitmap(wxString bitmapname
, wxString varname
)
1150 int x
,y
,width
,height
;
1151 ReadRect(x
,y
,width
,height
);
1153 m_xmlfile
.Write("\t\t<object class=\"wxStaticBitmap\"");
1154 WriteBasicInfo(x
,y
,width
,height
,varname
);
1155 WriteBitmap(bitmapname
);
1156 m_xmlfile
.Write("\t\t</object>\n");
1160 void rc2xml::ParseNormalMSControl()
1162 wxString label
,varname
,kindctrl
;
1164 label
=GetQuoteField();
1166 kindctrl
=GetQuoteField();
1167 kindctrl
.MakeUpper();
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
);
1185 if (kindctrl
=="STATIC")
1191 if (token
.Find("SS_BITMAP")!=-1)
1192 ParseStaticBitmap(label
,varname
);
1194 ParseStaticText(label
,varname
);
1196 if (kindctrl
=="EDIT")
1197 ParseTextCtrl(varname
);
1198 if (kindctrl
=="LISTBOX")
1199 ParseListBox(varname
);
1200 if (kindctrl
=="COMBOBOX")
1201 ParseComboBox(varname
);
1205 void rc2xml::ParseWeirdMSControl()
1212 kindctrl
=GetQuoteField();
1213 kindctrl
.MakeUpper();
1214 // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
1215 if (kindctrl
=="STATIC")
1217 if (PeekToken()=="SS_BITMAP")
1218 ParseStaticBitmap(id
,varname
);
1220 wxLogError("Unknown MS Control Static token");
1224 //SCROLLBAR IDC_SCROLLBAR1,219,56,10,40,SBS_VERT
1226 void rc2xml::ParseScrollBar()
1232 int x
,y
,width
,height
;
1233 ReadRect(x
,y
,width
,height
);
1238 if (token
.Find("SBS_VERT")!=-1)
1239 style
=_T("wxSB_VERTICAL");
1240 //Default MFC style is horizontal
1242 style
=_T("wxSB_HORIZONTAL");
1244 m_xmlfile
.Write("\t\t<object class=\"wxScrollBar\"");
1245 WriteBasicInfo(x
,y
,width
,height
,varname
);
1247 m_xmlfile
.Write("\n\t\t</object>\n");
1250 // CONTROL "Tree1",IDC_TREE1,"SysTreeView32",WS_BORDER | WS_TABSTOP,
1253 void rc2xml::ParseTreeCtrl(wxString label
, wxString varname
)
1256 //while (ReadOrs(token));
1258 int x
,y
,width
,height
;
1259 ReadRect(x
,y
,width
,height
);
1260 m_xmlfile
.Write("\t\t<object class=\"wxTreeCtrl\"");
1261 WriteBasicInfo(x
,y
,width
,height
,varname
);
1262 m_xmlfile
.Write("\t\t</object>\n");
1265 // CONTROL "MonthCalendar1",IDC_MONTHCALENDAR1,"SysMonthCal32",
1266 //MCS_NOTODAY | WS_TABSTOP,105,71,129,89
1268 void rc2xml::ParseCalendar(wxString label
, wxString varname
)
1271 //while (ReadOrs(token));
1273 int x
,y
,width
,height
;
1274 ReadRect(x
,y
,width
,height
);
1275 m_xmlfile
.Write("\t\t<object class=\"wxCalendarCtrl\"");
1276 WriteBasicInfo(x
,y
,width
,height
,varname
);
1277 m_xmlfile
.Write("\t\t</object>\n");
1279 // CONTROL "List1",IDC_LIST1,"SysListView32",WS_BORDER | WS_TABSTOP,
1282 void rc2xml::ParseListCtrl(wxString label
, wxString varname
)
1285 //while (ReadOrs(token));
1287 int x
,y
,width
,height
;
1288 ReadRect(x
,y
,width
,height
);
1289 m_xmlfile
.Write("\t\t<object class=\"wxListCtrl\"");
1290 WriteBasicInfo(x
,y
,width
,height
,varname
);
1291 m_xmlfile
.Write("\t\t</object>\n");
1295 void rc2xml::WriteBitmap(wxString bitmapname
)
1298 wxNode
*node
=m_bitmaplist
->Find(LookUpId(bitmapname
));
1301 m_xmlfile
.Write("\t\t\t<bitmap>missingfile</bitmap>\n");
1302 wxLogError("Unable to find bitmap:"+bitmapname
);
1306 wxString
*bitmappath
;
1307 bitmappath
=(wxString
*)node
->Data();
1309 bitmapname
=wxFileNameFromPath(*bitmappath
);
1311 if (!bitmap
.LoadFile(*bitmappath
,wxBITMAP_TYPE_BMP
))
1312 wxLogError("Unable to load bitmap:"+*bitmappath
);
1314 //Make a bitmap file name
1315 bitmapname
=CleanName(bitmapname
);
1317 m_xmlfile
.Write("\t\t\t<bitmap>"+bitmapname
+"</bitmap>\n");
1318 bitmap
.SaveFile(m_targetpath
+bitmapname
,wxBITMAP_TYPE_BMP
);
1321 void rc2xml::WriteIcon(wxString iconname
)
1323 wxNode
*node
=m_iconlist
->Find(iconname
);
1326 m_xmlfile
.Write("\t\t\t<bitmap>missing_file</bitmap>\n");
1327 wxLogError("Unable to find icon:"+iconname
);
1330 iconpath
=(wxString
*)node
->Data();
1333 if (!icon
.LoadFile(*iconpath
,wxBITMAP_TYPE_ICO
))
1334 wxLogError("Unable to load icon:"+*iconpath
);
1336 bitmap
.CopyFromIcon(icon
);
1340 iconname
=wxFileNameFromPath(*iconpath
);
1341 //Make a bitmap file name
1342 iconname
=CleanName(iconname
);
1344 m_xmlfile
.Write("\t\t\t<bitmap>"+iconname
+"</bitmap>\n");
1345 bitmap
.SaveFile(m_targetpath
+iconname
,wxBITMAP_TYPE_BMP
);
1349 /*Unfortunately sometimes the great MSVC Resource editor decides
1350 to use numbers instead of the word id. I have no idea why they
1351 do this, but that is the way it is.
1353 /* this is a quick and dirty way to parse the resource.h file
1354 it will not recognize #ifdef so it can be easily fooled
1356 void rc2xml::ParseResourceHeader()
1359 //Attempt to load resource.h in current path
1360 if (!r
.Open("resource.h"))
1362 wxLogError("Warining Unable to load resource.h file");
1368 wxStringTokenizer tok
;
1374 //Read through entire file
1375 for ( str
= r
.GetFirstLine(); !r
.Eof(); str
= r
.GetNextLine() )
1377 if (str
.Find("#define")!=-1)
1380 //Just ignore #define token
1382 v
=tok
.GetNextToken();
1383 id
=tok
.GetNextToken();
1386 varname
=new wxString
;
1389 m_resourcelist
->Append(n
,varname
);
1399 wxString
rc2xml::LookUpId(wxString id
)
1407 wxNode
*node
=m_resourcelist
->Find(n
);
1412 s
=(wxString
*)node
->Data();