]> git.saurik.com Git - wxWidgets.git/blob - src/common/resourc2.cpp
Moved fix from 2.2 branch that allows the attributes in MSW wxListCtrl
[wxWidgets.git] / src / common / resourc2.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: resourc2.cpp
3 // Purpose: Resource system (2nd file). Only required for 16-bit BC++.
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "resource.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #if wxUSE_WX_RESOURCES
24
25 #ifdef __VISUALC__
26 #pragma warning(disable:4706) // assignment within conditional expression
27 #endif // VC++
28
29 #ifndef WX_PRECOMP
30 #include "wx/defs.h"
31 #include "wx/setup.h"
32 #include "wx/list.h"
33 #include "wx/hash.h"
34 #include "wx/gdicmn.h"
35 #include "wx/utils.h"
36 #include "wx/types.h"
37 #include "wx/menu.h"
38 #include "wx/stattext.h"
39 #include "wx/button.h"
40 #include "wx/bmpbuttn.h"
41 #include "wx/radiobox.h"
42 #include "wx/listbox.h"
43 #include "wx/choice.h"
44 #include "wx/checkbox.h"
45 #include "wx/settings.h"
46 #include "wx/slider.h"
47 #include "wx/statbox.h"
48 #if wxUSE_GAUGE
49 #include "wx/gauge.h"
50 #endif
51 #include "wx/textctrl.h"
52 #include "wx/msgdlg.h"
53 #include "wx/intl.h"
54 #endif
55
56 #if wxUSE_SCROLLBAR
57 #include "wx/scrolbar.h"
58 #endif
59
60 #if wxUSE_COMBOBOX
61 #include "wx/combobox.h"
62 #endif
63
64 #include "wx/validate.h"
65
66 #include "wx/log.h"
67
68 #include <ctype.h>
69 #include <math.h>
70 #include <stdlib.h>
71 #include <string.h>
72
73 #include "wx/resource.h"
74 #include "wx/string.h"
75 #include "wx/wxexpr.h"
76
77 #include "wx/settings.h"
78
79 #if ((defined(__BORLANDC__) || defined(__SC__)) && defined(__WIN16__))
80
81 // Forward (private) declarations
82 bool wxResourceInterpretResources(wxResourceTable& table, wxExprDatabase& db);
83 wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, wxExpr *expr, bool isPanel = FALSE);
84 wxItemResource *wxResourceInterpretControl(wxResourceTable& table, wxExpr *expr);
85 wxItemResource *wxResourceInterpretMenu(wxResourceTable& table, wxExpr *expr);
86 wxItemResource *wxResourceInterpretMenuBar(wxResourceTable& table, wxExpr *expr);
87 wxItemResource *wxResourceInterpretString(wxResourceTable& table, wxExpr *expr);
88 wxItemResource *wxResourceInterpretBitmap(wxResourceTable& table, wxExpr *expr);
89 wxItemResource *wxResourceInterpretIcon(wxResourceTable& table, wxExpr *expr);
90 // Interpret list expression
91 wxFont wxResourceInterpretFontSpec(wxExpr *expr);
92
93 bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table = (wxResourceTable *) NULL);
94 bool wxResourceParseIncludeFile(const wxString& f, wxResourceTable *table = (wxResourceTable *) NULL);
95
96 extern wxResourceTable *wxDefaultResourceTable;
97
98 extern char *wxResourceBuffer;
99 extern long wxResourceBufferSize;
100 extern long wxResourceBufferCount;
101 extern int wxResourceStringPtr;
102
103 /*
104 * (Re)allocate buffer for reading in from resource file
105 */
106
107 bool wxReallocateResourceBuffer()
108 {
109 if (!wxResourceBuffer)
110 {
111 wxResourceBufferSize = 1000;
112 wxResourceBuffer = new char[wxResourceBufferSize];
113 return TRUE;
114 }
115 if (wxResourceBuffer)
116 {
117 long newSize = wxResourceBufferSize + 1000;
118 char *tmp = new char[(int)newSize];
119 strncpy(tmp, wxResourceBuffer, (int)wxResourceBufferCount);
120 delete[] wxResourceBuffer;
121 wxResourceBuffer = tmp;
122 wxResourceBufferSize = newSize;
123 }
124 return TRUE;
125 }
126
127 static bool wxEatWhiteSpace(FILE *fd)
128 {
129 int ch = getc(fd);
130 if ((ch != ' ') && (ch != '/') && (ch != ' ') && (ch != 10) && (ch != 13) && (ch != 9))
131 {
132 ungetc(ch, fd);
133 return TRUE;
134 }
135
136 // Eat whitespace
137 while (ch == ' ' || ch == 10 || ch == 13 || ch == 9)
138 ch = getc(fd);
139 // Check for comment
140 if (ch == '/')
141 {
142 ch = getc(fd);
143 if (ch == '*')
144 {
145 bool finished = FALSE;
146 while (!finished)
147 {
148 ch = getc(fd);
149 if (ch == EOF)
150 return FALSE;
151 if (ch == '*')
152 {
153 int newCh = getc(fd);
154 if (newCh == '/')
155 finished = TRUE;
156 else
157 {
158 ungetc(newCh, fd);
159 }
160 }
161 }
162 }
163 else // False alarm
164 return FALSE;
165 }
166 else
167 ungetc(ch, fd);
168 return wxEatWhiteSpace(fd);
169 }
170
171 bool wxGetResourceToken(FILE *fd)
172 {
173 if (!wxResourceBuffer)
174 wxReallocateResourceBuffer();
175 wxResourceBuffer[0] = 0;
176 wxEatWhiteSpace(fd);
177
178 int ch = getc(fd);
179 if (ch == '"')
180 {
181 // Get string
182 wxResourceBufferCount = 0;
183 ch = getc(fd);
184 while (ch != '"')
185 {
186 int actualCh = ch;
187 if (ch == EOF)
188 {
189 wxResourceBuffer[wxResourceBufferCount] = 0;
190 return FALSE;
191 }
192 // Escaped characters
193 else if (ch == '\\')
194 {
195 int newCh = getc(fd);
196 if (newCh == '"')
197 actualCh = '"';
198 else if (newCh == 10)
199 actualCh = 10;
200 else
201 {
202 ungetc(newCh, fd);
203 }
204 }
205
206 if (wxResourceBufferCount >= wxResourceBufferSize-1)
207 wxReallocateResourceBuffer();
208 wxResourceBuffer[wxResourceBufferCount] = (char)actualCh;
209 wxResourceBufferCount ++;
210 ch = getc(fd);
211 }
212 wxResourceBuffer[wxResourceBufferCount] = 0;
213 }
214 else
215 {
216 wxResourceBufferCount = 0;
217 // Any other token
218 while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10)
219 {
220 if (wxResourceBufferCount >= wxResourceBufferSize-1)
221 wxReallocateResourceBuffer();
222 wxResourceBuffer[wxResourceBufferCount] = (char)ch;
223 wxResourceBufferCount ++;
224
225 ch = getc(fd);
226 }
227 wxResourceBuffer[wxResourceBufferCount] = 0;
228 if (ch == EOF)
229 return FALSE;
230 }
231 return TRUE;
232 }
233
234 /*
235 * Files are in form:
236 static char *name = "....";
237 with possible comments.
238 */
239
240 bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table)
241 {
242 if (!table)
243 table = wxDefaultResourceTable;
244
245 // static or #define
246 if (!wxGetResourceToken(fd))
247 {
248 *eof = TRUE;
249 return FALSE;
250 }
251
252 if (strcmp(wxResourceBuffer, "#define") == 0)
253 {
254 wxGetResourceToken(fd);
255 char *name = copystring(wxResourceBuffer);
256 wxGetResourceToken(fd);
257 char *value = copystring(wxResourceBuffer);
258 if (isalpha(value[0]))
259 {
260 int val = (int)atol(value);
261 wxResourceAddIdentifier(name, val, table);
262 }
263 else
264 {
265 wxLogWarning(_("#define %s must be an integer."), name);
266 delete[] name;
267 delete[] value;
268 return FALSE;
269 }
270 delete[] name;
271 delete[] value;
272
273 return TRUE;
274 }
275 else if (strcmp(wxResourceBuffer, "#include") == 0)
276 {
277 wxGetResourceToken(fd);
278 char *name = copystring(wxResourceBuffer);
279 char *actualName = name;
280 if (name[0] == '"')
281 actualName = name + 1;
282 int len = strlen(name);
283 if ((len > 0) && (name[len-1] == '"'))
284 name[len-1] = 0;
285 if (!wxResourceParseIncludeFile(actualName, table))
286 {
287 wxLogWarning(_("Could not find resource include file %s."), actualName);
288 }
289 delete[] name;
290 return TRUE;
291 }
292 else if (strcmp(wxResourceBuffer, "static") != 0)
293 {
294 char buf[300];
295 strcpy(buf, _("Found "));
296 strncat(buf, wxResourceBuffer, 30);
297 strcat(buf, _(", expected static, #include or #define\nwhilst parsing resource."));
298 wxLogWarning(buf);
299 return FALSE;
300 }
301
302 // char
303 if (!wxGetResourceToken(fd))
304 {
305 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
306 *eof = TRUE;
307 return FALSE;
308 }
309
310 if (strcmp(wxResourceBuffer, "char") != 0)
311 {
312 wxLogWarning(_("Expected 'char' whilst parsing resource."));
313 return FALSE;
314 }
315
316 // *name
317 if (!wxGetResourceToken(fd))
318 {
319 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
320 *eof = TRUE;
321 return FALSE;
322 }
323
324 if (wxResourceBuffer[0] != '*')
325 {
326 wxLogWarning(_("Expected '*' whilst parsing resource."));
327 return FALSE;
328 }
329 char nameBuf[100];
330 strncpy(nameBuf, wxResourceBuffer+1, 99);
331
332 // =
333 if (!wxGetResourceToken(fd))
334 {
335 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
336 *eof = TRUE;
337 return FALSE;
338 }
339
340 if (strcmp(wxResourceBuffer, "=") != 0)
341 {
342 wxLogWarning(_("Expected '=' whilst parsing resource."));
343 return FALSE;
344 }
345
346 // String
347 if (!wxGetResourceToken(fd))
348 {
349 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
350 *eof = TRUE;
351 return FALSE;
352 }
353 else
354 {
355 if (!db.ReadPrologFromString(wxResourceBuffer))
356 {
357 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf);
358 return FALSE;
359 }
360 }
361 // Semicolon
362 if (!wxGetResourceToken(fd))
363 {
364 *eof = TRUE;
365 }
366 return TRUE;
367 }
368
369 /*
370 * Parses string window style into integer window style
371 */
372
373 /*
374 * Style flag parsing, e.g.
375 * "wxSYSTEM_MENU | wxBORDER" -> integer
376 */
377
378 char* wxResourceParseWord(char*s, int *i)
379 {
380 if (!s)
381 return (char*) NULL;
382
383 static char buf[150];
384 int len = strlen(s);
385 int j = 0;
386 int ii = *i;
387 while ((ii < len) && (isalpha(s[ii]) || (s[ii] == '_')))
388 {
389 buf[j] = s[ii];
390 j ++;
391 ii ++;
392 }
393 buf[j] = 0;
394
395 // Eat whitespace and conjunction characters
396 while ((ii < len) &&
397 ((s[ii] == ' ') || (s[ii] == '|') || (s[ii] == ',')))
398 {
399 ii ++;
400 }
401 *i = ii;
402 if (j == 0)
403 return (char*) NULL;
404 else
405 return buf;
406 }
407
408 struct wxResourceBitListStruct
409 {
410 char *word;
411 long bits;
412 };
413
414 static wxResourceBitListStruct wxResourceBitListTable[] =
415 {
416 /* wxListBox */
417 { "wxSINGLE", wxLB_SINGLE },
418 { "wxMULTIPLE", wxLB_MULTIPLE },
419 { "wxEXTENDED", wxLB_EXTENDED },
420 { "wxLB_SINGLE", wxLB_SINGLE },
421 { "wxLB_MULTIPLE", wxLB_MULTIPLE },
422 { "wxLB_EXTENDED", wxLB_EXTENDED },
423 { "wxLB_NEEDED_SB", wxLB_NEEDED_SB },
424 { "wxLB_ALWAYS_SB", wxLB_ALWAYS_SB },
425 { "wxLB_SORT", wxLB_SORT },
426 { "wxLB_OWNERDRAW", wxLB_OWNERDRAW },
427 { "wxLB_HSCROLL", wxLB_HSCROLL },
428
429 /* wxComboxBox */
430 { "wxCB_SIMPLE", wxCB_SIMPLE },
431 { "wxCB_DROPDOWN", wxCB_DROPDOWN },
432 { "wxCB_READONLY", wxCB_READONLY },
433 { "wxCB_SORT", wxCB_SORT },
434
435 /* wxGauge */
436 { "wxGA_PROGRESSBAR", wxGA_PROGRESSBAR },
437 { "wxGA_HORIZONTAL", wxGA_HORIZONTAL },
438 { "wxGA_VERTICAL", wxGA_VERTICAL },
439
440 /* wxTextCtrl */
441 { "wxPASSWORD", wxPASSWORD},
442 { "wxPROCESS_ENTER", wxPROCESS_ENTER},
443 { "wxTE_PASSWORD", wxTE_PASSWORD},
444 { "wxTE_READONLY", wxTE_READONLY},
445 { "wxTE_PROCESS_ENTER", wxTE_PROCESS_ENTER},
446 { "wxTE_MULTILINE", wxTE_MULTILINE},
447
448 /* wxRadioBox/wxRadioButton */
449 { "wxRB_GROUP", wxRB_GROUP },
450 { "wxRA_SPECIFY_COLS", wxRA_SPECIFY_COLS },
451 { "wxRA_SPECIFY_ROWS", wxRA_SPECIFY_ROWS },
452 { "wxRA_HORIZONTAL", wxRA_HORIZONTAL },
453 { "wxRA_VERTICAL", wxRA_VERTICAL },
454
455 /* wxSlider */
456 { "wxSL_HORIZONTAL", wxSL_HORIZONTAL },
457 { "wxSL_VERTICAL", wxSL_VERTICAL },
458 { "wxSL_AUTOTICKS", wxSL_AUTOTICKS },
459 { "wxSL_LABELS", wxSL_LABELS },
460 { "wxSL_LEFT", wxSL_LEFT },
461 { "wxSL_TOP", wxSL_TOP },
462 { "wxSL_RIGHT", wxSL_RIGHT },
463 { "wxSL_BOTTOM", wxSL_BOTTOM },
464 { "wxSL_BOTH", wxSL_BOTH },
465 { "wxSL_SELRANGE", wxSL_SELRANGE },
466
467 /* wxScrollBar */
468 { "wxSB_HORIZONTAL", wxSB_HORIZONTAL },
469 { "wxSB_VERTICAL", wxSB_VERTICAL },
470
471 /* wxButton */
472 { "wxBU_AUTODRAW", wxBU_AUTODRAW },
473 { "wxBU_NOAUTODRAW", wxBU_NOAUTODRAW },
474
475 /* wxTreeCtrl */
476 { "wxTR_HAS_BUTTONS", wxTR_HAS_BUTTONS },
477 { "wxTR_EDIT_LABELS", wxTR_EDIT_LABELS },
478 { "wxTR_LINES_AT_ROOT", wxTR_LINES_AT_ROOT },
479
480 /* wxListCtrl */
481 { "wxLC_ICON", wxLC_ICON },
482 { "wxLC_SMALL_ICON", wxLC_SMALL_ICON },
483 { "wxLC_LIST", wxLC_LIST },
484 { "wxLC_REPORT", wxLC_REPORT },
485 { "wxLC_ALIGN_TOP", wxLC_ALIGN_TOP },
486 { "wxLC_ALIGN_LEFT", wxLC_ALIGN_LEFT },
487 { "wxLC_AUTOARRANGE", wxLC_AUTOARRANGE },
488 { "wxLC_USER_TEXT", wxLC_USER_TEXT },
489 { "wxLC_EDIT_LABELS", wxLC_EDIT_LABELS },
490 { "wxLC_NO_HEADER", wxLC_NO_HEADER },
491 { "wxLC_NO_SORT_HEADER", wxLC_NO_SORT_HEADER },
492 { "wxLC_SINGLE_SEL", wxLC_SINGLE_SEL },
493 { "wxLC_SORT_ASCENDING", wxLC_SORT_ASCENDING },
494 { "wxLC_SORT_DESCENDING", wxLC_SORT_DESCENDING },
495
496 /* wxSpinButton */
497 { "wxSP_VERTICAL", wxSP_VERTICAL},
498 { "wxSP_HORIZONTAL", wxSP_HORIZONTAL},
499 { "wxSP_ARROW_KEYS", wxSP_ARROW_KEYS},
500 { "wxSP_WRAP", wxSP_WRAP},
501
502 /* wxSplitterWnd */
503 { "wxSP_NOBORDER", wxSP_NOBORDER},
504 { "wxSP_3D", wxSP_3D},
505 { "wxSP_BORDER", wxSP_BORDER},
506
507 /* wxTabCtrl */
508 { "wxTC_MULTILINE", wxTC_MULTILINE},
509 { "wxTC_RIGHTJUSTIFY", wxTC_RIGHTJUSTIFY},
510 { "wxTC_FIXEDWIDTH", wxTC_FIXEDWIDTH},
511 { "wxTC_OWNERDRAW", wxTC_OWNERDRAW},
512
513 /* wxStatusBar95 */
514 { "wxST_SIZEGRIP", wxST_SIZEGRIP},
515
516 /* wxControl */
517 { "wxFIXED_LENGTH", wxFIXED_LENGTH},
518 { "wxALIGN_LEFT", wxALIGN_LEFT},
519 { "wxALIGN_CENTER", wxALIGN_CENTER},
520 { "wxALIGN_CENTRE", wxALIGN_CENTRE},
521 { "wxALIGN_RIGHT", wxALIGN_RIGHT},
522 { "wxCOLOURED", wxCOLOURED},
523
524 /* wxToolBar */
525 { "wxTB_3DBUTTONS", wxTB_3DBUTTONS},
526 { "wxTB_HORIZONTAL", wxTB_HORIZONTAL},
527 { "wxTB_VERTICAL", wxTB_VERTICAL},
528 { "wxTB_FLAT", wxTB_FLAT},
529
530 /* Generic */
531 { "wxVSCROLL", wxVSCROLL },
532 { "wxHSCROLL", wxHSCROLL },
533 { "wxCAPTION", wxCAPTION },
534 { "wxSTAY_ON_TOP", wxSTAY_ON_TOP},
535 { "wxICONIZE", wxICONIZE},
536 { "wxMINIMIZE", wxICONIZE},
537 { "wxMAXIMIZE", wxMAXIMIZE},
538 { "wxSDI", 0},
539 { "wxMDI_PARENT", 0},
540 { "wxMDI_CHILD", 0},
541 { "wxTHICK_FRAME", wxTHICK_FRAME},
542 { "wxRESIZE_BORDER", wxRESIZE_BORDER},
543 { "wxSYSTEM_MENU", wxSYSTEM_MENU},
544 { "wxMINIMIZE_BOX", wxMINIMIZE_BOX},
545 { "wxMAXIMIZE_BOX", wxMAXIMIZE_BOX},
546 { "wxRESIZE_BOX", wxRESIZE_BOX},
547 { "wxDEFAULT_FRAME_STYLE", wxDEFAULT_FRAME_STYLE},
548 { "wxDEFAULT_FRAME", wxDEFAULT_FRAME_STYLE},
549 { "wxDEFAULT_DIALOG_STYLE", wxDEFAULT_DIALOG_STYLE},
550 { "wxBORDER", wxBORDER},
551 { "wxRETAINED", wxRETAINED},
552 { "wxNATIVE_IMPL", 0},
553 { "wxEXTENDED_IMPL", 0},
554 { "wxBACKINGSTORE", wxBACKINGSTORE},
555 // { "wxFLAT", wxFLAT},
556 // { "wxMOTIF_RESIZE", wxMOTIF_RESIZE},
557 { "wxFIXED_LENGTH", 0},
558 { "wxDOUBLE_BORDER", wxDOUBLE_BORDER},
559 { "wxSUNKEN_BORDER", wxSUNKEN_BORDER},
560 { "wxRAISED_BORDER", wxRAISED_BORDER},
561 { "wxSIMPLE_BORDER", wxSIMPLE_BORDER},
562 { "wxSTATIC_BORDER", wxSTATIC_BORDER},
563 { "wxTRANSPARENT_WINDOW", wxTRANSPARENT_WINDOW},
564 { "wxNO_BORDER", wxNO_BORDER},
565 { "wxCLIP_CHILDREN", wxCLIP_CHILDREN},
566
567 { "wxTINY_CAPTION_HORIZ", wxTINY_CAPTION_HORIZ},
568 { "wxTINY_CAPTION_VERT", wxTINY_CAPTION_VERT},
569
570 // Text font families
571 { "wxDEFAULT", wxDEFAULT},
572 { "wxDECORATIVE", wxDECORATIVE},
573 { "wxROMAN", wxROMAN},
574 { "wxSCRIPT", wxSCRIPT},
575 { "wxSWISS", wxSWISS},
576 { "wxMODERN", wxMODERN},
577 { "wxTELETYPE", wxTELETYPE},
578 { "wxVARIABLE", wxVARIABLE},
579 { "wxFIXED", wxFIXED},
580 { "wxNORMAL", wxNORMAL},
581 { "wxLIGHT", wxLIGHT},
582 { "wxBOLD", wxBOLD},
583 { "wxITALIC", wxITALIC},
584 { "wxSLANT", wxSLANT},
585 { "wxSOLID", wxSOLID},
586 { "wxDOT", wxDOT},
587 { "wxLONG_DASH", wxLONG_DASH},
588 { "wxSHORT_DASH", wxSHORT_DASH},
589 { "wxDOT_DASH", wxDOT_DASH},
590 { "wxUSER_DASH", wxUSER_DASH},
591 { "wxTRANSPARENT", wxTRANSPARENT},
592 { "wxSTIPPLE", wxSTIPPLE},
593 { "wxBDIAGONAL_HATCH", wxBDIAGONAL_HATCH},
594 { "wxCROSSDIAG_HATCH", wxCROSSDIAG_HATCH},
595 { "wxFDIAGONAL_HATCH", wxFDIAGONAL_HATCH},
596 { "wxCROSS_HATCH", wxCROSS_HATCH},
597 { "wxHORIZONTAL_HATCH", wxHORIZONTAL_HATCH},
598 { "wxVERTICAL_HATCH", wxVERTICAL_HATCH},
599 { "wxJOIN_BEVEL", wxJOIN_BEVEL},
600 { "wxJOIN_MITER", wxJOIN_MITER},
601 { "wxJOIN_ROUND", wxJOIN_ROUND},
602 { "wxCAP_ROUND", wxCAP_ROUND},
603 { "wxCAP_PROJECTING", wxCAP_PROJECTING},
604 { "wxCAP_BUTT", wxCAP_BUTT},
605
606 // Logical ops
607 { "wxCLEAR", wxCLEAR},
608 { "wxXOR", wxXOR},
609 { "wxINVERT", wxINVERT},
610 { "wxOR_REVERSE", wxOR_REVERSE},
611 { "wxAND_REVERSE", wxAND_REVERSE},
612 { "wxCOPY", wxCOPY},
613 { "wxAND", wxAND},
614 { "wxAND_INVERT", wxAND_INVERT},
615 { "wxNO_OP", wxNO_OP},
616 { "wxNOR", wxNOR},
617 { "wxEQUIV", wxEQUIV},
618 { "wxSRC_INVERT", wxSRC_INVERT},
619 { "wxOR_INVERT", wxOR_INVERT},
620 { "wxNAND", wxNAND},
621 { "wxOR", wxOR},
622 { "wxSET", wxSET},
623
624 { "wxFLOOD_SURFACE", wxFLOOD_SURFACE},
625 { "wxFLOOD_BORDER", wxFLOOD_BORDER},
626 { "wxODDEVEN_RULE", wxODDEVEN_RULE},
627 { "wxWINDING_RULE", wxWINDING_RULE},
628 { "wxHORIZONTAL", wxHORIZONTAL},
629 { "wxVERTICAL", wxVERTICAL},
630 { "wxBOTH", wxBOTH},
631 { "wxCENTER_FRAME", wxCENTER_FRAME},
632 { "wxOK", wxOK},
633 { "wxYES_NO", wxYES_NO},
634 { "wxCANCEL", wxCANCEL},
635 { "wxYES", wxYES},
636 { "wxNO", wxNO},
637 { "wxICON_EXCLAMATION", wxICON_EXCLAMATION},
638 { "wxICON_HAND", wxICON_HAND},
639 { "wxICON_QUESTION", wxICON_QUESTION},
640 { "wxICON_INFORMATION", wxICON_INFORMATION},
641 { "wxICON_STOP", wxICON_STOP},
642 { "wxICON_ASTERISK", wxICON_ASTERISK},
643 { "wxICON_MASK", wxICON_MASK},
644 { "wxCENTRE", wxCENTRE},
645 { "wxCENTER", wxCENTRE},
646 { "wxUSER_COLOURS", wxUSER_COLOURS},
647 { "wxVERTICAL_LABEL", 0},
648 { "wxHORIZONTAL_LABEL", 0},
649
650 // Bitmap types (not strictly styles)
651 { "wxBITMAP_TYPE_XPM", wxBITMAP_TYPE_XPM},
652 { "wxBITMAP_TYPE_XBM", wxBITMAP_TYPE_XBM},
653 { "wxBITMAP_TYPE_BMP", wxBITMAP_TYPE_BMP},
654 { "wxBITMAP_TYPE_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE},
655 { "wxBITMAP_TYPE_BMP_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE},
656 { "wxBITMAP_TYPE_GIF", wxBITMAP_TYPE_GIF},
657 { "wxBITMAP_TYPE_TIF", wxBITMAP_TYPE_TIF},
658 { "wxBITMAP_TYPE_ICO", wxBITMAP_TYPE_ICO},
659 { "wxBITMAP_TYPE_ICO_RESOURCE", wxBITMAP_TYPE_ICO_RESOURCE},
660 { "wxBITMAP_TYPE_CUR", wxBITMAP_TYPE_CUR},
661 { "wxBITMAP_TYPE_CUR_RESOURCE", wxBITMAP_TYPE_CUR_RESOURCE},
662 { "wxBITMAP_TYPE_XBM_DATA", wxBITMAP_TYPE_XBM_DATA},
663 { "wxBITMAP_TYPE_XPM_DATA", wxBITMAP_TYPE_XPM_DATA},
664 { "wxBITMAP_TYPE_ANY", wxBITMAP_TYPE_ANY}
665 };
666
667 static int wxResourceBitListCount = (sizeof(wxResourceBitListTable)/sizeof(wxResourceBitListStruct));
668
669 long wxParseWindowStyle(const wxString& bitListString)
670 {
671 int i = 0;
672 char *word;
673 long bitList = 0;
674 while ((word = wxResourceParseWord((char*) (const char*) bitListString, &i)))
675 {
676 bool found = FALSE;
677 int j;
678 for (j = 0; j < wxResourceBitListCount; j++)
679 if (strcmp(wxResourceBitListTable[j].word, word) == 0)
680 {
681 bitList |= wxResourceBitListTable[j].bits;
682 found = TRUE;
683 break;
684 }
685 if (!found)
686 {
687 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word);
688 return 0;
689 }
690 }
691 return bitList;
692 }
693
694 /*
695 * Load a bitmap from a wxWindows resource, choosing an optimum
696 * depth and appropriate type.
697 */
698
699 wxBitmap wxResourceCreateBitmap(const wxString& resource, wxResourceTable *table)
700 {
701 if (!table)
702 table = wxDefaultResourceTable;
703
704 wxItemResource *item = table->FindResource(resource);
705 if (item)
706 {
707 if ((item->GetType() == "") || (item->GetType() != "wxBitmap"))
708 {
709 wxLogWarning(_("%s not a bitmap resource specification."), (const char*) resource);
710 return wxNullBitmap;
711 }
712 int thisDepth = wxDisplayDepth();
713 long thisNoColours = (long)pow(2.0, (double)thisDepth);
714
715 wxItemResource *optResource = (wxItemResource *) NULL;
716
717 // Try to find optimum bitmap for this platform/colour depth
718 wxNode *node = item->GetChildren().First();
719 while (node)
720 {
721 wxItemResource *child = (wxItemResource *)node->Data();
722 int platform = (int)child->GetValue2();
723 int noColours = (int)child->GetValue3();
724 /*
725 char *name = child->GetName();
726 int bitmapType = (int)child->GetValue1();
727 int xRes = child->GetWidth();
728 int yRes = child->GetHeight();
729 */
730
731 switch (platform)
732 {
733 case RESOURCE_PLATFORM_ANY:
734 {
735 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
736 optResource = child;
737 else
738 {
739 // Maximise the number of colours.
740 // If noColours is zero (unspecified), then assume this
741 // is the right one.
742 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
743 optResource = child;
744 }
745 break;
746 }
747 #ifdef __WXMSW__
748 case RESOURCE_PLATFORM_WINDOWS:
749 {
750 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
751 optResource = child;
752 else
753 {
754 // Maximise the number of colours
755 if ((noColours > 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
756 optResource = child;
757 }
758 break;
759 }
760 #endif
761 #ifdef __WXGTK__
762 case RESOURCE_PLATFORM_X:
763 {
764 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
765 optResource = child;
766 else
767 {
768 // Maximise the number of colours
769 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
770 optResource = child;
771 }
772 break;
773 }
774 #endif
775 #ifdef wx_max
776 case RESOURCE_PLATFORM_MAC:
777 {
778 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
779 optResource = child;
780 else
781 {
782 // Maximise the number of colours
783 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
784 optResource = child;
785 }
786 break;
787 }
788 #endif
789 default:
790 break;
791 }
792 node = node->Next();
793 }
794 // If no matching resource, fail.
795 if (!optResource)
796 return wxNullBitmap;
797
798 wxString name = optResource->GetName();
799 int bitmapType = (int)optResource->GetValue1();
800 switch (bitmapType)
801 {
802 case wxBITMAP_TYPE_XBM_DATA:
803 {
804 #ifdef __WXGTK__
805 wxItemResource *item = table->FindResource(name);
806 if (!item)
807 {
808 wxLogWarning(_("Failed to find XBM resource %s.\n"
809 "Forgot to use wxResourceLoadBitmapData?"), (const char*) name);
810 return wxNullBitmap;
811 }
812 return wxBitmap(item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3()) ;
813 #else
814 wxLogWarning(_("No XBM facility available!"));
815 #endif
816 break;
817 }
818 case wxBITMAP_TYPE_XPM_DATA:
819 {
820 wxItemResource *item = table->FindResource(name);
821 if (!item)
822 {
823 wxLogWarning(_("Failed to find XPM resource %s.\n"
824 "Forgot to use wxResourceLoadBitmapData?"), (const char*) name);
825 return wxNullBitmap;
826 }
827 return wxBitmap(item->GetValue1());
828 break;
829 }
830 default:
831 {
832 return wxBitmap(name, bitmapType);
833 break;
834 }
835 }
836 return wxNullBitmap;
837 }
838 else
839 {
840 wxLogWarning(_("Bitmap resource specification %s not found."), (const char*) resource);
841 return wxNullBitmap;
842 }
843 }
844
845 /*
846 * Load an icon from a wxWindows resource, choosing an optimum
847 * depth and appropriate type.
848 */
849
850 wxIcon wxResourceCreateIcon(const wxString& resource, wxResourceTable *table)
851 {
852 if (!table)
853 table = wxDefaultResourceTable;
854
855 wxItemResource *item = table->FindResource(resource);
856 if (item)
857 {
858 if ((item->GetType() == "") || (item->GetType() != "wxIcon"))
859 {
860 wxLogWarning(_("%s not an icon resource specification."), (const char*) resource);
861 return wxNullIcon;
862 }
863 int thisDepth = wxDisplayDepth();
864 long thisNoColours = (long)pow(2.0, (double)thisDepth);
865
866 wxItemResource *optResource = (wxItemResource *) NULL;
867
868 // Try to find optimum icon for this platform/colour depth
869 wxNode *node = item->GetChildren().First();
870 while (node)
871 {
872 wxItemResource *child = (wxItemResource *)node->Data();
873 int platform = (int)child->GetValue2();
874 int noColours = (int)child->GetValue3();
875 /*
876 char *name = child->GetName();
877 int bitmapType = (int)child->GetValue1();
878 int xRes = child->GetWidth();
879 int yRes = child->GetHeight();
880 */
881
882 switch (platform)
883 {
884 case RESOURCE_PLATFORM_ANY:
885 {
886 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
887 optResource = child;
888 else
889 {
890 // Maximise the number of colours.
891 // If noColours is zero (unspecified), then assume this
892 // is the right one.
893 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
894 optResource = child;
895 }
896 break;
897 }
898 #ifdef __WXMSW__
899 case RESOURCE_PLATFORM_WINDOWS:
900 {
901 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
902 optResource = child;
903 else
904 {
905 // Maximise the number of colours
906 if ((noColours > 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
907 optResource = child;
908 }
909 break;
910 }
911 #endif
912 #ifdef __WXGTK__
913 case RESOURCE_PLATFORM_X:
914 {
915 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
916 optResource = child;
917 else
918 {
919 // Maximise the number of colours
920 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
921 optResource = child;
922 }
923 break;
924 }
925 #endif
926 #ifdef wx_max
927 case RESOURCE_PLATFORM_MAC:
928 {
929 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
930 optResource = child;
931 else
932 {
933 // Maximise the number of colours
934 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
935 optResource = child;
936 }
937 break;
938 }
939 #endif
940 default:
941 break;
942 }
943 node = node->Next();
944 }
945 // If no matching resource, fail.
946 if (!optResource)
947 return wxNullIcon;
948
949 wxString name = optResource->GetName();
950 int bitmapType = (int)optResource->GetValue1();
951 switch (bitmapType)
952 {
953 case wxBITMAP_TYPE_XBM_DATA:
954 {
955 #ifdef __WXGTK__
956 wxItemResource *item = table->FindResource(name);
957 if (!item)
958 {
959 wxLogWarning(_("Failed to find XBM resource %s.\n"
960 "Forgot to use wxResourceLoadIconData?"), (const char*) name);
961 return wxNullIcon;
962 }
963 return wxIcon((const char **)item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3());
964 #else
965 wxLogWarning(_("No XBM facility available!"));
966 #endif
967 break;
968 }
969 case wxBITMAP_TYPE_XPM_DATA:
970 {
971 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
972 /*
973 wxItemResource *item = table->FindResource(name);
974 if (!item)
975 {
976 char buf[400];
977 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
978 wxLogWarning(buf);
979 return NULL;
980 }
981 return wxIcon((char **)item->GetValue1());
982 */
983 wxLogWarning(_("No XPM icon facility available!"));
984 break;
985 }
986 default:
987 {
988 #ifdef __WXGTK__
989 wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource);
990 #else
991 return wxIcon(name, bitmapType);
992 #endif
993 break;
994 }
995 }
996 return wxNullIcon;
997 }
998 else
999 {
1000 wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource);
1001 return wxNullIcon;
1002 }
1003 }
1004
1005 wxMenu *wxResourceCreateMenu(wxItemResource *item)
1006 {
1007 wxMenu *menu = new wxMenu;
1008 wxNode *node = item->GetChildren().First();
1009 while (node)
1010 {
1011 wxItemResource *child = (wxItemResource *)node->Data();
1012 if ((child->GetType() != "") && (child->GetType() == "wxMenuSeparator"))
1013 menu->AppendSeparator();
1014 else if (child->GetChildren().Number() > 0)
1015 {
1016 wxMenu *subMenu = wxResourceCreateMenu(child);
1017 if (subMenu)
1018 menu->Append((int)child->GetValue1(), child->GetTitle(), subMenu, child->GetValue4());
1019 }
1020 else
1021 {
1022 menu->Append((int)child->GetValue1(), child->GetTitle(), child->GetValue4(), (child->GetValue2() != 0));
1023 }
1024 node = node->Next();
1025 }
1026 return menu;
1027 }
1028
1029 wxMenuBar *wxResourceCreateMenuBar(const wxString& resource, wxResourceTable *table, wxMenuBar *menuBar)
1030 {
1031 if (!table)
1032 table = wxDefaultResourceTable;
1033
1034 wxItemResource *menuResource = table->FindResource(resource);
1035 if (menuResource && (menuResource->GetType() != "") && (menuResource->GetType() == "wxMenu"))
1036 {
1037 if (!menuBar)
1038 menuBar = new wxMenuBar;
1039 wxNode *node = menuResource->GetChildren().First();
1040 while (node)
1041 {
1042 wxItemResource *child = (wxItemResource *)node->Data();
1043 wxMenu *menu = wxResourceCreateMenu(child);
1044 if (menu)
1045 menuBar->Append(menu, child->GetTitle());
1046 node = node->Next();
1047 }
1048 return menuBar;
1049 }
1050 return (wxMenuBar *) NULL;
1051 }
1052
1053 wxMenu *wxResourceCreateMenu(const wxString& resource, wxResourceTable *table)
1054 {
1055 if (!table)
1056 table = wxDefaultResourceTable;
1057
1058 wxItemResource *menuResource = table->FindResource(resource);
1059 if (menuResource && (menuResource->GetType() != "") && (menuResource->GetType() == "wxMenu"))
1060 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
1061 return wxResourceCreateMenu(menuResource);
1062 return (wxMenu *) NULL;
1063 }
1064
1065 // Global equivalents (so don't have to refer to default table explicitly)
1066 bool wxResourceParseData(const wxString& resource, wxResourceTable *table)
1067 {
1068 if (!table)
1069 table = wxDefaultResourceTable;
1070
1071 return table->ParseResourceData(resource);
1072 }
1073
1074 bool wxResourceParseFile(const wxString& filename, wxResourceTable *table)
1075 {
1076 if (!table)
1077 table = wxDefaultResourceTable;
1078
1079 return table->ParseResourceFile(filename);
1080 }
1081
1082 // Register XBM/XPM data
1083 bool wxResourceRegisterBitmapData(const wxString& name, char bits[], int width, int height, wxResourceTable *table)
1084 {
1085 if (!table)
1086 table = wxDefaultResourceTable;
1087
1088 return table->RegisterResourceBitmapData(name, bits, width, height);
1089 }
1090
1091 bool wxResourceRegisterBitmapData(const wxString& name, char **data, wxResourceTable *table)
1092 {
1093 if (!table)
1094 table = wxDefaultResourceTable;
1095
1096 return table->RegisterResourceBitmapData(name, data);
1097 }
1098
1099 void wxResourceClear(wxResourceTable *table)
1100 {
1101 if (!table)
1102 table = wxDefaultResourceTable;
1103
1104 table->ClearTable();
1105 }
1106
1107 /*
1108 * Identifiers
1109 */
1110
1111 bool wxResourceAddIdentifier(const wxString& name, int value, wxResourceTable *table)
1112 {
1113 if (!table)
1114 table = wxDefaultResourceTable;
1115
1116 table->identifiers.Put(name, (wxObject *)value);
1117 return TRUE;
1118 }
1119
1120 int wxResourceGetIdentifier(const wxString& name, wxResourceTable *table)
1121 {
1122 if (!table)
1123 table = wxDefaultResourceTable;
1124
1125 return (int)table->identifiers.Get(name);
1126 }
1127
1128 /*
1129 * Parse #include file for #defines (only)
1130 */
1131
1132 bool wxResourceParseIncludeFile(const wxString& f, wxResourceTable *table)
1133 {
1134 if (!table)
1135 table = wxDefaultResourceTable;
1136
1137 FILE *fd = fopen(f, "r");
1138 if (!fd)
1139 {
1140 return FALSE;
1141 }
1142 while (wxGetResourceToken(fd))
1143 {
1144 if (strcmp(wxResourceBuffer, "#define") == 0)
1145 {
1146 wxGetResourceToken(fd);
1147 char *name = copystring(wxResourceBuffer);
1148 wxGetResourceToken(fd);
1149 char *value = copystring(wxResourceBuffer);
1150 if (isdigit(value[0]))
1151 {
1152 int val = (int)atol(value);
1153 wxResourceAddIdentifier(name, val, table);
1154 }
1155 delete[] name;
1156 delete[] value;
1157 }
1158 }
1159 fclose(fd);
1160 return TRUE;
1161 }
1162
1163 /*
1164 * Reading strings as if they were .wxr files
1165 */
1166
1167 static int getc_string(char *s)
1168 {
1169 int ch = s[wxResourceStringPtr];
1170 if (ch == 0)
1171 return EOF;
1172 else
1173 {
1174 wxResourceStringPtr ++;
1175 return ch;
1176 }
1177 }
1178
1179 static int ungetc_string()
1180 {
1181 wxResourceStringPtr --;
1182 return 0;
1183 }
1184
1185 bool wxEatWhiteSpaceString(char *s)
1186 {
1187 int ch = getc_string(s);
1188 if (ch == EOF)
1189 return TRUE;
1190
1191 if ((ch != ' ') && (ch != '/') && (ch != ' ') && (ch != 10) && (ch != 13) && (ch != 9))
1192 {
1193 ungetc_string();
1194 return TRUE;
1195 }
1196
1197 // Eat whitespace
1198 while (ch == ' ' || ch == 10 || ch == 13 || ch == 9)
1199 ch = getc_string(s);
1200 // Check for comment
1201 if (ch == '/')
1202 {
1203 ch = getc_string(s);
1204 if (ch == '*')
1205 {
1206 bool finished = FALSE;
1207 while (!finished)
1208 {
1209 ch = getc_string(s);
1210 if (ch == EOF)
1211 return FALSE;
1212 if (ch == '*')
1213 {
1214 int newCh = getc_string(s);
1215 if (newCh == '/')
1216 finished = TRUE;
1217 else
1218 {
1219 ungetc_string();
1220 }
1221 }
1222 }
1223 }
1224 else // False alarm
1225 return FALSE;
1226 }
1227 else if (ch != EOF)
1228 ungetc_string();
1229 return wxEatWhiteSpaceString(s);
1230 }
1231
1232 bool wxGetResourceTokenString(char *s)
1233 {
1234 if (!wxResourceBuffer)
1235 wxReallocateResourceBuffer();
1236 wxResourceBuffer[0] = 0;
1237 wxEatWhiteSpaceString(s);
1238
1239 int ch = getc_string(s);
1240 if (ch == '"')
1241 {
1242 // Get string
1243 wxResourceBufferCount = 0;
1244 ch = getc_string(s);
1245 while (ch != '"')
1246 {
1247 int actualCh = ch;
1248 if (ch == EOF)
1249 {
1250 wxResourceBuffer[wxResourceBufferCount] = 0;
1251 return FALSE;
1252 }
1253 // Escaped characters
1254 else if (ch == '\\')
1255 {
1256 int newCh = getc_string(s);
1257 if (newCh == '"')
1258 actualCh = '"';
1259 else if (newCh == 10)
1260 actualCh = 10;
1261 else
1262 {
1263 ungetc_string();
1264 }
1265 }
1266
1267 if (wxResourceBufferCount >= wxResourceBufferSize-1)
1268 wxReallocateResourceBuffer();
1269 wxResourceBuffer[wxResourceBufferCount] = (char)actualCh;
1270 wxResourceBufferCount ++;
1271 ch = getc_string(s);
1272 }
1273 wxResourceBuffer[wxResourceBufferCount] = 0;
1274 }
1275 else
1276 {
1277 wxResourceBufferCount = 0;
1278 // Any other token
1279 while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10)
1280 {
1281 if (wxResourceBufferCount >= wxResourceBufferSize-1)
1282 wxReallocateResourceBuffer();
1283 wxResourceBuffer[wxResourceBufferCount] = (char)ch;
1284 wxResourceBufferCount ++;
1285
1286 ch = getc_string(s);
1287 }
1288 wxResourceBuffer[wxResourceBufferCount] = 0;
1289 if (ch == EOF)
1290 return FALSE;
1291 }
1292 return TRUE;
1293 }
1294
1295 /*
1296 * Files are in form:
1297 static char *name = "....";
1298 with possible comments.
1299 */
1300
1301 bool wxResourceReadOneResourceString(char *s, wxExprDatabase& db, bool *eof, wxResourceTable *table)
1302 {
1303 if (!table)
1304 table = wxDefaultResourceTable;
1305
1306 // static or #define
1307 if (!wxGetResourceTokenString(s))
1308 {
1309 *eof = TRUE;
1310 return FALSE;
1311 }
1312
1313 if (strcmp(wxResourceBuffer, "#define") == 0)
1314 {
1315 wxGetResourceTokenString(s);
1316 char *name = copystring(wxResourceBuffer);
1317 wxGetResourceTokenString(s);
1318 char *value = copystring(wxResourceBuffer);
1319 if (isalpha(value[0]))
1320 {
1321 int val = (int)atol(value);
1322 wxResourceAddIdentifier(name, val, table);
1323 }
1324 else
1325 {
1326 wxLogWarning(_("#define %s must be an integer."), name);
1327 delete[] name;
1328 delete[] value;
1329 return FALSE;
1330 }
1331 delete[] name;
1332 delete[] value;
1333
1334 return TRUE;
1335 }
1336 /*
1337 else if (strcmp(wxResourceBuffer, "#include") == 0)
1338 {
1339 wxGetResourceTokenString(s);
1340 char *name = copystring(wxResourceBuffer);
1341 char *actualName = name;
1342 if (name[0] == '"')
1343 actualName = name + 1;
1344 int len = strlen(name);
1345 if ((len > 0) && (name[len-1] == '"'))
1346 name[len-1] = 0;
1347 if (!wxResourceParseIncludeFile(actualName, table))
1348 {
1349 char buf[400];
1350 sprintf(buf, _("Could not find resource include file %s."), actualName);
1351 wxLogWarning(buf);
1352 }
1353 delete[] name;
1354 return TRUE;
1355 }
1356 */
1357 else if (strcmp(wxResourceBuffer, "static") != 0)
1358 {
1359 char buf[300];
1360 strcpy(buf, _("Found "));
1361 strncat(buf, wxResourceBuffer, 30);
1362 strcat(buf, _(", expected static, #include or #define\nwhilst parsing resource."));
1363 wxLogWarning(buf);
1364 return FALSE;
1365 }
1366
1367 // char
1368 if (!wxGetResourceTokenString(s))
1369 {
1370 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1371 *eof = TRUE;
1372 return FALSE;
1373 }
1374
1375 if (strcmp(wxResourceBuffer, "char") != 0)
1376 {
1377 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1378 return FALSE;
1379 }
1380
1381 // *name
1382 if (!wxGetResourceTokenString(s))
1383 {
1384 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1385 *eof = TRUE;
1386 return FALSE;
1387 }
1388
1389 if (wxResourceBuffer[0] != '*')
1390 {
1391 wxLogWarning(_("Expected '*' whilst parsing resource."));
1392 return FALSE;
1393 }
1394 char nameBuf[100];
1395 strncpy(nameBuf, wxResourceBuffer+1, 99);
1396
1397 // =
1398 if (!wxGetResourceTokenString(s))
1399 {
1400 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1401 *eof = TRUE;
1402 return FALSE;
1403 }
1404
1405 if (strcmp(wxResourceBuffer, "=") != 0)
1406 {
1407 wxLogWarning(_("Expected '=' whilst parsing resource."));
1408 return FALSE;
1409 }
1410
1411 // String
1412 if (!wxGetResourceTokenString(s))
1413 {
1414 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1415 *eof = TRUE;
1416 return FALSE;
1417 }
1418 else
1419 {
1420 if (!db.ReadPrologFromString(wxResourceBuffer))
1421 {
1422 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf);
1423 return FALSE;
1424 }
1425 }
1426 // Semicolon
1427 if (!wxGetResourceTokenString(s))
1428 {
1429 *eof = TRUE;
1430 }
1431 return TRUE;
1432 }
1433
1434 bool wxResourceParseString(char *s, wxResourceTable *table)
1435 {
1436 if (!table)
1437 table = wxDefaultResourceTable;
1438
1439 if (!s)
1440 return FALSE;
1441
1442 // Turn backslashes into spaces
1443 if (s)
1444 {
1445 int len = strlen(s);
1446 int i;
1447 for (i = 0; i < len; i++)
1448 if (s[i] == 92 && s[i+1] == 13)
1449 {
1450 s[i] = ' ';
1451 s[i+1] = ' ';
1452 }
1453 }
1454
1455 wxExprDatabase db;
1456 wxResourceStringPtr = 0;
1457
1458 bool eof = FALSE;
1459 while (wxResourceReadOneResourceString(s, db, &eof, table) && !eof)
1460 {
1461 // Loop
1462 }
1463 return wxResourceInterpretResources(*table, db);
1464 }
1465
1466 /*
1467 * resource loading facility
1468 */
1469
1470 bool wxWindow::LoadFromResource(wxWindow *parent, const wxString& resourceName, const wxResourceTable *table)
1471 {
1472 if (!table)
1473 table = wxDefaultResourceTable;
1474
1475 wxItemResource *resource = table->FindResource((const char *)resourceName);
1476 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
1477 if (!resource || (resource->GetType() == "") ||
1478 ! ((strcmp(resource->GetType(), "wxDialog") == 0) || (strcmp(resource->GetType(), "wxPanel") == 0)))
1479 return FALSE;
1480
1481 wxString title(resource->GetTitle());
1482 long theWindowStyle = resource->GetStyle();
1483 bool isModal = (resource->GetValue1() != 0);
1484 int x = resource->GetX();
1485 int y = resource->GetY();
1486 int width = resource->GetWidth();
1487 int height = resource->GetHeight();
1488 wxString name = resource->GetName();
1489
1490 if (IsKindOf(CLASSINFO(wxDialog)))
1491 {
1492 wxDialog *dialogBox = (wxDialog *)this;
1493 long modalStyle = isModal ? wxDIALOG_MODAL : 0;
1494 if (!dialogBox->Create(parent, -1, title, wxPoint(x, y), wxSize(width, height), theWindowStyle|modalStyle, name))
1495 return FALSE;
1496
1497 // Only reset the client size if we know we're not going to do it again below.
1498 if ((resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) == 0)
1499 dialogBox->SetClientSize(width, height);
1500 }
1501 else if (IsKindOf(CLASSINFO(wxPanel)))
1502 {
1503 wxPanel* panel = (wxPanel *)this;
1504 if (!panel->Create(parent, -1, wxPoint(x, y), wxSize(width, height), theWindowStyle, name))
1505 return FALSE;
1506 }
1507 else
1508 {
1509 if (!this->Create(parent, -1, wxPoint(x, y), wxSize(width, height), theWindowStyle, name))
1510 return FALSE;
1511 }
1512
1513 if ((resource->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS) != 0)
1514 {
1515 // No need to do this since it's done in wxPanel or wxDialog constructor.
1516 // SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
1517 }
1518 else
1519 {
1520 if (resource->GetFont().Ok())
1521 SetFont(resource->GetFont());
1522 if (resource->GetBackgroundColour().Ok())
1523 SetBackgroundColour(resource->GetBackgroundColour());
1524 }
1525
1526 // Should have some kind of font at this point
1527 if (!GetFont().Ok())
1528 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
1529 if (!GetBackgroundColour().Ok())
1530 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
1531
1532 // Only when we've created the window and set the font can we set the correct size,
1533 // if based on dialog units.
1534 if ((resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0)
1535 {
1536 wxSize sz = ConvertDialogToPixels(wxSize(width, height));
1537 SetClientSize(sz.x, sz.y);
1538
1539 wxPoint pt = ConvertDialogToPixels(wxPoint(x, y));
1540 #ifdef __WXMAC__
1541 int mbarheight = 2 * LMGetMBarHeight() ;
1542 pt.y += mbarheight ;
1543 #endif
1544 Move(pt.x, pt.y);
1545 }
1546
1547 // Now create children
1548 wxNode *node = resource->GetChildren().First();
1549 while (node)
1550 {
1551 wxItemResource *childResource = (wxItemResource *)node->Data();
1552
1553 (void) CreateItem(childResource, resource, table);
1554
1555 node = node->Next();
1556 }
1557 return TRUE;
1558 }
1559
1560 wxControl *wxWindow::CreateItem(const wxItemResource *resource, const wxItemResource* parentResource, const wxResourceTable *table)
1561 {
1562 if (!table)
1563 table = wxDefaultResourceTable;
1564 return table->CreateItem((wxWindow *)this, resource, parentResource);
1565 }
1566
1567 #ifdef __VISUALC__
1568 #pragma warning(default:4706) // assignment within conditional expression
1569 #endif // VC++
1570
1571 #endif
1572 // BC++/Win16 only
1573 #endif // wxUSE_WX_RESOURCES