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