Signed-off-by: Jeff Smith whydoubt@gmail.com --- dlls/user32/button.c | 68 +++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 45 deletions(-)
diff --git a/dlls/user32/button.c b/dlls/user32/button.c index e3af68e0e54..bbb56edb792 100644 --- a/dlls/user32/button.c +++ b/dlls/user32/button.c @@ -177,6 +177,22 @@ static inline WCHAR *get_button_text( HWND hwnd ) return buffer; }
+static HBRUSH BUTTON_BrushSendMessage( HWND hwnd, HDC hDC, UINT message ) +{ + HBRUSH hBrush; + HWND parent; + + parent = GetParent( hwnd ); + if (!parent) + parent = hwnd; + + hBrush = (HBRUSH)SendMessageW( parent, message, (WPARAM)hDC, (LPARAM)hwnd ); + /* did the app forget to call defwindowproc ? */ + if (!hBrush) + hBrush = (HBRUSH)DefWindowProcW( parent, message, (WPARAM)hDC, (LPARAM)hwnd ); + return hBrush; +} + /*********************************************************************** * ButtonWndProc_common */ @@ -230,13 +246,7 @@ LRESULT ButtonWndProc_common(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, { HDC hdc = (HDC)wParam; RECT rc; - HBRUSH hBrush; - HWND parent = GetParent(hWnd); - if (!parent) parent = hWnd; - hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORBTN, (WPARAM)hdc, (LPARAM)hWnd); - if (!hBrush) /* did the app forget to call defwindowproc ? */ - hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORBTN, - (WPARAM)hdc, (LPARAM)hWnd); + HBRUSH hBrush = BUTTON_BrushSendMessage( hWnd, hdc, WM_CTLCOLORBTN ); GetClientRect(hWnd, &rc); FillRect(hdc, &rc, hBrush); } @@ -350,21 +360,14 @@ LRESULT ButtonWndProc_common(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, if (IsWindowVisible(hWnd)) { HDC hdc = GetDC(hWnd); - HBRUSH hbrush; RECT client, rc; - HWND parent = GetParent(hWnd); UINT message = (btn_type == BS_PUSHBUTTON || btn_type == BS_DEFPUSHBUTTON || btn_type == BS_USERBUTTON || btn_type == BS_OWNERDRAW) ? WM_CTLCOLORBTN : WM_CTLCOLORSTATIC;
- if (!parent) parent = hWnd; - hbrush = (HBRUSH)SendMessageW(parent, message, - (WPARAM)hdc, (LPARAM)hWnd); - if (!hbrush) /* did the app forget to call DefWindowProc ? */ - hbrush = (HBRUSH)DefWindowProcW(parent, message, - (WPARAM)hdc, (LPARAM)hWnd); + HBRUSH hbrush = BUTTON_BrushSendMessage( hWnd, hdc, message );
GetClientRect(hWnd, &client); rc = client; @@ -738,16 +741,13 @@ static void PB_Paint( HWND hwnd, HDC hDC, UINT action ) LONG state = get_button_state( hwnd ); LONG style = GetWindowLongW( hwnd, GWL_STYLE ); BOOL pushedState = (state & BST_PUSHED); - HWND parent; HRGN hrgn;
GetClientRect( hwnd, &rc );
/* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */ if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont ); - parent = GetParent(hwnd); - if (!parent) parent = hwnd; - SendMessageW( parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd ); + BUTTON_BrushSendMessage( hwnd, hDC, WM_CTLCOLORBTN );
hrgn = set_control_clipping( hDC, &rc );
@@ -827,7 +827,6 @@ static void CB_Paint( HWND hwnd, HDC hDC, UINT action ) LONG state = get_button_state( hwnd ); LONG style = GetWindowLongW( hwnd, GWL_STYLE ); LONG ex_style = GetWindowLongW( hwnd, GWL_EXSTYLE ); - HWND parent; HRGN hrgn;
if (style & BS_PUSHLIKE) @@ -846,13 +845,7 @@ static void CB_Paint( HWND hwnd, HDC hDC, UINT action ) GetCharWidthW( hDC, '0', '0', &text_offset ); text_offset /= 2;
- parent = GetParent(hwnd); - if (!parent) parent = hwnd; - hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC, - (WPARAM)hDC, (LPARAM)hwnd); - if (!hBrush) /* did the app forget to call defwindowproc ? */ - hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC, - (WPARAM)hDC, (LPARAM)hwnd ); + hBrush = BUTTON_BrushSendMessage( hwnd, hDC, WM_CTLCOLORSTATIC ); hrgn = set_control_clipping( hDC, &client );
if (style & BS_LEFTTEXT || ex_style & WS_EX_RIGHT) @@ -981,17 +974,11 @@ static void GB_Paint( HWND hwnd, HDC hDC, UINT action ) UINT dtFlags; TEXTMETRICW tm; LONG style = GetWindowLongW( hwnd, GWL_STYLE ); - HWND parent; HRGN hrgn;
if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont ); /* GroupBox acts like static control, so it sends CTLCOLORSTATIC */ - parent = GetParent(hwnd); - if (!parent) parent = hwnd; - hbr = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)hwnd); - if (!hbr) /* did the app forget to call defwindowproc ? */ - hbr = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC, - (WPARAM)hDC, (LPARAM)hwnd); + hbr = BUTTON_BrushSendMessage( hwnd, hDC, WM_CTLCOLORSTATIC ); GetClientRect( hwnd, &rc); rcFrame = rc; hrgn = set_control_clipping( hDC, &rc ); @@ -1032,18 +1019,12 @@ static void UB_Paint( HWND hwnd, HDC hDC, UINT action ) HBRUSH hBrush; HFONT hFont; LONG state = get_button_state( hwnd ); - HWND parent;
GetClientRect( hwnd, &rc);
if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont );
- parent = GetParent(hwnd); - if (!parent) parent = hwnd; - hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd); - if (!hBrush) /* did the app forget to call defwindowproc ? */ - hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORBTN, - (WPARAM)hDC, (LPARAM)hwnd); + hBrush = BUTTON_BrushSendMessage( hwnd, hDC, WM_CTLCOLORBTN );
FillRect( hDC, &rc, hBrush ); if (action == ODA_FOCUS || (state & BST_FOCUS)) @@ -1075,7 +1056,6 @@ static void OB_Paint( HWND hwnd, HDC hDC, UINT action ) LONG state = get_button_state( hwnd ); DRAWITEMSTRUCT dis; LONG_PTR id = GetWindowLongPtrW( hwnd, GWLP_ID ); - HWND parent; HFONT hFont; HRGN hrgn;
@@ -1092,9 +1072,7 @@ static void OB_Paint( HWND hwnd, HDC hDC, UINT action ) GetClientRect( hwnd, &dis.rcItem );
if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont ); - parent = GetParent(hwnd); - if (!parent) parent = hwnd; - SendMessageW( parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd ); + BUTTON_BrushSendMessage( hwnd, hDC, WM_CTLCOLORBTN );
hrgn = set_control_clipping( hDC, &dis.rcItem );