]>
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()
489 if ((ch
==34)&&(lastch
!='\\'))
491 wxFileOffset p
= m_rc
.Tell();
493 // RC supports "", for embedded quote, as well as \"
505 ReadChar(ch
); // skip
506 if ((ch
=='\n')&&(lastch
=='\\')) // lastch <should> be this
507 phrase
+='n'; // escape
518 void rc2xml::ReadChar(int &ch
)
520 wxFileOffset result
= m_rc
.Tell();
522 if((result
>=m_filesize
))
525 result
= m_rc
.Read(&ch
,1);
527 if( result
== wxInvalidOffset
)
534 void rc2xml::ParseComboBox(wxString varname
)
536 /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
537 WS_VSCROLL | WS_TABSTOP */
538 wxString token
,style
;
539 int x
,y
,width
,height
;
541 GotOrs
= ReadOrs(token
);
542 if (ReadRect(x
,y
,width
,height
))
546 m_xmlfile
.Write(_T("\t\t<object class=\"wxComboBox\""));
547 WriteBasicInfo(x
,y
,width
,height
,varname
);
548 if (token
.Find(_T("CBS_SIMPLE")) != wxNOT_FOUND
)
549 WriteStyle(_T("wxCB_SIMPLE"));
550 if (token
.Find(_T("CBS_SORT")) != wxNOT_FOUND
)
551 WriteStyle(_T("wxCB_SORT"));
552 if (token
.Find(_T("CBS_DISABLENOSCROLL")) != wxNOT_FOUND
)
553 WriteStyle(_T("wxLB_ALWAYS_SB"));
554 m_xmlfile
.Write(_T("\n\t\t</object>\n"));
558 void rc2xml::ParseMenu(wxString varname
)
560 wxString token
=wxEmptyString
;
562 //Write menubar to xml file
563 m_xmlfile
.Write(_T("\t<object class=\"wxMenuBar\""));
564 //Avoid duplicate names this way
565 varname
.Replace(_T("IDR_"),_T("MB_"));
567 m_xmlfile
.Write(_T(">\n"));
569 while ((token
!=_T("BEGIN"))&(token
!=_T("{")))
572 while ((token
!=_T("END"))&(token
!=_T("}")))
577 if (token
==_T("POPUP"))
582 m_xmlfile
.Write(_T("\t</object>\n"));
585 void rc2xml::ParsePopupMenu()
587 static int menucount
=0;
589 wxString token
,name
,msg
,longhelp
,tip
;
590 token
=GetQuoteField();
592 //Remove \t because it causes problems
594 //spot=token.First("\\t");
595 //token=token.Left(spot);
598 //Generate a fake name since RC menus don't have one
599 name
<< _T("Menu_") << menucount
;
600 m_xmlfile
.Write(_T("\t\t<object class=\"wxMenu\""));
602 m_xmlfile
.Write(_T(">\n"));
605 while ((token
!=_T("BEGIN"))&(token
!=_T("{")))
608 while ((token
!=_T("END"))&(token
!=_T("}")))
613 if (token
==_T("POPUP"))
616 if (token
==_T("MENUITEM"))
619 m_xmlfile
.Write(_T("\t\t\t</object>\n"));
622 wxString
rc2xml::PeekToken()
624 wxFileOffset p
= m_rc
.Tell();
625 wxString token
=GetToken();
631 //MS Windows pain in the butt CONTROL
632 void rc2xml::ParseControlMS()
634 wxString token
= PeekToken();
636 if (token
.Contains(_T("\"")))
637 ParseNormalMSControl();
639 ParseWeirdMSControl();
642 /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
643 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
646 void rc2xml::ParseSlider(wxString
WXUNUSED(label
), wxString varname
)
648 wxString token
,style
;
650 if (token
.Find(_T("TBS_VERT"))!=wxNOT_FOUND
)
651 style
+=_T("wxSL_VERTICAL");
652 //MFC RC Default is horizontal
654 style
+=_T("wxSL_HORIZONTAL");
656 int x
,y
,width
,height
;
657 ReadRect(x
,y
,width
,height
);
658 m_xmlfile
.Write(_T("\t\t<object class=\"wxSlider\""));
659 WriteBasicInfo(x
,y
,width
,height
,varname
);
661 m_xmlfile
.Write(_T("\n\t\t</object>\n"));
665 CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
666 WS_BORDER,15,52,154,13
668 void rc2xml::ParseProgressBar(wxString
WXUNUSED(label
), wxString varname
)
670 wxString token
,style
;
673 int x
,y
,width
,height
;
674 ReadRect(x
,y
,width
,height
);
676 //Always horizontal in MFC
677 m_xmlfile
.Write(_T("\t\t<object class=\"wxGauge\""));
678 WriteBasicInfo(x
,y
,width
,height
,varname
);
680 m_xmlfile
.Write(_T("\t\t</object>\n"));
683 bool rc2xml::ReadOrs(wxString
& orstring
)
688 if (token
.IsNumber())
692 while(PeekToken()==_T("|"))
695 orstring
+=GetToken();
697 orstring
+=GetToken();
702 //Is it a checkbutton or a radiobutton or a pushbutton or a groupbox
703 void rc2xml::ParseCtrlButton(wxString label
, wxString varname
)
706 wxFileOffset p
= m_rc
.Tell();
710 if (token
.Find(_T("BS_AUTOCHECKBOX"))!=wxNOT_FOUND
)
711 ParseCheckBox(label
, varname
);
712 else if ((token
.Find(_T("BS_AUTORADIOBUTTON"))!=wxNOT_FOUND
)||
713 (token
.Find(_T("BS_RADIOBUTTON"))!=wxNOT_FOUND
))
714 ParseRadioButton(label
, varname
);
715 else if (token
.Find(_T("BS_GROUPBOX"))!=wxNOT_FOUND
)
716 ParseGroupBox(label
, varname
);
717 else // if ((token.Find("BS_PUSHBUTTON")!=wxNOT_FOUND)||
718 // (token.Find("BS_DEFPUSHBUTTON")!=wxNOT_FOUND))
719 ParsePushButton(label
, varname
); // make default case
722 void rc2xml::WriteSize(int width
, int height
)
725 msg
<< _T(" <size>") << width
<< _T(",") << height
<< _T("d</size>");
726 m_xmlfile
.Write(msg
);
729 void rc2xml::WritePosition(int x
, int y
)
732 msg
<< _T(" <pos>") << x
<< _T(",") << y
<< _T("d</pos>");
733 m_xmlfile
.Write(msg
);
736 void rc2xml::WriteTitle(wxString title
)
739 msg
=_T("\t\t<title>")+title
+_T("</title>\n");
740 m_xmlfile
.Write(msg
);
743 void rc2xml::WriteName(wxString name
)
746 //Try to convert any number ids into names
748 //Replace common MS ids with wxWidgets ids
749 //I didn't do everyone of them
750 if (name
==_T("IDOK"))
752 else if (name
==_T("IDCANCEL"))
753 name
=_T("wxID_CANCEL");
754 else if (name
==_T("IDAPPLY"))
755 name
=_T("wxID_APPLY");
756 else if (name
==_T("ID_FILE_OPEN"))
757 name
=_T("wxID_OPEN");
758 else if (name
==_T("ID_FILE_CLOSE"))
759 name
=_T("wxID_CLOSE");
760 else if (name
==_T("ID_FILE_SAVE"))
761 name
=_T("wxID_SAVE");
762 else if (name
==_T("ID_FILE_SAVE_AS"))
763 name
=_T("wxID_SAVEAS");
764 else if (name
==_T("ID_APP_EXIT"))
765 name
=_T("wxID_EXIT");
766 else if (name
==_T("ID_FILE_PRINT"))
767 name
=_T("wxID_PRINT");
768 else if (name
==_T("ID_FILE_PRINT_PREVIEW"))
769 name
=_T("wxID_PREVIEW");
770 else if (name
==_T("ID_FILE_PRINT_SETUP"))
771 name
=_T("wxID_PRINT_SETUP");
772 else if (name
==_T("ID_APP_ABOUT"))
773 name
=_T("wxID_ABOUT");
774 else if (name
==_T("ID_EDIT_UNDO"))
775 name
=_T("wxID_UNDO");
776 else if (name
==_T("ID_EDIT_CUT"))
778 else if (name
==_T("ID_EDIT_COPY"))
779 name
=_T("wxID_COPY");
780 else if (name
==_T("ID_EDIT_PASTE"))
781 name
=_T("wxID_PASTE");
782 else if (name
==_T("IDYES"))
784 else if (name
==_T("IDNO"))
786 else if (name
==_T("IDHELP"))
787 name
=_T("wxID_HELP");
789 m_xmlfile
.Write(_T(" name= \"")+name
+_T("\""));
792 void rc2xml::WriteLabel(wxString label
)
794 label
.Replace(_T("&"),_T("$"));
795 // changes by MS, handle '<' '>' characters within a label.
796 label
.Replace(_T("<"),_T("<"));
797 label
.Replace(_T(">"),_T(">"));
798 m_xmlfile
.Write(_T("\t\t\t<label>")+label
+_T("</label>\n"));
801 void rc2xml::WriteBasicInfo(int x
, int y
, int width
, int height
, wxString name
)
804 m_xmlfile
.Write(_T(">\n"));
805 m_xmlfile
.Write(_T("\t\t\t"));
807 WriteSize(width
,height
);
808 m_xmlfile
.Write(_T("\n"));
811 void rc2xml::WriteStyle(wxString style
)
813 if (style
.Length()==0)
815 m_xmlfile
.Write(_T("\t\t\t<style>")+style
+_T("</style>\n"));
818 LISTBOX IDC_LIST1,16,89,48,40,LBS_SORT | LBS_MULTIPLESEL |
819 LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
821 void rc2xml::ParseListBox(wxString varname
)
825 while (!token
.IsNumber())
830 int x
,y
,width
,height
;
831 ReadRect(x
,y
,width
,height
);
833 m_xmlfile
.Write(_T("\t\t<object class=\"wxListBox\""));
834 WriteBasicInfo(x
,y
,width
,height
,varname
);
835 m_xmlfile
.Write(_T("\n\t\t</object>\n"));
839 CONTROL "",IDC_RICHEDIT1,"RICHEDIT",ES_AUTOHSCROLL | WS_BORDER |
840 WS_TABSTOP,103,110,40,14
842 void rc2xml::ParseRichEdit(wxString
WXUNUSED(label
), wxString varname
)
845 //while (ReadOrs(token));
847 int x
,y
,width
,height
;
848 ReadRect(x
,y
,width
,height
);
850 //Make it a rich text control
851 style
+=_T("wxTE_MULTILINE ");
852 m_xmlfile
.Write(_T("\t\t<object class=\"wxTextCtrl\""));
853 WriteBasicInfo(x
,y
,width
,height
,varname
);
855 m_xmlfile
.Write(_T("\t\t</object>\n"));
859 CONTROL "Spin1",IDC_SPIN1,"msctls_updown32",UDS_ARROWKEYS,209,72,
862 void rc2xml::ParseSpinCtrl(wxString
WXUNUSED(label
), wxString varname
)
864 wxString token
,style
;
867 if (token
.Find(_T("UDS_HORZ"))!=wxNOT_FOUND
)
868 style
=_T("wxSP_HORIZONTAL");
871 style
=_T("wxSP_VERTICAL");
873 int x
,y
,width
,height
;
874 ReadRect(x
,y
,width
,height
);
875 m_xmlfile
.Write(_T("\t\t<object class=\"wxSpinButton\""));
876 WriteBasicInfo(x
,y
,width
,height
,varname
);
878 m_xmlfile
.Write(_T("\n\t\t</object>\n"));
882 void rc2xml::FirstPass()
884 wxString token
,prevtok
;
888 if (token
==_T("BITMAP"))
889 ParseBitmap(prevtok
);
890 else if (token
==_T("STRINGTABLE"))
891 ParseStringTable(prevtok
);
892 else if (token
==_T("ICON"))
899 void rc2xml::ParseBitmap(wxString varname
)
902 wxString
*bitmapfile
;
905 //Microsoft notation?
906 if (token
==_T("DISCARDABLE"))
911 bitmapfile
=new wxString
;
912 *bitmapfile
=GetQuoteField();
913 m_bitmaplist
->Append(varname
,bitmapfile
);
918 void rc2xml::SecondPass()
920 wxString token
,prevtok
;
924 if ((token
==_T("DIALOG"))||(token
==_T("DIALOGEX")))
925 ParseDialog(prevtok
);
926 else if (token
==_T("MENU"))
928 else if (token
==_T("TOOLBAR"))
929 ParseToolBar(prevtok
);
936 void rc2xml::ParseToolBar(wxString varname
)
940 wxASSERT_MSG(token
==_T("DISCARDABLE"),_T("Error in toolbar parsing"));
941 //Look up bitmap for toolbar and load
942 wxNode
*node
=m_bitmaplist
->Find(LookUpId(varname
));
943 wxString
*bitmappath
;
944 bitmappath
=(wxString
*)node
->GetData();
946 if (!bitmap
.LoadFile(*bitmappath
,wxBITMAP_TYPE_BMP
))
947 wxLogError(_T("Unable to load bitmap:")+*bitmappath
);
949 //Write toolbar to xml file
950 m_xmlfile
.Write(_T("\t<object class=\"wxToolBar\""));
951 //Avoid duplicate names this way
952 varname
.Replace(_T("IDR_"),_T("TB_"));
954 m_xmlfile
.Write(_T(">\n"));
956 style
+=_T("wxTB_FLAT");
960 //Grab width and height
962 width
=wxAtoi(GetToken());
963 height
=wxAtoi(GetToken());
966 wxString buttonname
,msg
,tip
,longhelp
;
968 while ((token
!=_T("BEGIN"))&(token
!=_T("{")))
971 while ((token
!=_T("END"))&(token
!=_T("}")))
973 if (token
==_T("BUTTON"))
975 buttonname
=GetToken();
976 m_xmlfile
.Write(_T("\t\t\t<object class=\"tool\""));
977 WriteName(buttonname
);
978 m_xmlfile
.Write(_T(">\n"));
979 //Write tool tip if any
980 if (LookUpString(buttonname
,msg
))
982 SplitHelp(msg
,tip
,longhelp
);
983 m_xmlfile
.Write(_T("\t\t\t\t<tooltip>")+tip
+_T("</tooltip>\n"));
984 m_xmlfile
.Write(_T("\t\t<longhelp>")+longhelp
+_T("</longhelp>\n"));
986 //Make a bitmap file name
987 buttonname
=CleanName(buttonname
);
988 buttonname
+=_T(".bmp");
989 m_xmlfile
.Write(_T("\t\t\t\t<bitmap>")+buttonname
+_T("</bitmap>\n"));
990 WriteToolButton(buttonname
,c
,width
,height
,bitmap
);
991 m_xmlfile
.Write(_T("\t\t\t</object>\n"));
994 else if (token
==_T("SEPARATOR"))
996 m_xmlfile
.Write(_T("\t\t\t<object class=\"separator\"/>\n"));
1000 m_xmlfile
.Write(_T("\t</object>\n"));
1003 //Extract bitmaps from larger toolbar bitmap
1004 void rc2xml::WriteToolButton(wxString name
,int index
, int width
, int height
, wxBitmap bitmap
)
1008 wxRect
r(x
,0,width
,height
);
1010 little
=bitmap
.GetSubBitmap(r
);
1011 little
.SaveFile(m_targetpath
+name
,wxBITMAP_TYPE_BMP
);
1014 void rc2xml::ParseStringTable(wxString
WXUNUSED(varname
))
1018 while ((token
!=_T("BEGIN"))&(token
!=_T("{")))
1023 while ((token
!=_T("END"))&(token
!=_T("}")))
1026 *msg
=GetStringQuote();
1027 m_stringtable
->Append(token
,msg
);
1032 bool rc2xml::LookUpString(wxString strid
,wxString
& st
)
1034 wxNode
*node
=m_stringtable
->Find(strid
);
1039 s
=(wxString
*)node
->GetData();
1045 bool rc2xml::SplitHelp(wxString msg
, wxString
&shorthelp
, wxString
&longhelp
)
1048 spot
=msg
.Find(_T("\\n"));
1049 if (spot
==wxNOT_FOUND
)
1055 longhelp
=msg
.Left(spot
);
1056 spot
=msg
.Length()-spot
-2;
1057 shorthelp
=msg
.Right(spot
);
1061 void rc2xml::ParseMenuItem()
1063 wxString token
,name
,msg
,tip
,longhelp
;
1065 if (PeekToken()==_T("SEPARATOR"))
1067 m_xmlfile
.Write(_T("\t\t\t<object class=\"separator\"/>\n"));
1071 token
=GetQuoteField();
1073 //Remove \t because it causes problems
1074 //spot=token.First("\\t");
1075 //token=token.Left(spot);
1076 m_xmlfile
.Write(_T("\t\t\t<object class=\"wxMenuItem\""));
1078 m_xmlfile
.Write(_T(">\n"));
1080 //Look up help if any listed in stringtable
1081 //can't assume numbers correlate, restrict to string identifiers
1082 if ((!name
.IsNumber())&&(LookUpString(name
,msg
)))
1084 SplitHelp(msg
,tip
,longhelp
);
1085 m_xmlfile
.Write(_T("\t\t\t<help>")
1086 +longhelp
+_T("</help>\n"));
1088 //look for extra attributes like checked and break
1092 while ((ptoken
!=_T("MENUITEM"))&(ptoken
!=_T("POPUP"))&(ptoken
!=_T("END")))
1096 if (token
==_T("CHECKED"))
1097 m_xmlfile
.Write(_T("\t\t\t<checkable>1</checkable>\n"));
1098 else if (token
==_T("MENUBREAK"))
1100 //m_xmlfile.Write("\t\t\t</break>\n");
1101 else if (token
==_T("GRAYED"))
1104 wxLogError(_T("Unknown Menu Item token:")+token
);
1109 m_xmlfile
.Write(_T("\t\t\t</object>\n"));
1113 //ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
1114 void rc2xml::ParseIconStatic()
1117 wxString varname
,iconname
;
1118 token
= PeekToken();
1119 if (token
.Contains(_T("\"")))
1120 iconname
= GetQuoteField();
1122 iconname
=GetToken();
1126 int x
,y
,width
,height
;
1127 ReadRect(x
,y
,width
,height
);
1129 m_xmlfile
.Write(_T("\t\t<object class=\"wxStaticBitmap\""));
1130 WriteBasicInfo(x
,y
,width
,height
,varname
);
1131 //Save icon as a bitmap
1132 WriteIcon(iconname
);
1133 m_xmlfile
.Write(_T("\t\t</object>\n"));
1136 //IDR_MAINFRAME ICON DISCARDABLE "res\\mfcexample.ico"
1137 void rc2xml::ParseIcon(wxString varname
)
1141 iconfile
=new wxString
;
1144 *iconfile
=GetQuoteField();
1145 m_iconlist
->Append(varname
,iconfile
);
1150 wxString
rc2xml::CleanName(wxString name
)
1153 name
.Replace(_T("id_"),wxEmptyString
);
1154 name
.Replace(_T("idr_"),wxEmptyString
);
1155 name
.Replace(_T("idb_"),wxEmptyString
);
1156 name
.Replace(_T("idc_"),wxEmptyString
);
1158 name
.Replace(_T(".ico"),wxEmptyString
);
1160 name
.Replace(_T(".bmp"),wxEmptyString
);
1163 // And the award for most messed up control goes to...
1164 // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
1165 void rc2xml::ParseStaticBitmap(wxString bitmapname
, wxString varname
)
1172 int x
,y
,width
,height
;
1173 ReadRect(x
,y
,width
,height
);
1175 m_xmlfile
.Write(_T("\t\t<object class=\"wxStaticBitmap\""));
1176 WriteBasicInfo(x
,y
,width
,height
,varname
);
1177 WriteBitmap(bitmapname
);
1178 m_xmlfile
.Write(_T("\t\t</object>\n"));
1182 void rc2xml::ParseNormalMSControl()
1184 wxString label
=GetQuoteField();
1185 wxString varname
=GetToken();
1186 wxString kindctrl
=GetQuoteField();
1187 kindctrl
.MakeUpper();
1189 if (kindctrl
==_T("MSCTLS_UPDOWN32"))
1190 ParseSpinCtrl(label
,varname
);
1191 else if (kindctrl
==_T("MSCTLS_TRACKBAR32"))
1192 ParseSlider(label
,varname
);
1193 else if (kindctrl
==_T("MSCTLS_PROGRESS32"))
1194 ParseProgressBar(label
,varname
);
1195 else if (kindctrl
==_T("SYSTREEVIEW32"))
1196 ParseTreeCtrl(label
,varname
);
1197 else if (kindctrl
==_T("SYSMONTHCAL32"))
1198 ParseCalendar(label
,varname
);
1199 else if (kindctrl
==_T("SYSLISTVIEW32"))
1200 ParseListCtrl(label
,varname
);
1201 else if (kindctrl
==_T("BUTTON"))
1202 ParseCtrlButton(label
,varname
);
1203 else if (kindctrl
==_T("RICHEDIT"))
1204 ParseRichEdit(label
,varname
);
1205 else if (kindctrl
==_T("STATIC"))
1208 wxFileOffset p
= m_rc
.Tell();
1211 if (token
.Find(_T("SS_BITMAP"))!=wxNOT_FOUND
)
1212 ParseStaticBitmap(label
,varname
);
1214 ParseStaticText(label
,varname
);
1216 else if (kindctrl
==_T("EDIT"))
1217 ParseTextCtrl(varname
);
1218 else if (kindctrl
==_T("LISTBOX"))
1219 ParseListBox(varname
);
1220 else if (kindctrl
==_T("COMBOBOX"))
1221 ParseComboBox(varname
);
1224 void rc2xml::ParseWeirdMSControl()
1226 wxString id
= GetToken();
1227 wxString varname
= GetToken();
1228 wxString kindctrl
= GetQuoteField();
1229 kindctrl
.MakeUpper();
1230 // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
1231 if (kindctrl
==_T("STATIC"))
1233 if (PeekToken()==_T("SS_BITMAP"))
1234 ParseStaticBitmap(id
,varname
);
1236 wxLogError(_T("Unknown MS Control Static token"));
1240 //SCROLLBAR IDC_SCROLLBAR1,219,56,10,40,SBS_VERT
1241 void rc2xml::ParseScrollBar()
1247 int x
,y
,width
,height
;
1248 ReadRect(x
,y
,width
,height
);
1253 if (token
.Find(_T("SBS_VERT"))!=wxNOT_FOUND
)
1254 style
=_T("wxSB_VERTICAL");
1255 //Default MFC style is horizontal
1257 style
=_T("wxSB_HORIZONTAL");
1259 m_xmlfile
.Write(_T("\t\t<object class=\"wxScrollBar\""));
1260 WriteBasicInfo(x
,y
,width
,height
,varname
);
1262 m_xmlfile
.Write(_T("\n\t\t</object>\n"));
1265 // CONTROL "Tree1",IDC_TREE1,"SysTreeView32",WS_BORDER | WS_TABSTOP,
1268 void rc2xml::ParseTreeCtrl(wxString
WXUNUSED(label
), wxString varname
)
1271 //while (ReadOrs(token));
1273 int x
,y
,width
,height
;
1274 ReadRect(x
,y
,width
,height
);
1275 m_xmlfile
.Write(_T("\t\t<object class=\"wxTreeCtrl\""));
1276 WriteBasicInfo(x
,y
,width
,height
,varname
);
1277 m_xmlfile
.Write(_T("\t\t</object>\n"));
1280 // CONTROL "MonthCalendar1",IDC_MONTHCALENDAR1,"SysMonthCal32",
1281 //MCS_NOTODAY | WS_TABSTOP,105,71,129,89
1283 void rc2xml::ParseCalendar(wxString
WXUNUSED(label
), wxString varname
)
1286 //while (ReadOrs(token));
1288 int x
,y
,width
,height
;
1289 ReadRect(x
,y
,width
,height
);
1290 m_xmlfile
.Write(_T("\t\t<object class=\"wxCalendarCtrl\""));
1291 WriteBasicInfo(x
,y
,width
,height
,varname
);
1292 m_xmlfile
.Write(_T("\t\t</object>\n"));
1294 // CONTROL "List1",IDC_LIST1,"SysListView32",WS_BORDER | WS_TABSTOP,
1297 void rc2xml::ParseListCtrl(wxString
WXUNUSED(label
), wxString varname
)
1300 //while (ReadOrs(token));
1302 int x
,y
,width
,height
;
1303 ReadRect(x
,y
,width
,height
);
1304 m_xmlfile
.Write(_T("\t\t<object class=\"wxListCtrl\""));
1305 WriteBasicInfo(x
,y
,width
,height
,varname
);
1306 m_xmlfile
.Write(_T("\t\t</object>\n"));
1310 void rc2xml::WriteBitmap(wxString bitmapname
)
1313 wxNode
*node
=m_bitmaplist
->Find(LookUpId(bitmapname
));
1316 m_xmlfile
.Write(_T("\t\t\t<bitmap>missingfile</bitmap>\n"));
1317 wxLogError(_T("Unable to find bitmap:")+bitmapname
);
1321 wxString
*bitmappath
;
1322 bitmappath
=(wxString
*)node
->GetData();
1324 bitmapname
=wxFileNameFromPath(*bitmappath
);
1326 if (!bitmap
.LoadFile(*bitmappath
,wxBITMAP_TYPE_BMP
))
1327 wxLogError(_T("Unable to load bitmap:")+*bitmappath
);
1329 //Make a bitmap file name
1330 bitmapname
=CleanName(bitmapname
);
1331 bitmapname
+=_T(".bmp");
1332 m_xmlfile
.Write(_T("\t\t\t<bitmap>")+bitmapname
+_T("</bitmap>\n"));
1333 bitmap
.SaveFile(m_targetpath
+bitmapname
,wxBITMAP_TYPE_BMP
);
1336 void rc2xml::WriteIcon(wxString iconname
)
1338 wxNode
*node
=m_iconlist
->Find(iconname
);
1341 m_xmlfile
.Write(_T("\t\t\t<bitmap>missing_file</bitmap>\n"));
1342 wxLogError(_T("Unable to find icon:")+iconname
);
1345 iconpath
=(wxString
*)node
->GetData();
1348 if (!icon
.LoadFile(*iconpath
,wxBITMAP_TYPE_ICO
))
1349 wxLogError(_T("Unable to load icon:")+*iconpath
);
1351 bitmap
.CopyFromIcon(icon
);
1355 iconname
=wxFileNameFromPath(*iconpath
);
1356 //Make a bitmap file name
1357 iconname
=CleanName(iconname
);
1358 iconname
+=_T(".bmp");
1359 m_xmlfile
.Write(_T("\t\t\t<bitmap>")+iconname
+_T("</bitmap>\n"));
1360 bitmap
.SaveFile(m_targetpath
+iconname
,wxBITMAP_TYPE_BMP
);
1364 /*Unfortunately sometimes the great MSVC Resource editor decides
1365 to use numbers instead of the word id. I have no idea why they
1366 do this, but that is the way it is.
1368 /* this is a quick and dirty way to parse the resource.h file
1369 it will not recognize #ifdef so it can be easily fooled
1371 void rc2xml::ParseResourceHeader()
1374 //Attempt to load resource.h in current path
1375 if (!r
.Open(_T("resource.h")))
1377 wxLogError(_T("Warining Unable to load resource.h file"));
1383 wxStringTokenizer tok
;
1389 //Read through entire file
1390 for ( str
= r
.GetFirstLine(); !r
.Eof(); str
= r
.GetNextLine() )
1392 if (str
.Find(_T("#define"))!=wxNOT_FOUND
)
1395 //Just ignore #define token
1397 v
=tok
.GetNextToken();
1398 id
=tok
.GetNextToken();
1401 varname
=new wxString
;
1404 m_resourcelist
->Append(n
,varname
);
1414 wxString
rc2xml::LookUpId(wxString id
)
1422 wxNode
*node
=m_resourcelist
->Find(n
);
1427 s
=(wxString
*)node
->GetData();