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