removed USE_SHARED_LIBRARY(IES)
[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 long 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 #endif
2194 break;
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 #endif
2210 break;
2211 }
2212 default:
2213 {
2214 return wxBitmap(name, bitmapType);
2215 break;
2216 }
2217 }
2218 return wxNullBitmap;
2219 }
2220 else
2221 {
2222 wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar*) resource);
2223 return wxNullBitmap;
2224 }
2225 }
2226
2227 /*
2228 * Load an icon from a wxWindows resource, choosing an optimum
2229 * depth and appropriate type.
2230 */
2231
2232 wxIcon wxResourceCreateIcon(const wxString& resource, wxResourceTable *table)
2233 {
2234 if (!table)
2235 table = wxDefaultResourceTable;
2236
2237 wxItemResource *item = table->FindResource(resource);
2238 if (item)
2239 {
2240 if ((item->GetType() == wxT("")) || wxStrcmp(item->GetType(), wxT("wxIcon")) != 0)
2241 {
2242 wxLogWarning(_("%s not an icon resource specification."), (const wxChar*) resource);
2243 return wxNullIcon;
2244 }
2245 int thisDepth = wxDisplayDepth();
2246 long thisNoColours = (long)pow(2.0, (double)thisDepth);
2247
2248 wxItemResource *optResource = (wxItemResource *) NULL;
2249
2250 // Try to find optimum icon for this platform/colour depth
2251 wxNode *node = item->GetChildren().First();
2252 while (node)
2253 {
2254 wxItemResource *child = (wxItemResource *)node->Data();
2255 int platform = (int)child->GetValue2();
2256 int noColours = (int)child->GetValue3();
2257 /*
2258 char *name = child->GetName();
2259 int bitmapType = (int)child->GetValue1();
2260 int xRes = child->GetWidth();
2261 int yRes = child->GetHeight();
2262 */
2263
2264 switch (platform)
2265 {
2266 case RESOURCE_PLATFORM_ANY:
2267 {
2268 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
2269 optResource = child;
2270 else
2271 {
2272 // Maximise the number of colours.
2273 // If noColours is zero (unspecified), then assume this
2274 // is the right one.
2275 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
2276 optResource = child;
2277 }
2278 break;
2279 }
2280 #ifdef __WXMSW__
2281 case RESOURCE_PLATFORM_WINDOWS:
2282 {
2283 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
2284 optResource = child;
2285 else
2286 {
2287 // Maximise the number of colours
2288 if ((noColours > 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
2289 optResource = child;
2290 }
2291 break;
2292 }
2293 #endif
2294 #ifdef __WXGTK__
2295 case RESOURCE_PLATFORM_X:
2296 {
2297 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
2298 optResource = child;
2299 else
2300 {
2301 // Maximise the number of colours
2302 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
2303 optResource = child;
2304 }
2305 break;
2306 }
2307 #endif
2308 #ifdef wx_max
2309 case RESOURCE_PLATFORM_MAC:
2310 {
2311 if (!optResource && ((noColours == 0) || (noColours <= thisNoColours)))
2312 optResource = child;
2313 else
2314 {
2315 // Maximise the number of colours
2316 if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3())))
2317 optResource = child;
2318 }
2319 break;
2320 }
2321 #endif
2322 default:
2323 break;
2324 }
2325 node = node->Next();
2326 }
2327 // If no matching resource, fail.
2328 if (!optResource)
2329 return wxNullIcon;
2330
2331 wxString name = optResource->GetName();
2332 int bitmapType = (int)optResource->GetValue1();
2333 switch (bitmapType)
2334 {
2335 case wxBITMAP_TYPE_XBM_DATA:
2336 {
2337 #ifdef __WXGTK__
2338 wxItemResource *item = table->FindResource(name);
2339 if (!item)
2340 {
2341 wxLogWarning(_("Failed to find XBM resource %s.\n"
2342 "Forgot to use wxResourceLoadIconData?"), (const wxChar*) name);
2343 return wxNullIcon;
2344 }
2345 return wxIcon((const char **)item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3());
2346 #else
2347 wxLogWarning(_("No XBM facility available!"));
2348 #endif
2349 break;
2350 }
2351 case wxBITMAP_TYPE_XPM_DATA:
2352 {
2353 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2354 /*
2355 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2356 wxItemResource *item = table->FindResource(name);
2357 if (!item)
2358 {
2359 char buf[400];
2360 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2361 wxLogWarning(buf);
2362 return NULL;
2363 }
2364 return wxIcon((char **)item->GetValue1());
2365 #else
2366 wxLogWarning(_("No XPM facility available!"));
2367 #endif
2368 */
2369 wxLogWarning(_("No XPM icon facility available!"));
2370 break;
2371 }
2372 default:
2373 {
2374 #ifdef __WXGTK__
2375 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar*) resource);
2376 #else
2377 return wxIcon(name, bitmapType);
2378 #endif
2379 break;
2380 }
2381 }
2382 return wxNullIcon;
2383 }
2384 else
2385 {
2386 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar*) resource);
2387 return wxNullIcon;
2388 }
2389 }
2390
2391 wxMenu *wxResourceCreateMenu(wxItemResource *item)
2392 {
2393 wxMenu *menu = new wxMenu;
2394 wxNode *node = item->GetChildren().First();
2395 while (node)
2396 {
2397 wxItemResource *child = (wxItemResource *)node->Data();
2398 if ((child->GetType() != wxT("")) && (child->GetType() == wxT("wxMenuSeparator")))
2399 menu->AppendSeparator();
2400 else if (child->GetChildren().Number() > 0)
2401 {
2402 wxMenu *subMenu = wxResourceCreateMenu(child);
2403 if (subMenu)
2404 menu->Append((int)child->GetValue1(), child->GetTitle(), subMenu, child->GetValue4());
2405 }
2406 else
2407 {
2408 menu->Append((int)child->GetValue1(), child->GetTitle(), child->GetValue4(), (child->GetValue2() != 0));
2409 }
2410 node = node->Next();
2411 }
2412 return menu;
2413 }
2414
2415 wxMenuBar *wxResourceCreateMenuBar(const wxString& resource, wxResourceTable *table, wxMenuBar *menuBar)
2416 {
2417 if (!table)
2418 table = wxDefaultResourceTable;
2419
2420 wxItemResource *menuResource = table->FindResource(resource);
2421 if (menuResource && (menuResource->GetType() != wxT("")) && (menuResource->GetType() == wxT("wxMenu")))
2422 {
2423 if (!menuBar)
2424 menuBar = new wxMenuBar;
2425 wxNode *node = menuResource->GetChildren().First();
2426 while (node)
2427 {
2428 wxItemResource *child = (wxItemResource *)node->Data();
2429 wxMenu *menu = wxResourceCreateMenu(child);
2430 if (menu)
2431 menuBar->Append(menu, child->GetTitle());
2432 node = node->Next();
2433 }
2434 return menuBar;
2435 }
2436 return (wxMenuBar *) NULL;
2437 }
2438
2439 wxMenu *wxResourceCreateMenu(const wxString& resource, wxResourceTable *table)
2440 {
2441 if (!table)
2442 table = wxDefaultResourceTable;
2443
2444 wxItemResource *menuResource = table->FindResource(resource);
2445 if (menuResource && (menuResource->GetType() != wxT("")) && (menuResource->GetType() == wxT("wxMenu")))
2446 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2447 return wxResourceCreateMenu(menuResource);
2448 return (wxMenu *) NULL;
2449 }
2450
2451 // Global equivalents (so don't have to refer to default table explicitly)
2452 bool wxResourceParseData(const wxString& resource, wxResourceTable *table)
2453 {
2454 if (!table)
2455 table = wxDefaultResourceTable;
2456
2457 return table->ParseResourceData(resource);
2458 }
2459
2460 bool wxResourceParseFile(const wxString& filename, wxResourceTable *table)
2461 {
2462 if (!table)
2463 table = wxDefaultResourceTable;
2464
2465 return table->ParseResourceFile(filename);
2466 }
2467
2468 // Register XBM/XPM data
2469 bool wxResourceRegisterBitmapData(const wxString& name, char bits[], int width, int height, wxResourceTable *table)
2470 {
2471 if (!table)
2472 table = wxDefaultResourceTable;
2473
2474 return table->RegisterResourceBitmapData(name, bits, width, height);
2475 }
2476
2477 bool wxResourceRegisterBitmapData(const wxString& name, char **data, wxResourceTable *table)
2478 {
2479 if (!table)
2480 table = wxDefaultResourceTable;
2481
2482 return table->RegisterResourceBitmapData(name, data);
2483 }
2484
2485 void wxResourceClear(wxResourceTable *table)
2486 {
2487 if (!table)
2488 table = wxDefaultResourceTable;
2489
2490 table->ClearTable();
2491 }
2492
2493 /*
2494 * Identifiers
2495 */
2496
2497 bool wxResourceAddIdentifier(const wxString& name, int value, wxResourceTable *table)
2498 {
2499 if (!table)
2500 table = wxDefaultResourceTable;
2501
2502 table->identifiers.Put(name, (wxObject *)(long)value);
2503 return TRUE;
2504 }
2505
2506 int wxResourceGetIdentifier(const wxString& name, wxResourceTable *table)
2507 {
2508 if (!table)
2509 table = wxDefaultResourceTable;
2510
2511 return (int)(long)table->identifiers.Get(name);
2512 }
2513
2514 /*
2515 * Parse #include file for #defines (only)
2516 */
2517
2518 bool wxResourceParseIncludeFile(const wxString& f, wxResourceTable *table)
2519 {
2520 if (!table)
2521 table = wxDefaultResourceTable;
2522
2523 FILE *fd = fopen(f.fn_str(), "r");
2524 if (!fd)
2525 {
2526 return FALSE;
2527 }
2528 while (wxGetResourceToken(fd))
2529 {
2530 if (strcmp(wxResourceBuffer, "#define") == 0)
2531 {
2532 wxGetResourceToken(fd);
2533 wxChar *name = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer));
2534 wxGetResourceToken(fd);
2535 wxChar *value = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer));
2536 if (wxIsdigit(value[0]))
2537 {
2538 int val = (int)wxAtol(value);
2539 wxResourceAddIdentifier(name, val, table);
2540 }
2541 delete[] name;
2542 delete[] value;
2543 }
2544 }
2545 fclose(fd);
2546 return TRUE;
2547 }
2548
2549 /*
2550 * Reading strings as if they were .wxr files
2551 */
2552
2553 static int getc_string(char *s)
2554 {
2555 int ch = s[wxResourceStringPtr];
2556 if (ch == 0)
2557 return EOF;
2558 else
2559 {
2560 wxResourceStringPtr ++;
2561 return ch;
2562 }
2563 }
2564
2565 static int ungetc_string()
2566 {
2567 wxResourceStringPtr --;
2568 return 0;
2569 }
2570
2571 bool wxEatWhiteSpaceString(char *s)
2572 {
2573 int ch = 0;
2574
2575 while ((ch = getc_string(s)) != EOF)
2576 {
2577 switch (ch)
2578 {
2579 case ' ':
2580 case 0x0a:
2581 case 0x0d:
2582 case 0x09:
2583 break;
2584 case '/':
2585 {
2586 int prev_ch = ch;
2587 ch = getc_string(s);
2588 if (ch == EOF)
2589 {
2590 ungetc_string();
2591 return TRUE;
2592 }
2593
2594 if (ch == '*')
2595 {
2596 // Eat C comment
2597 prev_ch = 0;
2598 while ((ch = getc_string(s)) != EOF)
2599 {
2600 if (ch == '/' && prev_ch == '*')
2601 break;
2602 prev_ch = ch;
2603 }
2604 }
2605 else
2606 {
2607 ungetc_string();
2608 ungetc_string();
2609 return TRUE;
2610 }
2611 }
2612 break;
2613 default:
2614 ungetc_string();
2615 return TRUE;
2616
2617 }
2618 }
2619 return FALSE;
2620 }
2621
2622 bool wxGetResourceTokenString(char *s)
2623 {
2624 if (!wxResourceBuffer)
2625 wxReallocateResourceBuffer();
2626 wxResourceBuffer[0] = 0;
2627 wxEatWhiteSpaceString(s);
2628
2629 int ch = getc_string(s);
2630 if (ch == '"')
2631 {
2632 // Get string
2633 wxResourceBufferCount = 0;
2634 ch = getc_string(s);
2635 while (ch != '"')
2636 {
2637 int actualCh = ch;
2638 if (ch == EOF)
2639 {
2640 wxResourceBuffer[wxResourceBufferCount] = 0;
2641 return FALSE;
2642 }
2643 // Escaped characters
2644 else if (ch == '\\')
2645 {
2646 int newCh = getc_string(s);
2647 if (newCh == '"')
2648 actualCh = '"';
2649 else if (newCh == 10)
2650 actualCh = 10;
2651 else
2652 {
2653 ungetc_string();
2654 }
2655 }
2656
2657 if (wxResourceBufferCount >= wxResourceBufferSize-1)
2658 wxReallocateResourceBuffer();
2659 wxResourceBuffer[wxResourceBufferCount] = (char)actualCh;
2660 wxResourceBufferCount ++;
2661 ch = getc_string(s);
2662 }
2663 wxResourceBuffer[wxResourceBufferCount] = 0;
2664 }
2665 else
2666 {
2667 wxResourceBufferCount = 0;
2668 // Any other token
2669 while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10)
2670 {
2671 if (wxResourceBufferCount >= wxResourceBufferSize-1)
2672 wxReallocateResourceBuffer();
2673 wxResourceBuffer[wxResourceBufferCount] = (char)ch;
2674 wxResourceBufferCount ++;
2675
2676 ch = getc_string(s);
2677 }
2678 wxResourceBuffer[wxResourceBufferCount] = 0;
2679 if (ch == EOF)
2680 return FALSE;
2681 }
2682 return TRUE;
2683 }
2684
2685 /*
2686 * Files are in form:
2687 static char *name = "....";
2688 with possible comments.
2689 */
2690
2691 bool wxResourceReadOneResourceString(char *s, wxExprDatabase& db, bool *eof, wxResourceTable *table)
2692 {
2693 if (!table)
2694 table = wxDefaultResourceTable;
2695
2696 // static or #define
2697 if (!wxGetResourceTokenString(s))
2698 {
2699 *eof = TRUE;
2700 return FALSE;
2701 }
2702
2703 if (strcmp(wxResourceBuffer, "#define") == 0)
2704 {
2705 wxGetResourceTokenString(s);
2706 wxChar *name = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer));
2707 wxGetResourceTokenString(s);
2708 wxChar *value = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer));
2709 if (wxIsdigit(value[0]))
2710 {
2711 int val = (int)wxAtol(value);
2712 wxResourceAddIdentifier(name, val, table);
2713 }
2714 else
2715 {
2716 wxLogWarning(_("#define %s must be an integer."), name);
2717 delete[] name;
2718 delete[] value;
2719 return FALSE;
2720 }
2721 delete[] name;
2722 delete[] value;
2723
2724 return TRUE;
2725 }
2726 /*
2727 else if (strcmp(wxResourceBuffer, "#include") == 0)
2728 {
2729 wxGetResourceTokenString(s);
2730 char *name = copystring(wxResourceBuffer);
2731 char *actualName = name;
2732 if (name[0] == '"')
2733 actualName = name + 1;
2734 int len = strlen(name);
2735 if ((len > 0) && (name[len-1] == '"'))
2736 name[len-1] = 0;
2737 if (!wxResourceParseIncludeFile(actualName, table))
2738 {
2739 char buf[400];
2740 sprintf(buf, _("Could not find resource include file %s."), actualName);
2741 wxLogWarning(buf);
2742 }
2743 delete[] name;
2744 return TRUE;
2745 }
2746 */
2747 else if (strcmp(wxResourceBuffer, "static") != 0)
2748 {
2749 wxChar buf[300];
2750 wxStrcpy(buf, _("Found "));
2751 wxStrncat(buf, wxConvCurrent->cMB2WX(wxResourceBuffer), 30);
2752 wxStrcat(buf, _(", expected static, #include or #define\nwhilst parsing resource."));
2753 wxLogWarning(buf);
2754 return FALSE;
2755 }
2756
2757 // char
2758 if (!wxGetResourceTokenString(s))
2759 {
2760 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2761 *eof = TRUE;
2762 return FALSE;
2763 }
2764
2765 if (strcmp(wxResourceBuffer, "char") != 0)
2766 {
2767 wxLogWarning(_("Expected 'char' whilst parsing resource."));
2768 return FALSE;
2769 }
2770
2771 // *name
2772 if (!wxGetResourceTokenString(s))
2773 {
2774 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2775 *eof = TRUE;
2776 return FALSE;
2777 }
2778
2779 if (wxResourceBuffer[0] != '*')
2780 {
2781 wxLogWarning(_("Expected '*' whilst parsing resource."));
2782 return FALSE;
2783 }
2784 wxChar nameBuf[100];
2785 wxMB2WX(nameBuf, wxResourceBuffer+1, 99);
2786 nameBuf[99] = 0;
2787
2788 // =
2789 if (!wxGetResourceTokenString(s))
2790 {
2791 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2792 *eof = TRUE;
2793 return FALSE;
2794 }
2795
2796 if (strcmp(wxResourceBuffer, "=") != 0)
2797 {
2798 wxLogWarning(_("Expected '=' whilst parsing resource."));
2799 return FALSE;
2800 }
2801
2802 // String
2803 if (!wxGetResourceTokenString(s))
2804 {
2805 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2806 *eof = TRUE;
2807 return FALSE;
2808 }
2809 else
2810 {
2811 if (!db.ReadPrologFromString(wxResourceBuffer))
2812 {
2813 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf);
2814 return FALSE;
2815 }
2816 }
2817 // Semicolon
2818 if (!wxGetResourceTokenString(s))
2819 {
2820 *eof = TRUE;
2821 }
2822 return TRUE;
2823 }
2824
2825 bool wxResourceParseString(char *s, wxResourceTable *table)
2826 {
2827 if (!table)
2828 table = wxDefaultResourceTable;
2829
2830 if (!s)
2831 return FALSE;
2832
2833 // Turn backslashes into spaces
2834 if (s)
2835 {
2836 int len = strlen(s);
2837 int i;
2838 for (i = 0; i < len; i++)
2839 if (s[i] == 92 && s[i+1] == 13)
2840 {
2841 s[i] = ' ';
2842 s[i+1] = ' ';
2843 }
2844 }
2845
2846 wxExprDatabase db;
2847 wxResourceStringPtr = 0;
2848
2849 bool eof = FALSE;
2850 while (wxResourceReadOneResourceString(s, db, &eof, table) && !eof)
2851 {
2852 // Loop
2853 }
2854 return wxResourceInterpretResources(*table, db);
2855 }
2856
2857 /*
2858 * resource loading facility
2859 */
2860
2861 bool wxWindowBase::LoadFromResource(wxWindow *parent, const wxString& resourceName, const wxResourceTable *table)
2862 {
2863 if (!table)
2864 table = wxDefaultResourceTable;
2865
2866 wxItemResource *resource = table->FindResource((const wxChar *)resourceName);
2867 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
2868 if (!resource || (resource->GetType() == wxT("")) ||
2869 ! ((resource->GetType() == wxT("wxDialog")) || (resource->GetType() == wxT("wxPanel"))))
2870 return FALSE;
2871
2872 wxString title(resource->GetTitle());
2873 long theWindowStyle = resource->GetStyle();
2874 bool isModal = (resource->GetValue1() != 0);
2875 int x = resource->GetX();
2876 int y = resource->GetY();
2877 int width = resource->GetWidth();
2878 int height = resource->GetHeight();
2879 wxString name = resource->GetName();
2880
2881 if (IsKindOf(CLASSINFO(wxDialog)))
2882 {
2883 wxDialog *dialogBox = (wxDialog *)this;
2884 long modalStyle = isModal ? wxDIALOG_MODAL : 0;
2885 if (!dialogBox->Create(parent, -1, title, wxPoint(x, y), wxSize(width, height), theWindowStyle|modalStyle, name))
2886 return FALSE;
2887
2888 // Only reset the client size if we know we're not going to do it again below.
2889 if ((resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) == 0)
2890 dialogBox->SetClientSize(width, height);
2891 }
2892 else if (IsKindOf(CLASSINFO(wxPanel)))
2893 {
2894 wxPanel* panel = (wxPanel *)this;
2895 if (!panel->Create(parent, -1, wxPoint(x, y), wxSize(width, height), theWindowStyle | wxTAB_TRAVERSAL, name))
2896 return FALSE;
2897 }
2898 else
2899 {
2900 if (!((wxWindow *)this)->Create(parent, -1, wxPoint(x, y), wxSize(width, height), theWindowStyle, name))
2901 return FALSE;
2902 }
2903
2904 if ((resource->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS) != 0)
2905 {
2906 // No need to do this since it's done in wxPanel or wxDialog constructor.
2907 // SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
2908 }
2909 else
2910 {
2911 if (resource->GetFont().Ok())
2912 SetFont(resource->GetFont());
2913 if (resource->GetBackgroundColour().Ok())
2914 SetBackgroundColour(resource->GetBackgroundColour());
2915 }
2916
2917 // Should have some kind of font at this point
2918 if (!GetFont().Ok())
2919 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
2920 if (!GetBackgroundColour().Ok())
2921 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
2922
2923 // Only when we've created the window and set the font can we set the correct size,
2924 // if based on dialog units.
2925 if ((resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0)
2926 {
2927 wxSize sz = ConvertDialogToPixels(wxSize(width, height));
2928 SetClientSize(sz.x, sz.y);
2929
2930 wxPoint pt = ConvertDialogToPixels(wxPoint(x, y));
2931 Move(pt.x, pt.y);
2932 }
2933
2934 // Now create children
2935 wxNode *node = resource->GetChildren().First();
2936 while (node)
2937 {
2938 wxItemResource *childResource = (wxItemResource *)node->Data();
2939
2940 (void) CreateItem(childResource, resource, table);
2941
2942 node = node->Next();
2943 }
2944 return TRUE;
2945 }
2946
2947 wxControl *wxWindowBase::CreateItem(const wxItemResource *resource, const wxItemResource* parentResource, const wxResourceTable *table)
2948 {
2949 if (!table)
2950 table = wxDefaultResourceTable;
2951 return table->CreateItem((wxWindow *)this, resource, parentResource);
2952 }
2953
2954 #ifdef __VISUALC__
2955 #pragma warning(default:4706) // assignment within conditional expression
2956 #endif // VC++
2957
2958 #endif
2959 // BC++/Win16
2960
2961 #endif // wxUSE_WX_RESOURCES