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