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