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