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