// rc2xml.cpp: implementation of the wxRC2XML class.
//
//////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#include "rc2xml.h"
#include "wx/image.h"
#include "wx/resource.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
wxRC2XML::wxRC2XML()
{
m_done=FALSE;
m_bitmaplist=new wxList(wxKEY_STRING);
m_stringtable=new wxList(wxKEY_STRING);
m_iconlist = new wxList(wxKEY_STRING);
}
wxRC2XML::~wxRC2XML()
{
delete m_bitmaplist;
delete m_stringtable;
delete m_iconlist;
}
bool wxRC2XML::Convert(wxString rcfile, wxString xmlfile)
{
m_rc.Open(rcfile.c_str());
m_filesize=m_rc.Length();
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");
//Gather all the resource we need for toolbars,menus, and etc
FirstPass();
m_done=FALSE;
m_rc.Seek(0);
//Read in dialogs, toolbars,menus
SecondPass();
m_xmlfile.Write("\n");
m_xmlfile.Close();
m_rc.Close();
return TRUE;
}
void wxRC2XML::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;
//Record x,y,width,height
int x,y,width,height;
ReadRect(x,y,width,height);
//Get Title
token=GetToken();
wxString title;
while ((token!="BEGIN")&(token!="{"))
{
if (token=="CAPTION")
{
title=GetQuoteField();
}
token=GetToken();
}
m_xmlfile.Write(" \n");
}
/*
BEGIN
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()
{
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();
}
}
//LTEXT "Radius",IDC_STATIC,9,67,23,8
void wxRC2XML::ParseStaticText()
{
wxString token;
wxString phrase,varname;
phrase=GetQuoteField();
varname=GetToken();
int x,y,width,height;
ReadRect(x,y,width,height);
m_xmlfile.Write(" \n");
}
//EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
void wxRC2XML::ParseTextCtrl()
{
wxString token;
wxString varname,style;
varname=GetToken();
int x,y,width,height;
ReadRect(x,y,width,height);
//TODO
//style=GetToken();
m_xmlfile.Write(" \n");
}
//PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
void wxRC2XML::ParsePushButton()
{
wxString token;
wxString phrase,varname;
phrase=GetQuoteField();
varname=GetToken();
int x,y,width,height;
ReadRect(x,y,width,height);
m_xmlfile.Write("