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