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