]>
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.cpp"
15 #pragma interface "rc2wxr.cpp"
18 // For compilers that support precompilation, includes "wx/wx.h".
19 #include "wx/wxprec.h"
25 // for all others, include the necessary headers (this file is usually all you
27 // need because it includes almost all "standard" wxWidgets headers
34 #include "wx/deprecated/setup.h"
35 #include "wx/deprecated/resource.h"
39 //////////////////////////////////////////////////////////////////////
40 // Construction/Destruction
41 //////////////////////////////////////////////////////////////////////
53 void rc2wxr::Convert(wxString wxrfile
, wxString rcfile
)
56 m_filesize
=m_rc
.Length();
57 if( (m_wxr
= wxFopen( wxrfile
, _T("wt") )) == NULL
)
68 if (tok
==_T("DIALOG"))
91 Microsoft style as of v5.0
93 IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 217, 55
95 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
97 CAPTION "About Funimator"
99 FONT 8, "MS Sans Serif"
103 IDD_DIBATTR DIALOG 7, 16, 172, 119
105 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
107 CAPTION "DIB Attributes"
109 FONT 8, "MS Sans Serif"
113 DEFPUSHBUTTON "Ok", IDOK, 114, 8, 50, 14
115 PUSHBUTTON "Cancel", IDCANCEL, 114, 28, 50, 14
119 void rc2wxr::ParseDialog(wxString dlgname
)
125 static int dlgid
=999;
129 /* Make sure that this really is a dialog
131 microsoft reuses the keyword DIALOG for other things
137 //Microsoft notation?
139 if (tok
==_T("DISCARDABLE"))
149 //This isn't a Dialog resource eject eject
155 //Generate Dialog text
157 wxFprintf(m_wxr
,_T("static char *dialog%i = \"dialog(name = '%s',\\\n"),dlgid
,dlgname
.c_str());
159 //be lazy about style for now. add it later
161 wxFprintf(m_wxr
,_T("style = 'wxRAISED_BORDER | wxCAPTION | wxTHICK_FRAME | wxSYSTEM_MENU',\\\n"));
162 wxFprintf(m_wxr
,_T("id = %i,\\\n"),dlgid
);
164 //Record x,y,width,height
166 int x
,y
,width
,height
;
168 ReadRect(x
,y
,width
,height
);
170 wxFprintf(m_wxr
,_T("x = %i, y = %i, width = %i, height = %i,\\\n"),x
,y
,width
,height
);
173 //CAPTION "About Funimator"
183 while ((tok
!=_T("BEGIN"))&(tok
!=_T("{")))
187 if (tok
==_T("CAPTION"))
191 title
=GetQuoteField();
193 wxFprintf(m_wxr
,_T("title = '%s',\\\n"),title
.c_str());
201 wxFprintf(m_wxr
,_T("use_dialog_units = 1,\\\n"));
203 wxFprintf(m_wxr
,_T("use_system_defaults = 0,\\\n"));
207 wxFprintf(m_wxr
,_T("font = [8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif'],\\\n"));
211 wxFprintf(m_wxr
,_T(").\";\n\n"));
227 EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT
231 LTEXT "Bands",IDC_STATIC,11,86,21,8
233 EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL
239 void rc2wxr::ParseControls()
249 while ((tok
!=_T("END"))&(tok
!=_T("}")))
253 if (tok
==_T("LTEXT"))
257 if (tok
==_T("EDITTEXT"))
261 if (tok
==_T("PUSHBUTTON"))
265 if (tok
==_T("DEFPUSHBUTTON"))
269 if (tok
==_T("GROUPBOX"))
273 if (tok
==_T("COMBOBOX"))
277 if (tok
==_T("CONTROL"))
291 //LTEXT "Radius",IDC_STATIC,9,67,23,8
293 void rc2wxr::ParseStaticText()
299 wxString phrase
,varname
;
301 phrase
=GetQuoteField();
307 int x
,y
,width
,height
;
309 ReadRect(x
,y
,width
,height
);
311 wxFprintf(m_wxr
,_T(" control = [%i,wxStaticText,'%s','0','%s',"),m_controlid
,phrase
.c_str(),varname
.c_str());
313 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,'',\\\n"),x
,y
,width
,height
);
315 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
319 //EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
321 void rc2wxr::ParseTextCtrl()
333 int x
,y
,width
,height
;
335 ReadRect(x
,y
,width
,height
);
337 wxFprintf(m_wxr
,_T(" control = [%i,wxTextCtrl,'','0','%s',"),m_controlid
,varname
.c_str());
339 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,'',\\\n"),x
,y
,width
,height
);
341 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
347 //PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
349 void rc2wxr::ParsePushButton()
355 wxString phrase
,varname
;
357 phrase
=GetQuoteField();
367 if (varname
==_T("IDOK"))
373 if (varname
==_T("IDCANCEL"))
379 if (varname
==_T("IDAPPLY"))
385 int x
,y
,width
,height
;
387 ReadRect(x
,y
,width
,height
);
389 wxFprintf(m_wxr
,_T(" control = [%i,wxButton,'%s','0','%s',"),c
,phrase
.c_str(),varname
.c_str());
391 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,'',\\\n"),x
,y
,width
,height
);
393 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
403 bool rc2wxr::Seperator(int ch
)
407 if ((ch
==' ')|(ch
==',')|(ch
==13)|(ch
==10)|(ch
=='|'))
429 void rc2wxr::ParseGroupBox()
433 // GROUPBOX "Rotate",IDC_STATIC,1,1,71,79
437 wxString phrase
,varname
;
439 phrase
=GetQuoteField();
445 int x
,y
,width
,height
;
447 ReadRect(x
,y
,width
,height
);
449 wxFprintf(m_wxr
,_T(" control = [%i,wxStaticBox,'%s','0','%s',"),m_controlid
,phrase
.c_str(),varname
.c_str());
451 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,'',\\\n"),x
,y
,width
,height
);
453 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
463 void rc2wxr::ReadRect(int & x
, int & y
, int & width
, int & height
)
467 x
=wxAtoi(GetToken());
469 y
=wxAtoi(GetToken());
471 width
=wxAtoi(GetToken());
473 height
=wxAtoi(GetToken());
481 wxString
rc2wxr::GetToken()
485 wxString tok
=wxEmptyString
;
517 while (Seperator(ch
))
545 while (!Seperator(ch
))
573 wxString
rc2wxr::GetQuoteField()
597 void rc2wxr::ReadChar(int &ch
)
599 wxFileOffset result
= m_rc
.Tell();
601 if ( result
>= m_filesize
)
604 result
= m_rc
.Read(&ch
,1);
606 if ( result
==wxInvalidOffset
)
614 /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
615 WS_VSCROLL | WS_TABSTOP */
616 void rc2wxr::ParseComboBox()
618 int x
,y
,width
,height
;
620 wxString varname
= GetToken();
624 ReadRect(x
,y
,width
,height
);
625 wxFprintf(m_wxr
,_T(" control = [%i,wxChoice,'','0','%s',"),m_controlid
,varname
.c_str());
626 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,[],\\\n"),x
,y
,width
,height
);
627 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
631 void rc2wxr::ParseMenu(wxString name
)
636 wxFprintf(m_wxr
,_T("static char *MenuBar%i = \"menu(name = '%s',\\\n"),menuid
,name
.c_str());
637 wxFprintf(m_wxr
,_T("menu = \\\n"));
638 wxFprintf(m_wxr
,_T("[\\\n"));
640 while ((tok
!=_T("BEGIN"))&(tok
!=_T("{")))
643 while ((tok
!=_T("END"))&(tok
!=_T("}")))
647 if (tok
==_T("POPUP"))
650 wxFprintf(m_wxr
,_T(" ],\\\n"));
654 wxFprintf(m_wxr
,_T("]).\";\n\n"));
658 void rc2wxr::ParsePopupMenu()
660 static int menuitem
=99;
664 wxString tok
= GetQuoteField();
667 //Remove /t because it causes problems
668 spot
=tok
.First(_T("\\t"));
671 wxFprintf(m_wxr
,_T(" ['%s',%i,'',\\\n"),tok
.c_str(),menuitem
);
673 while ((tok
!=_T("BEGIN"))&(tok
!=_T("{")))
676 while ((tok
!=_T("END"))&(tok
!=_T("}")))
680 if (tok
==_T("MENUITEM"))
682 if (PeekToken()==_T("SEPARATOR"))
684 wxFprintf(m_wxr
,_T(" [],\\\n"));
689 //Remove /t because it causes problems
690 spot
=tok
.First(_T("\\t"));
693 wxFprintf(m_wxr
,_T(" ['%s',%i,''],\\\n"),tok
.c_str(),menuitem
);
701 wxString
rc2wxr::PeekToken()
703 wxFileOffset p
= m_rc
.Tell();
704 wxString tok
= GetToken();
709 //Windows pain in the butt CONTROL
710 void rc2wxr::ParseControlMS()
713 wxString label
=GetQuoteField();
714 wxString varname
=GetToken();
715 wxString kindctrl
=GetQuoteField();
717 kindctrl
.MakeUpper();
718 if (kindctrl
==_T("MSCTLS_TRACKBAR32"))
719 ParseSlider(label
,varname
);
720 if (kindctrl
==_T("MSCTLS_PROGRESS32"))
721 ParseProgressBar(label
,varname
);
722 if (kindctrl
==_T("BUTTON"))
723 ParseCtrlButton(label
,varname
);
726 /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
727 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
729 void rc2wxr::ParseSlider(wxString
WXUNUSED(label
), wxString varname
)
731 int x
,y
,width
,height
;
736 wxFprintf(m_wxr
,_T(" control = [%i,wxSlider,'','wxSL_HORIZONTAL','%s',"),m_controlid
,varname
.c_str());
737 ReadRect(x
,y
,width
,height
);
738 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,"),x
,y
,width
,height
);
739 wxFprintf(m_wxr
,_T(" 1, 1, 10,\\\n"));
740 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
744 CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
745 WS_BORDER,15,52,154,13
747 void rc2wxr::ParseProgressBar(wxString
WXUNUSED(label
), wxString varname
)
749 int x
,y
,width
,height
;
755 wxFprintf(m_wxr
,_T(" control = [%i,wxGauge,'','wxGA_HORIZONTAL','%s',"),m_controlid
,varname
.c_str());
756 ReadRect(x
,y
,width
,height
);
757 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,"),x
,y
,width
,height
);
758 wxFprintf(m_wxr
,_T(" 0, 10,\\\n"));
759 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
763 bool rc2wxr::ReadOrs(wxString
& w
)
765 wxString tok
= PeekToken();
773 //Is it a check button or a radio button
774 void rc2wxr::ParseCtrlButton(wxString label
, wxString varname
)
776 int x
,y
,width
,height
;
777 wxString tok
= GetToken();
781 if (tok
==_T("BS_AUTOCHECKBOX"))
783 wxFprintf(m_wxr
,_T(" control = [%i,wxCheckBox,'%s','0','%s',"),m_controlid
,label
.c_str(),varname
.c_str());
787 ReadRect(x
,y
,width
,height
);
788 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,0,\\\n"),x
,y
,width
,height
);
789 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));
792 if (tok
==_T("BS_AUTORADIOBUTTON"))
794 wxFprintf(m_wxr
,_T(" control = [%i,wxRadioButton,'%s','0','%s',"),m_controlid
,label
.c_str(),varname
.c_str());
798 ReadRect(x
,y
,width
,height
);
799 wxFprintf(m_wxr
,_T("%i,%i,%i,%i,0,\\\n"),x
,y
,width
,height
);
800 wxFprintf(m_wxr
,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n"));