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
;
321 pdata
= _GetButtonData(hwnd
);
322 text
= get_button_text( hwnd
);
324 if (!pdata
|| !text
|| !hdc
|| !text
[0])
327 /* FIXME : Should use GetThemeTextExtent but unfortunately uses DrawTextW which is broken */
330 HRESULT hr
= GetThemeFont(theme
, hdc
, BP_PUSHBUTTON
, PBS_NORMAL
, TMT_FONT
, &logfont
);
333 hFont
= CreateFontIndirectW(&logfont
);
335 hPrevFont
= SelectObject( hdc
, hFont
);
341 hPrevFont
= SelectObject( hdc
, pdata
->font
);
344 GetTextExtentPoint32W(hdc
, text
, wcslen(text
), &TextSize
);
346 if (logfont
.lfHeight
== -1 && logfont
.lfWidth
== 0 && wcscmp(logfont
.lfFaceName
, L
"Arial") == 0)
353 SelectObject( hdc
, hPrevFont
);
355 TextSize
.cy
+= pdata
->rcTextMargin
.top
+ pdata
->rcTextMargin
.bottom
;
356 TextSize
.cx
+= pdata
->rcTextMargin
.left
+ pdata
->rcTextMargin
.right
;
358 if (pdata
->imlData
.himl
&& ImageList_GetIconSize(pdata
->imlData
.himl
, &ImageSize
.cx
, &ImageSize
.cy
))
360 ImageSize
.cx
+= pdata
->imlData
.margin
.left
+ pdata
->imlData
.margin
.right
;
361 ImageSize
.cy
+= pdata
->imlData
.margin
.top
+ pdata
->imlData
.margin
.bottom
;
365 ImageSize
.cx
= ImageSize
.cy
= 0;
370 RECT rcContents
= {0};
371 RECT rcButtonExtent
= {0};
372 rcContents
.right
= ImageSize
.cx
+ TextSize
.cx
;
373 rcContents
.bottom
= max(ImageSize
.cy
, TextSize
.cy
);
374 GetThemeBackgroundExtent(theme
, hdc
, BP_PUSHBUTTON
, PBS_NORMAL
, &rcContents
, &rcButtonExtent
);
375 ERR("rcContents: %d, %d, %d, %d\n", rcContents
.left
, rcContents
.top
, rcContents
.right
, rcContents
.bottom
);
376 ERR("rcButtonExtent: %d, %d, %d, %d\n", rcButtonExtent
.left
, rcButtonExtent
.top
, rcButtonExtent
.right
, rcButtonExtent
.bottom
);
377 ButtonSize
.cx
= rcButtonExtent
.right
- rcButtonExtent
.left
;
378 ButtonSize
.cy
= rcButtonExtent
.bottom
- rcButtonExtent
.top
;
382 ButtonSize
.cx
= ImageSize
.cx
+ TextSize
.cx
+ 5;
383 ButtonSize
.cy
= max(ImageSize
.cy
, TextSize
.cy
+ 7);
393 HeapFree( GetProcessHeap(), 0, text
);
395 ReleaseDC(hwnd
, hdc
);
403 /* retrieve the button text; returned buffer must be freed by caller */
404 inline WCHAR
*get_button_text( HWND hwnd
)
407 WCHAR
*buffer
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) );
408 if (buffer
) InternalGetWindowText( hwnd
, buffer
, len
+ 1 );
413 /* Retrieve the UI state for the control */
414 static BOOL
button_update_uistate(HWND hwnd
, BOOL unicode
)
416 LONG flags
, prevflags
;
419 flags
= DefWindowProcW(hwnd
, WM_QUERYUISTATE
, 0, 0);
421 flags
= DefWindowProcA(hwnd
, WM_QUERYUISTATE
, 0, 0);
423 prevflags
= get_ui_state(hwnd
);
425 if (prevflags
!= flags
)
427 set_ui_state(hwnd
, flags
);
435 /***********************************************************************
436 * ButtonWndProc_common
438 LRESULT WINAPI
ButtonWndProc_common(HWND hWnd
, UINT uMsg
,
439 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
443 LONG style
= GetWindowLongPtrW( hWnd
, GWL_STYLE
);
444 UINT btn_type
= get_button_type( style
);
447 #if defined(__REACTOS__) && defined(_USER32_)
450 pWnd
= ValidateHwnd(hWnd
);
455 NtUserSetWindowFNID(hWnd
, FNID_BUTTON
);
459 if (pWnd
->fnid
!= FNID_BUTTON
)
461 ERR("Wrong window class for Button! fnId 0x%x\n",pWnd
->fnid
);
469 if (!IsWindow( hWnd
)) return 0;
472 pt
.x
= (short)LOWORD(lParam
);
473 pt
.y
= (short)HIWORD(lParam
);
480 PBUTTON_DATA data
= HeapAlloc( GetProcessHeap(), 0, sizeof(BUTTON_DATA
) );
483 ERR("Failed to alloc internal button data\n");
487 memset(data
, 0, sizeof(BUTTON_DATA
));
488 SetRect(&data
->rcTextMargin
, 1,1,1,1);
490 _SetButtonData(hWnd
, data
);
495 PBUTTON_DATA data
= _GetButtonData(hWnd
);
501 HeapFree( GetProcessHeap(), 0, data
);
502 _SetButtonData(hWnd
, NULL
);
505 OpenThemeData(hWnd
, WC_BUTTONW
);
508 CloseThemeData (GetWindowTheme(hWnd
));
510 case WM_THEMECHANGED
:
511 CloseThemeData (GetWindowTheme(hWnd
));
512 OpenThemeData(hWnd
, WC_BUTTONW
);
513 InvalidateRect(hWnd
, NULL
, FALSE
);
517 int state
= (int)SendMessageW(hWnd
, BM_GETSTATE
, 0, 0);
518 set_button_state(hWnd
, state
|BST_HOT
);
519 InvalidateRect(hWnd
, NULL
, FALSE
);
524 int state
= (int)SendMessageW(hWnd
, BM_GETSTATE
, 0, 0);
525 set_button_state(hWnd
, state
&(~BST_HOT
));
526 InvalidateRect(hWnd
, NULL
, FALSE
);
531 TRACKMOUSEEVENT mouse_event
;
532 mouse_event
.cbSize
= sizeof(TRACKMOUSEEVENT
);
533 mouse_event
.dwFlags
= TME_QUERY
;
534 if(!TrackMouseEvent(&mouse_event
) || !(mouse_event
.dwFlags
&(TME_HOVER
|TME_LEAVE
)))
536 mouse_event
.dwFlags
= TME_HOVER
|TME_LEAVE
;
537 mouse_event
.hwndTrack
= hWnd
;
538 mouse_event
.dwHoverTime
= 1;
539 TrackMouseEvent(&mouse_event
);
543 case BCM_GETTEXTMARGIN
:
545 RECT
* prc
= (RECT
*)lParam
;
546 PBUTTON_DATA data
= _GetButtonData(hWnd
);
549 *prc
= data
->rcTextMargin
;
552 case BCM_SETTEXTMARGIN
:
554 RECT
* prc
= (RECT
*)lParam
;
555 PBUTTON_DATA data
= _GetButtonData(hWnd
);
558 data
->rcTextMargin
= *prc
;
561 case BCM_SETIMAGELIST
:
563 BUTTON_IMAGELIST
* pimldata
= (BUTTON_IMAGELIST
*)lParam
;
564 PBUTTON_DATA data
= _GetButtonData(hWnd
);
565 if (!data
|| !pimldata
|| !pimldata
->himl
)
567 data
->imlData
= *pimldata
;
570 case BCM_GETIMAGELIST
:
572 BUTTON_IMAGELIST
* pimldata
= (BUTTON_IMAGELIST
*)lParam
;
573 PBUTTON_DATA data
= _GetButtonData(hWnd
);
574 if (!data
|| !pimldata
)
576 *pimldata
= data
->imlData
;
579 case BCM_GETIDEALSIZE
:
581 HTHEME theme
= GetWindowTheme(hWnd
);
583 SIZE
* pSize
= (SIZE
*)lParam
;
585 if (btn_type
== BS_PUSHBUTTON
||
586 btn_type
== BS_DEFPUSHBUTTON
||
587 btn_type
== BS_USERBUTTON
)
589 ret
= BUTTON_GetIdealSize(theme
, hWnd
, pSize
);
594 GetClientRect(hWnd
, &rect
);
595 pSize
->cx
= rect
.right
;
596 pSize
->cy
= rect
.bottom
;
603 if (!_GetButtonData(hWnd
))
606 return unicode
? DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
) :
607 DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
618 case BS_PUSHBUTTON
: return DLGC_BUTTON
| DLGC_UNDEFPUSHBUTTON
;
619 case BS_DEFPUSHBUTTON
: return DLGC_BUTTON
| DLGC_DEFPUSHBUTTON
;
621 case BS_AUTORADIOBUTTON
: return DLGC_BUTTON
| DLGC_RADIOBUTTON
;
622 case BS_GROUPBOX
: return DLGC_STATIC
;
623 default: return DLGC_BUTTON
;
627 paint_button( hWnd
, btn_type
, ODA_DRAWENTIRE
);
631 if (btn_type
>= MAX_BTN_TYPE
)
632 return -1; /* abort */
634 /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
635 if (btn_type
== BS_USERBUTTON
)
637 style
= (style
& ~BS_TYPEMASK
) | BS_PUSHBUTTON
;
639 NtUserAlterWindowStyle(hWnd
, GWL_STYLE
, style
);
641 WIN_SetStyle( hWnd
, style
, BS_TYPEMASK
& ~style
);
644 set_button_state( hWnd
, BST_UNCHECKED
);
646 button_update_uistate( hWnd
, unicode
);
650 #if defined(__REACTOS__) && defined(_USER32_)
652 NtUserSetWindowFNID(hWnd
, FNID_DESTROY
);
657 if (btn_type
== BS_OWNERDRAW
)
659 HDC hdc
= (HDC
)wParam
;
662 HWND parent
= GetParent(hWnd
);
663 if (!parent
) parent
= hWnd
;
664 #if defined(__REACTOS__) && defined(_USER32_)
665 hBrush
= GetControlColor( parent
, hWnd
, hdc
, WM_CTLCOLORBTN
);
667 hBrush
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORBTN
, (WPARAM
)hdc
, (LPARAM
)hWnd
);
668 if (!hBrush
) /* did the app forget to call defwindowproc ? */
669 hBrush
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORBTN
,
670 (WPARAM
)hdc
, (LPARAM
)hWnd
);
672 GetClientRect(hWnd
, &rc
);
673 FillRect(hdc
, &rc
, hBrush
);
681 HDC hdc
= wParam
? (HDC
)wParam
: BeginPaint( hWnd
, &ps
);
683 HTHEME theme
= GetWindowTheme(hWnd
);
684 if (theme
&& BUTTON_PaintWithTheme(theme
, hWnd
, hdc
, uMsg
== WM_PRINTCLIENT
? lParam
: 0))
686 if ( !wParam
) EndPaint( hWnd
, &ps
);
690 if (btnPaintFunc
[btn_type
])
692 int nOldMode
= SetBkMode( hdc
, OPAQUE
);
693 (btnPaintFunc
[btn_type
])( hWnd
, hdc
, ODA_DRAWENTIRE
);
694 SetBkMode(hdc
, nOldMode
); /* reset painting mode */
696 if ( !wParam
) EndPaint( hWnd
, &ps
);
701 if (wParam
== VK_SPACE
)
703 SendMessageW( hWnd
, BM_SETSTATE
, TRUE
, 0 );
704 set_button_state( hWnd
, get_button_state( hWnd
) | BUTTON_BTNPRESSED
);
709 case WM_LBUTTONDBLCLK
:
710 if(style
& BS_NOTIFY
||
711 btn_type
== BS_RADIOBUTTON
||
712 btn_type
== BS_USERBUTTON
||
713 btn_type
== BS_OWNERDRAW
)
715 BUTTON_NOTIFY_PARENT(hWnd
, BN_DOUBLECLICKED
);
722 set_button_state( hWnd
, get_button_state( hWnd
) | BUTTON_BTNPRESSED
);
723 SendMessageW( hWnd
, BM_SETSTATE
, TRUE
, 0 );
727 if (wParam
!= VK_SPACE
)
732 BOOL TellParent
= FALSE
; //// ReactOS see note below.
734 state
= get_button_state( hWnd
);
735 if (!(state
& BUTTON_BTNPRESSED
)) break;
736 state
&= BUTTON_NSTATES
;
737 set_button_state( hWnd
, state
);
738 if (!(state
& BST_PUSHED
))
743 SendMessageW( hWnd
, BM_SETSTATE
, FALSE
, 0 );
744 GetClientRect( hWnd
, &rect
);
745 if (uMsg
== WM_KEYUP
|| PtInRect( &rect
, pt
))
747 state
= get_button_state( hWnd
);
750 case BS_AUTOCHECKBOX
:
751 SendMessageW( hWnd
, BM_SETCHECK
, !(state
& BST_CHECKED
), 0 );
753 case BS_AUTORADIOBUTTON
:
754 SendMessageW( hWnd
, BM_SETCHECK
, TRUE
, 0 );
757 SendMessageW( hWnd
, BM_SETCHECK
,
758 (state
& BST_INDETERMINATE
) ? 0 : ((state
& 3) + 1), 0 );
762 TellParent
= TRUE
; // <---- Fix CORE-10194, Notify parent after capture is released.
765 BUTTON_NOTIFY_PARENT(hWnd
, BN_CLICKED
);
770 if (TellParent
) BUTTON_NOTIFY_PARENT(hWnd
, BN_CLICKED
);
779 case WM_CAPTURECHANGED
:
780 TRACE("WM_CAPTURECHANGED %p\n", hWnd
);
781 if (hWnd
== (HWND
)lParam
) break;
782 state
= get_button_state( hWnd
);
783 if (state
& BUTTON_BTNPRESSED
)
785 state
&= BUTTON_NSTATES
;
786 set_button_state( hWnd
, state
);
787 if (state
& BST_PUSHED
) SendMessageW( hWnd
, BM_SETSTATE
, FALSE
, 0 );
792 if ((wParam
& MK_LBUTTON
) && GetCapture() == hWnd
)
794 GetClientRect( hWnd
, &rect
);
795 SendMessageW( hWnd
, BM_SETSTATE
, PtInRect(&rect
, pt
), 0 );
801 /* Clear an old text here as Windows does */
804 // wine Bug: http://bugs.winehq.org/show_bug.cgi?id=25790
805 // Patch: http://source.winehq.org/patches/data/70889
806 // By: Alexander LAW, Replicate Windows behavior of WM_SETTEXT handler regarding WM_CTLCOLOR*
809 if (style
& WS_VISIBLE
)
811 if (IsWindowVisible(hWnd
))
814 HDC hdc
= GetDC(hWnd
);
817 HWND parent
= GetParent(hWnd
);
818 UINT message
= (btn_type
== BS_PUSHBUTTON
||
819 btn_type
== BS_DEFPUSHBUTTON
||
820 btn_type
== BS_PUSHLIKE
||
821 btn_type
== BS_USERBUTTON
||
822 btn_type
== BS_OWNERDRAW
) ?
823 WM_CTLCOLORBTN
: WM_CTLCOLORSTATIC
;
825 if (!parent
) parent
= hWnd
;
826 #if defined(__REACTOS__) && defined(_USER32_)
827 hbrush
= GetControlColor(parent
, hWnd
, hdc
, message
);
829 hbrush
= (HBRUSH
)SendMessageW(parent
, message
,
830 (WPARAM
)hdc
, (LPARAM
)hWnd
);
831 if (!hbrush
) /* did the app forget to call DefWindowProc ? */
832 hbrush
= (HBRUSH
)DefWindowProcW(parent
, message
,
833 (WPARAM
)hdc
, (LPARAM
)hWnd
);
836 GetClientRect(hWnd
, &client
);
838 /* FIXME: check other BS_* handlers */
839 if (btn_type
== BS_GROUPBOX
)
840 InflateRect(&rc
, -7, 1); /* GB_Paint does this */
841 BUTTON_CalcLabelRect(hWnd
, hdc
, &rc
);
842 /* Clip by client rect bounds */
843 if (rc
.right
> client
.right
) rc
.right
= client
.right
;
844 if (rc
.bottom
> client
.bottom
) rc
.bottom
= client
.bottom
;
845 FillRect(hdc
, &rc
, hbrush
);
846 ReleaseDC(hWnd
, hdc
);
849 if (unicode
) DefWindowProcW( hWnd
, WM_SETTEXT
, wParam
, lParam
);
850 else DefWindowProcA( hWnd
, WM_SETTEXT
, wParam
, lParam
);
851 if (btn_type
== BS_GROUPBOX
) /* Yes, only for BS_GROUPBOX */
852 InvalidateRect( hWnd
, NULL
, TRUE
);
854 paint_button( hWnd
, btn_type
, ODA_DRAWENTIRE
);
855 return 1; /* success. FIXME: check text length */
859 set_button_font( hWnd
, (HFONT
)wParam
);
860 if (lParam
) InvalidateRect(hWnd
, NULL
, TRUE
);
864 return (LRESULT
)get_button_font( hWnd
);
867 TRACE("WM_SETFOCUS %p\n",hWnd
);
868 set_button_state( hWnd
, get_button_state(hWnd
) | BST_FOCUS
);
870 if (btn_type
!= BS_OWNERDRAW
)
871 InvalidateRect(hWnd
, NULL
, FALSE
);
874 paint_button( hWnd
, btn_type
, ODA_FOCUS
);
875 if (style
& BS_NOTIFY
)
876 BUTTON_NOTIFY_PARENT(hWnd
, BN_SETFOCUS
);
880 TRACE("WM_KILLFOCUS %p\n",hWnd
);
881 state
= get_button_state( hWnd
);
882 set_button_state( hWnd
, state
& ~BST_FOCUS
);
884 paint_button( hWnd
, btn_type
, ODA_FOCUS
);
887 if ((state
& BUTTON_BTNPRESSED
) && GetCapture() == hWnd
)
889 if (style
& BS_NOTIFY
)
890 BUTTON_NOTIFY_PARENT(hWnd
, BN_KILLFOCUS
);
892 InvalidateRect( hWnd
, NULL
, FALSE
);
895 case WM_SYSCOLORCHANGE
:
896 InvalidateRect( hWnd
, NULL
, FALSE
);
900 btn_type
= wParam
& BS_TYPEMASK
;
901 style
= (style
& ~BS_TYPEMASK
) | btn_type
;
903 NtUserAlterWindowStyle(hWnd
, GWL_STYLE
, style
);
905 WIN_SetStyle( hWnd
, style
, BS_TYPEMASK
& ~style
);
908 /* Only redraw if lParam flag is set.*/
910 InvalidateRect( hWnd
, NULL
, TRUE
);
916 state
= get_button_state(hWnd
);
917 if (state
& BUTTON_BMCLICK
)
919 set_button_state(hWnd
, state
| BUTTON_BMCLICK
); // Tracked in STATE_GWL_OFFSET.
921 SendMessageW( hWnd
, WM_LBUTTONDOWN
, 0, 0 );
922 SendMessageW( hWnd
, WM_LBUTTONUP
, 0, 0 );
924 state
= get_button_state(hWnd
);
925 if (!(state
& BUTTON_BMCLICK
)) break;
926 state
&= ~BUTTON_BMCLICK
;
927 set_button_state(hWnd
, state
);
932 /* Check that image format matches button style */
933 switch (style
& (BS_BITMAP
|BS_ICON
))
936 if (wParam
!= IMAGE_BITMAP
) return 0;
939 if (wParam
!= IMAGE_ICON
) return 0;
945 oldHbitmap
= (HBITMAP
)SetWindowLongPtrW( hWnd
, HIMAGE_GWL_OFFSET
, lParam
);
947 oldHbitmap
= (HBITMAP
)set_button_image(hWnd
, lParam
);
949 InvalidateRect( hWnd
, NULL
, FALSE
);
950 return (LRESULT
)oldHbitmap
;
954 return GetWindowLongPtrW( hWnd
, HIMAGE_GWL_OFFSET
);
956 return get_button_image(hWnd
);
960 return get_button_state( hWnd
) & 3;
963 if (wParam
> maxCheckState
[btn_type
]) wParam
= maxCheckState
[btn_type
];
964 state
= get_button_state( hWnd
);
965 if ((btn_type
== BS_RADIOBUTTON
) || (btn_type
== BS_AUTORADIOBUTTON
))
968 if (wParam
) style
|= WS_TABSTOP
;
969 else style
&= ~WS_TABSTOP
;
970 NtUserAlterWindowStyle(hWnd
, GWL_STYLE
, style
);
972 if (wParam
) WIN_SetStyle( hWnd
, WS_TABSTOP
, 0 );
973 else WIN_SetStyle( hWnd
, 0, WS_TABSTOP
);
976 if ((state
& 3) != wParam
)
978 set_button_state( hWnd
, (state
& ~3) | wParam
);
980 paint_button( hWnd
, btn_type
, ODA_SELECT
);
982 InvalidateRect(hWnd
, NULL
, FALSE
);
985 if ((btn_type
== BS_AUTORADIOBUTTON
) && (wParam
== BST_CHECKED
) && (style
& WS_CHILD
))
986 BUTTON_CheckAutoRadioButton( hWnd
);
990 return get_button_state( hWnd
);
993 state
= get_button_state( hWnd
);
995 set_button_state( hWnd
, state
| BST_PUSHED
);
997 set_button_state( hWnd
, state
& ~BST_PUSHED
);
1000 paint_button( hWnd
, btn_type
, ODA_SELECT
);
1002 InvalidateRect(hWnd
, NULL
, FALSE
);
1007 case WM_UPDATEUISTATE
:
1009 DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
1011 DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
1013 if (button_update_uistate(hWnd
, unicode
))
1014 paint_button( hWnd
, btn_type
, ODA_DRAWENTIRE
);
1019 if(btn_type
== BS_GROUPBOX
) return HTTRANSPARENT
;
1022 return unicode
? DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
) :
1023 DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
1030 /***********************************************************************
1032 * The button window procedure. This is just a wrapper which locks
1033 * the passed HWND and calls the real window procedure (with a WND*
1034 * pointer pointing to the locked windowstructure).
1036 LRESULT WINAPI
ButtonWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1038 if (!IsWindow(hWnd
)) return 0;
1039 return ButtonWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
1042 /***********************************************************************
1045 LRESULT WINAPI
ButtonWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1047 if (!IsWindow(hWnd
)) return 0;
1048 return ButtonWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
1051 #endif /* __REACTOS__ */
1053 /**********************************************************************
1054 * Convert button styles to flags used by DrawText.
1056 static UINT
BUTTON_BStoDT( DWORD style
, DWORD ex_style
)
1058 UINT dtStyle
= DT_NOCLIP
; /* We use SelectClipRgn to limit output */
1060 /* "Convert" pushlike buttons to pushbuttons */
1061 if (style
& BS_PUSHLIKE
)
1062 style
&= ~BS_TYPEMASK
;
1064 if (!(style
& BS_MULTILINE
))
1065 dtStyle
|= DT_SINGLELINE
;
1067 dtStyle
|= DT_WORDBREAK
;
1069 switch (style
& BS_CENTER
)
1071 case BS_LEFT
: /* DT_LEFT is 0 */ break;
1072 case BS_RIGHT
: dtStyle
|= DT_RIGHT
; break;
1073 case BS_CENTER
: dtStyle
|= DT_CENTER
; break;
1075 /* Pushbutton's text is centered by default */
1076 if (get_button_type(style
) <= BS_DEFPUSHBUTTON
) dtStyle
|= DT_CENTER
;
1077 /* all other flavours have left aligned text */
1080 if (ex_style
& WS_EX_RIGHT
) dtStyle
= DT_RIGHT
| (dtStyle
& ~(DT_LEFT
| DT_CENTER
));
1082 /* DrawText ignores vertical alignment for multiline text,
1083 * but we use these flags to align label manually.
1085 if (get_button_type(style
) != BS_GROUPBOX
)
1087 switch (style
& BS_VCENTER
)
1089 case BS_TOP
: /* DT_TOP is 0 */ break;
1090 case BS_BOTTOM
: dtStyle
|= DT_BOTTOM
; break;
1091 case BS_VCENTER
: /* fall through */
1092 default: dtStyle
|= DT_VCENTER
; break;
1096 /* GroupBox's text is always single line and is top aligned. */
1097 dtStyle
|= DT_SINGLELINE
;
1102 /**********************************************************************
1103 * BUTTON_CalcLabelRect
1105 * Calculates label's rectangle depending on button style.
1107 * Returns flags to be passed to DrawText.
1108 * Calculated rectangle doesn't take into account button state
1109 * (pushed, etc.). If there is nothing to draw (no text/image) output
1110 * rectangle is empty, and return value is (UINT)-1.
1112 static UINT
BUTTON_CalcLabelRect(HWND hwnd
, HDC hdc
, RECT
*rc
)
1114 LONG style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
1115 LONG ex_style
= GetWindowLongPtrW( hwnd
, GWL_EXSTYLE
);
1119 UINT dtStyle
= BUTTON_BStoDT( style
, ex_style
);
1123 /* Calculate label rectangle according to label type */
1124 switch (style
& (BS_ICON
|BS_BITMAP
))
1128 HFONT hFont
, hPrevFont
= 0;
1130 if (!(text
= get_button_text( hwnd
))) goto empty_rect
;
1133 HeapFree( GetProcessHeap(), 0, text
);
1137 if ((hFont
= get_button_font( hwnd
))) hPrevFont
= SelectObject( hdc
, hFont
);
1138 DrawTextW(hdc
, text
, -1, &r
, dtStyle
| DT_CALCRECT
);
1139 if (hPrevFont
) SelectObject( hdc
, hPrevFont
);
1140 HeapFree( GetProcessHeap(), 0, text
);
1142 if (get_ui_state(hwnd
) & UISF_HIDEACCEL
)
1143 dtStyle
|= DT_HIDEPREFIX
;
1150 if (!GetIconInfo((HICON
)GetWindowLongPtrW( hwnd
, HIMAGE_GWL_OFFSET
), &iconInfo
))
1152 if (!GetIconInfo((HICON
)get_button_image(hwnd
), &iconInfo
))
1156 GetObjectW (iconInfo
.hbmColor
, sizeof(BITMAP
), &bm
);
1158 r
.right
= r
.left
+ bm
.bmWidth
;
1159 r
.bottom
= r
.top
+ bm
.bmHeight
;
1161 DeleteObject(iconInfo
.hbmColor
);
1162 DeleteObject(iconInfo
.hbmMask
);
1167 if (!GetObjectW( (HANDLE
)GetWindowLongPtrW( hwnd
, HIMAGE_GWL_OFFSET
), sizeof(BITMAP
), &bm
))
1169 if (!GetObjectW( (HANDLE
)get_button_image(hwnd
), sizeof(BITMAP
), &bm
))
1173 r
.right
= r
.left
+ bm
.bmWidth
;
1174 r
.bottom
= r
.top
+ bm
.bmHeight
;
1184 /* Position label inside bounding rectangle according to
1185 * alignment flags. (calculated rect is always left-top aligned).
1186 * If label is aligned to any side - shift label in opposite
1187 * direction to leave extra space for focus rectangle.
1189 switch (dtStyle
& (DT_CENTER
|DT_RIGHT
))
1191 case DT_LEFT
: r
.left
++; r
.right
++; break;
1192 case DT_CENTER
: n
= r
.right
- r
.left
;
1193 r
.left
= rc
->left
+ ((rc
->right
- rc
->left
) - n
) / 2;
1194 r
.right
= r
.left
+ n
; break;
1195 case DT_RIGHT
: n
= r
.right
- r
.left
;
1196 r
.right
= rc
->right
- 1;
1197 r
.left
= r
.right
- n
;
1201 switch (dtStyle
& (DT_VCENTER
|DT_BOTTOM
))
1203 case DT_TOP
: r
.top
++; r
.bottom
++; break;
1204 case DT_VCENTER
: n
= r
.bottom
- r
.top
;
1205 r
.top
= rc
->top
+ ((rc
->bottom
- rc
->top
) - n
) / 2;
1206 r
.bottom
= r
.top
+ n
; break;
1207 case DT_BOTTOM
: n
= r
.bottom
- r
.top
;
1208 r
.bottom
= rc
->bottom
- 1;
1209 r
.top
= r
.bottom
- n
;
1218 /**********************************************************************
1219 * BUTTON_DrawTextCallback
1221 * Callback function used by DrawStateW function.
1223 static BOOL CALLBACK
BUTTON_DrawTextCallback(HDC hdc
, LPARAM lp
, WPARAM wp
, int cx
, int cy
)
1228 SetRect(&rc
, 0, 0, cx
, cy
);
1229 DrawTextW(hdc
, (LPCWSTR
)lp
, -1, &rc
, (UINT
)wp
);
1232 HWND hwnd
= (HWND
)lp
;
1234 PBUTTON_DATA pdata
= _GetButtonData(hwnd
);
1238 if (!(text
= get_button_text( hwnd
))) return TRUE
;
1240 SetRect(&rc
, 0, 0, cx
, cy
);
1242 if (pdata
->imlData
.himl
&& ImageList_GetIconSize(pdata
->imlData
.himl
, &ImageSize
.cx
, &ImageSize
.cy
))
1244 int left
= pdata
->imlData
.margin
.left
;
1245 int top
= (cy
- ImageSize
.cy
) / 2;
1246 rc
.left
+= pdata
->imlData
.margin
.left
+ pdata
->imlData
.margin
.right
+ ImageSize
.cy
;
1247 ImageList_Draw(pdata
->imlData
.himl
, 0, hdc
, left
, top
, 0);
1250 DrawTextW(hdc
, text
, -1, &rc
, (UINT
)wp
);
1256 /**********************************************************************
1259 * Common function for drawing button label.
1261 static void BUTTON_DrawLabel(HWND hwnd
, HDC hdc
, UINT dtFlags
, const RECT
*rc
)
1263 DRAWSTATEPROC lpOutputProc
= NULL
;
1267 UINT flags
= IsWindowEnabled(hwnd
) ? DSS_NORMAL
: DSS_DISABLED
;
1268 LONG state
= get_button_state( hwnd
);
1269 LONG style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
1272 /* FIXME: To draw disabled label in Win31 look-and-feel, we probably
1273 * must use DSS_MONO flag and COLOR_GRAYTEXT brush (or maybe DSS_UNION).
1274 * I don't have Win31 on hand to verify that, so I leave it as is.
1277 if ((style
& BS_PUSHLIKE
) && (state
& BST_INDETERMINATE
))
1279 hbr
= GetSysColorBrush(COLOR_GRAYTEXT
);
1283 switch (style
& (BS_ICON
|BS_BITMAP
))
1286 /* DST_COMPLEX -- is 0 */
1287 lpOutputProc
= BUTTON_DrawTextCallback
;
1289 if (!(text
= get_button_text( hwnd
))) return;
1295 wp
= (WPARAM
)dtFlags
;
1298 if (dtFlags
& DT_HIDEPREFIX
)
1299 flags
|= DSS_HIDEPREFIX
;
1306 lp
= GetWindowLongPtrW( hwnd
, HIMAGE_GWL_OFFSET
);
1308 lp
= get_button_image(hwnd
);
1313 flags
|= DST_BITMAP
;
1315 lp
= GetWindowLongPtrW( hwnd
, HIMAGE_GWL_OFFSET
);
1317 lp
= get_button_image(hwnd
);
1325 DrawStateW(hdc
, hbr
, lpOutputProc
, lp
, wp
, rc
->left
, rc
->top
,
1326 rc
->right
- rc
->left
, rc
->bottom
- rc
->top
, flags
);
1327 HeapFree( GetProcessHeap(), 0, text
);
1330 /**********************************************************************
1331 * Push Button Functions
1333 static void PB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1336 UINT dtFlags
, uState
;
1340 COLORREF oldTxtColor
;
1342 LONG state
= get_button_state( hwnd
);
1343 LONG style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
1344 BOOL pushedState
= (state
& BST_PUSHED
);
1348 GetClientRect( hwnd
, &rc
);
1350 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
1351 if ((hFont
= get_button_font( hwnd
))) SelectObject( hDC
, hFont
);
1352 parent
= GetParent(hwnd
);
1353 if (!parent
) parent
= hwnd
;
1354 #if defined(__REACTOS__) && defined(_USER32_)
1355 GetControlColor( parent
, hwnd
, hDC
, WM_CTLCOLORBTN
);
1357 SendMessageW( parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)hwnd
);
1360 hrgn
= set_control_clipping( hDC
, &rc
);
1362 hOldPen
= SelectObject(hDC
, GetStockObject(DC_PEN
));
1363 SetDCPenColor(hDC
, GetSysColor(COLOR_WINDOWFRAME
));
1365 hOldPen
= SelectObject(hDC
, SYSCOLOR_GetPen(COLOR_WINDOWFRAME
));
1367 hOldBrush
= SelectObject(hDC
,GetSysColorBrush(COLOR_BTNFACE
));
1368 oldBkMode
= SetBkMode(hDC
, TRANSPARENT
);
1370 if (get_button_type(style
) == BS_DEFPUSHBUTTON
)
1372 if (action
!= ODA_FOCUS
)
1373 Rectangle(hDC
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1374 InflateRect( &rc
, -1, -1 );
1377 /* completely skip the drawing if only focus has changed */
1378 if (action
== ODA_FOCUS
) goto draw_focus
;
1380 uState
= DFCS_BUTTONPUSH
;
1382 if (style
& BS_FLAT
)
1383 uState
|= DFCS_MONO
;
1384 else if (pushedState
)
1386 if (get_button_type(style
) == BS_DEFPUSHBUTTON
)
1387 uState
|= DFCS_FLAT
;
1389 uState
|= DFCS_PUSHED
;
1392 if (state
& (BST_CHECKED
| BST_INDETERMINATE
))
1393 uState
|= DFCS_CHECKED
;
1395 DrawFrameControl( hDC
, &rc
, DFC_BUTTON
, uState
);
1397 /* draw button label */
1399 dtFlags
= BUTTON_CalcLabelRect(hwnd
, hDC
, &r
);
1401 if (dtFlags
== (UINT
)-1L)
1405 OffsetRect(&r
, 1, 1);
1407 oldTxtColor
= SetTextColor( hDC
, GetSysColor(COLOR_BTNTEXT
) );
1409 BUTTON_DrawLabel(hwnd
, hDC
, dtFlags
, &r
);
1411 SetTextColor( hDC
, oldTxtColor
);
1414 if (action
== ODA_FOCUS
|| (state
& BST_FOCUS
))
1417 if (!(get_ui_state(hwnd
) & UISF_HIDEFOCUS
))
1420 InflateRect( &rc
, -2, -2 );
1421 DrawFocusRect( hDC
, &rc
);
1428 SelectObject( hDC
, hOldPen
);
1429 SelectObject( hDC
, hOldBrush
);
1430 SetBkMode(hDC
, oldBkMode
);
1431 SelectClipRgn( hDC
, hrgn
);
1432 if (hrgn
) DeleteObject( hrgn
);
1435 /**********************************************************************
1436 * Check Box & Radio Button Functions
1439 static void CB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1441 RECT rbox
, rtext
, client
;
1443 int delta
, text_offset
, checkBoxWidth
, checkBoxHeight
;
1446 LONG state
= get_button_state( hwnd
);
1447 LONG style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
1448 LONG ex_style
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
1452 if (style
& BS_PUSHLIKE
)
1454 PB_Paint( hwnd
, hDC
, action
);
1458 GetClientRect(hwnd
, &client
);
1459 rbox
= rtext
= client
;
1461 checkBoxWidth
= 12 * GetDeviceCaps( hDC
, LOGPIXELSX
) / 96 + 1;
1462 checkBoxHeight
= 12 * GetDeviceCaps( hDC
, LOGPIXELSY
) / 96 + 1;
1464 if ((hFont
= get_button_font( hwnd
))) SelectObject( hDC
, hFont
);
1465 GetCharWidthW( hDC
, '0', '0', &text_offset
);
1468 parent
= GetParent(hwnd
);
1469 if (!parent
) parent
= hwnd
;
1470 #if defined(__REACTOS__) && defined(_USER32_)
1471 hBrush
= GetControlColor(parent
, hwnd
, hDC
, WM_CTLCOLORSTATIC
);
1473 hBrush
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORSTATIC
,
1474 (WPARAM
)hDC
, (LPARAM
)hwnd
);
1475 if (!hBrush
) /* did the app forget to call defwindowproc ? */
1476 hBrush
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORSTATIC
,
1477 (WPARAM
)hDC
, (LPARAM
)hwnd
);
1479 hrgn
= set_control_clipping( hDC
, &client
);
1481 if (style
& BS_LEFTTEXT
|| ex_style
& WS_EX_RIGHT
)
1483 /* magic +4 is what CTL3D expects */
1485 rtext
.right
-= checkBoxWidth
+ text_offset
;;
1486 rbox
.left
= rbox
.right
- checkBoxWidth
;
1490 rtext
.left
+= checkBoxWidth
+ text_offset
;;
1491 rbox
.right
= checkBoxWidth
;
1494 /* Since WM_ERASEBKGND does nothing, first prepare background */
1495 if (action
== ODA_SELECT
) FillRect( hDC
, &rbox
, hBrush
);
1496 if (action
== ODA_DRAWENTIRE
) FillRect( hDC
, &client
, hBrush
);
1500 dtFlags
= BUTTON_CalcLabelRect(hwnd
, hDC
, &rtext
);
1502 /* Only adjust rbox when rtext is valid */
1503 if (dtFlags
!= (UINT
)-1L)
1505 rbox
.top
= rtext
.top
;
1506 rbox
.bottom
= rtext
.bottom
;
1509 /* Draw the check-box bitmap */
1510 if (action
== ODA_DRAWENTIRE
|| action
== ODA_SELECT
)
1514 if ((get_button_type(style
) == BS_RADIOBUTTON
) ||
1515 (get_button_type(style
) == BS_AUTORADIOBUTTON
)) flags
= DFCS_BUTTONRADIO
;
1516 else if (state
& BST_INDETERMINATE
) flags
= DFCS_BUTTON3STATE
;
1517 else flags
= DFCS_BUTTONCHECK
;
1519 if (state
& (BST_CHECKED
| BST_INDETERMINATE
)) flags
|= DFCS_CHECKED
;
1520 if (state
& BST_PUSHED
) flags
|= DFCS_PUSHED
;
1522 if (style
& WS_DISABLED
) flags
|= DFCS_INACTIVE
;
1524 /* rbox must have the correct height */
1525 delta
= rbox
.bottom
- rbox
.top
- checkBoxHeight
;
1527 if (style
& BS_TOP
) {
1529 rbox
.bottom
= rbox
.top
+ checkBoxHeight
;
1531 rbox
.top
-= -delta
/2 + 1;
1532 rbox
.bottom
= rbox
.top
+ checkBoxHeight
;
1534 } else if (style
& BS_BOTTOM
) {
1536 rbox
.top
= rbox
.bottom
- checkBoxHeight
;
1538 rbox
.bottom
+= -delta
/2 + 1;
1539 rbox
.top
= rbox
.bottom
- checkBoxHeight
;
1541 } else { /* Default */
1543 int ofs
= (delta
/ 2);
1544 rbox
.bottom
-= ofs
+ 1;
1545 rbox
.top
= rbox
.bottom
- checkBoxHeight
;
1546 } else if (delta
< 0) {
1547 int ofs
= (-delta
/ 2);
1548 rbox
.top
-= ofs
+ 1;
1549 rbox
.bottom
= rbox
.top
+ checkBoxHeight
;
1553 DrawFrameControl( hDC
, &rbox
, DFC_BUTTON
, flags
);
1556 if (dtFlags
== (UINT
)-1L) /* Noting to draw */
1559 if (action
== ODA_DRAWENTIRE
)
1560 BUTTON_DrawLabel(hwnd
, hDC
, dtFlags
, &rtext
);
1563 if (action
== ODA_FOCUS
|| (state
& BST_FOCUS
))
1566 if (!(get_ui_state(hwnd
) & UISF_HIDEFOCUS
))
1571 IntersectRect(&rtext
, &rtext
, &client
);
1572 DrawFocusRect( hDC
, &rtext
);
1577 SelectClipRgn( hDC
, hrgn
);
1578 if (hrgn
) DeleteObject( hrgn
);
1582 /**********************************************************************
1583 * BUTTON_CheckAutoRadioButton
1585 * hwnd is checked, uncheck every other auto radio button in group
1587 static void BUTTON_CheckAutoRadioButton( HWND hwnd
)
1589 HWND parent
, sibling
, start
;
1591 parent
= GetParent(hwnd
);
1592 /* make sure that starting control is not disabled or invisible */
1593 start
= sibling
= GetNextDlgGroupItem( parent
, hwnd
, TRUE
);
1596 if (!sibling
) break;
1597 if ((hwnd
!= sibling
) &&
1598 ((GetWindowLongPtrW( sibling
, GWL_STYLE
) & BS_TYPEMASK
) == BS_AUTORADIOBUTTON
))
1599 SendMessageW( sibling
, BM_SETCHECK
, BST_UNCHECKED
, 0 );
1600 sibling
= GetNextDlgGroupItem( parent
, sibling
, FALSE
);
1601 } while (sibling
!= start
);
1605 /**********************************************************************
1606 * Group Box Functions
1609 static void GB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1616 LONG style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
1620 if ((hFont
= get_button_font( hwnd
))) SelectObject( hDC
, hFont
);
1621 /* GroupBox acts like static control, so it sends CTLCOLORSTATIC */
1622 parent
= GetParent(hwnd
);
1623 if (!parent
) parent
= hwnd
;
1624 #if defined(__REACTOS__) && defined(_USER32_)
1625 hbr
= GetControlColor(parent
, hwnd
, hDC
, WM_CTLCOLORSTATIC
);
1627 hbr
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORSTATIC
, (WPARAM
)hDC
, (LPARAM
)hwnd
);
1628 if (!hbr
) /* did the app forget to call defwindowproc ? */
1629 hbr
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORSTATIC
,
1630 (WPARAM
)hDC
, (LPARAM
)hwnd
);
1632 GetClientRect( hwnd
, &rc
);
1634 hrgn
= set_control_clipping( hDC
, &rc
);
1636 GetTextMetricsW (hDC
, &tm
);
1637 rcFrame
.top
+= (tm
.tmHeight
/ 2) - 1;
1638 DrawEdge (hDC
, &rcFrame
, EDGE_ETCHED
, BF_RECT
| ((style
& BS_FLAT
) ? BF_FLAT
: 0));
1640 InflateRect(&rc
, -7, 1);
1641 dtFlags
= BUTTON_CalcLabelRect(hwnd
, hDC
, &rc
);
1643 if (dtFlags
!= (UINT
)-1L)
1645 /* Because buttons have CS_PARENTDC class style, there is a chance
1646 * that label will be drawn out of client rect.
1647 * But Windows doesn't clip label's rect, so do I.
1650 /* There is 1-pixel margin at the left, right, and bottom */
1651 rc
.left
--; rc
.right
++; rc
.bottom
++;
1652 FillRect(hDC
, &rc
, hbr
);
1653 rc
.left
++; rc
.right
--; rc
.bottom
--;
1655 BUTTON_DrawLabel(hwnd
, hDC
, dtFlags
, &rc
);
1657 SelectClipRgn( hDC
, hrgn
);
1658 if (hrgn
) DeleteObject( hrgn
);
1662 /**********************************************************************
1663 * User Button Functions
1666 static void UB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1671 LONG state
= get_button_state( hwnd
);
1674 GetClientRect( hwnd
, &rc
);
1676 if ((hFont
= get_button_font( hwnd
))) SelectObject( hDC
, hFont
);
1678 parent
= GetParent(hwnd
);
1679 if (!parent
) parent
= hwnd
;
1680 #if defined(__REACTOS__) && defined(_USER32_)
1681 hBrush
= GetControlColor( parent
, hwnd
, hDC
, WM_CTLCOLORBTN
);
1683 hBrush
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)hwnd
);
1684 if (!hBrush
) /* did the app forget to call defwindowproc ? */
1685 hBrush
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORBTN
,
1686 (WPARAM
)hDC
, (LPARAM
)hwnd
);
1689 FillRect( hDC
, &rc
, hBrush
);
1690 if (action
== ODA_FOCUS
|| (state
& BST_FOCUS
))
1693 if (!(get_ui_state(hwnd
) & UISF_HIDEFOCUS
))
1695 DrawFocusRect( hDC
, &rc
);
1703 BUTTON_NOTIFY_PARENT( hwnd
, (state
& BST_FOCUS
) ? BN_SETFOCUS
: BN_KILLFOCUS
);
1707 BUTTON_NOTIFY_PARENT( hwnd
, (state
& BST_PUSHED
) ? BN_HILITE
: BN_UNHILITE
);
1711 BUTTON_NOTIFY_PARENT( hwnd
, BN_PAINT
);
1717 /**********************************************************************
1718 * Ownerdrawn Button Functions
1721 static void OB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1723 LONG state
= get_button_state( hwnd
);
1725 LONG_PTR id
= GetWindowLongPtrW( hwnd
, GWLP_ID
);
1727 HFONT hFont
, hPrevFont
= 0;
1730 dis
.CtlType
= ODT_BUTTON
;
1733 dis
.itemAction
= action
;
1734 dis
.itemState
= ((state
& BST_FOCUS
) ? ODS_FOCUS
: 0) |
1735 ((state
& BST_PUSHED
) ? ODS_SELECTED
: 0) |
1736 (IsWindowEnabled(hwnd
) ? 0: ODS_DISABLED
);
1737 dis
.hwndItem
= hwnd
;
1740 GetClientRect( hwnd
, &dis
.rcItem
);
1742 if ((hFont
= get_button_font( hwnd
))) hPrevFont
= SelectObject( hDC
, hFont
);
1743 parent
= GetParent(hwnd
);
1744 if (!parent
) parent
= hwnd
;
1745 #if defined(__REACTOS__) && defined(_USER32_)
1746 GetControlColor( parent
, hwnd
, hDC
, WM_CTLCOLORBTN
);
1748 SendMessageW( parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)hwnd
);
1751 hrgn
= set_control_clipping( hDC
, &dis
.rcItem
);
1753 SendMessageW( GetParent(hwnd
), WM_DRAWITEM
, id
, (LPARAM
)&dis
);
1754 if (hPrevFont
) SelectObject(hDC
, hPrevFont
);
1755 SelectClipRgn( hDC
, hrgn
);
1756 if (hrgn
) DeleteObject( hrgn
);
1760 void BUTTON_Register()
1764 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
1765 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_VREDRAW
| CS_HREDRAW
| CS_PARENTDC
;
1766 wndClass
.lpfnWndProc
= ButtonWndProcW
;
1767 wndClass
.cbClsExtra
= 0;
1768 wndClass
.cbWndExtra
= sizeof(PBUTTON_DATA
);
1769 wndClass
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
1770 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
1771 wndClass
.lpszClassName
= WC_BUTTONW
;
1773 RegisterClassW(&wndClass
);
1776 void BUTTON_Unregister()
1778 UnregisterClassW(WC_BUTTONW
, NULL
);