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