1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Resource system
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "resource.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #if wxUSE_WX_RESOURCES
26 #pragma warning(disable:4706) // assignment within conditional expression
34 #include "wx/gdicmn.h"
38 #include "wx/stattext.h"
39 #include "wx/button.h"
40 #include "wx/bmpbuttn.h"
41 #include "wx/radiobox.h"
42 #include "wx/listbox.h"
43 #include "wx/choice.h"
44 #include "wx/checkbox.h"
45 #include "wx/settings.h"
46 #include "wx/slider.h"
48 #include "wx/statbox.h"
49 #include "wx/statbmp.h"
51 #include "wx/textctrl.h"
52 #include "wx/msgdlg.h"
57 #include "wx/radiobut.h"
61 #include "wx/scrolbar.h"
65 #include "wx/combobox.h"
68 #include "wx/validate.h"
77 #include "wx/resource.h"
78 #include "wx/string.h"
79 #include "wx/wxexpr.h"
81 #include "wx/settings.h"
83 // Forward (private) declarations
84 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
);
85 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
= FALSE
);
86 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
);
87 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
);
88 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
);
89 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, wxExpr
*expr
);
90 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, wxExpr
*expr
);
91 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
);
92 // Interpret list expression
93 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
);
95 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
96 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
98 wxResourceTable
*wxDefaultResourceTable
= (wxResourceTable
*) NULL
;
100 char *wxResourceBuffer
= (char *) NULL
;
101 long wxResourceBufferSize
= 0;
102 long wxResourceBufferCount
= 0;
103 int wxResourceStringPtr
= 0;
105 void wxInitializeResourceSystem()
107 wxDefaultResourceTable
= new wxResourceTable
;
110 void wxCleanUpResourceSystem()
112 delete wxDefaultResourceTable
;
113 if (wxResourceBuffer
)
114 delete[] wxResourceBuffer
;
117 void wxLogWarning(char *msg
)
119 wxMessageBox(msg
, _("Warning"), wxOK
);
122 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
123 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
125 wxItemResource::wxItemResource()
131 m_x
= m_y
= m_width
= m_height
= 0;
132 m_value1
= m_value2
= m_value3
= m_value5
= 0;
138 wxItemResource::~wxItemResource()
140 wxNode
*node
= m_children
.First();
143 wxItemResource
*item
= (wxItemResource
*)node
->Data();
146 node
= m_children
.First();
154 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
158 wxResourceTable::~wxResourceTable()
163 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
165 wxItemResource
*item
= (wxItemResource
*)Get(WXSTRINGCAST name
);
169 void wxResourceTable::AddResource(wxItemResource
*item
)
171 wxString name
= item
->GetName();
173 name
= item
->GetTitle();
175 name
= wxT("no name");
177 // Delete existing resource, if any.
183 bool wxResourceTable::DeleteResource(const wxString
& name
)
185 wxItemResource
*item
= (wxItemResource
*)Delete(WXSTRINGCAST name
);
188 // See if any resource has this as its child; if so, delete from
189 // parent's child list.
191 wxNode
*node
= (wxNode
*) NULL
;
195 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
196 if (parent
->GetChildren().Member(item
))
198 parent
->GetChildren().DeleteObject(item
);
211 bool wxResourceTable::ParseResourceFile(const wxString
& filename
)
216 FILE *fd
= fopen(wxUnix2MacFilename(filename
.fn_str()), "r");
218 FILE *fd
= fopen(filename
.fn_str(), "r");
223 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
228 return wxResourceInterpretResources(*this, db
);
231 bool wxResourceTable::ParseResourceData(const wxString
& data
)
234 if (!db
.ReadFromString(data
))
236 wxLogWarning(_("Ill-formed resource file syntax."));
240 return wxResourceInterpretResources(*this, db
);
243 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char bits
[], int width
, int height
)
245 // Register pre-loaded bitmap data
246 wxItemResource
*item
= new wxItemResource
;
247 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
248 item
->SetType(wxT("wxXBMData"));
250 item
->SetValue1((long)bits
);
251 item
->SetValue2((long)width
);
252 item
->SetValue3((long)height
);
257 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char **data
)
259 // Register pre-loaded bitmap data
260 wxItemResource
*item
= new wxItemResource
;
261 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
262 item
->SetType(wxT("wxXPMData"));
264 item
->SetValue1((long)data
);
269 bool wxResourceTable::SaveResource(const wxString
& WXUNUSED(filename
))
274 void wxResourceTable::ClearTable()
277 wxNode
*node
= Next();
280 wxNode
*next
= Next();
281 wxItemResource
*item
= (wxItemResource
*)node
->Data();
288 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, const wxItemResource
* childResource
, const wxItemResource
* parentResource
) const
290 int id
= childResource
->GetId();
294 bool dlgUnits
= ((parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0);
296 wxControl
*control
= (wxControl
*) NULL
;
297 wxString
itemType(childResource
->GetType());
303 pos
= parent
->ConvertDialogToPixels(wxPoint(childResource
->GetX(), childResource
->GetY()));
304 size
= parent
->ConvertDialogToPixels(wxSize(childResource
->GetWidth(), childResource
->GetHeight()));
308 pos
= wxPoint(childResource
->GetX(), childResource
->GetY());
309 size
= wxSize(childResource
->GetWidth(), childResource
->GetHeight());
312 if (itemType
== wxString(wxT("wxButton")) || itemType
== wxString(wxT("wxBitmapButton")))
314 if (childResource
->GetValue4() != wxT(""))
317 wxBitmap bitmap
= childResource
->GetBitmap();
320 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
321 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
324 control
= new wxBitmapButton(parent
, id
, bitmap
, pos
, size
,
325 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
328 // Normal, text button
329 control
= new wxButton(parent
, id
, childResource
->GetTitle(), pos
, size
,
330 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
332 else if (itemType
== wxString(wxT("wxMessage")) || itemType
== wxString(wxT("wxStaticText")) ||
333 itemType
== wxString(wxT("wxStaticBitmap")))
335 if (childResource
->GetValue4() != wxT(""))
338 wxBitmap bitmap
= childResource
->GetBitmap();
341 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
342 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
344 #if wxUSE_BITMAP_MESSAGE
346 control
= new wxStaticBitmap(parent
, id
, bitmap
, pos
, size
,
347 childResource
->GetStyle(), childResource
->GetName());
352 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(), pos
, size
,
353 childResource
->GetStyle(), childResource
->GetName());
356 else if (itemType
== wxString(wxT("wxText")) || itemType
== wxString(wxT("wxTextCtrl")) || itemType
== wxString(wxT("wxMultiText")))
358 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), pos
, size
,
359 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
361 else if (itemType
== wxString(wxT("wxCheckBox")))
363 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
364 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
366 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
369 else if (itemType
== wxString(wxT("wxGauge")))
371 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(), pos
, size
,
372 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
374 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
378 else if (itemType
== wxString(wxT("wxRadioButton")))
380 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
382 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
386 else if (itemType
== wxString(wxT("wxScrollBar")))
388 control
= new wxScrollBar(parent
, id
, pos
, size
,
389 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
391 ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1());
392 ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2());
393 ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3());
394 ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5());
396 ((wxScrollBar
*)control
)->SetScrollbar((int)childResource
->GetValue1(),(int)childResource
->GetValue2(),
397 (int)childResource
->GetValue3(),(int)(long)childResource
->GetValue5(),FALSE
);
401 else if (itemType
== wxString(wxT("wxSlider")))
403 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
404 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), pos
, size
,
405 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
407 else if (itemType
== wxString(wxT("wxGroupBox")) || itemType
== wxString(wxT("wxStaticBox")))
409 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
410 childResource
->GetStyle(), childResource
->GetName());
412 else if (itemType
== wxString(wxT("wxListBox")))
414 wxStringList
& stringList
= childResource
->GetStringValues();
415 wxString
*strings
= (wxString
*) NULL
;
417 if (stringList
.Number() > 0)
419 noStrings
= stringList
.Number();
420 strings
= new wxString
[noStrings
];
421 wxNode
*node
= stringList
.First();
425 strings
[i
] = (wxChar
*)node
->Data();
430 control
= new wxListBox(parent
, id
, pos
, size
,
431 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
436 else if (itemType
== wxString(wxT("wxChoice")))
438 wxStringList
& stringList
= childResource
->GetStringValues();
439 wxString
*strings
= (wxString
*) NULL
;
441 if (stringList
.Number() > 0)
443 noStrings
= stringList
.Number();
444 strings
= new wxString
[noStrings
];
445 wxNode
*node
= stringList
.First();
449 strings
[i
] = (wxChar
*)node
->Data();
454 control
= new wxChoice(parent
, id
, pos
, size
,
455 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
461 else if (itemType
== wxString(wxT("wxComboBox")))
463 wxStringList
& stringList
= childResource
->GetStringValues();
464 wxString
*strings
= (wxString
*) NULL
;
466 if (stringList
.Number() > 0)
468 noStrings
= stringList
.Number();
469 strings
= new wxString
[noStrings
];
470 wxNode
*node
= stringList
.First();
474 strings
[i
] = (wxChar
*)node
->Data();
479 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(), pos
, size
,
480 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
486 else if (itemType
== wxString(wxT("wxRadioBox")))
488 wxStringList
& stringList
= childResource
->GetStringValues();
489 wxString
*strings
= (wxString
*) NULL
;
491 if (stringList
.Number() > 0)
493 noStrings
= stringList
.Number();
494 strings
= new wxString
[noStrings
];
495 wxNode
*node
= stringList
.First();
499 strings
[i
] = (wxChar
*)node
->Data();
504 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), pos
, size
,
505 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
506 childResource
->GetName());
512 if ((parentResource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
514 // Don't set font; will be inherited from parent.
518 if (control
&& childResource
->GetFont().Ok())
519 control
->SetFont(childResource
->GetFont());
525 * Interpret database as a series of resources
528 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
)
530 wxNode
*node
= db
.First();
533 wxExpr
*clause
= (wxExpr
*)node
->Data();
534 wxString
functor(clause
->Functor());
536 wxItemResource
*item
= (wxItemResource
*) NULL
;
537 if (functor
== wxT("dialog"))
538 item
= wxResourceInterpretDialog(table
, clause
);
539 else if (functor
== wxT("panel"))
540 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
541 else if (functor
== wxT("menubar"))
542 item
= wxResourceInterpretMenuBar(table
, clause
);
543 else if (functor
== wxT("menu"))
544 item
= wxResourceInterpretMenu(table
, clause
);
545 else if (functor
== wxT("string"))
546 item
= wxResourceInterpretString(table
, clause
);
547 else if (functor
== wxT("bitmap"))
548 item
= wxResourceInterpretBitmap(table
, clause
);
549 else if (functor
== wxT("icon"))
550 item
= wxResourceInterpretIcon(table
, clause
);
554 // Remove any existing resource of same name
555 if (item
->GetName() != wxT(""))
556 table
.DeleteResource(item
->GetName());
557 table
.AddResource(item
);
564 static const wxChar
*g_ValidControlClasses
[] =
567 wxT("wxBitmapButton"),
570 wxT("wxStaticBitmap"),
576 wxT("wxRadioButton"),
578 wxT("wxBitmapCheckBox"),
588 static bool wxIsValidControlClass(const wxString
& c
)
590 for ( size_t i
= 0; i
< WXSIZEOF(g_ValidControlClasses
); i
++ )
592 if ( c
== g_ValidControlClasses
[i
] )
598 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
600 wxItemResource
*dialogItem
= new wxItemResource
;
602 dialogItem
->SetType(wxT("wxPanel"));
604 dialogItem
->SetType(wxT("wxDialog"));
605 wxString style
= wxT("");
606 wxString title
= wxT("");
607 wxString name
= wxT("");
608 wxString backColourHex
= wxT("");
609 wxString labelColourHex
= wxT("");
610 wxString buttonColourHex
= wxT("");
612 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
616 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
618 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
619 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
620 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
621 expr
->GetAttributeValue(wxT("style"), style
);
622 expr
->GetAttributeValue(wxT("name"), name
);
623 expr
->GetAttributeValue(wxT("title"), title
);
624 expr
->GetAttributeValue(wxT("x"), x
);
625 expr
->GetAttributeValue(wxT("y"), y
);
626 expr
->GetAttributeValue(wxT("width"), width
);
627 expr
->GetAttributeValue(wxT("height"), height
);
628 expr
->GetAttributeValue(wxT("modal"), isModal
);
629 expr
->GetAttributeValue(wxT("label_font"), &labelFontExpr
);
630 expr
->GetAttributeValue(wxT("button_font"), &buttonFontExpr
);
631 expr
->GetAttributeValue(wxT("font"), &fontExpr
);
632 expr
->GetAttributeValue(wxT("background_colour"), backColourHex
);
633 expr
->GetAttributeValue(wxT("label_colour"), labelColourHex
);
634 expr
->GetAttributeValue(wxT("button_colour"), buttonColourHex
);
636 int useDialogUnits
= 0;
637 expr
->GetAttributeValue(wxT("use_dialog_units"), useDialogUnits
);
638 if (useDialogUnits
!= 0)
639 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
642 expr
->GetAttributeValue(wxT("use_system_defaults"), useDefaults
);
643 if (useDefaults
!= 0)
644 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
647 expr
->GetAttributeValue(wxT("id"), id
);
648 dialogItem
->SetId(id
);
650 if (style
!= wxT(""))
652 windowStyle
= wxParseWindowStyle(style
);
654 dialogItem
->SetStyle(windowStyle
);
655 dialogItem
->SetValue1(isModal
);
656 if (windowStyle
& wxDIALOG_MODAL
) // Uses style in wxWin 2
657 dialogItem
->SetValue1(TRUE
);
659 dialogItem
->SetName(name
);
660 dialogItem
->SetTitle(title
);
661 dialogItem
->SetSize(x
, y
, width
, height
);
663 if (backColourHex
!= wxT(""))
668 r
= wxHexToDec(backColourHex
.Mid(0, 2));
669 g
= wxHexToDec(backColourHex
.Mid(2, 2));
670 b
= wxHexToDec(backColourHex
.Mid(4, 2));
671 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
673 if (labelColourHex
!= wxT(""))
678 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
679 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
680 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
681 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
683 if (buttonColourHex
!= wxT(""))
688 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
689 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
690 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
691 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
695 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
696 else if (buttonFontExpr
)
697 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
698 else if (labelFontExpr
)
699 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
701 // Now parse all controls
702 wxExpr
*controlExpr
= expr
->GetFirst();
705 if (controlExpr
->Number() == 3)
707 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
708 if (controlKeyword
!= wxT("") && controlKeyword
== wxT("control"))
710 // The value part: always a list.
711 wxExpr
*listExpr
= controlExpr
->Nth(2);
712 if (listExpr
->Type() == PrologList
)
714 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
717 dialogItem
->GetChildren().Append(controlItem
);
722 controlExpr
= controlExpr
->GetNext();
727 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
729 wxItemResource
*controlItem
= new wxItemResource
;
731 // First, find the standard features of a control definition:
732 // [optional integer/string id], control name, title, style, name, x, y, width, height
734 wxString controlType
;
739 long windowStyle
= 0;
740 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
743 wxExpr
*expr1
= expr
->Nth(0);
745 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
747 if ( wxIsValidControlClass(expr1
->StringValue()) )
750 controlType
= expr1
->StringValue();
754 wxString
str(expr1
->StringValue());
755 id
= wxResourceGetIdentifier(str
, &table
);
758 wxLogWarning(_("Could not resolve control class or id '%s'. "
759 "Use (non-zero) integer instead\n or provide #define "
760 "(see manual for caveats)"),
761 (const wxChar
*) expr1
->StringValue());
763 return (wxItemResource
*) NULL
;
767 // Success - we have an id, so the 2nd element must be the control class.
768 controlType
= expr
->Nth(1)->StringValue();
773 else if (expr1
->Type() == PrologInteger
)
775 id
= (int)expr1
->IntegerValue();
776 // Success - we have an id, so the 2nd element must be the control class.
777 controlType
= expr
->Nth(1)->StringValue();
781 expr1
= expr
->Nth(count
);
784 title
= expr1
->StringValue();
786 expr1
= expr
->Nth(count
);
790 style
= expr1
->StringValue();
791 windowStyle
= wxParseWindowStyle(style
);
794 expr1
= expr
->Nth(count
);
797 name
= expr1
->StringValue();
799 expr1
= expr
->Nth(count
);
802 x
= (int)expr1
->IntegerValue();
804 expr1
= expr
->Nth(count
);
807 y
= (int)expr1
->IntegerValue();
809 expr1
= expr
->Nth(count
);
812 width
= (int)expr1
->IntegerValue();
814 expr1
= expr
->Nth(count
);
817 height
= (int)expr1
->IntegerValue();
819 controlItem
->SetStyle(windowStyle
);
820 controlItem
->SetName(name
);
821 controlItem
->SetTitle(title
);
822 controlItem
->SetSize(x
, y
, width
, height
);
823 controlItem
->SetType(controlType
);
824 controlItem
->SetId(id
);
826 if (controlType
== wxT("wxButton"))
828 // Check for bitmap resource name (in case loading old-style resource file)
829 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
831 wxString
str(expr
->Nth(count
)->StringValue());
836 controlItem
->SetValue4(str
);
837 controlItem
->SetType(wxT("wxBitmapButton"));
840 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
841 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
843 else if (controlType
== wxT("wxBitmapButton"))
845 // Check for bitmap resource name
846 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
848 wxString
str(expr
->Nth(count
)->StringValue());
849 controlItem
->SetValue4(str
);
851 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
852 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
855 else if (controlType
== wxT("wxCheckBox"))
857 // Check for default value
858 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
860 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
862 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
863 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
867 else if (controlType
== wxT("wxRadioButton"))
869 // Check for default value
870 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
872 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
874 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
875 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
879 else if (controlType
== wxT("wxText") || controlType
== wxT("wxTextCtrl") || controlType
== wxT("wxMultiText"))
881 // Check for default value
882 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
884 wxString
str(expr
->Nth(count
)->StringValue());
885 controlItem
->SetValue4(str
);
888 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
890 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
891 // Do nothing - no label font any more
893 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
894 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
898 else if (controlType
== wxT("wxMessage") || controlType
== wxT("wxStaticText"))
900 // Check for bitmap resource name (in case it's an old-style .wxr file)
901 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
903 wxString
str(expr
->Nth(count
)->StringValue());
904 controlItem
->SetValue4(str
);
906 controlItem
->SetType(wxT("wxStaticText"));
908 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
909 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
911 else if (controlType
== wxT("wxStaticBitmap"))
913 // Check for bitmap resource name
914 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
916 wxString
str(expr
->Nth(count
)->StringValue());
917 controlItem
->SetValue4(str
);
920 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
921 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
923 else if (controlType
== wxT("wxGroupBox") || controlType
== wxT("wxStaticBox"))
925 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
926 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
928 else if (controlType
== wxT("wxGauge"))
930 // Check for default value
931 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
933 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
937 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
939 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
942 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
944 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
948 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
949 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
954 else if (controlType
== wxT("wxSlider"))
956 // Check for default value
957 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
959 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
963 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
965 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
969 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
971 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
974 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
976 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
980 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
981 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
987 else if (controlType
== wxT("wxScrollBar"))
990 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
992 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
996 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
998 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1002 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1004 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1008 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1009 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1014 else if (controlType
== wxT("wxListBox"))
1016 wxExpr
*valueList
= (wxExpr
*) NULL
;
1018 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1020 wxStringList stringList
;
1021 wxExpr
*stringExpr
= valueList
->GetFirst();
1024 stringList
.Add(stringExpr
->StringValue());
1025 stringExpr
= stringExpr
->GetNext();
1027 controlItem
->SetStringValues(stringList
);
1029 // This is now obsolete: it's in the window style.
1030 // Check for wxSINGLE/wxMULTIPLE
1031 wxExpr
*mult
= (wxExpr
*) NULL
;
1033 controlItem->SetValue1(wxLB_SINGLE);
1035 if ((mult
= expr
->Nth(count
)) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1038 wxString m(mult->StringValue());
1039 if (m == "wxLB_MULTIPLE")
1040 controlItem->SetValue1(wxLB_MULTIPLE);
1041 else if (m == "wxLB_EXTENDED")
1042 controlItem->SetValue1(wxLB_EXTENDED);
1047 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1049 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1051 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1052 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1056 else if (controlType
== wxT("wxChoice"))
1058 wxExpr
*valueList
= (wxExpr
*) NULL
;
1059 // Check for default value list
1060 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1062 wxStringList stringList
;
1063 wxExpr
*stringExpr
= valueList
->GetFirst();
1066 stringList
.Add(stringExpr
->StringValue());
1067 stringExpr
= stringExpr
->GetNext();
1069 controlItem
->SetStringValues(stringList
);
1073 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1075 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1078 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1079 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1084 else if (controlType
== wxT("wxComboBox"))
1086 wxExpr
*textValue
= expr
->Nth(count
);
1087 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1089 wxString
str(textValue
->StringValue());
1090 controlItem
->SetValue4(str
);
1094 wxExpr
*valueList
= (wxExpr
*) NULL
;
1095 // Check for default value list
1096 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1098 wxStringList stringList
;
1099 wxExpr
*stringExpr
= valueList
->GetFirst();
1102 stringList
.Add(stringExpr
->StringValue());
1103 stringExpr
= stringExpr
->GetNext();
1105 controlItem
->SetStringValues(stringList
);
1109 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1111 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1114 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1115 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1122 else if (controlType
== wxT("wxRadioBox"))
1124 wxExpr
*valueList
= (wxExpr
*) NULL
;
1125 // Check for default value list
1126 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1128 wxStringList stringList
;
1129 wxExpr
*stringExpr
= valueList
->GetFirst();
1132 stringList
.Add(stringExpr
->StringValue());
1133 stringExpr
= stringExpr
->GetNext();
1135 controlItem
->SetStringValues(stringList
);
1138 // majorDim (number of rows or cols)
1139 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1141 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1145 controlItem
->SetValue1(0);
1147 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1149 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1152 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1153 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1161 return (wxItemResource
*) NULL
;
1166 // Forward declaration
1167 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1170 * Interpet a menu item
1173 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1175 wxItemResource
*item
= new wxItemResource
;
1177 wxExpr
*labelExpr
= expr
->Nth(0);
1178 wxExpr
*idExpr
= expr
->Nth(1);
1179 wxExpr
*helpExpr
= expr
->Nth(2);
1180 wxExpr
*checkableExpr
= expr
->Nth(3);
1182 // Further keywords/attributes to follow sometime...
1183 if (expr
->Number() == 0)
1185 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1186 item
->SetType(wxT("wxMenuSeparator"));
1191 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1192 item
->SetType(wxT("wxMenu")); // Well, menu item, but doesn't matter.
1195 wxString
str(labelExpr
->StringValue());
1196 item
->SetTitle(str
);
1201 // If a string or word, must look up in identifier table.
1202 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1204 wxString
str(idExpr
->StringValue());
1205 id
= wxResourceGetIdentifier(str
, &table
);
1208 wxLogWarning(_("Could not resolve menu id '%s'. "
1209 "Use (non-zero) integer instead\n"
1210 "or provide #define (see manual for caveats)"),
1211 (const wxChar
*) idExpr
->StringValue());
1214 else if (idExpr
->Type() == PrologInteger
)
1215 id
= (int)idExpr
->IntegerValue();
1216 item
->SetValue1(id
);
1220 wxString
str(helpExpr
->StringValue());
1221 item
->SetValue4(str
);
1224 item
->SetValue2(checkableExpr
->IntegerValue());
1226 // Find the first expression that's a list, for submenu
1227 wxExpr
*subMenuExpr
= expr
->GetFirst();
1228 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1229 subMenuExpr
= subMenuExpr
->GetNext();
1233 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1234 item
->GetChildren().Append(child
);
1235 subMenuExpr
= subMenuExpr
->GetNext();
1242 * Interpret a nested list as a menu
1245 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1247 wxItemResource *menu = new wxItemResource;
1248 // menu->SetType(wxTYPE_MENU);
1249 menu->SetType("wxMenu");
1250 wxExpr *element = expr->GetFirst();
1253 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1255 menu->GetChildren().Append(item);
1256 element = element->GetNext();
1262 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1264 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1265 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1267 return (wxItemResource
*) NULL
;
1269 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1272 return (wxItemResource
*) NULL
;
1275 if (expr
->GetAttributeValue(wxT("name"), name
))
1277 menuResource
->SetName(name
);
1280 return menuResource
;
1283 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1285 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1286 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1288 return (wxItemResource
*) NULL
;
1290 wxItemResource
*resource
= new wxItemResource
;
1291 resource
->SetType(wxT("wxMenu"));
1292 // resource->SetType(wxTYPE_MENU);
1294 wxExpr
*element
= listExpr
->GetFirst();
1297 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1298 resource
->GetChildren().Append(menuResource
);
1299 element
= element
->GetNext();
1303 if (expr
->GetAttributeValue(wxT("name"), name
))
1305 resource
->SetName(name
);
1311 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1313 return (wxItemResource
*) NULL
;
1316 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1318 wxItemResource
*bitmapItem
= new wxItemResource
;
1319 // bitmapItem->SetType(wxTYPE_BITMAP);
1320 bitmapItem
->SetType(wxT("wxBitmap"));
1322 if (expr
->GetAttributeValue(wxT("name"), name
))
1324 bitmapItem
->SetName(name
);
1326 // Now parse all bitmap specifications
1327 wxExpr
*bitmapExpr
= expr
->GetFirst();
1330 if (bitmapExpr
->Number() == 3)
1332 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1333 if (bitmapKeyword
== wxT("bitmap") || bitmapKeyword
== wxT("icon"))
1335 // The value part: always a list.
1336 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1337 if (listExpr
->Type() == PrologList
)
1339 wxItemResource
*bitmapSpec
= new wxItemResource
;
1340 // bitmapSpec->SetType(wxTYPE_BITMAP);
1341 bitmapSpec
->SetType(wxT("wxBitmap"));
1343 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1344 // where everything after 'filename' is optional.
1345 wxExpr
*nameExpr
= listExpr
->Nth(0);
1346 wxExpr
*typeExpr
= listExpr
->Nth(1);
1347 wxExpr
*platformExpr
= listExpr
->Nth(2);
1348 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1349 wxExpr
*xresExpr
= listExpr
->Nth(4);
1350 wxExpr
*yresExpr
= listExpr
->Nth(5);
1351 if (nameExpr
&& nameExpr
->StringValue() != wxT(""))
1353 bitmapSpec
->SetName(nameExpr
->StringValue());
1355 if (typeExpr
&& typeExpr
->StringValue() != wxT(""))
1357 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1360 bitmapSpec
->SetValue1(0);
1362 if (platformExpr
&& platformExpr
->StringValue() != wxT(""))
1364 wxString
plat(platformExpr
->StringValue());
1365 if (plat
== wxT("windows") || plat
== wxT("WINDOWS"))
1366 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1367 else if (plat
== wxT("x") || plat
== wxT("X"))
1368 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1369 else if (plat
== wxT("mac") || plat
== wxT("MAC"))
1370 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1372 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1375 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1378 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1382 xres
= (int)xresExpr
->IntegerValue();
1384 yres
= (int)yresExpr
->IntegerValue();
1385 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1387 bitmapItem
->GetChildren().Append(bitmapSpec
);
1391 bitmapExpr
= bitmapExpr
->GetNext();
1397 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1399 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1402 // item->SetType(wxTYPE_ICON);
1403 item
->SetType(wxT("wxIcon"));
1407 return (wxItemResource
*) NULL
;
1410 // Interpret list expression as a font
1411 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1413 if (expr
->Type() != PrologList
)
1417 int family
= wxSWISS
;
1418 int style
= wxNORMAL
;
1419 int weight
= wxNORMAL
;
1421 wxString
faceName(wxT(""));
1423 wxExpr
*pointExpr
= expr
->Nth(0);
1424 wxExpr
*familyExpr
= expr
->Nth(1);
1425 wxExpr
*styleExpr
= expr
->Nth(2);
1426 wxExpr
*weightExpr
= expr
->Nth(3);
1427 wxExpr
*underlineExpr
= expr
->Nth(4);
1428 wxExpr
*faceNameExpr
= expr
->Nth(5);
1430 point
= (int)pointExpr
->IntegerValue();
1435 str
= familyExpr
->StringValue();
1436 family
= (int)wxParseWindowStyle(str
);
1440 str
= styleExpr
->StringValue();
1441 style
= (int)wxParseWindowStyle(str
);
1445 str
= weightExpr
->StringValue();
1446 weight
= (int)wxParseWindowStyle(str
);
1449 underline
= (int)underlineExpr
->IntegerValue();
1451 faceName
= faceNameExpr
->StringValue();
1453 wxFont
font(point
, family
, style
, weight
, (underline
!= 0), faceName
);
1457 // Separate file for the remainder of this, for BC++/Win16
1459 #if !((defined(__BORLANDC__) || defined(__SC__)) && defined(__WIN16__))
1461 * (Re)allocate buffer for reading in from resource file
1464 bool wxReallocateResourceBuffer()
1466 if (!wxResourceBuffer
)
1468 wxResourceBufferSize
= 1000;
1469 wxResourceBuffer
= new char[wxResourceBufferSize
];
1472 if (wxResourceBuffer
)
1474 long newSize
= wxResourceBufferSize
+ 1000;
1475 char *tmp
= new char[(int)newSize
];
1476 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1477 delete[] wxResourceBuffer
;
1478 wxResourceBuffer
= tmp
;
1479 wxResourceBufferSize
= newSize
;
1484 static bool wxEatWhiteSpace(FILE *fd
)
1488 while ((ch
= getc(fd
)) != EOF
)
1503 ungetc(prev_ch
, fd
);
1511 while ((ch
= getc(fd
)) != EOF
)
1513 if (ch
== '/' && prev_ch
== '*')
1521 static char buffer
[255];
1522 fgets(buffer
, 255, fd
);
1526 ungetc(prev_ch
, fd
);
1541 bool wxGetResourceToken(FILE *fd
)
1543 if (!wxResourceBuffer
)
1544 wxReallocateResourceBuffer();
1545 wxResourceBuffer
[0] = 0;
1546 wxEatWhiteSpace(fd
);
1552 wxResourceBufferCount
= 0;
1559 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1562 // Escaped characters
1563 else if (ch
== '\\')
1565 int newCh
= getc(fd
);
1568 else if (newCh
== 10)
1576 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1577 wxReallocateResourceBuffer();
1578 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1579 wxResourceBufferCount
++;
1582 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1586 wxResourceBufferCount
= 0;
1588 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1590 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1591 wxReallocateResourceBuffer();
1592 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1593 wxResourceBufferCount
++;
1597 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1605 * Files are in form:
1606 static char *name = "....";
1607 with possible comments.
1610 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1613 table
= wxDefaultResourceTable
;
1615 // static or #define
1616 if (!wxGetResourceToken(fd
))
1622 if (strcmp(wxResourceBuffer
, "#define") == 0)
1624 wxGetResourceToken(fd
);
1625 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1626 wxGetResourceToken(fd
);
1627 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1628 if (wxIsdigit(value
[0]))
1630 int val
= (int)wxAtol(value
);
1631 wxResourceAddIdentifier(name
, val
, table
);
1635 wxLogWarning(_("#define %s must be an integer."), name
);
1645 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1647 wxGetResourceToken(fd
);
1648 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1649 wxChar
*actualName
= name
;
1650 if (name
[0] == wxT('"'))
1651 actualName
= name
+ 1;
1652 int len
= wxStrlen(name
);
1653 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1655 if (!wxResourceParseIncludeFile(actualName
, table
))
1657 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1662 else if (strcmp(wxResourceBuffer
, "static") != 0)
1665 wxStrcpy(buf
, _("Found "));
1666 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
1667 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1673 if (!wxGetResourceToken(fd
))
1675 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1680 if (strcmp(wxResourceBuffer
, "char") != 0)
1682 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1687 if (!wxGetResourceToken(fd
))
1689 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1694 if (wxResourceBuffer
[0] != '*')
1696 wxLogWarning(_("Expected '*' whilst parsing resource."));
1699 wxChar nameBuf
[100];
1700 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
1704 if (!wxGetResourceToken(fd
))
1706 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1711 if (strcmp(wxResourceBuffer
, "=") != 0)
1713 wxLogWarning(_("Expected '=' whilst parsing resource."));
1718 if (!wxGetResourceToken(fd
))
1720 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1726 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1728 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1733 if (!wxGetResourceToken(fd
))
1741 * Parses string window style into integer window style
1745 * Style flag parsing, e.g.
1746 * "wxSYSTEM_MENU | wxBORDER" -> integer
1749 wxChar
* wxResourceParseWord(wxChar
*s
, int *i
)
1752 return (wxChar
*) NULL
;
1754 static wxChar buf
[150];
1755 int len
= wxStrlen(s
);
1758 while ((ii
< len
) && (wxIsalpha(s
[ii
]) || (s
[ii
] == wxT('_'))))
1766 // Eat whitespace and conjunction characters
1767 while ((ii
< len
) &&
1768 ((s
[ii
] == wxT(' ')) || (s
[ii
] == wxT('|')) || (s
[ii
] == wxT(','))))
1774 return (wxChar
*) NULL
;
1779 struct wxResourceBitListStruct
1785 static wxResourceBitListStruct wxResourceBitListTable
[] =
1788 { wxT("wxSINGLE"), wxLB_SINGLE
},
1789 { wxT("wxMULTIPLE"), wxLB_MULTIPLE
},
1790 { wxT("wxEXTENDED"), wxLB_EXTENDED
},
1791 { wxT("wxLB_SINGLE"), wxLB_SINGLE
},
1792 { wxT("wxLB_MULTIPLE"), wxLB_MULTIPLE
},
1793 { wxT("wxLB_EXTENDED"), wxLB_EXTENDED
},
1794 { wxT("wxLB_NEEDED_SB"), wxLB_NEEDED_SB
},
1795 { wxT("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB
},
1796 { wxT("wxLB_SORT"), wxLB_SORT
},
1797 { wxT("wxLB_OWNERDRAW"), wxLB_OWNERDRAW
},
1798 { wxT("wxLB_HSCROLL"), wxLB_HSCROLL
},
1801 { wxT("wxCB_SIMPLE"), wxCB_SIMPLE
},
1802 { wxT("wxCB_DROPDOWN"), wxCB_DROPDOWN
},
1803 { wxT("wxCB_READONLY"), wxCB_READONLY
},
1804 { wxT("wxCB_SORT"), wxCB_SORT
},
1807 { wxT("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR
},
1808 { wxT("wxGA_HORIZONTAL"), wxGA_HORIZONTAL
},
1809 { wxT("wxGA_VERTICAL"), wxGA_VERTICAL
},
1812 { wxT("wxPASSWORD"), wxPASSWORD
},
1813 { wxT("wxPROCESS_ENTER"), wxPROCESS_ENTER
},
1814 { wxT("wxTE_PASSWORD"), wxTE_PASSWORD
},
1815 { wxT("wxTE_READONLY"), wxTE_READONLY
},
1816 { wxT("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER
},
1817 { wxT("wxTE_MULTILINE"), wxTE_MULTILINE
},
1818 { wxT("wxTE_NO_VSCROLL"), wxTE_NO_VSCROLL
},
1820 /* wxRadioBox/wxRadioButton */
1821 { wxT("wxRB_GROUP"), wxRB_GROUP
},
1822 { wxT("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS
},
1823 { wxT("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS
},
1824 { wxT("wxRA_HORIZONTAL"), wxRA_HORIZONTAL
},
1825 { wxT("wxRA_VERTICAL"), wxRA_VERTICAL
},
1828 { wxT("wxSL_HORIZONTAL"), wxSL_HORIZONTAL
},
1829 { wxT("wxSL_VERTICAL"), wxSL_VERTICAL
},
1830 { wxT("wxSL_AUTOTICKS"), wxSL_AUTOTICKS
},
1831 { wxT("wxSL_LABELS"), wxSL_LABELS
},
1832 { wxT("wxSL_LEFT"), wxSL_LEFT
},
1833 { wxT("wxSL_TOP"), wxSL_TOP
},
1834 { wxT("wxSL_RIGHT"), wxSL_RIGHT
},
1835 { wxT("wxSL_BOTTOM"), wxSL_BOTTOM
},
1836 { wxT("wxSL_BOTH"), wxSL_BOTH
},
1837 { wxT("wxSL_SELRANGE"), wxSL_SELRANGE
},
1840 { wxT("wxSB_HORIZONTAL"), wxSB_HORIZONTAL
},
1841 { wxT("wxSB_VERTICAL"), wxSB_VERTICAL
},
1844 { wxT("wxBU_AUTODRAW"), wxBU_AUTODRAW
},
1845 { wxT("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW
},
1848 { wxT("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS
},
1849 { wxT("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS
},
1850 { wxT("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT
},
1853 { wxT("wxLC_ICON"), wxLC_ICON
},
1854 { wxT("wxLC_SMALL_ICON"), wxLC_SMALL_ICON
},
1855 { wxT("wxLC_LIST"), wxLC_LIST
},
1856 { wxT("wxLC_REPORT"), wxLC_REPORT
},
1857 { wxT("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP
},
1858 { wxT("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT
},
1859 { wxT("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE
},
1860 { wxT("wxLC_USER_TEXT"), wxLC_USER_TEXT
},
1861 { wxT("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS
},
1862 { wxT("wxLC_NO_HEADER"), wxLC_NO_HEADER
},
1863 { wxT("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER
},
1864 { wxT("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL
},
1865 { wxT("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING
},
1866 { wxT("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING
},
1869 { wxT("wxSP_VERTICAL"), wxSP_VERTICAL
},
1870 { wxT("wxSP_HORIZONTAL"), wxSP_HORIZONTAL
},
1871 { wxT("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS
},
1872 { wxT("wxSP_WRAP"), wxSP_WRAP
},
1875 { wxT("wxSP_NOBORDER"), wxSP_NOBORDER
},
1876 { wxT("wxSP_3D"), wxSP_3D
},
1877 { wxT("wxSP_BORDER"), wxSP_BORDER
},
1880 { wxT("wxTC_MULTILINE"), wxTC_MULTILINE
},
1881 { wxT("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY
},
1882 { wxT("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH
},
1883 { wxT("wxTC_OWNERDRAW"), wxTC_OWNERDRAW
},
1886 { wxT("wxST_SIZEGRIP"), wxST_SIZEGRIP
},
1889 { wxT("wxFIXED_LENGTH"), wxFIXED_LENGTH
},
1890 { wxT("wxALIGN_LEFT"), wxALIGN_LEFT
},
1891 { wxT("wxALIGN_CENTER"), wxALIGN_CENTER
},
1892 { wxT("wxALIGN_CENTRE"), wxALIGN_CENTRE
},
1893 { wxT("wxALIGN_RIGHT"), wxALIGN_RIGHT
},
1894 { wxT("wxCOLOURED"), wxCOLOURED
},
1897 { wxT("wxTB_3DBUTTONS"), wxTB_3DBUTTONS
},
1898 { wxT("wxTB_HORIZONTAL"), wxTB_HORIZONTAL
},
1899 { wxT("wxTB_VERTICAL"), wxTB_VERTICAL
},
1900 { wxT("wxTB_FLAT"), wxTB_FLAT
},
1903 { wxT("wxDIALOG_MODAL"), wxDIALOG_MODAL
},
1906 { wxT("wxVSCROLL"), wxVSCROLL
},
1907 { wxT("wxHSCROLL"), wxHSCROLL
},
1908 { wxT("wxCAPTION"), wxCAPTION
},
1909 { wxT("wxSTAY_ON_TOP"), wxSTAY_ON_TOP
},
1910 { wxT("wxICONIZE"), wxICONIZE
},
1911 { wxT("wxMINIMIZE"), wxICONIZE
},
1912 { wxT("wxMAXIMIZE"), wxMAXIMIZE
},
1914 { wxT("wxMDI_PARENT"), 0},
1915 { wxT("wxMDI_CHILD"), 0},
1916 { wxT("wxTHICK_FRAME"), wxTHICK_FRAME
},
1917 { wxT("wxRESIZE_BORDER"), wxRESIZE_BORDER
},
1918 { wxT("wxSYSTEM_MENU"), wxSYSTEM_MENU
},
1919 { wxT("wxMINIMIZE_BOX"), wxMINIMIZE_BOX
},
1920 { wxT("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX
},
1921 { wxT("wxRESIZE_BOX"), wxRESIZE_BOX
},
1922 { wxT("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE
},
1923 { wxT("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE
},
1924 { wxT("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE
},
1925 { wxT("wxBORDER"), wxBORDER
},
1926 { wxT("wxRETAINED"), wxRETAINED
},
1927 { wxT("wxNATIVE_IMPL"), 0},
1928 { wxT("wxEXTENDED_IMPL"), 0},
1929 { wxT("wxBACKINGSTORE"), wxBACKINGSTORE
},
1930 // { wxT("wxFLAT"), wxFLAT},
1931 // { wxT("wxMOTIF_RESIZE"), wxMOTIF_RESIZE},
1932 { wxT("wxFIXED_LENGTH"), 0},
1933 { wxT("wxDOUBLE_BORDER"), wxDOUBLE_BORDER
},
1934 { wxT("wxSUNKEN_BORDER"), wxSUNKEN_BORDER
},
1935 { wxT("wxRAISED_BORDER"), wxRAISED_BORDER
},
1936 { wxT("wxSIMPLE_BORDER"), wxSIMPLE_BORDER
},
1937 { wxT("wxSTATIC_BORDER"), wxSTATIC_BORDER
},
1938 { wxT("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW
},
1939 { wxT("wxNO_BORDER"), wxNO_BORDER
},
1940 { wxT("wxCLIP_CHILDREN"), wxCLIP_CHILDREN
},
1941 { wxT("wxTAB_TRAVERSAL"), 0}, // Compatibility only
1943 { wxT("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ
},
1944 { wxT("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT
},
1946 // Text font families
1947 { wxT("wxDEFAULT"), wxDEFAULT
},
1948 { wxT("wxDECORATIVE"), wxDECORATIVE
},
1949 { wxT("wxROMAN"), wxROMAN
},
1950 { wxT("wxSCRIPT"), wxSCRIPT
},
1951 { wxT("wxSWISS"), wxSWISS
},
1952 { wxT("wxMODERN"), wxMODERN
},
1953 { wxT("wxTELETYPE"), wxTELETYPE
},
1954 { wxT("wxVARIABLE"), wxVARIABLE
},
1955 { wxT("wxFIXED"), wxFIXED
},
1956 { wxT("wxNORMAL"), wxNORMAL
},
1957 { wxT("wxLIGHT"), wxLIGHT
},
1958 { wxT("wxBOLD"), wxBOLD
},
1959 { wxT("wxITALIC"), wxITALIC
},
1960 { wxT("wxSLANT"), wxSLANT
},
1961 { wxT("wxSOLID"), wxSOLID
},
1962 { wxT("wxDOT"), wxDOT
},
1963 { wxT("wxLONG_DASH"), wxLONG_DASH
},
1964 { wxT("wxSHORT_DASH"), wxSHORT_DASH
},
1965 { wxT("wxDOT_DASH"), wxDOT_DASH
},
1966 { wxT("wxUSER_DASH"), wxUSER_DASH
},
1967 { wxT("wxTRANSPARENT"), wxTRANSPARENT
},
1968 { wxT("wxSTIPPLE"), wxSTIPPLE
},
1969 { wxT("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH
},
1970 { wxT("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH
},
1971 { wxT("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH
},
1972 { wxT("wxCROSS_HATCH"), wxCROSS_HATCH
},
1973 { wxT("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH
},
1974 { wxT("wxVERTICAL_HATCH"), wxVERTICAL_HATCH
},
1975 { wxT("wxJOIN_BEVEL"), wxJOIN_BEVEL
},
1976 { wxT("wxJOIN_MITER"), wxJOIN_MITER
},
1977 { wxT("wxJOIN_ROUND"), wxJOIN_ROUND
},
1978 { wxT("wxCAP_ROUND"), wxCAP_ROUND
},
1979 { wxT("wxCAP_PROJECTING"), wxCAP_PROJECTING
},
1980 { wxT("wxCAP_BUTT"), wxCAP_BUTT
},
1983 { wxT("wxCLEAR"), wxCLEAR
},
1984 { wxT("wxXOR"), wxXOR
},
1985 { wxT("wxINVERT"), wxINVERT
},
1986 { wxT("wxOR_REVERSE"), wxOR_REVERSE
},
1987 { wxT("wxAND_REVERSE"), wxAND_REVERSE
},
1988 { wxT("wxCOPY"), wxCOPY
},
1989 { wxT("wxAND"), wxAND
},
1990 { wxT("wxAND_INVERT"), wxAND_INVERT
},
1991 { wxT("wxNO_OP"), wxNO_OP
},
1992 { wxT("wxNOR"), wxNOR
},
1993 { wxT("wxEQUIV"), wxEQUIV
},
1994 { wxT("wxSRC_INVERT"), wxSRC_INVERT
},
1995 { wxT("wxOR_INVERT"), wxOR_INVERT
},
1996 { wxT("wxNAND"), wxNAND
},
1997 { wxT("wxOR"), wxOR
},
1998 { wxT("wxSET"), wxSET
},
2000 { wxT("wxFLOOD_SURFACE"), wxFLOOD_SURFACE
},
2001 { wxT("wxFLOOD_BORDER"), wxFLOOD_BORDER
},
2002 { wxT("wxODDEVEN_RULE"), wxODDEVEN_RULE
},
2003 { wxT("wxWINDING_RULE"), wxWINDING_RULE
},
2004 { wxT("wxHORIZONTAL"), wxHORIZONTAL
},
2005 { wxT("wxVERTICAL"), wxVERTICAL
},
2006 { wxT("wxBOTH"), wxBOTH
},
2007 { wxT("wxCENTER_FRAME"), wxCENTER_FRAME
},
2008 { wxT("wxOK"), wxOK
},
2009 { wxT("wxYES_NO"), wxYES_NO
},
2010 { wxT("wxCANCEL"), wxCANCEL
},
2011 { wxT("wxYES"), wxYES
},
2012 { wxT("wxNO"), wxNO
},
2013 { wxT("wxICON_EXCLAMATION"), wxICON_EXCLAMATION
},
2014 { wxT("wxICON_HAND"), wxICON_HAND
},
2015 { wxT("wxICON_QUESTION"), wxICON_QUESTION
},
2016 { wxT("wxICON_INFORMATION"), wxICON_INFORMATION
},
2017 { wxT("wxICON_STOP"), wxICON_STOP
},
2018 { wxT("wxICON_ASTERISK"), wxICON_ASTERISK
},
2019 { wxT("wxICON_MASK"), wxICON_MASK
},
2020 { wxT("wxCENTRE"), wxCENTRE
},
2021 { wxT("wxCENTER"), wxCENTRE
},
2022 { wxT("wxUSER_COLOURS"), wxUSER_COLOURS
},
2023 { wxT("wxVERTICAL_LABEL"), 0},
2024 { wxT("wxHORIZONTAL_LABEL"), 0},
2026 // Bitmap types (not strictly styles)
2027 { wxT("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM
},
2028 { wxT("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM
},
2029 { wxT("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP
},
2030 { wxT("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2031 { wxT("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2032 { wxT("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF
},
2033 { wxT("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF
},
2034 { wxT("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO
},
2035 { wxT("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE
},
2036 { wxT("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR
},
2037 { wxT("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE
},
2038 { wxT("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA
},
2039 { wxT("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA
},
2040 { wxT("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY
}
2043 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2045 long wxParseWindowStyle(const wxString
& bitListString
)
2050 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2051 while (word
!= NULL
)
2055 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2056 if (wxStrcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2058 bitList
|= wxResourceBitListTable
[j
].bits
;
2064 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
2067 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2073 * Load a bitmap from a wxWindows resource, choosing an optimum
2074 * depth and appropriate type.
2077 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2080 table
= wxDefaultResourceTable
;
2082 wxItemResource
*item
= table
->FindResource(resource
);
2085 if ((item
->GetType() == wxT("")) || (item
->GetType() != wxT("wxBitmap")))
2087 wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar
*) resource
);
2088 return wxNullBitmap
;
2090 int thisDepth
= wxDisplayDepth();
2091 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2093 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2095 // Try to find optimum bitmap for this platform/colour depth
2096 wxNode
*node
= item
->GetChildren().First();
2099 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2100 int platform
= (int)child
->GetValue2();
2101 int noColours
= (int)child
->GetValue3();
2103 char *name = child->GetName();
2104 int bitmapType = (int)child->GetValue1();
2105 int xRes = child->GetWidth();
2106 int yRes = child->GetHeight();
2111 case RESOURCE_PLATFORM_ANY
:
2113 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2114 optResource
= child
;
2117 // Maximise the number of colours.
2118 // If noColours is zero (unspecified), then assume this
2119 // is the right one.
2120 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2121 optResource
= child
;
2126 case RESOURCE_PLATFORM_WINDOWS
:
2128 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2129 optResource
= child
;
2132 // Maximise the number of colours
2133 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2134 optResource
= child
;
2140 case RESOURCE_PLATFORM_X
:
2142 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2143 optResource
= child
;
2146 // Maximise the number of colours
2147 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2148 optResource
= child
;
2154 case RESOURCE_PLATFORM_MAC
:
2156 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2157 optResource
= child
;
2160 // Maximise the number of colours
2161 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2162 optResource
= child
;
2170 node
= node
->Next();
2172 // If no matching resource, fail.
2174 return wxNullBitmap
;
2176 wxString name
= optResource
->GetName();
2177 int bitmapType
= (int)optResource
->GetValue1();
2180 case wxBITMAP_TYPE_XBM_DATA
:
2183 wxItemResource
*item
= table
->FindResource(name
);
2186 wxLogWarning(_("Failed to find XBM resource %s.\n"
2187 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2188 return wxNullBitmap
;
2190 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2192 wxLogWarning(_("No XBM facility available!"));
2196 case wxBITMAP_TYPE_XPM_DATA
:
2198 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2199 wxItemResource
*item
= table
->FindResource(name
);
2202 wxLogWarning(_("Failed to find XPM resource %s.\n"
2203 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2204 return wxNullBitmap
;
2206 return wxBitmap((char **)item
->GetValue1());
2208 wxLogWarning(_("No XPM facility available!"));
2214 return wxBitmap(name
, bitmapType
);
2218 return wxNullBitmap
;
2222 wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar
*) resource
);
2223 return wxNullBitmap
;
2228 * Load an icon from a wxWindows resource, choosing an optimum
2229 * depth and appropriate type.
2232 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2235 table
= wxDefaultResourceTable
;
2237 wxItemResource
*item
= table
->FindResource(resource
);
2240 if ((item
->GetType() == wxT("")) || wxStrcmp(item
->GetType(), wxT("wxIcon")) != 0)
2242 wxLogWarning(_("%s not an icon resource specification."), (const wxChar
*) resource
);
2245 int thisDepth
= wxDisplayDepth();
2246 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2248 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2250 // Try to find optimum icon for this platform/colour depth
2251 wxNode
*node
= item
->GetChildren().First();
2254 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2255 int platform
= (int)child
->GetValue2();
2256 int noColours
= (int)child
->GetValue3();
2258 char *name = child->GetName();
2259 int bitmapType = (int)child->GetValue1();
2260 int xRes = child->GetWidth();
2261 int yRes = child->GetHeight();
2266 case RESOURCE_PLATFORM_ANY
:
2268 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2269 optResource
= child
;
2272 // Maximise the number of colours.
2273 // If noColours is zero (unspecified), then assume this
2274 // is the right one.
2275 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2276 optResource
= child
;
2281 case RESOURCE_PLATFORM_WINDOWS
:
2283 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2284 optResource
= child
;
2287 // Maximise the number of colours
2288 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2289 optResource
= child
;
2295 case RESOURCE_PLATFORM_X
:
2297 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2298 optResource
= child
;
2301 // Maximise the number of colours
2302 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2303 optResource
= child
;
2309 case RESOURCE_PLATFORM_MAC
:
2311 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2312 optResource
= child
;
2315 // Maximise the number of colours
2316 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2317 optResource
= child
;
2325 node
= node
->Next();
2327 // If no matching resource, fail.
2331 wxString name
= optResource
->GetName();
2332 int bitmapType
= (int)optResource
->GetValue1();
2335 case wxBITMAP_TYPE_XBM_DATA
:
2338 wxItemResource
*item
= table
->FindResource(name
);
2341 wxLogWarning(_("Failed to find XBM resource %s.\n"
2342 "Forgot to use wxResourceLoadIconData?"), (const wxChar
*) name
);
2345 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2347 wxLogWarning(_("No XBM facility available!"));
2351 case wxBITMAP_TYPE_XPM_DATA
:
2353 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2355 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2356 wxItemResource *item = table->FindResource(name);
2360 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2364 return wxIcon((char **)item->GetValue1());
2366 wxLogWarning(_("No XPM facility available!"));
2369 wxLogWarning(_("No XPM icon facility available!"));
2375 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2377 return wxIcon(name
, bitmapType
);
2386 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2391 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2393 wxMenu
*menu
= new wxMenu
;
2394 wxNode
*node
= item
->GetChildren().First();
2397 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2398 if ((child
->GetType() != wxT("")) && (child
->GetType() == wxT("wxMenuSeparator")))
2399 menu
->AppendSeparator();
2400 else if (child
->GetChildren().Number() > 0)
2402 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2404 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2408 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2410 node
= node
->Next();
2415 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2418 table
= wxDefaultResourceTable
;
2420 wxItemResource
*menuResource
= table
->FindResource(resource
);
2421 if (menuResource
&& (menuResource
->GetType() != wxT("")) && (menuResource
->GetType() == wxT("wxMenu")))
2424 menuBar
= new wxMenuBar
;
2425 wxNode
*node
= menuResource
->GetChildren().First();
2428 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2429 wxMenu
*menu
= wxResourceCreateMenu(child
);
2431 menuBar
->Append(menu
, child
->GetTitle());
2432 node
= node
->Next();
2436 return (wxMenuBar
*) NULL
;
2439 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2442 table
= wxDefaultResourceTable
;
2444 wxItemResource
*menuResource
= table
->FindResource(resource
);
2445 if (menuResource
&& (menuResource
->GetType() != wxT("")) && (menuResource
->GetType() == wxT("wxMenu")))
2446 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2447 return wxResourceCreateMenu(menuResource
);
2448 return (wxMenu
*) NULL
;
2451 // Global equivalents (so don't have to refer to default table explicitly)
2452 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2455 table
= wxDefaultResourceTable
;
2457 return table
->ParseResourceData(resource
);
2460 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2463 table
= wxDefaultResourceTable
;
2465 return table
->ParseResourceFile(filename
);
2468 // Register XBM/XPM data
2469 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2472 table
= wxDefaultResourceTable
;
2474 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2477 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2480 table
= wxDefaultResourceTable
;
2482 return table
->RegisterResourceBitmapData(name
, data
);
2485 void wxResourceClear(wxResourceTable
*table
)
2488 table
= wxDefaultResourceTable
;
2490 table
->ClearTable();
2497 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2500 table
= wxDefaultResourceTable
;
2502 table
->identifiers
.Put(name
, (wxObject
*)(long)value
);
2506 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2509 table
= wxDefaultResourceTable
;
2511 return (int)(long)table
->identifiers
.Get(name
);
2515 * Parse #include file for #defines (only)
2518 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2521 table
= wxDefaultResourceTable
;
2523 FILE *fd
= fopen(f
.fn_str(), "r");
2528 while (wxGetResourceToken(fd
))
2530 if (strcmp(wxResourceBuffer
, "#define") == 0)
2532 wxGetResourceToken(fd
);
2533 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2534 wxGetResourceToken(fd
);
2535 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2536 if (wxIsdigit(value
[0]))
2538 int val
= (int)wxAtol(value
);
2539 wxResourceAddIdentifier(name
, val
, table
);
2550 * Reading strings as if they were .wxr files
2553 static int getc_string(char *s
)
2555 int ch
= s
[wxResourceStringPtr
];
2560 wxResourceStringPtr
++;
2565 static int ungetc_string()
2567 wxResourceStringPtr
--;
2571 bool wxEatWhiteSpaceString(char *s
)
2575 while ((ch
= getc_string(s
)) != EOF
)
2587 ch
= getc_string(s
);
2598 while ((ch
= getc_string(s
)) != EOF
)
2600 if (ch
== '/' && prev_ch
== '*')
2622 bool wxGetResourceTokenString(char *s
)
2624 if (!wxResourceBuffer
)
2625 wxReallocateResourceBuffer();
2626 wxResourceBuffer
[0] = 0;
2627 wxEatWhiteSpaceString(s
);
2629 int ch
= getc_string(s
);
2633 wxResourceBufferCount
= 0;
2634 ch
= getc_string(s
);
2640 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2643 // Escaped characters
2644 else if (ch
== '\\')
2646 int newCh
= getc_string(s
);
2649 else if (newCh
== 10)
2657 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2658 wxReallocateResourceBuffer();
2659 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2660 wxResourceBufferCount
++;
2661 ch
= getc_string(s
);
2663 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2667 wxResourceBufferCount
= 0;
2669 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2671 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2672 wxReallocateResourceBuffer();
2673 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2674 wxResourceBufferCount
++;
2676 ch
= getc_string(s
);
2678 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2686 * Files are in form:
2687 static char *name = "....";
2688 with possible comments.
2691 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2694 table
= wxDefaultResourceTable
;
2696 // static or #define
2697 if (!wxGetResourceTokenString(s
))
2703 if (strcmp(wxResourceBuffer
, "#define") == 0)
2705 wxGetResourceTokenString(s
);
2706 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2707 wxGetResourceTokenString(s
);
2708 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2709 if (wxIsdigit(value
[0]))
2711 int val
= (int)wxAtol(value
);
2712 wxResourceAddIdentifier(name
, val
, table
);
2716 wxLogWarning(_("#define %s must be an integer."), name
);
2727 else if (strcmp(wxResourceBuffer, "#include") == 0)
2729 wxGetResourceTokenString(s);
2730 char *name = copystring(wxResourceBuffer);
2731 char *actualName = name;
2733 actualName = name + 1;
2734 int len = strlen(name);
2735 if ((len > 0) && (name[len-1] == '"'))
2737 if (!wxResourceParseIncludeFile(actualName, table))
2740 sprintf(buf, _("Could not find resource include file %s."), actualName);
2747 else if (strcmp(wxResourceBuffer
, "static") != 0)
2750 wxStrcpy(buf
, _("Found "));
2751 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
2752 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
2758 if (!wxGetResourceTokenString(s
))
2760 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2765 if (strcmp(wxResourceBuffer
, "char") != 0)
2767 wxLogWarning(_("Expected 'char' whilst parsing resource."));
2772 if (!wxGetResourceTokenString(s
))
2774 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2779 if (wxResourceBuffer
[0] != '*')
2781 wxLogWarning(_("Expected '*' whilst parsing resource."));
2784 wxChar nameBuf
[100];
2785 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
2789 if (!wxGetResourceTokenString(s
))
2791 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2796 if (strcmp(wxResourceBuffer
, "=") != 0)
2798 wxLogWarning(_("Expected '=' whilst parsing resource."));
2803 if (!wxGetResourceTokenString(s
))
2805 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2811 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2813 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2818 if (!wxGetResourceTokenString(s
))
2825 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
2828 table
= wxDefaultResourceTable
;
2833 // Turn backslashes into spaces
2836 int len
= strlen(s
);
2838 for (i
= 0; i
< len
; i
++)
2839 if (s
[i
] == 92 && s
[i
+1] == 13)
2847 wxResourceStringPtr
= 0;
2850 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
2854 return wxResourceInterpretResources(*table
, db
);
2858 * resource loading facility
2861 bool wxWindowBase::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
2864 table
= wxDefaultResourceTable
;
2866 wxItemResource
*resource
= table
->FindResource((const wxChar
*)resourceName
);
2867 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
2868 if (!resource
|| (resource
->GetType() == wxT("")) ||
2869 ! ((resource
->GetType() == wxT("wxDialog")) || (resource
->GetType() == wxT("wxPanel"))))
2872 wxString
title(resource
->GetTitle());
2873 long theWindowStyle
= resource
->GetStyle();
2874 bool isModal
= (resource
->GetValue1() != 0);
2875 int x
= resource
->GetX();
2876 int y
= resource
->GetY();
2877 int width
= resource
->GetWidth();
2878 int height
= resource
->GetHeight();
2879 wxString name
= resource
->GetName();
2881 if (IsKindOf(CLASSINFO(wxDialog
)))
2883 wxDialog
*dialogBox
= (wxDialog
*)this;
2884 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
2885 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
2888 // Only reset the client size if we know we're not going to do it again below.
2889 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
2890 dialogBox
->SetClientSize(width
, height
);
2892 else if (IsKindOf(CLASSINFO(wxPanel
)))
2894 wxPanel
* panel
= (wxPanel
*)this;
2895 if (!panel
->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
| wxTAB_TRAVERSAL
, name
))
2900 if (!((wxWindow
*)this)->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2904 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
2906 // No need to do this since it's done in wxPanel or wxDialog constructor.
2907 // SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
2911 if (resource
->GetFont().Ok())
2912 SetFont(resource
->GetFont());
2913 if (resource
->GetBackgroundColour().Ok())
2914 SetBackgroundColour(resource
->GetBackgroundColour());
2917 // Should have some kind of font at this point
2918 if (!GetFont().Ok())
2919 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
2920 if (!GetBackgroundColour().Ok())
2921 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
2923 // Only when we've created the window and set the font can we set the correct size,
2924 // if based on dialog units.
2925 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
2927 wxSize sz
= ConvertDialogToPixels(wxSize(width
, height
));
2928 SetClientSize(sz
.x
, sz
.y
);
2930 wxPoint pt
= ConvertDialogToPixels(wxPoint(x
, y
));
2934 // Now create children
2935 wxNode
*node
= resource
->GetChildren().First();
2938 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
2940 (void) CreateItem(childResource
, resource
, table
);
2942 node
= node
->Next();
2947 wxControl
*wxWindowBase::CreateItem(const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
2950 table
= wxDefaultResourceTable
;
2951 return table
->CreateItem((wxWindow
*)this, resource
, parentResource
);
2955 #pragma warning(default:4706) // assignment within conditional expression
2961 #endif // wxUSE_WX_RESOURCES