]> git.saurik.com Git - wxWidgets.git/blob - contrib/utils/convertrc/rc2xml.cpp
fixed bug in wxHtmlWindow: HistoryBack/Forward now correctly preserves last entry...
[wxWidgets.git] / contrib / utils / convertrc / rc2xml.cpp
1 // rc2xml.cpp: implementation of the wxRC2XML class.
2 //
3 //////////////////////////////////////////////////////////////////////
4 // For compilers that support precompilation, includes "wx/wx.h".
5 #include "wx/wxprec.h"
6
7 #include "rc2xml.h"
8 #include "wx/image.h"
9 #include "wx/resource.h"
10 //////////////////////////////////////////////////////////////////////
11 // Construction/Destruction
12 //////////////////////////////////////////////////////////////////////
13
14 wxRC2XML::wxRC2XML()
15 {
16 m_done=FALSE;
17 m_bitmaplist=new wxList(wxKEY_STRING);
18 m_stringtable=new wxList(wxKEY_STRING);
19 m_iconlist = new wxList(wxKEY_STRING);
20 }
21
22 wxRC2XML::~wxRC2XML()
23 {
24 delete m_bitmaplist;
25 delete m_stringtable;
26 delete m_iconlist;
27 }
28
29 bool wxRC2XML::Convert(wxString rcfile, wxString xmlfile)
30 {
31 m_rc.Open(rcfile.c_str());
32 m_filesize=m_rc.Length();
33
34 bool result;
35 result=m_xmlfile.Open(xmlfile.c_str(),"w+t");
36 wxASSERT_MSG(result,"Couldn't create XML file");
37 if (!result)
38 return FALSE;
39
40
41 /* Write Basic header for XML file */
42 m_xmlfile.Write("<?xml version=\"1.0\" ?>\n");
43 m_xmlfile.Write("<resource>\n");
44
45 //Gather all the resource we need for toolbars,menus, and etc
46 FirstPass();
47 m_done=FALSE;
48 m_rc.Seek(0);
49 //Read in dialogs, toolbars,menus
50 SecondPass();
51
52 m_xmlfile.Write("</resource>\n");
53 m_xmlfile.Close();
54 m_rc.Close();
55
56 return TRUE;
57 }
58
59
60 void wxRC2XML::ParseDialog(wxString dlgname)
61 {
62 wxString token;
63 static int dlgid=999;
64 dlgid++;
65 /* Make sure that this really is a dialog
66 microsoft reuses the keyword DIALOG for other things
67 */
68 token=PeekToken();
69 //Microsoft notation?
70 if (token=="DISCARDABLE")
71 {
72 token=GetToken();
73 token=PeekToken();
74 }
75 //Error isn't a Dialog resource eject eject
76 if (!token.IsNumber())
77 return;
78
79 //Record x,y,width,height
80 int x,y,width,height;
81 ReadRect(x,y,width,height);
82 //Get Title
83 token=GetToken();
84 wxString title;
85
86 while ((token!="BEGIN")&(token!="{"))
87 {
88 if (token=="CAPTION")
89 {
90 title=GetQuoteField();
91 }
92 token=GetToken();
93 }
94 m_xmlfile.Write(" <dialog");
95 //Avoid duplicate names this way
96 dlgname.Replace("IDD_","DLG_");
97
98 WriteBasicInfo(x,y,width,height,dlgname);
99 WriteTitle(title);
100 m_xmlfile.Write(" <children>\n");
101 ParseControls();
102 m_xmlfile.Write(" </children>\n");
103 m_xmlfile.Write(" </dialog>\n");
104 }
105
106 /*
107 BEGIN
108 EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT
109 WS_TABSTOP
110 LTEXT "Bands",IDC_STATIC,11,86,21,8
111 EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL
112 END
113 */
114 void wxRC2XML::ParseControls()
115 {
116 wxString token;
117
118 token=GetToken();
119 while ((token!="END")&(token!="}"))
120 {
121 if (token=="LTEXT")
122 ParseStaticText();
123 else if (token=="EDITTEXT")
124 ParseTextCtrl();
125 else if (token=="PUSHBUTTON")
126 ParsePushButton();
127 else if (token=="DEFPUSHBUTTON")
128 ParsePushButton();
129 else if (token=="GROUPBOX")
130 ParseGroupBox();
131 else if (token=="COMBOBOX")
132 ParseComboBox();
133 else if (token=="CONTROL")
134 ParseControlMS();
135 else if (token=="LISTBOX")
136 ParseListBox();
137 else if (token=="ICON")
138 ParseIconStatic();
139 else if (token=="SCROLLBAR")
140 ParseScrollBar();
141 token=GetToken();
142 }
143
144 }
145 //LTEXT "Radius",IDC_STATIC,9,67,23,8
146 void wxRC2XML::ParseStaticText()
147 {
148 wxString token;
149 wxString phrase,varname;
150 phrase=GetQuoteField();
151 varname=GetToken();
152 int x,y,width,height;
153 ReadRect(x,y,width,height);
154
155 m_xmlfile.Write(" <statictext");
156 WriteBasicInfo(x,y,width,height,varname);WriteLabel(phrase);
157 m_xmlfile.Write(" </statictext>\n");
158
159 }
160 //EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
161 void wxRC2XML::ParseTextCtrl()
162 {
163 wxString token;
164 wxString varname,style;
165 varname=GetToken();
166 int x,y,width,height;
167 ReadRect(x,y,width,height);
168 //TODO
169 //style=GetToken();
170
171 m_xmlfile.Write(" <textctrl");
172 WriteBasicInfo(x,y,width,height,varname);
173 m_xmlfile.Write("\n </textctrl>\n");
174
175 }
176 //PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
177 void wxRC2XML::ParsePushButton()
178 {
179 wxString token;
180 wxString phrase,varname;
181 phrase=GetQuoteField();
182 varname=GetToken();
183
184
185 int x,y,width,height;
186 ReadRect(x,y,width,height);
187
188 m_xmlfile.Write(" <button");
189 WriteBasicInfo(x,y,width,height,varname);
190 WriteLabel(phrase);
191 m_xmlfile.Write(" </button>\n");
192
193 }
194
195
196 bool wxRC2XML::Seperator(int ch)
197 {
198 //if ((ch==' ')|(ch==',')|(ch==13)|(ch==10)|(ch=='|')|(ch=='\t'))
199 if ((ch==' ')|(ch==',')|(ch==13)|(ch==10)|(ch=='\t'))
200 return TRUE;
201
202 if (ch==EOF)
203 {
204 m_done=TRUE;
205 return TRUE;
206 }
207 return FALSE;
208 }
209
210 void wxRC2XML::ParseGroupBox()
211 {
212 // GROUPBOX "Rotate",IDC_STATIC,1,1,71,79
213 wxString token;
214 wxString phrase,varname;
215 phrase=GetQuoteField();
216 varname=GetToken();
217 int x,y,width,height;
218 ReadRect(x,y,width,height);
219
220 m_xmlfile.Write(" <staticbox");
221 WriteBasicInfo(x,y,width,height,varname);
222 WriteLabel(phrase);
223 m_xmlfile.Write(" </staticbox>\n");
224
225
226 }
227
228 void wxRC2XML::ReadRect(int & x, int & y, int & width, int & height)
229 {
230 x=atoi(GetToken());
231 y=atoi(GetToken());
232 width=atoi(GetToken());
233 height=atoi(GetToken());
234
235 }
236
237 wxString wxRC2XML::GetToken()
238 {
239 wxString token="";
240
241 if (m_rc.Eof())
242 {
243 m_done=TRUE;
244 return token;
245 }
246
247 int ch=0;
248 ReadChar(ch);
249 if (ch==EOF)
250 {
251 m_done=TRUE;
252 return token;
253 }
254
255 while (Seperator(ch))
256 {
257 ReadChar(ch);
258 if (m_done)
259 return token;
260 }
261
262 if (ch==EOF)
263 {
264 m_done=TRUE;
265
266 }
267
268
269 while (!Seperator(ch))
270 {
271 token+=(char)ch;
272 ReadChar(ch);
273
274 }
275
276 if (ch==EOF)
277 m_done=TRUE;
278
279
280 return token;
281 }
282
283 wxString wxRC2XML::GetQuoteField()
284 {
285 wxString phrase;
286 //ASCII code 34 "
287 int ch=0;
288 ReadChar(ch);
289
290 while (ch!=34)
291 ReadChar(ch);
292
293 ReadChar(ch);
294
295 while (ch!=34)
296 {
297 phrase+=(char)ch;
298 ReadChar(ch);
299 }
300 return phrase;
301 }
302
303 void wxRC2XML::ReadChar(int &ch)
304 {
305 int result;
306 result=m_rc.Tell();
307
308 if((result>=m_filesize))
309 m_done=TRUE;
310
311 result=m_rc.Read(&ch,1);
312
313 if((result==-1))
314 m_done=TRUE;
315
316 if(ch==EOF)
317 m_done=TRUE;
318 }
319
320 void wxRC2XML::ParseComboBox()
321 {
322 /* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
323 WS_VSCROLL | WS_TABSTOP */
324 wxString token;
325 wxString varname;
326 varname=GetToken();
327 int x,y,width,height;
328 ReadRect(x,y,width,height);
329
330 m_xmlfile.Write(" <combobox");
331 WriteBasicInfo(x,y,width,height,varname);
332 m_xmlfile.Write("\n </combobox>\n");
333
334
335
336 }
337
338 void wxRC2XML::ParseMenu(wxString varname)
339 {
340 wxString token="";
341
342 //Write menubar to xml file
343 m_xmlfile.Write(" <menubar");
344 //Avoid duplicate names this way
345 varname.Replace("IDR_","MB_");
346 WriteName(varname);
347 m_xmlfile.Write(">\n");
348 m_xmlfile.Write(" <children>\n");
349
350 while ((token!="BEGIN")&(token!="{"))
351 token=GetToken();
352
353 while ((token!="END")&(token!="}"))
354 {
355 token=GetToken();
356 if (token=="POPUP")
357 {
358 ParsePopupMenu();
359 }
360 }
361 m_xmlfile.Write(" </children>\n");
362 m_xmlfile.Write(" </menubar>\n");
363 }
364
365 void wxRC2XML::ParsePopupMenu()
366 {
367 static menucount=0;
368 menucount++;
369 wxString token,name,msg,longhelp,tip;
370 token=GetQuoteField();
371 int spot;
372 //Remove /t because it causes problems
373
374 spot=token.First("\\t");
375 token=token.Left(spot);
376
377 //Write Menu item
378 //Generate a fake name since RC menus don't have one
379 name<<"Menu_"<<menucount;
380 m_xmlfile.Write(" <menu");
381 WriteName(name);
382 m_xmlfile.Write(">\n");
383 WriteLabel(token);
384 m_xmlfile.Write(" <children>\n");
385
386 while ((token!="BEGIN")&(token!="{"))
387 token=GetToken();
388
389 while ((token!="END")&(token!="}"))
390 {
391 token=GetToken();
392
393 if (token=="POPUP")
394 ParsePopupMenu();
395
396 if (token=="MENUITEM")
397 ParseMenuItem();
398
399 }
400 m_xmlfile.Write(" </children>\n");
401 m_xmlfile.Write(" </menu>\n");
402 }
403
404 wxString wxRC2XML::PeekToken()
405 {
406 wxString token;
407 int p;
408 p=m_rc.Tell();
409 token=GetToken();
410
411 m_rc.Seek(p);
412 return token;
413 }
414 //MS Windows pain in the butt CONTROL
415 void wxRC2XML::ParseControlMS()
416 {
417 wxString label,varname,kindctrl,token;
418 token=PeekToken();
419
420 if (token.Contains("\""))
421 ParseNormalMSControl();
422 else
423 ParseWeirdMSControl();
424
425 }
426
427 /* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
428 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
429 */
430
431 void wxRC2XML::ParseSlider(wxString label, wxString varname)
432 {
433 wxString token;
434 while (ReadOrs(token));
435 //TODO Handle styles
436 //fprintf(m_wxrfile," control = [%i,wxSlider,'','wxSL_HORIZONTAL','%s',",m_controlid,varname);
437 int x,y,width,height;
438 ReadRect(x,y,width,height);
439 m_xmlfile.Write(" <slider");
440 WriteBasicInfo(x,y,width,height,varname);
441 m_xmlfile.Write("\n </slider>\n");
442
443 }
444 /*
445 CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
446 WS_BORDER,15,52,154,13
447 */
448 void wxRC2XML::ParseProgressBar(wxString label, wxString varname)
449 {
450 wxString token;
451 while (ReadOrs(token));
452 int x,y,width,height;
453 ReadRect(x,y,width,height);
454 wxString style;
455 //Always horizontal in MFC
456 style+="wxGA_HORIZONTAL";
457 m_xmlfile.Write(" <gauge");
458 WriteBasicInfo(x,y,width,height,varname);
459 WriteStyle(style);
460 m_xmlfile.Write(" </gauge>\n");
461 }
462
463 /* FIXME: this function needs to be rewritten */
464 bool wxRC2XML::ReadOrs(wxString & w)
465 {
466 wxString token;
467 token=PeekToken();
468
469 if (token.IsNumber())
470 return FALSE;
471
472 w=GetToken();
473 return TRUE;
474 }
475
476 //Is it a check button or a radio button
477 void wxRC2XML::ParseCtrlButton(wxString label, wxString varname)
478 {
479 wxString token;
480 token=GetToken();
481 int x,y,width,height;
482
483 if (token=="BS_AUTOCHECKBOX")
484 {
485 while (ReadOrs(token));
486 ReadRect(x,y,width,height);
487 m_xmlfile.Write(" <checkbox");
488 WriteBasicInfo(x,y,width,height,varname);
489 WriteLabel(label);
490 m_xmlfile.Write(" </checkbox>\n");
491 }
492
493 if (token=="BS_AUTORADIOBUTTON")
494 {
495 while(ReadOrs(token));
496 ReadRect(x,y,width,height);
497 m_xmlfile.Write(" <radiobutton");
498 WriteBasicInfo(x,y,width,height,varname);
499 WriteLabel(label);
500 m_xmlfile.Write(" </radiobutton>\n");
501 }
502
503
504
505 }
506
507
508 void wxRC2XML::WriteSize(int width, int height)
509 {
510 wxString msg;
511 msg<<" <size>"<<width<<","<<height<<"d</size>";
512 m_xmlfile.Write(msg);
513 }
514
515 void wxRC2XML::WritePosition(int x, int y)
516 {
517 wxString msg;
518 msg<<" <pos>"<<x<<","<<y<<"d</pos>";
519 m_xmlfile.Write(msg);
520 }
521
522 void wxRC2XML::WriteTitle(wxString title)
523 {
524 wxString msg;
525 msg=_T(" <title>"+title+"</title>\n");
526 m_xmlfile.Write(msg);
527 }
528
529 void wxRC2XML::WriteName(wxString name)
530 {
531
532 //Replace common MS ids with wxWindows ids
533 //I didn't do everyone of them
534 if (name=="IDOK")
535 name="wxID_OK";
536 else if (name=="IDCANCEL")
537 name="wxID_CANCEL";
538 else if (name=="IDAPPLY")
539 name="wxID_APPLY";
540 else if (name=="ID_FILE_OPEN")
541 name="wxID_OPEN";
542 else if (name=="ID_FILE_CLOSE")
543 name="wxID_CLOSE";
544 else if (name=="ID_FILE_SAVE")
545 name="wxID_SAVE";
546 else if (name=="ID_FILE_SAVE_AS")
547 name="wxID_SAVEAS";
548 else if (name=="ID_APP_EXIT")
549 name="wxID_EXIT";
550 else if (name=="ID_FILE_PRINT")
551 name="wxID_PRINT";
552 else if (name=="ID_FILE_PRINT_PREVIEW")
553 name="wxID_PREVIEW";
554 else if (name=="ID_FILE_PRINT_SETUP")
555 name="wxID_PRINT_SETUP";
556 else if (name=="ID_APP_ABOUT")
557 name="wxID_ABOUT";
558 else if (name=="ID_EDIT_UNDO")
559 name="wxID_UNDO";
560 else if (name=="ID_EDIT_CUT")
561 name="wxID_CUT";
562 else if (name=="ID_EDIT_COPY")
563 name="wxID_COPY";
564 else if (name=="ID_EDIT_PASTE")
565 name="wxID_PASTE";
566
567 m_xmlfile.Write(" name= \""+name+"\"");
568 }
569
570 void wxRC2XML::WriteLabel(wxString label)
571 {
572 label.Replace("&","$");
573 m_xmlfile.Write(" <label>"+label+"</label>\n");
574 }
575
576 void wxRC2XML::WriteBasicInfo(int x, int y, int width, int height, wxString name)
577 {
578 WriteName(name);
579 m_xmlfile.Write(">\n");
580 m_xmlfile.Write(" ");
581 WritePosition(x,y);
582 WriteSize(width,height);
583 m_xmlfile.Write("\n");
584
585 }
586
587 void wxRC2XML::WriteStyle(wxString style)
588 {
589 if (style.Length()==0)
590 return;
591 m_xmlfile.Write("\n <style>"+style+"</style>\n");
592 }
593 /*
594 LISTBOX IDC_LIST1,16,89,48,40,LBS_SORT | LBS_MULTIPLESEL |
595 LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
596 */
597 void wxRC2XML::ParseListBox()
598 {
599 wxString token;
600 wxString varname;
601
602 varname=GetToken();
603 int x,y,width,height;
604 ReadRect(x,y,width,height);
605
606 m_xmlfile.Write(" <listbox");
607 WriteBasicInfo(x,y,width,height,varname);
608 m_xmlfile.Write("\n </listbox>\n");
609
610 }
611 /*
612 CONTROL "",IDC_RICHEDIT1,"RICHEDIT",ES_AUTOHSCROLL | WS_BORDER |
613 WS_TABSTOP,103,110,40,14
614 */
615 void wxRC2XML::ParseRichEdit(wxString label, wxString varname)
616 {
617 wxString token;
618 while (ReadOrs(token));
619 int x,y,width,height;
620 ReadRect(x,y,width,height);
621 wxString style;
622 //Make it a rich text control
623 style+="wxTE_MULTILINE ";
624 m_xmlfile.Write(" <textctrl");
625 WriteBasicInfo(x,y,width,height,varname);
626 WriteStyle(style);
627 m_xmlfile.Write(" </textctrl>\n");
628
629 }
630 /*
631 CONTROL "Spin1",IDC_SPIN1,"msctls_updown32",UDS_ARROWKEYS,209,72,
632 19,26
633 */
634 void wxRC2XML::ParseSpinCtrl(wxString label, wxString varname)
635 {
636 wxString token;
637 while (ReadOrs(token));
638 int x,y,width,height;
639 ReadRect(x,y,width,height);
640 wxString style;
641 m_xmlfile.Write(" <spinbutton");
642 WriteBasicInfo(x,y,width,height,varname);
643 WriteStyle(style);
644 m_xmlfile.Write("\n </spinbutton>\n");
645
646
647 }
648
649 void wxRC2XML::FirstPass()
650 {
651 wxString token,prevtok;
652 while (!m_done)
653 {
654 token=GetToken();
655 if (token=="BITMAP")
656 ParseBitmap(prevtok);
657 else if (token=="STRINGTABLE")
658 ParseStringTable(prevtok);
659 else if (token=="ICON")
660 ParseIcon(prevtok);
661 prevtok=token;
662 }
663 }
664
665 void wxRC2XML::ParseBitmap(wxString varname)
666 {
667 wxString token,*bitmapfile;
668 bitmapfile=new wxString;
669 token=PeekToken();
670 //Microsoft notation?
671 if (token=="DISCARDABLE")
672 {
673 token=GetToken();
674 token=PeekToken();
675 }
676
677 *bitmapfile=GetQuoteField();
678 m_bitmaplist->Append(varname,bitmapfile);
679
680 }
681
682
683 void wxRC2XML::SecondPass()
684 {
685 wxString token,prevtok;
686 while (!m_done)
687 {
688 token=GetToken();
689 if (token=="DIALOG")
690 ParseDialog(prevtok);
691 else if (token=="MENU")
692 ParseMenu(prevtok);
693 else if (token=="TOOLBAR")
694 ParseToolBar(prevtok);
695 prevtok=token;
696 }
697
698 }
699
700 void wxRC2XML::ParseToolBar(wxString varname)
701 {
702 wxString token;
703 token=GetToken();
704 wxASSERT_MSG(token=="DISCARDABLE","Error in toolbar parsing");
705
706 //Look up bitmap for toolbar and load
707 wxNode *node=m_bitmaplist->Find(varname);
708 wxString *bitmappath;
709 bitmappath=(wxString *)node->Data();
710 wxBitmap bitmap;
711 if (!bitmap.LoadFile(*bitmappath,wxBITMAP_TYPE_BMP ))
712 wxLogError("Unable to load bitmap:"+*bitmappath);
713
714 //Write toolbar to xml file
715 m_xmlfile.Write(" <toolbar");
716 //Avoid duplicate names this way
717 varname.Replace("IDR_","TB_");
718 WriteName(varname);
719 m_xmlfile.Write(">\n");
720 wxString style;
721 style+="wxTB_FLAT";
722 WriteStyle(style);
723
724 m_xmlfile.Write(" <children>\n");
725
726 //Grab width and height
727 int width,height;
728 width=atoi(GetToken());
729 height=atoi(GetToken());
730
731 int c=0;
732 wxString buttonname,msg,tip,longhelp;
733 token=GetToken();
734 while ((token!="BEGIN"))
735 token=GetToken();
736
737 while ((token!="END")&(token!="}"))
738 {
739 if (token=="BUTTON")
740 {
741 buttonname=GetToken();
742 m_xmlfile.Write(" <tool");
743 WriteName(buttonname);
744 m_xmlfile.Write(">\n");
745 //Write tool tip if any
746 if (LookUpString(buttonname,msg))
747 {
748 SplitHelp(msg,tip,longhelp);
749 m_xmlfile.Write(" <tooltip>"+tip+"</tooltip>\n");
750 m_xmlfile.Write(" <longhelp>"+longhelp+"</longhelp>\n");
751 }
752 //Make a bitmap file name
753 buttonname=CleanName(buttonname);
754 buttonname+=".bmp";
755 m_xmlfile.Write(" <bitmap>"+buttonname+"</bitmap>\n");
756 WriteToolButton(buttonname,c,width,height,bitmap);
757 m_xmlfile.Write(" </tool>\n");
758 c++;
759 }
760 else if (token=="SEPARATOR")
761 {
762 m_xmlfile.Write(" <separator/>\n");
763 }
764 token=GetToken();
765 }
766 m_xmlfile.Write(" </children>\n");
767 m_xmlfile.Write(" </toolbar>\n");
768 }
769
770 //Extract bitmaps from larger toolbar bitmap
771 void wxRC2XML::WriteToolButton(wxString name,int index, int width, int height, wxBitmap bitmap)
772 {
773 int x;
774 x=index*width;
775 wxRect r(x,0,width,height);
776 wxBitmap little;
777
778 little=bitmap.GetSubBitmap(r);
779 little.SaveFile(name,wxBITMAP_TYPE_BMP);
780 }
781
782 void wxRC2XML::ParseStringTable(wxString varname)
783 {
784 wxString token;
785 token=GetToken();
786 while ((token!="BEGIN"))
787 token=GetToken();
788 token=GetToken();
789 wxString *msg;
790
791 while ((token!="END")&(token!="}"))
792 {
793 msg=new wxString;
794 *msg=GetQuoteField();
795 m_stringtable->Append(token,msg);
796 token=GetToken();
797 }
798
799 }
800
801 bool wxRC2XML::LookUpString(wxString strid,wxString & st)
802 {
803 wxNode *node=m_stringtable->Find(strid);
804 wxString *s;
805 if (node==NULL)
806 return FALSE;
807
808 s=(wxString *)node->Data();
809 st=*s;
810
811 return TRUE;
812 }
813
814 bool wxRC2XML::SplitHelp(wxString msg, wxString &shorthelp, wxString &longhelp)
815 {
816 int spot;
817 spot=msg.Find("\\n");
818 if (spot==-1)
819 {
820 shorthelp=msg;
821 longhelp=msg;
822 }
823
824 longhelp=msg.Left(spot);
825 spot=msg.Length()-spot-2;
826 shorthelp=msg.Right(spot);
827 return TRUE;
828 }
829
830 void wxRC2XML::ParseMenuItem()
831 {
832 wxString token,name,msg,tip,longhelp;
833 int spot;
834 if (PeekToken()=="SEPARATOR")
835 {
836 m_xmlfile.Write(" <separator/>\n");
837 return;
838 }
839
840 token=GetQuoteField();
841 name=GetToken();
842 //Remove /t because it causes problems
843 spot=token.First("\\t");
844 token=token.Left(spot);
845 m_xmlfile.Write(" <menuitem");
846 WriteName(name);
847 m_xmlfile.Write(">\n");
848 WriteLabel(token);
849 //Look up help if any listed in stringtable
850 if (LookUpString(name,msg))
851 {
852 SplitHelp(msg,tip,longhelp);
853 m_xmlfile.Write(" <help>"
854 +longhelp+"</help>\n");
855 }
856 //look for extra attributes like checked and break
857 wxString ptoken;
858 ptoken=PeekToken();
859 while ((ptoken!="MENUITEM")&(ptoken!="POPUP")&(ptoken!="END"))
860 {
861 token=GetToken();
862 if (token=="CHECKED")
863 m_xmlfile.Write(" <checkable>1</checkable>\n");
864 else if (token=="MENUBREAK");
865 //m_xmlfile.Write(" </break>\n");
866 else if (token=="GRAYED");
867 else
868 wxLogError("Unknown Menu Item token:"+token);
869 ptoken=PeekToken();
870 }
871 m_xmlfile.Write(" </menuitem>\n");
872
873 }
874
875 //ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
876 void wxRC2XML::ParseIconStatic()
877 {
878 wxString token;
879 wxString varname,iconname;
880 iconname=GetToken();
881 //Look up icon
882 wxNode *node=m_iconlist->Find(iconname);
883 wxString *iconpath;
884 iconpath=(wxString *)node->Data();
885 wxIcon icon;
886 wxBitmap bitmap;
887 if (!icon.LoadFile(*iconpath,wxBITMAP_TYPE_ICO ))
888 wxLogError("Unable to load icon:"+*iconpath);
889 bitmap.CopyFromIcon(icon);
890 varname=GetToken();
891
892 int x,y,width,height;
893 ReadRect(x,y,width,height);
894
895 m_xmlfile.Write(" <staticbitmap");
896 WriteBasicInfo(x,y,width,height,varname);
897 //Save icon as a bitmap
898 //Make a bitmap file name
899 iconname=CleanName(iconname);
900 iconname+=".bmp";
901 m_xmlfile.Write(" <bitmap>"+iconname+"</bitmap>\n");
902 bitmap.SaveFile(iconname,wxBITMAP_TYPE_BMP);
903 m_xmlfile.Write(" </staticbitmap>\n");
904
905 }
906 //IDR_MAINFRAME ICON DISCARDABLE "res\\mfcexample.ico"
907 void wxRC2XML::ParseIcon(wxString varname)
908 {
909 wxString token,*iconfile;
910 iconfile=new wxString;
911 token=PeekToken();
912
913 *iconfile=GetQuoteField();
914 m_iconlist->Append(varname,iconfile);
915
916 }
917
918 wxString wxRC2XML::CleanName(wxString name)
919 {
920 name.MakeLower();
921 name.Replace("id_","");
922 name.Replace("idr_","");
923 name.Replace("idb_","");
924 name.Replace("idc_","");
925 return name;
926 }
927 // And the award for most messed up control goes to...
928 // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
929 void wxRC2XML::ParseStaticBitmap(wxString bitmapname, wxString varname)
930 {
931 wxString token;
932 //Grab SS_BITMAP
933 token=GetToken();
934
935 //Look up bitmap
936 wxNode *node=m_bitmaplist->Find(bitmapname);
937 wxString *bitmappath;
938 bitmappath=(wxString *)node->Data();
939 wxBitmap bitmap;
940 if (!bitmap.LoadFile(*bitmappath,wxBITMAP_TYPE_BMP ))
941 wxLogError("Unable to load bitmap:"+*bitmappath);
942
943 int x,y,width,height;
944 ReadRect(x,y,width,height);
945
946 m_xmlfile.Write(" <staticbitmap");
947 WriteBasicInfo(x,y,width,height,varname);
948 //Make a bitmap file name
949 bitmapname=CleanName(bitmapname);
950 bitmapname+=".bmp";
951 m_xmlfile.Write(" <bitmap>"+bitmapname+"</bitmap>\n");
952 bitmap.SaveFile(bitmapname,wxBITMAP_TYPE_BMP);
953 m_xmlfile.Write(" </staticbitmap>\n");
954
955
956 }
957
958 void wxRC2XML::ParseNormalMSControl()
959 {
960 wxString label,varname,kindctrl;
961
962 label=GetQuoteField();
963 varname=GetToken();
964 kindctrl=GetQuoteField();
965 kindctrl.MakeUpper();
966
967 if (kindctrl=="MSCTLS_UPDOWN32")
968 ParseSpinCtrl(label,varname);
969 if (kindctrl=="MSCTLS_TRACKBAR32")
970 ParseSlider(label,varname);
971 if (kindctrl=="MSCTLS_PROGRESS32")
972 ParseProgressBar(label,varname);
973 if (kindctrl=="SYSTREEVIEW32")
974 ParseTreeCtrl(label,varname);
975 if (kindctrl=="SYSMONTHCAL32")
976 ParseCalendar(label,varname);
977 if (kindctrl=="SYSLISTVIEW32")
978 ParseListCtrl(label,varname);
979 if (kindctrl=="BUTTON")
980 ParseCtrlButton(label,varname);
981 if (kindctrl=="RICHEDIT")
982 ParseRichEdit(label,varname);
983
984 }
985
986 void wxRC2XML::ParseWeirdMSControl()
987 {
988 wxString kindctrl;
989 wxString varname;
990 wxString id;
991 id=GetToken();
992 varname=GetToken();
993 kindctrl=GetQuoteField();
994 kindctrl.MakeUpper();
995 // CONTROL IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30
996 if (kindctrl=="STATIC")
997 {
998 if (PeekToken()=="SS_BITMAP")
999 ParseStaticBitmap(id,varname);
1000 else
1001 wxLogError("Unknown MS Control Static token");
1002 }
1003
1004 }
1005 //SCROLLBAR IDC_SCROLLBAR1,219,56,10,40,SBS_VERT
1006
1007 void wxRC2XML::ParseScrollBar()
1008 {
1009 wxString token;
1010 wxString varname;
1011
1012 varname=GetToken();
1013 int x,y,width,height;
1014 ReadRect(x,y,width,height);
1015 wxString style;
1016 //Default MFC style is horizontal
1017 style=_T("wxSB_HORIZONTAL");
1018 /*
1019 while (ReadOrs(token))
1020 {
1021 if (token=="SBS_VERT")
1022 style=_T("wxSB_VERTICAL");
1023 }
1024 */
1025 m_xmlfile.Write(" <scrollbar");
1026 WriteBasicInfo(x,y,width,height,varname);
1027 WriteStyle(style);
1028 m_xmlfile.Write("\n </scrollbar>\n");
1029
1030
1031 }
1032 // CONTROL "Tree1",IDC_TREE1,"SysTreeView32",WS_BORDER | WS_TABSTOP,
1033 // 7,7,66,61
1034
1035 void wxRC2XML::ParseTreeCtrl(wxString label, wxString varname)
1036 {
1037 wxString token;
1038 while (ReadOrs(token));
1039 int x,y,width,height;
1040 ReadRect(x,y,width,height);
1041 m_xmlfile.Write(" <treectrl");
1042 WriteBasicInfo(x,y,width,height,varname);
1043 m_xmlfile.Write(" </treectrl>\n");
1044
1045 }
1046 // CONTROL "MonthCalendar1",IDC_MONTHCALENDAR1,"SysMonthCal32",
1047 //MCS_NOTODAY | WS_TABSTOP,105,71,129,89
1048
1049 void wxRC2XML::ParseCalendar(wxString label, wxString varname)
1050 {
1051 wxString token;
1052 while (ReadOrs(token));
1053 int x,y,width,height;
1054 ReadRect(x,y,width,height);
1055 m_xmlfile.Write(" <calendarctrl");
1056 WriteBasicInfo(x,y,width,height,varname);
1057 m_xmlfile.Write(" </calendarctrl>\n");
1058 }
1059 // CONTROL "List1",IDC_LIST1,"SysListView32",WS_BORDER | WS_TABSTOP,
1060 // 7,89,68,71
1061
1062 void wxRC2XML::ParseListCtrl(wxString label, wxString varname)
1063 {
1064 wxString token;
1065 while (ReadOrs(token));
1066 int x,y,width,height;
1067 ReadRect(x,y,width,height);
1068 m_xmlfile.Write(" <listctrl");
1069 WriteBasicInfo(x,y,width,height,varname);
1070 m_xmlfile.Write(" </listctrl>\n");
1071
1072 }