]>
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
!="}"))
181 else if (token
=="EDITTEXT")
183 else if (token
=="PUSHBUTTON")
185 else if (token
=="DEFPUSHBUTTON")
187 else if (token
=="GROUPBOX")
189 else if (token
=="COMBOBOX")
191 else if (token
=="CONTROL")
193 else if (token
=="LISTBOX")
195 else if (token
=="ICON")
197 else if (token
=="SCROLLBAR")
203 //LTEXT "Radius",IDC_STATIC,9,67,23,8
204 void rc2xml::ParseStaticText()
207 wxString phrase
,varname
;
208 phrase
=GetQuoteField();
210 int x
,y
,width
,height
;
211 ReadRect(x
,y
,width
,height
);
213 m_xmlfile
.Write("\t\t<object class=\"wxStaticText\"");
214 WriteBasicInfo(x
,y
,width
,height
,varname
);WriteLabel(phrase
);
215 m_xmlfile
.Write("\t\t</object>\n");
218 //EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
219 void rc2xml::ParseTextCtrl()
222 wxString varname
,style
;
224 int x
,y
,width
,height
;
225 ReadRect(x
,y
,width
,height
);
228 m_xmlfile
.Write("\t\t<object class\"wxTextCtrl\"");
229 WriteBasicInfo(x
,y
,width
,height
,varname
);
230 m_xmlfile
.Write("\t\t</object>\n");
233 //PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
234 void rc2xml::ParsePushButton()
237 wxString phrase
,varname
;
238 phrase
=GetQuoteField();
241 int x
,y
,width
,height
;
242 ReadRect(x
,y
,width
,height
);
244 m_xmlfile
.Write("\t\t<object class=\"wxButton\"");
245 WriteBasicInfo(x
,y
,width
,height
,varname
);
247 m_xmlfile
.Write("\t\t</object>\n");
252 bool rc2xml::Seperator(int ch
)
254 //if ((ch==' ')|(ch==',')|(ch==13)|(ch==10)|(ch=='|')|(ch=='\t'))
255 if ((ch
==' ')|(ch
==',')|(ch
==13)|(ch
==10)|(ch
=='\t'))
267 void rc2xml::ParseGroupBox()
269 // GROUPBOX "Rotate",IDC_STATIC,1,1,71,79
271 wxString phrase
,varname
;
272 phrase
=GetQuoteField();
274 int x
,y
,width
,height
;
275 ReadRect(x
,y
,width
,height
);
277 m_xmlfile
.Write("\t\t<object class=\"wxStaticBox\"");
278 WriteBasicInfo(x
,y
,width
,height
,varname
);
280 m_xmlfile
.Write("\t\t</object>\n");
283 void rc2xml::ReadRect(int & x
, int & y
, int & width
, int & height
)
287 width
=atoi(GetToken());
288 height
=atoi(GetToken());
291 wxString
rc2xml::GetToken()
309 while (Seperator(ch
))
322 while (!Seperator(ch
))
334 wxString
rc2xml::GetQuoteField()
354 void rc2xml::ReadChar(int &ch
)
359 if((result
>=m_filesize
))
362 result
=m_rc
.Read(&ch
,1);
371 void rc2xml::ParseComboBox()
373 /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
374 WS_VSCROLL | WS_TABSTOP */
378 int x
,y
,width
,height
;
379 ReadRect(x
,y
,width
,height
);
381 m_xmlfile
.Write("\t\t<object class=\"wxComboBox\"");
382 WriteBasicInfo(x
,y
,width
,height
,varname
);
383 m_xmlfile
.Write("\n\t\t</object>\n");
387 void rc2xml::ParseMenu(wxString varname
)
391 //Write menubar to xml file
392 m_xmlfile
.Write("\t<object class=\"wxMenuBar\"");
393 //Avoid duplicate names this way
394 varname
.Replace("IDR_","MB_");
396 m_xmlfile
.Write(">\n");
398 while ((token
!="BEGIN")&(token
!="{"))
401 while ((token
!="END")&(token
!="}"))
409 m_xmlfile
.Write("\t</object>\n");
412 void rc2xml::ParsePopupMenu()
414 static int menucount
=0;
416 wxString token
,name
,msg
,longhelp
,tip
;
417 token
=GetQuoteField();
419 //Remove \t because it causes problems
421 //spot=token.First("\\t");
422 //token=token.Left(spot);
425 //Generate a fake name since RC menus don't have one
426 name
<<"Menu_"<<menucount
;
427 m_xmlfile
.Write("\t\t<object class=\"wxMenu\"");
429 m_xmlfile
.Write(">\n");
432 while ((token
!="BEGIN")&(token
!="{"))
435 while ((token
!="END")&(token
!="}"))
441 if (token
=="MENUITEM")
444 m_xmlfile
.Write("\t\t\t</object>\n");
447 wxString
rc2xml::PeekToken()
457 //MS Windows pain in the butt CONTROL
458 void rc2xml::ParseControlMS()
460 wxString label
,varname
,kindctrl
,token
;
463 if (token
.Contains("\""))
464 ParseNormalMSControl();
466 ParseWeirdMSControl();
470 /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
471 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
474 void rc2xml::ParseSlider(wxString label
, wxString varname
)
476 wxString token
,style
;
478 if (token
.Find("TBS_VERT")!=-1)
479 style
+="wxSL_VERTICAL";
480 //MFC RC Default is horizontal
482 style
+="wxSL_HORIZONTAL";
484 int x
,y
,width
,height
;
485 ReadRect(x
,y
,width
,height
);
486 m_xmlfile
.Write("\t\t<object class=\"wxSlider\"");
487 WriteBasicInfo(x
,y
,width
,height
,varname
);
489 m_xmlfile
.Write("\n\t\t</object>\n");
493 CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
494 WS_BORDER,15,52,154,13
496 void rc2xml::ParseProgressBar(wxString label
, wxString varname
)
498 wxString token
,style
;
501 int x
,y
,width
,height
;
502 ReadRect(x
,y
,width
,height
);
504 //Always horizontal in MFC
505 m_xmlfile
.Write("\t\t<object class=\"wxGauge\"");
506 WriteBasicInfo(x
,y
,width
,height
,varname
);
508 m_xmlfile
.Write("\t\t</object>\n");
511 bool rc2xml::ReadOrs(wxString
& orstring
)
516 if (token
.IsNumber())
520 while(PeekToken()==_T("|"))
523 orstring
+=GetToken();
525 orstring
+=GetToken();
530 //Is it a check button or a radio button
531 void rc2xml::ParseCtrlButton(wxString label
, wxString varname
)
535 int x
,y
,width
,height
;
537 if (token
.Find("BS_AUTOCHECKBOX")!=-1)
539 ReadRect(x
,y
,width
,height
);
540 m_xmlfile
.Write("\t\t<object class=\"wxCheckBox\"");
541 WriteBasicInfo(x
,y
,width
,height
,varname
);
543 m_xmlfile
.Write("\t\t</object>\n");
546 if (token
.Find("BS_AUTORADIOBUTTON")!=-1)
548 ReadRect(x
,y
,width
,height
);
549 m_xmlfile
.Write("\t\t<object class=\"wxRadioButton\"");
550 WriteBasicInfo(x
,y
,width
,height
,varname
);
552 m_xmlfile
.Write("\t\t</object>\n");
558 void rc2xml::WriteSize(int width
, int height
)
561 msg
<<" <size>"<<width
<<","<<height
<<"d</size>";
562 m_xmlfile
.Write(msg
);
565 void rc2xml::WritePosition(int x
, int y
)
568 msg
<<" <pos>"<<x
<<","<<y
<<"d</pos>";
569 m_xmlfile
.Write(msg
);
572 void rc2xml::WriteTitle(wxString title
)
575 msg
=_T("\t\t<title>"+title
+"</title>\n");
576 m_xmlfile
.Write(msg
);
579 void rc2xml::WriteName(wxString name
)
582 //Try to convert any number ids into names
584 //Replace common MS ids with wxWindows ids
585 //I didn't do everyone of them
588 else if (name
=="IDCANCEL")
590 else if (name
=="IDAPPLY")
592 else if (name
=="ID_FILE_OPEN")
594 else if (name
=="ID_FILE_CLOSE")
596 else if (name
=="ID_FILE_SAVE")
598 else if (name
=="ID_FILE_SAVE_AS")
600 else if (name
=="ID_APP_EXIT")
602 else if (name
=="ID_FILE_PRINT")
604 else if (name
=="ID_FILE_PRINT_PREVIEW")
606 else if (name
=="ID_FILE_PRINT_SETUP")
607 name
="wxID_PRINT_SETUP";
608 else if (name
=="ID_APP_ABOUT")
610 else if (name
=="ID_EDIT_UNDO")
612 else if (name
=="ID_EDIT_CUT")
614 else if (name
=="ID_EDIT_COPY")
616 else if (name
=="ID_EDIT_PASTE")
619 m_xmlfile
.Write(" name= \""+name
+"\"");
622 void rc2xml::WriteLabel(wxString label
)
624 label
.Replace("&","$");
625 m_xmlfile
.Write("\t\t\t<label>"+label
+"</label>\n");
628 void rc2xml::WriteBasicInfo(int x
, int y
, int width
, int height
, wxString name
)
631 m_xmlfile
.Write(">\n");
632 m_xmlfile
.Write("\t\t\t");
634 WriteSize(width
,height
);
635 m_xmlfile
.Write("\n");
638 void rc2xml::WriteStyle(wxString style
)
640 if (style
.Length()==0)
642 m_xmlfile
.Write("\n\t\t<style>"+style
+"</style>\n");
645 LISTBOX IDC_LIST1,16,89,48,40,LBS_SORT | LBS_MULTIPLESEL |
646 LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
648 void rc2xml::ParseListBox()
653 int x
,y
,width
,height
;
654 ReadRect(x
,y
,width
,height
);
656 m_xmlfile
.Write("\t\t<object class=\"wxListBox\"");
657 WriteBasicInfo(x
,y
,width
,height
,varname
);
658 m_xmlfile
.Write("\n\t\t</object>\n");
662 CONTROL "",IDC_RICHEDIT1,"RICHEDIT",ES_AUTOHSCROLL | WS_BORDER |
663 WS_TABSTOP,103,110,40,14
665 void rc2xml::ParseRichEdit(wxString label
, wxString varname
)
668 //while (ReadOrs(token));
670 int x
,y
,width
,height
;
671 ReadRect(x
,y
,width
,height
);
673 //Make it a rich text control
674 style
+="wxTE_MULTILINE ";
675 m_xmlfile
.Write("\t\t<object class=\"wxTextCtrl\"");
676 WriteBasicInfo(x
,y
,width
,height
,varname
);
678 m_xmlfile
.Write("\t\t</object>\n");
682 CONTROL "Spin1",IDC_SPIN1,"msctls_updown32",UDS_ARROWKEYS,209,72,
685 void rc2xml::ParseSpinCtrl(wxString label
, wxString varname
)
687 wxString token
,style
;
690 if (token
.Find("UDS_HORZ")!=-1)
691 style
="wxSP_HORIZONTAL";
694 style
="wxSP_VERTICAL";
696 int x
,y
,width
,height
;
697 ReadRect(x
,y
,width
,height
);
698 m_xmlfile
.Write("\t\t<object class=\"wxSpinButton\"");
699 WriteBasicInfo(x
,y
,width
,height
,varname
);
701 m_xmlfile
.Write("\n\t\t</object>\n");
705 void rc2xml::FirstPass()
707 wxString token
,prevtok
;
712 ParseBitmap(prevtok
);
713 else if (token
=="STRINGTABLE")
714 ParseStringTable(prevtok
);
715 else if (token
=="ICON")
722 void rc2xml::ParseBitmap(wxString varname
)
724 wxString token
,*bitmapfile
;
727 //Microsoft notation?
728 if (token
=="DISCARDABLE")
733 bitmapfile
=new wxString
;
734 *bitmapfile
=GetQuoteField();
735 m_bitmaplist
->Append(varname
,bitmapfile
);
740 void rc2xml::SecondPass()
742 wxString token
,prevtok
;
747 ParseDialog(prevtok
);
748 else if (token
=="MENU")
750 else if (token
=="TOOLBAR")
751 ParseToolBar(prevtok
);
758 void rc2xml::ParseToolBar(wxString varname
)
762 wxASSERT_MSG(token
=="DISCARDABLE","Error in toolbar parsing");
763 //Look up bitmap for toolbar and load
764 wxNode
*node
=m_bitmaplist
->Find(LookUpId(varname
));
765 wxString
*bitmappath
;
766 bitmappath
=(wxString
*)node
->Data();
768 if (!bitmap
.LoadFile(*bitmappath
,wxBITMAP_TYPE_BMP
))
769 wxLogError("Unable to load bitmap:"+*bitmappath
);
771 //Write toolbar to xml file
772 m_xmlfile
.Write(" <object class=\"wxToolBar\"");
773 //Avoid duplicate names this way
774 varname
.Replace("IDR_","TB_");
776 m_xmlfile
.Write(">\n");
782 //Grab width and height
784 width
=atoi(GetToken());
785 height
=atoi(GetToken());
788 wxString buttonname
,msg
,tip
,longhelp
;
790 while ((token
!="BEGIN"))
793 while ((token
!="END")&(token
!="}"))
797 buttonname
=GetToken();
798 m_xmlfile
.Write("\t\t\t<object class=\"tool\"");
799 WriteName(buttonname
);
800 m_xmlfile
.Write(">\n");
801 //Write tool tip if any
802 if (LookUpString(buttonname
,msg
))
804 SplitHelp(msg
,tip
,longhelp
);
805 m_xmlfile
.Write("\t\t\t\t<tooltip>"+tip
+"</tooltip>\n");
806 m_xmlfile
.Write(" <longhelp>"+longhelp
+"</longhelp>\n");
808 //Make a bitmap file name
809 buttonname
=CleanName(buttonname
);
811 m_xmlfile
.Write("\t\t\t\t<bitmap>"+buttonname
+"</bitmap>\n");
812 WriteToolButton(buttonname
,c
,width
,height
,bitmap
);
813 m_xmlfile
.Write("\t\t\t</object>\n");
816 else if (token
=="SEPARATOR")
818 m_xmlfile
.Write("\t\t\t<object class=\"separator\"/>\n");
822 m_xmlfile
.Write("\t</object>\n");
825 //Extract bitmaps from larger toolbar bitmap
826 void rc2xml::WriteToolButton(wxString name
,int index
, int width
, int height
, wxBitmap bitmap
)
830 wxRect
r(x
,0,width
,height
);
832 little
=bitmap
.GetSubBitmap(r
);
833 little
.SaveFile(m_targetpath
+name
,wxBITMAP_TYPE_BMP
);
836 void rc2xml::ParseStringTable(wxString varname
)
840 while ((token
!="BEGIN"))
845 while ((token
!="END")&(token
!="}"))
848 *msg
=GetQuoteField();
849 m_stringtable
->Append(token
,msg
);
855 bool rc2xml::LookUpString(wxString strid
,wxString
& st
)
857 wxNode
*node
=m_stringtable
->Find(strid
);
862 s
=(wxString
*)node
->Data();
868 bool rc2xml::SplitHelp(wxString msg
, wxString
&shorthelp
, wxString
&longhelp
)
871 spot
=msg
.Find("\\n");
878 longhelp
=msg
.Left(spot
);
879 spot
=msg
.Length()-spot
-2;
880 shorthelp
=msg
.Right(spot
);
884 void rc2xml::ParseMenuItem()
886 wxString token
,name
,msg
,tip
,longhelp
;
888 if (PeekToken()=="SEPARATOR")
890 m_xmlfile
.Write("\t\t\t<object class=\"separator\"/>\n");
894 token
=GetQuoteField();
896 //Remove \t because it causes problems
897 //spot=token.First("\\t");
898 //token=token.Left(spot);
899 m_xmlfile
.Write("\t\t\t<object class=\"wxMenuItem\"");
901 m_xmlfile
.Write(">\n");
903 //Look up help if any listed in stringtable
904 if (LookUpString(name
,msg
))
906 SplitHelp(msg
,tip
,longhelp
);
907 m_xmlfile
.Write("\t\t\t<help>"
908 +longhelp
+"</help>\n");
910 //look for extra attributes like checked and break
913 while ((ptoken
!="MENUITEM")&(ptoken
!="POPUP")&(ptoken
!="END"))
916 if (token
=="CHECKED")
917 m_xmlfile
.Write("\t\t\t<checkable>1</checkable>\n");
918 else if (token
=="MENUBREAK");
919 //m_xmlfile.Write("\t\t\t</break>\n");
920 else if (token
=="GRAYED");
922 wxLogError("Unknown Menu Item token:"+token
);
926 m_xmlfile
.Write("\t\t\t</object>\n");
930 //ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
931 void rc2xml::ParseIconStatic()
934 wxString varname
,iconname
;
939 int x
,y
,width
,height
;
940 ReadRect(x
,y
,width
,height
);
942 m_xmlfile
.Write("\t\t<object class=\"wxStaticBitmap\"");
943 WriteBasicInfo(x
,y
,width
,height
,varname
);
944 //Save icon as a bitmap
946 m_xmlfile
.Write("\t\t</object>\n");
949 //IDR_MAINFRAME ICON DISCARDABLE "res\\mfcexample.ico"
950 void rc2xml::ParseIcon(wxString varname
)
952 wxString token
,*iconfile
;
953 iconfile
=new wxString
;
956 *iconfile
=GetQuoteField();
957 m_iconlist
->Append(varname
,iconfile
);
962 wxString
rc2xml::CleanName(wxString name
)
965 name
.Replace("id_","");
966 name
.Replace("idr_","");
967 name
.Replace("idb_","");
968 name
.Replace("idc_","");
969 name
.Replace(".ico","");
970 name
.Replace(".bmp","");
973 // And the award for most messed up control goes to...
974 // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
975 void rc2xml::ParseStaticBitmap(wxString bitmapname
, wxString varname
)
983 int x
,y
,width
,height
;
984 ReadRect(x
,y
,width
,height
);
986 m_xmlfile
.Write("\t\t<object class=\"wxStaticBitmap\"");
987 WriteBasicInfo(x
,y
,width
,height
,varname
);
988 WriteBitmap(bitmapname
);
989 m_xmlfile
.Write("\t\t</object>\n");
993 void rc2xml::ParseNormalMSControl()
995 wxString label
,varname
,kindctrl
;
997 label
=GetQuoteField();
999 kindctrl
=GetQuoteField();
1000 kindctrl
.MakeUpper();
1002 if (kindctrl
=="MSCTLS_UPDOWN32")
1003 ParseSpinCtrl(label
,varname
);
1004 if (kindctrl
=="MSCTLS_TRACKBAR32")
1005 ParseSlider(label
,varname
);
1006 if (kindctrl
=="MSCTLS_PROGRESS32")
1007 ParseProgressBar(label
,varname
);
1008 if (kindctrl
=="SYSTREEVIEW32")
1009 ParseTreeCtrl(label
,varname
);
1010 if (kindctrl
=="SYSMONTHCAL32")
1011 ParseCalendar(label
,varname
);
1012 if (kindctrl
=="SYSLISTVIEW32")
1013 ParseListCtrl(label
,varname
);
1014 if (kindctrl
=="BUTTON")
1015 ParseCtrlButton(label
,varname
);
1016 if (kindctrl
=="RICHEDIT")
1017 ParseRichEdit(label
,varname
);
1021 void rc2xml::ParseWeirdMSControl()
1028 kindctrl
=GetQuoteField();
1029 kindctrl
.MakeUpper();
1030 // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
1031 if (kindctrl
=="STATIC")
1033 if (PeekToken()=="SS_BITMAP")
1034 ParseStaticBitmap(id
,varname
);
1036 wxLogError("Unknown MS Control Static token");
1040 //SCROLLBAR IDC_SCROLLBAR1,219,56,10,40,SBS_VERT
1042 void rc2xml::ParseScrollBar()
1048 int x
,y
,width
,height
;
1049 ReadRect(x
,y
,width
,height
);
1054 if (token
.Find("SBS_VERT")!=-1)
1055 style
=_T("wxSB_VERTICAL");
1056 //Default MFC style is horizontal
1058 style
=_T("wxSB_HORIZONTAL");
1060 m_xmlfile
.Write("\t\t<object class=\"wxScrollBar\"");
1061 WriteBasicInfo(x
,y
,width
,height
,varname
);
1063 m_xmlfile
.Write("\n\t\t</object>\n");
1066 // CONTROL "Tree1",IDC_TREE1,"SysTreeView32",WS_BORDER | WS_TABSTOP,
1069 void rc2xml::ParseTreeCtrl(wxString label
, wxString varname
)
1072 //while (ReadOrs(token));
1074 int x
,y
,width
,height
;
1075 ReadRect(x
,y
,width
,height
);
1076 m_xmlfile
.Write("\t\t<object class=\"wxTreeCtrl\"");
1077 WriteBasicInfo(x
,y
,width
,height
,varname
);
1078 m_xmlfile
.Write("\t\t</object>\n");
1081 // CONTROL "MonthCalendar1",IDC_MONTHCALENDAR1,"SysMonthCal32",
1082 //MCS_NOTODAY | WS_TABSTOP,105,71,129,89
1084 void rc2xml::ParseCalendar(wxString label
, wxString varname
)
1087 //while (ReadOrs(token));
1089 int x
,y
,width
,height
;
1090 ReadRect(x
,y
,width
,height
);
1091 m_xmlfile
.Write("\t\t<object class=\"wxCalendarCtrl\"");
1092 WriteBasicInfo(x
,y
,width
,height
,varname
);
1093 m_xmlfile
.Write("\t\t</object>\n");
1095 // CONTROL "List1",IDC_LIST1,"SysListView32",WS_BORDER | WS_TABSTOP,
1098 void rc2xml::ParseListCtrl(wxString label
, wxString varname
)
1101 //while (ReadOrs(token));
1103 int x
,y
,width
,height
;
1104 ReadRect(x
,y
,width
,height
);
1105 m_xmlfile
.Write("\t\t<object class=\"wxListCtrl\"");
1106 WriteBasicInfo(x
,y
,width
,height
,varname
);
1107 m_xmlfile
.Write("\t\t</object>\n");
1111 void rc2xml::WriteBitmap(wxString bitmapname
)
1114 wxNode
*node
=m_bitmaplist
->Find(LookUpId(bitmapname
));
1117 m_xmlfile
.Write("\t\t\t<bitmap>missingfile</bitmap>\n");
1118 wxLogError("Unable to find bitmap:"+bitmapname
);
1122 wxString
*bitmappath
;
1123 bitmappath
=(wxString
*)node
->Data();
1124 bitmapname
=wxFileNameFromPath(*bitmappath
);
1126 if (!bitmap
.LoadFile(*bitmappath
,wxBITMAP_TYPE_BMP
))
1127 wxLogError("Unable to load bitmap:"+*bitmappath
);
1129 //Make a bitmap file name
1130 bitmapname
=CleanName(bitmapname
);
1132 m_xmlfile
.Write("\t\t\t<bitmap>"+bitmapname
+"</bitmap>\n");
1133 bitmap
.SaveFile(m_targetpath
+bitmapname
,wxBITMAP_TYPE_BMP
);
1136 void rc2xml::WriteIcon(wxString iconname
)
1138 wxNode
*node
=m_iconlist
->Find(iconname
);
1141 m_xmlfile
.Write("\t\t\t<bitmap>missing_file</bitmap>\n");
1142 wxLogError("Unable to find icon:"+iconname
);
1145 iconpath
=(wxString
*)node
->Data();
1148 if (!icon
.LoadFile(*iconpath
,wxBITMAP_TYPE_ICO
))
1149 wxLogError("Unable to load icon:"+*iconpath
);
1151 bitmap
.CopyFromIcon(icon
);
1155 iconname
=wxFileNameFromPath(*iconpath
);
1156 //Make a bitmap file name
1157 iconname
=CleanName(iconname
);
1159 m_xmlfile
.Write("\t\t\t<bitmap>"+iconname
+"</bitmap>\n");
1160 bitmap
.SaveFile(m_targetpath
+iconname
,wxBITMAP_TYPE_BMP
);
1164 /*Unfortunately sometimes the great MSVC Resource editor decides
1165 to use numbers instead of the word id. I have no idea why they
1166 do this, but that is the way it is.
1168 /* this is a quick and dirty way to parse the resource.h file
1169 it will not recognize #ifdef so it can be easily fooled
1171 void rc2xml::ParseResourceHeader()
1174 //Attempt to load resource.h in current path
1175 if (!r
.Open("resource.h"))
1177 wxLogError("Warining Unable to load resource.h file");
1183 wxStringTokenizer tok
;
1189 //Read through entire file
1190 for ( str
= r
.GetFirstLine(); !r
.Eof(); str
= r
.GetNextLine() )
1192 if (str
.Find("#define")!=-1)
1195 //Just ignore #define token
1197 v
=tok
.GetNextToken();
1198 id
=tok
.GetNextToken();
1201 varname
=new wxString
;
1204 m_resourcelist
->Append(n
,varname
);
1214 wxString
rc2xml::LookUpId(wxString id
)
1222 wxNode
*node
=m_resourcelist
->Find(n
);
1227 s
=(wxString
*)node
->Data();