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