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