]> git.saurik.com Git - wxWidgets.git/blame_incremental - contrib/utils/convertrc/rc2wxr.cpp
Make text control send text update events.
[wxWidgets.git] / contrib / utils / convertrc / rc2wxr.cpp
... / ...
CommitLineData
1// rc2wxr.cpp: implementation of the rc2wxr class.
2
3//
4
5//////////////////////////////////////////////////////////////////////
6
7//Author: Brian Gavin 9/24/00
8
9//License: wxWindows License
10
11/*
12
13WARNING- I know this code has some bugs to work out but
14
15I don't plan to fix them since I feel that wxr files will
16
17not be used much longer.
18
19This code was used as a starting point for my rc2xml converter
20
21*/
22
23#ifdef __GNUG__
24
25#pragma implementation "rc2wxr.cpp"
26
27#pragma interface "rc2wxr.cpp"
28
29#endif
30
31
32
33// For compilers that support precompilation, includes "wx/wx.h".
34
35#include "wx/wxprec.h"
36
37
38
39#ifdef __BORLANDC__
40
41#pragma hdrstop
42
43#endif
44
45
46
47// for all others, include the necessary headers (this file is usually all you
48
49// need because it includes almost all "standard" wxWindows headers
50
51#ifndef WX_PRECOMP
52
53#include <wx/wx.h>
54
55#endif
56
57
58
59
60
61#include "rc2wxr.h"
62
63#include "wx/image.h"
64
65#include "wx/resource.h"
66
67//////////////////////////////////////////////////////////////////////
68
69// Construction/Destruction
70
71//////////////////////////////////////////////////////////////////////
72
73
74
75rc2wxr::rc2wxr()
76
77{
78
79m_done=FALSE;
80
81m_controlid=6000;
82
83}
84
85
86
87rc2wxr::~rc2wxr()
88
89{
90
91
92
93}
94
95
96
97void rc2wxr::Convert(wxString wxrfile, wxString rcfile)
98
99{
100
101m_rc.Open(rcfile);
102
103m_filesize=m_rc.Length();
104
105if( (m_wxr = fopen( wxrfile, "wt" )) == NULL )
106
107{
108
109 return;
110
111}
112
113
114
115
116
117wxString tok,prevtok;
118
119
120
121
122
123while (!m_done)
124
125{
126
127
128
129tok=GetToken();
130
131
132
133if (tok=="DIALOG")
134
135{
136
137ParseDialog(prevtok);
138
139}
140
141
142
143
144
145if (tok=="MENU")
146
147{
148
149ParseMenu(prevtok);
150
151}
152
153
154
155prevtok=tok;
156
157}
158
159
160
161fclose(m_wxr);
162
163//fclose(m_rc);
164
165m_rc.Close();
166
167
168
169}
170
171
172
173
174
175/*
176
177Example .rc
178
179Microsoft style as of v5.0
180
181IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 217, 55
182
183STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
184
185CAPTION "About Funimator"
186
187FONT 8, "MS Sans Serif"
188
189
190
191 Borland 4.5 style rc
192
193IDD_DIBATTR DIALOG 7, 16, 172, 119
194
195STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
196
197CAPTION "DIB Attributes"
198
199FONT 8, "MS Sans Serif"
200
201{
202
203 DEFPUSHBUTTON "Ok", IDOK, 114, 8, 50, 14
204
205 PUSHBUTTON "Cancel", IDCANCEL, 114, 28, 50, 14
206
207
208
209
210
211
212
213*/
214
215void rc2wxr::ParseDialog(wxString dlgname)
216
217{
218
219wxString tok;
220
221static int dlgid=999;
222
223dlgid++;
224
225/* Make sure that this really is a dialog
226
227microsoft reuses the keyword DIALOG for other things
228
229*/
230
231tok=PeekToken();
232
233//Microsoft notation?
234
235if (tok=="DISCARDABLE")
236
237{
238
239tok=GetToken();
240
241tok=PeekToken();
242
243}
244
245//This isn't a Dialog resource eject eject
246
247if (!tok.IsNumber())
248
249 return;
250
251//Generate Dialog text
252
253fprintf(m_wxr,"static char *dialog%i = \"dialog(name = '%s',\\\n",dlgid,dlgname);
254
255//be lazy about style for now. add it later
256
257fprintf(m_wxr,"style = 'wxRAISED_BORDER | wxCAPTION | wxTHICK_FRAME | wxSYSTEM_MENU',\\\n");
258
259
260
261fprintf(m_wxr,"id = %i,\\\n",dlgid);
262
263
264
265//Record x,y,width,height
266
267int x,y,width,height;
268
269ReadRect(x,y,width,height);
270
271fprintf(m_wxr,"x = %i, y = %i, width = %i, height = %i,\\\n",x,y,width,height);
272
273
274
275
276
277//CAPTION "About Funimator"
278
279//Get Title
280
281tok=GetToken();
282
283wxString title;
284
285
286
287while ((tok!="BEGIN")&(tok!="{"))
288
289{
290
291if (tok=="CAPTION")
292
293{
294
295title=GetQuoteField();
296
297fprintf(m_wxr,"title = '%s',\\\n",title);
298
299}
300
301tok=GetToken();
302
303}
304
305fprintf(m_wxr,"use_dialog_units = 1,\\\n");
306
307fprintf(m_wxr,"use_system_defaults = 0,\\\n");
308
309
310
311fprintf(m_wxr,"font = [8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif'],\\\n");
312
313ParseControls();
314
315fprintf(m_wxr,").\";\n\n");
316
317}
318
319
320
321/*
322
323BEGIN
324
325
326
327
328
329
330
331 EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT
332
333 WS_TABSTOP
334
335 LTEXT "Bands",IDC_STATIC,11,86,21,8
336
337 EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL
338
339END
340
341*/
342
343void rc2wxr::ParseControls()
344
345{
346
347wxString tok;
348
349
350
351tok=GetToken();
352
353while ((tok!="END")&(tok!="}"))
354
355{
356
357if (tok=="LTEXT")
358
359 ParseStaticText();
360
361if (tok=="EDITTEXT")
362
363 ParseTextCtrl();
364
365if (tok=="PUSHBUTTON")
366
367 ParsePushButton();
368
369if (tok=="DEFPUSHBUTTON")
370
371 ParsePushButton();
372
373if (tok=="GROUPBOX")
374
375 ParseGroupBox();
376
377if (tok=="COMBOBOX")
378
379 ParseComboBox();
380
381if (tok=="CONTROL")
382
383 ParseControlMS();
384
385
386
387tok=GetToken();
388
389}
390
391
392
393}
394
395//LTEXT "Radius",IDC_STATIC,9,67,23,8
396
397void rc2wxr::ParseStaticText()
398
399{
400
401wxString tok;
402
403wxString phrase,varname;
404
405phrase=GetQuoteField();
406
407varname=GetToken();
408
409m_controlid++;
410
411int x,y,width,height;
412
413ReadRect(x,y,width,height);
414
415fprintf(m_wxr," control = [%i,wxStaticText,'%s','0','%s',",m_controlid,phrase,varname);
416
417fprintf(m_wxr,"%i,%i,%i,%i,'',\\\n",x,y,width,height);
418
419fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
420
421}
422
423//EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
424
425void rc2wxr::ParseTextCtrl()
426
427{
428
429wxString tok;
430
431wxString varname;
432
433varname=GetToken();
434
435m_controlid++;
436
437int x,y,width,height;
438
439ReadRect(x,y,width,height);
440
441fprintf(m_wxr," control = [%i,wxTextCtrl,'','0','%s',",m_controlid,varname);
442
443fprintf(m_wxr,"%i,%i,%i,%i,'',\\\n",x,y,width,height);
444
445fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
446
447
448
449}
450
451//PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
452
453void rc2wxr::ParsePushButton()
454
455{
456
457wxString tok;
458
459wxString phrase,varname;
460
461phrase=GetQuoteField();
462
463varname=GetToken();
464
465int c;
466
467m_controlid++;
468
469c=m_controlid;
470
471if (varname=="IDOK")
472
473c=wxID_OK;
474
475
476
477if (varname=="IDCANCEL")
478
479c=wxID_CANCEL;
480
481
482
483if (varname=="IDAPPLY")
484
485c=wxID_APPLY;
486
487
488
489int x,y,width,height;
490
491ReadRect(x,y,width,height);
492
493fprintf(m_wxr," control = [%i,wxButton,'%s','0','%s',",c,phrase,varname);
494
495fprintf(m_wxr,"%i,%i,%i,%i,'',\\\n",x,y,width,height);
496
497fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
498
499
500
501}
502
503
504
505
506
507bool rc2wxr::Seperator(int ch)
508
509{
510
511if ((ch==' ')|(ch==',')|(ch==13)|(ch==10)|(ch=='|'))
512
513 return TRUE;
514
515
516
517if (ch==EOF)
518
519{
520
521m_done=TRUE;
522
523return TRUE;
524
525}
526
527return FALSE;
528
529}
530
531
532
533void rc2wxr::ParseGroupBox()
534
535{
536
537// GROUPBOX "Rotate",IDC_STATIC,1,1,71,79
538
539wxString tok;
540
541wxString phrase,varname;
542
543phrase=GetQuoteField();
544
545varname=GetToken();
546
547m_controlid++;
548
549int x,y,width,height;
550
551ReadRect(x,y,width,height);
552
553fprintf(m_wxr," control = [%i,wxStaticBox,'%s','0','%s',",m_controlid,phrase,varname);
554
555fprintf(m_wxr,"%i,%i,%i,%i,'',\\\n",x,y,width,height);
556
557fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
558
559
560
561
562
563}
564
565
566
567void rc2wxr::ReadRect(int & x, int & y, int & width, int & height)
568
569{
570
571x=atoi(GetToken());
572
573y=atoi(GetToken());
574
575width=atoi(GetToken());
576
577height=atoi(GetToken());
578
579
580
581}
582
583
584
585wxString rc2wxr::GetToken()
586
587{
588
589wxString tok="";
590
591
592
593if (m_rc.Eof())
594
595{
596
597m_done=TRUE;
598
599return tok;
600
601}
602
603
604
605int ch=0;
606
607ReadChar(ch);
608
609if (ch==EOF)
610
611{
612
613m_done=TRUE;
614
615return tok;
616
617}
618
619
620
621while (Seperator(ch))
622
623{
624
625 ReadChar(ch);
626
627 if (m_done)
628
629 return tok;
630
631}
632
633
634
635if (ch==EOF)
636
637{
638
639m_done=TRUE;
640
641
642
643}
644
645
646
647
648
649while (!Seperator(ch))
650
651{
652
653tok+=(char)ch;
654
655ReadChar(ch);
656
657
658
659}
660
661
662
663if (ch==EOF)
664
665 m_done=TRUE;
666
667
668
669
670
671return tok;
672
673}
674
675
676
677wxString rc2wxr::GetQuoteField()
678
679{
680
681wxString phrase;
682
683//ASCII code 34 "
684
685int ch=0;
686
687ReadChar(ch);
688
689
690
691while (ch!=34)
692
693 ReadChar(ch);
694
695
696
697 ReadChar(ch);
698
699
700
701while (ch!=34)
702
703{
704
705 phrase+=(char)ch;
706
707 ReadChar(ch);
708
709}
710
711return phrase;
712
713}
714
715
716
717void rc2wxr::ReadChar(int &ch)
718
719{
720
721 int result;
722
723result=m_rc.Tell();
724
725
726
727if((result>=m_filesize))
728
729 m_done=TRUE;
730
731
732
733result=m_rc.Read(&ch,1);
734
735
736
737if((result==-1))
738
739 m_done=TRUE;
740
741
742
743if(ch==EOF)
744
745 m_done=TRUE;
746
747}
748
749
750
751void rc2wxr::ParseComboBox()
752
753{
754
755/* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
756
757 WS_VSCROLL | WS_TABSTOP */
758
759wxString tok;
760
761wxString varname;
762
763varname=GetToken();
764
765m_controlid++;
766
767int x,y,width,height;
768
769ReadRect(x,y,width,height);
770
771
772
773fprintf(m_wxr," control = [%i,wxChoice,'','0','%s',",m_controlid,varname);
774
775fprintf(m_wxr,"%i,%i,%i,%i,[],\\\n",x,y,width,height);
776
777fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
778
779
780
781
782
783}
784
785
786
787void rc2wxr::ParseMenu(wxString name)
788
789{
790
791wxString tok="";
792
793static int menuid=0;
794
795menuid++;
796
797fprintf(m_wxr,"static char *MenuBar%i = \"menu(name = '%s',\\\n",menuid,name);
798
799fprintf(m_wxr,"menu = \\\n");
800
801fprintf(m_wxr,"[\\\n");
802
803
804
805while ((tok!="BEGIN")&(tok!="{"))
806
807 tok=GetToken();
808
809
810
811while ((tok!="END")&(tok!="}"))
812
813{
814
815 tok=GetToken();
816
817if (tok=="POPUP")
818
819 {
820
821 ParsePopupMenu();
822
823 fprintf(m_wxr," ],\\\n");
824
825 }
826
827}
828
829
830
831fprintf(m_wxr,"]).\";\n\n");
832
833}
834
835
836
837void rc2wxr::ParsePopupMenu()
838
839{
840
841static int menuitem=99;
842
843menuitem++;
844
845
846
847wxString tok;
848
849tok=GetQuoteField();
850
851int spot;
852
853//Remove /t because it causes problems
854
855spot=tok.First("\\t");
856
857tok=tok.Left(spot);
858
859fprintf(m_wxr," ['%s',%i,'',\\\n",tok,menuitem);
860
861while ((tok!="BEGIN")&(tok!="{"))
862
863 tok=GetToken();
864
865
866
867while ((tok!="END")&(tok!="}"))
868
869{
870
871 tok=GetToken();
872
873if (tok=="MENUITEM")
874
875{
876
877if (PeekToken()=="SEPARATOR")
878
879fprintf(m_wxr," [],\\\n");
880
881else
882
883{
884
885tok=GetQuoteField();
886
887//Remove /t because it causes problems
888
889spot=tok.First("\\t");
890
891tok=tok.Left(spot);
892
893menuitem++;
894
895fprintf(m_wxr," ['%s',%i,''],\\\n",tok,menuitem);
896
897}
898
899}
900
901
902
903}
904
905
906
907
908
909}
910
911
912
913wxString rc2wxr::PeekToken()
914
915{
916
917wxString tok;
918
919int p;
920
921p=m_rc.Tell();
922
923tok=GetToken();
924
925
926
927m_rc.Seek(p);
928
929return tok;
930
931}
932
933//Windows pain in the butt CONTROL
934
935void rc2wxr::ParseControlMS()
936
937{
938
939wxString label,varname,kindctrl,tok;
940
941label=GetQuoteField();
942
943varname=GetToken();
944
945kindctrl=GetQuoteField();
946
947kindctrl.MakeUpper();
948
949
950
951
952
953if (kindctrl=="MSCTLS_TRACKBAR32")
954
955 ParseSlider(label,varname);
956
957if (kindctrl=="MSCTLS_PROGRESS32")
958
959 ParseProgressBar(label,varname);
960
961if (kindctrl=="BUTTON")
962
963 ParseCtrlButton(label,varname);
964
965}
966
967/* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
968
969 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
970
971*/
972
973
974
975void rc2wxr::ParseSlider(wxString label, wxString varname)
976
977{
978
979wxString tok;
980
981while (ReadOrs(tok));
982
983fprintf(m_wxr," control = [%i,wxSlider,'','wxSL_HORIZONTAL','%s',",m_controlid,varname);
984
985int x,y,width,height;
986
987ReadRect(x,y,width,height);
988
989fprintf(m_wxr,"%i,%i,%i,%i,",x,y,width,height);
990
991fprintf(m_wxr," 1, 1, 10,\\\n");
992
993fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
994
995}
996
997/*
998
999CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
1000
1001 WS_BORDER,15,52,154,13
1002
1003*/
1004
1005void rc2wxr::ParseProgressBar(wxString label, wxString varname)
1006
1007{
1008
1009wxString tok;
1010
1011while (ReadOrs(tok));
1012
1013fprintf(m_wxr," control = [%i,wxGauge,'','wxGA_HORIZONTAL','%s',",m_controlid,varname);
1014
1015int x,y,width,height;
1016
1017ReadRect(x,y,width,height);
1018
1019fprintf(m_wxr,"%i,%i,%i,%i,",x,y,width,height);
1020
1021fprintf(m_wxr," 0, 10,\\\n");
1022
1023fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
1024
1025}
1026
1027
1028
1029bool rc2wxr::ReadOrs(wxString & w)
1030
1031{
1032
1033wxString tok;
1034
1035tok=PeekToken();
1036
1037if (tok.IsNumber())
1038
1039 return false;
1040
1041w=GetToken();
1042
1043return TRUE;
1044
1045}
1046
1047
1048
1049//Is it a check button or a radio button
1050
1051void rc2wxr::ParseCtrlButton(wxString label, wxString varname)
1052
1053{
1054
1055wxString tok;
1056
1057tok=GetToken();
1058
1059
1060
1061m_controlid++;
1062
1063int x,y,width,height;
1064
1065
1066
1067if (tok=="BS_AUTOCHECKBOX")
1068
1069{
1070
1071 fprintf(m_wxr," control = [%i,wxCheckBox,'%s','0','%s',",m_controlid,label,varname);
1072
1073 while (ReadOrs(tok));
1074
1075 ReadRect(x,y,width,height);
1076
1077 fprintf(m_wxr,"%i,%i,%i,%i,0,\\\n",x,y,width,height);
1078
1079 fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
1080
1081}
1082
1083
1084
1085if (tok=="BS_AUTORADIOBUTTON")
1086
1087{
1088
1089 fprintf(m_wxr," control = [%i,wxRadioButton,'%s','0','%s',",m_controlid,label,varname);
1090
1091 while(ReadOrs(tok));
1092
1093 ReadRect(x,y,width,height);
1094
1095 fprintf(m_wxr,"%i,%i,%i,%i,0,\\\n",x,y,width,height);
1096
1097 fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
1098
1099}
1100
1101
1102
1103
1104
1105
1106
1107}
1108
1109
1110