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