]>
git.saurik.com Git - wxWidgets.git/blob - contrib/utils/convertrc/rc2wxr.cpp
1 // rc2wxr.cpp: implementation of the rc2wxr class.
5 //////////////////////////////////////////////////////////////////////
7 //Author: Brian Gavin 9/24/00
9 //License: wxWindows License
13 WARNING- I know this code has some bugs to work out but
15 I don't plan to fix them since I feel that wxr files will
17 not be used much longer.
19 This code was used as a starting point for my rc2xml converter
25 #pragma implementation "rc2wxr.cpp"
27 #pragma interface "rc2wxr.cpp"
33 // For compilers that support precompilation, includes "wx/wx.h".
35 #include "wx/wxprec.h"
47 // for all others, include the necessary headers (this file is usually all you
49 // need because it includes almost all "standard" wxWindows headers
65 #include "wx/deprecated/setup.h"
66 #include "wx/deprecated/resource.h"
68 //////////////////////////////////////////////////////////////////////
70 // Construction/Destruction
72 //////////////////////////////////////////////////////////////////////
98 void rc2wxr::Convert(wxString wxrfile
, wxString rcfile
)
104 m_filesize
=m_rc
.Length();
106 if( (m_wxr
= fopen( wxrfile
, "wt" )) == NULL
)
118 wxString tok
,prevtok
;
138 ParseDialog(prevtok
);
180 Microsoft style as of v5.0
182 IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 217, 55
184 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
186 CAPTION "About Funimator"
188 FONT 8, "MS Sans Serif"
194 IDD_DIBATTR DIALOG 7, 16, 172, 119
196 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
198 CAPTION "DIB Attributes"
200 FONT 8, "MS Sans Serif"
204 DEFPUSHBUTTON "Ok", IDOK, 114, 8, 50, 14
206 PUSHBUTTON "Cancel", IDCANCEL, 114, 28, 50, 14
216 void rc2wxr::ParseDialog(wxString dlgname
)
222 static int dlgid
=999;
226 /* Make sure that this really is a dialog
228 microsoft reuses the keyword DIALOG for other things
234 //Microsoft notation?
236 if (tok
=="DISCARDABLE")
246 //This isn't a Dialog resource eject eject
252 //Generate Dialog text
254 fprintf(m_wxr
,"static char *dialog%i = \"dialog(name = '%s',\\\n",dlgid
,dlgname
);
256 //be lazy about style for now. add it later
258 fprintf(m_wxr
,"style = 'wxRAISED_BORDER | wxCAPTION | wxTHICK_FRAME | wxSYSTEM_MENU',\\\n");
262 fprintf(m_wxr
,"id = %i,\\\n",dlgid
);
266 //Record x,y,width,height
268 int x
,y
,width
,height
;
270 ReadRect(x
,y
,width
,height
);
272 fprintf(m_wxr
,"x = %i, y = %i, width = %i, height = %i,\\\n",x
,y
,width
,height
);
278 //CAPTION "About Funimator"
288 while ((tok
!="BEGIN")&(tok
!="{"))
296 title
=GetQuoteField();
298 fprintf(m_wxr
,"title = '%s',\\\n",title
);
306 fprintf(m_wxr
,"use_dialog_units = 1,\\\n");
308 fprintf(m_wxr
,"use_system_defaults = 0,\\\n");
312 fprintf(m_wxr
,"font = [8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif'],\\\n");
316 fprintf(m_wxr
,").\";\n\n");
332 EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT
336 LTEXT "Bands",IDC_STATIC,11,86,21,8
338 EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL
344 void rc2wxr::ParseControls()
354 while ((tok
!="END")&(tok
!="}"))
366 if (tok
=="PUSHBUTTON")
370 if (tok
=="DEFPUSHBUTTON")
396 //LTEXT "Radius",IDC_STATIC,9,67,23,8
398 void rc2wxr::ParseStaticText()
404 wxString phrase
,varname
;
406 phrase
=GetQuoteField();
412 int x
,y
,width
,height
;
414 ReadRect(x
,y
,width
,height
);
416 fprintf(m_wxr
," control = [%i,wxStaticText,'%s','0','%s',",m_controlid
,phrase
,varname
);
418 fprintf(m_wxr
,"%i,%i,%i,%i,'',\\\n",x
,y
,width
,height
);
420 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
424 //EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
426 void rc2wxr::ParseTextCtrl()
438 int x
,y
,width
,height
;
440 ReadRect(x
,y
,width
,height
);
442 fprintf(m_wxr
," control = [%i,wxTextCtrl,'','0','%s',",m_controlid
,varname
);
444 fprintf(m_wxr
,"%i,%i,%i,%i,'',\\\n",x
,y
,width
,height
);
446 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
452 //PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
454 void rc2wxr::ParsePushButton()
460 wxString phrase
,varname
;
462 phrase
=GetQuoteField();
478 if (varname
=="IDCANCEL")
484 if (varname
=="IDAPPLY")
490 int x
,y
,width
,height
;
492 ReadRect(x
,y
,width
,height
);
494 fprintf(m_wxr
," control = [%i,wxButton,'%s','0','%s',",c
,phrase
,varname
);
496 fprintf(m_wxr
,"%i,%i,%i,%i,'',\\\n",x
,y
,width
,height
);
498 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
508 bool rc2wxr::Seperator(int ch
)
512 if ((ch
==' ')|(ch
==',')|(ch
==13)|(ch
==10)|(ch
=='|'))
534 void rc2wxr::ParseGroupBox()
538 // GROUPBOX "Rotate",IDC_STATIC,1,1,71,79
542 wxString phrase
,varname
;
544 phrase
=GetQuoteField();
550 int x
,y
,width
,height
;
552 ReadRect(x
,y
,width
,height
);
554 fprintf(m_wxr
," control = [%i,wxStaticBox,'%s','0','%s',",m_controlid
,phrase
,varname
);
556 fprintf(m_wxr
,"%i,%i,%i,%i,'',\\\n",x
,y
,width
,height
);
558 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
568 void rc2wxr::ReadRect(int & x
, int & y
, int & width
, int & height
)
576 width
=atoi(GetToken());
578 height
=atoi(GetToken());
586 wxString
rc2wxr::GetToken()
622 while (Seperator(ch
))
650 while (!Seperator(ch
))
678 wxString
rc2wxr::GetQuoteField()
718 void rc2wxr::ReadChar(int &ch
)
728 if((result
>=m_filesize
))
734 result
=m_rc
.Read(&ch
,1);
752 void rc2wxr::ParseComboBox()
756 /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
758 WS_VSCROLL | WS_TABSTOP */
768 int x
,y
,width
,height
;
770 ReadRect(x
,y
,width
,height
);
774 fprintf(m_wxr
," control = [%i,wxChoice,'','0','%s',",m_controlid
,varname
);
776 fprintf(m_wxr
,"%i,%i,%i,%i,[],\\\n",x
,y
,width
,height
);
778 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
788 void rc2wxr::ParseMenu(wxString name
)
798 fprintf(m_wxr
,"static char *MenuBar%i = \"menu(name = '%s',\\\n",menuid
,name
);
800 fprintf(m_wxr
,"menu = \\\n");
802 fprintf(m_wxr
,"[\\\n");
806 while ((tok
!="BEGIN")&(tok
!="{"))
812 while ((tok
!="END")&(tok
!="}"))
824 fprintf(m_wxr
," ],\\\n");
832 fprintf(m_wxr
,"]).\";\n\n");
838 void rc2wxr::ParsePopupMenu()
842 static int menuitem
=99;
854 //Remove /t because it causes problems
856 spot
=tok
.First("\\t");
860 fprintf(m_wxr
," ['%s',%i,'',\\\n",tok
,menuitem
);
862 while ((tok
!="BEGIN")&(tok
!="{"))
868 while ((tok
!="END")&(tok
!="}"))
878 if (PeekToken()=="SEPARATOR")
880 fprintf(m_wxr
," [],\\\n");
888 //Remove /t because it causes problems
890 spot
=tok
.First("\\t");
896 fprintf(m_wxr
," ['%s',%i,''],\\\n",tok
,menuitem
);
914 wxString
rc2wxr::PeekToken()
934 //Windows pain in the butt CONTROL
936 void rc2wxr::ParseControlMS()
940 wxString label
,varname
,kindctrl
,tok
;
942 label
=GetQuoteField();
946 kindctrl
=GetQuoteField();
948 kindctrl
.MakeUpper();
954 if (kindctrl
=="MSCTLS_TRACKBAR32")
956 ParseSlider(label
,varname
);
958 if (kindctrl
=="MSCTLS_PROGRESS32")
960 ParseProgressBar(label
,varname
);
962 if (kindctrl
=="BUTTON")
964 ParseCtrlButton(label
,varname
);
968 /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
970 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
976 void rc2wxr::ParseSlider(wxString label
, wxString varname
)
982 while (ReadOrs(tok
));
984 fprintf(m_wxr
," control = [%i,wxSlider,'','wxSL_HORIZONTAL','%s',",m_controlid
,varname
);
986 int x
,y
,width
,height
;
988 ReadRect(x
,y
,width
,height
);
990 fprintf(m_wxr
,"%i,%i,%i,%i,",x
,y
,width
,height
);
992 fprintf(m_wxr
," 1, 1, 10,\\\n");
994 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
1000 CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
1002 WS_BORDER,15,52,154,13
1006 void rc2wxr::ParseProgressBar(wxString label
, wxString varname
)
1012 while (ReadOrs(tok
));
1014 fprintf(m_wxr
," control = [%i,wxGauge,'','wxGA_HORIZONTAL','%s',",m_controlid
,varname
);
1016 int x
,y
,width
,height
;
1018 ReadRect(x
,y
,width
,height
);
1020 fprintf(m_wxr
,"%i,%i,%i,%i,",x
,y
,width
,height
);
1022 fprintf(m_wxr
," 0, 10,\\\n");
1024 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
1030 bool rc2wxr::ReadOrs(wxString
& w
)
1050 //Is it a check button or a radio button
1052 void rc2wxr::ParseCtrlButton(wxString label
, wxString varname
)
1064 int x
,y
,width
,height
;
1068 if (tok
=="BS_AUTOCHECKBOX")
1072 fprintf(m_wxr
," control = [%i,wxCheckBox,'%s','0','%s',",m_controlid
,label
,varname
);
1074 while (ReadOrs(tok
));
1076 ReadRect(x
,y
,width
,height
);
1078 fprintf(m_wxr
,"%i,%i,%i,%i,0,\\\n",x
,y
,width
,height
);
1080 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
1086 if (tok
=="BS_AUTORADIOBUTTON")
1090 fprintf(m_wxr
," control = [%i,wxRadioButton,'%s','0','%s',",m_controlid
,label
,varname
);
1092 while(ReadOrs(tok
));
1094 ReadRect(x
,y
,width
,height
);
1096 fprintf(m_wxr
,"%i,%i,%i,%i,0,\\\n",x
,y
,width
,height
);
1098 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");