]> git.saurik.com Git - wxWidgets.git/blob - src/common/resourc2.cpp
Fixed status bar probs,
[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 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
821 wxItemResource *item = table->FindResource(name);
822 if (!item)
823 {
824 wxLogWarning(_("Failed to find XPM resource %s.\n"
825 "Forgot to use wxResourceLoadBitmapData?"), (const char*) name);
826 return wxNullBitmap;
827 }
828 return wxBitmap(item->GetValue1());
829 #else
830 wxLogWarning(_("No XPM facility available!"));
831 #endif
832 break;
833 }
834 default:
835 {
836 return wxBitmap(name, bitmapType);
837 break;
838 }
839 }
840 return wxNullBitmap;
841 }
842 else
843 {
844 wxLogWarning(_("Bitmap resource specification %s not found."), (const char*) resource);
845 return wxNullBitmap;
846 }
847 }
848
849 /*
850 * Load an icon from a wxWindows resource, choosing an optimum
851 * depth and appropriate type.
852 */
853
854 wxIcon wxResourceCreateIcon(const wxString& resource, wxResourceTable *table)
855 {
856 if (!table)
857 table = wxDefaultResourceTable;
858
859 wxItemResource *item = table->FindResource(resource);
860 if (item)
861 {
862 if ((item->GetType() == "") || (item->GetType() != "wxIcon"))
863 {
864 wxLogWarning(_("%s not an icon resource specification."), (const char*) resource);
865 return wxNullIcon;
866 }
867 int thisDepth = wxDisplayDepth();
868 long thisNoColours = (long)pow(2.0, (double)thisDepth);
869
870 wxItemResource *optResource = (wxItemResource *) NULL;
871
872 // Try to find optimum icon for this platform/colour depth
873 wxNode *node = item->GetChildren().First();
874 while (node)
875 {
876 wxItemResource *child = (wxItemResource *)node->Data();
877 int platform = (int)child->GetValue2();
878 int noColours = (int)child->GetValue3();
879 /*
880 char *name = child->GetName();
881 int bitmapType = (int)child->GetValue1();
882 int xRes = child->GetWidth();
883 int yRes = child->GetHeight();
884 */
885
886 switch (platform)
887 {
888 case RESOURCE_PLATFORM_ANY:
889 {
890 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
891 optResource = child;
892 else
893 {
894 // Maximise the number of colours.
895 // If noColours is zero (unspecified), then assume this
896 // is the right one.
897 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
898 optResource = child;
899 }
900 break;
901 }
902 #ifdef __WXMSW__
903 case RESOURCE_PLATFORM_WINDOWS:
904 {
905 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
906 optResource = child;
907 else
908 {
909 // Maximise the number of colours
910 if ((noColours > 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
911 optResource = child;
912 }
913 break;
914 }
915 #endif
916 #ifdef __WXGTK__
917 case RESOURCE_PLATFORM_X:
918 {
919 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
920 optResource = child;
921 else
922 {
923 // Maximise the number of colours
924 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
925 optResource = child;
926 }
927 break;
928 }
929 #endif
930 #ifdef wx_max
931 case RESOURCE_PLATFORM_MAC:
932 {
933 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
934 optResource = child;
935 else
936 {
937 // Maximise the number of colours
938 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
939 optResource = child;
940 }
941 break;
942 }
943 #endif
944 default:
945 break;
946 }
947 node = node->Next();
948 }
949 // If no matching resource, fail.
950 if (!optResource)
951 return wxNullIcon;
952
953 wxString name = optResource->GetName();
954 int bitmapType = (int)optResource->GetValue1();
955 switch (bitmapType)
956 {
957 case wxBITMAP_TYPE_XBM_DATA:
958 {
959 #ifdef __WXGTK__
960 wxItemResource *item = table->FindResource(name);
961 if (!item)
962 {
963 wxLogWarning(_("Failed to find XBM resource %s.\n"
964 "Forgot to use wxResourceLoadIconData?"), (const char*) name);
965 return wxNullIcon;
966 }
967 return wxIcon((const char **)item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3());
968 #else
969 wxLogWarning(_("No XBM facility available!"));
970 #endif
971 break;
972 }
973 case wxBITMAP_TYPE_XPM_DATA:
974 {
975 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
976 /*
977 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
978 wxItemResource *item = table->FindResource(name);
979 if (!item)
980 {
981 char buf[400];
982 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
983 wxLogWarning(buf);
984 return NULL;
985 }
986 return wxIcon((char **)item->GetValue1());
987 #else
988 wxLogWarning(_("No XPM facility available!"));
989 #endif
990 */
991 wxLogWarning(_("No XPM icon facility available!"));
992 break;
993 }
994 default:
995 {
996 #ifdef __WXGTK__
997 wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource);
998 #else
999 return wxIcon(name, bitmapType);
1000 #endif
1001 break;
1002 }
1003 }
1004 return wxNullIcon;
1005 }
1006 else
1007 {
1008 wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource);
1009 return wxNullIcon;
1010 }
1011 }
1012
1013 wxMenu *wxResourceCreateMenu(wxItemResource *item)
1014 {
1015 wxMenu *menu = new wxMenu;
1016 wxNode *node = item->GetChildren().First();
1017 while (node)
1018 {
1019 wxItemResource *child = (wxItemResource *)node->Data();
1020 if ((child->GetType() != "") && (child->GetType() == "wxMenuSeparator"))
1021 menu->AppendSeparator();
1022 else if (child->GetChildren().Number() > 0)
1023 {
1024 wxMenu *subMenu = wxResourceCreateMenu(child);
1025 if (subMenu)
1026 menu->Append((int)child->GetValue1(), child->GetTitle(), subMenu, child->GetValue4());
1027 }
1028 else
1029 {
1030 menu->Append((int)child->GetValue1(), child->GetTitle(), child->GetValue4(), (child->GetValue2() != 0));
1031 }
1032 node = node->Next();
1033 }
1034 return menu;
1035 }
1036
1037 wxMenuBar *wxResourceCreateMenuBar(const wxString& resource, wxResourceTable *table, wxMenuBar *menuBar)
1038 {
1039 if (!table)
1040 table = wxDefaultResourceTable;
1041
1042 wxItemResource *menuResource = table->FindResource(resource);
1043 if (menuResource && (menuResource->GetType() != "") && (menuResource->GetType() == "wxMenu"))
1044 {
1045 if (!menuBar)
1046 menuBar = new wxMenuBar;
1047 wxNode *node = menuResource->GetChildren().First();
1048 while (node)
1049 {
1050 wxItemResource *child = (wxItemResource *)node->Data();
1051 wxMenu *menu = wxResourceCreateMenu(child);
1052 if (menu)
1053 menuBar->Append(menu, child->GetTitle());
1054 node = node->Next();
1055 }
1056 return menuBar;
1057 }
1058 return (wxMenuBar *) NULL;
1059 }
1060
1061 wxMenu *wxResourceCreateMenu(const wxString& resource, wxResourceTable *table)
1062 {
1063 if (!table)
1064 table = wxDefaultResourceTable;
1065
1066 wxItemResource *menuResource = table->FindResource(resource);
1067 if (menuResource && (menuResource->GetType() != "") && (menuResource->GetType() == "wxMenu"))
1068 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
1069 return wxResourceCreateMenu(menuResource);
1070 return (wxMenu *) NULL;
1071 }
1072
1073 // Global equivalents (so don't have to refer to default table explicitly)
1074 bool wxResourceParseData(const wxString& resource, wxResourceTable *table)
1075 {
1076 if (!table)
1077 table = wxDefaultResourceTable;
1078
1079 return table->ParseResourceData(resource);
1080 }
1081
1082 bool wxResourceParseFile(const wxString& filename, wxResourceTable *table)
1083 {
1084 if (!table)
1085 table = wxDefaultResourceTable;
1086
1087 return table->ParseResourceFile(filename);
1088 }
1089
1090 // Register XBM/XPM data
1091 bool wxResourceRegisterBitmapData(const wxString& name, char bits[], int width, int height, wxResourceTable *table)
1092 {
1093 if (!table)
1094 table = wxDefaultResourceTable;
1095
1096 return table->RegisterResourceBitmapData(name, bits, width, height);
1097 }
1098
1099 bool wxResourceRegisterBitmapData(const wxString& name, char **data, wxResourceTable *table)
1100 {
1101 if (!table)
1102 table = wxDefaultResourceTable;
1103
1104 return table->RegisterResourceBitmapData(name, data);
1105 }
1106
1107 void wxResourceClear(wxResourceTable *table)
1108 {
1109 if (!table)
1110 table = wxDefaultResourceTable;
1111
1112 table->ClearTable();
1113 }
1114
1115 /*
1116 * Identifiers
1117 */
1118
1119 bool wxResourceAddIdentifier(const wxString& name, int value, wxResourceTable *table)
1120 {
1121 if (!table)
1122 table = wxDefaultResourceTable;
1123
1124 table->identifiers.Put(name, (wxObject *)value);
1125 return TRUE;
1126 }
1127
1128 int wxResourceGetIdentifier(const wxString& name, wxResourceTable *table)
1129 {
1130 if (!table)
1131 table = wxDefaultResourceTable;
1132
1133 return (int)table->identifiers.Get(name);
1134 }
1135
1136 /*
1137 * Parse #include file for #defines (only)
1138 */
1139
1140 bool wxResourceParseIncludeFile(const wxString& f, wxResourceTable *table)
1141 {
1142 if (!table)
1143 table = wxDefaultResourceTable;
1144
1145 FILE *fd = fopen(f, "r");
1146 if (!fd)
1147 {
1148 return FALSE;
1149 }
1150 while (wxGetResourceToken(fd))
1151 {
1152 if (strcmp(wxResourceBuffer, "#define") == 0)
1153 {
1154 wxGetResourceToken(fd);
1155 char *name = copystring(wxResourceBuffer);
1156 wxGetResourceToken(fd);
1157 char *value = copystring(wxResourceBuffer);
1158 if (isdigit(value[0]))
1159 {
1160 int val = (int)atol(value);
1161 wxResourceAddIdentifier(name, val, table);
1162 }
1163 delete[] name;
1164 delete[] value;
1165 }
1166 }
1167 fclose(fd);
1168 return TRUE;
1169 }
1170
1171 /*
1172 * Reading strings as if they were .wxr files
1173 */
1174
1175 static int getc_string(char *s)
1176 {
1177 int ch = s[wxResourceStringPtr];
1178 if (ch == 0)
1179 return EOF;
1180 else
1181 {
1182 wxResourceStringPtr ++;
1183 return ch;
1184 }
1185 }
1186
1187 static int ungetc_string()
1188 {
1189 wxResourceStringPtr --;
1190 return 0;
1191 }
1192
1193 bool wxEatWhiteSpaceString(char *s)
1194 {
1195 int ch = getc_string(s);
1196 if (ch == EOF)
1197 return TRUE;
1198
1199 if ((ch != ' ') && (ch != '/') && (ch != ' ') && (ch != 10) && (ch != 13) && (ch != 9))
1200 {
1201 ungetc_string();
1202 return TRUE;
1203 }
1204
1205 // Eat whitespace
1206 while (ch == ' ' || ch == 10 || ch == 13 || ch == 9)
1207 ch = getc_string(s);
1208 // Check for comment
1209 if (ch == '/')
1210 {
1211 ch = getc_string(s);
1212 if (ch == '*')
1213 {
1214 bool finished = FALSE;
1215 while (!finished)
1216 {
1217 ch = getc_string(s);
1218 if (ch == EOF)
1219 return FALSE;
1220 if (ch == '*')
1221 {
1222 int newCh = getc_string(s);
1223 if (newCh == '/')
1224 finished = TRUE;
1225 else
1226 {
1227 ungetc_string();
1228 }
1229 }
1230 }
1231 }
1232 else // False alarm
1233 return FALSE;
1234 }
1235 else if (ch != EOF)
1236 ungetc_string();
1237 return wxEatWhiteSpaceString(s);
1238 }
1239
1240 bool wxGetResourceTokenString(char *s)
1241 {
1242 if (!wxResourceBuffer)
1243 wxReallocateResourceBuffer();
1244 wxResourceBuffer[0] = 0;
1245 wxEatWhiteSpaceString(s);
1246
1247 int ch = getc_string(s);
1248 if (ch == '"')
1249 {
1250 // Get string
1251 wxResourceBufferCount = 0;
1252 ch = getc_string(s);
1253 while (ch != '"')
1254 {
1255 int actualCh = ch;
1256 if (ch == EOF)
1257 {
1258 wxResourceBuffer[wxResourceBufferCount] = 0;
1259 return FALSE;
1260 }
1261 // Escaped characters
1262 else if (ch == '\\')
1263 {
1264 int newCh = getc_string(s);
1265 if (newCh == '"')
1266 actualCh = '"';
1267 else if (newCh == 10)
1268 actualCh = 10;
1269 else
1270 {
1271 ungetc_string();
1272 }
1273 }
1274
1275 if (wxResourceBufferCount >= wxResourceBufferSize-1)
1276 wxReallocateResourceBuffer();
1277 wxResourceBuffer[wxResourceBufferCount] = (char)actualCh;
1278 wxResourceBufferCount ++;
1279 ch = getc_string(s);
1280 }
1281 wxResourceBuffer[wxResourceBufferCount] = 0;
1282 }
1283 else
1284 {
1285 wxResourceBufferCount = 0;
1286 // Any other token
1287 while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10)
1288 {
1289 if (wxResourceBufferCount >= wxResourceBufferSize-1)
1290 wxReallocateResourceBuffer();
1291 wxResourceBuffer[wxResourceBufferCount] = (char)ch;
1292 wxResourceBufferCount ++;
1293
1294 ch = getc_string(s);
1295 }
1296 wxResourceBuffer[wxResourceBufferCount] = 0;
1297 if (ch == EOF)
1298 return FALSE;
1299 }
1300 return TRUE;
1301 }
1302
1303 /*
1304 * Files are in form:
1305 static char *name = "....";
1306 with possible comments.
1307 */
1308
1309 bool wxResourceReadOneResourceString(char *s, wxExprDatabase& db, bool *eof, wxResourceTable *table)
1310 {
1311 if (!table)
1312 table = wxDefaultResourceTable;
1313
1314 // static or #define
1315 if (!wxGetResourceTokenString(s))
1316 {
1317 *eof = TRUE;
1318 return FALSE;
1319 }
1320
1321 if (strcmp(wxResourceBuffer, "#define") == 0)
1322 {
1323 wxGetResourceTokenString(s);
1324 char *name = copystring(wxResourceBuffer);
1325 wxGetResourceTokenString(s);
1326 char *value = copystring(wxResourceBuffer);
1327 if (isalpha(value[0]))
1328 {
1329 int val = (int)atol(value);
1330 wxResourceAddIdentifier(name, val, table);
1331 }
1332 else
1333 {
1334 wxLogWarning(_("#define %s must be an integer."), name);
1335 delete[] name;
1336 delete[] value;
1337 return FALSE;
1338 }
1339 delete[] name;
1340 delete[] value;
1341
1342 return TRUE;
1343 }
1344 /*
1345 else if (strcmp(wxResourceBuffer, "#include") == 0)
1346 {
1347 wxGetResourceTokenString(s);
1348 char *name = copystring(wxResourceBuffer);
1349 char *actualName = name;
1350 if (name[0] == '"')
1351 actualName = name + 1;
1352 int len = strlen(name);
1353 if ((len > 0) && (name[len-1] == '"'))
1354 name[len-1] = 0;
1355 if (!wxResourceParseIncludeFile(actualName, table))
1356 {
1357 char buf[400];
1358 sprintf(buf, _("Could not find resource include file %s."), actualName);
1359 wxLogWarning(buf);
1360 }
1361 delete[] name;
1362 return TRUE;
1363 }
1364 */
1365 else if (strcmp(wxResourceBuffer, "static") != 0)
1366 {
1367 char buf[300];
1368 strcpy(buf, _("Found "));
1369 strncat(buf, wxResourceBuffer, 30);
1370 strcat(buf, _(", expected static, #include or #define\nwhilst parsing resource."));
1371 wxLogWarning(buf);
1372 return FALSE;
1373 }
1374
1375 // char
1376 if (!wxGetResourceTokenString(s))
1377 {
1378 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1379 *eof = TRUE;
1380 return FALSE;
1381 }
1382
1383 if (strcmp(wxResourceBuffer, "char") != 0)
1384 {
1385 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1386 return FALSE;
1387 }
1388
1389 // *name
1390 if (!wxGetResourceTokenString(s))
1391 {
1392 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1393 *eof = TRUE;
1394 return FALSE;
1395 }
1396
1397 if (wxResourceBuffer[0] != '*')
1398 {
1399 wxLogWarning(_("Expected '*' whilst parsing resource."));
1400 return FALSE;
1401 }
1402 char nameBuf[100];
1403 strncpy(nameBuf, wxResourceBuffer+1, 99);
1404
1405 // =
1406 if (!wxGetResourceTokenString(s))
1407 {
1408 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1409 *eof = TRUE;
1410 return FALSE;
1411 }
1412
1413 if (strcmp(wxResourceBuffer, "=") != 0)
1414 {
1415 wxLogWarning(_("Expected '=' whilst parsing resource."));
1416 return FALSE;
1417 }
1418
1419 // String
1420 if (!wxGetResourceTokenString(s))
1421 {
1422 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1423 *eof = TRUE;
1424 return FALSE;
1425 }
1426 else
1427 {
1428 if (!db.ReadPrologFromString(wxResourceBuffer))
1429 {
1430 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf);
1431 return FALSE;
1432 }
1433 }
1434 // Semicolon
1435 if (!wxGetResourceTokenString(s))
1436 {
1437 *eof = TRUE;
1438 }
1439 return TRUE;
1440 }
1441
1442 bool wxResourceParseString(char *s, wxResourceTable *table)
1443 {
1444 if (!table)
1445 table = wxDefaultResourceTable;
1446
1447 if (!s)
1448 return FALSE;
1449
1450 // Turn backslashes into spaces
1451 if (s)
1452 {
1453 int len = strlen(s);
1454 int i;
1455 for (i = 0; i < len; i++)
1456 if (s[i] == 92 && s[i+1] == 13)
1457 {
1458 s[i] = ' ';
1459 s[i+1] = ' ';
1460 }
1461 }
1462
1463 wxExprDatabase db;
1464 wxResourceStringPtr = 0;
1465
1466 bool eof = FALSE;
1467 while (wxResourceReadOneResourceString(s, db, &eof, table) && !eof)
1468 {
1469 // Loop
1470 }
1471 return wxResourceInterpretResources(*table, db);
1472 }
1473
1474 /*
1475 * resource loading facility
1476 */
1477
1478 bool wxWindow::LoadFromResource(wxWindow *parent, const wxString& resourceName, const wxResourceTable *table)
1479 {
1480 if (!table)
1481 table = wxDefaultResourceTable;
1482
1483 wxItemResource *resource = table->FindResource((const char *)resourceName);
1484 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
1485 if (!resource || (resource->GetType() == "") ||
1486 ! ((strcmp(resource->GetType(), "wxDialog") == 0) || (strcmp(resource->GetType(), "wxPanel") == 0)))
1487 return FALSE;
1488
1489 wxString title(resource->GetTitle());
1490 long theWindowStyle = resource->GetStyle();
1491 bool isModal = (resource->GetValue1() != 0);
1492 int x = resource->GetX();
1493 int y = resource->GetY();
1494 int width = resource->GetWidth();
1495 int height = resource->GetHeight();
1496 wxString name = resource->GetName();
1497
1498 if (IsKindOf(CLASSINFO(wxDialog)))
1499 {
1500 wxDialog *dialogBox = (wxDialog *)this;
1501 long modalStyle = isModal ? wxDIALOG_MODAL : 0;
1502 if (!dialogBox->Create(parent, -1, title, wxPoint(x, y), wxSize(width, height), theWindowStyle|modalStyle, name))
1503 return FALSE;
1504
1505 // Only reset the client size if we know we're not going to do it again below.
1506 if ((resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) == 0)
1507 dialogBox->SetClientSize(width, height);
1508 }
1509 else if (IsKindOf(CLASSINFO(wxPanel)))
1510 {
1511 wxPanel* panel = (wxPanel *)this;
1512 if (!panel->Create(parent, -1, wxPoint(x, y), wxSize(width, height), theWindowStyle, name))
1513 return FALSE;
1514 }
1515 else
1516 {
1517 if (!this->Create(parent, -1, wxPoint(x, y), wxSize(width, height), theWindowStyle, name))
1518 return FALSE;
1519 }
1520
1521 if ((resource->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS) != 0)
1522 {
1523 // No need to do this since it's done in wxPanel or wxDialog constructor.
1524 // SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
1525 }
1526 else
1527 {
1528 if (resource->GetFont().Ok())
1529 SetFont(resource->GetFont());
1530 if (resource->GetBackgroundColour().Ok())
1531 SetBackgroundColour(resource->GetBackgroundColour());
1532 }
1533
1534 // Should have some kind of font at this point
1535 if (!GetFont().Ok())
1536 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
1537 if (!GetBackgroundColour().Ok())
1538 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
1539
1540 // Only when we've created the window and set the font can we set the correct size,
1541 // if based on dialog units.
1542 if ((resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0)
1543 {
1544 wxSize sz = ConvertDialogToPixels(wxSize(width, height));
1545 SetClientSize(sz.x, sz.y);
1546
1547 wxPoint pt = ConvertDialogToPixels(wxPoint(x, y));
1548 #ifdef __WXMAC__
1549 int mbarheight = 2 * LMGetMBarHeight() ;
1550 pt.y += mbarheight ;
1551 #endif
1552 Move(pt.x, pt.y);
1553 }
1554
1555 // Now create children
1556 wxNode *node = resource->GetChildren().First();
1557 while (node)
1558 {
1559 wxItemResource *childResource = (wxItemResource *)node->Data();
1560
1561 (void) CreateItem(childResource, resource, table);
1562
1563 node = node->Next();
1564 }
1565 return TRUE;
1566 }
1567
1568 wxControl *wxWindow::CreateItem(const wxItemResource *resource, const wxItemResource* parentResource, const wxResourceTable *table)
1569 {
1570 if (!table)
1571 table = wxDefaultResourceTable;
1572 return table->CreateItem((wxWindow *)this, resource, parentResource);
1573 }
1574
1575 #ifdef __VISUALC__
1576 #pragma warning(default:4706) // assignment within conditional expression
1577 #endif // VC++
1578
1579 #endif
1580 // BC++/Win16 only
1581 #endif // wxUSE_WX_RESOURCES