Fall back on default margins if the theme doesn't provide them

::GetThemeMargins() may fail if the custom theme being currently used
doesn't implement the required functionality, so initialize MARGINS with
some reasonable values before calling it, if only in order to avoid
using uninitialized (and so wildly wrong) margin values in this case.

Closes https://github.com/wxWidgets/wxWidgets/pull/1036

Closes #18278.
This commit is contained in:
Tomay
2018-12-01 14:06:22 +01:00
committed by Vadim Zeitlin
parent ce45edcc51
commit f271cc61e8

View File

@@ -524,7 +524,9 @@ void wxAnyButton::AdjustForBitmapSize(wxSize &size) const
{
wxUxThemeHandle theme(const_cast<wxAnyButton *>(this), L"BUTTON");
MARGINS margins;
// Initialize margins with the default values (at least under
// Windows 7) in case GetThemeMargins() fails.
MARGINS margins = {3, 3, 3, 3};
::GetThemeMargins(theme, NULL,
BP_PUSHBUTTON,
PBS_NORMAL,
@@ -1148,8 +1150,9 @@ void DrawXPBackground(wxAnyButton *button, HDC hdc, RECT& rectBtn, UINT state)
::DrawThemeBackground(theme, hdc, BP_PUSHBUTTON, iState,
&rectBtn, NULL);
// calculate content area margins
MARGINS margins;
// calculate content area margins, using the defaults in case we fail to
// retrieve the current theme margins
MARGINS margins = {3, 3, 3, 3};
::GetThemeMargins(theme, hdc, BP_PUSHBUTTON, iState,
TMT_CONTENTMARGINS, &rectBtn, &margins);
::InflateRect(&rectBtn, -margins.cxLeftWidth, -margins.cyTopHeight);