]>
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
= wxFopen( wxrfile
, _T("wt") )) == NULL
)
118 wxString tok
,prevtok
;
134 if (tok
==_T("DIALOG"))
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
==_T("DISCARDABLE"))
246 //This isn't a Dialog resource eject eject
252 //Generate Dialog text
254 wxFprintf(m_wxr
,_T("static char *dialog%i = \"dialog(name = '%s',\\\n"),dlgid
,dlgname
.c_str());
256 //be lazy about style for now. add it later
258 wxFprintf(m_wxr
,_T("style = 'wxRAISED_BORDER | wxCAPTION | wxTHICK_FRAME | wxSYSTEM_MENU',\\\n"));
262 wxFprintf(m_wxr
,_T("id = %i,\\\n"),dlgid
);
266 //Record x,y,width,height
268 int x
,y
,width
,height
;
270 ReadRect(x
,y
,width
,height
);
272 wxFprintf(m_wxr
,_T("x = %i, y = %i, width = %i, height = %i,\\\n"),x
,y
,width
,height
);
278 //CAPTION "About Funimator"
288 while ((tok
!=_T("BEGIN"))&(tok
!=_T("{")))
292 if (tok
==_T("CAPTION"))
296 title
=GetQuoteField();
298 wxFprintf(m_wxr
,_T("title = '%s',\\\n"),title
.c_str());
306 wxFprintf(m_wxr
,_T("use_dialog_units = 1,\\\n"));
308 wxFprintf(m_wxr
,_T("use_system_defaults = 0,\\\n"));
312 wxFprintf(m_wxr
,_T("font = [8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif'],\\\n"));
316 wxFprintf(m_wxr
,_T(").\";\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
!=_T("END"))&(tok
!=_T("}")))
358 if (tok
==_T("LTEXT"))
362 if (tok
==_T("EDITTEXT"))
366 if (tok
==_T("PUSHBUTTON"))
370 if (tok
==_T("DEFPUSHBUTTON"))
374 if (tok
==_T("GROUPBOX"))
378 if (tok
==_T("COMBOBOX"))
382 if (tok
==_T("CONTROL"))
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 wxFprintf(m_wxr
,_T(" control = [%i,wxStaticText,'%s','0','%s',"),m_controlid
,phrase
.c_str(),varname
.c_str());
418 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,'',\\\n"),x
,y
,width
,height
);
420 wxFprintf(m_wxr
,_T("[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 wxFprintf(m_wxr
,_T(" control = [%i,wxTextCtrl,'','0','%s',"),m_controlid
,varname
.c_str());
444 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,'',\\\n"),x
,y
,width
,height
);
446 wxFprintf(m_wxr
,_T("[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();
472 if (varname
==_T("IDOK"))
478 if (varname
==_T("IDCANCEL"))
484 if (varname
==_T("IDAPPLY"))
490 int x
,y
,width
,height
;
492 ReadRect(x
,y
,width
,height
);
494 wxFprintf(m_wxr
,_T(" control = [%i,wxButton,'%s','0','%s',"),c
,phrase
.c_str(),varname
.c_str());
496 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,'',\\\n"),x
,y
,width
,height
);
498 wxFprintf(m_wxr
,_T("[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 wxFprintf(m_wxr
,_T(" control = [%i,wxStaticBox,'%s','0','%s',"),m_controlid
,phrase
.c_str(),varname
.c_str());
556 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,'',\\\n"),x
,y
,width
,height
);
558 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
568 void rc2wxr::ReadRect(int & x
, int & y
, int & width
, int & height
)
572 x
=wxAtoi(GetToken());
574 y
=wxAtoi(GetToken());
576 width
=wxAtoi(GetToken());
578 height
=wxAtoi(GetToken());
586 wxString
rc2wxr::GetToken()
590 wxString tok
=wxEmptyString
;
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 wxFprintf(m_wxr
,_T(" control = [%i,wxChoice,'','0','%s',"),m_controlid
,varname
.c_str());
776 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,[],\\\n"),x
,y
,width
,height
);
778 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
788 void rc2wxr::ParseMenu(wxString name
)
792 wxString tok
=wxEmptyString
;
798 wxFprintf(m_wxr
,_T("static char *MenuBar%i = \"menu(name = '%s',\\\n"),menuid
,name
.c_str());
800 wxFprintf(m_wxr
,_T("menu = \\\n"));
802 wxFprintf(m_wxr
,_T("[\\\n"));
806 while ((tok
!=_T("BEGIN"))&(tok
!=_T("{")))
812 while ((tok
!=_T("END"))&(tok
!=_T("}")))
818 if (tok
==_T("POPUP"))
824 wxFprintf(m_wxr
,_T(" ],\\\n"));
832 wxFprintf(m_wxr
,_T("]).\";\n\n"));
838 void rc2wxr::ParsePopupMenu()
842 static int menuitem
=99;
854 //Remove /t because it causes problems
856 spot
=tok
.First(_T("\\t"));
860 wxFprintf(m_wxr
,_T(" ['%s',%i,'',\\\n"),tok
.c_str(),menuitem
);
862 while ((tok
!=_T("BEGIN"))&(tok
!=_T("{")))
868 while ((tok
!=_T("END"))&(tok
!=_T("}")))
874 if (tok
==_T("MENUITEM"))
878 if (PeekToken()==_T("SEPARATOR"))
880 wxFprintf(m_wxr
,_T(" [],\\\n"));
888 //Remove /t because it causes problems
890 spot
=tok
.First(_T("\\t"));
896 wxFprintf(m_wxr
,_T(" ['%s',%i,''],\\\n"),tok
.c_str(),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
==_T("MSCTLS_TRACKBAR32"))
956 ParseSlider(label
,varname
);
958 if (kindctrl
==_T("MSCTLS_PROGRESS32"))
960 ParseProgressBar(label
,varname
);
962 if (kindctrl
==_T("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
WXUNUSED(label
), wxString varname
)
985 wxFprintf(m_wxr
,_T(" control = [%i,wxSlider,'','wxSL_HORIZONTAL','%s',"),m_controlid
,varname
.c_str());
987 int x
,y
,width
,height
;
989 ReadRect(x
,y
,width
,height
);
991 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,"),x
,y
,width
,height
);
993 wxFprintf(m_wxr
,_T(" 1, 1, 10,\\\n"));
995 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
1001 CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
1003 WS_BORDER,15,52,154,13
1007 void rc2wxr::ParseProgressBar(wxString
WXUNUSED(label
), wxString varname
)
1013 while (ReadOrs(tok
))
1016 wxFprintf(m_wxr
,_T(" control = [%i,wxGauge,'','wxGA_HORIZONTAL','%s',"),m_controlid
,varname
.c_str());
1018 int x
,y
,width
,height
;
1020 ReadRect(x
,y
,width
,height
);
1022 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,"),x
,y
,width
,height
);
1024 wxFprintf(m_wxr
,_T(" 0, 10,\\\n"));
1026 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
1032 bool rc2wxr::ReadOrs(wxString
& w
)
1052 //Is it a check button or a radio button
1054 void rc2wxr::ParseCtrlButton(wxString label
, wxString varname
)
1066 int x
,y
,width
,height
;
1070 if (tok
==_T("BS_AUTOCHECKBOX"))
1074 wxFprintf(m_wxr
,_T(" control = [%i,wxCheckBox,'%s','0','%s',"),m_controlid
,label
.c_str(),varname
.c_str());
1076 while (ReadOrs(tok
))
1079 ReadRect(x
,y
,width
,height
);
1081 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,0,\\\n"),x
,y
,width
,height
);
1083 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
1089 if (tok
==_T("BS_AUTORADIOBUTTON"))
1093 wxFprintf(m_wxr
,_T(" control = [%i,wxRadioButton,'%s','0','%s',"),m_controlid
,label
.c_str(),varname
.c_str());
1098 ReadRect(x
,y
,width
,height
);
1100 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,0,\\\n"),x
,y
,width
,height
);
1102 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));