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