From 3d3914bca0eb9d3646a6f9beb9fe20ec876dd230 Mon Sep 17 00:00:00 2001 From: Zhiyi Zhang Date: Thu, 4 Nov 2021 14:51:57 +0800 Subject: [PATCH] comctl32/button: Simplify focus rectangle calculation for drawing themed push buttons. The focus rectangle is the same as the result from GetThemeBackgroundContentRect(). So there is no need to retrieve content margins and calculate it again. Signed-off-by: Zhiyi Zhang Signed-off-by: Alexandre Julliard --- dlls/comctl32/button.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/dlls/comctl32/button.c b/dlls/comctl32/button.c index fbe060513d2..00f42322399 100644 --- a/dlls/comctl32/button.c +++ b/dlls/comctl32/button.c @@ -2651,7 +2651,7 @@ cleanup: */ static void PB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, int state, UINT dtFlags, BOOL focused) { - RECT bgRect, textRect; + RECT bgRect, textRect, focusRect; NMCUSTOMDRAW nmcd; LRESULT cdrf; HWND parent; @@ -2661,6 +2661,8 @@ static void PB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, in GetClientRect(infoPtr->hwnd, &bgRect); GetThemeBackgroundContentRect(theme, hDC, BP_PUSHBUTTON, state, &bgRect, &textRect); + focusRect = textRect; + init_custom_draw(&nmcd, infoPtr, hDC, &bgRect); parent = GetParent(infoPtr->hwnd); @@ -2698,20 +2700,7 @@ static void PB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, in } if (cdrf & CDRF_SKIPPOSTPAINT) return; - if (focused) - { - MARGINS margins; - RECT focusRect = bgRect; - - GetThemeMargins(theme, hDC, BP_PUSHBUTTON, state, TMT_CONTENTMARGINS, NULL, &margins); - - focusRect.left += margins.cxLeftWidth; - focusRect.top += margins.cyTopHeight; - focusRect.right -= margins.cxRightWidth; - focusRect.bottom -= margins.cyBottomHeight; - - DrawFocusRect( hDC, &focusRect ); - } + if (focused) DrawFocusRect(hDC, &focusRect); } static void CB_ThemedPaint(HTHEME theme, const BUTTON_INFO *infoPtr, HDC hDC, int state, UINT dtFlags, BOOL focused)