]>
git.saurik.com Git - wxWidgets.git/blob - contrib/utils/convertrc/rc2wxr.cpp
1 // rc2wxr.cpp: implementation of the rc2wxr class.
3 //////////////////////////////////////////////////////////////////////
4 //Author: Brian Gavin 9/24/00
5 //License: wxWindows License
7 WARNING- I know this code has some bugs to work out but
8 I don't plan to fix them since I feel that wxr files will
9 not be used much longer.
10 This code was used as a starting point for my rc2xml converter
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
20 // for all others, include the necessary headers (this file is usually all you
22 // need because it includes almost all "standard" wxWidgets headers
29 #include "wx/deprecated/setup.h"
30 #include "wx/deprecated/resource.h"
34 //////////////////////////////////////////////////////////////////////
35 // Construction/Destruction
36 //////////////////////////////////////////////////////////////////////
48 void rc2wxr::Convert(wxString wxrfile
, wxString rcfile
)
51 m_filesize
=m_rc
.Length();
52 if( (m_wxr
= wxFopen( wxrfile
, _T("wt") )) == NULL
)
63 if (tok
==_T("DIALOG"))
86 Microsoft style as of v5.0
88 IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 217, 55
90 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
92 CAPTION "About Funimator"
94 FONT 8, "MS Sans Serif"
98 IDD_DIBATTR DIALOG 7, 16, 172, 119
100 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
102 CAPTION "DIB Attributes"
104 FONT 8, "MS Sans Serif"
108 DEFPUSHBUTTON "Ok", IDOK, 114, 8, 50, 14
110 PUSHBUTTON "Cancel", IDCANCEL, 114, 28, 50, 14
114 void rc2wxr::ParseDialog(wxString dlgname
)
120 static int dlgid
=999;
124 /* Make sure that this really is a dialog
126 microsoft reuses the keyword DIALOG for other things
132 //Microsoft notation?
134 if (tok
==_T("DISCARDABLE"))
144 //This isn't a Dialog resource eject eject
150 //Generate Dialog text
152 wxFprintf(m_wxr
,_T("static char *dialog%i = \"dialog(name = '%s',\\\n"),dlgid
,dlgname
.c_str());
154 //be lazy about style for now. add it later
156 wxFprintf(m_wxr
,_T("style = 'wxRAISED_BORDER | wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU',\\\n"));
157 wxFprintf(m_wxr
,_T("id = %i,\\\n"),dlgid
);
159 //Record x,y,width,height
161 int x
,y
,width
,height
;
163 ReadRect(x
,y
,width
,height
);
165 wxFprintf(m_wxr
,_T("x = %i, y = %i, width = %i, height = %i,\\\n"),x
,y
,width
,height
);
168 //CAPTION "About Funimator"
178 while ((tok
!=_T("BEGIN"))&(tok
!=_T("{")))
182 if (tok
==_T("CAPTION"))
186 title
=GetQuoteField();
188 wxFprintf(m_wxr
,_T("title = '%s',\\\n"),title
.c_str());
196 wxFprintf(m_wxr
,_T("use_dialog_units = 1,\\\n"));
198 wxFprintf(m_wxr
,_T("use_system_defaults = 0,\\\n"));
202 wxFprintf(m_wxr
,_T("font = [8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif'],\\\n"));
206 wxFprintf(m_wxr
,_T(").\";\n\n"));
222 EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT
226 LTEXT "Bands",IDC_STATIC,11,86,21,8
228 EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL
234 void rc2wxr::ParseControls()
244 while ((tok
!=_T("END"))&(tok
!=_T("}")))
248 if (tok
==_T("LTEXT"))
252 if (tok
==_T("EDITTEXT"))
256 if (tok
==_T("PUSHBUTTON"))
260 if (tok
==_T("DEFPUSHBUTTON"))
264 if (tok
==_T("GROUPBOX"))
268 if (tok
==_T("COMBOBOX"))
272 if (tok
==_T("CONTROL"))
286 //LTEXT "Radius",IDC_STATIC,9,67,23,8
288 void rc2wxr::ParseStaticText()
294 wxString phrase
,varname
;
296 phrase
=GetQuoteField();
302 int x
,y
,width
,height
;
304 ReadRect(x
,y
,width
,height
);
306 wxFprintf(m_wxr
,_T(" control = [%i,wxStaticText,'%s','0','%s',"),m_controlid
,phrase
.c_str(),varname
.c_str());
308 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,'',\\\n"),x
,y
,width
,height
);
310 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
314 //EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
316 void rc2wxr::ParseTextCtrl()
328 int x
,y
,width
,height
;
330 ReadRect(x
,y
,width
,height
);
332 wxFprintf(m_wxr
,_T(" control = [%i,wxTextCtrl,'','0','%s',"),m_controlid
,varname
.c_str());
334 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,'',\\\n"),x
,y
,width
,height
);
336 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
342 //PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
344 void rc2wxr::ParsePushButton()
350 wxString phrase
,varname
;
352 phrase
=GetQuoteField();
362 if (varname
==_T("IDOK"))
368 if (varname
==_T("IDCANCEL"))
374 if (varname
==_T("IDAPPLY"))
380 int x
,y
,width
,height
;
382 ReadRect(x
,y
,width
,height
);
384 wxFprintf(m_wxr
,_T(" control = [%i,wxButton,'%s','0','%s',"),c
,phrase
.c_str(),varname
.c_str());
386 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,'',\\\n"),x
,y
,width
,height
);
388 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
398 bool rc2wxr::Separator(int ch
)
402 if ((ch
==' ')|(ch
==',')|(ch
==13)|(ch
==10)|(ch
=='|'))
424 void rc2wxr::ParseGroupBox()
428 // GROUPBOX "Rotate",IDC_STATIC,1,1,71,79
432 wxString phrase
,varname
;
434 phrase
=GetQuoteField();
440 int x
,y
,width
,height
;
442 ReadRect(x
,y
,width
,height
);
444 wxFprintf(m_wxr
,_T(" control = [%i,wxStaticBox,'%s','0','%s',"),m_controlid
,phrase
.c_str(),varname
.c_str());
446 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,'',\\\n"),x
,y
,width
,height
);
448 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
458 void rc2wxr::ReadRect(int & x
, int & y
, int & width
, int & height
)
462 x
=wxAtoi(GetToken());
464 y
=wxAtoi(GetToken());
466 width
=wxAtoi(GetToken());
468 height
=wxAtoi(GetToken());
476 wxString
rc2wxr::GetToken()
480 wxString tok
=wxEmptyString
;
512 while (Separator(ch
))
540 while (!Separator(ch
))
568 wxString
rc2wxr::GetQuoteField()
592 void rc2wxr::ReadChar(int &ch
)
594 wxFileOffset result
= m_rc
.Tell();
596 if ( result
>= m_filesize
)
599 result
= m_rc
.Read(&ch
,1);
601 if ( result
==wxInvalidOffset
)
609 /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
610 WS_VSCROLL | WS_TABSTOP */
611 void rc2wxr::ParseComboBox()
613 int x
,y
,width
,height
;
615 wxString varname
= GetToken();
619 ReadRect(x
,y
,width
,height
);
620 wxFprintf(m_wxr
,_T(" control = [%i,wxChoice,'','0','%s',"),m_controlid
,varname
.c_str());
621 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,[],\\\n"),x
,y
,width
,height
);
622 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
626 void rc2wxr::ParseMenu(wxString name
)
631 wxFprintf(m_wxr
,_T("static char *MenuBar%i = \"menu(name = '%s',\\\n"),menuid
,name
.c_str());
632 wxFprintf(m_wxr
,_T("menu = \\\n"));
633 wxFprintf(m_wxr
,_T("[\\\n"));
635 while ((tok
!=_T("BEGIN"))&(tok
!=_T("{")))
638 while ((tok
!=_T("END"))&(tok
!=_T("}")))
642 if (tok
==_T("POPUP"))
645 wxFprintf(m_wxr
,_T(" ],\\\n"));
649 wxFprintf(m_wxr
,_T("]).\";\n\n"));
653 void rc2wxr::ParsePopupMenu()
655 static int menuitem
=99;
659 wxString tok
= GetQuoteField();
662 //Remove /t because it causes problems
663 spot
=tok
.First(_T("\\t"));
666 wxFprintf(m_wxr
,_T(" ['%s',%i,'',\\\n"),tok
.c_str(),menuitem
);
668 while ((tok
!=_T("BEGIN"))&(tok
!=_T("{")))
671 while ((tok
!=_T("END"))&(tok
!=_T("}")))
675 if (tok
==_T("MENUITEM"))
677 if (PeekToken()==_T("SEPARATOR"))
679 wxFprintf(m_wxr
,_T(" [],\\\n"));
684 //Remove /t because it causes problems
685 spot
=tok
.First(_T("\\t"));
688 wxFprintf(m_wxr
,_T(" ['%s',%i,''],\\\n"),tok
.c_str(),menuitem
);
696 wxString
rc2wxr::PeekToken()
698 wxFileOffset p
= m_rc
.Tell();
699 wxString tok
= GetToken();
704 //Windows pain in the butt CONTROL
705 void rc2wxr::ParseControlMS()
708 wxString label
=GetQuoteField();
709 wxString varname
=GetToken();
710 wxString kindctrl
=GetQuoteField();
712 kindctrl
.MakeUpper();
713 if (kindctrl
==_T("MSCTLS_TRACKBAR32"))
714 ParseSlider(label
,varname
);
715 if (kindctrl
==_T("MSCTLS_PROGRESS32"))
716 ParseProgressBar(label
,varname
);
717 if (kindctrl
==_T("BUTTON"))
718 ParseCtrlButton(label
,varname
);
721 /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
722 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
724 void rc2wxr::ParseSlider(wxString
WXUNUSED(label
), wxString varname
)
726 int x
,y
,width
,height
;
731 wxFprintf(m_wxr
,_T(" control = [%i,wxSlider,'','wxSL_HORIZONTAL','%s',"),m_controlid
,varname
.c_str());
732 ReadRect(x
,y
,width
,height
);
733 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,"),x
,y
,width
,height
);
734 wxFprintf(m_wxr
,_T(" 1, 1, 10,\\\n"));
735 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
739 CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
740 WS_BORDER,15,52,154,13
742 void rc2wxr::ParseProgressBar(wxString
WXUNUSED(label
), wxString varname
)
744 int x
,y
,width
,height
;
750 wxFprintf(m_wxr
,_T(" control = [%i,wxGauge,'','wxGA_HORIZONTAL','%s',"),m_controlid
,varname
.c_str());
751 ReadRect(x
,y
,width
,height
);
752 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,"),x
,y
,width
,height
);
753 wxFprintf(m_wxr
,_T(" 0, 10,\\\n"));
754 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
758 bool rc2wxr::ReadOrs(wxString
& w
)
760 wxString tok
= PeekToken();
768 //Is it a check button or a radio button
769 void rc2wxr::ParseCtrlButton(wxString label
, wxString varname
)
771 int x
,y
,width
,height
;
772 wxString tok
= GetToken();
776 if (tok
==_T("BS_AUTOCHECKBOX"))
778 wxFprintf(m_wxr
,_T(" control = [%i,wxCheckBox,'%s','0','%s',"),m_controlid
,label
.c_str(),varname
.c_str());
782 ReadRect(x
,y
,width
,height
);
783 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,0,\\\n"),x
,y
,width
,height
);
784 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
787 if (tok
==_T("BS_AUTORADIOBUTTON"))
789 wxFprintf(m_wxr
,_T(" control = [%i,wxRadioButton,'%s','0','%s',"),m_controlid
,label
.c_str(),varname
.c_str());
793 ReadRect(x
,y
,width
,height
);
794 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,0,\\\n"),x
,y
,width
,height
);
795 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));