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