Commit aec7e91d authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

user32: Always clip the button painting to the client rectangle.

parent f4337b47
...@@ -217,6 +217,15 @@ static inline WCHAR *get_button_text( HWND hwnd ) ...@@ -217,6 +217,15 @@ static inline WCHAR *get_button_text( HWND hwnd )
return buffer; return buffer;
} }
static void setup_clipping( HWND hwnd, HDC hdc )
{
RECT rc;
GetClientRect( hwnd, &rc );
DPtoLP( hdc, (POINT *)&rc, 2 );
IntersectClipRect( hdc, rc.left, rc.top, rc.right, rc.bottom );
}
/*********************************************************************** /***********************************************************************
* ButtonWndProc_common * ButtonWndProc_common
*/ */
...@@ -798,6 +807,9 @@ static void PB_Paint( HWND hwnd, HDC hDC, UINT action ) ...@@ -798,6 +807,9 @@ static void PB_Paint( HWND hwnd, HDC hDC, UINT action )
parent = GetParent(hwnd); parent = GetParent(hwnd);
if (!parent) parent = hwnd; if (!parent) parent = hwnd;
SendMessageW( parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd ); SendMessageW( parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd );
setup_clipping( hwnd, hDC );
hOldPen = (HPEN)SelectObject(hDC, SYSCOLOR_GetPen(COLOR_WINDOWFRAME)); hOldPen = (HPEN)SelectObject(hDC, SYSCOLOR_GetPen(COLOR_WINDOWFRAME));
hOldBrush =(HBRUSH)SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE)); hOldBrush =(HBRUSH)SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE));
oldBkMode = SetBkMode(hDC, TRANSPARENT); oldBkMode = SetBkMode(hDC, TRANSPARENT);
...@@ -970,7 +982,7 @@ static void CB_Paint( HWND hwnd, HDC hDC, UINT action ) ...@@ -970,7 +982,7 @@ static void CB_Paint( HWND hwnd, HDC hDC, UINT action )
if (dtFlags == (UINT)-1L) /* Noting to draw */ if (dtFlags == (UINT)-1L) /* Noting to draw */
return; return;
IntersectClipRect(hDC, client.left, client.top, client.right, client.bottom); setup_clipping( hwnd, hDC );
if (action == ODA_DRAWENTIRE) if (action == ODA_DRAWENTIRE)
BUTTON_DrawLabel(hwnd, hDC, dtFlags, &rtext); BUTTON_DrawLabel(hwnd, hDC, dtFlags, &rtext);
...@@ -1046,6 +1058,8 @@ static void GB_Paint( HWND hwnd, HDC hDC, UINT action ) ...@@ -1046,6 +1058,8 @@ static void GB_Paint( HWND hwnd, HDC hDC, UINT action )
if (dtFlags == (UINT)-1L) if (dtFlags == (UINT)-1L)
return; return;
setup_clipping( hwnd, hDC );
/* Because buttons have CS_PARENTDC class style, there is a chance /* Because buttons have CS_PARENTDC class style, there is a chance
* that label will be drawn out of client rect. * that label will be drawn out of client rect.
* But Windows doesn't clip label's rect, so do I. * But Windows doesn't clip label's rect, so do I.
...@@ -1100,8 +1114,6 @@ static void OB_Paint( HWND hwnd, HDC hDC, UINT action ) ...@@ -1100,8 +1114,6 @@ static void OB_Paint( HWND hwnd, HDC hDC, UINT action )
{ {
LONG state = get_button_state( hwnd ); LONG state = get_button_state( hwnd );
DRAWITEMSTRUCT dis; DRAWITEMSTRUCT dis;
HRGN clipRegion;
RECT clipRect;
LONG_PTR id = GetWindowLongPtrW( hwnd, GWLP_ID ); LONG_PTR id = GetWindowLongPtrW( hwnd, GWLP_ID );
HWND parent; HWND parent;
HFONT hFont, hPrevFont = 0; HFONT hFont, hPrevFont = 0;
...@@ -1118,21 +1130,13 @@ static void OB_Paint( HWND hwnd, HDC hDC, UINT action ) ...@@ -1118,21 +1130,13 @@ static void OB_Paint( HWND hwnd, HDC hDC, UINT action )
dis.itemData = 0; dis.itemData = 0;
GetClientRect( hwnd, &dis.rcItem ); GetClientRect( hwnd, &dis.rcItem );
clipRegion = CreateRectRgnIndirect(&dis.rcItem);
if (GetClipRgn(hDC, clipRegion) != 1)
{
DeleteObject(clipRegion);
clipRegion=NULL;
}
clipRect = dis.rcItem;
DPtoLP(hDC, (LPPOINT) &clipRect, 2);
IntersectClipRect(hDC, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
if ((hFont = get_button_font( hwnd ))) hPrevFont = SelectObject( hDC, hFont ); if ((hFont = get_button_font( hwnd ))) hPrevFont = SelectObject( hDC, hFont );
parent = GetParent(hwnd); parent = GetParent(hwnd);
if (!parent) parent = hwnd; if (!parent) parent = hwnd;
SendMessageW( parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd ); SendMessageW( parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd );
setup_clipping( hwnd, hDC );
SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis ); SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
if (hPrevFont) SelectObject(hDC, hPrevFont); if (hPrevFont) SelectObject(hDC, hPrevFont);
SelectClipRgn(hDC, clipRegion);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment