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