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