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