added rc2xml and wxr2xml convertor (no makefiles yet)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8387 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2000-09-17 19:17:13 +00:00
parent 5183bfc60c
commit 88d42654d7
6 changed files with 2630 additions and 0 deletions

View File

@@ -0,0 +1,641 @@
// RC2WXR.cpp: implementation of the wxRC2WXR class.
//
//////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#include "rc2wxr.h"
#include "wx/image.h"
#include "wx/resource.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
wxRC2WXR::wxRC2WXR()
{
m_done=FALSE;
m_controlid=6000;
}
wxRC2WXR::~wxRC2WXR()
{
}
void wxRC2WXR::Open(wxString wxrfile, wxString rcfile)
{
wxFileProgressDlg fileprog;
m_rc.Open(rcfile);
m_filesize=m_rc.Length();
if( (m_wxr = fopen( wxrfile, "wt" )) == NULL )
{
return;
}
fileprog.Show(TRUE);
wxString tok,prevtok;
while (!m_done)
{
tok=GetToken();
if (tok=="DIALOG")
{
ParseDialog(prevtok);
fileprog.UpdateProgress(&m_rc);
}
if (tok=="MENU")
{
ParseMenu(prevtok);
fileprog.UpdateProgress(&m_rc);
}
prevtok=tok;
}
fileprog.UpdateProgress(&m_rc);
fclose(m_wxr);
//fclose(m_rc);
m_rc.Close();
fileprog.Show(FALSE);
}
/*
Example .rc
Microsoft style as of v5.0
IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 217, 55
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About Funimator"
FONT 8, "MS Sans Serif"
Borland 4.5 style rc
IDD_DIBATTR DIALOG 7, 16, 172, 119
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "DIB Attributes"
FONT 8, "MS Sans Serif"
{
DEFPUSHBUTTON "Ok", IDOK, 114, 8, 50, 14
PUSHBUTTON "Cancel", IDCANCEL, 114, 28, 50, 14
*/
void wxRC2WXR::ParseDialog(wxString dlgname)
{
wxString tok;
static int dlgid=999;
dlgid++;
/* Make sure that this really is a dialog
microsoft reuses the keyword DIALOG for other things
*/
tok=PeekToken();
//Microsoft notation?
if (tok=="DISCARDABLE")
{
tok=GetToken();
tok=PeekToken();
}
//This isn't a Dialog resource eject eject
if (!tok.IsNumber())
return;
//Generate Dialog text
fprintf(m_wxr,"static char *dialog%i = \"dialog(name = '%s',\\\n",dlgid,dlgname);
//be lazy about style for now. add it later
fprintf(m_wxr,"style = 'wxRAISED_BORDER | wxCAPTION | wxTHICK_FRAME | wxSYSTEM_MENU',\\\n");
fprintf(m_wxr,"id = %i,\\\n",dlgid);
//Record x,y,width,height
int x,y,width,height;
ReadRect(x,y,width,height);
fprintf(m_wxr,"x = %i, y = %i, width = %i, height = %i,\\\n",x,y,width,height);
//CAPTION "About Funimator"
//Get Title
tok=GetToken();
wxString title;
while ((tok!="BEGIN")&(tok!="{"))
{
if (tok=="CAPTION")
{
title=GetQuoteField();
fprintf(m_wxr,"title = '%s',\\\n",title);
}
tok=GetToken();
}
fprintf(m_wxr,"use_dialog_units = 1,\\\n");
fprintf(m_wxr,"use_system_defaults = 0,\\\n");
fprintf(m_wxr,"font = [8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif'],\\\n");
ParseControls();
fprintf(m_wxr,").\";\n\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 wxRC2WXR::ParseControls()
{
wxString tok;
tok=GetToken();
while ((tok!="END")&(tok!="}"))
{
if (tok=="LTEXT")
ParseStaticText();
if (tok=="EDITTEXT")
ParseTextCtrl();
if (tok=="PUSHBUTTON")
ParsePushButton();
if (tok=="DEFPUSHBUTTON")
ParsePushButton();
if (tok=="GROUPBOX")
ParseGroupBox();
if (tok=="COMBOBOX")
ParseComboBox();
if (tok=="CONTROL")
ParseControlMS();
tok=GetToken();
}
}
//LTEXT "Radius",IDC_STATIC,9,67,23,8
void wxRC2WXR::ParseStaticText()
{
wxString tok;
wxString phrase,varname;
phrase=GetQuoteField();
varname=GetToken();
m_controlid++;
int x,y,width,height;
ReadRect(x,y,width,height);
fprintf(m_wxr," control = [%i,wxStaticText,'%s','0','%s',",m_controlid,phrase,varname);
fprintf(m_wxr,"%i,%i,%i,%i,'',\\\n",x,y,width,height);
fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
}
//EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
void wxRC2WXR::ParseTextCtrl()
{
wxString tok;
wxString varname;
varname=GetToken();
m_controlid++;
int x,y,width,height;
ReadRect(x,y,width,height);
fprintf(m_wxr," control = [%i,wxTextCtrl,'','0','%s',",m_controlid,varname);
fprintf(m_wxr,"%i,%i,%i,%i,'',\\\n",x,y,width,height);
fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
}
//PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
void wxRC2WXR::ParsePushButton()
{
wxString tok;
wxString phrase,varname;
phrase=GetQuoteField();
varname=GetToken();
int c;
m_controlid++;
c=m_controlid;
if (varname=="IDOK")
c=wxID_OK;
if (varname=="IDCANCEL")
c=wxID_CANCEL;
if (varname=="IDAPPLY")
c=wxID_APPLY;
int x,y,width,height;
ReadRect(x,y,width,height);
fprintf(m_wxr," control = [%i,wxButton,'%s','0','%s',",c,phrase,varname);
fprintf(m_wxr,"%i,%i,%i,%i,'',\\\n",x,y,width,height);
fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
}
bool wxRC2WXR::Seperator(int ch)
{
if ((ch==' ')|(ch==',')|(ch==13)|(ch==10)|(ch=='|'))
return TRUE;
if (ch==EOF)
{
m_done=TRUE;
return TRUE;
}
return FALSE;
}
void wxRC2WXR::ParseGroupBox()
{
// GROUPBOX "Rotate",IDC_STATIC,1,1,71,79
wxString tok;
wxString phrase,varname;
phrase=GetQuoteField();
varname=GetToken();
m_controlid++;
int x,y,width,height;
ReadRect(x,y,width,height);
fprintf(m_wxr," control = [%i,wxStaticBox,'%s','0','%s',",m_controlid,phrase,varname);
fprintf(m_wxr,"%i,%i,%i,%i,'',\\\n",x,y,width,height);
fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
}
void wxRC2WXR::ReadRect(int & x, int & y, int & width, int & height)
{
x=atoi(GetToken());
y=atoi(GetToken());
width=atoi(GetToken());
height=atoi(GetToken());
}
wxString wxRC2WXR::GetToken()
{
wxString tok="";
if (m_rc.Eof())
{
m_done=TRUE;
return tok;
}
int ch=0;
ReadChar(ch);
if (ch==EOF)
{
m_done=TRUE;
return tok;
}
while (Seperator(ch))
{
ReadChar(ch);
if (m_done)
return tok;
}
if (ch==EOF)
{
m_done=TRUE;
}
while (!Seperator(ch))
{
tok+=(char)ch;
ReadChar(ch);
}
if (ch==EOF)
m_done=TRUE;
return tok;
}
wxString wxRC2WXR::GetQuoteField()
{
wxString phrase;
//ASCII code 34 "
int ch=0;
ReadChar(ch);
while (ch!=34)
ReadChar(ch);
ReadChar(ch);
while (ch!=34)
{
phrase+=(char)ch;
ReadChar(ch);
}
return phrase;
}
void wxRC2WXR::ReadChar(int &ch)
{
int result;
result=m_rc.Tell();
if((result>=m_filesize))
m_done=TRUE;
result=m_rc.Read(&ch,1);
if((result==-1))
m_done=TRUE;
if(ch==EOF)
m_done=TRUE;
}
void wxRC2WXR::ParseComboBox()
{
/* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
WS_VSCROLL | WS_TABSTOP */
wxString tok;
wxString varname;
varname=GetToken();
m_controlid++;
int x,y,width,height;
ReadRect(x,y,width,height);
fprintf(m_wxr," control = [%i,wxChoice,'','0','%s',",m_controlid,varname);
fprintf(m_wxr,"%i,%i,%i,%i,[],\\\n",x,y,width,height);
fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
}
void wxRC2WXR::ParseMenu(wxString name)
{
wxString tok="";
static int menuid=0;
menuid++;
fprintf(m_wxr,"static char *MenuBar%i = \"menu(name = '%s',\\\n",menuid,name);
fprintf(m_wxr,"menu = \\\n");
fprintf(m_wxr,"[\\\n");
while ((tok!="BEGIN")&(tok!="{"))
tok=GetToken();
while ((tok!="END")&(tok!="}"))
{
tok=GetToken();
if (tok=="POPUP")
{
ParsePopupMenu();
fprintf(m_wxr," ],\\\n");
}
}
fprintf(m_wxr,"]).\";\n\n");
}
void wxRC2WXR::ParsePopupMenu()
{
static int menuitem=99;
menuitem++;
wxString tok;
tok=GetQuoteField();
int spot;
//Remove /t because it causes problems
spot=tok.First("\\t");
tok=tok.Left(spot);
fprintf(m_wxr," ['%s',%i,'',\\\n",tok,menuitem);
while ((tok!="BEGIN")&(tok!="{"))
tok=GetToken();
while ((tok!="END")&(tok!="}"))
{
tok=GetToken();
if (tok=="MENUITEM")
{
if (PeekToken()=="SEPARATOR")
fprintf(m_wxr," [],\\\n");
else
{
tok=GetQuoteField();
//Remove /t because it causes problems
spot=tok.First("\\t");
tok=tok.Left(spot);
menuitem++;
fprintf(m_wxr," ['%s',%i,''],\\\n",tok,menuitem);
}
}
}
}
wxString wxRC2WXR::PeekToken()
{
wxString tok;
int p;
p=m_rc.Tell();
tok=GetToken();
m_rc.Seek(p);
return tok;
}
//Windows pain in the butt CONTROL
void wxRC2WXR::ParseControlMS()
{
wxString label,varname,kindctrl,tok;
label=GetQuoteField();
varname=GetToken();
kindctrl=GetQuoteField();
kindctrl.MakeUpper();
if (kindctrl=="MSCTLS_TRACKBAR32")
ParseSlider(label,varname);
if (kindctrl=="MSCTLS_PROGRESS32")
ParseProgressBar(label,varname);
if (kindctrl=="BUTTON")
ParseCtrlButton(label,varname);
}
/* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
TBS_NOTICKS | WS_TABSTOP,52,73,100,15
*/
void wxRC2WXR::ParseSlider(wxString label, wxString varname)
{
wxString tok;
while (ReadOrs(tok));
fprintf(m_wxr," control = [%i,wxSlider,'','wxSL_HORIZONTAL','%s',",m_controlid,varname);
int x,y,width,height;
ReadRect(x,y,width,height);
fprintf(m_wxr,"%i,%i,%i,%i,",x,y,width,height);
fprintf(m_wxr," 1, 1, 10,\\\n");
fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
}
/*
CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
WS_BORDER,15,52,154,13
*/
void wxRC2WXR::ParseProgressBar(wxString label, wxString varname)
{
wxString tok;
while (ReadOrs(tok));
fprintf(m_wxr," control = [%i,wxGauge,'','wxGA_HORIZONTAL','%s',",m_controlid,varname);
int x,y,width,height;
ReadRect(x,y,width,height);
fprintf(m_wxr,"%i,%i,%i,%i,",x,y,width,height);
fprintf(m_wxr," 0, 10,\\\n");
fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
}
bool wxRC2WXR::ReadOrs(wxString & w)
{
wxString tok;
tok=PeekToken();
if (tok.IsNumber())
return false;
w=GetToken();
return TRUE;
}
//Is it a check button or a radio button
void wxRC2WXR::ParseCtrlButton(wxString label, wxString varname)
{
wxString tok;
tok=GetToken();
m_controlid++;
int x,y,width,height;
if (tok=="BS_AUTOCHECKBOX")
{
fprintf(m_wxr," control = [%i,wxCheckBox,'%s','0','%s',",m_controlid,label,varname);
while (ReadOrs(tok));
ReadRect(x,y,width,height);
fprintf(m_wxr,"%i,%i,%i,%i,0,\\\n",x,y,width,height);
fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
}
if (tok=="BS_AUTORADIOBUTTON")
{
fprintf(m_wxr," control = [%i,wxRadioButton,'%s','0','%s',",m_controlid,label,varname);
while(ReadOrs(tok));
ReadRect(x,y,width,height);
fprintf(m_wxr,"%i,%i,%i,%i,0,\\\n",x,y,width,height);
fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
}
}
BEGIN_EVENT_TABLE(wxFileProgressDlg,wxDialog)
END_EVENT_TABLE()
wxFileProgressDlg::wxFileProgressDlg()
{
wxPoint pos;
wxSize size;
pos = ConvertDialogToPixels(wxPoint(10,10));
size = ConvertDialogToPixels(wxSize(170,31));
Create(GetParent(),100,"Parsing RC File",pos,size,603985920);
SetClientSize(size);
Move(pos);
//wxGauge Control
pos = ConvertDialogToPixels(wxPoint(16,16));
size = ConvertDialogToPixels(wxSize(136,6));
m_pProgress = new wxGauge(this,101,100,pos,size);
//wxStaticText Control
pos = ConvertDialogToPixels(wxPoint(72,4));
size = ConvertDialogToPixels(wxSize(18,6));
m_pCompleteLabel= new wxStaticText(this,102,"0",pos,size,0);
}
wxFileProgressDlg::~wxFileProgressDlg()
{
}
void wxFileProgressDlg::UpdateProgress(wxFile * f)
{
int p;
p=(int)((float)f->Tell()/(float)f->Length()*100.0);
m_pProgress->SetValue(p);
wxString t;
t.sprintf("%i%%",p);
m_pCompleteLabel->SetLabel(t);
Refresh();
}
//////////////////////////////////////////////////////////////////////
// GenerateBitmapSrc Class
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
GenerateBitmapSrc::GenerateBitmapSrc()
{
}
GenerateBitmapSrc::~GenerateBitmapSrc()
{
}
bool GenerateBitmapSrc::Create(wxString imfile, wxString srcfile,wxString varname)
{
wxImage img;
FILE *src;
int h,w;
img.LoadFile(imfile,wxBITMAP_TYPE_ANY);
h=img.GetHeight();
w=img.GetWidth();
if( (src = fopen( srcfile, "at" )) == NULL )
return FALSE;
fprintf(src,"#if !defined(IMG_%s)\n",varname);
fprintf(src,"#define IMG_%s\n",varname);
fprintf(src,"//Data from bitmap file %s \n",imfile);
fprintf(src,"//Image Height=%i,Width=%i RGB format\n",h,w);
fprintf(src,"static unsigned char %s[][3]={\n",varname);
for (int y=0;y<h;y++)
{
for (int x=0;x<w;x++)
{
//fprintf(src,"{%i,%i,%i},",img.GetRed(x,y),img.GetGreen(x,y),img.GetBlue(x,y));
}
fprintf(src,"\n");
}
fprintf(src,"};\n\n");
fprintf(src,"wxBitmap Load%s()\n{\n",varname);
fprintf(src,"wxImage myimg(%i,%i);\n",w,h);
int size=w*h*3;
fprintf(src,"memcpy(myimg.GetData(),&%s[0][0],%i);\n",varname,size);
fprintf(src,"return myimg.ConvertToBitmap();\n");
fprintf(src,"}\n");
fprintf(src,"#endif\n");
fclose(src);
return TRUE;
}

View File

@@ -0,0 +1,71 @@
// wxHandleWXR.h: interface for the wxHandleWXR class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(RC2WXR_H)
#define RC2WXR_H
#include "wx/file.h"
#include "stdio.h"
class wxRC2WXR : public wxObject
{
public:
wxRC2WXR();
~wxRC2WXR();
void Open(wxString wxrfile, wxString rcfile);
private:
wxFile m_rc;
FILE *m_wxr;
int m_filesize;
bool m_done;
int m_controlid;
void ParseDialog(wxString dlgname);
void ParseControls();
void ParseStaticText();
void ParseTextCtrl();
void ParsePushButton();
bool Seperator(int ch);
void ParseGroupBox();
void ReadRect(int & x, int & y, int & width, int & height);
wxString GetToken();
wxString GetQuoteField();
void ReadChar(int &ch);
void ParseComboBox();
void ParseMenu(wxString name);
void ParsePopupMenu();
wxString PeekToken();
void ParseControlMS();
void ParseSlider(wxString label, wxString varname);
void ParseProgressBar(wxString label, wxString varname);
bool ReadOrs(wxString & w);
void ParseCtrlButton(wxString label, wxString varname);
};
class wxFileProgressDlg : public wxDialog
{
public:
void UpdateProgress(wxFile *f);
wxFileProgressDlg();
virtual ~wxFileProgressDlg();
protected:
wxGauge *m_pProgress;
wxStaticText *m_pCompleteLabel;
DECLARE_EVENT_TABLE()
};
class GenerateBitmapSrc : public wxObject
{
public:
bool Create(wxString imfile, wxString srcfile,wxString varname);
GenerateBitmapSrc();
virtual ~GenerateBitmapSrc();
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,85 @@
// rc2xml.h
//
//////////////////////////////////////////////////////////////////////
#if !defined(RC2XML_H)
#define RC2XML_H
#include "wx/file.h"
#include <wx/ffile.h>
#include <wx/list.h>
class wxRC2XML : public wxObject
{
public:
void ParseNormalMSControl();
bool Convert(wxString rcfile, wxString xmlfile);
wxRC2XML();
~wxRC2XML();
protected:
void ParseListCtrl(wxString label,wxString varname);
void ParseCalendar(wxString label,wxString varname);
void ParseTreeCtrl(wxString label,wxString varname);
void ParseScrollBar();
void ParseWeirdMSControl();
void ParseStaticBitmap(wxString label,wxString varname);
wxString CleanName(wxString name);
void ParseIcon(wxString varname);
wxList * m_iconlist;
void ParseIconStatic();
void ParseMenuItem();
//Functions
bool SplitHelp(wxString msg, wxString &shorthelp, wxString &longhelp);
bool LookUpString(wxString strid,wxString & st);
void ParseStringTable(wxString varname);
void WriteToolButton(wxString name,int index,int width,int height,wxBitmap bitmap);
wxString LookupString(wxString varname,wxStringList id,wxStringList msg);
void ParseToolBar(wxString varname);
void SecondPass();
void FirstPass();
void ParseBitmap(wxString varname);
void ParseSpinCtrl(wxString label,wxString varname);
void ParseRichEdit(wxString label, wxString varname);
void ParseDialog(wxString dlgname);
void ParseControls();
void ParseListBox();
void ParseStaticText();
void ParseTextCtrl();
void ParsePushButton();
bool Seperator(int ch);
void ParseGroupBox();
void ReadRect(int & x, int & y, int & width, int & height);
wxString GetToken();
wxString GetQuoteField();
void ReadChar(int &ch);
void ParseComboBox();
void ParseMenu(wxString varname);
void ParsePopupMenu();
wxString PeekToken();
void ParseControlMS();
void ParseSlider(wxString label, wxString varname);
void ParseProgressBar(wxString label, wxString varname);
bool ReadOrs(wxString & w);
void ParseCtrlButton(wxString label, wxString varname);
void WriteStyle(wxString style);
void WriteBasicInfo(int x,int y,int width,int height,wxString name);
void WriteName(wxString name);
void WriteTitle(wxString title);
void WritePosition(int x,int y);
void WriteSize(int width,int height);
void WriteLabel(wxString label);
//variables
wxList * m_stringtable;
wxList *m_bitmaplist;
wxFile m_rc;
wxFFile m_xmlfile;
int m_filesize;
bool m_done;
};
#endif

View File

@@ -0,0 +1,694 @@
// wxr2xml.cpp: implementation of the wxWxr2Xml class.
// 8/30/00 Brian Gavin
// only tested on wxMSW so far
//////////////////////////////////////////////////////////////////////
/* TODO
port to wxGTK should be very easy
support fonts
add unsupported controls when XML format adds them
*/
#ifdef __GNUG__
#pragma implementation "wxr2xml.h"
#endif
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "wxr2xml.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
wxWxr2Xml::wxWxr2Xml()
{
}
wxWxr2Xml::~wxWxr2Xml()
{
}
bool wxWxr2Xml::Convert(wxString wxrfile, wxString xmlfile)
{
bool result;
result=m_xmlfile.Open(xmlfile.c_str(),"w+t");
wxASSERT_MSG(result,"Couldn't create XML file");
if (!result)
return FALSE;
result=m_table.ParseResourceFile(wxrfile);
wxASSERT_MSG(result,"Couldn't Load WXR file");
if (!result)
return FALSE;
//Write basic xml header
m_xmlfile.Write("<?xml version=\"1.0\" ?>\n");
m_xmlfile.Write("<resource>\n");
result=ParseResources();
m_xmlfile.Write("</resource>\n");
m_xmlfile.Close();
return result;
}
bool wxWxr2Xml::ParseResources()
{
m_table.BeginFind();
wxNode *node;
while ((node = m_table.Next()))
{
wxItemResource *res = (wxItemResource *)node->Data();
wxString resType(res->GetType());
if (resType=="wxDialog")
ParseDialog(res);
else if (resType=="wxPanel")
ParsePanel(res);
else if (resType=="wxPanel")
ParsePanel(res);
else if (resType=="wxMenu")
ParseMenuBar(res);
else if (resType=="wxBitmap")
ParseBitmap(res);
else
wxLogError("Found unsupported resource "+resType);
}
return TRUE;
}
void wxWxr2Xml::ParsePanel(wxItemResource *res)
{
m_xmlfile.Write(" <panel");
PanelStuff(res);
WriteControlInfo(res);
m_xmlfile.Write("\n");
m_xmlfile.Write(" <children>\n");
ParseControls(res);
m_xmlfile.Write(" </children>\n");
m_xmlfile.Write(" </panel>\n");
}
void wxWxr2Xml::ParseDialog(wxItemResource *res)
{
PanelStuff(res);
m_xmlfile.Write(" <dialog");
WriteControlInfo(res);
m_xmlfile.Write(GetTitle(res));
m_xmlfile.Write("\n");
m_xmlfile.Write(" <children>\n");
ParseControls(res);
m_xmlfile.Write(" </children>\n");
m_xmlfile.Write(" </dialog>\n");
}
void wxWxr2Xml::ParseControls(wxItemResource *res)
{
wxNode *node = res->GetChildren().First();
while (node)
{
wxItemResource *res = (wxItemResource *)node->Data();
wxString resType(res->GetType());
if (resType=="wxButton")
ParseButton(res);
else if ((resType=="wxTextCtrl")|(resType=="wxText")
|(resType=="wxMultiText"))
ParseTextCtrl(res);
else if (resType=="wxCheckBox")
ParseCheckBox(res);
else if (resType=="wxRadioBox")
ParseRadioBox(res);
else if (resType=="wxListBox")
ParseListBox(res);
else if ((resType=="wxStaticText")|(resType=="wxMessage"))
ParseStaticText(res);
else if (resType=="wxChoice")
ParseChoice(res);
else if (resType=="wxGauge")
ParseGauge(res);
else if (resType=="wxSlider")
ParseSlider(res);
else if (resType=="wxComboBox")
ParseComboBox(res);
else if (resType=="wxRadioButton")
ParseRadioButton(res);
else if (resType=="wxStaticBitmap")
ParseStaticBitmap(res);
else if (resType=="wxScrollBar")
wxLogError("wxScrollBar unsupported");
else if ((resType=="wxStaticBox")|(resType=="wxGroupBox"))
wxLogError("wxStaticBox unsupported");
else if (resType=="wxBitmapButton")
wxLogError("wxBitmapButton unsupported");
else
wxLogError("Found unsupported resource "+resType);
node = node->Next();
}
}
//Write out basic stuff every control has
// name,position,size,bg,fg
void wxWxr2Xml::WriteControlInfo(wxItemResource *res)
{
m_xmlfile.Write(GenerateName(res));
m_xmlfile.Write(">\n");
m_xmlfile.Write(GetPosition(res));
m_xmlfile.Write(GetSize(res));
m_xmlfile.Write(GetStyles(res));
}
wxString wxWxr2Xml::GetSize(wxItemResource *res)
{
wxString msg;
if (m_dlgunits)
msg<<" <size>"<<res->GetWidth()<<","<<res->GetHeight()<<"d</size>";
else
msg<<" <size>"<<res->GetWidth()<<","<<res->GetHeight()<<"</size>";
return msg;
}
wxString wxWxr2Xml::GetPosition(wxItemResource *res)
{
wxString msg;
if (m_dlgunits)
msg<<" <pos>"<<res->GetX()<<","<<res->GetY()<<"d</pos>";
else
msg<<" <pos>"<<res->GetX()<<","<<res->GetY()<<"</pos>";
return msg;
}
void wxWxr2Xml::ParseButton(wxItemResource *res)
{
m_xmlfile.Write(" <button");
WriteControlInfo(res);
m_xmlfile.Write(GetLabel(res));
m_xmlfile.Write("</button>\n");
}
void wxWxr2Xml::ParseTextCtrl(wxItemResource *res)
{
m_xmlfile.Write(" <textctrl");
WriteControlInfo(res);
m_xmlfile.Write(GetValue4(res));
m_xmlfile.Write("</textctrl>\n");
}
wxString wxWxr2Xml::GetTitle(wxItemResource *res)
{
wxString msg;
msg=_T(" <title>"+res->GetTitle()+"</title>");
return msg;
}
wxString wxWxr2Xml::GetValue4(wxItemResource *res)
{
wxString msg;
msg=_T(" <value>"+res->GetValue4()+"</value>");
return msg;
}
void wxWxr2Xml::ParseCheckBox(wxItemResource *res)
{
m_xmlfile.Write(" <checkbox");
WriteControlInfo(res);
m_xmlfile.Write(GetLabel(res));
m_xmlfile.Write(GetCheckStatus(res));
m_xmlfile.Write("</checkbox>\n");
}
wxString wxWxr2Xml::GetLabel(wxItemResource *res)
{
return _T(" <label>"+res->GetTitle()+"</label>");
}
void wxWxr2Xml::ParseRadioBox(wxItemResource *res)
{
m_xmlfile.Write(" <radiobox");
WriteControlInfo(res);
m_xmlfile.Write(GetLabel(res));
//Add radio box items
WriteStringList(res);
//Value1
m_xmlfile.Write(GetDimension(res));
m_xmlfile.Write("\n </radiobox>\n");
}
void wxWxr2Xml::ParseListBox(wxItemResource *res)
{
m_xmlfile.Write(" <listbox");
WriteControlInfo(res);
WriteStringList(res);
m_xmlfile.Write("</listbox>\n");
}
void wxWxr2Xml::ParseStaticText(wxItemResource *res)
{
m_xmlfile.Write(" <statictext");
WriteControlInfo(res);
m_xmlfile.Write(GetLabel(res));
m_xmlfile.Write("</statictext>\n");
}
void wxWxr2Xml::ParseStaticBox(wxItemResource *res)
{
m_xmlfile.Write(" <staticbox");
WriteControlInfo(res);
m_xmlfile.Write(GetLabel(res));
m_xmlfile.Write("</staticbox>\n");
}
void wxWxr2Xml::WriteStringList(wxItemResource *res)
{
m_xmlfile.Write("\n <content>");
for ( wxStringListNode *node = res->GetStringValues().GetFirst(); node;
node = node->GetNext() )
{
const wxString s1 = node->GetData();
m_xmlfile.Write("\n <item>"+s1+"</item>");
}
m_xmlfile.Write("\n </content>");
}
void wxWxr2Xml::ParseChoice(wxItemResource *res)
{
m_xmlfile.Write(" <choice");
WriteControlInfo(res);
//Add choice items
WriteStringList(res);
m_xmlfile.Write("\n </choice>\n");
}
void wxWxr2Xml::ParseGauge(wxItemResource *res)
{
m_xmlfile.Write(" <gauge");
WriteControlInfo(res);
m_xmlfile.Write(GetValue1(res));
m_xmlfile.Write(GetRange(res));
m_xmlfile.Write("\n </gauge>\n");
}
wxString wxWxr2Xml::GetValue1(wxItemResource *res)
{
wxString msg;
msg<<" <value>"<<res->GetValue1()<<"</value>";
return msg;
}
wxString wxWxr2Xml::GetRange(wxItemResource *res)
{
wxString msg;
msg<<" <range>"<<res->GetValue2()<<"</range>";
return msg;
}
void wxWxr2Xml::ParseSlider(wxItemResource *res)
{
m_xmlfile.Write(" <slider");
WriteControlInfo(res);
m_xmlfile.Write(GetValue1(res));
m_xmlfile.Write(GetMax(res));
m_xmlfile.Write(GetMin(res));
m_xmlfile.Write("\n </slider>\n");
}
wxString wxWxr2Xml::GetMax(wxItemResource *res)
{
wxString msg;
msg<<" <max>"<<res->GetValue3()<<"</max>";
return msg;
}
wxString wxWxr2Xml::GetMin(wxItemResource *res)
{
wxString msg;
msg<<" <min>"<<res->GetValue2()<<"</min>";
return msg;
}
void wxWxr2Xml::ParseComboBox(wxItemResource *res)
{
m_xmlfile.Write(" <combobox");
WriteControlInfo(res);
//Add combo items
WriteStringList(res);
m_xmlfile.Write("\n </combobox>\n");
}
void wxWxr2Xml::ParseRadioButton(wxItemResource *res)
{
m_xmlfile.Write(" <radiobutton");
WriteControlInfo(res);
m_xmlfile.Write(GetLabel(res));
wxString msg;
m_xmlfile.Write(GetValue1(res));
m_xmlfile.Write(GetCheckStatus(res));
m_xmlfile.Write("\n </radiobutton>\n");
}
void wxWxr2Xml::ParseScrollBar(wxItemResource *res)
{
m_xmlfile.Write(" <scrollbar");
WriteControlInfo(res);
//TODO learn more about XML scrollbar format
m_xmlfile.Write("\n </scrollbar>\n");
}
wxString wxWxr2Xml::GetCheckStatus(wxItemResource *res)
{
wxString msg;
msg<<" <checked>"<<res->GetValue1()<<"</checked>";
return msg;
}
wxString wxWxr2Xml::GetStyles(wxItemResource *res)
{
//Very crude way to get styles
long style;
wxString s,restype;
restype=res->GetType();
style=res->GetStyle();
s="<style>";
//Common styles for all controls
if (style&wxSIMPLE_BORDER)
s+="wxSIMPLE_BORDER|";
if (style&wxSUNKEN_BORDER)
s+="wxSUNKEN_BORDER|";
if (style&wxSIMPLE_BORDER)
s+="wxSIMPLE_BORDER|";
if (style&wxDOUBLE_BORDER)
s+="wxDOUBLE_BORDER|";
if (style&wxRAISED_BORDER)
s+="wxRAISED_BORDER|";
if (style&wxTRANSPARENT_WINDOW)
s+="wxTRANSPARENT_WINDOW|";
if (style&wxWANTS_CHARS)
s+="wxWANTS_CHARS|";
if (style&wxNO_FULL_REPAINT_ON_RESIZE)
s+="wxNO_FULL_REPAINT_ON_RESIZE|";
if (restype=="wxDialog")
{
if (style&wxDIALOG_MODAL)
s+="wxDIALOG_MODAL|";
if (style&wxDEFAULT_DIALOG_STYLE)
s+="wxDEFAULT_DIALOG_STYLE|";
if (style&wxDIALOG_MODELESS)
s+="wxDIALOG_MODELESS|";
if (style&wxNO_3D)
s+="wxNO_3D|";
if (style&wxTAB_TRAVERSAL)
s+="wxTAB_TRAVERSAL|";
if (style&wxWS_EX_VALIDATE_RECURSIVELY)
s+="wxWS_EX_VALIDATE_RECURSIVELY|";
if (style&wxSTAY_ON_TOP)
s+="wxSTAY_ON_TOP|";
if (style&wxCAPTION)
s+="wxCAPTION|";
if (style&wxTHICK_FRAME)
s+="wxTHICK_FRAME|";
if (style&wxRESIZE_BOX)
s+="wxRESIZE_BOX|";
if (style&wxRESIZE_BORDER)
s+="wxRESIZE_BORDER|";
if (style&wxSYSTEM_MENU)
s+="wxSYSTEM_MENU|";
if (style&wxCLIP_CHILDREN)
s+="wxCLIP_CHILDREN|";
}
if (restype=="wxPanel")
{
if (style&wxCLIP_CHILDREN)
s+="wxCLIP_CHILDREN|";
if (style&wxNO_3D)
s+="wxNO_3D|";
if (style&wxTAB_TRAVERSAL)
s+="wxTAB_TRAVERSAL|";
if (style&wxWS_EX_VALIDATE_RECURSIVELY)
s+="wxWS_EX_VALIDATE_RECURSIVELY|";
}
if (restype=="wxComboBox")
{
if (style&wxCB_SORT)
s+="wxCB_SORT|";
if (style&wxCB_SIMPLE)
s+="wxCB_SIMPLE|";
if (style&wxCB_READONLY)
s+="wxCB_READONLY|";
if (style&wxCB_DROPDOWN)
s+="wxCB_DROPDOWN|";
}
if (restype=="wxGauge")
{
if (style&wxGA_HORIZONTAL)
s+="wxGA_HORIZONTAL|";
if (style&wxGA_VERTICAL)
s+="wxGA_VERTICAL|";
if (style&wxGA_PROGRESSBAR)
s+="wxGA_PROGRESSBAR|";
// windows only
if (style&wxGA_SMOOTH)
s+="wxGA_SMOOTH|";
}
if (restype=="wxRadioButton")
{
if (style&wxRB_GROUP)
s+="wxRB_GROUP|";
}
if (restype=="wxStaticText")
{
if (style&wxST_NO_AUTORESIZE)
s+="wxST_NO_AUTORESIZEL|";
}
if (restype=="wxRadioBox")
{
if (style&wxRA_HORIZONTAL)
s+="wxRA_HORIZONTAL|";
if (style&wxRA_SPECIFY_COLS)
s+="wxRA_SPECIFY_COLS|";
if (style&wxRA_SPECIFY_ROWS)
s+="wxRA_SPECIFY_ROWS|";
if (style&wxRA_VERTICAL)
s+="wxRA_VERTICAL|";
}
if (restype=="wxListBox")
{
if (style&wxLB_SINGLE)
s+="wxLB_SINGLE|";
if (style&wxLB_MULTIPLE)
s+="wxLB_MULTIPLE|";
if (style&wxLB_EXTENDED)
s+="wxLB_EXTENDED|";
if (style&wxLB_HSCROLL)
s+="wxLB_HSCROLL|";
if (style&wxLB_ALWAYS_SB)
s+="wxLB_ALWAYS_SB|";
if (style&wxLB_NEEDED_SB)
s+="wxLB_NEEDED_SB|";
if (style&wxLB_SORT)
s+="wxLB_SORT|";
}
if (restype=="wxTextCtrl")
{
if (style&wxTE_PROCESS_ENTER)
s+="wxTE_PROCESS_ENTER|";
if (style&wxTE_PROCESS_TAB)
s+="wxTE_PROCESS_TAB|";
if (style&wxTE_MULTILINE)
s+="wxTE_MULTILINE|";
if (style&wxTE_PASSWORD)
s+="wxTE_PASSWORD|";
if (style&wxTE_READONLY)
s+="wxTE_READONLY|";
if (style&wxHSCROLL)
s+="wxHSCROLL|";
}
int l;
l=s.Length();
//No styles defined
if (l==7)
return _T("");
//Trim off last |
s=s.Truncate(l-1);
s+="</style>";
return s;
}
wxString wxWxr2Xml::GetDimension(wxItemResource *res)
{
wxString msg;
msg<<" <dimension>"<<res->GetValue1()<<"</dimension>";
return msg;
}
wxString wxWxr2Xml::GenerateName(wxItemResource *res)
{
wxString name;
name=_T(" name=\"");
switch (res->GetId())
{
case wxID_OK:
name+=_T("wxID_OK");
break;
case wxID_CANCEL:
name+=_T("wxID_CANCEL");
break;
default:
name+=res->GetName();
}
name+="\"";
return name;
}
void wxWxr2Xml::ParseMenuBar(wxItemResource *res)
{
wxItemResource *child;
wxNode *node = res->GetChildren().First();
//Get Menu Bar Name
m_xmlfile.Write("<menubar ");
m_xmlfile.Write(GenerateName(res));
m_xmlfile.Write(">\n");
m_xmlfile.Write(" <children>\n");
while (node)
{
child= (wxItemResource *)node->Data();
ParseMenu(child);
node = node->Next();
}
m_xmlfile.Write(" </children>\n");
m_xmlfile.Write("</menubar> \n");
}
void wxWxr2Xml::ParseMenu(wxItemResource *res)
{
wxItemResource *child;
wxNode *node = res->GetChildren().First();
//Get Menu
m_xmlfile.Write(" <menu ");
wxString menuname;
menuname<<"name = \"menu_"<<res->GetValue1()<<"\"";
m_xmlfile.Write(menuname);
m_xmlfile.Write(">\n");
m_xmlfile.Write(" <label>"
+FixMenuString(res->GetTitle())+"</label>\n");
if (res->GetValue4()!="")
m_xmlfile.Write(" <help>"+res->GetValue4()+"</help>\n");
m_xmlfile.Write(" <children>\n");
//Read in menu items and additional menus
while (node)
{
child= (wxItemResource *)node->Data();
if (!child->GetChildren().First())
ParseMenuItem(child);
else
ParseMenu(child);
node = node->Next();
}
m_xmlfile.Write(" </children>\n");
m_xmlfile.Write(" </menu> \n");
}
void wxWxr2Xml::ParseMenuItem(wxItemResource *res)
{
//Get Menu Item or Separator
if (res->GetTitle()=="")
{
m_xmlfile.Write(" <separator/>\n");
}
else
{
m_xmlfile.Write(" <menuitem ");
wxString menuname;
menuname<<"name = \"menuitem_"<<res->GetValue1()<<"\"";
m_xmlfile.Write(menuname);
m_xmlfile.Write(">\n");
m_xmlfile.Write(" <label>"
+FixMenuString(res->GetTitle())+"</label>\n");
if (res->GetValue4()!="")
m_xmlfile.Write(" <help>"+res->GetValue4()+"</help>\n");
if (res->GetValue2())
m_xmlfile.Write(" <checkable>1</checkable>\n");
m_xmlfile.Write(" </menuitem> \n");
}
}
wxString wxWxr2Xml::FixMenuString(wxString phrase)
{
phrase.Replace("&","$");
return phrase;
}
void wxWxr2Xml::ParseStaticBitmap(wxItemResource *res)
{
m_xmlfile.Write(" <staticbitmap");
WriteControlInfo(res);
//value4 holds bitmap name
wxString bitmapname;
bitmapname=res->GetValue4();
wxBitmap bitmap;
bitmap= wxResourceCreateBitmap(bitmapname,&m_table);
bitmapname+=_T(".bmp");
bitmap.SaveFile(bitmapname,wxBITMAP_TYPE_BMP);
m_xmlfile.Write("\n <bitmap>"+bitmapname+"</bitmap>");
m_xmlfile.Write("</staticbitmap>\n");
//bitmap5
}
void wxWxr2Xml::ParseBitmap(wxItemResource *res)
{
}
void wxWxr2Xml::PanelStuff(wxItemResource *res)
{
if ((res->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0)
m_dlgunits=TRUE;
else
m_dlgunits=FALSE;
//If this is true ignore fonts, background color and use system
//defaults instead
if ((res->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS) != 0)
m_systemdefaults=TRUE;
else
m_systemdefaults=FALSE;
}

View File

@@ -0,0 +1,67 @@
// wxr2xml.h:
// 8/30/00 Brian Gavin
//////////////////////////////////////////////////////////////////////
#if !defined(WXR2XML_H)
#define WXR2XML_H
#include <wx/ffile.h>
#include "wx/resource.h"
class wxWxr2Xml : public wxObject
{
public:
bool Convert(wxString wxrfile,wxString xmlfile);
wxWxr2Xml();
virtual ~wxWxr2Xml();
protected:
void PanelStuff(wxItemResource *res);
bool m_systemdefaults;
bool m_dlgunits;
void ParseBitmap(wxItemResource *res);
void ParseStaticBitmap(wxItemResource *res);
wxString FixMenuString(wxString phrase);
void ParseMenuItem(wxItemResource *res);
void ParseMenu(wxItemResource *res);
void ParseMenuBar(wxItemResource *res);
wxString GenerateName(wxItemResource *res);
wxString GetStyles(wxItemResource *res);
wxString GetDimension(wxItemResource *res);
void ParsePanel(wxItemResource *res);
void ParseRadioButton(wxItemResource *res);
wxString GetMin(wxItemResource *res);
wxString GetCheckStatus(wxItemResource *res);
void ParseScrollBar(wxItemResource *res);
void ParseComboBox(wxItemResource * res);
wxString GetMax(wxItemResource *res);
void ParseSlider(wxItemResource *res);
wxString GetValue1(wxItemResource *res);
wxString GetRange(wxItemResource *res);
void ParseGauge(wxItemResource *res);
void ParseChoice(wxItemResource *res);
void WriteStringList(wxItemResource *res);
void ParseStaticBox(wxItemResource *res);
void ParseRadioBox(wxItemResource *res);
wxString GetLabel(wxItemResource *res);
void ParseCheckBox(wxItemResource *res);
wxString GetValue4(wxItemResource *res);
wxString GetTitle(wxItemResource *res);
void ParseTextCtrl(wxItemResource *res);
void ParseButton(wxItemResource *res);
wxString GetPosition(wxItemResource *res);
void WriteControlInfo(wxItemResource *res);
void ParseStaticText(wxItemResource *res);
void ParseListBox(wxItemResource *res);
wxString GetSize(wxItemResource *res);
void ParseControls(wxItemResource *res);
void ParseDialog(wxItemResource *res);
bool ParseResources();
//Variables
wxResourceTable m_table;
wxFFile m_xmlfile;
};
#endif