]>
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/resource.h"
67 //////////////////////////////////////////////////////////////////////
69 // Construction/Destruction
71 //////////////////////////////////////////////////////////////////////
97 void rc2wxr::Convert(wxString wxrfile
, wxString rcfile
)
103 m_filesize
=m_rc
.Length();
105 if( (m_wxr
= fopen( wxrfile
, "wt" )) == NULL
)
117 wxString tok
,prevtok
;
137 ParseDialog(prevtok
);
179 Microsoft style as of v5.0
181 IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 217, 55
183 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
185 CAPTION "About Funimator"
187 FONT 8, "MS Sans Serif"
193 IDD_DIBATTR DIALOG 7, 16, 172, 119
195 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
197 CAPTION "DIB Attributes"
199 FONT 8, "MS Sans Serif"
203 DEFPUSHBUTTON "Ok", IDOK, 114, 8, 50, 14
205 PUSHBUTTON "Cancel", IDCANCEL, 114, 28, 50, 14
215 void rc2wxr::ParseDialog(wxString dlgname
)
221 static int dlgid
=999;
225 /* Make sure that this really is a dialog
227 microsoft reuses the keyword DIALOG for other things
233 //Microsoft notation?
235 if (tok
=="DISCARDABLE")
245 //This isn't a Dialog resource eject eject
251 //Generate Dialog text
253 fprintf(m_wxr
,"static char *dialog%i = \"dialog(name = '%s',\\\n",dlgid
,dlgname
);
255 //be lazy about style for now. add it later
257 fprintf(m_wxr
,"style = 'wxRAISED_BORDER | wxCAPTION | wxTHICK_FRAME | wxSYSTEM_MENU',\\\n");
261 fprintf(m_wxr
,"id = %i,\\\n",dlgid
);
265 //Record x,y,width,height
267 int x
,y
,width
,height
;
269 ReadRect(x
,y
,width
,height
);
271 fprintf(m_wxr
,"x = %i, y = %i, width = %i, height = %i,\\\n",x
,y
,width
,height
);
277 //CAPTION "About Funimator"
287 while ((tok
!="BEGIN")&(tok
!="{"))
295 title
=GetQuoteField();
297 fprintf(m_wxr
,"title = '%s',\\\n",title
);
305 fprintf(m_wxr
,"use_dialog_units = 1,\\\n");
307 fprintf(m_wxr
,"use_system_defaults = 0,\\\n");
311 fprintf(m_wxr
,"font = [8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif'],\\\n");
315 fprintf(m_wxr
,").\";\n\n");
331 EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT
335 LTEXT "Bands",IDC_STATIC,11,86,21,8
337 EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL
343 void rc2wxr::ParseControls()
353 while ((tok
!="END")&(tok
!="}"))
365 if (tok
=="PUSHBUTTON")
369 if (tok
=="DEFPUSHBUTTON")
395 //LTEXT "Radius",IDC_STATIC,9,67,23,8
397 void rc2wxr::ParseStaticText()
403 wxString phrase
,varname
;
405 phrase
=GetQuoteField();
411 int x
,y
,width
,height
;
413 ReadRect(x
,y
,width
,height
);
415 fprintf(m_wxr
," control = [%i,wxStaticText,'%s','0','%s',",m_controlid
,phrase
,varname
);
417 fprintf(m_wxr
,"%i,%i,%i,%i,'',\\\n",x
,y
,width
,height
);
419 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
423 //EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
425 void rc2wxr::ParseTextCtrl()
437 int x
,y
,width
,height
;
439 ReadRect(x
,y
,width
,height
);
441 fprintf(m_wxr
," control = [%i,wxTextCtrl,'','0','%s',",m_controlid
,varname
);
443 fprintf(m_wxr
,"%i,%i,%i,%i,'',\\\n",x
,y
,width
,height
);
445 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
451 //PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
453 void rc2wxr::ParsePushButton()
459 wxString phrase
,varname
;
461 phrase
=GetQuoteField();
477 if (varname
=="IDCANCEL")
483 if (varname
=="IDAPPLY")
489 int x
,y
,width
,height
;
491 ReadRect(x
,y
,width
,height
);
493 fprintf(m_wxr
," control = [%i,wxButton,'%s','0','%s',",c
,phrase
,varname
);
495 fprintf(m_wxr
,"%i,%i,%i,%i,'',\\\n",x
,y
,width
,height
);
497 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
507 bool rc2wxr::Seperator(int ch
)
511 if ((ch
==' ')|(ch
==',')|(ch
==13)|(ch
==10)|(ch
=='|'))
533 void rc2wxr::ParseGroupBox()
537 // GROUPBOX "Rotate",IDC_STATIC,1,1,71,79
541 wxString phrase
,varname
;
543 phrase
=GetQuoteField();
549 int x
,y
,width
,height
;
551 ReadRect(x
,y
,width
,height
);
553 fprintf(m_wxr
," control = [%i,wxStaticBox,'%s','0','%s',",m_controlid
,phrase
,varname
);
555 fprintf(m_wxr
,"%i,%i,%i,%i,'',\\\n",x
,y
,width
,height
);
557 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
567 void rc2wxr::ReadRect(int & x
, int & y
, int & width
, int & height
)
575 width
=atoi(GetToken());
577 height
=atoi(GetToken());
585 wxString
rc2wxr::GetToken()
621 while (Seperator(ch
))
649 while (!Seperator(ch
))
677 wxString
rc2wxr::GetQuoteField()
717 void rc2wxr::ReadChar(int &ch
)
727 if((result
>=m_filesize
))
733 result
=m_rc
.Read(&ch
,1);
751 void rc2wxr::ParseComboBox()
755 /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
757 WS_VSCROLL | WS_TABSTOP */
767 int x
,y
,width
,height
;
769 ReadRect(x
,y
,width
,height
);
773 fprintf(m_wxr
," control = [%i,wxChoice,'','0','%s',",m_controlid
,varname
);
775 fprintf(m_wxr
,"%i,%i,%i,%i,[],\\\n",x
,y
,width
,height
);
777 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
787 void rc2wxr::ParseMenu(wxString name
)
797 fprintf(m_wxr
,"static char *MenuBar%i = \"menu(name = '%s',\\\n",menuid
,name
);
799 fprintf(m_wxr
,"menu = \\\n");
801 fprintf(m_wxr
,"[\\\n");
805 while ((tok
!="BEGIN")&(tok
!="{"))
811 while ((tok
!="END")&(tok
!="}"))
823 fprintf(m_wxr
," ],\\\n");
831 fprintf(m_wxr
,"]).\";\n\n");
837 void rc2wxr::ParsePopupMenu()
841 static int menuitem
=99;
853 //Remove /t because it causes problems
855 spot
=tok
.First("\\t");
859 fprintf(m_wxr
," ['%s',%i,'',\\\n",tok
,menuitem
);
861 while ((tok
!="BEGIN")&(tok
!="{"))
867 while ((tok
!="END")&(tok
!="}"))
877 if (PeekToken()=="SEPARATOR")
879 fprintf(m_wxr
," [],\\\n");
887 //Remove /t because it causes problems
889 spot
=tok
.First("\\t");
895 fprintf(m_wxr
," ['%s',%i,''],\\\n",tok
,menuitem
);
913 wxString
rc2wxr::PeekToken()
933 //Windows pain in the butt CONTROL
935 void rc2wxr::ParseControlMS()
939 wxString label
,varname
,kindctrl
,tok
;
941 label
=GetQuoteField();
945 kindctrl
=GetQuoteField();
947 kindctrl
.MakeUpper();
953 if (kindctrl
=="MSCTLS_TRACKBAR32")
955 ParseSlider(label
,varname
);
957 if (kindctrl
=="MSCTLS_PROGRESS32")
959 ParseProgressBar(label
,varname
);
961 if (kindctrl
=="BUTTON")
963 ParseCtrlButton(label
,varname
);
967 /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
969 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
975 void rc2wxr::ParseSlider(wxString label
, wxString varname
)
981 while (ReadOrs(tok
));
983 fprintf(m_wxr
," control = [%i,wxSlider,'','wxSL_HORIZONTAL','%s',",m_controlid
,varname
);
985 int x
,y
,width
,height
;
987 ReadRect(x
,y
,width
,height
);
989 fprintf(m_wxr
,"%i,%i,%i,%i,",x
,y
,width
,height
);
991 fprintf(m_wxr
," 1, 1, 10,\\\n");
993 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
999 CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
1001 WS_BORDER,15,52,154,13
1005 void rc2wxr::ParseProgressBar(wxString label
, wxString varname
)
1011 while (ReadOrs(tok
));
1013 fprintf(m_wxr
," control = [%i,wxGauge,'','wxGA_HORIZONTAL','%s',",m_controlid
,varname
);
1015 int x
,y
,width
,height
;
1017 ReadRect(x
,y
,width
,height
);
1019 fprintf(m_wxr
,"%i,%i,%i,%i,",x
,y
,width
,height
);
1021 fprintf(m_wxr
," 0, 10,\\\n");
1023 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
1029 bool rc2wxr::ReadOrs(wxString
& w
)
1049 //Is it a check button or a radio button
1051 void rc2wxr::ParseCtrlButton(wxString label
, wxString varname
)
1063 int x
,y
,width
,height
;
1067 if (tok
=="BS_AUTOCHECKBOX")
1071 fprintf(m_wxr
," control = [%i,wxCheckBox,'%s','0','%s',",m_controlid
,label
,varname
);
1073 while (ReadOrs(tok
));
1075 ReadRect(x
,y
,width
,height
);
1077 fprintf(m_wxr
,"%i,%i,%i,%i,0,\\\n",x
,y
,width
,height
);
1079 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
1085 if (tok
=="BS_AUTORADIOBUTTON")
1089 fprintf(m_wxr
," control = [%i,wxRadioButton,'%s','0','%s',",m_controlid
,label
,varname
);
1091 while(ReadOrs(tok
));
1093 ReadRect(x
,y
,width
,height
);
1095 fprintf(m_wxr
,"%i,%i,%i,%i,0,\\\n",x
,y
,width
,height
);
1097 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");