Add more error checks to XRC handler for longs, doubles and fonts.
Verify that the values in the XRC really conform to the expected type. Closes #14766. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72709 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1633,11 +1633,20 @@ wxString wxXmlResourceHandler::GetText(const wxString& param, bool translate)
|
|||||||
|
|
||||||
long wxXmlResourceHandler::GetLong(const wxString& param, long defaultv)
|
long wxXmlResourceHandler::GetLong(const wxString& param, long defaultv)
|
||||||
{
|
{
|
||||||
long value;
|
long value = defaultv;
|
||||||
wxString str1 = GetParamValue(param);
|
wxString str1 = GetParamValue(param);
|
||||||
|
|
||||||
|
if (!str1.empty())
|
||||||
|
{
|
||||||
if (!str1.ToLong(&value))
|
if (!str1.ToLong(&value))
|
||||||
value = defaultv;
|
{
|
||||||
|
ReportParamError
|
||||||
|
(
|
||||||
|
param,
|
||||||
|
wxString::Format("invalid long specification \"%s\"", str1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@@ -1649,9 +1658,18 @@ float wxXmlResourceHandler::GetFloat(const wxString& param, float defaultv)
|
|||||||
// strings in XRC always use C locale so make sure to use the
|
// strings in XRC always use C locale so make sure to use the
|
||||||
// locale-independent wxString::ToCDouble() and not ToDouble() which uses
|
// locale-independent wxString::ToCDouble() and not ToDouble() which uses
|
||||||
// the current locale with a potentially different decimal point character
|
// the current locale with a potentially different decimal point character
|
||||||
double value;
|
double value = defaultv;
|
||||||
|
if (!str.empty())
|
||||||
|
{
|
||||||
if (!str.ToCDouble(&value))
|
if (!str.ToCDouble(&value))
|
||||||
value = defaultv;
|
{
|
||||||
|
ReportParamError
|
||||||
|
(
|
||||||
|
param,
|
||||||
|
wxString::Format("invalid float specification \"%s\"", str)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return wx_truncate_cast(float, value);
|
return wx_truncate_cast(float, value);
|
||||||
}
|
}
|
||||||
@@ -2240,6 +2258,14 @@ wxFont wxXmlResourceHandler::GetFont(const wxString& param, wxWindow* parent)
|
|||||||
istyle = wxITALIC;
|
istyle = wxITALIC;
|
||||||
else if (style == wxT("slant"))
|
else if (style == wxT("slant"))
|
||||||
istyle = wxSLANT;
|
istyle = wxSLANT;
|
||||||
|
else if (style != wxT("normal"))
|
||||||
|
{
|
||||||
|
ReportParamError
|
||||||
|
(
|
||||||
|
param,
|
||||||
|
wxString::Format("unknown font style \"%s\"", style)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// weight
|
// weight
|
||||||
@@ -2252,6 +2278,14 @@ wxFont wxXmlResourceHandler::GetFont(const wxString& param, wxWindow* parent)
|
|||||||
iweight = wxBOLD;
|
iweight = wxBOLD;
|
||||||
else if (weight == wxT("light"))
|
else if (weight == wxT("light"))
|
||||||
iweight = wxLIGHT;
|
iweight = wxLIGHT;
|
||||||
|
else if (weight != wxT("normal"))
|
||||||
|
{
|
||||||
|
ReportParamError
|
||||||
|
(
|
||||||
|
param,
|
||||||
|
wxString::Format("unknown font weight \"%s\"", weight)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// underline
|
// underline
|
||||||
@@ -2270,6 +2304,14 @@ wxFont wxXmlResourceHandler::GetFont(const wxString& param, wxWindow* parent)
|
|||||||
else if (family == wxT("swiss")) ifamily = wxSWISS;
|
else if (family == wxT("swiss")) ifamily = wxSWISS;
|
||||||
else if (family == wxT("modern")) ifamily = wxMODERN;
|
else if (family == wxT("modern")) ifamily = wxMODERN;
|
||||||
else if (family == wxT("teletype")) ifamily = wxTELETYPE;
|
else if (family == wxT("teletype")) ifamily = wxTELETYPE;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ReportParamError
|
||||||
|
(
|
||||||
|
param,
|
||||||
|
wxString::Format("unknown font family \"%s\"", family)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2318,6 +2360,14 @@ wxFont wxXmlResourceHandler::GetFont(const wxString& param, wxWindow* parent)
|
|||||||
if (HasParam(wxT("sysfont")))
|
if (HasParam(wxT("sysfont")))
|
||||||
{
|
{
|
||||||
font = GetSystemFont(GetParamValue(wxT("sysfont")));
|
font = GetSystemFont(GetParamValue(wxT("sysfont")));
|
||||||
|
if (HasParam(wxT("inherit")))
|
||||||
|
{
|
||||||
|
ReportParamError
|
||||||
|
(
|
||||||
|
param,
|
||||||
|
"double specification of \"sysfont\" and \"inherit\""
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// or should the font of the widget be used?
|
// or should the font of the widget be used?
|
||||||
else if (GetBool(wxT("inherit"), false))
|
else if (GetBool(wxT("inherit"), false))
|
||||||
@@ -2325,13 +2375,29 @@ wxFont wxXmlResourceHandler::GetFont(const wxString& param, wxWindow* parent)
|
|||||||
if (parent)
|
if (parent)
|
||||||
font = parent->GetFont();
|
font = parent->GetFont();
|
||||||
else
|
else
|
||||||
ReportError("no parent window specified to derive the font from");
|
{
|
||||||
|
ReportParamError
|
||||||
|
(
|
||||||
|
param,
|
||||||
|
"no parent window specified to derive the font from"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (font.IsOk())
|
if (font.IsOk())
|
||||||
{
|
{
|
||||||
if (hasSize && isize != -1)
|
if (hasSize && isize != -1)
|
||||||
|
{
|
||||||
font.SetPointSize(isize);
|
font.SetPointSize(isize);
|
||||||
|
if (HasParam(wxT("relativesize")))
|
||||||
|
{
|
||||||
|
ReportParamError
|
||||||
|
(
|
||||||
|
param,
|
||||||
|
"double specification of \"size\" and \"relativesize\""
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (HasParam(wxT("relativesize")))
|
else if (HasParam(wxT("relativesize")))
|
||||||
font.SetPointSize(int(font.GetPointSize() *
|
font.SetPointSize(int(font.GetPointSize() *
|
||||||
GetFloat(wxT("relativesize"))));
|
GetFloat(wxT("relativesize"))));
|
||||||
|
Reference in New Issue
Block a user