Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/comctl32/Makefile.in | 1 + dlls/comctl32/button.c | 1153 ++++++++++++++++++++++++++++++++++++++++++ dlls/comctl32/comctl32.h | 1 + dlls/comctl32/commctrl.c | 2 + dlls/comctl32/tests/button.c | 18 +- dlls/comctl32/tests/misc.c | 3 +- dlls/user32/class.c | 1 - 7 files changed, 1164 insertions(+), 15 deletions(-) create mode 100644 dlls/comctl32/button.c
diff --git a/dlls/comctl32/Makefile.in b/dlls/comctl32/Makefile.in index db65bbc400..37bc025510 100644 --- a/dlls/comctl32/Makefile.in +++ b/dlls/comctl32/Makefile.in @@ -6,6 +6,7 @@ DELAYIMPORTS = winmm uxtheme
C_SRCS = \ animate.c \ + button.c \ comboex.c \ comctl32undoc.c \ commctrl.c \ diff --git a/dlls/comctl32/button.c b/dlls/comctl32/button.c new file mode 100644 index 0000000000..de036c6542 --- /dev/null +++ b/dlls/comctl32/button.c @@ -0,0 +1,1153 @@ +/* + * Copyright (C) 1993 Johannes Ruscheinski + * Copyright (C) 1993 David Metcalfe + * Copyright (C) 1994 Alexandre Julliard + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + * NOTES + * + * This code was audited for completeness against the documented features + * of Comctl32.dll version 6.0 on Oct. 3, 2004, by Dimitrie O. Paun. + * + * Unless otherwise noted, we believe this code to be complete, as per + * the specification mentioned above. + * If you discover missing features, or bugs, please note them below. + * + * TODO + * Styles + * - BS_NOTIFY: is it complete? + * - BS_RIGHTBUTTON: same as BS_LEFTTEXT + * + * Messages + * - WM_CHAR: Checks a (manual or automatic) check box on '+' or '=', clears it on '-' key. + * - WM_SETFOCUS: For (manual or automatic) radio buttons, send the parent window BN_CLICKED + * - WM_NCCREATE: Turns any BS_OWNERDRAW button into a BS_PUSHBUTTON button. + * - WM_SYSKEYUP + * - BCM_GETIDEALSIZE + * - BCM_GETIMAGELIST + * - BCM_GETTEXTMARGIN + * - BCM_SETIMAGELIST + * - BCM_SETTEXTMARGIN + * + * Notifications + * - BCN_HOTITEMCHANGE + * - BN_DISABLE + * - BN_PUSHED/BN_HILITE + * + BN_KILLFOCUS: is it OK? + * - BN_PAINT + * + BN_SETFOCUS: is it OK? + * - BN_UNPUSHED/BN_UNHILITE + * - NM_CUSTOMDRAW + * + * Structures/Macros/Definitions + * - BUTTON_IMAGELIST + * - NMBCHOTITEM + * - Button_GetIdealSize + * - Button_GetImageList + * - Button_GetTextMargin + * - Button_SetImageList + * - Button_SetTextMargin + */ + +#include <stdarg.h> +#include <string.h> +#include <stdlib.h> + +#define OEMRESOURCE + +#include "windef.h" +#include "winbase.h" +#include "wingdi.h" +#include "wine/debug.h" + +#include "comctl32.h" + +WINE_DEFAULT_DEBUG_CHANNEL(button); + +/* GetWindowLong offsets for window extra information */ +#define STATE_GWL_OFFSET 0 +#define HFONT_GWL_OFFSET (sizeof(LONG)) +#define HIMAGE_GWL_OFFSET (HFONT_GWL_OFFSET+sizeof(HFONT)) +#define NB_EXTRA_BYTES (HIMAGE_GWL_OFFSET+sizeof(HANDLE)) + +/* undocumented flags */ +#define BUTTON_NSTATES 0x0F +#define BUTTON_BTNPRESSED 0x40 +#define BUTTON_UNKNOWN2 0x20 +#define BUTTON_UNKNOWN3 0x10 + +#define BUTTON_NOTIFY_PARENT(hWnd, code) \ + do { /* Notify parent which has created this button control */ \ + TRACE("notification " #code " sent to hwnd=%p\n", GetParent(hWnd)); \ + SendMessageW(GetParent(hWnd), WM_COMMAND, \ + MAKEWPARAM(GetWindowLongPtrW((hWnd),GWLP_ID), (code)), \ + (LPARAM)(hWnd)); \ + } while(0) + +static UINT BUTTON_CalcLabelRect( HWND hwnd, HDC hdc, RECT *rc ); +static void PB_Paint( HWND hwnd, HDC hDC, UINT action ); +static void CB_Paint( HWND hwnd, HDC hDC, UINT action ); +static void GB_Paint( HWND hwnd, HDC hDC, UINT action ); +static void UB_Paint( HWND hwnd, HDC hDC, UINT action ); +static void OB_Paint( HWND hwnd, HDC hDC, UINT action ); +static void BUTTON_CheckAutoRadioButton( HWND hwnd ); + +#define MAX_BTN_TYPE 16 + +static const WORD maxCheckState[MAX_BTN_TYPE] = +{ + BST_UNCHECKED, /* BS_PUSHBUTTON */ + BST_UNCHECKED, /* BS_DEFPUSHBUTTON */ + BST_CHECKED, /* BS_CHECKBOX */ + BST_CHECKED, /* BS_AUTOCHECKBOX */ + BST_CHECKED, /* BS_RADIOBUTTON */ + BST_INDETERMINATE, /* BS_3STATE */ + BST_INDETERMINATE, /* BS_AUTO3STATE */ + BST_UNCHECKED, /* BS_GROUPBOX */ + BST_UNCHECKED, /* BS_USERBUTTON */ + BST_CHECKED, /* BS_AUTORADIOBUTTON */ + BST_UNCHECKED, /* BS_PUSHBOX */ + BST_UNCHECKED /* BS_OWNERDRAW */ +}; + +typedef void (*pfPaint)( HWND hwnd, HDC hdc, UINT action ); + +static const pfPaint btnPaintFunc[MAX_BTN_TYPE] = +{ + PB_Paint, /* BS_PUSHBUTTON */ + PB_Paint, /* BS_DEFPUSHBUTTON */ + CB_Paint, /* BS_CHECKBOX */ + CB_Paint, /* BS_AUTOCHECKBOX */ + CB_Paint, /* BS_RADIOBUTTON */ + CB_Paint, /* BS_3STATE */ + CB_Paint, /* BS_AUTO3STATE */ + GB_Paint, /* BS_GROUPBOX */ + UB_Paint, /* BS_USERBUTTON */ + CB_Paint, /* BS_AUTORADIOBUTTON */ + NULL, /* BS_PUSHBOX */ + OB_Paint /* BS_OWNERDRAW */ +}; + +/********************************************************************* + * button class descriptor + */ + +static inline LONG get_button_state( HWND hwnd ) +{ + return GetWindowLongW( hwnd, STATE_GWL_OFFSET ); +} + +static inline void set_button_state( HWND hwnd, LONG state ) +{ + SetWindowLongW( hwnd, STATE_GWL_OFFSET, state ); +} + +static inline HFONT get_button_font( HWND hwnd ) +{ + return (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET ); +} + +static inline void set_button_font( HWND hwnd, HFONT font ) +{ + SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, (LONG_PTR)font ); +} + +static inline UINT get_button_type( LONG window_style ) +{ + return (window_style & BS_TYPEMASK); +} + +/* paint a button of any type */ +static inline void paint_button( HWND hwnd, LONG style, UINT action ) +{ + if (btnPaintFunc[style] && IsWindowVisible(hwnd)) + { + HDC hdc = GetDC( hwnd ); + btnPaintFunc[style]( hwnd, hdc, action ); + ReleaseDC( hwnd, hdc ); + } +} + +/* retrieve the button text; returned buffer must be freed by caller */ +static inline WCHAR *get_button_text( HWND hwnd ) +{ + static const INT len = 512; + WCHAR *buffer = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ); + if (buffer) InternalGetWindowText( hwnd, buffer, len + 1 ); + return buffer; +} + +static HRGN set_control_clipping( HDC hdc, const RECT *rect ) +{ + RECT rc = *rect; + HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 ); + + if (GetClipRgn( hdc, hrgn ) != 1) + { + DeleteObject( hrgn ); + hrgn = 0; + } + DPtoLP( hdc, (POINT *)&rc, 2 ); + if (GetLayout( hdc ) & LAYOUT_RTL) /* compensate for the shifting done by IntersectClipRect */ + { + rc.left++; + rc.right++; + } + IntersectClipRect( hdc, rc.left, rc.top, rc.right, rc.bottom ); + return hrgn; +} + +static LRESULT CALLBACK BUTTON_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + RECT rect; + POINT pt; + LONG style = GetWindowLongW( hWnd, GWL_STYLE ); + UINT btn_type = get_button_type( style ); + LONG state; + HANDLE oldHbitmap; + + if (!IsWindow( hWnd )) return 0; + + pt.x = (short)LOWORD(lParam); + pt.y = (short)HIWORD(lParam); + + switch (uMsg) + { + case WM_GETDLGCODE: + switch(btn_type) + { + case BS_USERBUTTON: + case BS_PUSHBUTTON: return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON; + case BS_DEFPUSHBUTTON: return DLGC_BUTTON | DLGC_DEFPUSHBUTTON; + case BS_RADIOBUTTON: + case BS_AUTORADIOBUTTON: return DLGC_BUTTON | DLGC_RADIOBUTTON; + case BS_GROUPBOX: return DLGC_STATIC; + default: return DLGC_BUTTON; + } + + case WM_ENABLE: + paint_button( hWnd, btn_type, ODA_DRAWENTIRE ); + break; + + case WM_CREATE: + if (btn_type >= MAX_BTN_TYPE) + return -1; /* abort */ + + /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */ + if (btn_type == BS_USERBUTTON ) + { + style = (style & ~BS_TYPEMASK) | BS_PUSHBUTTON; + SetWindowLongW( hWnd, GWL_STYLE, style ); + } + set_button_state( hWnd, BST_UNCHECKED ); + return 0; + + case WM_ERASEBKGND: + if (btn_type == BS_OWNERDRAW) + { + 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); + GetClientRect(hWnd, &rc); + FillRect(hdc, &rc, hBrush); + } + return 1; + + case WM_PRINTCLIENT: + case WM_PAINT: + { + PAINTSTRUCT ps; + HDC hdc = wParam ? (HDC)wParam : BeginPaint( hWnd, &ps ); + if (btnPaintFunc[btn_type]) + { + int nOldMode = SetBkMode( hdc, OPAQUE ); + (btnPaintFunc[btn_type])( hWnd, hdc, ODA_DRAWENTIRE ); + SetBkMode(hdc, nOldMode); /* reset painting mode */ + } + if ( !wParam ) EndPaint( hWnd, &ps ); + break; + } + + case WM_KEYDOWN: + if (wParam == VK_SPACE) + { + SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 ); + set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED ); + SetCapture( hWnd ); + } + break; + + case WM_LBUTTONDBLCLK: + if(style & BS_NOTIFY || + btn_type == BS_RADIOBUTTON || + btn_type == BS_USERBUTTON || + btn_type == BS_OWNERDRAW) + { + BUTTON_NOTIFY_PARENT(hWnd, BN_DOUBLECLICKED); + break; + } + /* fall through */ + case WM_LBUTTONDOWN: + SetCapture( hWnd ); + SetFocus( hWnd ); + set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED ); + SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 ); + break; + + case WM_KEYUP: + if (wParam != VK_SPACE) + break; + /* fall through */ + case WM_LBUTTONUP: + state = get_button_state( hWnd ); + if (!(state & BUTTON_BTNPRESSED)) break; + state &= BUTTON_NSTATES; + set_button_state( hWnd, state ); + if (!(state & BST_PUSHED)) + { + ReleaseCapture(); + break; + } + SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 ); + GetClientRect( hWnd, &rect ); + if (uMsg == WM_KEYUP || PtInRect( &rect, pt )) + { + state = get_button_state( hWnd ); + switch(btn_type) + { + case BS_AUTOCHECKBOX: + SendMessageW( hWnd, BM_SETCHECK, !(state & BST_CHECKED), 0 ); + break; + case BS_AUTORADIOBUTTON: + SendMessageW( hWnd, BM_SETCHECK, TRUE, 0 ); + break; + case BS_AUTO3STATE: + SendMessageW( hWnd, BM_SETCHECK, + (state & BST_INDETERMINATE) ? 0 : ((state & 3) + 1), 0 ); + break; + } + ReleaseCapture(); + BUTTON_NOTIFY_PARENT(hWnd, BN_CLICKED); + } + else + { + ReleaseCapture(); + } + break; + + case WM_CAPTURECHANGED: + TRACE("WM_CAPTURECHANGED %p\n", hWnd); + if (hWnd == (HWND)lParam) break; + state = get_button_state( hWnd ); + if (state & BUTTON_BTNPRESSED) + { + state &= BUTTON_NSTATES; + set_button_state( hWnd, state ); + if (state & BST_PUSHED) SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 ); + } + break; + + case WM_MOUSEMOVE: + if ((wParam & MK_LBUTTON) && GetCapture() == hWnd) + { + GetClientRect( hWnd, &rect ); + SendMessageW( hWnd, BM_SETSTATE, PtInRect(&rect, pt), 0 ); + } + break; + + case WM_SETTEXT: + { + /* Clear an old text here as Windows does */ + 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); + + GetClientRect(hWnd, &client); + rc = client; + /* FIXME: check other BS_* handlers */ + if (btn_type == BS_GROUPBOX) + InflateRect(&rc, -7, 1); /* GB_Paint does this */ + BUTTON_CalcLabelRect(hWnd, hdc, &rc); + /* Clip by client rect bounds */ + if (rc.right > client.right) rc.right = client.right; + if (rc.bottom > client.bottom) rc.bottom = client.bottom; + FillRect(hdc, &rc, hbrush); + ReleaseDC(hWnd, hdc); + } + + DefWindowProcW( hWnd, WM_SETTEXT, wParam, lParam ); + if (btn_type == BS_GROUPBOX) /* Yes, only for BS_GROUPBOX */ + InvalidateRect( hWnd, NULL, TRUE ); + else + paint_button( hWnd, btn_type, ODA_DRAWENTIRE ); + return 1; /* success. FIXME: check text length */ + } + + case WM_SETFONT: + set_button_font( hWnd, (HFONT)wParam ); + if (lParam) InvalidateRect(hWnd, NULL, TRUE); + break; + + case WM_GETFONT: + return (LRESULT)get_button_font( hWnd ); + + case WM_SETFOCUS: + TRACE("WM_SETFOCUS %p\n",hWnd); + set_button_state( hWnd, get_button_state(hWnd) | BST_FOCUS ); + paint_button( hWnd, btn_type, ODA_FOCUS ); + if (style & BS_NOTIFY) + BUTTON_NOTIFY_PARENT(hWnd, BN_SETFOCUS); + break; + + case WM_KILLFOCUS: + TRACE("WM_KILLFOCUS %p\n",hWnd); + state = get_button_state( hWnd ); + set_button_state( hWnd, state & ~BST_FOCUS ); + paint_button( hWnd, btn_type, ODA_FOCUS ); + + if ((state & BUTTON_BTNPRESSED) && GetCapture() == hWnd) + ReleaseCapture(); + if (style & BS_NOTIFY) + BUTTON_NOTIFY_PARENT(hWnd, BN_KILLFOCUS); + + InvalidateRect( hWnd, NULL, FALSE ); + break; + + case WM_SYSCOLORCHANGE: + InvalidateRect( hWnd, NULL, FALSE ); + break; + + case BM_SETSTYLE: + btn_type = wParam & BS_TYPEMASK; + style = (style & ~BS_TYPEMASK) | btn_type; + SetWindowLongW( hWnd, GWL_STYLE, style ); + + /* Only redraw if lParam flag is set.*/ + if (lParam) + InvalidateRect( hWnd, NULL, TRUE ); + + break; + + case BM_CLICK: + SendMessageW( hWnd, WM_LBUTTONDOWN, 0, 0 ); + SendMessageW( hWnd, WM_LBUTTONUP, 0, 0 ); + break; + + case BM_SETIMAGE: + /* Check that image format matches button style */ + switch (style & (BS_BITMAP|BS_ICON)) + { + case BS_BITMAP: + if (wParam != IMAGE_BITMAP) return 0; + break; + case BS_ICON: + if (wParam != IMAGE_ICON) return 0; + break; + default: + return 0; + } + oldHbitmap = (HBITMAP)SetWindowLongPtrW( hWnd, HIMAGE_GWL_OFFSET, lParam ); + InvalidateRect( hWnd, NULL, FALSE ); + return (LRESULT)oldHbitmap; + + case BM_GETIMAGE: + return GetWindowLongPtrW( hWnd, HIMAGE_GWL_OFFSET ); + + case BM_GETCHECK: + return get_button_state( hWnd ) & 3; + + case BM_SETCHECK: + if (wParam > maxCheckState[btn_type]) wParam = maxCheckState[btn_type]; + state = get_button_state( hWnd ); + if ((btn_type == BS_RADIOBUTTON) || (btn_type == BS_AUTORADIOBUTTON)) + { + style = wParam ? style | WS_TABSTOP : style & ~WS_TABSTOP; + SetWindowLongW( hWnd, GWL_STYLE, style ); + } + if ((state & 3) != wParam) + { + set_button_state( hWnd, (state & ~3) | wParam ); + paint_button( hWnd, btn_type, ODA_SELECT ); + } + if ((btn_type == BS_AUTORADIOBUTTON) && (wParam == BST_CHECKED) && (style & WS_CHILD)) + BUTTON_CheckAutoRadioButton( hWnd ); + break; + + case BM_GETSTATE: + return get_button_state( hWnd ); + + case BM_SETSTATE: + state = get_button_state( hWnd ); + if (wParam) + set_button_state( hWnd, state | BST_PUSHED ); + else + set_button_state( hWnd, state & ~BST_PUSHED ); + + paint_button( hWnd, btn_type, ODA_SELECT ); + break; + + case WM_NCHITTEST: + if(btn_type == BS_GROUPBOX) return HTTRANSPARENT; + /* fall through */ + default: + return DefWindowProcW(hWnd, uMsg, wParam, lParam); + } + return 0; +} + +/********************************************************************** + * Convert button styles to flags used by DrawText. + */ +static UINT BUTTON_BStoDT( DWORD style, DWORD ex_style ) +{ + UINT dtStyle = DT_NOCLIP; /* We use SelectClipRgn to limit output */ + + /* "Convert" pushlike buttons to pushbuttons */ + if (style & BS_PUSHLIKE) + style &= ~BS_TYPEMASK; + + if (!(style & BS_MULTILINE)) + dtStyle |= DT_SINGLELINE; + else + dtStyle |= DT_WORDBREAK; + + switch (style & BS_CENTER) + { + case BS_LEFT: /* DT_LEFT is 0 */ break; + case BS_RIGHT: dtStyle |= DT_RIGHT; break; + case BS_CENTER: dtStyle |= DT_CENTER; break; + default: + /* Pushbutton's text is centered by default */ + if (get_button_type(style) <= BS_DEFPUSHBUTTON) dtStyle |= DT_CENTER; + /* all other flavours have left aligned text */ + } + + if (ex_style & WS_EX_RIGHT) dtStyle = DT_RIGHT | (dtStyle & ~(DT_LEFT | DT_CENTER)); + + /* DrawText ignores vertical alignment for multiline text, + * but we use these flags to align label manually. + */ + if (get_button_type(style) != BS_GROUPBOX) + { + switch (style & BS_VCENTER) + { + case BS_TOP: /* DT_TOP is 0 */ break; + case BS_BOTTOM: dtStyle |= DT_BOTTOM; break; + case BS_VCENTER: /* fall through */ + default: dtStyle |= DT_VCENTER; break; + } + } + else + /* GroupBox's text is always single line and is top aligned. */ + dtStyle |= DT_SINGLELINE; + + return dtStyle; +} + +/********************************************************************** + * BUTTON_CalcLabelRect + * + * Calculates label's rectangle depending on button style. + * + * Returns flags to be passed to DrawText. + * Calculated rectangle doesn't take into account button state + * (pushed, etc.). If there is nothing to draw (no text/image) output + * rectangle is empty, and return value is (UINT)-1. + */ +static UINT BUTTON_CalcLabelRect(HWND hwnd, HDC hdc, RECT *rc) +{ + LONG style = GetWindowLongW( hwnd, GWL_STYLE ); + LONG ex_style = GetWindowLongW( hwnd, GWL_EXSTYLE ); + WCHAR *text; + ICONINFO iconInfo; + BITMAP bm; + UINT dtStyle = BUTTON_BStoDT( style, ex_style ); + RECT r = *rc; + INT n; + + /* Calculate label rectangle according to label type */ + switch (style & (BS_ICON|BS_BITMAP)) + { + case BS_TEXT: + { + HFONT hFont, hPrevFont = 0; + + if (!(text = get_button_text( hwnd ))) goto empty_rect; + if (!text[0]) + { + HeapFree( GetProcessHeap(), 0, text ); + goto empty_rect; + } + + if ((hFont = get_button_font( hwnd ))) hPrevFont = SelectObject( hdc, hFont ); + DrawTextW(hdc, text, -1, &r, dtStyle | DT_CALCRECT); + if (hPrevFont) SelectObject( hdc, hPrevFont ); + HeapFree( GetProcessHeap(), 0, text ); + break; + } + + case BS_ICON: + if (!GetIconInfo((HICON)GetWindowLongPtrW( hwnd, HIMAGE_GWL_OFFSET ), &iconInfo)) + goto empty_rect; + + GetObjectW (iconInfo.hbmColor, sizeof(BITMAP), &bm); + + r.right = r.left + bm.bmWidth; + r.bottom = r.top + bm.bmHeight; + + DeleteObject(iconInfo.hbmColor); + DeleteObject(iconInfo.hbmMask); + break; + + case BS_BITMAP: + if (!GetObjectW( (HANDLE)GetWindowLongPtrW( hwnd, HIMAGE_GWL_OFFSET ), sizeof(BITMAP), &bm)) + goto empty_rect; + + r.right = r.left + bm.bmWidth; + r.bottom = r.top + bm.bmHeight; + break; + + default: + empty_rect: + rc->right = r.left; + rc->bottom = r.top; + return (UINT)-1; + } + + /* Position label inside bounding rectangle according to + * alignment flags. (calculated rect is always left-top aligned). + * If label is aligned to any side - shift label in opposite + * direction to leave extra space for focus rectangle. + */ + switch (dtStyle & (DT_CENTER|DT_RIGHT)) + { + case DT_LEFT: r.left++; r.right++; break; + case DT_CENTER: n = r.right - r.left; + r.left = rc->left + ((rc->right - rc->left) - n) / 2; + r.right = r.left + n; break; + case DT_RIGHT: n = r.right - r.left; + r.right = rc->right - 1; + r.left = r.right - n; + break; + } + + switch (dtStyle & (DT_VCENTER|DT_BOTTOM)) + { + case DT_TOP: r.top++; r.bottom++; break; + case DT_VCENTER: n = r.bottom - r.top; + r.top = rc->top + ((rc->bottom - rc->top) - n) / 2; + r.bottom = r.top + n; break; + case DT_BOTTOM: n = r.bottom - r.top; + r.bottom = rc->bottom - 1; + r.top = r.bottom - n; + break; + } + + *rc = r; + return dtStyle; +} + + +/********************************************************************** + * BUTTON_DrawTextCallback + * + * Callback function used by DrawStateW function. + */ +static BOOL CALLBACK BUTTON_DrawTextCallback(HDC hdc, LPARAM lp, WPARAM wp, int cx, int cy) +{ + RECT rc; + + SetRect(&rc, 0, 0, cx, cy); + DrawTextW(hdc, (LPCWSTR)lp, -1, &rc, (UINT)wp); + return TRUE; +} + + +/********************************************************************** + * BUTTON_DrawLabel + * + * Common function for drawing button label. + */ +static void BUTTON_DrawLabel(HWND hwnd, HDC hdc, UINT dtFlags, const RECT *rc) +{ + DRAWSTATEPROC lpOutputProc = NULL; + LPARAM lp; + WPARAM wp = 0; + HBRUSH hbr = 0; + UINT flags = IsWindowEnabled(hwnd) ? DSS_NORMAL : DSS_DISABLED; + LONG state = get_button_state( hwnd ); + LONG style = GetWindowLongW( hwnd, GWL_STYLE ); + WCHAR *text = NULL; + + /* FIXME: To draw disabled label in Win31 look-and-feel, we probably + * must use DSS_MONO flag and COLOR_GRAYTEXT brush (or maybe DSS_UNION). + * I don't have Win31 on hand to verify that, so I leave it as is. + */ + + if ((style & BS_PUSHLIKE) && (state & BST_INDETERMINATE)) + { + hbr = GetSysColorBrush(COLOR_GRAYTEXT); + flags |= DSS_MONO; + } + + switch (style & (BS_ICON|BS_BITMAP)) + { + case BS_TEXT: + /* DST_COMPLEX -- is 0 */ + lpOutputProc = BUTTON_DrawTextCallback; + if (!(text = get_button_text( hwnd ))) return; + lp = (LPARAM)text; + wp = dtFlags; + break; + + case BS_ICON: + flags |= DST_ICON; + lp = GetWindowLongPtrW( hwnd, HIMAGE_GWL_OFFSET ); + break; + + case BS_BITMAP: + flags |= DST_BITMAP; + lp = GetWindowLongPtrW( hwnd, HIMAGE_GWL_OFFSET ); + break; + + default: + return; + } + + DrawStateW(hdc, hbr, lpOutputProc, lp, wp, rc->left, rc->top, + rc->right - rc->left, rc->bottom - rc->top, flags); + HeapFree( GetProcessHeap(), 0, text ); +} + +/********************************************************************** + * Push Button Functions + */ +static void PB_Paint( HWND hwnd, HDC hDC, UINT action ) +{ + RECT rc, r; + UINT dtFlags, uState; + HPEN hOldPen, hpen; + HBRUSH hOldBrush; + INT oldBkMode; + COLORREF oldTxtColor; + HFONT hFont; + 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 ); + + hrgn = set_control_clipping( hDC, &rc ); + + hpen = CreatePen( PS_SOLID, 1, GetSysColor(COLOR_WINDOWFRAME)); + hOldPen = SelectObject(hDC, hpen); + hOldBrush = SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE)); + oldBkMode = SetBkMode(hDC, TRANSPARENT); + + if (get_button_type(style) == BS_DEFPUSHBUTTON) + { + if (action != ODA_FOCUS) + Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); + InflateRect( &rc, -1, -1 ); + } + + /* completely skip the drawing if only focus has changed */ + if (action == ODA_FOCUS) goto draw_focus; + + uState = DFCS_BUTTONPUSH; + + if (style & BS_FLAT) + uState |= DFCS_MONO; + else if (pushedState) + { + if (get_button_type(style) == BS_DEFPUSHBUTTON ) + uState |= DFCS_FLAT; + else + uState |= DFCS_PUSHED; + } + + if (state & (BST_CHECKED | BST_INDETERMINATE)) + uState |= DFCS_CHECKED; + + DrawFrameControl( hDC, &rc, DFC_BUTTON, uState ); + + /* draw button label */ + r = rc; + dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &r); + + if (dtFlags == (UINT)-1L) + goto cleanup; + + if (pushedState) + OffsetRect(&r, 1, 1); + + oldTxtColor = SetTextColor( hDC, GetSysColor(COLOR_BTNTEXT) ); + + BUTTON_DrawLabel(hwnd, hDC, dtFlags, &r); + + SetTextColor( hDC, oldTxtColor ); + +draw_focus: + if (action == ODA_FOCUS || (state & BST_FOCUS)) + { + InflateRect( &rc, -2, -2 ); + DrawFocusRect( hDC, &rc ); + } + + cleanup: + SelectObject( hDC, hOldPen ); + SelectObject( hDC, hOldBrush ); + SetBkMode(hDC, oldBkMode); + SelectClipRgn( hDC, hrgn ); + if (hrgn) DeleteObject( hrgn ); + DeleteObject( hpen ); +} + +/********************************************************************** + * Check Box & Radio Button Functions + */ + +static void CB_Paint( HWND hwnd, HDC hDC, UINT action ) +{ + RECT rbox, rtext, client; + HBRUSH hBrush; + int delta, text_offset, checkBoxWidth, checkBoxHeight; + UINT dtFlags; + HFONT hFont; + 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) + { + PB_Paint( hwnd, hDC, action ); + return; + } + + GetClientRect(hwnd, &client); + rbox = rtext = client; + + checkBoxWidth = 12 * GetDeviceCaps( hDC, LOGPIXELSX ) / 96 + 1; + checkBoxHeight = 12 * GetDeviceCaps( hDC, LOGPIXELSY ) / 96 + 1; + + if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont ); + 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 ); + hrgn = set_control_clipping( hDC, &client ); + + if (style & BS_LEFTTEXT || ex_style & WS_EX_RIGHT) + { + rtext.right -= checkBoxWidth + text_offset; + rbox.left = rbox.right - checkBoxWidth; + } + else + { + rtext.left += checkBoxWidth + text_offset; + rbox.right = checkBoxWidth; + } + + /* Since WM_ERASEBKGND does nothing, first prepare background */ + if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush ); + if (action == ODA_DRAWENTIRE) FillRect( hDC, &client, hBrush ); + + /* Draw label */ + client = rtext; + dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &rtext); + + /* Only adjust rbox when rtext is valid */ + if (dtFlags != (UINT)-1L) + { + rbox.top = rtext.top; + rbox.bottom = rtext.bottom; + } + + /* Draw the check-box bitmap */ + if (action == ODA_DRAWENTIRE || action == ODA_SELECT) + { + UINT flags; + + if ((get_button_type(style) == BS_RADIOBUTTON) || + (get_button_type(style) == BS_AUTORADIOBUTTON)) flags = DFCS_BUTTONRADIO; + else if (state & BST_INDETERMINATE) flags = DFCS_BUTTON3STATE; + else flags = DFCS_BUTTONCHECK; + + if (state & (BST_CHECKED | BST_INDETERMINATE)) flags |= DFCS_CHECKED; + if (state & BST_PUSHED) flags |= DFCS_PUSHED; + + if (style & WS_DISABLED) flags |= DFCS_INACTIVE; + + /* rbox must have the correct height */ + delta = rbox.bottom - rbox.top - checkBoxHeight; + + if (style & BS_TOP) { + if (delta > 0) { + rbox.bottom = rbox.top + checkBoxHeight; + } else { + rbox.top -= -delta/2 + 1; + rbox.bottom = rbox.top + checkBoxHeight; + } + } else if (style & BS_BOTTOM) { + if (delta > 0) { + rbox.top = rbox.bottom - checkBoxHeight; + } else { + rbox.bottom += -delta/2 + 1; + rbox.top = rbox.bottom - checkBoxHeight; + } + } else { /* Default */ + if (delta > 0) { + int ofs = (delta / 2); + rbox.bottom -= ofs + 1; + rbox.top = rbox.bottom - checkBoxHeight; + } else if (delta < 0) { + int ofs = (-delta / 2); + rbox.top -= ofs + 1; + rbox.bottom = rbox.top + checkBoxHeight; + } + } + + DrawFrameControl( hDC, &rbox, DFC_BUTTON, flags ); + } + + if (dtFlags == (UINT)-1L) /* Noting to draw */ + return; + + if (action == ODA_DRAWENTIRE) + BUTTON_DrawLabel(hwnd, hDC, dtFlags, &rtext); + + /* ... and focus */ + if (action == ODA_FOCUS || (state & BST_FOCUS)) + { + rtext.left--; + rtext.right++; + IntersectRect(&rtext, &rtext, &client); + DrawFocusRect( hDC, &rtext ); + } + SelectClipRgn( hDC, hrgn ); + if (hrgn) DeleteObject( hrgn ); +} + + +/********************************************************************** + * BUTTON_CheckAutoRadioButton + * + * hwnd is checked, uncheck every other auto radio button in group + */ +static void BUTTON_CheckAutoRadioButton( HWND hwnd ) +{ + HWND parent, sibling, start; + + parent = GetParent(hwnd); + /* make sure that starting control is not disabled or invisible */ + start = sibling = GetNextDlgGroupItem( parent, hwnd, TRUE ); + do + { + if (!sibling) break; + if ((hwnd != sibling) && + ((GetWindowLongW( sibling, GWL_STYLE) & BS_TYPEMASK) == BS_AUTORADIOBUTTON)) + SendMessageW( sibling, BM_SETCHECK, BST_UNCHECKED, 0 ); + sibling = GetNextDlgGroupItem( parent, sibling, FALSE ); + } while (sibling != start); +} + + +/********************************************************************** + * Group Box Functions + */ + +static void GB_Paint( HWND hwnd, HDC hDC, UINT action ) +{ + RECT rc, rcFrame; + HBRUSH hbr; + HFONT hFont; + 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); + GetClientRect( hwnd, &rc); + rcFrame = rc; + hrgn = set_control_clipping( hDC, &rc ); + + GetTextMetricsW (hDC, &tm); + rcFrame.top += (tm.tmHeight / 2) - 1; + DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT | ((style & BS_FLAT) ? BF_FLAT : 0)); + + InflateRect(&rc, -7, 1); + dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &rc); + + if (dtFlags != (UINT)-1) + { + /* Because buttons have CS_PARENTDC class style, there is a chance + * that label will be drawn out of client rect. + * But Windows doesn't clip label's rect, so do I. + */ + + /* There is 1-pixel margin at the left, right, and bottom */ + rc.left--; rc.right++; rc.bottom++; + FillRect(hDC, &rc, hbr); + rc.left++; rc.right--; rc.bottom--; + + BUTTON_DrawLabel(hwnd, hDC, dtFlags, &rc); + } + SelectClipRgn( hDC, hrgn ); + if (hrgn) DeleteObject( hrgn ); +} + + +/********************************************************************** + * User Button Functions + */ + +static void UB_Paint( HWND hwnd, HDC hDC, UINT action ) +{ + RECT rc; + 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); + + FillRect( hDC, &rc, hBrush ); + if (action == ODA_FOCUS || (state & BST_FOCUS)) + DrawFocusRect( hDC, &rc ); + + switch (action) + { + case ODA_FOCUS: + BUTTON_NOTIFY_PARENT( hwnd, (state & BST_FOCUS) ? BN_SETFOCUS : BN_KILLFOCUS ); + break; + + case ODA_SELECT: + BUTTON_NOTIFY_PARENT( hwnd, (state & BST_PUSHED) ? BN_HILITE : BN_UNHILITE ); + break; + + default: + BUTTON_NOTIFY_PARENT( hwnd, BN_PAINT ); + break; + } +} + + +/********************************************************************** + * Ownerdrawn Button Functions + */ + +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, hPrevFont = 0; + HRGN hrgn; + + dis.CtlType = ODT_BUTTON; + dis.CtlID = id; + dis.itemID = 0; + dis.itemAction = action; + dis.itemState = ((state & BST_FOCUS) ? ODS_FOCUS : 0) | + ((state & BST_PUSHED) ? ODS_SELECTED : 0) | + (IsWindowEnabled(hwnd) ? 0: ODS_DISABLED); + dis.hwndItem = hwnd; + dis.hDC = hDC; + dis.itemData = 0; + GetClientRect( hwnd, &dis.rcItem ); + + if ((hFont = get_button_font( hwnd ))) hPrevFont = SelectObject( hDC, hFont ); + parent = GetParent(hwnd); + if (!parent) parent = hwnd; + SendMessageW( parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd ); + + 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 ); +} + +void BUTTON_Register(void) +{ + WNDCLASSW wndClass; + + memset(&wndClass, 0, sizeof(wndClass)); + wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC; + wndClass.lpfnWndProc = BUTTON_WindowProc; + wndClass.cbClsExtra = 0; + wndClass.cbWndExtra = NB_EXTRA_BYTES; + wndClass.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW); + wndClass.hbrBackground = NULL; + wndClass.lpszClassName = WC_BUTTONW; + RegisterClassW(&wndClass); +} diff --git a/dlls/comctl32/comctl32.h b/dlls/comctl32/comctl32.h index cb66ad420d..33cb0c78e2 100644 --- a/dlls/comctl32/comctl32.h +++ b/dlls/comctl32/comctl32.h @@ -175,6 +175,7 @@ BOOL WINAPI MirrorIcon(HICON *phicon1, HICON *phicon2);
extern void ANIMATE_Register(void) DECLSPEC_HIDDEN; extern void ANIMATE_Unregister(void) DECLSPEC_HIDDEN; +extern void BUTTON_Register(void) DECLSPEC_HIDDEN; extern void COMBOEX_Register(void) DECLSPEC_HIDDEN; extern void COMBOEX_Unregister(void) DECLSPEC_HIDDEN; extern void DATETIME_Register(void) DECLSPEC_HIDDEN; diff --git a/dlls/comctl32/commctrl.c b/dlls/comctl32/commctrl.c index 3bf4649112..b618ff2bfa 100644 --- a/dlls/comctl32/commctrl.c +++ b/dlls/comctl32/commctrl.c @@ -98,6 +98,7 @@ static void unregister_versioned_classes(void) #define VERSION "6.0.2600.2982!" static const char *classes[] = { + VERSION WC_BUTTONA, VERSION WC_EDITA, }; int i; @@ -167,6 +168,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) TREEVIEW_Register (); UPDOWN_Register ();
+ BUTTON_Register (); EDIT_Register ();
/* subclass user32 controls */ diff --git a/dlls/comctl32/tests/button.c b/dlls/comctl32/tests/button.c index 441ca581c5..38e55c8f69 100644 --- a/dlls/comctl32/tests/button.c +++ b/dlls/comctl32/tests/button.c @@ -576,7 +576,8 @@ static void test_button_messages(void) SendMessageA(hwnd, BM_SETSTYLE, button[i].style | BS_BOTTOM, TRUE); SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */ while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg); - ok_sequence(sequences, COMBINED_SEQ_INDEX, button[i].setstyle, "BM_SETSTYLE on a button", TRUE); + todo = button[i].style == BS_USERBUTTON || button[i].style == BS_OWNERDRAW; + ok_sequence(sequences, COMBINED_SEQ_INDEX, button[i].setstyle, "BM_SETSTYLE on a button", todo);
style = GetWindowLongA(hwnd, GWL_STYLE); style &= ~(WS_VISIBLE | WS_CHILD | BS_NOTIFY); @@ -623,17 +624,14 @@ static void test_button_messages(void) button[i].style == BS_AUTORADIOBUTTON) { seq = setcheck_radio_seq; - todo = TRUE; } else - { seq = setcheck_ignored_seq; - todo = FALSE; - } + SendMessageA(hwnd, BM_SETCHECK, BST_UNCHECKED, 0); SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */ while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg); - ok_sequence(sequences, COMBINED_SEQ_INDEX, seq, "BM_SETCHECK on a button", todo); + ok_sequence(sequences, COMBINED_SEQ_INDEX, seq, "BM_SETCHECK on a button", FALSE);
state = SendMessageA(hwnd, BM_GETCHECK, 0, 0); ok(state == BST_UNCHECKED, "expected BST_UNCHECKED, got %04x\n", state); @@ -715,7 +713,6 @@ static void test_button_class(void)
ret = GetClassInfoExA(NULL, WC_BUTTONA, &exA); ok(ret, "got %d\n", ret); -todo_wine ok(IS_WNDPROC_HANDLE(exA.lpfnWndProc), "got %p\n", exA.lpfnWndProc);
ret = GetClassInfoExW(NULL, WC_BUTTONW, &exW); @@ -727,9 +724,7 @@ todo_wine ok(lstrcmpW(nameW, WC_BUTTONW), "got %s\n", wine_dbgstr_w(nameW));
ret = GetClassInfoExW(NULL, nameW, &ex2W); -todo_wine ok(ret, "got %d\n", ret); -if (ret) /* TODO: remove once Wine is fixed */ ok(ex2W.lpfnWndProc == exW.lpfnWndProc, "got %p, %p\n", exW.lpfnWndProc, ex2W.lpfnWndProc);
/* Check reported class name */ @@ -745,10 +740,8 @@ if (ret) /* TODO: remove once Wine is fixed */
/* explicitly create with versioned class name */ hwnd = CreateWindowExW(0, nameW, testW, BS_CHECKBOX, 0, 0, 50, 14, NULL, 0, 0, NULL); -todo_wine ok(hwnd != NULL, "failed to create a window %s\n", wine_dbgstr_w(nameW)); -if (hwnd) -{ + len = GetClassNameA(hwnd, buffA, sizeof(buffA)); ok(len == strlen(buffA), "got %d\n", len); ok(!strcmp(buffA, "Button"), "got %s\n", buffA); @@ -759,7 +752,6 @@ if (hwnd)
DestroyWindow(hwnd); } -}
static void register_parent_class(void) { diff --git a/dlls/comctl32/tests/misc.c b/dlls/comctl32/tests/misc.c index bef92b88dc..cb59de243e 100644 --- a/dlls/comctl32/tests/misc.c +++ b/dlls/comctl32/tests/misc.c @@ -345,7 +345,8 @@ static void check_class( const char *name, int must_exist, UINT style, UINT igno
if (GetClassInfoA( 0, name, &wc )) { -todo_wine_if(strcmp(name, "Edit")) +todo_wine_if(strcmp(name, "Button") && + strcmp(name, "Edit")) ok( !(~wc.style & style & ~ignore), "System class %s is missing bits %x (%08x/%08x)\n", name, ~wc.style & style, wc.style, style ); ok( !(wc.style & ~style), "System class %s has extra bits %x (%08x/%08x)\n", diff --git a/dlls/user32/class.c b/dlls/user32/class.c index 8fba5bf115..441d5cb132 100644 --- a/dlls/user32/class.c +++ b/dlls/user32/class.c @@ -166,7 +166,6 @@ static BOOL is_builtin_class( const WCHAR *name ) { static const WCHAR classesW[][20] = { - {'B','u','t','t','o','n',0}, {'C','o','m','b','o','B','o','x',0}, {'C','o','m','b','o','L','B','o','x',0}, {'I','M','E',0},
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/comctl32/button.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/dlls/comctl32/button.c b/dlls/comctl32/button.c index de036c6542..b0eea996a4 100644 --- a/dlls/comctl32/button.c +++ b/dlls/comctl32/button.c @@ -120,7 +120,11 @@ static const WORD maxCheckState[MAX_BTN_TYPE] = BST_UNCHECKED, /* BS_USERBUTTON */ BST_CHECKED, /* BS_AUTORADIOBUTTON */ BST_UNCHECKED, /* BS_PUSHBOX */ - BST_UNCHECKED /* BS_OWNERDRAW */ + BST_UNCHECKED, /* BS_OWNERDRAW */ + BST_UNCHECKED, /* BS_SPLITBUTTON */ + BST_UNCHECKED, /* BS_DEFSPLITBUTTON */ + BST_UNCHECKED, /* BS_COMMANDLINK */ + BST_UNCHECKED /* BS_DEFCOMMANDLINK */ };
typedef void (*pfPaint)( HWND hwnd, HDC hdc, UINT action ); @@ -138,7 +142,11 @@ static const pfPaint btnPaintFunc[MAX_BTN_TYPE] = UB_Paint, /* BS_USERBUTTON */ CB_Paint, /* BS_AUTORADIOBUTTON */ NULL, /* BS_PUSHBOX */ - OB_Paint /* BS_OWNERDRAW */ + OB_Paint, /* BS_OWNERDRAW */ + PB_Paint, /* BS_SPLITBUTTON */ + PB_Paint, /* BS_DEFSPLITBUTTON */ + PB_Paint, /* BS_COMMANDLINK */ + PB_Paint /* BS_DEFCOMMANDLINK */ };
/*********************************************************************
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/comctl32/button.c | 4 ++++ dlls/comctl32/tests/button.c | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/dlls/comctl32/button.c b/dlls/comctl32/button.c index b0eea996a4..a39a64c9a3 100644 --- a/dlls/comctl32/button.c +++ b/dlls/comctl32/button.c @@ -237,12 +237,16 @@ static LRESULT CALLBACK BUTTON_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, L case WM_GETDLGCODE: switch(btn_type) { + case BS_COMMANDLINK: case BS_USERBUTTON: case BS_PUSHBUTTON: return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON; + case BS_DEFCOMMANDLINK: case BS_DEFPUSHBUTTON: return DLGC_BUTTON | DLGC_DEFPUSHBUTTON; case BS_RADIOBUTTON: case BS_AUTORADIOBUTTON: return DLGC_BUTTON | DLGC_RADIOBUTTON; case BS_GROUPBOX: return DLGC_STATIC; + case BS_SPLITBUTTON: return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON | DLGC_WANTARROWS; + case BS_DEFSPLITBUTTON: return DLGC_BUTTON | DLGC_DEFPUSHBUTTON | DLGC_WANTARROWS; default: return DLGC_BUTTON; }
diff --git a/dlls/comctl32/tests/button.c b/dlls/comctl32/tests/button.c index 38e55c8f69..f2f081dc2f 100644 --- a/dlls/comctl32/tests/button.c +++ b/dlls/comctl32/tests/button.c @@ -511,6 +511,18 @@ static void test_button_messages(void) { BS_OWNERDRAW, DLGC_BUTTON, setfocus_ownerdraw_seq, killfocus_ownerdraw_seq, setstyle_ownerdraw_seq, setstate_ownerdraw_seq, clearstate_ownerdraw_seq, setcheck_ignored_seq }, + { BS_SPLITBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON | DLGC_WANTARROWS, + setfocus_seq, killfocus_seq, setstyle_seq, + setstate_seq, setstate_seq, setcheck_ignored_seq }, + { BS_DEFSPLITBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON | DLGC_WANTARROWS, + setfocus_seq, killfocus_seq, setstyle_seq, + setstate_seq, setstate_seq, setcheck_ignored_seq }, + { BS_COMMANDLINK, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON, + setfocus_seq, killfocus_seq, setstyle_seq, + setstate_seq, setstate_seq, setcheck_ignored_seq }, + { BS_DEFCOMMANDLINK, DLGC_BUTTON | DLGC_DEFPUSHBUTTON, + setfocus_seq, killfocus_seq, setstyle_seq, + setstate_seq, setstate_seq, setcheck_ignored_seq }, }; const struct message *seq; unsigned int i; @@ -650,7 +662,11 @@ static void test_button_messages(void) button[i].style == BS_DEFPUSHBUTTON || button[i].style == BS_GROUPBOX || button[i].style == BS_USERBUTTON || - button[i].style == BS_OWNERDRAW) + button[i].style == BS_OWNERDRAW || + button[i].style == BS_SPLITBUTTON || + button[i].style == BS_DEFSPLITBUTTON || + button[i].style == BS_COMMANDLINK || + button[i].style == BS_DEFCOMMANDLINK) { ok_sequence(sequences, COMBINED_SEQ_INDEX, button[i].setcheck, "BM_SETCHECK on a button", FALSE); state = SendMessageA(hwnd, BM_GETCHECK, 0, 0);
Hi,
While running your changed tests on Windows, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check? Full results can be found at https://testbot.winehq.org/JobDetails.pl?Key=35770
Your paranoid android.
=== wxppro (32 bit button) === button.c:565: Test failed: 11: wrong dlg_code 00002000 button.c:565: Test failed: 12: wrong dlg_code 00002000 button.c:565: Test failed: 13: wrong dlg_code 00002000 button.c:565: Test failed: 14: wrong dlg_code 00002000
=== w2003std (32 bit button) === button.c:565: Test failed: 11: wrong dlg_code 00002000 button.c:565: Test failed: 12: wrong dlg_code 00002000 button.c:565: Test failed: 13: wrong dlg_code 00002000 button.c:565: Test failed: 14: wrong dlg_code 00002000
On 2/6/2018 9:08 AM, Marvin wrote:
Hi,
While running your changed tests on Windows, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check? Full results can be found at https://testbot.winehq.org/JobDetails.pl?Key=35770
Your paranoid android.
=== wxppro (32 bit button) === button.c:565: Test failed: 11: wrong dlg_code 00002000 button.c:565: Test failed: 12: wrong dlg_code 00002000 button.c:565: Test failed: 13: wrong dlg_code 00002000 button.c:565: Test failed: 14: wrong dlg_code 00002000
=== w2003std (32 bit button) === button.c:565: Test failed: 11: wrong dlg_code 00002000 button.c:565: Test failed: 12: wrong dlg_code 00002000 button.c:565: Test failed: 13: wrong dlg_code 00002000 button.c:565: Test failed: 14: wrong dlg_code 00002000
Ok, XP probably does not support new styles. Please ignore this one for now, I'll fix it later. Patches 4 and 5 don't depend on it.
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/comctl32/monthcal.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/dlls/comctl32/monthcal.c b/dlls/comctl32/monthcal.c index b94345c38b..9d00094bc7 100644 --- a/dlls/comctl32/monthcal.c +++ b/dlls/comctl32/monthcal.c @@ -56,6 +56,7 @@ #include "vssym32.h" #include "wine/unicode.h" #include "wine/debug.h" +#include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(monthcal);
@@ -1966,7 +1967,7 @@ static void MONTHCAL_NotifyDayState(MONTHCAL_INFO *infoPtr) nmds.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID); nmds.nmhdr.code = MCN_GETDAYSTATE; nmds.cDayState = MONTHCAL_GetMonthRange(infoPtr, GMR_DAYSTATE, 0); - nmds.prgDayState = state = Alloc(nmds.cDayState * sizeof(MONTHDAYSTATE)); + nmds.prgDayState = state = heap_alloc_zero(nmds.cDayState * sizeof(MONTHDAYSTATE));
MONTHCAL_GetMinDate(infoPtr, &nmds.stStart); nmds.stStart.wDay = 1; @@ -1975,7 +1976,7 @@ static void MONTHCAL_NotifyDayState(MONTHCAL_INFO *infoPtr) memcpy(infoPtr->monthdayState, nmds.prgDayState, MONTHCAL_GetMonthRange(infoPtr, GMR_DAYSTATE, 0)*sizeof(MONTHDAYSTATE));
- Free(state); + heap_free(state); }
/* no valid range check performed */ @@ -2615,9 +2616,9 @@ static void MONTHCAL_UpdateSize(MONTHCAL_INFO *infoPtr) { infoPtr->dim.cx = x; infoPtr->dim.cy = y; - infoPtr->calendars = ReAlloc(infoPtr->calendars, MONTHCAL_GetCalCount(infoPtr)*sizeof(CALENDAR_INFO)); + infoPtr->calendars = heap_realloc(infoPtr->calendars, MONTHCAL_GetCalCount(infoPtr)*sizeof(CALENDAR_INFO));
- infoPtr->monthdayState = ReAlloc(infoPtr->monthdayState, + infoPtr->monthdayState = heap_realloc(infoPtr->monthdayState, MONTHCAL_GetMonthRange(infoPtr, GMR_DAYSTATE, 0)*sizeof(MONTHDAYSTATE)); MONTHCAL_NotifyDayState(infoPtr);
@@ -2773,7 +2774,7 @@ MONTHCAL_Create(HWND hwnd, LPCREATESTRUCTW lpcs) MONTHCAL_INFO *infoPtr;
/* allocate memory for info structure */ - infoPtr = Alloc(sizeof(MONTHCAL_INFO)); + infoPtr = heap_alloc_zero(sizeof(*infoPtr)); SetWindowLongPtrW(hwnd, 0, (DWORD_PTR)infoPtr);
if (infoPtr == NULL) { @@ -2785,9 +2786,9 @@ MONTHCAL_Create(HWND hwnd, LPCREATESTRUCTW lpcs) infoPtr->hwndNotify = lpcs->hwndParent; infoPtr->dwStyle = GetWindowLongW(hwnd, GWL_STYLE); infoPtr->dim.cx = infoPtr->dim.cy = 1; - infoPtr->calendars = Alloc(sizeof(CALENDAR_INFO)); + infoPtr->calendars = heap_alloc_zero(sizeof(CALENDAR_INFO)); if (!infoPtr->calendars) goto fail; - infoPtr->monthdayState = Alloc(3*sizeof(MONTHDAYSTATE)); + infoPtr->monthdayState = heap_alloc_zero(3 * sizeof(MONTHDAYSTATE)); if (!infoPtr->monthdayState) goto fail;
/* initialize info structure */ @@ -2828,9 +2829,9 @@ MONTHCAL_Create(HWND hwnd, LPCREATESTRUCTW lpcs) return 0;
fail: - Free(infoPtr->monthdayState); - Free(infoPtr->calendars); - Free(infoPtr); + heap_free(infoPtr->monthdayState); + heap_free(infoPtr->calendars); + heap_free(infoPtr); return 0; }
@@ -2840,8 +2841,8 @@ MONTHCAL_Destroy(MONTHCAL_INFO *infoPtr) INT i;
/* free month calendar info data */ - Free(infoPtr->monthdayState); - Free(infoPtr->calendars); + heap_free(infoPtr->monthdayState); + heap_free(infoPtr->calendars); SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
CloseThemeData (GetWindowTheme (infoPtr->hwndSelf)); @@ -2849,7 +2850,7 @@ MONTHCAL_Destroy(MONTHCAL_INFO *infoPtr) for (i = 0; i < BrushLast; i++) DeleteObject(infoPtr->brushes[i]); for (i = 0; i < PenLast; i++) DeleteObject(infoPtr->pens[i]);
- Free(infoPtr); + heap_free(infoPtr); return 0; }
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/comctl32/tests/listbox.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/dlls/comctl32/tests/listbox.c b/dlls/comctl32/tests/listbox.c index 23aaac29e2..4d80beaf58 100644 --- a/dlls/comctl32/tests/listbox.c +++ b/dlls/comctl32/tests/listbox.c @@ -26,6 +26,7 @@ #include "wingdi.h" #include "winuser.h" #include "winnls.h" +#include "commctrl.h"
#include "wine/test.h" #include "v6util.h" @@ -50,7 +51,7 @@ static HWND create_listbox(DWORD add_style, HWND parent) if (parent) ctl_id=1;
- handle = CreateWindowA("LISTBOX", "TestList", (LBS_STANDARD & ~LBS_SORT) | add_style, 0, 0, 100, 100, + handle = CreateWindowA(WC_LISTBOXA, "TestList", (LBS_STANDARD & ~LBS_SORT) | add_style, 0, 0, 100, 100, parent, (HMENU)ctl_id, NULL, 0); ok(handle != NULL, "Failed to create listbox window.\n");
@@ -207,7 +208,7 @@ static void test_item_height(void)
DestroyWindow (hLB);
- hLB = CreateWindowA("LISTBOX", "TestList", LBS_OWNERDRAWVARIABLE, 0, 0, 100, 100, NULL, NULL, NULL, 0); + hLB = CreateWindowA(WC_LISTBOXA, "TestList", LBS_OWNERDRAWVARIABLE, 0, 0, 100, 100, NULL, NULL, NULL, 0);
itemHeight = SendMessageA(hLB, LB_GETITEMHEIGHT, 0, 0); ok(itemHeight > 0 && itemHeight <= tm.tmHeight, "Unexpected item height %d, expected %d.\n", @@ -430,7 +431,7 @@ static void test_listbox_height(void) HWND hList; int r, id;
- hList = CreateWindowA( "ListBox", "list test", 0, + hList = CreateWindowA( WC_LISTBOXA, "list test", 0, 1, 1, 600, 100, NULL, NULL, NULL, NULL ); ok( hList != NULL, "failed to create listbox\n");
@@ -470,21 +471,20 @@ static void test_itemfrompoint(void) without caption). LBS_NOINTEGRALHEIGHT is required in order to test behavior of partially-displayed item. */ - HWND hList = CreateWindowA( "ListBox", "list test", + HWND hList = CreateWindowA( WC_LISTBOXA, "list test", WS_VISIBLE|WS_POPUP|LBS_NOINTEGRALHEIGHT, 1, 1, 600, 100, NULL, NULL, NULL, NULL ); ULONG r, id; RECT rc;
- /* For an empty listbox win2k returns 0x1ffff, win98 returns 0x10000, nt4 returns 0xffffffff */ r = SendMessageA(hList, LB_ITEMFROMPOINT, 0, MAKELPARAM( /* x */ 30, /* y */ 30 )); - ok( r == 0x1ffff || r == 0x10000 || r == 0xffffffff, "ret %x\n", r ); + ok( r == MAKELPARAM(0xffff, 1), "Unexpected ret value %#x.\n", r );
r = SendMessageA(hList, LB_ITEMFROMPOINT, 0, MAKELPARAM( 700, 30 )); - ok( r == 0x1ffff || r == 0x10000 || r == 0xffffffff, "ret %x\n", r ); + ok( r == MAKELPARAM(0xffff, 1), "Unexpected ret value %#x.\n", r );
r = SendMessageA(hList, LB_ITEMFROMPOINT, 0, MAKELPARAM( 30, 300 )); - ok( r == 0x1ffff || r == 0x10000 || r == 0xffffffff, "ret %x\n", r ); + ok( r == MAKELPARAM(0xffff, 1), "Unexpected ret value %#x.\n", r );
id = SendMessageA( hList, LB_ADDSTRING, 0, (LPARAM) "hi"); ok( id == 0, "item id wrong\n"); @@ -495,7 +495,7 @@ static void test_itemfrompoint(void) ok( r == 0x1, "ret %x\n", r );
r = SendMessageA(hList, LB_ITEMFROMPOINT, 0, MAKELPARAM( /* x */ 30, /* y */ 601 )); - ok( r == 0x10001, "ret %x\n", r ); + ok( r == MAKELPARAM(1, 1), "Unexpected ret value %#x.\n", r );
/* Resize control so that below assertions about sizes are valid */ r = SendMessageA( hList, LB_GETITEMRECT, 0, (LPARAM)&rc); @@ -551,7 +551,7 @@ static void test_listbox_item_data(void) HWND hList; int r, id;
- hList = CreateWindowA( "ListBox", "list test", 0, + hList = CreateWindowA( WC_LISTBOXA, "list test", 0, 1, 1, 600, 100, NULL, NULL, NULL, NULL ); ok( hList != NULL, "failed to create listbox\n");
@@ -591,7 +591,7 @@ static void test_listbox_LB_DIR(void) one file that fits the wildcard w*.c . Normally, the test directory itself satisfies both conditions. */ - hList = CreateWindowA( "ListBox", "list test", WS_VISIBLE|WS_POPUP, + hList = CreateWindowA( WC_LISTBOXA, "list test", WS_VISIBLE|WS_POPUP, 1, 1, 600, 100, NULL, NULL, NULL, NULL ); assert(hList);
@@ -902,7 +902,7 @@ static void test_listbox_LB_DIR(void) strcpy(pathBuffer, wildcard); SendMessageA(hList, LB_RESETCONTENT, 0, 0); res = SendMessageA(hList, LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, (LPARAM)pathBuffer); - ok (res != -1 || broken(res == -1), "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, *) failed err %u\n", + ok (res != -1, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, *) failed err %u\n", GetLastError());
itemCount = SendMessageA(hList, LB_GETCOUNT, 0, 0); @@ -1010,11 +1010,11 @@ static HWND g_label;
static BOOL on_listbox_container_create(HWND hwnd, CREATESTRUCTA *lpcs) { - g_label = CreateWindowA("Static", "Contents of static control before DlgDirList.", + g_label = CreateWindowA(WC_STATICA, "Contents of static control before DlgDirList.", WS_CHILD | WS_VISIBLE, 10, 10, 512, 32, hwnd, (HMENU)ID_TEST_LABEL, NULL, 0); if (!g_label) return FALSE;
- g_listBox = CreateWindowA("ListBox", "DlgDirList test", + g_listBox = CreateWindowA(WC_LISTBOXA, "DlgDirList test", WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_VSCROLL, 10, 60, 256, 256, hwnd, (HMENU)ID_TEST_LISTBOX, NULL, 0); if (!g_listBox) return FALSE;
Hi,
While running your changed tests on Windows, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check? Full results can be found at https://testbot.winehq.org/JobDetails.pl?Key=35771
Your paranoid android.
=== wvistau64 (32 bit listbox) === listbox.c:905: Test failed: SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, *) failed err 18
=== wvistau64 (64 bit listbox) === listbox.c:905: Test failed: SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, *) failed err 18