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