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 #if !USE_SHARED_LIBRARY
123 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
124 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
127 wxItemResource::wxItemResource()
133 m_x
= m_y
= m_width
= m_height
= 0;
134 m_value1
= m_value2
= m_value3
= m_value5
= 0;
140 wxItemResource::~wxItemResource()
142 wxNode
*node
= m_children
.First();
145 wxItemResource
*item
= (wxItemResource
*)node
->Data();
148 node
= m_children
.First();
156 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
160 wxResourceTable::~wxResourceTable()
165 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
167 wxItemResource
*item
= (wxItemResource
*)Get(WXSTRINGCAST name
);
171 void wxResourceTable::AddResource(wxItemResource
*item
)
173 wxString name
= item
->GetName();
175 name
= item
->GetTitle();
177 name
= wxT("no name");
179 // Delete existing resource, if any.
185 bool wxResourceTable::DeleteResource(const wxString
& name
)
187 wxItemResource
*item
= (wxItemResource
*)Delete(WXSTRINGCAST name
);
190 // See if any resource has this as its child; if so, delete from
191 // parent's child list.
193 wxNode
*node
= (wxNode
*) NULL
;
197 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
198 if (parent
->GetChildren().Member(item
))
200 parent
->GetChildren().DeleteObject(item
);
213 bool wxResourceTable::ParseResourceFile(const wxString
& filename
)
218 FILE *fd
= fopen(wxUnix2MacFilename(filename
.fn_str()), "r");
220 FILE *fd
= fopen(filename
.fn_str(), "r");
225 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
230 return wxResourceInterpretResources(*this, db
);
233 bool wxResourceTable::ParseResourceData(const wxString
& data
)
236 if (!db
.ReadFromString(data
))
238 wxLogWarning(_("Ill-formed resource file syntax."));
242 return wxResourceInterpretResources(*this, db
);
245 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char bits
[], int width
, int height
)
247 // Register pre-loaded bitmap data
248 wxItemResource
*item
= new wxItemResource
;
249 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
250 item
->SetType(wxT("wxXBMData"));
252 item
->SetValue1((long)bits
);
253 item
->SetValue2((long)width
);
254 item
->SetValue3((long)height
);
259 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char **data
)
261 // Register pre-loaded bitmap data
262 wxItemResource
*item
= new wxItemResource
;
263 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
264 item
->SetType(wxT("wxXPMData"));
266 item
->SetValue1((long)data
);
271 bool wxResourceTable::SaveResource(const wxString
& WXUNUSED(filename
))
276 void wxResourceTable::ClearTable()
279 wxNode
*node
= Next();
282 wxNode
*next
= Next();
283 wxItemResource
*item
= (wxItemResource
*)node
->Data();
290 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, const wxItemResource
* childResource
, const wxItemResource
* parentResource
) const
292 int id
= childResource
->GetId();
296 bool dlgUnits
= ((parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0);
298 wxControl
*control
= (wxControl
*) NULL
;
299 wxString
itemType(childResource
->GetType());
305 pos
= parent
->ConvertDialogToPixels(wxPoint(childResource
->GetX(), childResource
->GetY()));
306 size
= parent
->ConvertDialogToPixels(wxSize(childResource
->GetWidth(), childResource
->GetHeight()));
310 pos
= wxPoint(childResource
->GetX(), childResource
->GetY());
311 size
= wxSize(childResource
->GetWidth(), childResource
->GetHeight());
314 if (itemType
== wxString(wxT("wxButton")) || itemType
== wxString(wxT("wxBitmapButton")))
316 if (childResource
->GetValue4() != wxT(""))
319 wxBitmap bitmap
= childResource
->GetBitmap();
322 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
323 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
326 control
= new wxBitmapButton(parent
, id
, bitmap
, pos
, size
,
327 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
330 // Normal, text button
331 control
= new wxButton(parent
, id
, childResource
->GetTitle(), pos
, size
,
332 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
334 else if (itemType
== wxString(wxT("wxMessage")) || itemType
== wxString(wxT("wxStaticText")) ||
335 itemType
== wxString(wxT("wxStaticBitmap")))
337 if (childResource
->GetValue4() != wxT(""))
340 wxBitmap bitmap
= childResource
->GetBitmap();
343 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
344 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
346 #if wxUSE_BITMAP_MESSAGE
348 control
= new wxStaticBitmap(parent
, id
, bitmap
, pos
, size
,
349 childResource
->GetStyle(), childResource
->GetName());
354 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(), pos
, size
,
355 childResource
->GetStyle(), childResource
->GetName());
358 else if (itemType
== wxString(wxT("wxText")) || itemType
== wxString(wxT("wxTextCtrl")) || itemType
== wxString(wxT("wxMultiText")))
360 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), pos
, size
,
361 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
363 else if (itemType
== wxString(wxT("wxCheckBox")))
365 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
366 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
368 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
371 else if (itemType
== wxString(wxT("wxGauge")))
373 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(), pos
, size
,
374 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
376 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
380 else if (itemType
== wxString(wxT("wxRadioButton")))
382 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
384 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
388 else if (itemType
== wxString(wxT("wxScrollBar")))
390 control
= new wxScrollBar(parent
, id
, pos
, size
,
391 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
393 ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1());
394 ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2());
395 ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3());
396 ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5());
398 ((wxScrollBar
*)control
)->SetScrollbar((int)childResource
->GetValue1(),(int)childResource
->GetValue2(),
399 (int)childResource
->GetValue3(),(int)(long)childResource
->GetValue5(),FALSE
);
403 else if (itemType
== wxString(wxT("wxSlider")))
405 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
406 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), pos
, size
,
407 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
409 else if (itemType
== wxString(wxT("wxGroupBox")) || itemType
== wxString(wxT("wxStaticBox")))
411 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
412 childResource
->GetStyle(), childResource
->GetName());
414 else if (itemType
== wxString(wxT("wxListBox")))
416 wxStringList
& stringList
= childResource
->GetStringValues();
417 wxString
*strings
= (wxString
*) NULL
;
419 if (stringList
.Number() > 0)
421 noStrings
= stringList
.Number();
422 strings
= new wxString
[noStrings
];
423 wxNode
*node
= stringList
.First();
427 strings
[i
] = (wxChar
*)node
->Data();
432 control
= new wxListBox(parent
, id
, pos
, size
,
433 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
438 else if (itemType
== wxString(wxT("wxChoice")))
440 wxStringList
& stringList
= childResource
->GetStringValues();
441 wxString
*strings
= (wxString
*) NULL
;
443 if (stringList
.Number() > 0)
445 noStrings
= stringList
.Number();
446 strings
= new wxString
[noStrings
];
447 wxNode
*node
= stringList
.First();
451 strings
[i
] = (wxChar
*)node
->Data();
456 control
= new wxChoice(parent
, id
, pos
, size
,
457 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
463 else if (itemType
== wxString(wxT("wxComboBox")))
465 wxStringList
& stringList
= childResource
->GetStringValues();
466 wxString
*strings
= (wxString
*) NULL
;
468 if (stringList
.Number() > 0)
470 noStrings
= stringList
.Number();
471 strings
= new wxString
[noStrings
];
472 wxNode
*node
= stringList
.First();
476 strings
[i
] = (wxChar
*)node
->Data();
481 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(), pos
, size
,
482 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
488 else if (itemType
== wxString(wxT("wxRadioBox")))
490 wxStringList
& stringList
= childResource
->GetStringValues();
491 wxString
*strings
= (wxString
*) NULL
;
493 if (stringList
.Number() > 0)
495 noStrings
= stringList
.Number();
496 strings
= new wxString
[noStrings
];
497 wxNode
*node
= stringList
.First();
501 strings
[i
] = (wxChar
*)node
->Data();
506 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), pos
, size
,
507 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
508 childResource
->GetName());
514 if ((parentResource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
516 // Don't set font; will be inherited from parent.
520 if (control
&& childResource
->GetFont().Ok())
521 control
->SetFont(childResource
->GetFont());
527 * Interpret database as a series of resources
530 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
)
532 wxNode
*node
= db
.First();
535 wxExpr
*clause
= (wxExpr
*)node
->Data();
536 wxString
functor(clause
->Functor());
538 wxItemResource
*item
= (wxItemResource
*) NULL
;
539 if (functor
== wxT("dialog"))
540 item
= wxResourceInterpretDialog(table
, clause
);
541 else if (functor
== wxT("panel"))
542 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
543 else if (functor
== wxT("menubar"))
544 item
= wxResourceInterpretMenuBar(table
, clause
);
545 else if (functor
== wxT("menu"))
546 item
= wxResourceInterpretMenu(table
, clause
);
547 else if (functor
== wxT("string"))
548 item
= wxResourceInterpretString(table
, clause
);
549 else if (functor
== wxT("bitmap"))
550 item
= wxResourceInterpretBitmap(table
, clause
);
551 else if (functor
== wxT("icon"))
552 item
= wxResourceInterpretIcon(table
, clause
);
556 // Remove any existing resource of same name
557 if (item
->GetName() != wxT(""))
558 table
.DeleteResource(item
->GetName());
559 table
.AddResource(item
);
566 static const wxChar
*g_ValidControlClasses
[] =
569 wxT("wxBitmapButton"),
572 wxT("wxStaticBitmap"),
578 wxT("wxRadioButton"),
580 wxT("wxBitmapCheckBox"),
590 static bool wxIsValidControlClass(const wxString
& c
)
592 for ( size_t i
= 0; i
< WXSIZEOF(g_ValidControlClasses
); i
++ )
594 if ( c
== g_ValidControlClasses
[i
] )
600 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
602 wxItemResource
*dialogItem
= new wxItemResource
;
604 dialogItem
->SetType(wxT("wxPanel"));
606 dialogItem
->SetType(wxT("wxDialog"));
607 wxString style
= wxT("");
608 wxString title
= wxT("");
609 wxString name
= wxT("");
610 wxString backColourHex
= wxT("");
611 wxString labelColourHex
= wxT("");
612 wxString buttonColourHex
= wxT("");
614 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
618 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
620 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
621 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
622 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
623 expr
->GetAttributeValue(wxT("style"), style
);
624 expr
->GetAttributeValue(wxT("name"), name
);
625 expr
->GetAttributeValue(wxT("title"), title
);
626 expr
->GetAttributeValue(wxT("x"), x
);
627 expr
->GetAttributeValue(wxT("y"), y
);
628 expr
->GetAttributeValue(wxT("width"), width
);
629 expr
->GetAttributeValue(wxT("height"), height
);
630 expr
->GetAttributeValue(wxT("modal"), isModal
);
631 expr
->GetAttributeValue(wxT("label_font"), &labelFontExpr
);
632 expr
->GetAttributeValue(wxT("button_font"), &buttonFontExpr
);
633 expr
->GetAttributeValue(wxT("font"), &fontExpr
);
634 expr
->GetAttributeValue(wxT("background_colour"), backColourHex
);
635 expr
->GetAttributeValue(wxT("label_colour"), labelColourHex
);
636 expr
->GetAttributeValue(wxT("button_colour"), buttonColourHex
);
638 int useDialogUnits
= 0;
639 expr
->GetAttributeValue(wxT("use_dialog_units"), useDialogUnits
);
640 if (useDialogUnits
!= 0)
641 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
644 expr
->GetAttributeValue(wxT("use_system_defaults"), useDefaults
);
645 if (useDefaults
!= 0)
646 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
649 expr
->GetAttributeValue(wxT("id"), id
);
650 dialogItem
->SetId(id
);
652 if (style
!= wxT(""))
654 windowStyle
= wxParseWindowStyle(style
);
656 dialogItem
->SetStyle(windowStyle
);
657 dialogItem
->SetValue1(isModal
);
658 if (windowStyle
& wxDIALOG_MODAL
) // Uses style in wxWin 2
659 dialogItem
->SetValue1(TRUE
);
661 dialogItem
->SetName(name
);
662 dialogItem
->SetTitle(title
);
663 dialogItem
->SetSize(x
, y
, width
, height
);
665 if (backColourHex
!= wxT(""))
670 r
= wxHexToDec(backColourHex
.Mid(0, 2));
671 g
= wxHexToDec(backColourHex
.Mid(2, 2));
672 b
= wxHexToDec(backColourHex
.Mid(4, 2));
673 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
675 if (labelColourHex
!= wxT(""))
680 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
681 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
682 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
683 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
685 if (buttonColourHex
!= wxT(""))
690 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
691 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
692 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
693 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
697 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
698 else if (buttonFontExpr
)
699 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
700 else if (labelFontExpr
)
701 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
703 // Now parse all controls
704 wxExpr
*controlExpr
= expr
->GetFirst();
707 if (controlExpr
->Number() == 3)
709 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
710 if (controlKeyword
!= wxT("") && controlKeyword
== wxT("control"))
712 // The value part: always a list.
713 wxExpr
*listExpr
= controlExpr
->Nth(2);
714 if (listExpr
->Type() == PrologList
)
716 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
719 dialogItem
->GetChildren().Append(controlItem
);
724 controlExpr
= controlExpr
->GetNext();
729 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
731 wxItemResource
*controlItem
= new wxItemResource
;
733 // First, find the standard features of a control definition:
734 // [optional integer/string id], control name, title, style, name, x, y, width, height
736 wxString controlType
;
741 long windowStyle
= 0;
742 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
745 wxExpr
*expr1
= expr
->Nth(0);
747 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
749 if ( wxIsValidControlClass(expr1
->StringValue()) )
752 controlType
= expr1
->StringValue();
756 wxString
str(expr1
->StringValue());
757 id
= wxResourceGetIdentifier(str
, &table
);
760 wxLogWarning(_("Could not resolve control class or id '%s'. "
761 "Use (non-zero) integer instead\n or provide #define "
762 "(see manual for caveats)"),
763 (const wxChar
*) expr1
->StringValue());
765 return (wxItemResource
*) NULL
;
769 // Success - we have an id, so the 2nd element must be the control class.
770 controlType
= expr
->Nth(1)->StringValue();
775 else if (expr1
->Type() == PrologInteger
)
777 id
= (int)expr1
->IntegerValue();
778 // Success - we have an id, so the 2nd element must be the control class.
779 controlType
= expr
->Nth(1)->StringValue();
783 expr1
= expr
->Nth(count
);
786 title
= expr1
->StringValue();
788 expr1
= expr
->Nth(count
);
792 style
= expr1
->StringValue();
793 windowStyle
= wxParseWindowStyle(style
);
796 expr1
= expr
->Nth(count
);
799 name
= expr1
->StringValue();
801 expr1
= expr
->Nth(count
);
804 x
= (int)expr1
->IntegerValue();
806 expr1
= expr
->Nth(count
);
809 y
= (int)expr1
->IntegerValue();
811 expr1
= expr
->Nth(count
);
814 width
= (int)expr1
->IntegerValue();
816 expr1
= expr
->Nth(count
);
819 height
= (int)expr1
->IntegerValue();
821 controlItem
->SetStyle(windowStyle
);
822 controlItem
->SetName(name
);
823 controlItem
->SetTitle(title
);
824 controlItem
->SetSize(x
, y
, width
, height
);
825 controlItem
->SetType(controlType
);
826 controlItem
->SetId(id
);
828 if (controlType
== wxT("wxButton"))
830 // Check for bitmap resource name (in case loading old-style resource file)
831 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
833 wxString
str(expr
->Nth(count
)->StringValue());
838 controlItem
->SetValue4(str
);
839 controlItem
->SetType(wxT("wxBitmapButton"));
842 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
843 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
845 else if (controlType
== wxT("wxBitmapButton"))
847 // Check for bitmap resource name
848 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
850 wxString
str(expr
->Nth(count
)->StringValue());
851 controlItem
->SetValue4(str
);
853 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
854 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
857 else if (controlType
== wxT("wxCheckBox"))
859 // Check for default value
860 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
862 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
864 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
865 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
869 else if (controlType
== wxT("wxRadioButton"))
871 // Check for default value
872 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
874 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
876 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
877 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
881 else if (controlType
== wxT("wxText") || controlType
== wxT("wxTextCtrl") || controlType
== wxT("wxMultiText"))
883 // Check for default value
884 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
886 wxString
str(expr
->Nth(count
)->StringValue());
887 controlItem
->SetValue4(str
);
890 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
892 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
893 // Do nothing - no label font any more
895 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
896 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
900 else if (controlType
== wxT("wxMessage") || controlType
== wxT("wxStaticText"))
902 // Check for bitmap resource name (in case it's an old-style .wxr file)
903 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
905 wxString
str(expr
->Nth(count
)->StringValue());
906 controlItem
->SetValue4(str
);
908 controlItem
->SetType(wxT("wxStaticText"));
910 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
911 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
913 else if (controlType
== wxT("wxStaticBitmap"))
915 // Check for bitmap resource name
916 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
918 wxString
str(expr
->Nth(count
)->StringValue());
919 controlItem
->SetValue4(str
);
922 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
923 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
925 else if (controlType
== wxT("wxGroupBox") || controlType
== wxT("wxStaticBox"))
927 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
928 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
930 else if (controlType
== wxT("wxGauge"))
932 // Check for default value
933 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
935 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
939 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
941 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
944 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
946 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
950 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
951 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
956 else if (controlType
== wxT("wxSlider"))
958 // Check for default value
959 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
961 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
965 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
967 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
971 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
973 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
976 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
978 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
982 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
983 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
989 else if (controlType
== wxT("wxScrollBar"))
992 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
994 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
998 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1000 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1004 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1006 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1010 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1011 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1016 else if (controlType
== wxT("wxListBox"))
1018 wxExpr
*valueList
= (wxExpr
*) NULL
;
1020 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1022 wxStringList stringList
;
1023 wxExpr
*stringExpr
= valueList
->GetFirst();
1026 stringList
.Add(stringExpr
->StringValue());
1027 stringExpr
= stringExpr
->GetNext();
1029 controlItem
->SetStringValues(stringList
);
1031 // This is now obsolete: it's in the window style.
1032 // Check for wxSINGLE/wxMULTIPLE
1033 wxExpr
*mult
= (wxExpr
*) NULL
;
1035 controlItem->SetValue1(wxLB_SINGLE);
1037 if ((mult
= expr
->Nth(count
)) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1040 wxString m(mult->StringValue());
1041 if (m == "wxLB_MULTIPLE")
1042 controlItem->SetValue1(wxLB_MULTIPLE);
1043 else if (m == "wxLB_EXTENDED")
1044 controlItem->SetValue1(wxLB_EXTENDED);
1049 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1051 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1053 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1054 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1058 else if (controlType
== wxT("wxChoice"))
1060 wxExpr
*valueList
= (wxExpr
*) NULL
;
1061 // Check for default value list
1062 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1064 wxStringList stringList
;
1065 wxExpr
*stringExpr
= valueList
->GetFirst();
1068 stringList
.Add(stringExpr
->StringValue());
1069 stringExpr
= stringExpr
->GetNext();
1071 controlItem
->SetStringValues(stringList
);
1075 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1077 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1080 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1081 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1086 else if (controlType
== wxT("wxComboBox"))
1088 wxExpr
*textValue
= expr
->Nth(count
);
1089 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1091 wxString
str(textValue
->StringValue());
1092 controlItem
->SetValue4(str
);
1096 wxExpr
*valueList
= (wxExpr
*) NULL
;
1097 // Check for default value list
1098 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1100 wxStringList stringList
;
1101 wxExpr
*stringExpr
= valueList
->GetFirst();
1104 stringList
.Add(stringExpr
->StringValue());
1105 stringExpr
= stringExpr
->GetNext();
1107 controlItem
->SetStringValues(stringList
);
1111 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1113 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1116 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1117 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1124 else if (controlType
== wxT("wxRadioBox"))
1126 wxExpr
*valueList
= (wxExpr
*) NULL
;
1127 // Check for default value list
1128 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1130 wxStringList stringList
;
1131 wxExpr
*stringExpr
= valueList
->GetFirst();
1134 stringList
.Add(stringExpr
->StringValue());
1135 stringExpr
= stringExpr
->GetNext();
1137 controlItem
->SetStringValues(stringList
);
1140 // majorDim (number of rows or cols)
1141 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1143 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1147 controlItem
->SetValue1(0);
1149 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1151 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1154 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1155 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1163 return (wxItemResource
*) NULL
;
1168 // Forward declaration
1169 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1172 * Interpet a menu item
1175 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1177 wxItemResource
*item
= new wxItemResource
;
1179 wxExpr
*labelExpr
= expr
->Nth(0);
1180 wxExpr
*idExpr
= expr
->Nth(1);
1181 wxExpr
*helpExpr
= expr
->Nth(2);
1182 wxExpr
*checkableExpr
= expr
->Nth(3);
1184 // Further keywords/attributes to follow sometime...
1185 if (expr
->Number() == 0)
1187 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1188 item
->SetType(wxT("wxMenuSeparator"));
1193 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1194 item
->SetType(wxT("wxMenu")); // Well, menu item, but doesn't matter.
1197 wxString
str(labelExpr
->StringValue());
1198 item
->SetTitle(str
);
1203 // If a string or word, must look up in identifier table.
1204 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1206 wxString
str(idExpr
->StringValue());
1207 id
= wxResourceGetIdentifier(str
, &table
);
1210 wxLogWarning(_("Could not resolve menu id '%s'. "
1211 "Use (non-zero) integer instead\n"
1212 "or provide #define (see manual for caveats)"),
1213 (const wxChar
*) idExpr
->StringValue());
1216 else if (idExpr
->Type() == PrologInteger
)
1217 id
= (int)idExpr
->IntegerValue();
1218 item
->SetValue1(id
);
1222 wxString
str(helpExpr
->StringValue());
1223 item
->SetValue4(str
);
1226 item
->SetValue2(checkableExpr
->IntegerValue());
1228 // Find the first expression that's a list, for submenu
1229 wxExpr
*subMenuExpr
= expr
->GetFirst();
1230 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1231 subMenuExpr
= subMenuExpr
->GetNext();
1235 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1236 item
->GetChildren().Append(child
);
1237 subMenuExpr
= subMenuExpr
->GetNext();
1244 * Interpret a nested list as a menu
1247 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1249 wxItemResource *menu = new wxItemResource;
1250 // menu->SetType(wxTYPE_MENU);
1251 menu->SetType("wxMenu");
1252 wxExpr *element = expr->GetFirst();
1255 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1257 menu->GetChildren().Append(item);
1258 element = element->GetNext();
1264 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1266 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1267 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1269 return (wxItemResource
*) NULL
;
1271 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1274 return (wxItemResource
*) NULL
;
1277 if (expr
->GetAttributeValue(wxT("name"), name
))
1279 menuResource
->SetName(name
);
1282 return menuResource
;
1285 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1287 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1288 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1290 return (wxItemResource
*) NULL
;
1292 wxItemResource
*resource
= new wxItemResource
;
1293 resource
->SetType(wxT("wxMenu"));
1294 // resource->SetType(wxTYPE_MENU);
1296 wxExpr
*element
= listExpr
->GetFirst();
1299 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1300 resource
->GetChildren().Append(menuResource
);
1301 element
= element
->GetNext();
1305 if (expr
->GetAttributeValue(wxT("name"), name
))
1307 resource
->SetName(name
);
1313 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1315 return (wxItemResource
*) NULL
;
1318 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1320 wxItemResource
*bitmapItem
= new wxItemResource
;
1321 // bitmapItem->SetType(wxTYPE_BITMAP);
1322 bitmapItem
->SetType(wxT("wxBitmap"));
1324 if (expr
->GetAttributeValue(wxT("name"), name
))
1326 bitmapItem
->SetName(name
);
1328 // Now parse all bitmap specifications
1329 wxExpr
*bitmapExpr
= expr
->GetFirst();
1332 if (bitmapExpr
->Number() == 3)
1334 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1335 if (bitmapKeyword
== wxT("bitmap") || bitmapKeyword
== wxT("icon"))
1337 // The value part: always a list.
1338 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1339 if (listExpr
->Type() == PrologList
)
1341 wxItemResource
*bitmapSpec
= new wxItemResource
;
1342 // bitmapSpec->SetType(wxTYPE_BITMAP);
1343 bitmapSpec
->SetType(wxT("wxBitmap"));
1345 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1346 // where everything after 'filename' is optional.
1347 wxExpr
*nameExpr
= listExpr
->Nth(0);
1348 wxExpr
*typeExpr
= listExpr
->Nth(1);
1349 wxExpr
*platformExpr
= listExpr
->Nth(2);
1350 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1351 wxExpr
*xresExpr
= listExpr
->Nth(4);
1352 wxExpr
*yresExpr
= listExpr
->Nth(5);
1353 if (nameExpr
&& nameExpr
->StringValue() != wxT(""))
1355 bitmapSpec
->SetName(nameExpr
->StringValue());
1357 if (typeExpr
&& typeExpr
->StringValue() != wxT(""))
1359 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1362 bitmapSpec
->SetValue1(0);
1364 if (platformExpr
&& platformExpr
->StringValue() != wxT(""))
1366 wxString
plat(platformExpr
->StringValue());
1367 if (plat
== wxT("windows") || plat
== wxT("WINDOWS"))
1368 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1369 else if (plat
== wxT("x") || plat
== wxT("X"))
1370 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1371 else if (plat
== wxT("mac") || plat
== wxT("MAC"))
1372 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1374 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1377 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1380 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1384 xres
= (int)xresExpr
->IntegerValue();
1386 yres
= (int)yresExpr
->IntegerValue();
1387 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1389 bitmapItem
->GetChildren().Append(bitmapSpec
);
1393 bitmapExpr
= bitmapExpr
->GetNext();
1399 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1401 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1404 // item->SetType(wxTYPE_ICON);
1405 item
->SetType(wxT("wxIcon"));
1409 return (wxItemResource
*) NULL
;
1412 // Interpret list expression as a font
1413 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1415 if (expr
->Type() != PrologList
)
1419 int family
= wxSWISS
;
1420 int style
= wxNORMAL
;
1421 int weight
= wxNORMAL
;
1423 wxString
faceName(wxT(""));
1425 wxExpr
*pointExpr
= expr
->Nth(0);
1426 wxExpr
*familyExpr
= expr
->Nth(1);
1427 wxExpr
*styleExpr
= expr
->Nth(2);
1428 wxExpr
*weightExpr
= expr
->Nth(3);
1429 wxExpr
*underlineExpr
= expr
->Nth(4);
1430 wxExpr
*faceNameExpr
= expr
->Nth(5);
1432 point
= (int)pointExpr
->IntegerValue();
1437 str
= familyExpr
->StringValue();
1438 family
= (int)wxParseWindowStyle(str
);
1442 str
= styleExpr
->StringValue();
1443 style
= (int)wxParseWindowStyle(str
);
1447 str
= weightExpr
->StringValue();
1448 weight
= (int)wxParseWindowStyle(str
);
1451 underline
= (int)underlineExpr
->IntegerValue();
1453 faceName
= faceNameExpr
->StringValue();
1455 wxFont
font(point
, family
, style
, weight
, (underline
!= 0), faceName
);
1459 // Separate file for the remainder of this, for BC++/Win16
1461 #if !((defined(__BORLANDC__) || defined(__SC__)) && defined(__WIN16__))
1463 * (Re)allocate buffer for reading in from resource file
1466 bool wxReallocateResourceBuffer()
1468 if (!wxResourceBuffer
)
1470 wxResourceBufferSize
= 1000;
1471 wxResourceBuffer
= new char[wxResourceBufferSize
];
1474 if (wxResourceBuffer
)
1476 long newSize
= wxResourceBufferSize
+ 1000;
1477 char *tmp
= new char[(int)newSize
];
1478 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1479 delete[] wxResourceBuffer
;
1480 wxResourceBuffer
= tmp
;
1481 wxResourceBufferSize
= newSize
;
1486 static bool wxEatWhiteSpace(FILE *fd
)
1490 while ((ch
= getc(fd
)) != EOF
)
1505 ungetc(prev_ch
, fd
);
1513 while ((ch
= getc(fd
)) != EOF
)
1515 if (ch
== '/' && prev_ch
== '*')
1523 static char buffer
[255];
1524 fgets(buffer
, 255, fd
);
1528 ungetc(prev_ch
, fd
);
1543 bool wxGetResourceToken(FILE *fd
)
1545 if (!wxResourceBuffer
)
1546 wxReallocateResourceBuffer();
1547 wxResourceBuffer
[0] = 0;
1548 wxEatWhiteSpace(fd
);
1554 wxResourceBufferCount
= 0;
1561 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1564 // Escaped characters
1565 else if (ch
== '\\')
1567 int newCh
= getc(fd
);
1570 else if (newCh
== 10)
1578 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1579 wxReallocateResourceBuffer();
1580 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1581 wxResourceBufferCount
++;
1584 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1588 wxResourceBufferCount
= 0;
1590 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1592 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1593 wxReallocateResourceBuffer();
1594 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1595 wxResourceBufferCount
++;
1599 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1607 * Files are in form:
1608 static char *name = "....";
1609 with possible comments.
1612 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1615 table
= wxDefaultResourceTable
;
1617 // static or #define
1618 if (!wxGetResourceToken(fd
))
1624 if (strcmp(wxResourceBuffer
, "#define") == 0)
1626 wxGetResourceToken(fd
);
1627 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1628 wxGetResourceToken(fd
);
1629 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1630 if (wxIsdigit(value
[0]))
1632 int val
= (int)wxAtol(value
);
1633 wxResourceAddIdentifier(name
, val
, table
);
1637 wxLogWarning(_("#define %s must be an integer."), name
);
1647 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1649 wxGetResourceToken(fd
);
1650 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1651 wxChar
*actualName
= name
;
1652 if (name
[0] == wxT('"'))
1653 actualName
= name
+ 1;
1654 int len
= wxStrlen(name
);
1655 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1657 if (!wxResourceParseIncludeFile(actualName
, table
))
1659 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1664 else if (strcmp(wxResourceBuffer
, "static") != 0)
1667 wxStrcpy(buf
, _("Found "));
1668 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
1669 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1675 if (!wxGetResourceToken(fd
))
1677 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1682 if (strcmp(wxResourceBuffer
, "char") != 0)
1684 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1689 if (!wxGetResourceToken(fd
))
1691 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1696 if (wxResourceBuffer
[0] != '*')
1698 wxLogWarning(_("Expected '*' whilst parsing resource."));
1701 wxChar nameBuf
[100];
1702 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
1706 if (!wxGetResourceToken(fd
))
1708 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1713 if (strcmp(wxResourceBuffer
, "=") != 0)
1715 wxLogWarning(_("Expected '=' whilst parsing resource."));
1720 if (!wxGetResourceToken(fd
))
1722 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1728 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1730 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1735 if (!wxGetResourceToken(fd
))
1743 * Parses string window style into integer window style
1747 * Style flag parsing, e.g.
1748 * "wxSYSTEM_MENU | wxBORDER" -> integer
1751 wxChar
* wxResourceParseWord(wxChar
*s
, int *i
)
1754 return (wxChar
*) NULL
;
1756 static wxChar buf
[150];
1757 int len
= wxStrlen(s
);
1760 while ((ii
< len
) && (wxIsalpha(s
[ii
]) || (s
[ii
] == wxT('_'))))
1768 // Eat whitespace and conjunction characters
1769 while ((ii
< len
) &&
1770 ((s
[ii
] == wxT(' ')) || (s
[ii
] == wxT('|')) || (s
[ii
] == wxT(','))))
1776 return (wxChar
*) NULL
;
1781 struct wxResourceBitListStruct
1787 static wxResourceBitListStruct wxResourceBitListTable
[] =
1790 { wxT("wxSINGLE"), wxLB_SINGLE
},
1791 { wxT("wxMULTIPLE"), wxLB_MULTIPLE
},
1792 { wxT("wxEXTENDED"), wxLB_EXTENDED
},
1793 { wxT("wxLB_SINGLE"), wxLB_SINGLE
},
1794 { wxT("wxLB_MULTIPLE"), wxLB_MULTIPLE
},
1795 { wxT("wxLB_EXTENDED"), wxLB_EXTENDED
},
1796 { wxT("wxLB_NEEDED_SB"), wxLB_NEEDED_SB
},
1797 { wxT("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB
},
1798 { wxT("wxLB_SORT"), wxLB_SORT
},
1799 { wxT("wxLB_OWNERDRAW"), wxLB_OWNERDRAW
},
1800 { wxT("wxLB_HSCROLL"), wxLB_HSCROLL
},
1803 { wxT("wxCB_SIMPLE"), wxCB_SIMPLE
},
1804 { wxT("wxCB_DROPDOWN"), wxCB_DROPDOWN
},
1805 { wxT("wxCB_READONLY"), wxCB_READONLY
},
1806 { wxT("wxCB_SORT"), wxCB_SORT
},
1809 { wxT("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR
},
1810 { wxT("wxGA_HORIZONTAL"), wxGA_HORIZONTAL
},
1811 { wxT("wxGA_VERTICAL"), wxGA_VERTICAL
},
1814 { wxT("wxPASSWORD"), wxPASSWORD
},
1815 { wxT("wxPROCESS_ENTER"), wxPROCESS_ENTER
},
1816 { wxT("wxTE_PASSWORD"), wxTE_PASSWORD
},
1817 { wxT("wxTE_READONLY"), wxTE_READONLY
},
1818 { wxT("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER
},
1819 { wxT("wxTE_MULTILINE"), wxTE_MULTILINE
},
1820 { wxT("wxTE_NO_VSCROLL"), wxTE_NO_VSCROLL
},
1822 /* wxRadioBox/wxRadioButton */
1823 { wxT("wxRB_GROUP"), wxRB_GROUP
},
1824 { wxT("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS
},
1825 { wxT("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS
},
1826 { wxT("wxRA_HORIZONTAL"), wxRA_HORIZONTAL
},
1827 { wxT("wxRA_VERTICAL"), wxRA_VERTICAL
},
1830 { wxT("wxSL_HORIZONTAL"), wxSL_HORIZONTAL
},
1831 { wxT("wxSL_VERTICAL"), wxSL_VERTICAL
},
1832 { wxT("wxSL_AUTOTICKS"), wxSL_AUTOTICKS
},
1833 { wxT("wxSL_LABELS"), wxSL_LABELS
},
1834 { wxT("wxSL_LEFT"), wxSL_LEFT
},
1835 { wxT("wxSL_TOP"), wxSL_TOP
},
1836 { wxT("wxSL_RIGHT"), wxSL_RIGHT
},
1837 { wxT("wxSL_BOTTOM"), wxSL_BOTTOM
},
1838 { wxT("wxSL_BOTH"), wxSL_BOTH
},
1839 { wxT("wxSL_SELRANGE"), wxSL_SELRANGE
},
1842 { wxT("wxSB_HORIZONTAL"), wxSB_HORIZONTAL
},
1843 { wxT("wxSB_VERTICAL"), wxSB_VERTICAL
},
1846 { wxT("wxBU_AUTODRAW"), wxBU_AUTODRAW
},
1847 { wxT("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW
},
1850 { wxT("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS
},
1851 { wxT("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS
},
1852 { wxT("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT
},
1855 { wxT("wxLC_ICON"), wxLC_ICON
},
1856 { wxT("wxLC_SMALL_ICON"), wxLC_SMALL_ICON
},
1857 { wxT("wxLC_LIST"), wxLC_LIST
},
1858 { wxT("wxLC_REPORT"), wxLC_REPORT
},
1859 { wxT("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP
},
1860 { wxT("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT
},
1861 { wxT("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE
},
1862 { wxT("wxLC_USER_TEXT"), wxLC_USER_TEXT
},
1863 { wxT("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS
},
1864 { wxT("wxLC_NO_HEADER"), wxLC_NO_HEADER
},
1865 { wxT("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER
},
1866 { wxT("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL
},
1867 { wxT("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING
},
1868 { wxT("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING
},
1871 { wxT("wxSP_VERTICAL"), wxSP_VERTICAL
},
1872 { wxT("wxSP_HORIZONTAL"), wxSP_HORIZONTAL
},
1873 { wxT("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS
},
1874 { wxT("wxSP_WRAP"), wxSP_WRAP
},
1877 { wxT("wxSP_NOBORDER"), wxSP_NOBORDER
},
1878 { wxT("wxSP_3D"), wxSP_3D
},
1879 { wxT("wxSP_BORDER"), wxSP_BORDER
},
1882 { wxT("wxTC_MULTILINE"), wxTC_MULTILINE
},
1883 { wxT("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY
},
1884 { wxT("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH
},
1885 { wxT("wxTC_OWNERDRAW"), wxTC_OWNERDRAW
},
1888 { wxT("wxST_SIZEGRIP"), wxST_SIZEGRIP
},
1891 { wxT("wxFIXED_LENGTH"), wxFIXED_LENGTH
},
1892 { wxT("wxALIGN_LEFT"), wxALIGN_LEFT
},
1893 { wxT("wxALIGN_CENTER"), wxALIGN_CENTER
},
1894 { wxT("wxALIGN_CENTRE"), wxALIGN_CENTRE
},
1895 { wxT("wxALIGN_RIGHT"), wxALIGN_RIGHT
},
1896 { wxT("wxCOLOURED"), wxCOLOURED
},
1899 { wxT("wxTB_3DBUTTONS"), wxTB_3DBUTTONS
},
1900 { wxT("wxTB_HORIZONTAL"), wxTB_HORIZONTAL
},
1901 { wxT("wxTB_VERTICAL"), wxTB_VERTICAL
},
1902 { wxT("wxTB_FLAT"), wxTB_FLAT
},
1905 { wxT("wxDIALOG_MODAL"), wxDIALOG_MODAL
},
1908 { wxT("wxVSCROLL"), wxVSCROLL
},
1909 { wxT("wxHSCROLL"), wxHSCROLL
},
1910 { wxT("wxCAPTION"), wxCAPTION
},
1911 { wxT("wxSTAY_ON_TOP"), wxSTAY_ON_TOP
},
1912 { wxT("wxICONIZE"), wxICONIZE
},
1913 { wxT("wxMINIMIZE"), wxICONIZE
},
1914 { wxT("wxMAXIMIZE"), wxMAXIMIZE
},
1916 { wxT("wxMDI_PARENT"), 0},
1917 { wxT("wxMDI_CHILD"), 0},
1918 { wxT("wxTHICK_FRAME"), wxTHICK_FRAME
},
1919 { wxT("wxRESIZE_BORDER"), wxRESIZE_BORDER
},
1920 { wxT("wxSYSTEM_MENU"), wxSYSTEM_MENU
},
1921 { wxT("wxMINIMIZE_BOX"), wxMINIMIZE_BOX
},
1922 { wxT("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX
},
1923 { wxT("wxRESIZE_BOX"), wxRESIZE_BOX
},
1924 { wxT("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE
},
1925 { wxT("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE
},
1926 { wxT("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE
},
1927 { wxT("wxBORDER"), wxBORDER
},
1928 { wxT("wxRETAINED"), wxRETAINED
},
1929 { wxT("wxNATIVE_IMPL"), 0},
1930 { wxT("wxEXTENDED_IMPL"), 0},
1931 { wxT("wxBACKINGSTORE"), wxBACKINGSTORE
},
1932 // { wxT("wxFLAT"), wxFLAT},
1933 // { wxT("wxMOTIF_RESIZE"), wxMOTIF_RESIZE},
1934 { wxT("wxFIXED_LENGTH"), 0},
1935 { wxT("wxDOUBLE_BORDER"), wxDOUBLE_BORDER
},
1936 { wxT("wxSUNKEN_BORDER"), wxSUNKEN_BORDER
},
1937 { wxT("wxRAISED_BORDER"), wxRAISED_BORDER
},
1938 { wxT("wxSIMPLE_BORDER"), wxSIMPLE_BORDER
},
1939 { wxT("wxSTATIC_BORDER"), wxSTATIC_BORDER
},
1940 { wxT("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW
},
1941 { wxT("wxNO_BORDER"), wxNO_BORDER
},
1942 { wxT("wxCLIP_CHILDREN"), wxCLIP_CHILDREN
},
1943 { wxT("wxTAB_TRAVERSAL"), 0}, // Compatibility only
1945 { wxT("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ
},
1946 { wxT("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT
},
1948 // Text font families
1949 { wxT("wxDEFAULT"), wxDEFAULT
},
1950 { wxT("wxDECORATIVE"), wxDECORATIVE
},
1951 { wxT("wxROMAN"), wxROMAN
},
1952 { wxT("wxSCRIPT"), wxSCRIPT
},
1953 { wxT("wxSWISS"), wxSWISS
},
1954 { wxT("wxMODERN"), wxMODERN
},
1955 { wxT("wxTELETYPE"), wxTELETYPE
},
1956 { wxT("wxVARIABLE"), wxVARIABLE
},
1957 { wxT("wxFIXED"), wxFIXED
},
1958 { wxT("wxNORMAL"), wxNORMAL
},
1959 { wxT("wxLIGHT"), wxLIGHT
},
1960 { wxT("wxBOLD"), wxBOLD
},
1961 { wxT("wxITALIC"), wxITALIC
},
1962 { wxT("wxSLANT"), wxSLANT
},
1963 { wxT("wxSOLID"), wxSOLID
},
1964 { wxT("wxDOT"), wxDOT
},
1965 { wxT("wxLONG_DASH"), wxLONG_DASH
},
1966 { wxT("wxSHORT_DASH"), wxSHORT_DASH
},
1967 { wxT("wxDOT_DASH"), wxDOT_DASH
},
1968 { wxT("wxUSER_DASH"), wxUSER_DASH
},
1969 { wxT("wxTRANSPARENT"), wxTRANSPARENT
},
1970 { wxT("wxSTIPPLE"), wxSTIPPLE
},
1971 { wxT("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH
},
1972 { wxT("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH
},
1973 { wxT("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH
},
1974 { wxT("wxCROSS_HATCH"), wxCROSS_HATCH
},
1975 { wxT("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH
},
1976 { wxT("wxVERTICAL_HATCH"), wxVERTICAL_HATCH
},
1977 { wxT("wxJOIN_BEVEL"), wxJOIN_BEVEL
},
1978 { wxT("wxJOIN_MITER"), wxJOIN_MITER
},
1979 { wxT("wxJOIN_ROUND"), wxJOIN_ROUND
},
1980 { wxT("wxCAP_ROUND"), wxCAP_ROUND
},
1981 { wxT("wxCAP_PROJECTING"), wxCAP_PROJECTING
},
1982 { wxT("wxCAP_BUTT"), wxCAP_BUTT
},
1985 { wxT("wxCLEAR"), wxCLEAR
},
1986 { wxT("wxXOR"), wxXOR
},
1987 { wxT("wxINVERT"), wxINVERT
},
1988 { wxT("wxOR_REVERSE"), wxOR_REVERSE
},
1989 { wxT("wxAND_REVERSE"), wxAND_REVERSE
},
1990 { wxT("wxCOPY"), wxCOPY
},
1991 { wxT("wxAND"), wxAND
},
1992 { wxT("wxAND_INVERT"), wxAND_INVERT
},
1993 { wxT("wxNO_OP"), wxNO_OP
},
1994 { wxT("wxNOR"), wxNOR
},
1995 { wxT("wxEQUIV"), wxEQUIV
},
1996 { wxT("wxSRC_INVERT"), wxSRC_INVERT
},
1997 { wxT("wxOR_INVERT"), wxOR_INVERT
},
1998 { wxT("wxNAND"), wxNAND
},
1999 { wxT("wxOR"), wxOR
},
2000 { wxT("wxSET"), wxSET
},
2002 { wxT("wxFLOOD_SURFACE"), wxFLOOD_SURFACE
},
2003 { wxT("wxFLOOD_BORDER"), wxFLOOD_BORDER
},
2004 { wxT("wxODDEVEN_RULE"), wxODDEVEN_RULE
},
2005 { wxT("wxWINDING_RULE"), wxWINDING_RULE
},
2006 { wxT("wxHORIZONTAL"), wxHORIZONTAL
},
2007 { wxT("wxVERTICAL"), wxVERTICAL
},
2008 { wxT("wxBOTH"), wxBOTH
},
2009 { wxT("wxCENTER_FRAME"), wxCENTER_FRAME
},
2010 { wxT("wxOK"), wxOK
},
2011 { wxT("wxYES_NO"), wxYES_NO
},
2012 { wxT("wxCANCEL"), wxCANCEL
},
2013 { wxT("wxYES"), wxYES
},
2014 { wxT("wxNO"), wxNO
},
2015 { wxT("wxICON_EXCLAMATION"), wxICON_EXCLAMATION
},
2016 { wxT("wxICON_HAND"), wxICON_HAND
},
2017 { wxT("wxICON_QUESTION"), wxICON_QUESTION
},
2018 { wxT("wxICON_INFORMATION"), wxICON_INFORMATION
},
2019 { wxT("wxICON_STOP"), wxICON_STOP
},
2020 { wxT("wxICON_ASTERISK"), wxICON_ASTERISK
},
2021 { wxT("wxICON_MASK"), wxICON_MASK
},
2022 { wxT("wxCENTRE"), wxCENTRE
},
2023 { wxT("wxCENTER"), wxCENTRE
},
2024 { wxT("wxUSER_COLOURS"), wxUSER_COLOURS
},
2025 { wxT("wxVERTICAL_LABEL"), 0},
2026 { wxT("wxHORIZONTAL_LABEL"), 0},
2028 // Bitmap types (not strictly styles)
2029 { wxT("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM
},
2030 { wxT("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM
},
2031 { wxT("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP
},
2032 { wxT("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2033 { wxT("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2034 { wxT("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF
},
2035 { wxT("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF
},
2036 { wxT("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO
},
2037 { wxT("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE
},
2038 { wxT("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR
},
2039 { wxT("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE
},
2040 { wxT("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA
},
2041 { wxT("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA
},
2042 { wxT("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY
}
2045 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2047 long wxParseWindowStyle(const wxString
& bitListString
)
2052 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2053 while (word
!= NULL
)
2057 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2058 if (wxStrcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2060 bitList
|= wxResourceBitListTable
[j
].bits
;
2066 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
2069 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2075 * Load a bitmap from a wxWindows resource, choosing an optimum
2076 * depth and appropriate type.
2079 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2082 table
= wxDefaultResourceTable
;
2084 wxItemResource
*item
= table
->FindResource(resource
);
2087 if ((item
->GetType() == wxT("")) || (item
->GetType() != wxT("wxBitmap")))
2089 wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar
*) resource
);
2090 return wxNullBitmap
;
2092 int thisDepth
= wxDisplayDepth();
2093 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2095 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2097 // Try to find optimum bitmap for this platform/colour depth
2098 wxNode
*node
= item
->GetChildren().First();
2101 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2102 int platform
= (int)child
->GetValue2();
2103 int noColours
= (int)child
->GetValue3();
2105 char *name = child->GetName();
2106 int bitmapType = (int)child->GetValue1();
2107 int xRes = child->GetWidth();
2108 int yRes = child->GetHeight();
2113 case RESOURCE_PLATFORM_ANY
:
2115 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2116 optResource
= child
;
2119 // Maximise the number of colours.
2120 // If noColours is zero (unspecified), then assume this
2121 // is the right one.
2122 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2123 optResource
= child
;
2128 case RESOURCE_PLATFORM_WINDOWS
:
2130 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2131 optResource
= child
;
2134 // Maximise the number of colours
2135 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2136 optResource
= child
;
2142 case RESOURCE_PLATFORM_X
:
2144 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2145 optResource
= child
;
2148 // Maximise the number of colours
2149 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2150 optResource
= child
;
2156 case RESOURCE_PLATFORM_MAC
:
2158 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2159 optResource
= child
;
2162 // Maximise the number of colours
2163 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2164 optResource
= child
;
2172 node
= node
->Next();
2174 // If no matching resource, fail.
2176 return wxNullBitmap
;
2178 wxString name
= optResource
->GetName();
2179 int bitmapType
= (int)optResource
->GetValue1();
2182 case wxBITMAP_TYPE_XBM_DATA
:
2185 wxItemResource
*item
= table
->FindResource(name
);
2188 wxLogWarning(_("Failed to find XBM resource %s.\n"
2189 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2190 return wxNullBitmap
;
2192 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2194 wxLogWarning(_("No XBM facility available!"));
2198 case wxBITMAP_TYPE_XPM_DATA
:
2200 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2201 wxItemResource
*item
= table
->FindResource(name
);
2204 wxLogWarning(_("Failed to find XPM resource %s.\n"
2205 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2206 return wxNullBitmap
;
2208 return wxBitmap((char **)item
->GetValue1());
2210 wxLogWarning(_("No XPM facility available!"));
2216 return wxBitmap(name
, bitmapType
);
2220 return wxNullBitmap
;
2224 wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar
*) resource
);
2225 return wxNullBitmap
;
2230 * Load an icon from a wxWindows resource, choosing an optimum
2231 * depth and appropriate type.
2234 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2237 table
= wxDefaultResourceTable
;
2239 wxItemResource
*item
= table
->FindResource(resource
);
2242 if ((item
->GetType() == wxT("")) || wxStrcmp(item
->GetType(), wxT("wxIcon")) != 0)
2244 wxLogWarning(_("%s not an icon resource specification."), (const wxChar
*) resource
);
2247 int thisDepth
= wxDisplayDepth();
2248 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2250 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2252 // Try to find optimum icon for this platform/colour depth
2253 wxNode
*node
= item
->GetChildren().First();
2256 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2257 int platform
= (int)child
->GetValue2();
2258 int noColours
= (int)child
->GetValue3();
2260 char *name = child->GetName();
2261 int bitmapType = (int)child->GetValue1();
2262 int xRes = child->GetWidth();
2263 int yRes = child->GetHeight();
2268 case RESOURCE_PLATFORM_ANY
:
2270 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2271 optResource
= child
;
2274 // Maximise the number of colours.
2275 // If noColours is zero (unspecified), then assume this
2276 // is the right one.
2277 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2278 optResource
= child
;
2283 case RESOURCE_PLATFORM_WINDOWS
:
2285 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2286 optResource
= child
;
2289 // Maximise the number of colours
2290 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2291 optResource
= child
;
2297 case RESOURCE_PLATFORM_X
:
2299 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2300 optResource
= child
;
2303 // Maximise the number of colours
2304 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2305 optResource
= child
;
2311 case RESOURCE_PLATFORM_MAC
:
2313 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2314 optResource
= child
;
2317 // Maximise the number of colours
2318 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2319 optResource
= child
;
2327 node
= node
->Next();
2329 // If no matching resource, fail.
2333 wxString name
= optResource
->GetName();
2334 int bitmapType
= (int)optResource
->GetValue1();
2337 case wxBITMAP_TYPE_XBM_DATA
:
2340 wxItemResource
*item
= table
->FindResource(name
);
2343 wxLogWarning(_("Failed to find XBM resource %s.\n"
2344 "Forgot to use wxResourceLoadIconData?"), (const wxChar
*) name
);
2347 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2349 wxLogWarning(_("No XBM facility available!"));
2353 case wxBITMAP_TYPE_XPM_DATA
:
2355 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2357 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2358 wxItemResource *item = table->FindResource(name);
2362 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2366 return wxIcon((char **)item->GetValue1());
2368 wxLogWarning(_("No XPM facility available!"));
2371 wxLogWarning(_("No XPM icon facility available!"));
2377 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2379 return wxIcon(name
, bitmapType
);
2388 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2393 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2395 wxMenu
*menu
= new wxMenu
;
2396 wxNode
*node
= item
->GetChildren().First();
2399 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2400 if ((child
->GetType() != wxT("")) && (child
->GetType() == wxT("wxMenuSeparator")))
2401 menu
->AppendSeparator();
2402 else if (child
->GetChildren().Number() > 0)
2404 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2406 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2410 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2412 node
= node
->Next();
2417 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2420 table
= wxDefaultResourceTable
;
2422 wxItemResource
*menuResource
= table
->FindResource(resource
);
2423 if (menuResource
&& (menuResource
->GetType() != wxT("")) && (menuResource
->GetType() == wxT("wxMenu")))
2426 menuBar
= new wxMenuBar
;
2427 wxNode
*node
= menuResource
->GetChildren().First();
2430 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2431 wxMenu
*menu
= wxResourceCreateMenu(child
);
2433 menuBar
->Append(menu
, child
->GetTitle());
2434 node
= node
->Next();
2438 return (wxMenuBar
*) NULL
;
2441 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2444 table
= wxDefaultResourceTable
;
2446 wxItemResource
*menuResource
= table
->FindResource(resource
);
2447 if (menuResource
&& (menuResource
->GetType() != wxT("")) && (menuResource
->GetType() == wxT("wxMenu")))
2448 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2449 return wxResourceCreateMenu(menuResource
);
2450 return (wxMenu
*) NULL
;
2453 // Global equivalents (so don't have to refer to default table explicitly)
2454 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2457 table
= wxDefaultResourceTable
;
2459 return table
->ParseResourceData(resource
);
2462 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2465 table
= wxDefaultResourceTable
;
2467 return table
->ParseResourceFile(filename
);
2470 // Register XBM/XPM data
2471 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2474 table
= wxDefaultResourceTable
;
2476 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2479 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2482 table
= wxDefaultResourceTable
;
2484 return table
->RegisterResourceBitmapData(name
, data
);
2487 void wxResourceClear(wxResourceTable
*table
)
2490 table
= wxDefaultResourceTable
;
2492 table
->ClearTable();
2499 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2502 table
= wxDefaultResourceTable
;
2504 table
->identifiers
.Put(name
, (wxObject
*)(long)value
);
2508 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2511 table
= wxDefaultResourceTable
;
2513 return (int)(long)table
->identifiers
.Get(name
);
2517 * Parse #include file for #defines (only)
2520 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2523 table
= wxDefaultResourceTable
;
2525 FILE *fd
= fopen(f
.fn_str(), "r");
2530 while (wxGetResourceToken(fd
))
2532 if (strcmp(wxResourceBuffer
, "#define") == 0)
2534 wxGetResourceToken(fd
);
2535 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2536 wxGetResourceToken(fd
);
2537 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2538 if (wxIsdigit(value
[0]))
2540 int val
= (int)wxAtol(value
);
2541 wxResourceAddIdentifier(name
, val
, table
);
2552 * Reading strings as if they were .wxr files
2555 static int getc_string(char *s
)
2557 int ch
= s
[wxResourceStringPtr
];
2562 wxResourceStringPtr
++;
2567 static int ungetc_string()
2569 wxResourceStringPtr
--;
2573 bool wxEatWhiteSpaceString(char *s
)
2577 while ((ch
= getc_string(s
)) != EOF
)
2589 ch
= getc_string(s
);
2600 while ((ch
= getc_string(s
)) != EOF
)
2602 if (ch
== '/' && prev_ch
== '*')
2624 bool wxGetResourceTokenString(char *s
)
2626 if (!wxResourceBuffer
)
2627 wxReallocateResourceBuffer();
2628 wxResourceBuffer
[0] = 0;
2629 wxEatWhiteSpaceString(s
);
2631 int ch
= getc_string(s
);
2635 wxResourceBufferCount
= 0;
2636 ch
= getc_string(s
);
2642 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2645 // Escaped characters
2646 else if (ch
== '\\')
2648 int newCh
= getc_string(s
);
2651 else if (newCh
== 10)
2659 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2660 wxReallocateResourceBuffer();
2661 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2662 wxResourceBufferCount
++;
2663 ch
= getc_string(s
);
2665 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2669 wxResourceBufferCount
= 0;
2671 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2673 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2674 wxReallocateResourceBuffer();
2675 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2676 wxResourceBufferCount
++;
2678 ch
= getc_string(s
);
2680 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2688 * Files are in form:
2689 static char *name = "....";
2690 with possible comments.
2693 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2696 table
= wxDefaultResourceTable
;
2698 // static or #define
2699 if (!wxGetResourceTokenString(s
))
2705 if (strcmp(wxResourceBuffer
, "#define") == 0)
2707 wxGetResourceTokenString(s
);
2708 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2709 wxGetResourceTokenString(s
);
2710 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2711 if (wxIsdigit(value
[0]))
2713 int val
= (int)wxAtol(value
);
2714 wxResourceAddIdentifier(name
, val
, table
);
2718 wxLogWarning(_("#define %s must be an integer."), name
);
2729 else if (strcmp(wxResourceBuffer, "#include") == 0)
2731 wxGetResourceTokenString(s);
2732 char *name = copystring(wxResourceBuffer);
2733 char *actualName = name;
2735 actualName = name + 1;
2736 int len = strlen(name);
2737 if ((len > 0) && (name[len-1] == '"'))
2739 if (!wxResourceParseIncludeFile(actualName, table))
2742 sprintf(buf, _("Could not find resource include file %s."), actualName);
2749 else if (strcmp(wxResourceBuffer
, "static") != 0)
2752 wxStrcpy(buf
, _("Found "));
2753 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
2754 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
2760 if (!wxGetResourceTokenString(s
))
2762 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2767 if (strcmp(wxResourceBuffer
, "char") != 0)
2769 wxLogWarning(_("Expected 'char' whilst parsing resource."));
2774 if (!wxGetResourceTokenString(s
))
2776 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2781 if (wxResourceBuffer
[0] != '*')
2783 wxLogWarning(_("Expected '*' whilst parsing resource."));
2786 wxChar nameBuf
[100];
2787 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
2791 if (!wxGetResourceTokenString(s
))
2793 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2798 if (strcmp(wxResourceBuffer
, "=") != 0)
2800 wxLogWarning(_("Expected '=' whilst parsing resource."));
2805 if (!wxGetResourceTokenString(s
))
2807 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2813 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2815 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2820 if (!wxGetResourceTokenString(s
))
2827 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
2830 table
= wxDefaultResourceTable
;
2835 // Turn backslashes into spaces
2838 int len
= strlen(s
);
2840 for (i
= 0; i
< len
; i
++)
2841 if (s
[i
] == 92 && s
[i
+1] == 13)
2849 wxResourceStringPtr
= 0;
2852 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
2856 return wxResourceInterpretResources(*table
, db
);
2860 * resource loading facility
2863 bool wxWindowBase::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
2866 table
= wxDefaultResourceTable
;
2868 wxItemResource
*resource
= table
->FindResource((const wxChar
*)resourceName
);
2869 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
2870 if (!resource
|| (resource
->GetType() == wxT("")) ||
2871 ! ((resource
->GetType() == wxT("wxDialog")) || (resource
->GetType() == wxT("wxPanel"))))
2874 wxString
title(resource
->GetTitle());
2875 long theWindowStyle
= resource
->GetStyle();
2876 bool isModal
= (resource
->GetValue1() != 0);
2877 int x
= resource
->GetX();
2878 int y
= resource
->GetY();
2879 int width
= resource
->GetWidth();
2880 int height
= resource
->GetHeight();
2881 wxString name
= resource
->GetName();
2883 if (IsKindOf(CLASSINFO(wxDialog
)))
2885 wxDialog
*dialogBox
= (wxDialog
*)this;
2886 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
2887 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
2890 // Only reset the client size if we know we're not going to do it again below.
2891 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
2892 dialogBox
->SetClientSize(width
, height
);
2894 else if (IsKindOf(CLASSINFO(wxPanel
)))
2896 wxPanel
* panel
= (wxPanel
*)this;
2897 if (!panel
->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
| wxTAB_TRAVERSAL
, name
))
2902 if (!((wxWindow
*)this)->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2906 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
2908 // No need to do this since it's done in wxPanel or wxDialog constructor.
2909 // SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
2913 if (resource
->GetFont().Ok())
2914 SetFont(resource
->GetFont());
2915 if (resource
->GetBackgroundColour().Ok())
2916 SetBackgroundColour(resource
->GetBackgroundColour());
2919 // Should have some kind of font at this point
2920 if (!GetFont().Ok())
2921 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
2922 if (!GetBackgroundColour().Ok())
2923 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
2925 // Only when we've created the window and set the font can we set the correct size,
2926 // if based on dialog units.
2927 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
2929 wxSize sz
= ConvertDialogToPixels(wxSize(width
, height
));
2930 SetClientSize(sz
.x
, sz
.y
);
2932 wxPoint pt
= ConvertDialogToPixels(wxPoint(x
, y
));
2936 // Now create children
2937 wxNode
*node
= resource
->GetChildren().First();
2940 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
2942 (void) CreateItem(childResource
, resource
, table
);
2944 node
= node
->Next();
2949 wxControl
*wxWindowBase::CreateItem(const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
2952 table
= wxDefaultResourceTable
;
2953 return table
->CreateItem((wxWindow
*)this, resource
, parentResource
);
2957 #pragma warning(default:4706) // assignment within conditional expression
2963 #endif // wxUSE_WX_RESOURCES