1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Resource system
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "resource.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #if wxUSE_WX_RESOURCES
26 #pragma warning(disable:4706) // assignment within conditional expression
34 #include "wx/gdicmn.h"
38 #include "wx/stattext.h"
39 #include "wx/button.h"
40 #include "wx/bmpbuttn.h"
41 #include "wx/radiobox.h"
42 #include "wx/listbox.h"
43 #include "wx/choice.h"
44 #include "wx/checkbox.h"
45 #include "wx/settings.h"
46 #include "wx/slider.h"
48 #include "wx/statbox.h"
49 #include "wx/statbmp.h"
51 #include "wx/textctrl.h"
52 #include "wx/msgdlg.h"
56 #include "wx/treebase.h"
57 #include "wx/listctrl.h"
60 #include "wx/radiobut.h"
64 #include "wx/scrolbar.h"
68 #include "wx/combobox.h"
71 #include "wx/validate.h"
80 #include "wx/resource.h"
81 #include "wx/string.h"
82 #include "wx/wxexpr.h"
84 #include "wx/settings.h"
85 #include "wx/stream.h"
87 // Forward (private) declarations
88 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
);
89 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
= FALSE
);
90 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
);
91 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
);
92 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
);
93 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, wxExpr
*expr
);
94 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, wxExpr
*expr
);
95 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
);
96 // Interpret list expression
97 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
);
99 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
100 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
) ;
101 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
103 wxResourceTable
*wxDefaultResourceTable
= (wxResourceTable
*) NULL
;
105 char *wxResourceBuffer
= (char *) NULL
;
106 long wxResourceBufferSize
= 0;
107 long wxResourceBufferCount
= 0;
108 int wxResourceStringPtr
= 0;
110 void wxInitializeResourceSystem()
112 wxDefaultResourceTable
= new wxResourceTable
;
115 void wxCleanUpResourceSystem()
117 delete wxDefaultResourceTable
;
118 if (wxResourceBuffer
)
119 delete[] wxResourceBuffer
;
123 void wxLogWarning(char *msg
)
125 wxMessageBox(msg
, _("Warning"), wxOK
);
129 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
130 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
132 wxItemResource::wxItemResource()
134 m_itemType
= wxT("");
138 m_x
= m_y
= m_width
= m_height
= 0;
139 m_value1
= m_value2
= m_value3
= m_value5
= 0;
145 wxItemResource::~wxItemResource()
147 wxNode
*node
= m_children
.First();
150 wxItemResource
*item
= (wxItemResource
*)node
->Data();
153 node
= m_children
.First();
161 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
165 wxResourceTable::~wxResourceTable()
170 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
172 wxItemResource
*item
= (wxItemResource
*)Get(WXSTRINGCAST name
);
176 void wxResourceTable::AddResource(wxItemResource
*item
)
178 wxString name
= item
->GetName();
180 name
= item
->GetTitle();
182 name
= wxT("no name");
184 // Delete existing resource, if any.
190 bool wxResourceTable::DeleteResource(const wxString
& name
)
192 wxItemResource
*item
= (wxItemResource
*)Delete(WXSTRINGCAST name
);
195 // See if any resource has this as its child; if so, delete from
196 // parent's child list.
198 wxNode
*node
= (wxNode
*) NULL
;
202 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
203 if (parent
->GetChildren().Member(item
))
205 parent
->GetChildren().DeleteObject(item
);
218 bool wxResourceTable::ParseResourceFile( wxInputStream
*is
)
221 int len
= is
->GetSize() ;
224 while ( is
->TellI() + 10 < len
) // it's a hack because the streams dont support EOF
226 wxResourceReadOneResource(is
, db
, &eof
, this) ;
228 return wxResourceInterpretResources(*this, db
);
231 bool wxResourceTable::ParseResourceFile(const wxString
& filename
)
235 FILE *fd
= wxFopen(filename
, wxT("r"));
239 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
244 return wxResourceInterpretResources(*this, db
);
247 bool wxResourceTable::ParseResourceData(const wxString
& data
)
250 if (!db
.ReadFromString(data
))
252 wxLogWarning(_("Ill-formed resource file syntax."));
256 return wxResourceInterpretResources(*this, db
);
259 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char bits
[], int width
, int height
)
261 // Register pre-loaded bitmap data
262 wxItemResource
*item
= new wxItemResource
;
263 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
264 item
->SetType(wxT("wxXBMData"));
266 item
->SetValue1((long)bits
);
267 item
->SetValue2((long)width
);
268 item
->SetValue3((long)height
);
273 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char **data
)
275 // Register pre-loaded bitmap data
276 wxItemResource
*item
= new wxItemResource
;
277 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
278 item
->SetType(wxT("wxXPMData"));
280 item
->SetValue1((long)data
);
285 bool wxResourceTable::SaveResource(const wxString
& WXUNUSED(filename
))
290 void wxResourceTable::ClearTable()
293 wxNode
*node
= Next();
296 wxNode
*next
= Next();
297 wxItemResource
*item
= (wxItemResource
*)node
->Data();
304 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, const wxItemResource
* childResource
, const wxItemResource
* parentResource
) const
306 int id
= childResource
->GetId();
310 bool dlgUnits
= ((parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0);
312 wxControl
*control
= (wxControl
*) NULL
;
313 wxString
itemType(childResource
->GetType());
319 pos
= parent
->ConvertDialogToPixels(wxPoint(childResource
->GetX(), childResource
->GetY()));
320 size
= parent
->ConvertDialogToPixels(wxSize(childResource
->GetWidth(), childResource
->GetHeight()));
324 pos
= wxPoint(childResource
->GetX(), childResource
->GetY());
325 size
= wxSize(childResource
->GetWidth(), childResource
->GetHeight());
328 if (itemType
== wxString(wxT("wxButton")) || itemType
== wxString(wxT("wxBitmapButton")))
330 if (childResource
->GetValue4() != wxT(""))
333 wxBitmap bitmap
= childResource
->GetBitmap();
336 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
337 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
340 #if defined(__WXPM__)
342 // OS/2 uses integer id's to access resources, not file name strings
344 bitmap
.LoadFile(wxCROSS_BITMAP
, wxBITMAP_TYPE_BMP_RESOURCE
);
346 bitmap
.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE
);
348 control
= new wxBitmapButton(parent
, id
, bitmap
, pos
, size
,
349 childResource
->GetStyle() | wxBU_AUTODRAW
, wxDefaultValidator
, childResource
->GetName());
352 // Normal, text button
353 control
= new wxButton(parent
, id
, childResource
->GetTitle(), pos
, size
,
354 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
356 else if (itemType
== wxString(wxT("wxMessage")) || itemType
== wxString(wxT("wxStaticText")) ||
357 itemType
== wxString(wxT("wxStaticBitmap")))
359 if (childResource
->GetValue4() != wxT("") || itemType
== wxString(wxT("wxStaticBitmap")) )
362 wxBitmap bitmap
= childResource
->GetBitmap();
365 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
366 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
368 #if wxUSE_BITMAP_MESSAGE
370 // Use a default bitmap
372 bitmap
.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE
);
376 control
= new wxStaticBitmap(parent
, id
, bitmap
, pos
, size
,
377 childResource
->GetStyle(), childResource
->GetName());
382 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(), pos
, size
,
383 childResource
->GetStyle(), childResource
->GetName());
386 else if (itemType
== wxString(wxT("wxText")) || itemType
== wxString(wxT("wxTextCtrl")) || itemType
== wxString(wxT("wxMultiText")))
388 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), pos
, size
,
389 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
391 else if (itemType
== wxString(wxT("wxCheckBox")))
393 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
394 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
396 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
399 else if (itemType
== wxString(wxT("wxGauge")))
401 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(), pos
, size
,
402 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
404 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
408 else if (itemType
== wxString(wxT("wxRadioButton")))
410 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
412 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
416 else if (itemType
== wxString(wxT("wxScrollBar")))
418 control
= new wxScrollBar(parent
, id
, pos
, size
,
419 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
421 ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1());
422 ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2());
423 ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3());
424 ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5());
426 ((wxScrollBar
*)control
)->SetScrollbar((int)childResource
->GetValue1(),(int)childResource
->GetValue2(),
427 (int)childResource
->GetValue3(),(int)(long)childResource
->GetValue5(),FALSE
);
431 else if (itemType
== wxString(wxT("wxSlider")))
433 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
434 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), pos
, size
,
435 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
437 else if (itemType
== wxString(wxT("wxGroupBox")) || itemType
== wxString(wxT("wxStaticBox")))
439 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
440 childResource
->GetStyle(), childResource
->GetName());
442 else if (itemType
== wxString(wxT("wxListBox")))
444 wxStringList
& stringList
= childResource
->GetStringValues();
445 wxString
*strings
= (wxString
*) NULL
;
447 if (stringList
.Number() > 0)
449 noStrings
= stringList
.Number();
450 strings
= new wxString
[noStrings
];
451 wxNode
*node
= stringList
.First();
455 strings
[i
] = (wxChar
*)node
->Data();
460 control
= new wxListBox(parent
, id
, pos
, size
,
461 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
466 else if (itemType
== wxString(wxT("wxChoice")))
468 wxStringList
& stringList
= childResource
->GetStringValues();
469 wxString
*strings
= (wxString
*) NULL
;
471 if (stringList
.Number() > 0)
473 noStrings
= stringList
.Number();
474 strings
= new wxString
[noStrings
];
475 wxNode
*node
= stringList
.First();
479 strings
[i
] = (wxChar
*)node
->Data();
484 control
= new wxChoice(parent
, id
, pos
, size
,
485 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
491 else if (itemType
== wxString(wxT("wxComboBox")))
493 wxStringList
& stringList
= childResource
->GetStringValues();
494 wxString
*strings
= (wxString
*) NULL
;
496 if (stringList
.Number() > 0)
498 noStrings
= stringList
.Number();
499 strings
= new wxString
[noStrings
];
500 wxNode
*node
= stringList
.First();
504 strings
[i
] = (wxChar
*)node
->Data();
509 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(), pos
, size
,
510 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
516 else if (itemType
== wxString(wxT("wxRadioBox")))
518 wxStringList
& stringList
= childResource
->GetStringValues();
519 wxString
*strings
= (wxString
*) NULL
;
521 if (stringList
.Number() > 0)
523 noStrings
= stringList
.Number();
524 strings
= new wxString
[noStrings
];
525 wxNode
*node
= stringList
.First();
529 strings
[i
] = (wxChar
*)node
->Data();
534 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), pos
, size
,
535 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
536 childResource
->GetName());
542 if ((parentResource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
544 // Don't set font; will be inherited from parent.
548 if (control
&& childResource
->GetFont().Ok())
550 control
->SetFont(childResource
->GetFont());
553 // Force the layout algorithm since the size changes the layout
554 if (control
->IsKindOf(CLASSINFO(wxRadioBox
)))
556 control
->SetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
|wxSIZE_AUTO_HEIGHT
);
565 * Interpret database as a series of resources
568 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
)
570 wxNode
*node
= db
.First();
573 wxExpr
*clause
= (wxExpr
*)node
->Data();
574 wxString
functor(clause
->Functor());
576 wxItemResource
*item
= (wxItemResource
*) NULL
;
577 if (functor
== wxT("dialog"))
578 item
= wxResourceInterpretDialog(table
, clause
);
579 else if (functor
== wxT("panel"))
580 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
581 else if (functor
== wxT("menubar"))
582 item
= wxResourceInterpretMenuBar(table
, clause
);
583 else if (functor
== wxT("menu"))
584 item
= wxResourceInterpretMenu(table
, clause
);
585 else if (functor
== wxT("string"))
586 item
= wxResourceInterpretString(table
, clause
);
587 else if (functor
== wxT("bitmap"))
588 item
= wxResourceInterpretBitmap(table
, clause
);
589 else if (functor
== wxT("icon"))
590 item
= wxResourceInterpretIcon(table
, clause
);
594 // Remove any existing resource of same name
595 if (item
->GetName() != wxT(""))
596 table
.DeleteResource(item
->GetName());
597 table
.AddResource(item
);
604 static const wxChar
*g_ValidControlClasses
[] =
607 wxT("wxBitmapButton"),
610 wxT("wxStaticBitmap"),
616 wxT("wxRadioButton"),
618 wxT("wxBitmapCheckBox"),
628 static bool wxIsValidControlClass(const wxString
& c
)
630 for ( size_t i
= 0; i
< WXSIZEOF(g_ValidControlClasses
); i
++ )
632 if ( c
== g_ValidControlClasses
[i
] )
638 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
640 wxItemResource
*dialogItem
= new wxItemResource
;
642 dialogItem
->SetType(wxT("wxPanel"));
644 dialogItem
->SetType(wxT("wxDialog"));
645 wxString style
= wxT("");
646 wxString title
= wxT("");
647 wxString name
= wxT("");
648 wxString backColourHex
= wxT("");
649 wxString labelColourHex
= wxT("");
650 wxString buttonColourHex
= wxT("");
652 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
656 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
658 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
659 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
660 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
661 expr
->GetAttributeValue(wxT("style"), style
);
662 expr
->GetAttributeValue(wxT("name"), name
);
663 expr
->GetAttributeValue(wxT("title"), title
);
664 expr
->GetAttributeValue(wxT("x"), x
);
665 expr
->GetAttributeValue(wxT("y"), y
);
666 expr
->GetAttributeValue(wxT("width"), width
);
667 expr
->GetAttributeValue(wxT("height"), height
);
668 expr
->GetAttributeValue(wxT("modal"), isModal
);
669 expr
->GetAttributeValue(wxT("label_font"), &labelFontExpr
);
670 expr
->GetAttributeValue(wxT("button_font"), &buttonFontExpr
);
671 expr
->GetAttributeValue(wxT("font"), &fontExpr
);
672 expr
->GetAttributeValue(wxT("background_colour"), backColourHex
);
673 expr
->GetAttributeValue(wxT("label_colour"), labelColourHex
);
674 expr
->GetAttributeValue(wxT("button_colour"), buttonColourHex
);
676 int useDialogUnits
= 0;
677 expr
->GetAttributeValue(wxT("use_dialog_units"), useDialogUnits
);
678 if (useDialogUnits
!= 0)
679 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
682 expr
->GetAttributeValue(wxT("use_system_defaults"), useDefaults
);
683 if (useDefaults
!= 0)
684 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
687 expr
->GetAttributeValue(wxT("id"), id
);
688 dialogItem
->SetId(id
);
690 if (style
!= wxT(""))
692 windowStyle
= wxParseWindowStyle(style
);
694 dialogItem
->SetStyle(windowStyle
);
695 dialogItem
->SetValue1(isModal
);
696 if (windowStyle
& wxDIALOG_MODAL
) // Uses style in wxWin 2
697 dialogItem
->SetValue1(TRUE
);
699 dialogItem
->SetName(name
);
700 dialogItem
->SetTitle(title
);
701 dialogItem
->SetSize(x
, y
, width
, height
);
703 // Check for wxWin 1.68-style specifications
704 if (style
.Find(wxT("VERTICAL_LABEL")) != -1)
705 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
706 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != -1)
707 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
709 if (backColourHex
!= wxT(""))
714 r
= wxHexToDec(backColourHex
.Mid(0, 2));
715 g
= wxHexToDec(backColourHex
.Mid(2, 2));
716 b
= wxHexToDec(backColourHex
.Mid(4, 2));
717 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
719 if (labelColourHex
!= wxT(""))
724 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
725 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
726 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
727 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
729 if (buttonColourHex
!= wxT(""))
734 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
735 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
736 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
737 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
741 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
742 else if (buttonFontExpr
)
743 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
744 else if (labelFontExpr
)
745 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
747 // Now parse all controls
748 wxExpr
*controlExpr
= expr
->GetFirst();
751 if (controlExpr
->Number() == 3)
753 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
754 if (controlKeyword
!= wxT("") && controlKeyword
== wxT("control"))
756 // The value part: always a list.
757 wxExpr
*listExpr
= controlExpr
->Nth(2);
758 if (listExpr
->Type() == PrologList
)
760 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
763 dialogItem
->GetChildren().Append(controlItem
);
768 controlExpr
= controlExpr
->GetNext();
773 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
775 wxItemResource
*controlItem
= new wxItemResource
;
777 // First, find the standard features of a control definition:
778 // [optional integer/string id], control name, title, style, name, x, y, width, height
780 wxString controlType
;
785 long windowStyle
= 0;
786 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
789 wxExpr
*expr1
= expr
->Nth(0);
791 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
793 if ( wxIsValidControlClass(expr1
->StringValue()) )
796 controlType
= expr1
->StringValue();
800 wxString
str(expr1
->StringValue());
801 id
= wxResourceGetIdentifier(str
, &table
);
804 wxLogWarning(_("Could not resolve control class or id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)"),
805 (const wxChar
*) expr1
->StringValue());
807 return (wxItemResource
*) NULL
;
811 // Success - we have an id, so the 2nd element must be the control class.
812 controlType
= expr
->Nth(1)->StringValue();
817 else if (expr1
->Type() == PrologInteger
)
819 id
= (int)expr1
->IntegerValue();
820 // Success - we have an id, so the 2nd element must be the control class.
821 controlType
= expr
->Nth(1)->StringValue();
825 expr1
= expr
->Nth(count
);
828 title
= expr1
->StringValue();
830 expr1
= expr
->Nth(count
);
834 style
= expr1
->StringValue();
835 windowStyle
= wxParseWindowStyle(style
);
838 expr1
= expr
->Nth(count
);
841 name
= expr1
->StringValue();
843 expr1
= expr
->Nth(count
);
846 x
= (int)expr1
->IntegerValue();
848 expr1
= expr
->Nth(count
);
851 y
= (int)expr1
->IntegerValue();
853 expr1
= expr
->Nth(count
);
856 width
= (int)expr1
->IntegerValue();
858 expr1
= expr
->Nth(count
);
861 height
= (int)expr1
->IntegerValue();
863 controlItem
->SetStyle(windowStyle
);
864 controlItem
->SetName(name
);
865 controlItem
->SetTitle(title
);
866 controlItem
->SetSize(x
, y
, width
, height
);
867 controlItem
->SetType(controlType
);
868 controlItem
->SetId(id
);
870 // Check for wxWin 1.68-style specifications
871 if (style
.Find(wxT("VERTICAL_LABEL")) != -1)
872 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
873 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != -1)
874 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
876 if (controlType
== wxT("wxButton"))
878 // Check for bitmap resource name (in case loading old-style resource file)
879 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
881 wxString
str(expr
->Nth(count
)->StringValue());
886 controlItem
->SetValue4(str
);
887 controlItem
->SetType(wxT("wxBitmapButton"));
890 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
891 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
893 else if (controlType
== wxT("wxBitmapButton"))
895 // Check for bitmap resource name
896 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
898 wxString
str(expr
->Nth(count
)->StringValue());
899 controlItem
->SetValue4(str
);
901 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
902 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
905 else if (controlType
== wxT("wxCheckBox"))
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("wxRadioButton"))
919 // Check for default value
920 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
922 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
924 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
925 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
929 else if (controlType
== wxT("wxText") || controlType
== wxT("wxTextCtrl") || controlType
== wxT("wxMultiText"))
931 // Check for default value
932 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
934 wxString
str(expr
->Nth(count
)->StringValue());
935 controlItem
->SetValue4(str
);
938 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
940 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
941 // Skip past the obsolete label font spec if there are two consecutive specs
942 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
944 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
948 else if (controlType
== wxT("wxMessage") || controlType
== wxT("wxStaticText"))
950 // Check for bitmap resource name (in case it's an old-style .wxr file)
951 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
953 wxString
str(expr
->Nth(count
)->StringValue());
954 controlItem
->SetValue4(str
);
956 controlItem
->SetType(wxT("wxStaticText"));
958 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
959 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
961 else if (controlType
== wxT("wxStaticBitmap"))
963 // Check for bitmap resource name
964 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
966 wxString
str(expr
->Nth(count
)->StringValue());
967 controlItem
->SetValue4(str
);
970 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
971 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
973 else if (controlType
== wxT("wxGroupBox") || controlType
== wxT("wxStaticBox"))
975 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
976 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
978 else if (controlType
== wxT("wxGauge"))
980 // Check for default value
981 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
983 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
987 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
989 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
992 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
994 // Skip past the obsolete label font spec if there are two consecutive specs
995 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
997 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1002 else if (controlType
== wxT("wxSlider"))
1004 // Check for default value
1005 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1007 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1011 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1013 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1017 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1019 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1022 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1024 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1028 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1029 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1035 else if (controlType
== wxT("wxScrollBar"))
1038 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1040 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1044 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1046 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1050 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1052 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1056 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1057 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1062 else if (controlType
== wxT("wxListBox"))
1064 wxExpr
*valueList
= (wxExpr
*) NULL
;
1066 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1068 wxStringList stringList
;
1069 wxExpr
*stringExpr
= valueList
->GetFirst();
1072 stringList
.Add(stringExpr
->StringValue());
1073 stringExpr
= stringExpr
->GetNext();
1075 controlItem
->SetStringValues(stringList
);
1077 // This is now obsolete: it's in the window style.
1078 // Check for wxSINGLE/wxMULTIPLE
1079 wxExpr
*mult
= (wxExpr
*) NULL
;
1081 controlItem->SetValue1(wxLB_SINGLE);
1083 if (((mult
= expr
->Nth(count
)) != 0) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1086 wxString m(mult->StringValue());
1087 if (m == "wxLB_MULTIPLE")
1088 controlItem->SetValue1(wxLB_MULTIPLE);
1089 else if (m == "wxLB_EXTENDED")
1090 controlItem->SetValue1(wxLB_EXTENDED);
1095 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1097 // Skip past the obsolete label font spec if there are two consecutive specs
1098 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1100 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1104 else if (controlType
== wxT("wxChoice"))
1106 wxExpr
*valueList
= (wxExpr
*) NULL
;
1107 // Check for default value list
1108 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1110 wxStringList stringList
;
1111 wxExpr
*stringExpr
= valueList
->GetFirst();
1114 stringList
.Add(stringExpr
->StringValue());
1115 stringExpr
= stringExpr
->GetNext();
1117 controlItem
->SetStringValues(stringList
);
1121 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1123 // Skip past the obsolete label font spec if there are two consecutive specs
1124 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1126 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1131 else if (controlType
== wxT("wxComboBox"))
1133 wxExpr
*textValue
= expr
->Nth(count
);
1134 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1136 wxString
str(textValue
->StringValue());
1137 controlItem
->SetValue4(str
);
1141 wxExpr
*valueList
= (wxExpr
*) NULL
;
1142 // Check for default value list
1143 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1145 wxStringList stringList
;
1146 wxExpr
*stringExpr
= valueList
->GetFirst();
1149 stringList
.Add(stringExpr
->StringValue());
1150 stringExpr
= stringExpr
->GetNext();
1152 controlItem
->SetStringValues(stringList
);
1156 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1158 // Skip past the obsolete label font spec if there are two consecutive specs
1159 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1161 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1168 else if (controlType
== wxT("wxRadioBox"))
1170 wxExpr
*valueList
= (wxExpr
*) NULL
;
1171 // Check for default value list
1172 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1174 wxStringList stringList
;
1175 wxExpr
*stringExpr
= valueList
->GetFirst();
1178 stringList
.Add(stringExpr
->StringValue());
1179 stringExpr
= stringExpr
->GetNext();
1181 controlItem
->SetStringValues(stringList
);
1184 // majorDim (number of rows or cols)
1185 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1187 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1191 controlItem
->SetValue1(0);
1193 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1195 // Skip past the obsolete label font spec if there are two consecutive specs
1196 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1198 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1206 return (wxItemResource
*) NULL
;
1211 // Forward declaration
1212 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1215 * Interpet a menu item
1218 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1220 wxItemResource
*item
= new wxItemResource
;
1222 wxExpr
*labelExpr
= expr
->Nth(0);
1223 wxExpr
*idExpr
= expr
->Nth(1);
1224 wxExpr
*helpExpr
= expr
->Nth(2);
1225 wxExpr
*checkableExpr
= expr
->Nth(3);
1227 // Further keywords/attributes to follow sometime...
1228 if (expr
->Number() == 0)
1230 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1231 item
->SetType(wxT("wxMenuSeparator"));
1236 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1237 item
->SetType(wxT("wxMenu")); // Well, menu item, but doesn't matter.
1240 wxString
str(labelExpr
->StringValue());
1241 item
->SetTitle(str
);
1246 // If a string or word, must look up in identifier table.
1247 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1249 wxString
str(idExpr
->StringValue());
1250 id
= wxResourceGetIdentifier(str
, &table
);
1253 wxLogWarning(_("Could not resolve menu id '%s'. Use (non-zero) integer instead\nor provide #define (see manual for caveats)"),
1254 (const wxChar
*) idExpr
->StringValue());
1257 else if (idExpr
->Type() == PrologInteger
)
1258 id
= (int)idExpr
->IntegerValue();
1259 item
->SetValue1(id
);
1263 wxString
str(helpExpr
->StringValue());
1264 item
->SetValue4(str
);
1267 item
->SetValue2(checkableExpr
->IntegerValue());
1269 // Find the first expression that's a list, for submenu
1270 wxExpr
*subMenuExpr
= expr
->GetFirst();
1271 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1272 subMenuExpr
= subMenuExpr
->GetNext();
1276 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1277 item
->GetChildren().Append(child
);
1278 subMenuExpr
= subMenuExpr
->GetNext();
1285 * Interpret a nested list as a menu
1288 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1290 wxItemResource *menu = new wxItemResource;
1291 // menu->SetType(wxTYPE_MENU);
1292 menu->SetType("wxMenu");
1293 wxExpr *element = expr->GetFirst();
1296 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1298 menu->GetChildren().Append(item);
1299 element = element->GetNext();
1305 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1307 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1308 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1310 return (wxItemResource
*) NULL
;
1312 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1315 return (wxItemResource
*) NULL
;
1318 if (expr
->GetAttributeValue(wxT("name"), name
))
1320 menuResource
->SetName(name
);
1323 return menuResource
;
1326 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1328 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1329 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1331 return (wxItemResource
*) NULL
;
1333 wxItemResource
*resource
= new wxItemResource
;
1334 resource
->SetType(wxT("wxMenu"));
1335 // resource->SetType(wxTYPE_MENU);
1337 wxExpr
*element
= listExpr
->GetFirst();
1340 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1341 resource
->GetChildren().Append(menuResource
);
1342 element
= element
->GetNext();
1346 if (expr
->GetAttributeValue(wxT("name"), name
))
1348 resource
->SetName(name
);
1354 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1356 return (wxItemResource
*) NULL
;
1359 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1361 wxItemResource
*bitmapItem
= new wxItemResource
;
1362 // bitmapItem->SetType(wxTYPE_BITMAP);
1363 bitmapItem
->SetType(wxT("wxBitmap"));
1365 if (expr
->GetAttributeValue(wxT("name"), name
))
1367 bitmapItem
->SetName(name
);
1369 // Now parse all bitmap specifications
1370 wxExpr
*bitmapExpr
= expr
->GetFirst();
1373 if (bitmapExpr
->Number() == 3)
1375 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1376 if (bitmapKeyword
== wxT("bitmap") || bitmapKeyword
== wxT("icon"))
1378 // The value part: always a list.
1379 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1380 if (listExpr
->Type() == PrologList
)
1382 wxItemResource
*bitmapSpec
= new wxItemResource
;
1383 // bitmapSpec->SetType(wxTYPE_BITMAP);
1384 bitmapSpec
->SetType(wxT("wxBitmap"));
1386 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1387 // where everything after 'filename' is optional.
1388 wxExpr
*nameExpr
= listExpr
->Nth(0);
1389 wxExpr
*typeExpr
= listExpr
->Nth(1);
1390 wxExpr
*platformExpr
= listExpr
->Nth(2);
1391 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1392 wxExpr
*xresExpr
= listExpr
->Nth(4);
1393 wxExpr
*yresExpr
= listExpr
->Nth(5);
1394 if (nameExpr
&& nameExpr
->StringValue() != wxT(""))
1396 bitmapSpec
->SetName(nameExpr
->StringValue());
1398 if (typeExpr
&& typeExpr
->StringValue() != wxT(""))
1400 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1403 bitmapSpec
->SetValue1(0);
1405 if (platformExpr
&& platformExpr
->StringValue() != wxT(""))
1407 wxString
plat(platformExpr
->StringValue());
1408 if (plat
== wxT("windows") || plat
== wxT("WINDOWS"))
1409 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1410 else if (plat
== wxT("x") || plat
== wxT("X"))
1411 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1412 else if (plat
== wxT("mac") || plat
== wxT("MAC"))
1413 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1415 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1418 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1421 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1425 xres
= (int)xresExpr
->IntegerValue();
1427 yres
= (int)yresExpr
->IntegerValue();
1428 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1430 bitmapItem
->GetChildren().Append(bitmapSpec
);
1434 bitmapExpr
= bitmapExpr
->GetNext();
1440 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1442 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1445 // item->SetType(wxTYPE_ICON);
1446 item
->SetType(wxT("wxIcon"));
1450 return (wxItemResource
*) NULL
;
1453 // Interpret list expression as a font
1454 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1456 if (expr
->Type() != PrologList
)
1460 int family
= wxSWISS
;
1461 int style
= wxNORMAL
;
1462 int weight
= wxNORMAL
;
1464 wxString
faceName(wxT(""));
1466 wxExpr
*pointExpr
= expr
->Nth(0);
1467 wxExpr
*familyExpr
= expr
->Nth(1);
1468 wxExpr
*styleExpr
= expr
->Nth(2);
1469 wxExpr
*weightExpr
= expr
->Nth(3);
1470 wxExpr
*underlineExpr
= expr
->Nth(4);
1471 wxExpr
*faceNameExpr
= expr
->Nth(5);
1473 point
= (int)pointExpr
->IntegerValue();
1478 str
= familyExpr
->StringValue();
1479 family
= (int)wxParseWindowStyle(str
);
1483 str
= styleExpr
->StringValue();
1484 style
= (int)wxParseWindowStyle(str
);
1488 str
= weightExpr
->StringValue();
1489 weight
= (int)wxParseWindowStyle(str
);
1492 underline
= (int)underlineExpr
->IntegerValue();
1494 faceName
= faceNameExpr
->StringValue();
1496 return *wxTheFontList
->FindOrCreateFont(point
, family
, style
, weight
,
1497 (underline
!= 0), faceName
);
1500 // Separate file for the remainder of this, for BC++/Win16
1502 #if !((defined(__BORLANDC__) || defined(__SC__)) && defined(__WIN16__))
1504 * (Re)allocate buffer for reading in from resource file
1507 bool wxReallocateResourceBuffer()
1509 if (!wxResourceBuffer
)
1511 wxResourceBufferSize
= 1000;
1512 wxResourceBuffer
= new char[wxResourceBufferSize
];
1515 if (wxResourceBuffer
)
1517 long newSize
= wxResourceBufferSize
+ 1000;
1518 char *tmp
= new char[(int)newSize
];
1519 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1520 delete[] wxResourceBuffer
;
1521 wxResourceBuffer
= tmp
;
1522 wxResourceBufferSize
= newSize
;
1527 static bool wxEatWhiteSpace(FILE *fd
)
1531 while ((ch
= getc(fd
)) != EOF
)
1546 ungetc(prev_ch
, fd
);
1554 while ((ch
= getc(fd
)) != EOF
)
1556 if (ch
== '/' && prev_ch
== '*')
1564 static char buffer
[255];
1565 fgets(buffer
, 255, fd
);
1569 ungetc(prev_ch
, fd
);
1583 static bool wxEatWhiteSpace(wxInputStream
*is
)
1585 int ch
= is
->GetC() ;
1586 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1593 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1595 // Check for comment
1601 bool finished
= FALSE
;
1609 int newCh
= is
->GetC();
1624 return wxEatWhiteSpace(is
);
1627 bool wxGetResourceToken(FILE *fd
)
1629 if (!wxResourceBuffer
)
1630 wxReallocateResourceBuffer();
1631 wxResourceBuffer
[0] = 0;
1632 wxEatWhiteSpace(fd
);
1638 wxResourceBufferCount
= 0;
1645 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1648 // Escaped characters
1649 else if (ch
== '\\')
1651 int newCh
= getc(fd
);
1654 else if (newCh
== 10)
1662 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1663 wxReallocateResourceBuffer();
1664 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1665 wxResourceBufferCount
++;
1668 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1672 wxResourceBufferCount
= 0;
1674 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1676 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1677 wxReallocateResourceBuffer();
1678 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1679 wxResourceBufferCount
++;
1683 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1690 bool wxGetResourceToken(wxInputStream
*is
)
1692 if (!wxResourceBuffer
)
1693 wxReallocateResourceBuffer();
1694 wxResourceBuffer
[0] = 0;
1695 wxEatWhiteSpace(is
);
1697 int ch
= is
->GetC() ;
1701 wxResourceBufferCount
= 0;
1708 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1711 // Escaped characters
1712 else if (ch
== '\\')
1714 int newCh
= is
->GetC();
1717 else if (newCh
== 10)
1719 else if (newCh
== 13) // mac
1727 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1728 wxReallocateResourceBuffer();
1729 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1730 wxResourceBufferCount
++;
1733 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1737 wxResourceBufferCount
= 0;
1739 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1741 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1742 wxReallocateResourceBuffer();
1743 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1744 wxResourceBufferCount
++;
1748 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1756 * Files are in form:
1757 static char *name = "....";
1758 with possible comments.
1761 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1764 table
= wxDefaultResourceTable
;
1766 // static or #define
1767 if (!wxGetResourceToken(fd
))
1773 if (strcmp(wxResourceBuffer
, "#define") == 0)
1775 wxGetResourceToken(fd
);
1776 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1777 wxGetResourceToken(fd
);
1778 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1779 if (wxIsdigit(value
[0]))
1781 int val
= (int)wxAtol(value
);
1782 wxResourceAddIdentifier(name
, val
, table
);
1786 wxLogWarning(_("#define %s must be an integer."), name
);
1796 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1798 wxGetResourceToken(fd
);
1799 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1800 wxChar
*actualName
= name
;
1801 if (name
[0] == wxT('"'))
1802 actualName
= name
+ 1;
1803 int len
= wxStrlen(name
);
1804 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1806 if (!wxResourceParseIncludeFile(actualName
, table
))
1808 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1813 else if (strcmp(wxResourceBuffer
, "static") != 0)
1816 wxStrcpy(buf
, _("Found "));
1817 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
1818 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1824 if (!wxGetResourceToken(fd
))
1826 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1831 if (strcmp(wxResourceBuffer
, "char") != 0)
1833 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1838 if (!wxGetResourceToken(fd
))
1840 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1845 if (wxResourceBuffer
[0] != '*')
1847 wxLogWarning(_("Expected '*' whilst parsing resource."));
1850 wxChar nameBuf
[100];
1851 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
1855 if (!wxGetResourceToken(fd
))
1857 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1862 if (strcmp(wxResourceBuffer
, "=") != 0)
1864 wxLogWarning(_("Expected '=' whilst parsing resource."));
1869 if (!wxGetResourceToken(fd
))
1871 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1877 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1879 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1884 if (!wxGetResourceToken(fd
))
1891 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1894 table
= wxDefaultResourceTable
;
1896 // static or #define
1897 if (!wxGetResourceToken(fd
))
1903 if (strcmp(wxResourceBuffer
, "#define") == 0)
1905 wxGetResourceToken(fd
);
1906 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1907 wxGetResourceToken(fd
);
1908 wxChar
*value
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1909 if (wxIsalpha(value
[0]))
1911 int val
= (int)wxAtol(value
);
1912 wxResourceAddIdentifier(name
, val
, table
);
1916 wxLogWarning(_("#define %s must be an integer."), name
);
1926 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1928 wxGetResourceToken(fd
);
1929 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1930 wxChar
*actualName
= name
;
1931 if (name
[0] == wxT('"'))
1932 actualName
= name
+ 1;
1933 int len
= wxStrlen(name
);
1934 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1936 if (!wxResourceParseIncludeFile(actualName
, table
))
1938 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1943 else if (strcmp(wxResourceBuffer
, "static") != 0)
1946 wxStrcpy(buf
, _("Found "));
1947 wxStrncat(buf
, wxConvLibc
.cMB2WX(wxResourceBuffer
), 30);
1948 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1954 if (!wxGetResourceToken(fd
))
1956 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1961 if (strcmp(wxResourceBuffer
, "char") != 0)
1963 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1968 if (!wxGetResourceToken(fd
))
1970 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1975 if (wxResourceBuffer
[0] != '*')
1977 wxLogWarning(_("Expected '*' whilst parsing resource."));
1981 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
1984 if (!wxGetResourceToken(fd
))
1986 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1991 if (strcmp(wxResourceBuffer
, "=") != 0)
1993 wxLogWarning(_("Expected '=' whilst parsing resource."));
1998 if (!wxGetResourceToken(fd
))
2000 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2006 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2008 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2013 if (!wxGetResourceToken(fd
))
2021 * Parses string window style into integer window style
2025 * Style flag parsing, e.g.
2026 * "wxSYSTEM_MENU | wxBORDER" -> integer
2029 wxChar
* wxResourceParseWord(wxChar
*s
, int *i
)
2032 return (wxChar
*) NULL
;
2034 static wxChar buf
[150];
2035 int len
= wxStrlen(s
);
2038 while ((ii
< len
) && (wxIsalpha(s
[ii
]) || (s
[ii
] == wxT('_'))))
2046 // Eat whitespace and conjunction characters
2047 while ((ii
< len
) &&
2048 ((s
[ii
] == wxT(' ')) || (s
[ii
] == wxT('|')) || (s
[ii
] == wxT(','))))
2054 return (wxChar
*) NULL
;
2059 struct wxResourceBitListStruct
2065 static wxResourceBitListStruct wxResourceBitListTable
[] =
2068 { wxT("wxSINGLE"), wxLB_SINGLE
},
2069 { wxT("wxMULTIPLE"), wxLB_MULTIPLE
},
2070 { wxT("wxEXTENDED"), wxLB_EXTENDED
},
2071 { wxT("wxLB_SINGLE"), wxLB_SINGLE
},
2072 { wxT("wxLB_MULTIPLE"), wxLB_MULTIPLE
},
2073 { wxT("wxLB_EXTENDED"), wxLB_EXTENDED
},
2074 { wxT("wxLB_NEEDED_SB"), wxLB_NEEDED_SB
},
2075 { wxT("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB
},
2076 { wxT("wxLB_SORT"), wxLB_SORT
},
2077 { wxT("wxLB_OWNERDRAW"), wxLB_OWNERDRAW
},
2078 { wxT("wxLB_HSCROLL"), wxLB_HSCROLL
},
2081 { wxT("wxCB_SIMPLE"), wxCB_SIMPLE
},
2082 { wxT("wxCB_DROPDOWN"), wxCB_DROPDOWN
},
2083 { wxT("wxCB_READONLY"), wxCB_READONLY
},
2084 { wxT("wxCB_SORT"), wxCB_SORT
},
2087 { wxT("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR
},
2088 { wxT("wxGA_HORIZONTAL"), wxGA_HORIZONTAL
},
2089 { wxT("wxGA_VERTICAL"), wxGA_VERTICAL
},
2092 { wxT("wxPASSWORD"), wxPASSWORD
},
2093 { wxT("wxPROCESS_ENTER"), wxPROCESS_ENTER
},
2094 { wxT("wxTE_PASSWORD"), wxTE_PASSWORD
},
2095 { wxT("wxTE_READONLY"), wxTE_READONLY
},
2096 { wxT("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER
},
2097 { wxT("wxTE_MULTILINE"), wxTE_MULTILINE
},
2098 { wxT("wxTE_NO_VSCROLL"), wxTE_NO_VSCROLL
},
2100 /* wxRadioBox/wxRadioButton */
2101 { wxT("wxRB_GROUP"), wxRB_GROUP
},
2102 { wxT("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS
},
2103 { wxT("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS
},
2104 { wxT("wxRA_HORIZONTAL"), wxRA_HORIZONTAL
},
2105 { wxT("wxRA_VERTICAL"), wxRA_VERTICAL
},
2108 { wxT("wxSL_HORIZONTAL"), wxSL_HORIZONTAL
},
2109 { wxT("wxSL_VERTICAL"), wxSL_VERTICAL
},
2110 { wxT("wxSL_AUTOTICKS"), wxSL_AUTOTICKS
},
2111 { wxT("wxSL_LABELS"), wxSL_LABELS
},
2112 { wxT("wxSL_LEFT"), wxSL_LEFT
},
2113 { wxT("wxSL_TOP"), wxSL_TOP
},
2114 { wxT("wxSL_RIGHT"), wxSL_RIGHT
},
2115 { wxT("wxSL_BOTTOM"), wxSL_BOTTOM
},
2116 { wxT("wxSL_BOTH"), wxSL_BOTH
},
2117 { wxT("wxSL_SELRANGE"), wxSL_SELRANGE
},
2120 { wxT("wxSB_HORIZONTAL"), wxSB_HORIZONTAL
},
2121 { wxT("wxSB_VERTICAL"), wxSB_VERTICAL
},
2124 { wxT("wxBU_AUTODRAW"), wxBU_AUTODRAW
},
2125 { wxT("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW
},
2128 { wxT("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS
},
2129 { wxT("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS
},
2130 { wxT("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT
},
2133 { wxT("wxLC_ICON"), wxLC_ICON
},
2134 { wxT("wxLC_SMALL_ICON"), wxLC_SMALL_ICON
},
2135 { wxT("wxLC_LIST"), wxLC_LIST
},
2136 { wxT("wxLC_REPORT"), wxLC_REPORT
},
2137 { wxT("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP
},
2138 { wxT("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT
},
2139 { wxT("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE
},
2140 { wxT("wxLC_USER_TEXT"), wxLC_USER_TEXT
},
2141 { wxT("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS
},
2142 { wxT("wxLC_NO_HEADER"), wxLC_NO_HEADER
},
2143 { wxT("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER
},
2144 { wxT("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL
},
2145 { wxT("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING
},
2146 { wxT("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING
},
2149 { wxT("wxSP_VERTICAL"), wxSP_VERTICAL
},
2150 { wxT("wxSP_HORIZONTAL"), wxSP_HORIZONTAL
},
2151 { wxT("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS
},
2152 { wxT("wxSP_WRAP"), wxSP_WRAP
},
2155 { wxT("wxSP_NOBORDER"), wxSP_NOBORDER
},
2156 { wxT("wxSP_3D"), wxSP_3D
},
2157 { wxT("wxSP_BORDER"), wxSP_BORDER
},
2160 { wxT("wxTC_MULTILINE"), wxTC_MULTILINE
},
2161 { wxT("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY
},
2162 { wxT("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH
},
2163 { wxT("wxTC_OWNERDRAW"), wxTC_OWNERDRAW
},
2166 { wxT("wxST_SIZEGRIP"), wxST_SIZEGRIP
},
2169 { wxT("wxFIXED_LENGTH"), wxFIXED_LENGTH
},
2170 { wxT("wxALIGN_LEFT"), wxALIGN_LEFT
},
2171 { wxT("wxALIGN_CENTER"), wxALIGN_CENTER
},
2172 { wxT("wxALIGN_CENTRE"), wxALIGN_CENTRE
},
2173 { wxT("wxALIGN_RIGHT"), wxALIGN_RIGHT
},
2174 { wxT("wxCOLOURED"), wxCOLOURED
},
2177 { wxT("wxTB_3DBUTTONS"), wxTB_3DBUTTONS
},
2178 { wxT("wxTB_HORIZONTAL"), wxTB_HORIZONTAL
},
2179 { wxT("wxTB_VERTICAL"), wxTB_VERTICAL
},
2180 { wxT("wxTB_FLAT"), wxTB_FLAT
},
2183 { wxT("wxDIALOG_MODAL"), wxDIALOG_MODAL
},
2186 { wxT("wxVSCROLL"), wxVSCROLL
},
2187 { wxT("wxHSCROLL"), wxHSCROLL
},
2188 { wxT("wxCAPTION"), wxCAPTION
},
2189 { wxT("wxSTAY_ON_TOP"), wxSTAY_ON_TOP
},
2190 { wxT("wxICONIZE"), wxICONIZE
},
2191 { wxT("wxMINIMIZE"), wxICONIZE
},
2192 { wxT("wxMAXIMIZE"), wxMAXIMIZE
},
2194 { wxT("wxMDI_PARENT"), 0},
2195 { wxT("wxMDI_CHILD"), 0},
2196 { wxT("wxTHICK_FRAME"), wxTHICK_FRAME
},
2197 { wxT("wxRESIZE_BORDER"), wxRESIZE_BORDER
},
2198 { wxT("wxSYSTEM_MENU"), wxSYSTEM_MENU
},
2199 { wxT("wxMINIMIZE_BOX"), wxMINIMIZE_BOX
},
2200 { wxT("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX
},
2201 { wxT("wxRESIZE_BOX"), wxRESIZE_BOX
},
2202 { wxT("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE
},
2203 { wxT("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE
},
2204 { wxT("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE
},
2205 { wxT("wxBORDER"), wxBORDER
},
2206 { wxT("wxRETAINED"), wxRETAINED
},
2207 { wxT("wxNATIVE_IMPL"), 0},
2208 { wxT("wxEXTENDED_IMPL"), 0},
2209 { wxT("wxBACKINGSTORE"), wxBACKINGSTORE
},
2210 // { wxT("wxFLAT"), wxFLAT},
2211 // { wxT("wxMOTIF_RESIZE"), wxMOTIF_RESIZE},
2212 { wxT("wxFIXED_LENGTH"), 0},
2213 { wxT("wxDOUBLE_BORDER"), wxDOUBLE_BORDER
},
2214 { wxT("wxSUNKEN_BORDER"), wxSUNKEN_BORDER
},
2215 { wxT("wxRAISED_BORDER"), wxRAISED_BORDER
},
2216 { wxT("wxSIMPLE_BORDER"), wxSIMPLE_BORDER
},
2217 { wxT("wxSTATIC_BORDER"), wxSTATIC_BORDER
},
2218 { wxT("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW
},
2219 { wxT("wxNO_BORDER"), wxNO_BORDER
},
2220 { wxT("wxCLIP_CHILDREN"), wxCLIP_CHILDREN
},
2221 { wxT("wxCLIP_SIBLINGS"), wxCLIP_SIBLINGS
},
2222 { wxT("wxTAB_TRAVERSAL"), 0}, // Compatibility only
2224 { wxT("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ
},
2225 { wxT("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT
},
2227 // Text font families
2228 { wxT("wxDEFAULT"), wxDEFAULT
},
2229 { wxT("wxDECORATIVE"), wxDECORATIVE
},
2230 { wxT("wxROMAN"), wxROMAN
},
2231 { wxT("wxSCRIPT"), wxSCRIPT
},
2232 { wxT("wxSWISS"), wxSWISS
},
2233 { wxT("wxMODERN"), wxMODERN
},
2234 { wxT("wxTELETYPE"), wxTELETYPE
},
2235 { wxT("wxVARIABLE"), wxVARIABLE
},
2236 { wxT("wxFIXED"), wxFIXED
},
2237 { wxT("wxNORMAL"), wxNORMAL
},
2238 { wxT("wxLIGHT"), wxLIGHT
},
2239 { wxT("wxBOLD"), wxBOLD
},
2240 { wxT("wxITALIC"), wxITALIC
},
2241 { wxT("wxSLANT"), wxSLANT
},
2242 { wxT("wxSOLID"), wxSOLID
},
2243 { wxT("wxDOT"), wxDOT
},
2244 { wxT("wxLONG_DASH"), wxLONG_DASH
},
2245 { wxT("wxSHORT_DASH"), wxSHORT_DASH
},
2246 { wxT("wxDOT_DASH"), wxDOT_DASH
},
2247 { wxT("wxUSER_DASH"), wxUSER_DASH
},
2248 { wxT("wxTRANSPARENT"), wxTRANSPARENT
},
2249 { wxT("wxSTIPPLE"), wxSTIPPLE
},
2250 { wxT("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH
},
2251 { wxT("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH
},
2252 { wxT("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH
},
2253 { wxT("wxCROSS_HATCH"), wxCROSS_HATCH
},
2254 { wxT("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH
},
2255 { wxT("wxVERTICAL_HATCH"), wxVERTICAL_HATCH
},
2256 { wxT("wxJOIN_BEVEL"), wxJOIN_BEVEL
},
2257 { wxT("wxJOIN_MITER"), wxJOIN_MITER
},
2258 { wxT("wxJOIN_ROUND"), wxJOIN_ROUND
},
2259 { wxT("wxCAP_ROUND"), wxCAP_ROUND
},
2260 { wxT("wxCAP_PROJECTING"), wxCAP_PROJECTING
},
2261 { wxT("wxCAP_BUTT"), wxCAP_BUTT
},
2264 { wxT("wxCLEAR"), wxCLEAR
},
2265 { wxT("wxXOR"), wxXOR
},
2266 { wxT("wxINVERT"), wxINVERT
},
2267 { wxT("wxOR_REVERSE"), wxOR_REVERSE
},
2268 { wxT("wxAND_REVERSE"), wxAND_REVERSE
},
2269 { wxT("wxCOPY"), wxCOPY
},
2270 { wxT("wxAND"), wxAND
},
2271 { wxT("wxAND_INVERT"), wxAND_INVERT
},
2272 { wxT("wxNO_OP"), wxNO_OP
},
2273 { wxT("wxNOR"), wxNOR
},
2274 { wxT("wxEQUIV"), wxEQUIV
},
2275 { wxT("wxSRC_INVERT"), wxSRC_INVERT
},
2276 { wxT("wxOR_INVERT"), wxOR_INVERT
},
2277 { wxT("wxNAND"), wxNAND
},
2278 { wxT("wxOR"), wxOR
},
2279 { wxT("wxSET"), wxSET
},
2281 { wxT("wxFLOOD_SURFACE"), wxFLOOD_SURFACE
},
2282 { wxT("wxFLOOD_BORDER"), wxFLOOD_BORDER
},
2283 { wxT("wxODDEVEN_RULE"), wxODDEVEN_RULE
},
2284 { wxT("wxWINDING_RULE"), wxWINDING_RULE
},
2285 { wxT("wxHORIZONTAL"), wxHORIZONTAL
},
2286 { wxT("wxVERTICAL"), wxVERTICAL
},
2287 { wxT("wxBOTH"), wxBOTH
},
2288 { wxT("wxCENTER_FRAME"), wxCENTER_FRAME
},
2289 { wxT("wxOK"), wxOK
},
2290 { wxT("wxYES_NO"), wxYES_NO
},
2291 { wxT("wxCANCEL"), wxCANCEL
},
2292 { wxT("wxYES"), wxYES
},
2293 { wxT("wxNO"), wxNO
},
2294 { wxT("wxICON_EXCLAMATION"), wxICON_EXCLAMATION
},
2295 { wxT("wxICON_HAND"), wxICON_HAND
},
2296 { wxT("wxICON_QUESTION"), wxICON_QUESTION
},
2297 { wxT("wxICON_INFORMATION"), wxICON_INFORMATION
},
2298 { wxT("wxICON_STOP"), wxICON_STOP
},
2299 { wxT("wxICON_ASTERISK"), wxICON_ASTERISK
},
2300 { wxT("wxICON_MASK"), wxICON_MASK
},
2301 { wxT("wxCENTRE"), wxCENTRE
},
2302 { wxT("wxCENTER"), wxCENTRE
},
2303 { wxT("wxUSER_COLOURS"), wxUSER_COLOURS
},
2304 { wxT("wxVERTICAL_LABEL"), 0},
2305 { wxT("wxHORIZONTAL_LABEL"), 0},
2307 // Bitmap types (not strictly styles)
2308 { wxT("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM
},
2309 { wxT("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM
},
2310 { wxT("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP
},
2311 { wxT("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2312 { wxT("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2313 { wxT("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF
},
2314 { wxT("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF
},
2315 { wxT("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO
},
2316 { wxT("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE
},
2317 { wxT("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR
},
2318 { wxT("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE
},
2319 { wxT("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA
},
2320 { wxT("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA
},
2321 { wxT("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY
}
2324 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2326 long wxParseWindowStyle(const wxString
& bitListString
)
2331 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2332 while (word
!= NULL
)
2336 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2337 if (wxStrcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2339 bitList
|= wxResourceBitListTable
[j
].bits
;
2345 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
2348 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2354 * Load a bitmap from a wxWindows resource, choosing an optimum
2355 * depth and appropriate type.
2358 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2361 table
= wxDefaultResourceTable
;
2363 wxItemResource
*item
= table
->FindResource(resource
);
2366 if ((item
->GetType() == wxT("")) || (item
->GetType() != wxT("wxBitmap")))
2368 wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar
*) resource
);
2369 return wxNullBitmap
;
2371 int thisDepth
= wxDisplayDepth();
2372 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2374 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2376 // Try to find optimum bitmap for this platform/colour depth
2377 wxNode
*node
= item
->GetChildren().First();
2380 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2381 int platform
= (int)child
->GetValue2();
2382 int noColours
= (int)child
->GetValue3();
2384 char *name = child->GetName();
2385 int bitmapType = (int)child->GetValue1();
2386 int xRes = child->GetWidth();
2387 int yRes = child->GetHeight();
2392 case RESOURCE_PLATFORM_ANY
:
2394 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2395 optResource
= child
;
2398 // Maximise the number of colours.
2399 // If noColours is zero (unspecified), then assume this
2400 // is the right one.
2401 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2402 optResource
= child
;
2407 case RESOURCE_PLATFORM_WINDOWS
:
2409 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2410 optResource
= child
;
2413 // Maximise the number of colours
2414 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2415 optResource
= child
;
2421 case RESOURCE_PLATFORM_X
:
2423 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2424 optResource
= child
;
2427 // Maximise the number of colours
2428 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2429 optResource
= child
;
2435 case RESOURCE_PLATFORM_MAC
:
2437 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2438 optResource
= child
;
2441 // Maximise the number of colours
2442 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2443 optResource
= child
;
2451 node
= node
->Next();
2453 // If no matching resource, fail.
2455 return wxNullBitmap
;
2457 wxString name
= optResource
->GetName();
2458 int bitmapType
= (int)optResource
->GetValue1();
2461 case wxBITMAP_TYPE_XBM_DATA
:
2464 wxItemResource
*item
= table
->FindResource(name
);
2467 wxLogWarning(_("Failed to find XBM resource %s.\n"
2468 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2469 return wxNullBitmap
;
2471 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2473 wxLogWarning(_("No XBM facility available!"));
2477 case wxBITMAP_TYPE_XPM_DATA
:
2479 wxItemResource
*item
= table
->FindResource(name
);
2482 wxLogWarning(_("Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2483 return wxNullBitmap
;
2485 return wxBitmap((char **)item
->GetValue1());
2489 #if defined(__WXPM__)
2490 return wxNullBitmap
;
2492 return wxBitmap(name
, (wxBitmapType
)bitmapType
);
2497 return wxNullBitmap
;
2502 wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar
*) resource
);
2503 return wxNullBitmap
;
2508 * Load an icon from a wxWindows resource, choosing an optimum
2509 * depth and appropriate type.
2512 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2515 table
= wxDefaultResourceTable
;
2517 wxItemResource
*item
= table
->FindResource(resource
);
2520 if ((item
->GetType() == wxT("")) || wxStrcmp(item
->GetType(), wxT("wxIcon")) != 0)
2522 wxLogWarning(_("%s not an icon resource specification."), (const wxChar
*) resource
);
2525 int thisDepth
= wxDisplayDepth();
2526 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2528 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2530 // Try to find optimum icon for this platform/colour depth
2531 wxNode
*node
= item
->GetChildren().First();
2534 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2535 int platform
= (int)child
->GetValue2();
2536 int noColours
= (int)child
->GetValue3();
2538 char *name = child->GetName();
2539 int bitmapType = (int)child->GetValue1();
2540 int xRes = child->GetWidth();
2541 int yRes = child->GetHeight();
2546 case RESOURCE_PLATFORM_ANY
:
2548 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2549 optResource
= child
;
2552 // Maximise the number of colours.
2553 // If noColours is zero (unspecified), then assume this
2554 // is the right one.
2555 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2556 optResource
= child
;
2561 case RESOURCE_PLATFORM_WINDOWS
:
2563 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2564 optResource
= child
;
2567 // Maximise the number of colours
2568 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2569 optResource
= child
;
2575 case RESOURCE_PLATFORM_X
:
2577 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2578 optResource
= child
;
2581 // Maximise the number of colours
2582 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2583 optResource
= child
;
2589 case RESOURCE_PLATFORM_MAC
:
2591 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2592 optResource
= child
;
2595 // Maximise the number of colours
2596 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2597 optResource
= child
;
2605 node
= node
->Next();
2607 // If no matching resource, fail.
2611 wxString name
= optResource
->GetName();
2612 int bitmapType
= (int)optResource
->GetValue1();
2615 case wxBITMAP_TYPE_XBM_DATA
:
2618 wxItemResource
*item
= table
->FindResource(name
);
2621 wxLogWarning(_("Failed to find XBM resource %s.\n"
2622 "Forgot to use wxResourceLoadIconData?"), (const wxChar
*) name
);
2625 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2627 wxLogWarning(_("No XBM facility available!"));
2631 case wxBITMAP_TYPE_XPM_DATA
:
2633 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2635 wxItemResource *item = table->FindResource(name);
2639 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2643 return wxIcon((char **)item->GetValue1());
2645 wxLogWarning(_("No XPM icon facility available!"));
2650 #if defined( __WXGTK__ ) || defined( __WXMOTIF__ )
2651 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2654 return wxIcon(name
, bitmapType
);
2662 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2669 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2671 wxMenu
*menu
= new wxMenu
;
2672 wxNode
*node
= item
->GetChildren().First();
2675 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2676 if ((child
->GetType() != wxT("")) && (child
->GetType() == wxT("wxMenuSeparator")))
2677 menu
->AppendSeparator();
2678 else if (child
->GetChildren().Number() > 0)
2680 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2682 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2686 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2688 node
= node
->Next();
2693 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2696 table
= wxDefaultResourceTable
;
2698 wxItemResource
*menuResource
= table
->FindResource(resource
);
2699 if (menuResource
&& (menuResource
->GetType() != wxT("")) && (menuResource
->GetType() == wxT("wxMenu")))
2702 menuBar
= new wxMenuBar
;
2703 wxNode
*node
= menuResource
->GetChildren().First();
2706 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2707 wxMenu
*menu
= wxResourceCreateMenu(child
);
2709 menuBar
->Append(menu
, child
->GetTitle());
2710 node
= node
->Next();
2714 return (wxMenuBar
*) NULL
;
2717 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2720 table
= wxDefaultResourceTable
;
2722 wxItemResource
*menuResource
= table
->FindResource(resource
);
2723 if (menuResource
&& (menuResource
->GetType() != wxT("")) && (menuResource
->GetType() == wxT("wxMenu")))
2724 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2725 return wxResourceCreateMenu(menuResource
);
2726 return (wxMenu
*) NULL
;
2729 #endif // wxUSE_MENUS
2731 // Global equivalents (so don't have to refer to default table explicitly)
2732 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2735 table
= wxDefaultResourceTable
;
2737 return table
->ParseResourceData(resource
);
2740 bool wxResourceParseData(const char* resource
, wxResourceTable
*table
)
2742 wxString
str(resource
, wxConvLibc
);
2744 table
= wxDefaultResourceTable
;
2746 return table
->ParseResourceData(str
);
2749 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2752 table
= wxDefaultResourceTable
;
2754 return table
->ParseResourceFile(filename
);
2757 // Register XBM/XPM data
2758 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2761 table
= wxDefaultResourceTable
;
2763 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2766 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2769 table
= wxDefaultResourceTable
;
2771 return table
->RegisterResourceBitmapData(name
, data
);
2774 void wxResourceClear(wxResourceTable
*table
)
2777 table
= wxDefaultResourceTable
;
2779 table
->ClearTable();
2786 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2789 table
= wxDefaultResourceTable
;
2791 table
->identifiers
.Put(name
, (wxObject
*)(long)value
);
2795 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2798 table
= wxDefaultResourceTable
;
2800 return (int)(long)table
->identifiers
.Get(name
);
2804 * Parse #include file for #defines (only)
2807 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2810 table
= wxDefaultResourceTable
;
2812 FILE *fd
= wxFopen(f
, wxT("r"));
2817 while (wxGetResourceToken(fd
))
2819 if (strcmp(wxResourceBuffer
, "#define") == 0)
2821 wxGetResourceToken(fd
);
2822 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2823 wxGetResourceToken(fd
);
2824 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2825 if (wxIsdigit(value
[0]))
2827 int val
= (int)wxAtol(value
);
2828 wxResourceAddIdentifier(name
, val
, table
);
2839 * Reading strings as if they were .wxr files
2842 static int getc_string(char *s
)
2844 int ch
= s
[wxResourceStringPtr
];
2849 wxResourceStringPtr
++;
2854 static int ungetc_string()
2856 wxResourceStringPtr
--;
2860 bool wxEatWhiteSpaceString(char *s
)
2864 while ((ch
= getc_string(s
)) != EOF
)
2876 ch
= getc_string(s
);
2887 while ((ch
= getc_string(s
)) != EOF
)
2889 if (ch
== '/' && prev_ch
== '*')
2911 bool wxGetResourceTokenString(char *s
)
2913 if (!wxResourceBuffer
)
2914 wxReallocateResourceBuffer();
2915 wxResourceBuffer
[0] = 0;
2916 wxEatWhiteSpaceString(s
);
2918 int ch
= getc_string(s
);
2922 wxResourceBufferCount
= 0;
2923 ch
= getc_string(s
);
2929 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2932 // Escaped characters
2933 else if (ch
== '\\')
2935 int newCh
= getc_string(s
);
2938 else if (newCh
== 10)
2946 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2947 wxReallocateResourceBuffer();
2948 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2949 wxResourceBufferCount
++;
2950 ch
= getc_string(s
);
2952 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2956 wxResourceBufferCount
= 0;
2958 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2960 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2961 wxReallocateResourceBuffer();
2962 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2963 wxResourceBufferCount
++;
2965 ch
= getc_string(s
);
2967 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2975 * Files are in form:
2976 static char *name = "....";
2977 with possible comments.
2980 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2983 table
= wxDefaultResourceTable
;
2985 // static or #define
2986 if (!wxGetResourceTokenString(s
))
2992 if (strcmp(wxResourceBuffer
, "#define") == 0)
2994 wxGetResourceTokenString(s
);
2995 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2996 wxGetResourceTokenString(s
);
2997 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2998 if (wxIsdigit(value
[0]))
3000 int val
= (int)wxAtol(value
);
3001 wxResourceAddIdentifier(name
, val
, table
);
3005 wxLogWarning(_("#define %s must be an integer."), name
);
3016 else if (strcmp(wxResourceBuffer, "#include") == 0)
3018 wxGetResourceTokenString(s);
3019 char *name = copystring(wxResourceBuffer);
3020 char *actualName = name;
3022 actualName = name + 1;
3023 int len = strlen(name);
3024 if ((len > 0) && (name[len-1] == '"'))
3026 if (!wxResourceParseIncludeFile(actualName, table))
3029 sprintf(buf, _("Could not find resource include file %s."), actualName);
3036 else if (strcmp(wxResourceBuffer
, "static") != 0)
3039 wxStrcpy(buf
, _("Found "));
3040 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
3041 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
3047 if (!wxGetResourceTokenString(s
))
3049 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3054 if (strcmp(wxResourceBuffer
, "char") != 0)
3056 wxLogWarning(_("Expected 'char' whilst parsing resource."));
3061 if (!wxGetResourceTokenString(s
))
3063 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3068 if (wxResourceBuffer
[0] != '*')
3070 wxLogWarning(_("Expected '*' whilst parsing resource."));
3073 wxChar nameBuf
[100];
3074 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
3078 if (!wxGetResourceTokenString(s
))
3080 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3085 if (strcmp(wxResourceBuffer
, "=") != 0)
3087 wxLogWarning(_("Expected '=' whilst parsing resource."));
3092 if (!wxGetResourceTokenString(s
))
3094 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3100 if (!db
.ReadPrologFromString(wxResourceBuffer
))
3102 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
3107 if (!wxGetResourceTokenString(s
))
3114 bool wxResourceParseString(const wxString
& s
, wxResourceTable
*table
)
3117 return wxResourceParseString( (char*)s
.mb_str().data() );
3119 return wxResourceParseString( (char*)s
.c_str() );
3123 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
3126 table
= wxDefaultResourceTable
;
3131 // Turn backslashes into spaces
3134 int len
= strlen(s
);
3136 for (i
= 0; i
< len
; i
++)
3137 if (s
[i
] == 92 && s
[i
+1] == 13)
3145 wxResourceStringPtr
= 0;
3148 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
3152 return wxResourceInterpretResources(*table
, db
);
3156 * resource loading facility
3159 bool wxWindowBase::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
3162 table
= wxDefaultResourceTable
;
3164 wxItemResource
*resource
= table
->FindResource((const wxChar
*)resourceName
);
3165 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
3166 if (!resource
|| (resource
->GetType() == wxT("")) ||
3167 ! ((resource
->GetType() == wxT("wxDialog")) || (resource
->GetType() == wxT("wxPanel"))))
3170 wxString
title(resource
->GetTitle());
3171 long theWindowStyle
= resource
->GetStyle();
3172 bool isModal
= (resource
->GetValue1() != 0) ;
3173 int x
= resource
->GetX();
3174 int y
= resource
->GetY();
3175 int width
= resource
->GetWidth();
3176 int height
= resource
->GetHeight();
3177 wxString name
= resource
->GetName();
3179 // this is used for loading wxWizard pages from WXR
3180 if ( parent
!= this )
3182 if (IsKindOf(CLASSINFO(wxDialog
)))
3184 wxDialog
*dialogBox
= (wxDialog
*)this;
3185 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
3186 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
3189 // Only reset the client size if we know we're not going to do it again below.
3190 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
3191 dialogBox
->SetClientSize(width
, height
);
3193 else if (IsKindOf(CLASSINFO(wxPanel
)))
3195 wxPanel
* panel
= (wxPanel
*)this;
3196 if (!panel
->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
| wxTAB_TRAVERSAL
, name
))
3201 if (!((wxWindow
*)this)->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
3206 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
3208 // No need to do this since it's done in wxPanel or wxDialog constructor.
3209 // SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
3213 if (resource
->GetFont().Ok())
3214 SetFont(resource
->GetFont());
3215 if (resource
->GetBackgroundColour().Ok())
3216 SetBackgroundColour(resource
->GetBackgroundColour());
3219 // Should have some kind of font at this point
3220 if (!GetFont().Ok())
3221 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
3222 if (!GetBackgroundColour().Ok())
3223 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
3225 // Only when we've created the window and set the font can we set the correct size,
3226 // if based on dialog units.
3227 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
3229 wxSize sz
= ConvertDialogToPixels(wxSize(width
, height
));
3230 SetClientSize(sz
.x
, sz
.y
);
3232 wxPoint pt
= ConvertDialogToPixels(wxPoint(x
, y
));
3236 // Now create children
3237 wxNode
*node
= resource
->GetChildren().First();
3240 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
3242 (void) CreateItem(childResource
, resource
, table
);
3244 node
= node
->Next();
3249 wxControl
*wxWindowBase::CreateItem(const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
3252 table
= wxDefaultResourceTable
;
3253 return table
->CreateItem((wxWindow
*)this, resource
, parentResource
);
3257 #pragma warning(default:4706) // assignment within conditional expression
3263 #endif // wxUSE_WX_RESOURCES