]>
git.saurik.com Git - wxWidgets.git/blob - contrib/utils/convertrc/rc2xml.cpp
1 // rc2xml.cpp: implementation of the rc2xml class.
2 //Author: Brian Gavin 9/24/00
3 //License: wxWindows License
9 trans->Convert("Myfile.rc","Myfile.xml");
12 1. Figure how to fix memory leaks in all wxLists in this class
13 2. Find a way to rename MS Windows fonts so that they work
14 cross platform (wxGTK,etc)
15 3. Be able to abort incorrectly formated files without crashing
19 #pragma implementation "rc2xml.cpp"
20 #pragma interface "rc2xml.cpp"
23 // For compilers that support precompilation, includes "wx/wx.h".
24 #include "wx/wxprec.h"
30 // for all others, include the necessary headers (this file is usually all you
31 // need because it includes almost all "standard" wxWidgets headers
39 #include "wx/deprecated/setup.h"
40 #include "wx/deprecated/resource.h"
41 #include <wx/textfile.h>
42 #include <wx/tokenzr.h>
46 //////////////////////////////////////////////////////////////////////
47 // Construction/Destruction
48 //////////////////////////////////////////////////////////////////////
53 m_bitmaplist
=new wxList(wxKEY_STRING
);
54 m_stringtable
=new wxList(wxKEY_STRING
);
55 m_iconlist
= new wxList(wxKEY_STRING
);
56 m_resourcelist
=new wxList(wxKEY_INTEGER
);
64 delete m_resourcelist
;
67 bool rc2xml::Convert(wxString rcfile
, wxString xmlfile
)
69 m_rc
.Open(rcfile
.c_str());
70 m_filesize
=m_rc
.Length();
73 m_workingpath
=wxPathOnly(rcfile
);
75 m_targetpath
=wxPathOnly(xmlfile
) + _T("\\");
79 wxSetWorkingDirectory(m_workingpath
);
83 result
=m_xmlfile
.Open(xmlfile
.c_str(),_T("w+t"));
84 wxASSERT_MSG(result
,_T("Couldn't create XML file"));
89 /* Write Basic header for XML file */
90 m_xmlfile
.Write(_T("<?xml version=\"1.0\" ?>\n"));
91 m_xmlfile
.Write(_T("<resource>\n"));
94 ParseResourceHeader();
95 //Gather all the resource we need for toolbars,menus, and etc
99 //Read in dialogs, toolbars,menus
102 m_xmlfile
.Write(_T("</resource>\n"));
105 wxMessageBox(_("Conversion complete."), _("Done"),
106 wxOK
| wxICON_INFORMATION
);
112 void rc2xml::ParseDialog(wxString dlgname
)
115 static int dlgid
=999;
117 /* Make sure that this really is a dialog
118 microsoft reuses the keyword DIALOG for other things
121 //Microsoft notation?
122 while ((token
==_T("DISCARDABLE"))
123 ||(token
==_T("LOADONCALL"))||(token
==_T("MOVEABLE")))
128 //Error isn't a Dialog resource eject eject
129 if (!token
.IsNumber())
132 //Record x,y,width,height
133 int x
,y
,width
,height
;
134 ReadRect(x
,y
,width
,height
);
138 wxString ptsize
,face
;
140 m_xmlfile
.Write(_T("\t<object class=\"wxDialog\""));
141 //Avoid duplicate names this way
142 dlgname
.Replace(_T("IDD_"),_T("DLG_"));
143 WriteBasicInfo(x
,y
,width
,height
,dlgname
);
147 while ((token
!=_T("BEGIN"))&(token
!=_T("{")))
149 if (token
==_T("CAPTION"))
151 title
=GetQuoteField();
154 //TODO fix face name so that it is cross platform name
155 // FONT 8, "MS Sans Serif"
156 if (token
==_T("FONT"))
159 face
=GetQuoteField();
160 m_xmlfile
.Write(_T("\t\t<font>\n"));
161 m_xmlfile
.Write(_T("\t\t\t<size>")+ptsize
+_T("</size>\n"));
162 m_xmlfile
.Write(_T("\t\t\t<face>")+face
+_T("</face>\n"));
163 m_xmlfile
.Write(_T("\t\t</font>\n"));
170 m_xmlfile
.Write(_T("\t</object>\n"));
175 EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT
177 LTEXT "Bands",IDC_STATIC,11,86,21,8
178 EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL
181 void rc2xml::ParseControls()
184 wxString label
,varname
;
187 while ((token
!=_T("END"))&(token
!=_T("}")))
189 if (token
==_T("AUTOCHECKBOX"))
191 label
=GetQuoteField();
193 ParseCheckBox(label
,varname
);
196 if (token
==_T("AUTORADIOBUTTON"))
198 label
=GetQuoteField();
200 ParseRadioButton(label
,varname
);
203 if (token
==_T("LTEXT"))
205 label
=GetQuoteField();
207 ParseStaticText(label
,varname
);
209 else if (token
==_T("EDITTEXT"))
212 ParseTextCtrl(varname
);
214 else if ((token
==_T("PUSHBUTTON"))||(token
==_T("DEFPUSHBUTTON")))
216 label
=GetQuoteField();
218 ParsePushButton(label
,varname
);
220 else if (token
==_T("GROUPBOX"))
222 label
=GetQuoteField();
224 ParseGroupBox(label
,varname
);
226 else if (token
==_T("COMBOBOX"))
229 ParseComboBox(varname
);
231 else if (token
==_T("CONTROL"))
233 else if (token
==_T("LISTBOX"))
236 ParseListBox(varname
);
238 else if (token
==_T("ICON"))
240 else if (token
==_T("SCROLLBAR"))
246 //LTEXT "Radius",IDC_STATIC,9,67,23,8
247 void rc2xml::ParseStaticText(wxString phrase
, wxString varname
)
251 while (!token
.IsNumber())
256 int x
,y
,width
,height
;
257 ReadRect(x
,y
,width
,height
);
259 m_xmlfile
.Write(_T("\t\t<object class=\"wxStaticText\""));
260 WriteBasicInfo(x
,y
,width
,height
,varname
);WriteLabel(phrase
);
261 m_xmlfile
.Write(_T("\t\t</object>\n"));
264 //EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
265 void rc2xml::ParseTextCtrl(wxString varname
)
270 while (!token
.IsNumber())
275 int x
,y
,width
,height
;
276 ReadRect(x
,y
,width
,height
);
279 m_xmlfile
.Write(_T("\t\t<object class=\"wxTextCtrl\""));
280 WriteBasicInfo(x
,y
,width
,height
,varname
);
281 m_xmlfile
.Write(_T("\t\t</object>\n"));
284 //AUTOCHECKBOX "&log.", ID_XLOG, 25, 24, 21, 12
285 void rc2xml::ParseCheckBox(wxString phrase
, wxString varname
)
289 while (!token
.IsNumber())
294 int x
,y
,width
,height
;
295 ReadRect(x
,y
,width
,height
);
297 m_xmlfile
.Write(_T("\t\t<object class=\"wxCheckBox\""));
298 WriteBasicInfo(x
,y
,width
,height
,varname
);
300 m_xmlfile
.Write(_T("\t\t</object>\n"));
303 //AUTORADIOBUTTON "&text", ID_SW10, 13, 12, 68, 10, BS_AUTORADIOBUTTON | WS_GROUP
304 void rc2xml::ParseRadioButton(wxString phrase
, wxString varname
)
306 wxString token
,style
;
307 int x
,y
,width
,height
;
309 GotOrs
= ReadOrs(token
);
310 if (ReadRect(x
,y
,width
,height
))
313 if (token
.Find(_T("WS_GROUP")) != wxNOT_FOUND
)
314 style
+= _T("wxRB_GROUP");
316 m_xmlfile
.Write(_T("\t\t<object class=\"wxRadioButton\""));
317 WriteBasicInfo(x
,y
,width
,height
,varname
);
320 m_xmlfile
.Write(_T("\t\t</object>\n"));
324 //PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
325 void rc2xml::ParsePushButton(wxString phrase
, wxString varname
)
330 while (!token
.IsNumber())
335 int x
,y
,width
,height
;
336 ReadRect(x
,y
,width
,height
);
338 m_xmlfile
.Write(_T("\t\t<object class=\"wxButton\""));
339 WriteBasicInfo(x
,y
,width
,height
,varname
);
341 m_xmlfile
.Write(_T("\t\t</object>\n"));
346 bool rc2xml::Seperator(int ch
)
348 //if ((ch==' ')|(ch==',')|(ch==13)|(ch==10)|(ch=='|')|(ch=='\t'))
349 if ((ch
==' ')|(ch
==',')|(ch
==13)|(ch
==10)|(ch
=='\t'))
361 void rc2xml::ParseGroupBox(wxString phrase
, wxString varname
)
363 // GROUPBOX "Rotate",IDC_STATIC,1,1,71,79
366 while (!token
.IsNumber())
371 int x
,y
,width
,height
;
372 ReadRect(x
,y
,width
,height
);
374 m_xmlfile
.Write(_T("\t\t<object class=\"wxStaticBox\""));
375 WriteBasicInfo(x
,y
,width
,height
,varname
);
377 m_xmlfile
.Write(_T("\t\t</object>\n"));
380 bool rc2xml::ReadRect(int & x
, int & y
, int & width
, int & height
)
382 x
=wxAtoi(GetToken());
383 y
=wxAtoi(GetToken());
384 width
=wxAtoi(GetToken());
386 wxString tmp
= GetToken(&ret
);
388 return ret
; // check for more parameters
391 wxString
rc2xml::GetToken(bool *listseperator
)
393 wxString token
=wxEmptyString
;
409 while (Seperator(ch
))
422 while (!Seperator(ch
))
432 *listseperator
= (ch
== ',');
436 wxString
rc2xml::GetQuoteField()
445 // !! Changed by MS, 15th/11/04. Can now read strings such as
446 // """Catapult"" - blah blah", ...
461 // real end of string..
465 // add a single quote - fall through
473 // string in stringtable may contain embedded quotes
474 // escape characters retained to allow strings to be rewritten
475 wxString
rc2xml::GetStringQuote()
488 if ((ch
==34)&&(lastch
!='\\'))
492 // RC supports "", for embedded quote, as well as \"
504 ReadChar(ch
); // skip
505 if ((ch
=='\n')&&(lastch
=='\\')) // lastch <should> be this
506 phrase
+='n'; // escape
516 void rc2xml::ReadChar(int &ch
)
521 if((result
>=m_filesize
))
524 result
=m_rc
.Read(&ch
,1);
533 void rc2xml::ParseComboBox(wxString varname
)
535 /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
536 WS_VSCROLL | WS_TABSTOP */
537 wxString token
,style
;
538 int x
,y
,width
,height
;
540 GotOrs
= ReadOrs(token
);
541 if (ReadRect(x
,y
,width
,height
))
545 m_xmlfile
.Write(_T("\t\t<object class=\"wxComboBox\""));
546 WriteBasicInfo(x
,y
,width
,height
,varname
);
547 if (token
.Find(_T("CBS_SIMPLE")) != wxNOT_FOUND
)
548 WriteStyle(_T("wxCB_SIMPLE"));
549 if (token
.Find(_T("CBS_SORT")) != wxNOT_FOUND
)
550 WriteStyle(_T("wxCB_SORT"));
551 if (token
.Find(_T("CBS_DISABLENOSCROLL")) != wxNOT_FOUND
)
552 WriteStyle(_T("wxLB_ALWAYS_SB"));
553 m_xmlfile
.Write(_T("\n\t\t</object>\n"));
557 void rc2xml::ParseMenu(wxString varname
)
559 wxString token
=wxEmptyString
;
561 //Write menubar to xml file
562 m_xmlfile
.Write(_T("\t<object class=\"wxMenuBar\""));
563 //Avoid duplicate names this way
564 varname
.Replace(_T("IDR_"),_T("MB_"));
566 m_xmlfile
.Write(_T(">\n"));
568 while ((token
!=_T("BEGIN"))&(token
!=_T("{")))
571 while ((token
!=_T("END"))&(token
!=_T("}")))
576 if (token
==_T("POPUP"))
581 m_xmlfile
.Write(_T("\t</object>\n"));
584 void rc2xml::ParsePopupMenu()
586 static int menucount
=0;
588 wxString token
,name
,msg
,longhelp
,tip
;
589 token
=GetQuoteField();
591 //Remove \t because it causes problems
593 //spot=token.First("\\t");
594 //token=token.Left(spot);
597 //Generate a fake name since RC menus don't have one
598 name
<< _T("Menu_") << menucount
;
599 m_xmlfile
.Write(_T("\t\t<object class=\"wxMenu\""));
601 m_xmlfile
.Write(_T(">\n"));
604 while ((token
!=_T("BEGIN"))&(token
!=_T("{")))
607 while ((token
!=_T("END"))&(token
!=_T("}")))
612 if (token
==_T("POPUP"))
615 if (token
==_T("MENUITEM"))
618 m_xmlfile
.Write(_T("\t\t\t</object>\n"));
621 wxString
rc2xml::PeekToken()
631 //MS Windows pain in the butt CONTROL
632 void rc2xml::ParseControlMS()
634 wxString label
,varname
,kindctrl
,token
;
637 if (token
.Contains(_T("\"")))
638 ParseNormalMSControl();
640 ParseWeirdMSControl();
644 /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
645 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
648 void rc2xml::ParseSlider(wxString
WXUNUSED(label
), wxString varname
)
650 wxString token
,style
;
652 if (token
.Find(_T("TBS_VERT"))!=wxNOT_FOUND
)
653 style
+=_T("wxSL_VERTICAL");
654 //MFC RC Default is horizontal
656 style
+=_T("wxSL_HORIZONTAL");
658 int x
,y
,width
,height
;
659 ReadRect(x
,y
,width
,height
);
660 m_xmlfile
.Write(_T("\t\t<object class=\"wxSlider\""));
661 WriteBasicInfo(x
,y
,width
,height
,varname
);
663 m_xmlfile
.Write(_T("\n\t\t</object>\n"));
667 CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
668 WS_BORDER,15,52,154,13
670 void rc2xml::ParseProgressBar(wxString
WXUNUSED(label
), wxString varname
)
672 wxString token
,style
;
675 int x
,y
,width
,height
;
676 ReadRect(x
,y
,width
,height
);
678 //Always horizontal in MFC
679 m_xmlfile
.Write(_T("\t\t<object class=\"wxGauge\""));
680 WriteBasicInfo(x
,y
,width
,height
,varname
);
682 m_xmlfile
.Write(_T("\t\t</object>\n"));
685 bool rc2xml::ReadOrs(wxString
& orstring
)
690 if (token
.IsNumber())
694 while(PeekToken()==_T("|"))
697 orstring
+=GetToken();
699 orstring
+=GetToken();
704 //Is it a checkbutton or a radiobutton or a pushbutton or a groupbox
705 void rc2xml::ParseCtrlButton(wxString label
, wxString varname
)
713 if (token
.Find(_T("BS_AUTOCHECKBOX"))!=wxNOT_FOUND
)
714 ParseCheckBox(label
, varname
);
715 else if ((token
.Find(_T("BS_AUTORADIOBUTTON"))!=wxNOT_FOUND
)||
716 (token
.Find(_T("BS_RADIOBUTTON"))!=wxNOT_FOUND
))
717 ParseRadioButton(label
, varname
);
718 else if (token
.Find(_T("BS_GROUPBOX"))!=wxNOT_FOUND
)
719 ParseGroupBox(label
, varname
);
720 else // if ((token.Find("BS_PUSHBUTTON")!=wxNOT_FOUND)||
721 // (token.Find("BS_DEFPUSHBUTTON")!=wxNOT_FOUND))
722 ParsePushButton(label
, varname
); // make default case
725 void rc2xml::WriteSize(int width
, int height
)
728 msg
<< _T(" <size>") << width
<< _T(",") << height
<< _T("d</size>");
729 m_xmlfile
.Write(msg
);
732 void rc2xml::WritePosition(int x
, int y
)
735 msg
<< _T(" <pos>") << x
<< _T(",") << y
<< _T("d</pos>");
736 m_xmlfile
.Write(msg
);
739 void rc2xml::WriteTitle(wxString title
)
742 msg
=_T("\t\t<title>")+title
+_T("</title>\n");
743 m_xmlfile
.Write(msg
);
746 void rc2xml::WriteName(wxString name
)
749 //Try to convert any number ids into names
751 //Replace common MS ids with wxWidgets ids
752 //I didn't do everyone of them
753 if (name
==_T("IDOK"))
755 else if (name
==_T("IDCANCEL"))
756 name
=_T("wxID_CANCEL");
757 else if (name
==_T("IDAPPLY"))
758 name
=_T("wxID_APPLY");
759 else if (name
==_T("ID_FILE_OPEN"))
760 name
=_T("wxID_OPEN");
761 else if (name
==_T("ID_FILE_CLOSE"))
762 name
=_T("wxID_CLOSE");
763 else if (name
==_T("ID_FILE_SAVE"))
764 name
=_T("wxID_SAVE");
765 else if (name
==_T("ID_FILE_SAVE_AS"))
766 name
=_T("wxID_SAVEAS");
767 else if (name
==_T("ID_APP_EXIT"))
768 name
=_T("wxID_EXIT");
769 else if (name
==_T("ID_FILE_PRINT"))
770 name
=_T("wxID_PRINT");
771 else if (name
==_T("ID_FILE_PRINT_PREVIEW"))
772 name
=_T("wxID_PREVIEW");
773 else if (name
==_T("ID_FILE_PRINT_SETUP"))
774 name
=_T("wxID_PRINT_SETUP");
775 else if (name
==_T("ID_APP_ABOUT"))
776 name
=_T("wxID_ABOUT");
777 else if (name
==_T("ID_EDIT_UNDO"))
778 name
=_T("wxID_UNDO");
779 else if (name
==_T("ID_EDIT_CUT"))
781 else if (name
==_T("ID_EDIT_COPY"))
782 name
=_T("wxID_COPY");
783 else if (name
==_T("ID_EDIT_PASTE"))
784 name
=_T("wxID_PASTE");
785 else if (name
==_T("IDYES"))
787 else if (name
==_T("IDNO"))
789 else if (name
==_T("IDHELP"))
790 name
=_T("wxID_HELP");
792 m_xmlfile
.Write(_T(" name= \"")+name
+_T("\""));
795 void rc2xml::WriteLabel(wxString label
)
797 label
.Replace(_T("&"),_T("$"));
798 // changes by MS, handle '<' '>' characters within a label.
799 label
.Replace(_T("<"),_T("<"));
800 label
.Replace(_T(">"),_T(">"));
801 m_xmlfile
.Write(_T("\t\t\t<label>")+label
+_T("</label>\n"));
804 void rc2xml::WriteBasicInfo(int x
, int y
, int width
, int height
, wxString name
)
807 m_xmlfile
.Write(_T(">\n"));
808 m_xmlfile
.Write(_T("\t\t\t"));
810 WriteSize(width
,height
);
811 m_xmlfile
.Write(_T("\n"));
814 void rc2xml::WriteStyle(wxString style
)
816 if (style
.Length()==0)
818 m_xmlfile
.Write(_T("\t\t\t<style>")+style
+_T("</style>\n"));
821 LISTBOX IDC_LIST1,16,89,48,40,LBS_SORT | LBS_MULTIPLESEL |
822 LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
824 void rc2xml::ParseListBox(wxString varname
)
828 while (!token
.IsNumber())
833 int x
,y
,width
,height
;
834 ReadRect(x
,y
,width
,height
);
836 m_xmlfile
.Write(_T("\t\t<object class=\"wxListBox\""));
837 WriteBasicInfo(x
,y
,width
,height
,varname
);
838 m_xmlfile
.Write(_T("\n\t\t</object>\n"));
842 CONTROL "",IDC_RICHEDIT1,"RICHEDIT",ES_AUTOHSCROLL | WS_BORDER |
843 WS_TABSTOP,103,110,40,14
845 void rc2xml::ParseRichEdit(wxString
WXUNUSED(label
), wxString varname
)
848 //while (ReadOrs(token));
850 int x
,y
,width
,height
;
851 ReadRect(x
,y
,width
,height
);
853 //Make it a rich text control
854 style
+=_T("wxTE_MULTILINE ");
855 m_xmlfile
.Write(_T("\t\t<object class=\"wxTextCtrl\""));
856 WriteBasicInfo(x
,y
,width
,height
,varname
);
858 m_xmlfile
.Write(_T("\t\t</object>\n"));
862 CONTROL "Spin1",IDC_SPIN1,"msctls_updown32",UDS_ARROWKEYS,209,72,
865 void rc2xml::ParseSpinCtrl(wxString
WXUNUSED(label
), wxString varname
)
867 wxString token
,style
;
870 if (token
.Find(_T("UDS_HORZ"))!=wxNOT_FOUND
)
871 style
=_T("wxSP_HORIZONTAL");
874 style
=_T("wxSP_VERTICAL");
876 int x
,y
,width
,height
;
877 ReadRect(x
,y
,width
,height
);
878 m_xmlfile
.Write(_T("\t\t<object class=\"wxSpinButton\""));
879 WriteBasicInfo(x
,y
,width
,height
,varname
);
881 m_xmlfile
.Write(_T("\n\t\t</object>\n"));
885 void rc2xml::FirstPass()
887 wxString token
,prevtok
;
891 if (token
==_T("BITMAP"))
892 ParseBitmap(prevtok
);
893 else if (token
==_T("STRINGTABLE"))
894 ParseStringTable(prevtok
);
895 else if (token
==_T("ICON"))
902 void rc2xml::ParseBitmap(wxString varname
)
904 wxString token
,*bitmapfile
;
907 //Microsoft notation?
908 if (token
==_T("DISCARDABLE"))
913 bitmapfile
=new wxString
;
914 *bitmapfile
=GetQuoteField();
915 m_bitmaplist
->Append(varname
,bitmapfile
);
920 void rc2xml::SecondPass()
922 wxString token
,prevtok
;
926 if ((token
==_T("DIALOG"))||(token
==_T("DIALOGEX")))
927 ParseDialog(prevtok
);
928 else if (token
==_T("MENU"))
930 else if (token
==_T("TOOLBAR"))
931 ParseToolBar(prevtok
);
938 void rc2xml::ParseToolBar(wxString varname
)
942 wxASSERT_MSG(token
==_T("DISCARDABLE"),_T("Error in toolbar parsing"));
943 //Look up bitmap for toolbar and load
944 wxNode
*node
=m_bitmaplist
->Find(LookUpId(varname
));
945 wxString
*bitmappath
;
946 bitmappath
=(wxString
*)node
->GetData();
948 if (!bitmap
.LoadFile(*bitmappath
,wxBITMAP_TYPE_BMP
))
949 wxLogError(_T("Unable to load bitmap:")+*bitmappath
);
951 //Write toolbar to xml file
952 m_xmlfile
.Write(_T("\t<object class=\"wxToolBar\""));
953 //Avoid duplicate names this way
954 varname
.Replace(_T("IDR_"),_T("TB_"));
956 m_xmlfile
.Write(_T(">\n"));
958 style
+=_T("wxTB_FLAT");
962 //Grab width and height
964 width
=wxAtoi(GetToken());
965 height
=wxAtoi(GetToken());
968 wxString buttonname
,msg
,tip
,longhelp
;
970 while ((token
!=_T("BEGIN"))&(token
!=_T("{")))
973 while ((token
!=_T("END"))&(token
!=_T("}")))
975 if (token
==_T("BUTTON"))
977 buttonname
=GetToken();
978 m_xmlfile
.Write(_T("\t\t\t<object class=\"tool\""));
979 WriteName(buttonname
);
980 m_xmlfile
.Write(_T(">\n"));
981 //Write tool tip if any
982 if (LookUpString(buttonname
,msg
))
984 SplitHelp(msg
,tip
,longhelp
);
985 m_xmlfile
.Write(_T("\t\t\t\t<tooltip>")+tip
+_T("</tooltip>\n"));
986 m_xmlfile
.Write(_T("\t\t<longhelp>")+longhelp
+_T("</longhelp>\n"));
988 //Make a bitmap file name
989 buttonname
=CleanName(buttonname
);
990 buttonname
+=_T(".bmp");
991 m_xmlfile
.Write(_T("\t\t\t\t<bitmap>")+buttonname
+_T("</bitmap>\n"));
992 WriteToolButton(buttonname
,c
,width
,height
,bitmap
);
993 m_xmlfile
.Write(_T("\t\t\t</object>\n"));
996 else if (token
==_T("SEPARATOR"))
998 m_xmlfile
.Write(_T("\t\t\t<object class=\"separator\"/>\n"));
1002 m_xmlfile
.Write(_T("\t</object>\n"));
1005 //Extract bitmaps from larger toolbar bitmap
1006 void rc2xml::WriteToolButton(wxString name
,int index
, int width
, int height
, wxBitmap bitmap
)
1010 wxRect
r(x
,0,width
,height
);
1012 little
=bitmap
.GetSubBitmap(r
);
1013 little
.SaveFile(m_targetpath
+name
,wxBITMAP_TYPE_BMP
);
1016 void rc2xml::ParseStringTable(wxString
WXUNUSED(varname
))
1020 while ((token
!=_T("BEGIN"))&(token
!=_T("{")))
1025 while ((token
!=_T("END"))&(token
!=_T("}")))
1028 *msg
=GetStringQuote();
1029 m_stringtable
->Append(token
,msg
);
1034 bool rc2xml::LookUpString(wxString strid
,wxString
& st
)
1036 wxNode
*node
=m_stringtable
->Find(strid
);
1041 s
=(wxString
*)node
->GetData();
1047 bool rc2xml::SplitHelp(wxString msg
, wxString
&shorthelp
, wxString
&longhelp
)
1050 spot
=msg
.Find(_T("\\n"));
1051 if (spot
==wxNOT_FOUND
)
1057 longhelp
=msg
.Left(spot
);
1058 spot
=msg
.Length()-spot
-2;
1059 shorthelp
=msg
.Right(spot
);
1063 void rc2xml::ParseMenuItem()
1065 wxString token
,name
,msg
,tip
,longhelp
;
1067 if (PeekToken()==_T("SEPARATOR"))
1069 m_xmlfile
.Write(_T("\t\t\t<object class=\"separator\"/>\n"));
1073 token
=GetQuoteField();
1075 //Remove \t because it causes problems
1076 //spot=token.First("\\t");
1077 //token=token.Left(spot);
1078 m_xmlfile
.Write(_T("\t\t\t<object class=\"wxMenuItem\""));
1080 m_xmlfile
.Write(_T(">\n"));
1082 //Look up help if any listed in stringtable
1083 //can't assume numbers correlate, restrict to string identifiers
1084 if ((!name
.IsNumber())&&(LookUpString(name
,msg
)))
1086 SplitHelp(msg
,tip
,longhelp
);
1087 m_xmlfile
.Write(_T("\t\t\t<help>")
1088 +longhelp
+_T("</help>\n"));
1090 //look for extra attributes like checked and break
1094 while ((ptoken
!=_T("MENUITEM"))&(ptoken
!=_T("POPUP"))&(ptoken
!=_T("END")))
1098 if (token
==_T("CHECKED"))
1099 m_xmlfile
.Write(_T("\t\t\t<checkable>1</checkable>\n"));
1100 else if (token
==_T("MENUBREAK"))
1102 //m_xmlfile.Write("\t\t\t</break>\n");
1103 else if (token
==_T("GRAYED"))
1106 wxLogError(_T("Unknown Menu Item token:")+token
);
1111 m_xmlfile
.Write(_T("\t\t\t</object>\n"));
1115 //ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
1116 void rc2xml::ParseIconStatic()
1119 wxString varname
,iconname
;
1120 token
= PeekToken();
1121 if (token
.Contains(_T("\"")))
1122 iconname
= GetQuoteField();
1124 iconname
=GetToken();
1128 int x
,y
,width
,height
;
1129 ReadRect(x
,y
,width
,height
);
1131 m_xmlfile
.Write(_T("\t\t<object class=\"wxStaticBitmap\""));
1132 WriteBasicInfo(x
,y
,width
,height
,varname
);
1133 //Save icon as a bitmap
1134 WriteIcon(iconname
);
1135 m_xmlfile
.Write(_T("\t\t</object>\n"));
1138 //IDR_MAINFRAME ICON DISCARDABLE "res\\mfcexample.ico"
1139 void rc2xml::ParseIcon(wxString varname
)
1141 wxString token
,*iconfile
;
1142 iconfile
=new wxString
;
1145 *iconfile
=GetQuoteField();
1146 m_iconlist
->Append(varname
,iconfile
);
1151 wxString
rc2xml::CleanName(wxString name
)
1154 name
.Replace(_T("id_"),wxEmptyString
);
1155 name
.Replace(_T("idr_"),wxEmptyString
);
1156 name
.Replace(_T("idb_"),wxEmptyString
);
1157 name
.Replace(_T("idc_"),wxEmptyString
);
1159 name
.Replace(_T(".ico"),wxEmptyString
);
1161 name
.Replace(_T(".bmp"),wxEmptyString
);
1164 // And the award for most messed up control goes to...
1165 // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
1166 void rc2xml::ParseStaticBitmap(wxString bitmapname
, wxString varname
)
1173 int x
,y
,width
,height
;
1174 ReadRect(x
,y
,width
,height
);
1176 m_xmlfile
.Write(_T("\t\t<object class=\"wxStaticBitmap\""));
1177 WriteBasicInfo(x
,y
,width
,height
,varname
);
1178 WriteBitmap(bitmapname
);
1179 m_xmlfile
.Write(_T("\t\t</object>\n"));
1183 void rc2xml::ParseNormalMSControl()
1185 wxString label
,varname
,kindctrl
;
1187 label
=GetQuoteField();
1189 kindctrl
=GetQuoteField();
1190 kindctrl
.MakeUpper();
1192 if (kindctrl
==_T("MSCTLS_UPDOWN32"))
1193 ParseSpinCtrl(label
,varname
);
1194 if (kindctrl
==_T("MSCTLS_TRACKBAR32"))
1195 ParseSlider(label
,varname
);
1196 if (kindctrl
==_T("MSCTLS_PROGRESS32"))
1197 ParseProgressBar(label
,varname
);
1198 if (kindctrl
==_T("SYSTREEVIEW32"))
1199 ParseTreeCtrl(label
,varname
);
1200 if (kindctrl
==_T("SYSMONTHCAL32"))
1201 ParseCalendar(label
,varname
);
1202 if (kindctrl
==_T("SYSLISTVIEW32"))
1203 ParseListCtrl(label
,varname
);
1204 if (kindctrl
==_T("BUTTON"))
1205 ParseCtrlButton(label
,varname
);
1206 if (kindctrl
==_T("RICHEDIT"))
1207 ParseRichEdit(label
,varname
);
1208 if (kindctrl
==_T("STATIC"))
1214 if (token
.Find(_T("SS_BITMAP"))!=wxNOT_FOUND
)
1215 ParseStaticBitmap(label
,varname
);
1217 ParseStaticText(label
,varname
);
1219 if (kindctrl
==_T("EDIT"))
1220 ParseTextCtrl(varname
);
1221 if (kindctrl
==_T("LISTBOX"))
1222 ParseListBox(varname
);
1223 if (kindctrl
==_T("COMBOBOX"))
1224 ParseComboBox(varname
);
1228 void rc2xml::ParseWeirdMSControl()
1235 kindctrl
=GetQuoteField();
1236 kindctrl
.MakeUpper();
1237 // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
1238 if (kindctrl
==_T("STATIC"))
1240 if (PeekToken()==_T("SS_BITMAP"))
1241 ParseStaticBitmap(id
,varname
);
1243 wxLogError(_T("Unknown MS Control Static token"));
1247 //SCROLLBAR IDC_SCROLLBAR1,219,56,10,40,SBS_VERT
1249 void rc2xml::ParseScrollBar()
1255 int x
,y
,width
,height
;
1256 ReadRect(x
,y
,width
,height
);
1261 if (token
.Find(_T("SBS_VERT"))!=wxNOT_FOUND
)
1262 style
=_T("wxSB_VERTICAL");
1263 //Default MFC style is horizontal
1265 style
=_T("wxSB_HORIZONTAL");
1267 m_xmlfile
.Write(_T("\t\t<object class=\"wxScrollBar\""));
1268 WriteBasicInfo(x
,y
,width
,height
,varname
);
1270 m_xmlfile
.Write(_T("\n\t\t</object>\n"));
1273 // CONTROL "Tree1",IDC_TREE1,"SysTreeView32",WS_BORDER | WS_TABSTOP,
1276 void rc2xml::ParseTreeCtrl(wxString
WXUNUSED(label
), wxString varname
)
1279 //while (ReadOrs(token));
1281 int x
,y
,width
,height
;
1282 ReadRect(x
,y
,width
,height
);
1283 m_xmlfile
.Write(_T("\t\t<object class=\"wxTreeCtrl\""));
1284 WriteBasicInfo(x
,y
,width
,height
,varname
);
1285 m_xmlfile
.Write(_T("\t\t</object>\n"));
1288 // CONTROL "MonthCalendar1",IDC_MONTHCALENDAR1,"SysMonthCal32",
1289 //MCS_NOTODAY | WS_TABSTOP,105,71,129,89
1291 void rc2xml::ParseCalendar(wxString
WXUNUSED(label
), wxString varname
)
1294 //while (ReadOrs(token));
1296 int x
,y
,width
,height
;
1297 ReadRect(x
,y
,width
,height
);
1298 m_xmlfile
.Write(_T("\t\t<object class=\"wxCalendarCtrl\""));
1299 WriteBasicInfo(x
,y
,width
,height
,varname
);
1300 m_xmlfile
.Write(_T("\t\t</object>\n"));
1302 // CONTROL "List1",IDC_LIST1,"SysListView32",WS_BORDER | WS_TABSTOP,
1305 void rc2xml::ParseListCtrl(wxString
WXUNUSED(label
), wxString varname
)
1308 //while (ReadOrs(token));
1310 int x
,y
,width
,height
;
1311 ReadRect(x
,y
,width
,height
);
1312 m_xmlfile
.Write(_T("\t\t<object class=\"wxListCtrl\""));
1313 WriteBasicInfo(x
,y
,width
,height
,varname
);
1314 m_xmlfile
.Write(_T("\t\t</object>\n"));
1318 void rc2xml::WriteBitmap(wxString bitmapname
)
1321 wxNode
*node
=m_bitmaplist
->Find(LookUpId(bitmapname
));
1324 m_xmlfile
.Write(_T("\t\t\t<bitmap>missingfile</bitmap>\n"));
1325 wxLogError(_T("Unable to find bitmap:")+bitmapname
);
1329 wxString
*bitmappath
;
1330 bitmappath
=(wxString
*)node
->GetData();
1332 bitmapname
=wxFileNameFromPath(*bitmappath
);
1334 if (!bitmap
.LoadFile(*bitmappath
,wxBITMAP_TYPE_BMP
))
1335 wxLogError(_T("Unable to load bitmap:")+*bitmappath
);
1337 //Make a bitmap file name
1338 bitmapname
=CleanName(bitmapname
);
1339 bitmapname
+=_T(".bmp");
1340 m_xmlfile
.Write(_T("\t\t\t<bitmap>")+bitmapname
+_T("</bitmap>\n"));
1341 bitmap
.SaveFile(m_targetpath
+bitmapname
,wxBITMAP_TYPE_BMP
);
1344 void rc2xml::WriteIcon(wxString iconname
)
1346 wxNode
*node
=m_iconlist
->Find(iconname
);
1349 m_xmlfile
.Write(_T("\t\t\t<bitmap>missing_file</bitmap>\n"));
1350 wxLogError(_T("Unable to find icon:")+iconname
);
1353 iconpath
=(wxString
*)node
->GetData();
1356 if (!icon
.LoadFile(*iconpath
,wxBITMAP_TYPE_ICO
))
1357 wxLogError(_T("Unable to load icon:")+*iconpath
);
1359 bitmap
.CopyFromIcon(icon
);
1363 iconname
=wxFileNameFromPath(*iconpath
);
1364 //Make a bitmap file name
1365 iconname
=CleanName(iconname
);
1366 iconname
+=_T(".bmp");
1367 m_xmlfile
.Write(_T("\t\t\t<bitmap>")+iconname
+_T("</bitmap>\n"));
1368 bitmap
.SaveFile(m_targetpath
+iconname
,wxBITMAP_TYPE_BMP
);
1372 /*Unfortunately sometimes the great MSVC Resource editor decides
1373 to use numbers instead of the word id. I have no idea why they
1374 do this, but that is the way it is.
1376 /* this is a quick and dirty way to parse the resource.h file
1377 it will not recognize #ifdef so it can be easily fooled
1379 void rc2xml::ParseResourceHeader()
1382 //Attempt to load resource.h in current path
1383 if (!r
.Open(_T("resource.h")))
1385 wxLogError(_T("Warining Unable to load resource.h file"));
1391 wxStringTokenizer tok
;
1397 //Read through entire file
1398 for ( str
= r
.GetFirstLine(); !r
.Eof(); str
= r
.GetNextLine() )
1400 if (str
.Find(_T("#define"))!=wxNOT_FOUND
)
1403 //Just ignore #define token
1405 v
=tok
.GetNextToken();
1406 id
=tok
.GetNextToken();
1409 varname
=new wxString
;
1412 m_resourcelist
->Append(n
,varname
);
1422 wxString
rc2xml::LookUpId(wxString id
)
1430 wxNode
*node
=m_resourcelist
->Find(n
);
1435 s
=(wxString
*)node
->GetData();