]>
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
14 #pragma implementation "rc2wxr.h"
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
24 // for all others, include the necessary headers (this file is usually all you
26 // need because it includes almost all "standard" wxWidgets headers
33 #include "wx/deprecated/setup.h"
34 #include "wx/deprecated/resource.h"
38 //////////////////////////////////////////////////////////////////////
39 // Construction/Destruction
40 //////////////////////////////////////////////////////////////////////
52 void rc2wxr::Convert(wxString wxrfile
, wxString rcfile
)
55 m_filesize
=m_rc
.Length();
56 if( (m_wxr
= wxFopen( wxrfile
, _T("wt") )) == NULL
)
67 if (tok
==_T("DIALOG"))
90 Microsoft style as of v5.0
92 IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 217, 55
94 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
96 CAPTION "About Funimator"
98 FONT 8, "MS Sans Serif"
102 IDD_DIBATTR DIALOG 7, 16, 172, 119
104 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
106 CAPTION "DIB Attributes"
108 FONT 8, "MS Sans Serif"
112 DEFPUSHBUTTON "Ok", IDOK, 114, 8, 50, 14
114 PUSHBUTTON "Cancel", IDCANCEL, 114, 28, 50, 14
118 void rc2wxr::ParseDialog(wxString dlgname
)
124 static int dlgid
=999;
128 /* Make sure that this really is a dialog
130 microsoft reuses the keyword DIALOG for other things
136 //Microsoft notation?
138 if (tok
==_T("DISCARDABLE"))
148 //This isn't a Dialog resource eject eject
154 //Generate Dialog text
156 wxFprintf(m_wxr
,_T("static char *dialog%i = \"dialog(name = '%s',\\\n"),dlgid
,dlgname
.c_str());
158 //be lazy about style for now. add it later
160 wxFprintf(m_wxr
,_T("style = 'wxRAISED_BORDER | wxCAPTION | wxTHICK_FRAME | wxSYSTEM_MENU',\\\n"));
161 wxFprintf(m_wxr
,_T("id = %i,\\\n"),dlgid
);
163 //Record x,y,width,height
165 int x
,y
,width
,height
;
167 ReadRect(x
,y
,width
,height
);
169 wxFprintf(m_wxr
,_T("x = %i, y = %i, width = %i, height = %i,\\\n"),x
,y
,width
,height
);
172 //CAPTION "About Funimator"
182 while ((tok
!=_T("BEGIN"))&(tok
!=_T("{")))
186 if (tok
==_T("CAPTION"))
190 title
=GetQuoteField();
192 wxFprintf(m_wxr
,_T("title = '%s',\\\n"),title
.c_str());
200 wxFprintf(m_wxr
,_T("use_dialog_units = 1,\\\n"));
202 wxFprintf(m_wxr
,_T("use_system_defaults = 0,\\\n"));
206 wxFprintf(m_wxr
,_T("font = [8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif'],\\\n"));
210 wxFprintf(m_wxr
,_T(").\";\n\n"));
226 EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT
230 LTEXT "Bands",IDC_STATIC,11,86,21,8
232 EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL
238 void rc2wxr::ParseControls()
248 while ((tok
!=_T("END"))&(tok
!=_T("}")))
252 if (tok
==_T("LTEXT"))
256 if (tok
==_T("EDITTEXT"))
260 if (tok
==_T("PUSHBUTTON"))
264 if (tok
==_T("DEFPUSHBUTTON"))
268 if (tok
==_T("GROUPBOX"))
272 if (tok
==_T("COMBOBOX"))
276 if (tok
==_T("CONTROL"))
290 //LTEXT "Radius",IDC_STATIC,9,67,23,8
292 void rc2wxr::ParseStaticText()
298 wxString phrase
,varname
;
300 phrase
=GetQuoteField();
306 int x
,y
,width
,height
;
308 ReadRect(x
,y
,width
,height
);
310 wxFprintf(m_wxr
,_T(" control = [%i,wxStaticText,'%s','0','%s',"),m_controlid
,phrase
.c_str(),varname
.c_str());
312 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,'',\\\n"),x
,y
,width
,height
);
314 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
318 //EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
320 void rc2wxr::ParseTextCtrl()
332 int x
,y
,width
,height
;
334 ReadRect(x
,y
,width
,height
);
336 wxFprintf(m_wxr
,_T(" control = [%i,wxTextCtrl,'','0','%s',"),m_controlid
,varname
.c_str());
338 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,'',\\\n"),x
,y
,width
,height
);
340 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
346 //PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
348 void rc2wxr::ParsePushButton()
354 wxString phrase
,varname
;
356 phrase
=GetQuoteField();
366 if (varname
==_T("IDOK"))
372 if (varname
==_T("IDCANCEL"))
378 if (varname
==_T("IDAPPLY"))
384 int x
,y
,width
,height
;
386 ReadRect(x
,y
,width
,height
);
388 wxFprintf(m_wxr
,_T(" control = [%i,wxButton,'%s','0','%s',"),c
,phrase
.c_str(),varname
.c_str());
390 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,'',\\\n"),x
,y
,width
,height
);
392 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
402 bool rc2wxr::Seperator(int ch
)
406 if ((ch
==' ')|(ch
==',')|(ch
==13)|(ch
==10)|(ch
=='|'))
428 void rc2wxr::ParseGroupBox()
432 // GROUPBOX "Rotate",IDC_STATIC,1,1,71,79
436 wxString phrase
,varname
;
438 phrase
=GetQuoteField();
444 int x
,y
,width
,height
;
446 ReadRect(x
,y
,width
,height
);
448 wxFprintf(m_wxr
,_T(" control = [%i,wxStaticBox,'%s','0','%s',"),m_controlid
,phrase
.c_str(),varname
.c_str());
450 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,'',\\\n"),x
,y
,width
,height
);
452 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
462 void rc2wxr::ReadRect(int & x
, int & y
, int & width
, int & height
)
466 x
=wxAtoi(GetToken());
468 y
=wxAtoi(GetToken());
470 width
=wxAtoi(GetToken());
472 height
=wxAtoi(GetToken());
480 wxString
rc2wxr::GetToken()
484 wxString tok
=wxEmptyString
;
516 while (Seperator(ch
))
544 while (!Seperator(ch
))
572 wxString
rc2wxr::GetQuoteField()
596 void rc2wxr::ReadChar(int &ch
)
598 wxFileOffset result
= m_rc
.Tell();
600 if ( result
>= m_filesize
)
603 result
= m_rc
.Read(&ch
,1);
605 if ( result
==wxInvalidOffset
)
613 /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
614 WS_VSCROLL | WS_TABSTOP */
615 void rc2wxr::ParseComboBox()
617 int x
,y
,width
,height
;
619 wxString varname
= GetToken();
623 ReadRect(x
,y
,width
,height
);
624 wxFprintf(m_wxr
,_T(" control = [%i,wxChoice,'','0','%s',"),m_controlid
,varname
.c_str());
625 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,[],\\\n"),x
,y
,width
,height
);
626 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
630 void rc2wxr::ParseMenu(wxString name
)
635 wxFprintf(m_wxr
,_T("static char *MenuBar%i = \"menu(name = '%s',\\\n"),menuid
,name
.c_str());
636 wxFprintf(m_wxr
,_T("menu = \\\n"));
637 wxFprintf(m_wxr
,_T("[\\\n"));
639 while ((tok
!=_T("BEGIN"))&(tok
!=_T("{")))
642 while ((tok
!=_T("END"))&(tok
!=_T("}")))
646 if (tok
==_T("POPUP"))
649 wxFprintf(m_wxr
,_T(" ],\\\n"));
653 wxFprintf(m_wxr
,_T("]).\";\n\n"));
657 void rc2wxr::ParsePopupMenu()
659 static int menuitem
=99;
663 wxString tok
= GetQuoteField();
666 //Remove /t because it causes problems
667 spot
=tok
.First(_T("\\t"));
670 wxFprintf(m_wxr
,_T(" ['%s',%i,'',\\\n"),tok
.c_str(),menuitem
);
672 while ((tok
!=_T("BEGIN"))&(tok
!=_T("{")))
675 while ((tok
!=_T("END"))&(tok
!=_T("}")))
679 if (tok
==_T("MENUITEM"))
681 if (PeekToken()==_T("SEPARATOR"))
683 wxFprintf(m_wxr
,_T(" [],\\\n"));
688 //Remove /t because it causes problems
689 spot
=tok
.First(_T("\\t"));
692 wxFprintf(m_wxr
,_T(" ['%s',%i,''],\\\n"),tok
.c_str(),menuitem
);
700 wxString
rc2wxr::PeekToken()
702 wxFileOffset p
= m_rc
.Tell();
703 wxString tok
= GetToken();
708 //Windows pain in the butt CONTROL
709 void rc2wxr::ParseControlMS()
712 wxString label
=GetQuoteField();
713 wxString varname
=GetToken();
714 wxString kindctrl
=GetQuoteField();
716 kindctrl
.MakeUpper();
717 if (kindctrl
==_T("MSCTLS_TRACKBAR32"))
718 ParseSlider(label
,varname
);
719 if (kindctrl
==_T("MSCTLS_PROGRESS32"))
720 ParseProgressBar(label
,varname
);
721 if (kindctrl
==_T("BUTTON"))
722 ParseCtrlButton(label
,varname
);
725 /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
726 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
728 void rc2wxr::ParseSlider(wxString
WXUNUSED(label
), wxString varname
)
730 int x
,y
,width
,height
;
735 wxFprintf(m_wxr
,_T(" control = [%i,wxSlider,'','wxSL_HORIZONTAL','%s',"),m_controlid
,varname
.c_str());
736 ReadRect(x
,y
,width
,height
);
737 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,"),x
,y
,width
,height
);
738 wxFprintf(m_wxr
,_T(" 1, 1, 10,\\\n"));
739 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
743 CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
744 WS_BORDER,15,52,154,13
746 void rc2wxr::ParseProgressBar(wxString
WXUNUSED(label
), wxString varname
)
748 int x
,y
,width
,height
;
754 wxFprintf(m_wxr
,_T(" control = [%i,wxGauge,'','wxGA_HORIZONTAL','%s',"),m_controlid
,varname
.c_str());
755 ReadRect(x
,y
,width
,height
);
756 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,"),x
,y
,width
,height
);
757 wxFprintf(m_wxr
,_T(" 0, 10,\\\n"));
758 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
762 bool rc2wxr::ReadOrs(wxString
& w
)
764 wxString tok
= PeekToken();
772 //Is it a check button or a radio button
773 void rc2wxr::ParseCtrlButton(wxString label
, wxString varname
)
775 int x
,y
,width
,height
;
776 wxString tok
= GetToken();
780 if (tok
==_T("BS_AUTOCHECKBOX"))
782 wxFprintf(m_wxr
,_T(" control = [%i,wxCheckBox,'%s','0','%s',"),m_controlid
,label
.c_str(),varname
.c_str());
786 ReadRect(x
,y
,width
,height
);
787 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,0,\\\n"),x
,y
,width
,height
);
788 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
791 if (tok
==_T("BS_AUTORADIOBUTTON"))
793 wxFprintf(m_wxr
,_T(" control = [%i,wxRadioButton,'%s','0','%s',"),m_controlid
,label
.c_str(),varname
.c_str());
797 ReadRect(x
,y
,width
,height
);
798 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,0,\\\n"),x
,y
,width
,height
);
799 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));