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