X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/88d42654d76be0098f6a1fa12b83af97f5b6235a..65baafba0e8cd74f2264b7e2f7625ff5bea84864:/contrib/utils/convertrc/rc2xml.cpp
diff --git a/contrib/utils/convertrc/rc2xml.cpp b/contrib/utils/convertrc/rc2xml.cpp
index 2518c9d8c8..84550e0205 100644
--- a/contrib/utils/convertrc/rc2xml.cpp
+++ b/contrib/utils/convertrc/rc2xml.cpp
@@ -1,1072 +1,1425 @@
-// rc2xml.cpp: implementation of the wxRC2XML class.
-//
-//////////////////////////////////////////////////////////////////////
+// rc2xml.cpp: implementation of the rc2xml class.
+//Author: Brian Gavin 9/24/00
+//License: wxWindows License
+/*
+How to use:
+#include "rc2xml.h"
+...
+rc2xml trans;
+trans->Convert("Myfile.rc","Myfile.xml");
+*/
+/* TODO
+1. Figure how to fix memory leaks in all wxLists in this class
+2. Find a way to rename MS Windows fonts so that they work
+cross platform (wxGTK,etc)
+3. Be able to abort incorrectly formated files without crashing
+*/
+
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+// for all others, include the necessary headers (this file is usually all you
+// need because it includes almost all "standard" wxWidgets headers
+#ifndef WX_PRECOMP
+#include "wx/wx.h"
+#endif
+
+
#include "rc2xml.h"
#include "wx/image.h"
-#include "wx/resource.h"
+#include "wx/deprecated/setup.h"
+#include "wx/deprecated/resource.h"
+#include "wx/textfile.h"
+#include "wx/tokenzr.h"
+
+
+
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
-wxRC2XML::wxRC2XML()
+rc2xml::rc2xml()
{
-m_done=FALSE;
-m_bitmaplist=new wxList(wxKEY_STRING);
-m_stringtable=new wxList(wxKEY_STRING);
-m_iconlist = new wxList(wxKEY_STRING);
+ m_done=false;
+ m_bitmaplist=new wxList(wxKEY_STRING);
+ m_stringtable=new wxList(wxKEY_STRING);
+ m_iconlist = new wxList(wxKEY_STRING);
+ m_resourcelist =new wxList(wxKEY_INTEGER);
}
-wxRC2XML::~wxRC2XML()
+rc2xml::~rc2xml()
{
-delete m_bitmaplist;
-delete m_stringtable;
-delete m_iconlist;
+ delete m_bitmaplist;
+ delete m_stringtable;
+ delete m_iconlist;
+ delete m_resourcelist;
}
-bool wxRC2XML::Convert(wxString rcfile, wxString xmlfile)
+bool rc2xml::Convert(wxString rcfile, wxString xmlfile)
{
-m_rc.Open(rcfile.c_str());
-m_filesize=m_rc.Length();
+ m_rc.Open(rcfile.c_str());
+ m_filesize=m_rc.Length();
+
+
+ m_workingpath=wxPathOnly(rcfile);
+
+ m_targetpath=wxPathOnly(xmlfile) + _T("\\");
+
+
+
+ wxSetWorkingDirectory(m_workingpath);
+
+
+ bool result;
+ result=m_xmlfile.Open(xmlfile.c_str(),_T("w+t"));
+ wxASSERT_MSG(result,_T("Couldn't create XML file"));
+ if (!result)
+ return false;
-bool result;
-result=m_xmlfile.Open(xmlfile.c_str(),"w+t");
-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");
+ m_xmlfile.Write(_T("\n"));
+ m_xmlfile.Write(_T("\n"));
+//Read resource.h
+ ParseResourceHeader();
//Gather all the resource we need for toolbars,menus, and etc
-FirstPass();
-m_done=FALSE;
-m_rc.Seek(0);
+ FirstPass();
+ m_done=false;
+ m_rc.Seek(0);
//Read in dialogs, toolbars,menus
-SecondPass();
+ SecondPass();
-m_xmlfile.Write("\n");
-m_xmlfile.Close();
-m_rc.Close();
+ m_xmlfile.Write(_T("\n"));
+ m_xmlfile.Close();
+ m_rc.Close();
+ wxMessageBox(_("Conversion complete."), _("Done"),
+ wxOK | wxICON_INFORMATION);
-return TRUE;
+return true;
}
-void wxRC2XML::ParseDialog(wxString dlgname)
+void rc2xml::ParseDialog(wxString dlgname)
{
- wxString token;
- static int dlgid=999;
- dlgid++;
- /* Make sure that this really is a dialog
- microsoft reuses the keyword DIALOG for other things
- */
- token=PeekToken();
- //Microsoft notation?
- if (token=="DISCARDABLE")
- {
- token=GetToken();
- token=PeekToken();
- }
- //Error isn't a Dialog resource eject eject
- if (!token.IsNumber())
- return;
+ wxString token;
+ static int dlgid=999;
+ dlgid++;
+/* Make sure that this really is a dialog
+microsoft reuses the keyword DIALOG for other things
+*/
+ token=PeekToken();
+//Microsoft notation?
+ while ((token==_T("DISCARDABLE"))
+ ||(token==_T("LOADONCALL"))||(token==_T("MOVEABLE")))
+ {
+ token=GetToken();
+ token=PeekToken();
+ }
+//Error isn't a Dialog resource eject eject
+ if (!token.IsNumber())
+ return;
//Record x,y,width,height
-int x,y,width,height;
-ReadRect(x,y,width,height);
+ int x,y,width,height;
+ ReadRect(x,y,width,height);
//Get Title
-token=GetToken();
-wxString title;
+ token=GetToken();
+ wxString title;
+ wxString ptsize,face;
+
+ m_xmlfile.Write(_T("\t\n"));
}
/*
BEGIN
- EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT
+ EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT
WS_TABSTOP
LTEXT "Bands",IDC_STATIC,11,86,21,8
EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL
END
*/
-void wxRC2XML::ParseControls()
+void rc2xml::ParseControls()
{
-wxString token;
-
-token=GetToken();
-while ((token!="END")&(token!="}"))
- {
- if (token=="LTEXT")
- ParseStaticText();
- else if (token=="EDITTEXT")
- ParseTextCtrl();
- else if (token=="PUSHBUTTON")
- ParsePushButton();
- else if (token=="DEFPUSHBUTTON")
- ParsePushButton();
- else if (token=="GROUPBOX")
- ParseGroupBox();
- else if (token=="COMBOBOX")
- ParseComboBox();
- else if (token=="CONTROL")
- ParseControlMS();
- else if (token=="LISTBOX")
- ParseListBox();
- else if (token=="ICON")
- ParseIconStatic();
- else if (token=="SCROLLBAR")
- ParseScrollBar();
- token=GetToken();
- }
+ wxString token;
+ wxString label,varname;
+
+ token=GetToken();
+ while ((token!=_T("END"))&(token!=_T("}")))
+ {
+ if (token==_T("AUTOCHECKBOX"))
+ {
+ label=GetQuoteField();
+ varname=GetToken();
+ ParseCheckBox(label,varname);
+ }
+ else
+ if (token==_T("AUTORADIOBUTTON"))
+ {
+ label=GetQuoteField();
+ varname=GetToken();
+ ParseRadioButton(label,varname);
+ }
+ else
+ if (token==_T("LTEXT"))
+ {
+ label=GetQuoteField();
+ varname=GetToken();
+ ParseStaticText(label,varname);
+ }
+ else if (token==_T("EDITTEXT"))
+ {
+ varname=GetToken();
+ ParseTextCtrl(varname);
+ }
+ else if ((token==_T("PUSHBUTTON"))||(token==_T("DEFPUSHBUTTON")))
+ {
+ label=GetQuoteField();
+ varname=GetToken();
+ ParsePushButton(label,varname);
+ }
+ else if (token==_T("GROUPBOX"))
+ {
+ label=GetQuoteField();
+ varname=GetToken();
+ ParseGroupBox(label,varname);
+ }
+ else if (token==_T("COMBOBOX"))
+ {
+ varname=GetToken();
+ ParseComboBox(varname);
+ }
+ else if (token==_T("CONTROL"))
+ ParseControlMS();
+ else if (token==_T("LISTBOX"))
+ {
+ varname=GetToken();
+ ParseListBox(varname);
+ }
+ else if (token==_T("ICON"))
+ ParseIconStatic();
+ else if (token==_T("SCROLLBAR"))
+ ParseScrollBar();
+ token=GetToken();
+ }
}
//LTEXT "Radius",IDC_STATIC,9,67,23,8
-void wxRC2XML::ParseStaticText()
+void rc2xml::ParseStaticText(wxString phrase, wxString varname)
{
-wxString token;
-wxString phrase,varname;
-phrase=GetQuoteField();
-varname=GetToken();
-int x,y,width,height;
-ReadRect(x,y,width,height);
-
-m_xmlfile.Write(" \n");
+ 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\t