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