1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Resource system
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "resource.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #include "wx/deprecated/setup.h"
25 #if wxUSE_WX_RESOURCES
28 #pragma warning(disable:4706) // assignment within conditional expression
36 #include "wx/gdicmn.h"
40 #include "wx/stattext.h"
41 #include "wx/button.h"
42 #include "wx/bmpbuttn.h"
43 #include "wx/radiobox.h"
44 #include "wx/listbox.h"
45 #include "wx/choice.h"
46 #include "wx/checkbox.h"
47 #include "wx/settings.h"
48 #include "wx/slider.h"
50 #include "wx/statbox.h"
51 #include "wx/statbmp.h"
53 #include "wx/textctrl.h"
54 #include "wx/msgdlg.h"
58 #include "wx/treebase.h"
59 #include "wx/listctrl.h"
62 #include "wx/radiobut.h"
66 #include "wx/scrolbar.h"
70 #include "wx/combobox.h"
73 #include "wx/validate.h"
82 #include "wx/string.h"
83 #include "wx/settings.h"
84 #include "wx/stream.h"
86 #include "wx/deprecated/resource.h"
87 #include "wx/deprecated/wxexpr.h"
89 // Forward (private) declarations
90 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
);
91 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
= FALSE
);
92 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
);
93 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
);
94 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
);
95 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, wxExpr
*expr
);
96 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, wxExpr
*expr
);
97 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
);
98 // Interpret list expression
99 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
);
101 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
102 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
) ;
103 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
105 wxResourceTable
*wxDefaultResourceTable
= (wxResourceTable
*) NULL
;
107 char *wxResourceBuffer
= (char *) NULL
;
108 long wxResourceBufferSize
= 0;
109 long wxResourceBufferCount
= 0;
110 int wxResourceStringPtr
= 0;
112 void wxInitializeResourceSystem()
114 wxDefaultResourceTable
= new wxResourceTable
;
117 void wxCleanUpResourceSystem()
119 delete wxDefaultResourceTable
;
120 if (wxResourceBuffer
)
121 delete[] wxResourceBuffer
;
125 void wxLogWarning(char *msg
)
127 wxMessageBox(msg
, _("Warning"), wxOK
);
131 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
132 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
134 wxItemResource::wxItemResource()
136 m_itemType
= wxT("");
140 m_x
= m_y
= m_width
= m_height
= 0;
141 m_value1
= m_value2
= m_value3
= m_value5
= 0;
147 wxItemResource::~wxItemResource()
149 wxNode
*node
= m_children
.First();
152 wxItemResource
*item
= (wxItemResource
*)node
->Data();
155 node
= m_children
.First();
163 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
167 wxResourceTable::~wxResourceTable()
172 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
174 wxItemResource
*item
= (wxItemResource
*)Get(WXSTRINGCAST name
);
178 void wxResourceTable::AddResource(wxItemResource
*item
)
180 wxString name
= item
->GetName();
182 name
= item
->GetTitle();
184 name
= wxT("no name");
186 // Delete existing resource, if any.
192 bool wxResourceTable::DeleteResource(const wxString
& name
)
194 wxItemResource
*item
= (wxItemResource
*)Delete(WXSTRINGCAST name
);
197 // See if any resource has this as its child; if so, delete from
198 // parent's child list.
200 wxNode
*node
= (wxNode
*) NULL
;
204 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
205 if (parent
->GetChildren().Member(item
))
207 parent
->GetChildren().DeleteObject(item
);
220 bool wxResourceTable::ParseResourceFile( wxInputStream
*is
)
223 int len
= is
->GetSize() ;
226 while ( is
->TellI() + 10 < len
) // it's a hack because the streams dont support EOF
228 wxResourceReadOneResource(is
, db
, &eof
, this) ;
230 return wxResourceInterpretResources(*this, db
);
233 bool wxResourceTable::ParseResourceFile(const wxString
& filename
)
237 FILE *fd
= wxFopen(filename
, wxT("r"));
241 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
246 return wxResourceInterpretResources(*this, db
);
249 bool wxResourceTable::ParseResourceData(const wxString
& data
)
252 if (!db
.ReadFromString(data
))
254 wxLogWarning(_("Ill-formed resource file syntax."));
258 return wxResourceInterpretResources(*this, db
);
261 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char bits
[], int width
, int height
)
263 // Register pre-loaded bitmap data
264 wxItemResource
*item
= new wxItemResource
;
265 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
266 item
->SetType(wxT("wxXBMData"));
268 item
->SetValue1((long)bits
);
269 item
->SetValue2((long)width
);
270 item
->SetValue3((long)height
);
275 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char **data
)
277 // Register pre-loaded bitmap data
278 wxItemResource
*item
= new wxItemResource
;
279 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
280 item
->SetType(wxT("wxXPMData"));
282 item
->SetValue1((long)data
);
287 bool wxResourceTable::SaveResource(const wxString
& WXUNUSED(filename
))
292 void wxResourceTable::ClearTable()
295 wxNode
*node
= Next();
298 wxNode
*next
= Next();
299 wxItemResource
*item
= (wxItemResource
*)node
->Data();
306 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, const wxItemResource
* childResource
, const wxItemResource
* parentResource
) const
308 int id
= childResource
->GetId();
312 bool dlgUnits
= ((parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0);
314 wxControl
*control
= (wxControl
*) NULL
;
315 wxString
itemType(childResource
->GetType());
321 pos
= parent
->ConvertDialogToPixels(wxPoint(childResource
->GetX(), childResource
->GetY()));
322 size
= parent
->ConvertDialogToPixels(wxSize(childResource
->GetWidth(), childResource
->GetHeight()));
326 pos
= wxPoint(childResource
->GetX(), childResource
->GetY());
327 size
= wxSize(childResource
->GetWidth(), childResource
->GetHeight());
330 if (itemType
== wxString(wxT("wxButton")) || itemType
== wxString(wxT("wxBitmapButton")))
332 if (childResource
->GetValue4() != wxT(""))
335 wxBitmap bitmap
= childResource
->GetBitmap();
338 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
339 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
342 #if defined(__WXPM__)
344 // OS/2 uses integer id's to access resources, not file name strings
346 bitmap
.LoadFile(wxCROSS_BITMAP
, wxBITMAP_TYPE_BMP_RESOURCE
);
348 bitmap
.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE
);
350 control
= new wxBitmapButton(parent
, id
, bitmap
, pos
, size
,
351 childResource
->GetStyle() | wxBU_AUTODRAW
, wxDefaultValidator
, childResource
->GetName());
354 // Normal, text button
355 control
= new wxButton(parent
, id
, childResource
->GetTitle(), pos
, size
,
356 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
358 else if (itemType
== wxString(wxT("wxMessage")) || itemType
== wxString(wxT("wxStaticText")) ||
359 itemType
== wxString(wxT("wxStaticBitmap")))
361 if (childResource
->GetValue4() != wxT("") || itemType
== wxString(wxT("wxStaticBitmap")) )
364 wxBitmap bitmap
= childResource
->GetBitmap();
367 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
368 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
370 #if wxUSE_BITMAP_MESSAGE
372 // Use a default bitmap
374 bitmap
.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE
);
378 control
= new wxStaticBitmap(parent
, id
, bitmap
, pos
, size
,
379 childResource
->GetStyle(), childResource
->GetName());
384 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(), pos
, size
,
385 childResource
->GetStyle(), childResource
->GetName());
388 else if (itemType
== wxString(wxT("wxText")) || itemType
== wxString(wxT("wxTextCtrl")) || itemType
== wxString(wxT("wxMultiText")))
390 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), pos
, size
,
391 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
393 else if (itemType
== wxString(wxT("wxCheckBox")))
395 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
396 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
398 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
401 else if (itemType
== wxString(wxT("wxGauge")))
403 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(), pos
, size
,
404 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
406 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
410 else if (itemType
== wxString(wxT("wxRadioButton")))
412 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
414 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
418 else if (itemType
== wxString(wxT("wxScrollBar")))
420 control
= new wxScrollBar(parent
, id
, pos
, size
,
421 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
423 ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1());
424 ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2());
425 ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3());
426 ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5());
428 ((wxScrollBar
*)control
)->SetScrollbar((int)childResource
->GetValue1(),(int)childResource
->GetValue2(),
429 (int)childResource
->GetValue3(),(int)(long)childResource
->GetValue5(),FALSE
);
433 else if (itemType
== wxString(wxT("wxSlider")))
435 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
436 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), pos
, size
,
437 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
439 else if (itemType
== wxString(wxT("wxGroupBox")) || itemType
== wxString(wxT("wxStaticBox")))
441 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
442 childResource
->GetStyle(), childResource
->GetName());
444 else if (itemType
== wxString(wxT("wxListBox")))
446 wxStringList
& stringList
= childResource
->GetStringValues();
447 wxString
*strings
= (wxString
*) NULL
;
449 if (stringList
.Number() > 0)
451 noStrings
= stringList
.Number();
452 strings
= new wxString
[noStrings
];
453 wxNode
*node
= stringList
.First();
457 strings
[i
] = (wxChar
*)node
->Data();
462 control
= new wxListBox(parent
, id
, pos
, size
,
463 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
468 else if (itemType
== wxString(wxT("wxChoice")))
470 wxStringList
& stringList
= childResource
->GetStringValues();
471 wxString
*strings
= (wxString
*) NULL
;
473 if (stringList
.Number() > 0)
475 noStrings
= stringList
.Number();
476 strings
= new wxString
[noStrings
];
477 wxNode
*node
= stringList
.First();
481 strings
[i
] = (wxChar
*)node
->Data();
486 control
= new wxChoice(parent
, id
, pos
, size
,
487 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
493 else if (itemType
== wxString(wxT("wxComboBox")))
495 wxStringList
& stringList
= childResource
->GetStringValues();
496 wxString
*strings
= (wxString
*) NULL
;
498 if (stringList
.Number() > 0)
500 noStrings
= stringList
.Number();
501 strings
= new wxString
[noStrings
];
502 wxNode
*node
= stringList
.First();
506 strings
[i
] = (wxChar
*)node
->Data();
511 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(), pos
, size
,
512 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
518 else if (itemType
== wxString(wxT("wxRadioBox")))
520 wxStringList
& stringList
= childResource
->GetStringValues();
521 wxString
*strings
= (wxString
*) NULL
;
523 if (stringList
.Number() > 0)
525 noStrings
= stringList
.Number();
526 strings
= new wxString
[noStrings
];
527 wxNode
*node
= stringList
.First();
531 strings
[i
] = (wxChar
*)node
->Data();
536 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), pos
, size
,
537 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
538 childResource
->GetName());
544 if ((parentResource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
546 // Don't set font; will be inherited from parent.
550 if (control
&& childResource
->GetFont().Ok())
552 control
->SetFont(childResource
->GetFont());
555 // Force the layout algorithm since the size changes the layout
556 if (control
->IsKindOf(CLASSINFO(wxRadioBox
)))
558 control
->SetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
|wxSIZE_AUTO_HEIGHT
);
567 * Interpret database as a series of resources
570 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
)
572 wxNode
*node
= db
.First();
575 wxExpr
*clause
= (wxExpr
*)node
->Data();
576 wxString
functor(clause
->Functor());
578 wxItemResource
*item
= (wxItemResource
*) NULL
;
579 if (functor
== wxT("dialog"))
580 item
= wxResourceInterpretDialog(table
, clause
);
581 else if (functor
== wxT("panel"))
582 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
583 else if (functor
== wxT("menubar"))
584 item
= wxResourceInterpretMenuBar(table
, clause
);
585 else if (functor
== wxT("menu"))
586 item
= wxResourceInterpretMenu(table
, clause
);
587 else if (functor
== wxT("string"))
588 item
= wxResourceInterpretString(table
, clause
);
589 else if (functor
== wxT("bitmap"))
590 item
= wxResourceInterpretBitmap(table
, clause
);
591 else if (functor
== wxT("icon"))
592 item
= wxResourceInterpretIcon(table
, clause
);
596 // Remove any existing resource of same name
597 if (item
->GetName() != wxT(""))
598 table
.DeleteResource(item
->GetName());
599 table
.AddResource(item
);
606 static const wxChar
*g_ValidControlClasses
[] =
609 wxT("wxBitmapButton"),
612 wxT("wxStaticBitmap"),
618 wxT("wxRadioButton"),
620 wxT("wxBitmapCheckBox"),
630 static bool wxIsValidControlClass(const wxString
& c
)
632 for ( size_t i
= 0; i
< WXSIZEOF(g_ValidControlClasses
); i
++ )
634 if ( c
== g_ValidControlClasses
[i
] )
640 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
642 wxItemResource
*dialogItem
= new wxItemResource
;
644 dialogItem
->SetType(wxT("wxPanel"));
646 dialogItem
->SetType(wxT("wxDialog"));
647 wxString style
= wxT("");
648 wxString title
= wxT("");
649 wxString name
= wxT("");
650 wxString backColourHex
= wxT("");
651 wxString labelColourHex
= wxT("");
652 wxString buttonColourHex
= wxT("");
654 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
658 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
660 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
661 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
662 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
663 expr
->GetAttributeValue(wxT("style"), style
);
664 expr
->GetAttributeValue(wxT("name"), name
);
665 expr
->GetAttributeValue(wxT("title"), title
);
666 expr
->GetAttributeValue(wxT("x"), x
);
667 expr
->GetAttributeValue(wxT("y"), y
);
668 expr
->GetAttributeValue(wxT("width"), width
);
669 expr
->GetAttributeValue(wxT("height"), height
);
670 expr
->GetAttributeValue(wxT("modal"), isModal
);
671 expr
->GetAttributeValue(wxT("label_font"), &labelFontExpr
);
672 expr
->GetAttributeValue(wxT("button_font"), &buttonFontExpr
);
673 expr
->GetAttributeValue(wxT("font"), &fontExpr
);
674 expr
->GetAttributeValue(wxT("background_colour"), backColourHex
);
675 expr
->GetAttributeValue(wxT("label_colour"), labelColourHex
);
676 expr
->GetAttributeValue(wxT("button_colour"), buttonColourHex
);
678 int useDialogUnits
= 0;
679 expr
->GetAttributeValue(wxT("use_dialog_units"), useDialogUnits
);
680 if (useDialogUnits
!= 0)
681 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
684 expr
->GetAttributeValue(wxT("use_system_defaults"), useDefaults
);
685 if (useDefaults
!= 0)
686 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
689 expr
->GetAttributeValue(wxT("id"), id
);
690 dialogItem
->SetId(id
);
692 if (style
!= wxT(""))
694 windowStyle
= wxParseWindowStyle(style
);
696 dialogItem
->SetStyle(windowStyle
);
697 dialogItem
->SetValue1(isModal
);
698 if (windowStyle
& wxDIALOG_MODAL
) // Uses style in wxWin 2
699 dialogItem
->SetValue1(TRUE
);
701 dialogItem
->SetName(name
);
702 dialogItem
->SetTitle(title
);
703 dialogItem
->SetSize(x
, y
, width
, height
);
705 // Check for wxWin 1.68-style specifications
706 if (style
.Find(wxT("VERTICAL_LABEL")) != -1)
707 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
708 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != -1)
709 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
711 if (backColourHex
!= wxT(""))
716 r
= wxHexToDec(backColourHex
.Mid(0, 2));
717 g
= wxHexToDec(backColourHex
.Mid(2, 2));
718 b
= wxHexToDec(backColourHex
.Mid(4, 2));
719 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
721 if (labelColourHex
!= wxT(""))
726 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
727 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
728 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
729 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
731 if (buttonColourHex
!= wxT(""))
736 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
737 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
738 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
739 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
743 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
744 else if (buttonFontExpr
)
745 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
746 else if (labelFontExpr
)
747 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
749 // Now parse all controls
750 wxExpr
*controlExpr
= expr
->GetFirst();
753 if (controlExpr
->Number() == 3)
755 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
756 if (controlKeyword
!= wxT("") && controlKeyword
== wxT("control"))
758 // The value part: always a list.
759 wxExpr
*listExpr
= controlExpr
->Nth(2);
760 if (listExpr
->Type() == PrologList
)
762 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
765 dialogItem
->GetChildren().Append(controlItem
);
770 controlExpr
= controlExpr
->GetNext();
775 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
777 wxItemResource
*controlItem
= new wxItemResource
;
779 // First, find the standard features of a control definition:
780 // [optional integer/string id], control name, title, style, name, x, y, width, height
782 wxString controlType
;
787 long windowStyle
= 0;
788 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
791 wxExpr
*expr1
= expr
->Nth(0);
793 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
795 if ( wxIsValidControlClass(expr1
->StringValue()) )
798 controlType
= expr1
->StringValue();
802 wxString
str(expr1
->StringValue());
803 id
= wxResourceGetIdentifier(str
, &table
);
806 wxLogWarning(_("Could not resolve control class or id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)"),
807 (const wxChar
*) expr1
->StringValue());
809 return (wxItemResource
*) NULL
;
813 // Success - we have an id, so the 2nd element must be the control class.
814 controlType
= expr
->Nth(1)->StringValue();
819 else if (expr1
->Type() == PrologInteger
)
821 id
= (int)expr1
->IntegerValue();
822 // Success - we have an id, so the 2nd element must be the control class.
823 controlType
= expr
->Nth(1)->StringValue();
827 expr1
= expr
->Nth(count
);
830 title
= expr1
->StringValue();
832 expr1
= expr
->Nth(count
);
836 style
= expr1
->StringValue();
837 windowStyle
= wxParseWindowStyle(style
);
840 expr1
= expr
->Nth(count
);
843 name
= expr1
->StringValue();
845 expr1
= expr
->Nth(count
);
848 x
= (int)expr1
->IntegerValue();
850 expr1
= expr
->Nth(count
);
853 y
= (int)expr1
->IntegerValue();
855 expr1
= expr
->Nth(count
);
858 width
= (int)expr1
->IntegerValue();
860 expr1
= expr
->Nth(count
);
863 height
= (int)expr1
->IntegerValue();
865 controlItem
->SetStyle(windowStyle
);
866 controlItem
->SetName(name
);
867 controlItem
->SetTitle(title
);
868 controlItem
->SetSize(x
, y
, width
, height
);
869 controlItem
->SetType(controlType
);
870 controlItem
->SetId(id
);
872 // Check for wxWin 1.68-style specifications
873 if (style
.Find(wxT("VERTICAL_LABEL")) != -1)
874 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
875 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != -1)
876 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
878 if (controlType
== wxT("wxButton"))
880 // Check for bitmap resource name (in case loading old-style resource file)
881 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
883 wxString
str(expr
->Nth(count
)->StringValue());
888 controlItem
->SetValue4(str
);
889 controlItem
->SetType(wxT("wxBitmapButton"));
892 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
893 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
895 else if (controlType
== wxT("wxBitmapButton"))
897 // Check for bitmap resource name
898 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
900 wxString
str(expr
->Nth(count
)->StringValue());
901 controlItem
->SetValue4(str
);
903 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
904 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
907 else if (controlType
== wxT("wxCheckBox"))
909 // Check for default value
910 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
912 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
914 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
915 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
919 else if (controlType
== wxT("wxRadioButton"))
921 // Check for default value
922 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
924 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
926 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
927 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
931 else if (controlType
== wxT("wxText") || controlType
== wxT("wxTextCtrl") || controlType
== wxT("wxMultiText"))
933 // Check for default value
934 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
936 wxString
str(expr
->Nth(count
)->StringValue());
937 controlItem
->SetValue4(str
);
940 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
942 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
943 // Skip past the obsolete label font spec if there are two consecutive specs
944 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
946 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
950 else if (controlType
== wxT("wxMessage") || controlType
== wxT("wxStaticText"))
952 // Check for bitmap resource name (in case it's an old-style .wxr file)
953 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
955 wxString
str(expr
->Nth(count
)->StringValue());
956 controlItem
->SetValue4(str
);
958 controlItem
->SetType(wxT("wxStaticText"));
960 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
961 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
963 else if (controlType
== wxT("wxStaticBitmap"))
965 // Check for bitmap resource name
966 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
968 wxString
str(expr
->Nth(count
)->StringValue());
969 controlItem
->SetValue4(str
);
972 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
973 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
975 else if (controlType
== wxT("wxGroupBox") || controlType
== wxT("wxStaticBox"))
977 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
978 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
980 else if (controlType
== wxT("wxGauge"))
982 // Check for default value
983 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
985 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
989 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
991 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
994 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
996 // Skip past the obsolete label font spec if there are two consecutive specs
997 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
999 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1004 else if (controlType
== wxT("wxSlider"))
1006 // Check for default value
1007 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1009 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1013 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1015 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1019 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1021 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1024 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1026 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1030 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1031 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1037 else if (controlType
== wxT("wxScrollBar"))
1040 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1042 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1046 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1048 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1052 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1054 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1058 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1059 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1064 else if (controlType
== wxT("wxListBox"))
1066 wxExpr
*valueList
= (wxExpr
*) NULL
;
1068 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1070 wxStringList stringList
;
1071 wxExpr
*stringExpr
= valueList
->GetFirst();
1074 stringList
.Add(stringExpr
->StringValue());
1075 stringExpr
= stringExpr
->GetNext();
1077 controlItem
->SetStringValues(stringList
);
1079 // This is now obsolete: it's in the window style.
1080 // Check for wxSINGLE/wxMULTIPLE
1081 wxExpr
*mult
= (wxExpr
*) NULL
;
1083 controlItem->SetValue1(wxLB_SINGLE);
1085 if (((mult
= expr
->Nth(count
)) != 0) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1088 wxString m(mult->StringValue());
1089 if (m == "wxLB_MULTIPLE")
1090 controlItem->SetValue1(wxLB_MULTIPLE);
1091 else if (m == "wxLB_EXTENDED")
1092 controlItem->SetValue1(wxLB_EXTENDED);
1097 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1099 // Skip past the obsolete label font spec if there are two consecutive specs
1100 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1102 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1106 else if (controlType
== wxT("wxChoice"))
1108 wxExpr
*valueList
= (wxExpr
*) NULL
;
1109 // Check for default value list
1110 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1112 wxStringList stringList
;
1113 wxExpr
*stringExpr
= valueList
->GetFirst();
1116 stringList
.Add(stringExpr
->StringValue());
1117 stringExpr
= stringExpr
->GetNext();
1119 controlItem
->SetStringValues(stringList
);
1123 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1125 // Skip past the obsolete label font spec if there are two consecutive specs
1126 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1128 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1133 else if (controlType
== wxT("wxComboBox"))
1135 wxExpr
*textValue
= expr
->Nth(count
);
1136 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1138 wxString
str(textValue
->StringValue());
1139 controlItem
->SetValue4(str
);
1143 wxExpr
*valueList
= (wxExpr
*) NULL
;
1144 // Check for default value list
1145 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1147 wxStringList stringList
;
1148 wxExpr
*stringExpr
= valueList
->GetFirst();
1151 stringList
.Add(stringExpr
->StringValue());
1152 stringExpr
= stringExpr
->GetNext();
1154 controlItem
->SetStringValues(stringList
);
1158 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1160 // Skip past the obsolete label font spec if there are two consecutive specs
1161 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1163 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1170 else if (controlType
== wxT("wxRadioBox"))
1172 wxExpr
*valueList
= (wxExpr
*) NULL
;
1173 // Check for default value list
1174 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1176 wxStringList stringList
;
1177 wxExpr
*stringExpr
= valueList
->GetFirst();
1180 stringList
.Add(stringExpr
->StringValue());
1181 stringExpr
= stringExpr
->GetNext();
1183 controlItem
->SetStringValues(stringList
);
1186 // majorDim (number of rows or cols)
1187 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1189 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1193 controlItem
->SetValue1(0);
1195 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1197 // Skip past the obsolete label font spec if there are two consecutive specs
1198 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1200 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1208 return (wxItemResource
*) NULL
;
1213 // Forward declaration
1214 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1217 * Interpet a menu item
1220 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1222 wxItemResource
*item
= new wxItemResource
;
1224 wxExpr
*labelExpr
= expr
->Nth(0);
1225 wxExpr
*idExpr
= expr
->Nth(1);
1226 wxExpr
*helpExpr
= expr
->Nth(2);
1227 wxExpr
*checkableExpr
= expr
->Nth(3);
1229 // Further keywords/attributes to follow sometime...
1230 if (expr
->Number() == 0)
1232 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1233 item
->SetType(wxT("wxMenuSeparator"));
1238 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1239 item
->SetType(wxT("wxMenu")); // Well, menu item, but doesn't matter.
1242 wxString
str(labelExpr
->StringValue());
1243 item
->SetTitle(str
);
1248 // If a string or word, must look up in identifier table.
1249 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1251 wxString
str(idExpr
->StringValue());
1252 id
= wxResourceGetIdentifier(str
, &table
);
1255 wxLogWarning(_("Could not resolve menu id '%s'. Use (non-zero) integer instead\nor provide #define (see manual for caveats)"),
1256 (const wxChar
*) idExpr
->StringValue());
1259 else if (idExpr
->Type() == PrologInteger
)
1260 id
= (int)idExpr
->IntegerValue();
1261 item
->SetValue1(id
);
1265 wxString
str(helpExpr
->StringValue());
1266 item
->SetValue4(str
);
1269 item
->SetValue2(checkableExpr
->IntegerValue());
1271 // Find the first expression that's a list, for submenu
1272 wxExpr
*subMenuExpr
= expr
->GetFirst();
1273 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1274 subMenuExpr
= subMenuExpr
->GetNext();
1278 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1279 item
->GetChildren().Append(child
);
1280 subMenuExpr
= subMenuExpr
->GetNext();
1287 * Interpret a nested list as a menu
1290 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1292 wxItemResource *menu = new wxItemResource;
1293 // menu->SetType(wxTYPE_MENU);
1294 menu->SetType("wxMenu");
1295 wxExpr *element = expr->GetFirst();
1298 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1300 menu->GetChildren().Append(item);
1301 element = element->GetNext();
1307 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1309 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1310 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1312 return (wxItemResource
*) NULL
;
1314 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1317 return (wxItemResource
*) NULL
;
1320 if (expr
->GetAttributeValue(wxT("name"), name
))
1322 menuResource
->SetName(name
);
1325 return menuResource
;
1328 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1330 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1331 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1333 return (wxItemResource
*) NULL
;
1335 wxItemResource
*resource
= new wxItemResource
;
1336 resource
->SetType(wxT("wxMenu"));
1337 // resource->SetType(wxTYPE_MENU);
1339 wxExpr
*element
= listExpr
->GetFirst();
1342 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1343 resource
->GetChildren().Append(menuResource
);
1344 element
= element
->GetNext();
1348 if (expr
->GetAttributeValue(wxT("name"), name
))
1350 resource
->SetName(name
);
1356 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1358 return (wxItemResource
*) NULL
;
1361 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1363 wxItemResource
*bitmapItem
= new wxItemResource
;
1364 // bitmapItem->SetType(wxTYPE_BITMAP);
1365 bitmapItem
->SetType(wxT("wxBitmap"));
1367 if (expr
->GetAttributeValue(wxT("name"), name
))
1369 bitmapItem
->SetName(name
);
1371 // Now parse all bitmap specifications
1372 wxExpr
*bitmapExpr
= expr
->GetFirst();
1375 if (bitmapExpr
->Number() == 3)
1377 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1378 if (bitmapKeyword
== wxT("bitmap") || bitmapKeyword
== wxT("icon"))
1380 // The value part: always a list.
1381 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1382 if (listExpr
->Type() == PrologList
)
1384 wxItemResource
*bitmapSpec
= new wxItemResource
;
1385 // bitmapSpec->SetType(wxTYPE_BITMAP);
1386 bitmapSpec
->SetType(wxT("wxBitmap"));
1388 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1389 // where everything after 'filename' is optional.
1390 wxExpr
*nameExpr
= listExpr
->Nth(0);
1391 wxExpr
*typeExpr
= listExpr
->Nth(1);
1392 wxExpr
*platformExpr
= listExpr
->Nth(2);
1393 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1394 wxExpr
*xresExpr
= listExpr
->Nth(4);
1395 wxExpr
*yresExpr
= listExpr
->Nth(5);
1396 if (nameExpr
&& nameExpr
->StringValue() != wxT(""))
1398 bitmapSpec
->SetName(nameExpr
->StringValue());
1400 if (typeExpr
&& typeExpr
->StringValue() != wxT(""))
1402 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1405 bitmapSpec
->SetValue1(0);
1407 if (platformExpr
&& platformExpr
->StringValue() != wxT(""))
1409 wxString
plat(platformExpr
->StringValue());
1410 if (plat
== wxT("windows") || plat
== wxT("WINDOWS"))
1411 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1412 else if (plat
== wxT("x") || plat
== wxT("X"))
1413 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1414 else if (plat
== wxT("mac") || plat
== wxT("MAC"))
1415 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1417 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1420 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1423 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1427 xres
= (int)xresExpr
->IntegerValue();
1429 yres
= (int)yresExpr
->IntegerValue();
1430 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1432 bitmapItem
->GetChildren().Append(bitmapSpec
);
1436 bitmapExpr
= bitmapExpr
->GetNext();
1442 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1444 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1447 // item->SetType(wxTYPE_ICON);
1448 item
->SetType(wxT("wxIcon"));
1452 return (wxItemResource
*) NULL
;
1455 // Interpret list expression as a font
1456 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1458 if (expr
->Type() != PrologList
)
1462 int family
= wxSWISS
;
1463 int style
= wxNORMAL
;
1464 int weight
= wxNORMAL
;
1466 wxString
faceName(wxT(""));
1468 wxExpr
*pointExpr
= expr
->Nth(0);
1469 wxExpr
*familyExpr
= expr
->Nth(1);
1470 wxExpr
*styleExpr
= expr
->Nth(2);
1471 wxExpr
*weightExpr
= expr
->Nth(3);
1472 wxExpr
*underlineExpr
= expr
->Nth(4);
1473 wxExpr
*faceNameExpr
= expr
->Nth(5);
1475 point
= (int)pointExpr
->IntegerValue();
1480 str
= familyExpr
->StringValue();
1481 family
= (int)wxParseWindowStyle(str
);
1485 str
= styleExpr
->StringValue();
1486 style
= (int)wxParseWindowStyle(str
);
1490 str
= weightExpr
->StringValue();
1491 weight
= (int)wxParseWindowStyle(str
);
1494 underline
= (int)underlineExpr
->IntegerValue();
1496 faceName
= faceNameExpr
->StringValue();
1498 return *wxTheFontList
->FindOrCreateFont(point
, family
, style
, weight
,
1499 (underline
!= 0), faceName
);
1502 // Separate file for the remainder of this, for BC++/Win16
1504 #if !((defined(__BORLANDC__) || defined(__SC__)) && defined(__WIN16__))
1506 * (Re)allocate buffer for reading in from resource file
1509 bool wxReallocateResourceBuffer()
1511 if (!wxResourceBuffer
)
1513 wxResourceBufferSize
= 1000;
1514 wxResourceBuffer
= new char[wxResourceBufferSize
];
1517 if (wxResourceBuffer
)
1519 long newSize
= wxResourceBufferSize
+ 1000;
1520 char *tmp
= new char[(int)newSize
];
1521 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1522 delete[] wxResourceBuffer
;
1523 wxResourceBuffer
= tmp
;
1524 wxResourceBufferSize
= newSize
;
1529 static bool wxEatWhiteSpace(FILE *fd
)
1533 while ((ch
= getc(fd
)) != EOF
)
1548 ungetc(prev_ch
, fd
);
1556 while ((ch
= getc(fd
)) != EOF
)
1558 if (ch
== '/' && prev_ch
== '*')
1566 static char buffer
[255];
1567 fgets(buffer
, 255, fd
);
1571 ungetc(prev_ch
, fd
);
1585 static bool wxEatWhiteSpace(wxInputStream
*is
)
1587 int ch
= is
->GetC() ;
1588 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1595 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1597 // Check for comment
1603 bool finished
= FALSE
;
1611 int newCh
= is
->GetC();
1626 return wxEatWhiteSpace(is
);
1629 bool wxGetResourceToken(FILE *fd
)
1631 if (!wxResourceBuffer
)
1632 wxReallocateResourceBuffer();
1633 wxResourceBuffer
[0] = 0;
1634 wxEatWhiteSpace(fd
);
1640 wxResourceBufferCount
= 0;
1647 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1650 // Escaped characters
1651 else if (ch
== '\\')
1653 int newCh
= getc(fd
);
1656 else if (newCh
== 10)
1664 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1665 wxReallocateResourceBuffer();
1666 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1667 wxResourceBufferCount
++;
1670 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1674 wxResourceBufferCount
= 0;
1676 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1678 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1679 wxReallocateResourceBuffer();
1680 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1681 wxResourceBufferCount
++;
1685 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1692 bool wxGetResourceToken(wxInputStream
*is
)
1694 if (!wxResourceBuffer
)
1695 wxReallocateResourceBuffer();
1696 wxResourceBuffer
[0] = 0;
1697 wxEatWhiteSpace(is
);
1699 int ch
= is
->GetC() ;
1703 wxResourceBufferCount
= 0;
1710 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1713 // Escaped characters
1714 else if (ch
== '\\')
1716 int newCh
= is
->GetC();
1719 else if (newCh
== 10)
1721 else if (newCh
== 13) // mac
1729 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1730 wxReallocateResourceBuffer();
1731 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1732 wxResourceBufferCount
++;
1735 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1739 wxResourceBufferCount
= 0;
1741 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1743 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1744 wxReallocateResourceBuffer();
1745 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1746 wxResourceBufferCount
++;
1750 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1758 * Files are in form:
1759 static char *name = "....";
1760 with possible comments.
1763 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1766 table
= wxDefaultResourceTable
;
1768 // static or #define
1769 if (!wxGetResourceToken(fd
))
1775 if (strcmp(wxResourceBuffer
, "#define") == 0)
1777 wxGetResourceToken(fd
);
1778 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1779 wxGetResourceToken(fd
);
1780 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1781 if (wxIsdigit(value
[0]))
1783 int val
= (int)wxAtol(value
);
1784 wxResourceAddIdentifier(name
, val
, table
);
1788 wxLogWarning(_("#define %s must be an integer."), name
);
1798 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1800 wxGetResourceToken(fd
);
1801 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1802 wxChar
*actualName
= name
;
1803 if (name
[0] == wxT('"'))
1804 actualName
= name
+ 1;
1805 int len
= wxStrlen(name
);
1806 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1808 if (!wxResourceParseIncludeFile(actualName
, table
))
1810 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1815 else if (strcmp(wxResourceBuffer
, "static") != 0)
1818 wxStrcpy(buf
, _("Found "));
1819 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
1820 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1826 if (!wxGetResourceToken(fd
))
1828 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1833 if (strcmp(wxResourceBuffer
, "char") != 0)
1835 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1840 if (!wxGetResourceToken(fd
))
1842 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1847 if (wxResourceBuffer
[0] != '*')
1849 wxLogWarning(_("Expected '*' whilst parsing resource."));
1852 wxChar nameBuf
[100];
1853 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
1857 if (!wxGetResourceToken(fd
))
1859 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1864 if (strcmp(wxResourceBuffer
, "=") != 0)
1866 wxLogWarning(_("Expected '=' whilst parsing resource."));
1871 if (!wxGetResourceToken(fd
))
1873 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1879 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1881 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1886 if (!wxGetResourceToken(fd
))
1893 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1896 table
= wxDefaultResourceTable
;
1898 // static or #define
1899 if (!wxGetResourceToken(fd
))
1905 if (strcmp(wxResourceBuffer
, "#define") == 0)
1907 wxGetResourceToken(fd
);
1908 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1909 wxGetResourceToken(fd
);
1910 wxChar
*value
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1911 if (wxIsalpha(value
[0]))
1913 int val
= (int)wxAtol(value
);
1914 wxResourceAddIdentifier(name
, val
, table
);
1918 wxLogWarning(_("#define %s must be an integer."), name
);
1928 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1930 wxGetResourceToken(fd
);
1931 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1932 wxChar
*actualName
= name
;
1933 if (name
[0] == wxT('"'))
1934 actualName
= name
+ 1;
1935 int len
= wxStrlen(name
);
1936 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1938 if (!wxResourceParseIncludeFile(actualName
, table
))
1940 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1945 else if (strcmp(wxResourceBuffer
, "static") != 0)
1948 wxStrcpy(buf
, _("Found "));
1949 wxStrncat(buf
, wxConvLibc
.cMB2WX(wxResourceBuffer
), 30);
1950 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1956 if (!wxGetResourceToken(fd
))
1958 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1963 if (strcmp(wxResourceBuffer
, "char") != 0)
1965 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1970 if (!wxGetResourceToken(fd
))
1972 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1977 if (wxResourceBuffer
[0] != '*')
1979 wxLogWarning(_("Expected '*' whilst parsing resource."));
1983 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
1986 if (!wxGetResourceToken(fd
))
1988 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1993 if (strcmp(wxResourceBuffer
, "=") != 0)
1995 wxLogWarning(_("Expected '=' whilst parsing resource."));
2000 if (!wxGetResourceToken(fd
))
2002 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2008 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2010 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2015 if (!wxGetResourceToken(fd
))
2023 * Parses string window style into integer window style
2027 * Style flag parsing, e.g.
2028 * "wxSYSTEM_MENU | wxBORDER" -> integer
2031 wxChar
* wxResourceParseWord(wxChar
*s
, int *i
)
2034 return (wxChar
*) NULL
;
2036 static wxChar buf
[150];
2037 int len
= wxStrlen(s
);
2040 while ((ii
< len
) && (wxIsalpha(s
[ii
]) || (s
[ii
] == wxT('_'))))
2048 // Eat whitespace and conjunction characters
2049 while ((ii
< len
) &&
2050 ((s
[ii
] == wxT(' ')) || (s
[ii
] == wxT('|')) || (s
[ii
] == wxT(','))))
2056 return (wxChar
*) NULL
;
2061 struct wxResourceBitListStruct
2067 static wxResourceBitListStruct wxResourceBitListTable
[] =
2070 { wxT("wxSINGLE"), wxLB_SINGLE
},
2071 { wxT("wxMULTIPLE"), wxLB_MULTIPLE
},
2072 { wxT("wxEXTENDED"), wxLB_EXTENDED
},
2073 { wxT("wxLB_SINGLE"), wxLB_SINGLE
},
2074 { wxT("wxLB_MULTIPLE"), wxLB_MULTIPLE
},
2075 { wxT("wxLB_EXTENDED"), wxLB_EXTENDED
},
2076 { wxT("wxLB_NEEDED_SB"), wxLB_NEEDED_SB
},
2077 { wxT("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB
},
2078 { wxT("wxLB_SORT"), wxLB_SORT
},
2079 { wxT("wxLB_OWNERDRAW"), wxLB_OWNERDRAW
},
2080 { wxT("wxLB_HSCROLL"), wxLB_HSCROLL
},
2083 { wxT("wxCB_SIMPLE"), wxCB_SIMPLE
},
2084 { wxT("wxCB_DROPDOWN"), wxCB_DROPDOWN
},
2085 { wxT("wxCB_READONLY"), wxCB_READONLY
},
2086 { wxT("wxCB_SORT"), wxCB_SORT
},
2089 { wxT("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR
},
2090 { wxT("wxGA_HORIZONTAL"), wxGA_HORIZONTAL
},
2091 { wxT("wxGA_VERTICAL"), wxGA_VERTICAL
},
2094 { wxT("wxPASSWORD"), wxPASSWORD
},
2095 { wxT("wxPROCESS_ENTER"), wxPROCESS_ENTER
},
2096 { wxT("wxTE_PASSWORD"), wxTE_PASSWORD
},
2097 { wxT("wxTE_READONLY"), wxTE_READONLY
},
2098 { wxT("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER
},
2099 { wxT("wxTE_MULTILINE"), wxTE_MULTILINE
},
2100 { wxT("wxTE_NO_VSCROLL"), wxTE_NO_VSCROLL
},
2102 /* wxRadioBox/wxRadioButton */
2103 { wxT("wxRB_GROUP"), wxRB_GROUP
},
2104 { wxT("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS
},
2105 { wxT("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS
},
2106 { wxT("wxRA_HORIZONTAL"), wxRA_HORIZONTAL
},
2107 { wxT("wxRA_VERTICAL"), wxRA_VERTICAL
},
2110 { wxT("wxSL_HORIZONTAL"), wxSL_HORIZONTAL
},
2111 { wxT("wxSL_VERTICAL"), wxSL_VERTICAL
},
2112 { wxT("wxSL_AUTOTICKS"), wxSL_AUTOTICKS
},
2113 { wxT("wxSL_LABELS"), wxSL_LABELS
},
2114 { wxT("wxSL_LEFT"), wxSL_LEFT
},
2115 { wxT("wxSL_TOP"), wxSL_TOP
},
2116 { wxT("wxSL_RIGHT"), wxSL_RIGHT
},
2117 { wxT("wxSL_BOTTOM"), wxSL_BOTTOM
},
2118 { wxT("wxSL_BOTH"), wxSL_BOTH
},
2119 { wxT("wxSL_SELRANGE"), wxSL_SELRANGE
},
2122 { wxT("wxSB_HORIZONTAL"), wxSB_HORIZONTAL
},
2123 { wxT("wxSB_VERTICAL"), wxSB_VERTICAL
},
2126 { wxT("wxBU_AUTODRAW"), wxBU_AUTODRAW
},
2127 { wxT("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW
},
2130 { wxT("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS
},
2131 { wxT("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS
},
2132 { wxT("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT
},
2135 { wxT("wxLC_ICON"), wxLC_ICON
},
2136 { wxT("wxLC_SMALL_ICON"), wxLC_SMALL_ICON
},
2137 { wxT("wxLC_LIST"), wxLC_LIST
},
2138 { wxT("wxLC_REPORT"), wxLC_REPORT
},
2139 { wxT("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP
},
2140 { wxT("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT
},
2141 { wxT("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE
},
2142 { wxT("wxLC_USER_TEXT"), wxLC_USER_TEXT
},
2143 { wxT("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS
},
2144 { wxT("wxLC_NO_HEADER"), wxLC_NO_HEADER
},
2145 { wxT("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER
},
2146 { wxT("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL
},
2147 { wxT("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING
},
2148 { wxT("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING
},
2151 { wxT("wxSP_VERTICAL"), wxSP_VERTICAL
},
2152 { wxT("wxSP_HORIZONTAL"), wxSP_HORIZONTAL
},
2153 { wxT("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS
},
2154 { wxT("wxSP_WRAP"), wxSP_WRAP
},
2157 { wxT("wxSP_NOBORDER"), wxSP_NOBORDER
},
2158 { wxT("wxSP_3D"), wxSP_3D
},
2159 { wxT("wxSP_BORDER"), wxSP_BORDER
},
2162 { wxT("wxTC_MULTILINE"), wxTC_MULTILINE
},
2163 { wxT("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY
},
2164 { wxT("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH
},
2165 { wxT("wxTC_OWNERDRAW"), wxTC_OWNERDRAW
},
2168 { wxT("wxST_SIZEGRIP"), wxST_SIZEGRIP
},
2171 { wxT("wxFIXED_LENGTH"), wxFIXED_LENGTH
},
2172 { wxT("wxALIGN_LEFT"), wxALIGN_LEFT
},
2173 { wxT("wxALIGN_CENTER"), wxALIGN_CENTER
},
2174 { wxT("wxALIGN_CENTRE"), wxALIGN_CENTRE
},
2175 { wxT("wxALIGN_RIGHT"), wxALIGN_RIGHT
},
2176 { wxT("wxCOLOURED"), wxCOLOURED
},
2179 { wxT("wxTB_3DBUTTONS"), wxTB_3DBUTTONS
},
2180 { wxT("wxTB_HORIZONTAL"), wxTB_HORIZONTAL
},
2181 { wxT("wxTB_VERTICAL"), wxTB_VERTICAL
},
2182 { wxT("wxTB_FLAT"), wxTB_FLAT
},
2185 { wxT("wxDIALOG_MODAL"), wxDIALOG_MODAL
},
2188 { wxT("wxVSCROLL"), wxVSCROLL
},
2189 { wxT("wxHSCROLL"), wxHSCROLL
},
2190 { wxT("wxCAPTION"), wxCAPTION
},
2191 { wxT("wxSTAY_ON_TOP"), wxSTAY_ON_TOP
},
2192 { wxT("wxICONIZE"), wxICONIZE
},
2193 { wxT("wxMINIMIZE"), wxICONIZE
},
2194 { wxT("wxMAXIMIZE"), wxMAXIMIZE
},
2196 { wxT("wxMDI_PARENT"), 0},
2197 { wxT("wxMDI_CHILD"), 0},
2198 { wxT("wxTHICK_FRAME"), wxTHICK_FRAME
},
2199 { wxT("wxRESIZE_BORDER"), wxRESIZE_BORDER
},
2200 { wxT("wxSYSTEM_MENU"), wxSYSTEM_MENU
},
2201 { wxT("wxMINIMIZE_BOX"), wxMINIMIZE_BOX
},
2202 { wxT("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX
},
2203 { wxT("wxRESIZE_BOX"), wxRESIZE_BOX
},
2204 { wxT("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE
},
2205 { wxT("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE
},
2206 { wxT("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE
},
2207 { wxT("wxBORDER"), wxBORDER
},
2208 { wxT("wxRETAINED"), wxRETAINED
},
2209 { wxT("wxNATIVE_IMPL"), 0},
2210 { wxT("wxEXTENDED_IMPL"), 0},
2211 { wxT("wxBACKINGSTORE"), wxBACKINGSTORE
},
2212 // { wxT("wxFLAT"), wxFLAT},
2213 // { wxT("wxMOTIF_RESIZE"), wxMOTIF_RESIZE},
2214 { wxT("wxFIXED_LENGTH"), 0},
2215 { wxT("wxDOUBLE_BORDER"), wxDOUBLE_BORDER
},
2216 { wxT("wxSUNKEN_BORDER"), wxSUNKEN_BORDER
},
2217 { wxT("wxRAISED_BORDER"), wxRAISED_BORDER
},
2218 { wxT("wxSIMPLE_BORDER"), wxSIMPLE_BORDER
},
2219 { wxT("wxSTATIC_BORDER"), wxSTATIC_BORDER
},
2220 { wxT("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW
},
2221 { wxT("wxNO_BORDER"), wxNO_BORDER
},
2222 { wxT("wxCLIP_CHILDREN"), wxCLIP_CHILDREN
},
2223 { wxT("wxCLIP_SIBLINGS"), wxCLIP_SIBLINGS
},
2224 { wxT("wxTAB_TRAVERSAL"), 0}, // Compatibility only
2226 { wxT("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ
},
2227 { wxT("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT
},
2229 // Text font families
2230 { wxT("wxDEFAULT"), wxDEFAULT
},
2231 { wxT("wxDECORATIVE"), wxDECORATIVE
},
2232 { wxT("wxROMAN"), wxROMAN
},
2233 { wxT("wxSCRIPT"), wxSCRIPT
},
2234 { wxT("wxSWISS"), wxSWISS
},
2235 { wxT("wxMODERN"), wxMODERN
},
2236 { wxT("wxTELETYPE"), wxTELETYPE
},
2237 { wxT("wxVARIABLE"), wxVARIABLE
},
2238 { wxT("wxFIXED"), wxFIXED
},
2239 { wxT("wxNORMAL"), wxNORMAL
},
2240 { wxT("wxLIGHT"), wxLIGHT
},
2241 { wxT("wxBOLD"), wxBOLD
},
2242 { wxT("wxITALIC"), wxITALIC
},
2243 { wxT("wxSLANT"), wxSLANT
},
2244 { wxT("wxSOLID"), wxSOLID
},
2245 { wxT("wxDOT"), wxDOT
},
2246 { wxT("wxLONG_DASH"), wxLONG_DASH
},
2247 { wxT("wxSHORT_DASH"), wxSHORT_DASH
},
2248 { wxT("wxDOT_DASH"), wxDOT_DASH
},
2249 { wxT("wxUSER_DASH"), wxUSER_DASH
},
2250 { wxT("wxTRANSPARENT"), wxTRANSPARENT
},
2251 { wxT("wxSTIPPLE"), wxSTIPPLE
},
2252 { wxT("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH
},
2253 { wxT("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH
},
2254 { wxT("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH
},
2255 { wxT("wxCROSS_HATCH"), wxCROSS_HATCH
},
2256 { wxT("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH
},
2257 { wxT("wxVERTICAL_HATCH"), wxVERTICAL_HATCH
},
2258 { wxT("wxJOIN_BEVEL"), wxJOIN_BEVEL
},
2259 { wxT("wxJOIN_MITER"), wxJOIN_MITER
},
2260 { wxT("wxJOIN_ROUND"), wxJOIN_ROUND
},
2261 { wxT("wxCAP_ROUND"), wxCAP_ROUND
},
2262 { wxT("wxCAP_PROJECTING"), wxCAP_PROJECTING
},
2263 { wxT("wxCAP_BUTT"), wxCAP_BUTT
},
2266 { wxT("wxCLEAR"), wxCLEAR
},
2267 { wxT("wxXOR"), wxXOR
},
2268 { wxT("wxINVERT"), wxINVERT
},
2269 { wxT("wxOR_REVERSE"), wxOR_REVERSE
},
2270 { wxT("wxAND_REVERSE"), wxAND_REVERSE
},
2271 { wxT("wxCOPY"), wxCOPY
},
2272 { wxT("wxAND"), wxAND
},
2273 { wxT("wxAND_INVERT"), wxAND_INVERT
},
2274 { wxT("wxNO_OP"), wxNO_OP
},
2275 { wxT("wxNOR"), wxNOR
},
2276 { wxT("wxEQUIV"), wxEQUIV
},
2277 { wxT("wxSRC_INVERT"), wxSRC_INVERT
},
2278 { wxT("wxOR_INVERT"), wxOR_INVERT
},
2279 { wxT("wxNAND"), wxNAND
},
2280 { wxT("wxOR"), wxOR
},
2281 { wxT("wxSET"), wxSET
},
2283 { wxT("wxFLOOD_SURFACE"), wxFLOOD_SURFACE
},
2284 { wxT("wxFLOOD_BORDER"), wxFLOOD_BORDER
},
2285 { wxT("wxODDEVEN_RULE"), wxODDEVEN_RULE
},
2286 { wxT("wxWINDING_RULE"), wxWINDING_RULE
},
2287 { wxT("wxHORIZONTAL"), wxHORIZONTAL
},
2288 { wxT("wxVERTICAL"), wxVERTICAL
},
2289 { wxT("wxBOTH"), wxBOTH
},
2290 { wxT("wxCENTER_FRAME"), wxCENTER_FRAME
},
2291 { wxT("wxOK"), wxOK
},
2292 { wxT("wxYES_NO"), wxYES_NO
},
2293 { wxT("wxCANCEL"), wxCANCEL
},
2294 { wxT("wxYES"), wxYES
},
2295 { wxT("wxNO"), wxNO
},
2296 { wxT("wxICON_EXCLAMATION"), wxICON_EXCLAMATION
},
2297 { wxT("wxICON_HAND"), wxICON_HAND
},
2298 { wxT("wxICON_QUESTION"), wxICON_QUESTION
},
2299 { wxT("wxICON_INFORMATION"), wxICON_INFORMATION
},
2300 { wxT("wxICON_STOP"), wxICON_STOP
},
2301 { wxT("wxICON_ASTERISK"), wxICON_ASTERISK
},
2302 { wxT("wxICON_MASK"), wxICON_MASK
},
2303 { wxT("wxCENTRE"), wxCENTRE
},
2304 { wxT("wxCENTER"), wxCENTRE
},
2305 { wxT("wxUSER_COLOURS"), wxUSER_COLOURS
},
2306 { wxT("wxVERTICAL_LABEL"), 0},
2307 { wxT("wxHORIZONTAL_LABEL"), 0},
2309 // Bitmap types (not strictly styles)
2310 { wxT("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM
},
2311 { wxT("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM
},
2312 { wxT("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP
},
2313 { wxT("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2314 { wxT("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2315 { wxT("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF
},
2316 { wxT("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF
},
2317 { wxT("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO
},
2318 { wxT("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE
},
2319 { wxT("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR
},
2320 { wxT("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE
},
2321 { wxT("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA
},
2322 { wxT("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA
},
2323 { wxT("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY
}
2326 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2328 long wxParseWindowStyle(const wxString
& bitListString
)
2333 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2334 while (word
!= NULL
)
2338 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2339 if (wxStrcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2341 bitList
|= wxResourceBitListTable
[j
].bits
;
2347 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
2350 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2356 * Load a bitmap from a wxWindows resource, choosing an optimum
2357 * depth and appropriate type.
2360 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2363 table
= wxDefaultResourceTable
;
2365 wxItemResource
*item
= table
->FindResource(resource
);
2368 if ((item
->GetType() == wxT("")) || (item
->GetType() != wxT("wxBitmap")))
2370 wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar
*) resource
);
2371 return wxNullBitmap
;
2373 int thisDepth
= wxDisplayDepth();
2374 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2376 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2378 // Try to find optimum bitmap for this platform/colour depth
2379 wxNode
*node
= item
->GetChildren().First();
2382 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2383 int platform
= (int)child
->GetValue2();
2384 int noColours
= (int)child
->GetValue3();
2386 char *name = child->GetName();
2387 int bitmapType = (int)child->GetValue1();
2388 int xRes = child->GetWidth();
2389 int yRes = child->GetHeight();
2394 case RESOURCE_PLATFORM_ANY
:
2396 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2397 optResource
= child
;
2400 // Maximise the number of colours.
2401 // If noColours is zero (unspecified), then assume this
2402 // is the right one.
2403 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2404 optResource
= child
;
2409 case RESOURCE_PLATFORM_WINDOWS
:
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_X
:
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
;
2437 case RESOURCE_PLATFORM_MAC
:
2439 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2440 optResource
= child
;
2443 // Maximise the number of colours
2444 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2445 optResource
= child
;
2453 node
= node
->Next();
2455 // If no matching resource, fail.
2457 return wxNullBitmap
;
2459 wxString name
= optResource
->GetName();
2460 int bitmapType
= (int)optResource
->GetValue1();
2463 case wxBITMAP_TYPE_XBM_DATA
:
2466 wxItemResource
*item
= table
->FindResource(name
);
2469 wxLogWarning(_("Failed to find XBM resource %s.\n"
2470 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2471 return wxNullBitmap
;
2473 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2475 wxLogWarning(_("No XBM facility available!"));
2479 case wxBITMAP_TYPE_XPM_DATA
:
2481 wxItemResource
*item
= table
->FindResource(name
);
2484 wxLogWarning(_("Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2485 return wxNullBitmap
;
2487 return wxBitmap((char **)item
->GetValue1());
2491 #if defined(__WXPM__)
2492 return wxNullBitmap
;
2494 return wxBitmap(name
, (wxBitmapType
)bitmapType
);
2499 return wxNullBitmap
;
2504 wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar
*) resource
);
2505 return wxNullBitmap
;
2510 * Load an icon from a wxWindows resource, choosing an optimum
2511 * depth and appropriate type.
2514 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2517 table
= wxDefaultResourceTable
;
2519 wxItemResource
*item
= table
->FindResource(resource
);
2522 if ((item
->GetType() == wxT("")) || wxStrcmp(item
->GetType(), wxT("wxIcon")) != 0)
2524 wxLogWarning(_("%s not an icon resource specification."), (const wxChar
*) resource
);
2527 int thisDepth
= wxDisplayDepth();
2528 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2530 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2532 // Try to find optimum icon for this platform/colour depth
2533 wxNode
*node
= item
->GetChildren().First();
2536 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2537 int platform
= (int)child
->GetValue2();
2538 int noColours
= (int)child
->GetValue3();
2540 char *name = child->GetName();
2541 int bitmapType = (int)child->GetValue1();
2542 int xRes = child->GetWidth();
2543 int yRes = child->GetHeight();
2548 case RESOURCE_PLATFORM_ANY
:
2550 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2551 optResource
= child
;
2554 // Maximise the number of colours.
2555 // If noColours is zero (unspecified), then assume this
2556 // is the right one.
2557 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2558 optResource
= child
;
2563 case RESOURCE_PLATFORM_WINDOWS
:
2565 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2566 optResource
= child
;
2569 // Maximise the number of colours
2570 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2571 optResource
= child
;
2577 case RESOURCE_PLATFORM_X
:
2579 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2580 optResource
= child
;
2583 // Maximise the number of colours
2584 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2585 optResource
= child
;
2591 case RESOURCE_PLATFORM_MAC
:
2593 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2594 optResource
= child
;
2597 // Maximise the number of colours
2598 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2599 optResource
= child
;
2607 node
= node
->Next();
2609 // If no matching resource, fail.
2613 wxString name
= optResource
->GetName();
2614 int bitmapType
= (int)optResource
->GetValue1();
2617 case wxBITMAP_TYPE_XBM_DATA
:
2620 wxItemResource
*item
= table
->FindResource(name
);
2623 wxLogWarning(_("Failed to find XBM resource %s.\n"
2624 "Forgot to use wxResourceLoadIconData?"), (const wxChar
*) name
);
2627 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2629 wxLogWarning(_("No XBM facility available!"));
2633 case wxBITMAP_TYPE_XPM_DATA
:
2635 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2637 wxItemResource *item = table->FindResource(name);
2641 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2645 return wxIcon((char **)item->GetValue1());
2647 wxLogWarning(_("No XPM icon facility available!"));
2652 #if defined( __WXGTK__ ) || defined( __WXMOTIF__ )
2653 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2656 return wxIcon(name
, bitmapType
);
2664 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2671 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2673 wxMenu
*menu
= new wxMenu
;
2674 wxNode
*node
= item
->GetChildren().First();
2677 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2678 if ((child
->GetType() != wxT("")) && (child
->GetType() == wxT("wxMenuSeparator")))
2679 menu
->AppendSeparator();
2680 else if (child
->GetChildren().Number() > 0)
2682 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2684 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2688 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2690 node
= node
->Next();
2695 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2698 table
= wxDefaultResourceTable
;
2700 wxItemResource
*menuResource
= table
->FindResource(resource
);
2701 if (menuResource
&& (menuResource
->GetType() != wxT("")) && (menuResource
->GetType() == wxT("wxMenu")))
2704 menuBar
= new wxMenuBar
;
2705 wxNode
*node
= menuResource
->GetChildren().First();
2708 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2709 wxMenu
*menu
= wxResourceCreateMenu(child
);
2711 menuBar
->Append(menu
, child
->GetTitle());
2712 node
= node
->Next();
2716 return (wxMenuBar
*) NULL
;
2719 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2722 table
= wxDefaultResourceTable
;
2724 wxItemResource
*menuResource
= table
->FindResource(resource
);
2725 if (menuResource
&& (menuResource
->GetType() != wxT("")) && (menuResource
->GetType() == wxT("wxMenu")))
2726 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2727 return wxResourceCreateMenu(menuResource
);
2728 return (wxMenu
*) NULL
;
2731 #endif // wxUSE_MENUS
2733 // Global equivalents (so don't have to refer to default table explicitly)
2734 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2737 table
= wxDefaultResourceTable
;
2739 return table
->ParseResourceData(resource
);
2742 bool wxResourceParseData(const char* resource
, wxResourceTable
*table
)
2744 wxString
str(resource
, wxConvLibc
);
2746 table
= wxDefaultResourceTable
;
2748 return table
->ParseResourceData(str
);
2751 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2754 table
= wxDefaultResourceTable
;
2756 return table
->ParseResourceFile(filename
);
2759 // Register XBM/XPM data
2760 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2763 table
= wxDefaultResourceTable
;
2765 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2768 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2771 table
= wxDefaultResourceTable
;
2773 return table
->RegisterResourceBitmapData(name
, data
);
2776 void wxResourceClear(wxResourceTable
*table
)
2779 table
= wxDefaultResourceTable
;
2781 table
->ClearTable();
2788 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2791 table
= wxDefaultResourceTable
;
2793 table
->identifiers
.Put(name
, (wxObject
*)(long)value
);
2797 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2800 table
= wxDefaultResourceTable
;
2802 return (int)(long)table
->identifiers
.Get(name
);
2806 * Parse #include file for #defines (only)
2809 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2812 table
= wxDefaultResourceTable
;
2814 FILE *fd
= wxFopen(f
, wxT("r"));
2819 while (wxGetResourceToken(fd
))
2821 if (strcmp(wxResourceBuffer
, "#define") == 0)
2823 wxGetResourceToken(fd
);
2824 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2825 wxGetResourceToken(fd
);
2826 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2827 if (wxIsdigit(value
[0]))
2829 int val
= (int)wxAtol(value
);
2830 wxResourceAddIdentifier(name
, val
, table
);
2841 * Reading strings as if they were .wxr files
2844 static int getc_string(char *s
)
2846 int ch
= s
[wxResourceStringPtr
];
2851 wxResourceStringPtr
++;
2856 static int ungetc_string()
2858 wxResourceStringPtr
--;
2862 bool wxEatWhiteSpaceString(char *s
)
2866 while ((ch
= getc_string(s
)) != EOF
)
2878 ch
= getc_string(s
);
2889 while ((ch
= getc_string(s
)) != EOF
)
2891 if (ch
== '/' && prev_ch
== '*')
2913 bool wxGetResourceTokenString(char *s
)
2915 if (!wxResourceBuffer
)
2916 wxReallocateResourceBuffer();
2917 wxResourceBuffer
[0] = 0;
2918 wxEatWhiteSpaceString(s
);
2920 int ch
= getc_string(s
);
2924 wxResourceBufferCount
= 0;
2925 ch
= getc_string(s
);
2931 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2934 // Escaped characters
2935 else if (ch
== '\\')
2937 int newCh
= getc_string(s
);
2940 else if (newCh
== 10)
2948 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2949 wxReallocateResourceBuffer();
2950 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2951 wxResourceBufferCount
++;
2952 ch
= getc_string(s
);
2954 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2958 wxResourceBufferCount
= 0;
2960 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2962 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2963 wxReallocateResourceBuffer();
2964 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2965 wxResourceBufferCount
++;
2967 ch
= getc_string(s
);
2969 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2977 * Files are in form:
2978 static char *name = "....";
2979 with possible comments.
2982 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2985 table
= wxDefaultResourceTable
;
2987 // static or #define
2988 if (!wxGetResourceTokenString(s
))
2994 if (strcmp(wxResourceBuffer
, "#define") == 0)
2996 wxGetResourceTokenString(s
);
2997 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2998 wxGetResourceTokenString(s
);
2999 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
3000 if (wxIsdigit(value
[0]))
3002 int val
= (int)wxAtol(value
);
3003 wxResourceAddIdentifier(name
, val
, table
);
3007 wxLogWarning(_("#define %s must be an integer."), name
);
3018 else if (strcmp(wxResourceBuffer, "#include") == 0)
3020 wxGetResourceTokenString(s);
3021 char *name = copystring(wxResourceBuffer);
3022 char *actualName = name;
3024 actualName = name + 1;
3025 int len = strlen(name);
3026 if ((len > 0) && (name[len-1] == '"'))
3028 if (!wxResourceParseIncludeFile(actualName, table))
3031 sprintf(buf, _("Could not find resource include file %s."), actualName);
3038 else if (strcmp(wxResourceBuffer
, "static") != 0)
3041 wxStrcpy(buf
, _("Found "));
3042 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
3043 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
3049 if (!wxGetResourceTokenString(s
))
3051 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3056 if (strcmp(wxResourceBuffer
, "char") != 0)
3058 wxLogWarning(_("Expected 'char' whilst parsing resource."));
3063 if (!wxGetResourceTokenString(s
))
3065 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3070 if (wxResourceBuffer
[0] != '*')
3072 wxLogWarning(_("Expected '*' whilst parsing resource."));
3075 wxChar nameBuf
[100];
3076 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
3080 if (!wxGetResourceTokenString(s
))
3082 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3087 if (strcmp(wxResourceBuffer
, "=") != 0)
3089 wxLogWarning(_("Expected '=' whilst parsing resource."));
3094 if (!wxGetResourceTokenString(s
))
3096 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3102 if (!db
.ReadPrologFromString(wxResourceBuffer
))
3104 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
3109 if (!wxGetResourceTokenString(s
))
3116 bool wxResourceParseString(const wxString
& s
, wxResourceTable
*table
)
3119 return wxResourceParseString( (char*)s
.mb_str().data() );
3121 return wxResourceParseString( (char*)s
.c_str() );
3125 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
3128 table
= wxDefaultResourceTable
;
3133 // Turn backslashes into spaces
3136 int len
= strlen(s
);
3138 for (i
= 0; i
< len
; i
++)
3139 if (s
[i
] == 92 && s
[i
+1] == 13)
3147 wxResourceStringPtr
= 0;
3150 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
3154 return wxResourceInterpretResources(*table
, db
);
3158 * resource loading facility
3161 bool wxWindowBase::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
3164 table
= wxDefaultResourceTable
;
3166 wxItemResource
*resource
= table
->FindResource((const wxChar
*)resourceName
);
3167 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
3168 if (!resource
|| (resource
->GetType() == wxT("")) ||
3169 ! ((resource
->GetType() == wxT("wxDialog")) || (resource
->GetType() == wxT("wxPanel"))))
3172 wxString
title(resource
->GetTitle());
3173 long theWindowStyle
= resource
->GetStyle();
3174 bool isModal
= (resource
->GetValue1() != 0) ;
3175 int x
= resource
->GetX();
3176 int y
= resource
->GetY();
3177 int width
= resource
->GetWidth();
3178 int height
= resource
->GetHeight();
3179 wxString name
= resource
->GetName();
3181 // this is used for loading wxWizard pages from WXR
3182 if ( parent
!= this )
3184 if (IsKindOf(CLASSINFO(wxDialog
)))
3186 wxDialog
*dialogBox
= (wxDialog
*)this;
3187 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
3188 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
3191 // Only reset the client size if we know we're not going to do it again below.
3192 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
3193 dialogBox
->SetClientSize(width
, height
);
3195 else if (IsKindOf(CLASSINFO(wxPanel
)))
3197 wxPanel
* panel
= (wxPanel
*)this;
3198 if (!panel
->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
| wxTAB_TRAVERSAL
, name
))
3203 if (!((wxWindow
*)this)->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
3208 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
3210 // No need to do this since it's done in wxPanel or wxDialog constructor.
3211 // SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
3215 if (resource
->GetFont().Ok())
3216 SetFont(resource
->GetFont());
3217 if (resource
->GetBackgroundColour().Ok())
3218 SetBackgroundColour(resource
->GetBackgroundColour());
3221 // Should have some kind of font at this point
3222 if (!GetFont().Ok())
3223 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
3224 if (!GetBackgroundColour().Ok())
3225 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
3227 // Only when we've created the window and set the font can we set the correct size,
3228 // if based on dialog units.
3229 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
3231 wxSize sz
= ConvertDialogToPixels(wxSize(width
, height
));
3232 SetClientSize(sz
.x
, sz
.y
);
3234 wxPoint pt
= ConvertDialogToPixels(wxPoint(x
, y
));
3238 // Now create children
3239 wxNode
*node
= resource
->GetChildren().First();
3242 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
3244 (void) CreateItem(childResource
, resource
, table
);
3246 node
= node
->Next();
3251 wxControl
*wxWindowBase::CreateItem(const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
3254 table
= wxDefaultResourceTable
;
3255 return table
->CreateItem((wxWindow
*)this, resource
, parentResource
);
3259 #pragma warning(default:4706) // assignment within conditional expression
3265 #endif // wxUSE_WX_RESOURCES