📄 rc2xml.cpp
字号:
while (ch!=34)
ReadChar(ch);
ReadChar(ch);
while (done==false)
{
if ((ch==34)&&(lastch!='\\'))
{
wxFileOffset p = m_rc.Tell();
ReadChar(ch);
// RC supports "", for embedded quote, as well as \"
if (ch==34)
phrase+='\\';
else
{
m_rc.Seek(p);
done = true;
}
}
if (done==true)
break;
if (ch=='\r')
ReadChar(ch); // skip
if ((ch=='\n')&&(lastch=='\\')) // lastch <should> be this
phrase+='n'; // escape
else
phrase+=(char)ch;
lastch=ch;
ReadChar(ch);
}
return phrase;
}
void rc2xml::ReadChar(int &ch)
{
wxFileOffset result = m_rc.Tell();
if((result>=m_filesize))
m_done=true;
result = m_rc.Read(&ch,1);
if( result == wxInvalidOffset )
m_done=true;
if(ch==EOF)
m_done=true;
}
void rc2xml::ParseComboBox(wxString varname)
{
/* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
WS_VSCROLL | WS_TABSTOP */
wxString token,style;
int x,y,width,height;
bool GotOrs;
GotOrs = ReadOrs(token);
if (ReadRect(x,y,width,height))
if (GotOrs==false)
ReadOrs(token);
m_xmlfile.Write(_T("\t\t<object class=\"wxComboBox\""));
WriteBasicInfo(x,y,width,height,varname);
if (token.Find(_T("CBS_SIMPLE")) != wxNOT_FOUND)
WriteStyle(_T("wxCB_SIMPLE"));
if (token.Find(_T("CBS_SORT")) != wxNOT_FOUND)
WriteStyle(_T("wxCB_SORT"));
if (token.Find(_T("CBS_DISABLENOSCROLL")) != wxNOT_FOUND)
WriteStyle(_T("wxLB_ALWAYS_SB"));
m_xmlfile.Write(_T("\n\t\t</object>\n"));
}
void rc2xml::ParseMenu(wxString varname)
{
wxString token=wxEmptyString;
//Write menubar to xml file
m_xmlfile.Write(_T("\t<object class=\"wxMenuBar\""));
//Avoid duplicate names this way
varname.Replace(_T("IDR_"),_T("MB_"));
WriteName(varname);
m_xmlfile.Write(_T(">\n"));
while ((token!=_T("BEGIN"))&(token!=_T("{")))
token=GetToken();
while ((token!=_T("END"))&(token!=_T("}")))
{
token=GetToken();
token.MakeUpper();
if (token==_T("POPUP"))
{
ParsePopupMenu();
}
}
m_xmlfile.Write(_T("\t</object>\n"));
}
void rc2xml::ParsePopupMenu()
{
static int menucount=0;
menucount++;
wxString token,name,msg,longhelp,tip;
token=GetQuoteField();
//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 << _T("Menu_") << menucount;
m_xmlfile.Write(_T("\t\t<object class=\"wxMenu\""));
WriteName(name);
m_xmlfile.Write(_T(">\n"));
WriteLabel(token);
while ((token!=_T("BEGIN"))&(token!=_T("{")))
token=GetToken();
while ((token!=_T("END"))&(token!=_T("}")))
{
token=GetToken();
token.MakeUpper();
if (token==_T("POPUP"))
ParsePopupMenu();
if (token==_T("MENUITEM"))
ParseMenuItem();
}
m_xmlfile.Write(_T("\t\t\t</object>\n"));
}
wxString rc2xml::PeekToken()
{
wxFileOffset p = m_rc.Tell();
wxString token=GetToken();
m_rc.Seek(p);
return token;
}
//MS Windows pain in the butt CONTROL
void rc2xml::ParseControlMS()
{
wxString token = PeekToken();
if (token.Contains(_T("\"")))
ParseNormalMSControl();
else
ParseWeirdMSControl();
}
/* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
TBS_NOTICKS | WS_TABSTOP,52,73,100,15
*/
void rc2xml::ParseSlider(wxString WXUNUSED(label), wxString varname)
{
wxString token,style;
ReadOrs(token);
if (token.Find(_T("TBS_VERT"))!=wxNOT_FOUND)
style+=_T("wxSL_VERTICAL");
//MFC RC Default is horizontal
else
style+=_T("wxSL_HORIZONTAL");
int x,y,width,height;
ReadRect(x,y,width,height);
m_xmlfile.Write(_T("\t\t<object class=\"wxSlider\""));
WriteBasicInfo(x,y,width,height,varname);
WriteStyle(style);
m_xmlfile.Write(_T("\n\t\t</object>\n"));
}
/*
CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
WS_BORDER,15,52,154,13
*/
void rc2xml::ParseProgressBar(wxString WXUNUSED(label), wxString varname)
{
wxString token,style;
ReadOrs(token);
int x,y,width,height;
ReadRect(x,y,width,height);
//Always horizontal in MFC
m_xmlfile.Write(_T("\t\t<object class=\"wxGauge\""));
WriteBasicInfo(x,y,width,height,varname);
WriteStyle(style);
m_xmlfile.Write(_T("\t\t</object>\n"));
}
bool rc2xml::ReadOrs(wxString & orstring)
{
wxString token;
token=PeekToken();
if (token.IsNumber())
return false;
orstring=GetToken();
while(PeekToken()==_T("|"))
{
//Grab |
orstring+=GetToken();
//Grab next token
orstring+=GetToken();
}
return true;
}
//Is it a checkbutton or a radiobutton or a pushbutton or a groupbox
void rc2xml::ParseCtrlButton(wxString label, wxString varname)
{
wxString token;
wxFileOffset p = m_rc.Tell();
ReadOrs(token);
m_rc.Seek(p);
if (token.Find(_T("BS_AUTOCHECKBOX"))!=wxNOT_FOUND)
ParseCheckBox(label, varname);
else if ((token.Find(_T("BS_AUTORADIOBUTTON"))!=wxNOT_FOUND)||
(token.Find(_T("BS_RADIOBUTTON"))!=wxNOT_FOUND))
ParseRadioButton(label, varname);
else if (token.Find(_T("BS_GROUPBOX"))!=wxNOT_FOUND)
ParseGroupBox(label, varname);
else // if ((token.Find("BS_PUSHBUTTON")!=wxNOT_FOUND)||
// (token.Find("BS_DEFPUSHBUTTON")!=wxNOT_FOUND))
ParsePushButton(label, varname); // make default case
}
void rc2xml::WriteSize(int width, int height)
{
wxString msg;
msg << _T(" <size>") << width << _T(",") << height << _T("d</size>");
m_xmlfile.Write(msg);
}
void rc2xml::WritePosition(int x, int y)
{
wxString msg;
msg << _T(" <pos>") << x << _T(",") << y << _T("d</pos>");
m_xmlfile.Write(msg);
}
void rc2xml::WriteTitle(wxString title)
{
wxString msg;
msg=_T("\t\t<title>")+title+_T("</title>\n");
m_xmlfile.Write(msg);
}
void rc2xml::WriteName(wxString name)
{
//Try to convert any number ids into names
name=LookUpId(name);
//Replace common MS ids with wxWidgets ids
//I didn't do everyone of them
if (name==_T("IDOK"))
name=_T("wxID_OK");
else if (name==_T("IDCANCEL"))
name=_T("wxID_CANCEL");
else if (name==_T("IDAPPLY"))
name=_T("wxID_APPLY");
else if (name==_T("ID_FILE_OPEN"))
name=_T("wxID_OPEN");
else if (name==_T("ID_FILE_CLOSE"))
name=_T("wxID_CLOSE");
else if (name==_T("ID_FILE_SAVE"))
name=_T("wxID_SAVE");
else if (name==_T("ID_FILE_SAVE_AS"))
name=_T("wxID_SAVEAS");
else if (name==_T("ID_APP_EXIT"))
name=_T("wxID_EXIT");
else if (name==_T("ID_FILE_PRINT"))
name=_T("wxID_PRINT");
else if (name==_T("ID_FILE_PRINT_PREVIEW"))
name=_T("wxID_PREVIEW");
else if (name==_T("ID_FILE_PRINT_SETUP"))
name=_T("wxID_PRINT_SETUP");
else if (name==_T("ID_APP_ABOUT"))
name=_T("wxID_ABOUT");
else if (name==_T("ID_EDIT_UNDO"))
name=_T("wxID_UNDO");
else if (name==_T("ID_EDIT_CUT"))
name=_T("wxID_CUT");
else if (name==_T("ID_EDIT_COPY"))
name=_T("wxID_COPY");
else if (name==_T("ID_EDIT_PASTE"))
name=_T("wxID_PASTE");
else if (name==_T("IDYES"))
name=_T("wxID_YES");
else if (name==_T("IDNO"))
name=_T("wxID_NO");
else if (name==_T("IDHELP"))
name=_T("wxID_HELP");
m_xmlfile.Write(_T(" name= \"")+name+_T("\""));
}
void rc2xml::WriteLabel(wxString label)
{
label.Replace(_T("&"),_T("$"));
// changes by MS, handle '<' '>' characters within a label.
label.Replace(_T("<"),_T("<"));
label.Replace(_T(">"),_T(">"));
m_xmlfile.Write(_T("\t\t\t<label>")+label+_T("</label>\n"));
}
void rc2xml::WriteBasicInfo(int x, int y, int width, int height, wxString name)
{
WriteName(name);
m_xmlfile.Write(_T(">\n"));
m_xmlfile.Write(_T("\t\t\t"));
WritePosition(x,y);
WriteSize(width,height);
m_xmlfile.Write(_T("\n"));
}
void rc2xml::WriteStyle(wxString style)
{
if (style.Length()==0)
return;
m_xmlfile.Write(_T("\t\t\t<style>")+style+_T("</style>\n"));
}
/*
LISTBOX IDC_LIST1,16,89,48,40,LBS_SORT | LBS_MULTIPLESEL |
LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
*/
void rc2xml::ParseListBox(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=\"wxListBox\""));
WriteBasicInfo(x,y,width,height,varname);
m_xmlfile.Write(_T("\n\t\t</object>\n"));
}
/*
CONTROL "",IDC_RICHEDIT1,"RICHEDIT",ES_AUTOHSCROLL | WS_BORDER |
WS_TABSTOP,103,110,40,14
*/
void rc2xml::ParseRichEdit(wxString WXUNUSED(label), wxString varname)
{
wxString token;
//while (ReadOrs(token));
ReadOrs(token);
int x,y,width,height;
ReadRect(x,y,width,height);
wxString style;
//Make it a rich text control
style+=_T("wxTE_MULTILINE ");
m_xmlfile.Write(_T("\t\t<object class=\"wxTextCtrl\""));
WriteBasicInfo(x,y,width,height,varname);
WriteStyle(style);
m_xmlfile.Write(_T("\t\t</object>\n"));
}
/*
CONTROL "Spin1",IDC_SPIN1,"msctls_updown32",UDS_ARROWKEYS,209,72,
19,26
*/
void rc2xml::ParseSpinCtrl(wxString WXUNUSED(label), wxString varname)
{
wxString token,style;
ReadOrs(token);
if (token.Find(_T("UDS_HORZ"))!=wxNOT_FOUND)
style=_T("wxSP_HORIZONTAL");
//MFC default
else
style=_T("wxSP_VERTICAL");
int x,y,width,height;
ReadRect(x,y,width,height);
m_xmlfile.Write(_T("\t\t<object class=\"wxSpinButton\""));
WriteBasicInfo(x,y,width,height,varname);
WriteStyle(style);
m_xmlfile.Write(_T("\n\t\t</object>\n"));
}
void rc2xml::FirstPass()
{
wxString token,prevtok;
while (!m_done)
{
token=GetToken();
if (token==_T("BITMAP"))
ParseBitmap(prevtok);
else if (token==_T("STRINGTABLE"))
ParseStringTable(prevtok);
else if (token==_T("ICON"))
ParseIcon(prevtok);
prevtok=token;
}
}
void rc2xml::ParseBitmap(wxString varname)
{
wxString token;
wxString *bitmapfile;
token=PeekToken();
//Microsoft notation?
if (token==_T("DISCARDABLE"))
{
token=GetToken();
token=PeekToken();
}
bitmapfile=new wxString;
*bitmapfile=GetQuoteField();
m_bitmaplist->Append(varname,bitmapfile);
}
void rc2xml::SecondPass()
{
wxString token,prevtok;
while (!m_done)
{
token=GetToken();
if ((token==_T("DIALOG"))||(token==_T("DIALOGEX")))
ParseDialog(prevtok);
else if (token==_T("MENU"))
ParseMenu(prevtok);
else if (token==_T("TOOLBAR"))
ParseToolBar(prevtok);
prevtok=token;
}
}
void rc2xml::ParseToolBar(wxString varname)
{
wxString token;
token=GetToken();
wxASSERT_MSG(token==_T("DISCARDABLE"),_T("Error in toolbar parsing"));
//Look up bitmap for toolbar and load
wxNode *node=m_bitmaplist->Find(LookUpId(varname));
wxString *bitmappath;
bitmappath=(wxString *)node->GetData();
wxBitmap bitmap;
if (!bitmap.LoadFile(*bitmappath,wxBITMAP_TYPE_BMP ))
wxLogError(_T("Unable to load bitmap:")+*bitmappath);
//Write toolbar to xml file
m_xmlfile.Write(_T("\t<object class=\"wxToolBar\""));
//Avoid duplicate names this way
varname.Replace(_T("IDR_"),_T("TB_"));
WriteName(varname);
m_xmlfile.Write(_T(">\n"));
wxString style;
style+=_T("wxTB_FLAT");
WriteStyle(style);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -