]>
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" wxWindows headers
39 #include "wx/resource.h"
40 #include <wx/textfile.h>
41 #include <wx/tokenzr.h>
45 //////////////////////////////////////////////////////////////////////
46 // Construction/Destruction
47 //////////////////////////////////////////////////////////////////////
52 m_bitmaplist
=new wxList(wxKEY_STRING
);
53 m_stringtable
=new wxList(wxKEY_STRING
);
54 m_iconlist
= new wxList(wxKEY_STRING
);
55 m_resourcelist
=new wxList(wxKEY_INTEGER
);
63 delete m_resourcelist
;
66 bool rc2xml::Convert(wxString rcfile
, wxString xmlfile
)
68 m_rc
.Open(rcfile
.c_str());
69 m_filesize
=m_rc
.Length();
71 m_workingpath
=wxPathOnly(rcfile
);
72 m_targetpath
=wxPathOnly(xmlfile
)+"\\";
74 wxSetWorkingDirectory(m_workingpath
);
77 result
=m_xmlfile
.Open(xmlfile
.c_str(),"w+t");
78 wxASSERT_MSG(result
,"Couldn't create XML file");
83 /* Write Basic header for XML file */
84 m_xmlfile
.Write("<?xml version=\"1.0\" ?>\n");
85 m_xmlfile
.Write("<resource>\n");
88 ParseResourceHeader();
89 //Gather all the resource we need for toolbars,menus, and etc
93 //Read in dialogs, toolbars,menus
96 m_xmlfile
.Write("</resource>\n");
104 void rc2xml::ParseDialog(wxString dlgname
)
107 static int dlgid
=999;
109 /* Make sure that this really is a dialog
110 microsoft reuses the keyword DIALOG for other things
113 //Microsoft notation?
114 if (token
=="DISCARDABLE")
119 //Error isn't a Dialog resource eject eject
120 if (!token
.IsNumber())
123 //Record x,y,width,height
124 int x
,y
,width
,height
;
125 ReadRect(x
,y
,width
,height
);
129 wxString ptsize
,face
;
131 m_xmlfile
.Write("\t<object class=\"wxDialog\"");
132 //Avoid duplicate names this way
133 dlgname
.Replace("IDD_","DLG_");
134 WriteBasicInfo(x
,y
,width
,height
,dlgname
);
138 while ((token
!="BEGIN")&(token
!="{"))
140 if (token
=="CAPTION")
142 title
=GetQuoteField();
145 //TODO fix face name so that it is cross platform name
146 // FONT 8, "MS Sans Serif"
150 face
=GetQuoteField();
151 m_xmlfile
.Write("\t\t<font>\n");
152 m_xmlfile
.Write("\t\t\t<size>"+ptsize
+"</size>\n");
153 m_xmlfile
.Write("\t\t\t<face>"+face
+"</face>\n");
154 m_xmlfile
.Write("\t\t</font>\n");
161 m_xmlfile
.Write("\t</object>\n");
166 EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT
168 LTEXT "Bands",IDC_STATIC,11,86,21,8
169 EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL
172 void rc2xml::ParseControls()
177 while ((token
!="END")&(token
!="}"))
179 if (token
=="AUTOCHECKBOX")
182 if (token
=="AUTORADIOBUTTON")
187 else if (token
=="EDITTEXT")
189 else if (token
=="PUSHBUTTON")
191 else if (token
=="DEFPUSHBUTTON")
193 else if (token
=="GROUPBOX")
195 else if (token
=="COMBOBOX")
197 else if (token
=="CONTROL")
199 else if (token
=="LISTBOX")
201 else if (token
=="ICON")
203 else if (token
=="SCROLLBAR")
209 //LTEXT "Radius",IDC_STATIC,9,67,23,8
210 void rc2xml::ParseStaticText()
213 wxString phrase
,varname
;
214 phrase
=GetQuoteField();
216 int x
,y
,width
,height
;
217 ReadRect(x
,y
,width
,height
);
219 m_xmlfile
.Write("\t\t<object class=\"wxStaticText\"");
220 WriteBasicInfo(x
,y
,width
,height
,varname
);WriteLabel(phrase
);
221 m_xmlfile
.Write("\t\t</object>\n");
224 //EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
225 void rc2xml::ParseTextCtrl()
228 wxString varname
,style
;
230 int x
,y
,width
,height
;
231 ReadRect(x
,y
,width
,height
);
234 m_xmlfile
.Write("\t\t<object class=\"wxTextCtrl\"");
235 WriteBasicInfo(x
,y
,width
,height
,varname
);
236 m_xmlfile
.Write("\t\t</object>\n");
239 //AUTOCHECKBOX "&log.", ID_XLOG, 25, 24, 21, 12
240 void rc2xml::ParseCheckBox()
243 wxString phrase
,varname
;
244 phrase
=GetQuoteField();
247 int x
,y
,width
,height
;
248 ReadRect(x
,y
,width
,height
);
250 m_xmlfile
.Write("\t\t<object class=\"wxCheckBox\"");
251 WriteBasicInfo(x
,y
,width
,height
,varname
);
253 m_xmlfile
.Write("\t\t</object>\n");
256 //AUTORADIOBUTTON "&text", ID_SW10, 13, 12, 68, 10, BS_AUTORADIOBUTTON | WS_GROUP
257 void rc2xml::ParseRadioButton()
259 wxString token
,style
;
260 wxString phrase
,varname
;
261 phrase
=GetQuoteField();
264 int x
,y
,width
,height
;
265 if (ReadRect(x
,y
,width
,height
))
267 if (token
.Find("WS_GROUP") != -1)
268 style
+= "wxRB_GROUP";
270 m_xmlfile
.Write("\t\t<object class=\"wxRadioButton\"");
271 WriteBasicInfo(x
,y
,width
,height
,varname
);
274 m_xmlfile
.Write("\t\t</object>\n");
278 //PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
279 void rc2xml::ParsePushButton()
282 wxString phrase
,varname
;
283 phrase
=GetQuoteField();
286 int x
,y
,width
,height
;
287 ReadRect(x
,y
,width
,height
);
289 m_xmlfile
.Write("\t\t<object class=\"wxButton\"");
290 WriteBasicInfo(x
,y
,width
,height
,varname
);
292 m_xmlfile
.Write("\t\t</object>\n");
297 bool rc2xml::Seperator(int ch
)
299 //if ((ch==' ')|(ch==',')|(ch==13)|(ch==10)|(ch=='|')|(ch=='\t'))
300 if ((ch
==' ')|(ch
==',')|(ch
==13)|(ch
==10)|(ch
=='\t'))
312 void rc2xml::ParseGroupBox()
314 // GROUPBOX "Rotate",IDC_STATIC,1,1,71,79
316 wxString phrase
,varname
;
317 phrase
=GetQuoteField();
319 int x
,y
,width
,height
;
320 ReadRect(x
,y
,width
,height
);
322 m_xmlfile
.Write("\t\t<object class=\"wxStaticBox\"");
323 WriteBasicInfo(x
,y
,width
,height
,varname
);
325 m_xmlfile
.Write("\t\t</object>\n");
328 bool rc2xml::ReadRect(int & x
, int & y
, int & width
, int & height
)
332 width
=atoi(GetToken());
334 wxString tmp
= GetToken(&ret
);
336 return ret
; // check for more parameters
339 wxString
rc2xml::GetToken(bool *listseperator
)
357 while (Seperator(ch
))
370 while (!Seperator(ch
))
380 *listseperator
= (ch
== ',');
384 wxString
rc2xml::GetQuoteField()
404 void rc2xml::ReadChar(int &ch
)
409 if((result
>=m_filesize
))
412 result
=m_rc
.Read(&ch
,1);
421 void rc2xml::ParseComboBox()
423 /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
424 WS_VSCROLL | WS_TABSTOP */
425 wxString token
,style
;
428 int x
,y
,width
,height
;
429 if (ReadRect(x
,y
,width
,height
))
432 m_xmlfile
.Write("\t\t<object class=\"wxComboBox\"");
433 WriteBasicInfo(x
,y
,width
,height
,varname
);
434 if (token
.Find("CBS_SIMPLE") != -1)
435 WriteStyle("wxCB_SIMPLE");
436 if (token
.Find("CBS_SORT") != -1)
437 WriteStyle("wxCB_SORT");
438 if (token
.Find("CBS_DISABLENOSCROLL") != -1)
439 WriteStyle("wxLB_ALWAYS_SB");
440 m_xmlfile
.Write("\n\t\t</object>\n");
444 void rc2xml::ParseMenu(wxString varname
)
448 //Write menubar to xml file
449 m_xmlfile
.Write("\t<object class=\"wxMenuBar\"");
450 //Avoid duplicate names this way
451 varname
.Replace("IDR_","MB_");
453 m_xmlfile
.Write(">\n");
455 while ((token
!="BEGIN")&(token
!="{"))
458 while ((token
!="END")&(token
!="}"))
466 m_xmlfile
.Write("\t</object>\n");
469 void rc2xml::ParsePopupMenu()
471 static int menucount
=0;
473 wxString token
,name
,msg
,longhelp
,tip
;
474 token
=GetQuoteField();
476 //Remove \t because it causes problems
478 //spot=token.First("\\t");
479 //token=token.Left(spot);
482 //Generate a fake name since RC menus don't have one
483 name
<<"Menu_"<<menucount
;
484 m_xmlfile
.Write("\t\t<object class=\"wxMenu\"");
486 m_xmlfile
.Write(">\n");
489 while ((token
!="BEGIN")&(token
!="{"))
492 while ((token
!="END")&(token
!="}"))
498 if (token
=="MENUITEM")
501 m_xmlfile
.Write("\t\t\t</object>\n");
504 wxString
rc2xml::PeekToken()
514 //MS Windows pain in the butt CONTROL
515 void rc2xml::ParseControlMS()
517 wxString label
,varname
,kindctrl
,token
;
520 if (token
.Contains("\""))
521 ParseNormalMSControl();
523 ParseWeirdMSControl();
527 /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
528 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
531 void rc2xml::ParseSlider(wxString label
, wxString varname
)
533 wxString token
,style
;
535 if (token
.Find("TBS_VERT")!=-1)
536 style
+="wxSL_VERTICAL";
537 //MFC RC Default is horizontal
539 style
+="wxSL_HORIZONTAL";
541 int x
,y
,width
,height
;
542 ReadRect(x
,y
,width
,height
);
543 m_xmlfile
.Write("\t\t<object class=\"wxSlider\"");
544 WriteBasicInfo(x
,y
,width
,height
,varname
);
546 m_xmlfile
.Write("\n\t\t</object>\n");
550 CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
551 WS_BORDER,15,52,154,13
553 void rc2xml::ParseProgressBar(wxString label
, wxString varname
)
555 wxString token
,style
;
558 int x
,y
,width
,height
;
559 ReadRect(x
,y
,width
,height
);
561 //Always horizontal in MFC
562 m_xmlfile
.Write("\t\t<object class=\"wxGauge\"");
563 WriteBasicInfo(x
,y
,width
,height
,varname
);
565 m_xmlfile
.Write("\t\t</object>\n");
568 bool rc2xml::ReadOrs(wxString
& orstring
)
573 if (token
.IsNumber())
577 while(PeekToken()==_T("|"))
580 orstring
+=GetToken();
582 orstring
+=GetToken();
587 //Is it a check button or a radio button
588 void rc2xml::ParseCtrlButton(wxString label
, wxString varname
)
592 int x
,y
,width
,height
;
594 if (token
.Find("BS_AUTOCHECKBOX")!=-1)
596 ReadRect(x
,y
,width
,height
);
597 m_xmlfile
.Write("\t\t<object class=\"wxCheckBox\"");
598 WriteBasicInfo(x
,y
,width
,height
,varname
);
600 m_xmlfile
.Write("\t\t</object>\n");
603 if (token
.Find("BS_AUTORADIOBUTTON")!=-1)
605 ReadRect(x
,y
,width
,height
);
606 m_xmlfile
.Write("\t\t<object class=\"wxRadioButton\"");
607 WriteBasicInfo(x
,y
,width
,height
,varname
);
609 m_xmlfile
.Write("\t\t</object>\n");
615 void rc2xml::WriteSize(int width
, int height
)
618 msg
<<" <size>"<<width
<<","<<height
<<"d</size>";
619 m_xmlfile
.Write(msg
);
622 void rc2xml::WritePosition(int x
, int y
)
625 msg
<<" <pos>"<<x
<<","<<y
<<"d</pos>";
626 m_xmlfile
.Write(msg
);
629 void rc2xml::WriteTitle(wxString title
)
632 msg
=_T("\t\t<title>"+title
+"</title>\n");
633 m_xmlfile
.Write(msg
);
636 void rc2xml::WriteName(wxString name
)
639 //Try to convert any number ids into names
641 //Replace common MS ids with wxWindows ids
642 //I didn't do everyone of them
645 else if (name
=="IDCANCEL")
647 else if (name
=="IDAPPLY")
649 else if (name
=="ID_FILE_OPEN")
651 else if (name
=="ID_FILE_CLOSE")
653 else if (name
=="ID_FILE_SAVE")
655 else if (name
=="ID_FILE_SAVE_AS")
657 else if (name
=="ID_APP_EXIT")
659 else if (name
=="ID_FILE_PRINT")
661 else if (name
=="ID_FILE_PRINT_PREVIEW")
663 else if (name
=="ID_FILE_PRINT_SETUP")
664 name
="wxID_PRINT_SETUP";
665 else if (name
=="ID_APP_ABOUT")
667 else if (name
=="ID_EDIT_UNDO")
669 else if (name
=="ID_EDIT_CUT")
671 else if (name
=="ID_EDIT_COPY")
673 else if (name
=="ID_EDIT_PASTE")
675 else if (name
=="IDYES")
677 else if (name
=="IDNO")
679 else if (name
=="IDHELP")
682 m_xmlfile
.Write(" name= \""+name
+"\"");
685 void rc2xml::WriteLabel(wxString label
)
687 label
.Replace("&","$");
688 m_xmlfile
.Write("\t\t\t<label>"+label
+"</label>\n");
691 void rc2xml::WriteBasicInfo(int x
, int y
, int width
, int height
, wxString name
)
694 m_xmlfile
.Write(">\n");
695 m_xmlfile
.Write("\t\t\t");
697 WriteSize(width
,height
);
698 m_xmlfile
.Write("\n");
701 void rc2xml::WriteStyle(wxString style
)
703 if (style
.Length()==0)
705 m_xmlfile
.Write("\t\t\t<style>"+style
+"</style>\n");
708 LISTBOX IDC_LIST1,16,89,48,40,LBS_SORT | LBS_MULTIPLESEL |
709 LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
711 void rc2xml::ParseListBox()
716 int x
,y
,width
,height
;
717 ReadRect(x
,y
,width
,height
);
719 m_xmlfile
.Write("\t\t<object class=\"wxListBox\"");
720 WriteBasicInfo(x
,y
,width
,height
,varname
);
721 m_xmlfile
.Write("\n\t\t</object>\n");
725 CONTROL "",IDC_RICHEDIT1,"RICHEDIT",ES_AUTOHSCROLL | WS_BORDER |
726 WS_TABSTOP,103,110,40,14
728 void rc2xml::ParseRichEdit(wxString label
, wxString varname
)
731 //while (ReadOrs(token));
733 int x
,y
,width
,height
;
734 ReadRect(x
,y
,width
,height
);
736 //Make it a rich text control
737 style
+="wxTE_MULTILINE ";
738 m_xmlfile
.Write("\t\t<object class=\"wxTextCtrl\"");
739 WriteBasicInfo(x
,y
,width
,height
,varname
);
741 m_xmlfile
.Write("\t\t</object>\n");
745 CONTROL "Spin1",IDC_SPIN1,"msctls_updown32",UDS_ARROWKEYS,209,72,
748 void rc2xml::ParseSpinCtrl(wxString label
, wxString varname
)
750 wxString token
,style
;
753 if (token
.Find("UDS_HORZ")!=-1)
754 style
="wxSP_HORIZONTAL";
757 style
="wxSP_VERTICAL";
759 int x
,y
,width
,height
;
760 ReadRect(x
,y
,width
,height
);
761 m_xmlfile
.Write("\t\t<object class=\"wxSpinButton\"");
762 WriteBasicInfo(x
,y
,width
,height
,varname
);
764 m_xmlfile
.Write("\n\t\t</object>\n");
768 void rc2xml::FirstPass()
770 wxString token
,prevtok
;
775 ParseBitmap(prevtok
);
776 else if (token
=="STRINGTABLE")
777 ParseStringTable(prevtok
);
778 else if (token
=="ICON")
785 void rc2xml::ParseBitmap(wxString varname
)
787 wxString token
,*bitmapfile
;
790 //Microsoft notation?
791 if (token
=="DISCARDABLE")
796 bitmapfile
=new wxString
;
797 *bitmapfile
=GetQuoteField();
798 m_bitmaplist
->Append(varname
,bitmapfile
);
803 void rc2xml::SecondPass()
805 wxString token
,prevtok
;
810 ParseDialog(prevtok
);
811 else if (token
=="MENU")
813 else if (token
=="TOOLBAR")
814 ParseToolBar(prevtok
);
821 void rc2xml::ParseToolBar(wxString varname
)
825 wxASSERT_MSG(token
=="DISCARDABLE","Error in toolbar parsing");
826 //Look up bitmap for toolbar and load
827 wxNode
*node
=m_bitmaplist
->Find(LookUpId(varname
));
828 wxString
*bitmappath
;
829 bitmappath
=(wxString
*)node
->Data();
831 if (!bitmap
.LoadFile(*bitmappath
,wxBITMAP_TYPE_BMP
))
832 wxLogError("Unable to load bitmap:"+*bitmappath
);
834 //Write toolbar to xml file
835 m_xmlfile
.Write(" <object class=\"wxToolBar\"");
836 //Avoid duplicate names this way
837 varname
.Replace("IDR_","TB_");
839 m_xmlfile
.Write(">\n");
845 //Grab width and height
847 width
=atoi(GetToken());
848 height
=atoi(GetToken());
851 wxString buttonname
,msg
,tip
,longhelp
;
853 while ((token
!="BEGIN"))
856 while ((token
!="END")&(token
!="}"))
860 buttonname
=GetToken();
861 m_xmlfile
.Write("\t\t\t<object class=\"tool\"");
862 WriteName(buttonname
);
863 m_xmlfile
.Write(">\n");
864 //Write tool tip if any
865 if (LookUpString(buttonname
,msg
))
867 SplitHelp(msg
,tip
,longhelp
);
868 m_xmlfile
.Write("\t\t\t\t<tooltip>"+tip
+"</tooltip>\n");
869 m_xmlfile
.Write(" <longhelp>"+longhelp
+"</longhelp>\n");
871 //Make a bitmap file name
872 buttonname
=CleanName(buttonname
);
874 m_xmlfile
.Write("\t\t\t\t<bitmap>"+buttonname
+"</bitmap>\n");
875 WriteToolButton(buttonname
,c
,width
,height
,bitmap
);
876 m_xmlfile
.Write("\t\t\t</object>\n");
879 else if (token
=="SEPARATOR")
881 m_xmlfile
.Write("\t\t\t<object class=\"separator\"/>\n");
885 m_xmlfile
.Write("\t</object>\n");
888 //Extract bitmaps from larger toolbar bitmap
889 void rc2xml::WriteToolButton(wxString name
,int index
, int width
, int height
, wxBitmap bitmap
)
893 wxRect
r(x
,0,width
,height
);
895 little
=bitmap
.GetSubBitmap(r
);
896 little
.SaveFile(m_targetpath
+name
,wxBITMAP_TYPE_BMP
);
899 void rc2xml::ParseStringTable(wxString varname
)
903 while ((token
!="BEGIN"))
908 while ((token
!="END")&(token
!="}"))
911 *msg
=GetQuoteField();
912 m_stringtable
->Append(token
,msg
);
918 bool rc2xml::LookUpString(wxString strid
,wxString
& st
)
920 wxNode
*node
=m_stringtable
->Find(strid
);
925 s
=(wxString
*)node
->Data();
931 bool rc2xml::SplitHelp(wxString msg
, wxString
&shorthelp
, wxString
&longhelp
)
934 spot
=msg
.Find("\\n");
941 longhelp
=msg
.Left(spot
);
942 spot
=msg
.Length()-spot
-2;
943 shorthelp
=msg
.Right(spot
);
947 void rc2xml::ParseMenuItem()
949 wxString token
,name
,msg
,tip
,longhelp
;
951 if (PeekToken()=="SEPARATOR")
953 m_xmlfile
.Write("\t\t\t<object class=\"separator\"/>\n");
957 token
=GetQuoteField();
959 //Remove \t because it causes problems
960 //spot=token.First("\\t");
961 //token=token.Left(spot);
962 m_xmlfile
.Write("\t\t\t<object class=\"wxMenuItem\"");
964 m_xmlfile
.Write(">\n");
966 //Look up help if any listed in stringtable
967 if (LookUpString(name
,msg
))
969 SplitHelp(msg
,tip
,longhelp
);
970 m_xmlfile
.Write("\t\t\t<help>"
971 +longhelp
+"</help>\n");
973 //look for extra attributes like checked and break
976 while ((ptoken
!="MENUITEM")&(ptoken
!="POPUP")&(ptoken
!="END"))
979 if (token
=="CHECKED")
980 m_xmlfile
.Write("\t\t\t<checkable>1</checkable>\n");
981 else if (token
=="MENUBREAK");
982 //m_xmlfile.Write("\t\t\t</break>\n");
983 else if (token
=="GRAYED");
985 wxLogError("Unknown Menu Item token:"+token
);
989 m_xmlfile
.Write("\t\t\t</object>\n");
993 //ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
994 void rc2xml::ParseIconStatic()
997 wxString varname
,iconname
;
1002 int x
,y
,width
,height
;
1003 ReadRect(x
,y
,width
,height
);
1005 m_xmlfile
.Write("\t\t<object class=\"wxStaticBitmap\"");
1006 WriteBasicInfo(x
,y
,width
,height
,varname
);
1007 //Save icon as a bitmap
1008 WriteIcon(iconname
);
1009 m_xmlfile
.Write("\t\t</object>\n");
1012 //IDR_MAINFRAME ICON DISCARDABLE "res\\mfcexample.ico"
1013 void rc2xml::ParseIcon(wxString varname
)
1015 wxString token
,*iconfile
;
1016 iconfile
=new wxString
;
1019 *iconfile
=GetQuoteField();
1020 m_iconlist
->Append(varname
,iconfile
);
1025 wxString
rc2xml::CleanName(wxString name
)
1028 name
.Replace("id_","");
1029 name
.Replace("idr_","");
1030 name
.Replace("idb_","");
1031 name
.Replace("idc_","");
1032 name
.Replace(".ico","");
1033 name
.Replace(".bmp","");
1036 // And the award for most messed up control goes to...
1037 // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
1038 void rc2xml::ParseStaticBitmap(wxString bitmapname
, wxString varname
)
1046 int x
,y
,width
,height
;
1047 ReadRect(x
,y
,width
,height
);
1049 m_xmlfile
.Write("\t\t<object class=\"wxStaticBitmap\"");
1050 WriteBasicInfo(x
,y
,width
,height
,varname
);
1051 WriteBitmap(bitmapname
);
1052 m_xmlfile
.Write("\t\t</object>\n");
1056 void rc2xml::ParseNormalMSControl()
1058 wxString label
,varname
,kindctrl
;
1060 label
=GetQuoteField();
1062 kindctrl
=GetQuoteField();
1063 kindctrl
.MakeUpper();
1065 if (kindctrl
=="MSCTLS_UPDOWN32")
1066 ParseSpinCtrl(label
,varname
);
1067 if (kindctrl
=="MSCTLS_TRACKBAR32")
1068 ParseSlider(label
,varname
);
1069 if (kindctrl
=="MSCTLS_PROGRESS32")
1070 ParseProgressBar(label
,varname
);
1071 if (kindctrl
=="SYSTREEVIEW32")
1072 ParseTreeCtrl(label
,varname
);
1073 if (kindctrl
=="SYSMONTHCAL32")
1074 ParseCalendar(label
,varname
);
1075 if (kindctrl
=="SYSLISTVIEW32")
1076 ParseListCtrl(label
,varname
);
1077 if (kindctrl
=="BUTTON")
1078 ParseCtrlButton(label
,varname
);
1079 if (kindctrl
=="RICHEDIT")
1080 ParseRichEdit(label
,varname
);
1084 void rc2xml::ParseWeirdMSControl()
1091 kindctrl
=GetQuoteField();
1092 kindctrl
.MakeUpper();
1093 // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
1094 if (kindctrl
=="STATIC")
1096 if (PeekToken()=="SS_BITMAP")
1097 ParseStaticBitmap(id
,varname
);
1099 wxLogError("Unknown MS Control Static token");
1103 //SCROLLBAR IDC_SCROLLBAR1,219,56,10,40,SBS_VERT
1105 void rc2xml::ParseScrollBar()
1111 int x
,y
,width
,height
;
1112 ReadRect(x
,y
,width
,height
);
1117 if (token
.Find("SBS_VERT")!=-1)
1118 style
=_T("wxSB_VERTICAL");
1119 //Default MFC style is horizontal
1121 style
=_T("wxSB_HORIZONTAL");
1123 m_xmlfile
.Write("\t\t<object class=\"wxScrollBar\"");
1124 WriteBasicInfo(x
,y
,width
,height
,varname
);
1126 m_xmlfile
.Write("\n\t\t</object>\n");
1129 // CONTROL "Tree1",IDC_TREE1,"SysTreeView32",WS_BORDER | WS_TABSTOP,
1132 void rc2xml::ParseTreeCtrl(wxString label
, wxString varname
)
1135 //while (ReadOrs(token));
1137 int x
,y
,width
,height
;
1138 ReadRect(x
,y
,width
,height
);
1139 m_xmlfile
.Write("\t\t<object class=\"wxTreeCtrl\"");
1140 WriteBasicInfo(x
,y
,width
,height
,varname
);
1141 m_xmlfile
.Write("\t\t</object>\n");
1144 // CONTROL "MonthCalendar1",IDC_MONTHCALENDAR1,"SysMonthCal32",
1145 //MCS_NOTODAY | WS_TABSTOP,105,71,129,89
1147 void rc2xml::ParseCalendar(wxString label
, wxString varname
)
1150 //while (ReadOrs(token));
1152 int x
,y
,width
,height
;
1153 ReadRect(x
,y
,width
,height
);
1154 m_xmlfile
.Write("\t\t<object class=\"wxCalendarCtrl\"");
1155 WriteBasicInfo(x
,y
,width
,height
,varname
);
1156 m_xmlfile
.Write("\t\t</object>\n");
1158 // CONTROL "List1",IDC_LIST1,"SysListView32",WS_BORDER | WS_TABSTOP,
1161 void rc2xml::ParseListCtrl(wxString label
, wxString varname
)
1164 //while (ReadOrs(token));
1166 int x
,y
,width
,height
;
1167 ReadRect(x
,y
,width
,height
);
1168 m_xmlfile
.Write("\t\t<object class=\"wxListCtrl\"");
1169 WriteBasicInfo(x
,y
,width
,height
,varname
);
1170 m_xmlfile
.Write("\t\t</object>\n");
1174 void rc2xml::WriteBitmap(wxString bitmapname
)
1177 wxNode
*node
=m_bitmaplist
->Find(LookUpId(bitmapname
));
1180 m_xmlfile
.Write("\t\t\t<bitmap>missingfile</bitmap>\n");
1181 wxLogError("Unable to find bitmap:"+bitmapname
);
1185 wxString
*bitmappath
;
1186 bitmappath
=(wxString
*)node
->Data();
1187 bitmapname
=wxFileNameFromPath(*bitmappath
);
1189 if (!bitmap
.LoadFile(*bitmappath
,wxBITMAP_TYPE_BMP
))
1190 wxLogError("Unable to load bitmap:"+*bitmappath
);
1192 //Make a bitmap file name
1193 bitmapname
=CleanName(bitmapname
);
1195 m_xmlfile
.Write("\t\t\t<bitmap>"+bitmapname
+"</bitmap>\n");
1196 bitmap
.SaveFile(m_targetpath
+bitmapname
,wxBITMAP_TYPE_BMP
);
1199 void rc2xml::WriteIcon(wxString iconname
)
1201 wxNode
*node
=m_iconlist
->Find(iconname
);
1204 m_xmlfile
.Write("\t\t\t<bitmap>missing_file</bitmap>\n");
1205 wxLogError("Unable to find icon:"+iconname
);
1208 iconpath
=(wxString
*)node
->Data();
1211 if (!icon
.LoadFile(*iconpath
,wxBITMAP_TYPE_ICO
))
1212 wxLogError("Unable to load icon:"+*iconpath
);
1214 bitmap
.CopyFromIcon(icon
);
1218 iconname
=wxFileNameFromPath(*iconpath
);
1219 //Make a bitmap file name
1220 iconname
=CleanName(iconname
);
1222 m_xmlfile
.Write("\t\t\t<bitmap>"+iconname
+"</bitmap>\n");
1223 bitmap
.SaveFile(m_targetpath
+iconname
,wxBITMAP_TYPE_BMP
);
1227 /*Unfortunately sometimes the great MSVC Resource editor decides
1228 to use numbers instead of the word id. I have no idea why they
1229 do this, but that is the way it is.
1231 /* this is a quick and dirty way to parse the resource.h file
1232 it will not recognize #ifdef so it can be easily fooled
1234 void rc2xml::ParseResourceHeader()
1237 //Attempt to load resource.h in current path
1238 if (!r
.Open("resource.h"))
1240 wxLogError("Warining Unable to load resource.h file");
1246 wxStringTokenizer tok
;
1252 //Read through entire file
1253 for ( str
= r
.GetFirstLine(); !r
.Eof(); str
= r
.GetNextLine() )
1255 if (str
.Find("#define")!=-1)
1258 //Just ignore #define token
1260 v
=tok
.GetNextToken();
1261 id
=tok
.GetNextToken();
1264 varname
=new wxString
;
1267 m_resourcelist
->Append(n
,varname
);
1277 wxString
rc2xml::LookUpId(wxString id
)
1285 wxNode
*node
=m_resourcelist
->Find(n
);
1290 s
=(wxString
*)node
->Data();