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