1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Resource system
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "resource.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #if wxUSE_WX_RESOURCES
26 #pragma warning(disable:4706) // assignment within conditional expression
34 #include "wx/gdicmn.h"
38 #include "wx/stattext.h"
39 #include "wx/button.h"
40 #include "wx/bmpbuttn.h"
41 #include "wx/radiobox.h"
42 #include "wx/listbox.h"
43 #include "wx/choice.h"
44 #include "wx/checkbox.h"
45 #include "wx/settings.h"
46 #include "wx/slider.h"
48 #include "wx/statbox.h"
49 #include "wx/statbmp.h"
51 #include "wx/textctrl.h"
52 #include "wx/msgdlg.h"
56 #include "wx/treebase.h"
57 #include "wx/listctrl.h"
60 #include "wx/radiobut.h"
64 #include "wx/scrolbar.h"
68 #include "wx/combobox.h"
71 #include "wx/validate.h"
80 #include "wx/resource.h"
81 #include "wx/string.h"
82 #include "wx/wxexpr.h"
84 #include "wx/settings.h"
85 #include "wx/stream.h"
87 // Forward (private) declarations
88 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
);
89 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
= FALSE
);
90 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
);
91 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
);
92 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
);
93 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, wxExpr
*expr
);
94 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, wxExpr
*expr
);
95 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
);
96 // Interpret list expression
97 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
);
99 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
100 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
) ;
101 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
103 wxResourceTable
*wxDefaultResourceTable
= (wxResourceTable
*) NULL
;
105 char *wxResourceBuffer
= (char *) NULL
;
106 long wxResourceBufferSize
= 0;
107 long wxResourceBufferCount
= 0;
108 int wxResourceStringPtr
= 0;
110 void wxInitializeResourceSystem()
112 wxDefaultResourceTable
= new wxResourceTable
;
115 void wxCleanUpResourceSystem()
117 delete wxDefaultResourceTable
;
118 if (wxResourceBuffer
)
119 delete[] wxResourceBuffer
;
122 void wxLogWarning(char *msg
)
124 wxMessageBox(msg
, _("Warning"), wxOK
);
127 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
128 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
130 wxItemResource::wxItemResource()
136 m_x
= m_y
= m_width
= m_height
= 0;
137 m_value1
= m_value2
= m_value3
= m_value5
= 0;
143 wxItemResource::~wxItemResource()
145 wxNode
*node
= m_children
.First();
148 wxItemResource
*item
= (wxItemResource
*)node
->Data();
151 node
= m_children
.First();
159 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
163 wxResourceTable::~wxResourceTable()
168 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
170 wxItemResource
*item
= (wxItemResource
*)Get(WXSTRINGCAST name
);
174 void wxResourceTable::AddResource(wxItemResource
*item
)
176 wxString name
= item
->GetName();
178 name
= item
->GetTitle();
180 name
= wxT("no name");
182 // Delete existing resource, if any.
188 bool wxResourceTable::DeleteResource(const wxString
& name
)
190 wxItemResource
*item
= (wxItemResource
*)Delete(WXSTRINGCAST name
);
193 // See if any resource has this as its child; if so, delete from
194 // parent's child list.
196 wxNode
*node
= (wxNode
*) NULL
;
200 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
201 if (parent
->GetChildren().Member(item
))
203 parent
->GetChildren().DeleteObject(item
);
216 bool wxResourceTable::ParseResourceFile( wxInputStream
*is
)
219 int len
= is
->GetSize() ;
222 while ( is
->TellI() + 10 < len
) // it's a hack because the streams dont support EOF
224 wxResourceReadOneResource(is
, db
, &eof
, this) ;
226 return wxResourceInterpretResources(*this, db
);
229 bool wxResourceTable::ParseResourceFile(const wxString
& filename
)
233 FILE *fd
= wxFopen(filename
, _T("r"));
237 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
242 return wxResourceInterpretResources(*this, db
);
245 bool wxResourceTable::ParseResourceData(const wxString
& data
)
248 if (!db
.ReadFromString(data
))
250 wxLogWarning(_("Ill-formed resource file syntax."));
254 return wxResourceInterpretResources(*this, db
);
257 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char bits
[], int width
, int height
)
259 // Register pre-loaded bitmap data
260 wxItemResource
*item
= new wxItemResource
;
261 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
262 item
->SetType(wxT("wxXBMData"));
264 item
->SetValue1((long)bits
);
265 item
->SetValue2((long)width
);
266 item
->SetValue3((long)height
);
271 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char **data
)
273 // Register pre-loaded bitmap data
274 wxItemResource
*item
= new wxItemResource
;
275 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
276 item
->SetType(wxT("wxXPMData"));
278 item
->SetValue1((long)data
);
283 bool wxResourceTable::SaveResource(const wxString
& WXUNUSED(filename
))
288 void wxResourceTable::ClearTable()
291 wxNode
*node
= Next();
294 wxNode
*next
= Next();
295 wxItemResource
*item
= (wxItemResource
*)node
->Data();
302 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, const wxItemResource
* childResource
, const wxItemResource
* parentResource
) const
304 int id
= childResource
->GetId();
308 bool dlgUnits
= ((parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0);
310 wxControl
*control
= (wxControl
*) NULL
;
311 wxString
itemType(childResource
->GetType());
317 pos
= parent
->ConvertDialogToPixels(wxPoint(childResource
->GetX(), childResource
->GetY()));
318 size
= parent
->ConvertDialogToPixels(wxSize(childResource
->GetWidth(), childResource
->GetHeight()));
322 pos
= wxPoint(childResource
->GetX(), childResource
->GetY());
323 size
= wxSize(childResource
->GetWidth(), childResource
->GetHeight());
326 if (itemType
== wxString(wxT("wxButton")) || itemType
== wxString(wxT("wxBitmapButton")))
328 if (childResource
->GetValue4() != wxT(""))
331 wxBitmap bitmap
= childResource
->GetBitmap();
334 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
335 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
338 #if defined(__WXPM__)
340 // OS/2 uses integer id's to access resources, not file name strings
342 bitmap
.LoadFile(wxCROSS_BITMAP
, wxBITMAP_TYPE_BMP_RESOURCE
);
344 bitmap
.LoadFile("cross_bmp", wxBITMAP_TYPE_BMP_RESOURCE
);
346 control
= new wxBitmapButton(parent
, id
, bitmap
, pos
, size
,
347 childResource
->GetStyle() | wxBU_AUTODRAW
, wxDefaultValidator
, childResource
->GetName());
350 // Normal, text button
351 control
= new wxButton(parent
, id
, childResource
->GetTitle(), pos
, size
,
352 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
354 else if (itemType
== wxString(wxT("wxMessage")) || itemType
== wxString(wxT("wxStaticText")) ||
355 itemType
== wxString(wxT("wxStaticBitmap")))
357 if (childResource
->GetValue4() != wxT("") || itemType
== wxString(wxT("wxStaticBitmap")) )
360 wxBitmap bitmap
= childResource
->GetBitmap();
363 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
364 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
366 #if wxUSE_BITMAP_MESSAGE
368 // Use a default bitmap
370 bitmap
.LoadFile("cross_bmp", wxBITMAP_TYPE_BMP_RESOURCE
);
374 control
= new wxStaticBitmap(parent
, id
, bitmap
, pos
, size
,
375 childResource
->GetStyle(), childResource
->GetName());
380 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(), pos
, size
,
381 childResource
->GetStyle(), childResource
->GetName());
384 else if (itemType
== wxString(wxT("wxText")) || itemType
== wxString(wxT("wxTextCtrl")) || itemType
== wxString(wxT("wxMultiText")))
386 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), pos
, size
,
387 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
389 else if (itemType
== wxString(wxT("wxCheckBox")))
391 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
392 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
394 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
397 else if (itemType
== wxString(wxT("wxGauge")))
399 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(), pos
, size
,
400 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
402 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
406 else if (itemType
== wxString(wxT("wxRadioButton")))
408 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
410 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
414 else if (itemType
== wxString(wxT("wxScrollBar")))
416 control
= new wxScrollBar(parent
, id
, pos
, size
,
417 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
419 ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1());
420 ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2());
421 ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3());
422 ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5());
424 ((wxScrollBar
*)control
)->SetScrollbar((int)childResource
->GetValue1(),(int)childResource
->GetValue2(),
425 (int)childResource
->GetValue3(),(int)(long)childResource
->GetValue5(),FALSE
);
429 else if (itemType
== wxString(wxT("wxSlider")))
431 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
432 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), pos
, size
,
433 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
435 else if (itemType
== wxString(wxT("wxGroupBox")) || itemType
== wxString(wxT("wxStaticBox")))
437 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
438 childResource
->GetStyle(), childResource
->GetName());
440 else if (itemType
== wxString(wxT("wxListBox")))
442 wxStringList
& stringList
= childResource
->GetStringValues();
443 wxString
*strings
= (wxString
*) NULL
;
445 if (stringList
.Number() > 0)
447 noStrings
= stringList
.Number();
448 strings
= new wxString
[noStrings
];
449 wxNode
*node
= stringList
.First();
453 strings
[i
] = (wxChar
*)node
->Data();
458 control
= new wxListBox(parent
, id
, pos
, size
,
459 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
464 else if (itemType
== wxString(wxT("wxChoice")))
466 wxStringList
& stringList
= childResource
->GetStringValues();
467 wxString
*strings
= (wxString
*) NULL
;
469 if (stringList
.Number() > 0)
471 noStrings
= stringList
.Number();
472 strings
= new wxString
[noStrings
];
473 wxNode
*node
= stringList
.First();
477 strings
[i
] = (wxChar
*)node
->Data();
482 control
= new wxChoice(parent
, id
, pos
, size
,
483 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
489 else if (itemType
== wxString(wxT("wxComboBox")))
491 wxStringList
& stringList
= childResource
->GetStringValues();
492 wxString
*strings
= (wxString
*) NULL
;
494 if (stringList
.Number() > 0)
496 noStrings
= stringList
.Number();
497 strings
= new wxString
[noStrings
];
498 wxNode
*node
= stringList
.First();
502 strings
[i
] = (wxChar
*)node
->Data();
507 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(), pos
, size
,
508 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
514 else if (itemType
== wxString(wxT("wxRadioBox")))
516 wxStringList
& stringList
= childResource
->GetStringValues();
517 wxString
*strings
= (wxString
*) NULL
;
519 if (stringList
.Number() > 0)
521 noStrings
= stringList
.Number();
522 strings
= new wxString
[noStrings
];
523 wxNode
*node
= stringList
.First();
527 strings
[i
] = (wxChar
*)node
->Data();
532 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), pos
, size
,
533 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
534 childResource
->GetName());
540 if ((parentResource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
542 // Don't set font; will be inherited from parent.
546 if (control
&& childResource
->GetFont().Ok())
548 control
->SetFont(childResource
->GetFont());
551 // Force the layout algorithm since the size changes the layout
552 if (control
->IsKindOf(CLASSINFO(wxRadioBox
)))
554 control
->SetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
|wxSIZE_AUTO_HEIGHT
);
563 * Interpret database as a series of resources
566 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
)
568 wxNode
*node
= db
.First();
571 wxExpr
*clause
= (wxExpr
*)node
->Data();
572 wxString
functor(clause
->Functor());
574 wxItemResource
*item
= (wxItemResource
*) NULL
;
575 if (functor
== wxT("dialog"))
576 item
= wxResourceInterpretDialog(table
, clause
);
577 else if (functor
== wxT("panel"))
578 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
579 else if (functor
== wxT("menubar"))
580 item
= wxResourceInterpretMenuBar(table
, clause
);
581 else if (functor
== wxT("menu"))
582 item
= wxResourceInterpretMenu(table
, clause
);
583 else if (functor
== wxT("string"))
584 item
= wxResourceInterpretString(table
, clause
);
585 else if (functor
== wxT("bitmap"))
586 item
= wxResourceInterpretBitmap(table
, clause
);
587 else if (functor
== wxT("icon"))
588 item
= wxResourceInterpretIcon(table
, clause
);
592 // Remove any existing resource of same name
593 if (item
->GetName() != wxT(""))
594 table
.DeleteResource(item
->GetName());
595 table
.AddResource(item
);
602 static const wxChar
*g_ValidControlClasses
[] =
605 wxT("wxBitmapButton"),
608 wxT("wxStaticBitmap"),
614 wxT("wxRadioButton"),
616 wxT("wxBitmapCheckBox"),
626 static bool wxIsValidControlClass(const wxString
& c
)
628 for ( size_t i
= 0; i
< WXSIZEOF(g_ValidControlClasses
); i
++ )
630 if ( c
== g_ValidControlClasses
[i
] )
636 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
638 wxItemResource
*dialogItem
= new wxItemResource
;
640 dialogItem
->SetType(wxT("wxPanel"));
642 dialogItem
->SetType(wxT("wxDialog"));
643 wxString style
= wxT("");
644 wxString title
= wxT("");
645 wxString name
= wxT("");
646 wxString backColourHex
= wxT("");
647 wxString labelColourHex
= wxT("");
648 wxString buttonColourHex
= wxT("");
650 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
654 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
656 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
657 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
658 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
659 expr
->GetAttributeValue(wxT("style"), style
);
660 expr
->GetAttributeValue(wxT("name"), name
);
661 expr
->GetAttributeValue(wxT("title"), title
);
662 expr
->GetAttributeValue(wxT("x"), x
);
663 expr
->GetAttributeValue(wxT("y"), y
);
664 expr
->GetAttributeValue(wxT("width"), width
);
665 expr
->GetAttributeValue(wxT("height"), height
);
666 expr
->GetAttributeValue(wxT("modal"), isModal
);
667 expr
->GetAttributeValue(wxT("label_font"), &labelFontExpr
);
668 expr
->GetAttributeValue(wxT("button_font"), &buttonFontExpr
);
669 expr
->GetAttributeValue(wxT("font"), &fontExpr
);
670 expr
->GetAttributeValue(wxT("background_colour"), backColourHex
);
671 expr
->GetAttributeValue(wxT("label_colour"), labelColourHex
);
672 expr
->GetAttributeValue(wxT("button_colour"), buttonColourHex
);
674 int useDialogUnits
= 0;
675 expr
->GetAttributeValue(wxT("use_dialog_units"), useDialogUnits
);
676 if (useDialogUnits
!= 0)
677 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
680 expr
->GetAttributeValue(wxT("use_system_defaults"), useDefaults
);
681 if (useDefaults
!= 0)
682 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
685 expr
->GetAttributeValue(wxT("id"), id
);
686 dialogItem
->SetId(id
);
688 if (style
!= wxT(""))
690 windowStyle
= wxParseWindowStyle(style
);
692 dialogItem
->SetStyle(windowStyle
);
693 dialogItem
->SetValue1(isModal
);
694 if (windowStyle
& wxDIALOG_MODAL
) // Uses style in wxWin 2
695 dialogItem
->SetValue1(TRUE
);
697 dialogItem
->SetName(name
);
698 dialogItem
->SetTitle(title
);
699 dialogItem
->SetSize(x
, y
, width
, height
);
701 // Check for wxWin 1.68-style specifications
702 if (style
.Find(wxT("VERTICAL_LABEL")) != -1)
703 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
704 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != -1)
705 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
707 if (backColourHex
!= wxT(""))
712 r
= wxHexToDec(backColourHex
.Mid(0, 2));
713 g
= wxHexToDec(backColourHex
.Mid(2, 2));
714 b
= wxHexToDec(backColourHex
.Mid(4, 2));
715 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
717 if (labelColourHex
!= wxT(""))
722 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
723 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
724 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
725 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
727 if (buttonColourHex
!= wxT(""))
732 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
733 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
734 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
735 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
739 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
740 else if (buttonFontExpr
)
741 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
742 else if (labelFontExpr
)
743 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
745 // Now parse all controls
746 wxExpr
*controlExpr
= expr
->GetFirst();
749 if (controlExpr
->Number() == 3)
751 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
752 if (controlKeyword
!= wxT("") && controlKeyword
== wxT("control"))
754 // The value part: always a list.
755 wxExpr
*listExpr
= controlExpr
->Nth(2);
756 if (listExpr
->Type() == PrologList
)
758 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
761 dialogItem
->GetChildren().Append(controlItem
);
766 controlExpr
= controlExpr
->GetNext();
771 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
773 wxItemResource
*controlItem
= new wxItemResource
;
775 // First, find the standard features of a control definition:
776 // [optional integer/string id], control name, title, style, name, x, y, width, height
778 wxString controlType
;
783 long windowStyle
= 0;
784 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
787 wxExpr
*expr1
= expr
->Nth(0);
789 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
791 if ( wxIsValidControlClass(expr1
->StringValue()) )
794 controlType
= expr1
->StringValue();
798 wxString
str(expr1
->StringValue());
799 id
= wxResourceGetIdentifier(str
, &table
);
802 wxLogWarning(_("Could not resolve control class or id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)"),
803 (const wxChar
*) expr1
->StringValue());
805 return (wxItemResource
*) NULL
;
809 // Success - we have an id, so the 2nd element must be the control class.
810 controlType
= expr
->Nth(1)->StringValue();
815 else if (expr1
->Type() == PrologInteger
)
817 id
= (int)expr1
->IntegerValue();
818 // Success - we have an id, so the 2nd element must be the control class.
819 controlType
= expr
->Nth(1)->StringValue();
823 expr1
= expr
->Nth(count
);
826 title
= expr1
->StringValue();
828 expr1
= expr
->Nth(count
);
832 style
= expr1
->StringValue();
833 windowStyle
= wxParseWindowStyle(style
);
836 expr1
= expr
->Nth(count
);
839 name
= expr1
->StringValue();
841 expr1
= expr
->Nth(count
);
844 x
= (int)expr1
->IntegerValue();
846 expr1
= expr
->Nth(count
);
849 y
= (int)expr1
->IntegerValue();
851 expr1
= expr
->Nth(count
);
854 width
= (int)expr1
->IntegerValue();
856 expr1
= expr
->Nth(count
);
859 height
= (int)expr1
->IntegerValue();
861 controlItem
->SetStyle(windowStyle
);
862 controlItem
->SetName(name
);
863 controlItem
->SetTitle(title
);
864 controlItem
->SetSize(x
, y
, width
, height
);
865 controlItem
->SetType(controlType
);
866 controlItem
->SetId(id
);
868 // Check for wxWin 1.68-style specifications
869 if (style
.Find(wxT("VERTICAL_LABEL")) != -1)
870 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
871 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != -1)
872 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
874 if (controlType
== wxT("wxButton"))
876 // Check for bitmap resource name (in case loading old-style resource file)
877 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
879 wxString
str(expr
->Nth(count
)->StringValue());
884 controlItem
->SetValue4(str
);
885 controlItem
->SetType(wxT("wxBitmapButton"));
888 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
889 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
891 else if (controlType
== wxT("wxBitmapButton"))
893 // Check for bitmap resource name
894 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
896 wxString
str(expr
->Nth(count
)->StringValue());
897 controlItem
->SetValue4(str
);
899 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
900 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
903 else if (controlType
== wxT("wxCheckBox"))
905 // Check for default value
906 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
908 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
910 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
911 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
915 else if (controlType
== wxT("wxRadioButton"))
917 // Check for default value
918 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
920 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
922 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
923 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
927 else if (controlType
== wxT("wxText") || controlType
== wxT("wxTextCtrl") || controlType
== wxT("wxMultiText"))
929 // Check for default value
930 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
932 wxString
str(expr
->Nth(count
)->StringValue());
933 controlItem
->SetValue4(str
);
936 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
938 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
939 // Skip past the obsolete label font spec if there are two consecutive specs
940 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
942 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
946 else if (controlType
== wxT("wxMessage") || controlType
== wxT("wxStaticText"))
948 // Check for bitmap resource name (in case it's an old-style .wxr file)
949 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
951 wxString
str(expr
->Nth(count
)->StringValue());
952 controlItem
->SetValue4(str
);
954 controlItem
->SetType(wxT("wxStaticText"));
956 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
957 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
959 else if (controlType
== wxT("wxStaticBitmap"))
961 // Check for bitmap resource name
962 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
964 wxString
str(expr
->Nth(count
)->StringValue());
965 controlItem
->SetValue4(str
);
968 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
969 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
971 else if (controlType
== wxT("wxGroupBox") || controlType
== wxT("wxStaticBox"))
973 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
974 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
976 else if (controlType
== wxT("wxGauge"))
978 // Check for default value
979 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
981 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
985 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
987 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
990 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
992 // Skip past the obsolete label font spec if there are two consecutive specs
993 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
995 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1000 else if (controlType
== wxT("wxSlider"))
1002 // Check for default value
1003 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1005 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1009 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1011 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1015 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1017 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1020 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1022 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1026 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1027 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1033 else if (controlType
== wxT("wxScrollBar"))
1036 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1038 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1042 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1044 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1048 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1050 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1054 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1055 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1060 else if (controlType
== wxT("wxListBox"))
1062 wxExpr
*valueList
= (wxExpr
*) NULL
;
1064 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1066 wxStringList stringList
;
1067 wxExpr
*stringExpr
= valueList
->GetFirst();
1070 stringList
.Add(stringExpr
->StringValue());
1071 stringExpr
= stringExpr
->GetNext();
1073 controlItem
->SetStringValues(stringList
);
1075 // This is now obsolete: it's in the window style.
1076 // Check for wxSINGLE/wxMULTIPLE
1077 wxExpr
*mult
= (wxExpr
*) NULL
;
1079 controlItem->SetValue1(wxLB_SINGLE);
1081 if (((mult
= expr
->Nth(count
)) != 0) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1084 wxString m(mult->StringValue());
1085 if (m == "wxLB_MULTIPLE")
1086 controlItem->SetValue1(wxLB_MULTIPLE);
1087 else if (m == "wxLB_EXTENDED")
1088 controlItem->SetValue1(wxLB_EXTENDED);
1093 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1095 // Skip past the obsolete label font spec if there are two consecutive specs
1096 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1098 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1102 else if (controlType
== wxT("wxChoice"))
1104 wxExpr
*valueList
= (wxExpr
*) NULL
;
1105 // Check for default value list
1106 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1108 wxStringList stringList
;
1109 wxExpr
*stringExpr
= valueList
->GetFirst();
1112 stringList
.Add(stringExpr
->StringValue());
1113 stringExpr
= stringExpr
->GetNext();
1115 controlItem
->SetStringValues(stringList
);
1119 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1121 // Skip past the obsolete label font spec if there are two consecutive specs
1122 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1124 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1129 else if (controlType
== wxT("wxComboBox"))
1131 wxExpr
*textValue
= expr
->Nth(count
);
1132 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1134 wxString
str(textValue
->StringValue());
1135 controlItem
->SetValue4(str
);
1139 wxExpr
*valueList
= (wxExpr
*) NULL
;
1140 // Check for default value list
1141 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1143 wxStringList stringList
;
1144 wxExpr
*stringExpr
= valueList
->GetFirst();
1147 stringList
.Add(stringExpr
->StringValue());
1148 stringExpr
= stringExpr
->GetNext();
1150 controlItem
->SetStringValues(stringList
);
1154 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1156 // Skip past the obsolete label font spec if there are two consecutive specs
1157 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1159 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1166 else if (controlType
== wxT("wxRadioBox"))
1168 wxExpr
*valueList
= (wxExpr
*) NULL
;
1169 // Check for default value list
1170 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1172 wxStringList stringList
;
1173 wxExpr
*stringExpr
= valueList
->GetFirst();
1176 stringList
.Add(stringExpr
->StringValue());
1177 stringExpr
= stringExpr
->GetNext();
1179 controlItem
->SetStringValues(stringList
);
1182 // majorDim (number of rows or cols)
1183 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1185 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1189 controlItem
->SetValue1(0);
1191 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1193 // Skip past the obsolete label font spec if there are two consecutive specs
1194 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1196 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1204 return (wxItemResource
*) NULL
;
1209 // Forward declaration
1210 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1213 * Interpet a menu item
1216 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1218 wxItemResource
*item
= new wxItemResource
;
1220 wxExpr
*labelExpr
= expr
->Nth(0);
1221 wxExpr
*idExpr
= expr
->Nth(1);
1222 wxExpr
*helpExpr
= expr
->Nth(2);
1223 wxExpr
*checkableExpr
= expr
->Nth(3);
1225 // Further keywords/attributes to follow sometime...
1226 if (expr
->Number() == 0)
1228 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1229 item
->SetType(wxT("wxMenuSeparator"));
1234 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1235 item
->SetType(wxT("wxMenu")); // Well, menu item, but doesn't matter.
1238 wxString
str(labelExpr
->StringValue());
1239 item
->SetTitle(str
);
1244 // If a string or word, must look up in identifier table.
1245 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1247 wxString
str(idExpr
->StringValue());
1248 id
= wxResourceGetIdentifier(str
, &table
);
1251 wxLogWarning(_("Could not resolve menu id '%s'. Use (non-zero) integer instead\nor provide #define (see manual for caveats)"),
1252 (const wxChar
*) idExpr
->StringValue());
1255 else if (idExpr
->Type() == PrologInteger
)
1256 id
= (int)idExpr
->IntegerValue();
1257 item
->SetValue1(id
);
1261 wxString
str(helpExpr
->StringValue());
1262 item
->SetValue4(str
);
1265 item
->SetValue2(checkableExpr
->IntegerValue());
1267 // Find the first expression that's a list, for submenu
1268 wxExpr
*subMenuExpr
= expr
->GetFirst();
1269 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1270 subMenuExpr
= subMenuExpr
->GetNext();
1274 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1275 item
->GetChildren().Append(child
);
1276 subMenuExpr
= subMenuExpr
->GetNext();
1283 * Interpret a nested list as a menu
1286 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1288 wxItemResource *menu = new wxItemResource;
1289 // menu->SetType(wxTYPE_MENU);
1290 menu->SetType("wxMenu");
1291 wxExpr *element = expr->GetFirst();
1294 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1296 menu->GetChildren().Append(item);
1297 element = element->GetNext();
1303 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1305 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1306 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1308 return (wxItemResource
*) NULL
;
1310 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1313 return (wxItemResource
*) NULL
;
1316 if (expr
->GetAttributeValue(wxT("name"), name
))
1318 menuResource
->SetName(name
);
1321 return menuResource
;
1324 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1326 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1327 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1329 return (wxItemResource
*) NULL
;
1331 wxItemResource
*resource
= new wxItemResource
;
1332 resource
->SetType(wxT("wxMenu"));
1333 // resource->SetType(wxTYPE_MENU);
1335 wxExpr
*element
= listExpr
->GetFirst();
1338 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1339 resource
->GetChildren().Append(menuResource
);
1340 element
= element
->GetNext();
1344 if (expr
->GetAttributeValue(wxT("name"), name
))
1346 resource
->SetName(name
);
1352 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1354 return (wxItemResource
*) NULL
;
1357 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1359 wxItemResource
*bitmapItem
= new wxItemResource
;
1360 // bitmapItem->SetType(wxTYPE_BITMAP);
1361 bitmapItem
->SetType(wxT("wxBitmap"));
1363 if (expr
->GetAttributeValue(wxT("name"), name
))
1365 bitmapItem
->SetName(name
);
1367 // Now parse all bitmap specifications
1368 wxExpr
*bitmapExpr
= expr
->GetFirst();
1371 if (bitmapExpr
->Number() == 3)
1373 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1374 if (bitmapKeyword
== wxT("bitmap") || bitmapKeyword
== wxT("icon"))
1376 // The value part: always a list.
1377 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1378 if (listExpr
->Type() == PrologList
)
1380 wxItemResource
*bitmapSpec
= new wxItemResource
;
1381 // bitmapSpec->SetType(wxTYPE_BITMAP);
1382 bitmapSpec
->SetType(wxT("wxBitmap"));
1384 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1385 // where everything after 'filename' is optional.
1386 wxExpr
*nameExpr
= listExpr
->Nth(0);
1387 wxExpr
*typeExpr
= listExpr
->Nth(1);
1388 wxExpr
*platformExpr
= listExpr
->Nth(2);
1389 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1390 wxExpr
*xresExpr
= listExpr
->Nth(4);
1391 wxExpr
*yresExpr
= listExpr
->Nth(5);
1392 if (nameExpr
&& nameExpr
->StringValue() != wxT(""))
1394 bitmapSpec
->SetName(nameExpr
->StringValue());
1396 if (typeExpr
&& typeExpr
->StringValue() != wxT(""))
1398 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1401 bitmapSpec
->SetValue1(0);
1403 if (platformExpr
&& platformExpr
->StringValue() != wxT(""))
1405 wxString
plat(platformExpr
->StringValue());
1406 if (plat
== wxT("windows") || plat
== wxT("WINDOWS"))
1407 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1408 else if (plat
== wxT("x") || plat
== wxT("X"))
1409 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1410 else if (plat
== wxT("mac") || plat
== wxT("MAC"))
1411 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1413 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1416 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1419 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1423 xres
= (int)xresExpr
->IntegerValue();
1425 yres
= (int)yresExpr
->IntegerValue();
1426 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1428 bitmapItem
->GetChildren().Append(bitmapSpec
);
1432 bitmapExpr
= bitmapExpr
->GetNext();
1438 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1440 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1443 // item->SetType(wxTYPE_ICON);
1444 item
->SetType(wxT("wxIcon"));
1448 return (wxItemResource
*) NULL
;
1451 // Interpret list expression as a font
1452 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1454 if (expr
->Type() != PrologList
)
1458 int family
= wxSWISS
;
1459 int style
= wxNORMAL
;
1460 int weight
= wxNORMAL
;
1462 wxString
faceName(wxT(""));
1464 wxExpr
*pointExpr
= expr
->Nth(0);
1465 wxExpr
*familyExpr
= expr
->Nth(1);
1466 wxExpr
*styleExpr
= expr
->Nth(2);
1467 wxExpr
*weightExpr
= expr
->Nth(3);
1468 wxExpr
*underlineExpr
= expr
->Nth(4);
1469 wxExpr
*faceNameExpr
= expr
->Nth(5);
1471 point
= (int)pointExpr
->IntegerValue();
1476 str
= familyExpr
->StringValue();
1477 family
= (int)wxParseWindowStyle(str
);
1481 str
= styleExpr
->StringValue();
1482 style
= (int)wxParseWindowStyle(str
);
1486 str
= weightExpr
->StringValue();
1487 weight
= (int)wxParseWindowStyle(str
);
1490 underline
= (int)underlineExpr
->IntegerValue();
1492 faceName
= faceNameExpr
->StringValue();
1494 return *wxTheFontList
->FindOrCreateFont(point
, family
, style
, weight
,
1495 (underline
!= 0), faceName
);
1498 // Separate file for the remainder of this, for BC++/Win16
1500 #if !((defined(__BORLANDC__) || defined(__SC__)) && defined(__WIN16__))
1502 * (Re)allocate buffer for reading in from resource file
1505 bool wxReallocateResourceBuffer()
1507 if (!wxResourceBuffer
)
1509 wxResourceBufferSize
= 1000;
1510 wxResourceBuffer
= new char[wxResourceBufferSize
];
1513 if (wxResourceBuffer
)
1515 long newSize
= wxResourceBufferSize
+ 1000;
1516 char *tmp
= new char[(int)newSize
];
1517 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1518 delete[] wxResourceBuffer
;
1519 wxResourceBuffer
= tmp
;
1520 wxResourceBufferSize
= newSize
;
1525 static bool wxEatWhiteSpace(FILE *fd
)
1529 while ((ch
= getc(fd
)) != EOF
)
1544 ungetc(prev_ch
, fd
);
1552 while ((ch
= getc(fd
)) != EOF
)
1554 if (ch
== '/' && prev_ch
== '*')
1562 static char buffer
[255];
1563 fgets(buffer
, 255, fd
);
1567 ungetc(prev_ch
, fd
);
1581 static bool wxEatWhiteSpace(wxInputStream
*is
)
1583 int ch
= is
->GetC() ;
1584 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1591 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1593 // Check for comment
1599 bool finished
= FALSE
;
1607 int newCh
= is
->GetC();
1622 return wxEatWhiteSpace(is
);
1625 bool wxGetResourceToken(FILE *fd
)
1627 if (!wxResourceBuffer
)
1628 wxReallocateResourceBuffer();
1629 wxResourceBuffer
[0] = 0;
1630 wxEatWhiteSpace(fd
);
1636 wxResourceBufferCount
= 0;
1643 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1646 // Escaped characters
1647 else if (ch
== '\\')
1649 int newCh
= getc(fd
);
1652 else if (newCh
== 10)
1660 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1661 wxReallocateResourceBuffer();
1662 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1663 wxResourceBufferCount
++;
1666 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1670 wxResourceBufferCount
= 0;
1672 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1674 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1675 wxReallocateResourceBuffer();
1676 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1677 wxResourceBufferCount
++;
1681 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1688 bool wxGetResourceToken(wxInputStream
*is
)
1690 if (!wxResourceBuffer
)
1691 wxReallocateResourceBuffer();
1692 wxResourceBuffer
[0] = 0;
1693 wxEatWhiteSpace(is
);
1695 int ch
= is
->GetC() ;
1699 wxResourceBufferCount
= 0;
1706 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1709 // Escaped characters
1710 else if (ch
== '\\')
1712 int newCh
= is
->GetC();
1715 else if (newCh
== 10)
1717 else if (newCh
== 13) // mac
1725 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1726 wxReallocateResourceBuffer();
1727 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1728 wxResourceBufferCount
++;
1731 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1735 wxResourceBufferCount
= 0;
1737 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1739 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1740 wxReallocateResourceBuffer();
1741 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1742 wxResourceBufferCount
++;
1746 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1754 * Files are in form:
1755 static char *name = "....";
1756 with possible comments.
1759 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1762 table
= wxDefaultResourceTable
;
1764 // static or #define
1765 if (!wxGetResourceToken(fd
))
1771 if (strcmp(wxResourceBuffer
, "#define") == 0)
1773 wxGetResourceToken(fd
);
1774 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1775 wxGetResourceToken(fd
);
1776 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1777 if (wxIsdigit(value
[0]))
1779 int val
= (int)wxAtol(value
);
1780 wxResourceAddIdentifier(name
, val
, table
);
1784 wxLogWarning(_("#define %s must be an integer."), name
);
1794 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1796 wxGetResourceToken(fd
);
1797 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1798 wxChar
*actualName
= name
;
1799 if (name
[0] == wxT('"'))
1800 actualName
= name
+ 1;
1801 int len
= wxStrlen(name
);
1802 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1804 if (!wxResourceParseIncludeFile(actualName
, table
))
1806 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1811 else if (strcmp(wxResourceBuffer
, "static") != 0)
1814 wxStrcpy(buf
, _("Found "));
1815 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
1816 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1822 if (!wxGetResourceToken(fd
))
1824 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1829 if (strcmp(wxResourceBuffer
, "char") != 0)
1831 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1836 if (!wxGetResourceToken(fd
))
1838 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1843 if (wxResourceBuffer
[0] != '*')
1845 wxLogWarning(_("Expected '*' whilst parsing resource."));
1848 wxChar nameBuf
[100];
1849 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
1853 if (!wxGetResourceToken(fd
))
1855 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1860 if (strcmp(wxResourceBuffer
, "=") != 0)
1862 wxLogWarning(_("Expected '=' whilst parsing resource."));
1867 if (!wxGetResourceToken(fd
))
1869 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1875 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1877 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1882 if (!wxGetResourceToken(fd
))
1889 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1892 table
= wxDefaultResourceTable
;
1894 // static or #define
1895 if (!wxGetResourceToken(fd
))
1901 if (strcmp(wxResourceBuffer
, "#define") == 0)
1903 wxGetResourceToken(fd
);
1904 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1905 wxGetResourceToken(fd
);
1906 wxChar
*value
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1907 if (wxIsalpha(value
[0]))
1909 int val
= (int)wxAtol(value
);
1910 wxResourceAddIdentifier(name
, val
, table
);
1914 wxLogWarning(_("#define %s must be an integer."), name
);
1924 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1926 wxGetResourceToken(fd
);
1927 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1928 wxChar
*actualName
= name
;
1929 if (name
[0] == wxT('"'))
1930 actualName
= name
+ 1;
1931 int len
= wxStrlen(name
);
1932 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1934 if (!wxResourceParseIncludeFile(actualName
, table
))
1936 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1941 else if (strcmp(wxResourceBuffer
, "static") != 0)
1944 wxStrcpy(buf
, _("Found "));
1945 wxStrncat(buf
, wxConvLibc
.cMB2WX(wxResourceBuffer
), 30);
1946 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1952 if (!wxGetResourceToken(fd
))
1954 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1959 if (strcmp(wxResourceBuffer
, "char") != 0)
1961 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1966 if (!wxGetResourceToken(fd
))
1968 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1973 if (wxResourceBuffer
[0] != '*')
1975 wxLogWarning(_("Expected '*' whilst parsing resource."));
1979 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
1982 if (!wxGetResourceToken(fd
))
1984 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1989 if (strcmp(wxResourceBuffer
, "=") != 0)
1991 wxLogWarning(_("Expected '=' whilst parsing resource."));
1996 if (!wxGetResourceToken(fd
))
1998 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2004 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2006 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2011 if (!wxGetResourceToken(fd
))
2019 * Parses string window style into integer window style
2023 * Style flag parsing, e.g.
2024 * "wxSYSTEM_MENU | wxBORDER" -> integer
2027 wxChar
* wxResourceParseWord(wxChar
*s
, int *i
)
2030 return (wxChar
*) NULL
;
2032 static wxChar buf
[150];
2033 int len
= wxStrlen(s
);
2036 while ((ii
< len
) && (wxIsalpha(s
[ii
]) || (s
[ii
] == wxT('_'))))
2044 // Eat whitespace and conjunction characters
2045 while ((ii
< len
) &&
2046 ((s
[ii
] == wxT(' ')) || (s
[ii
] == wxT('|')) || (s
[ii
] == wxT(','))))
2052 return (wxChar
*) NULL
;
2057 struct wxResourceBitListStruct
2063 static wxResourceBitListStruct wxResourceBitListTable
[] =
2066 { wxT("wxSINGLE"), wxLB_SINGLE
},
2067 { wxT("wxMULTIPLE"), wxLB_MULTIPLE
},
2068 { wxT("wxEXTENDED"), wxLB_EXTENDED
},
2069 { wxT("wxLB_SINGLE"), wxLB_SINGLE
},
2070 { wxT("wxLB_MULTIPLE"), wxLB_MULTIPLE
},
2071 { wxT("wxLB_EXTENDED"), wxLB_EXTENDED
},
2072 { wxT("wxLB_NEEDED_SB"), wxLB_NEEDED_SB
},
2073 { wxT("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB
},
2074 { wxT("wxLB_SORT"), wxLB_SORT
},
2075 { wxT("wxLB_OWNERDRAW"), wxLB_OWNERDRAW
},
2076 { wxT("wxLB_HSCROLL"), wxLB_HSCROLL
},
2079 { wxT("wxCB_SIMPLE"), wxCB_SIMPLE
},
2080 { wxT("wxCB_DROPDOWN"), wxCB_DROPDOWN
},
2081 { wxT("wxCB_READONLY"), wxCB_READONLY
},
2082 { wxT("wxCB_SORT"), wxCB_SORT
},
2085 { wxT("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR
},
2086 { wxT("wxGA_HORIZONTAL"), wxGA_HORIZONTAL
},
2087 { wxT("wxGA_VERTICAL"), wxGA_VERTICAL
},
2090 { wxT("wxPASSWORD"), wxPASSWORD
},
2091 { wxT("wxPROCESS_ENTER"), wxPROCESS_ENTER
},
2092 { wxT("wxTE_PASSWORD"), wxTE_PASSWORD
},
2093 { wxT("wxTE_READONLY"), wxTE_READONLY
},
2094 { wxT("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER
},
2095 { wxT("wxTE_MULTILINE"), wxTE_MULTILINE
},
2096 { wxT("wxTE_NO_VSCROLL"), wxTE_NO_VSCROLL
},
2098 /* wxRadioBox/wxRadioButton */
2099 { wxT("wxRB_GROUP"), wxRB_GROUP
},
2100 { wxT("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS
},
2101 { wxT("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS
},
2102 { wxT("wxRA_HORIZONTAL"), wxRA_HORIZONTAL
},
2103 { wxT("wxRA_VERTICAL"), wxRA_VERTICAL
},
2106 { wxT("wxSL_HORIZONTAL"), wxSL_HORIZONTAL
},
2107 { wxT("wxSL_VERTICAL"), wxSL_VERTICAL
},
2108 { wxT("wxSL_AUTOTICKS"), wxSL_AUTOTICKS
},
2109 { wxT("wxSL_LABELS"), wxSL_LABELS
},
2110 { wxT("wxSL_LEFT"), wxSL_LEFT
},
2111 { wxT("wxSL_TOP"), wxSL_TOP
},
2112 { wxT("wxSL_RIGHT"), wxSL_RIGHT
},
2113 { wxT("wxSL_BOTTOM"), wxSL_BOTTOM
},
2114 { wxT("wxSL_BOTH"), wxSL_BOTH
},
2115 { wxT("wxSL_SELRANGE"), wxSL_SELRANGE
},
2118 { wxT("wxSB_HORIZONTAL"), wxSB_HORIZONTAL
},
2119 { wxT("wxSB_VERTICAL"), wxSB_VERTICAL
},
2122 { wxT("wxBU_AUTODRAW"), wxBU_AUTODRAW
},
2123 { wxT("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW
},
2126 { wxT("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS
},
2127 { wxT("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS
},
2128 { wxT("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT
},
2131 { wxT("wxLC_ICON"), wxLC_ICON
},
2132 { wxT("wxLC_SMALL_ICON"), wxLC_SMALL_ICON
},
2133 { wxT("wxLC_LIST"), wxLC_LIST
},
2134 { wxT("wxLC_REPORT"), wxLC_REPORT
},
2135 { wxT("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP
},
2136 { wxT("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT
},
2137 { wxT("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE
},
2138 { wxT("wxLC_USER_TEXT"), wxLC_USER_TEXT
},
2139 { wxT("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS
},
2140 { wxT("wxLC_NO_HEADER"), wxLC_NO_HEADER
},
2141 { wxT("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER
},
2142 { wxT("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL
},
2143 { wxT("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING
},
2144 { wxT("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING
},
2147 { wxT("wxSP_VERTICAL"), wxSP_VERTICAL
},
2148 { wxT("wxSP_HORIZONTAL"), wxSP_HORIZONTAL
},
2149 { wxT("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS
},
2150 { wxT("wxSP_WRAP"), wxSP_WRAP
},
2153 { wxT("wxSP_NOBORDER"), wxSP_NOBORDER
},
2154 { wxT("wxSP_3D"), wxSP_3D
},
2155 { wxT("wxSP_BORDER"), wxSP_BORDER
},
2158 { wxT("wxTC_MULTILINE"), wxTC_MULTILINE
},
2159 { wxT("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY
},
2160 { wxT("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH
},
2161 { wxT("wxTC_OWNERDRAW"), wxTC_OWNERDRAW
},
2164 { wxT("wxST_SIZEGRIP"), wxST_SIZEGRIP
},
2167 { wxT("wxFIXED_LENGTH"), wxFIXED_LENGTH
},
2168 { wxT("wxALIGN_LEFT"), wxALIGN_LEFT
},
2169 { wxT("wxALIGN_CENTER"), wxALIGN_CENTER
},
2170 { wxT("wxALIGN_CENTRE"), wxALIGN_CENTRE
},
2171 { wxT("wxALIGN_RIGHT"), wxALIGN_RIGHT
},
2172 { wxT("wxCOLOURED"), wxCOLOURED
},
2175 { wxT("wxTB_3DBUTTONS"), wxTB_3DBUTTONS
},
2176 { wxT("wxTB_HORIZONTAL"), wxTB_HORIZONTAL
},
2177 { wxT("wxTB_VERTICAL"), wxTB_VERTICAL
},
2178 { wxT("wxTB_FLAT"), wxTB_FLAT
},
2181 { wxT("wxDIALOG_MODAL"), wxDIALOG_MODAL
},
2184 { wxT("wxVSCROLL"), wxVSCROLL
},
2185 { wxT("wxHSCROLL"), wxHSCROLL
},
2186 { wxT("wxCAPTION"), wxCAPTION
},
2187 { wxT("wxSTAY_ON_TOP"), wxSTAY_ON_TOP
},
2188 { wxT("wxICONIZE"), wxICONIZE
},
2189 { wxT("wxMINIMIZE"), wxICONIZE
},
2190 { wxT("wxMAXIMIZE"), wxMAXIMIZE
},
2192 { wxT("wxMDI_PARENT"), 0},
2193 { wxT("wxMDI_CHILD"), 0},
2194 { wxT("wxTHICK_FRAME"), wxTHICK_FRAME
},
2195 { wxT("wxRESIZE_BORDER"), wxRESIZE_BORDER
},
2196 { wxT("wxSYSTEM_MENU"), wxSYSTEM_MENU
},
2197 { wxT("wxMINIMIZE_BOX"), wxMINIMIZE_BOX
},
2198 { wxT("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX
},
2199 { wxT("wxRESIZE_BOX"), wxRESIZE_BOX
},
2200 { wxT("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE
},
2201 { wxT("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE
},
2202 { wxT("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE
},
2203 { wxT("wxBORDER"), wxBORDER
},
2204 { wxT("wxRETAINED"), wxRETAINED
},
2205 { wxT("wxNATIVE_IMPL"), 0},
2206 { wxT("wxEXTENDED_IMPL"), 0},
2207 { wxT("wxBACKINGSTORE"), wxBACKINGSTORE
},
2208 // { wxT("wxFLAT"), wxFLAT},
2209 // { wxT("wxMOTIF_RESIZE"), wxMOTIF_RESIZE},
2210 { wxT("wxFIXED_LENGTH"), 0},
2211 { wxT("wxDOUBLE_BORDER"), wxDOUBLE_BORDER
},
2212 { wxT("wxSUNKEN_BORDER"), wxSUNKEN_BORDER
},
2213 { wxT("wxRAISED_BORDER"), wxRAISED_BORDER
},
2214 { wxT("wxSIMPLE_BORDER"), wxSIMPLE_BORDER
},
2215 { wxT("wxSTATIC_BORDER"), wxSTATIC_BORDER
},
2216 { wxT("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW
},
2217 { wxT("wxNO_BORDER"), wxNO_BORDER
},
2218 { wxT("wxCLIP_CHILDREN"), wxCLIP_CHILDREN
},
2219 { wxT("wxCLIP_SIBLINGS"), wxCLIP_SIBLINGS
},
2220 { wxT("wxTAB_TRAVERSAL"), 0}, // Compatibility only
2222 { wxT("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ
},
2223 { wxT("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT
},
2225 // Text font families
2226 { wxT("wxDEFAULT"), wxDEFAULT
},
2227 { wxT("wxDECORATIVE"), wxDECORATIVE
},
2228 { wxT("wxROMAN"), wxROMAN
},
2229 { wxT("wxSCRIPT"), wxSCRIPT
},
2230 { wxT("wxSWISS"), wxSWISS
},
2231 { wxT("wxMODERN"), wxMODERN
},
2232 { wxT("wxTELETYPE"), wxTELETYPE
},
2233 { wxT("wxVARIABLE"), wxVARIABLE
},
2234 { wxT("wxFIXED"), wxFIXED
},
2235 { wxT("wxNORMAL"), wxNORMAL
},
2236 { wxT("wxLIGHT"), wxLIGHT
},
2237 { wxT("wxBOLD"), wxBOLD
},
2238 { wxT("wxITALIC"), wxITALIC
},
2239 { wxT("wxSLANT"), wxSLANT
},
2240 { wxT("wxSOLID"), wxSOLID
},
2241 { wxT("wxDOT"), wxDOT
},
2242 { wxT("wxLONG_DASH"), wxLONG_DASH
},
2243 { wxT("wxSHORT_DASH"), wxSHORT_DASH
},
2244 { wxT("wxDOT_DASH"), wxDOT_DASH
},
2245 { wxT("wxUSER_DASH"), wxUSER_DASH
},
2246 { wxT("wxTRANSPARENT"), wxTRANSPARENT
},
2247 { wxT("wxSTIPPLE"), wxSTIPPLE
},
2248 { wxT("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH
},
2249 { wxT("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH
},
2250 { wxT("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH
},
2251 { wxT("wxCROSS_HATCH"), wxCROSS_HATCH
},
2252 { wxT("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH
},
2253 { wxT("wxVERTICAL_HATCH"), wxVERTICAL_HATCH
},
2254 { wxT("wxJOIN_BEVEL"), wxJOIN_BEVEL
},
2255 { wxT("wxJOIN_MITER"), wxJOIN_MITER
},
2256 { wxT("wxJOIN_ROUND"), wxJOIN_ROUND
},
2257 { wxT("wxCAP_ROUND"), wxCAP_ROUND
},
2258 { wxT("wxCAP_PROJECTING"), wxCAP_PROJECTING
},
2259 { wxT("wxCAP_BUTT"), wxCAP_BUTT
},
2262 { wxT("wxCLEAR"), wxCLEAR
},
2263 { wxT("wxXOR"), wxXOR
},
2264 { wxT("wxINVERT"), wxINVERT
},
2265 { wxT("wxOR_REVERSE"), wxOR_REVERSE
},
2266 { wxT("wxAND_REVERSE"), wxAND_REVERSE
},
2267 { wxT("wxCOPY"), wxCOPY
},
2268 { wxT("wxAND"), wxAND
},
2269 { wxT("wxAND_INVERT"), wxAND_INVERT
},
2270 { wxT("wxNO_OP"), wxNO_OP
},
2271 { wxT("wxNOR"), wxNOR
},
2272 { wxT("wxEQUIV"), wxEQUIV
},
2273 { wxT("wxSRC_INVERT"), wxSRC_INVERT
},
2274 { wxT("wxOR_INVERT"), wxOR_INVERT
},
2275 { wxT("wxNAND"), wxNAND
},
2276 { wxT("wxOR"), wxOR
},
2277 { wxT("wxSET"), wxSET
},
2279 { wxT("wxFLOOD_SURFACE"), wxFLOOD_SURFACE
},
2280 { wxT("wxFLOOD_BORDER"), wxFLOOD_BORDER
},
2281 { wxT("wxODDEVEN_RULE"), wxODDEVEN_RULE
},
2282 { wxT("wxWINDING_RULE"), wxWINDING_RULE
},
2283 { wxT("wxHORIZONTAL"), wxHORIZONTAL
},
2284 { wxT("wxVERTICAL"), wxVERTICAL
},
2285 { wxT("wxBOTH"), wxBOTH
},
2286 { wxT("wxCENTER_FRAME"), wxCENTER_FRAME
},
2287 { wxT("wxOK"), wxOK
},
2288 { wxT("wxYES_NO"), wxYES_NO
},
2289 { wxT("wxCANCEL"), wxCANCEL
},
2290 { wxT("wxYES"), wxYES
},
2291 { wxT("wxNO"), wxNO
},
2292 { wxT("wxICON_EXCLAMATION"), wxICON_EXCLAMATION
},
2293 { wxT("wxICON_HAND"), wxICON_HAND
},
2294 { wxT("wxICON_QUESTION"), wxICON_QUESTION
},
2295 { wxT("wxICON_INFORMATION"), wxICON_INFORMATION
},
2296 { wxT("wxICON_STOP"), wxICON_STOP
},
2297 { wxT("wxICON_ASTERISK"), wxICON_ASTERISK
},
2298 { wxT("wxICON_MASK"), wxICON_MASK
},
2299 { wxT("wxCENTRE"), wxCENTRE
},
2300 { wxT("wxCENTER"), wxCENTRE
},
2301 { wxT("wxUSER_COLOURS"), wxUSER_COLOURS
},
2302 { wxT("wxVERTICAL_LABEL"), 0},
2303 { wxT("wxHORIZONTAL_LABEL"), 0},
2305 // Bitmap types (not strictly styles)
2306 { wxT("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM
},
2307 { wxT("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM
},
2308 { wxT("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP
},
2309 { wxT("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2310 { wxT("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2311 { wxT("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF
},
2312 { wxT("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF
},
2313 { wxT("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO
},
2314 { wxT("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE
},
2315 { wxT("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR
},
2316 { wxT("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE
},
2317 { wxT("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA
},
2318 { wxT("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA
},
2319 { wxT("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY
}
2322 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2324 long wxParseWindowStyle(const wxString
& bitListString
)
2329 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2330 while (word
!= NULL
)
2334 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2335 if (wxStrcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2337 bitList
|= wxResourceBitListTable
[j
].bits
;
2343 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
2346 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2352 * Load a bitmap from a wxWindows resource, choosing an optimum
2353 * depth and appropriate type.
2356 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2359 table
= wxDefaultResourceTable
;
2361 wxItemResource
*item
= table
->FindResource(resource
);
2364 if ((item
->GetType() == wxT("")) || (item
->GetType() != wxT("wxBitmap")))
2366 wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar
*) resource
);
2367 return wxNullBitmap
;
2369 int thisDepth
= wxDisplayDepth();
2370 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2372 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2374 // Try to find optimum bitmap for this platform/colour depth
2375 wxNode
*node
= item
->GetChildren().First();
2378 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2379 int platform
= (int)child
->GetValue2();
2380 int noColours
= (int)child
->GetValue3();
2382 char *name = child->GetName();
2383 int bitmapType = (int)child->GetValue1();
2384 int xRes = child->GetWidth();
2385 int yRes = child->GetHeight();
2390 case RESOURCE_PLATFORM_ANY
:
2392 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2393 optResource
= child
;
2396 // Maximise the number of colours.
2397 // If noColours is zero (unspecified), then assume this
2398 // is the right one.
2399 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2400 optResource
= child
;
2405 case RESOURCE_PLATFORM_WINDOWS
:
2407 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2408 optResource
= child
;
2411 // Maximise the number of colours
2412 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2413 optResource
= child
;
2419 case RESOURCE_PLATFORM_X
:
2421 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2422 optResource
= child
;
2425 // Maximise the number of colours
2426 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2427 optResource
= child
;
2433 case RESOURCE_PLATFORM_MAC
:
2435 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2436 optResource
= child
;
2439 // Maximise the number of colours
2440 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2441 optResource
= child
;
2449 node
= node
->Next();
2451 // If no matching resource, fail.
2453 return wxNullBitmap
;
2455 wxString name
= optResource
->GetName();
2456 int bitmapType
= (int)optResource
->GetValue1();
2459 case wxBITMAP_TYPE_XBM_DATA
:
2462 wxItemResource
*item
= table
->FindResource(name
);
2465 wxLogWarning(_("Failed to find XBM resource %s.\n"
2466 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2467 return wxNullBitmap
;
2469 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2471 wxLogWarning(_("No XBM facility available!"));
2475 case wxBITMAP_TYPE_XPM_DATA
:
2477 wxItemResource
*item
= table
->FindResource(name
);
2480 wxLogWarning(_("Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2481 return wxNullBitmap
;
2483 return wxBitmap((char **)item
->GetValue1());
2487 #if defined(__WXPM__)
2488 return wxNullBitmap
;
2490 return wxBitmap(name
, (wxBitmapType
)bitmapType
);
2495 return wxNullBitmap
;
2500 wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar
*) resource
);
2501 return wxNullBitmap
;
2506 * Load an icon from a wxWindows resource, choosing an optimum
2507 * depth and appropriate type.
2510 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2513 table
= wxDefaultResourceTable
;
2515 wxItemResource
*item
= table
->FindResource(resource
);
2518 if ((item
->GetType() == wxT("")) || wxStrcmp(item
->GetType(), wxT("wxIcon")) != 0)
2520 wxLogWarning(_("%s not an icon resource specification."), (const wxChar
*) resource
);
2523 int thisDepth
= wxDisplayDepth();
2524 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2526 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2528 // Try to find optimum icon for this platform/colour depth
2529 wxNode
*node
= item
->GetChildren().First();
2532 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2533 int platform
= (int)child
->GetValue2();
2534 int noColours
= (int)child
->GetValue3();
2536 char *name = child->GetName();
2537 int bitmapType = (int)child->GetValue1();
2538 int xRes = child->GetWidth();
2539 int yRes = child->GetHeight();
2544 case RESOURCE_PLATFORM_ANY
:
2546 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2547 optResource
= child
;
2550 // Maximise the number of colours.
2551 // If noColours is zero (unspecified), then assume this
2552 // is the right one.
2553 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2554 optResource
= child
;
2559 case RESOURCE_PLATFORM_WINDOWS
:
2561 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2562 optResource
= child
;
2565 // Maximise the number of colours
2566 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2567 optResource
= child
;
2573 case RESOURCE_PLATFORM_X
:
2575 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2576 optResource
= child
;
2579 // Maximise the number of colours
2580 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2581 optResource
= child
;
2587 case RESOURCE_PLATFORM_MAC
:
2589 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2590 optResource
= child
;
2593 // Maximise the number of colours
2594 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2595 optResource
= child
;
2603 node
= node
->Next();
2605 // If no matching resource, fail.
2609 wxString name
= optResource
->GetName();
2610 int bitmapType
= (int)optResource
->GetValue1();
2613 case wxBITMAP_TYPE_XBM_DATA
:
2616 wxItemResource
*item
= table
->FindResource(name
);
2619 wxLogWarning(_("Failed to find XBM resource %s.\n"
2620 "Forgot to use wxResourceLoadIconData?"), (const wxChar
*) name
);
2623 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2625 wxLogWarning(_("No XBM facility available!"));
2629 case wxBITMAP_TYPE_XPM_DATA
:
2631 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2633 wxItemResource *item = table->FindResource(name);
2637 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2641 return wxIcon((char **)item->GetValue1());
2643 wxLogWarning(_("No XPM icon facility available!"));
2648 #if defined( __WXGTK__ ) || defined( __WXMOTIF__ )
2649 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2652 return wxIcon(name
, bitmapType
);
2660 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2667 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2669 wxMenu
*menu
= new wxMenu
;
2670 wxNode
*node
= item
->GetChildren().First();
2673 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2674 if ((child
->GetType() != wxT("")) && (child
->GetType() == wxT("wxMenuSeparator")))
2675 menu
->AppendSeparator();
2676 else if (child
->GetChildren().Number() > 0)
2678 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2680 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2684 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2686 node
= node
->Next();
2691 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2694 table
= wxDefaultResourceTable
;
2696 wxItemResource
*menuResource
= table
->FindResource(resource
);
2697 if (menuResource
&& (menuResource
->GetType() != wxT("")) && (menuResource
->GetType() == wxT("wxMenu")))
2700 menuBar
= new wxMenuBar
;
2701 wxNode
*node
= menuResource
->GetChildren().First();
2704 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2705 wxMenu
*menu
= wxResourceCreateMenu(child
);
2707 menuBar
->Append(menu
, child
->GetTitle());
2708 node
= node
->Next();
2712 return (wxMenuBar
*) NULL
;
2715 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2718 table
= wxDefaultResourceTable
;
2720 wxItemResource
*menuResource
= table
->FindResource(resource
);
2721 if (menuResource
&& (menuResource
->GetType() != wxT("")) && (menuResource
->GetType() == wxT("wxMenu")))
2722 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2723 return wxResourceCreateMenu(menuResource
);
2724 return (wxMenu
*) NULL
;
2727 #endif // wxUSE_MENUS
2729 // Global equivalents (so don't have to refer to default table explicitly)
2730 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2733 table
= wxDefaultResourceTable
;
2735 return table
->ParseResourceData(resource
);
2738 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2741 table
= wxDefaultResourceTable
;
2743 return table
->ParseResourceFile(filename
);
2746 // Register XBM/XPM data
2747 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2750 table
= wxDefaultResourceTable
;
2752 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2755 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2758 table
= wxDefaultResourceTable
;
2760 return table
->RegisterResourceBitmapData(name
, data
);
2763 void wxResourceClear(wxResourceTable
*table
)
2766 table
= wxDefaultResourceTable
;
2768 table
->ClearTable();
2775 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2778 table
= wxDefaultResourceTable
;
2780 table
->identifiers
.Put(name
, (wxObject
*)(long)value
);
2784 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2787 table
= wxDefaultResourceTable
;
2789 return (int)(long)table
->identifiers
.Get(name
);
2793 * Parse #include file for #defines (only)
2796 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2799 table
= wxDefaultResourceTable
;
2801 FILE *fd
= wxFopen(f
, _T("r"));
2806 while (wxGetResourceToken(fd
))
2808 if (strcmp(wxResourceBuffer
, "#define") == 0)
2810 wxGetResourceToken(fd
);
2811 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2812 wxGetResourceToken(fd
);
2813 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2814 if (wxIsdigit(value
[0]))
2816 int val
= (int)wxAtol(value
);
2817 wxResourceAddIdentifier(name
, val
, table
);
2828 * Reading strings as if they were .wxr files
2831 static int getc_string(char *s
)
2833 int ch
= s
[wxResourceStringPtr
];
2838 wxResourceStringPtr
++;
2843 static int ungetc_string()
2845 wxResourceStringPtr
--;
2849 bool wxEatWhiteSpaceString(char *s
)
2853 while ((ch
= getc_string(s
)) != EOF
)
2865 ch
= getc_string(s
);
2876 while ((ch
= getc_string(s
)) != EOF
)
2878 if (ch
== '/' && prev_ch
== '*')
2900 bool wxGetResourceTokenString(char *s
)
2902 if (!wxResourceBuffer
)
2903 wxReallocateResourceBuffer();
2904 wxResourceBuffer
[0] = 0;
2905 wxEatWhiteSpaceString(s
);
2907 int ch
= getc_string(s
);
2911 wxResourceBufferCount
= 0;
2912 ch
= getc_string(s
);
2918 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2921 // Escaped characters
2922 else if (ch
== '\\')
2924 int newCh
= getc_string(s
);
2927 else if (newCh
== 10)
2935 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2936 wxReallocateResourceBuffer();
2937 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2938 wxResourceBufferCount
++;
2939 ch
= getc_string(s
);
2941 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2945 wxResourceBufferCount
= 0;
2947 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2949 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2950 wxReallocateResourceBuffer();
2951 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2952 wxResourceBufferCount
++;
2954 ch
= getc_string(s
);
2956 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2964 * Files are in form:
2965 static char *name = "....";
2966 with possible comments.
2969 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2972 table
= wxDefaultResourceTable
;
2974 // static or #define
2975 if (!wxGetResourceTokenString(s
))
2981 if (strcmp(wxResourceBuffer
, "#define") == 0)
2983 wxGetResourceTokenString(s
);
2984 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2985 wxGetResourceTokenString(s
);
2986 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2987 if (wxIsdigit(value
[0]))
2989 int val
= (int)wxAtol(value
);
2990 wxResourceAddIdentifier(name
, val
, table
);
2994 wxLogWarning(_("#define %s must be an integer."), name
);
3005 else if (strcmp(wxResourceBuffer, "#include") == 0)
3007 wxGetResourceTokenString(s);
3008 char *name = copystring(wxResourceBuffer);
3009 char *actualName = name;
3011 actualName = name + 1;
3012 int len = strlen(name);
3013 if ((len > 0) && (name[len-1] == '"'))
3015 if (!wxResourceParseIncludeFile(actualName, table))
3018 sprintf(buf, _("Could not find resource include file %s."), actualName);
3025 else if (strcmp(wxResourceBuffer
, "static") != 0)
3028 wxStrcpy(buf
, _("Found "));
3029 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
3030 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
3036 if (!wxGetResourceTokenString(s
))
3038 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3043 if (strcmp(wxResourceBuffer
, "char") != 0)
3045 wxLogWarning(_("Expected 'char' whilst parsing resource."));
3050 if (!wxGetResourceTokenString(s
))
3052 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3057 if (wxResourceBuffer
[0] != '*')
3059 wxLogWarning(_("Expected '*' whilst parsing resource."));
3062 wxChar nameBuf
[100];
3063 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
3067 if (!wxGetResourceTokenString(s
))
3069 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3074 if (strcmp(wxResourceBuffer
, "=") != 0)
3076 wxLogWarning(_("Expected '=' whilst parsing resource."));
3081 if (!wxGetResourceTokenString(s
))
3083 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3089 if (!db
.ReadPrologFromString(wxResourceBuffer
))
3091 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
3096 if (!wxGetResourceTokenString(s
))
3103 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
3106 table
= wxDefaultResourceTable
;
3111 // Turn backslashes into spaces
3114 int len
= strlen(s
);
3116 for (i
= 0; i
< len
; i
++)
3117 if (s
[i
] == 92 && s
[i
+1] == 13)
3125 wxResourceStringPtr
= 0;
3128 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
3132 return wxResourceInterpretResources(*table
, db
);
3136 * resource loading facility
3139 bool wxWindowBase::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
3142 table
= wxDefaultResourceTable
;
3144 wxItemResource
*resource
= table
->FindResource((const wxChar
*)resourceName
);
3145 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
3146 if (!resource
|| (resource
->GetType() == wxT("")) ||
3147 ! ((resource
->GetType() == wxT("wxDialog")) || (resource
->GetType() == wxT("wxPanel"))))
3150 wxString
title(resource
->GetTitle());
3151 long theWindowStyle
= resource
->GetStyle();
3152 bool isModal
= (resource
->GetValue1() != 0) ;
3153 int x
= resource
->GetX();
3154 int y
= resource
->GetY();
3155 int width
= resource
->GetWidth();
3156 int height
= resource
->GetHeight();
3157 wxString name
= resource
->GetName();
3159 // this is used for loading wxWizard pages from WXR
3160 if ( parent
!= this )
3162 if (IsKindOf(CLASSINFO(wxDialog
)))
3164 wxDialog
*dialogBox
= (wxDialog
*)this;
3165 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
3166 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
3169 // Only reset the client size if we know we're not going to do it again below.
3170 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
3171 dialogBox
->SetClientSize(width
, height
);
3173 else if (IsKindOf(CLASSINFO(wxPanel
)))
3175 wxPanel
* panel
= (wxPanel
*)this;
3176 if (!panel
->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
| wxTAB_TRAVERSAL
, name
))
3181 if (!((wxWindow
*)this)->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
3186 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
3188 // No need to do this since it's done in wxPanel or wxDialog constructor.
3189 // SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
3193 if (resource
->GetFont().Ok())
3194 SetFont(resource
->GetFont());
3195 if (resource
->GetBackgroundColour().Ok())
3196 SetBackgroundColour(resource
->GetBackgroundColour());
3199 // Should have some kind of font at this point
3200 if (!GetFont().Ok())
3201 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
3202 if (!GetBackgroundColour().Ok())
3203 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
3205 // Only when we've created the window and set the font can we set the correct size,
3206 // if based on dialog units.
3207 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
3209 wxSize sz
= ConvertDialogToPixels(wxSize(width
, height
));
3210 SetClientSize(sz
.x
, sz
.y
);
3212 wxPoint pt
= ConvertDialogToPixels(wxPoint(x
, y
));
3216 // Now create children
3217 wxNode
*node
= resource
->GetChildren().First();
3220 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
3222 (void) CreateItem(childResource
, resource
, table
);
3224 node
= node
->Next();
3229 wxControl
*wxWindowBase::CreateItem(const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
3232 table
= wxDefaultResourceTable
;
3233 return table
->CreateItem((wxWindow
*)this, resource
, parentResource
);
3237 #pragma warning(default:4706) // assignment within conditional expression
3243 #endif // wxUSE_WX_RESOURCES