]>
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();
72 result
=m_xmlfile
.Open(xmlfile
.c_str(),"w+t");
73 wxASSERT_MSG(result
,"Couldn't create XML file");
78 /* Write Basic header for XML file */
79 m_xmlfile
.Write("<?xml version=\"1.0\" ?>\n");
80 m_xmlfile
.Write("<resource>\n");
83 ParseResourceHeader();
84 //Gather all the resource we need for toolbars,menus, and etc
88 //Read in dialogs, toolbars,menus
91 m_xmlfile
.Write("</resource>\n");
99 void rc2xml::ParseDialog(wxString dlgname
)
102 static int dlgid
=999;
104 /* Make sure that this really is a dialog
105 microsoft reuses the keyword DIALOG for other things
108 //Microsoft notation?
109 if (token
=="DISCARDABLE")
114 //Error isn't a Dialog resource eject eject
115 if (!token
.IsNumber())
118 //Record x,y,width,height
119 int x
,y
,width
,height
;
120 ReadRect(x
,y
,width
,height
);
124 wxString ptsize
,face
;
126 m_xmlfile
.Write("\t<object class=\"wxDialog\"");
127 //Avoid duplicate names this way
128 dlgname
.Replace("IDD_","DLG_");
129 WriteBasicInfo(x
,y
,width
,height
,dlgname
);
133 while ((token
!="BEGIN")&(token
!="{"))
135 if (token
=="CAPTION")
137 title
=GetQuoteField();
140 //TODO fix face name so that it is cross platform name
141 // FONT 8, "MS Sans Serif"
145 face
=GetQuoteField();
146 m_xmlfile
.Write("\t\t<font>\n");
147 m_xmlfile
.Write("\t\t\t<size>"+ptsize
+"</size>\n");
148 m_xmlfile
.Write("\t\t\t<face>"+face
+"</face>\n");
149 m_xmlfile
.Write("\t\t</font>\n");
156 m_xmlfile
.Write("\t</object>\n");
161 EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT
163 LTEXT "Bands",IDC_STATIC,11,86,21,8
164 EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL
167 void rc2xml::ParseControls()
172 while ((token
!="END")&(token
!="}"))
176 else if (token
=="EDITTEXT")
178 else if (token
=="PUSHBUTTON")
180 else if (token
=="DEFPUSHBUTTON")
182 else if (token
=="GROUPBOX")
184 else if (token
=="COMBOBOX")
186 else if (token
=="CONTROL")
188 else if (token
=="LISTBOX")
190 else if (token
=="ICON")
192 else if (token
=="SCROLLBAR")
198 //LTEXT "Radius",IDC_STATIC,9,67,23,8
199 void rc2xml::ParseStaticText()
202 wxString phrase
,varname
;
203 phrase
=GetQuoteField();
205 int x
,y
,width
,height
;
206 ReadRect(x
,y
,width
,height
);
208 m_xmlfile
.Write("\t\t<object class=\"wxStaticText\"");
209 WriteBasicInfo(x
,y
,width
,height
,varname
);WriteLabel(phrase
);
210 m_xmlfile
.Write("\t\t</object>\n");
213 //EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
214 void rc2xml::ParseTextCtrl()
217 wxString varname
,style
;
219 int x
,y
,width
,height
;
220 ReadRect(x
,y
,width
,height
);
223 m_xmlfile
.Write("\t\t<object class\"wxTextCtrl\"");
224 WriteBasicInfo(x
,y
,width
,height
,varname
);
225 m_xmlfile
.Write("\t\t</object>\n");
228 //PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
229 void rc2xml::ParsePushButton()
232 wxString phrase
,varname
;
233 phrase
=GetQuoteField();
236 int x
,y
,width
,height
;
237 ReadRect(x
,y
,width
,height
);
239 m_xmlfile
.Write("\t\t<object class\"wxButton\"");
240 WriteBasicInfo(x
,y
,width
,height
,varname
);
242 m_xmlfile
.Write("\t\t</object>\n");
247 bool rc2xml::Seperator(int ch
)
249 //if ((ch==' ')|(ch==',')|(ch==13)|(ch==10)|(ch=='|')|(ch=='\t'))
250 if ((ch
==' ')|(ch
==',')|(ch
==13)|(ch
==10)|(ch
=='\t'))
262 void rc2xml::ParseGroupBox()
264 // GROUPBOX "Rotate",IDC_STATIC,1,1,71,79
266 wxString phrase
,varname
;
267 phrase
=GetQuoteField();
269 int x
,y
,width
,height
;
270 ReadRect(x
,y
,width
,height
);
272 m_xmlfile
.Write("\t\t<object class=\"wxStaticBox\"");
273 WriteBasicInfo(x
,y
,width
,height
,varname
);
275 m_xmlfile
.Write("\t\t</object>\n");
278 void rc2xml::ReadRect(int & x
, int & y
, int & width
, int & height
)
282 width
=atoi(GetToken());
283 height
=atoi(GetToken());
286 wxString
rc2xml::GetToken()
304 while (Seperator(ch
))
317 while (!Seperator(ch
))
329 wxString
rc2xml::GetQuoteField()
349 void rc2xml::ReadChar(int &ch
)
354 if((result
>=m_filesize
))
357 result
=m_rc
.Read(&ch
,1);
366 void rc2xml::ParseComboBox()
368 /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
369 WS_VSCROLL | WS_TABSTOP */
373 int x
,y
,width
,height
;
374 ReadRect(x
,y
,width
,height
);
376 m_xmlfile
.Write("\t\t<object class=\"wxComboBox\"");
377 WriteBasicInfo(x
,y
,width
,height
,varname
);
378 m_xmlfile
.Write("\n\t\t</object>\n");
382 void rc2xml::ParseMenu(wxString varname
)
386 //Write menubar to xml file
387 m_xmlfile
.Write("\t<object class=\"wxMenuBar\"");
388 //Avoid duplicate names this way
389 varname
.Replace("IDR_","MB_");
391 m_xmlfile
.Write(">\n");
393 while ((token
!="BEGIN")&(token
!="{"))
396 while ((token
!="END")&(token
!="}"))
404 m_xmlfile
.Write("\t</object>\n");
407 void rc2xml::ParsePopupMenu()
409 static int menucount
=0;
411 wxString token
,name
,msg
,longhelp
,tip
;
412 token
=GetQuoteField();
414 //Remove \t because it causes problems
416 //spot=token.First("\\t");
417 //token=token.Left(spot);
420 //Generate a fake name since RC menus don't have one
421 name
<<"Menu_"<<menucount
;
422 m_xmlfile
.Write("\t\t<object class=\"wxMenu\"");
424 m_xmlfile
.Write(">\n");
427 while ((token
!="BEGIN")&(token
!="{"))
430 while ((token
!="END")&(token
!="}"))
436 if (token
=="MENUITEM")
439 m_xmlfile
.Write("\t\t\t</object>\n");
442 wxString
rc2xml::PeekToken()
452 //MS Windows pain in the butt CONTROL
453 void rc2xml::ParseControlMS()
455 wxString label
,varname
,kindctrl
,token
;
458 if (token
.Contains("\""))
459 ParseNormalMSControl();
461 ParseWeirdMSControl();
465 /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
466 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
469 void rc2xml::ParseSlider(wxString label
, wxString varname
)
471 wxString token
,style
;
473 if (token
.Find("TBS_VERT")!=-1)
474 style
+="wxSL_VERTICAL";
475 //MFC RC Default is horizontal
477 style
+="wxSL_HORIZONTAL";
479 int x
,y
,width
,height
;
480 ReadRect(x
,y
,width
,height
);
481 m_xmlfile
.Write("\t\t<object class=\"wxSlider\"");
482 WriteBasicInfo(x
,y
,width
,height
,varname
);
484 m_xmlfile
.Write("\n\t\t</object>\n");
488 CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
489 WS_BORDER,15,52,154,13
491 void rc2xml::ParseProgressBar(wxString label
, wxString varname
)
493 wxString token
,style
;
496 int x
,y
,width
,height
;
497 ReadRect(x
,y
,width
,height
);
499 //Always horizontal in MFC
500 m_xmlfile
.Write("\t\t<object class=\"wxGauge\"");
501 WriteBasicInfo(x
,y
,width
,height
,varname
);
503 m_xmlfile
.Write("\t\t</object>\n");
506 bool rc2xml::ReadOrs(wxString
& orstring
)
511 if (token
.IsNumber())
515 while(PeekToken()==_T("|"))
518 orstring
+=GetToken();
520 orstring
+=GetToken();
525 //Is it a check button or a radio button
526 void rc2xml::ParseCtrlButton(wxString label
, wxString varname
)
530 int x
,y
,width
,height
;
532 if (token
.Find("BS_AUTOCHECKBOX")!=-1)
534 ReadRect(x
,y
,width
,height
);
535 m_xmlfile
.Write("\t\t<object class=\"wxCheckBox\"");
536 WriteBasicInfo(x
,y
,width
,height
,varname
);
538 m_xmlfile
.Write("\t\t</object>\n");
541 if (token
.Find("BS_AUTORADIOBUTTON")!=-1)
543 ReadRect(x
,y
,width
,height
);
544 m_xmlfile
.Write("\t\t<object class=\"wxRadioButton\"");
545 WriteBasicInfo(x
,y
,width
,height
,varname
);
547 m_xmlfile
.Write("\t\t</object>\n");
553 void rc2xml::WriteSize(int width
, int height
)
556 msg
<<" <size>"<<width
<<","<<height
<<"d</size>";
557 m_xmlfile
.Write(msg
);
560 void rc2xml::WritePosition(int x
, int y
)
563 msg
<<" <pos>"<<x
<<","<<y
<<"d</pos>";
564 m_xmlfile
.Write(msg
);
567 void rc2xml::WriteTitle(wxString title
)
570 msg
=_T("\t\t<title>"+title
+"</title>\n");
571 m_xmlfile
.Write(msg
);
574 void rc2xml::WriteName(wxString name
)
577 //Try to convert any number ids into names
579 //Replace common MS ids with wxWindows ids
580 //I didn't do everyone of them
583 else if (name
=="IDCANCEL")
585 else if (name
=="IDAPPLY")
587 else if (name
=="ID_FILE_OPEN")
589 else if (name
=="ID_FILE_CLOSE")
591 else if (name
=="ID_FILE_SAVE")
593 else if (name
=="ID_FILE_SAVE_AS")
595 else if (name
=="ID_APP_EXIT")
597 else if (name
=="ID_FILE_PRINT")
599 else if (name
=="ID_FILE_PRINT_PREVIEW")
601 else if (name
=="ID_FILE_PRINT_SETUP")
602 name
="wxID_PRINT_SETUP";
603 else if (name
=="ID_APP_ABOUT")
605 else if (name
=="ID_EDIT_UNDO")
607 else if (name
=="ID_EDIT_CUT")
609 else if (name
=="ID_EDIT_COPY")
611 else if (name
=="ID_EDIT_PASTE")
614 m_xmlfile
.Write(" name= \""+name
+"\"");
617 void rc2xml::WriteLabel(wxString label
)
619 label
.Replace("&","$");
620 m_xmlfile
.Write("\t\t\t<label>"+label
+"</label>\n");
623 void rc2xml::WriteBasicInfo(int x
, int y
, int width
, int height
, wxString name
)
626 m_xmlfile
.Write(">\n");
627 m_xmlfile
.Write("\t\t\t");
629 WriteSize(width
,height
);
630 m_xmlfile
.Write("\n");
633 void rc2xml::WriteStyle(wxString style
)
635 if (style
.Length()==0)
637 m_xmlfile
.Write("\n\t\t<style>"+style
+"</style>\n");
640 LISTBOX IDC_LIST1,16,89,48,40,LBS_SORT | LBS_MULTIPLESEL |
641 LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
643 void rc2xml::ParseListBox()
648 int x
,y
,width
,height
;
649 ReadRect(x
,y
,width
,height
);
651 m_xmlfile
.Write("\t\t<object class=\"wxListBox\"");
652 WriteBasicInfo(x
,y
,width
,height
,varname
);
653 m_xmlfile
.Write("\n\t\t</object>\n");
657 CONTROL "",IDC_RICHEDIT1,"RICHEDIT",ES_AUTOHSCROLL | WS_BORDER |
658 WS_TABSTOP,103,110,40,14
660 void rc2xml::ParseRichEdit(wxString label
, wxString varname
)
663 //while (ReadOrs(token));
665 int x
,y
,width
,height
;
666 ReadRect(x
,y
,width
,height
);
668 //Make it a rich text control
669 style
+="wxTE_MULTILINE ";
670 m_xmlfile
.Write("\t\t<object class=\"wxTextCtrl\"");
671 WriteBasicInfo(x
,y
,width
,height
,varname
);
673 m_xmlfile
.Write("\t\t</object>\n");
677 CONTROL "Spin1",IDC_SPIN1,"msctls_updown32",UDS_ARROWKEYS,209,72,
680 void rc2xml::ParseSpinCtrl(wxString label
, wxString varname
)
682 wxString token
,style
;
685 if (token
.Find("UDS_HORZ")!=-1)
686 style
="wxSP_HORIZONTAL";
689 style
="wxSP_VERTICAL";
691 int x
,y
,width
,height
;
692 ReadRect(x
,y
,width
,height
);
693 m_xmlfile
.Write("\t\t<object class=\"wxSpinButton\"");
694 WriteBasicInfo(x
,y
,width
,height
,varname
);
696 m_xmlfile
.Write("\n\t\t</object>\n");
700 void rc2xml::FirstPass()
702 wxString token
,prevtok
;
707 ParseBitmap(prevtok
);
708 else if (token
=="STRINGTABLE")
709 ParseStringTable(prevtok
);
710 else if (token
=="ICON")
717 void rc2xml::ParseBitmap(wxString varname
)
719 wxString token
,*bitmapfile
;
722 //Microsoft notation?
723 if (token
=="DISCARDABLE")
728 bitmapfile
=new wxString
;
729 *bitmapfile
=GetQuoteField();
730 m_bitmaplist
->Append(varname
,bitmapfile
);
735 void rc2xml::SecondPass()
737 wxString token
,prevtok
;
742 ParseDialog(prevtok
);
743 else if (token
=="MENU")
745 else if (token
=="TOOLBAR")
746 ParseToolBar(prevtok
);
753 void rc2xml::ParseToolBar(wxString varname
)
757 wxASSERT_MSG(token
=="DISCARDABLE","Error in toolbar parsing");
758 //Look up bitmap for toolbar and load
759 wxNode
*node
=m_bitmaplist
->Find(LookUpId(varname
));
760 wxString
*bitmappath
;
761 bitmappath
=(wxString
*)node
->Data();
763 if (!bitmap
.LoadFile(*bitmappath
,wxBITMAP_TYPE_BMP
))
764 wxLogError("Unable to load bitmap:"+*bitmappath
);
766 //Write toolbar to xml file
767 m_xmlfile
.Write(" <object class=\"wxToolBar\"");
768 //Avoid duplicate names this way
769 varname
.Replace("IDR_","TB_");
771 m_xmlfile
.Write(">\n");
777 //Grab width and height
779 width
=atoi(GetToken());
780 height
=atoi(GetToken());
783 wxString buttonname
,msg
,tip
,longhelp
;
785 while ((token
!="BEGIN"))
788 while ((token
!="END")&(token
!="}"))
792 buttonname
=GetToken();
793 m_xmlfile
.Write("\t\t\t<object class=\"tool\"");
794 WriteName(buttonname
);
795 m_xmlfile
.Write(">\n");
796 //Write tool tip if any
797 if (LookUpString(buttonname
,msg
))
799 SplitHelp(msg
,tip
,longhelp
);
800 m_xmlfile
.Write("\t\t\t\t<tooltip>"+tip
+"</tooltip>\n");
801 m_xmlfile
.Write(" <longhelp>"+longhelp
+"</longhelp>\n");
803 //Make a bitmap file name
804 buttonname
=CleanName(buttonname
);
806 m_xmlfile
.Write("\t\t\t\t<bitmap>"+buttonname
+"</bitmap>\n");
807 WriteToolButton(buttonname
,c
,width
,height
,bitmap
);
808 m_xmlfile
.Write("\t\t\t</object>\n");
811 else if (token
=="SEPARATOR")
813 m_xmlfile
.Write("\t\t\t<object class=\"separator\"/>\n");
817 m_xmlfile
.Write("\t</object>\n");
820 //Extract bitmaps from larger toolbar bitmap
821 void rc2xml::WriteToolButton(wxString name
,int index
, int width
, int height
, wxBitmap bitmap
)
825 wxRect
r(x
,0,width
,height
);
827 little
=bitmap
.GetSubBitmap(r
);
828 little
.SaveFile(name
,wxBITMAP_TYPE_BMP
);
831 void rc2xml::ParseStringTable(wxString varname
)
835 while ((token
!="BEGIN"))
840 while ((token
!="END")&(token
!="}"))
843 *msg
=GetQuoteField();
844 m_stringtable
->Append(token
,msg
);
850 bool rc2xml::LookUpString(wxString strid
,wxString
& st
)
852 wxNode
*node
=m_stringtable
->Find(strid
);
857 s
=(wxString
*)node
->Data();
863 bool rc2xml::SplitHelp(wxString msg
, wxString
&shorthelp
, wxString
&longhelp
)
866 spot
=msg
.Find("\\n");
873 longhelp
=msg
.Left(spot
);
874 spot
=msg
.Length()-spot
-2;
875 shorthelp
=msg
.Right(spot
);
879 void rc2xml::ParseMenuItem()
881 wxString token
,name
,msg
,tip
,longhelp
;
883 if (PeekToken()=="SEPARATOR")
885 m_xmlfile
.Write("\t\t\t<object class=\"separator\"/>\n");
889 token
=GetQuoteField();
891 //Remove \t because it causes problems
892 //spot=token.First("\\t");
893 //token=token.Left(spot);
894 m_xmlfile
.Write("\t\t\t<object class=\"wxMenuItem\"");
896 m_xmlfile
.Write(">\n");
898 //Look up help if any listed in stringtable
899 if (LookUpString(name
,msg
))
901 SplitHelp(msg
,tip
,longhelp
);
902 m_xmlfile
.Write("\t\t\t<help>"
903 +longhelp
+"</help>\n");
905 //look for extra attributes like checked and break
908 while ((ptoken
!="MENUITEM")&(ptoken
!="POPUP")&(ptoken
!="END"))
911 if (token
=="CHECKED")
912 m_xmlfile
.Write("\t\t\t<checkable>1</checkable>\n");
913 else if (token
=="MENUBREAK");
914 //m_xmlfile.Write("\t\t\t</break>\n");
915 else if (token
=="GRAYED");
917 wxLogError("Unknown Menu Item token:"+token
);
921 m_xmlfile
.Write("\t\t\t</object>\n");
925 //ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
926 void rc2xml::ParseIconStatic()
929 wxString varname
,iconname
;
934 int x
,y
,width
,height
;
935 ReadRect(x
,y
,width
,height
);
937 m_xmlfile
.Write("\t\t<object class=\"wxStaticBitmap\"");
938 WriteBasicInfo(x
,y
,width
,height
,varname
);
939 //Save icon as a bitmap
941 m_xmlfile
.Write("\t\t</object>\n");
944 //IDR_MAINFRAME ICON DISCARDABLE "res\\mfcexample.ico"
945 void rc2xml::ParseIcon(wxString varname
)
947 wxString token
,*iconfile
;
948 iconfile
=new wxString
;
951 *iconfile
=GetQuoteField();
952 m_iconlist
->Append(varname
,iconfile
);
957 wxString
rc2xml::CleanName(wxString name
)
960 name
.Replace("id_","");
961 name
.Replace("idr_","");
962 name
.Replace("idb_","");
963 name
.Replace("idc_","");
966 // And the award for most messed up control goes to...
967 // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
968 void rc2xml::ParseStaticBitmap(wxString bitmapname
, wxString varname
)
976 int x
,y
,width
,height
;
977 ReadRect(x
,y
,width
,height
);
979 m_xmlfile
.Write("\t\t<object class=\"wxStaticBitmap\"");
980 WriteBasicInfo(x
,y
,width
,height
,varname
);
981 WriteBitmap(bitmapname
);
982 m_xmlfile
.Write("\t\t</object>\n");
986 void rc2xml::ParseNormalMSControl()
988 wxString label
,varname
,kindctrl
;
990 label
=GetQuoteField();
992 kindctrl
=GetQuoteField();
993 kindctrl
.MakeUpper();
995 if (kindctrl
=="MSCTLS_UPDOWN32")
996 ParseSpinCtrl(label
,varname
);
997 if (kindctrl
=="MSCTLS_TRACKBAR32")
998 ParseSlider(label
,varname
);
999 if (kindctrl
=="MSCTLS_PROGRESS32")
1000 ParseProgressBar(label
,varname
);
1001 if (kindctrl
=="SYSTREEVIEW32")
1002 ParseTreeCtrl(label
,varname
);
1003 if (kindctrl
=="SYSMONTHCAL32")
1004 ParseCalendar(label
,varname
);
1005 if (kindctrl
=="SYSLISTVIEW32")
1006 ParseListCtrl(label
,varname
);
1007 if (kindctrl
=="BUTTON")
1008 ParseCtrlButton(label
,varname
);
1009 if (kindctrl
=="RICHEDIT")
1010 ParseRichEdit(label
,varname
);
1014 void rc2xml::ParseWeirdMSControl()
1021 kindctrl
=GetQuoteField();
1022 kindctrl
.MakeUpper();
1023 // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
1024 if (kindctrl
=="STATIC")
1026 if (PeekToken()=="SS_BITMAP")
1027 ParseStaticBitmap(id
,varname
);
1029 wxLogError("Unknown MS Control Static token");
1033 //SCROLLBAR IDC_SCROLLBAR1,219,56,10,40,SBS_VERT
1035 void rc2xml::ParseScrollBar()
1041 int x
,y
,width
,height
;
1042 ReadRect(x
,y
,width
,height
);
1047 if (token
.Find("SBS_VERT")!=-1)
1048 style
=_T("wxSB_VERTICAL");
1049 //Default MFC style is horizontal
1051 style
=_T("wxSB_HORIZONTAL");
1053 m_xmlfile
.Write("\t\t<object class=\"wxScrollBar\"");
1054 WriteBasicInfo(x
,y
,width
,height
,varname
);
1056 m_xmlfile
.Write("\n\t\t</object>\n");
1059 // CONTROL "Tree1",IDC_TREE1,"SysTreeView32",WS_BORDER | WS_TABSTOP,
1062 void rc2xml::ParseTreeCtrl(wxString label
, wxString varname
)
1065 //while (ReadOrs(token));
1067 int x
,y
,width
,height
;
1068 ReadRect(x
,y
,width
,height
);
1069 m_xmlfile
.Write("\t\t<object class=\"wxTreeCtrl\"");
1070 WriteBasicInfo(x
,y
,width
,height
,varname
);
1071 m_xmlfile
.Write("\t\t</object>\n");
1074 // CONTROL "MonthCalendar1",IDC_MONTHCALENDAR1,"SysMonthCal32",
1075 //MCS_NOTODAY | WS_TABSTOP,105,71,129,89
1077 void rc2xml::ParseCalendar(wxString label
, wxString varname
)
1080 //while (ReadOrs(token));
1082 int x
,y
,width
,height
;
1083 ReadRect(x
,y
,width
,height
);
1084 m_xmlfile
.Write("\t\t<object class=\"wxCalendarCtrl\"");
1085 WriteBasicInfo(x
,y
,width
,height
,varname
);
1086 m_xmlfile
.Write("\t\t</object>\n");
1088 // CONTROL "List1",IDC_LIST1,"SysListView32",WS_BORDER | WS_TABSTOP,
1091 void rc2xml::ParseListCtrl(wxString label
, wxString varname
)
1094 //while (ReadOrs(token));
1096 int x
,y
,width
,height
;
1097 ReadRect(x
,y
,width
,height
);
1098 m_xmlfile
.Write("\t\t<object class=\"wxListCtrl\"");
1099 WriteBasicInfo(x
,y
,width
,height
,varname
);
1100 m_xmlfile
.Write("\t\t</object>\n");
1104 void rc2xml::WriteBitmap(wxString bitmapname
)
1107 wxNode
*node
=m_bitmaplist
->Find(LookUpId(bitmapname
));
1110 m_xmlfile
.Write("\t\t\t<bitmap>missingfile</bitmap>\n");
1111 wxLogError("Unable to find bitmap:"+bitmapname
);
1115 wxString
*bitmappath
;
1116 bitmappath
=(wxString
*)node
->Data();
1118 if (!bitmap
.LoadFile(*bitmappath
,wxBITMAP_TYPE_BMP
))
1119 wxLogError("Unable to load bitmap:"+*bitmappath
);
1121 //Make a bitmap file name
1122 bitmapname
=CleanName(bitmapname
);
1124 m_xmlfile
.Write("\t\t\t<bitmap>"+bitmapname
+"</bitmap>\n");
1125 bitmap
.SaveFile(bitmapname
,wxBITMAP_TYPE_BMP
);
1128 void rc2xml::WriteIcon(wxString iconname
)
1130 wxNode
*node
=m_iconlist
->Find(iconname
);
1133 m_xmlfile
.Write("\t\t\t<bitmap>missing_file</bitmap>\n");
1134 wxLogError("Unable to find icon:"+iconname
);
1137 iconpath
=(wxString
*)node
->Data();
1140 if (!icon
.LoadFile(*iconpath
,wxBITMAP_TYPE_ICO
))
1141 wxLogError("Unable to load icon:"+*iconpath
);
1143 bitmap
.CopyFromIcon(icon
);
1148 //Make a bitmap file name
1149 iconname
=CleanName(iconname
);
1151 m_xmlfile
.Write("\t\t\t<bitmap>"+iconname
+"</bitmap>\n");
1152 bitmap
.SaveFile(iconname
,wxBITMAP_TYPE_BMP
);
1156 /*Unfortunately sometimes the great MSVC Resource editor decides
1157 to use numbers instead of the word id. I have no idea why they
1158 do this, but that is the way it is.
1160 /* this is a quick and dirty way to parse the resource.h file
1161 it will not recognize #ifdef so it can be easily fooled
1163 void rc2xml::ParseResourceHeader()
1166 //Attempt to load resource.h in current path
1167 if (!r
.Open("resource.h"))
1169 wxLogError("Warining Unable to load resource.h file");
1175 wxStringTokenizer tok
;
1181 //Read through entire file
1182 for ( str
= r
.GetFirstLine(); !r
.Eof(); str
= r
.GetNextLine() )
1184 if (str
.Find("#define")!=-1)
1187 //Just ignore #define token
1189 v
=tok
.GetNextToken();
1190 id
=tok
.GetNextToken();
1193 varname
=new wxString
;
1196 m_resourcelist
->Append(n
,varname
);
1206 wxString
rc2xml::LookUpId(wxString id
)
1214 wxNode
*node
=m_resourcelist
->Find(n
);
1219 s
=(wxString
*)node
->Data();