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