Audit the buttons code
Dimitrie O. Paun
dpaun at rogers.com
Mon Oct 4 07:56:07 CDT 2004
ChangeLog
Audit and document button code.
Change [GS]etWindowLong{,Ptr}A to [GS]etWindowLong{,Ptr}W.
Change WM_GETDLGCODE as per the MSDN documentation.
Index: dlls/user/button.c
===================================================================
RCS file: /var/cvs/wine/dlls/user/button.c,v
retrieving revision 1.2
diff -u -r1.2 button.c
--- dlls/user/button.c 7 Sep 2004 19:33:11 -0000 1.2
+++ dlls/user/button.c 4 Oct 2004 12:50:38 -0000
@@ -17,6 +17,51 @@
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
+ * - BS_TYPEMASK
+ *
+ * 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
+ * - BN_PAINT
+ * - BN_SETFOCUS
+ * - 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>
@@ -115,22 +160,22 @@
inline static LONG get_button_state( HWND hwnd )
{
- return GetWindowLongA( hwnd, STATE_GWL_OFFSET );
+ return GetWindowLongW( hwnd, STATE_GWL_OFFSET );
}
inline static void set_button_state( HWND hwnd, LONG state )
{
- SetWindowLongA( hwnd, STATE_GWL_OFFSET, state );
+ SetWindowLongW( hwnd, STATE_GWL_OFFSET, state );
}
inline static HFONT get_button_font( HWND hwnd )
{
- return (HFONT)GetWindowLongPtrA( hwnd, HFONT_GWL_OFFSET );
+ return (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
}
inline static void set_button_font( HWND hwnd, HFONT font )
{
- SetWindowLongPtrA( hwnd, HFONT_GWL_OFFSET, (LONG_PTR)font );
+ SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, (LONG_PTR)font );
}
inline static UINT get_button_type( LONG window_style )
@@ -166,7 +211,7 @@
{
RECT rect;
POINT pt;
- LONG style = GetWindowLongA( hWnd, GWL_STYLE );
+ LONG style = GetWindowLongW( hWnd, GWL_STYLE );
UINT btn_type = get_button_type( style );
LONG state;
HANDLE oldHbitmap;
@@ -179,10 +224,13 @@
case WM_GETDLGCODE:
switch(btn_type)
{
- 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_AUTOCHECKBOX: return DLGC_BUTTON | DLGC_WANTCHARS;
+ case BS_AUTORADIOBUTTON: return DLGC_RADIOBUTTON;
+ case BS_CHECKBOX: return DLGC_BUTTON | DLGC_WANTCHARS;
+ case BS_DEFPUSHBUTTON: return DLGC_DEFPUSHBUTTON;
+ case BS_GROUPBOX: return DLGC_STATIC;
+ case BS_PUSHBUTTON: return DLGC_UNDEFPUSHBUTTON;
+ case BS_RADIOBUTTON: return DLGC_RADIOBUTTON;
default: return DLGC_BUTTON;
}
@@ -248,7 +296,7 @@
btn_type == BS_OWNERDRAW)
{
SendMessageW( GetParent(hWnd), WM_COMMAND,
- MAKEWPARAM( GetWindowLongPtrA(hWnd,GWLP_ID), BN_DOUBLECLICKED ),
+ MAKEWPARAM( GetWindowLongPtrW(hWnd,GWLP_ID), BN_DOUBLECLICKED ),
(LPARAM)hWnd);
break;
}
@@ -294,7 +342,7 @@
break;
}
SendMessageW( GetParent(hWnd), WM_COMMAND,
- MAKEWPARAM( GetWindowLongPtrA(hWnd,GWLP_ID), BN_CLICKED ), (LPARAM)hWnd);
+ MAKEWPARAM( GetWindowLongPtrW(hWnd,GWLP_ID), BN_CLICKED ), (LPARAM)hWnd);
}
break;
@@ -380,7 +428,7 @@
if ((wParam & 0x0f) >= MAX_BTN_TYPE) break;
btn_type = wParam & 0x0f;
style = (style & ~0x0f) | btn_type;
- SetWindowLongA( hWnd, GWL_STYLE, style );
+ SetWindowLongW( hWnd, GWL_STYLE, style );
/* Only redraw if lParam flag is set.*/
if (lParam)
@@ -406,12 +454,12 @@
default:
return 0;
}
- oldHbitmap = (HBITMAP)SetWindowLongA( hWnd, HIMAGE_GWL_OFFSET, lParam );
+ oldHbitmap = (HBITMAP)SetWindowLongW( hWnd, HIMAGE_GWL_OFFSET, lParam );
InvalidateRect( hWnd, NULL, FALSE );
return (LRESULT)oldHbitmap;
case BM_GETIMAGE:
- return GetWindowLongPtrA( hWnd, HIMAGE_GWL_OFFSET );
+ return GetWindowLongPtrW( hWnd, HIMAGE_GWL_OFFSET );
case BM_GETCHECK16:
case BM_GETCHECK:
@@ -425,7 +473,7 @@
{
if (wParam) style |= WS_TABSTOP;
else style &= ~WS_TABSTOP;
- SetWindowLongA( hWnd, GWL_STYLE, style );
+ SetWindowLongW( hWnd, GWL_STYLE, style );
}
if ((state & 3) != wParam)
{
@@ -549,7 +597,7 @@
*/
static UINT BUTTON_CalcLabelRect(HWND hwnd, HDC hdc, RECT *rc)
{
- LONG style = GetWindowLongA( hwnd, GWL_STYLE );
+ LONG style = GetWindowLongW( hwnd, GWL_STYLE );
WCHAR *text;
ICONINFO iconInfo;
BITMAP bm;
@@ -572,7 +620,7 @@
break;
case BS_ICON:
- if (!GetIconInfo((HICON)GetWindowLongPtrA( hwnd, HIMAGE_GWL_OFFSET ), &iconInfo))
+ if (!GetIconInfo((HICON)GetWindowLongPtrW( hwnd, HIMAGE_GWL_OFFSET ), &iconInfo))
goto empty_rect;
GetObjectW (iconInfo.hbmColor, sizeof(BITMAP), &bm);
@@ -585,7 +633,7 @@
break;
case BS_BITMAP:
- if (!GetObjectW( (HANDLE)GetWindowLongPtrA( hwnd, HIMAGE_GWL_OFFSET ), sizeof(BITMAP), &bm))
+ if (!GetObjectW( (HANDLE)GetWindowLongPtrW( hwnd, HIMAGE_GWL_OFFSET ), sizeof(BITMAP), &bm))
goto empty_rect;
r.right = r.left + bm.bmWidth;
@@ -664,7 +712,7 @@
HBRUSH hbr = 0;
UINT flags = IsWindowEnabled(hwnd) ? DSS_NORMAL : DSS_DISABLED;
LONG state = get_button_state( hwnd );
- LONG style = GetWindowLongA( hwnd, GWL_STYLE );
+ LONG style = GetWindowLongW( hwnd, GWL_STYLE );
WCHAR *text = NULL;
/* FIXME: To draw disabled label in Win31 look-and-feel, we probably
@@ -690,12 +738,12 @@
case BS_ICON:
flags |= DST_ICON;
- lp = GetWindowLongPtrA( hwnd, HIMAGE_GWL_OFFSET );
+ lp = GetWindowLongPtrW( hwnd, HIMAGE_GWL_OFFSET );
break;
case BS_BITMAP:
flags |= DST_BITMAP;
- lp = GetWindowLongPtrA( hwnd, HIMAGE_GWL_OFFSET );
+ lp = GetWindowLongPtrW( hwnd, HIMAGE_GWL_OFFSET );
break;
default:
@@ -721,7 +769,7 @@
COLORREF oldTxtColor;
HFONT hFont;
LONG state = get_button_state( hwnd );
- LONG style = GetWindowLongA( hwnd, GWL_STYLE );
+ LONG style = GetWindowLongW( hwnd, GWL_STYLE );
BOOL pushedState = (state & BUTTON_HIGHLIGHTED);
HWND parent;
@@ -808,7 +856,7 @@
HRGN hRgn;
HFONT hFont;
LONG state = get_button_state( hwnd );
- LONG style = GetWindowLongA( hwnd, GWL_STYLE );
+ LONG style = GetWindowLongW( hwnd, GWL_STYLE );
HWND parent;
if (style & BS_PUSHLIKE)
@@ -938,7 +986,7 @@
{
if (!sibling) break;
if ((hwnd != sibling) &&
- ((GetWindowLongA( sibling, GWL_STYLE) & 0x0f) == BS_AUTORADIOBUTTON))
+ ((GetWindowLongW( sibling, GWL_STYLE) & 0x0f) == BS_AUTORADIOBUTTON))
SendMessageW( sibling, BM_SETCHECK, BUTTON_UNCHECKED, 0 );
sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
} while (sibling != start);
@@ -956,7 +1004,7 @@
HFONT hFont;
UINT dtFlags;
TEXTMETRICW tm;
- LONG style = GetWindowLongA( hwnd, GWL_STYLE );
+ LONG style = GetWindowLongW( hwnd, GWL_STYLE );
HWND parent;
if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont );
@@ -1037,7 +1085,7 @@
DRAWITEMSTRUCT dis;
HRGN clipRegion;
RECT clipRect;
- LONG_PTR id = GetWindowLongPtrA( hwnd, GWLP_ID );
+ LONG_PTR id = GetWindowLongPtrW( hwnd, GWLP_ID );
HWND parent;
HFONT hFont, hPrevFont = 0;
More information about the wine-patches
mailing list