]>
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" wxWidgets 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
)
101 m_filesize
=m_rc
.Length();
102 if( (m_wxr
= wxFopen( wxrfile
.fn_str(), _T("wt") )) == NULL
)
107 wxString tok
,prevtok
;
113 if (tok
==_T("DIALOG"))
115 ParseDialog(prevtok
);
139 Microsoft style as of v5.0
141 IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 217, 55
143 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
145 CAPTION "About Funimator"
147 FONT 8, "MS Sans Serif"
153 IDD_DIBATTR DIALOG 7, 16, 172, 119
155 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
157 CAPTION "DIB Attributes"
159 FONT 8, "MS Sans Serif"
163 DEFPUSHBUTTON "Ok", IDOK, 114, 8, 50, 14
165 PUSHBUTTON "Cancel", IDCANCEL, 114, 28, 50, 14
175 void rc2wxr::ParseDialog(wxString dlgname
)
181 static int dlgid
=999;
185 /* Make sure that this really is a dialog
187 microsoft reuses the keyword DIALOG for other things
193 //Microsoft notation?
195 if (tok
==_T("DISCARDABLE"))
205 //This isn't a Dialog resource eject eject
211 //Generate Dialog text
213 wxFprintf(m_wxr
,_T("static char *dialog%i = \"dialog(name = '%s',\\\n"),dlgid
,dlgname
.c_str());
215 //be lazy about style for now. add it later
217 wxFprintf(m_wxr
,_T("style = 'wxRAISED_BORDER | wxCAPTION | wxTHICK_FRAME | wxSYSTEM_MENU',\\\n"));
221 wxFprintf(m_wxr
,_T("id = %i,\\\n"),dlgid
);
225 //Record x,y,width,height
227 int x
,y
,width
,height
;
229 ReadRect(x
,y
,width
,height
);
231 wxFprintf(m_wxr
,_T("x = %i, y = %i, width = %i, height = %i,\\\n"),x
,y
,width
,height
);
237 //CAPTION "About Funimator"
247 while ((tok
!=_T("BEGIN"))&(tok
!=_T("{")))
251 if (tok
==_T("CAPTION"))
255 title
=GetQuoteField();
257 wxFprintf(m_wxr
,_T("title = '%s',\\\n"),title
.c_str());
265 wxFprintf(m_wxr
,_T("use_dialog_units = 1,\\\n"));
267 wxFprintf(m_wxr
,_T("use_system_defaults = 0,\\\n"));
271 wxFprintf(m_wxr
,_T("font = [8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif'],\\\n"));
275 wxFprintf(m_wxr
,_T(").\";\n\n"));
291 EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT
295 LTEXT "Bands",IDC_STATIC,11,86,21,8
297 EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL
303 void rc2wxr::ParseControls()
313 while ((tok
!=_T("END"))&(tok
!=_T("}")))
317 if (tok
==_T("LTEXT"))
321 if (tok
==_T("EDITTEXT"))
325 if (tok
==_T("PUSHBUTTON"))
329 if (tok
==_T("DEFPUSHBUTTON"))
333 if (tok
==_T("GROUPBOX"))
337 if (tok
==_T("COMBOBOX"))
341 if (tok
==_T("CONTROL"))
355 //LTEXT "Radius",IDC_STATIC,9,67,23,8
357 void rc2wxr::ParseStaticText()
363 wxString phrase
,varname
;
365 phrase
=GetQuoteField();
371 int x
,y
,width
,height
;
373 ReadRect(x
,y
,width
,height
);
375 wxFprintf(m_wxr
,_T(" control = [%i,wxStaticText,'%s','0','%s',"),m_controlid
,phrase
.c_str(),varname
.c_str());
377 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,'',\\\n"),x
,y
,width
,height
);
379 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
383 //EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
385 void rc2wxr::ParseTextCtrl()
397 int x
,y
,width
,height
;
399 ReadRect(x
,y
,width
,height
);
401 wxFprintf(m_wxr
,_T(" control = [%i,wxTextCtrl,'','0','%s',"),m_controlid
,varname
.c_str());
403 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,'',\\\n"),x
,y
,width
,height
);
405 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
411 //PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
413 void rc2wxr::ParsePushButton()
419 wxString phrase
,varname
;
421 phrase
=GetQuoteField();
431 if (varname
==_T("IDOK"))
437 if (varname
==_T("IDCANCEL"))
443 if (varname
==_T("IDAPPLY"))
449 int x
,y
,width
,height
;
451 ReadRect(x
,y
,width
,height
);
453 wxFprintf(m_wxr
,_T(" control = [%i,wxButton,'%s','0','%s',"),c
,phrase
.c_str(),varname
.c_str());
455 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,'',\\\n"),x
,y
,width
,height
);
457 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
467 bool rc2wxr::Seperator(int ch
)
471 if ((ch
==' ')|(ch
==',')|(ch
==13)|(ch
==10)|(ch
=='|'))
493 void rc2wxr::ParseGroupBox()
497 // GROUPBOX "Rotate",IDC_STATIC,1,1,71,79
501 wxString phrase
,varname
;
503 phrase
=GetQuoteField();
509 int x
,y
,width
,height
;
511 ReadRect(x
,y
,width
,height
);
513 wxFprintf(m_wxr
,_T(" control = [%i,wxStaticBox,'%s','0','%s',"),m_controlid
,phrase
.c_str(),varname
.c_str());
515 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,'',\\\n"),x
,y
,width
,height
);
517 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
527 void rc2wxr::ReadRect(int & x
, int & y
, int & width
, int & height
)
531 x
=wxAtoi(GetToken());
533 y
=wxAtoi(GetToken());
535 width
=wxAtoi(GetToken());
537 height
=wxAtoi(GetToken());
545 wxString
rc2wxr::GetToken()
549 wxString tok
=wxEmptyString
;
581 while (Seperator(ch
))
609 while (!Seperator(ch
))
637 wxString
rc2wxr::GetQuoteField()
677 void rc2wxr::ReadChar(int &ch
)
687 if((result
>=m_filesize
))
693 result
=m_rc
.Read(&ch
,1);
711 void rc2wxr::ParseComboBox()
715 /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
717 WS_VSCROLL | WS_TABSTOP */
727 int x
,y
,width
,height
;
729 ReadRect(x
,y
,width
,height
);
733 wxFprintf(m_wxr
,_T(" control = [%i,wxChoice,'','0','%s',"),m_controlid
,varname
.c_str());
735 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,[],\\\n"),x
,y
,width
,height
);
737 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
747 void rc2wxr::ParseMenu(wxString name
)
751 wxString tok
=wxEmptyString
;
757 wxFprintf(m_wxr
,_T("static char *MenuBar%i = \"menu(name = '%s',\\\n"),menuid
,name
.c_str());
759 wxFprintf(m_wxr
,_T("menu = \\\n"));
761 wxFprintf(m_wxr
,_T("[\\\n"));
765 while ((tok
!=_T("BEGIN"))&(tok
!=_T("{")))
771 while ((tok
!=_T("END"))&(tok
!=_T("}")))
777 if (tok
==_T("POPUP"))
783 wxFprintf(m_wxr
,_T(" ],\\\n"));
791 wxFprintf(m_wxr
,_T("]).\";\n\n"));
797 void rc2wxr::ParsePopupMenu()
801 static int menuitem
=99;
813 //Remove /t because it causes problems
815 spot
=tok
.First(_T("\\t"));
819 wxFprintf(m_wxr
,_T(" ['%s',%i,'',\\\n"),tok
.c_str(),menuitem
);
821 while ((tok
!=_T("BEGIN"))&(tok
!=_T("{")))
827 while ((tok
!=_T("END"))&(tok
!=_T("}")))
833 if (tok
==_T("MENUITEM"))
837 if (PeekToken()==_T("SEPARATOR"))
839 wxFprintf(m_wxr
,_T(" [],\\\n"));
847 //Remove /t because it causes problems
849 spot
=tok
.First(_T("\\t"));
855 wxFprintf(m_wxr
,_T(" ['%s',%i,''],\\\n"),tok
.c_str(),menuitem
);
873 wxString
rc2wxr::PeekToken()
893 //Windows pain in the butt CONTROL
895 void rc2wxr::ParseControlMS()
899 wxString label
,varname
,kindctrl
,tok
;
901 label
=GetQuoteField();
905 kindctrl
=GetQuoteField();
907 kindctrl
.MakeUpper();
913 if (kindctrl
==_T("MSCTLS_TRACKBAR32"))
915 ParseSlider(label
,varname
);
917 if (kindctrl
==_T("MSCTLS_PROGRESS32"))
919 ParseProgressBar(label
,varname
);
921 if (kindctrl
==_T("BUTTON"))
923 ParseCtrlButton(label
,varname
);
927 /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
929 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
935 void rc2wxr::ParseSlider(wxString
WXUNUSED(label
), wxString varname
)
944 wxFprintf(m_wxr
,_T(" control = [%i,wxSlider,'','wxSL_HORIZONTAL','%s',"),m_controlid
,varname
.c_str());
946 int x
,y
,width
,height
;
948 ReadRect(x
,y
,width
,height
);
950 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,"),x
,y
,width
,height
);
952 wxFprintf(m_wxr
,_T(" 1, 1, 10,\\\n"));
954 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
960 CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
962 WS_BORDER,15,52,154,13
966 void rc2wxr::ParseProgressBar(wxString
WXUNUSED(label
), wxString varname
)
975 wxFprintf(m_wxr
,_T(" control = [%i,wxGauge,'','wxGA_HORIZONTAL','%s',"),m_controlid
,varname
.c_str());
977 int x
,y
,width
,height
;
979 ReadRect(x
,y
,width
,height
);
981 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,"),x
,y
,width
,height
);
983 wxFprintf(m_wxr
,_T(" 0, 10,\\\n"));
985 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
991 bool rc2wxr::ReadOrs(wxString
& w
)
1011 //Is it a check button or a radio button
1013 void rc2wxr::ParseCtrlButton(wxString label
, wxString varname
)
1025 int x
,y
,width
,height
;
1029 if (tok
==_T("BS_AUTOCHECKBOX"))
1033 wxFprintf(m_wxr
,_T(" control = [%i,wxCheckBox,'%s','0','%s',"),m_controlid
,label
.c_str(),varname
.c_str());
1035 while (ReadOrs(tok
))
1038 ReadRect(x
,y
,width
,height
);
1040 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,0,\\\n"),x
,y
,width
,height
);
1042 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
1048 if (tok
==_T("BS_AUTORADIOBUTTON"))
1052 wxFprintf(m_wxr
,_T(" control = [%i,wxRadioButton,'%s','0','%s',"),m_controlid
,label
.c_str(),varname
.c_str());
1057 ReadRect(x
,y
,width
,height
);
1059 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,0,\\\n"),x
,y
,width
,height
);
1061 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));