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