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