]>
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 #pragma implementation "rc2wxr.cpp"
14 #pragma interface "rc2wxr.cpp"
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
25 // need because it includes almost all "standard" wxWindows headers
33 #include "wx/resource.h"
34 //////////////////////////////////////////////////////////////////////
35 // Construction/Destruction
36 //////////////////////////////////////////////////////////////////////
49 void rc2wxr::Convert(wxString wxrfile
, wxString rcfile
)
52 m_filesize
=m_rc
.Length();
53 if( (m_wxr
= fopen( wxrfile
, "wt" )) == NULL
)
90 Microsoft style as of v5.0
91 IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 217, 55
92 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
93 CAPTION "About Funimator"
94 FONT 8, "MS Sans Serif"
97 IDD_DIBATTR DIALOG 7, 16, 172, 119
98 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
99 CAPTION "DIB Attributes"
100 FONT 8, "MS Sans Serif"
102 DEFPUSHBUTTON "Ok", IDOK, 114, 8, 50, 14
103 PUSHBUTTON "Cancel", IDCANCEL, 114, 28, 50, 14
108 void rc2wxr::ParseDialog(wxString dlgname
)
111 static int dlgid
=999;
113 /* Make sure that this really is a dialog
114 microsoft reuses the keyword DIALOG for other things
117 //Microsoft notation?
118 if (tok
=="DISCARDABLE")
123 //This isn't a Dialog resource eject eject
126 //Generate Dialog text
127 fprintf(m_wxr
,"static char *dialog%i = \"dialog(name = '%s',\\\n",dlgid
,dlgname
);
128 //be lazy about style for now. add it later
129 fprintf(m_wxr
,"style = 'wxRAISED_BORDER | wxCAPTION | wxTHICK_FRAME | wxSYSTEM_MENU',\\\n");
131 fprintf(m_wxr
,"id = %i,\\\n",dlgid
);
133 //Record x,y,width,height
134 int x
,y
,width
,height
;
135 ReadRect(x
,y
,width
,height
);
136 fprintf(m_wxr
,"x = %i, y = %i, width = %i, height = %i,\\\n",x
,y
,width
,height
);
139 //CAPTION "About Funimator"
144 while ((tok
!="BEGIN")&(tok
!="{"))
148 title
=GetQuoteField();
149 fprintf(m_wxr
,"title = '%s',\\\n",title
);
153 fprintf(m_wxr
,"use_dialog_units = 1,\\\n");
154 fprintf(m_wxr
,"use_system_defaults = 0,\\\n");
156 fprintf(m_wxr
,"font = [8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif'],\\\n");
158 fprintf(m_wxr
,").\";\n\n");
166 EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT
168 LTEXT "Bands",IDC_STATIC,11,86,21,8
169 EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL
172 void rc2wxr::ParseControls()
177 while ((tok
!="END")&(tok
!="}"))
183 if (tok
=="PUSHBUTTON")
185 if (tok
=="DEFPUSHBUTTON")
198 //LTEXT "Radius",IDC_STATIC,9,67,23,8
199 void rc2wxr::ParseStaticText()
202 wxString phrase
,varname
;
203 phrase
=GetQuoteField();
206 int x
,y
,width
,height
;
207 ReadRect(x
,y
,width
,height
);
208 fprintf(m_wxr
," control = [%i,wxStaticText,'%s','0','%s',",m_controlid
,phrase
,varname
);
209 fprintf(m_wxr
,"%i,%i,%i,%i,'',\\\n",x
,y
,width
,height
);
210 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
212 //EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
213 void rc2wxr::ParseTextCtrl()
219 int x
,y
,width
,height
;
220 ReadRect(x
,y
,width
,height
);
221 fprintf(m_wxr
," control = [%i,wxTextCtrl,'','0','%s',",m_controlid
,varname
);
222 fprintf(m_wxr
,"%i,%i,%i,%i,'',\\\n",x
,y
,width
,height
);
223 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
226 //PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
227 void rc2wxr::ParsePushButton()
230 wxString phrase
,varname
;
231 phrase
=GetQuoteField();
239 if (varname
=="IDCANCEL")
242 if (varname
=="IDAPPLY")
245 int x
,y
,width
,height
;
246 ReadRect(x
,y
,width
,height
);
247 fprintf(m_wxr
," control = [%i,wxButton,'%s','0','%s',",c
,phrase
,varname
);
248 fprintf(m_wxr
,"%i,%i,%i,%i,'',\\\n",x
,y
,width
,height
);
249 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
254 bool rc2wxr::Seperator(int ch
)
256 if ((ch
==' ')|(ch
==',')|(ch
==13)|(ch
==10)|(ch
=='|'))
267 void rc2wxr::ParseGroupBox()
269 // GROUPBOX "Rotate",IDC_STATIC,1,1,71,79
271 wxString phrase
,varname
;
272 phrase
=GetQuoteField();
275 int x
,y
,width
,height
;
276 ReadRect(x
,y
,width
,height
);
277 fprintf(m_wxr
," control = [%i,wxStaticBox,'%s','0','%s',",m_controlid
,phrase
,varname
);
278 fprintf(m_wxr
,"%i,%i,%i,%i,'',\\\n",x
,y
,width
,height
);
279 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
284 void rc2wxr::ReadRect(int & x
, int & y
, int & width
, int & height
)
288 width
=atoi(GetToken());
289 height
=atoi(GetToken());
293 wxString
rc2wxr::GetToken()
311 while (Seperator(ch
))
325 while (!Seperator(ch
))
339 wxString
rc2wxr::GetQuoteField()
359 void rc2wxr::ReadChar(int &ch
)
364 if((result
>=m_filesize
))
367 result
=m_rc
.Read(&ch
,1);
376 void rc2wxr::ParseComboBox()
378 /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
379 WS_VSCROLL | WS_TABSTOP */
384 int x
,y
,width
,height
;
385 ReadRect(x
,y
,width
,height
);
387 fprintf(m_wxr
," control = [%i,wxChoice,'','0','%s',",m_controlid
,varname
);
388 fprintf(m_wxr
,"%i,%i,%i,%i,[],\\\n",x
,y
,width
,height
);
389 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
394 void rc2wxr::ParseMenu(wxString name
)
399 fprintf(m_wxr
,"static char *MenuBar%i = \"menu(name = '%s',\\\n",menuid
,name
);
400 fprintf(m_wxr
,"menu = \\\n");
401 fprintf(m_wxr
,"[\\\n");
403 while ((tok
!="BEGIN")&(tok
!="{"))
406 while ((tok
!="END")&(tok
!="}"))
412 fprintf(m_wxr
," ],\\\n");
416 fprintf(m_wxr
,"]).\";\n\n");
419 void rc2wxr::ParsePopupMenu()
421 static int menuitem
=99;
427 //Remove /t because it causes problems
428 spot
=tok
.First("\\t");
430 fprintf(m_wxr
," ['%s',%i,'',\\\n",tok
,menuitem
);
431 while ((tok
!="BEGIN")&(tok
!="{"))
434 while ((tok
!="END")&(tok
!="}"))
439 if (PeekToken()=="SEPARATOR")
440 fprintf(m_wxr
," [],\\\n");
444 //Remove /t because it causes problems
445 spot
=tok
.First("\\t");
448 fprintf(m_wxr
," ['%s',%i,''],\\\n",tok
,menuitem
);
457 wxString
rc2wxr::PeekToken()
467 //Windows pain in the butt CONTROL
468 void rc2wxr::ParseControlMS()
470 wxString label
,varname
,kindctrl
,tok
;
471 label
=GetQuoteField();
473 kindctrl
=GetQuoteField();
474 kindctrl
.MakeUpper();
477 if (kindctrl
=="MSCTLS_TRACKBAR32")
478 ParseSlider(label
,varname
);
479 if (kindctrl
=="MSCTLS_PROGRESS32")
480 ParseProgressBar(label
,varname
);
481 if (kindctrl
=="BUTTON")
482 ParseCtrlButton(label
,varname
);
484 /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
485 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
488 void rc2wxr::ParseSlider(wxString label
, wxString varname
)
491 while (ReadOrs(tok
));
492 fprintf(m_wxr
," control = [%i,wxSlider,'','wxSL_HORIZONTAL','%s',",m_controlid
,varname
);
493 int x
,y
,width
,height
;
494 ReadRect(x
,y
,width
,height
);
495 fprintf(m_wxr
,"%i,%i,%i,%i,",x
,y
,width
,height
);
496 fprintf(m_wxr
," 1, 1, 10,\\\n");
497 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
500 CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
501 WS_BORDER,15,52,154,13
503 void rc2wxr::ParseProgressBar(wxString label
, wxString varname
)
506 while (ReadOrs(tok
));
507 fprintf(m_wxr
," control = [%i,wxGauge,'','wxGA_HORIZONTAL','%s',",m_controlid
,varname
);
508 int x
,y
,width
,height
;
509 ReadRect(x
,y
,width
,height
);
510 fprintf(m_wxr
,"%i,%i,%i,%i,",x
,y
,width
,height
);
511 fprintf(m_wxr
," 0, 10,\\\n");
512 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
515 bool rc2wxr::ReadOrs(wxString
& w
)
525 //Is it a check button or a radio button
526 void rc2wxr::ParseCtrlButton(wxString label
, wxString varname
)
532 int x
,y
,width
,height
;
534 if (tok
=="BS_AUTOCHECKBOX")
536 fprintf(m_wxr
," control = [%i,wxCheckBox,'%s','0','%s',",m_controlid
,label
,varname
);
537 while (ReadOrs(tok
));
538 ReadRect(x
,y
,width
,height
);
539 fprintf(m_wxr
,"%i,%i,%i,%i,0,\\\n",x
,y
,width
,height
);
540 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
543 if (tok
=="BS_AUTORADIOBUTTON")
545 fprintf(m_wxr
," control = [%i,wxRadioButton,'%s','0','%s',",m_controlid
,label
,varname
);
547 ReadRect(x
,y
,width
,height
);
548 fprintf(m_wxr
,"%i,%i,%i,%i,0,\\\n",x
,y
,width
,height
);
549 fprintf(m_wxr
,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");