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

📄 wxr2xml.cpp

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// wxr2xml.cpp: implementation of the wxr2xml class.// 8/30/00  Brian Gavin// only tested on wxMSW so far// License: wxWindows Liscense// /////////////////////////////////////////////////////////////////////*How to use class:#include "wxr2xml.h"...wxr2xml trans;trans->Convert("Myfile.wxr","Myfile.xml");*/// 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// ////////////////////////////////////////////////////////////////////wxr2xml::wxr2xml(){}wxr2xml::~wxr2xml(){}bool wxr2xml::Convert(wxString wxrfile, wxString xmlfile){    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;    result = m_table.ParseResourceFile(wxrfile);    wxASSERT_MSG(result, _T("Couldn't Load WXR file"));    if (!result)        return false;    // Write basic xml header    m_xmlfile.Write(_T("<?xml version=\"1.0\" ?>\n"));    m_xmlfile.Write(_T("<resource>\n"));    result = ParseResources();    m_xmlfile.Write(_T("</resource>\n"));    m_xmlfile.Close();    return result;}bool wxr2xml::ParseResources(){    m_table.BeginFind();    wxHashTable::Node *node;    node = m_table.Next();    while (node)        {        wxItemResource *res = (wxItemResource *) node->GetData();        wxString resType(res->GetType());        if (resType == _T("wxDialog"))            ParseDialog(res);        else if (resType == _T("wxPanel"))            ParsePanel(res);        else if (resType == _T("wxPanel"))            ParsePanel(res);        else if (resType == _T("wxMenu"))            ParseMenuBar(res);        else if (resType == _T("wxBitmap"))            ParseBitmap(res);        else            wxLogError(_T("Found unsupported resource ") + resType);        node = m_table.Next();    }    return true;}void wxr2xml::ParsePanel(wxItemResource * res){    m_xmlfile.Write(_T("\t<object class=\"wxPanel\""));    PanelStuff(res);    WriteControlInfo(res);    m_xmlfile.Write(_T("\n"));    ParseControls(res);    m_xmlfile.Write(_T("\t</object>\n\n"));}void wxr2xml::ParseDialog(wxItemResource * res){    PanelStuff(res);    m_xmlfile.Write(_T("\t<object class=\"wxDialog\""));    WriteControlInfo(res);    m_xmlfile.Write(GetTitle(res));    m_xmlfile.Write(_T("\n"));    ParseControls(res);    m_xmlfile.Write(_T("\t</object>\n\n"));}void wxr2xml::ParseControls(wxItemResource * res){    wxNode *node = res->GetChildren().GetFirst();    while (node)        {        wxItemResource *res = (wxItemResource *) node->GetData();        wxString resType(res->GetType());        if (resType == _T("wxButton"))            ParseButton(res);        else if ((resType == _T("wxTextCtrl")) | (resType == _T("wxText"))         | (resType == _T("wxMultiText")))            ParseTextCtrl(res);        else if (resType == _T("wxCheckBox"))            ParseCheckBox(res);        else if (resType == _T("wxRadioBox"))            ParseRadioBox(res);        else if (resType == _T("wxListBox"))            ParseListBox(res);        else if ((resType == _T("wxStaticText")) | (resType == _T("wxMessage")))            ParseStaticText(res);        else if (resType == _T("wxChoice"))            ParseChoice(res);        else if (resType == _T("wxGauge"))           ParseGauge(res);        else if (resType == _T("wxSlider"))            ParseSlider(res);        else if (resType == _T("wxComboBox"))            ParseComboBox(res);        else if (resType == _T("wxRadioButton"))            ParseRadioButton(res);        else if (resType == _T("wxStaticBitmap"))            ParseStaticBitmap(res);        else if (resType == _T("wxScrollBar"))            ParseScrollBar(res);        else if ((resType == _T("wxStaticBox")) | (resType == _T("wxGroupBox")))            ParseStaticBox(res);        else if (resType == _T("wxBitmapButton"))            ParseBitmapButton(res);        else            wxLogError(_T("Found unsupported resource ") + resType);        node = node->GetNext();        }}// Write out basic stuff every control has// name,position,size,bg,fgvoid wxr2xml::WriteControlInfo(wxItemResource * res){    m_xmlfile.Write(GenerateName(res));    m_xmlfile.Write(_T(">\n"));    m_xmlfile.Write(GetPosition(res));    m_xmlfile.Write(GetSize(res));    m_xmlfile.Write(GetStyles(res));    WriteFontInfo(res);}wxString wxr2xml::GetSize(wxItemResource * res){    wxString msg;    if (m_dlgunits)        msg << _T("\t\t\t\t<size>") << res->GetWidth() << _T(",") << res->GetHeight() << _T("d</size>\n");    else        msg << _T("\t\t\t\t<size>") << res->GetWidth() << _T(",") << res->GetHeight() << _T("</size>\n");    return msg;}wxString wxr2xml::GetPosition(wxItemResource * res){    wxString msg;    if (m_dlgunits)        msg << _T("\t\t\t\t<pos>") << res->GetX() << _T(",") << res->GetY() << _T("d</pos>\n");    else        msg << _T("\t\t\t\t<pos>") << res->GetX() << _T(",") << res->GetY() << _T("</pos>\n");    return msg;}void wxr2xml::ParseButton(wxItemResource * res){    m_xmlfile.Write(_T("\t\t\t<object class=\"wxButton\""));    WriteControlInfo(res);    m_xmlfile.Write(GetLabel(res));    m_xmlfile.Write(_T("\t\t\t</object>\n"));}void wxr2xml::ParseTextCtrl(wxItemResource * res){    m_xmlfile.Write(_T("\t\t\t<object class=\"wxTextCtrl\""));    WriteControlInfo(res);    m_xmlfile.Write(GetValue4(res));    m_xmlfile.Write(_T("\t\t\t</object>\n"));}wxString wxr2xml::GetTitle(wxItemResource * res){    wxString msg;    msg = _T("\t\t\t\t<title>") + res->GetTitle() + _T("</title>");    return msg;}wxString wxr2xml::GetValue4(wxItemResource * res){    wxString msg;    msg = _T("\t\t\t\t<value>") + res->GetValue4() + _T("</value>\n");    return msg;}void wxr2xml::ParseCheckBox(wxItemResource * res){    m_xmlfile.Write(_T("\t\t\t<object class=\"wxCheckBox\""));    WriteControlInfo(res);    m_xmlfile.Write(GetLabel(res));    m_xmlfile.Write(GetCheckStatus(res));    m_xmlfile.Write(_T("\t\t\t</object>\n"));}wxString wxr2xml::GetLabel(wxItemResource * res){    return _T("\t\t\t\t<label>") + res->GetTitle() + _T("</label>\n");}void wxr2xml::ParseRadioBox(wxItemResource * res){    m_xmlfile.Write(_T("\t\t\t<object class=\"wxRadioBox\""));    WriteControlInfo(res);    m_xmlfile.Write(GetLabel(res));    // Add radio box items    WriteStringList(res);    // Value1    m_xmlfile.Write(GetDimension(res));    m_xmlfile.Write(_T("\t\t\t</object>\n"));}void wxr2xml::ParseListBox(wxItemResource * res){    m_xmlfile.Write(_T("\t\t\t<object class=\"wxListBox\""));    WriteControlInfo(res);    WriteStringList(res);    m_xmlfile.Write(_T("\t\t\t</object>\n"));}void wxr2xml::ParseStaticText(wxItemResource * res){    m_xmlfile.Write(_T("\t\t\t<object class=\"wxStaticText\""));    WriteControlInfo(res);    m_xmlfile.Write(GetLabel(res));    m_xmlfile.Write(_T("\t\t\t</object>\n"));}void wxr2xml::ParseStaticBox(wxItemResource * res){    m_xmlfile.Write(_T("\t\t\t<object class=\"wxStaticBox\""));    WriteControlInfo(res);    m_xmlfile.Write(GetLabel(res));    m_xmlfile.Write(_T("\t\t\t</object>\n"));}void wxr2xml::WriteStringList(wxItemResource * res){    m_xmlfile.Write(_T("\t\t\t\t<content>\n"));    for (wxStringListNode * node = res->GetStringValues().GetFirst();        node;node = node->GetNext()) {        const wxString s1 = node->GetData();        m_xmlfile.Write(_T("\t\t\t\t\t<item>") + s1 + _T("</item>\n"));    }    m_xmlfile.Write(_T("\t\t\t\t</content>\n"));}void wxr2xml::ParseChoice(wxItemResource * res){    m_xmlfile.Write(_T("\t\t\t<object class=\"wxChoice\""));    WriteControlInfo(res);    // Add choice items    WriteStringList(res);    m_xmlfile.Write(_T("\t\t\t</object>\n"));}void wxr2xml::ParseGauge(wxItemResource * res){    m_xmlfile.Write(_T("\t\t\t<object class=\"wxGauge\""));    WriteControlInfo(res);    m_xmlfile.Write(GetValue1(res));    m_xmlfile.Write(GetRange(res));    m_xmlfile.Write(_T("\n\t\t\t</object>\n"));}wxString wxr2xml::GetValue1(wxItemResource * res){    wxString msg;    msg << _T("\t\t\t\t<value>") << res->GetValue1() << _T("</value>\n");    return msg;}wxString wxr2xml::GetRange(wxItemResource * res){    wxString msg;    msg << _T("\t\t\t\t<range>") << res->GetValue2() << _T("</range>");    return msg;}void wxr2xml::ParseSlider(wxItemResource * res){    m_xmlfile.Write(_T("\t\t\t<object class=\"wxSlider\""));    WriteControlInfo(res);    m_xmlfile.Write(GetValue1(res));    m_xmlfile.Write(GetMax(res));    m_xmlfile.Write(GetMin(res));    m_xmlfile.Write(_T("\n\t\t\t</object>\n"));}wxString wxr2xml::GetMax(wxItemResource * res){    wxString msg;    msg << _T("\t\t\t\t<max>") << res->GetValue3() << _T("</max>\n");    return msg;}wxString wxr2xml::GetMin(wxItemResource * res){    wxString msg;    msg << _T("\t\t\t\t<min>") << res->GetValue2() << _T("</min>");    return msg;}void wxr2xml::ParseComboBox(wxItemResource * res){    m_xmlfile.Write(_T("\t\t\t<object class=\"wxComboBox\""));    WriteControlInfo(res);    // Add combo items    WriteStringList(res);    m_xmlfile.Write(_T("\n\t\t\t</object>\n"));}void wxr2xml::ParseRadioButton(wxItemResource * res){    m_xmlfile.Write(_T("\t\t\t<object class=\"wxRadioButton\""));    WriteControlInfo(res);    m_xmlfile.Write(GetLabel(res));    wxString msg;    m_xmlfile.Write(GetValue1(res));    m_xmlfile.Write(GetCheckStatus(res));    m_xmlfile.Write(_T("\t\t\t</object>\n"));}void wxr2xml::ParseScrollBar(wxItemResource * res){    m_xmlfile.Write(_T("\t\t\t<object class=\"wxScrollBar\""));    WriteControlInfo(res);    m_xmlfile.Write(GetValue1(res));    m_xmlfile.Write(_T("\t\t\t\t<thumbsize>")+GetValue2(res)+_T("</thumbsize>\n"));    m_xmlfile.Write(_T("\t\t\t\t<range>")+GetValue3(res)+_T("</range>\n"));    m_xmlfile.Write(_T("\t\t\t\t<pagesize>")+GetValue5(res)+_T("</pagesize>\n"));    m_xmlfile.Write(_T("\t\t\t</object>\n"));}wxString wxr2xml::GetCheckStatus(wxItemResource * res){    wxString msg;    msg << _T("\t\t\t\t<checked>") << res->GetValue1() << _T("</checked>\n");    return msg;}wxString wxr2xml::GetStyles(wxItemResource * res){    // Very crude way to get styles    long style;    wxString s, restype;    restype = res->GetType();    style = res->GetStyle();    s = _T("\t\t\t\t<style>");    // Common styles for all controls    if (style & wxSIMPLE_BORDER)        s += _T("wxSIMPLE_BORDER|");    if (style & wxSUNKEN_BORDER)        s += _T("wxSUNKEN_BORDER|");    if (style & wxSIMPLE_BORDER)        s += _T("wxSIMPLE_BORDER|");    if (style & wxDOUBLE_BORDER)        s += _T("wxDOUBLE_BORDER|");    if (style & wxRAISED_BORDER)        s += _T("wxRAISED_BORDER|");    if (style & wxTRANSPARENT_WINDOW)        s += _T("wxTRANSPARENT_WINDOW|");    if (style & wxWANTS_CHARS)        s += _T("wxWANTS_CHARS|");    if (style & wxNO_FULL_REPAINT_ON_RESIZE)        s += _T("wxNO_FULL_REPAINT_ON_RESIZE|");    if (restype == _T("wxDialog"))        {        if (style & wxDEFAULT_DIALOG_STYLE)            s += _T("wxDEFAULT_DIALOG_STYLE|");#if WXWIN_COMPATIBILITY_2_6        if (style & wxDIALOG_MODAL)            s += _T("wxDIALOG_MODAL|");        if (style & wxDIALOG_MODELESS)            s += _T("wxDIALOG_MODELESS|");        if (style & wxNO_3D)            s += _T("wxNO_3D|");#endif // WXWIN_COMPATIBILITY_2_6        if (style & wxTAB_TRAVERSAL)            s += _T("wxTAB_TRAVERSAL|");        if (style & wxWS_EX_VALIDATE_RECURSIVELY)

⌨️ 快捷键说明

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