]> git.saurik.com Git - wxWidgets.git/blame - contrib/utils/convertrc/rc2wxr.cpp
implemented (untested) work around for wxScrolledWindow painting bug
[wxWidgets.git] / contrib / utils / convertrc / rc2wxr.cpp
CommitLineData
2193517f 1// rc2wxr.cpp: implementation of the rc2wxr class.
88d42654
VS
2//
3//////////////////////////////////////////////////////////////////////
2193517f
VS
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#ifdef __GNUG__
13#pragma implementation "rc2wxr.cpp"
14#pragma interface "rc2wxr.cpp"
15#endif
16
88d42654 17// For compilers that support precompilation, includes "wx/wx.h".
2193517f
VS
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// need because it includes almost all "standard" wxWindows headers
26#ifndef WX_PRECOMP
27#include <wx/wx.h>
28#endif
29
88d42654
VS
30
31#include "rc2wxr.h"
32#include "wx/image.h"
33#include "wx/resource.h"
34//////////////////////////////////////////////////////////////////////
35// Construction/Destruction
36//////////////////////////////////////////////////////////////////////
37
2193517f 38rc2wxr::rc2wxr()
88d42654
VS
39{
40m_done=FALSE;
41m_controlid=6000;
42}
43
2193517f 44rc2wxr::~rc2wxr()
88d42654
VS
45{
46
47}
48
2193517f 49void rc2wxr::Convert(wxString wxrfile, wxString rcfile)
88d42654 50{
2193517f
VS
51m_rc.Open(rcfile);
52m_filesize=m_rc.Length();
88d42654
VS
53if( (m_wxr = fopen( wxrfile, "wt" )) == NULL )
54{
2193517f 55 return;
88d42654
VS
56}
57
88d42654
VS
58
59wxString tok,prevtok;
60
61
62while (!m_done)
63{
64
65tok=GetToken();
66
67if (tok=="DIALOG")
68{
2193517f 69ParseDialog(prevtok);
88d42654
VS
70}
71
72
73if (tok=="MENU")
74{
2193517f 75ParseMenu(prevtok);
88d42654
VS
76}
77
78prevtok=tok;
79}
2193517f 80
88d42654
VS
81fclose(m_wxr);
82//fclose(m_rc);
83m_rc.Close();
84
88d42654
VS
85}
86
87
88/*
89Example .rc
90Microsoft style as of v5.0
91IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 217, 55
92STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
93CAPTION "About Funimator"
94FONT 8, "MS Sans Serif"
95
96 Borland 4.5 style rc
97IDD_DIBATTR DIALOG 7, 16, 172, 119
98STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
99CAPTION "DIB Attributes"
100FONT 8, "MS Sans Serif"
101{
102 DEFPUSHBUTTON "Ok", IDOK, 114, 8, 50, 14
103 PUSHBUTTON "Cancel", IDCANCEL, 114, 28, 50, 14
104
105
106
107*/
2193517f
VS
108void rc2wxr::ParseDialog(wxString dlgname)
109{
110wxString tok;
111static int dlgid=999;
112dlgid++;
113/* Make sure that this really is a dialog
114microsoft reuses the keyword DIALOG for other things
115*/
116tok=PeekToken();
117//Microsoft notation?
118if (tok=="DISCARDABLE")
119{
120tok=GetToken();
121tok=PeekToken();
122}
123//This isn't a Dialog resource eject eject
124if (!tok.IsNumber())
125 return;
88d42654 126//Generate Dialog text
15993304 127fprintf(m_wxr,"static char *dialog%i = \"dialog(name = '%s',\\\n",dlgid,dlgname);
88d42654
VS
128//be lazy about style for now. add it later
129fprintf(m_wxr,"style = 'wxRAISED_BORDER | wxCAPTION | wxTHICK_FRAME | wxSYSTEM_MENU',\\\n");
130
131fprintf(m_wxr,"id = %i,\\\n",dlgid);
132
133//Record x,y,width,height
134int x,y,width,height;
135ReadRect(x,y,width,height);
136fprintf(m_wxr,"x = %i, y = %i, width = %i, height = %i,\\\n",x,y,width,height);
137
138
139//CAPTION "About Funimator"
140//Get Title
141tok=GetToken();
142wxString title;
143
144while ((tok!="BEGIN")&(tok!="{"))
145{
146if (tok=="CAPTION")
2193517f
VS
147{
148title=GetQuoteField();
15993304 149fprintf(m_wxr,"title = '%s',\\\n",title);
2193517f 150}
88d42654
VS
151tok=GetToken();
152}
153fprintf(m_wxr,"use_dialog_units = 1,\\\n");
154fprintf(m_wxr,"use_system_defaults = 0,\\\n");
155
156fprintf(m_wxr,"font = [8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif'],\\\n");
157ParseControls();
158fprintf(m_wxr,").\";\n\n");
159}
160
161/*
162BEGIN
163
164
165
166 EDITTEXT IDC_BANDS,36,83,22,14,ES_AUTOHSCROLL | ES_NUMBER | NOT
167 WS_TABSTOP
168 LTEXT "Bands",IDC_STATIC,11,86,21,8
169 EDITTEXT IDC_NAME,10,3,75,14,ES_AUTOHSCROLL
170END
171*/
2193517f 172void rc2wxr::ParseControls()
88d42654
VS
173{
174wxString tok;
175
176tok=GetToken();
177while ((tok!="END")&(tok!="}"))
178{
179if (tok=="LTEXT")
180 ParseStaticText();
181if (tok=="EDITTEXT")
182 ParseTextCtrl();
183if (tok=="PUSHBUTTON")
184 ParsePushButton();
185if (tok=="DEFPUSHBUTTON")
186 ParsePushButton();
187if (tok=="GROUPBOX")
188 ParseGroupBox();
189if (tok=="COMBOBOX")
190 ParseComboBox();
191if (tok=="CONTROL")
192 ParseControlMS();
193
194tok=GetToken();
195}
196
197}
198//LTEXT "Radius",IDC_STATIC,9,67,23,8
2193517f 199void rc2wxr::ParseStaticText()
88d42654
VS
200{
201wxString tok;
202wxString phrase,varname;
203phrase=GetQuoteField();
204varname=GetToken();
205m_controlid++;
206int x,y,width,height;
207ReadRect(x,y,width,height);
15993304 208fprintf(m_wxr," control = [%i,wxStaticText,'%s','0','%s',",m_controlid,phrase,varname);
88d42654
VS
209fprintf(m_wxr,"%i,%i,%i,%i,'',\\\n",x,y,width,height);
210fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
211}
212//EDITTEXT IDC_RADIUS,36,65,40,14,ES_AUTOHSCROLL
2193517f 213void rc2wxr::ParseTextCtrl()
88d42654
VS
214{
215wxString tok;
216wxString varname;
217varname=GetToken();
218m_controlid++;
219int x,y,width,height;
220ReadRect(x,y,width,height);
15993304 221fprintf(m_wxr," control = [%i,wxTextCtrl,'','0','%s',",m_controlid,varname);
88d42654
VS
222fprintf(m_wxr,"%i,%i,%i,%i,'',\\\n",x,y,width,height);
223fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
224
225}
226//PUSHBUTTON "Create/Update",IDC_CREATE,15,25,53,13,NOT WS_TABSTOP
2193517f 227void rc2wxr::ParsePushButton()
88d42654
VS
228{
229wxString tok;
230wxString phrase,varname;
231phrase=GetQuoteField();
232varname=GetToken();
233int c;
234m_controlid++;
235c=m_controlid;
236if (varname=="IDOK")
237c=wxID_OK;
238
239if (varname=="IDCANCEL")
240c=wxID_CANCEL;
241
242if (varname=="IDAPPLY")
243c=wxID_APPLY;
244
245int x,y,width,height;
246ReadRect(x,y,width,height);
15993304 247fprintf(m_wxr," control = [%i,wxButton,'%s','0','%s',",c,phrase,varname);
88d42654
VS
248fprintf(m_wxr,"%i,%i,%i,%i,'',\\\n",x,y,width,height);
249fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
250
251}
252
253
2193517f 254bool rc2wxr::Seperator(int ch)
88d42654
VS
255{
256if ((ch==' ')|(ch==',')|(ch==13)|(ch==10)|(ch=='|'))
257 return TRUE;
258
259if (ch==EOF)
260{
2193517f
VS
261m_done=TRUE;
262return TRUE;
88d42654
VS
263}
264return FALSE;
265}
266
2193517f 267void rc2wxr::ParseGroupBox()
88d42654
VS
268{
269// GROUPBOX "Rotate",IDC_STATIC,1,1,71,79
270wxString tok;
271wxString phrase,varname;
272phrase=GetQuoteField();
273varname=GetToken();
274m_controlid++;
275int x,y,width,height;
276ReadRect(x,y,width,height);
15993304 277fprintf(m_wxr," control = [%i,wxStaticBox,'%s','0','%s',",m_controlid,phrase,varname);
88d42654
VS
278fprintf(m_wxr,"%i,%i,%i,%i,'',\\\n",x,y,width,height);
279fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
280
281
282}
283
2193517f 284void rc2wxr::ReadRect(int & x, int & y, int & width, int & height)
88d42654
VS
285{
286x=atoi(GetToken());
287y=atoi(GetToken());
288width=atoi(GetToken());
289height=atoi(GetToken());
290
291}
292
2193517f 293wxString rc2wxr::GetToken()
88d42654
VS
294{
295wxString tok="";
296
297if (m_rc.Eof())
298{
299m_done=TRUE;
300return tok;
301}
302
303int ch=0;
304ReadChar(ch);
305if (ch==EOF)
306{
307m_done=TRUE;
308return tok;
309}
310
311while (Seperator(ch))
312{
313 ReadChar(ch);
314 if (m_done)
2193517f 315 return tok;
88d42654
VS
316}
317
318if (ch==EOF)
319{
2193517f 320m_done=TRUE;
88d42654
VS
321
322}
323
324
325while (!Seperator(ch))
326{
2193517f
VS
327tok+=(char)ch;
328ReadChar(ch);
88d42654
VS
329
330}
331
332if (ch==EOF)
333 m_done=TRUE;
334
335
336return tok;
337}
338
2193517f 339wxString rc2wxr::GetQuoteField()
88d42654
VS
340{
341wxString phrase;
342//ASCII code 34 "
343int ch=0;
344ReadChar(ch);
345
346while (ch!=34)
347 ReadChar(ch);
348
349 ReadChar(ch);
350
351while (ch!=34)
352{
353 phrase+=(char)ch;
354 ReadChar(ch);
355}
356return phrase;
357}
358
2193517f 359void rc2wxr::ReadChar(int &ch)
88d42654
VS
360{
361 int result;
362result=m_rc.Tell();
363
364if((result>=m_filesize))
365 m_done=TRUE;
366
367result=m_rc.Read(&ch,1);
368
369if((result==-1))
370 m_done=TRUE;
371
372if(ch==EOF)
373 m_done=TRUE;
374}
375
2193517f 376void rc2wxr::ParseComboBox()
88d42654
VS
377{
378/* COMBOBOX IDC_SCALECOMBO,10,110,48,52,CBS_DROPDOWNLIST | CBS_SORT |
379 WS_VSCROLL | WS_TABSTOP */
380wxString tok;
381wxString varname;
382varname=GetToken();
383m_controlid++;
384int x,y,width,height;
385ReadRect(x,y,width,height);
386
15993304 387fprintf(m_wxr," control = [%i,wxChoice,'','0','%s',",m_controlid,varname);
88d42654
VS
388fprintf(m_wxr,"%i,%i,%i,%i,[],\\\n",x,y,width,height);
389fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
390
391
392}
393
2193517f 394void rc2wxr::ParseMenu(wxString name)
88d42654
VS
395{
396wxString tok="";
397static int menuid=0;
398menuid++;
15993304 399fprintf(m_wxr,"static char *MenuBar%i = \"menu(name = '%s',\\\n",menuid,name);
88d42654
VS
400fprintf(m_wxr,"menu = \\\n");
401fprintf(m_wxr,"[\\\n");
402
403while ((tok!="BEGIN")&(tok!="{"))
404 tok=GetToken();
405
406while ((tok!="END")&(tok!="}"))
407{
408 tok=GetToken();
409if (tok=="POPUP")
410 {
411 ParsePopupMenu();
412 fprintf(m_wxr," ],\\\n");
413 }
414}
415
416fprintf(m_wxr,"]).\";\n\n");
417}
418
2193517f 419void rc2wxr::ParsePopupMenu()
88d42654
VS
420{
421static int menuitem=99;
422menuitem++;
423
424wxString tok;
425tok=GetQuoteField();
426int spot;
427//Remove /t because it causes problems
428spot=tok.First("\\t");
429tok=tok.Left(spot);
15993304 430fprintf(m_wxr," ['%s',%i,'',\\\n",tok,menuitem);
88d42654
VS
431while ((tok!="BEGIN")&(tok!="{"))
432 tok=GetToken();
433
434while ((tok!="END")&(tok!="}"))
435{
436 tok=GetToken();
437if (tok=="MENUITEM")
2193517f
VS
438{
439if (PeekToken()=="SEPARATOR")
440fprintf(m_wxr," [],\\\n");
441else
442{
443tok=GetQuoteField();
444//Remove /t because it causes problems
445spot=tok.First("\\t");
446tok=tok.Left(spot);
447menuitem++;
15993304 448fprintf(m_wxr," ['%s',%i,''],\\\n",tok,menuitem);
2193517f
VS
449}
450}
88d42654
VS
451
452}
453
454
455}
456
2193517f 457wxString rc2wxr::PeekToken()
88d42654
VS
458{
459wxString tok;
460int p;
461p=m_rc.Tell();
462tok=GetToken();
463
464m_rc.Seek(p);
465return tok;
466}
467//Windows pain in the butt CONTROL
2193517f 468void rc2wxr::ParseControlMS()
88d42654
VS
469{
470wxString label,varname,kindctrl,tok;
471label=GetQuoteField();
472varname=GetToken();
473kindctrl=GetQuoteField();
474kindctrl.MakeUpper();
475
476
477if (kindctrl=="MSCTLS_TRACKBAR32")
478 ParseSlider(label,varname);
479if (kindctrl=="MSCTLS_PROGRESS32")
480 ParseProgressBar(label,varname);
481if (kindctrl=="BUTTON")
482 ParseCtrlButton(label,varname);
483}
484/* CONTROL "Slider1",IDC_SLIDER1,"msctls_trackbar32",TBS_BOTH |
485 TBS_NOTICKS | WS_TABSTOP,52,73,100,15
486*/
487
2193517f 488void rc2wxr::ParseSlider(wxString label, wxString varname)
88d42654 489{
2193517f
VS
490wxString tok;
491while (ReadOrs(tok));
15993304 492fprintf(m_wxr," control = [%i,wxSlider,'','wxSL_HORIZONTAL','%s',",m_controlid,varname);
88d42654
VS
493int x,y,width,height;
494ReadRect(x,y,width,height);
495fprintf(m_wxr,"%i,%i,%i,%i,",x,y,width,height);
496fprintf(m_wxr," 1, 1, 10,\\\n");
497fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
498}
499/*
500CONTROL "Progress1",CG_IDC_PROGDLG_PROGRESS,"msctls_progress32",
501 WS_BORDER,15,52,154,13
502*/
2193517f 503void rc2wxr::ParseProgressBar(wxString label, wxString varname)
88d42654
VS
504{
505wxString tok;
506while (ReadOrs(tok));
15993304 507fprintf(m_wxr," control = [%i,wxGauge,'','wxGA_HORIZONTAL','%s',",m_controlid,varname);
88d42654
VS
508int x,y,width,height;
509ReadRect(x,y,width,height);
510fprintf(m_wxr,"%i,%i,%i,%i,",x,y,width,height);
511fprintf(m_wxr," 0, 10,\\\n");
512fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
513}
514
2193517f 515bool rc2wxr::ReadOrs(wxString & w)
88d42654
VS
516{
517wxString tok;
518tok=PeekToken();
519if (tok.IsNumber())
520 return false;
521w=GetToken();
522return TRUE;
523}
524
525//Is it a check button or a radio button
2193517f 526void rc2wxr::ParseCtrlButton(wxString label, wxString varname)
88d42654
VS
527{
528wxString tok;
2193517f 529tok=GetToken();
88d42654
VS
530
531m_controlid++;
2193517f 532int x,y,width,height;
88d42654
VS
533
534if (tok=="BS_AUTOCHECKBOX")
535{
15993304 536 fprintf(m_wxr," control = [%i,wxCheckBox,'%s','0','%s',",m_controlid,label,varname);
88d42654 537 while (ReadOrs(tok));
2193517f 538 ReadRect(x,y,width,height);
88d42654
VS
539 fprintf(m_wxr,"%i,%i,%i,%i,0,\\\n",x,y,width,height);
540 fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
541}
542
543if (tok=="BS_AUTORADIOBUTTON")
544{
15993304 545 fprintf(m_wxr," control = [%i,wxRadioButton,'%s','0','%s',",m_controlid,label,varname);
88d42654 546 while(ReadOrs(tok));
2193517f 547 ReadRect(x,y,width,height);
88d42654
VS
548 fprintf(m_wxr,"%i,%i,%i,%i,0,\\\n",x,y,width,height);
549 fprintf(m_wxr,"[8, 'wxSWISS', 'wxNORMAL', 'wxNORMAL', 0, 'MS Sans Serif']],\\\n");
550}
551
552
553
554}
555