]>
Commit | Line | Data |
---|---|---|
2193517f | 1 | // rc2wxr.cpp: implementation of the rc2wxr class. |
88d42654 VS |
2 | // |
3 | ////////////////////////////////////////////////////////////////////// | |
2193517f VS |
4 | //Author: Brian Gavin 9/24/00 |
5 | //License: wxWindows License | |
6 | /* | |
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 | |
11 | */ | |
92a19c2e | 12 | |
88d42654 | 13 | // For compilers that support precompilation, includes "wx/wx.h". |
92a19c2e GT |
14 | #include "wx/wxprec.h" |
15 | ||
2193517f | 16 | #ifdef __BORLANDC__ |
d7e3abf7 | 17 | #pragma hdrstop |
2193517f VS |
18 | #endif |
19 | ||
20 | // for all others, include the necessary headers (this file is usually all you | |
92a19c2e | 21 | |
be5a51fb | 22 | // need because it includes almost all "standard" wxWidgets headers |
92a19c2e | 23 | |
2193517f | 24 | #ifndef WX_PRECOMP |
d7e3abf7 | 25 | #include "wx/wx.h" |
2193517f VS |
26 | #endif |
27 | ||
88d42654 | 28 | #include "wx/image.h" |
7c9955d1 JS |
29 | #include "wx/deprecated/setup.h" |
30 | #include "wx/deprecated/resource.h" | |
92a19c2e | 31 | |
d7e3abf7 | 32 | #include "rc2wxr.h" |
92a19c2e | 33 | |
d7e3abf7 | 34 | ////////////////////////////////////////////////////////////////////// |
88d42654 VS |
35 | // Construction/Destruction |
36 | ////////////////////////////////////////////////////////////////////// | |
37 | ||
2193517f | 38 | rc2wxr::rc2wxr() |
88d42654 | 39 | { |
d7e3abf7 WS |
40 | m_done=false; |
41 | m_controlid=6000; | |
88d42654 VS |
42 | } |
43 | ||
2193517f | 44 | rc2wxr::~rc2wxr() |
88d42654 | 45 | { |
88d42654 VS |
46 | } |
47 | ||
2193517f | 48 | void rc2wxr::Convert(wxString wxrfile, wxString rcfile) |
88d42654 | 49 | { |
4430ec36 WS |
50 | m_rc.Open(rcfile); |
51 | m_filesize=m_rc.Length(); | |
994e41cb | 52 | if( (m_wxr = wxFopen( wxrfile, _T("wt") )) == NULL ) |
4430ec36 WS |
53 | { |
54 | return; | |
55 | } | |
92a19c2e | 56 | |
4430ec36 | 57 | wxString tok,prevtok; |
92a19c2e | 58 | |
4430ec36 WS |
59 | while (!m_done) |
60 | { | |
61 | tok=GetToken(); | |
92a19c2e | 62 | |
4430ec36 WS |
63 | if (tok==_T("DIALOG")) |
64 | { | |
65 | ParseDialog(prevtok); | |
66 | } | |
92a19c2e | 67 | |
4430ec36 WS |
68 | if (tok==_T("MENU")) |
69 | { | |
70 | ParseMenu(prevtok); | |
71 | } | |
88d42654 | 72 | |
4430ec36 WS |
73 | prevtok=tok; |
74 | } | |
92a19c2e | 75 | |
4430ec36 | 76 | fclose(m_wxr); |
92a19c2e | 77 | |
4430ec36 | 78 | m_rc.Close(); |
88d42654 VS |
79 | } |
80 | ||
81 | ||
82 | /* | |
92a19c2e | 83 | |
7c9955d1 | 84 | Example .rc |
92a19c2e | 85 | |
88d42654 | 86 | Microsoft style as of v5.0 |
92a19c2e | 87 | |
88d42654 | 88 | IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 217, 55 |
92a19c2e | 89 | |
88d42654 | 90 | STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU |
92a19c2e | 91 | |
88d42654 | 92 | CAPTION "About Funimator" |
92a19c2e | 93 | |
88d42654 VS |
94 | FONT 8, "MS Sans Serif" |
95 | ||
96 | Borland 4.5 style rc | |
92a19c2e | 97 | |
88d42654 | 98 | IDD_DIBATTR DIALOG 7, 16, 172, 119 |
92a19c2e | 99 | |
88d42654 | 100 | STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU |
92a19c2e | 101 | |
88d42654 | 102 | CAPTION "DIB Attributes" |
92a19c2e | 103 | |
88d42654 | 104 | FONT 8, "MS Sans Serif" |
92a19c2e | 105 | |
88d42654 | 106 | { |
92a19c2e | 107 | |
88d42654 | 108 | DEFPUSHBUTTON "Ok", IDOK, 114, 8, 50, 14 |
92a19c2e | 109 | |
88d42654 VS |
110 | PUSHBUTTON "Cancel", IDCANCEL, 114, 28, 50, 14 |
111 | ||
88d42654 | 112 | */ |
92a19c2e | 113 | |
2193517f | 114 | void rc2wxr::ParseDialog(wxString dlgname) |
92a19c2e | 115 | |
2193517f | 116 | { |
92a19c2e | 117 | |
2193517f | 118 | wxString tok; |
92a19c2e | 119 | |
2193517f | 120 | static int dlgid=999; |
92a19c2e | 121 | |
2193517f | 122 | dlgid++; |
92a19c2e | 123 | |
7c9955d1 | 124 | /* Make sure that this really is a dialog |
92a19c2e | 125 | |
2193517f | 126 | microsoft reuses the keyword DIALOG for other things |
92a19c2e | 127 | |
2193517f | 128 | */ |
92a19c2e | 129 | |
2193517f | 130 | tok=PeekToken(); |
92a19c2e | 131 | |
2193517f | 132 | //Microsoft notation? |
92a19c2e | 133 | |
19d0f58d | 134 | if (tok==_T("DISCARDABLE")) |
92a19c2e | 135 | |
2193517f | 136 | { |
92a19c2e | 137 | |
2193517f | 138 | tok=GetToken(); |
92a19c2e | 139 | |
2193517f | 140 | tok=PeekToken(); |
92a19c2e | 141 | |
2193517f | 142 | } |
92a19c2e | 143 | |
2193517f | 144 | //This isn't a Dialog resource eject eject |
92a19c2e | 145 | |
2193517f | 146 | if (!tok.IsNumber()) |
92a19c2e | 147 | |
2193517f | 148 | return; |
92a19c2e | 149 | |
88d42654 | 150 | //Generate Dialog text |
92a19c2e | 151 | |
19d0f58d | 152 | wxFprintf(m_wxr,_T("static char *dialog%i = \"dialog(name = '%s',\\\n"),dlgid,dlgname.c_str()); |
92a19c2e | 153 | |
88d42654 | 154 | //be lazy about style for now. add it later |
92a19c2e | 155 | |
19d0f58d | 156 | wxFprintf(m_wxr,_T("style = 'wxRAISED_BORDER | wxCAPTION | wxTHICK_FRAME | wxSYSTEM_MENU',\\\n")); |
19d0f58d | 157 | wxFprintf(m_wxr,_T("id = %i,\\\n"),dlgid); |
88d42654 VS |
158 | |
159 | //Record x,y,width,height | |
92a19c2e | 160 | |
88d42654 | 161 | int x,y,width,height; |
92a19c2e | 162 | |
88d42654 | 163 | ReadRect(x,y,width,height); |
92a19c2e | 164 | |
19d0f58d | 165 | wxFprintf(m_wxr,_T("x = %i, y = %i, width = %i, height = %i,\\\n"),x,y,width,height); |
88d42654 VS |
166 | |
167 | ||
168 | //CAPTION "About Funimator" | |
92a19c2e | 169 | |
88d42654 | 170 | //Get Title |
92a19c2e | 171 | |
88d42654 | 172 | tok=GetToken(); |
92a19c2e | 173 | |
88d42654 VS |
174 | wxString title; |
175 | ||
92a19c2e GT |
176 | |
177 | ||
19d0f58d | 178 | while ((tok!=_T("BEGIN"))&(tok!=_T("{"))) |
92a19c2e | 179 | |
88d42654 | 180 | { |
92a19c2e | 181 | |
19d0f58d | 182 | if (tok==_T("CAPTION")) |
92a19c2e | 183 | |
2193517f | 184 | { |
92a19c2e | 185 | |
2193517f | 186 | title=GetQuoteField(); |
92a19c2e | 187 | |
19d0f58d | 188 | wxFprintf(m_wxr,_T("title = '%s',\\\n"),title.c_str()); |
92a19c2e | 189 | |
2193517f | 190 | } |
92a19c2e | 191 | |
88d42654 | 192 | tok=GetToken(); |
92a19c2e | 193 | |
88d42654 | 194 | } |
92a19c2e | 195 | |
19d0f58d | 196 | wxFprintf(m_wxr,_T("use_dialog_units = 1,\\\n")); |
92a19c2e | 197 | |
19d0f58d | 198 | wxFprintf(m_wxr,_T("use_system_defaults = 0,\\\n")); |
88d42654 | 199 | |
92a19c2e GT |
200 | |
201 | ||
19d0f58d | 202 | wxFprintf(m_wxr,_T("font = [8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif'],\\\n")); |
92a19c2e | 203 | |
88d42654 | 204 | ParseControls(); |
92a19c2e | 205 | |
19d0f58d | 206 | wxFprintf(m_wxr,_T(").\";\n\n")); |
92a19c2e | 207 | |
88d42654 VS |
208 | } |
209 | ||
92a19c2e GT |
210 | |
211 | ||
88d42654 | 212 | /* |
92a19c2e | 213 | |
88d42654 VS |
214 | BEGIN |
215 | ||
216 | ||
217 | ||
92a19c2e GT |
218 | |
219 | ||
220 | ||
221 | ||
7c9955d1 | 222 | EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT |
92a19c2e | 223 | |
88d42654 | 224 | WS_TABSTOP |
92a19c2e | 225 | |
88d42654 | 226 | LTEXT "Bands",IDC_STATIC,11,86,21,8 |
92a19c2e | 227 | |
88d42654 | 228 | EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL |
92a19c2e | 229 | |
88d42654 | 230 | END |
92a19c2e | 231 | |
88d42654 | 232 | */ |
92a19c2e | 233 | |
2193517f | 234 | void rc2wxr::ParseControls() |
92a19c2e | 235 | |
88d42654 | 236 | { |
92a19c2e | 237 | |
88d42654 VS |
238 | wxString tok; |
239 | ||
92a19c2e GT |
240 | |
241 | ||
88d42654 | 242 | tok=GetToken(); |
92a19c2e | 243 | |
19d0f58d | 244 | while ((tok!=_T("END"))&(tok!=_T("}"))) |
92a19c2e | 245 | |
88d42654 | 246 | { |
92a19c2e | 247 | |
19d0f58d | 248 | if (tok==_T("LTEXT")) |
92a19c2e | 249 | |
88d42654 | 250 | ParseStaticText(); |
92a19c2e | 251 | |
19d0f58d | 252 | if (tok==_T("EDITTEXT")) |
92a19c2e | 253 | |
88d42654 | 254 | ParseTextCtrl(); |
92a19c2e | 255 | |
19d0f58d | 256 | if (tok==_T("PUSHBUTTON")) |
92a19c2e | 257 | |
88d42654 | 258 | ParsePushButton(); |
92a19c2e | 259 | |
19d0f58d | 260 | if (tok==_T("DEFPUSHBUTTON")) |
92a19c2e | 261 | |
88d42654 | 262 | ParsePushButton(); |
92a19c2e | 263 | |
19d0f58d | 264 | if (tok==_T("GROUPBOX")) |
92a19c2e | 265 | |
88d42654 | 266 | ParseGroupBox(); |
92a19c2e | 267 | |
19d0f58d | 268 | if (tok==_T("COMBOBOX")) |
92a19c2e | 269 | |
88d42654 | 270 | ParseComboBox(); |
92a19c2e | 271 | |
19d0f58d | 272 | if (tok==_T("CONTROL")) |
92a19c2e | 273 | |
88d42654 VS |
274 | ParseControlMS(); |
275 | ||
92a19c2e GT |
276 | |
277 | ||
88d42654 | 278 | tok=GetToken(); |
92a19c2e | 279 | |
88d42654 VS |
280 | } |
281 | ||
92a19c2e GT |
282 | |
283 | ||
88d42654 | 284 | } |
92a19c2e | 285 | |
88d42654 | 286 | //LTEXT "Radius",IDC_STATIC,9,67,23,8 |
92a19c2e | 287 | |
2193517f | 288 | void rc2wxr::ParseStaticText() |
92a19c2e | 289 | |
88d42654 | 290 | { |
92a19c2e | 291 | |
88d42654 | 292 | wxString tok; |
92a19c2e | 293 | |
88d42654 | 294 | wxString phrase,varname; |
92a19c2e | 295 | |
88d42654 | 296 | phrase=GetQuoteField(); |
92a19c2e | 297 | |
88d42654 | 298 | varname=GetToken(); |
92a19c2e | 299 | |
88d42654 | 300 | m_controlid++; |
92a19c2e | 301 | |
88d42654 | 302 | int x,y,width,height; |
92a19c2e | 303 | |
88d42654 | 304 | ReadRect(x,y,width,height); |
92a19c2e | 305 | |
19d0f58d | 306 | wxFprintf(m_wxr,_T(" control = [%i,wxStaticText,'%s','0','%s',"),m_controlid,phrase.c_str(),varname.c_str()); |
92a19c2e | 307 | |
19d0f58d | 308 | wxFprintf(m_wxr,_T("%i,%i,%i,%i,'',\\\n"),x,y,width,height); |
92a19c2e | 309 | |
19d0f58d | 310 | wxFprintf(m_wxr,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n")); |
92a19c2e | 311 | |
88d42654 | 312 | } |
92a19c2e | 313 | |
88d42654 | 314 | //EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL |
92a19c2e | 315 | |
2193517f | 316 | void rc2wxr::ParseTextCtrl() |
92a19c2e | 317 | |
88d42654 | 318 | { |
92a19c2e | 319 | |
88d42654 | 320 | wxString tok; |
92a19c2e | 321 | |
88d42654 | 322 | wxString varname; |
92a19c2e | 323 | |
88d42654 | 324 | varname=GetToken(); |
92a19c2e | 325 | |
88d42654 | 326 | m_controlid++; |
92a19c2e | 327 | |
88d42654 | 328 | int x,y,width,height; |
92a19c2e | 329 | |
88d42654 | 330 | ReadRect(x,y,width,height); |
92a19c2e | 331 | |
19d0f58d | 332 | wxFprintf(m_wxr,_T(" control = [%i,wxTextCtrl,'','0','%s',"),m_controlid,varname.c_str()); |
92a19c2e | 333 | |
19d0f58d | 334 | wxFprintf(m_wxr,_T("%i,%i,%i,%i,'',\\\n"),x,y,width,height); |
92a19c2e | 335 | |
19d0f58d | 336 | wxFprintf(m_wxr,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n")); |
88d42654 | 337 | |
92a19c2e GT |
338 | |
339 | ||
88d42654 | 340 | } |
92a19c2e | 341 | |
88d42654 | 342 | //PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP |
92a19c2e | 343 | |
2193517f | 344 | void rc2wxr::ParsePushButton() |
92a19c2e | 345 | |
88d42654 | 346 | { |
92a19c2e | 347 | |
88d42654 | 348 | wxString tok; |
92a19c2e | 349 | |
88d42654 | 350 | wxString phrase,varname; |
92a19c2e | 351 | |
88d42654 | 352 | phrase=GetQuoteField(); |
92a19c2e | 353 | |
88d42654 | 354 | varname=GetToken(); |
92a19c2e | 355 | |
88d42654 | 356 | int c; |
92a19c2e | 357 | |
88d42654 | 358 | m_controlid++; |
92a19c2e | 359 | |
88d42654 | 360 | c=m_controlid; |
92a19c2e | 361 | |
19d0f58d | 362 | if (varname==_T("IDOK")) |
92a19c2e | 363 | |
88d42654 VS |
364 | c=wxID_OK; |
365 | ||
92a19c2e GT |
366 | |
367 | ||
19d0f58d | 368 | if (varname==_T("IDCANCEL")) |
92a19c2e | 369 | |
88d42654 VS |
370 | c=wxID_CANCEL; |
371 | ||
92a19c2e GT |
372 | |
373 | ||
19d0f58d | 374 | if (varname==_T("IDAPPLY")) |
92a19c2e | 375 | |
88d42654 VS |
376 | c=wxID_APPLY; |
377 | ||
92a19c2e GT |
378 | |
379 | ||
88d42654 | 380 | int x,y,width,height; |
92a19c2e | 381 | |
88d42654 | 382 | ReadRect(x,y,width,height); |
92a19c2e | 383 | |
19d0f58d | 384 | wxFprintf(m_wxr,_T(" control = [%i,wxButton,'%s','0','%s',"),c,phrase.c_str(),varname.c_str()); |
92a19c2e | 385 | |
19d0f58d | 386 | wxFprintf(m_wxr,_T("%i,%i,%i,%i,'',\\\n"),x,y,width,height); |
92a19c2e | 387 | |
19d0f58d | 388 | wxFprintf(m_wxr,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n")); |
88d42654 | 389 | |
92a19c2e GT |
390 | |
391 | ||
88d42654 VS |
392 | } |
393 | ||
394 | ||
92a19c2e GT |
395 | |
396 | ||
397 | ||
3103e8a9 | 398 | bool rc2wxr::Separator(int ch) |
92a19c2e | 399 | |
88d42654 | 400 | { |
92a19c2e | 401 | |
88d42654 | 402 | if ((ch==' ')|(ch==',')|(ch==13)|(ch==10)|(ch=='|')) |
92a19c2e | 403 | |
f80ea77b | 404 | return true; |
88d42654 | 405 | |
92a19c2e GT |
406 | |
407 | ||
88d42654 | 408 | if (ch==EOF) |
92a19c2e | 409 | |
88d42654 | 410 | { |
92a19c2e | 411 | |
f80ea77b | 412 | m_done=true; |
92a19c2e | 413 | |
f80ea77b | 414 | return true; |
92a19c2e | 415 | |
88d42654 | 416 | } |
92a19c2e | 417 | |
f80ea77b | 418 | return false; |
92a19c2e | 419 | |
88d42654 VS |
420 | } |
421 | ||
92a19c2e GT |
422 | |
423 | ||
2193517f | 424 | void rc2wxr::ParseGroupBox() |
92a19c2e | 425 | |
88d42654 | 426 | { |
92a19c2e | 427 | |
88d42654 | 428 | // GROUPBOX "Rotate",IDC_STATIC,1,1,71,79 |
92a19c2e | 429 | |
88d42654 | 430 | wxString tok; |
92a19c2e | 431 | |
88d42654 | 432 | wxString phrase,varname; |
92a19c2e | 433 | |
88d42654 | 434 | phrase=GetQuoteField(); |
92a19c2e | 435 | |
88d42654 | 436 | varname=GetToken(); |
92a19c2e | 437 | |
88d42654 | 438 | m_controlid++; |
92a19c2e | 439 | |
88d42654 | 440 | int x,y,width,height; |
92a19c2e | 441 | |
88d42654 | 442 | ReadRect(x,y,width,height); |
92a19c2e | 443 | |
19d0f58d | 444 | wxFprintf(m_wxr,_T(" control = [%i,wxStaticBox,'%s','0','%s',"),m_controlid,phrase.c_str(),varname.c_str()); |
92a19c2e | 445 | |
19d0f58d | 446 | wxFprintf(m_wxr,_T("%i,%i,%i,%i,'',\\\n"),x,y,width,height); |
92a19c2e | 447 | |
19d0f58d | 448 | wxFprintf(m_wxr,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n")); |
88d42654 VS |
449 | |
450 | ||
92a19c2e GT |
451 | |
452 | ||
453 | ||
88d42654 VS |
454 | } |
455 | ||
92a19c2e GT |
456 | |
457 | ||
2193517f | 458 | void rc2wxr::ReadRect(int & x, int & y, int & width, int & height) |
92a19c2e | 459 | |
88d42654 | 460 | { |
92a19c2e | 461 | |
19d0f58d | 462 | x=wxAtoi(GetToken()); |
92a19c2e | 463 | |
19d0f58d | 464 | y=wxAtoi(GetToken()); |
92a19c2e | 465 | |
19d0f58d | 466 | width=wxAtoi(GetToken()); |
92a19c2e | 467 | |
19d0f58d | 468 | height=wxAtoi(GetToken()); |
88d42654 | 469 | |
92a19c2e GT |
470 | |
471 | ||
88d42654 VS |
472 | } |
473 | ||
92a19c2e GT |
474 | |
475 | ||
2193517f | 476 | wxString rc2wxr::GetToken() |
92a19c2e | 477 | |
88d42654 | 478 | { |
92a19c2e | 479 | |
19d0f58d | 480 | wxString tok=wxEmptyString; |
88d42654 | 481 | |
92a19c2e GT |
482 | |
483 | ||
88d42654 | 484 | if (m_rc.Eof()) |
92a19c2e | 485 | |
88d42654 | 486 | { |
92a19c2e | 487 | |
f80ea77b | 488 | m_done=true; |
92a19c2e | 489 | |
88d42654 | 490 | return tok; |
92a19c2e | 491 | |
88d42654 VS |
492 | } |
493 | ||
92a19c2e GT |
494 | |
495 | ||
88d42654 | 496 | int ch=0; |
92a19c2e | 497 | |
88d42654 | 498 | ReadChar(ch); |
92a19c2e | 499 | |
88d42654 | 500 | if (ch==EOF) |
92a19c2e | 501 | |
88d42654 | 502 | { |
92a19c2e | 503 | |
f80ea77b | 504 | m_done=true; |
92a19c2e | 505 | |
88d42654 | 506 | return tok; |
92a19c2e | 507 | |
88d42654 VS |
508 | } |
509 | ||
92a19c2e GT |
510 | |
511 | ||
3103e8a9 | 512 | while (Separator(ch)) |
92a19c2e | 513 | |
88d42654 | 514 | { |
92a19c2e | 515 | |
88d42654 | 516 | ReadChar(ch); |
92a19c2e | 517 | |
88d42654 | 518 | if (m_done) |
92a19c2e | 519 | |
2193517f | 520 | return tok; |
92a19c2e | 521 | |
88d42654 VS |
522 | } |
523 | ||
92a19c2e GT |
524 | |
525 | ||
88d42654 | 526 | if (ch==EOF) |
92a19c2e | 527 | |
88d42654 | 528 | { |
92a19c2e | 529 | |
f80ea77b | 530 | m_done=true; |
88d42654 | 531 | |
92a19c2e GT |
532 | |
533 | ||
88d42654 | 534 | } |
92a19c2e | 535 | |
7c9955d1 | 536 | |
88d42654 | 537 | |
92a19c2e GT |
538 | |
539 | ||
3103e8a9 | 540 | while (!Separator(ch)) |
92a19c2e | 541 | |
88d42654 | 542 | { |
92a19c2e | 543 | |
2193517f | 544 | tok+=(char)ch; |
92a19c2e | 545 | |
2193517f | 546 | ReadChar(ch); |
88d42654 | 547 | |
92a19c2e GT |
548 | |
549 | ||
88d42654 VS |
550 | } |
551 | ||
92a19c2e GT |
552 | |
553 | ||
88d42654 | 554 | if (ch==EOF) |
92a19c2e | 555 | |
f80ea77b | 556 | m_done=true; |
88d42654 VS |
557 | |
558 | ||
92a19c2e GT |
559 | |
560 | ||
561 | ||
88d42654 | 562 | return tok; |
92a19c2e | 563 | |
88d42654 VS |
564 | } |
565 | ||
92a19c2e GT |
566 | |
567 | ||
2193517f | 568 | wxString rc2wxr::GetQuoteField() |
88d42654 | 569 | { |
d7e3abf7 | 570 | wxString phrase; |
92a19c2e | 571 | |
d7e3abf7 WS |
572 | //ASCII code 34 " |
573 | int ch=0; | |
574 | ReadChar(ch); | |
92a19c2e | 575 | |
d7e3abf7 WS |
576 | while (ch!=34) |
577 | ReadChar(ch); | |
92a19c2e | 578 | |
d7e3abf7 | 579 | ReadChar(ch); |
92a19c2e | 580 | |
d7e3abf7 WS |
581 | while (ch!=34) |
582 | { | |
583 | phrase+=(char)ch; | |
584 | ReadChar(ch); | |
585 | } | |
92a19c2e | 586 | |
d7e3abf7 | 587 | return phrase; |
88d42654 VS |
588 | } |
589 | ||
92a19c2e GT |
590 | |
591 | ||
2193517f | 592 | void rc2wxr::ReadChar(int &ch) |
88d42654 | 593 | { |
19311d4e | 594 | wxFileOffset result = m_rc.Tell(); |
92a19c2e | 595 | |
19311d4e WS |
596 | if ( result >= m_filesize ) |
597 | m_done=true; | |
88d42654 | 598 | |
19311d4e | 599 | result = m_rc.Read(&ch,1); |
92a19c2e | 600 | |
19311d4e WS |
601 | if ( result==wxInvalidOffset ) |
602 | m_done=true; | |
92a19c2e | 603 | |
19311d4e WS |
604 | if(ch==EOF) |
605 | m_done=true; | |
88d42654 VS |
606 | } |
607 | ||
92a19c2e | 608 | |
7c9955d1 | 609 | /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT | |
88d42654 | 610 | WS_VSCROLL | WS_TABSTOP */ |
d7e3abf7 WS |
611 | void rc2wxr::ParseComboBox() |
612 | { | |
613 | int x,y,width,height; | |
614 | wxString tok; | |
615 | wxString varname = GetToken(); | |
92a19c2e | 616 | |
d7e3abf7 | 617 | m_controlid++; |
92a19c2e | 618 | |
d7e3abf7 WS |
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")); | |
88d42654 VS |
623 | } |
624 | ||
92a19c2e | 625 | |
2193517f | 626 | void rc2wxr::ParseMenu(wxString name) |
88d42654 | 627 | { |
d7e3abf7 WS |
628 | wxString tok; |
629 | static int menuid=0; | |
630 | menuid++; | |
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")); | |
92a19c2e | 634 | |
d7e3abf7 WS |
635 | while ((tok!=_T("BEGIN"))&(tok!=_T("{"))) |
636 | tok=GetToken(); | |
92a19c2e | 637 | |
d7e3abf7 | 638 | while ((tok!=_T("END"))&(tok!=_T("}"))) |
f80ea77b | 639 | { |
d7e3abf7 | 640 | tok=GetToken(); |
92a19c2e | 641 | |
d7e3abf7 WS |
642 | if (tok==_T("POPUP")) |
643 | { | |
644 | ParsePopupMenu(); | |
645 | wxFprintf(m_wxr,_T(" ],\\\n")); | |
646 | } | |
f80ea77b | 647 | } |
92a19c2e | 648 | |
d7e3abf7 | 649 | wxFprintf(m_wxr,_T("]).\";\n\n")); |
88d42654 VS |
650 | } |
651 | ||
92a19c2e | 652 | |
2193517f | 653 | void rc2wxr::ParsePopupMenu() |
2193517f | 654 | { |
d7e3abf7 | 655 | static int menuitem=99; |
92a19c2e | 656 | |
d7e3abf7 | 657 | menuitem++; |
92a19c2e | 658 | |
d7e3abf7 WS |
659 | wxString tok = GetQuoteField(); |
660 | int spot; | |
88d42654 | 661 | |
d7e3abf7 WS |
662 | //Remove /t because it causes problems |
663 | spot=tok.First(_T("\\t")); | |
664 | tok=tok.Left(spot); | |
92a19c2e | 665 | |
d7e3abf7 | 666 | wxFprintf(m_wxr,_T(" ['%s',%i,'',\\\n"),tok.c_str(),menuitem); |
92a19c2e | 667 | |
d7e3abf7 WS |
668 | while ((tok!=_T("BEGIN"))&(tok!=_T("{"))) |
669 | tok=GetToken(); | |
7c9955d1 | 670 | |
d7e3abf7 WS |
671 | while ((tok!=_T("END"))&(tok!=_T("}"))) |
672 | { | |
673 | tok=GetToken(); | |
92a19c2e | 674 | |
d7e3abf7 WS |
675 | if (tok==_T("MENUITEM")) |
676 | { | |
677 | if (PeekToken()==_T("SEPARATOR")) | |
678 | { | |
679 | wxFprintf(m_wxr,_T(" [],\\\n")); | |
680 | } | |
681 | else | |
682 | { | |
683 | tok=GetQuoteField(); | |
684 | //Remove /t because it causes problems | |
685 | spot=tok.First(_T("\\t")); | |
686 | tok=tok.Left(spot); | |
687 | menuitem++; | |
688 | wxFprintf(m_wxr,_T(" ['%s',%i,''],\\\n"),tok.c_str(),menuitem); | |
689 | } | |
690 | } | |
691 | } | |
88d42654 VS |
692 | } |
693 | ||
92a19c2e GT |
694 | |
695 | ||
2193517f | 696 | wxString rc2wxr::PeekToken() |
88d42654 | 697 | { |
d7e3abf7 WS |
698 | wxFileOffset p = m_rc.Tell(); |
699 | wxString tok = GetToken(); | |
700 | m_rc.Seek(p); | |
701 | return tok; | |
88d42654 | 702 | } |
92a19c2e | 703 | |
88d42654 | 704 | //Windows pain in the butt CONTROL |
2193517f | 705 | void rc2wxr::ParseControlMS() |
88d42654 | 706 | { |
d7e3abf7 WS |
707 | wxString tok; |
708 | wxString label=GetQuoteField(); | |
709 | wxString varname=GetToken(); | |
710 | wxString kindctrl=GetQuoteField(); | |
92a19c2e | 711 | |
d7e3abf7 WS |
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); | |
88d42654 | 719 | } |
92a19c2e | 720 | |
7c9955d1 | 721 | /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH | |
88d42654 VS |
722 | TBS_NOTICKS | WS_TABSTOP,52,73,100,15 |
723 | */ | |
19d0f58d | 724 | void rc2wxr::ParseSlider(wxString WXUNUSED(label), wxString varname) |
88d42654 | 725 | { |
d7e3abf7 WS |
726 | int x,y,width,height; |
727 | wxString tok; | |
92a19c2e | 728 | |
d7e3abf7 WS |
729 | while (ReadOrs(tok)) |
730 | ; | |
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")); | |
88d42654 | 736 | } |
92a19c2e | 737 | |
7c9955d1 | 738 | /* |
88d42654 VS |
739 | CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32", |
740 | WS_BORDER,15,52,154,13 | |
741 | */ | |
19d0f58d | 742 | void rc2wxr::ParseProgressBar(wxString WXUNUSED(label), wxString varname) |
88d42654 | 743 | { |
d7e3abf7 WS |
744 | int x,y,width,height; |
745 | wxString tok; | |
92a19c2e | 746 | |
b2247ee9 CE |
747 | while (ReadOrs(tok)) |
748 | ; | |
92a19c2e | 749 | |
d7e3abf7 | 750 | wxFprintf(m_wxr,_T(" control = [%i,wxGauge,'','wxGA_HORIZONTAL','%s',"),m_controlid,varname.c_str()); |
2193517f | 751 | ReadRect(x,y,width,height); |
d7e3abf7 WS |
752 | wxFprintf(m_wxr,_T("%i,%i,%i,%i,"),x,y,width,height); |
753 | wxFprintf(m_wxr,_T(" 0, 10,\\\n")); | |
19d0f58d | 754 | wxFprintf(m_wxr,_T("[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n")); |
88d42654 VS |
755 | } |
756 | ||
92a19c2e | 757 | |
d7e3abf7 | 758 | bool rc2wxr::ReadOrs(wxString & w) |
88d42654 | 759 | { |
d7e3abf7 WS |
760 | wxString tok = PeekToken(); |
761 | if (tok.IsNumber()) | |
762 | return false; | |
763 | w=GetToken(); | |
764 | return true; | |
88d42654 VS |
765 | } |
766 | ||
767 | ||
d7e3abf7 WS |
768 | //Is it a check button or a radio button |
769 | void rc2wxr::ParseCtrlButton(wxString label, wxString varname) | |
770 | { | |
771 | int x,y,width,height; | |
772 | wxString tok = GetToken(); | |
88d42654 | 773 | |
d7e3abf7 | 774 | m_controlid++; |
92a19c2e | 775 | |
d7e3abf7 WS |
776 | if (tok==_T("BS_AUTOCHECKBOX")) |
777 | { | |
778 | wxFprintf(m_wxr,_T(" control = [%i,wxCheckBox,'%s','0','%s',"),m_controlid,label.c_str(),varname.c_str()); | |
779 | while (ReadOrs(tok)) | |
780 | ; | |
92a19c2e | 781 | |
d7e3abf7 WS |
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")); | |
785 | } | |
92a19c2e | 786 | |
d7e3abf7 WS |
787 | if (tok==_T("BS_AUTORADIOBUTTON")) |
788 | { | |
789 | wxFprintf(m_wxr,_T(" control = [%i,wxRadioButton,'%s','0','%s',"),m_controlid,label.c_str(),varname.c_str()); | |
790 | while(ReadOrs(tok)) | |
791 | ; | |
92a19c2e | 792 | |
d7e3abf7 WS |
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")); | |
796 | } | |
88d42654 VS |
797 | } |
798 |