1 /* File: button.c -- Button type widgets
3 * Copyright (C) 1993 Johannes Ruscheinski
4 * Copyright (C) 1993 David Metcalfe
5 * Copyright (C) 1994 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Oct. 3, 2004, by Dimitrie O. Paun.
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features, or bugs, please note them below.
32 * - BS_NOTIFY: is it complete?
33 * - BS_RIGHTBUTTON: same as BS_LEFTTEXT
36 * - WM_CHAR: Checks a (manual or automatic) check box on '+' or '=', clears it on '-' key.
37 * - WM_SETFOCUS: For (manual or automatic) radio buttons, send the parent window BN_CLICKED
38 * - WM_NCCREATE: Turns any BS_OWNERDRAW button into a BS_PUSHBUTTON button.
49 * - BN_PUSHED/BN_HILITE
50 * + BN_KILLFOCUS: is it OK?
52 * + BN_SETFOCUS: is it OK?
53 * - BN_UNPUSHED/BN_UNHILITE
56 * Structures/Macros/Definitions
59 * - Button_GetIdealSize
60 * - Button_GetImageList
61 * - Button_GetTextMargin
62 * - Button_SetImageList
63 * - Button_SetTextMargin
67 #include <wine/debug.h>
68 WINE_DEFAULT_DEBUG_CHANNEL(button
);
70 /* GetWindowLong offsets for window extra information */
71 #define STATE_GWL_OFFSET 0
72 #define HFONT_GWL_OFFSET (sizeof(LONG))
73 #define HIMAGE_GWL_OFFSET (HFONT_GWL_OFFSET+sizeof(HFONT))
74 #define UISTATE_GWL_OFFSET (HIMAGE_GWL_OFFSET+sizeof(HFONT))
75 #define NB_EXTRA_BYTES (UISTATE_GWL_OFFSET+sizeof(LONG))
77 /* undocumented flags */
78 #define BUTTON_NSTATES 0x0F
79 #define BUTTON_BTNPRESSED 0x40
80 #define BUTTON_UNKNOWN2 0x20
81 #define BUTTON_UNKNOWN3 0x10
83 #define BUTTON_BMCLICK 0x100 // ReactOS Need to up to wine!
86 #define BUTTON_NOTIFY_PARENT(hWnd, code) \
87 do { /* Notify parent which has created this button control */ \
88 TRACE("notification " #code " sent to hwnd=%p\n", GetParent(hWnd)); \
89 SendMessageW(GetParent(hWnd), WM_COMMAND, \
90 MAKEWPARAM(GetWindowLongPtrW((hWnd),GWLP_ID), (code)), \
94 static UINT
BUTTON_CalcLabelRect( HWND hwnd
, HDC hdc
, RECT
*rc
);
95 static void PB_Paint( HWND hwnd
, HDC hDC
, UINT action
);
96 static void CB_Paint( HWND hwnd
, HDC hDC
, UINT action
);
97 static void GB_Paint( HWND hwnd
, HDC hDC
, UINT action
);
98 static void UB_Paint( HWND hwnd
, HDC hDC
, UINT action
);
99 static void OB_Paint( HWND hwnd
, HDC hDC
, UINT action
);
100 static void BUTTON_CheckAutoRadioButton( HWND hwnd
);
102 #define MAX_BTN_TYPE 16
104 static const WORD maxCheckState
[MAX_BTN_TYPE
] =
106 BST_UNCHECKED
, /* BS_PUSHBUTTON */
107 BST_UNCHECKED
, /* BS_DEFPUSHBUTTON */
108 BST_CHECKED
, /* BS_CHECKBOX */
109 BST_CHECKED
, /* BS_AUTOCHECKBOX */
110 BST_CHECKED
, /* BS_RADIOBUTTON */
111 BST_INDETERMINATE
, /* BS_3STATE */
112 BST_INDETERMINATE
, /* BS_AUTO3STATE */
113 BST_UNCHECKED
, /* BS_GROUPBOX */
114 BST_UNCHECKED
, /* BS_USERBUTTON */
115 BST_CHECKED
, /* BS_AUTORADIOBUTTON */
116 BST_UNCHECKED
, /* BS_PUSHBOX */
117 BST_UNCHECKED
/* BS_OWNERDRAW */
120 typedef void (*pfPaint
)( HWND hwnd
, HDC hdc
, UINT action
);
122 static const pfPaint btnPaintFunc
[MAX_BTN_TYPE
] =
124 PB_Paint
, /* BS_PUSHBUTTON */
125 PB_Paint
, /* BS_DEFPUSHBUTTON */
126 CB_Paint
, /* BS_CHECKBOX */
127 CB_Paint
, /* BS_AUTOCHECKBOX */
128 CB_Paint
, /* BS_RADIOBUTTON */
129 CB_Paint
, /* BS_3STATE */
130 CB_Paint
, /* BS_AUTO3STATE */
131 GB_Paint
, /* BS_GROUPBOX */
132 UB_Paint
, /* BS_USERBUTTON */
133 CB_Paint
, /* BS_AUTORADIOBUTTON */
134 NULL
, /* BS_PUSHBOX */
135 OB_Paint
/* BS_OWNERDRAW */
138 /* The original code from user32 was kept in order to make it easier to bring changes from user32 */
140 /*********************************************************************
141 * button class descriptor
143 static const WCHAR buttonW
[] = {'B','u','t','t','o','n',0};
144 const struct builtin_class_descr BUTTON_builtin_class
=
147 CS_DBLCLKS
| CS_VREDRAW
| CS_HREDRAW
| CS_PARENTDC
, /* style */
149 ButtonWndProcA
, /* procA */
150 ButtonWndProcW
, /* procW */
152 WINPROC_BUTTON
, /* proc */
154 NB_EXTRA_BYTES
, /* extra */
155 IDC_ARROW
, /* cursor */
160 static inline LONG
get_button_state( HWND hwnd
)
162 return GetWindowLongPtrW( hwnd
, STATE_GWL_OFFSET
);
165 static inline void set_button_state( HWND hwnd
, LONG state
)
167 SetWindowLongPtrW( hwnd
, STATE_GWL_OFFSET
, state
);
172 static __inline
void set_ui_state( HWND hwnd
, LONG flags
)
174 SetWindowLongPtrW( hwnd
, UISTATE_GWL_OFFSET
, flags
);
177 static __inline LONG
get_ui_state( HWND hwnd
)
179 return GetWindowLongPtrW( hwnd
, UISTATE_GWL_OFFSET
);
182 #endif /* __REACTOS__ */
184 static inline HFONT
get_button_font( HWND hwnd
)
186 return (HFONT
)GetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
);
189 static inline void set_button_font( HWND hwnd
, HFONT font
)
191 SetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
, (LONG_PTR
)font
);
194 static inline UINT
get_button_type( LONG window_style
)
196 return (window_style
& BS_TYPEMASK
);
199 /* paint a button of any type */
200 static inline void paint_button( HWND hwnd
, LONG style
, UINT action
)
202 if (btnPaintFunc
[style
] && IsWindowVisible(hwnd
))
204 HDC hdc
= GetDC( hwnd
);
205 btnPaintFunc
[style
]( hwnd
, hdc
, action
);
206 ReleaseDC( hwnd
, hdc
);
212 #define NtUserAlterWindowStyle SetWindowLongPtrW
214 static inline void _SetButtonData(HWND hwnd
, PBUTTON_DATA data
)
216 SetWindowLongPtrW( hwnd
, 0, (LONG
)data
);
219 HRGN
set_control_clipping( HDC hdc
, const RECT
*rect
)
222 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
224 if (GetClipRgn( hdc
, hrgn
) != 1)
226 DeleteObject( hrgn
);
229 DPtoLP( hdc
, (POINT
*)&rc
, 2 );
230 if (GetLayout( hdc
) & LAYOUT_RTL
) /* compensate for the shifting done by IntersectClipRect */
235 IntersectClipRect( hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
239 BOOL
BUTTON_PaintWithTheme(HTHEME theme
, HWND hwnd
, HDC hParamDC
, LPARAM prfFlag
);
240 WCHAR
*get_button_text( HWND hwnd
);
242 static inline LONG_PTR
get_button_image(HWND hwnd
)
244 return _GetButtonData(hwnd
)->image
;
247 static inline LONG_PTR
set_button_image(HWND hwnd
, LONG_PTR image
)
249 PBUTTON_DATA data
= _GetButtonData(hwnd
);
250 LONG_PTR ret
= data
->image
;
255 static inline LONG
get_button_state( HWND hwnd
)
257 return _GetButtonData(hwnd
)->state
;
260 static inline void set_button_state( HWND hwnd
, LONG state
)
262 _GetButtonData(hwnd
)->state
= state
;
265 static __inline
void set_ui_state( HWND hwnd
, LONG flags
)
267 _GetButtonData(hwnd
)->ui_state
= flags
;
270 static __inline LONG
get_ui_state( HWND hwnd
)
272 return _GetButtonData(hwnd
)->ui_state
;
275 static inline HFONT
get_button_font( HWND hwnd
)
277 return (HFONT
)_GetButtonData(hwnd
)->font
;
280 static inline void set_button_font( HWND hwnd
, HFONT font
)
282 _GetButtonData(hwnd
)->font
= font
;
285 static inline UINT
get_button_type( LONG window_style
)
287 return (window_style
& BS_TYPEMASK
);
290 /* paint a button of any type */
291 static inline void paint_button( HWND hwnd
, LONG style
, UINT action
)
293 HTHEME theme
= GetWindowTheme(hwnd
);
295 HDC hdc
= GetDC( hwnd
);
296 /* GetDC appears to give a dc with a clip rect that includes the whoe parent, not sure if it is correct or not. */
297 GetClientRect(hwnd
, &rc
);
298 IntersectClipRect (hdc
, rc
.left
, rc
. top
, rc
.right
, rc
.bottom
);
299 if (theme
&& BUTTON_PaintWithTheme(theme
, hwnd
, hdc
, 0))
301 ReleaseDC( hwnd
, hdc
);
304 if (btnPaintFunc
[style
] && IsWindowVisible(hwnd
))
306 btnPaintFunc
[style
]( hwnd
, hdc
, action
);
308 ReleaseDC( hwnd
, hdc
);
311 BOOL
BUTTON_GetIdealSize(HTHEME theme
, HWND hwnd
, SIZE
* psize
)
316 HFONT hFont
= 0, hPrevFont
= 0;
317 SIZE TextSize
, ImageSize
, ButtonSize
;
319 pdata
= _GetButtonData(hwnd
);
320 text
= get_button_text( hwnd
);
322 if (!pdata
|| !text
|| !hdc
|| !text
[0])
329 /* FIXME : Should use GetThemeTextExtent but unfortunately uses DrawTextW which is broken */
333 HRESULT hr
= GetThemeFont(theme
, hdc
, BP_PUSHBUTTON
, PBS_NORMAL
, TMT_FONT
, &logfont
);
336 hFont
= CreateFontIndirectW(&logfont
);
338 hPrevFont
= SelectObject( hdc
, hFont
);
344 hPrevFont
= SelectObject( hdc
, pdata
->font
);
347 GetTextExtentPoint32W(hdc
, text
, wcslen(text
), &TextSize
);
350 SelectObject( hdc
, hPrevFont
);
352 TextSize
.cy
+= pdata
->rcTextMargin
.top
+ pdata
->rcTextMargin
.bottom
;
353 TextSize
.cx
+= pdata
->rcTextMargin
.left
+ pdata
->rcTextMargin
.right
;
355 if (pdata
->imlData
.himl
&& ImageList_GetIconSize(pdata
->imlData
.himl
, &ImageSize
.cx
, &ImageSize
.cy
))
357 ImageSize
.cx
+= pdata
->imlData
.margin
.left
+ pdata
->imlData
.margin
.right
;
358 ImageSize
.cy
+= pdata
->imlData
.margin
.top
+ pdata
->imlData
.margin
.bottom
;
362 ImageSize
.cx
= ImageSize
.cy
= 0;
367 RECT rcContents
= {0};
368 RECT rcButtonExtent
= {0};
369 rcContents
.right
= ImageSize
.cx
+ TextSize
.cx
;
370 rcContents
.bottom
= max(ImageSize
.cy
, TextSize
.cy
);
371 GetThemeBackgroundExtent(theme
, hdc
, BP_PUSHBUTTON
, PBS_NORMAL
, &rcContents
, &rcButtonExtent
);
372 ERR("rcContents: %d, %d, %d, %d\n", rcContents
.left
, rcContents
.top
, rcContents
.right
, rcContents
.bottom
);
373 ERR("rcButtonExtent: %d, %d, %d, %d\n", rcButtonExtent
.left
, rcButtonExtent
.top
, rcButtonExtent
.right
, rcButtonExtent
.bottom
);
374 ButtonSize
.cx
= abs(rcButtonExtent
.right
- rcButtonExtent
.left
) + 1;
375 ButtonSize
.cy
= abs(rcButtonExtent
.bottom
- rcButtonExtent
.top
) - 1;
379 ButtonSize
.cx
= ImageSize
.cx
+ TextSize
.cx
+ 5;
380 ButtonSize
.cy
= max(ImageSize
.cy
, TextSize
.cy
+ 7);
389 HeapFree( GetProcessHeap(), 0, text
);
391 ReleaseDC(hwnd
, hdc
);
399 /* retrieve the button text; returned buffer must be freed by caller */
400 inline WCHAR
*get_button_text( HWND hwnd
)
403 WCHAR
*buffer
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) );
404 if (buffer
) InternalGetWindowText( hwnd
, buffer
, len
+ 1 );
409 /* Retrieve the UI state for the control */
410 static BOOL
button_update_uistate(HWND hwnd
, BOOL unicode
)
412 LONG flags
, prevflags
;
415 flags
= DefWindowProcW(hwnd
, WM_QUERYUISTATE
, 0, 0);
417 flags
= DefWindowProcA(hwnd
, WM_QUERYUISTATE
, 0, 0);
419 prevflags
= get_ui_state(hwnd
);
421 if (prevflags
!= flags
)
423 set_ui_state(hwnd
, flags
);
431 /***********************************************************************
432 * ButtonWndProc_common
434 LRESULT WINAPI
ButtonWndProc_common(HWND hWnd
, UINT uMsg
,
435 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
439 LONG style
= GetWindowLongPtrW( hWnd
, GWL_STYLE
);
440 UINT btn_type
= get_button_type( style
);
443 #if defined(__REACTOS__) && defined(_USER32_)
446 pWnd
= ValidateHwnd(hWnd
);
451 NtUserSetWindowFNID(hWnd
, FNID_BUTTON
);
455 if (pWnd
->fnid
!= FNID_BUTTON
)
457 ERR("Wrong window class for Button! fnId 0x%x\n",pWnd
->fnid
);
465 if (!IsWindow( hWnd
)) return 0;
468 pt
.x
= (short)LOWORD(lParam
);
469 pt
.y
= (short)HIWORD(lParam
);
476 PBUTTON_DATA data
= HeapAlloc( GetProcessHeap(), 0, sizeof(BUTTON_DATA
) );
479 ERR("Failed to alloc internal button data\n");
483 memset(data
, 0, sizeof(BUTTON_DATA
));
484 SetRect(&data
->rcTextMargin
, 1,1,1,1);
486 _SetButtonData(hWnd
, data
);
491 PBUTTON_DATA data
= _GetButtonData(hWnd
);
497 HeapFree( GetProcessHeap(), 0, data
);
498 _SetButtonData(hWnd
, NULL
);
501 OpenThemeData(hWnd
, WC_BUTTONW
);
504 CloseThemeData (GetWindowTheme(hWnd
));
506 case WM_THEMECHANGED
:
507 CloseThemeData (GetWindowTheme(hWnd
));
508 OpenThemeData(hWnd
, WC_BUTTONW
);
509 InvalidateRect(hWnd
, NULL
, FALSE
);
513 int state
= (int)SendMessageW(hWnd
, BM_GETSTATE
, 0, 0);
514 set_button_state(hWnd
, state
|BST_HOT
);
515 InvalidateRect(hWnd
, NULL
, FALSE
);
520 int state
= (int)SendMessageW(hWnd
, BM_GETSTATE
, 0, 0);
521 set_button_state(hWnd
, state
&(~BST_HOT
));
522 InvalidateRect(hWnd
, NULL
, FALSE
);
527 TRACKMOUSEEVENT mouse_event
;
528 mouse_event
.cbSize
= sizeof(TRACKMOUSEEVENT
);
529 mouse_event
.dwFlags
= TME_QUERY
;
530 if(!TrackMouseEvent(&mouse_event
) || !(mouse_event
.dwFlags
&(TME_HOVER
|TME_LEAVE
)))
532 mouse_event
.dwFlags
= TME_HOVER
|TME_LEAVE
;
533 mouse_event
.hwndTrack
= hWnd
;
534 mouse_event
.dwHoverTime
= 1;
535 TrackMouseEvent(&mouse_event
);
539 case BCM_GETTEXTMARGIN
:
541 RECT
* prc
= (RECT
*)lParam
;
542 PBUTTON_DATA data
= _GetButtonData(hWnd
);
545 *prc
= data
->rcTextMargin
;
548 case BCM_SETTEXTMARGIN
:
550 RECT
* prc
= (RECT
*)lParam
;
551 PBUTTON_DATA data
= _GetButtonData(hWnd
);
554 data
->rcTextMargin
= *prc
;
557 case BCM_SETIMAGELIST
:
559 BUTTON_IMAGELIST
* pimldata
= (BUTTON_IMAGELIST
*)lParam
;
560 PBUTTON_DATA data
= _GetButtonData(hWnd
);
561 if (!data
|| !pimldata
|| !pimldata
->himl
)
563 data
->imlData
= *pimldata
;
566 case BCM_GETIMAGELIST
:
568 BUTTON_IMAGELIST
* pimldata
= (BUTTON_IMAGELIST
*)lParam
;
569 PBUTTON_DATA data
= _GetButtonData(hWnd
);
570 if (!data
|| !pimldata
)
572 *pimldata
= data
->imlData
;
575 case BCM_GETIDEALSIZE
:
577 HTHEME theme
= GetWindowTheme(hWnd
);
579 if (btn_type
!= BS_PUSHBUTTON
&& btn_type
!= BS_DEFPUSHBUTTON
)
581 SIZE
* pSize
= (SIZE
*)lParam
;
582 GetClientRect(hWnd
, &rect
);
583 pSize
->cx
= rect
.right
;
584 pSize
->cy
= rect
.bottom
;
588 return BUTTON_GetIdealSize(theme
, hWnd
, (SIZE
*)lParam
);
592 if (!_GetButtonData(hWnd
))
595 return unicode
? DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
) :
596 DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
607 case BS_PUSHBUTTON
: return DLGC_BUTTON
| DLGC_UNDEFPUSHBUTTON
;
608 case BS_DEFPUSHBUTTON
: return DLGC_BUTTON
| DLGC_DEFPUSHBUTTON
;
610 case BS_AUTORADIOBUTTON
: return DLGC_BUTTON
| DLGC_RADIOBUTTON
;
611 case BS_GROUPBOX
: return DLGC_STATIC
;
612 default: return DLGC_BUTTON
;
616 paint_button( hWnd
, btn_type
, ODA_DRAWENTIRE
);
620 if (btn_type
>= MAX_BTN_TYPE
)
621 return -1; /* abort */
623 /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
624 if (btn_type
== BS_USERBUTTON
)
626 style
= (style
& ~BS_TYPEMASK
) | BS_PUSHBUTTON
;
628 NtUserAlterWindowStyle(hWnd
, GWL_STYLE
, style
);
630 WIN_SetStyle( hWnd
, style
, BS_TYPEMASK
& ~style
);
633 set_button_state( hWnd
, BST_UNCHECKED
);
635 button_update_uistate( hWnd
, unicode
);
639 #if defined(__REACTOS__) && defined(_USER32_)
641 NtUserSetWindowFNID(hWnd
, FNID_DESTROY
);
646 if (btn_type
== BS_OWNERDRAW
)
648 HDC hdc
= (HDC
)wParam
;
651 HWND parent
= GetParent(hWnd
);
652 if (!parent
) parent
= hWnd
;
653 #if defined(__REACTOS__) && defined(_USER32_)
654 hBrush
= GetControlColor( parent
, hWnd
, hdc
, WM_CTLCOLORBTN
);
656 hBrush
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORBTN
, (WPARAM
)hdc
, (LPARAM
)hWnd
);
657 if (!hBrush
) /* did the app forget to call defwindowproc ? */
658 hBrush
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORBTN
,
659 (WPARAM
)hdc
, (LPARAM
)hWnd
);
661 GetClientRect(hWnd
, &rc
);
662 FillRect(hdc
, &rc
, hBrush
);
670 HDC hdc
= wParam
? (HDC
)wParam
: BeginPaint( hWnd
, &ps
);
672 HTHEME theme
= GetWindowTheme(hWnd
);
673 if (theme
&& BUTTON_PaintWithTheme(theme
, hWnd
, hdc
, uMsg
== WM_PRINTCLIENT
? lParam
: 0))
675 if ( !wParam
) EndPaint( hWnd
, &ps
);
679 if (btnPaintFunc
[btn_type
])
681 int nOldMode
= SetBkMode( hdc
, OPAQUE
);
682 (btnPaintFunc
[btn_type
])( hWnd
, hdc
, ODA_DRAWENTIRE
);
683 SetBkMode(hdc
, nOldMode
); /* reset painting mode */
685 if ( !wParam
) EndPaint( hWnd
, &ps
);
690 if (wParam
== VK_SPACE
)
692 SendMessageW( hWnd
, BM_SETSTATE
, TRUE
, 0 );
693 set_button_state( hWnd
, get_button_state( hWnd
) | BUTTON_BTNPRESSED
);
698 case WM_LBUTTONDBLCLK
:
699 if(style
& BS_NOTIFY
||
700 btn_type
== BS_RADIOBUTTON
||
701 btn_type
== BS_USERBUTTON
||
702 btn_type
== BS_OWNERDRAW
)
704 BUTTON_NOTIFY_PARENT(hWnd
, BN_DOUBLECLICKED
);
711 set_button_state( hWnd
, get_button_state( hWnd
) | BUTTON_BTNPRESSED
);
712 SendMessageW( hWnd
, BM_SETSTATE
, TRUE
, 0 );
716 if (wParam
!= VK_SPACE
)
721 BOOL TellParent
= FALSE
; //// ReactOS see note below.
723 state
= get_button_state( hWnd
);
724 if (!(state
& BUTTON_BTNPRESSED
)) break;
725 state
&= BUTTON_NSTATES
;
726 set_button_state( hWnd
, state
);
727 if (!(state
& BST_PUSHED
))
732 SendMessageW( hWnd
, BM_SETSTATE
, FALSE
, 0 );
733 GetClientRect( hWnd
, &rect
);
734 if (uMsg
== WM_KEYUP
|| PtInRect( &rect
, pt
))
736 state
= get_button_state( hWnd
);
739 case BS_AUTOCHECKBOX
:
740 SendMessageW( hWnd
, BM_SETCHECK
, !(state
& BST_CHECKED
), 0 );
742 case BS_AUTORADIOBUTTON
:
743 SendMessageW( hWnd
, BM_SETCHECK
, TRUE
, 0 );
746 SendMessageW( hWnd
, BM_SETCHECK
,
747 (state
& BST_INDETERMINATE
) ? 0 : ((state
& 3) + 1), 0 );
751 TellParent
= TRUE
; // <---- Fix CORE-10194, Notify parent after capture is released.
754 BUTTON_NOTIFY_PARENT(hWnd
, BN_CLICKED
);
759 if (TellParent
) BUTTON_NOTIFY_PARENT(hWnd
, BN_CLICKED
);
768 case WM_CAPTURECHANGED
:
769 TRACE("WM_CAPTURECHANGED %p\n", hWnd
);
770 if (hWnd
== (HWND
)lParam
) break;
771 state
= get_button_state( hWnd
);
772 if (state
& BUTTON_BTNPRESSED
)
774 state
&= BUTTON_NSTATES
;
775 set_button_state( hWnd
, state
);
776 if (state
& BST_PUSHED
) SendMessageW( hWnd
, BM_SETSTATE
, FALSE
, 0 );
781 if ((wParam
& MK_LBUTTON
) && GetCapture() == hWnd
)
783 GetClientRect( hWnd
, &rect
);
784 SendMessageW( hWnd
, BM_SETSTATE
, PtInRect(&rect
, pt
), 0 );
790 /* Clear an old text here as Windows does */
793 // wine Bug: http://bugs.winehq.org/show_bug.cgi?id=25790
794 // Patch: http://source.winehq.org/patches/data/70889
795 // By: Alexander LAW, Replicate Windows behavior of WM_SETTEXT handler regarding WM_CTLCOLOR*
798 if (style
& WS_VISIBLE
)
800 if (IsWindowVisible(hWnd
))
803 HDC hdc
= GetDC(hWnd
);
806 HWND parent
= GetParent(hWnd
);
807 UINT message
= (btn_type
== BS_PUSHBUTTON
||
808 btn_type
== BS_DEFPUSHBUTTON
||
809 btn_type
== BS_PUSHLIKE
||
810 btn_type
== BS_USERBUTTON
||
811 btn_type
== BS_OWNERDRAW
) ?
812 WM_CTLCOLORBTN
: WM_CTLCOLORSTATIC
;
814 if (!parent
) parent
= hWnd
;
815 #if defined(__REACTOS__) && defined(_USER32_)
816 hbrush
= GetControlColor(parent
, hWnd
, hdc
, message
);
818 hbrush
= (HBRUSH
)SendMessageW(parent
, message
,
819 (WPARAM
)hdc
, (LPARAM
)hWnd
);
820 if (!hbrush
) /* did the app forget to call DefWindowProc ? */
821 hbrush
= (HBRUSH
)DefWindowProcW(parent
, message
,
822 (WPARAM
)hdc
, (LPARAM
)hWnd
);
825 GetClientRect(hWnd
, &client
);
827 /* FIXME: check other BS_* handlers */
828 if (btn_type
== BS_GROUPBOX
)
829 InflateRect(&rc
, -7, 1); /* GB_Paint does this */
830 BUTTON_CalcLabelRect(hWnd
, hdc
, &rc
);
831 /* Clip by client rect bounds */
832 if (rc
.right
> client
.right
) rc
.right
= client
.right
;
833 if (rc
.bottom
> client
.bottom
) rc
.bottom
= client
.bottom
;
834 FillRect(hdc
, &rc
, hbrush
);
835 ReleaseDC(hWnd
, hdc
);
838 if (unicode
) DefWindowProcW( hWnd
, WM_SETTEXT
, wParam
, lParam
);
839 else DefWindowProcA( hWnd
, WM_SETTEXT
, wParam
, lParam
);
840 if (btn_type
== BS_GROUPBOX
) /* Yes, only for BS_GROUPBOX */
841 InvalidateRect( hWnd
, NULL
, TRUE
);
843 paint_button( hWnd
, btn_type
, ODA_DRAWENTIRE
);
844 return 1; /* success. FIXME: check text length */
848 set_button_font( hWnd
, (HFONT
)wParam
);
849 if (lParam
) InvalidateRect(hWnd
, NULL
, TRUE
);
853 return (LRESULT
)get_button_font( hWnd
);
856 TRACE("WM_SETFOCUS %p\n",hWnd
);
857 set_button_state( hWnd
, get_button_state(hWnd
) | BST_FOCUS
);
859 if (btn_type
!= BS_OWNERDRAW
)
860 InvalidateRect(hWnd
, NULL
, FALSE
);
863 paint_button( hWnd
, btn_type
, ODA_FOCUS
);
864 if (style
& BS_NOTIFY
)
865 BUTTON_NOTIFY_PARENT(hWnd
, BN_SETFOCUS
);
869 TRACE("WM_KILLFOCUS %p\n",hWnd
);
870 state
= get_button_state( hWnd
);
871 set_button_state( hWnd
, state
& ~BST_FOCUS
);
873 paint_button( hWnd
, btn_type
, ODA_FOCUS
);
876 if ((state
& BUTTON_BTNPRESSED
) && GetCapture() == hWnd
)
878 if (style
& BS_NOTIFY
)
879 BUTTON_NOTIFY_PARENT(hWnd
, BN_KILLFOCUS
);
881 InvalidateRect( hWnd
, NULL
, FALSE
);
884 case WM_SYSCOLORCHANGE
:
885 InvalidateRect( hWnd
, NULL
, FALSE
);
889 btn_type
= wParam
& BS_TYPEMASK
;
890 style
= (style
& ~BS_TYPEMASK
) | btn_type
;
892 NtUserAlterWindowStyle(hWnd
, GWL_STYLE
, style
);
894 WIN_SetStyle( hWnd
, style
, BS_TYPEMASK
& ~style
);
897 /* Only redraw if lParam flag is set.*/
899 InvalidateRect( hWnd
, NULL
, TRUE
);
905 state
= get_button_state(hWnd
);
906 if (state
& BUTTON_BMCLICK
)
908 set_button_state(hWnd
, state
| BUTTON_BMCLICK
); // Tracked in STATE_GWL_OFFSET.
910 SendMessageW( hWnd
, WM_LBUTTONDOWN
, 0, 0 );
911 SendMessageW( hWnd
, WM_LBUTTONUP
, 0, 0 );
913 state
= get_button_state(hWnd
);
914 if (!(state
& BUTTON_BMCLICK
)) break;
915 state
&= ~BUTTON_BMCLICK
;
916 set_button_state(hWnd
, state
);
921 /* Check that image format matches button style */
922 switch (style
& (BS_BITMAP
|BS_ICON
))
925 if (wParam
!= IMAGE_BITMAP
) return 0;
928 if (wParam
!= IMAGE_ICON
) return 0;
934 oldHbitmap
= (HBITMAP
)SetWindowLongPtrW( hWnd
, HIMAGE_GWL_OFFSET
, lParam
);
936 oldHbitmap
= (HBITMAP
)set_button_image(hWnd
, lParam
);
938 InvalidateRect( hWnd
, NULL
, FALSE
);
939 return (LRESULT
)oldHbitmap
;
943 return GetWindowLongPtrW( hWnd
, HIMAGE_GWL_OFFSET
);
945 return get_button_image(hWnd
);
949 return get_button_state( hWnd
) & 3;
952 if (wParam
> maxCheckState
[btn_type
]) wParam
= maxCheckState
[btn_type
];
953 state
= get_button_state( hWnd
);
954 if ((btn_type
== BS_RADIOBUTTON
) || (btn_type
== BS_AUTORADIOBUTTON
))
957 if (wParam
) style
|= WS_TABSTOP
;
958 else style
&= ~WS_TABSTOP
;
959 NtUserAlterWindowStyle(hWnd
, GWL_STYLE
, style
);
961 if (wParam
) WIN_SetStyle( hWnd
, WS_TABSTOP
, 0 );
962 else WIN_SetStyle( hWnd
, 0, WS_TABSTOP
);
965 if ((state
& 3) != wParam
)
967 set_button_state( hWnd
, (state
& ~3) | wParam
);
969 paint_button( hWnd
, btn_type
, ODA_SELECT
);
971 InvalidateRect(hWnd
, NULL
, FALSE
);
974 if ((btn_type
== BS_AUTORADIOBUTTON
) && (wParam
== BST_CHECKED
) && (style
& WS_CHILD
))
975 BUTTON_CheckAutoRadioButton( hWnd
);
979 return get_button_state( hWnd
);
982 state
= get_button_state( hWnd
);
984 set_button_state( hWnd
, state
| BST_PUSHED
);
986 set_button_state( hWnd
, state
& ~BST_PUSHED
);
989 paint_button( hWnd
, btn_type
, ODA_SELECT
);
991 InvalidateRect(hWnd
, NULL
, FALSE
);
996 case WM_UPDATEUISTATE
:
998 DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
1000 DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
1002 if (button_update_uistate(hWnd
, unicode
))
1003 paint_button( hWnd
, btn_type
, ODA_DRAWENTIRE
);
1008 if(btn_type
== BS_GROUPBOX
) return HTTRANSPARENT
;
1011 return unicode
? DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
) :
1012 DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
1019 /***********************************************************************
1021 * The button window procedure. This is just a wrapper which locks
1022 * the passed HWND and calls the real window procedure (with a WND*
1023 * pointer pointing to the locked windowstructure).
1025 LRESULT WINAPI
ButtonWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1027 if (!IsWindow(hWnd
)) return 0;
1028 return ButtonWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
1031 /***********************************************************************
1034 LRESULT WINAPI
ButtonWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1036 if (!IsWindow(hWnd
)) return 0;
1037 return ButtonWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
1040 #endif /* __REACTOS__ */
1042 /**********************************************************************
1043 * Convert button styles to flags used by DrawText.
1045 static UINT
BUTTON_BStoDT( DWORD style
, DWORD ex_style
)
1047 UINT dtStyle
= DT_NOCLIP
; /* We use SelectClipRgn to limit output */
1049 /* "Convert" pushlike buttons to pushbuttons */
1050 if (style
& BS_PUSHLIKE
)
1051 style
&= ~BS_TYPEMASK
;
1053 if (!(style
& BS_MULTILINE
))
1054 dtStyle
|= DT_SINGLELINE
;
1056 dtStyle
|= DT_WORDBREAK
;
1058 switch (style
& BS_CENTER
)
1060 case BS_LEFT
: /* DT_LEFT is 0 */ break;
1061 case BS_RIGHT
: dtStyle
|= DT_RIGHT
; break;
1062 case BS_CENTER
: dtStyle
|= DT_CENTER
; break;
1064 /* Pushbutton's text is centered by default */
1065 if (get_button_type(style
) <= BS_DEFPUSHBUTTON
) dtStyle
|= DT_CENTER
;
1066 /* all other flavours have left aligned text */
1069 if (ex_style
& WS_EX_RIGHT
) dtStyle
= DT_RIGHT
| (dtStyle
& ~(DT_LEFT
| DT_CENTER
));
1071 /* DrawText ignores vertical alignment for multiline text,
1072 * but we use these flags to align label manually.
1074 if (get_button_type(style
) != BS_GROUPBOX
)
1076 switch (style
& BS_VCENTER
)
1078 case BS_TOP
: /* DT_TOP is 0 */ break;
1079 case BS_BOTTOM
: dtStyle
|= DT_BOTTOM
; break;
1080 case BS_VCENTER
: /* fall through */
1081 default: dtStyle
|= DT_VCENTER
; break;
1085 /* GroupBox's text is always single line and is top aligned. */
1086 dtStyle
|= DT_SINGLELINE
;
1091 /**********************************************************************
1092 * BUTTON_CalcLabelRect
1094 * Calculates label's rectangle depending on button style.
1096 * Returns flags to be passed to DrawText.
1097 * Calculated rectangle doesn't take into account button state
1098 * (pushed, etc.). If there is nothing to draw (no text/image) output
1099 * rectangle is empty, and return value is (UINT)-1.
1101 static UINT
BUTTON_CalcLabelRect(HWND hwnd
, HDC hdc
, RECT
*rc
)
1103 LONG style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
1104 LONG ex_style
= GetWindowLongPtrW( hwnd
, GWL_EXSTYLE
);
1108 UINT dtStyle
= BUTTON_BStoDT( style
, ex_style
);
1112 /* Calculate label rectangle according to label type */
1113 switch (style
& (BS_ICON
|BS_BITMAP
))
1117 HFONT hFont
, hPrevFont
= 0;
1119 if (!(text
= get_button_text( hwnd
))) goto empty_rect
;
1122 HeapFree( GetProcessHeap(), 0, text
);
1126 if ((hFont
= get_button_font( hwnd
))) hPrevFont
= SelectObject( hdc
, hFont
);
1127 DrawTextW(hdc
, text
, -1, &r
, dtStyle
| DT_CALCRECT
);
1128 if (hPrevFont
) SelectObject( hdc
, hPrevFont
);
1129 HeapFree( GetProcessHeap(), 0, text
);
1131 if (get_ui_state(hwnd
) & UISF_HIDEACCEL
)
1132 dtStyle
|= DT_HIDEPREFIX
;
1139 if (!GetIconInfo((HICON
)GetWindowLongPtrW( hwnd
, HIMAGE_GWL_OFFSET
), &iconInfo
))
1141 if (!GetIconInfo((HICON
)get_button_image(hwnd
), &iconInfo
))
1145 GetObjectW (iconInfo
.hbmColor
, sizeof(BITMAP
), &bm
);
1147 r
.right
= r
.left
+ bm
.bmWidth
;
1148 r
.bottom
= r
.top
+ bm
.bmHeight
;
1150 DeleteObject(iconInfo
.hbmColor
);
1151 DeleteObject(iconInfo
.hbmMask
);
1156 if (!GetObjectW( (HANDLE
)GetWindowLongPtrW( hwnd
, HIMAGE_GWL_OFFSET
), sizeof(BITMAP
), &bm
))
1158 if (!GetObjectW( (HANDLE
)get_button_image(hwnd
), sizeof(BITMAP
), &bm
))
1162 r
.right
= r
.left
+ bm
.bmWidth
;
1163 r
.bottom
= r
.top
+ bm
.bmHeight
;
1173 /* Position label inside bounding rectangle according to
1174 * alignment flags. (calculated rect is always left-top aligned).
1175 * If label is aligned to any side - shift label in opposite
1176 * direction to leave extra space for focus rectangle.
1178 switch (dtStyle
& (DT_CENTER
|DT_RIGHT
))
1180 case DT_LEFT
: r
.left
++; r
.right
++; break;
1181 case DT_CENTER
: n
= r
.right
- r
.left
;
1182 r
.left
= rc
->left
+ ((rc
->right
- rc
->left
) - n
) / 2;
1183 r
.right
= r
.left
+ n
; break;
1184 case DT_RIGHT
: n
= r
.right
- r
.left
;
1185 r
.right
= rc
->right
- 1;
1186 r
.left
= r
.right
- n
;
1190 switch (dtStyle
& (DT_VCENTER
|DT_BOTTOM
))
1192 case DT_TOP
: r
.top
++; r
.bottom
++; break;
1193 case DT_VCENTER
: n
= r
.bottom
- r
.top
;
1194 r
.top
= rc
->top
+ ((rc
->bottom
- rc
->top
) - n
) / 2;
1195 r
.bottom
= r
.top
+ n
; break;
1196 case DT_BOTTOM
: n
= r
.bottom
- r
.top
;
1197 r
.bottom
= rc
->bottom
- 1;
1198 r
.top
= r
.bottom
- n
;
1207 /**********************************************************************
1208 * BUTTON_DrawTextCallback
1210 * Callback function used by DrawStateW function.
1212 static BOOL CALLBACK
BUTTON_DrawTextCallback(HDC hdc
, LPARAM lp
, WPARAM wp
, int cx
, int cy
)
1217 SetRect(&rc
, 0, 0, cx
, cy
);
1218 DrawTextW(hdc
, (LPCWSTR
)lp
, -1, &rc
, (UINT
)wp
);
1221 HWND hwnd
= (HWND
)lp
;
1223 PBUTTON_DATA pdata
= _GetButtonData(hwnd
);
1227 if (!(text
= get_button_text( hwnd
))) return TRUE
;
1229 SetRect(&rc
, 0, 0, cx
, cy
);
1231 if (pdata
->imlData
.himl
&& ImageList_GetIconSize(pdata
->imlData
.himl
, &ImageSize
.cx
, &ImageSize
.cy
))
1233 int left
= pdata
->imlData
.margin
.left
;
1234 int top
= (cy
- ImageSize
.cy
) / 2;
1235 rc
.left
+= pdata
->imlData
.margin
.left
+ pdata
->imlData
.margin
.right
+ ImageSize
.cy
;
1236 ImageList_Draw(pdata
->imlData
.himl
, 0, hdc
, left
, top
, 0);
1239 DrawTextW(hdc
, text
, -1, &rc
, (UINT
)wp
);
1245 /**********************************************************************
1248 * Common function for drawing button label.
1250 static void BUTTON_DrawLabel(HWND hwnd
, HDC hdc
, UINT dtFlags
, const RECT
*rc
)
1252 DRAWSTATEPROC lpOutputProc
= NULL
;
1256 UINT flags
= IsWindowEnabled(hwnd
) ? DSS_NORMAL
: DSS_DISABLED
;
1257 LONG state
= get_button_state( hwnd
);
1258 LONG style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
1261 /* FIXME: To draw disabled label in Win31 look-and-feel, we probably
1262 * must use DSS_MONO flag and COLOR_GRAYTEXT brush (or maybe DSS_UNION).
1263 * I don't have Win31 on hand to verify that, so I leave it as is.
1266 if ((style
& BS_PUSHLIKE
) && (state
& BST_INDETERMINATE
))
1268 hbr
= GetSysColorBrush(COLOR_GRAYTEXT
);
1272 switch (style
& (BS_ICON
|BS_BITMAP
))
1275 /* DST_COMPLEX -- is 0 */
1276 lpOutputProc
= BUTTON_DrawTextCallback
;
1278 if (!(text
= get_button_text( hwnd
))) return;
1284 wp
= (WPARAM
)dtFlags
;
1287 if (dtFlags
& DT_HIDEPREFIX
)
1288 flags
|= DSS_HIDEPREFIX
;
1295 lp
= GetWindowLongPtrW( hwnd
, HIMAGE_GWL_OFFSET
);
1297 lp
= get_button_image(hwnd
);
1302 flags
|= DST_BITMAP
;
1304 lp
= GetWindowLongPtrW( hwnd
, HIMAGE_GWL_OFFSET
);
1306 lp
= get_button_image(hwnd
);
1314 DrawStateW(hdc
, hbr
, lpOutputProc
, lp
, wp
, rc
->left
, rc
->top
,
1315 rc
->right
- rc
->left
, rc
->bottom
- rc
->top
, flags
);
1316 HeapFree( GetProcessHeap(), 0, text
);
1319 /**********************************************************************
1320 * Push Button Functions
1322 static void PB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1325 UINT dtFlags
, uState
;
1329 COLORREF oldTxtColor
;
1331 LONG state
= get_button_state( hwnd
);
1332 LONG style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
1333 BOOL pushedState
= (state
& BST_PUSHED
);
1337 GetClientRect( hwnd
, &rc
);
1339 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
1340 if ((hFont
= get_button_font( hwnd
))) SelectObject( hDC
, hFont
);
1341 parent
= GetParent(hwnd
);
1342 if (!parent
) parent
= hwnd
;
1343 #if defined(__REACTOS__) && defined(_USER32_)
1344 GetControlColor( parent
, hwnd
, hDC
, WM_CTLCOLORBTN
);
1346 SendMessageW( parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)hwnd
);
1349 hrgn
= set_control_clipping( hDC
, &rc
);
1351 hOldPen
= SelectObject(hDC
, GetStockObject(DC_PEN
));
1352 SetDCPenColor(hDC
, GetSysColor(COLOR_WINDOWFRAME
));
1354 hOldPen
= SelectObject(hDC
, SYSCOLOR_GetPen(COLOR_WINDOWFRAME
));
1356 hOldBrush
= SelectObject(hDC
,GetSysColorBrush(COLOR_BTNFACE
));
1357 oldBkMode
= SetBkMode(hDC
, TRANSPARENT
);
1359 if (get_button_type(style
) == BS_DEFPUSHBUTTON
)
1361 if (action
!= ODA_FOCUS
)
1362 Rectangle(hDC
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1363 InflateRect( &rc
, -1, -1 );
1366 /* completely skip the drawing if only focus has changed */
1367 if (action
== ODA_FOCUS
) goto draw_focus
;
1369 uState
= DFCS_BUTTONPUSH
;
1371 if (style
& BS_FLAT
)
1372 uState
|= DFCS_MONO
;
1373 else if (pushedState
)
1375 if (get_button_type(style
) == BS_DEFPUSHBUTTON
)
1376 uState
|= DFCS_FLAT
;
1378 uState
|= DFCS_PUSHED
;
1381 if (state
& (BST_CHECKED
| BST_INDETERMINATE
))
1382 uState
|= DFCS_CHECKED
;
1384 DrawFrameControl( hDC
, &rc
, DFC_BUTTON
, uState
);
1386 /* draw button label */
1388 dtFlags
= BUTTON_CalcLabelRect(hwnd
, hDC
, &r
);
1390 if (dtFlags
== (UINT
)-1L)
1394 OffsetRect(&r
, 1, 1);
1396 oldTxtColor
= SetTextColor( hDC
, GetSysColor(COLOR_BTNTEXT
) );
1398 BUTTON_DrawLabel(hwnd
, hDC
, dtFlags
, &r
);
1400 SetTextColor( hDC
, oldTxtColor
);
1403 if (action
== ODA_FOCUS
|| (state
& BST_FOCUS
))
1406 if (!(get_ui_state(hwnd
) & UISF_HIDEFOCUS
))
1409 InflateRect( &rc
, -2, -2 );
1410 DrawFocusRect( hDC
, &rc
);
1417 SelectObject( hDC
, hOldPen
);
1418 SelectObject( hDC
, hOldBrush
);
1419 SetBkMode(hDC
, oldBkMode
);
1420 SelectClipRgn( hDC
, hrgn
);
1421 if (hrgn
) DeleteObject( hrgn
);
1424 /**********************************************************************
1425 * Check Box & Radio Button Functions
1428 static void CB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1430 RECT rbox
, rtext
, client
;
1432 int delta
, text_offset
, checkBoxWidth
, checkBoxHeight
;
1435 LONG state
= get_button_state( hwnd
);
1436 LONG style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
1437 LONG ex_style
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
1441 if (style
& BS_PUSHLIKE
)
1443 PB_Paint( hwnd
, hDC
, action
);
1447 GetClientRect(hwnd
, &client
);
1448 rbox
= rtext
= client
;
1450 checkBoxWidth
= 12 * GetDeviceCaps( hDC
, LOGPIXELSX
) / 96 + 1;
1451 checkBoxHeight
= 12 * GetDeviceCaps( hDC
, LOGPIXELSY
) / 96 + 1;
1453 if ((hFont
= get_button_font( hwnd
))) SelectObject( hDC
, hFont
);
1454 GetCharWidthW( hDC
, '0', '0', &text_offset
);
1457 parent
= GetParent(hwnd
);
1458 if (!parent
) parent
= hwnd
;
1459 #if defined(__REACTOS__) && defined(_USER32_)
1460 hBrush
= GetControlColor(parent
, hwnd
, hDC
, WM_CTLCOLORSTATIC
);
1462 hBrush
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORSTATIC
,
1463 (WPARAM
)hDC
, (LPARAM
)hwnd
);
1464 if (!hBrush
) /* did the app forget to call defwindowproc ? */
1465 hBrush
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORSTATIC
,
1466 (WPARAM
)hDC
, (LPARAM
)hwnd
);
1468 hrgn
= set_control_clipping( hDC
, &client
);
1470 if (style
& BS_LEFTTEXT
|| ex_style
& WS_EX_RIGHT
)
1472 /* magic +4 is what CTL3D expects */
1474 rtext
.right
-= checkBoxWidth
+ text_offset
;;
1475 rbox
.left
= rbox
.right
- checkBoxWidth
;
1479 rtext
.left
+= checkBoxWidth
+ text_offset
;;
1480 rbox
.right
= checkBoxWidth
;
1483 /* Since WM_ERASEBKGND does nothing, first prepare background */
1484 if (action
== ODA_SELECT
) FillRect( hDC
, &rbox
, hBrush
);
1485 if (action
== ODA_DRAWENTIRE
) FillRect( hDC
, &client
, hBrush
);
1489 dtFlags
= BUTTON_CalcLabelRect(hwnd
, hDC
, &rtext
);
1491 /* Only adjust rbox when rtext is valid */
1492 if (dtFlags
!= (UINT
)-1L)
1494 rbox
.top
= rtext
.top
;
1495 rbox
.bottom
= rtext
.bottom
;
1498 /* Draw the check-box bitmap */
1499 if (action
== ODA_DRAWENTIRE
|| action
== ODA_SELECT
)
1503 if ((get_button_type(style
) == BS_RADIOBUTTON
) ||
1504 (get_button_type(style
) == BS_AUTORADIOBUTTON
)) flags
= DFCS_BUTTONRADIO
;
1505 else if (state
& BST_INDETERMINATE
) flags
= DFCS_BUTTON3STATE
;
1506 else flags
= DFCS_BUTTONCHECK
;
1508 if (state
& (BST_CHECKED
| BST_INDETERMINATE
)) flags
|= DFCS_CHECKED
;
1509 if (state
& BST_PUSHED
) flags
|= DFCS_PUSHED
;
1511 if (style
& WS_DISABLED
) flags
|= DFCS_INACTIVE
;
1513 /* rbox must have the correct height */
1514 delta
= rbox
.bottom
- rbox
.top
- checkBoxHeight
;
1516 if (style
& BS_TOP
) {
1518 rbox
.bottom
= rbox
.top
+ checkBoxHeight
;
1520 rbox
.top
-= -delta
/2 + 1;
1521 rbox
.bottom
= rbox
.top
+ checkBoxHeight
;
1523 } else if (style
& BS_BOTTOM
) {
1525 rbox
.top
= rbox
.bottom
- checkBoxHeight
;
1527 rbox
.bottom
+= -delta
/2 + 1;
1528 rbox
.top
= rbox
.bottom
- checkBoxHeight
;
1530 } else { /* Default */
1532 int ofs
= (delta
/ 2);
1533 rbox
.bottom
-= ofs
+ 1;
1534 rbox
.top
= rbox
.bottom
- checkBoxHeight
;
1535 } else if (delta
< 0) {
1536 int ofs
= (-delta
/ 2);
1537 rbox
.top
-= ofs
+ 1;
1538 rbox
.bottom
= rbox
.top
+ checkBoxHeight
;
1542 DrawFrameControl( hDC
, &rbox
, DFC_BUTTON
, flags
);
1545 if (dtFlags
== (UINT
)-1L) /* Noting to draw */
1548 if (action
== ODA_DRAWENTIRE
)
1549 BUTTON_DrawLabel(hwnd
, hDC
, dtFlags
, &rtext
);
1552 if (action
== ODA_FOCUS
|| (state
& BST_FOCUS
))
1555 if (!(get_ui_state(hwnd
) & UISF_HIDEFOCUS
))
1560 IntersectRect(&rtext
, &rtext
, &client
);
1561 DrawFocusRect( hDC
, &rtext
);
1566 SelectClipRgn( hDC
, hrgn
);
1567 if (hrgn
) DeleteObject( hrgn
);
1571 /**********************************************************************
1572 * BUTTON_CheckAutoRadioButton
1574 * hwnd is checked, uncheck every other auto radio button in group
1576 static void BUTTON_CheckAutoRadioButton( HWND hwnd
)
1578 HWND parent
, sibling
, start
;
1580 parent
= GetParent(hwnd
);
1581 /* make sure that starting control is not disabled or invisible */
1582 start
= sibling
= GetNextDlgGroupItem( parent
, hwnd
, TRUE
);
1585 if (!sibling
) break;
1586 if ((hwnd
!= sibling
) &&
1587 ((GetWindowLongPtrW( sibling
, GWL_STYLE
) & BS_TYPEMASK
) == BS_AUTORADIOBUTTON
))
1588 SendMessageW( sibling
, BM_SETCHECK
, BST_UNCHECKED
, 0 );
1589 sibling
= GetNextDlgGroupItem( parent
, sibling
, FALSE
);
1590 } while (sibling
!= start
);
1594 /**********************************************************************
1595 * Group Box Functions
1598 static void GB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1605 LONG style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
1609 if ((hFont
= get_button_font( hwnd
))) SelectObject( hDC
, hFont
);
1610 /* GroupBox acts like static control, so it sends CTLCOLORSTATIC */
1611 parent
= GetParent(hwnd
);
1612 if (!parent
) parent
= hwnd
;
1613 #if defined(__REACTOS__) && defined(_USER32_)
1614 hbr
= GetControlColor(parent
, hwnd
, hDC
, WM_CTLCOLORSTATIC
);
1616 hbr
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORSTATIC
, (WPARAM
)hDC
, (LPARAM
)hwnd
);
1617 if (!hbr
) /* did the app forget to call defwindowproc ? */
1618 hbr
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORSTATIC
,
1619 (WPARAM
)hDC
, (LPARAM
)hwnd
);
1621 GetClientRect( hwnd
, &rc
);
1623 hrgn
= set_control_clipping( hDC
, &rc
);
1625 GetTextMetricsW (hDC
, &tm
);
1626 rcFrame
.top
+= (tm
.tmHeight
/ 2) - 1;
1627 DrawEdge (hDC
, &rcFrame
, EDGE_ETCHED
, BF_RECT
| ((style
& BS_FLAT
) ? BF_FLAT
: 0));
1629 InflateRect(&rc
, -7, 1);
1630 dtFlags
= BUTTON_CalcLabelRect(hwnd
, hDC
, &rc
);
1632 if (dtFlags
!= (UINT
)-1L)
1634 /* Because buttons have CS_PARENTDC class style, there is a chance
1635 * that label will be drawn out of client rect.
1636 * But Windows doesn't clip label's rect, so do I.
1639 /* There is 1-pixel margin at the left, right, and bottom */
1640 rc
.left
--; rc
.right
++; rc
.bottom
++;
1641 FillRect(hDC
, &rc
, hbr
);
1642 rc
.left
++; rc
.right
--; rc
.bottom
--;
1644 BUTTON_DrawLabel(hwnd
, hDC
, dtFlags
, &rc
);
1646 SelectClipRgn( hDC
, hrgn
);
1647 if (hrgn
) DeleteObject( hrgn
);
1651 /**********************************************************************
1652 * User Button Functions
1655 static void UB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1660 LONG state
= get_button_state( hwnd
);
1663 GetClientRect( hwnd
, &rc
);
1665 if ((hFont
= get_button_font( hwnd
))) SelectObject( hDC
, hFont
);
1667 parent
= GetParent(hwnd
);
1668 if (!parent
) parent
= hwnd
;
1669 #if defined(__REACTOS__) && defined(_USER32_)
1670 hBrush
= GetControlColor( parent
, hwnd
, hDC
, WM_CTLCOLORBTN
);
1672 hBrush
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)hwnd
);
1673 if (!hBrush
) /* did the app forget to call defwindowproc ? */
1674 hBrush
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORBTN
,
1675 (WPARAM
)hDC
, (LPARAM
)hwnd
);
1678 FillRect( hDC
, &rc
, hBrush
);
1679 if (action
== ODA_FOCUS
|| (state
& BST_FOCUS
))
1682 if (!(get_ui_state(hwnd
) & UISF_HIDEFOCUS
))
1684 DrawFocusRect( hDC
, &rc
);
1692 BUTTON_NOTIFY_PARENT( hwnd
, (state
& BST_FOCUS
) ? BN_SETFOCUS
: BN_KILLFOCUS
);
1696 BUTTON_NOTIFY_PARENT( hwnd
, (state
& BST_PUSHED
) ? BN_HILITE
: BN_UNHILITE
);
1700 BUTTON_NOTIFY_PARENT( hwnd
, BN_PAINT
);
1706 /**********************************************************************
1707 * Ownerdrawn Button Functions
1710 static void OB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1712 LONG state
= get_button_state( hwnd
);
1714 LONG_PTR id
= GetWindowLongPtrW( hwnd
, GWLP_ID
);
1716 HFONT hFont
, hPrevFont
= 0;
1719 dis
.CtlType
= ODT_BUTTON
;
1722 dis
.itemAction
= action
;
1723 dis
.itemState
= ((state
& BST_FOCUS
) ? ODS_FOCUS
: 0) |
1724 ((state
& BST_PUSHED
) ? ODS_SELECTED
: 0) |
1725 (IsWindowEnabled(hwnd
) ? 0: ODS_DISABLED
);
1726 dis
.hwndItem
= hwnd
;
1729 GetClientRect( hwnd
, &dis
.rcItem
);
1731 if ((hFont
= get_button_font( hwnd
))) hPrevFont
= SelectObject( hDC
, hFont
);
1732 parent
= GetParent(hwnd
);
1733 if (!parent
) parent
= hwnd
;
1734 #if defined(__REACTOS__) && defined(_USER32_)
1735 GetControlColor( parent
, hwnd
, hDC
, WM_CTLCOLORBTN
);
1737 SendMessageW( parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)hwnd
);
1740 hrgn
= set_control_clipping( hDC
, &dis
.rcItem
);
1742 SendMessageW( GetParent(hwnd
), WM_DRAWITEM
, id
, (LPARAM
)&dis
);
1743 if (hPrevFont
) SelectObject(hDC
, hPrevFont
);
1744 SelectClipRgn( hDC
, hrgn
);
1745 if (hrgn
) DeleteObject( hrgn
);
1749 void BUTTON_Register()
1753 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
1754 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_VREDRAW
| CS_HREDRAW
| CS_PARENTDC
;
1755 wndClass
.lpfnWndProc
= ButtonWndProcW
;
1756 wndClass
.cbClsExtra
= 0;
1757 wndClass
.cbWndExtra
= sizeof(PBUTTON_DATA
);
1758 wndClass
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
1759 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
1760 wndClass
.lpszClassName
= WC_BUTTONW
;
1762 RegisterClassW(&wndClass
);
1765 void BUTTON_Unregister()
1767 UnregisterClassW(WC_BUTTONW
, NULL
);