From 712e3652ffbfaa42ac27adc0a6846dc2abff5fca Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 16 Jan 2019 01:52:37 +0100 Subject: [PATCH] Deal with themes not implementing GetThemeBackgroundContentRect() Some custom themes apparently don't implement this function at all and just return failure error code from it, but our code either assumed that it never failed (when handling WM_NCPAINT) or didn't handle its failure correctly (when handle WM_NCCALCSIZE the client rect wasn't returned at all to the system in this case). Fix this by just falling back to the initial rectangle in case of failure. --- src/msw/window.cpp | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 522a544b88..5da2ec427e 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -3740,18 +3740,23 @@ wxWindowMSW::MSWHandleMessage(WXLRESULT *result, EP_EDITTEXT, IsEnabled() ? ETS_NORMAL : ETS_DISABLED, rect, - &rcClient) == S_OK ) + &rcClient) != S_OK ) { - InflateRect(&rcClient, -1, -1); - if (wParam) - csparam->rgrc[0] = rcClient; - else - *((RECT*)lParam) = rcClient; - - // WVR_REDRAW triggers a bug whereby child windows are moved up and left, - // so don't use. - // rc.result = WVR_REDRAW; + // If GetThemeBackgroundContentRect() failed, as can + // happen with at least some custom themes, just use + // the original client rectangle. + rcClient = *rect; } + + InflateRect(&rcClient, -1, -1); + if (wParam) + csparam->rgrc[0] = rcClient; + else + *((RECT*)lParam) = rcClient; + + // WVR_REDRAW triggers a bug whereby child windows are moved up and left, + // so don't use. + // rc.result = WVR_REDRAW; } } break; @@ -3776,8 +3781,23 @@ wxWindowMSW::MSWHandleMessage(WXLRESULT *result, RECT rcClient; const int nState = IsEnabled() ? ETS_NORMAL : ETS_DISABLED; - ::GetThemeBackgroundContentRect( - hTheme, GetHdcOf(*impl), EP_EDITTEXT, nState, &rcBorder, &rcClient); + + if ( ::GetThemeBackgroundContentRect + ( + hTheme, + GetHdcOf(*impl), + EP_EDITTEXT, + nState, + &rcBorder, + &rcClient + ) != S_OK ) + { + // As above in WM_NCCALCSIZE, fall back on something + // reasonable for themes which don't implement this + // function. + rcClient = rcBorder; + } + InflateRect(&rcClient, -1, -1); ::ExcludeClipRect(GetHdcOf(*impl), rcClient.left, rcClient.top,