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"
57 #include "wx/radiobut.h"
61 #include "wx/scrolbar.h"
65 #include "wx/combobox.h"
68 #include "wx/validate.h"
77 #include "wx/resource.h"
78 #include "wx/string.h"
79 #include "wx/wxexpr.h"
81 #include "wx/settings.h"
82 #include "wx/stream.h"
84 // Forward (private) declarations
85 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
);
86 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
= FALSE
);
87 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
);
88 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
);
89 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
);
90 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, wxExpr
*expr
);
91 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, wxExpr
*expr
);
92 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
);
93 // Interpret list expression
94 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
);
96 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
97 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
) ;
98 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
100 wxResourceTable
*wxDefaultResourceTable
= (wxResourceTable
*) NULL
;
102 char *wxResourceBuffer
= (char *) NULL
;
103 long wxResourceBufferSize
= 0;
104 long wxResourceBufferCount
= 0;
105 int wxResourceStringPtr
= 0;
107 void wxInitializeResourceSystem()
109 wxDefaultResourceTable
= new wxResourceTable
;
112 void wxCleanUpResourceSystem()
114 delete wxDefaultResourceTable
;
115 if (wxResourceBuffer
)
116 delete[] wxResourceBuffer
;
119 void wxLogWarning(char *msg
)
121 wxMessageBox(msg
, _("Warning"), wxOK
);
124 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
125 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
127 wxItemResource::wxItemResource()
133 m_x
= m_y
= m_width
= m_height
= 0;
134 m_value1
= m_value2
= m_value3
= m_value5
= 0;
140 wxItemResource::~wxItemResource()
142 wxNode
*node
= m_children
.First();
145 wxItemResource
*item
= (wxItemResource
*)node
->Data();
148 node
= m_children
.First();
156 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
160 wxResourceTable::~wxResourceTable()
165 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
167 wxItemResource
*item
= (wxItemResource
*)Get(WXSTRINGCAST name
);
171 void wxResourceTable::AddResource(wxItemResource
*item
)
173 wxString name
= item
->GetName();
175 name
= item
->GetTitle();
177 name
= wxT("no name");
179 // Delete existing resource, if any.
185 bool wxResourceTable::DeleteResource(const wxString
& name
)
187 wxItemResource
*item
= (wxItemResource
*)Delete(WXSTRINGCAST name
);
190 // See if any resource has this as its child; if so, delete from
191 // parent's child list.
193 wxNode
*node
= (wxNode
*) NULL
;
197 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
198 if (parent
->GetChildren().Member(item
))
200 parent
->GetChildren().DeleteObject(item
);
213 bool wxResourceTable::ParseResourceFile( wxInputStream
*is
)
216 int len
= is
->StreamSize() ;
219 while ( is
->TellI() + 10 < len
) // it's a hack because the streams dont support EOF
221 wxResourceReadOneResource(is
, db
, &eof
, this) ;
223 return wxResourceInterpretResources(*this, db
);
226 bool wxResourceTable::ParseResourceFile(const wxString
& filename
)
230 FILE *fd
= wxFopen(filename
, _T("r"));
234 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
239 return wxResourceInterpretResources(*this, db
);
242 bool wxResourceTable::ParseResourceData(const wxString
& data
)
245 if (!db
.ReadFromString(data
))
247 wxLogWarning(_("Ill-formed resource file syntax."));
251 return wxResourceInterpretResources(*this, db
);
254 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char bits
[], int width
, int height
)
256 // Register pre-loaded bitmap data
257 wxItemResource
*item
= new wxItemResource
;
258 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
259 item
->SetType(wxT("wxXBMData"));
261 item
->SetValue1((long)bits
);
262 item
->SetValue2((long)width
);
263 item
->SetValue3((long)height
);
268 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char **data
)
270 // Register pre-loaded bitmap data
271 wxItemResource
*item
= new wxItemResource
;
272 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
273 item
->SetType(wxT("wxXPMData"));
275 item
->SetValue1((long)data
);
280 bool wxResourceTable::SaveResource(const wxString
& WXUNUSED(filename
))
285 void wxResourceTable::ClearTable()
288 wxNode
*node
= Next();
291 wxNode
*next
= Next();
292 wxItemResource
*item
= (wxItemResource
*)node
->Data();
299 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, const wxItemResource
* childResource
, const wxItemResource
* parentResource
) const
301 int id
= childResource
->GetId();
305 bool dlgUnits
= ((parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0);
307 wxControl
*control
= (wxControl
*) NULL
;
308 wxString
itemType(childResource
->GetType());
314 pos
= parent
->ConvertDialogToPixels(wxPoint(childResource
->GetX(), childResource
->GetY()));
315 size
= parent
->ConvertDialogToPixels(wxSize(childResource
->GetWidth(), childResource
->GetHeight()));
319 pos
= wxPoint(childResource
->GetX(), childResource
->GetY());
320 size
= wxSize(childResource
->GetWidth(), childResource
->GetHeight());
323 if (itemType
== wxString(wxT("wxButton")) || itemType
== wxString(wxT("wxBitmapButton")))
325 if (childResource
->GetValue4() != wxT(""))
328 wxBitmap bitmap
= childResource
->GetBitmap();
331 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
332 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
335 bitmap
.LoadFile("cross_bmp", wxBITMAP_TYPE_BMP_RESOURCE
);
336 control
= new wxBitmapButton(parent
, id
, bitmap
, pos
, size
,
337 childResource
->GetStyle() | wxBU_AUTODRAW
, wxDefaultValidator
, childResource
->GetName());
340 // Normal, text button
341 control
= new wxButton(parent
, id
, childResource
->GetTitle(), pos
, size
,
342 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
344 else if (itemType
== wxString(wxT("wxMessage")) || itemType
== wxString(wxT("wxStaticText")) ||
345 itemType
== wxString(wxT("wxStaticBitmap")))
347 if (childResource
->GetValue4() != wxT("") || itemType
== wxString(wxT("wxStaticBitmap")) )
350 wxBitmap bitmap
= childResource
->GetBitmap();
353 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
354 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
356 #if wxUSE_BITMAP_MESSAGE
358 // Use a default bitmap
360 bitmap
.LoadFile("cross_bmp", wxBITMAP_TYPE_BMP_RESOURCE
);
364 control
= new wxStaticBitmap(parent
, id
, bitmap
, pos
, size
,
365 childResource
->GetStyle(), childResource
->GetName());
370 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(), pos
, size
,
371 childResource
->GetStyle(), childResource
->GetName());
374 else if (itemType
== wxString(wxT("wxText")) || itemType
== wxString(wxT("wxTextCtrl")) || itemType
== wxString(wxT("wxMultiText")))
376 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), pos
, size
,
377 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
379 else if (itemType
== wxString(wxT("wxCheckBox")))
381 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
382 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
384 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
387 else if (itemType
== wxString(wxT("wxGauge")))
389 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(), pos
, size
,
390 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
392 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
396 else if (itemType
== wxString(wxT("wxRadioButton")))
398 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
400 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
404 else if (itemType
== wxString(wxT("wxScrollBar")))
406 control
= new wxScrollBar(parent
, id
, pos
, size
,
407 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
409 ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1());
410 ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2());
411 ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3());
412 ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5());
414 ((wxScrollBar
*)control
)->SetScrollbar((int)childResource
->GetValue1(),(int)childResource
->GetValue2(),
415 (int)childResource
->GetValue3(),(int)(long)childResource
->GetValue5(),FALSE
);
419 else if (itemType
== wxString(wxT("wxSlider")))
421 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
422 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), pos
, size
,
423 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
425 else if (itemType
== wxString(wxT("wxGroupBox")) || itemType
== wxString(wxT("wxStaticBox")))
427 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
428 childResource
->GetStyle(), childResource
->GetName());
430 else if (itemType
== wxString(wxT("wxListBox")))
432 wxStringList
& stringList
= childResource
->GetStringValues();
433 wxString
*strings
= (wxString
*) NULL
;
435 if (stringList
.Number() > 0)
437 noStrings
= stringList
.Number();
438 strings
= new wxString
[noStrings
];
439 wxNode
*node
= stringList
.First();
443 strings
[i
] = (wxChar
*)node
->Data();
448 control
= new wxListBox(parent
, id
, pos
, size
,
449 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
454 else if (itemType
== wxString(wxT("wxChoice")))
456 wxStringList
& stringList
= childResource
->GetStringValues();
457 wxString
*strings
= (wxString
*) NULL
;
459 if (stringList
.Number() > 0)
461 noStrings
= stringList
.Number();
462 strings
= new wxString
[noStrings
];
463 wxNode
*node
= stringList
.First();
467 strings
[i
] = (wxChar
*)node
->Data();
472 control
= new wxChoice(parent
, id
, pos
, size
,
473 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
479 else if (itemType
== wxString(wxT("wxComboBox")))
481 wxStringList
& stringList
= childResource
->GetStringValues();
482 wxString
*strings
= (wxString
*) NULL
;
484 if (stringList
.Number() > 0)
486 noStrings
= stringList
.Number();
487 strings
= new wxString
[noStrings
];
488 wxNode
*node
= stringList
.First();
492 strings
[i
] = (wxChar
*)node
->Data();
497 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(), pos
, size
,
498 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
504 else if (itemType
== wxString(wxT("wxRadioBox")))
506 wxStringList
& stringList
= childResource
->GetStringValues();
507 wxString
*strings
= (wxString
*) NULL
;
509 if (stringList
.Number() > 0)
511 noStrings
= stringList
.Number();
512 strings
= new wxString
[noStrings
];
513 wxNode
*node
= stringList
.First();
517 strings
[i
] = (wxChar
*)node
->Data();
522 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), pos
, size
,
523 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
524 childResource
->GetName());
530 if ((parentResource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
532 // Don't set font; will be inherited from parent.
536 if (control
&& childResource
->GetFont().Ok())
538 control
->SetFont(childResource
->GetFont());
541 // Force the layout algorithm since the size changes the layout
542 if (control
->IsKindOf(CLASSINFO(wxRadioBox
)))
544 control
->SetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
|wxSIZE_AUTO_HEIGHT
);
553 * Interpret database as a series of resources
556 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
)
558 wxNode
*node
= db
.First();
561 wxExpr
*clause
= (wxExpr
*)node
->Data();
562 wxString
functor(clause
->Functor());
564 wxItemResource
*item
= (wxItemResource
*) NULL
;
565 if (functor
== wxT("dialog"))
566 item
= wxResourceInterpretDialog(table
, clause
);
567 else if (functor
== wxT("panel"))
568 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
569 else if (functor
== wxT("menubar"))
570 item
= wxResourceInterpretMenuBar(table
, clause
);
571 else if (functor
== wxT("menu"))
572 item
= wxResourceInterpretMenu(table
, clause
);
573 else if (functor
== wxT("string"))
574 item
= wxResourceInterpretString(table
, clause
);
575 else if (functor
== wxT("bitmap"))
576 item
= wxResourceInterpretBitmap(table
, clause
);
577 else if (functor
== wxT("icon"))
578 item
= wxResourceInterpretIcon(table
, clause
);
582 // Remove any existing resource of same name
583 if (item
->GetName() != wxT(""))
584 table
.DeleteResource(item
->GetName());
585 table
.AddResource(item
);
592 static const wxChar
*g_ValidControlClasses
[] =
595 wxT("wxBitmapButton"),
598 wxT("wxStaticBitmap"),
604 wxT("wxRadioButton"),
606 wxT("wxBitmapCheckBox"),
616 static bool wxIsValidControlClass(const wxString
& c
)
618 for ( size_t i
= 0; i
< WXSIZEOF(g_ValidControlClasses
); i
++ )
620 if ( c
== g_ValidControlClasses
[i
] )
626 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
628 wxItemResource
*dialogItem
= new wxItemResource
;
630 dialogItem
->SetType(wxT("wxPanel"));
632 dialogItem
->SetType(wxT("wxDialog"));
633 wxString style
= wxT("");
634 wxString title
= wxT("");
635 wxString name
= wxT("");
636 wxString backColourHex
= wxT("");
637 wxString labelColourHex
= wxT("");
638 wxString buttonColourHex
= wxT("");
640 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
644 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
646 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
647 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
648 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
649 expr
->GetAttributeValue(wxT("style"), style
);
650 expr
->GetAttributeValue(wxT("name"), name
);
651 expr
->GetAttributeValue(wxT("title"), title
);
652 expr
->GetAttributeValue(wxT("x"), x
);
653 expr
->GetAttributeValue(wxT("y"), y
);
654 expr
->GetAttributeValue(wxT("width"), width
);
655 expr
->GetAttributeValue(wxT("height"), height
);
656 expr
->GetAttributeValue(wxT("modal"), isModal
);
657 expr
->GetAttributeValue(wxT("label_font"), &labelFontExpr
);
658 expr
->GetAttributeValue(wxT("button_font"), &buttonFontExpr
);
659 expr
->GetAttributeValue(wxT("font"), &fontExpr
);
660 expr
->GetAttributeValue(wxT("background_colour"), backColourHex
);
661 expr
->GetAttributeValue(wxT("label_colour"), labelColourHex
);
662 expr
->GetAttributeValue(wxT("button_colour"), buttonColourHex
);
664 int useDialogUnits
= 0;
665 expr
->GetAttributeValue(wxT("use_dialog_units"), useDialogUnits
);
666 if (useDialogUnits
!= 0)
667 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
670 expr
->GetAttributeValue(wxT("use_system_defaults"), useDefaults
);
671 if (useDefaults
!= 0)
672 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
675 expr
->GetAttributeValue(wxT("id"), id
);
676 dialogItem
->SetId(id
);
678 if (style
!= wxT(""))
680 windowStyle
= wxParseWindowStyle(style
);
682 dialogItem
->SetStyle(windowStyle
);
683 dialogItem
->SetValue1(isModal
);
684 if (windowStyle
& wxDIALOG_MODAL
) // Uses style in wxWin 2
685 dialogItem
->SetValue1(TRUE
);
687 dialogItem
->SetName(name
);
688 dialogItem
->SetTitle(title
);
689 dialogItem
->SetSize(x
, y
, width
, height
);
691 // Check for wxWin 1.68-style specifications
692 if (style
.Find(wxT("VERTICAL_LABEL")) != -1)
693 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
694 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != -1)
695 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
697 if (backColourHex
!= wxT(""))
702 r
= wxHexToDec(backColourHex
.Mid(0, 2));
703 g
= wxHexToDec(backColourHex
.Mid(2, 2));
704 b
= wxHexToDec(backColourHex
.Mid(4, 2));
705 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
707 if (labelColourHex
!= wxT(""))
712 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
713 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
714 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
715 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
717 if (buttonColourHex
!= wxT(""))
722 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
723 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
724 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
725 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
729 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
730 else if (buttonFontExpr
)
731 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
732 else if (labelFontExpr
)
733 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
735 // Now parse all controls
736 wxExpr
*controlExpr
= expr
->GetFirst();
739 if (controlExpr
->Number() == 3)
741 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
742 if (controlKeyword
!= wxT("") && controlKeyword
== wxT("control"))
744 // The value part: always a list.
745 wxExpr
*listExpr
= controlExpr
->Nth(2);
746 if (listExpr
->Type() == PrologList
)
748 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
751 dialogItem
->GetChildren().Append(controlItem
);
756 controlExpr
= controlExpr
->GetNext();
761 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
763 wxItemResource
*controlItem
= new wxItemResource
;
765 // First, find the standard features of a control definition:
766 // [optional integer/string id], control name, title, style, name, x, y, width, height
768 wxString controlType
;
773 long windowStyle
= 0;
774 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
777 wxExpr
*expr1
= expr
->Nth(0);
779 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
781 if ( wxIsValidControlClass(expr1
->StringValue()) )
784 controlType
= expr1
->StringValue();
788 wxString
str(expr1
->StringValue());
789 id
= wxResourceGetIdentifier(str
, &table
);
792 wxLogWarning(_("Could not resolve control class or id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)"),
793 (const wxChar
*) expr1
->StringValue());
795 return (wxItemResource
*) NULL
;
799 // Success - we have an id, so the 2nd element must be the control class.
800 controlType
= expr
->Nth(1)->StringValue();
805 else if (expr1
->Type() == PrologInteger
)
807 id
= (int)expr1
->IntegerValue();
808 // Success - we have an id, so the 2nd element must be the control class.
809 controlType
= expr
->Nth(1)->StringValue();
813 expr1
= expr
->Nth(count
);
816 title
= expr1
->StringValue();
818 expr1
= expr
->Nth(count
);
822 style
= expr1
->StringValue();
823 windowStyle
= wxParseWindowStyle(style
);
826 expr1
= expr
->Nth(count
);
829 name
= expr1
->StringValue();
831 expr1
= expr
->Nth(count
);
834 x
= (int)expr1
->IntegerValue();
836 expr1
= expr
->Nth(count
);
839 y
= (int)expr1
->IntegerValue();
841 expr1
= expr
->Nth(count
);
844 width
= (int)expr1
->IntegerValue();
846 expr1
= expr
->Nth(count
);
849 height
= (int)expr1
->IntegerValue();
851 controlItem
->SetStyle(windowStyle
);
852 controlItem
->SetName(name
);
853 controlItem
->SetTitle(title
);
854 controlItem
->SetSize(x
, y
, width
, height
);
855 controlItem
->SetType(controlType
);
856 controlItem
->SetId(id
);
858 // Check for wxWin 1.68-style specifications
859 if (style
.Find(wxT("VERTICAL_LABEL")) != -1)
860 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
861 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != -1)
862 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
864 if (controlType
== wxT("wxButton"))
866 // Check for bitmap resource name (in case loading old-style resource file)
867 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
869 wxString
str(expr
->Nth(count
)->StringValue());
874 controlItem
->SetValue4(str
);
875 controlItem
->SetType(wxT("wxBitmapButton"));
878 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
879 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
881 else if (controlType
== wxT("wxBitmapButton"))
883 // Check for bitmap resource name
884 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
886 wxString
str(expr
->Nth(count
)->StringValue());
887 controlItem
->SetValue4(str
);
889 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
890 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
893 else if (controlType
== wxT("wxCheckBox"))
895 // Check for default value
896 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
898 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
900 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
901 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
905 else if (controlType
== wxT("wxRadioButton"))
907 // Check for default value
908 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
910 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
912 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
913 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
917 else if (controlType
== wxT("wxText") || controlType
== wxT("wxTextCtrl") || controlType
== wxT("wxMultiText"))
919 // Check for default value
920 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
922 wxString
str(expr
->Nth(count
)->StringValue());
923 controlItem
->SetValue4(str
);
926 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
928 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
929 // Skip past the obsolete label font spec if there are two consecutive specs
930 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
932 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
936 else if (controlType
== wxT("wxMessage") || controlType
== wxT("wxStaticText"))
938 // Check for bitmap resource name (in case it's an old-style .wxr file)
939 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
941 wxString
str(expr
->Nth(count
)->StringValue());
942 controlItem
->SetValue4(str
);
944 controlItem
->SetType(wxT("wxStaticText"));
946 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
947 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
949 else if (controlType
== wxT("wxStaticBitmap"))
951 // Check for bitmap resource name
952 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
954 wxString
str(expr
->Nth(count
)->StringValue());
955 controlItem
->SetValue4(str
);
958 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
959 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
961 else if (controlType
== wxT("wxGroupBox") || controlType
== wxT("wxStaticBox"))
963 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
964 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
966 else if (controlType
== wxT("wxGauge"))
968 // Check for default value
969 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
971 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
975 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
977 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
980 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
982 // Skip past the obsolete label font spec if there are two consecutive specs
983 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
985 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
990 else if (controlType
== wxT("wxSlider"))
992 // Check for default value
993 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
995 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
999 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1001 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1005 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1007 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1010 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1012 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1016 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1017 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1023 else if (controlType
== wxT("wxScrollBar"))
1026 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1028 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1032 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1034 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1038 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1040 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1044 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1045 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1050 else if (controlType
== wxT("wxListBox"))
1052 wxExpr
*valueList
= (wxExpr
*) NULL
;
1054 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1056 wxStringList stringList
;
1057 wxExpr
*stringExpr
= valueList
->GetFirst();
1060 stringList
.Add(stringExpr
->StringValue());
1061 stringExpr
= stringExpr
->GetNext();
1063 controlItem
->SetStringValues(stringList
);
1065 // This is now obsolete: it's in the window style.
1066 // Check for wxSINGLE/wxMULTIPLE
1067 wxExpr
*mult
= (wxExpr
*) NULL
;
1069 controlItem->SetValue1(wxLB_SINGLE);
1071 if (((mult
= expr
->Nth(count
)) != 0) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1074 wxString m(mult->StringValue());
1075 if (m == "wxLB_MULTIPLE")
1076 controlItem->SetValue1(wxLB_MULTIPLE);
1077 else if (m == "wxLB_EXTENDED")
1078 controlItem->SetValue1(wxLB_EXTENDED);
1083 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1085 // Skip past the obsolete label font spec if there are two consecutive specs
1086 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1088 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1092 else if (controlType
== wxT("wxChoice"))
1094 wxExpr
*valueList
= (wxExpr
*) NULL
;
1095 // Check for default value list
1096 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1098 wxStringList stringList
;
1099 wxExpr
*stringExpr
= valueList
->GetFirst();
1102 stringList
.Add(stringExpr
->StringValue());
1103 stringExpr
= stringExpr
->GetNext();
1105 controlItem
->SetStringValues(stringList
);
1109 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1111 // Skip past the obsolete label font spec if there are two consecutive specs
1112 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1114 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1119 else if (controlType
== wxT("wxComboBox"))
1121 wxExpr
*textValue
= expr
->Nth(count
);
1122 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1124 wxString
str(textValue
->StringValue());
1125 controlItem
->SetValue4(str
);
1129 wxExpr
*valueList
= (wxExpr
*) NULL
;
1130 // Check for default value list
1131 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1133 wxStringList stringList
;
1134 wxExpr
*stringExpr
= valueList
->GetFirst();
1137 stringList
.Add(stringExpr
->StringValue());
1138 stringExpr
= stringExpr
->GetNext();
1140 controlItem
->SetStringValues(stringList
);
1144 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1146 // Skip past the obsolete label font spec if there are two consecutive specs
1147 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1149 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1156 else if (controlType
== wxT("wxRadioBox"))
1158 wxExpr
*valueList
= (wxExpr
*) NULL
;
1159 // Check for default value list
1160 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1162 wxStringList stringList
;
1163 wxExpr
*stringExpr
= valueList
->GetFirst();
1166 stringList
.Add(stringExpr
->StringValue());
1167 stringExpr
= stringExpr
->GetNext();
1169 controlItem
->SetStringValues(stringList
);
1172 // majorDim (number of rows or cols)
1173 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1175 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1179 controlItem
->SetValue1(0);
1181 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1183 // Skip past the obsolete label font spec if there are two consecutive specs
1184 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1186 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1194 return (wxItemResource
*) NULL
;
1199 // Forward declaration
1200 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1203 * Interpet a menu item
1206 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1208 wxItemResource
*item
= new wxItemResource
;
1210 wxExpr
*labelExpr
= expr
->Nth(0);
1211 wxExpr
*idExpr
= expr
->Nth(1);
1212 wxExpr
*helpExpr
= expr
->Nth(2);
1213 wxExpr
*checkableExpr
= expr
->Nth(3);
1215 // Further keywords/attributes to follow sometime...
1216 if (expr
->Number() == 0)
1218 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1219 item
->SetType(wxT("wxMenuSeparator"));
1224 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1225 item
->SetType(wxT("wxMenu")); // Well, menu item, but doesn't matter.
1228 wxString
str(labelExpr
->StringValue());
1229 item
->SetTitle(str
);
1234 // If a string or word, must look up in identifier table.
1235 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1237 wxString
str(idExpr
->StringValue());
1238 id
= wxResourceGetIdentifier(str
, &table
);
1241 wxLogWarning(_("Could not resolve menu id '%s'. Use (non-zero) integer instead\nor provide #define (see manual for caveats)"),
1242 (const wxChar
*) idExpr
->StringValue());
1245 else if (idExpr
->Type() == PrologInteger
)
1246 id
= (int)idExpr
->IntegerValue();
1247 item
->SetValue1(id
);
1251 wxString
str(helpExpr
->StringValue());
1252 item
->SetValue4(str
);
1255 item
->SetValue2(checkableExpr
->IntegerValue());
1257 // Find the first expression that's a list, for submenu
1258 wxExpr
*subMenuExpr
= expr
->GetFirst();
1259 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1260 subMenuExpr
= subMenuExpr
->GetNext();
1264 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1265 item
->GetChildren().Append(child
);
1266 subMenuExpr
= subMenuExpr
->GetNext();
1273 * Interpret a nested list as a menu
1276 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1278 wxItemResource *menu = new wxItemResource;
1279 // menu->SetType(wxTYPE_MENU);
1280 menu->SetType("wxMenu");
1281 wxExpr *element = expr->GetFirst();
1284 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1286 menu->GetChildren().Append(item);
1287 element = element->GetNext();
1293 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1295 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1296 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1298 return (wxItemResource
*) NULL
;
1300 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1303 return (wxItemResource
*) NULL
;
1306 if (expr
->GetAttributeValue(wxT("name"), name
))
1308 menuResource
->SetName(name
);
1311 return menuResource
;
1314 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1316 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1317 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1319 return (wxItemResource
*) NULL
;
1321 wxItemResource
*resource
= new wxItemResource
;
1322 resource
->SetType(wxT("wxMenu"));
1323 // resource->SetType(wxTYPE_MENU);
1325 wxExpr
*element
= listExpr
->GetFirst();
1328 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1329 resource
->GetChildren().Append(menuResource
);
1330 element
= element
->GetNext();
1334 if (expr
->GetAttributeValue(wxT("name"), name
))
1336 resource
->SetName(name
);
1342 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1344 return (wxItemResource
*) NULL
;
1347 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1349 wxItemResource
*bitmapItem
= new wxItemResource
;
1350 // bitmapItem->SetType(wxTYPE_BITMAP);
1351 bitmapItem
->SetType(wxT("wxBitmap"));
1353 if (expr
->GetAttributeValue(wxT("name"), name
))
1355 bitmapItem
->SetName(name
);
1357 // Now parse all bitmap specifications
1358 wxExpr
*bitmapExpr
= expr
->GetFirst();
1361 if (bitmapExpr
->Number() == 3)
1363 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1364 if (bitmapKeyword
== wxT("bitmap") || bitmapKeyword
== wxT("icon"))
1366 // The value part: always a list.
1367 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1368 if (listExpr
->Type() == PrologList
)
1370 wxItemResource
*bitmapSpec
= new wxItemResource
;
1371 // bitmapSpec->SetType(wxTYPE_BITMAP);
1372 bitmapSpec
->SetType(wxT("wxBitmap"));
1374 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1375 // where everything after 'filename' is optional.
1376 wxExpr
*nameExpr
= listExpr
->Nth(0);
1377 wxExpr
*typeExpr
= listExpr
->Nth(1);
1378 wxExpr
*platformExpr
= listExpr
->Nth(2);
1379 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1380 wxExpr
*xresExpr
= listExpr
->Nth(4);
1381 wxExpr
*yresExpr
= listExpr
->Nth(5);
1382 if (nameExpr
&& nameExpr
->StringValue() != wxT(""))
1384 bitmapSpec
->SetName(nameExpr
->StringValue());
1386 if (typeExpr
&& typeExpr
->StringValue() != wxT(""))
1388 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1391 bitmapSpec
->SetValue1(0);
1393 if (platformExpr
&& platformExpr
->StringValue() != wxT(""))
1395 wxString
plat(platformExpr
->StringValue());
1396 if (plat
== wxT("windows") || plat
== wxT("WINDOWS"))
1397 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1398 else if (plat
== wxT("x") || plat
== wxT("X"))
1399 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1400 else if (plat
== wxT("mac") || plat
== wxT("MAC"))
1401 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1403 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1406 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1409 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1413 xres
= (int)xresExpr
->IntegerValue();
1415 yres
= (int)yresExpr
->IntegerValue();
1416 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1418 bitmapItem
->GetChildren().Append(bitmapSpec
);
1422 bitmapExpr
= bitmapExpr
->GetNext();
1428 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1430 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1433 // item->SetType(wxTYPE_ICON);
1434 item
->SetType(wxT("wxIcon"));
1438 return (wxItemResource
*) NULL
;
1441 // Interpret list expression as a font
1442 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1444 if (expr
->Type() != PrologList
)
1448 int family
= wxSWISS
;
1449 int style
= wxNORMAL
;
1450 int weight
= wxNORMAL
;
1452 wxString
faceName(wxT(""));
1454 wxExpr
*pointExpr
= expr
->Nth(0);
1455 wxExpr
*familyExpr
= expr
->Nth(1);
1456 wxExpr
*styleExpr
= expr
->Nth(2);
1457 wxExpr
*weightExpr
= expr
->Nth(3);
1458 wxExpr
*underlineExpr
= expr
->Nth(4);
1459 wxExpr
*faceNameExpr
= expr
->Nth(5);
1461 point
= (int)pointExpr
->IntegerValue();
1466 str
= familyExpr
->StringValue();
1467 family
= (int)wxParseWindowStyle(str
);
1471 str
= styleExpr
->StringValue();
1472 style
= (int)wxParseWindowStyle(str
);
1476 str
= weightExpr
->StringValue();
1477 weight
= (int)wxParseWindowStyle(str
);
1480 underline
= (int)underlineExpr
->IntegerValue();
1482 faceName
= faceNameExpr
->StringValue();
1484 wxFont
font(point
, family
, style
, weight
, (underline
!= 0), faceName
);
1488 // Separate file for the remainder of this, for BC++/Win16
1490 #if !((defined(__BORLANDC__) || defined(__SC__)) && defined(__WIN16__))
1492 * (Re)allocate buffer for reading in from resource file
1495 bool wxReallocateResourceBuffer()
1497 if (!wxResourceBuffer
)
1499 wxResourceBufferSize
= 1000;
1500 wxResourceBuffer
= new char[wxResourceBufferSize
];
1503 if (wxResourceBuffer
)
1505 long newSize
= wxResourceBufferSize
+ 1000;
1506 char *tmp
= new char[(int)newSize
];
1507 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1508 delete[] wxResourceBuffer
;
1509 wxResourceBuffer
= tmp
;
1510 wxResourceBufferSize
= newSize
;
1515 static bool wxEatWhiteSpace(FILE *fd
)
1519 while ((ch
= getc(fd
)) != EOF
)
1534 ungetc(prev_ch
, fd
);
1542 while ((ch
= getc(fd
)) != EOF
)
1544 if (ch
== '/' && prev_ch
== '*')
1552 static char buffer
[255];
1553 fgets(buffer
, 255, fd
);
1557 ungetc(prev_ch
, fd
);
1571 static bool wxEatWhiteSpace(wxInputStream
*is
)
1573 int ch
= is
->GetC() ;
1574 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1581 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1583 // Check for comment
1589 bool finished
= FALSE
;
1597 int newCh
= is
->GetC();
1612 return wxEatWhiteSpace(is
);
1615 bool wxGetResourceToken(FILE *fd
)
1617 if (!wxResourceBuffer
)
1618 wxReallocateResourceBuffer();
1619 wxResourceBuffer
[0] = 0;
1620 wxEatWhiteSpace(fd
);
1626 wxResourceBufferCount
= 0;
1633 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1636 // Escaped characters
1637 else if (ch
== '\\')
1639 int newCh
= getc(fd
);
1642 else if (newCh
== 10)
1650 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1651 wxReallocateResourceBuffer();
1652 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1653 wxResourceBufferCount
++;
1656 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1660 wxResourceBufferCount
= 0;
1662 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1664 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1665 wxReallocateResourceBuffer();
1666 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1667 wxResourceBufferCount
++;
1671 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1678 bool wxGetResourceToken(wxInputStream
*is
)
1680 if (!wxResourceBuffer
)
1681 wxReallocateResourceBuffer();
1682 wxResourceBuffer
[0] = 0;
1683 wxEatWhiteSpace(is
);
1685 int ch
= is
->GetC() ;
1689 wxResourceBufferCount
= 0;
1696 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1699 // Escaped characters
1700 else if (ch
== '\\')
1702 int newCh
= is
->GetC();
1705 else if (newCh
== 10)
1707 else if (newCh
== 13) // mac
1715 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1716 wxReallocateResourceBuffer();
1717 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1718 wxResourceBufferCount
++;
1721 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1725 wxResourceBufferCount
= 0;
1727 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1729 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1730 wxReallocateResourceBuffer();
1731 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1732 wxResourceBufferCount
++;
1736 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1744 * Files are in form:
1745 static char *name = "....";
1746 with possible comments.
1749 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1752 table
= wxDefaultResourceTable
;
1754 // static or #define
1755 if (!wxGetResourceToken(fd
))
1761 if (strcmp(wxResourceBuffer
, "#define") == 0)
1763 wxGetResourceToken(fd
);
1764 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1765 wxGetResourceToken(fd
);
1766 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1767 if (wxIsdigit(value
[0]))
1769 int val
= (int)wxAtol(value
);
1770 wxResourceAddIdentifier(name
, val
, table
);
1774 wxLogWarning(_("#define %s must be an integer."), name
);
1784 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1786 wxGetResourceToken(fd
);
1787 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1788 wxChar
*actualName
= name
;
1789 if (name
[0] == wxT('"'))
1790 actualName
= name
+ 1;
1791 int len
= wxStrlen(name
);
1792 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1794 if (!wxResourceParseIncludeFile(actualName
, table
))
1796 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1801 else if (strcmp(wxResourceBuffer
, "static") != 0)
1804 wxStrcpy(buf
, _("Found "));
1805 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
1806 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1812 if (!wxGetResourceToken(fd
))
1814 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1819 if (strcmp(wxResourceBuffer
, "char") != 0)
1821 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1826 if (!wxGetResourceToken(fd
))
1828 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1833 if (wxResourceBuffer
[0] != '*')
1835 wxLogWarning(_("Expected '*' whilst parsing resource."));
1838 wxChar nameBuf
[100];
1839 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
1843 if (!wxGetResourceToken(fd
))
1845 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1850 if (strcmp(wxResourceBuffer
, "=") != 0)
1852 wxLogWarning(_("Expected '=' whilst parsing resource."));
1857 if (!wxGetResourceToken(fd
))
1859 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1865 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1867 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1872 if (!wxGetResourceToken(fd
))
1879 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1882 table
= wxDefaultResourceTable
;
1884 // static or #define
1885 if (!wxGetResourceToken(fd
))
1891 if (strcmp(wxResourceBuffer
, "#define") == 0)
1893 wxGetResourceToken(fd
);
1894 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1895 wxGetResourceToken(fd
);
1896 wxChar
*value
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1897 if (wxIsalpha(value
[0]))
1899 int val
= (int)wxAtol(value
);
1900 wxResourceAddIdentifier(name
, val
, table
);
1904 wxLogWarning(_("#define %s must be an integer."), name
);
1914 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1916 wxGetResourceToken(fd
);
1917 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1918 wxChar
*actualName
= name
;
1919 if (name
[0] == wxT('"'))
1920 actualName
= name
+ 1;
1921 int len
= wxStrlen(name
);
1922 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1924 if (!wxResourceParseIncludeFile(actualName
, table
))
1926 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1931 else if (strcmp(wxResourceBuffer
, "static") != 0)
1934 wxStrcpy(buf
, _("Found "));
1935 wxStrncat(buf
, wxConvLibc
.cMB2WX(wxResourceBuffer
), 30);
1936 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1942 if (!wxGetResourceToken(fd
))
1944 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1949 if (strcmp(wxResourceBuffer
, "char") != 0)
1951 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1956 if (!wxGetResourceToken(fd
))
1958 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1963 if (wxResourceBuffer
[0] != '*')
1965 wxLogWarning(_("Expected '*' whilst parsing resource."));
1969 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
1972 if (!wxGetResourceToken(fd
))
1974 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1979 if (strcmp(wxResourceBuffer
, "=") != 0)
1981 wxLogWarning(_("Expected '=' whilst parsing resource."));
1986 if (!wxGetResourceToken(fd
))
1988 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1994 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1996 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2001 if (!wxGetResourceToken(fd
))
2009 * Parses string window style into integer window style
2013 * Style flag parsing, e.g.
2014 * "wxSYSTEM_MENU | wxBORDER" -> integer
2017 wxChar
* wxResourceParseWord(wxChar
*s
, int *i
)
2020 return (wxChar
*) NULL
;
2022 static wxChar buf
[150];
2023 int len
= wxStrlen(s
);
2026 while ((ii
< len
) && (wxIsalpha(s
[ii
]) || (s
[ii
] == wxT('_'))))
2034 // Eat whitespace and conjunction characters
2035 while ((ii
< len
) &&
2036 ((s
[ii
] == wxT(' ')) || (s
[ii
] == wxT('|')) || (s
[ii
] == wxT(','))))
2042 return (wxChar
*) NULL
;
2047 struct wxResourceBitListStruct
2053 static wxResourceBitListStruct wxResourceBitListTable
[] =
2056 { wxT("wxSINGLE"), wxLB_SINGLE
},
2057 { wxT("wxMULTIPLE"), wxLB_MULTIPLE
},
2058 { wxT("wxEXTENDED"), wxLB_EXTENDED
},
2059 { wxT("wxLB_SINGLE"), wxLB_SINGLE
},
2060 { wxT("wxLB_MULTIPLE"), wxLB_MULTIPLE
},
2061 { wxT("wxLB_EXTENDED"), wxLB_EXTENDED
},
2062 { wxT("wxLB_NEEDED_SB"), wxLB_NEEDED_SB
},
2063 { wxT("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB
},
2064 { wxT("wxLB_SORT"), wxLB_SORT
},
2065 { wxT("wxLB_OWNERDRAW"), wxLB_OWNERDRAW
},
2066 { wxT("wxLB_HSCROLL"), wxLB_HSCROLL
},
2069 { wxT("wxCB_SIMPLE"), wxCB_SIMPLE
},
2070 { wxT("wxCB_DROPDOWN"), wxCB_DROPDOWN
},
2071 { wxT("wxCB_READONLY"), wxCB_READONLY
},
2072 { wxT("wxCB_SORT"), wxCB_SORT
},
2075 { wxT("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR
},
2076 { wxT("wxGA_HORIZONTAL"), wxGA_HORIZONTAL
},
2077 { wxT("wxGA_VERTICAL"), wxGA_VERTICAL
},
2080 { wxT("wxPASSWORD"), wxPASSWORD
},
2081 { wxT("wxPROCESS_ENTER"), wxPROCESS_ENTER
},
2082 { wxT("wxTE_PASSWORD"), wxTE_PASSWORD
},
2083 { wxT("wxTE_READONLY"), wxTE_READONLY
},
2084 { wxT("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER
},
2085 { wxT("wxTE_MULTILINE"), wxTE_MULTILINE
},
2086 { wxT("wxTE_NO_VSCROLL"), wxTE_NO_VSCROLL
},
2088 /* wxRadioBox/wxRadioButton */
2089 { wxT("wxRB_GROUP"), wxRB_GROUP
},
2090 { wxT("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS
},
2091 { wxT("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS
},
2092 { wxT("wxRA_HORIZONTAL"), wxRA_HORIZONTAL
},
2093 { wxT("wxRA_VERTICAL"), wxRA_VERTICAL
},
2096 { wxT("wxSL_HORIZONTAL"), wxSL_HORIZONTAL
},
2097 { wxT("wxSL_VERTICAL"), wxSL_VERTICAL
},
2098 { wxT("wxSL_AUTOTICKS"), wxSL_AUTOTICKS
},
2099 { wxT("wxSL_LABELS"), wxSL_LABELS
},
2100 { wxT("wxSL_LEFT"), wxSL_LEFT
},
2101 { wxT("wxSL_TOP"), wxSL_TOP
},
2102 { wxT("wxSL_RIGHT"), wxSL_RIGHT
},
2103 { wxT("wxSL_BOTTOM"), wxSL_BOTTOM
},
2104 { wxT("wxSL_BOTH"), wxSL_BOTH
},
2105 { wxT("wxSL_SELRANGE"), wxSL_SELRANGE
},
2108 { wxT("wxSB_HORIZONTAL"), wxSB_HORIZONTAL
},
2109 { wxT("wxSB_VERTICAL"), wxSB_VERTICAL
},
2112 { wxT("wxBU_AUTODRAW"), wxBU_AUTODRAW
},
2113 { wxT("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW
},
2116 { wxT("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS
},
2117 { wxT("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS
},
2118 { wxT("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT
},
2121 { wxT("wxLC_ICON"), wxLC_ICON
},
2122 { wxT("wxLC_SMALL_ICON"), wxLC_SMALL_ICON
},
2123 { wxT("wxLC_LIST"), wxLC_LIST
},
2124 { wxT("wxLC_REPORT"), wxLC_REPORT
},
2125 { wxT("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP
},
2126 { wxT("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT
},
2127 { wxT("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE
},
2128 { wxT("wxLC_USER_TEXT"), wxLC_USER_TEXT
},
2129 { wxT("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS
},
2130 { wxT("wxLC_NO_HEADER"), wxLC_NO_HEADER
},
2131 { wxT("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER
},
2132 { wxT("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL
},
2133 { wxT("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING
},
2134 { wxT("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING
},
2137 { wxT("wxSP_VERTICAL"), wxSP_VERTICAL
},
2138 { wxT("wxSP_HORIZONTAL"), wxSP_HORIZONTAL
},
2139 { wxT("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS
},
2140 { wxT("wxSP_WRAP"), wxSP_WRAP
},
2143 { wxT("wxSP_NOBORDER"), wxSP_NOBORDER
},
2144 { wxT("wxSP_3D"), wxSP_3D
},
2145 { wxT("wxSP_BORDER"), wxSP_BORDER
},
2148 { wxT("wxTC_MULTILINE"), wxTC_MULTILINE
},
2149 { wxT("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY
},
2150 { wxT("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH
},
2151 { wxT("wxTC_OWNERDRAW"), wxTC_OWNERDRAW
},
2154 { wxT("wxST_SIZEGRIP"), wxST_SIZEGRIP
},
2157 { wxT("wxFIXED_LENGTH"), wxFIXED_LENGTH
},
2158 { wxT("wxALIGN_LEFT"), wxALIGN_LEFT
},
2159 { wxT("wxALIGN_CENTER"), wxALIGN_CENTER
},
2160 { wxT("wxALIGN_CENTRE"), wxALIGN_CENTRE
},
2161 { wxT("wxALIGN_RIGHT"), wxALIGN_RIGHT
},
2162 { wxT("wxCOLOURED"), wxCOLOURED
},
2165 { wxT("wxTB_3DBUTTONS"), wxTB_3DBUTTONS
},
2166 { wxT("wxTB_HORIZONTAL"), wxTB_HORIZONTAL
},
2167 { wxT("wxTB_VERTICAL"), wxTB_VERTICAL
},
2168 { wxT("wxTB_FLAT"), wxTB_FLAT
},
2171 { wxT("wxDIALOG_MODAL"), wxDIALOG_MODAL
},
2174 { wxT("wxVSCROLL"), wxVSCROLL
},
2175 { wxT("wxHSCROLL"), wxHSCROLL
},
2176 { wxT("wxCAPTION"), wxCAPTION
},
2177 { wxT("wxSTAY_ON_TOP"), wxSTAY_ON_TOP
},
2178 { wxT("wxICONIZE"), wxICONIZE
},
2179 { wxT("wxMINIMIZE"), wxICONIZE
},
2180 { wxT("wxMAXIMIZE"), wxMAXIMIZE
},
2182 { wxT("wxMDI_PARENT"), 0},
2183 { wxT("wxMDI_CHILD"), 0},
2184 { wxT("wxTHICK_FRAME"), wxTHICK_FRAME
},
2185 { wxT("wxRESIZE_BORDER"), wxRESIZE_BORDER
},
2186 { wxT("wxSYSTEM_MENU"), wxSYSTEM_MENU
},
2187 { wxT("wxMINIMIZE_BOX"), wxMINIMIZE_BOX
},
2188 { wxT("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX
},
2189 { wxT("wxRESIZE_BOX"), wxRESIZE_BOX
},
2190 { wxT("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE
},
2191 { wxT("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE
},
2192 { wxT("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE
},
2193 { wxT("wxBORDER"), wxBORDER
},
2194 { wxT("wxRETAINED"), wxRETAINED
},
2195 { wxT("wxNATIVE_IMPL"), 0},
2196 { wxT("wxEXTENDED_IMPL"), 0},
2197 { wxT("wxBACKINGSTORE"), wxBACKINGSTORE
},
2198 // { wxT("wxFLAT"), wxFLAT},
2199 // { wxT("wxMOTIF_RESIZE"), wxMOTIF_RESIZE},
2200 { wxT("wxFIXED_LENGTH"), 0},
2201 { wxT("wxDOUBLE_BORDER"), wxDOUBLE_BORDER
},
2202 { wxT("wxSUNKEN_BORDER"), wxSUNKEN_BORDER
},
2203 { wxT("wxRAISED_BORDER"), wxRAISED_BORDER
},
2204 { wxT("wxSIMPLE_BORDER"), wxSIMPLE_BORDER
},
2205 { wxT("wxSTATIC_BORDER"), wxSTATIC_BORDER
},
2206 { wxT("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW
},
2207 { wxT("wxNO_BORDER"), wxNO_BORDER
},
2208 { wxT("wxCLIP_CHILDREN"), wxCLIP_CHILDREN
},
2209 { wxT("wxCLIP_SIBLINGS"), wxCLIP_SIBLINGS
},
2210 { wxT("wxTAB_TRAVERSAL"), 0}, // Compatibility only
2212 { wxT("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ
},
2213 { wxT("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT
},
2215 // Text font families
2216 { wxT("wxDEFAULT"), wxDEFAULT
},
2217 { wxT("wxDECORATIVE"), wxDECORATIVE
},
2218 { wxT("wxROMAN"), wxROMAN
},
2219 { wxT("wxSCRIPT"), wxSCRIPT
},
2220 { wxT("wxSWISS"), wxSWISS
},
2221 { wxT("wxMODERN"), wxMODERN
},
2222 { wxT("wxTELETYPE"), wxTELETYPE
},
2223 { wxT("wxVARIABLE"), wxVARIABLE
},
2224 { wxT("wxFIXED"), wxFIXED
},
2225 { wxT("wxNORMAL"), wxNORMAL
},
2226 { wxT("wxLIGHT"), wxLIGHT
},
2227 { wxT("wxBOLD"), wxBOLD
},
2228 { wxT("wxITALIC"), wxITALIC
},
2229 { wxT("wxSLANT"), wxSLANT
},
2230 { wxT("wxSOLID"), wxSOLID
},
2231 { wxT("wxDOT"), wxDOT
},
2232 { wxT("wxLONG_DASH"), wxLONG_DASH
},
2233 { wxT("wxSHORT_DASH"), wxSHORT_DASH
},
2234 { wxT("wxDOT_DASH"), wxDOT_DASH
},
2235 { wxT("wxUSER_DASH"), wxUSER_DASH
},
2236 { wxT("wxTRANSPARENT"), wxTRANSPARENT
},
2237 { wxT("wxSTIPPLE"), wxSTIPPLE
},
2238 { wxT("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH
},
2239 { wxT("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH
},
2240 { wxT("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH
},
2241 { wxT("wxCROSS_HATCH"), wxCROSS_HATCH
},
2242 { wxT("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH
},
2243 { wxT("wxVERTICAL_HATCH"), wxVERTICAL_HATCH
},
2244 { wxT("wxJOIN_BEVEL"), wxJOIN_BEVEL
},
2245 { wxT("wxJOIN_MITER"), wxJOIN_MITER
},
2246 { wxT("wxJOIN_ROUND"), wxJOIN_ROUND
},
2247 { wxT("wxCAP_ROUND"), wxCAP_ROUND
},
2248 { wxT("wxCAP_PROJECTING"), wxCAP_PROJECTING
},
2249 { wxT("wxCAP_BUTT"), wxCAP_BUTT
},
2252 { wxT("wxCLEAR"), wxCLEAR
},
2253 { wxT("wxXOR"), wxXOR
},
2254 { wxT("wxINVERT"), wxINVERT
},
2255 { wxT("wxOR_REVERSE"), wxOR_REVERSE
},
2256 { wxT("wxAND_REVERSE"), wxAND_REVERSE
},
2257 { wxT("wxCOPY"), wxCOPY
},
2258 { wxT("wxAND"), wxAND
},
2259 { wxT("wxAND_INVERT"), wxAND_INVERT
},
2260 { wxT("wxNO_OP"), wxNO_OP
},
2261 { wxT("wxNOR"), wxNOR
},
2262 { wxT("wxEQUIV"), wxEQUIV
},
2263 { wxT("wxSRC_INVERT"), wxSRC_INVERT
},
2264 { wxT("wxOR_INVERT"), wxOR_INVERT
},
2265 { wxT("wxNAND"), wxNAND
},
2266 { wxT("wxOR"), wxOR
},
2267 { wxT("wxSET"), wxSET
},
2269 { wxT("wxFLOOD_SURFACE"), wxFLOOD_SURFACE
},
2270 { wxT("wxFLOOD_BORDER"), wxFLOOD_BORDER
},
2271 { wxT("wxODDEVEN_RULE"), wxODDEVEN_RULE
},
2272 { wxT("wxWINDING_RULE"), wxWINDING_RULE
},
2273 { wxT("wxHORIZONTAL"), wxHORIZONTAL
},
2274 { wxT("wxVERTICAL"), wxVERTICAL
},
2275 { wxT("wxBOTH"), wxBOTH
},
2276 { wxT("wxCENTER_FRAME"), wxCENTER_FRAME
},
2277 { wxT("wxOK"), wxOK
},
2278 { wxT("wxYES_NO"), wxYES_NO
},
2279 { wxT("wxCANCEL"), wxCANCEL
},
2280 { wxT("wxYES"), wxYES
},
2281 { wxT("wxNO"), wxNO
},
2282 { wxT("wxICON_EXCLAMATION"), wxICON_EXCLAMATION
},
2283 { wxT("wxICON_HAND"), wxICON_HAND
},
2284 { wxT("wxICON_QUESTION"), wxICON_QUESTION
},
2285 { wxT("wxICON_INFORMATION"), wxICON_INFORMATION
},
2286 { wxT("wxICON_STOP"), wxICON_STOP
},
2287 { wxT("wxICON_ASTERISK"), wxICON_ASTERISK
},
2288 { wxT("wxICON_MASK"), wxICON_MASK
},
2289 { wxT("wxCENTRE"), wxCENTRE
},
2290 { wxT("wxCENTER"), wxCENTRE
},
2291 { wxT("wxUSER_COLOURS"), wxUSER_COLOURS
},
2292 { wxT("wxVERTICAL_LABEL"), 0},
2293 { wxT("wxHORIZONTAL_LABEL"), 0},
2295 // Bitmap types (not strictly styles)
2296 { wxT("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM
},
2297 { wxT("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM
},
2298 { wxT("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP
},
2299 { wxT("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2300 { wxT("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2301 { wxT("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF
},
2302 { wxT("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF
},
2303 { wxT("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO
},
2304 { wxT("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE
},
2305 { wxT("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR
},
2306 { wxT("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE
},
2307 { wxT("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA
},
2308 { wxT("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA
},
2309 { wxT("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY
}
2312 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2314 long wxParseWindowStyle(const wxString
& bitListString
)
2319 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2320 while (word
!= NULL
)
2324 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2325 if (wxStrcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2327 bitList
|= wxResourceBitListTable
[j
].bits
;
2333 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
2336 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2342 * Load a bitmap from a wxWindows resource, choosing an optimum
2343 * depth and appropriate type.
2346 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2349 table
= wxDefaultResourceTable
;
2351 wxItemResource
*item
= table
->FindResource(resource
);
2354 if ((item
->GetType() == wxT("")) || (item
->GetType() != wxT("wxBitmap")))
2356 wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar
*) resource
);
2357 return wxNullBitmap
;
2359 int thisDepth
= wxDisplayDepth();
2360 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2362 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2364 // Try to find optimum bitmap for this platform/colour depth
2365 wxNode
*node
= item
->GetChildren().First();
2368 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2369 int platform
= (int)child
->GetValue2();
2370 int noColours
= (int)child
->GetValue3();
2372 char *name = child->GetName();
2373 int bitmapType = (int)child->GetValue1();
2374 int xRes = child->GetWidth();
2375 int yRes = child->GetHeight();
2380 case RESOURCE_PLATFORM_ANY
:
2382 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2383 optResource
= child
;
2386 // Maximise the number of colours.
2387 // If noColours is zero (unspecified), then assume this
2388 // is the right one.
2389 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2390 optResource
= child
;
2395 case RESOURCE_PLATFORM_WINDOWS
:
2397 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2398 optResource
= child
;
2401 // Maximise the number of colours
2402 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2403 optResource
= child
;
2409 case RESOURCE_PLATFORM_X
:
2411 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2412 optResource
= child
;
2415 // Maximise the number of colours
2416 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2417 optResource
= child
;
2423 case RESOURCE_PLATFORM_MAC
:
2425 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2426 optResource
= child
;
2429 // Maximise the number of colours
2430 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2431 optResource
= child
;
2439 node
= node
->Next();
2441 // If no matching resource, fail.
2443 return wxNullBitmap
;
2445 wxString name
= optResource
->GetName();
2446 int bitmapType
= (int)optResource
->GetValue1();
2449 case wxBITMAP_TYPE_XBM_DATA
:
2452 wxItemResource
*item
= table
->FindResource(name
);
2455 wxLogWarning(_("Failed to find XBM resource %s.\n"
2456 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2457 return wxNullBitmap
;
2459 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2461 wxLogWarning(_("No XBM facility available!"));
2465 case wxBITMAP_TYPE_XPM_DATA
:
2467 wxItemResource
*item
= table
->FindResource(name
);
2470 wxLogWarning(_("Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2471 return wxNullBitmap
;
2473 return wxBitmap((char **)item
->GetValue1());
2477 return wxBitmap(name
, (wxBitmapType
)bitmapType
);
2481 return wxNullBitmap
;
2486 wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar
*) resource
);
2487 return wxNullBitmap
;
2492 * Load an icon from a wxWindows resource, choosing an optimum
2493 * depth and appropriate type.
2496 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2499 table
= wxDefaultResourceTable
;
2501 wxItemResource
*item
= table
->FindResource(resource
);
2504 if ((item
->GetType() == wxT("")) || wxStrcmp(item
->GetType(), wxT("wxIcon")) != 0)
2506 wxLogWarning(_("%s not an icon resource specification."), (const wxChar
*) resource
);
2509 int thisDepth
= wxDisplayDepth();
2510 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2512 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2514 // Try to find optimum icon for this platform/colour depth
2515 wxNode
*node
= item
->GetChildren().First();
2518 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2519 int platform
= (int)child
->GetValue2();
2520 int noColours
= (int)child
->GetValue3();
2522 char *name = child->GetName();
2523 int bitmapType = (int)child->GetValue1();
2524 int xRes = child->GetWidth();
2525 int yRes = child->GetHeight();
2530 case RESOURCE_PLATFORM_ANY
:
2532 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2533 optResource
= child
;
2536 // Maximise the number of colours.
2537 // If noColours is zero (unspecified), then assume this
2538 // is the right one.
2539 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2540 optResource
= child
;
2545 case RESOURCE_PLATFORM_WINDOWS
:
2547 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2548 optResource
= child
;
2551 // Maximise the number of colours
2552 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2553 optResource
= child
;
2559 case RESOURCE_PLATFORM_X
:
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_MAC
:
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
;
2589 node
= node
->Next();
2591 // If no matching resource, fail.
2595 wxString name
= optResource
->GetName();
2596 int bitmapType
= (int)optResource
->GetValue1();
2599 case wxBITMAP_TYPE_XBM_DATA
:
2602 wxItemResource
*item
= table
->FindResource(name
);
2605 wxLogWarning(_("Failed to find XBM resource %s.\n"
2606 "Forgot to use wxResourceLoadIconData?"), (const wxChar
*) name
);
2609 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2611 wxLogWarning(_("No XBM facility available!"));
2615 case wxBITMAP_TYPE_XPM_DATA
:
2617 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2619 wxItemResource *item = table->FindResource(name);
2623 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2627 return wxIcon((char **)item->GetValue1());
2629 wxLogWarning(_("No XPM icon facility available!"));
2635 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2638 return wxIcon(name
, bitmapType
);
2646 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2653 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2655 wxMenu
*menu
= new wxMenu
;
2656 wxNode
*node
= item
->GetChildren().First();
2659 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2660 if ((child
->GetType() != wxT("")) && (child
->GetType() == wxT("wxMenuSeparator")))
2661 menu
->AppendSeparator();
2662 else if (child
->GetChildren().Number() > 0)
2664 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2666 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2670 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2672 node
= node
->Next();
2677 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2680 table
= wxDefaultResourceTable
;
2682 wxItemResource
*menuResource
= table
->FindResource(resource
);
2683 if (menuResource
&& (menuResource
->GetType() != wxT("")) && (menuResource
->GetType() == wxT("wxMenu")))
2686 menuBar
= new wxMenuBar
;
2687 wxNode
*node
= menuResource
->GetChildren().First();
2690 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2691 wxMenu
*menu
= wxResourceCreateMenu(child
);
2693 menuBar
->Append(menu
, child
->GetTitle());
2694 node
= node
->Next();
2698 return (wxMenuBar
*) NULL
;
2701 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2704 table
= wxDefaultResourceTable
;
2706 wxItemResource
*menuResource
= table
->FindResource(resource
);
2707 if (menuResource
&& (menuResource
->GetType() != wxT("")) && (menuResource
->GetType() == wxT("wxMenu")))
2708 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2709 return wxResourceCreateMenu(menuResource
);
2710 return (wxMenu
*) NULL
;
2713 #endif // wxUSE_MENUS
2715 // Global equivalents (so don't have to refer to default table explicitly)
2716 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2719 table
= wxDefaultResourceTable
;
2721 return table
->ParseResourceData(resource
);
2724 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2727 table
= wxDefaultResourceTable
;
2729 return table
->ParseResourceFile(filename
);
2732 // Register XBM/XPM data
2733 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2736 table
= wxDefaultResourceTable
;
2738 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2741 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2744 table
= wxDefaultResourceTable
;
2746 return table
->RegisterResourceBitmapData(name
, data
);
2749 void wxResourceClear(wxResourceTable
*table
)
2752 table
= wxDefaultResourceTable
;
2754 table
->ClearTable();
2761 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2764 table
= wxDefaultResourceTable
;
2766 table
->identifiers
.Put(name
, (wxObject
*)(long)value
);
2770 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2773 table
= wxDefaultResourceTable
;
2775 return (int)(long)table
->identifiers
.Get(name
);
2779 * Parse #include file for #defines (only)
2782 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2785 table
= wxDefaultResourceTable
;
2787 FILE *fd
= wxFopen(f
, _T("r"));
2792 while (wxGetResourceToken(fd
))
2794 if (strcmp(wxResourceBuffer
, "#define") == 0)
2796 wxGetResourceToken(fd
);
2797 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2798 wxGetResourceToken(fd
);
2799 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2800 if (wxIsdigit(value
[0]))
2802 int val
= (int)wxAtol(value
);
2803 wxResourceAddIdentifier(name
, val
, table
);
2814 * Reading strings as if they were .wxr files
2817 static int getc_string(char *s
)
2819 int ch
= s
[wxResourceStringPtr
];
2824 wxResourceStringPtr
++;
2829 static int ungetc_string()
2831 wxResourceStringPtr
--;
2835 bool wxEatWhiteSpaceString(char *s
)
2839 while ((ch
= getc_string(s
)) != EOF
)
2851 ch
= getc_string(s
);
2862 while ((ch
= getc_string(s
)) != EOF
)
2864 if (ch
== '/' && prev_ch
== '*')
2886 bool wxGetResourceTokenString(char *s
)
2888 if (!wxResourceBuffer
)
2889 wxReallocateResourceBuffer();
2890 wxResourceBuffer
[0] = 0;
2891 wxEatWhiteSpaceString(s
);
2893 int ch
= getc_string(s
);
2897 wxResourceBufferCount
= 0;
2898 ch
= getc_string(s
);
2904 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2907 // Escaped characters
2908 else if (ch
== '\\')
2910 int newCh
= getc_string(s
);
2913 else if (newCh
== 10)
2921 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2922 wxReallocateResourceBuffer();
2923 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2924 wxResourceBufferCount
++;
2925 ch
= getc_string(s
);
2927 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2931 wxResourceBufferCount
= 0;
2933 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2935 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2936 wxReallocateResourceBuffer();
2937 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2938 wxResourceBufferCount
++;
2940 ch
= getc_string(s
);
2942 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2950 * Files are in form:
2951 static char *name = "....";
2952 with possible comments.
2955 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2958 table
= wxDefaultResourceTable
;
2960 // static or #define
2961 if (!wxGetResourceTokenString(s
))
2967 if (strcmp(wxResourceBuffer
, "#define") == 0)
2969 wxGetResourceTokenString(s
);
2970 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2971 wxGetResourceTokenString(s
);
2972 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2973 if (wxIsdigit(value
[0]))
2975 int val
= (int)wxAtol(value
);
2976 wxResourceAddIdentifier(name
, val
, table
);
2980 wxLogWarning(_("#define %s must be an integer."), name
);
2991 else if (strcmp(wxResourceBuffer, "#include") == 0)
2993 wxGetResourceTokenString(s);
2994 char *name = copystring(wxResourceBuffer);
2995 char *actualName = name;
2997 actualName = name + 1;
2998 int len = strlen(name);
2999 if ((len > 0) && (name[len-1] == '"'))
3001 if (!wxResourceParseIncludeFile(actualName, table))
3004 sprintf(buf, _("Could not find resource include file %s."), actualName);
3011 else if (strcmp(wxResourceBuffer
, "static") != 0)
3014 wxStrcpy(buf
, _("Found "));
3015 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
3016 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
3022 if (!wxGetResourceTokenString(s
))
3024 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3029 if (strcmp(wxResourceBuffer
, "char") != 0)
3031 wxLogWarning(_("Expected 'char' whilst parsing resource."));
3036 if (!wxGetResourceTokenString(s
))
3038 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3043 if (wxResourceBuffer
[0] != '*')
3045 wxLogWarning(_("Expected '*' whilst parsing resource."));
3048 wxChar nameBuf
[100];
3049 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
3053 if (!wxGetResourceTokenString(s
))
3055 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3060 if (strcmp(wxResourceBuffer
, "=") != 0)
3062 wxLogWarning(_("Expected '=' whilst parsing resource."));
3067 if (!wxGetResourceTokenString(s
))
3069 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3075 if (!db
.ReadPrologFromString(wxResourceBuffer
))
3077 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
3082 if (!wxGetResourceTokenString(s
))
3089 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
3092 table
= wxDefaultResourceTable
;
3097 // Turn backslashes into spaces
3100 int len
= strlen(s
);
3102 for (i
= 0; i
< len
; i
++)
3103 if (s
[i
] == 92 && s
[i
+1] == 13)
3111 wxResourceStringPtr
= 0;
3114 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
3118 return wxResourceInterpretResources(*table
, db
);
3122 * resource loading facility
3125 bool wxWindowBase::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
3128 table
= wxDefaultResourceTable
;
3130 wxItemResource
*resource
= table
->FindResource((const wxChar
*)resourceName
);
3131 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
3132 if (!resource
|| (resource
->GetType() == wxT("")) ||
3133 ! ((resource
->GetType() == wxT("wxDialog")) || (resource
->GetType() == wxT("wxPanel"))))
3136 wxString
title(resource
->GetTitle());
3137 long theWindowStyle
= resource
->GetStyle();
3138 bool isModal
= (resource
->GetValue1() != 0) ;
3139 int x
= resource
->GetX();
3140 int y
= resource
->GetY();
3141 int width
= resource
->GetWidth();
3142 int height
= resource
->GetHeight();
3143 wxString name
= resource
->GetName();
3145 if (IsKindOf(CLASSINFO(wxDialog
)))
3147 wxDialog
*dialogBox
= (wxDialog
*)this;
3148 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
3149 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
3152 // Only reset the client size if we know we're not going to do it again below.
3153 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
3154 dialogBox
->SetClientSize(width
, height
);
3156 else if (IsKindOf(CLASSINFO(wxPanel
)))
3158 wxPanel
* panel
= (wxPanel
*)this;
3159 if (!panel
->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
| wxTAB_TRAVERSAL
, name
))
3164 if (!((wxWindow
*)this)->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
3168 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
3170 // No need to do this since it's done in wxPanel or wxDialog constructor.
3171 // SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
3175 if (resource
->GetFont().Ok())
3176 SetFont(resource
->GetFont());
3177 if (resource
->GetBackgroundColour().Ok())
3178 SetBackgroundColour(resource
->GetBackgroundColour());
3181 // Should have some kind of font at this point
3182 if (!GetFont().Ok())
3183 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
3184 if (!GetBackgroundColour().Ok())
3185 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
3187 // Only when we've created the window and set the font can we set the correct size,
3188 // if based on dialog units.
3189 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
3191 wxSize sz
= ConvertDialogToPixels(wxSize(width
, height
));
3192 SetClientSize(sz
.x
, sz
.y
);
3194 wxPoint pt
= ConvertDialogToPixels(wxPoint(x
, y
));
3198 // Now create children
3199 wxNode
*node
= resource
->GetChildren().First();
3202 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
3204 (void) CreateItem(childResource
, resource
, table
);
3206 node
= node
->Next();
3211 wxControl
*wxWindowBase::CreateItem(const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
3214 table
= wxDefaultResourceTable
;
3215 return table
->CreateItem((wxWindow
*)this, resource
, parentResource
);
3219 #pragma warning(default:4706) // assignment within conditional expression
3225 #endif // wxUSE_WX_RESOURCES