X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/92a19c2e7757ba742846f83e56356de0a607bdc2..77e0239d76ac5f2dbe9ba53e3278184ce83868ed:/contrib/utils/convertrc/rc2xml.cpp diff --git a/contrib/utils/convertrc/rc2xml.cpp b/contrib/utils/convertrc/rc2xml.cpp index ee909b0256..fc65fe51b3 100644 --- a/contrib/utils/convertrc/rc2xml.cpp +++ b/contrib/utils/convertrc/rc2xml.cpp @@ -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,7 +68,7 @@ bool rc2xml::Convert(wxString rcfile, wxString xmlfile) { m_rc.Open(rcfile.c_str()); m_filesize=m_rc.Length(); - + m_workingpath=wxPathOnly(rcfile); @@ -80,15 +81,15 @@ bool rc2xml::Convert(wxString rcfile, wxString xmlfile) 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 @@ -101,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; } @@ -111,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(); @@ -132,13 +136,13 @@ microsoft reuses the keyword DIALOG for other things token=GetToken(); wxString title; wxString ptsize,face; - + m_xmlfile.Write("\t be this + phrase+='n'; // escape + else + phrase+=(char)ch; + lastch=ch; + ReadChar(ch); + } + + return phrase; +} + void rc2xml::ReadChar(int &ch) { int result; @@ -423,15 +512,16 @@ 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,style; - wxString varname; - varname=GetToken(); int 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"); } -/* +/* CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32", WS_BORDER,15,52,154,13 */ @@ -559,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); @@ -581,7 +675,7 @@ bool rc2xml::ReadOrs(wxString & orstring) while(PeekToken()==_T("|")) { - //Grab | + //Grab | orstring+=GetToken(); //Grab next token orstring+=GetToken(); @@ -589,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; @@ -640,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 @@ -710,14 +797,18 @@ void rc2xml::WriteStyle(wxString style) 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); @@ -727,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) @@ -753,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"; @@ -782,7 +873,7 @@ void rc2xml::FirstPass() ParseStringTable(prevtok); else if (token=="ICON") ParseIcon(prevtok); - + prevtok=token; } } @@ -790,7 +881,7 @@ void rc2xml::FirstPass() void rc2xml::ParseBitmap(wxString varname) { wxString token,*bitmapfile; - + token=PeekToken(); //Microsoft notation? if (token=="DISCARDABLE") @@ -811,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; } @@ -825,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 @@ -852,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!="}")) @@ -905,7 +996,7 @@ void rc2xml::ParseStringTable(wxString varname) { wxString token; token=GetToken(); - while ((token!="BEGIN")) + while ((token!="BEGIN")&(token!="{")) token=GetToken(); token=GetToken(); wxString *msg; @@ -913,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(); } @@ -969,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" @@ -978,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"); @@ -988,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"); } @@ -1000,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(); @@ -1023,7 +1122,7 @@ void rc2xml::ParseIcon(wxString varname) *iconfile=GetQuoteField(); m_iconlist->Append(varname,iconfile); - + } @@ -1046,8 +1145,7 @@ void rc2xml::ParseStaticBitmap(wxString bitmapname, wxString varname) { wxString token; //Grab SS_BITMAP - token=GetToken(); - + ReadOrs(token); int x,y,width,height; @@ -1085,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); } @@ -1120,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 @@ -1188,7 +1303,7 @@ void rc2xml::WriteBitmap(wxString bitmapname) wxLogError("Unable to find bitmap:"+bitmapname); return; } - + wxString *bitmappath; bitmappath=(wxString *)node->Data(); @@ -1230,7 +1345,7 @@ wxNode *node=m_iconlist->Find(iconname); m_xmlfile.Write("\t\t\t"+iconname+"\n"); 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 @@ -1248,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 @@ -1277,8 +1392,8 @@ wxTextFile r; } } - - + + }