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