]> git.saurik.com Git - wxWidgets.git/blob - src/common/resource.cpp
More SC++ fixes; HelpGen starting to compile with VC++; image sample now compiles...
[wxWidgets.git] / src / common / resource.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: resource.cpp
3 // Purpose: Resource system
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 license
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 _MSC_VER
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/radiobut.h"
43 #include "wx/listbox.h"
44 #include "wx/choice.h"
45 #include "wx/checkbox.h"
46 #include "wx/settings.h"
47 #include "wx/slider.h"
48 #include "wx/statbox.h"
49 #include "wx/statbmp.h"
50 #if wxUSE_GAUGE
51 #include "wx/gauge.h"
52 #endif
53 #include "wx/textctrl.h"
54 #include "wx/msgdlg.h"
55 #include "wx/intl.h"
56 #endif
57
58 #if wxUSE_RADIOBUTTON
59 #include "wx/radiobut.h"
60 #endif
61
62 #if wxUSE_SCROLLBAR
63 #include "wx/scrolbar.h"
64 #endif
65
66 #if wxUSE_COMBOBOX
67 #include "wx/combobox.h"
68 #endif
69
70 #include "wx/validate.h"
71
72 #include "wx/log.h"
73
74 #include <ctype.h>
75 #include <math.h>
76 #include <stdlib.h>
77 #include <string.h>
78
79 #include "wx/resource.h"
80 #include "wx/string.h"
81 #include "wx/wxexpr.h"
82
83 #include "wx/settings.h"
84
85 // Forward (private) declarations
86 bool wxResourceInterpretResources(wxResourceTable& table, wxExprDatabase& db);
87 wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, wxExpr *expr, bool isPanel = FALSE);
88 wxItemResource *wxResourceInterpretControl(wxResourceTable& table, wxExpr *expr);
89 wxItemResource *wxResourceInterpretMenu(wxResourceTable& table, wxExpr *expr);
90 wxItemResource *wxResourceInterpretMenuBar(wxResourceTable& table, wxExpr *expr);
91 wxItemResource *wxResourceInterpretString(wxResourceTable& table, wxExpr *expr);
92 wxItemResource *wxResourceInterpretBitmap(wxResourceTable& table, wxExpr *expr);
93 wxItemResource *wxResourceInterpretIcon(wxResourceTable& table, wxExpr *expr);
94 // Interpret list expression
95 wxFont wxResourceInterpretFontSpec(wxExpr *expr);
96
97 bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table = (wxResourceTable *) NULL);
98 bool wxResourceParseIncludeFile(const wxString& f, wxResourceTable *table = (wxResourceTable *) NULL);
99
100 wxResourceTable *wxDefaultResourceTable = (wxResourceTable *) NULL;
101
102 char *wxResourceBuffer = (char *) NULL;
103 long wxResourceBufferSize = 0;
104 long wxResourceBufferCount = 0;
105 int wxResourceStringPtr = 0;
106
107 void wxInitializeResourceSystem()
108 {
109 wxDefaultResourceTable = new wxResourceTable;
110 }
111
112 void wxCleanUpResourceSystem()
113 {
114 delete wxDefaultResourceTable;
115 if (wxResourceBuffer)
116 delete[] wxResourceBuffer;
117 }
118
119 void wxLogWarning(char *msg)
120 {
121 wxMessageBox(msg, _("Warning"), wxOK);
122 }
123
124 #if !USE_SHARED_LIBRARY
125 IMPLEMENT_DYNAMIC_CLASS(wxItemResource, wxObject)
126 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable, wxHashTable)
127 #endif
128
129 wxItemResource::wxItemResource()
130 {
131 m_itemType = "";
132 m_title = "";
133 m_name = "";
134 m_windowStyle = 0;
135 m_x = m_y = m_width = m_height = 0;
136 m_value1 = m_value2 = m_value3 = m_value5 = 0;
137 m_value4 = "";
138 m_windowId = 0;
139 m_exStyle = 0;
140 }
141
142 wxItemResource::~wxItemResource()
143 {
144 wxNode *node = m_children.First();
145 while (node)
146 {
147 wxItemResource *item = (wxItemResource *)node->Data();
148 delete item;
149 delete node;
150 node = m_children.First();
151 }
152 }
153
154 /*
155 * Resource table
156 */
157
158 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING), identifiers(wxKEY_STRING)
159 {
160 }
161
162 wxResourceTable::~wxResourceTable()
163 {
164 ClearTable();
165 }
166
167 wxItemResource *wxResourceTable::FindResource(const wxString& name) const
168 {
169 wxItemResource *item = (wxItemResource *)Get((char *)(const char *)name);
170 return item;
171 }
172
173 void wxResourceTable::AddResource(wxItemResource *item)
174 {
175 wxString name = item->GetName();
176 if (name == "")
177 name = item->GetTitle();
178 if (name == "")
179 name = "no name";
180
181 // Delete existing resource, if any.
182 Delete(name);
183
184 Put(name, item);
185 }
186
187 bool wxResourceTable::DeleteResource(const wxString& name)
188 {
189 wxItemResource *item = (wxItemResource *)Delete((char *)(const char *)name);
190 if (item)
191 {
192 // See if any resource has this as its child; if so, delete from
193 // parent's child list.
194 BeginFind();
195 wxNode *node = (wxNode *) NULL;
196 while ((node = Next()))
197 {
198 wxItemResource *parent = (wxItemResource *)node->Data();
199 if (parent->GetChildren().Member(item))
200 {
201 parent->GetChildren().DeleteObject(item);
202 break;
203 }
204 }
205
206 delete item;
207 return TRUE;
208 }
209 else
210 return FALSE;
211 }
212
213 bool wxResourceTable::ParseResourceFile(const wxString& filename)
214 {
215 wxExprDatabase db;
216
217 FILE *fd = fopen((const char*) filename, "r");
218 if (!fd)
219 return FALSE;
220 bool eof = FALSE;
221 while (wxResourceReadOneResource(fd, db, &eof, this) && !eof)
222 {
223 // Loop
224 }
225 fclose(fd);
226 return wxResourceInterpretResources(*this, db);
227 }
228
229 bool wxResourceTable::ParseResourceData(const wxString& data)
230 {
231 wxExprDatabase db;
232 if (!db.ReadFromString(data))
233 {
234 wxLogWarning(_("Ill-formed resource file syntax."));
235 return FALSE;
236 }
237
238 return wxResourceInterpretResources(*this, db);
239 }
240
241 bool wxResourceTable::RegisterResourceBitmapData(const wxString& name, char bits[], int width, int height)
242 {
243 // Register pre-loaded bitmap data
244 wxItemResource *item = new wxItemResource;
245 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
246 item->SetType("wxXBMData");
247 item->SetName(name);
248 item->SetValue1((long)bits);
249 item->SetValue2((long)width);
250 item->SetValue3((long)height);
251 AddResource(item);
252 return TRUE;
253 }
254
255 bool wxResourceTable::RegisterResourceBitmapData(const wxString& name, char **data)
256 {
257 // Register pre-loaded bitmap data
258 wxItemResource *item = new wxItemResource;
259 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
260 item->SetType("wxXPMData");
261 item->SetName(name);
262 item->SetValue1((long)data);
263 AddResource(item);
264 return TRUE;
265 }
266
267 bool wxResourceTable::SaveResource(const wxString& WXUNUSED(filename))
268 {
269 return FALSE;
270 }
271
272 void wxResourceTable::ClearTable()
273 {
274 BeginFind();
275 wxNode *node = Next();
276 while (node)
277 {
278 wxNode *next = Next();
279 wxItemResource *item = (wxItemResource *)node->Data();
280 delete item;
281 delete node;
282 node = next;
283 }
284 }
285
286 wxControl *wxResourceTable::CreateItem(wxWindow *parent, const wxItemResource* childResource, const wxItemResource* parentResource) const
287 {
288 int id = childResource->GetId();
289 if ( id == 0 )
290 id = -1;
291
292 bool dlgUnits = ((parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0);
293
294 wxControl *control = (wxControl *) NULL;
295 wxString itemType(childResource->GetType());
296
297 wxPoint pos;
298 wxSize size;
299 if (dlgUnits)
300 {
301 pos = parent->ConvertDialogToPixels(wxPoint(childResource->GetX(), childResource->GetY()));
302 size = parent->ConvertDialogToPixels(wxSize(childResource->GetWidth(), childResource->GetHeight()));
303 }
304 else
305 {
306 pos = wxPoint(childResource->GetX(), childResource->GetY());
307 size = wxSize(childResource->GetWidth(), childResource->GetHeight());
308 }
309
310 if (itemType == wxString("wxButton") || itemType == wxString("wxBitmapButton"))
311 {
312 if (childResource->GetValue4() != "")
313 {
314 // Bitmap button
315 wxBitmap bitmap = childResource->GetBitmap();
316 if (!bitmap.Ok())
317 {
318 bitmap = wxResourceCreateBitmap(childResource->GetValue4(), (wxResourceTable *)this);
319 ((wxItemResource*) childResource)->SetBitmap(bitmap);
320 }
321 if (bitmap.Ok())
322 control = new wxBitmapButton(parent, id, bitmap, pos, size,
323 childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
324 }
325 else
326 // Normal, text button
327 control = new wxButton(parent, id, childResource->GetTitle(), pos, size,
328 childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
329 }
330 else if (itemType == wxString("wxMessage") || itemType == wxString("wxStaticText") ||
331 itemType == wxString("wxStaticBitmap"))
332 {
333 if (childResource->GetValue4() != "")
334 {
335 // Bitmap message
336 wxBitmap bitmap = childResource->GetBitmap();
337 if (!bitmap.Ok())
338 {
339 bitmap = wxResourceCreateBitmap(childResource->GetValue4(), (wxResourceTable *)this);
340 ((wxItemResource*) childResource)->SetBitmap(bitmap);
341 }
342 #if wxUSE_BITMAP_MESSAGE
343 if (bitmap.Ok())
344 control = new wxStaticBitmap(parent, id, bitmap, pos, size,
345 childResource->GetStyle(), childResource->GetName());
346 #endif
347 }
348 else
349 {
350 control = new wxStaticText(parent, id, childResource->GetTitle(), pos, size,
351 childResource->GetStyle(), childResource->GetName());
352 }
353 }
354 else if (itemType == wxString("wxText") || itemType == wxString("wxTextCtrl") || itemType == wxString("wxMultiText"))
355 {
356 control = new wxTextCtrl(parent, id, childResource->GetValue4(), pos, size,
357 childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
358 }
359 else if (itemType == wxString("wxCheckBox"))
360 {
361 control = new wxCheckBox(parent, id, childResource->GetTitle(), pos, size,
362 childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
363
364 ((wxCheckBox *)control)->SetValue((childResource->GetValue1() != 0));
365 }
366 #if wxUSE_GAUGE
367 else if (itemType == wxString("wxGauge"))
368 {
369 control = new wxGauge(parent, id, (int)childResource->GetValue2(), pos, size,
370 childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
371
372 ((wxGauge *)control)->SetValue((int)childResource->GetValue1());
373 }
374 #endif
375 #if wxUSE_RADIOBUTTON
376 else if (itemType == wxString("wxRadioButton"))
377 {
378 control = new wxRadioButton(parent, id, childResource->GetTitle(), // (int)childResource->GetValue1(),
379 pos, size,
380 childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
381 }
382 #endif
383 #if wxUSE_SCROLLBAR
384 else if (itemType == wxString("wxScrollBar"))
385 {
386 control = new wxScrollBar(parent, id, pos, size,
387 childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
388 /*
389 ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1());
390 ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2());
391 ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3());
392 ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5());
393 */
394 ((wxScrollBar *)control)->SetScrollbar((int)childResource->GetValue1(),(int)childResource->GetValue2(),
395 (int)childResource->GetValue3(),(int)(long)childResource->GetValue5(),FALSE);
396
397 }
398 #endif
399 else if (itemType == wxString("wxSlider"))
400 {
401 control = new wxSlider(parent, id, (int)childResource->GetValue1(),
402 (int)childResource->GetValue2(), (int)childResource->GetValue3(), pos, size,
403 childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
404 }
405 else if (itemType == wxString("wxGroupBox") || itemType == wxString("wxStaticBox"))
406 {
407 control = new wxStaticBox(parent, id, childResource->GetTitle(), pos, size,
408 childResource->GetStyle(), childResource->GetName());
409 }
410 else if (itemType == wxString("wxListBox"))
411 {
412 wxStringList& stringList = childResource->GetStringValues();
413 wxString *strings = (wxString *) NULL;
414 int noStrings = 0;
415 if (stringList.Number() > 0)
416 {
417 noStrings = stringList.Number();
418 strings = new wxString[noStrings];
419 wxNode *node = stringList.First();
420 int i = 0;
421 while (node)
422 {
423 strings[i] = (char *)node->Data();
424 i ++;
425 node = node->Next();
426 }
427 }
428 control = new wxListBox(parent, id, pos, size,
429 noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
430
431 if (strings)
432 delete[] strings;
433 }
434 else if (itemType == wxString("wxChoice"))
435 {
436 wxStringList& stringList = childResource->GetStringValues();
437 wxString *strings = (wxString *) NULL;
438 int noStrings = 0;
439 if (stringList.Number() > 0)
440 {
441 noStrings = stringList.Number();
442 strings = new wxString[noStrings];
443 wxNode *node = stringList.First();
444 int i = 0;
445 while (node)
446 {
447 strings[i] = (char *)node->Data();
448 i ++;
449 node = node->Next();
450 }
451 }
452 control = new wxChoice(parent, id, pos, size,
453 noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
454
455 if (strings)
456 delete[] strings;
457 }
458 #if wxUSE_COMBOBOX
459 else if (itemType == wxString("wxComboBox"))
460 {
461 wxStringList& stringList = childResource->GetStringValues();
462 wxString *strings = (wxString *) NULL;
463 int noStrings = 0;
464 if (stringList.Number() > 0)
465 {
466 noStrings = stringList.Number();
467 strings = new wxString[noStrings];
468 wxNode *node = stringList.First();
469 int i = 0;
470 while (node)
471 {
472 strings[i] = (char *)node->Data();
473 i ++;
474 node = node->Next();
475 }
476 }
477 control = new wxComboBox(parent, id, childResource->GetValue4(), pos, size,
478 noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName());
479
480 if (strings)
481 delete[] strings;
482 }
483 #endif
484 else if (itemType == wxString("wxRadioBox"))
485 {
486 wxStringList& stringList = childResource->GetStringValues();
487 wxString *strings = (wxString *) NULL;
488 int noStrings = 0;
489 if (stringList.Number() > 0)
490 {
491 noStrings = stringList.Number();
492 strings = new wxString[noStrings];
493 wxNode *node = stringList.First();
494 int i = 0;
495 while (node)
496 {
497 strings[i] = (char *)node->Data();
498 i ++;
499 node = node->Next();
500 }
501 }
502 control = new wxRadioBox(parent, (wxWindowID) id, wxString(childResource->GetTitle()), pos, size,
503 noStrings, strings, (int)childResource->GetValue1(), childResource->GetStyle(), wxDefaultValidator,
504 childResource->GetName());
505
506 if (strings)
507 delete[] strings;
508 }
509
510 if ((parentResource->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS) != 0)
511 {
512 // Don't set font; will be inherited from parent.
513 }
514 else
515 {
516 if (control && childResource->GetFont().Ok())
517 control->SetFont(childResource->GetFont());
518 }
519 return control;
520 }
521
522 /*
523 * Interpret database as a series of resources
524 */
525
526 bool wxResourceInterpretResources(wxResourceTable& table, wxExprDatabase& db)
527 {
528 wxNode *node = db.First();
529 while (node)
530 {
531 wxExpr *clause = (wxExpr *)node->Data();
532 wxString functor(clause->Functor());
533
534 wxItemResource *item = (wxItemResource *) NULL;
535 if (functor == "dialog")
536 item = wxResourceInterpretDialog(table, clause);
537 else if (functor == "panel")
538 item = wxResourceInterpretDialog(table, clause, TRUE);
539 else if (functor == "menubar")
540 item = wxResourceInterpretMenuBar(table, clause);
541 else if (functor == "menu")
542 item = wxResourceInterpretMenu(table, clause);
543 else if (functor == "string")
544 item = wxResourceInterpretString(table, clause);
545 else if (functor == "bitmap")
546 item = wxResourceInterpretBitmap(table, clause);
547 else if (functor == "icon")
548 item = wxResourceInterpretIcon(table, clause);
549
550 if (item)
551 {
552 // Remove any existing resource of same name
553 if (item->GetName() != "")
554 table.DeleteResource(item->GetName());
555 table.AddResource(item);
556 }
557 node = node->Next();
558 }
559 return TRUE;
560 }
561
562 static char *g_ValidControlClasses[] = { "wxButton", "wxBitmapButton", "wxMessage",
563 "wxStaticText", "wxStaticBitmap", "wxText", "wxTextCtrl", "wxMultiText",
564 "wxListBox", "wxRadioBox", "wxRadioButton", "wxCheckBox", "wxBitmapCheckBox",
565 "wxGroupBox", "wxStaticBox", "wxSlider", "wxGauge", "wxScrollBar",
566 "wxChoice", "wxComboBox" } ;
567 static int g_ValidControlClassesCount = sizeof(g_ValidControlClasses) / sizeof(char *) ;
568
569 static bool wxIsValidControlClass(const wxString& c)
570 {
571 int i;
572 for ( i = 0; i < g_ValidControlClassesCount; i++)
573 {
574 if ( c == g_ValidControlClasses[i] )
575 return TRUE;
576 }
577 return FALSE;
578 }
579
580 wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, wxExpr *expr, bool isPanel)
581 {
582 wxItemResource *dialogItem = new wxItemResource;
583 if (isPanel)
584 dialogItem->SetType("wxPanel");
585 else
586 dialogItem->SetType("wxDialog");
587 wxString style = "";
588 wxString title = "";
589 wxString name = "";
590 wxString backColourHex = "";
591 wxString labelColourHex = "";
592 wxString buttonColourHex = "";
593
594 long windowStyle = wxDEFAULT_DIALOG_STYLE;
595 if (isPanel)
596 windowStyle = 0;
597
598 int x = 0; int y = 0; int width = -1; int height = -1;
599 int isModal = 0;
600 wxExpr *labelFontExpr = (wxExpr *) NULL;
601 wxExpr *buttonFontExpr = (wxExpr *) NULL;
602 wxExpr *fontExpr = (wxExpr *) NULL;
603 expr->GetAttributeValue("style", style);
604 expr->GetAttributeValue("name", name);
605 expr->GetAttributeValue("title", title);
606 expr->GetAttributeValue("x", x);
607 expr->GetAttributeValue("y", y);
608 expr->GetAttributeValue("width", width);
609 expr->GetAttributeValue("height", height);
610 expr->GetAttributeValue("modal", isModal);
611 expr->GetAttributeValue("label_font", &labelFontExpr);
612 expr->GetAttributeValue("button_font", &buttonFontExpr);
613 expr->GetAttributeValue("font", &fontExpr);
614 expr->GetAttributeValue("background_colour", backColourHex);
615 expr->GetAttributeValue("label_colour", labelColourHex);
616 expr->GetAttributeValue("button_colour", buttonColourHex);
617
618 int useDialogUnits = 0;
619 expr->GetAttributeValue("use_dialog_units", useDialogUnits);
620 if (useDialogUnits != 0)
621 dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS);
622
623 int useDefaults = 0;
624 expr->GetAttributeValue("use_system_defaults", useDefaults);
625 if (useDefaults != 0)
626 dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS);
627
628 long id = 0;
629 expr->GetAttributeValue("id", id);
630 dialogItem->SetId(id);
631
632 if (style != "")
633 {
634 windowStyle = wxParseWindowStyle(style);
635 }
636 dialogItem->SetStyle(windowStyle);
637 dialogItem->SetValue1(isModal);
638 dialogItem->SetName(name);
639 dialogItem->SetTitle(title);
640 dialogItem->SetSize(x, y, width, height);
641
642 if (backColourHex != "")
643 {
644 int r = 0;
645 int g = 0;
646 int b = 0;
647 r = wxHexToDec(backColourHex.Mid(0, 2));
648 g = wxHexToDec(backColourHex.Mid(2, 2));
649 b = wxHexToDec(backColourHex.Mid(4, 2));
650 dialogItem->SetBackgroundColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b));
651 }
652 if (labelColourHex != "")
653 {
654 int r = 0;
655 int g = 0;
656 int b = 0;
657 r = wxHexToDec(labelColourHex.Mid(0, 2));
658 g = wxHexToDec(labelColourHex.Mid(2, 2));
659 b = wxHexToDec(labelColourHex.Mid(4, 2));
660 dialogItem->SetLabelColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b));
661 }
662 if (buttonColourHex != "")
663 {
664 int r = 0;
665 int g = 0;
666 int b = 0;
667 r = wxHexToDec(buttonColourHex.Mid(0, 2));
668 g = wxHexToDec(buttonColourHex.Mid(2, 2));
669 b = wxHexToDec(buttonColourHex.Mid(4, 2));
670 dialogItem->SetButtonColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b));
671 }
672
673 if (fontExpr)
674 dialogItem->SetFont(wxResourceInterpretFontSpec(fontExpr));
675 else if (buttonFontExpr)
676 dialogItem->SetFont(wxResourceInterpretFontSpec(buttonFontExpr));
677 else if (labelFontExpr)
678 dialogItem->SetFont(wxResourceInterpretFontSpec(labelFontExpr));
679
680 // Now parse all controls
681 wxExpr *controlExpr = expr->GetFirst();
682 while (controlExpr)
683 {
684 if (controlExpr->Number() == 3)
685 {
686 wxString controlKeyword(controlExpr->Nth(1)->StringValue());
687 if (controlKeyword != "" && controlKeyword == "control")
688 {
689 // The value part: always a list.
690 wxExpr *listExpr = controlExpr->Nth(2);
691 if (listExpr->Type() == PrologList)
692 {
693 wxItemResource *controlItem = wxResourceInterpretControl(table, listExpr);
694 if (controlItem)
695 {
696 dialogItem->GetChildren().Append(controlItem);
697 }
698 }
699 }
700 }
701 controlExpr = controlExpr->GetNext();
702 }
703 return dialogItem;
704 }
705
706 wxItemResource *wxResourceInterpretControl(wxResourceTable& table, wxExpr *expr)
707 {
708 wxItemResource *controlItem = new wxItemResource;
709
710 // First, find the standard features of a control definition:
711 // [optional integer/string id], control name, title, style, name, x, y, width, height
712
713 wxString controlType;
714 wxString style;
715 wxString title;
716 wxString name;
717 int id = 0;
718 long windowStyle = 0;
719 int x = 0; int y = 0; int width = -1; int height = -1;
720 int count = 0;
721
722 wxExpr *expr1 = expr->Nth(0);
723
724 if ( expr1->Type() == PrologString || expr1->Type() == PrologWord )
725 {
726 if ( wxIsValidControlClass(expr1->StringValue()) )
727 {
728 count = 1;
729 controlType = expr1->StringValue();
730 }
731 else
732 {
733 wxString str(expr1->StringValue());
734 id = wxResourceGetIdentifier(str, &table);
735 if (id == 0)
736 {
737 wxLogWarning(_("Could not resolve control class or id '%s'. "
738 "Use (non-zero) integer instead\n or provide #define "
739 "(see manual for caveats)"),
740 (const char*) expr1->StringValue());
741 delete controlItem;
742 return (wxItemResource *) NULL;
743 }
744 else
745 {
746 // Success - we have an id, so the 2nd element must be the control class.
747 controlType = expr->Nth(1)->StringValue();
748 count = 2;
749 }
750 }
751 }
752 else if (expr1->Type() == PrologInteger)
753 {
754 id = (int)expr1->IntegerValue();
755 // Success - we have an id, so the 2nd element must be the control class.
756 controlType = expr->Nth(1)->StringValue();
757 count = 2;
758 }
759
760 expr1 = expr->Nth(count);
761 count ++;
762 if ( expr1 )
763 title = expr1->StringValue();
764
765 expr1 = expr->Nth(count);
766 count ++;
767 if (expr1)
768 {
769 style = expr1->StringValue();
770 windowStyle = wxParseWindowStyle(style);
771 }
772
773 expr1 = expr->Nth(count);
774 count ++;
775 if (expr1)
776 name = expr1->StringValue();
777
778 expr1 = expr->Nth(count);
779 count ++;
780 if (expr1)
781 x = (int)expr1->IntegerValue();
782
783 expr1 = expr->Nth(count);
784 count ++;
785 if (expr1)
786 y = (int)expr1->IntegerValue();
787
788 expr1 = expr->Nth(count);
789 count ++;
790 if (expr1)
791 width = (int)expr1->IntegerValue();
792
793 expr1 = expr->Nth(count);
794 count ++;
795 if (expr1)
796 height = (int)expr1->IntegerValue();
797
798 controlItem->SetStyle(windowStyle);
799 controlItem->SetName(name);
800 controlItem->SetTitle(title);
801 controlItem->SetSize(x, y, width, height);
802 controlItem->SetType(controlType);
803 controlItem->SetId(id);
804
805 if (controlType == "wxButton")
806 {
807 // Check for bitmap resource name (in case loading old-style resource file)
808 if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord)))
809 {
810 wxString str(expr->Nth(count)->StringValue());
811 controlItem->SetValue4(str);
812 count ++;
813 controlItem->SetType("wxBitmapButton");
814 }
815 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
816 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
817 }
818 else if (controlType == "wxBitmapButton")
819 {
820 // Check for bitmap resource name
821 if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord)))
822 {
823 wxString str(expr->Nth(count)->StringValue());
824 controlItem->SetValue4(str);
825 count ++;
826 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
827 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
828 }
829 }
830 else if (controlType == "wxCheckBox")
831 {
832 // Check for default value
833 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
834 {
835 controlItem->SetValue1(expr->Nth(count)->IntegerValue());
836 count ++;
837 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
838 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
839 }
840 }
841 #if wxUSE_RADIOBUTTON
842 else if (controlType == "wxRadioButton")
843 {
844 // Check for default value
845 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
846 {
847 controlItem->SetValue1(expr->Nth(count)->IntegerValue());
848 count ++;
849 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
850 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
851 }
852 }
853 #endif
854 else if (controlType == "wxText" || controlType == "wxTextCtrl" || controlType == "wxMultiText")
855 {
856 // Check for default value
857 if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord)))
858 {
859 wxString str(expr->Nth(count)->StringValue());
860 controlItem->SetValue4(str);
861 count ++;
862
863 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
864 {
865 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
866 // Do nothing - no label font any more
867 count ++;
868 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
869 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
870 }
871 }
872 }
873 else if (controlType == "wxMessage" || controlType == "wxStaticText")
874 {
875 // Check for bitmap resource name (in case it's an old-style .wxr file)
876 if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord)))
877 {
878 wxString str(expr->Nth(count)->StringValue());
879 controlItem->SetValue4(str);
880 count ++;
881 controlItem->SetType("wxStaticText");
882 }
883 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
884 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
885 }
886 else if (controlType == "wxStaticBitmap")
887 {
888 // Check for bitmap resource name
889 if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord)))
890 {
891 wxString str(expr->Nth(count)->StringValue());
892 controlItem->SetValue4(str);
893 count ++;
894 }
895 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
896 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
897 }
898 else if (controlType == "wxGroupBox" || controlType == "wxStaticBox")
899 {
900 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
901 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
902 }
903 else if (controlType == "wxGauge")
904 {
905 // Check for default value
906 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
907 {
908 controlItem->SetValue1(expr->Nth(count)->IntegerValue());
909 count ++;
910
911 // Check for range
912 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
913 {
914 controlItem->SetValue2(expr->Nth(count)->IntegerValue());
915 count ++;
916
917 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
918 {
919 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
920 // Do nothing
921 count ++;
922
923 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
924 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
925 }
926 }
927 }
928 }
929 else if (controlType == "wxSlider")
930 {
931 // Check for default value
932 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
933 {
934 controlItem->SetValue1(expr->Nth(count)->IntegerValue());
935 count ++;
936
937 // Check for min
938 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
939 {
940 controlItem->SetValue2(expr->Nth(count)->IntegerValue());
941 count ++;
942
943 // Check for max
944 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
945 {
946 controlItem->SetValue3(expr->Nth(count)->IntegerValue());
947 count ++;
948
949 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
950 {
951 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
952 // do nothing
953 count ++;
954
955 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
956 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
957 }
958 }
959 }
960 }
961 }
962 else if (controlType == "wxScrollBar")
963 {
964 // DEFAULT VALUE
965 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
966 {
967 controlItem->SetValue1(expr->Nth(count)->IntegerValue());
968 count ++;
969
970 // PAGE LENGTH
971 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
972 {
973 controlItem->SetValue2(expr->Nth(count)->IntegerValue());
974 count ++;
975
976 // OBJECT LENGTH
977 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
978 {
979 controlItem->SetValue3(expr->Nth(count)->IntegerValue());
980 count ++;
981
982 // VIEW LENGTH
983 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
984 controlItem->SetValue5(expr->Nth(count)->IntegerValue());
985 }
986 }
987 }
988 }
989 else if (controlType == "wxListBox")
990 {
991 wxExpr *valueList = (wxExpr *) NULL;
992
993 if ((valueList = expr->Nth(count)) && (valueList->Type() == PrologList))
994 {
995 wxStringList stringList;
996 wxExpr *stringExpr = valueList->GetFirst();
997 while (stringExpr)
998 {
999 stringList.Add(stringExpr->StringValue());
1000 stringExpr = stringExpr->GetNext();
1001 }
1002 controlItem->SetStringValues(stringList);
1003 count ++;
1004 // This is now obsolete: it's in the window style.
1005 // Check for wxSINGLE/wxMULTIPLE
1006 wxExpr *mult = (wxExpr *) NULL;
1007 /*
1008 controlItem->SetValue1(wxLB_SINGLE);
1009 */
1010 if ((mult = expr->Nth(count)) && ((mult->Type() == PrologString)||(mult->Type() == PrologWord)))
1011 {
1012 /*
1013 wxString m(mult->StringValue());
1014 if (m == "wxLB_MULTIPLE")
1015 controlItem->SetValue1(wxLB_MULTIPLE);
1016 else if (m == "wxLB_EXTENDED")
1017 controlItem->SetValue1(wxLB_EXTENDED);
1018 */
1019 // Ignore the value
1020 count ++;
1021 }
1022 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
1023 {
1024 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1025 count ++;
1026 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
1027 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1028 }
1029 }
1030 }
1031 else if (controlType == "wxChoice")
1032 {
1033 wxExpr *valueList = (wxExpr *) NULL;
1034 // Check for default value list
1035 if ((valueList = expr->Nth(count)) && (valueList->Type() == PrologList))
1036 {
1037 wxStringList stringList;
1038 wxExpr *stringExpr = valueList->GetFirst();
1039 while (stringExpr)
1040 {
1041 stringList.Add(stringExpr->StringValue());
1042 stringExpr = stringExpr->GetNext();
1043 }
1044 controlItem->SetStringValues(stringList);
1045
1046 count ++;
1047
1048 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
1049 {
1050 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1051 count ++;
1052
1053 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
1054 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1055 }
1056 }
1057 }
1058 #if wxUSE_COMBOBOX
1059 else if (controlType == "wxComboBox")
1060 {
1061 wxExpr *textValue = expr->Nth(count);
1062 if (textValue && (textValue->Type() == PrologString || textValue->Type() == PrologWord))
1063 {
1064 wxString str(textValue->StringValue());
1065 controlItem->SetValue4(str);
1066
1067 count ++;
1068
1069 wxExpr *valueList = (wxExpr *) NULL;
1070 // Check for default value list
1071 if ((valueList = expr->Nth(count)) && (valueList->Type() == PrologList))
1072 {
1073 wxStringList stringList;
1074 wxExpr *stringExpr = valueList->GetFirst();
1075 while (stringExpr)
1076 {
1077 stringList.Add(stringExpr->StringValue());
1078 stringExpr = stringExpr->GetNext();
1079 }
1080 controlItem->SetStringValues(stringList);
1081
1082 count ++;
1083
1084 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
1085 {
1086 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1087 count ++;
1088
1089 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
1090 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1091 }
1092 }
1093 }
1094 }
1095 #endif
1096 #if 1
1097 else if (controlType == "wxRadioBox")
1098 {
1099 wxExpr *valueList = (wxExpr *) NULL;
1100 // Check for default value list
1101 if ((valueList = expr->Nth(count)) && (valueList->Type() == PrologList))
1102 {
1103 wxStringList stringList;
1104 wxExpr *stringExpr = valueList->GetFirst();
1105 while (stringExpr)
1106 {
1107 stringList.Add(stringExpr->StringValue());
1108 stringExpr = stringExpr->GetNext();
1109 }
1110 controlItem->SetStringValues(stringList);
1111 count ++;
1112
1113 // majorDim (number of rows or cols)
1114 if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger))
1115 {
1116 controlItem->SetValue1(expr->Nth(count)->IntegerValue());
1117 count ++;
1118 }
1119 else
1120 controlItem->SetValue1(0);
1121
1122 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
1123 {
1124 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1125 count ++;
1126
1127 if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList)
1128 controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1129 }
1130 }
1131 }
1132 #endif
1133 else
1134 {
1135 delete controlItem;
1136 return (wxItemResource *) NULL;
1137 }
1138 return controlItem;
1139 }
1140
1141 // Forward declaration
1142 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr);
1143
1144 /*
1145 * Interpet a menu item
1146 */
1147
1148 wxItemResource *wxResourceInterpretMenuItem(wxResourceTable& table, wxExpr *expr)
1149 {
1150 wxItemResource *item = new wxItemResource;
1151
1152 wxExpr *labelExpr = expr->Nth(0);
1153 wxExpr *idExpr = expr->Nth(1);
1154 wxExpr *helpExpr = expr->Nth(2);
1155 wxExpr *checkableExpr = expr->Nth(3);
1156
1157 // Further keywords/attributes to follow sometime...
1158 if (expr->Number() == 0)
1159 {
1160 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1161 item->SetType("wxMenuSeparator");
1162 return item;
1163 }
1164 else
1165 {
1166 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1167 item->SetType("wxMenu"); // Well, menu item, but doesn't matter.
1168 if (labelExpr)
1169 {
1170 wxString str(labelExpr->StringValue());
1171 item->SetTitle(str);
1172 }
1173 if (idExpr)
1174 {
1175 int id = 0;
1176 // If a string or word, must look up in identifier table.
1177 if ((idExpr->Type() == PrologString) || (idExpr->Type() == PrologWord))
1178 {
1179 wxString str(idExpr->StringValue());
1180 id = wxResourceGetIdentifier(str, &table);
1181 if (id == 0)
1182 {
1183 wxLogWarning(_("Could not resolve menu id '%s'. "
1184 "Use (non-zero) integer instead\n"
1185 "or provide #define (see manual for caveats)"),
1186 (const char*) idExpr->StringValue());
1187 }
1188 }
1189 else if (idExpr->Type() == PrologInteger)
1190 id = (int)idExpr->IntegerValue();
1191 item->SetValue1(id);
1192 }
1193 if (helpExpr)
1194 {
1195 wxString str(helpExpr->StringValue());
1196 item->SetValue4(str);
1197 }
1198 if (checkableExpr)
1199 item->SetValue2(checkableExpr->IntegerValue());
1200
1201 // Find the first expression that's a list, for submenu
1202 wxExpr *subMenuExpr = expr->GetFirst();
1203 while (subMenuExpr && (subMenuExpr->Type() != PrologList))
1204 subMenuExpr = subMenuExpr->GetNext();
1205
1206 while (subMenuExpr)
1207 {
1208 wxItemResource *child = wxResourceInterpretMenuItem(table, subMenuExpr);
1209 item->GetChildren().Append(child);
1210 subMenuExpr = subMenuExpr->GetNext();
1211 }
1212 }
1213 return item;
1214 }
1215
1216 /*
1217 * Interpret a nested list as a menu
1218 */
1219 /*
1220 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1221 {
1222 wxItemResource *menu = new wxItemResource;
1223 // menu->SetType(wxTYPE_MENU);
1224 menu->SetType("wxMenu");
1225 wxExpr *element = expr->GetFirst();
1226 while (element)
1227 {
1228 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1229 if (item)
1230 menu->GetChildren().Append(item);
1231 element = element->GetNext();
1232 }
1233 return menu;
1234 }
1235 */
1236
1237 wxItemResource *wxResourceInterpretMenu(wxResourceTable& table, wxExpr *expr)
1238 {
1239 wxExpr *listExpr = (wxExpr *) NULL;
1240 expr->GetAttributeValue("menu", &listExpr);
1241 if (!listExpr)
1242 return (wxItemResource *) NULL;
1243
1244 wxItemResource *menuResource = wxResourceInterpretMenuItem(table, listExpr);
1245
1246 if (!menuResource)
1247 return (wxItemResource *) NULL;
1248
1249 wxString name;
1250 if (expr->GetAttributeValue("name", name))
1251 {
1252 menuResource->SetName(name);
1253 }
1254
1255 return menuResource;
1256 }
1257
1258 wxItemResource *wxResourceInterpretMenuBar(wxResourceTable& table, wxExpr *expr)
1259 {
1260 wxExpr *listExpr = (wxExpr *) NULL;
1261 expr->GetAttributeValue("menu", &listExpr);
1262 if (!listExpr)
1263 return (wxItemResource *) NULL;
1264
1265 wxItemResource *resource = new wxItemResource;
1266 resource->SetType("wxMenu");
1267 // resource->SetType(wxTYPE_MENU);
1268
1269 wxExpr *element = listExpr->GetFirst();
1270 while (element)
1271 {
1272 wxItemResource *menuResource = wxResourceInterpretMenuItem(table, listExpr);
1273 resource->GetChildren().Append(menuResource);
1274 element = element->GetNext();
1275 }
1276
1277 wxString name;
1278 if (expr->GetAttributeValue("name", name))
1279 {
1280 resource->SetName(name);
1281 }
1282
1283 return resource;
1284 }
1285
1286 wxItemResource *wxResourceInterpretString(wxResourceTable& WXUNUSED(table), wxExpr *WXUNUSED(expr))
1287 {
1288 return (wxItemResource *) NULL;
1289 }
1290
1291 wxItemResource *wxResourceInterpretBitmap(wxResourceTable& WXUNUSED(table), wxExpr *expr)
1292 {
1293 wxItemResource *bitmapItem = new wxItemResource;
1294 // bitmapItem->SetType(wxTYPE_BITMAP);
1295 bitmapItem->SetType("wxBitmap");
1296 wxString name;
1297 if (expr->GetAttributeValue("name", name))
1298 {
1299 bitmapItem->SetName(name);
1300 }
1301 // Now parse all bitmap specifications
1302 wxExpr *bitmapExpr = expr->GetFirst();
1303 while (bitmapExpr)
1304 {
1305 if (bitmapExpr->Number() == 3)
1306 {
1307 wxString bitmapKeyword(bitmapExpr->Nth(1)->StringValue());
1308 if (bitmapKeyword == "bitmap" || bitmapKeyword == "icon")
1309 {
1310 // The value part: always a list.
1311 wxExpr *listExpr = bitmapExpr->Nth(2);
1312 if (listExpr->Type() == PrologList)
1313 {
1314 wxItemResource *bitmapSpec = new wxItemResource;
1315 // bitmapSpec->SetType(wxTYPE_BITMAP);
1316 bitmapSpec->SetType("wxBitmap");
1317
1318 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1319 // where everything after 'filename' is optional.
1320 wxExpr *nameExpr = listExpr->Nth(0);
1321 wxExpr *typeExpr = listExpr->Nth(1);
1322 wxExpr *platformExpr = listExpr->Nth(2);
1323 wxExpr *coloursExpr = listExpr->Nth(3);
1324 wxExpr *xresExpr = listExpr->Nth(4);
1325 wxExpr *yresExpr = listExpr->Nth(5);
1326 if (nameExpr && nameExpr->StringValue() != "")
1327 {
1328 bitmapSpec->SetName(nameExpr->StringValue());
1329 }
1330 if (typeExpr && typeExpr->StringValue() != "")
1331 {
1332 bitmapSpec->SetValue1(wxParseWindowStyle(typeExpr->StringValue()));
1333 }
1334 else
1335 bitmapSpec->SetValue1(0);
1336
1337 if (platformExpr && platformExpr->StringValue() != "")
1338 {
1339 wxString plat(platformExpr->StringValue());
1340 if (plat == "windows" || plat == "WINDOWS")
1341 bitmapSpec->SetValue2(RESOURCE_PLATFORM_WINDOWS);
1342 else if (plat == "x" || plat == "X")
1343 bitmapSpec->SetValue2(RESOURCE_PLATFORM_X);
1344 else if (plat == "mac" || plat == "MAC")
1345 bitmapSpec->SetValue2(RESOURCE_PLATFORM_MAC);
1346 else
1347 bitmapSpec->SetValue2(RESOURCE_PLATFORM_ANY);
1348 }
1349 else
1350 bitmapSpec->SetValue2(RESOURCE_PLATFORM_ANY);
1351
1352 if (coloursExpr)
1353 bitmapSpec->SetValue3(coloursExpr->IntegerValue());
1354 int xres = 0;
1355 int yres = 0;
1356 if (xresExpr)
1357 xres = (int)xresExpr->IntegerValue();
1358 if (yresExpr)
1359 yres = (int)yresExpr->IntegerValue();
1360 bitmapSpec->SetSize(0, 0, xres, yres);
1361
1362 bitmapItem->GetChildren().Append(bitmapSpec);
1363 }
1364 }
1365 }
1366 bitmapExpr = bitmapExpr->GetNext();
1367 }
1368
1369 return bitmapItem;
1370 }
1371
1372 wxItemResource *wxResourceInterpretIcon(wxResourceTable& table, wxExpr *expr)
1373 {
1374 wxItemResource *item = wxResourceInterpretBitmap(table, expr);
1375 if (item)
1376 {
1377 // item->SetType(wxTYPE_ICON);
1378 item->SetType("wxIcon");
1379 return item;
1380 }
1381 else
1382 return (wxItemResource *) NULL;
1383 }
1384
1385 // Interpret list expression as a font
1386 wxFont wxResourceInterpretFontSpec(wxExpr *expr)
1387 {
1388 if (expr->Type() != PrologList)
1389 return wxNullFont;
1390
1391 int point = 10;
1392 int family = wxSWISS;
1393 int style = wxNORMAL;
1394 int weight = wxNORMAL;
1395 int underline = 0;
1396 wxString faceName("");
1397
1398 wxExpr *pointExpr = expr->Nth(0);
1399 wxExpr *familyExpr = expr->Nth(1);
1400 wxExpr *styleExpr = expr->Nth(2);
1401 wxExpr *weightExpr = expr->Nth(3);
1402 wxExpr *underlineExpr = expr->Nth(4);
1403 wxExpr *faceNameExpr = expr->Nth(5);
1404 if (pointExpr)
1405 point = (int)pointExpr->IntegerValue();
1406
1407 wxString str;
1408 if (familyExpr)
1409 {
1410 str = familyExpr->StringValue();
1411 family = (int)wxParseWindowStyle(str);
1412 }
1413 if (styleExpr)
1414 {
1415 str = styleExpr->StringValue();
1416 style = (int)wxParseWindowStyle(str);
1417 }
1418 if (weightExpr)
1419 {
1420 str = weightExpr->StringValue();
1421 weight = (int)wxParseWindowStyle(str);
1422 }
1423 if (underlineExpr)
1424 underline = (int)underlineExpr->IntegerValue();
1425 if (faceNameExpr)
1426 faceName = faceNameExpr->StringValue();
1427
1428 wxFont font(point, family, style, weight, (underline != 0), faceName);
1429 return font;
1430 }
1431
1432 // Separate file for the remainder of this, for BC++/Win16
1433
1434 #if !((defined(__BORLANDC__) || defined(__SC__)) && defined(__WIN16__))
1435 /*
1436 * (Re)allocate buffer for reading in from resource file
1437 */
1438
1439 bool wxReallocateResourceBuffer()
1440 {
1441 if (!wxResourceBuffer)
1442 {
1443 wxResourceBufferSize = 1000;
1444 wxResourceBuffer = new char[wxResourceBufferSize];
1445 return TRUE;
1446 }
1447 if (wxResourceBuffer)
1448 {
1449 long newSize = wxResourceBufferSize + 1000;
1450 char *tmp = new char[(int)newSize];
1451 strncpy(tmp, wxResourceBuffer, (int)wxResourceBufferCount);
1452 delete[] wxResourceBuffer;
1453 wxResourceBuffer = tmp;
1454 wxResourceBufferSize = newSize;
1455 }
1456 return TRUE;
1457 }
1458
1459 static bool wxEatWhiteSpace(FILE *fd)
1460 {
1461 int ch = getc(fd);
1462 if ((ch != ' ') && (ch != '/') && (ch != ' ') && (ch != 10) && (ch != 13) && (ch != 9))
1463 {
1464 ungetc(ch, fd);
1465 return TRUE;
1466 }
1467
1468 // Eat whitespace
1469 while (ch == ' ' || ch == 10 || ch == 13 || ch == 9)
1470 ch = getc(fd);
1471 // Check for comment
1472 if (ch == '/')
1473 {
1474 ch = getc(fd);
1475 if (ch == '*')
1476 {
1477 bool finished = FALSE;
1478 while (!finished)
1479 {
1480 ch = getc(fd);
1481 if (ch == EOF)
1482 return FALSE;
1483 if (ch == '*')
1484 {
1485 int newCh = getc(fd);
1486 if (newCh == '/')
1487 finished = TRUE;
1488 else
1489 {
1490 ungetc(newCh, fd);
1491 }
1492 }
1493 }
1494 }
1495 else // False alarm
1496 return FALSE;
1497 }
1498 else
1499 ungetc(ch, fd);
1500 return wxEatWhiteSpace(fd);
1501 }
1502
1503 bool wxGetResourceToken(FILE *fd)
1504 {
1505 if (!wxResourceBuffer)
1506 wxReallocateResourceBuffer();
1507 wxResourceBuffer[0] = 0;
1508 wxEatWhiteSpace(fd);
1509
1510 int ch = getc(fd);
1511 if (ch == '"')
1512 {
1513 // Get string
1514 wxResourceBufferCount = 0;
1515 ch = getc(fd);
1516 while (ch != '"')
1517 {
1518 int actualCh = ch;
1519 if (ch == EOF)
1520 {
1521 wxResourceBuffer[wxResourceBufferCount] = 0;
1522 return FALSE;
1523 }
1524 // Escaped characters
1525 else if (ch == '\\')
1526 {
1527 int newCh = getc(fd);
1528 if (newCh == '"')
1529 actualCh = '"';
1530 else if (newCh == 10)
1531 actualCh = 10;
1532 else
1533 {
1534 ungetc(newCh, fd);
1535 }
1536 }
1537
1538 if (wxResourceBufferCount >= wxResourceBufferSize-1)
1539 wxReallocateResourceBuffer();
1540 wxResourceBuffer[wxResourceBufferCount] = (char)actualCh;
1541 wxResourceBufferCount ++;
1542 ch = getc(fd);
1543 }
1544 wxResourceBuffer[wxResourceBufferCount] = 0;
1545 }
1546 else
1547 {
1548 wxResourceBufferCount = 0;
1549 // Any other token
1550 while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10)
1551 {
1552 if (wxResourceBufferCount >= wxResourceBufferSize-1)
1553 wxReallocateResourceBuffer();
1554 wxResourceBuffer[wxResourceBufferCount] = (char)ch;
1555 wxResourceBufferCount ++;
1556
1557 ch = getc(fd);
1558 }
1559 wxResourceBuffer[wxResourceBufferCount] = 0;
1560 if (ch == EOF)
1561 return FALSE;
1562 }
1563 return TRUE;
1564 }
1565
1566 /*
1567 * Files are in form:
1568 static char *name = "....";
1569 with possible comments.
1570 */
1571
1572 bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table)
1573 {
1574 if (!table)
1575 table = wxDefaultResourceTable;
1576
1577 // static or #define
1578 if (!wxGetResourceToken(fd))
1579 {
1580 *eof = TRUE;
1581 return FALSE;
1582 }
1583
1584 if (strcmp(wxResourceBuffer, "#define") == 0)
1585 {
1586 wxGetResourceToken(fd);
1587 char *name = copystring(wxResourceBuffer);
1588 wxGetResourceToken(fd);
1589 char *value = copystring(wxResourceBuffer);
1590 if (isalpha(value[0]))
1591 {
1592 int val = (int)atol(value);
1593 wxResourceAddIdentifier(name, val, table);
1594 }
1595 else
1596 {
1597 wxLogWarning(_("#define %s must be an integer."), name);
1598 delete[] name;
1599 delete[] value;
1600 return FALSE;
1601 }
1602 delete[] name;
1603 delete[] value;
1604
1605 return TRUE;
1606 }
1607 else if (strcmp(wxResourceBuffer, "#include") == 0)
1608 {
1609 wxGetResourceToken(fd);
1610 char *name = copystring(wxResourceBuffer);
1611 char *actualName = name;
1612 if (name[0] == '"')
1613 actualName = name + 1;
1614 int len = strlen(name);
1615 if ((len > 0) && (name[len-1] == '"'))
1616 name[len-1] = 0;
1617 if (!wxResourceParseIncludeFile(actualName, table))
1618 {
1619 wxLogWarning(_("Could not find resource include file %s."), actualName);
1620 }
1621 delete[] name;
1622 return TRUE;
1623 }
1624 else if (strcmp(wxResourceBuffer, "static") != 0)
1625 {
1626 char buf[300];
1627 strcpy(buf, _("Found "));
1628 strncat(buf, wxResourceBuffer, 30);
1629 strcat(buf, _(", expected static, #include or #define\nwhilst parsing resource."));
1630 wxLogWarning(buf);
1631 return FALSE;
1632 }
1633
1634 // char
1635 if (!wxGetResourceToken(fd))
1636 {
1637 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1638 *eof = TRUE;
1639 return FALSE;
1640 }
1641
1642 if (strcmp(wxResourceBuffer, "char") != 0)
1643 {
1644 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1645 return FALSE;
1646 }
1647
1648 // *name
1649 if (!wxGetResourceToken(fd))
1650 {
1651 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1652 *eof = TRUE;
1653 return FALSE;
1654 }
1655
1656 if (wxResourceBuffer[0] != '*')
1657 {
1658 wxLogWarning(_("Expected '*' whilst parsing resource."));
1659 return FALSE;
1660 }
1661 char nameBuf[100];
1662 strncpy(nameBuf, wxResourceBuffer+1, 99);
1663
1664 // =
1665 if (!wxGetResourceToken(fd))
1666 {
1667 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1668 *eof = TRUE;
1669 return FALSE;
1670 }
1671
1672 if (strcmp(wxResourceBuffer, "=") != 0)
1673 {
1674 wxLogWarning(_("Expected '=' whilst parsing resource."));
1675 return FALSE;
1676 }
1677
1678 // String
1679 if (!wxGetResourceToken(fd))
1680 {
1681 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1682 *eof = TRUE;
1683 return FALSE;
1684 }
1685 else
1686 {
1687 if (!db.ReadPrologFromString(wxResourceBuffer))
1688 {
1689 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf);
1690 return FALSE;
1691 }
1692 }
1693 // Semicolon
1694 if (!wxGetResourceToken(fd))
1695 {
1696 *eof = TRUE;
1697 }
1698 return TRUE;
1699 }
1700
1701 /*
1702 * Parses string window style into integer window style
1703 */
1704
1705 /*
1706 * Style flag parsing, e.g.
1707 * "wxSYSTEM_MENU | wxBORDER" -> integer
1708 */
1709
1710 char* wxResourceParseWord(char*s, int *i)
1711 {
1712 if (!s)
1713 return (char*) NULL;
1714
1715 static char buf[150];
1716 int len = strlen(s);
1717 int j = 0;
1718 int ii = *i;
1719 while ((ii < len) && (isalpha(s[ii]) || (s[ii] == '_')))
1720 {
1721 buf[j] = s[ii];
1722 j ++;
1723 ii ++;
1724 }
1725 buf[j] = 0;
1726
1727 // Eat whitespace and conjunction characters
1728 while ((ii < len) &&
1729 ((s[ii] == ' ') || (s[ii] == '|') || (s[ii] == ',')))
1730 {
1731 ii ++;
1732 }
1733 *i = ii;
1734 if (j == 0)
1735 return (char*) NULL;
1736 else
1737 return buf;
1738 }
1739
1740 struct wxResourceBitListStruct
1741 {
1742 char *word;
1743 long bits;
1744 };
1745
1746 static wxResourceBitListStruct wxResourceBitListTable[] =
1747 {
1748 /* wxListBox */
1749 { "wxSINGLE", wxLB_SINGLE },
1750 { "wxMULTIPLE", wxLB_MULTIPLE },
1751 { "wxEXTENDED", wxLB_EXTENDED },
1752 { "wxLB_SINGLE", wxLB_SINGLE },
1753 { "wxLB_MULTIPLE", wxLB_MULTIPLE },
1754 { "wxLB_EXTENDED", wxLB_EXTENDED },
1755 { "wxLB_NEEDED_SB", wxLB_NEEDED_SB },
1756 { "wxLB_ALWAYS_SB", wxLB_ALWAYS_SB },
1757 { "wxLB_SORT", wxLB_SORT },
1758 { "wxLB_OWNERDRAW", wxLB_OWNERDRAW },
1759 { "wxLB_HSCROLL", wxLB_HSCROLL },
1760
1761 /* wxComboxBox */
1762 { "wxCB_SIMPLE", wxCB_SIMPLE },
1763 { "wxCB_DROPDOWN", wxCB_DROPDOWN },
1764 { "wxCB_READONLY", wxCB_READONLY },
1765 { "wxCB_SORT", wxCB_SORT },
1766
1767 /* wxGauge */
1768 { "wxGA_PROGRESSBAR", wxGA_PROGRESSBAR },
1769 { "wxGA_HORIZONTAL", wxGA_HORIZONTAL },
1770 { "wxGA_VERTICAL", wxGA_VERTICAL },
1771
1772 /* wxTextCtrl */
1773 { "wxPASSWORD", wxPASSWORD},
1774 { "wxPROCESS_ENTER", wxPROCESS_ENTER},
1775 { "wxTE_PASSWORD", wxTE_PASSWORD},
1776 { "wxTE_READONLY", wxTE_READONLY},
1777 { "wxTE_PROCESS_ENTER", wxTE_PROCESS_ENTER},
1778 { "wxTE_MULTILINE", wxTE_MULTILINE},
1779
1780 /* wxRadioBox/wxRadioButton */
1781 { "wxRB_GROUP", wxRB_GROUP },
1782 { "wxRA_SPECIFY_COLS", wxRA_SPECIFY_COLS },
1783 { "wxRA_SPECIFY_ROWS", wxRA_SPECIFY_ROWS },
1784 { "wxRA_HORIZONTAL", wxRA_HORIZONTAL },
1785 { "wxRA_VERTICAL", wxRA_VERTICAL },
1786
1787 /* wxSlider */
1788 { "wxSL_HORIZONTAL", wxSL_HORIZONTAL },
1789 { "wxSL_VERTICAL", wxSL_VERTICAL },
1790 { "wxSL_AUTOTICKS", wxSL_AUTOTICKS },
1791 { "wxSL_LABELS", wxSL_LABELS },
1792 { "wxSL_LEFT", wxSL_LEFT },
1793 { "wxSL_TOP", wxSL_TOP },
1794 { "wxSL_RIGHT", wxSL_RIGHT },
1795 { "wxSL_BOTTOM", wxSL_BOTTOM },
1796 { "wxSL_BOTH", wxSL_BOTH },
1797 { "wxSL_SELRANGE", wxSL_SELRANGE },
1798
1799 /* wxScrollBar */
1800 { "wxSB_HORIZONTAL", wxSB_HORIZONTAL },
1801 { "wxSB_VERTICAL", wxSB_VERTICAL },
1802
1803 /* wxButton */
1804 { "wxBU_AUTODRAW", wxBU_AUTODRAW },
1805 { "wxBU_NOAUTODRAW", wxBU_NOAUTODRAW },
1806
1807 /* wxTreeCtrl */
1808 { "wxTR_HAS_BUTTONS", wxTR_HAS_BUTTONS },
1809 { "wxTR_EDIT_LABELS", wxTR_EDIT_LABELS },
1810 { "wxTR_LINES_AT_ROOT", wxTR_LINES_AT_ROOT },
1811
1812 /* wxListCtrl */
1813 { "wxLC_ICON", wxLC_ICON },
1814 { "wxLC_SMALL_ICON", wxLC_SMALL_ICON },
1815 { "wxLC_LIST", wxLC_LIST },
1816 { "wxLC_REPORT", wxLC_REPORT },
1817 { "wxLC_ALIGN_TOP", wxLC_ALIGN_TOP },
1818 { "wxLC_ALIGN_LEFT", wxLC_ALIGN_LEFT },
1819 { "wxLC_AUTOARRANGE", wxLC_AUTOARRANGE },
1820 { "wxLC_USER_TEXT", wxLC_USER_TEXT },
1821 { "wxLC_EDIT_LABELS", wxLC_EDIT_LABELS },
1822 { "wxLC_NO_HEADER", wxLC_NO_HEADER },
1823 { "wxLC_NO_SORT_HEADER", wxLC_NO_SORT_HEADER },
1824 { "wxLC_SINGLE_SEL", wxLC_SINGLE_SEL },
1825 { "wxLC_SORT_ASCENDING", wxLC_SORT_ASCENDING },
1826 { "wxLC_SORT_DESCENDING", wxLC_SORT_DESCENDING },
1827
1828 /* wxSpinButton */
1829 { "wxSP_VERTICAL", wxSP_VERTICAL},
1830 { "wxSP_HORIZONTAL", wxSP_HORIZONTAL},
1831 { "wxSP_ARROW_KEYS", wxSP_ARROW_KEYS},
1832 { "wxSP_WRAP", wxSP_WRAP},
1833
1834 /* wxSplitterWnd */
1835 { "wxSP_NOBORDER", wxSP_NOBORDER},
1836 { "wxSP_3D", wxSP_3D},
1837 { "wxSP_BORDER", wxSP_BORDER},
1838
1839 /* wxTabCtrl */
1840 { "wxTC_MULTILINE", wxTC_MULTILINE},
1841 { "wxTC_RIGHTJUSTIFY", wxTC_RIGHTJUSTIFY},
1842 { "wxTC_FIXEDWIDTH", wxTC_FIXEDWIDTH},
1843 { "wxTC_OWNERDRAW", wxTC_OWNERDRAW},
1844
1845 /* wxStatusBar95 */
1846 { "wxST_SIZEGRIP", wxST_SIZEGRIP},
1847
1848 /* wxControl */
1849 { "wxFIXED_LENGTH", wxFIXED_LENGTH},
1850 { "wxALIGN_LEFT", wxALIGN_LEFT},
1851 { "wxALIGN_CENTER", wxALIGN_CENTER},
1852 { "wxALIGN_CENTRE", wxALIGN_CENTRE},
1853 { "wxALIGN_RIGHT", wxALIGN_RIGHT},
1854 { "wxCOLOURED", wxCOLOURED},
1855
1856 /* wxToolBar */
1857 { "wxTB_3DBUTTONS", wxTB_3DBUTTONS},
1858 { "wxTB_HORIZONTAL", wxTB_HORIZONTAL},
1859 { "wxTB_VERTICAL", wxTB_VERTICAL},
1860 { "wxTB_FLAT", wxTB_FLAT},
1861
1862 /* Generic */
1863 { "wxVSCROLL", wxVSCROLL },
1864 { "wxHSCROLL", wxHSCROLL },
1865 { "wxCAPTION", wxCAPTION },
1866 { "wxSTAY_ON_TOP", wxSTAY_ON_TOP},
1867 { "wxICONIZE", wxICONIZE},
1868 { "wxMINIMIZE", wxICONIZE},
1869 { "wxMAXIMIZE", wxMAXIMIZE},
1870 { "wxSDI", 0},
1871 { "wxMDI_PARENT", 0},
1872 { "wxMDI_CHILD", 0},
1873 { "wxTHICK_FRAME", wxTHICK_FRAME},
1874 { "wxRESIZE_BORDER", wxRESIZE_BORDER},
1875 { "wxSYSTEM_MENU", wxSYSTEM_MENU},
1876 { "wxMINIMIZE_BOX", wxMINIMIZE_BOX},
1877 { "wxMAXIMIZE_BOX", wxMAXIMIZE_BOX},
1878 { "wxRESIZE_BOX", wxRESIZE_BOX},
1879 { "wxDEFAULT_FRAME_STYLE", wxDEFAULT_FRAME_STYLE},
1880 { "wxDEFAULT_FRAME", wxDEFAULT_FRAME_STYLE},
1881 { "wxDEFAULT_DIALOG_STYLE", wxDEFAULT_DIALOG_STYLE},
1882 { "wxBORDER", wxBORDER},
1883 { "wxRETAINED", wxRETAINED},
1884 { "wxNATIVE_IMPL", 0},
1885 { "wxEXTENDED_IMPL", 0},
1886 { "wxBACKINGSTORE", wxBACKINGSTORE},
1887 // { "wxFLAT", wxFLAT},
1888 // { "wxMOTIF_RESIZE", wxMOTIF_RESIZE},
1889 { "wxFIXED_LENGTH", 0},
1890 { "wxDOUBLE_BORDER", wxDOUBLE_BORDER},
1891 { "wxSUNKEN_BORDER", wxSUNKEN_BORDER},
1892 { "wxRAISED_BORDER", wxRAISED_BORDER},
1893 { "wxSIMPLE_BORDER", wxSIMPLE_BORDER},
1894 { "wxSTATIC_BORDER", wxSTATIC_BORDER},
1895 { "wxTRANSPARENT_WINDOW", wxTRANSPARENT_WINDOW},
1896 { "wxNO_BORDER", wxNO_BORDER},
1897 { "wxCLIP_CHILDREN", wxCLIP_CHILDREN},
1898
1899 { "wxTINY_CAPTION_HORIZ", wxTINY_CAPTION_HORIZ},
1900 { "wxTINY_CAPTION_VERT", wxTINY_CAPTION_VERT},
1901
1902 // Text font families
1903 { "wxDEFAULT", wxDEFAULT},
1904 { "wxDECORATIVE", wxDECORATIVE},
1905 { "wxROMAN", wxROMAN},
1906 { "wxSCRIPT", wxSCRIPT},
1907 { "wxSWISS", wxSWISS},
1908 { "wxMODERN", wxMODERN},
1909 { "wxTELETYPE", wxTELETYPE},
1910 { "wxVARIABLE", wxVARIABLE},
1911 { "wxFIXED", wxFIXED},
1912 { "wxNORMAL", wxNORMAL},
1913 { "wxLIGHT", wxLIGHT},
1914 { "wxBOLD", wxBOLD},
1915 { "wxITALIC", wxITALIC},
1916 { "wxSLANT", wxSLANT},
1917 { "wxSOLID", wxSOLID},
1918 { "wxDOT", wxDOT},
1919 { "wxLONG_DASH", wxLONG_DASH},
1920 { "wxSHORT_DASH", wxSHORT_DASH},
1921 { "wxDOT_DASH", wxDOT_DASH},
1922 { "wxUSER_DASH", wxUSER_DASH},
1923 { "wxTRANSPARENT", wxTRANSPARENT},
1924 { "wxSTIPPLE", wxSTIPPLE},
1925 { "wxBDIAGONAL_HATCH", wxBDIAGONAL_HATCH},
1926 { "wxCROSSDIAG_HATCH", wxCROSSDIAG_HATCH},
1927 { "wxFDIAGONAL_HATCH", wxFDIAGONAL_HATCH},
1928 { "wxCROSS_HATCH", wxCROSS_HATCH},
1929 { "wxHORIZONTAL_HATCH", wxHORIZONTAL_HATCH},
1930 { "wxVERTICAL_HATCH", wxVERTICAL_HATCH},
1931 { "wxJOIN_BEVEL", wxJOIN_BEVEL},
1932 { "wxJOIN_MITER", wxJOIN_MITER},
1933 { "wxJOIN_ROUND", wxJOIN_ROUND},
1934 { "wxCAP_ROUND", wxCAP_ROUND},
1935 { "wxCAP_PROJECTING", wxCAP_PROJECTING},
1936 { "wxCAP_BUTT", wxCAP_BUTT},
1937
1938 // Logical ops
1939 { "wxCLEAR", wxCLEAR},
1940 { "wxXOR", wxXOR},
1941 { "wxINVERT", wxINVERT},
1942 { "wxOR_REVERSE", wxOR_REVERSE},
1943 { "wxAND_REVERSE", wxAND_REVERSE},
1944 { "wxCOPY", wxCOPY},
1945 { "wxAND", wxAND},
1946 { "wxAND_INVERT", wxAND_INVERT},
1947 { "wxNO_OP", wxNO_OP},
1948 { "wxNOR", wxNOR},
1949 { "wxEQUIV", wxEQUIV},
1950 { "wxSRC_INVERT", wxSRC_INVERT},
1951 { "wxOR_INVERT", wxOR_INVERT},
1952 { "wxNAND", wxNAND},
1953 { "wxOR", wxOR},
1954 { "wxSET", wxSET},
1955
1956 { "wxFLOOD_SURFACE", wxFLOOD_SURFACE},
1957 { "wxFLOOD_BORDER", wxFLOOD_BORDER},
1958 { "wxODDEVEN_RULE", wxODDEVEN_RULE},
1959 { "wxWINDING_RULE", wxWINDING_RULE},
1960 { "wxHORIZONTAL", wxHORIZONTAL},
1961 { "wxVERTICAL", wxVERTICAL},
1962 { "wxBOTH", wxBOTH},
1963 { "wxCENTER_FRAME", wxCENTER_FRAME},
1964 { "wxOK", wxOK},
1965 { "wxYES_NO", wxYES_NO},
1966 { "wxCANCEL", wxCANCEL},
1967 { "wxYES", wxYES},
1968 { "wxNO", wxNO},
1969 { "wxICON_EXCLAMATION", wxICON_EXCLAMATION},
1970 { "wxICON_HAND", wxICON_HAND},
1971 { "wxICON_QUESTION", wxICON_QUESTION},
1972 { "wxICON_INFORMATION", wxICON_INFORMATION},
1973 { "wxICON_STOP", wxICON_STOP},
1974 { "wxICON_ASTERISK", wxICON_ASTERISK},
1975 { "wxICON_MASK", wxICON_MASK},
1976 { "wxCENTRE", wxCENTRE},
1977 { "wxCENTER", wxCENTRE},
1978 { "wxUSER_COLOURS", wxUSER_COLOURS},
1979 { "wxVERTICAL_LABEL", 0},
1980 { "wxHORIZONTAL_LABEL", 0},
1981
1982 // Bitmap types (not strictly styles)
1983 { "wxBITMAP_TYPE_XPM", wxBITMAP_TYPE_XPM},
1984 { "wxBITMAP_TYPE_XBM", wxBITMAP_TYPE_XBM},
1985 { "wxBITMAP_TYPE_BMP", wxBITMAP_TYPE_BMP},
1986 { "wxBITMAP_TYPE_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE},
1987 { "wxBITMAP_TYPE_BMP_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE},
1988 { "wxBITMAP_TYPE_GIF", wxBITMAP_TYPE_GIF},
1989 { "wxBITMAP_TYPE_TIF", wxBITMAP_TYPE_TIF},
1990 { "wxBITMAP_TYPE_ICO", wxBITMAP_TYPE_ICO},
1991 { "wxBITMAP_TYPE_ICO_RESOURCE", wxBITMAP_TYPE_ICO_RESOURCE},
1992 { "wxBITMAP_TYPE_CUR", wxBITMAP_TYPE_CUR},
1993 { "wxBITMAP_TYPE_CUR_RESOURCE", wxBITMAP_TYPE_CUR_RESOURCE},
1994 { "wxBITMAP_TYPE_XBM_DATA", wxBITMAP_TYPE_XBM_DATA},
1995 { "wxBITMAP_TYPE_XPM_DATA", wxBITMAP_TYPE_XPM_DATA},
1996 { "wxBITMAP_TYPE_ANY", wxBITMAP_TYPE_ANY}
1997 };
1998
1999 static int wxResourceBitListCount = (sizeof(wxResourceBitListTable)/sizeof(wxResourceBitListStruct));
2000
2001 long wxParseWindowStyle(const wxString& bitListString)
2002 {
2003 int i = 0;
2004 char *word;
2005 long bitList = 0;
2006 while ((word = wxResourceParseWord((char*) (const char*) bitListString, &i)))
2007 {
2008 bool found = FALSE;
2009 int j;
2010 for (j = 0; j < wxResourceBitListCount; j++)
2011 if (strcmp(wxResourceBitListTable[j].word, word) == 0)
2012 {
2013 bitList |= wxResourceBitListTable[j].bits;
2014 found = TRUE;
2015 break;
2016 }
2017 if (!found)
2018 {
2019 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word);
2020 return 0;
2021 }
2022 }
2023 return bitList;
2024 }
2025
2026 /*
2027 * Load a bitmap from a wxWindows resource, choosing an optimum
2028 * depth and appropriate type.
2029 */
2030
2031 wxBitmap wxResourceCreateBitmap(const wxString& resource, wxResourceTable *table)
2032 {
2033 if (!table)
2034 table = wxDefaultResourceTable;
2035
2036 wxItemResource *item = table->FindResource(resource);
2037 if (item)
2038 {
2039 if ((item->GetType() == "") || (item->GetType() != "wxBitmap"))
2040 {
2041 wxLogWarning(_("%s not a bitmap resource specification."), (const char*) resource);
2042 return wxNullBitmap;
2043 }
2044 int thisDepth = wxDisplayDepth();
2045 long thisNoColours = (long)pow(2.0, (double)thisDepth);
2046
2047 wxItemResource *optResource = (wxItemResource *) NULL;
2048
2049 // Try to find optimum bitmap for this platform/colour depth
2050 wxNode *node = item->GetChildren().First();
2051 while (node)
2052 {
2053 wxItemResource *child = (wxItemResource *)node->Data();
2054 int platform = (int)child->GetValue2();
2055 int noColours = (int)child->GetValue3();
2056 /*
2057 char *name = child->GetName();
2058 int bitmapType = (int)child->GetValue1();
2059 int xRes = child->GetWidth();
2060 int yRes = child->GetHeight();
2061 */
2062
2063 switch (platform)
2064 {
2065 case RESOURCE_PLATFORM_ANY:
2066 {
2067 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
2068 optResource = child;
2069 else
2070 {
2071 // Maximise the number of colours.
2072 // If noColours is zero (unspecified), then assume this
2073 // is the right one.
2074 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
2075 optResource = child;
2076 }
2077 break;
2078 }
2079 #ifdef __WXMSW__
2080 case RESOURCE_PLATFORM_WINDOWS:
2081 {
2082 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
2083 optResource = child;
2084 else
2085 {
2086 // Maximise the number of colours
2087 if ((noColours > 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
2088 optResource = child;
2089 }
2090 break;
2091 }
2092 #endif
2093 #ifdef __WXGTK__
2094 case RESOURCE_PLATFORM_X:
2095 {
2096 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
2097 optResource = child;
2098 else
2099 {
2100 // Maximise the number of colours
2101 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
2102 optResource = child;
2103 }
2104 break;
2105 }
2106 #endif
2107 #ifdef wx_max
2108 case RESOURCE_PLATFORM_MAC:
2109 {
2110 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
2111 optResource = child;
2112 else
2113 {
2114 // Maximise the number of colours
2115 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
2116 optResource = child;
2117 }
2118 break;
2119 }
2120 #endif
2121 default:
2122 break;
2123 }
2124 node = node->Next();
2125 }
2126 // If no matching resource, fail.
2127 if (!optResource)
2128 return wxNullBitmap;
2129
2130 wxString name = optResource->GetName();
2131 int bitmapType = (int)optResource->GetValue1();
2132 switch (bitmapType)
2133 {
2134 case wxBITMAP_TYPE_XBM_DATA:
2135 {
2136 #ifdef __WXGTK__
2137 wxItemResource *item = table->FindResource(name);
2138 if (!item)
2139 {
2140 wxLogWarning(_("Failed to find XBM resource %s.\n"
2141 "Forgot to use wxResourceLoadBitmapData?"), (const char*) name);
2142 return wxNullBitmap;
2143 }
2144 return wxBitmap(item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3()) ;
2145 #else
2146 wxLogWarning(_("No XBM facility available!"));
2147 #endif
2148 break;
2149 }
2150 case wxBITMAP_TYPE_XPM_DATA:
2151 {
2152 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2153 wxItemResource *item = table->FindResource(name);
2154 if (!item)
2155 {
2156 wxLogWarning(_("Failed to find XPM resource %s.\n"
2157 "Forgot to use wxResourceLoadBitmapData?"), (const char*) name);
2158 return wxNullBitmap;
2159 }
2160 return wxBitmap(item->GetValue1());
2161 #else
2162 wxLogWarning(_("No XPM facility available!"));
2163 #endif
2164 break;
2165 }
2166 default:
2167 {
2168 return wxBitmap(name, bitmapType);
2169 break;
2170 }
2171 }
2172 return wxNullBitmap;
2173 }
2174 else
2175 {
2176 wxLogWarning(_("Bitmap resource specification %s not found."), (const char*) resource);
2177 return wxNullBitmap;
2178 }
2179 }
2180
2181 /*
2182 * Load an icon from a wxWindows resource, choosing an optimum
2183 * depth and appropriate type.
2184 */
2185
2186 wxIcon wxResourceCreateIcon(const wxString& resource, wxResourceTable *table)
2187 {
2188 if (!table)
2189 table = wxDefaultResourceTable;
2190
2191 wxItemResource *item = table->FindResource(resource);
2192 if (item)
2193 {
2194 if ((item->GetType() == "") || strcmp(item->GetType(), "wxIcon") != 0)
2195 {
2196 wxLogWarning(_("%s not an icon resource specification."), (const char*) resource);
2197 return wxNullIcon;
2198 }
2199 int thisDepth = wxDisplayDepth();
2200 long thisNoColours = (long)pow(2.0, (double)thisDepth);
2201
2202 wxItemResource *optResource = (wxItemResource *) NULL;
2203
2204 // Try to find optimum icon for this platform/colour depth
2205 wxNode *node = item->GetChildren().First();
2206 while (node)
2207 {
2208 wxItemResource *child = (wxItemResource *)node->Data();
2209 int platform = (int)child->GetValue2();
2210 int noColours = (int)child->GetValue3();
2211 /*
2212 char *name = child->GetName();
2213 int bitmapType = (int)child->GetValue1();
2214 int xRes = child->GetWidth();
2215 int yRes = child->GetHeight();
2216 */
2217
2218 switch (platform)
2219 {
2220 case RESOURCE_PLATFORM_ANY:
2221 {
2222 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
2223 optResource = child;
2224 else
2225 {
2226 // Maximise the number of colours.
2227 // If noColours is zero (unspecified), then assume this
2228 // is the right one.
2229 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
2230 optResource = child;
2231 }
2232 break;
2233 }
2234 #ifdef __WXMSW__
2235 case RESOURCE_PLATFORM_WINDOWS:
2236 {
2237 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
2238 optResource = child;
2239 else
2240 {
2241 // Maximise the number of colours
2242 if ((noColours > 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
2243 optResource = child;
2244 }
2245 break;
2246 }
2247 #endif
2248 #ifdef __WXGTK__
2249 case RESOURCE_PLATFORM_X:
2250 {
2251 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
2252 optResource = child;
2253 else
2254 {
2255 // Maximise the number of colours
2256 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
2257 optResource = child;
2258 }
2259 break;
2260 }
2261 #endif
2262 #ifdef wx_max
2263 case RESOURCE_PLATFORM_MAC:
2264 {
2265 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
2266 optResource = child;
2267 else
2268 {
2269 // Maximise the number of colours
2270 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
2271 optResource = child;
2272 }
2273 break;
2274 }
2275 #endif
2276 default:
2277 break;
2278 }
2279 node = node->Next();
2280 }
2281 // If no matching resource, fail.
2282 if (!optResource)
2283 return wxNullIcon;
2284
2285 wxString name = optResource->GetName();
2286 int bitmapType = (int)optResource->GetValue1();
2287 switch (bitmapType)
2288 {
2289 case wxBITMAP_TYPE_XBM_DATA:
2290 {
2291 #ifdef __WXGTK__
2292 wxItemResource *item = table->FindResource(name);
2293 if (!item)
2294 {
2295 wxLogWarning(_("Failed to find XBM resource %s.\n"
2296 "Forgot to use wxResourceLoadIconData?"), (const char*) name);
2297 return wxNullIcon;
2298 }
2299 return wxIcon((const char **)item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3());
2300 #else
2301 wxLogWarning(_("No XBM facility available!"));
2302 #endif
2303 break;
2304 }
2305 case wxBITMAP_TYPE_XPM_DATA:
2306 {
2307 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2308 /*
2309 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2310 wxItemResource *item = table->FindResource(name);
2311 if (!item)
2312 {
2313 char buf[400];
2314 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2315 wxLogWarning(buf);
2316 return NULL;
2317 }
2318 return wxIcon((char **)item->GetValue1());
2319 #else
2320 wxLogWarning(_("No XPM facility available!"));
2321 #endif
2322 */
2323 wxLogWarning(_("No XPM icon facility available!"));
2324 break;
2325 }
2326 default:
2327 {
2328 #ifdef __WXGTK__
2329 wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource);
2330 #else
2331 return wxIcon(name, bitmapType);
2332 #endif
2333 break;
2334 }
2335 }
2336 return wxNullIcon;
2337 }
2338 else
2339 {
2340 wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource);
2341 return wxNullIcon;
2342 }
2343 }
2344
2345 wxMenu *wxResourceCreateMenu(wxItemResource *item)
2346 {
2347 wxMenu *menu = new wxMenu;
2348 wxNode *node = item->GetChildren().First();
2349 while (node)
2350 {
2351 wxItemResource *child = (wxItemResource *)node->Data();
2352 if ((child->GetType() != "") && (child->GetType() == "wxMenuSeparator"))
2353 menu->AppendSeparator();
2354 else if (child->GetChildren().Number() > 0)
2355 {
2356 wxMenu *subMenu = wxResourceCreateMenu(child);
2357 if (subMenu)
2358 menu->Append((int)child->GetValue1(), child->GetTitle(), subMenu, child->GetValue4());
2359 }
2360 else
2361 {
2362 menu->Append((int)child->GetValue1(), child->GetTitle(), child->GetValue4(), (child->GetValue2() != 0));
2363 }
2364 node = node->Next();
2365 }
2366 return menu;
2367 }
2368
2369 wxMenuBar *wxResourceCreateMenuBar(const wxString& resource, wxResourceTable *table, wxMenuBar *menuBar)
2370 {
2371 if (!table)
2372 table = wxDefaultResourceTable;
2373
2374 wxItemResource *menuResource = table->FindResource(resource);
2375 if (menuResource && (menuResource->GetType() != "") && (menuResource->GetType() == "wxMenu"))
2376 {
2377 if (!menuBar)
2378 menuBar = new wxMenuBar;
2379 wxNode *node = menuResource->GetChildren().First();
2380 while (node)
2381 {
2382 wxItemResource *child = (wxItemResource *)node->Data();
2383 wxMenu *menu = wxResourceCreateMenu(child);
2384 if (menu)
2385 menuBar->Append(menu, child->GetTitle());
2386 node = node->Next();
2387 }
2388 return menuBar;
2389 }
2390 return (wxMenuBar *) NULL;
2391 }
2392
2393 wxMenu *wxResourceCreateMenu(const wxString& resource, wxResourceTable *table)
2394 {
2395 if (!table)
2396 table = wxDefaultResourceTable;
2397
2398 wxItemResource *menuResource = table->FindResource(resource);
2399 if (menuResource && (menuResource->GetType() != "") && (menuResource->GetType() == "wxMenu"))
2400 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2401 return wxResourceCreateMenu(menuResource);
2402 return (wxMenu *) NULL;
2403 }
2404
2405 // Global equivalents (so don't have to refer to default table explicitly)
2406 bool wxResourceParseData(const wxString& resource, wxResourceTable *table)
2407 {
2408 if (!table)
2409 table = wxDefaultResourceTable;
2410
2411 return table->ParseResourceData(resource);
2412 }
2413
2414 bool wxResourceParseFile(const wxString& filename, wxResourceTable *table)
2415 {
2416 if (!table)
2417 table = wxDefaultResourceTable;
2418
2419 return table->ParseResourceFile(filename);
2420 }
2421
2422 // Register XBM/XPM data
2423 bool wxResourceRegisterBitmapData(const wxString& name, char bits[], int width, int height, wxResourceTable *table)
2424 {
2425 if (!table)
2426 table = wxDefaultResourceTable;
2427
2428 return table->RegisterResourceBitmapData(name, bits, width, height);
2429 }
2430
2431 bool wxResourceRegisterBitmapData(const wxString& name, char **data, wxResourceTable *table)
2432 {
2433 if (!table)
2434 table = wxDefaultResourceTable;
2435
2436 return table->RegisterResourceBitmapData(name, data);
2437 }
2438
2439 void wxResourceClear(wxResourceTable *table)
2440 {
2441 if (!table)
2442 table = wxDefaultResourceTable;
2443
2444 table->ClearTable();
2445 }
2446
2447 /*
2448 * Identifiers
2449 */
2450
2451 bool wxResourceAddIdentifier(const wxString& name, int value, wxResourceTable *table)
2452 {
2453 if (!table)
2454 table = wxDefaultResourceTable;
2455
2456 table->identifiers.Put(name, (wxObject *)value);
2457 return TRUE;
2458 }
2459
2460 int wxResourceGetIdentifier(const wxString& name, wxResourceTable *table)
2461 {
2462 if (!table)
2463 table = wxDefaultResourceTable;
2464
2465 return (int)table->identifiers.Get(name);
2466 }
2467
2468 /*
2469 * Parse #include file for #defines (only)
2470 */
2471
2472 bool wxResourceParseIncludeFile(const wxString& f, wxResourceTable *table)
2473 {
2474 if (!table)
2475 table = wxDefaultResourceTable;
2476
2477 FILE *fd = fopen(f, "r");
2478 if (!fd)
2479 {
2480 return FALSE;
2481 }
2482 while (wxGetResourceToken(fd))
2483 {
2484 if (strcmp(wxResourceBuffer, "#define") == 0)
2485 {
2486 wxGetResourceToken(fd);
2487 char *name = copystring(wxResourceBuffer);
2488 wxGetResourceToken(fd);
2489 char *value = copystring(wxResourceBuffer);
2490 if (isdigit(value[0]))
2491 {
2492 int val = (int)atol(value);
2493 wxResourceAddIdentifier(name, val, table);
2494 }
2495 delete[] name;
2496 delete[] value;
2497 }
2498 }
2499 fclose(fd);
2500 return TRUE;
2501 }
2502
2503 /*
2504 * Reading strings as if they were .wxr files
2505 */
2506
2507 static int getc_string(char *s)
2508 {
2509 int ch = s[wxResourceStringPtr];
2510 if (ch == 0)
2511 return EOF;
2512 else
2513 {
2514 wxResourceStringPtr ++;
2515 return ch;
2516 }
2517 }
2518
2519 static int ungetc_string()
2520 {
2521 wxResourceStringPtr --;
2522 return 0;
2523 }
2524
2525 bool wxEatWhiteSpaceString(char *s)
2526 {
2527 int ch = getc_string(s);
2528 if (ch == EOF)
2529 return TRUE;
2530
2531 if ((ch != ' ') && (ch != '/') && (ch != ' ') && (ch != 10) && (ch != 13) && (ch != 9))
2532 {
2533 ungetc_string();
2534 return TRUE;
2535 }
2536
2537 // Eat whitespace
2538 while (ch == ' ' || ch == 10 || ch == 13 || ch == 9)
2539 ch = getc_string(s);
2540 // Check for comment
2541 if (ch == '/')
2542 {
2543 ch = getc_string(s);
2544 if (ch == '*')
2545 {
2546 bool finished = FALSE;
2547 while (!finished)
2548 {
2549 ch = getc_string(s);
2550 if (ch == EOF)
2551 return FALSE;
2552 if (ch == '*')
2553 {
2554 int newCh = getc_string(s);
2555 if (newCh == '/')
2556 finished = TRUE;
2557 else
2558 {
2559 ungetc_string();
2560 }
2561 }
2562 }
2563 }
2564 else // False alarm
2565 return FALSE;
2566 }
2567 else if (ch != EOF)
2568 ungetc_string();
2569 return wxEatWhiteSpaceString(s);
2570 }
2571
2572 bool wxGetResourceTokenString(char *s)
2573 {
2574 if (!wxResourceBuffer)
2575 wxReallocateResourceBuffer();
2576 wxResourceBuffer[0] = 0;
2577 wxEatWhiteSpaceString(s);
2578
2579 int ch = getc_string(s);
2580 if (ch == '"')
2581 {
2582 // Get string
2583 wxResourceBufferCount = 0;
2584 ch = getc_string(s);
2585 while (ch != '"')
2586 {
2587 int actualCh = ch;
2588 if (ch == EOF)
2589 {
2590 wxResourceBuffer[wxResourceBufferCount] = 0;
2591 return FALSE;
2592 }
2593 // Escaped characters
2594 else if (ch == '\\')
2595 {
2596 int newCh = getc_string(s);
2597 if (newCh == '"')
2598 actualCh = '"';
2599 else if (newCh == 10)
2600 actualCh = 10;
2601 else
2602 {
2603 ungetc_string();
2604 }
2605 }
2606
2607 if (wxResourceBufferCount >= wxResourceBufferSize-1)
2608 wxReallocateResourceBuffer();
2609 wxResourceBuffer[wxResourceBufferCount] = (char)actualCh;
2610 wxResourceBufferCount ++;
2611 ch = getc_string(s);
2612 }
2613 wxResourceBuffer[wxResourceBufferCount] = 0;
2614 }
2615 else
2616 {
2617 wxResourceBufferCount = 0;
2618 // Any other token
2619 while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10)
2620 {
2621 if (wxResourceBufferCount >= wxResourceBufferSize-1)
2622 wxReallocateResourceBuffer();
2623 wxResourceBuffer[wxResourceBufferCount] = (char)ch;
2624 wxResourceBufferCount ++;
2625
2626 ch = getc_string(s);
2627 }
2628 wxResourceBuffer[wxResourceBufferCount] = 0;
2629 if (ch == EOF)
2630 return FALSE;
2631 }
2632 return TRUE;
2633 }
2634
2635 /*
2636 * Files are in form:
2637 static char *name = "....";
2638 with possible comments.
2639 */
2640
2641 bool wxResourceReadOneResourceString(char *s, wxExprDatabase& db, bool *eof, wxResourceTable *table)
2642 {
2643 if (!table)
2644 table = wxDefaultResourceTable;
2645
2646 // static or #define
2647 if (!wxGetResourceTokenString(s))
2648 {
2649 *eof = TRUE;
2650 return FALSE;
2651 }
2652
2653 if (strcmp(wxResourceBuffer, "#define") == 0)
2654 {
2655 wxGetResourceTokenString(s);
2656 char *name = copystring(wxResourceBuffer);
2657 wxGetResourceTokenString(s);
2658 char *value = copystring(wxResourceBuffer);
2659 if (isalpha(value[0]))
2660 {
2661 int val = (int)atol(value);
2662 wxResourceAddIdentifier(name, val, table);
2663 }
2664 else
2665 {
2666 wxLogWarning(_("#define %s must be an integer."), name);
2667 delete[] name;
2668 delete[] value;
2669 return FALSE;
2670 }
2671 delete[] name;
2672 delete[] value;
2673
2674 return TRUE;
2675 }
2676 /*
2677 else if (strcmp(wxResourceBuffer, "#include") == 0)
2678 {
2679 wxGetResourceTokenString(s);
2680 char *name = copystring(wxResourceBuffer);
2681 char *actualName = name;
2682 if (name[0] == '"')
2683 actualName = name + 1;
2684 int len = strlen(name);
2685 if ((len > 0) && (name[len-1] == '"'))
2686 name[len-1] = 0;
2687 if (!wxResourceParseIncludeFile(actualName, table))
2688 {
2689 char buf[400];
2690 sprintf(buf, _("Could not find resource include file %s."), actualName);
2691 wxLogWarning(buf);
2692 }
2693 delete[] name;
2694 return TRUE;
2695 }
2696 */
2697 else if (strcmp(wxResourceBuffer, "static") != 0)
2698 {
2699 char buf[300];
2700 strcpy(buf, _("Found "));
2701 strncat(buf, wxResourceBuffer, 30);
2702 strcat(buf, _(", expected static, #include or #define\nwhilst parsing resource."));
2703 wxLogWarning(buf);
2704 return FALSE;
2705 }
2706
2707 // char
2708 if (!wxGetResourceTokenString(s))
2709 {
2710 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2711 *eof = TRUE;
2712 return FALSE;
2713 }
2714
2715 if (strcmp(wxResourceBuffer, "char") != 0)
2716 {
2717 wxLogWarning(_("Expected 'char' whilst parsing resource."));
2718 return FALSE;
2719 }
2720
2721 // *name
2722 if (!wxGetResourceTokenString(s))
2723 {
2724 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2725 *eof = TRUE;
2726 return FALSE;
2727 }
2728
2729 if (wxResourceBuffer[0] != '*')
2730 {
2731 wxLogWarning(_("Expected '*' whilst parsing resource."));
2732 return FALSE;
2733 }
2734 char nameBuf[100];
2735 strncpy(nameBuf, wxResourceBuffer+1, 99);
2736
2737 // =
2738 if (!wxGetResourceTokenString(s))
2739 {
2740 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2741 *eof = TRUE;
2742 return FALSE;
2743 }
2744
2745 if (strcmp(wxResourceBuffer, "=") != 0)
2746 {
2747 wxLogWarning(_("Expected '=' whilst parsing resource."));
2748 return FALSE;
2749 }
2750
2751 // String
2752 if (!wxGetResourceTokenString(s))
2753 {
2754 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2755 *eof = TRUE;
2756 return FALSE;
2757 }
2758 else
2759 {
2760 if (!db.ReadPrologFromString(wxResourceBuffer))
2761 {
2762 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf);
2763 return FALSE;
2764 }
2765 }
2766 // Semicolon
2767 if (!wxGetResourceTokenString(s))
2768 {
2769 *eof = TRUE;
2770 }
2771 return TRUE;
2772 }
2773
2774 bool wxResourceParseString(char *s, wxResourceTable *table)
2775 {
2776 if (!table)
2777 table = wxDefaultResourceTable;
2778
2779 if (!s)
2780 return FALSE;
2781
2782 // Turn backslashes into spaces
2783 if (s)
2784 {
2785 int len = strlen(s);
2786 int i;
2787 for (i = 0; i < len; i++)
2788 if (s[i] == 92 && s[i+1] == 13)
2789 {
2790 s[i] = ' ';
2791 s[i+1] = ' ';
2792 }
2793 }
2794
2795 wxExprDatabase db;
2796 wxResourceStringPtr = 0;
2797
2798 bool eof = FALSE;
2799 while (wxResourceReadOneResourceString(s, db, &eof, table) && !eof)
2800 {
2801 // Loop
2802 }
2803 return wxResourceInterpretResources(*table, db);
2804 }
2805
2806 /*
2807 * resource loading facility
2808 */
2809
2810 bool wxWindow::LoadFromResource(wxWindow *parent, const wxString& resourceName, const wxResourceTable *table)
2811 {
2812 if (!table)
2813 table = wxDefaultResourceTable;
2814
2815 wxItemResource *resource = table->FindResource((const char *)resourceName);
2816 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
2817 if (!resource || (resource->GetType() == "") ||
2818 ! ((resource->GetType() == "wxDialog") || (resource->GetType() == "wxPanel")))
2819 return FALSE;
2820
2821 wxString title(resource->GetTitle());
2822 long theWindowStyle = resource->GetStyle();
2823 bool isModal = (resource->GetValue1() != 0);
2824 int x = resource->GetX();
2825 int y = resource->GetY();
2826 int width = resource->GetWidth();
2827 int height = resource->GetHeight();
2828 wxString name = resource->GetName();
2829
2830 if (IsKindOf(CLASSINFO(wxDialog)))
2831 {
2832 wxDialog *dialogBox = (wxDialog *)this;
2833 long modalStyle = isModal ? wxDIALOG_MODAL : 0;
2834 if (!dialogBox->Create(parent, -1, title, wxPoint(x, y), wxSize(width, height), theWindowStyle|modalStyle, name))
2835 return FALSE;
2836
2837 // Only reset the client size if we know we're not going to do it again below.
2838 if ((resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) == 0)
2839 dialogBox->SetClientSize(width, height);
2840 }
2841 else if (IsKindOf(CLASSINFO(wxPanel)))
2842 {
2843 wxPanel* panel = (wxPanel *)this;
2844 if (!panel->Create(parent, -1, wxPoint(x, y), wxSize(width, height), theWindowStyle, name))
2845 return FALSE;
2846 }
2847 else
2848 {
2849 if (!this->Create(parent, -1, wxPoint(x, y), wxSize(width, height), theWindowStyle, name))
2850 return FALSE;
2851 }
2852
2853 if ((resource->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS) != 0)
2854 {
2855 // No need to do this since it's done in wxPanel or wxDialog constructor.
2856 // SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
2857 }
2858 else
2859 {
2860 if (resource->GetFont().Ok())
2861 SetFont(resource->GetFont());
2862 if (resource->GetBackgroundColour().Ok())
2863 SetBackgroundColour(resource->GetBackgroundColour());
2864 }
2865
2866 // Should have some kind of font at this point
2867 if (!GetFont().Ok())
2868 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
2869 if (!GetBackgroundColour().Ok())
2870 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
2871
2872 // Only when we've created the window and set the font can we set the correct size,
2873 // if based on dialog units.
2874 if ((resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0)
2875 {
2876 wxSize sz = ConvertDialogToPixels(wxSize(width, height));
2877 SetClientSize(sz.x, sz.y);
2878
2879 wxPoint pt = ConvertDialogToPixels(wxPoint(x, y));
2880 Move(pt.x, pt.y);
2881 }
2882
2883 // Now create children
2884 wxNode *node = resource->GetChildren().First();
2885 while (node)
2886 {
2887 wxItemResource *childResource = (wxItemResource *)node->Data();
2888
2889 (void) CreateItem(childResource, resource, table);
2890
2891 node = node->Next();
2892 }
2893 return TRUE;
2894 }
2895
2896 wxControl *wxWindow::CreateItem(const wxItemResource *resource, const wxItemResource* parentResource, const wxResourceTable *table)
2897 {
2898 if (!table)
2899 table = wxDefaultResourceTable;
2900 return table->CreateItem((wxWindow *)this, resource, parentResource);
2901 }
2902
2903 #ifdef _MSC_VER
2904 #pragma warning(default:4706) // assignment within conditional expression
2905 #endif // VC++
2906
2907 #endif
2908 // BC++/Win16
2909
2910 #endif // wxUSE_WX_RESOURCES