[v2 PATCH 1/3] user32/button: Do not restore font after button has been painted

Nikolay Sivov nsivov at codeweavers.com
Mon Feb 6 02:43:48 CST 2017


Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
 dlls/user32/button.c    |  5 ++---
 dlls/user32/tests/msg.c | 31 ++++++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/dlls/user32/button.c b/dlls/user32/button.c
index e85e30daaf..f85b1af3b4 100644
--- a/dlls/user32/button.c
+++ b/dlls/user32/button.c
@@ -1095,7 +1095,7 @@ static void OB_Paint( HWND hwnd, HDC hDC, UINT action )
     DRAWITEMSTRUCT dis;
     LONG_PTR id = GetWindowLongPtrW( hwnd, GWLP_ID );
     HWND parent;
-    HFONT hFont, hPrevFont = 0;
+    HFONT hFont;
     HRGN hrgn;
 
     dis.CtlType    = ODT_BUTTON;
@@ -1110,7 +1110,7 @@ static void OB_Paint( HWND hwnd, HDC hDC, UINT action )
     dis.itemData   = 0;
     GetClientRect( hwnd, &dis.rcItem );
 
-    if ((hFont = get_button_font( hwnd ))) hPrevFont = SelectObject( hDC, hFont );
+    if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont );
     parent = GetParent(hwnd);
     if (!parent) parent = hwnd;
     SendMessageW( parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd );
@@ -1118,7 +1118,6 @@ static void OB_Paint( HWND hwnd, HDC hDC, UINT action )
     hrgn = set_control_clipping( hDC, &dis.rcItem );
 
     SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
-    if (hPrevFont) SelectObject(hDC, hPrevFont);
     SelectClipRgn( hDC, hrgn );
     if (hrgn) DeleteObject( hrgn );
 }
diff --git a/dlls/user32/tests/msg.c b/dlls/user32/tests/msg.c
index c608c11c22..dd04de5b9a 100644
--- a/dlls/user32/tests/msg.c
+++ b/dlls/user32/tests/msg.c
@@ -5800,10 +5800,11 @@ static void test_button_messages(void)
           WmLButtonDownSeq, WmLButtonUpSeq, WmSetFontButtonSeq,
           WmSetTextButtonSeq },
     };
+    LOGFONTA logfont = { 0 };
+    HFONT zfont, hfont2;
     unsigned int i;
     HWND hwnd, parent;
     DWORD dlg_code;
-    HFONT zfont;
 
     /* selection with VK_SPACE should capture button window */
     hwnd = CreateWindowExA(0, "button", "test", BS_CHECKBOX | WS_VISIBLE | WS_POPUP,
@@ -5822,11 +5823,21 @@ static void test_button_messages(void)
                              100, 100, 200, 200, 0, 0, 0, NULL);
     ok(parent != 0, "Failed to create parent window\n");
 
+    memset(&logfont, 0, sizeof(logfont));
+    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++)
     {
         MSG msg;
         DWORD style, state;
+        HFONT prevfont;
         char desc[64];
+        HDC hdc;
 
         trace("button style %08x\n", button[i].style);
 
@@ -6007,9 +6018,27 @@ static void test_button_messages(void)
         sprintf(desc, "button[%i]: WM_SETFONT on a button", i);
         ok_sequence(button[i].setfont, desc, FALSE);
 
+        /* Test that original font is not selected back after painting */
+        hdc = CreateCompatibleDC(0);
+
+        prevfont = SelectObject(hdc, hfont2);
+        SendMessageA(hwnd, WM_PRINTCLIENT, (WPARAM)hdc, 0);
+        ok(zfont == GetCurrentObject(hdc, OBJ_FONT), "button[%u]: unexpected font selected after WM_PRINTCLIENT %p, "
+            "expected %p\n", i, GetCurrentObject(hdc, OBJ_FONT), zfont);
+        SelectObject(hdc, prevfont);
+
+        prevfont = SelectObject(hdc, hfont2);
+        SendMessageA(hwnd, WM_PAINT, (WPARAM)hdc, 0);
+        ok(zfont == GetCurrentObject(hdc, OBJ_FONT), "button[%u]: unexpected font selected after WM_PAINT %p, "
+            "expected %p\n", i, GetCurrentObject(hdc, OBJ_FONT), zfont);
+        SelectObject(hdc, prevfont);
+
+        DeleteDC(hdc);
+
         DestroyWindow(hwnd);
     }
 
+    DeleteObject(hfont2);
     DestroyWindow(parent);
 }
 
-- 
2.11.0




More information about the wine-patches mailing list