Use correct font for ownerdraw buttons (second try)

Michael Kaufmann hallo at michael-kaufmann.ch
Thu Aug 19 19:12:52 CDT 2004


I resubmit this patch because a space character was missing on some 
lines in the patch. Thanks to Alexandre Julliard for notifying me.

(If you are interested how the space characters got missing, read along: 
I sent the text with Mozilla Mail to myself to check if everything 
worked fine. It didn't (Mozilla wrapped some lines), so I marked the 
patch text in Mozilla Mail and copied it to the clipboard. Then I pasted 
the patch into another mail program. Because Mozilla Mail uses 
"format=flowed" (RFC 2646), it removed the first space character from 
every line and copied this modified version of the patch to the clipboard.)


So here's the patch again:

This patch fixes a font issue with buttons that have the BS_OWNERDRAW 
style. It's necessary to select the font set by WM_SETFONT into the 
device context before WM_DRAWITEM is sent. Windows does this too: It's 
undocumented, but some custom controls (e.g. CButtonST) rely on this.

The other controls that support owner draw styles (combo box, list box, 
menu) already do this correctly.

Changelog:

* controls/button.c:
   Use correct font for ownerdraw buttons
-------------- next part --------------
diff -u -r1.72 button.c
--- controls/button.c	16 Aug 2004 20:00:41 -0000	1.72
+++ controls/button.c	16 Aug 2004 20:51:45 -0000
@@ -1035,6 +1035,7 @@
     RECT clipRect;
     UINT id = GetWindowLongA( hwnd, GWL_ID );
     HWND parent;
+    HFONT hPrevFont;
 
     dis.CtlType    = ODT_BUTTON;
     dis.CtlID      = id;
@@ -1058,9 +1059,11 @@
     DPtoLP(hDC, (LPPOINT) &clipRect, 2);
     IntersectClipRect(hDC, clipRect.left,  clipRect.top, clipRect.right, clipRect.bottom);
 
+    hPrevFont = (get_button_font(hwnd)) ? SelectObject(hDC, get_button_font(hwnd)) : 0;
     parent = GetParent(hwnd);
     if (!parent) parent = hwnd;
     SendMessageW( parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd );
     SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
+    if (hPrevFont) SelectObject(hDC, hPrevFont);
     SelectClipRgn(hDC, clipRegion);
 }


More information about the wine-patches mailing list