]>
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
18 // For compilers that support precompilation, includes "wx/wx.h".
19 #include "wx/wxprec.h"
25 // for all others, include the necessary headers (this file is usually all you
26 // need because it includes almost all "standard" wxWidgets headers
34 #include "wx/deprecated/setup.h"
35 #include "wx/deprecated/resource.h"
36 #include "wx/textfile.h"
37 #include "wx/tokenzr.h"
41 //////////////////////////////////////////////////////////////////////
42 // Construction/Destruction
43 //////////////////////////////////////////////////////////////////////
48 m_bitmaplist
=new wxList(wxKEY_STRING
);
49 m_stringtable
=new wxList(wxKEY_STRING
);
50 m_iconlist
= new wxList(wxKEY_STRING
);
51 m_resourcelist
=new wxList(wxKEY_INTEGER
);
59 delete m_resourcelist
;
62 bool rc2xml::Convert(wxString rcfile
, wxString xmlfile
)
64 m_rc
.Open(rcfile
.c_str());
65 m_filesize
=m_rc
.Length();
68 m_workingpath
=wxPathOnly(rcfile
);
70 m_targetpath
=wxPathOnly(xmlfile
) + _T("\\");
74 wxSetWorkingDirectory(m_workingpath
);
78 result
=m_xmlfile
.Open(xmlfile
.c_str(),_T("w+t"));
79 wxASSERT_MSG(result
,_T("Couldn't create XML file"));
84 /* Write Basic header for XML file */
85 m_xmlfile
.Write(_T("<?xml version=\"1.0\" ?>\n"));
86 m_xmlfile
.Write(_T("<resource>\n"));
89 ParseResourceHeader();
90 //Gather all the resource we need for toolbars,menus, and etc
94 //Read in dialogs, toolbars,menus
97 m_xmlfile
.Write(_T("</resource>\n"));
100 wxMessageBox(_("Conversion complete."), _("Done"),
101 wxOK
| wxICON_INFORMATION
);
107 void rc2xml::ParseDialog(wxString dlgname
)
110 static int dlgid
=999;
112 /* Make sure that this really is a dialog
113 microsoft reuses the keyword DIALOG for other things
116 //Microsoft notation?
117 while ((token
==_T("DISCARDABLE"))
118 ||(token
==_T("LOADONCALL"))||(token
==_T("MOVEABLE")))
123 //Error isn't a Dialog resource eject eject
124 if (!token
.IsNumber())
127 //Record x,y,width,height
128 int x
,y
,width
,height
;
129 ReadRect(x
,y
,width
,height
);
133 wxString ptsize
,face
;
135 m_xmlfile
.Write(_T("\t<object class=\"wxDialog\""));
136 //Avoid duplicate names this way
137 dlgname
.Replace(_T("IDD_"),_T("DLG_"));
138 WriteBasicInfo(x
,y
,width
,height
,dlgname
);
142 while ((token
!=_T("BEGIN"))&(token
!=_T("{")))
144 if (token
==_T("CAPTION"))
146 title
=GetQuoteField();
149 //TODO fix face name so that it is cross platform name
150 // FONT 8, "MS Sans Serif"
151 if (token
==_T("FONT"))
154 face
=GetQuoteField();
155 m_xmlfile
.Write(_T("\t\t<font>\n"));
156 m_xmlfile
.Write(_T("\t\t\t<size>")+ptsize
+_T("</size>\n"));
157 m_xmlfile
.Write(_T("\t\t\t<face>")+face
+_T("</face>\n"));
158 m_xmlfile
.Write(_T("\t\t</font>\n"));
165 m_xmlfile
.Write(_T("\t</object>\n"));
170 EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT
172 LTEXT "Bands",IDC_STATIC,11,86,21,8
173 EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL
176 void rc2xml::ParseControls()
179 wxString label
,varname
;
182 while ((token
!=_T("END"))&(token
!=_T("}")))
184 if (token
==_T("AUTOCHECKBOX"))
186 label
=GetQuoteField();
188 ParseCheckBox(label
,varname
);
191 if (token
==_T("AUTORADIOBUTTON"))
193 label
=GetQuoteField();
195 ParseRadioButton(label
,varname
);
198 if (token
==_T("LTEXT"))
200 label
=GetQuoteField();
202 ParseStaticText(label
,varname
);
204 else if (token
==_T("EDITTEXT"))
207 ParseTextCtrl(varname
);
209 else if ((token
==_T("PUSHBUTTON"))||(token
==_T("DEFPUSHBUTTON")))
211 label
=GetQuoteField();
213 ParsePushButton(label
,varname
);
215 else if (token
==_T("GROUPBOX"))
217 label
=GetQuoteField();
219 ParseGroupBox(label
,varname
);
221 else if (token
==_T("COMBOBOX"))
224 ParseComboBox(varname
);
226 else if (token
==_T("CONTROL"))
228 else if (token
==_T("LISTBOX"))
231 ParseListBox(varname
);
233 else if (token
==_T("ICON"))
235 else if (token
==_T("SCROLLBAR"))
241 //LTEXT "Radius",IDC_STATIC,9,67,23,8
242 void rc2xml::ParseStaticText(wxString phrase
, wxString varname
)
246 while (!token
.IsNumber())
251 int x
,y
,width
,height
;
252 ReadRect(x
,y
,width
,height
);
254 m_xmlfile
.Write(_T("\t\t<object class=\"wxStaticText\""));
255 WriteBasicInfo(x
,y
,width
,height
,varname
);WriteLabel(phrase
);
256 m_xmlfile
.Write(_T("\t\t</object>\n"));
259 //EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
260 void rc2xml::ParseTextCtrl(wxString varname
)
265 while (!token
.IsNumber())
270 int x
,y
,width
,height
;
271 ReadRect(x
,y
,width
,height
);
274 m_xmlfile
.Write(_T("\t\t<object class=\"wxTextCtrl\""));
275 WriteBasicInfo(x
,y
,width
,height
,varname
);
276 m_xmlfile
.Write(_T("\t\t</object>\n"));
279 //AUTOCHECKBOX "&log.", ID_XLOG, 25, 24, 21, 12
280 void rc2xml::ParseCheckBox(wxString phrase
, wxString varname
)
284 while (!token
.IsNumber())
289 int x
,y
,width
,height
;
290 ReadRect(x
,y
,width
,height
);
292 m_xmlfile
.Write(_T("\t\t<object class=\"wxCheckBox\""));
293 WriteBasicInfo(x
,y
,width
,height
,varname
);
295 m_xmlfile
.Write(_T("\t\t</object>\n"));
298 //AUTORADIOBUTTON "&text", ID_SW10, 13, 12, 68, 10, BS_AUTORADIOBUTTON | WS_GROUP
299 void rc2xml::ParseRadioButton(wxString phrase
, wxString varname
)
301 wxString token
,style
;
302 int x
,y
,width
,height
;
304 GotOrs
= ReadOrs(token
);
305 if (ReadRect(x
,y
,width
,height
))
308 if (token
.Find(_T("WS_GROUP")) != wxNOT_FOUND
)
309 style
+= _T("wxRB_GROUP");
311 m_xmlfile
.Write(_T("\t\t<object class=\"wxRadioButton\""));
312 WriteBasicInfo(x
,y
,width
,height
,varname
);
315 m_xmlfile
.Write(_T("\t\t</object>\n"));
319 //PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
320 void rc2xml::ParsePushButton(wxString phrase
, wxString varname
)
325 while (!token
.IsNumber())
330 int x
,y
,width
,height
;
331 ReadRect(x
,y
,width
,height
);
333 m_xmlfile
.Write(_T("\t\t<object class=\"wxButton\""));
334 WriteBasicInfo(x
,y
,width
,height
,varname
);
336 m_xmlfile
.Write(_T("\t\t</object>\n"));
341 bool rc2xml::Separator(int ch
)
343 //if ((ch==' ')|(ch==',')|(ch==13)|(ch==10)|(ch=='|')|(ch=='\t'))
344 if ((ch
==' ')|(ch
==',')|(ch
==13)|(ch
==10)|(ch
=='\t'))
356 void rc2xml::ParseGroupBox(wxString phrase
, wxString varname
)
358 // GROUPBOX "Rotate",IDC_STATIC,1,1,71,79
361 while (!token
.IsNumber())
366 int x
,y
,width
,height
;
367 ReadRect(x
,y
,width
,height
);
369 m_xmlfile
.Write(_T("\t\t<object class=\"wxStaticBox\""));
370 WriteBasicInfo(x
,y
,width
,height
,varname
);
372 m_xmlfile
.Write(_T("\t\t</object>\n"));
375 bool rc2xml::ReadRect(int & x
, int & y
, int & width
, int & height
)
377 x
=wxAtoi(GetToken());
378 y
=wxAtoi(GetToken());
379 width
=wxAtoi(GetToken());
381 wxString tmp
= GetToken(&ret
);
383 return ret
; // check for more parameters
386 wxString
rc2xml::GetToken(bool *listseparator
)
388 wxString token
=wxEmptyString
;
404 while (Separator(ch
))
417 while (!Separator(ch
))
427 *listseparator
= (ch
== ',');
431 wxString
rc2xml::GetQuoteField()
440 // !! Changed by MS, 15th/11/04. Can now read strings such as
441 // """Catapult"" - blah blah", ...
456 // real end of string..
460 // add a single quote - fall through
468 // string in stringtable may contain embedded quotes
469 // escape characters retained to allow strings to be rewritten
470 wxString
rc2xml::GetStringQuote()
484 if ((ch
==34)&&(lastch
!='\\'))
486 wxFileOffset p
= m_rc
.Tell();
488 // RC supports "", for embedded quote, as well as \"
500 ReadChar(ch
); // skip
501 if ((ch
=='\n')&&(lastch
=='\\')) // lastch <should> be this
502 phrase
+='n'; // escape
513 void rc2xml::ReadChar(int &ch
)
515 wxFileOffset result
= m_rc
.Tell();
517 if((result
>=m_filesize
))
520 result
= m_rc
.Read(&ch
,1);
522 if( result
== wxInvalidOffset
)
529 void rc2xml::ParseComboBox(wxString varname
)
531 /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
532 WS_VSCROLL | WS_TABSTOP */
533 wxString token
,style
;
534 int x
,y
,width
,height
;
536 GotOrs
= ReadOrs(token
);
537 if (ReadRect(x
,y
,width
,height
))
541 m_xmlfile
.Write(_T("\t\t<object class=\"wxComboBox\""));
542 WriteBasicInfo(x
,y
,width
,height
,varname
);
543 if (token
.Find(_T("CBS_SIMPLE")) != wxNOT_FOUND
)
544 WriteStyle(_T("wxCB_SIMPLE"));
545 if (token
.Find(_T("CBS_SORT")) != wxNOT_FOUND
)
546 WriteStyle(_T("wxCB_SORT"));
547 if (token
.Find(_T("CBS_DISABLENOSCROLL")) != wxNOT_FOUND
)
548 WriteStyle(_T("wxLB_ALWAYS_SB"));
549 m_xmlfile
.Write(_T("\n\t\t</object>\n"));
553 void rc2xml::ParseMenu(wxString varname
)
555 wxString token
=wxEmptyString
;
557 //Write menubar to xml file
558 m_xmlfile
.Write(_T("\t<object class=\"wxMenuBar\""));
559 //Avoid duplicate names this way
560 varname
.Replace(_T("IDR_"),_T("MB_"));
562 m_xmlfile
.Write(_T(">\n"));
564 while ((token
!=_T("BEGIN"))&(token
!=_T("{")))
567 while ((token
!=_T("END"))&(token
!=_T("}")))
572 if (token
==_T("POPUP"))
577 m_xmlfile
.Write(_T("\t</object>\n"));
580 void rc2xml::ParsePopupMenu()
582 static int menucount
=0;
584 wxString token
,name
,msg
,longhelp
,tip
;
585 token
=GetQuoteField();
587 //Remove \t because it causes problems
589 //spot=token.First("\\t");
590 //token=token.Left(spot);
593 //Generate a fake name since RC menus don't have one
594 name
<< _T("Menu_") << menucount
;
595 m_xmlfile
.Write(_T("\t\t<object class=\"wxMenu\""));
597 m_xmlfile
.Write(_T(">\n"));
600 while ((token
!=_T("BEGIN"))&(token
!=_T("{")))
603 while ((token
!=_T("END"))&(token
!=_T("}")))
608 if (token
==_T("POPUP"))
611 if (token
==_T("MENUITEM"))
614 m_xmlfile
.Write(_T("\t\t\t</object>\n"));
617 wxString
rc2xml::PeekToken()
619 wxFileOffset p
= m_rc
.Tell();
620 wxString token
=GetToken();
626 //MS Windows pain in the butt CONTROL
627 void rc2xml::ParseControlMS()
629 wxString token
= PeekToken();
631 if (token
.Contains(_T("\"")))
632 ParseNormalMSControl();
634 ParseWeirdMSControl();
637 /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
638 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
641 void rc2xml::ParseSlider(wxString
WXUNUSED(label
), wxString varname
)
643 wxString token
,style
;
645 if (token
.Find(_T("TBS_VERT"))!=wxNOT_FOUND
)
646 style
+=_T("wxSL_VERTICAL");
647 //MFC RC Default is horizontal
649 style
+=_T("wxSL_HORIZONTAL");
651 int x
,y
,width
,height
;
652 ReadRect(x
,y
,width
,height
);
653 m_xmlfile
.Write(_T("\t\t<object class=\"wxSlider\""));
654 WriteBasicInfo(x
,y
,width
,height
,varname
);
656 m_xmlfile
.Write(_T("\n\t\t</object>\n"));
660 CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
661 WS_BORDER,15,52,154,13
663 void rc2xml::ParseProgressBar(wxString
WXUNUSED(label
), wxString varname
)
665 wxString token
,style
;
668 int x
,y
,width
,height
;
669 ReadRect(x
,y
,width
,height
);
671 //Always horizontal in MFC
672 m_xmlfile
.Write(_T("\t\t<object class=\"wxGauge\""));
673 WriteBasicInfo(x
,y
,width
,height
,varname
);
675 m_xmlfile
.Write(_T("\t\t</object>\n"));
678 bool rc2xml::ReadOrs(wxString
& orstring
)
683 if (token
.IsNumber())
687 while(PeekToken()==_T("|"))
690 orstring
+=GetToken();
692 orstring
+=GetToken();
697 //Is it a checkbutton or a radiobutton or a pushbutton or a groupbox
698 void rc2xml::ParseCtrlButton(wxString label
, wxString varname
)
701 wxFileOffset p
= m_rc
.Tell();
705 if (token
.Find(_T("BS_AUTOCHECKBOX"))!=wxNOT_FOUND
)
706 ParseCheckBox(label
, varname
);
707 else if ((token
.Find(_T("BS_AUTORADIOBUTTON"))!=wxNOT_FOUND
)||
708 (token
.Find(_T("BS_RADIOBUTTON"))!=wxNOT_FOUND
))
709 ParseRadioButton(label
, varname
);
710 else if (token
.Find(_T("BS_GROUPBOX"))!=wxNOT_FOUND
)
711 ParseGroupBox(label
, varname
);
712 else // if ((token.Find("BS_PUSHBUTTON")!=wxNOT_FOUND)||
713 // (token.Find("BS_DEFPUSHBUTTON")!=wxNOT_FOUND))
714 ParsePushButton(label
, varname
); // make default case
717 void rc2xml::WriteSize(int width
, int height
)
720 msg
<< _T(" <size>") << width
<< _T(",") << height
<< _T("d</size>");
721 m_xmlfile
.Write(msg
);
724 void rc2xml::WritePosition(int x
, int y
)
727 msg
<< _T(" <pos>") << x
<< _T(",") << y
<< _T("d</pos>");
728 m_xmlfile
.Write(msg
);
731 void rc2xml::WriteTitle(wxString title
)
734 msg
=_T("\t\t<title>")+title
+_T("</title>\n");
735 m_xmlfile
.Write(msg
);
738 void rc2xml::WriteName(wxString name
)
741 //Try to convert any number ids into names
743 //Replace common MS ids with wxWidgets ids
744 //I didn't do everyone of them
745 if (name
==_T("IDOK"))
747 else if (name
==_T("IDCANCEL"))
748 name
=_T("wxID_CANCEL");
749 else if (name
==_T("IDAPPLY"))
750 name
=_T("wxID_APPLY");
751 else if (name
==_T("ID_FILE_OPEN"))
752 name
=_T("wxID_OPEN");
753 else if (name
==_T("ID_FILE_CLOSE"))
754 name
=_T("wxID_CLOSE");
755 else if (name
==_T("ID_FILE_SAVE"))
756 name
=_T("wxID_SAVE");
757 else if (name
==_T("ID_FILE_SAVE_AS"))
758 name
=_T("wxID_SAVEAS");
759 else if (name
==_T("ID_APP_EXIT"))
760 name
=_T("wxID_EXIT");
761 else if (name
==_T("ID_FILE_PRINT"))
762 name
=_T("wxID_PRINT");
763 else if (name
==_T("ID_FILE_PRINT_PREVIEW"))
764 name
=_T("wxID_PREVIEW");
765 else if (name
==_T("ID_FILE_PRINT_SETUP"))
766 name
=_T("wxID_PRINT_SETUP");
767 else if (name
==_T("ID_APP_ABOUT"))
768 name
=_T("wxID_ABOUT");
769 else if (name
==_T("ID_EDIT_UNDO"))
770 name
=_T("wxID_UNDO");
771 else if (name
==_T("ID_EDIT_CUT"))
773 else if (name
==_T("ID_EDIT_COPY"))
774 name
=_T("wxID_COPY");
775 else if (name
==_T("ID_EDIT_PASTE"))
776 name
=_T("wxID_PASTE");
777 else if (name
==_T("IDYES"))
779 else if (name
==_T("IDNO"))
781 else if (name
==_T("IDHELP"))
782 name
=_T("wxID_HELP");
784 m_xmlfile
.Write(_T(" name= \"")+name
+_T("\""));
787 void rc2xml::WriteLabel(wxString label
)
789 label
.Replace(_T("&"),_T("$"));
790 // changes by MS, handle '<' '>' characters within a label.
791 label
.Replace(_T("<"),_T("<"));
792 label
.Replace(_T(">"),_T(">"));
793 m_xmlfile
.Write(_T("\t\t\t<label>")+label
+_T("</label>\n"));
796 void rc2xml::WriteBasicInfo(int x
, int y
, int width
, int height
, wxString name
)
799 m_xmlfile
.Write(_T(">\n"));
800 m_xmlfile
.Write(_T("\t\t\t"));
802 WriteSize(width
,height
);
803 m_xmlfile
.Write(_T("\n"));
806 void rc2xml::WriteStyle(wxString style
)
808 if (style
.Length()==0)
810 m_xmlfile
.Write(_T("\t\t\t<style>")+style
+_T("</style>\n"));
813 LISTBOX IDC_LIST1,16,89,48,40,LBS_SORT | LBS_MULTIPLESEL |
814 LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
816 void rc2xml::ParseListBox(wxString varname
)
820 while (!token
.IsNumber())
825 int x
,y
,width
,height
;
826 ReadRect(x
,y
,width
,height
);
828 m_xmlfile
.Write(_T("\t\t<object class=\"wxListBox\""));
829 WriteBasicInfo(x
,y
,width
,height
,varname
);
830 m_xmlfile
.Write(_T("\n\t\t</object>\n"));
834 CONTROL "",IDC_RICHEDIT1,"RICHEDIT",ES_AUTOHSCROLL | WS_BORDER |
835 WS_TABSTOP,103,110,40,14
837 void rc2xml::ParseRichEdit(wxString
WXUNUSED(label
), wxString varname
)
840 //while (ReadOrs(token));
842 int x
,y
,width
,height
;
843 ReadRect(x
,y
,width
,height
);
845 //Make it a rich text control
846 style
+=_T("wxTE_MULTILINE ");
847 m_xmlfile
.Write(_T("\t\t<object class=\"wxTextCtrl\""));
848 WriteBasicInfo(x
,y
,width
,height
,varname
);
850 m_xmlfile
.Write(_T("\t\t</object>\n"));
854 CONTROL "Spin1",IDC_SPIN1,"msctls_updown32",UDS_ARROWKEYS,209,72,
857 void rc2xml::ParseSpinCtrl(wxString
WXUNUSED(label
), wxString varname
)
859 wxString token
,style
;
862 if (token
.Find(_T("UDS_HORZ"))!=wxNOT_FOUND
)
863 style
=_T("wxSP_HORIZONTAL");
866 style
=_T("wxSP_VERTICAL");
868 int x
,y
,width
,height
;
869 ReadRect(x
,y
,width
,height
);
870 m_xmlfile
.Write(_T("\t\t<object class=\"wxSpinButton\""));
871 WriteBasicInfo(x
,y
,width
,height
,varname
);
873 m_xmlfile
.Write(_T("\n\t\t</object>\n"));
877 void rc2xml::FirstPass()
879 wxString token
,prevtok
;
883 if (token
==_T("BITMAP"))
884 ParseBitmap(prevtok
);
885 else if (token
==_T("STRINGTABLE"))
886 ParseStringTable(prevtok
);
887 else if (token
==_T("ICON"))
894 void rc2xml::ParseBitmap(wxString varname
)
897 wxString
*bitmapfile
;
900 //Microsoft notation?
901 if (token
==_T("DISCARDABLE"))
906 bitmapfile
=new wxString
;
907 *bitmapfile
=GetQuoteField();
908 m_bitmaplist
->Append(varname
,bitmapfile
);
913 void rc2xml::SecondPass()
915 wxString token
,prevtok
;
919 if ((token
==_T("DIALOG"))||(token
==_T("DIALOGEX")))
920 ParseDialog(prevtok
);
921 else if (token
==_T("MENU"))
923 else if (token
==_T("TOOLBAR"))
924 ParseToolBar(prevtok
);
931 void rc2xml::ParseToolBar(wxString varname
)
935 wxASSERT_MSG(token
==_T("DISCARDABLE"),_T("Error in toolbar parsing"));
936 //Look up bitmap for toolbar and load
937 wxNode
*node
=m_bitmaplist
->Find(LookUpId(varname
));
938 wxString
*bitmappath
;
939 bitmappath
=(wxString
*)node
->GetData();
941 if (!bitmap
.LoadFile(*bitmappath
,wxBITMAP_TYPE_BMP
))
942 wxLogError(_T("Unable to load bitmap:")+*bitmappath
);
944 //Write toolbar to xml file
945 m_xmlfile
.Write(_T("\t<object class=\"wxToolBar\""));
946 //Avoid duplicate names this way
947 varname
.Replace(_T("IDR_"),_T("TB_"));
949 m_xmlfile
.Write(_T(">\n"));
951 style
+=_T("wxTB_FLAT");
955 //Grab width and height
957 width
=wxAtoi(GetToken());
958 height
=wxAtoi(GetToken());
961 wxString buttonname
,msg
,tip
,longhelp
;
963 while ((token
!=_T("BEGIN"))&(token
!=_T("{")))
966 while ((token
!=_T("END"))&(token
!=_T("}")))
968 if (token
==_T("BUTTON"))
970 buttonname
=GetToken();
971 m_xmlfile
.Write(_T("\t\t\t<object class=\"tool\""));
972 WriteName(buttonname
);
973 m_xmlfile
.Write(_T(">\n"));
974 //Write tool tip if any
975 if (LookUpString(buttonname
,msg
))
977 SplitHelp(msg
,tip
,longhelp
);
978 m_xmlfile
.Write(_T("\t\t\t\t<tooltip>")+tip
+_T("</tooltip>\n"));
979 m_xmlfile
.Write(_T("\t\t<longhelp>")+longhelp
+_T("</longhelp>\n"));
981 //Make a bitmap file name
982 buttonname
=CleanName(buttonname
);
983 buttonname
+=_T(".bmp");
984 m_xmlfile
.Write(_T("\t\t\t\t<bitmap>")+buttonname
+_T("</bitmap>\n"));
985 WriteToolButton(buttonname
,c
,width
,height
,bitmap
);
986 m_xmlfile
.Write(_T("\t\t\t</object>\n"));
989 else if (token
==_T("SEPARATOR"))
991 m_xmlfile
.Write(_T("\t\t\t<object class=\"separator\"/>\n"));
995 m_xmlfile
.Write(_T("\t</object>\n"));
998 //Extract bitmaps from larger toolbar bitmap
999 void rc2xml::WriteToolButton(wxString name
,int index
, int width
, int height
, wxBitmap bitmap
)
1003 wxRect
r(x
,0,width
,height
);
1005 little
=bitmap
.GetSubBitmap(r
);
1006 little
.SaveFile(m_targetpath
+name
,wxBITMAP_TYPE_BMP
);
1009 void rc2xml::ParseStringTable(wxString
WXUNUSED(varname
))
1013 while ((token
!=_T("BEGIN"))&(token
!=_T("{")))
1018 while ((token
!=_T("END"))&(token
!=_T("}")))
1021 *msg
=GetStringQuote();
1022 m_stringtable
->Append(token
,msg
);
1027 bool rc2xml::LookUpString(wxString strid
,wxString
& st
)
1029 wxNode
*node
=m_stringtable
->Find(strid
);
1034 s
=(wxString
*)node
->GetData();
1040 bool rc2xml::SplitHelp(wxString msg
, wxString
&shorthelp
, wxString
&longhelp
)
1043 spot
=msg
.Find(_T("\\n"));
1044 if (spot
==wxNOT_FOUND
)
1050 longhelp
=msg
.Left(spot
);
1051 spot
=msg
.Length()-spot
-2;
1052 shorthelp
=msg
.Right(spot
);
1056 void rc2xml::ParseMenuItem()
1058 wxString token
,name
,msg
,tip
,longhelp
;
1060 if (PeekToken()==_T("SEPARATOR"))
1062 m_xmlfile
.Write(_T("\t\t\t<object class=\"separator\"/>\n"));
1066 token
=GetQuoteField();
1068 //Remove \t because it causes problems
1069 //spot=token.First("\\t");
1070 //token=token.Left(spot);
1071 m_xmlfile
.Write(_T("\t\t\t<object class=\"wxMenuItem\""));
1073 m_xmlfile
.Write(_T(">\n"));
1075 //Look up help if any listed in stringtable
1076 //can't assume numbers correlate, restrict to string identifiers
1077 if ((!name
.IsNumber())&&(LookUpString(name
,msg
)))
1079 SplitHelp(msg
,tip
,longhelp
);
1080 m_xmlfile
.Write(_T("\t\t\t<help>")
1081 +longhelp
+_T("</help>\n"));
1083 //look for extra attributes like checked and break
1087 while ((ptoken
!=_T("MENUITEM"))&(ptoken
!=_T("POPUP"))&(ptoken
!=_T("END")))
1091 if (token
==_T("CHECKED"))
1092 m_xmlfile
.Write(_T("\t\t\t<checkable>1</checkable>\n"));
1093 else if (token
==_T("MENUBREAK"))
1095 //m_xmlfile.Write("\t\t\t</break>\n");
1096 else if (token
==_T("GRAYED"))
1099 wxLogError(_T("Unknown Menu Item token:")+token
);
1104 m_xmlfile
.Write(_T("\t\t\t</object>\n"));
1108 //ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
1109 void rc2xml::ParseIconStatic()
1112 wxString varname
,iconname
;
1113 token
= PeekToken();
1114 if (token
.Contains(_T("\"")))
1115 iconname
= GetQuoteField();
1117 iconname
=GetToken();
1121 int x
,y
,width
,height
;
1122 ReadRect(x
,y
,width
,height
);
1124 m_xmlfile
.Write(_T("\t\t<object class=\"wxStaticBitmap\""));
1125 WriteBasicInfo(x
,y
,width
,height
,varname
);
1126 //Save icon as a bitmap
1127 WriteIcon(iconname
);
1128 m_xmlfile
.Write(_T("\t\t</object>\n"));
1131 //IDR_MAINFRAME ICON DISCARDABLE "res\\mfcexample.ico"
1132 void rc2xml::ParseIcon(wxString varname
)
1136 iconfile
=new wxString
;
1139 *iconfile
=GetQuoteField();
1140 m_iconlist
->Append(varname
,iconfile
);
1145 wxString
rc2xml::CleanName(wxString name
)
1148 name
.Replace(_T("id_"),wxEmptyString
);
1149 name
.Replace(_T("idr_"),wxEmptyString
);
1150 name
.Replace(_T("idb_"),wxEmptyString
);
1151 name
.Replace(_T("idc_"),wxEmptyString
);
1153 name
.Replace(_T(".ico"),wxEmptyString
);
1155 name
.Replace(_T(".bmp"),wxEmptyString
);
1158 // And the award for most messed up control goes to...
1159 // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
1160 void rc2xml::ParseStaticBitmap(wxString bitmapname
, wxString varname
)
1167 int x
,y
,width
,height
;
1168 ReadRect(x
,y
,width
,height
);
1170 m_xmlfile
.Write(_T("\t\t<object class=\"wxStaticBitmap\""));
1171 WriteBasicInfo(x
,y
,width
,height
,varname
);
1172 WriteBitmap(bitmapname
);
1173 m_xmlfile
.Write(_T("\t\t</object>\n"));
1177 void rc2xml::ParseNormalMSControl()
1179 wxString label
=GetQuoteField();
1180 wxString varname
=GetToken();
1181 wxString kindctrl
=GetQuoteField();
1182 kindctrl
.MakeUpper();
1184 if (kindctrl
==_T("MSCTLS_UPDOWN32"))
1185 ParseSpinCtrl(label
,varname
);
1186 else if (kindctrl
==_T("MSCTLS_TRACKBAR32"))
1187 ParseSlider(label
,varname
);
1188 else if (kindctrl
==_T("MSCTLS_PROGRESS32"))
1189 ParseProgressBar(label
,varname
);
1190 else if (kindctrl
==_T("SYSTREEVIEW32"))
1191 ParseTreeCtrl(label
,varname
);
1192 else if (kindctrl
==_T("SYSMONTHCAL32"))
1193 ParseCalendar(label
,varname
);
1194 else if (kindctrl
==_T("SYSLISTVIEW32"))
1195 ParseListCtrl(label
,varname
);
1196 else if (kindctrl
==_T("BUTTON"))
1197 ParseCtrlButton(label
,varname
);
1198 else if (kindctrl
==_T("RICHEDIT"))
1199 ParseRichEdit(label
,varname
);
1200 else if (kindctrl
==_T("STATIC"))
1203 wxFileOffset p
= m_rc
.Tell();
1206 if (token
.Find(_T("SS_BITMAP"))!=wxNOT_FOUND
)
1207 ParseStaticBitmap(label
,varname
);
1209 ParseStaticText(label
,varname
);
1211 else if (kindctrl
==_T("EDIT"))
1212 ParseTextCtrl(varname
);
1213 else if (kindctrl
==_T("LISTBOX"))
1214 ParseListBox(varname
);
1215 else if (kindctrl
==_T("COMBOBOX"))
1216 ParseComboBox(varname
);
1219 void rc2xml::ParseWeirdMSControl()
1221 wxString id
= GetToken();
1222 wxString varname
= GetToken();
1223 wxString kindctrl
= GetQuoteField();
1224 kindctrl
.MakeUpper();
1225 // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
1226 if (kindctrl
==_T("STATIC"))
1228 if (PeekToken()==_T("SS_BITMAP"))
1229 ParseStaticBitmap(id
,varname
);
1231 wxLogError(_T("Unknown MS Control Static token"));
1235 //SCROLLBAR IDC_SCROLLBAR1,219,56,10,40,SBS_VERT
1236 void rc2xml::ParseScrollBar()
1242 int x
,y
,width
,height
;
1243 ReadRect(x
,y
,width
,height
);
1248 if (token
.Find(_T("SBS_VERT"))!=wxNOT_FOUND
)
1249 style
=_T("wxSB_VERTICAL");
1250 //Default MFC style is horizontal
1252 style
=_T("wxSB_HORIZONTAL");
1254 m_xmlfile
.Write(_T("\t\t<object class=\"wxScrollBar\""));
1255 WriteBasicInfo(x
,y
,width
,height
,varname
);
1257 m_xmlfile
.Write(_T("\n\t\t</object>\n"));
1260 // CONTROL "Tree1",IDC_TREE1,"SysTreeView32",WS_BORDER | WS_TABSTOP,
1263 void rc2xml::ParseTreeCtrl(wxString
WXUNUSED(label
), wxString varname
)
1266 //while (ReadOrs(token));
1268 int x
,y
,width
,height
;
1269 ReadRect(x
,y
,width
,height
);
1270 m_xmlfile
.Write(_T("\t\t<object class=\"wxTreeCtrl\""));
1271 WriteBasicInfo(x
,y
,width
,height
,varname
);
1272 m_xmlfile
.Write(_T("\t\t</object>\n"));
1275 // CONTROL "MonthCalendar1",IDC_MONTHCALENDAR1,"SysMonthCal32",
1276 //MCS_NOTODAY | WS_TABSTOP,105,71,129,89
1278 void rc2xml::ParseCalendar(wxString
WXUNUSED(label
), wxString varname
)
1281 //while (ReadOrs(token));
1283 int x
,y
,width
,height
;
1284 ReadRect(x
,y
,width
,height
);
1285 m_xmlfile
.Write(_T("\t\t<object class=\"wxCalendarCtrl\""));
1286 WriteBasicInfo(x
,y
,width
,height
,varname
);
1287 m_xmlfile
.Write(_T("\t\t</object>\n"));
1289 // CONTROL "List1",IDC_LIST1,"SysListView32",WS_BORDER | WS_TABSTOP,
1292 void rc2xml::ParseListCtrl(wxString
WXUNUSED(label
), wxString varname
)
1295 //while (ReadOrs(token));
1297 int x
,y
,width
,height
;
1298 ReadRect(x
,y
,width
,height
);
1299 m_xmlfile
.Write(_T("\t\t<object class=\"wxListCtrl\""));
1300 WriteBasicInfo(x
,y
,width
,height
,varname
);
1301 m_xmlfile
.Write(_T("\t\t</object>\n"));
1305 void rc2xml::WriteBitmap(wxString bitmapname
)
1308 wxNode
*node
=m_bitmaplist
->Find(LookUpId(bitmapname
));
1311 m_xmlfile
.Write(_T("\t\t\t<bitmap>missingfile</bitmap>\n"));
1312 wxLogError(_T("Unable to find bitmap:")+bitmapname
);
1316 wxString
*bitmappath
;
1317 bitmappath
=(wxString
*)node
->GetData();
1319 bitmapname
=wxFileNameFromPath(*bitmappath
);
1321 if (!bitmap
.LoadFile(*bitmappath
,wxBITMAP_TYPE_BMP
))
1322 wxLogError(_T("Unable to load bitmap:")+*bitmappath
);
1324 //Make a bitmap file name
1325 bitmapname
=CleanName(bitmapname
);
1326 bitmapname
+=_T(".bmp");
1327 m_xmlfile
.Write(_T("\t\t\t<bitmap>")+bitmapname
+_T("</bitmap>\n"));
1328 bitmap
.SaveFile(m_targetpath
+bitmapname
,wxBITMAP_TYPE_BMP
);
1331 void rc2xml::WriteIcon(wxString iconname
)
1333 wxNode
*node
=m_iconlist
->Find(iconname
);
1336 m_xmlfile
.Write(_T("\t\t\t<bitmap>missing_file</bitmap>\n"));
1337 wxLogError(_T("Unable to find icon:")+iconname
);
1340 iconpath
=(wxString
*)node
->GetData();
1343 if (!icon
.LoadFile(*iconpath
,wxBITMAP_TYPE_ICO
))
1344 wxLogError(_T("Unable to load icon:")+*iconpath
);
1346 bitmap
.CopyFromIcon(icon
);
1350 iconname
=wxFileNameFromPath(*iconpath
);
1351 //Make a bitmap file name
1352 iconname
=CleanName(iconname
);
1353 iconname
+=_T(".bmp");
1354 m_xmlfile
.Write(_T("\t\t\t<bitmap>")+iconname
+_T("</bitmap>\n"));
1355 bitmap
.SaveFile(m_targetpath
+iconname
,wxBITMAP_TYPE_BMP
);
1359 /*Unfortunately sometimes the great MSVC Resource editor decides
1360 to use numbers instead of the word id. I have no idea why they
1361 do this, but that is the way it is.
1363 /* this is a quick and dirty way to parse the resource.h file
1364 it will not recognize #ifdef so it can be easily fooled
1366 void rc2xml::ParseResourceHeader()
1369 //Attempt to load resource.h in current path
1370 if (!r
.Open(_T("resource.h")))
1372 wxLogError(_T("Warining Unable to load resource.h file"));
1378 wxStringTokenizer tok
;
1384 //Read through entire file
1385 for ( str
= r
.GetFirstLine(); !r
.Eof(); str
= r
.GetNextLine() )
1387 if (str
.Find(_T("#define"))!=wxNOT_FOUND
)
1390 //Just ignore #define token
1392 v
=tok
.GetNextToken();
1393 id
=tok
.GetNextToken();
1396 varname
=new wxString
;
1399 m_resourcelist
->Append(n
,varname
);
1409 wxString
rc2xml::LookUpId(wxString id
)
1417 wxNode
*node
=m_resourcelist
->Find(n
);
1422 s
=(wxString
*)node
->GetData();