]>
git.saurik.com Git - wxWidgets.git/blob - contrib/utils/convertrc/rc2wxr.cpp
2a923d54459a204bb51992e563b010efdba2bac2
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
, _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
)
679 wxFileOffset result
= m_rc
.Tell();
681 if ( result
>= m_filesize
)
684 result
= m_rc
.Read(&ch
,1);
686 if ( result
==wxInvalidOffset
)
695 void rc2wxr::ParseComboBox()
698 /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
700 WS_VSCROLL | WS_TABSTOP */
710 int x
,y
,width
,height
;
712 ReadRect(x
,y
,width
,height
);
716 wxFprintf(m_wxr
,_T(" control = [%i,wxChoice,'','0','%s',"),m_controlid
,varname
.c_str());
718 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,[],\\\n"),x
,y
,width
,height
);
720 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
730 void rc2wxr::ParseMenu(wxString name
)
734 wxString tok
=wxEmptyString
;
740 wxFprintf(m_wxr
,_T("static char *MenuBar%i = \"menu(name = '%s',\\\n"),menuid
,name
.c_str());
742 wxFprintf(m_wxr
,_T("menu = \\\n"));
744 wxFprintf(m_wxr
,_T("[\\\n"));
748 while ((tok
!=_T("BEGIN"))&(tok
!=_T("{")))
754 while ((tok
!=_T("END"))&(tok
!=_T("}")))
760 if (tok
==_T("POPUP"))
766 wxFprintf(m_wxr
,_T(" ],\\\n"));
774 wxFprintf(m_wxr
,_T("]).\";\n\n"));
780 void rc2wxr::ParsePopupMenu()
784 static int menuitem
=99;
796 //Remove /t because it causes problems
798 spot
=tok
.First(_T("\\t"));
802 wxFprintf(m_wxr
,_T(" ['%s',%i,'',\\\n"),tok
.c_str(),menuitem
);
804 while ((tok
!=_T("BEGIN"))&(tok
!=_T("{")))
810 while ((tok
!=_T("END"))&(tok
!=_T("}")))
816 if (tok
==_T("MENUITEM"))
820 if (PeekToken()==_T("SEPARATOR"))
822 wxFprintf(m_wxr
,_T(" [],\\\n"));
830 //Remove /t because it causes problems
832 spot
=tok
.First(_T("\\t"));
838 wxFprintf(m_wxr
,_T(" ['%s',%i,''],\\\n"),tok
.c_str(),menuitem
);
856 wxString
rc2wxr::PeekToken()
876 //Windows pain in the butt CONTROL
878 void rc2wxr::ParseControlMS()
882 wxString label
,varname
,kindctrl
,tok
;
884 label
=GetQuoteField();
888 kindctrl
=GetQuoteField();
890 kindctrl
.MakeUpper();
896 if (kindctrl
==_T("MSCTLS_TRACKBAR32"))
898 ParseSlider(label
,varname
);
900 if (kindctrl
==_T("MSCTLS_PROGRESS32"))
902 ParseProgressBar(label
,varname
);
904 if (kindctrl
==_T("BUTTON"))
906 ParseCtrlButton(label
,varname
);
910 /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
912 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
918 void rc2wxr::ParseSlider(wxString
WXUNUSED(label
), wxString varname
)
927 wxFprintf(m_wxr
,_T(" control = [%i,wxSlider,'','wxSL_HORIZONTAL','%s',"),m_controlid
,varname
.c_str());
929 int x
,y
,width
,height
;
931 ReadRect(x
,y
,width
,height
);
933 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,"),x
,y
,width
,height
);
935 wxFprintf(m_wxr
,_T(" 1, 1, 10,\\\n"));
937 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
943 CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
945 WS_BORDER,15,52,154,13
949 void rc2wxr::ParseProgressBar(wxString
WXUNUSED(label
), wxString varname
)
958 wxFprintf(m_wxr
,_T(" control = [%i,wxGauge,'','wxGA_HORIZONTAL','%s',"),m_controlid
,varname
.c_str());
960 int x
,y
,width
,height
;
962 ReadRect(x
,y
,width
,height
);
964 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,"),x
,y
,width
,height
);
966 wxFprintf(m_wxr
,_T(" 0, 10,\\\n"));
968 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
974 bool rc2wxr::ReadOrs(wxString
& w
)
994 //Is it a check button or a radio button
996 void rc2wxr::ParseCtrlButton(wxString label
, wxString varname
)
1008 int x
,y
,width
,height
;
1012 if (tok
==_T("BS_AUTOCHECKBOX"))
1016 wxFprintf(m_wxr
,_T(" control = [%i,wxCheckBox,'%s','0','%s',"),m_controlid
,label
.c_str(),varname
.c_str());
1018 while (ReadOrs(tok
))
1021 ReadRect(x
,y
,width
,height
);
1023 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,0,\\\n"),x
,y
,width
,height
);
1025 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
1031 if (tok
==_T("BS_AUTORADIOBUTTON"))
1035 wxFprintf(m_wxr
,_T(" control = [%i,wxRadioButton,'%s','0','%s',"),m_controlid
,label
.c_str(),varname
.c_str());
1040 ReadRect(x
,y
,width
,height
);
1042 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,0,\\\n"),x
,y
,width
,height
);
1044 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));