From: Václav Slavík Date: Sun, 17 Sep 2000 19:17:13 +0000 (+0000) Subject: added rc2xml and wxr2xml convertor (no makefiles yet) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/88d42654d76be0098f6a1fa12b83af97f5b6235a?ds=sidebyside 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 --- diff --git a/contrib/utils/convertrc/rc2wxr.cpp b/contrib/utils/convertrc/rc2wxr.cpp new file mode 100644 index 0000000000..3c91b14a61 --- /dev/null +++ b/contrib/utils/convertrc/rc2wxr.cpp @@ -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\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"); +ParseControls(); +m_xmlfile.Write(" \n"); +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(" \n"); + +} + + +bool wxRC2XML::Seperator(int ch) +{ +//if ((ch==' ')|(ch==',')|(ch==13)|(ch==10)|(ch=='|')|(ch=='\t')) +if ((ch==' ')|(ch==',')|(ch==13)|(ch==10)|(ch=='\t')) + return TRUE; + +if (ch==EOF) +{ + m_done=TRUE; + return TRUE; +} +return FALSE; +} + +void wxRC2XML::ParseGroupBox() +{ +// GROUPBOX "Rotate",IDC_STATIC,1,1,71,79 +wxString token; +wxString phrase,varname; +phrase=GetQuoteField(); +varname=GetToken(); +int x,y,width,height; +ReadRect(x,y,width,height); + +m_xmlfile.Write(" \n"); + + +} + +void wxRC2XML::ReadRect(int & x, int & y, int & width, int & height) +{ +x=atoi(GetToken()); +y=atoi(GetToken()); +width=atoi(GetToken()); +height=atoi(GetToken()); + +} + +wxString wxRC2XML::GetToken() +{ +wxString token=""; + +if (m_rc.Eof()) +{ +m_done=TRUE; +return token; +} + +int ch=0; +ReadChar(ch); +if (ch==EOF) +{ +m_done=TRUE; +return token; +} + +while (Seperator(ch)) +{ + ReadChar(ch); + if (m_done) + return token; +} + +if (ch==EOF) +{ + m_done=TRUE; + +} + + +while (!Seperator(ch)) +{ + token+=(char)ch; + ReadChar(ch); + +} + +if (ch==EOF) + m_done=TRUE; + + +return token; +} + +wxString wxRC2XML::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 wxRC2XML::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 wxRC2XML::ParseComboBox() +{ +/* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT | + WS_VSCROLL | WS_TABSTOP */ +wxString token; +wxString varname; +varname=GetToken(); +int x,y,width,height; +ReadRect(x,y,width,height); + +m_xmlfile.Write(" \n"); + + + +} + +void wxRC2XML::ParseMenu(wxString varname) +{ +wxString token=""; + +//Write menubar to xml file +m_xmlfile.Write(" \n"); +m_xmlfile.Write(" \n"); + +while ((token!="BEGIN")&(token!="{")) + token=GetToken(); + +while ((token!="END")&(token!="}")) +{ + token=GetToken(); +if (token=="POPUP") + { + ParsePopupMenu(); + } +} +m_xmlfile.Write(" \n"); +m_xmlfile.Write(" \n"); +} + +void wxRC2XML::ParsePopupMenu() +{ +static menucount=0; +menucount++; +wxString token,name,msg,longhelp,tip; +token=GetQuoteField(); +int spot; +//Remove /t because it causes problems + +spot=token.First("\\t"); +token=token.Left(spot); + +//Write Menu item +//Generate a fake name since RC menus don't have one +name<<"Menu_"<\n"); +WriteLabel(token); +m_xmlfile.Write(" \n"); + +while ((token!="BEGIN")&(token!="{")) + token=GetToken(); + +while ((token!="END")&(token!="}")) + { + token=GetToken(); + + if (token=="POPUP") + ParsePopupMenu(); + + if (token=="MENUITEM") + ParseMenuItem(); + + } +m_xmlfile.Write(" \n"); +m_xmlfile.Write(" \n"); +} + +wxString wxRC2XML::PeekToken() +{ +wxString token; +int p; +p=m_rc.Tell(); +token=GetToken(); + +m_rc.Seek(p); +return token; +} +//MS Windows pain in the butt CONTROL +void wxRC2XML::ParseControlMS() +{ +wxString label,varname,kindctrl,token; +token=PeekToken(); + +if (token.Contains("\"")) + ParseNormalMSControl(); +else + ParseWeirdMSControl(); + +} + +/* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH | + TBS_NOTICKS | WS_TABSTOP,52,73,100,15 +*/ + +void wxRC2XML::ParseSlider(wxString label, wxString varname) +{ +wxString token; +while (ReadOrs(token)); +//TODO Handle styles +//fprintf(m_wxrfile," control = [%i,wxSlider,'','wxSL_HORIZONTAL','%s',",m_controlid,varname); +int x,y,width,height; +ReadRect(x,y,width,height); +m_xmlfile.Write(" \n"); + +} +/* +CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32", + WS_BORDER,15,52,154,13 +*/ +void wxRC2XML::ParseProgressBar(wxString label, wxString varname) +{ +wxString token; +while (ReadOrs(token)); +int x,y,width,height; +ReadRect(x,y,width,height); +wxString style; +//Always horizontal in MFC +style+="wxGA_HORIZONTAL"; +m_xmlfile.Write(" \n"); +} + +/* FIXME: this function needs to be rewritten */ +bool wxRC2XML::ReadOrs(wxString & w) +{ +wxString token; +token=PeekToken(); + +if (token.IsNumber()) + return FALSE; + +w=GetToken(); +return TRUE; +} + +//Is it a check button or a radio button +void wxRC2XML::ParseCtrlButton(wxString label, wxString varname) +{ +wxString token; + token=GetToken(); + int x,y,width,height; + +if (token=="BS_AUTOCHECKBOX") + { + while (ReadOrs(token)); + ReadRect(x,y,width,height); + m_xmlfile.Write(" \n"); + } + +if (token=="BS_AUTORADIOBUTTON") + { + while(ReadOrs(token)); + ReadRect(x,y,width,height); + m_xmlfile.Write(" \n"); + } + + + +} + + +void wxRC2XML::WriteSize(int width, int height) +{ +wxString msg; +msg<<" "<"; +m_xmlfile.Write(msg); +} + +void wxRC2XML::WritePosition(int x, int y) +{ +wxString msg; +msg<<" "<"; +m_xmlfile.Write(msg); +} + +void wxRC2XML::WriteTitle(wxString title) +{ +wxString msg; +msg=_T(" "+title+"\n"); +m_xmlfile.Write(msg); +} + +void wxRC2XML::WriteName(wxString name) +{ + +//Replace common MS ids with wxWindows ids +//I didn't do everyone of them +if (name=="IDOK") + name="wxID_OK"; +else if (name=="IDCANCEL") + name="wxID_CANCEL"; +else if (name=="IDAPPLY") + name="wxID_APPLY"; +else if (name=="ID_FILE_OPEN") + name="wxID_OPEN"; +else if (name=="ID_FILE_CLOSE") + name="wxID_CLOSE"; +else if (name=="ID_FILE_SAVE") + name="wxID_SAVE"; +else if (name=="ID_FILE_SAVE_AS") + name="wxID_SAVEAS"; +else if (name=="ID_APP_EXIT") + name="wxID_EXIT"; +else if (name=="ID_FILE_PRINT") + name="wxID_PRINT"; +else if (name=="ID_FILE_PRINT_PREVIEW") + name="wxID_PREVIEW"; +else if (name=="ID_FILE_PRINT_SETUP") + name="wxID_PRINT_SETUP"; +else if (name=="ID_APP_ABOUT") + name="wxID_ABOUT"; +else if (name=="ID_EDIT_UNDO") + name="wxID_UNDO"; +else if (name=="ID_EDIT_CUT") + name="wxID_CUT"; +else if (name=="ID_EDIT_COPY") + name="wxID_COPY"; +else if (name=="ID_EDIT_PASTE") + name="wxID_PASTE"; + +m_xmlfile.Write(" name= \""+name+"\""); +} + +void wxRC2XML::WriteLabel(wxString label) +{ +label.Replace("&","$"); +m_xmlfile.Write(" \n"); +} + +void wxRC2XML::WriteBasicInfo(int x, int y, int width, int height, wxString name) +{ +WriteName(name); +m_xmlfile.Write(">\n"); +m_xmlfile.Write(" "); +WritePosition(x,y); +WriteSize(width,height); +m_xmlfile.Write("\n"); + +} + +void wxRC2XML::WriteStyle(wxString style) +{ +if (style.Length()==0) + return; +m_xmlfile.Write("\n \n"); +} +/* + LISTBOX IDC_LIST1,16,89,48,40,LBS_SORT | LBS_MULTIPLESEL | + LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP +*/ +void wxRC2XML::ParseListBox() +{ +wxString token; +wxString varname; + +varname=GetToken(); +int x,y,width,height; +ReadRect(x,y,width,height); + +m_xmlfile.Write(" \n"); + +} +/* + CONTROL "",IDC_RICHEDIT1,"RICHEDIT",ES_AUTOHSCROLL | WS_BORDER | + WS_TABSTOP,103,110,40,14 +*/ +void wxRC2XML::ParseRichEdit(wxString label, wxString varname) +{ +wxString token; +while (ReadOrs(token)); +int x,y,width,height; +ReadRect(x,y,width,height); +wxString style; +//Make it a rich text control +style+="wxTE_MULTILINE "; +m_xmlfile.Write(" \n"); + +} +/* +CONTROL "Spin1",IDC_SPIN1,"msctls_updown32",UDS_ARROWKEYS,209,72, + 19,26 +*/ +void wxRC2XML::ParseSpinCtrl(wxString label, wxString varname) +{ +wxString token; +while (ReadOrs(token)); +int x,y,width,height; +ReadRect(x,y,width,height); +wxString style; +m_xmlfile.Write(" \n"); + + +} + +void wxRC2XML::FirstPass() +{ +wxString token,prevtok; +while (!m_done) + { + token=GetToken(); + if (token=="BITMAP") + ParseBitmap(prevtok); + else if (token=="STRINGTABLE") + ParseStringTable(prevtok); + else if (token=="ICON") + ParseIcon(prevtok); + prevtok=token; + } +} + +void wxRC2XML::ParseBitmap(wxString varname) +{ +wxString token,*bitmapfile; +bitmapfile=new wxString; +token=PeekToken(); +//Microsoft notation? +if (token=="DISCARDABLE") + { + token=GetToken(); + token=PeekToken(); + } + +*bitmapfile=GetQuoteField(); +m_bitmaplist->Append(varname,bitmapfile); + +} + + +void wxRC2XML::SecondPass() +{ +wxString token,prevtok; +while (!m_done) + { + token=GetToken(); + if (token=="DIALOG") + ParseDialog(prevtok); + else if (token=="MENU") + ParseMenu(prevtok); + else if (token=="TOOLBAR") + ParseToolBar(prevtok); + prevtok=token; + } + +} + +void wxRC2XML::ParseToolBar(wxString varname) +{ +wxString token; +token=GetToken(); +wxASSERT_MSG(token=="DISCARDABLE","Error in toolbar parsing"); + +//Look up bitmap for toolbar and load +wxNode *node=m_bitmaplist->Find(varname); +wxString *bitmappath; +bitmappath=(wxString *)node->Data(); +wxBitmap bitmap; +if (!bitmap.LoadFile(*bitmappath,wxBITMAP_TYPE_BMP )) + wxLogError("Unable to load bitmap:"+*bitmappath); + +//Write toolbar to xml file +m_xmlfile.Write(" \n"); +wxString style; +style+="wxTB_FLAT"; +WriteStyle(style); + +m_xmlfile.Write(" \n"); + +//Grab width and height +int width,height; +width=atoi(GetToken()); +height=atoi(GetToken()); + +int c=0; +wxString buttonname,msg,tip,longhelp; +token=GetToken(); +while ((token!="BEGIN")) + token=GetToken(); + +while ((token!="END")&(token!="}")) + { + if (token=="BUTTON") + { + buttonname=GetToken(); + m_xmlfile.Write(" \n"); + //Write tool tip if any + if (LookUpString(buttonname,msg)) + { + SplitHelp(msg,tip,longhelp); + m_xmlfile.Write(" "+tip+"\n"); + m_xmlfile.Write(" "+longhelp+"\n"); + } + //Make a bitmap file name + buttonname=CleanName(buttonname); + buttonname+=".bmp"; + m_xmlfile.Write(" "+buttonname+"\n"); + WriteToolButton(buttonname,c,width,height,bitmap); + m_xmlfile.Write(" \n"); + c++; + } + else if (token=="SEPARATOR") + { + m_xmlfile.Write(" \n"); + } + token=GetToken(); + } +m_xmlfile.Write(" \n"); +m_xmlfile.Write(" \n"); +} + +//Extract bitmaps from larger toolbar bitmap +void wxRC2XML::WriteToolButton(wxString name,int index, int width, int height, wxBitmap bitmap) +{ +int x; +x=index*width; +wxRect r(x,0,width,height); +wxBitmap little; + +little=bitmap.GetSubBitmap(r); +little.SaveFile(name,wxBITMAP_TYPE_BMP); +} + +void wxRC2XML::ParseStringTable(wxString varname) +{ +wxString token; +token=GetToken(); +while ((token!="BEGIN")) + token=GetToken(); +token=GetToken(); +wxString *msg; + +while ((token!="END")&(token!="}")) + { + msg=new wxString; + *msg=GetQuoteField(); + m_stringtable->Append(token,msg); + token=GetToken(); + } + +} + +bool wxRC2XML::LookUpString(wxString strid,wxString & st) +{ +wxNode *node=m_stringtable->Find(strid); +wxString *s; +if (node==NULL) + return FALSE; + +s=(wxString *)node->Data(); +st=*s; + +return TRUE; +} + +bool wxRC2XML::SplitHelp(wxString msg, wxString &shorthelp, wxString &longhelp) +{ +int spot; +spot=msg.Find("\\n"); +if (spot==-1) + { + shorthelp=msg; + longhelp=msg; + } + +longhelp=msg.Left(spot); +spot=msg.Length()-spot-2; +shorthelp=msg.Right(spot); +return TRUE; +} + +void wxRC2XML::ParseMenuItem() +{ +wxString token,name,msg,tip,longhelp; +int spot; +if (PeekToken()=="SEPARATOR") + { + m_xmlfile.Write(" \n"); + return; + } + +token=GetQuoteField(); +name=GetToken(); +//Remove /t because it causes problems +spot=token.First("\\t"); +token=token.Left(spot); +m_xmlfile.Write(" \n"); +WriteLabel(token); +//Look up help if any listed in stringtable +if (LookUpString(name,msg)) + { + SplitHelp(msg,tip,longhelp); + m_xmlfile.Write(" " + +longhelp+"\n"); + } +//look for extra attributes like checked and break +wxString ptoken; +ptoken=PeekToken(); +while ((ptoken!="MENUITEM")&(ptoken!="POPUP")&(ptoken!="END")) + { + token=GetToken(); + if (token=="CHECKED") + m_xmlfile.Write(" 1\n"); + else if (token=="MENUBREAK"); + //m_xmlfile.Write(" \n"); + else if (token=="GRAYED"); + else + wxLogError("Unknown Menu Item token:"+token); + ptoken=PeekToken(); + } +m_xmlfile.Write(" \n"); + +} + +//ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20 +void wxRC2XML::ParseIconStatic() +{ +wxString token; +wxString varname,iconname; +iconname=GetToken(); +//Look up icon +wxNode *node=m_iconlist->Find(iconname); +wxString *iconpath; +iconpath=(wxString *)node->Data(); +wxIcon icon; +wxBitmap bitmap; +if (!icon.LoadFile(*iconpath,wxBITMAP_TYPE_ICO )) + wxLogError("Unable to load icon:"+*iconpath); +bitmap.CopyFromIcon(icon); +varname=GetToken(); + +int x,y,width,height; +ReadRect(x,y,width,height); + +m_xmlfile.Write(" "+iconname+"\n"); +bitmap.SaveFile(iconname,wxBITMAP_TYPE_BMP); +m_xmlfile.Write(" \n"); + +} +//IDR_MAINFRAME ICON DISCARDABLE "res\\mfcexample.ico" +void wxRC2XML::ParseIcon(wxString varname) +{ +wxString token,*iconfile; +iconfile=new wxString; +token=PeekToken(); + +*iconfile=GetQuoteField(); +m_iconlist->Append(varname,iconfile); + +} + +wxString wxRC2XML::CleanName(wxString name) +{ +name.MakeLower(); +name.Replace("id_",""); +name.Replace("idr_",""); +name.Replace("idb_",""); +name.Replace("idc_",""); +return name; +} +// And the award for most messed up control goes to... +// CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30 +void wxRC2XML::ParseStaticBitmap(wxString bitmapname, wxString varname) +{ +wxString token; +//Grab SS_BITMAP +token=GetToken(); + +//Look up bitmap +wxNode *node=m_bitmaplist->Find(bitmapname); +wxString *bitmappath; +bitmappath=(wxString *)node->Data(); +wxBitmap bitmap; +if (!bitmap.LoadFile(*bitmappath,wxBITMAP_TYPE_BMP )) + wxLogError("Unable to load bitmap:"+*bitmappath); + +int x,y,width,height; +ReadRect(x,y,width,height); + +m_xmlfile.Write(" "+bitmapname+"\n"); +bitmap.SaveFile(bitmapname,wxBITMAP_TYPE_BMP); +m_xmlfile.Write(" \n"); + + +} + +void wxRC2XML::ParseNormalMSControl() +{ +wxString label,varname,kindctrl; + +label=GetQuoteField(); +varname=GetToken(); +kindctrl=GetQuoteField(); +kindctrl.MakeUpper(); + +if (kindctrl=="MSCTLS_UPDOWN32") + ParseSpinCtrl(label,varname); +if (kindctrl=="MSCTLS_TRACKBAR32") + ParseSlider(label,varname); +if (kindctrl=="MSCTLS_PROGRESS32") + ParseProgressBar(label,varname); +if (kindctrl=="SYSTREEVIEW32") + ParseTreeCtrl(label,varname); +if (kindctrl=="SYSMONTHCAL32") + ParseCalendar(label,varname); +if (kindctrl=="SYSLISTVIEW32") + ParseListCtrl(label,varname); +if (kindctrl=="BUTTON") + ParseCtrlButton(label,varname); +if (kindctrl=="RICHEDIT") + ParseRichEdit(label,varname); + +} + +void wxRC2XML::ParseWeirdMSControl() +{ +wxString kindctrl; +wxString varname; +wxString id; +id=GetToken(); +varname=GetToken(); +kindctrl=GetQuoteField(); +kindctrl.MakeUpper(); +// CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30 +if (kindctrl=="STATIC") + { + if (PeekToken()=="SS_BITMAP") + ParseStaticBitmap(id,varname); + else + wxLogError("Unknown MS Control Static token"); + } + +} +//SCROLLBAR IDC_SCROLLBAR1,219,56,10,40,SBS_VERT + +void wxRC2XML::ParseScrollBar() +{ +wxString token; +wxString varname; + +varname=GetToken(); +int x,y,width,height; +ReadRect(x,y,width,height); +wxString style; +//Default MFC style is horizontal +style=_T("wxSB_HORIZONTAL"); +/* +while (ReadOrs(token)) +{ +if (token=="SBS_VERT") + style=_T("wxSB_VERTICAL"); +} +*/ +m_xmlfile.Write(" \n"); + + +} +// CONTROL "Tree1",IDC_TREE1,"SysTreeView32",WS_BORDER | WS_TABSTOP, +// 7,7,66,61 + +void wxRC2XML::ParseTreeCtrl(wxString label, wxString varname) +{ +wxString token; +while (ReadOrs(token)); +int x,y,width,height; +ReadRect(x,y,width,height); +m_xmlfile.Write(" \n"); + +} +// CONTROL "MonthCalendar1",IDC_MONTHCALENDAR1,"SysMonthCal32", + //MCS_NOTODAY | WS_TABSTOP,105,71,129,89 + +void wxRC2XML::ParseCalendar(wxString label, wxString varname) +{ +wxString token; +while (ReadOrs(token)); +int x,y,width,height; +ReadRect(x,y,width,height); +m_xmlfile.Write(" \n"); +} +// CONTROL "List1",IDC_LIST1,"SysListView32",WS_BORDER | WS_TABSTOP, + // 7,89,68,71 + +void wxRC2XML::ParseListCtrl(wxString label, wxString varname) +{ +wxString token; +while (ReadOrs(token)); +int x,y,width,height; +ReadRect(x,y,width,height); +m_xmlfile.Write(" \n"); + +} diff --git a/contrib/utils/convertrc/rc2xml.h b/contrib/utils/convertrc/rc2xml.h new file mode 100644 index 0000000000..697efea085 --- /dev/null +++ b/contrib/utils/convertrc/rc2xml.h @@ -0,0 +1,85 @@ +// rc2xml.h +// +////////////////////////////////////////////////////////////////////// + +#if !defined(RC2XML_H) +#define RC2XML_H + +#include "wx/file.h" +#include +#include + + +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 \ No newline at end of file diff --git a/contrib/utils/convertrc/wxr2xml.cpp b/contrib/utils/convertrc/wxr2xml.cpp new file mode 100644 index 0000000000..a6e9d0d973 --- /dev/null +++ b/contrib/utils/convertrc/wxr2xml.cpp @@ -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("\n"); +m_xmlfile.Write("\n"); +result=ParseResources(); +m_xmlfile.Write("\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(" \n"); +ParseControls(res); +m_xmlfile.Write(" \n"); + +m_xmlfile.Write(" \n"); +} + + +void wxWxr2Xml::ParseDialog(wxItemResource *res) +{ +PanelStuff(res); +m_xmlfile.Write(" \n"); +ParseControls(res); +m_xmlfile.Write(" \n"); +m_xmlfile.Write(" \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<<" "<GetWidth()<<","<GetHeight()<<"d"; +else + msg<<" "<GetWidth()<<","<GetHeight()<<""; +return msg; +} + +wxString wxWxr2Xml::GetPosition(wxItemResource *res) +{ +wxString msg; +if (m_dlgunits) + msg<<" "<GetX()<<","<GetY()<<"d"; +else + msg<<" "<GetX()<<","<GetY()<<""; +return msg; +} + +void wxWxr2Xml::ParseButton(wxItemResource *res) +{ +m_xmlfile.Write(" \n"); +} + +void wxWxr2Xml::ParseTextCtrl(wxItemResource *res) +{ +m_xmlfile.Write(" \n"); + +} + +wxString wxWxr2Xml::GetTitle(wxItemResource *res) +{ +wxString msg; +msg=_T(" "+res->GetTitle()+""); +return msg; +} + +wxString wxWxr2Xml::GetValue4(wxItemResource *res) +{ +wxString msg; +msg=_T(" "+res->GetValue4()+""); +return msg; +} + +void wxWxr2Xml::ParseCheckBox(wxItemResource *res) +{ +m_xmlfile.Write(" \n"); +} + +wxString wxWxr2Xml::GetLabel(wxItemResource *res) +{ +return _T(" "); +} + +void wxWxr2Xml::ParseRadioBox(wxItemResource *res) +{ +m_xmlfile.Write(" \n"); +} + +void wxWxr2Xml::ParseListBox(wxItemResource *res) +{ +m_xmlfile.Write(" \n"); +} + +void wxWxr2Xml::ParseStaticText(wxItemResource *res) +{ +m_xmlfile.Write(" \n"); +} + +void wxWxr2Xml::ParseStaticBox(wxItemResource *res) +{ +m_xmlfile.Write(" \n"); +} + +void wxWxr2Xml::WriteStringList(wxItemResource *res) +{ +m_xmlfile.Write("\n "); +for ( wxStringListNode *node = res->GetStringValues().GetFirst(); node; + node = node->GetNext() ) + { + const wxString s1 = node->GetData(); + m_xmlfile.Write("\n "+s1+""); + } + m_xmlfile.Write("\n "); +} + +void wxWxr2Xml::ParseChoice(wxItemResource *res) +{ +m_xmlfile.Write(" \n"); +} + +void wxWxr2Xml::ParseGauge(wxItemResource *res) +{ +m_xmlfile.Write(" \n"); +} + + +wxString wxWxr2Xml::GetValue1(wxItemResource *res) +{ +wxString msg; +msg<<" "<GetValue1()<<""; +return msg; +} + +wxString wxWxr2Xml::GetRange(wxItemResource *res) +{ +wxString msg; +msg<<" "<GetValue2()<<""; +return msg; +} + +void wxWxr2Xml::ParseSlider(wxItemResource *res) +{ +m_xmlfile.Write(" \n"); +} + +wxString wxWxr2Xml::GetMax(wxItemResource *res) +{ +wxString msg; +msg<<" "<GetValue3()<<""; +return msg; +} + +wxString wxWxr2Xml::GetMin(wxItemResource *res) +{ +wxString msg; +msg<<" "<GetValue2()<<""; +return msg; +} + +void wxWxr2Xml::ParseComboBox(wxItemResource *res) +{ +m_xmlfile.Write(" \n"); +} + +void wxWxr2Xml::ParseRadioButton(wxItemResource *res) +{ +m_xmlfile.Write(" \n"); +} + +void wxWxr2Xml::ParseScrollBar(wxItemResource *res) +{ +m_xmlfile.Write(" \n"); +} + +wxString wxWxr2Xml::GetCheckStatus(wxItemResource *res) +{ +wxString msg; +msg<<" "<GetValue1()<<""; +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=""; +return s; +} + +wxString wxWxr2Xml::GetDimension(wxItemResource *res) +{ +wxString msg; +msg<<" "<GetValue1()<<""; +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("\n"); + m_xmlfile.Write(" \n"); + while (node) + { + child= (wxItemResource *)node->Data(); + ParseMenu(child); + node = node->Next(); + } + + m_xmlfile.Write(" \n"); + m_xmlfile.Write(" \n"); +} + + +void wxWxr2Xml::ParseMenu(wxItemResource *res) +{ + wxItemResource *child; + wxNode *node = res->GetChildren().First(); + //Get Menu + m_xmlfile.Write(" GetValue1()<<"\""; + m_xmlfile.Write(menuname); + m_xmlfile.Write(">\n"); + m_xmlfile.Write(" \n"); + if (res->GetValue4()!="") + m_xmlfile.Write(" "+res->GetValue4()+"\n"); + m_xmlfile.Write(" \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(" \n"); +m_xmlfile.Write(" \n"); +} + +void wxWxr2Xml::ParseMenuItem(wxItemResource *res) +{ + //Get Menu Item or Separator +if (res->GetTitle()=="") + { + m_xmlfile.Write(" \n"); + } +else + { + m_xmlfile.Write(" GetValue1()<<"\""; + m_xmlfile.Write(menuname); + m_xmlfile.Write(">\n"); + m_xmlfile.Write(" \n"); + if (res->GetValue4()!="") + m_xmlfile.Write(" "+res->GetValue4()+"\n"); + if (res->GetValue2()) + m_xmlfile.Write(" 1\n"); + m_xmlfile.Write(" \n"); + } +} + +wxString wxWxr2Xml::FixMenuString(wxString phrase) +{ +phrase.Replace("&","$"); +return phrase; +} + +void wxWxr2Xml::ParseStaticBitmap(wxItemResource *res) +{ +m_xmlfile.Write(" GetValue4(); +wxBitmap bitmap; +bitmap= wxResourceCreateBitmap(bitmapname,&m_table); +bitmapname+=_T(".bmp"); +bitmap.SaveFile(bitmapname,wxBITMAP_TYPE_BMP); +m_xmlfile.Write("\n "+bitmapname+""); +m_xmlfile.Write("\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; + +} diff --git a/contrib/utils/convertrc/wxr2xml.h b/contrib/utils/convertrc/wxr2xml.h new file mode 100644 index 0000000000..3cebb8082f --- /dev/null +++ b/contrib/utils/convertrc/wxr2xml.h @@ -0,0 +1,67 @@ +// wxr2xml.h: +// 8/30/00 Brian Gavin +////////////////////////////////////////////////////////////////////// + +#if !defined(WXR2XML_H) +#define WXR2XML_H + +#include +#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