Add "inherit" to <font> XRC tag.

This allows to construct a font based on the parent window font instead of
either fully specifying all font parameters or basing it on a standard font.

Closes #14632.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72572 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-09-28 23:48:34 +00:00
parent 9696657f22
commit 45df4bb6c2
6 changed files with 85 additions and 16 deletions

View File

@@ -2201,7 +2201,7 @@ static wxFont GetSystemFont(const wxString& name)
return wxNullFont;
}
wxFont wxXmlResourceHandler::GetFont(const wxString& param)
wxFont wxXmlResourceHandler::GetFont(const wxString& param, wxWindow* parent)
{
wxXmlNode *font_node = GetParamNode(param);
if (font_node == NULL)
@@ -2304,8 +2304,21 @@ wxFont wxXmlResourceHandler::GetFont(const wxString& param)
}
#endif // wxUSE_FONTMAP
wxFont font;
// is this font based on a system font?
wxFont font = GetSystemFont(GetParamValue(wxT("sysfont")));
if (HasParam(wxT("sysfont")))
{
font = GetSystemFont(GetParamValue(wxT("sysfont")));
}
// or should the font of the widget be used?
else if (GetBool(wxT("inherit"), false))
{
if (parent)
font = parent->GetFont();
else
ReportError("no parent window specified to derive the font from");
}
if (font.IsOk())
{
@@ -2368,9 +2381,9 @@ void wxXmlResourceHandler::SetupWindow(wxWindow *wnd)
wnd->SetToolTip(GetText(wxT("tooltip")));
#endif
if (HasParam(wxT("font")))
wnd->SetFont(GetFont(wxT("font")));
wnd->SetFont(GetFont(wxT("font"), wnd));
if (HasParam(wxT("ownfont")))
wnd->SetOwnFont(GetFont(wxT("ownfont")));
wnd->SetOwnFont(GetFont(wxT("ownfont"), wnd));
if (HasParam(wxT("help")))
wnd->SetHelpText(GetText(wxT("help")));
}