⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rc2xml.cpp

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// 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");*//* TODO1.  Figure how to fix memory leaks in all wxLists in this class2.  Find a way to rename MS Windows fonts so that they workcross platform (wxGTK,etc)3.  Be able to abort incorrectly formatted 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/deprecated/setup.h"#include "wx/deprecated/resource.h"#include "wx/textfile.h"#include "wx/tokenzr.h"//////////////////////////////////////////////////////////////////////// Construction/Destruction//////////////////////////////////////////////////////////////////////rc2xml::rc2xml(){    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);}rc2xml::~rc2xml(){    delete m_bitmaplist;    delete m_stringtable;    delete m_iconlist;    delete m_resourcelist;}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) + _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;/* Write Basic header for XML file */    m_xmlfile.Write(_T("<?xml version=\"1.0\" ?>\n"));    m_xmlfile.Write(_T("<resource>\n"));//Read resource.h    ParseResourceHeader();//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(_T("</resource>\n"));    m_xmlfile.Close();    m_rc.Close();    wxMessageBox(_("Conversion complete."), _("Done"),                            wxOK | wxICON_INFORMATION);return true;}void rc2xml::ParseDialog(wxString dlgname){    wxString token;    static int dlgid=999;    dlgid++;/* Make sure that this really is a dialogmicrosoft 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);//Get Title    token=GetToken();    wxString title;    wxString ptsize,face;    m_xmlfile.Write(_T("\t<object class=\"wxDialog\""));    //Avoid duplicate names this way    dlgname.Replace(_T("IDD_"),_T("DLG_"));    WriteBasicInfo(x,y,width,height,dlgname);    WriteTitle(title);    while ((token!=_T("BEGIN"))&(token!=_T("{")))    {        if (token==_T("CAPTION"))        {            title=GetQuoteField();        }//TODO fix face name so that it is cross platform name//  FONT 8, "MS Sans Serif"    if (token==_T("FONT"))    {        ptsize=GetToken();        face=GetQuoteField();        m_xmlfile.Write(_T("\t\t<font>\n"));        m_xmlfile.Write(_T("\t\t\t<size>")+ptsize+_T("</size>\n"));        m_xmlfile.Write(_T("\t\t\t<face>")+face+_T("</face>\n"));        m_xmlfile.Write(_T("\t\t</font>\n"));    }    token=GetToken();    }    ParseControls();    m_xmlfile.Write(_T("\t</object>\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_AUTOHSCROLLEND*/void rc2xml::ParseControls(){    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,8void rc2xml::ParseStaticText(wxString phrase, wxString varname){    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<object class=\"wxStaticText\""));    WriteBasicInfo(x,y,width,height,varname);WriteLabel(phrase);    m_xmlfile.Write(_T("\t\t</object>\n"));}//EDITTEXT        IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLLvoid rc2xml::ParseTextCtrl(wxString varname){    wxString token;    wxString style;    token=PeekToken();    while (!token.IsNumber())        {        token=GetToken();        token=PeekToken();        }    int x,y,width,height;    ReadRect(x,y,width,height);//TODO//style=GetToken();    m_xmlfile.Write(_T("\t\t<object class=\"wxTextCtrl\""));    WriteBasicInfo(x,y,width,height,varname);    m_xmlfile.Write(_T("\t\t</object>\n"));}//AUTOCHECKBOX "&log.", ID_XLOG, 25, 24, 21, 12void rc2xml::ParseCheckBox(wxString phrase, wxString varname){    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<object class=\"wxCheckBox\""));    WriteBasicInfo(x,y,width,height,varname);    WriteLabel(phrase);    m_xmlfile.Write(_T("\t\t</object>\n"));}//AUTORADIOBUTTON "&text", ID_SW10, 13, 12, 68, 10, BS_AUTORADIOBUTTON | WS_GROUPvoid rc2xml::ParseRadioButton(wxString phrase, wxString varname){    wxString token,style;    int x,y,width,height;    bool GotOrs;    GotOrs = ReadOrs(token);    if (ReadRect(x,y,width,height))        if (GotOrs==false)      ReadOrs(token);    if (token.Find(_T("WS_GROUP")) != wxNOT_FOUND)        style += _T("wxRB_GROUP");    m_xmlfile.Write(_T("\t\t<object class=\"wxRadioButton\""));    WriteBasicInfo(x,y,width,height,varname);    WriteLabel(phrase);    WriteStyle(style);    m_xmlfile.Write(_T("\t\t</object>\n"));}//PUSHBUTTON      "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOPvoid rc2xml::ParsePushButton(wxString phrase, wxString varname){    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<object class=\"wxButton\""));    WriteBasicInfo(x,y,width,height,varname);    WriteLabel(phrase);    m_xmlfile.Write(_T("\t\t</object>\n"));}bool rc2xml::Separator(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 rc2xml::ParseGroupBox(wxString phrase, wxString varname){//    GROUPBOX        "Rotate",IDC_STATIC,1,1,71,79    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<object class=\"wxStaticBox\""));    WriteBasicInfo(x,y,width,height,varname);    WriteLabel(phrase);    m_xmlfile.Write(_T("\t\t</object>\n"));}bool rc2xml::ReadRect(int & x, int & y, int & width, int & height){    x=wxAtoi(GetToken());    y=wxAtoi(GetToken());    width=wxAtoi(GetToken());    bool ret;    wxString tmp = GetToken(&ret);    height=wxAtoi(tmp);    return ret; // check for more parameters}wxString rc2xml::GetToken(bool *listseparator){    wxString token=wxEmptyString;    if (m_rc.Eof())    {    m_done=true;    return token;}    int ch=0;    ReadChar(ch);    if (ch==EOF)    {    m_done=true;    return token;    }    while (Separator(ch))    {    ReadChar(ch);    if (m_done)        return token;    }    if (ch==EOF)    {    m_done=true;    }    while (!Separator(ch))    {    token += (char)ch;    ReadChar(ch);    }    if (ch == EOF)        m_done = true;    if (listseparator)      *listseparator = (ch == ',');    return token;}wxString rc2xml::GetQuoteField(){    wxString phrase;    //ASCII code 34 "    int ch=0;    int ch1=0;    ReadChar(ch);    // !! Changed by MS, 15th/11/04. Can now read strings such as    // """Catapult"" - blah blah", ...    while (ch!=34)        ReadChar(ch);    // found first '"'    while (true)    {        ReadChar(ch);        if (ch == 34)        {            // another quote?            ReadChar(ch1);            if (ch1 != 34)            {                // real end of string..                break;            }            // add a single quote - fall through        }        phrase+=(char)ch;    }    return phrase;}// string in stringtable may contain embedded quotes// escape characters retained to allow strings to be rewrittenwxString rc2xml::GetStringQuote(){    wxString phrase;    //ASCII code 34 "    bool done=false;    int ch=0,lastch=0;    ReadChar(ch);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -