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