X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2193517f1b909b834dc6e314acc3b873dc8196d9..fc9a9b2ab212efcf595dee50e58942c71344eca4:/contrib/utils/convertrc/rc2xml.cpp?ds=sidebyside diff --git a/contrib/utils/convertrc/rc2xml.cpp b/contrib/utils/convertrc/rc2xml.cpp index 795f45a9eb..3c8e797ae1 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 @@ -68,6 +68,16 @@ 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"); @@ -91,6 +101,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; } @@ -106,7 +118,8 @@ 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(); @@ -123,7 +136,7 @@ microsoft reuses the keyword DIALOG for other things wxString title; wxString ptsize,face; - m_xmlfile.Write("\t\n"); ParseControls(); - m_xmlfile.Write("\t\n"); - m_xmlfile.Write("\t\n"); + m_xmlfile.Write("\t\n"); } /* @@ -169,26 +180,60 @@ END void rc2xml::ParseControls() { wxString token; + wxString label,varname; token=GetToken(); while ((token!="END")&(token!="}")) { + if (token=="AUTOCHECKBOX") + { + label=GetQuoteField(); + varname=GetToken(); + ParseCheckBox(label,varname); + } + else + if (token=="AUTORADIOBUTTON") + { + label=GetQuoteField(); + varname=GetToken(); + ParseRadioButton(label,varname); + } + else if (token=="LTEXT") - ParseStaticText(); + { + label=GetQuoteField(); + varname=GetToken(); + ParseStaticText(label,varname); + } else if (token=="EDITTEXT") - ParseTextCtrl(); - else if (token=="PUSHBUTTON") - ParsePushButton(); - else if (token=="DEFPUSHBUTTON") - ParsePushButton(); + { + varname=GetToken(); + ParseTextCtrl(varname); + } + else if ((token=="PUSHBUTTON")||(token=="DEFPUSHBUTTON")) + { + label=GetQuoteField(); + varname=GetToken(); + ParsePushButton(label,varname); + } else if (token=="GROUPBOX") - ParseGroupBox(); + { + label=GetQuoteField(); + varname=GetToken(); + ParseGroupBox(label,varname); + } else if (token=="COMBOBOX") - ParseComboBox(); + { + varname=GetToken(); + ParseComboBox(varname); + } else if (token=="CONTROL") ParseControlMS(); else if (token=="LISTBOX") - ParseListBox(); + { + varname=GetToken(); + ParseListBox(varname); + } else if (token=="ICON") ParseIconStatic(); else if (token=="SCROLLBAR") @@ -198,50 +243,101 @@ void rc2xml::ParseControls() } //LTEXT "Radius",IDC_STATIC,9,67,23,8 -void rc2xml::ParseStaticText() +void rc2xml::ParseStaticText(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"); + m_xmlfile.Write("\t\t\n"); } //EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL -void rc2xml::ParseTextCtrl() +void rc2xml::ParseTextCtrl(wxString varname) { wxString token; - wxString varname,style; - varname=GetToken(); + wxString style; + token=PeekToken(); + while (!token.IsNumber()) + { + token=GetToken(); + token=PeekToken(); + } int x,y,width,height; ReadRect(x,y,width,height); //TODO //style=GetToken(); - m_xmlfile.Write("\t\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"); + WriteLabel(phrase); + WriteStyle(style); + 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"); + m_xmlfile.Write("\t\t\n"); } @@ -261,31 +357,37 @@ bool rc2xml::Seperator(int ch) 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); - m_xmlfile.Write("\t\t\n"); + 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=""; @@ -318,13 +420,15 @@ wxString rc2xml::GetToken() 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; } @@ -337,14 +441,56 @@ wxString rc2xml::GetQuoteField() while (ch!=34) ReadChar(ch); + ReadChar(ch); + while (ch!=34) + { + phrase+=(char)ch; + ReadChar(ch); + } + 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; } @@ -365,19 +511,27 @@ 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 | 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"); + if (token.Find("CBS_SIMPLE") != -1) + WriteStyle("wxCB_SIMPLE"); + if (token.Find("CBS_SORT") != -1) + WriteStyle("wxCB_SORT"); + if (token.Find("CBS_DISABLENOSCROLL") != -1) + WriteStyle("wxLB_ALWAYS_SB"); + m_xmlfile.Write("\n\t\t\n"); } @@ -386,12 +540,11 @@ void rc2xml::ParseMenu(wxString varname) wxString token=""; //Write menubar to xml file - m_xmlfile.Write("\t\n"); - m_xmlfile.Write("\t\t\n"); while ((token!="BEGIN")&(token!="{")) token=GetToken(); @@ -399,13 +552,14 @@ void rc2xml::ParseMenu(wxString varname) while ((token!="END")&(token!="}")) { token=GetToken(); + token.MakeUpper(); + if (token=="POPUP") { ParsePopupMenu(); } } - m_xmlfile.Write("\t\t\n"); - m_xmlfile.Write("\t\n"); + m_xmlfile.Write("\t\n"); } void rc2xml::ParsePopupMenu() @@ -423,11 +577,10 @@ void rc2xml::ParsePopupMenu() //Write Menu item //Generate a fake name since RC menus don't have one name<<"Menu_"<\n"); WriteLabel(token); - m_xmlfile.Write("\t\t\t\n"); while ((token!="BEGIN")&(token!="{")) token=GetToken(); @@ -435,14 +588,15 @@ void rc2xml::ParsePopupMenu() while ((token!="END")&(token!="}")) { token=GetToken(); + token.MakeUpper(); + if (token=="POPUP") ParsePopupMenu(); if (token=="MENUITEM") ParseMenuItem(); } - m_xmlfile.Write("\t\t\t\n"); - m_xmlfile.Write("\t\t\t\n"); + m_xmlfile.Write("\t\t\t\n"); } wxString rc2xml::PeekToken() @@ -484,10 +638,10 @@ void rc2xml::ParseSlider(wxString label, wxString varname) int x,y,width,height; ReadRect(x,y,width,height); - m_xmlfile.Write("\t\t\n"); + m_xmlfile.Write("\n\t\t\n"); } /* @@ -503,10 +657,10 @@ void rc2xml::ParseProgressBar(wxString label, wxString varname) ReadRect(x,y,width,height); //Always horizontal in MFC - m_xmlfile.Write("\t\t\n"); + m_xmlfile.Write("\t\t\n"); } bool rc2xml::ReadOrs(wxString & orstring) @@ -528,34 +682,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; @@ -616,6 +763,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+"\""); } @@ -640,23 +793,27 @@ 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 | 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); - m_xmlfile.Write("\t\t\n"); + m_xmlfile.Write("\n\t\t\n"); } /* @@ -673,10 +830,10 @@ void rc2xml::ParseRichEdit(wxString label, wxString varname) wxString style; //Make it a rich text control style+="wxTE_MULTILINE "; - m_xmlfile.Write("\t\t\n"); + m_xmlfile.Write("\t\t\n"); } /* @@ -696,10 +853,10 @@ void rc2xml::ParseSpinCtrl(wxString label, wxString varname) int x,y,width,height; ReadRect(x,y,width,height); - m_xmlfile.Write("\t\t\n"); + m_xmlfile.Write("\n\t\t\n"); } @@ -744,7 +901,7 @@ void rc2xml::SecondPass() while (!m_done) { token=GetToken(); - if (token=="DIALOG") + if ((token=="DIALOG")||(token=="DIALOGEX")) ParseDialog(prevtok); else if (token=="MENU") ParseMenu(prevtok); @@ -770,7 +927,7 @@ void rc2xml::ParseToolBar(wxString varname) wxLogError("Unable to load bitmap:"+*bitmappath); //Write toolbar to xml file - m_xmlfile.Write(" \n"); //Grab width and height int width,height; @@ -789,7 +945,7 @@ void rc2xml::ParseToolBar(wxString varname) int c=0; wxString buttonname,msg,tip,longhelp; token=GetToken(); - while ((token!="BEGIN")) + while ((token!="BEGIN")&(token!="{")) token=GetToken(); while ((token!="END")&(token!="}")) @@ -797,7 +953,7 @@ void rc2xml::ParseToolBar(wxString varname) if (token=="BUTTON") { buttonname=GetToken(); - m_xmlfile.Write("\t\t\t\n"); //Write tool tip if any @@ -812,17 +968,16 @@ void rc2xml::ParseToolBar(wxString varname) buttonname+=".bmp"; m_xmlfile.Write("\t\t\t\t"+buttonname+"\n"); WriteToolButton(buttonname,c,width,height,bitmap); - m_xmlfile.Write("\t\t\t\n"); + m_xmlfile.Write("\t\t\t\n"); c++; } else if (token=="SEPARATOR") { - m_xmlfile.Write("\t\t\t\n"); + m_xmlfile.Write("\t\t\t\n"); } token=GetToken(); } - m_xmlfile.Write("\t\n"); - m_xmlfile.Write("\t\n"); + m_xmlfile.Write("\t\n"); } //Extract bitmaps from larger toolbar bitmap @@ -833,14 +988,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; @@ -848,7 +1003,7 @@ void rc2xml::ParseStringTable(wxString varname) while ((token!="END")&(token!="}")) { msg=new wxString; - *msg=GetQuoteField(); + *msg=GetStringQuote(); m_stringtable->Append(token,msg); token=GetToken(); } @@ -890,7 +1045,7 @@ void rc2xml::ParseMenuItem() //int spot; if (PeekToken()=="SEPARATOR") { - m_xmlfile.Write("\t\t\t\n"); + m_xmlfile.Write("\t\t\t\n"); return; } @@ -899,12 +1054,13 @@ void rc2xml::ParseMenuItem() //Remove \t because it causes problems //spot=token.First("\\t"); //token=token.Left(spot); - m_xmlfile.Write("\t\t\t\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" @@ -913,9 +1069,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"); @@ -925,8 +1083,9 @@ void rc2xml::ParseMenuItem() wxLogError("Unknown Menu Item token:"+token); ptoken=PeekToken(); + ptoken.MakeUpper(); } - m_xmlfile.Write("\t\t\t\n"); + m_xmlfile.Write("\t\t\t\n"); } @@ -935,6 +1094,10 @@ void rc2xml::ParseIconStatic() { wxString token; wxString varname,iconname; + token = PeekToken(); + if (token.Contains("\"")) + iconname = GetQuoteField(); + else iconname=GetToken(); //Look up icon varname=GetToken(); @@ -942,11 +1105,11 @@ void rc2xml::ParseIconStatic() int x,y,width,height; ReadRect(x,y,width,height); - m_xmlfile.Write("\t\t\n"); + m_xmlfile.Write("\t\t\n"); } //IDR_MAINFRAME ICON DISCARDABLE "res\\mfcexample.ico" @@ -969,6 +1132,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... @@ -977,17 +1144,16 @@ void rc2xml::ParseStaticBitmap(wxString bitmapname, wxString varname) { wxString token; //Grab SS_BITMAP - token=GetToken(); - + ReadOrs(token); int x,y,width,height; ReadRect(x,y,width,height); - m_xmlfile.Write("\t\t\n"); + m_xmlfile.Write("\t\t\n"); } @@ -1016,6 +1182,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); } @@ -1058,10 +1241,10 @@ if (token.Find("SBS_VERT")!=-1) else style=_T("wxSB_HORIZONTAL"); - m_xmlfile.Write("\t\t\n"); + m_xmlfile.Write("\n\t\t\n"); } // CONTROL "Tree1",IDC_TREE1,"SysTreeView32",WS_BORDER | WS_TABSTOP, @@ -1074,9 +1257,9 @@ void rc2xml::ParseTreeCtrl(wxString label, wxString varname) ReadOrs(token); int x,y,width,height; ReadRect(x,y,width,height); - m_xmlfile.Write("\t\t\n"); + m_xmlfile.Write("\t\t\n"); } // CONTROL "MonthCalendar1",IDC_MONTHCALENDAR1,"SysMonthCal32", @@ -1089,9 +1272,9 @@ void rc2xml::ParseCalendar(wxString label, wxString varname) ReadOrs(token); int x,y,width,height; ReadRect(x,y,width,height); - m_xmlfile.Write("\t\t\n"); + m_xmlfile.Write("\t\t\n"); } // CONTROL "List1",IDC_LIST1,"SysListView32",WS_BORDER | WS_TABSTOP, // 7,89,68,71 @@ -1103,9 +1286,9 @@ void rc2xml::ParseListCtrl(wxString label, wxString varname) ReadOrs(token); int x,y,width,height; ReadRect(x,y,width,height); - m_xmlfile.Write("\t\t\n"); + m_xmlfile.Write("\t\t\n"); } @@ -1122,6 +1305,8 @@ void rc2xml::WriteBitmap(wxString bitmapname) wxString *bitmappath; bitmappath=(wxString *)node->Data(); + + bitmapname=wxFileNameFromPath(*bitmappath); wxBitmap bitmap; if (!bitmap.LoadFile(*bitmappath,wxBITMAP_TYPE_BMP )) wxLogError("Unable to load bitmap:"+*bitmappath); @@ -1130,7 +1315,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) @@ -1152,12 +1337,12 @@ 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); }