[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().
This commit is contained in:
Tomáš Veselý 2024-07-18 22:03:36 +02:00 committed by GitHub
parent 7f31cdc18f
commit 466a19817f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 2 deletions

View file

@ -533,6 +533,15 @@ static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
if (font) SelectObject( hdc, oldFont ); 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 ) static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
{ {
RECT rc; RECT rc;
@ -626,7 +635,14 @@ static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
} }
else 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: no_TextOut:

View file

@ -611,6 +611,15 @@ static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
if (font) SelectObject( hdc, oldFont ); 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 ) static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
{ {
RECT rc; RECT rc;
@ -706,7 +715,14 @@ static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
} }
else 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: no_TextOut: