From 466a19817fba93197ba7a4c3199fbe24d9edd718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Vesel=C3=BD?= Date: Thu, 18 Jul 2024 22:03:36 +0200 Subject: [PATCH] [COMCTL32][USER32] STATIC: Fix grayed drawing (#7024) CORE-15298 Use DrawTextW() to correctly render disabled grayed text. Applies to both dll\win32\comctl32\static.c and win32ss\user\user32\controls\static.c A similar solution is already used by button.c!BUTTON_DrawLabel(). --- dll/win32/comctl32/static.c | 18 +++++++++++++++++- win32ss/user/user32/controls/static.c | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/dll/win32/comctl32/static.c b/dll/win32/comctl32/static.c index b4e240ad91a..1d2e39f84ee 100644 --- a/dll/win32/comctl32/static.c +++ b/dll/win32/comctl32/static.c @@ -533,6 +533,15 @@ static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style ) if (font) SelectObject( hdc, oldFont ); } +static BOOL CALLBACK STATIC_DrawTextCallback(HDC hdc, LPARAM lp, WPARAM wp, int cx, int cy) +{ + RECT rc; + + SetRect(&rc, 0, 0, cx, cy); + DrawTextW(hdc, (LPCWSTR)lp, -1, &rc, (UINT)wp); + return TRUE; +} + static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style ) { RECT rc; @@ -626,7 +635,14 @@ static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style ) } else { - DrawTextW( hdc, text, -1, &rc, format ); + UINT flags = DST_COMPLEX; + if (style & WS_DISABLED) + flags |= DSS_DISABLED; + DrawStateW(hdc, hBrush, STATIC_DrawTextCallback, + (LPARAM)text, (WPARAM)format, + rc.left, rc.top, + rc.right - rc.left, rc.bottom - rc.top, + flags); } no_TextOut: diff --git a/win32ss/user/user32/controls/static.c b/win32ss/user/user32/controls/static.c index 3ae50684b6f..485ba82ab1a 100644 --- a/win32ss/user/user32/controls/static.c +++ b/win32ss/user/user32/controls/static.c @@ -611,6 +611,15 @@ static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style ) if (font) SelectObject( hdc, oldFont ); } +static BOOL CALLBACK STATIC_DrawTextCallback(HDC hdc, LPARAM lp, WPARAM wp, int cx, int cy) +{ + RECT rc; + + SetRect(&rc, 0, 0, cx, cy); + DrawTextW(hdc, (LPCWSTR)lp, -1, &rc, (UINT)wp); + return TRUE; +} + static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style ) { RECT rc; @@ -706,7 +715,14 @@ static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style ) } else { - DrawTextW( hdc, text, -1, &rc, format ); + UINT flags = DST_COMPLEX; + if (style & WS_DISABLED) + flags |= DSS_DISABLED; + DrawStateW(hdc, hBrush, STATIC_DrawTextCallback, + (LPARAM)text, (WPARAM)format, + rc.left, rc.top, + rc.right - rc.left, rc.bottom - rc.top, + flags); } no_TextOut: