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