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