]>
Commit | Line | Data |
---|---|---|
2193517f VS |
1 | // rc2xml.cpp: implementation of the rc2xml class. |
2 | //Author: Brian Gavin 9/24/00 | |
3 | //License: wxWindows License | |
4 | /* | |
5 | How to use: | |
6 | #include "rc2xml.h" | |
7 | ... | |
8 | rc2xml trans; | |
9 | trans->Convert("Myfile.rc","Myfile.xml"); | |
10 | */ | |
11 | /* TODO | |
12 | 1. Figure how to fix memory leaks in all wxLists in this class | |
13 | 2. Find a way to rename MS Windows fonts so that they work | |
14 | cross platform (wxGTK,etc) | |
90e572f1 | 15 | 3. Be able to abort incorrectly formatted files without crashing |
2193517f VS |
16 | */ |
17 | ||
88d42654 | 18 | // For compilers that support precompilation, includes "wx/wx.h". |
92a19c2e | 19 | #include "wx/wxprec.h" |
2193517f VS |
20 | |
21 | #ifdef __BORLANDC__ | |
22 | #pragma hdrstop | |
23 | #endif | |
24 | ||
25 | // for all others, include the necessary headers (this file is usually all you | |
be5a51fb | 26 | // need because it includes almost all "standard" wxWidgets headers |
2193517f | 27 | #ifndef WX_PRECOMP |
94dadb0a | 28 | #include "wx/wx.h" |
2193517f VS |
29 | #endif |
30 | ||
88d42654 VS |
31 | |
32 | #include "rc2xml.h" | |
33 | #include "wx/image.h" | |
7c9955d1 JS |
34 | #include "wx/deprecated/setup.h" |
35 | #include "wx/deprecated/resource.h" | |
94dadb0a WS |
36 | #include "wx/textfile.h" |
37 | #include "wx/tokenzr.h" | |
2193517f VS |
38 | |
39 | ||
40 | ||
88d42654 VS |
41 | ////////////////////////////////////////////////////////////////////// |
42 | // Construction/Destruction | |
43 | ////////////////////////////////////////////////////////////////////// | |
44 | ||
2193517f | 45 | rc2xml::rc2xml() |
88d42654 | 46 | { |
f80ea77b | 47 | m_done=false; |
2193517f VS |
48 | m_bitmaplist=new wxList(wxKEY_STRING); |
49 | m_stringtable=new wxList(wxKEY_STRING); | |
50 | m_iconlist = new wxList(wxKEY_STRING); | |
51 | m_resourcelist =new wxList(wxKEY_INTEGER); | |
88d42654 VS |
52 | } |
53 | ||
2193517f | 54 | rc2xml::~rc2xml() |
88d42654 | 55 | { |
2193517f VS |
56 | delete m_bitmaplist; |
57 | delete m_stringtable; | |
58 | delete m_iconlist; | |
59 | delete m_resourcelist; | |
88d42654 VS |
60 | } |
61 | ||
2193517f | 62 | bool rc2xml::Convert(wxString rcfile, wxString xmlfile) |
88d42654 | 63 | { |
2193517f VS |
64 | m_rc.Open(rcfile.c_str()); |
65 | m_filesize=m_rc.Length(); | |
7c9955d1 | 66 | |
92a19c2e | 67 | |
2c99715a | 68 | m_workingpath=wxPathOnly(rcfile); |
92a19c2e | 69 | |
19d0f58d | 70 | m_targetpath=wxPathOnly(xmlfile) + _T("\\"); |
2c99715a | 71 | |
92a19c2e GT |
72 | |
73 | ||
2c99715a VS |
74 | wxSetWorkingDirectory(m_workingpath); |
75 | ||
92a19c2e | 76 | |
2193517f | 77 | bool result; |
19d0f58d JS |
78 | result=m_xmlfile.Open(xmlfile.c_str(),_T("w+t")); |
79 | wxASSERT_MSG(result,_T("Couldn't create XML file")); | |
2193517f | 80 | if (!result) |
f80ea77b | 81 | return false; |
88d42654 | 82 | |
7c9955d1 | 83 | |
88d42654 | 84 | /* Write Basic header for XML file */ |
19d0f58d JS |
85 | m_xmlfile.Write(_T("<?xml version=\"1.0\" ?>\n")); |
86 | m_xmlfile.Write(_T("<resource>\n")); | |
7c9955d1 | 87 | |
2193517f VS |
88 | //Read resource.h |
89 | ParseResourceHeader(); | |
88d42654 | 90 | //Gather all the resource we need for toolbars,menus, and etc |
2193517f | 91 | FirstPass(); |
f80ea77b | 92 | m_done=false; |
2193517f | 93 | m_rc.Seek(0); |
88d42654 | 94 | //Read in dialogs, toolbars,menus |
2193517f | 95 | SecondPass(); |
88d42654 | 96 | |
19d0f58d | 97 | m_xmlfile.Write(_T("</resource>\n")); |
2193517f VS |
98 | m_xmlfile.Close(); |
99 | m_rc.Close(); | |
7c9955d1 | 100 | wxMessageBox(_("Conversion complete."), _("Done"), |
5c8756b0 | 101 | wxOK | wxICON_INFORMATION); |
88d42654 | 102 | |
f80ea77b | 103 | return true; |
88d42654 VS |
104 | } |
105 | ||
106 | ||
2193517f | 107 | void rc2xml::ParseDialog(wxString dlgname) |
88d42654 | 108 | { |
2193517f VS |
109 | wxString token; |
110 | static int dlgid=999; | |
111 | dlgid++; | |
7c9955d1 | 112 | /* Make sure that this really is a dialog |
2193517f VS |
113 | microsoft reuses the keyword DIALOG for other things |
114 | */ | |
115 | token=PeekToken(); | |
116 | //Microsoft notation? | |
19d0f58d JS |
117 | while ((token==_T("DISCARDABLE")) |
118 | ||(token==_T("LOADONCALL"))||(token==_T("MOVEABLE"))) | |
2193517f VS |
119 | { |
120 | token=GetToken(); | |
121 | token=PeekToken(); | |
122 | } | |
123 | //Error isn't a Dialog resource eject eject | |
124 | if (!token.IsNumber()) | |
125 | return; | |
88d42654 VS |
126 | |
127 | //Record x,y,width,height | |
2193517f VS |
128 | int x,y,width,height; |
129 | ReadRect(x,y,width,height); | |
88d42654 | 130 | //Get Title |
2193517f VS |
131 | token=GetToken(); |
132 | wxString title; | |
133 | wxString ptsize,face; | |
7c9955d1 | 134 | |
19d0f58d | 135 | m_xmlfile.Write(_T("\t<object class=\"wxDialog\"")); |
2193517f | 136 | //Avoid duplicate names this way |
19d0f58d | 137 | dlgname.Replace(_T("IDD_"),_T("DLG_")); |
2193517f VS |
138 | WriteBasicInfo(x,y,width,height,dlgname); |
139 | WriteTitle(title); | |
7c9955d1 | 140 | |
2193517f | 141 | |
19d0f58d | 142 | while ((token!=_T("BEGIN"))&(token!=_T("{"))) |
2193517f | 143 | { |
d7e3abf7 | 144 | if (token==_T("CAPTION")) |
2193517f | 145 | { |
d7e3abf7 | 146 | title=GetQuoteField(); |
2193517f VS |
147 | } |
148 | ||
149 | //TODO fix face name so that it is cross platform name | |
150 | // FONT 8, "MS Sans Serif" | |
19d0f58d | 151 | if (token==_T("FONT")) |
d7e3abf7 | 152 | { |
2193517f VS |
153 | ptsize=GetToken(); |
154 | face=GetQuoteField(); | |
19d0f58d JS |
155 | m_xmlfile.Write(_T("\t\t<font>\n")); |
156 | m_xmlfile.Write(_T("\t\t\t<size>")+ptsize+_T("</size>\n")); | |
157 | m_xmlfile.Write(_T("\t\t\t<face>")+face+_T("</face>\n")); | |
158 | m_xmlfile.Write(_T("\t\t</font>\n")); | |
d7e3abf7 | 159 | } |
2193517f VS |
160 | |
161 | token=GetToken(); | |
162 | } | |
88d42654 | 163 | |
2193517f | 164 | ParseControls(); |
19d0f58d | 165 | m_xmlfile.Write(_T("\t</object>\n")); |
88d42654 VS |
166 | } |
167 | ||
168 | /* | |
169 | BEGIN | |
7c9955d1 | 170 | EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT |
88d42654 VS |
171 | WS_TABSTOP |
172 | LTEXT "Bands",IDC_STATIC,11,86,21,8 | |
173 | EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL | |
174 | END | |
175 | */ | |
2193517f | 176 | void rc2xml::ParseControls() |
88d42654 | 177 | { |
2193517f | 178 | wxString token; |
5c8756b0 | 179 | wxString label,varname; |
2193517f VS |
180 | |
181 | token=GetToken(); | |
19d0f58d | 182 | while ((token!=_T("END"))&(token!=_T("}"))) |
2193517f | 183 | { |
19d0f58d | 184 | if (token==_T("AUTOCHECKBOX")) |
5c8756b0 JS |
185 | { |
186 | label=GetQuoteField(); | |
187 | varname=GetToken(); | |
188 | ParseCheckBox(label,varname); | |
189 | } | |
11ad1132 | 190 | else |
19d0f58d | 191 | if (token==_T("AUTORADIOBUTTON")) |
5c8756b0 JS |
192 | { |
193 | label=GetQuoteField(); | |
194 | varname=GetToken(); | |
195 | ParseRadioButton(label,varname); | |
196 | } | |
11ad1132 | 197 | else |
19d0f58d | 198 | if (token==_T("LTEXT")) |
5c8756b0 JS |
199 | { |
200 | label=GetQuoteField(); | |
201 | varname=GetToken(); | |
202 | ParseStaticText(label,varname); | |
203 | } | |
19d0f58d | 204 | else if (token==_T("EDITTEXT")) |
5c8756b0 JS |
205 | { |
206 | varname=GetToken(); | |
207 | ParseTextCtrl(varname); | |
208 | } | |
19d0f58d | 209 | else if ((token==_T("PUSHBUTTON"))||(token==_T("DEFPUSHBUTTON"))) |
5c8756b0 JS |
210 | { |
211 | label=GetQuoteField(); | |
212 | varname=GetToken(); | |
213 | ParsePushButton(label,varname); | |
214 | } | |
19d0f58d | 215 | else if (token==_T("GROUPBOX")) |
5c8756b0 JS |
216 | { |
217 | label=GetQuoteField(); | |
218 | varname=GetToken(); | |
219 | ParseGroupBox(label,varname); | |
220 | } | |
19d0f58d | 221 | else if (token==_T("COMBOBOX")) |
5c8756b0 JS |
222 | { |
223 | varname=GetToken(); | |
224 | ParseComboBox(varname); | |
225 | } | |
19d0f58d | 226 | else if (token==_T("CONTROL")) |
2193517f | 227 | ParseControlMS(); |
19d0f58d | 228 | else if (token==_T("LISTBOX")) |
5c8756b0 JS |
229 | { |
230 | varname=GetToken(); | |
231 | ParseListBox(varname); | |
232 | } | |
19d0f58d | 233 | else if (token==_T("ICON")) |
2193517f | 234 | ParseIconStatic(); |
19d0f58d | 235 | else if (token==_T("SCROLLBAR")) |
2193517f VS |
236 | ParseScrollBar(); |
237 | token=GetToken(); | |
238 | } | |
88d42654 VS |
239 | |
240 | } | |
241 | //LTEXT "Radius",IDC_STATIC,9,67,23,8 | |
5c8756b0 | 242 | void rc2xml::ParseStaticText(wxString phrase, wxString varname) |
88d42654 | 243 | { |
2193517f | 244 | wxString token; |
5c8756b0 JS |
245 | token=PeekToken(); |
246 | while (!token.IsNumber()) | |
247 | { | |
248 | token=GetToken(); | |
249 | token=PeekToken(); | |
250 | } | |
2193517f VS |
251 | int x,y,width,height; |
252 | ReadRect(x,y,width,height); | |
88d42654 | 253 | |
19d0f58d | 254 | m_xmlfile.Write(_T("\t\t<object class=\"wxStaticText\"")); |
2193517f | 255 | WriteBasicInfo(x,y,width,height,varname);WriteLabel(phrase); |
19d0f58d | 256 | m_xmlfile.Write(_T("\t\t</object>\n")); |
88d42654 VS |
257 | |
258 | } | |
259 | //EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL | |
5c8756b0 | 260 | void rc2xml::ParseTextCtrl(wxString varname) |
88d42654 | 261 | { |
2193517f | 262 | wxString token; |
5c8756b0 JS |
263 | wxString style; |
264 | token=PeekToken(); | |
265 | while (!token.IsNumber()) | |
266 | { | |
267 | token=GetToken(); | |
268 | token=PeekToken(); | |
269 | } | |
2193517f VS |
270 | int x,y,width,height; |
271 | ReadRect(x,y,width,height); | |
88d42654 VS |
272 | //TODO |
273 | //style=GetToken(); | |
19d0f58d | 274 | m_xmlfile.Write(_T("\t\t<object class=\"wxTextCtrl\"")); |
2193517f | 275 | WriteBasicInfo(x,y,width,height,varname); |
19d0f58d | 276 | m_xmlfile.Write(_T("\t\t</object>\n")); |
88d42654 VS |
277 | |
278 | } | |
11ad1132 | 279 | //AUTOCHECKBOX "&log.", ID_XLOG, 25, 24, 21, 12 |
5c8756b0 | 280 | void rc2xml::ParseCheckBox(wxString phrase, wxString varname) |
11ad1132 VS |
281 | { |
282 | wxString token; | |
5c8756b0 JS |
283 | token=PeekToken(); |
284 | while (!token.IsNumber()) | |
285 | { | |
286 | token=GetToken(); | |
287 | token=PeekToken(); | |
288 | } | |
11ad1132 VS |
289 | int x,y,width,height; |
290 | ReadRect(x,y,width,height); | |
291 | ||
19d0f58d | 292 | m_xmlfile.Write(_T("\t\t<object class=\"wxCheckBox\"")); |
11ad1132 VS |
293 | WriteBasicInfo(x,y,width,height,varname); |
294 | WriteLabel(phrase); | |
19d0f58d | 295 | m_xmlfile.Write(_T("\t\t</object>\n")); |
11ad1132 VS |
296 | |
297 | } | |
298 | //AUTORADIOBUTTON "&text", ID_SW10, 13, 12, 68, 10, BS_AUTORADIOBUTTON | WS_GROUP | |
5c8756b0 | 299 | void rc2xml::ParseRadioButton(wxString phrase, wxString varname) |
11ad1132 VS |
300 | { |
301 | wxString token,style; | |
11ad1132 | 302 | int x,y,width,height; |
5c8756b0 JS |
303 | bool GotOrs; |
304 | GotOrs = ReadOrs(token); | |
11ad1132 | 305 | if (ReadRect(x,y,width,height)) |
f80ea77b | 306 | if (GotOrs==false) |
11ad1132 | 307 | ReadOrs(token); |
f80ea77b | 308 | if (token.Find(_T("WS_GROUP")) != wxNOT_FOUND) |
19d0f58d | 309 | style += _T("wxRB_GROUP"); |
11ad1132 | 310 | |
19d0f58d | 311 | m_xmlfile.Write(_T("\t\t<object class=\"wxRadioButton\"")); |
11ad1132 VS |
312 | WriteBasicInfo(x,y,width,height,varname); |
313 | WriteLabel(phrase); | |
314 | WriteStyle(style); | |
19d0f58d | 315 | m_xmlfile.Write(_T("\t\t</object>\n")); |
11ad1132 VS |
316 | |
317 | } | |
318 | ||
88d42654 | 319 | //PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP |
5c8756b0 | 320 | void rc2xml::ParsePushButton(wxString phrase, wxString varname) |
88d42654 | 321 | { |
2193517f | 322 | wxString token; |
88d42654 | 323 | |
5c8756b0 JS |
324 | token=PeekToken(); |
325 | while (!token.IsNumber()) | |
326 | { | |
327 | token=GetToken(); | |
328 | token=PeekToken(); | |
329 | } | |
2193517f VS |
330 | int x,y,width,height; |
331 | ReadRect(x,y,width,height); | |
88d42654 | 332 | |
19d0f58d | 333 | m_xmlfile.Write(_T("\t\t<object class=\"wxButton\"")); |
2193517f VS |
334 | WriteBasicInfo(x,y,width,height,varname); |
335 | WriteLabel(phrase); | |
19d0f58d | 336 | m_xmlfile.Write(_T("\t\t</object>\n")); |
88d42654 VS |
337 | |
338 | } | |
339 | ||
340 | ||
3103e8a9 | 341 | bool rc2xml::Separator(int ch) |
88d42654 VS |
342 | { |
343 | //if ((ch==' ')|(ch==',')|(ch==13)|(ch==10)|(ch=='|')|(ch=='\t')) | |
2193517f | 344 | if ((ch==' ')|(ch==',')|(ch==13)|(ch==10)|(ch=='\t')) |
f80ea77b | 345 | return true; |
2193517f VS |
346 | |
347 | if (ch==EOF) | |
d7e3abf7 | 348 | { |
f80ea77b WS |
349 | m_done=true; |
350 | return true; | |
d7e3abf7 | 351 | } |
7c9955d1 | 352 | |
f80ea77b | 353 | return false; |
88d42654 VS |
354 | } |
355 | ||
5c8756b0 | 356 | void rc2xml::ParseGroupBox(wxString phrase, wxString varname) |
88d42654 VS |
357 | { |
358 | // GROUPBOX "Rotate",IDC_STATIC,1,1,71,79 | |
2193517f | 359 | wxString token; |
5c8756b0 JS |
360 | token=PeekToken(); |
361 | while (!token.IsNumber()) | |
362 | { | |
363 | token=GetToken(); | |
364 | token=PeekToken(); | |
365 | } | |
2193517f VS |
366 | int x,y,width,height; |
367 | ReadRect(x,y,width,height); | |
368 | ||
19d0f58d | 369 | m_xmlfile.Write(_T("\t\t<object class=\"wxStaticBox\"")); |
2193517f VS |
370 | WriteBasicInfo(x,y,width,height,varname); |
371 | WriteLabel(phrase); | |
19d0f58d | 372 | m_xmlfile.Write(_T("\t\t</object>\n")); |
88d42654 VS |
373 | } |
374 | ||
11ad1132 | 375 | bool rc2xml::ReadRect(int & x, int & y, int & width, int & height) |
88d42654 | 376 | { |
19d0f58d JS |
377 | x=wxAtoi(GetToken()); |
378 | y=wxAtoi(GetToken()); | |
379 | width=wxAtoi(GetToken()); | |
11ad1132 VS |
380 | bool ret; |
381 | wxString tmp = GetToken(&ret); | |
19d0f58d | 382 | height=wxAtoi(tmp); |
11ad1132 | 383 | return ret; // check for more parameters |
88d42654 VS |
384 | } |
385 | ||
3103e8a9 | 386 | wxString rc2xml::GetToken(bool *listseparator) |
88d42654 | 387 | { |
19d0f58d | 388 | wxString token=wxEmptyString; |
88d42654 | 389 | |
2193517f VS |
390 | if (m_rc.Eof()) |
391 | { | |
f80ea77b | 392 | m_done=true; |
2193517f | 393 | return token; |
88d42654 VS |
394 | } |
395 | ||
2193517f VS |
396 | int ch=0; |
397 | ReadChar(ch); | |
398 | if (ch==EOF) | |
399 | { | |
f80ea77b | 400 | m_done=true; |
2193517f VS |
401 | return token; |
402 | } | |
88d42654 | 403 | |
3103e8a9 | 404 | while (Separator(ch)) |
2193517f VS |
405 | { |
406 | ReadChar(ch); | |
407 | if (m_done) | |
408 | return token; | |
409 | } | |
88d42654 | 410 | |
2193517f VS |
411 | if (ch==EOF) |
412 | { | |
f80ea77b | 413 | m_done=true; |
2193517f | 414 | } |
7c9955d1 | 415 | |
88d42654 | 416 | |
3103e8a9 | 417 | while (!Separator(ch)) |
2193517f | 418 | { |
11ad1132 | 419 | token += (char)ch; |
2193517f VS |
420 | ReadChar(ch); |
421 | } | |
88d42654 | 422 | |
11ad1132 | 423 | if (ch == EOF) |
f80ea77b | 424 | m_done = true; |
88d42654 | 425 | |
3103e8a9 JS |
426 | if (listseparator) |
427 | *listseparator = (ch == ','); | |
2193517f | 428 | return token; |
88d42654 VS |
429 | } |
430 | ||
2193517f | 431 | wxString rc2xml::GetQuoteField() |
88d42654 | 432 | { |
2193517f VS |
433 | wxString phrase; |
434 | //ASCII code 34 " | |
435 | int ch=0; | |
c988c5b2 JS |
436 | int ch1=0; |
437 | ||
2193517f | 438 | ReadChar(ch); |
88d42654 | 439 | |
c988c5b2 JS |
440 | // !! Changed by MS, 15th/11/04. Can now read strings such as |
441 | // """Catapult"" - blah blah", ... | |
442 | ||
2193517f VS |
443 | while (ch!=34) |
444 | ReadChar(ch); | |
7c9955d1 | 445 | |
c988c5b2 JS |
446 | // found first '"' |
447 | while (true) | |
5c8756b0 | 448 | { |
c988c5b2 JS |
449 | ReadChar(ch); |
450 | if (ch == 34) | |
451 | { | |
452 | // another quote? | |
453 | ReadChar(ch1); | |
454 | if (ch1 != 34) | |
455 | { | |
456 | // real end of string.. | |
457 | break; | |
458 | } | |
459 | ||
460 | // add a single quote - fall through | |
461 | } | |
462 | phrase+=(char)ch; | |
5c8756b0 | 463 | } |
c988c5b2 | 464 | |
5c8756b0 JS |
465 | return phrase; |
466 | } | |
467 | ||
468 | // string in stringtable may contain embedded quotes | |
469 | // escape characters retained to allow strings to be rewritten | |
470 | wxString rc2xml::GetStringQuote() | |
471 | { | |
472 | wxString phrase; | |
473 | //ASCII code 34 " | |
f80ea77b | 474 | bool done=false; |
d7e3abf7 | 475 | int ch=0,lastch=0; |
2193517f | 476 | ReadChar(ch); |
88d42654 | 477 | |
2193517f | 478 | while (ch!=34) |
5c8756b0 | 479 | ReadChar(ch); |
d7e3abf7 | 480 | |
5c8756b0 | 481 | ReadChar(ch); |
f80ea77b | 482 | while (done==false) |
d7e3abf7 | 483 | { |
5c8756b0 | 484 | if ((ch==34)&&(lastch!='\\')) |
d7e3abf7 WS |
485 | { |
486 | wxFileOffset p = m_rc.Tell(); | |
5c8756b0 | 487 | ReadChar(ch); |
d7e3abf7 | 488 | // RC supports "", for embedded quote, as well as \" |
7c9955d1 JS |
489 | if (ch==34) |
490 | phrase+='\\'; | |
5c8756b0 | 491 | else |
d7e3abf7 | 492 | { |
5c8756b0 | 493 | m_rc.Seek(p); |
f80ea77b | 494 | done = true; |
5c8756b0 JS |
495 | } |
496 | } | |
f80ea77b | 497 | if (done==true) |
5c8756b0 JS |
498 | break; |
499 | if (ch=='\r') | |
500 | ReadChar(ch); // skip | |
501 | if ((ch=='\n')&&(lastch=='\\')) // lastch <should> be this | |
502 | phrase+='n'; // escape | |
503 | else | |
d7e3abf7 WS |
504 | phrase+=(char)ch; |
505 | ||
5c8756b0 | 506 | lastch=ch; |
d7e3abf7 | 507 | ReadChar(ch); |
2193517f | 508 | } |
5c8756b0 | 509 | |
2193517f | 510 | return phrase; |
88d42654 VS |
511 | } |
512 | ||
2193517f | 513 | void rc2xml::ReadChar(int &ch) |
88d42654 | 514 | { |
d7e3abf7 | 515 | wxFileOffset result = m_rc.Tell(); |
88d42654 | 516 | |
2193517f | 517 | if((result>=m_filesize)) |
f80ea77b | 518 | m_done=true; |
88d42654 | 519 | |
d7e3abf7 | 520 | result = m_rc.Read(&ch,1); |
88d42654 | 521 | |
d7e3abf7 | 522 | if( result == wxInvalidOffset ) |
f80ea77b | 523 | m_done=true; |
88d42654 | 524 | |
2193517f | 525 | if(ch==EOF) |
f80ea77b | 526 | m_done=true; |
88d42654 VS |
527 | } |
528 | ||
5c8756b0 | 529 | void rc2xml::ParseComboBox(wxString varname) |
88d42654 | 530 | { |
7c9955d1 | 531 | /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT | |
88d42654 | 532 | WS_VSCROLL | WS_TABSTOP */ |
11ad1132 | 533 | wxString token,style; |
2193517f | 534 | int x,y,width,height; |
5c8756b0 JS |
535 | bool GotOrs; |
536 | GotOrs = ReadOrs(token); | |
11ad1132 | 537 | if (ReadRect(x,y,width,height)) |
f80ea77b | 538 | if (GotOrs==false) |
11ad1132 | 539 | ReadOrs(token); |
88d42654 | 540 | |
19d0f58d | 541 | m_xmlfile.Write(_T("\t\t<object class=\"wxComboBox\"")); |
2193517f | 542 | WriteBasicInfo(x,y,width,height,varname); |
f80ea77b | 543 | if (token.Find(_T("CBS_SIMPLE")) != wxNOT_FOUND) |
19d0f58d | 544 | WriteStyle(_T("wxCB_SIMPLE")); |
f80ea77b | 545 | if (token.Find(_T("CBS_SORT")) != wxNOT_FOUND) |
19d0f58d | 546 | WriteStyle(_T("wxCB_SORT")); |
f80ea77b | 547 | if (token.Find(_T("CBS_DISABLENOSCROLL")) != wxNOT_FOUND) |
19d0f58d JS |
548 | WriteStyle(_T("wxLB_ALWAYS_SB")); |
549 | m_xmlfile.Write(_T("\n\t\t</object>\n")); | |
88d42654 VS |
550 | |
551 | } | |
552 | ||
2193517f | 553 | void rc2xml::ParseMenu(wxString varname) |
88d42654 | 554 | { |
19d0f58d | 555 | wxString token=wxEmptyString; |
2193517f VS |
556 | |
557 | //Write menubar to xml file | |
19d0f58d | 558 | m_xmlfile.Write(_T("\t<object class=\"wxMenuBar\"")); |
2193517f | 559 | //Avoid duplicate names this way |
19d0f58d | 560 | varname.Replace(_T("IDR_"),_T("MB_")); |
2193517f | 561 | WriteName(varname); |
19d0f58d | 562 | m_xmlfile.Write(_T(">\n")); |
2193517f | 563 | |
19d0f58d | 564 | while ((token!=_T("BEGIN"))&(token!=_T("{"))) |
2193517f VS |
565 | token=GetToken(); |
566 | ||
19d0f58d | 567 | while ((token!=_T("END"))&(token!=_T("}"))) |
2193517f VS |
568 | { |
569 | token=GetToken(); | |
5c8756b0 JS |
570 | token.MakeUpper(); |
571 | ||
19d0f58d | 572 | if (token==_T("POPUP")) |
2193517f VS |
573 | { |
574 | ParsePopupMenu(); | |
575 | } | |
576 | } | |
19d0f58d | 577 | m_xmlfile.Write(_T("\t</object>\n")); |
88d42654 VS |
578 | } |
579 | ||
2193517f | 580 | void rc2xml::ParsePopupMenu() |
88d42654 | 581 | { |
2193517f VS |
582 | static int menucount=0; |
583 | menucount++; | |
584 | wxString token,name,msg,longhelp,tip; | |
585 | token=GetQuoteField(); | |
586 | ||
587 | //Remove \t because it causes problems | |
88d42654 | 588 | |
2193517f VS |
589 | //spot=token.First("\\t"); |
590 | //token=token.Left(spot); | |
88d42654 VS |
591 | |
592 | //Write Menu item | |
593 | //Generate a fake name since RC menus don't have one | |
19d0f58d JS |
594 | name << _T("Menu_") << menucount; |
595 | m_xmlfile.Write(_T("\t\t<object class=\"wxMenu\"")); | |
2193517f | 596 | WriteName(name); |
19d0f58d | 597 | m_xmlfile.Write(_T(">\n")); |
2193517f | 598 | WriteLabel(token); |
2193517f | 599 | |
19d0f58d | 600 | while ((token!=_T("BEGIN"))&(token!=_T("{"))) |
2193517f VS |
601 | token=GetToken(); |
602 | ||
19d0f58d | 603 | while ((token!=_T("END"))&(token!=_T("}"))) |
2193517f VS |
604 | { |
605 | token=GetToken(); | |
5c8756b0 JS |
606 | token.MakeUpper(); |
607 | ||
19d0f58d | 608 | if (token==_T("POPUP")) |
2193517f | 609 | ParsePopupMenu(); |
7c9955d1 | 610 | |
19d0f58d | 611 | if (token==_T("MENUITEM")) |
2193517f VS |
612 | ParseMenuItem(); |
613 | } | |
19d0f58d | 614 | m_xmlfile.Write(_T("\t\t\t</object>\n")); |
88d42654 VS |
615 | } |
616 | ||
2193517f | 617 | wxString rc2xml::PeekToken() |
88d42654 | 618 | { |
656dad21 WS |
619 | wxFileOffset p = m_rc.Tell(); |
620 | wxString token=GetToken(); | |
88d42654 | 621 | |
2193517f VS |
622 | m_rc.Seek(p); |
623 | return token; | |
88d42654 | 624 | } |
656dad21 | 625 | |
88d42654 | 626 | //MS Windows pain in the butt CONTROL |
2193517f | 627 | void rc2xml::ParseControlMS() |
88d42654 | 628 | { |
656dad21 | 629 | wxString token = PeekToken(); |
88d42654 | 630 | |
19d0f58d | 631 | if (token.Contains(_T("\""))) |
2193517f VS |
632 | ParseNormalMSControl(); |
633 | else | |
634 | ParseWeirdMSControl(); | |
88d42654 VS |
635 | } |
636 | ||
7c9955d1 | 637 | /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH | |
88d42654 VS |
638 | TBS_NOTICKS | WS_TABSTOP,52,73,100,15 |
639 | */ | |
640 | ||
19d0f58d | 641 | void rc2xml::ParseSlider(wxString WXUNUSED(label), wxString varname) |
88d42654 | 642 | { |
2193517f VS |
643 | wxString token,style; |
644 | ReadOrs(token); | |
f80ea77b | 645 | if (token.Find(_T("TBS_VERT"))!=wxNOT_FOUND) |
19d0f58d | 646 | style+=_T("wxSL_VERTICAL"); |
2193517f VS |
647 | //MFC RC Default is horizontal |
648 | else | |
19d0f58d | 649 | style+=_T("wxSL_HORIZONTAL"); |
2193517f VS |
650 | |
651 | int x,y,width,height; | |
652 | ReadRect(x,y,width,height); | |
19d0f58d | 653 | m_xmlfile.Write(_T("\t\t<object class=\"wxSlider\"")); |
2193517f VS |
654 | WriteBasicInfo(x,y,width,height,varname); |
655 | WriteStyle(style); | |
19d0f58d | 656 | m_xmlfile.Write(_T("\n\t\t</object>\n")); |
88d42654 VS |
657 | |
658 | } | |
7c9955d1 | 659 | /* |
88d42654 VS |
660 | CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32", |
661 | WS_BORDER,15,52,154,13 | |
662 | */ | |
19d0f58d | 663 | void rc2xml::ParseProgressBar(wxString WXUNUSED(label), wxString varname) |
88d42654 | 664 | { |
2193517f VS |
665 | wxString token,style; |
666 | ReadOrs(token); | |
7c9955d1 | 667 | |
2193517f VS |
668 | int x,y,width,height; |
669 | ReadRect(x,y,width,height); | |
670 | ||
88d42654 | 671 | //Always horizontal in MFC |
19d0f58d | 672 | m_xmlfile.Write(_T("\t\t<object class=\"wxGauge\"")); |
2193517f VS |
673 | WriteBasicInfo(x,y,width,height,varname); |
674 | WriteStyle(style); | |
19d0f58d | 675 | m_xmlfile.Write(_T("\t\t</object>\n")); |
88d42654 VS |
676 | } |
677 | ||
2193517f | 678 | bool rc2xml::ReadOrs(wxString & orstring) |
88d42654 | 679 | { |
2193517f VS |
680 | wxString token; |
681 | ||
682 | token=PeekToken(); | |
683 | if (token.IsNumber()) | |
f80ea77b | 684 | return false; |
2193517f VS |
685 | orstring=GetToken(); |
686 | ||
687 | while(PeekToken()==_T("|")) | |
688 | { | |
7c9955d1 | 689 | //Grab | |
2193517f VS |
690 | orstring+=GetToken(); |
691 | //Grab next token | |
692 | orstring+=GetToken(); | |
693 | } | |
f80ea77b | 694 | return true; |
88d42654 VS |
695 | } |
696 | ||
5c8756b0 | 697 | //Is it a checkbutton or a radiobutton or a pushbutton or a groupbox |
2193517f | 698 | void rc2xml::ParseCtrlButton(wxString label, wxString varname) |
88d42654 | 699 | { |
2193517f | 700 | wxString token; |
656dad21 | 701 | wxFileOffset p = m_rc.Tell(); |
2193517f | 702 | ReadOrs(token); |
5c8756b0 | 703 | m_rc.Seek(p); |
2193517f | 704 | |
f80ea77b | 705 | if (token.Find(_T("BS_AUTOCHECKBOX"))!=wxNOT_FOUND) |
5c8756b0 | 706 | ParseCheckBox(label, varname); |
f80ea77b | 707 | else if ((token.Find(_T("BS_AUTORADIOBUTTON"))!=wxNOT_FOUND)|| |
656dad21 | 708 | (token.Find(_T("BS_RADIOBUTTON"))!=wxNOT_FOUND)) |
5c8756b0 | 709 | ParseRadioButton(label, varname); |
f80ea77b | 710 | else if (token.Find(_T("BS_GROUPBOX"))!=wxNOT_FOUND) |
7c9955d1 | 711 | ParseGroupBox(label, varname); |
f80ea77b WS |
712 | else // if ((token.Find("BS_PUSHBUTTON")!=wxNOT_FOUND)|| |
713 | // (token.Find("BS_DEFPUSHBUTTON")!=wxNOT_FOUND)) | |
5c8756b0 | 714 | ParsePushButton(label, varname); // make default case |
88d42654 VS |
715 | } |
716 | ||
2193517f | 717 | void rc2xml::WriteSize(int width, int height) |
88d42654 | 718 | { |
2193517f | 719 | wxString msg; |
19d0f58d | 720 | msg << _T(" <size>") << width << _T(",") << height << _T("d</size>"); |
2193517f | 721 | m_xmlfile.Write(msg); |
88d42654 VS |
722 | } |
723 | ||
2193517f | 724 | void rc2xml::WritePosition(int x, int y) |
88d42654 | 725 | { |
2193517f | 726 | wxString msg; |
19d0f58d | 727 | msg << _T(" <pos>") << x << _T(",") << y << _T("d</pos>"); |
2193517f | 728 | m_xmlfile.Write(msg); |
88d42654 VS |
729 | } |
730 | ||
2193517f | 731 | void rc2xml::WriteTitle(wxString title) |
88d42654 | 732 | { |
2193517f | 733 | wxString msg; |
19d0f58d | 734 | msg=_T("\t\t<title>")+title+_T("</title>\n"); |
2193517f | 735 | m_xmlfile.Write(msg); |
88d42654 VS |
736 | } |
737 | ||
2193517f | 738 | void rc2xml::WriteName(wxString name) |
88d42654 | 739 | { |
7c9955d1 | 740 | |
2193517f VS |
741 | //Try to convert any number ids into names |
742 | name=LookUpId(name); | |
be5a51fb | 743 | //Replace common MS ids with wxWidgets ids |
88d42654 | 744 | //I didn't do everyone of them |
19d0f58d JS |
745 | if (name==_T("IDOK")) |
746 | name=_T("wxID_OK"); | |
747 | else if (name==_T("IDCANCEL")) | |
748 | name=_T("wxID_CANCEL"); | |
749 | else if (name==_T("IDAPPLY")) | |
750 | name=_T("wxID_APPLY"); | |
751 | else if (name==_T("ID_FILE_OPEN")) | |
752 | name=_T("wxID_OPEN"); | |
753 | else if (name==_T("ID_FILE_CLOSE")) | |
754 | name=_T("wxID_CLOSE"); | |
755 | else if (name==_T("ID_FILE_SAVE")) | |
756 | name=_T("wxID_SAVE"); | |
757 | else if (name==_T("ID_FILE_SAVE_AS")) | |
758 | name=_T("wxID_SAVEAS"); | |
759 | else if (name==_T("ID_APP_EXIT")) | |
760 | name=_T("wxID_EXIT"); | |
761 | else if (name==_T("ID_FILE_PRINT")) | |
762 | name=_T("wxID_PRINT"); | |
763 | else if (name==_T("ID_FILE_PRINT_PREVIEW")) | |
764 | name=_T("wxID_PREVIEW"); | |
765 | else if (name==_T("ID_FILE_PRINT_SETUP")) | |
766 | name=_T("wxID_PRINT_SETUP"); | |
767 | else if (name==_T("ID_APP_ABOUT")) | |
768 | name=_T("wxID_ABOUT"); | |
769 | else if (name==_T("ID_EDIT_UNDO")) | |
770 | name=_T("wxID_UNDO"); | |
771 | else if (name==_T("ID_EDIT_CUT")) | |
772 | name=_T("wxID_CUT"); | |
773 | else if (name==_T("ID_EDIT_COPY")) | |
774 | name=_T("wxID_COPY"); | |
775 | else if (name==_T("ID_EDIT_PASTE")) | |
776 | name=_T("wxID_PASTE"); | |
777 | else if (name==_T("IDYES")) | |
778 | name=_T("wxID_YES"); | |
779 | else if (name==_T("IDNO")) | |
780 | name=_T("wxID_NO"); | |
781 | else if (name==_T("IDHELP")) | |
782 | name=_T("wxID_HELP"); | |
783 | ||
784 | m_xmlfile.Write(_T(" name= \"")+name+_T("\"")); | |
88d42654 VS |
785 | } |
786 | ||
2193517f | 787 | void rc2xml::WriteLabel(wxString label) |
88d42654 | 788 | { |
19d0f58d | 789 | label.Replace(_T("&"),_T("$")); |
c988c5b2 | 790 | // changes by MS, handle '<' '>' characters within a label. |
b0e43baf WS |
791 | label.Replace(_T("<"),_T("<")); |
792 | label.Replace(_T(">"),_T(">")); | |
19d0f58d | 793 | m_xmlfile.Write(_T("\t\t\t<label>")+label+_T("</label>\n")); |
88d42654 VS |
794 | } |
795 | ||
2193517f | 796 | void rc2xml::WriteBasicInfo(int x, int y, int width, int height, wxString name) |
88d42654 | 797 | { |
2193517f | 798 | WriteName(name); |
19d0f58d JS |
799 | m_xmlfile.Write(_T(">\n")); |
800 | m_xmlfile.Write(_T("\t\t\t")); | |
2193517f VS |
801 | WritePosition(x,y); |
802 | WriteSize(width,height); | |
19d0f58d | 803 | m_xmlfile.Write(_T("\n")); |
88d42654 VS |
804 | } |
805 | ||
2193517f | 806 | void rc2xml::WriteStyle(wxString style) |
88d42654 | 807 | { |
2193517f VS |
808 | if (style.Length()==0) |
809 | return; | |
19d0f58d | 810 | m_xmlfile.Write(_T("\t\t\t<style>")+style+_T("</style>\n")); |
88d42654 VS |
811 | } |
812 | /* | |
7c9955d1 | 813 | LISTBOX IDC_LIST1,16,89,48,40,LBS_SORT | LBS_MULTIPLESEL | |
88d42654 VS |
814 | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP |
815 | */ | |
5c8756b0 | 816 | void rc2xml::ParseListBox(wxString varname) |
88d42654 | 817 | { |
2193517f | 818 | wxString token; |
5c8756b0 JS |
819 | token=PeekToken(); |
820 | while (!token.IsNumber()) | |
821 | { | |
822 | token=GetToken(); | |
823 | token=PeekToken(); | |
824 | } | |
2193517f VS |
825 | int x,y,width,height; |
826 | ReadRect(x,y,width,height); | |
88d42654 | 827 | |
19d0f58d | 828 | m_xmlfile.Write(_T("\t\t<object class=\"wxListBox\"")); |
2193517f | 829 | WriteBasicInfo(x,y,width,height,varname); |
19d0f58d | 830 | m_xmlfile.Write(_T("\n\t\t</object>\n")); |
88d42654 VS |
831 | |
832 | } | |
833 | /* | |
7c9955d1 | 834 | CONTROL "",IDC_RICHEDIT1,"RICHEDIT",ES_AUTOHSCROLL | WS_BORDER | |
88d42654 VS |
835 | WS_TABSTOP,103,110,40,14 |
836 | */ | |
8b523dc5 | 837 | void rc2xml::ParseRichEdit(wxString WXUNUSED(label), wxString varname) |
88d42654 | 838 | { |
2193517f VS |
839 | wxString token; |
840 | //while (ReadOrs(token)); | |
841 | ReadOrs(token); | |
842 | int x,y,width,height; | |
843 | ReadRect(x,y,width,height); | |
844 | wxString style; | |
88d42654 | 845 | //Make it a rich text control |
19d0f58d JS |
846 | style+=_T("wxTE_MULTILINE "); |
847 | m_xmlfile.Write(_T("\t\t<object class=\"wxTextCtrl\"")); | |
2193517f VS |
848 | WriteBasicInfo(x,y,width,height,varname); |
849 | WriteStyle(style); | |
19d0f58d | 850 | m_xmlfile.Write(_T("\t\t</object>\n")); |
88d42654 VS |
851 | |
852 | } | |
853 | /* | |
854 | CONTROL "Spin1",IDC_SPIN1,"msctls_updown32",UDS_ARROWKEYS,209,72, | |
855 | 19,26 | |
856 | */ | |
19d0f58d | 857 | void rc2xml::ParseSpinCtrl(wxString WXUNUSED(label), wxString varname) |
88d42654 | 858 | { |
2193517f | 859 | wxString token,style; |
7c9955d1 | 860 | |
2193517f | 861 | ReadOrs(token); |
f80ea77b | 862 | if (token.Find(_T("UDS_HORZ"))!=wxNOT_FOUND) |
19d0f58d | 863 | style=_T("wxSP_HORIZONTAL"); |
2193517f VS |
864 | //MFC default |
865 | else | |
19d0f58d | 866 | style=_T("wxSP_VERTICAL"); |
2193517f VS |
867 | |
868 | int x,y,width,height; | |
869 | ReadRect(x,y,width,height); | |
19d0f58d | 870 | m_xmlfile.Write(_T("\t\t<object class=\"wxSpinButton\"")); |
2193517f VS |
871 | WriteBasicInfo(x,y,width,height,varname); |
872 | WriteStyle(style); | |
19d0f58d | 873 | m_xmlfile.Write(_T("\n\t\t</object>\n")); |
88d42654 VS |
874 | |
875 | } | |
876 | ||
2193517f | 877 | void rc2xml::FirstPass() |
88d42654 | 878 | { |
2193517f VS |
879 | wxString token,prevtok; |
880 | while (!m_done) | |
881 | { | |
882 | token=GetToken(); | |
19d0f58d | 883 | if (token==_T("BITMAP")) |
2193517f | 884 | ParseBitmap(prevtok); |
19d0f58d | 885 | else if (token==_T("STRINGTABLE")) |
2193517f | 886 | ParseStringTable(prevtok); |
19d0f58d | 887 | else if (token==_T("ICON")) |
2193517f | 888 | ParseIcon(prevtok); |
7c9955d1 | 889 | |
2193517f VS |
890 | prevtok=token; |
891 | } | |
88d42654 VS |
892 | } |
893 | ||
2193517f | 894 | void rc2xml::ParseBitmap(wxString varname) |
88d42654 | 895 | { |
19311d4e WS |
896 | wxString token; |
897 | wxString *bitmapfile; | |
7c9955d1 | 898 | |
2193517f VS |
899 | token=PeekToken(); |
900 | //Microsoft notation? | |
19d0f58d | 901 | if (token==_T("DISCARDABLE")) |
2193517f VS |
902 | { |
903 | token=GetToken(); | |
904 | token=PeekToken(); | |
905 | } | |
906 | bitmapfile=new wxString; | |
907 | *bitmapfile=GetQuoteField(); | |
908 | m_bitmaplist->Append(varname,bitmapfile); | |
88d42654 VS |
909 | |
910 | } | |
911 | ||
912 | ||
2193517f | 913 | void rc2xml::SecondPass() |
88d42654 | 914 | { |
2193517f VS |
915 | wxString token,prevtok; |
916 | while (!m_done) | |
917 | { | |
918 | token=GetToken(); | |
19d0f58d | 919 | if ((token==_T("DIALOG"))||(token==_T("DIALOGEX"))) |
2193517f | 920 | ParseDialog(prevtok); |
19d0f58d | 921 | else if (token==_T("MENU")) |
2193517f | 922 | ParseMenu(prevtok); |
19d0f58d | 923 | else if (token==_T("TOOLBAR")) |
2193517f | 924 | ParseToolBar(prevtok); |
7c9955d1 | 925 | |
2193517f VS |
926 | prevtok=token; |
927 | } | |
88d42654 VS |
928 | |
929 | } | |
930 | ||
2193517f | 931 | void rc2xml::ParseToolBar(wxString varname) |
88d42654 | 932 | { |
7c9955d1 | 933 | wxString token; |
2193517f | 934 | token=GetToken(); |
19d0f58d | 935 | wxASSERT_MSG(token==_T("DISCARDABLE"),_T("Error in toolbar parsing")); |
88d42654 | 936 | //Look up bitmap for toolbar and load |
2193517f VS |
937 | wxNode *node=m_bitmaplist->Find(LookUpId(varname)); |
938 | wxString *bitmappath; | |
19d0f58d | 939 | bitmappath=(wxString *)node->GetData(); |
2193517f VS |
940 | wxBitmap bitmap; |
941 | if (!bitmap.LoadFile(*bitmappath,wxBITMAP_TYPE_BMP )) | |
19d0f58d | 942 | wxLogError(_T("Unable to load bitmap:")+*bitmappath); |
88d42654 VS |
943 | |
944 | //Write toolbar to xml file | |
f80ea77b | 945 | m_xmlfile.Write(_T("\t<object class=\"wxToolBar\"")); |
88d42654 | 946 | //Avoid duplicate names this way |
19d0f58d | 947 | varname.Replace(_T("IDR_"),_T("TB_")); |
2193517f | 948 | WriteName(varname); |
19d0f58d | 949 | m_xmlfile.Write(_T(">\n")); |
2193517f | 950 | wxString style; |
19d0f58d | 951 | style+=_T("wxTB_FLAT"); |
2193517f | 952 | WriteStyle(style); |
88d42654 | 953 | |
88d42654 VS |
954 | |
955 | //Grab width and height | |
2193517f | 956 | int width,height; |
19d0f58d JS |
957 | width=wxAtoi(GetToken()); |
958 | height=wxAtoi(GetToken()); | |
2193517f | 959 | |
7c9955d1 | 960 | int c=0; |
2193517f VS |
961 | wxString buttonname,msg,tip,longhelp; |
962 | token=GetToken(); | |
19d0f58d | 963 | while ((token!=_T("BEGIN"))&(token!=_T("{"))) |
2193517f VS |
964 | token=GetToken(); |
965 | ||
19d0f58d | 966 | while ((token!=_T("END"))&(token!=_T("}"))) |
2193517f | 967 | { |
19d0f58d | 968 | if (token==_T("BUTTON")) |
2193517f VS |
969 | { |
970 | buttonname=GetToken(); | |
19d0f58d | 971 | m_xmlfile.Write(_T("\t\t\t<object class=\"tool\"")); |
2193517f | 972 | WriteName(buttonname); |
19d0f58d | 973 | m_xmlfile.Write(_T(">\n")); |
2193517f VS |
974 | //Write tool tip if any |
975 | if (LookUpString(buttonname,msg)) | |
976 | { | |
977 | SplitHelp(msg,tip,longhelp); | |
19d0f58d | 978 | m_xmlfile.Write(_T("\t\t\t\t<tooltip>")+tip+_T("</tooltip>\n")); |
f80ea77b | 979 | m_xmlfile.Write(_T("\t\t<longhelp>")+longhelp+_T("</longhelp>\n")); |
2193517f VS |
980 | } |
981 | //Make a bitmap file name | |
982 | buttonname=CleanName(buttonname); | |
19d0f58d JS |
983 | buttonname+=_T(".bmp"); |
984 | m_xmlfile.Write(_T("\t\t\t\t<bitmap>")+buttonname+_T("</bitmap>\n")); | |
2193517f | 985 | WriteToolButton(buttonname,c,width,height,bitmap); |
19d0f58d | 986 | m_xmlfile.Write(_T("\t\t\t</object>\n")); |
2193517f VS |
987 | c++; |
988 | } | |
19d0f58d | 989 | else if (token==_T("SEPARATOR")) |
2193517f | 990 | { |
19d0f58d | 991 | m_xmlfile.Write(_T("\t\t\t<object class=\"separator\"/>\n")); |
2193517f VS |
992 | } |
993 | token=GetToken(); | |
994 | } | |
19d0f58d | 995 | m_xmlfile.Write(_T("\t</object>\n")); |
88d42654 VS |
996 | } |
997 | ||
998 | //Extract bitmaps from larger toolbar bitmap | |
2193517f | 999 | void rc2xml::WriteToolButton(wxString name,int index, int width, int height, wxBitmap bitmap) |
88d42654 | 1000 | { |
2193517f VS |
1001 | int x; |
1002 | x=index*width; | |
1003 | wxRect r(x,0,width,height); | |
1004 | wxBitmap little; | |
1005 | little=bitmap.GetSubBitmap(r); | |
2c99715a | 1006 | little.SaveFile(m_targetpath+name,wxBITMAP_TYPE_BMP); |
88d42654 VS |
1007 | } |
1008 | ||
8b523dc5 | 1009 | void rc2xml::ParseStringTable(wxString WXUNUSED(varname)) |
88d42654 | 1010 | { |
2193517f VS |
1011 | wxString token; |
1012 | token=GetToken(); | |
19d0f58d | 1013 | while ((token!=_T("BEGIN"))&(token!=_T("{"))) |
2193517f VS |
1014 | token=GetToken(); |
1015 | token=GetToken(); | |
1016 | wxString *msg; | |
1017 | ||
19d0f58d | 1018 | while ((token!=_T("END"))&(token!=_T("}"))) |
8b523dc5 | 1019 | { |
2193517f | 1020 | msg=new wxString; |
5c8756b0 | 1021 | *msg=GetStringQuote(); |
2193517f VS |
1022 | m_stringtable->Append(token,msg); |
1023 | token=GetToken(); | |
8b523dc5 | 1024 | } |
88d42654 VS |
1025 | } |
1026 | ||
2193517f | 1027 | bool rc2xml::LookUpString(wxString strid,wxString & st) |
88d42654 | 1028 | { |
2193517f VS |
1029 | wxNode *node=m_stringtable->Find(strid); |
1030 | wxString *s; | |
1031 | if (node==NULL) | |
f80ea77b | 1032 | return false; |
88d42654 | 1033 | |
19d0f58d | 1034 | s=(wxString *)node->GetData(); |
2193517f | 1035 | st=*s; |
88d42654 | 1036 | |
f80ea77b | 1037 | return true; |
88d42654 VS |
1038 | } |
1039 | ||
2193517f | 1040 | bool rc2xml::SplitHelp(wxString msg, wxString &shorthelp, wxString &longhelp) |
88d42654 | 1041 | { |
2193517f | 1042 | int spot; |
19d0f58d | 1043 | spot=msg.Find(_T("\\n")); |
f80ea77b | 1044 | if (spot==wxNOT_FOUND) |
2193517f VS |
1045 | { |
1046 | shorthelp=msg; | |
1047 | longhelp=msg; | |
1048 | } | |
1049 | ||
1050 | longhelp=msg.Left(spot); | |
1051 | spot=msg.Length()-spot-2; | |
1052 | shorthelp=msg.Right(spot); | |
f80ea77b | 1053 | return true; |
88d42654 VS |
1054 | } |
1055 | ||
2193517f | 1056 | void rc2xml::ParseMenuItem() |
88d42654 | 1057 | { |
2193517f VS |
1058 | wxString token,name,msg,tip,longhelp; |
1059 | //int spot; | |
19d0f58d | 1060 | if (PeekToken()==_T("SEPARATOR")) |
2193517f | 1061 | { |
19d0f58d | 1062 | m_xmlfile.Write(_T("\t\t\t<object class=\"separator\"/>\n")); |
2193517f VS |
1063 | return; |
1064 | } | |
1065 | ||
1066 | token=GetQuoteField(); | |
1067 | name=GetToken(); | |
1068 | //Remove \t because it causes problems | |
1069 | //spot=token.First("\\t"); | |
1070 | //token=token.Left(spot); | |
19d0f58d | 1071 | m_xmlfile.Write(_T("\t\t\t<object class=\"wxMenuItem\"")); |
2193517f | 1072 | WriteName(name); |
19d0f58d | 1073 | m_xmlfile.Write(_T(">\n")); |
2193517f | 1074 | WriteLabel(token); |
88d42654 | 1075 | //Look up help if any listed in stringtable |
5c8756b0 | 1076 | //can't assume numbers correlate, restrict to string identifiers |
7c9955d1 | 1077 | if ((!name.IsNumber())&&(LookUpString(name,msg))) |
2193517f VS |
1078 | { |
1079 | SplitHelp(msg,tip,longhelp); | |
19d0f58d JS |
1080 | m_xmlfile.Write(_T("\t\t\t<help>") |
1081 | +longhelp+_T("</help>\n")); | |
2193517f | 1082 | } |
88d42654 | 1083 | //look for extra attributes like checked and break |
2193517f VS |
1084 | wxString ptoken; |
1085 | ptoken=PeekToken(); | |
5c8756b0 | 1086 | ptoken.MakeUpper(); |
19d0f58d | 1087 | while ((ptoken!=_T("MENUITEM"))&(ptoken!=_T("POPUP"))&(ptoken!=_T("END"))) |
2193517f VS |
1088 | { |
1089 | token=GetToken(); | |
5c8756b0 | 1090 | ptoken.MakeUpper(); |
19d0f58d JS |
1091 | if (token==_T("CHECKED")) |
1092 | m_xmlfile.Write(_T("\t\t\t<checkable>1</checkable>\n")); | |
b2247ee9 CE |
1093 | else if (token==_T("MENUBREAK")) |
1094 | ; | |
2193517f | 1095 | //m_xmlfile.Write("\t\t\t</break>\n"); |
b2247ee9 CE |
1096 | else if (token==_T("GRAYED")) |
1097 | ; | |
2193517f | 1098 | else |
19d0f58d | 1099 | wxLogError(_T("Unknown Menu Item token:")+token); |
7c9955d1 | 1100 | |
2193517f | 1101 | ptoken=PeekToken(); |
5c8756b0 | 1102 | ptoken.MakeUpper(); |
2193517f | 1103 | } |
19d0f58d | 1104 | m_xmlfile.Write(_T("\t\t\t</object>\n")); |
88d42654 VS |
1105 | |
1106 | } | |
1107 | ||
1108 | //ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20 | |
2193517f | 1109 | void rc2xml::ParseIconStatic() |
88d42654 | 1110 | { |
2193517f VS |
1111 | wxString token; |
1112 | wxString varname,iconname; | |
5c8756b0 | 1113 | token = PeekToken(); |
19d0f58d | 1114 | if (token.Contains(_T("\""))) |
5c8756b0 JS |
1115 | iconname = GetQuoteField(); |
1116 | else | |
2193517f | 1117 | iconname=GetToken(); |
88d42654 | 1118 | //Look up icon |
2193517f | 1119 | varname=GetToken(); |
88d42654 | 1120 | |
2193517f VS |
1121 | int x,y,width,height; |
1122 | ReadRect(x,y,width,height); | |
88d42654 | 1123 | |
19d0f58d | 1124 | m_xmlfile.Write(_T("\t\t<object class=\"wxStaticBitmap\"")); |
2193517f | 1125 | WriteBasicInfo(x,y,width,height,varname); |
88d42654 | 1126 | //Save icon as a bitmap |
2193517f | 1127 | WriteIcon(iconname); |
19d0f58d | 1128 | m_xmlfile.Write(_T("\t\t</object>\n")); |
88d42654 VS |
1129 | |
1130 | } | |
1131 | //IDR_MAINFRAME ICON DISCARDABLE "res\\mfcexample.ico" | |
2193517f | 1132 | void rc2xml::ParseIcon(wxString varname) |
88d42654 | 1133 | { |
19311d4e WS |
1134 | wxString token; |
1135 | wxString *iconfile; | |
2193517f VS |
1136 | iconfile=new wxString; |
1137 | token=PeekToken(); | |
88d42654 | 1138 | |
2193517f VS |
1139 | *iconfile=GetQuoteField(); |
1140 | m_iconlist->Append(varname,iconfile); | |
7c9955d1 | 1141 | |
88d42654 VS |
1142 | |
1143 | } | |
1144 | ||
2193517f | 1145 | wxString rc2xml::CleanName(wxString name) |
88d42654 | 1146 | { |
2193517f | 1147 | name.MakeLower(); |
19d0f58d JS |
1148 | name.Replace(_T("id_"),wxEmptyString); |
1149 | name.Replace(_T("idr_"),wxEmptyString); | |
1150 | name.Replace(_T("idb_"),wxEmptyString); | |
1151 | name.Replace(_T("idc_"),wxEmptyString); | |
92a19c2e | 1152 | |
19d0f58d | 1153 | name.Replace(_T(".ico"),wxEmptyString); |
92a19c2e | 1154 | |
19d0f58d | 1155 | name.Replace(_T(".bmp"),wxEmptyString); |
2193517f | 1156 | return name; |
88d42654 VS |
1157 | } |
1158 | // And the award for most messed up control goes to... | |
1159 | // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30 | |
2193517f | 1160 | void rc2xml::ParseStaticBitmap(wxString bitmapname, wxString varname) |
88d42654 | 1161 | { |
2193517f VS |
1162 | wxString token; |
1163 | //Grab SS_BITMAP | |
5c8756b0 | 1164 | ReadOrs(token); |
88d42654 | 1165 | |
88d42654 | 1166 | |
2193517f VS |
1167 | int x,y,width,height; |
1168 | ReadRect(x,y,width,height); | |
1169 | ||
19d0f58d | 1170 | m_xmlfile.Write(_T("\t\t<object class=\"wxStaticBitmap\"")); |
2193517f VS |
1171 | WriteBasicInfo(x,y,width,height,varname); |
1172 | WriteBitmap(bitmapname); | |
19d0f58d | 1173 | m_xmlfile.Write(_T("\t\t</object>\n")); |
88d42654 VS |
1174 | |
1175 | } | |
1176 | ||
2193517f | 1177 | void rc2xml::ParseNormalMSControl() |
88d42654 | 1178 | { |
656dad21 WS |
1179 | wxString label=GetQuoteField(); |
1180 | wxString varname=GetToken(); | |
1181 | wxString kindctrl=GetQuoteField(); | |
1182 | kindctrl.MakeUpper(); | |
88d42654 | 1183 | |
19d0f58d | 1184 | if (kindctrl==_T("MSCTLS_UPDOWN32")) |
2193517f | 1185 | ParseSpinCtrl(label,varname); |
656dad21 | 1186 | else if (kindctrl==_T("MSCTLS_TRACKBAR32")) |
2193517f | 1187 | ParseSlider(label,varname); |
656dad21 | 1188 | else if (kindctrl==_T("MSCTLS_PROGRESS32")) |
2193517f | 1189 | ParseProgressBar(label,varname); |
656dad21 | 1190 | else if (kindctrl==_T("SYSTREEVIEW32")) |
2193517f | 1191 | ParseTreeCtrl(label,varname); |
656dad21 | 1192 | else if (kindctrl==_T("SYSMONTHCAL32")) |
2193517f | 1193 | ParseCalendar(label,varname); |
656dad21 | 1194 | else if (kindctrl==_T("SYSLISTVIEW32")) |
2193517f | 1195 | ParseListCtrl(label,varname); |
656dad21 | 1196 | else if (kindctrl==_T("BUTTON")) |
2193517f | 1197 | ParseCtrlButton(label,varname); |
656dad21 | 1198 | else if (kindctrl==_T("RICHEDIT")) |
2193517f | 1199 | ParseRichEdit(label,varname); |
656dad21 WS |
1200 | else if (kindctrl==_T("STATIC")) |
1201 | { | |
5c8756b0 | 1202 | wxString token; |
656dad21 | 1203 | wxFileOffset p = m_rc.Tell(); |
5c8756b0 JS |
1204 | ReadOrs(token); |
1205 | m_rc.Seek(p); | |
f80ea77b | 1206 | if (token.Find(_T("SS_BITMAP"))!=wxNOT_FOUND) |
5c8756b0 JS |
1207 | ParseStaticBitmap(label,varname); |
1208 | else | |
1209 | ParseStaticText(label,varname); | |
656dad21 WS |
1210 | } |
1211 | else if (kindctrl==_T("EDIT")) | |
5c8756b0 | 1212 | ParseTextCtrl(varname); |
656dad21 | 1213 | else if (kindctrl==_T("LISTBOX")) |
5c8756b0 | 1214 | ParseListBox(varname); |
656dad21 | 1215 | else if (kindctrl==_T("COMBOBOX")) |
5c8756b0 | 1216 | ParseComboBox(varname); |
88d42654 VS |
1217 | } |
1218 | ||
2193517f | 1219 | void rc2xml::ParseWeirdMSControl() |
88d42654 | 1220 | { |
656dad21 WS |
1221 | wxString id = GetToken(); |
1222 | wxString varname = GetToken(); | |
1223 | wxString kindctrl = GetQuoteField(); | |
2193517f | 1224 | kindctrl.MakeUpper(); |
88d42654 | 1225 | // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30 |
19d0f58d | 1226 | if (kindctrl==_T("STATIC")) |
656dad21 | 1227 | { |
19d0f58d | 1228 | if (PeekToken()==_T("SS_BITMAP")) |
2193517f VS |
1229 | ParseStaticBitmap(id,varname); |
1230 | else | |
19d0f58d | 1231 | wxLogError(_T("Unknown MS Control Static token")); |
656dad21 | 1232 | } |
88d42654 | 1233 | } |
88d42654 | 1234 | |
656dad21 | 1235 | //SCROLLBAR IDC_SCROLLBAR1,219,56,10,40,SBS_VERT |
2193517f | 1236 | void rc2xml::ParseScrollBar() |
88d42654 | 1237 | { |
2193517f VS |
1238 | wxString token; |
1239 | wxString varname; | |
1240 | ||
1241 | varname=GetToken(); | |
1242 | int x,y,width,height; | |
1243 | ReadRect(x,y,width,height); | |
1244 | wxString style; | |
1245 | ||
1246 | ReadOrs(token); | |
7c9955d1 | 1247 | |
f80ea77b | 1248 | if (token.Find(_T("SBS_VERT"))!=wxNOT_FOUND) |
2193517f | 1249 | style=_T("wxSB_VERTICAL"); |
88d42654 | 1250 | //Default MFC style is horizontal |
2193517f VS |
1251 | else |
1252 | style=_T("wxSB_HORIZONTAL"); | |
88d42654 | 1253 | |
19d0f58d | 1254 | m_xmlfile.Write(_T("\t\t<object class=\"wxScrollBar\"")); |
2193517f VS |
1255 | WriteBasicInfo(x,y,width,height,varname); |
1256 | WriteStyle(style); | |
19d0f58d | 1257 | m_xmlfile.Write(_T("\n\t\t</object>\n")); |
88d42654 VS |
1258 | |
1259 | } | |
1260 | // CONTROL "Tree1",IDC_TREE1,"SysTreeView32",WS_BORDER | WS_TABSTOP, | |
1261 | // 7,7,66,61 | |
1262 | ||
19d0f58d | 1263 | void rc2xml::ParseTreeCtrl(wxString WXUNUSED(label), wxString varname) |
88d42654 | 1264 | { |
2193517f VS |
1265 | wxString token; |
1266 | //while (ReadOrs(token)); | |
1267 | ReadOrs(token); | |
1268 | int x,y,width,height; | |
1269 | ReadRect(x,y,width,height); | |
19d0f58d | 1270 | m_xmlfile.Write(_T("\t\t<object class=\"wxTreeCtrl\"")); |
2193517f | 1271 | WriteBasicInfo(x,y,width,height,varname); |
19d0f58d | 1272 | m_xmlfile.Write(_T("\t\t</object>\n")); |
88d42654 VS |
1273 | |
1274 | } | |
1275 | // CONTROL "MonthCalendar1",IDC_MONTHCALENDAR1,"SysMonthCal32", | |
1276 | //MCS_NOTODAY | WS_TABSTOP,105,71,129,89 | |
1277 | ||
19d0f58d | 1278 | void rc2xml::ParseCalendar(wxString WXUNUSED(label), wxString varname) |
88d42654 | 1279 | { |
2193517f VS |
1280 | wxString token; |
1281 | //while (ReadOrs(token)); | |
1282 | ReadOrs(token); | |
1283 | int x,y,width,height; | |
1284 | ReadRect(x,y,width,height); | |
19d0f58d | 1285 | m_xmlfile.Write(_T("\t\t<object class=\"wxCalendarCtrl\"")); |
2193517f | 1286 | WriteBasicInfo(x,y,width,height,varname); |
19d0f58d | 1287 | m_xmlfile.Write(_T("\t\t</object>\n")); |
88d42654 VS |
1288 | } |
1289 | // CONTROL "List1",IDC_LIST1,"SysListView32",WS_BORDER | WS_TABSTOP, | |
1290 | // 7,89,68,71 | |
1291 | ||
19d0f58d | 1292 | void rc2xml::ParseListCtrl(wxString WXUNUSED(label), wxString varname) |
88d42654 | 1293 | { |
2193517f VS |
1294 | wxString token; |
1295 | //while (ReadOrs(token)); | |
1296 | ReadOrs(token); | |
1297 | int x,y,width,height; | |
1298 | ReadRect(x,y,width,height); | |
19d0f58d | 1299 | m_xmlfile.Write(_T("\t\t<object class=\"wxListCtrl\"")); |
2193517f | 1300 | WriteBasicInfo(x,y,width,height,varname); |
19d0f58d | 1301 | m_xmlfile.Write(_T("\t\t</object>\n")); |
88d42654 VS |
1302 | |
1303 | } | |
2193517f VS |
1304 | |
1305 | void rc2xml::WriteBitmap(wxString bitmapname) | |
1306 | { | |
1307 | //Look up bitmap | |
1308 | wxNode *node=m_bitmaplist->Find(LookUpId(bitmapname)); | |
1309 | if (node==NULL) | |
1310 | { | |
19d0f58d JS |
1311 | m_xmlfile.Write(_T("\t\t\t<bitmap>missingfile</bitmap>\n")); |
1312 | wxLogError(_T("Unable to find bitmap:")+bitmapname); | |
2193517f VS |
1313 | return; |
1314 | } | |
7c9955d1 | 1315 | |
2193517f | 1316 | wxString *bitmappath; |
19d0f58d | 1317 | bitmappath=(wxString *)node->GetData(); |
92a19c2e | 1318 | |
2c99715a | 1319 | bitmapname=wxFileNameFromPath(*bitmappath); |
2193517f VS |
1320 | wxBitmap bitmap; |
1321 | if (!bitmap.LoadFile(*bitmappath,wxBITMAP_TYPE_BMP )) | |
19d0f58d | 1322 | wxLogError(_T("Unable to load bitmap:")+*bitmappath); |
2193517f VS |
1323 | |
1324 | //Make a bitmap file name | |
1325 | bitmapname=CleanName(bitmapname); | |
19d0f58d JS |
1326 | bitmapname+=_T(".bmp"); |
1327 | m_xmlfile.Write(_T("\t\t\t<bitmap>")+bitmapname+_T("</bitmap>\n")); | |
2c99715a | 1328 | bitmap.SaveFile(m_targetpath+bitmapname,wxBITMAP_TYPE_BMP); |
2193517f VS |
1329 | } |
1330 | ||
1331 | void rc2xml::WriteIcon(wxString iconname) | |
1332 | { | |
1333 | wxNode *node=m_iconlist->Find(iconname); | |
1334 | if (node==NULL) | |
1335 | { | |
19d0f58d JS |
1336 | m_xmlfile.Write(_T("\t\t\t<bitmap>missing_file</bitmap>\n")); |
1337 | wxLogError(_T("Unable to find icon:")+iconname); | |
2193517f VS |
1338 | } |
1339 | wxString *iconpath; | |
19d0f58d | 1340 | iconpath=(wxString *)node->GetData(); |
2193517f VS |
1341 | wxIcon icon; |
1342 | wxBitmap bitmap; | |
1343 | if (!icon.LoadFile(*iconpath,wxBITMAP_TYPE_ICO )) | |
19d0f58d | 1344 | wxLogError(_T("Unable to load icon:")+*iconpath); |
2193517f VS |
1345 | #ifdef __WXMSW__ |
1346 | bitmap.CopyFromIcon(icon); | |
1347 | #else | |
1348 | bitmap = icon; | |
1349 | #endif | |
2c99715a | 1350 | iconname=wxFileNameFromPath(*iconpath); |
2193517f VS |
1351 | //Make a bitmap file name |
1352 | iconname=CleanName(iconname); | |
19d0f58d JS |
1353 | iconname+=_T(".bmp"); |
1354 | m_xmlfile.Write(_T("\t\t\t<bitmap>")+iconname+_T("</bitmap>\n")); | |
2c99715a | 1355 | bitmap.SaveFile(m_targetpath+iconname,wxBITMAP_TYPE_BMP); |
2193517f | 1356 | |
7c9955d1 | 1357 | |
2193517f VS |
1358 | } |
1359 | /*Unfortunately sometimes the great MSVC Resource editor decides | |
1360 | to use numbers instead of the word id. I have no idea why they | |
1361 | do this, but that is the way it is. | |
1362 | */ | |
1363 | /* this is a quick and dirty way to parse the resource.h file | |
1364 | it will not recognize #ifdef so it can be easily fooled | |
1365 | */ | |
1366 | void rc2xml::ParseResourceHeader() | |
1367 | { | |
1368 | wxTextFile r; | |
1369 | //Attempt to load resource.h in current path | |
19d0f58d | 1370 | if (!r.Open(_T("resource.h"))) |
2193517f | 1371 | { |
19d0f58d | 1372 | wxLogError(_T("Warining Unable to load resource.h file")); |
2193517f VS |
1373 | return; |
1374 | } | |
7c9955d1 | 1375 | |
2193517f VS |
1376 | wxString str; |
1377 | wxString id,v; | |
1378 | wxStringTokenizer tok; | |
1379 | wxString *varname; | |
7c9955d1 JS |
1380 | |
1381 | ||
2193517f VS |
1382 | long n; |
1383 | ||
1384 | //Read through entire file | |
1385 | for ( str = r.GetFirstLine(); !r.Eof(); str = r.GetNextLine() ) | |
1386 | { | |
f80ea77b | 1387 | if (str.Find(_T("#define"))!=wxNOT_FOUND) |
2193517f VS |
1388 | { |
1389 | tok.SetString(str); | |
1390 | //Just ignore #define token | |
1391 | tok.GetNextToken(); | |
1392 | v=tok.GetNextToken(); | |
1393 | id=tok.GetNextToken(); | |
1394 | if (id.IsNumber()) | |
1395 | { | |
1396 | varname=new wxString; | |
1397 | id.ToLong(&n); | |
1398 | *varname=v; | |
1399 | m_resourcelist->Append(n,varname); | |
1400 | } | |
1401 | } | |
1402 | } | |
1403 | ||
7c9955d1 JS |
1404 | |
1405 | ||
2193517f VS |
1406 | } |
1407 | ||
1408 | ||
1409 | wxString rc2xml::LookUpId(wxString id) | |
1410 | { | |
1411 | wxString st; | |
1412 | ||
1413 | if (!id.IsNumber()) | |
1414 | return id; | |
1415 | long n; | |
1416 | id.ToLong(&n); | |
1417 | wxNode *node=m_resourcelist->Find(n); | |
1418 | wxString *s; | |
1419 | if (node==NULL) | |
1420 | return id; | |
1421 | ||
19d0f58d | 1422 | s=(wxString *)node->GetData(); |
2193517f VS |
1423 | st=*s; |
1424 | return st; | |
1425 | } |