]>
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()
455 // string in stringtable may contain embedded quotes
456 // escape characters retained to allow strings to be rewritten
457 wxString
rc2xml::GetStringQuote()
470 if ((ch
==34)&&(lastch
!='\\'))
474 // RC supports "", for embedded quote, as well as \"
486 ReadChar(ch
); // skip
487 if ((ch
=='\n')&&(lastch
=='\\')) // lastch <should> be this
488 phrase
+='n'; // escape
498 void rc2xml::ReadChar(int &ch
)
503 if((result
>=m_filesize
))
506 result
=m_rc
.Read(&ch
,1);
515 void rc2xml::ParseComboBox(wxString varname
)
517 /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
518 WS_VSCROLL | WS_TABSTOP */
519 wxString token
,style
;
520 int x
,y
,width
,height
;
522 GotOrs
= ReadOrs(token
);
523 if (ReadRect(x
,y
,width
,height
))
527 m_xmlfile
.Write(_T("\t\t<object class=\"wxComboBox\""));
528 WriteBasicInfo(x
,y
,width
,height
,varname
);
529 if (token
.Find(_T("CBS_SIMPLE")) != wxNOT_FOUND
)
530 WriteStyle(_T("wxCB_SIMPLE"));
531 if (token
.Find(_T("CBS_SORT")) != wxNOT_FOUND
)
532 WriteStyle(_T("wxCB_SORT"));
533 if (token
.Find(_T("CBS_DISABLENOSCROLL")) != wxNOT_FOUND
)
534 WriteStyle(_T("wxLB_ALWAYS_SB"));
535 m_xmlfile
.Write(_T("\n\t\t</object>\n"));
539 void rc2xml::ParseMenu(wxString varname
)
541 wxString token
=wxEmptyString
;
543 //Write menubar to xml file
544 m_xmlfile
.Write(_T("\t<object class=\"wxMenuBar\""));
545 //Avoid duplicate names this way
546 varname
.Replace(_T("IDR_"),_T("MB_"));
548 m_xmlfile
.Write(_T(">\n"));
550 while ((token
!=_T("BEGIN"))&(token
!=_T("{")))
553 while ((token
!=_T("END"))&(token
!=_T("}")))
558 if (token
==_T("POPUP"))
563 m_xmlfile
.Write(_T("\t</object>\n"));
566 void rc2xml::ParsePopupMenu()
568 static int menucount
=0;
570 wxString token
,name
,msg
,longhelp
,tip
;
571 token
=GetQuoteField();
573 //Remove \t because it causes problems
575 //spot=token.First("\\t");
576 //token=token.Left(spot);
579 //Generate a fake name since RC menus don't have one
580 name
<< _T("Menu_") << menucount
;
581 m_xmlfile
.Write(_T("\t\t<object class=\"wxMenu\""));
583 m_xmlfile
.Write(_T(">\n"));
586 while ((token
!=_T("BEGIN"))&(token
!=_T("{")))
589 while ((token
!=_T("END"))&(token
!=_T("}")))
594 if (token
==_T("POPUP"))
597 if (token
==_T("MENUITEM"))
600 m_xmlfile
.Write(_T("\t\t\t</object>\n"));
603 wxString
rc2xml::PeekToken()
613 //MS Windows pain in the butt CONTROL
614 void rc2xml::ParseControlMS()
616 wxString label
,varname
,kindctrl
,token
;
619 if (token
.Contains(_T("\"")))
620 ParseNormalMSControl();
622 ParseWeirdMSControl();
626 /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
627 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
630 void rc2xml::ParseSlider(wxString
WXUNUSED(label
), wxString varname
)
632 wxString token
,style
;
634 if (token
.Find(_T("TBS_VERT"))!=wxNOT_FOUND
)
635 style
+=_T("wxSL_VERTICAL");
636 //MFC RC Default is horizontal
638 style
+=_T("wxSL_HORIZONTAL");
640 int x
,y
,width
,height
;
641 ReadRect(x
,y
,width
,height
);
642 m_xmlfile
.Write(_T("\t\t<object class=\"wxSlider\""));
643 WriteBasicInfo(x
,y
,width
,height
,varname
);
645 m_xmlfile
.Write(_T("\n\t\t</object>\n"));
649 CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
650 WS_BORDER,15,52,154,13
652 void rc2xml::ParseProgressBar(wxString
WXUNUSED(label
), wxString varname
)
654 wxString token
,style
;
657 int x
,y
,width
,height
;
658 ReadRect(x
,y
,width
,height
);
660 //Always horizontal in MFC
661 m_xmlfile
.Write(_T("\t\t<object class=\"wxGauge\""));
662 WriteBasicInfo(x
,y
,width
,height
,varname
);
664 m_xmlfile
.Write(_T("\t\t</object>\n"));
667 bool rc2xml::ReadOrs(wxString
& orstring
)
672 if (token
.IsNumber())
676 while(PeekToken()==_T("|"))
679 orstring
+=GetToken();
681 orstring
+=GetToken();
686 //Is it a checkbutton or a radiobutton or a pushbutton or a groupbox
687 void rc2xml::ParseCtrlButton(wxString label
, wxString varname
)
695 if (token
.Find(_T("BS_AUTOCHECKBOX"))!=wxNOT_FOUND
)
696 ParseCheckBox(label
, varname
);
697 else if ((token
.Find(_T("BS_AUTORADIOBUTTON"))!=wxNOT_FOUND
)||
698 (token
.Find(_T("BS_RADIOBUTTON"))!=wxNOT_FOUND
))
699 ParseRadioButton(label
, varname
);
700 else if (token
.Find(_T("BS_GROUPBOX"))!=wxNOT_FOUND
)
701 ParseGroupBox(label
, varname
);
702 else // if ((token.Find("BS_PUSHBUTTON")!=wxNOT_FOUND)||
703 // (token.Find("BS_DEFPUSHBUTTON")!=wxNOT_FOUND))
704 ParsePushButton(label
, varname
); // make default case
707 void rc2xml::WriteSize(int width
, int height
)
710 msg
<< _T(" <size>") << width
<< _T(",") << height
<< _T("d</size>");
711 m_xmlfile
.Write(msg
);
714 void rc2xml::WritePosition(int x
, int y
)
717 msg
<< _T(" <pos>") << x
<< _T(",") << y
<< _T("d</pos>");
718 m_xmlfile
.Write(msg
);
721 void rc2xml::WriteTitle(wxString title
)
724 msg
=_T("\t\t<title>")+title
+_T("</title>\n");
725 m_xmlfile
.Write(msg
);
728 void rc2xml::WriteName(wxString name
)
731 //Try to convert any number ids into names
733 //Replace common MS ids with wxWidgets ids
734 //I didn't do everyone of them
735 if (name
==_T("IDOK"))
737 else if (name
==_T("IDCANCEL"))
738 name
=_T("wxID_CANCEL");
739 else if (name
==_T("IDAPPLY"))
740 name
=_T("wxID_APPLY");
741 else if (name
==_T("ID_FILE_OPEN"))
742 name
=_T("wxID_OPEN");
743 else if (name
==_T("ID_FILE_CLOSE"))
744 name
=_T("wxID_CLOSE");
745 else if (name
==_T("ID_FILE_SAVE"))
746 name
=_T("wxID_SAVE");
747 else if (name
==_T("ID_FILE_SAVE_AS"))
748 name
=_T("wxID_SAVEAS");
749 else if (name
==_T("ID_APP_EXIT"))
750 name
=_T("wxID_EXIT");
751 else if (name
==_T("ID_FILE_PRINT"))
752 name
=_T("wxID_PRINT");
753 else if (name
==_T("ID_FILE_PRINT_PREVIEW"))
754 name
=_T("wxID_PREVIEW");
755 else if (name
==_T("ID_FILE_PRINT_SETUP"))
756 name
=_T("wxID_PRINT_SETUP");
757 else if (name
==_T("ID_APP_ABOUT"))
758 name
=_T("wxID_ABOUT");
759 else if (name
==_T("ID_EDIT_UNDO"))
760 name
=_T("wxID_UNDO");
761 else if (name
==_T("ID_EDIT_CUT"))
763 else if (name
==_T("ID_EDIT_COPY"))
764 name
=_T("wxID_COPY");
765 else if (name
==_T("ID_EDIT_PASTE"))
766 name
=_T("wxID_PASTE");
767 else if (name
==_T("IDYES"))
769 else if (name
==_T("IDNO"))
771 else if (name
==_T("IDHELP"))
772 name
=_T("wxID_HELP");
774 m_xmlfile
.Write(_T(" name= \"")+name
+_T("\""));
777 void rc2xml::WriteLabel(wxString label
)
779 label
.Replace(_T("&"),_T("$"));
780 m_xmlfile
.Write(_T("\t\t\t<label>")+label
+_T("</label>\n"));
783 void rc2xml::WriteBasicInfo(int x
, int y
, int width
, int height
, wxString name
)
786 m_xmlfile
.Write(_T(">\n"));
787 m_xmlfile
.Write(_T("\t\t\t"));
789 WriteSize(width
,height
);
790 m_xmlfile
.Write(_T("\n"));
793 void rc2xml::WriteStyle(wxString style
)
795 if (style
.Length()==0)
797 m_xmlfile
.Write(_T("\t\t\t<style>")+style
+_T("</style>\n"));
800 LISTBOX IDC_LIST1,16,89,48,40,LBS_SORT | LBS_MULTIPLESEL |
801 LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
803 void rc2xml::ParseListBox(wxString varname
)
807 while (!token
.IsNumber())
812 int x
,y
,width
,height
;
813 ReadRect(x
,y
,width
,height
);
815 m_xmlfile
.Write(_T("\t\t<object class=\"wxListBox\""));
816 WriteBasicInfo(x
,y
,width
,height
,varname
);
817 m_xmlfile
.Write(_T("\n\t\t</object>\n"));
821 CONTROL "",IDC_RICHEDIT1,"RICHEDIT",ES_AUTOHSCROLL | WS_BORDER |
822 WS_TABSTOP,103,110,40,14
824 void rc2xml::ParseRichEdit(wxString label
, wxString varname
)
827 //while (ReadOrs(token));
829 int x
,y
,width
,height
;
830 ReadRect(x
,y
,width
,height
);
832 //Make it a rich text control
833 style
+=_T("wxTE_MULTILINE ");
834 m_xmlfile
.Write(_T("\t\t<object class=\"wxTextCtrl\""));
835 WriteBasicInfo(x
,y
,width
,height
,varname
);
837 m_xmlfile
.Write(_T("\t\t</object>\n"));
841 CONTROL "Spin1",IDC_SPIN1,"msctls_updown32",UDS_ARROWKEYS,209,72,
844 void rc2xml::ParseSpinCtrl(wxString
WXUNUSED(label
), wxString varname
)
846 wxString token
,style
;
849 if (token
.Find(_T("UDS_HORZ"))!=wxNOT_FOUND
)
850 style
=_T("wxSP_HORIZONTAL");
853 style
=_T("wxSP_VERTICAL");
855 int x
,y
,width
,height
;
856 ReadRect(x
,y
,width
,height
);
857 m_xmlfile
.Write(_T("\t\t<object class=\"wxSpinButton\""));
858 WriteBasicInfo(x
,y
,width
,height
,varname
);
860 m_xmlfile
.Write(_T("\n\t\t</object>\n"));
864 void rc2xml::FirstPass()
866 wxString token
,prevtok
;
870 if (token
==_T("BITMAP"))
871 ParseBitmap(prevtok
);
872 else if (token
==_T("STRINGTABLE"))
873 ParseStringTable(prevtok
);
874 else if (token
==_T("ICON"))
881 void rc2xml::ParseBitmap(wxString varname
)
883 wxString token
,*bitmapfile
;
886 //Microsoft notation?
887 if (token
==_T("DISCARDABLE"))
892 bitmapfile
=new wxString
;
893 *bitmapfile
=GetQuoteField();
894 m_bitmaplist
->Append(varname
,bitmapfile
);
899 void rc2xml::SecondPass()
901 wxString token
,prevtok
;
905 if ((token
==_T("DIALOG"))||(token
==_T("DIALOGEX")))
906 ParseDialog(prevtok
);
907 else if (token
==_T("MENU"))
909 else if (token
==_T("TOOLBAR"))
910 ParseToolBar(prevtok
);
917 void rc2xml::ParseToolBar(wxString varname
)
921 wxASSERT_MSG(token
==_T("DISCARDABLE"),_T("Error in toolbar parsing"));
922 //Look up bitmap for toolbar and load
923 wxNode
*node
=m_bitmaplist
->Find(LookUpId(varname
));
924 wxString
*bitmappath
;
925 bitmappath
=(wxString
*)node
->GetData();
927 if (!bitmap
.LoadFile(*bitmappath
,wxBITMAP_TYPE_BMP
))
928 wxLogError(_T("Unable to load bitmap:")+*bitmappath
);
930 //Write toolbar to xml file
931 m_xmlfile
.Write(_T("\t<object class=\"wxToolBar\""));
932 //Avoid duplicate names this way
933 varname
.Replace(_T("IDR_"),_T("TB_"));
935 m_xmlfile
.Write(_T(">\n"));
937 style
+=_T("wxTB_FLAT");
941 //Grab width and height
943 width
=wxAtoi(GetToken());
944 height
=wxAtoi(GetToken());
947 wxString buttonname
,msg
,tip
,longhelp
;
949 while ((token
!=_T("BEGIN"))&(token
!=_T("{")))
952 while ((token
!=_T("END"))&(token
!=_T("}")))
954 if (token
==_T("BUTTON"))
956 buttonname
=GetToken();
957 m_xmlfile
.Write(_T("\t\t\t<object class=\"tool\""));
958 WriteName(buttonname
);
959 m_xmlfile
.Write(_T(">\n"));
960 //Write tool tip if any
961 if (LookUpString(buttonname
,msg
))
963 SplitHelp(msg
,tip
,longhelp
);
964 m_xmlfile
.Write(_T("\t\t\t\t<tooltip>")+tip
+_T("</tooltip>\n"));
965 m_xmlfile
.Write(_T("\t\t<longhelp>")+longhelp
+_T("</longhelp>\n"));
967 //Make a bitmap file name
968 buttonname
=CleanName(buttonname
);
969 buttonname
+=_T(".bmp");
970 m_xmlfile
.Write(_T("\t\t\t\t<bitmap>")+buttonname
+_T("</bitmap>\n"));
971 WriteToolButton(buttonname
,c
,width
,height
,bitmap
);
972 m_xmlfile
.Write(_T("\t\t\t</object>\n"));
975 else if (token
==_T("SEPARATOR"))
977 m_xmlfile
.Write(_T("\t\t\t<object class=\"separator\"/>\n"));
981 m_xmlfile
.Write(_T("\t</object>\n"));
984 //Extract bitmaps from larger toolbar bitmap
985 void rc2xml::WriteToolButton(wxString name
,int index
, int width
, int height
, wxBitmap bitmap
)
989 wxRect
r(x
,0,width
,height
);
991 little
=bitmap
.GetSubBitmap(r
);
992 little
.SaveFile(m_targetpath
+name
,wxBITMAP_TYPE_BMP
);
995 void rc2xml::ParseStringTable(wxString varname
)
999 while ((token
!=_T("BEGIN"))&(token
!=_T("{")))
1004 while ((token
!=_T("END"))&(token
!=_T("}")))
1007 *msg
=GetStringQuote();
1008 m_stringtable
->Append(token
,msg
);
1014 bool rc2xml::LookUpString(wxString strid
,wxString
& st
)
1016 wxNode
*node
=m_stringtable
->Find(strid
);
1021 s
=(wxString
*)node
->GetData();
1027 bool rc2xml::SplitHelp(wxString msg
, wxString
&shorthelp
, wxString
&longhelp
)
1030 spot
=msg
.Find(_T("\\n"));
1031 if (spot
==wxNOT_FOUND
)
1037 longhelp
=msg
.Left(spot
);
1038 spot
=msg
.Length()-spot
-2;
1039 shorthelp
=msg
.Right(spot
);
1043 void rc2xml::ParseMenuItem()
1045 wxString token
,name
,msg
,tip
,longhelp
;
1047 if (PeekToken()==_T("SEPARATOR"))
1049 m_xmlfile
.Write(_T("\t\t\t<object class=\"separator\"/>\n"));
1053 token
=GetQuoteField();
1055 //Remove \t because it causes problems
1056 //spot=token.First("\\t");
1057 //token=token.Left(spot);
1058 m_xmlfile
.Write(_T("\t\t\t<object class=\"wxMenuItem\""));
1060 m_xmlfile
.Write(_T(">\n"));
1062 //Look up help if any listed in stringtable
1063 //can't assume numbers correlate, restrict to string identifiers
1064 if ((!name
.IsNumber())&&(LookUpString(name
,msg
)))
1066 SplitHelp(msg
,tip
,longhelp
);
1067 m_xmlfile
.Write(_T("\t\t\t<help>")
1068 +longhelp
+_T("</help>\n"));
1070 //look for extra attributes like checked and break
1074 while ((ptoken
!=_T("MENUITEM"))&(ptoken
!=_T("POPUP"))&(ptoken
!=_T("END")))
1078 if (token
==_T("CHECKED"))
1079 m_xmlfile
.Write(_T("\t\t\t<checkable>1</checkable>\n"));
1080 else if (token
==_T("MENUBREAK"))
1082 //m_xmlfile.Write("\t\t\t</break>\n");
1083 else if (token
==_T("GRAYED"))
1086 wxLogError(_T("Unknown Menu Item token:")+token
);
1091 m_xmlfile
.Write(_T("\t\t\t</object>\n"));
1095 //ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
1096 void rc2xml::ParseIconStatic()
1099 wxString varname
,iconname
;
1100 token
= PeekToken();
1101 if (token
.Contains(_T("\"")))
1102 iconname
= GetQuoteField();
1104 iconname
=GetToken();
1108 int x
,y
,width
,height
;
1109 ReadRect(x
,y
,width
,height
);
1111 m_xmlfile
.Write(_T("\t\t<object class=\"wxStaticBitmap\""));
1112 WriteBasicInfo(x
,y
,width
,height
,varname
);
1113 //Save icon as a bitmap
1114 WriteIcon(iconname
);
1115 m_xmlfile
.Write(_T("\t\t</object>\n"));
1118 //IDR_MAINFRAME ICON DISCARDABLE "res\\mfcexample.ico"
1119 void rc2xml::ParseIcon(wxString varname
)
1121 wxString token
,*iconfile
;
1122 iconfile
=new wxString
;
1125 *iconfile
=GetQuoteField();
1126 m_iconlist
->Append(varname
,iconfile
);
1131 wxString
rc2xml::CleanName(wxString name
)
1134 name
.Replace(_T("id_"),wxEmptyString
);
1135 name
.Replace(_T("idr_"),wxEmptyString
);
1136 name
.Replace(_T("idb_"),wxEmptyString
);
1137 name
.Replace(_T("idc_"),wxEmptyString
);
1139 name
.Replace(_T(".ico"),wxEmptyString
);
1141 name
.Replace(_T(".bmp"),wxEmptyString
);
1144 // And the award for most messed up control goes to...
1145 // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
1146 void rc2xml::ParseStaticBitmap(wxString bitmapname
, wxString varname
)
1153 int x
,y
,width
,height
;
1154 ReadRect(x
,y
,width
,height
);
1156 m_xmlfile
.Write(_T("\t\t<object class=\"wxStaticBitmap\""));
1157 WriteBasicInfo(x
,y
,width
,height
,varname
);
1158 WriteBitmap(bitmapname
);
1159 m_xmlfile
.Write(_T("\t\t</object>\n"));
1163 void rc2xml::ParseNormalMSControl()
1165 wxString label
,varname
,kindctrl
;
1167 label
=GetQuoteField();
1169 kindctrl
=GetQuoteField();
1170 kindctrl
.MakeUpper();
1172 if (kindctrl
==_T("MSCTLS_UPDOWN32"))
1173 ParseSpinCtrl(label
,varname
);
1174 if (kindctrl
==_T("MSCTLS_TRACKBAR32"))
1175 ParseSlider(label
,varname
);
1176 if (kindctrl
==_T("MSCTLS_PROGRESS32"))
1177 ParseProgressBar(label
,varname
);
1178 if (kindctrl
==_T("SYSTREEVIEW32"))
1179 ParseTreeCtrl(label
,varname
);
1180 if (kindctrl
==_T("SYSMONTHCAL32"))
1181 ParseCalendar(label
,varname
);
1182 if (kindctrl
==_T("SYSLISTVIEW32"))
1183 ParseListCtrl(label
,varname
);
1184 if (kindctrl
==_T("BUTTON"))
1185 ParseCtrlButton(label
,varname
);
1186 if (kindctrl
==_T("RICHEDIT"))
1187 ParseRichEdit(label
,varname
);
1188 if (kindctrl
==_T("STATIC"))
1194 if (token
.Find(_T("SS_BITMAP"))!=wxNOT_FOUND
)
1195 ParseStaticBitmap(label
,varname
);
1197 ParseStaticText(label
,varname
);
1199 if (kindctrl
==_T("EDIT"))
1200 ParseTextCtrl(varname
);
1201 if (kindctrl
==_T("LISTBOX"))
1202 ParseListBox(varname
);
1203 if (kindctrl
==_T("COMBOBOX"))
1204 ParseComboBox(varname
);
1208 void rc2xml::ParseWeirdMSControl()
1215 kindctrl
=GetQuoteField();
1216 kindctrl
.MakeUpper();
1217 // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
1218 if (kindctrl
==_T("STATIC"))
1220 if (PeekToken()==_T("SS_BITMAP"))
1221 ParseStaticBitmap(id
,varname
);
1223 wxLogError(_T("Unknown MS Control Static token"));
1227 //SCROLLBAR IDC_SCROLLBAR1,219,56,10,40,SBS_VERT
1229 void rc2xml::ParseScrollBar()
1235 int x
,y
,width
,height
;
1236 ReadRect(x
,y
,width
,height
);
1241 if (token
.Find(_T("SBS_VERT"))!=wxNOT_FOUND
)
1242 style
=_T("wxSB_VERTICAL");
1243 //Default MFC style is horizontal
1245 style
=_T("wxSB_HORIZONTAL");
1247 m_xmlfile
.Write(_T("\t\t<object class=\"wxScrollBar\""));
1248 WriteBasicInfo(x
,y
,width
,height
,varname
);
1250 m_xmlfile
.Write(_T("\n\t\t</object>\n"));
1253 // CONTROL "Tree1",IDC_TREE1,"SysTreeView32",WS_BORDER | WS_TABSTOP,
1256 void rc2xml::ParseTreeCtrl(wxString
WXUNUSED(label
), wxString varname
)
1259 //while (ReadOrs(token));
1261 int x
,y
,width
,height
;
1262 ReadRect(x
,y
,width
,height
);
1263 m_xmlfile
.Write(_T("\t\t<object class=\"wxTreeCtrl\""));
1264 WriteBasicInfo(x
,y
,width
,height
,varname
);
1265 m_xmlfile
.Write(_T("\t\t</object>\n"));
1268 // CONTROL "MonthCalendar1",IDC_MONTHCALENDAR1,"SysMonthCal32",
1269 //MCS_NOTODAY | WS_TABSTOP,105,71,129,89
1271 void rc2xml::ParseCalendar(wxString
WXUNUSED(label
), wxString varname
)
1274 //while (ReadOrs(token));
1276 int x
,y
,width
,height
;
1277 ReadRect(x
,y
,width
,height
);
1278 m_xmlfile
.Write(_T("\t\t<object class=\"wxCalendarCtrl\""));
1279 WriteBasicInfo(x
,y
,width
,height
,varname
);
1280 m_xmlfile
.Write(_T("\t\t</object>\n"));
1282 // CONTROL "List1",IDC_LIST1,"SysListView32",WS_BORDER | WS_TABSTOP,
1285 void rc2xml::ParseListCtrl(wxString
WXUNUSED(label
), wxString varname
)
1288 //while (ReadOrs(token));
1290 int x
,y
,width
,height
;
1291 ReadRect(x
,y
,width
,height
);
1292 m_xmlfile
.Write(_T("\t\t<object class=\"wxListCtrl\""));
1293 WriteBasicInfo(x
,y
,width
,height
,varname
);
1294 m_xmlfile
.Write(_T("\t\t</object>\n"));
1298 void rc2xml::WriteBitmap(wxString bitmapname
)
1301 wxNode
*node
=m_bitmaplist
->Find(LookUpId(bitmapname
));
1304 m_xmlfile
.Write(_T("\t\t\t<bitmap>missingfile</bitmap>\n"));
1305 wxLogError(_T("Unable to find bitmap:")+bitmapname
);
1309 wxString
*bitmappath
;
1310 bitmappath
=(wxString
*)node
->GetData();
1312 bitmapname
=wxFileNameFromPath(*bitmappath
);
1314 if (!bitmap
.LoadFile(*bitmappath
,wxBITMAP_TYPE_BMP
))
1315 wxLogError(_T("Unable to load bitmap:")+*bitmappath
);
1317 //Make a bitmap file name
1318 bitmapname
=CleanName(bitmapname
);
1319 bitmapname
+=_T(".bmp");
1320 m_xmlfile
.Write(_T("\t\t\t<bitmap>")+bitmapname
+_T("</bitmap>\n"));
1321 bitmap
.SaveFile(m_targetpath
+bitmapname
,wxBITMAP_TYPE_BMP
);
1324 void rc2xml::WriteIcon(wxString iconname
)
1326 wxNode
*node
=m_iconlist
->Find(iconname
);
1329 m_xmlfile
.Write(_T("\t\t\t<bitmap>missing_file</bitmap>\n"));
1330 wxLogError(_T("Unable to find icon:")+iconname
);
1333 iconpath
=(wxString
*)node
->GetData();
1336 if (!icon
.LoadFile(*iconpath
,wxBITMAP_TYPE_ICO
))
1337 wxLogError(_T("Unable to load icon:")+*iconpath
);
1339 bitmap
.CopyFromIcon(icon
);
1343 iconname
=wxFileNameFromPath(*iconpath
);
1344 //Make a bitmap file name
1345 iconname
=CleanName(iconname
);
1346 iconname
+=_T(".bmp");
1347 m_xmlfile
.Write(_T("\t\t\t<bitmap>")+iconname
+_T("</bitmap>\n"));
1348 bitmap
.SaveFile(m_targetpath
+iconname
,wxBITMAP_TYPE_BMP
);
1352 /*Unfortunately sometimes the great MSVC Resource editor decides
1353 to use numbers instead of the word id. I have no idea why they
1354 do this, but that is the way it is.
1356 /* this is a quick and dirty way to parse the resource.h file
1357 it will not recognize #ifdef so it can be easily fooled
1359 void rc2xml::ParseResourceHeader()
1362 //Attempt to load resource.h in current path
1363 if (!r
.Open(_T("resource.h")))
1365 wxLogError(_T("Warining Unable to load resource.h file"));
1371 wxStringTokenizer tok
;
1377 //Read through entire file
1378 for ( str
= r
.GetFirstLine(); !r
.Eof(); str
= r
.GetNextLine() )
1380 if (str
.Find(_T("#define"))!=wxNOT_FOUND
)
1383 //Just ignore #define token
1385 v
=tok
.GetNextToken();
1386 id
=tok
.GetNextToken();
1389 varname
=new wxString
;
1392 m_resourcelist
->Append(n
,varname
);
1402 wxString
rc2xml::LookUpId(wxString id
)
1410 wxNode
*node
=m_resourcelist
->Find(n
);
1415 s
=(wxString
*)node
->GetData();