X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2193517f1b909b834dc6e314acc3b873dc8196d9..82dfea7723b354423e96221d4854878874cfce58:/contrib/utils/convertrc/rc2xml.cpp diff --git a/contrib/utils/convertrc/rc2xml.cpp b/contrib/utils/convertrc/rc2xml.cpp index 795f45a9eb..15f7ac44ee 100644 --- a/contrib/utils/convertrc/rc2xml.cpp +++ b/contrib/utils/convertrc/rc2xml.cpp @@ -68,6 +68,11 @@ 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"); @@ -123,7 +128,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"); } /* @@ -173,6 +176,12 @@ void rc2xml::ParseControls() token=GetToken(); while ((token!="END")&(token!="}")) { + if (token=="AUTOCHECKBOX") + ParseCheckBox(); + else + if (token=="AUTORADIOBUTTON") + ParseRadioButton(); + else if (token=="LTEXT") ParseStaticText(); else if (token=="EDITTEXT") @@ -207,9 +216,9 @@ void rc2xml::ParseStaticText() 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 @@ -222,11 +231,50 @@ void rc2xml::ParseTextCtrl() 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 token; + wxString phrase,varname; + phrase=GetQuoteField(); + varname=GetToken(); + + 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 token,style; + wxString phrase,varname; + phrase=GetQuoteField(); + varname=GetToken(); + + int x,y,width,height; + if (ReadRect(x,y,width,height)) + 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() { @@ -238,10 +286,10 @@ void rc2xml::ParsePushButton() int x,y,width,height; ReadRect(x,y,width,height); - m_xmlfile.Write("\t\t\n"); + m_xmlfile.Write("\t\t\n"); } @@ -271,21 +319,24 @@ void rc2xml::ParseGroupBox() 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 +369,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; } @@ -369,15 +422,22 @@ void rc2xml::ParseComboBox() { /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP */ - wxString token; + wxString token,style; wxString varname; varname=GetToken(); int x,y,width,height; - ReadRect(x,y,width,height); + if (ReadRect(x,y,width,height)) + 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 +446,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(); @@ -404,8 +463,7 @@ void rc2xml::ParseMenu(wxString varname) ParsePopupMenu(); } } - m_xmlfile.Write("\t\t\n"); - m_xmlfile.Write("\t\n"); + m_xmlfile.Write("\t\n"); } void rc2xml::ParsePopupMenu() @@ -423,11 +481,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(); @@ -441,8 +498,7 @@ void rc2xml::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 +540,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 +559,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) @@ -538,19 +594,19 @@ void rc2xml::ParseCtrlButton(wxString label, wxString varname) if (token.Find("BS_AUTOCHECKBOX")!=-1) { ReadRect(x,y,width,height); - m_xmlfile.Write("\t\t\n"); + m_xmlfile.Write("\t\t\n"); } if (token.Find("BS_AUTORADIOBUTTON")!=-1) { ReadRect(x,y,width,height); - m_xmlfile.Write("\t\t\n"); + m_xmlfile.Write("\t\t\n"); } } @@ -616,6 +672,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,7 +702,7 @@ 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 | @@ -654,9 +716,9 @@ void rc2xml::ParseListBox() 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 +735,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 +758,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"); } @@ -770,7 +832,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; @@ -797,7 +858,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 +873,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,7 +893,7 @@ 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) @@ -890,7 +950,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,7 +959,7 @@ 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); @@ -926,7 +986,7 @@ void rc2xml::ParseMenuItem() ptoken=PeekToken(); } - m_xmlfile.Write("\t\t\t\n"); + m_xmlfile.Write("\t\t\t\n"); } @@ -942,11 +1002,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 +1029,8 @@ 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... @@ -984,10 +1046,10 @@ void rc2xml::ParseStaticBitmap(wxString bitmapname, wxString varname) int x,y,width,height; ReadRect(x,y,width,height); - m_xmlfile.Write("\t\t\n"); + m_xmlfile.Write("\t\t\n"); } @@ -1058,10 +1120,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 +1136,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 +1151,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 +1165,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 +1184,7 @@ 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 +1193,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 +1215,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); }