X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e066e2566a4e5db3510fe6a204d66850eaeceade..77e0239d76ac5f2dbe9ba53e3278184ce83868ed:/contrib/utils/convertrc/rc2xml.cpp diff --git a/contrib/utils/convertrc/rc2xml.cpp b/contrib/utils/convertrc/rc2xml.cpp index be22c23737..fc65fe51b3 100644 --- a/contrib/utils/convertrc/rc2xml.cpp +++ b/contrib/utils/convertrc/rc2xml.cpp @@ -21,7 +21,7 @@ cross platform (wxGTK,etc) #endif // For compilers that support precompilation, includes "wx/wx.h". -#include +#include "wx/wxprec.h" #ifdef __BORLANDC__ #pragma hdrstop @@ -36,7 +36,8 @@ cross platform (wxGTK,etc) #include "rc2xml.h" #include "wx/image.h" -#include "wx/resource.h" +#include "wx/deprecated/setup.h" +#include "wx/deprecated/resource.h" #include #include @@ -67,18 +68,28 @@ bool rc2xml::Convert(wxString rcfile, wxString xmlfile) { m_rc.Open(rcfile.c_str()); m_filesize=m_rc.Length(); - + + + m_workingpath=wxPathOnly(rcfile); + + m_targetpath=wxPathOnly(xmlfile)+"\\"; + + + + wxSetWorkingDirectory(m_workingpath); + + bool result; result=m_xmlfile.Open(xmlfile.c_str(),"w+t"); - wxASSERT_MSG(result,"Couldn't create XML file"); + wxASSERT_MSG(result,"Couldn't create XML file"); if (!result) return FALSE; - + /* Write Basic header for XML file */ m_xmlfile.Write("\n"); m_xmlfile.Write("\n"); - + //Read resource.h ParseResourceHeader(); //Gather all the resource we need for toolbars,menus, and etc @@ -91,6 +102,8 @@ bool rc2xml::Convert(wxString rcfile, wxString xmlfile) m_xmlfile.Write("\n"); m_xmlfile.Close(); m_rc.Close(); + wxMessageBox(_("Conversion complete."), _("Done"), + wxOK | wxICON_INFORMATION); return TRUE; } @@ -101,12 +114,13 @@ void rc2xml::ParseDialog(wxString dlgname) wxString token; static int dlgid=999; dlgid++; -/* Make sure that this really is a dialog +/* Make sure that this really is a dialog microsoft reuses the keyword DIALOG for other things */ token=PeekToken(); //Microsoft notation? - if (token=="DISCARDABLE") + while ((token=="DISCARDABLE") + ||(token=="LOADONCALL")||(token=="MOVEABLE")) { token=GetToken(); token=PeekToken(); @@ -122,13 +136,13 @@ microsoft reuses the keyword DIALOG for other things token=GetToken(); wxString title; wxString ptsize,face; - + m_xmlfile.Write("\t\n"); } +//AUTOCHECKBOX "&log.", ID_XLOG, 25, 24, 21, 12 +void rc2xml::ParseCheckBox(wxString phrase, wxString varname) +{ + wxString token; + token=PeekToken(); + while (!token.IsNumber()) + { + token=GetToken(); + token=PeekToken(); + } + int x,y,width,height; + ReadRect(x,y,width,height); + + m_xmlfile.Write("\t\t\n"); + +} +//AUTORADIOBUTTON "&text", ID_SW10, 13, 12, 68, 10, BS_AUTORADIOBUTTON | WS_GROUP +void rc2xml::ParseRadioButton(wxString phrase, wxString varname) +{ + wxString token,style; + int x,y,width,height; + bool GotOrs; + GotOrs = ReadOrs(token); + if (ReadRect(x,y,width,height)) + if (GotOrs==FALSE) + ReadOrs(token); + if (token.Find("WS_GROUP") != -1) + style += "wxRB_GROUP"; + + m_xmlfile.Write("\t\t\n"); + +} + //PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP -void rc2xml::ParsePushButton() +void rc2xml::ParsePushButton(wxString phrase, wxString varname) { wxString token; - wxString phrase,varname; - phrase=GetQuoteField(); - varname=GetToken(); + token=PeekToken(); + while (!token.IsNumber()) + { + token=GetToken(); + token=PeekToken(); + } int x,y,width,height; ReadRect(x,y,width,height); - m_xmlfile.Write("\t\t\n"); @@ -255,17 +354,20 @@ bool rc2xml::Seperator(int ch) m_done=TRUE; return TRUE; } - + return FALSE; } -void rc2xml::ParseGroupBox() +void rc2xml::ParseGroupBox(wxString phrase, wxString varname) { // GROUPBOX "Rotate",IDC_STATIC,1,1,71,79 wxString token; - wxString phrase,varname; - phrase=GetQuoteField(); - varname=GetToken(); + token=PeekToken(); + while (!token.IsNumber()) + { + token=GetToken(); + token=PeekToken(); + } int x,y,width,height; ReadRect(x,y,width,height); @@ -275,15 +377,18 @@ void rc2xml::ParseGroupBox() m_xmlfile.Write("\t\t\n"); } -void rc2xml::ReadRect(int & x, int & y, int & width, int & height) +bool rc2xml::ReadRect(int & x, int & y, int & width, int & height) { x=atoi(GetToken()); y=atoi(GetToken()); width=atoi(GetToken()); - height=atoi(GetToken()); + bool ret; + wxString tmp = GetToken(&ret); + height=atoi(tmp); + return ret; // check for more parameters } -wxString rc2xml::GetToken() +wxString rc2xml::GetToken(bool *listseperator) { wxString token=""; @@ -312,17 +417,19 @@ wxString rc2xml::GetToken() { m_done=TRUE; } - + while (!Seperator(ch)) { - token+=(char)ch; + token += (char)ch; ReadChar(ch); } - if (ch==EOF) - m_done=TRUE; + if (ch == EOF) + m_done = TRUE; + if (listseperator) + *listseperator = (ch == ','); return token; } @@ -335,7 +442,6 @@ wxString rc2xml::GetQuoteField() while (ch!=34) ReadChar(ch); - ReadChar(ch); while (ch!=34) @@ -346,6 +452,49 @@ wxString rc2xml::GetQuoteField() return phrase; } +// string in stringtable may contain embedded quotes +// escape characters retained to allow strings to be rewritten +wxString rc2xml::GetStringQuote() +{ + wxString phrase; + //ASCII code 34 " + bool done=FALSE; + int p,ch=0,lastch=0; + ReadChar(ch); + + while (ch!=34) + ReadChar(ch); + ReadChar(ch); + while (done==FALSE) + { + if ((ch==34)&&(lastch!='\\')) + { + p=m_rc.Tell(); + ReadChar(ch); +// RC supports "", for embedded quote, as well as \" + if (ch==34) + phrase+='\\'; + else + { + m_rc.Seek(p); + done = TRUE; + } + } + if (done==TRUE) + break; + if (ch=='\r') + ReadChar(ch); // skip + if ((ch=='\n')&&(lastch=='\\')) // lastch be this + phrase+='n'; // escape + else + phrase+=(char)ch; + lastch=ch; + ReadChar(ch); + } + + return phrase; +} + void rc2xml::ReadChar(int &ch) { int result; @@ -363,18 +512,26 @@ void rc2xml::ReadChar(int &ch) m_done=TRUE; } -void rc2xml::ParseComboBox() +void rc2xml::ParseComboBox(wxString varname) { -/* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT | +/* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP */ - wxString token; - wxString varname; - varname=GetToken(); + wxString token,style; int x,y,width,height; - ReadRect(x,y,width,height); + bool GotOrs; + GotOrs = ReadOrs(token); + if (ReadRect(x,y,width,height)) + if (GotOrs==FALSE) + ReadOrs(token); m_xmlfile.Write("\t\t\n"); } @@ -396,6 +553,8 @@ void rc2xml::ParseMenu(wxString varname) while ((token!="END")&(token!="}")) { token=GetToken(); + token.MakeUpper(); + if (token=="POPUP") { ParsePopupMenu(); @@ -430,9 +589,11 @@ void rc2xml::ParsePopupMenu() while ((token!="END")&(token!="}")) { token=GetToken(); + token.MakeUpper(); + if (token=="POPUP") ParsePopupMenu(); - + if (token=="MENUITEM") ParseMenuItem(); } @@ -462,7 +623,7 @@ void rc2xml::ParseControlMS() } -/* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH | +/* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH | TBS_NOTICKS | WS_TABSTOP,52,73,100,15 */ @@ -484,7 +645,7 @@ void rc2xml::ParseSlider(wxString label, wxString varname) m_xmlfile.Write("\n\t\t\n"); } -/* +/* CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32", WS_BORDER,15,52,154,13 */ @@ -492,7 +653,7 @@ void rc2xml::ParseProgressBar(wxString label, wxString varname) { wxString token,style; ReadOrs(token); - + int x,y,width,height; ReadRect(x,y,width,height); @@ -514,7 +675,7 @@ bool rc2xml::ReadOrs(wxString & orstring) while(PeekToken()==_T("|")) { - //Grab | + //Grab | orstring+=GetToken(); //Grab next token orstring+=GetToken(); @@ -522,34 +683,27 @@ bool rc2xml::ReadOrs(wxString & orstring) return TRUE; } -//Is it a check button or a radio button +//Is it a checkbutton or a radiobutton or a pushbutton or a groupbox void rc2xml::ParseCtrlButton(wxString label, wxString varname) { wxString token; + int p; + p=m_rc.Tell(); ReadOrs(token); - int x,y,width,height; + m_rc.Seek(p); if (token.Find("BS_AUTOCHECKBOX")!=-1) - { - ReadRect(x,y,width,height); - m_xmlfile.Write("\t\t\n"); - } - - if (token.Find("BS_AUTORADIOBUTTON")!=-1) - { - ReadRect(x,y,width,height); - m_xmlfile.Write("\t\t\n"); - } - + ParseCheckBox(label, varname); + else if ((token.Find("BS_AUTORADIOBUTTON")!=-1)|| + (token.Find("BS_RADIOBUTTON")!=-1)) + ParseRadioButton(label, varname); + else if (token.Find("BS_GROUPBOX")!=-1) + ParseGroupBox(label, varname); + else // if ((token.Find("BS_PUSHBUTTON")!=-1)|| +// (token.Find("BS_DEFPUSHBUTTON")!=-1)) + ParsePushButton(label, varname); // make default case } - void rc2xml::WriteSize(int width, int height) { wxString msg; @@ -573,7 +727,7 @@ void rc2xml::WriteTitle(wxString title) void rc2xml::WriteName(wxString name) { - + //Try to convert any number ids into names name=LookUpId(name); //Replace common MS ids with wxWindows ids @@ -610,6 +764,12 @@ name=LookUpId(name); name="wxID_COPY"; else if (name=="ID_EDIT_PASTE") name="wxID_PASTE"; + else if (name=="IDYES") + name="wxID_YES"; + else if (name=="IDNO") + name="wxID_NO"; + else if (name=="IDHELP") + name="wxID_HELP"; m_xmlfile.Write(" name= \""+name+"\""); } @@ -634,17 +794,21 @@ void rc2xml::WriteStyle(wxString style) { if (style.Length()==0) return; - m_xmlfile.Write("\n\t\t\n"); + m_xmlfile.Write("\t\t\t\n"); } /* - LISTBOX IDC_LIST1,16,89,48,40,LBS_SORT | LBS_MULTIPLESEL | + LISTBOX IDC_LIST1,16,89,48,40,LBS_SORT | LBS_MULTIPLESEL | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP */ -void rc2xml::ParseListBox() +void rc2xml::ParseListBox(wxString varname) { wxString token; - wxString varname; - varname=GetToken(); + token=PeekToken(); + while (!token.IsNumber()) + { + token=GetToken(); + token=PeekToken(); + } int x,y,width,height; ReadRect(x,y,width,height); @@ -654,7 +818,7 @@ void rc2xml::ParseListBox() } /* - CONTROL "",IDC_RICHEDIT1,"RICHEDIT",ES_AUTOHSCROLL | WS_BORDER | + CONTROL "",IDC_RICHEDIT1,"RICHEDIT",ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP,103,110,40,14 */ void rc2xml::ParseRichEdit(wxString label, wxString varname) @@ -680,7 +844,7 @@ CONTROL "Spin1",IDC_SPIN1,"msctls_updown32",UDS_ARROWKEYS,209,72, void rc2xml::ParseSpinCtrl(wxString label, wxString varname) { wxString token,style; - + ReadOrs(token); if (token.Find("UDS_HORZ")!=-1) style="wxSP_HORIZONTAL"; @@ -709,7 +873,7 @@ void rc2xml::FirstPass() ParseStringTable(prevtok); else if (token=="ICON") ParseIcon(prevtok); - + prevtok=token; } } @@ -717,7 +881,7 @@ void rc2xml::FirstPass() void rc2xml::ParseBitmap(wxString varname) { wxString token,*bitmapfile; - + token=PeekToken(); //Microsoft notation? if (token=="DISCARDABLE") @@ -738,13 +902,13 @@ void rc2xml::SecondPass() while (!m_done) { token=GetToken(); - if (token=="DIALOG") + if ((token=="DIALOG")||(token=="DIALOGEX")) ParseDialog(prevtok); else if (token=="MENU") ParseMenu(prevtok); else if (token=="TOOLBAR") ParseToolBar(prevtok); - + prevtok=token; } @@ -752,7 +916,7 @@ void rc2xml::SecondPass() void rc2xml::ParseToolBar(wxString varname) { - wxString token; + wxString token; token=GetToken(); wxASSERT_MSG(token=="DISCARDABLE","Error in toolbar parsing"); //Look up bitmap for toolbar and load @@ -779,10 +943,10 @@ void rc2xml::ParseToolBar(wxString varname) width=atoi(GetToken()); height=atoi(GetToken()); - int c=0; + int c=0; wxString buttonname,msg,tip,longhelp; token=GetToken(); - while ((token!="BEGIN")) + while ((token!="BEGIN")&(token!="{")) token=GetToken(); while ((token!="END")&(token!="}")) @@ -825,14 +989,14 @@ void rc2xml::WriteToolButton(wxString name,int index, int width, int height, wxB wxRect r(x,0,width,height); wxBitmap little; little=bitmap.GetSubBitmap(r); - little.SaveFile(name,wxBITMAP_TYPE_BMP); + little.SaveFile(m_targetpath+name,wxBITMAP_TYPE_BMP); } void rc2xml::ParseStringTable(wxString varname) { wxString token; token=GetToken(); - while ((token!="BEGIN")) + while ((token!="BEGIN")&(token!="{")) token=GetToken(); token=GetToken(); wxString *msg; @@ -840,7 +1004,7 @@ void rc2xml::ParseStringTable(wxString varname) while ((token!="END")&(token!="}")) { msg=new wxString; - *msg=GetQuoteField(); + *msg=GetStringQuote(); m_stringtable->Append(token,msg); token=GetToken(); } @@ -896,7 +1060,8 @@ void rc2xml::ParseMenuItem() m_xmlfile.Write(">\n"); WriteLabel(token); //Look up help if any listed in stringtable - if (LookUpString(name,msg)) +//can't assume numbers correlate, restrict to string identifiers + if ((!name.IsNumber())&&(LookUpString(name,msg))) { SplitHelp(msg,tip,longhelp); m_xmlfile.Write("\t\t\t" @@ -905,9 +1070,11 @@ void rc2xml::ParseMenuItem() //look for extra attributes like checked and break wxString ptoken; ptoken=PeekToken(); + ptoken.MakeUpper(); while ((ptoken!="MENUITEM")&(ptoken!="POPUP")&(ptoken!="END")) { token=GetToken(); + ptoken.MakeUpper(); if (token=="CHECKED") m_xmlfile.Write("\t\t\t1\n"); else if (token=="MENUBREAK"); @@ -915,10 +1082,11 @@ void rc2xml::ParseMenuItem() else if (token=="GRAYED"); else wxLogError("Unknown Menu Item token:"+token); - + ptoken=PeekToken(); + ptoken.MakeUpper(); } - m_xmlfile.Write("\t\t\t\n"); + m_xmlfile.Write("\t\t\t\n"); } @@ -927,6 +1095,10 @@ void rc2xml::ParseIconStatic() { wxString token; wxString varname,iconname; + token = PeekToken(); + if (token.Contains("\"")) + iconname = GetQuoteField(); + else iconname=GetToken(); //Look up icon varname=GetToken(); @@ -950,7 +1122,7 @@ void rc2xml::ParseIcon(wxString varname) *iconfile=GetQuoteField(); m_iconlist->Append(varname,iconfile); - + } @@ -961,6 +1133,10 @@ wxString rc2xml::CleanName(wxString name) name.Replace("idr_",""); name.Replace("idb_",""); name.Replace("idc_",""); + + name.Replace(".ico",""); + + name.Replace(".bmp",""); return name; } // And the award for most messed up control goes to... @@ -969,8 +1145,7 @@ void rc2xml::ParseStaticBitmap(wxString bitmapname, wxString varname) { wxString token; //Grab SS_BITMAP - token=GetToken(); - + ReadOrs(token); int x,y,width,height; @@ -1008,6 +1183,23 @@ kindctrl.MakeUpper(); ParseCtrlButton(label,varname); if (kindctrl=="RICHEDIT") ParseRichEdit(label,varname); + if (kindctrl=="STATIC") + { + wxString token; + int p=m_rc.Tell(); + ReadOrs(token); + m_rc.Seek(p); + if (token.Find("SS_BITMAP")!=-1) + ParseStaticBitmap(label,varname); + else + ParseStaticText(label,varname); + } + if (kindctrl=="EDIT") + ParseTextCtrl(varname); + if (kindctrl=="LISTBOX") + ParseListBox(varname); + if (kindctrl=="COMBOBOX") + ParseComboBox(varname); } @@ -1043,7 +1235,7 @@ void rc2xml::ParseScrollBar() wxString style; ReadOrs(token); - + if (token.Find("SBS_VERT")!=-1) style=_T("wxSB_VERTICAL"); //Default MFC style is horizontal @@ -1111,9 +1303,11 @@ void rc2xml::WriteBitmap(wxString bitmapname) wxLogError("Unable to find bitmap:"+bitmapname); return; } - + wxString *bitmappath; bitmappath=(wxString *)node->Data(); + + bitmapname=wxFileNameFromPath(*bitmappath); wxBitmap bitmap; if (!bitmap.LoadFile(*bitmappath,wxBITMAP_TYPE_BMP )) wxLogError("Unable to load bitmap:"+*bitmappath); @@ -1122,7 +1316,7 @@ void rc2xml::WriteBitmap(wxString bitmapname) bitmapname=CleanName(bitmapname); bitmapname+=".bmp"; m_xmlfile.Write("\t\t\t"+bitmapname+"\n"); - bitmap.SaveFile(bitmapname,wxBITMAP_TYPE_BMP); + bitmap.SaveFile(m_targetpath+bitmapname,wxBITMAP_TYPE_BMP); } void rc2xml::WriteIcon(wxString iconname) @@ -1144,14 +1338,14 @@ wxNode *node=m_iconlist->Find(iconname); #else bitmap = icon; #endif - + iconname=wxFileNameFromPath(*iconpath); //Make a bitmap file name iconname=CleanName(iconname); iconname+=".bmp"; m_xmlfile.Write("\t\t\t"+iconname+"\n"); - bitmap.SaveFile(iconname,wxBITMAP_TYPE_BMP); + bitmap.SaveFile(m_targetpath+iconname,wxBITMAP_TYPE_BMP); + - } /*Unfortunately sometimes the great MSVC Resource editor decides to use numbers instead of the word id. I have no idea why they @@ -1169,13 +1363,13 @@ wxTextFile r; wxLogError("Warining Unable to load resource.h file"); return; } - + wxString str; wxString id,v; wxStringTokenizer tok; wxString *varname; - - + + long n; //Read through entire file @@ -1198,8 +1392,8 @@ wxTextFile r; } } - - + + }