Nikolay Sivov : comctl32/button: Do not select old font back after painting.
Alexandre Julliard
julliard at winehq.org
Thu Mar 1 13:34:44 CST 2018
Module: wine
Branch: master
Commit: 81e698da27ab5aaccfa09a3bb38d628e84c49367
URL: https://source.winehq.org/git/wine.git/?a=commit;h=81e698da27ab5aaccfa09a3bb38d628e84c49367
Author: Nikolay Sivov <nsivov at codeweavers.com>
Date: Thu Mar 1 14:38:33 2018 +0300
comctl32/button: Do not select old font back after painting.
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/comctl32/button.c | 5 ++---
dlls/comctl32/tests/button.c | 35 ++++++++++++++++++++++++++++++++++-
2 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/dlls/comctl32/button.c b/dlls/comctl32/button.c
index d7a47cb..9869585 100644
--- a/dlls/comctl32/button.c
+++ b/dlls/comctl32/button.c
@@ -1220,7 +1220,7 @@ static void OB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action )
DRAWITEMSTRUCT dis;
LONG_PTR id = GetWindowLongPtrW( infoPtr->hwnd, GWLP_ID );
HWND parent;
- HFONT hFont, hPrevFont = 0;
+ HFONT hFont;
HRGN hrgn;
dis.CtlType = ODT_BUTTON;
@@ -1235,7 +1235,7 @@ static void OB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action )
dis.itemData = 0;
GetClientRect( infoPtr->hwnd, &dis.rcItem );
- if ((hFont = infoPtr->font)) hPrevFont = SelectObject( hDC, hFont );
+ if ((hFont = infoPtr->font)) SelectObject( hDC, hFont );
parent = GetParent(infoPtr->hwnd);
if (!parent) parent = infoPtr->hwnd;
SendMessageW( parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)infoPtr->hwnd );
@@ -1243,7 +1243,6 @@ static void OB_Paint( const BUTTON_INFO *infoPtr, HDC hDC, UINT action )
hrgn = set_control_clipping( hDC, &dis.rcItem );
SendMessageW( GetParent(infoPtr->hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
- if (hPrevFont) SelectObject(hDC, hPrevFont);
SelectClipRgn( hDC, hrgn );
if (hrgn) DeleteObject( hrgn );
}
diff --git a/dlls/comctl32/tests/button.c b/dlls/comctl32/tests/button.c
index 45a390d..b3bc23d 100644
--- a/dlls/comctl32/tests/button.c
+++ b/dlls/comctl32/tests/button.c
@@ -519,11 +519,12 @@ static void test_button_messages(void)
setfocus_seq, killfocus_seq, setstyle_seq,
setstate_seq, setstate_seq, setcheck_ignored_seq },
};
+ LOGFONTA logfont = { 0 };
const struct message *seq;
+ HFONT zfont, hfont2;
unsigned int i;
HWND hwnd, parent;
DWORD dlg_code;
- HFONT zfont;
BOOL todo;
/* selection with VK_SPACE should capture button window */
@@ -540,10 +541,19 @@ static void test_button_messages(void)
100, 100, 200, 200, 0, 0, 0, NULL);
ok(parent != 0, "Failed to create parent window\n");
+ logfont.lfHeight = -12;
+ logfont.lfWeight = FW_NORMAL;
+ strcpy(logfont.lfFaceName, "Tahoma");
+
+ hfont2 = CreateFontIndirectA(&logfont);
+ ok(hfont2 != NULL, "Failed to create Tahoma font\n");
+
for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
{
+ HFONT prevfont, hfont;
MSG msg;
DWORD style, state;
+ HDC hdc;
trace("%d: button test sequence\n", i);
hwnd = create_button(button[i].style, parent);
@@ -686,9 +696,32 @@ static void test_button_messages(void)
else
ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);
+ /* Test that original font is not selected back after painting */
+ hfont = (HFONT)SendMessageA(hwnd, WM_GETFONT, 0, 0);
+ ok(hfont == NULL, "Unexpected control font.\n");
+
+ SendMessageA(hwnd, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0);
+
+ hdc = CreateCompatibleDC(0);
+
+ prevfont = SelectObject(hdc, hfont2);
+ SendMessageA(hwnd, WM_PRINTCLIENT, (WPARAM)hdc, 0);
+ ok(hfont2 != GetCurrentObject(hdc, OBJ_FONT) || broken(hfont2 == GetCurrentObject(hdc, OBJ_FONT)) /* WinXP */,
+ "button[%u]: unexpected font selected after WM_PRINTCLIENT\n", i);
+ SelectObject(hdc, prevfont);
+
+ prevfont = SelectObject(hdc, hfont2);
+ SendMessageA(hwnd, WM_PAINT, (WPARAM)hdc, 0);
+ ok(hfont2 != GetCurrentObject(hdc, OBJ_FONT) || broken(hfont2 == GetCurrentObject(hdc, OBJ_FONT)) /* WinXP */,
+ "button[%u]: unexpected font selected after WM_PAINT\n", i);
+ SelectObject(hdc, prevfont);
+
+ DeleteDC(hdc);
+
DestroyWindow(hwnd);
}
+ DeleteObject(hfont2);
DestroyWindow(parent);
hwnd = create_button(BS_PUSHBUTTON, NULL);
More information about the wine-cvs
mailing list