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