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
;
320 pdata
= _GetButtonData(hwnd
);
321 text
= get_button_text( hwnd
);
323 if (!pdata
|| !text
|| !hdc
|| !text
[0])
326 /* 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
);
347 SelectObject( hdc
, hPrevFont
);
349 TextSize
.cy
+= pdata
->rcTextMargin
.top
+ pdata
->rcTextMargin
.bottom
;
350 TextSize
.cx
+= pdata
->rcTextMargin
.left
+ pdata
->rcTextMargin
.right
;
352 if (pdata
->imlData
.himl
&& ImageList_GetIconSize(pdata
->imlData
.himl
, &ImageSize
.cx
, &ImageSize
.cy
))
354 ImageSize
.cx
+= pdata
->imlData
.margin
.left
+ pdata
->imlData
.margin
.right
;
355 ImageSize
.cy
+= pdata
->imlData
.margin
.top
+ pdata
->imlData
.margin
.bottom
;
359 ImageSize
.cx
= ImageSize
.cy
= 0;
364 RECT rcContents
= {0};
365 RECT rcButtonExtent
= {0};
366 rcContents
.right
= ImageSize
.cx
+ TextSize
.cx
;
367 rcContents
.bottom
= max(ImageSize
.cy
, TextSize
.cy
);
368 GetThemeBackgroundExtent(theme
, hdc
, BP_PUSHBUTTON
, PBS_NORMAL
, &rcContents
, &rcButtonExtent
);
369 ERR("rcContents: %d, %d, %d, %d\n", rcContents
.left
, rcContents
.top
, rcContents
.right
, rcContents
.bottom
);
370 ERR("rcButtonExtent: %d, %d, %d, %d\n", rcButtonExtent
.left
, rcButtonExtent
.top
, rcButtonExtent
.right
, rcButtonExtent
.bottom
);
371 ButtonSize
.cx
= abs(rcButtonExtent
.right
- rcButtonExtent
.left
) + 1;
372 ButtonSize
.cy
= abs(rcButtonExtent
.bottom
- rcButtonExtent
.top
) - 1;
376 ButtonSize
.cx
= ImageSize
.cx
+ TextSize
.cx
+ 5;
377 ButtonSize
.cy
= max(ImageSize
.cy
, TextSize
.cy
+ 7);
387 HeapFree( GetProcessHeap(), 0, text
);
389 ReleaseDC(hwnd
, hdc
);
397 /* retrieve the button text; returned buffer must be freed by caller */
398 inline WCHAR
*get_button_text( HWND hwnd
)
401 WCHAR
*buffer
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) );
402 if (buffer
) InternalGetWindowText( hwnd
, buffer
, len
+ 1 );
407 /* Retrieve the UI state for the control */
408 static BOOL
button_update_uistate(HWND hwnd
, BOOL unicode
)
410 LONG flags
, prevflags
;
413 flags
= DefWindowProcW(hwnd
, WM_QUERYUISTATE
, 0, 0);
415 flags
= DefWindowProcA(hwnd
, WM_QUERYUISTATE
, 0, 0);
417 prevflags
= get_ui_state(hwnd
);
419 if (prevflags
!= flags
)
421 set_ui_state(hwnd
, flags
);
429 /***********************************************************************
430 * ButtonWndProc_common
432 LRESULT WINAPI
ButtonWndProc_common(HWND hWnd
, UINT uMsg
,
433 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
437 LONG style
= GetWindowLongPtrW( hWnd
, GWL_STYLE
);
438 UINT btn_type
= get_button_type( style
);
441 #if defined(__REACTOS__) && defined(_USER32_)
444 pWnd
= ValidateHwnd(hWnd
);
449 NtUserSetWindowFNID(hWnd
, FNID_BUTTON
);
453 if (pWnd
->fnid
!= FNID_BUTTON
)
455 ERR("Wrong window class for Button! fnId 0x%x\n",pWnd
->fnid
);
463 if (!IsWindow( hWnd
)) return 0;
466 pt
.x
= (short)LOWORD(lParam
);
467 pt
.y
= (short)HIWORD(lParam
);
474 PBUTTON_DATA data
= HeapAlloc( GetProcessHeap(), 0, sizeof(BUTTON_DATA
) );
477 ERR("Failed to alloc internal button data\n");
481 memset(data
, 0, sizeof(BUTTON_DATA
));
482 SetRect(&data
->rcTextMargin
, 1,1,1,1);
484 _SetButtonData(hWnd
, data
);
489 PBUTTON_DATA data
= _GetButtonData(hWnd
);
495 HeapFree( GetProcessHeap(), 0, data
);
496 _SetButtonData(hWnd
, NULL
);
499 OpenThemeData(hWnd
, WC_BUTTONW
);
502 CloseThemeData (GetWindowTheme(hWnd
));
504 case WM_THEMECHANGED
:
505 CloseThemeData (GetWindowTheme(hWnd
));
506 OpenThemeData(hWnd
, WC_BUTTONW
);
507 InvalidateRect(hWnd
, NULL
, FALSE
);
511 int state
= (int)SendMessageW(hWnd
, BM_GETSTATE
, 0, 0);
512 set_button_state(hWnd
, state
|BST_HOT
);
513 InvalidateRect(hWnd
, NULL
, FALSE
);
518 int state
= (int)SendMessageW(hWnd
, BM_GETSTATE
, 0, 0);
519 set_button_state(hWnd
, state
&(~BST_HOT
));
520 InvalidateRect(hWnd
, NULL
, FALSE
);
525 TRACKMOUSEEVENT mouse_event
;
526 mouse_event
.cbSize
= sizeof(TRACKMOUSEEVENT
);
527 mouse_event
.dwFlags
= TME_QUERY
;
528 if(!TrackMouseEvent(&mouse_event
) || !(mouse_event
.dwFlags
&(TME_HOVER
|TME_LEAVE
)))
530 mouse_event
.dwFlags
= TME_HOVER
|TME_LEAVE
;
531 mouse_event
.hwndTrack
= hWnd
;
532 mouse_event
.dwHoverTime
= 1;
533 TrackMouseEvent(&mouse_event
);
537 case BCM_GETTEXTMARGIN
:
539 RECT
* prc
= (RECT
*)lParam
;
540 PBUTTON_DATA data
= _GetButtonData(hWnd
);
543 *prc
= data
->rcTextMargin
;
546 case BCM_SETTEXTMARGIN
:
548 RECT
* prc
= (RECT
*)lParam
;
549 PBUTTON_DATA data
= _GetButtonData(hWnd
);
552 data
->rcTextMargin
= *prc
;
555 case BCM_SETIMAGELIST
:
557 BUTTON_IMAGELIST
* pimldata
= (BUTTON_IMAGELIST
*)lParam
;
558 PBUTTON_DATA data
= _GetButtonData(hWnd
);
559 if (!data
|| !pimldata
|| !pimldata
->himl
)
561 data
->imlData
= *pimldata
;
564 case BCM_GETIMAGELIST
:
566 BUTTON_IMAGELIST
* pimldata
= (BUTTON_IMAGELIST
*)lParam
;
567 PBUTTON_DATA data
= _GetButtonData(hWnd
);
568 if (!data
|| !pimldata
)
570 *pimldata
= data
->imlData
;
573 case BCM_GETIDEALSIZE
:
575 HTHEME theme
= GetWindowTheme(hWnd
);
577 SIZE
* pSize
= (SIZE
*)lParam
;
579 if (btn_type
== BS_PUSHBUTTON
||
580 btn_type
== BS_DEFPUSHBUTTON
||
581 btn_type
== BS_USERBUTTON
)
583 ret
= BUTTON_GetIdealSize(theme
, hWnd
, pSize
);
588 GetClientRect(hWnd
, &rect
);
589 pSize
->cx
= rect
.right
;
590 pSize
->cy
= rect
.bottom
;
597 if (!_GetButtonData(hWnd
))
600 return unicode
? DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
) :
601 DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
612 case BS_PUSHBUTTON
: return DLGC_BUTTON
| DLGC_UNDEFPUSHBUTTON
;
613 case BS_DEFPUSHBUTTON
: return DLGC_BUTTON
| DLGC_DEFPUSHBUTTON
;
615 case BS_AUTORADIOBUTTON
: return DLGC_BUTTON
| DLGC_RADIOBUTTON
;
616 case BS_GROUPBOX
: return DLGC_STATIC
;
617 default: return DLGC_BUTTON
;
621 paint_button( hWnd
, btn_type
, ODA_DRAWENTIRE
);
625 if (btn_type
>= MAX_BTN_TYPE
)
626 return -1; /* abort */
628 /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
629 if (btn_type
== BS_USERBUTTON
)
631 style
= (style
& ~BS_TYPEMASK
) | BS_PUSHBUTTON
;
633 NtUserAlterWindowStyle(hWnd
, GWL_STYLE
, style
);
635 WIN_SetStyle( hWnd
, style
, BS_TYPEMASK
& ~style
);
638 set_button_state( hWnd
, BST_UNCHECKED
);
640 button_update_uistate( hWnd
, unicode
);
644 #if defined(__REACTOS__) && defined(_USER32_)
646 NtUserSetWindowFNID(hWnd
, FNID_DESTROY
);
651 if (btn_type
== BS_OWNERDRAW
)
653 HDC hdc
= (HDC
)wParam
;
656 HWND parent
= GetParent(hWnd
);
657 if (!parent
) parent
= hWnd
;
658 #if defined(__REACTOS__) && defined(_USER32_)
659 hBrush
= GetControlColor( parent
, hWnd
, hdc
, WM_CTLCOLORBTN
);
661 hBrush
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORBTN
, (WPARAM
)hdc
, (LPARAM
)hWnd
);
662 if (!hBrush
) /* did the app forget to call defwindowproc ? */
663 hBrush
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORBTN
,
664 (WPARAM
)hdc
, (LPARAM
)hWnd
);
666 GetClientRect(hWnd
, &rc
);
667 FillRect(hdc
, &rc
, hBrush
);
675 HDC hdc
= wParam
? (HDC
)wParam
: BeginPaint( hWnd
, &ps
);
677 HTHEME theme
= GetWindowTheme(hWnd
);
678 if (theme
&& BUTTON_PaintWithTheme(theme
, hWnd
, hdc
, uMsg
== WM_PRINTCLIENT
? lParam
: 0))
680 if ( !wParam
) EndPaint( hWnd
, &ps
);
684 if (btnPaintFunc
[btn_type
])
686 int nOldMode
= SetBkMode( hdc
, OPAQUE
);
687 (btnPaintFunc
[btn_type
])( hWnd
, hdc
, ODA_DRAWENTIRE
);
688 SetBkMode(hdc
, nOldMode
); /* reset painting mode */
690 if ( !wParam
) EndPaint( hWnd
, &ps
);
695 if (wParam
== VK_SPACE
)
697 SendMessageW( hWnd
, BM_SETSTATE
, TRUE
, 0 );
698 set_button_state( hWnd
, get_button_state( hWnd
) | BUTTON_BTNPRESSED
);
703 case WM_LBUTTONDBLCLK
:
704 if(style
& BS_NOTIFY
||
705 btn_type
== BS_RADIOBUTTON
||
706 btn_type
== BS_USERBUTTON
||
707 btn_type
== BS_OWNERDRAW
)
709 BUTTON_NOTIFY_PARENT(hWnd
, BN_DOUBLECLICKED
);
716 set_button_state( hWnd
, get_button_state( hWnd
) | BUTTON_BTNPRESSED
);
717 SendMessageW( hWnd
, BM_SETSTATE
, TRUE
, 0 );
721 if (wParam
!= VK_SPACE
)
726 BOOL TellParent
= FALSE
; //// ReactOS see note below.
728 state
= get_button_state( hWnd
);
729 if (!(state
& BUTTON_BTNPRESSED
)) break;
730 state
&= BUTTON_NSTATES
;
731 set_button_state( hWnd
, state
);
732 if (!(state
& BST_PUSHED
))
737 SendMessageW( hWnd
, BM_SETSTATE
, FALSE
, 0 );
738 GetClientRect( hWnd
, &rect
);
739 if (uMsg
== WM_KEYUP
|| PtInRect( &rect
, pt
))
741 state
= get_button_state( hWnd
);
744 case BS_AUTOCHECKBOX
:
745 SendMessageW( hWnd
, BM_SETCHECK
, !(state
& BST_CHECKED
), 0 );
747 case BS_AUTORADIOBUTTON
:
748 SendMessageW( hWnd
, BM_SETCHECK
, TRUE
, 0 );
751 SendMessageW( hWnd
, BM_SETCHECK
,
752 (state
& BST_INDETERMINATE
) ? 0 : ((state
& 3) + 1), 0 );
756 TellParent
= TRUE
; // <---- Fix CORE-10194, Notify parent after capture is released.
759 BUTTON_NOTIFY_PARENT(hWnd
, BN_CLICKED
);
764 if (TellParent
) BUTTON_NOTIFY_PARENT(hWnd
, BN_CLICKED
);
773 case WM_CAPTURECHANGED
:
774 TRACE("WM_CAPTURECHANGED %p\n", hWnd
);
775 if (hWnd
== (HWND
)lParam
) break;
776 state
= get_button_state( hWnd
);
777 if (state
& BUTTON_BTNPRESSED
)
779 state
&= BUTTON_NSTATES
;
780 set_button_state( hWnd
, state
);
781 if (state
& BST_PUSHED
) SendMessageW( hWnd
, BM_SETSTATE
, FALSE
, 0 );
786 if ((wParam
& MK_LBUTTON
) && GetCapture() == hWnd
)
788 GetClientRect( hWnd
, &rect
);
789 SendMessageW( hWnd
, BM_SETSTATE
, PtInRect(&rect
, pt
), 0 );
795 /* Clear an old text here as Windows does */
798 // wine Bug: http://bugs.winehq.org/show_bug.cgi?id=25790
799 // Patch: http://source.winehq.org/patches/data/70889
800 // By: Alexander LAW, Replicate Windows behavior of WM_SETTEXT handler regarding WM_CTLCOLOR*
803 if (style
& WS_VISIBLE
)
805 if (IsWindowVisible(hWnd
))
808 HDC hdc
= GetDC(hWnd
);
811 HWND parent
= GetParent(hWnd
);
812 UINT message
= (btn_type
== BS_PUSHBUTTON
||
813 btn_type
== BS_DEFPUSHBUTTON
||
814 btn_type
== BS_PUSHLIKE
||
815 btn_type
== BS_USERBUTTON
||
816 btn_type
== BS_OWNERDRAW
) ?
817 WM_CTLCOLORBTN
: WM_CTLCOLORSTATIC
;
819 if (!parent
) parent
= hWnd
;
820 #if defined(__REACTOS__) && defined(_USER32_)
821 hbrush
= GetControlColor(parent
, hWnd
, hdc
, message
);
823 hbrush
= (HBRUSH
)SendMessageW(parent
, message
,
824 (WPARAM
)hdc
, (LPARAM
)hWnd
);
825 if (!hbrush
) /* did the app forget to call DefWindowProc ? */
826 hbrush
= (HBRUSH
)DefWindowProcW(parent
, message
,
827 (WPARAM
)hdc
, (LPARAM
)hWnd
);
830 GetClientRect(hWnd
, &client
);
832 /* FIXME: check other BS_* handlers */
833 if (btn_type
== BS_GROUPBOX
)
834 InflateRect(&rc
, -7, 1); /* GB_Paint does this */
835 BUTTON_CalcLabelRect(hWnd
, hdc
, &rc
);
836 /* Clip by client rect bounds */
837 if (rc
.right
> client
.right
) rc
.right
= client
.right
;
838 if (rc
.bottom
> client
.bottom
) rc
.bottom
= client
.bottom
;
839 FillRect(hdc
, &rc
, hbrush
);
840 ReleaseDC(hWnd
, hdc
);
843 if (unicode
) DefWindowProcW( hWnd
, WM_SETTEXT
, wParam
, lParam
);
844 else DefWindowProcA( hWnd
, WM_SETTEXT
, wParam
, lParam
);
845 if (btn_type
== BS_GROUPBOX
) /* Yes, only for BS_GROUPBOX */
846 InvalidateRect( hWnd
, NULL
, TRUE
);
848 paint_button( hWnd
, btn_type
, ODA_DRAWENTIRE
);
849 return 1; /* success. FIXME: check text length */
853 set_button_font( hWnd
, (HFONT
)wParam
);
854 if (lParam
) InvalidateRect(hWnd
, NULL
, TRUE
);
858 return (LRESULT
)get_button_font( hWnd
);
861 TRACE("WM_SETFOCUS %p\n",hWnd
);
862 set_button_state( hWnd
, get_button_state(hWnd
) | BST_FOCUS
);
864 if (btn_type
!= BS_OWNERDRAW
)
865 InvalidateRect(hWnd
, NULL
, FALSE
);
868 paint_button( hWnd
, btn_type
, ODA_FOCUS
);
869 if (style
& BS_NOTIFY
)
870 BUTTON_NOTIFY_PARENT(hWnd
, BN_SETFOCUS
);
874 TRACE("WM_KILLFOCUS %p\n",hWnd
);
875 state
= get_button_state( hWnd
);
876 set_button_state( hWnd
, state
& ~BST_FOCUS
);
878 paint_button( hWnd
, btn_type
, ODA_FOCUS
);
881 if ((state
& BUTTON_BTNPRESSED
) && GetCapture() == hWnd
)
883 if (style
& BS_NOTIFY
)
884 BUTTON_NOTIFY_PARENT(hWnd
, BN_KILLFOCUS
);
886 InvalidateRect( hWnd
, NULL
, FALSE
);
889 case WM_SYSCOLORCHANGE
:
890 InvalidateRect( hWnd
, NULL
, FALSE
);
894 btn_type
= wParam
& BS_TYPEMASK
;
895 style
= (style
& ~BS_TYPEMASK
) | btn_type
;
897 NtUserAlterWindowStyle(hWnd
, GWL_STYLE
, style
);
899 WIN_SetStyle( hWnd
, style
, BS_TYPEMASK
& ~style
);
902 /* Only redraw if lParam flag is set.*/
904 InvalidateRect( hWnd
, NULL
, TRUE
);
910 state
= get_button_state(hWnd
);
911 if (state
& BUTTON_BMCLICK
)
913 set_button_state(hWnd
, state
| BUTTON_BMCLICK
); // Tracked in STATE_GWL_OFFSET.
915 SendMessageW( hWnd
, WM_LBUTTONDOWN
, 0, 0 );
916 SendMessageW( hWnd
, WM_LBUTTONUP
, 0, 0 );
918 state
= get_button_state(hWnd
);
919 if (!(state
& BUTTON_BMCLICK
)) break;
920 state
&= ~BUTTON_BMCLICK
;
921 set_button_state(hWnd
, state
);
926 /* Check that image format matches button style */
927 switch (style
& (BS_BITMAP
|BS_ICON
))
930 if (wParam
!= IMAGE_BITMAP
) return 0;
933 if (wParam
!= IMAGE_ICON
) return 0;
939 oldHbitmap
= (HBITMAP
)SetWindowLongPtrW( hWnd
, HIMAGE_GWL_OFFSET
, lParam
);
941 oldHbitmap
= (HBITMAP
)set_button_image(hWnd
, lParam
);
943 InvalidateRect( hWnd
, NULL
, FALSE
);
944 return (LRESULT
)oldHbitmap
;
948 return GetWindowLongPtrW( hWnd
, HIMAGE_GWL_OFFSET
);
950 return get_button_image(hWnd
);
954 return get_button_state( hWnd
) & 3;
957 if (wParam
> maxCheckState
[btn_type
]) wParam
= maxCheckState
[btn_type
];
958 state
= get_button_state( hWnd
);
959 if ((btn_type
== BS_RADIOBUTTON
) || (btn_type
== BS_AUTORADIOBUTTON
))
962 if (wParam
) style
|= WS_TABSTOP
;
963 else style
&= ~WS_TABSTOP
;
964 NtUserAlterWindowStyle(hWnd
, GWL_STYLE
, style
);
966 if (wParam
) WIN_SetStyle( hWnd
, WS_TABSTOP
, 0 );
967 else WIN_SetStyle( hWnd
, 0, WS_TABSTOP
);
970 if ((state
& 3) != wParam
)
972 set_button_state( hWnd
, (state
& ~3) | wParam
);
974 paint_button( hWnd
, btn_type
, ODA_SELECT
);
976 InvalidateRect(hWnd
, NULL
, FALSE
);
979 if ((btn_type
== BS_AUTORADIOBUTTON
) && (wParam
== BST_CHECKED
) && (style
& WS_CHILD
))
980 BUTTON_CheckAutoRadioButton( hWnd
);
984 return get_button_state( hWnd
);
987 state
= get_button_state( hWnd
);
989 set_button_state( hWnd
, state
| BST_PUSHED
);
991 set_button_state( hWnd
, state
& ~BST_PUSHED
);
994 paint_button( hWnd
, btn_type
, ODA_SELECT
);
996 InvalidateRect(hWnd
, NULL
, FALSE
);
1001 case WM_UPDATEUISTATE
:
1003 DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
1005 DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
1007 if (button_update_uistate(hWnd
, unicode
))
1008 paint_button( hWnd
, btn_type
, ODA_DRAWENTIRE
);
1013 if(btn_type
== BS_GROUPBOX
) return HTTRANSPARENT
;
1016 return unicode
? DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
) :
1017 DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
1024 /***********************************************************************
1026 * The button window procedure. This is just a wrapper which locks
1027 * the passed HWND and calls the real window procedure (with a WND*
1028 * pointer pointing to the locked windowstructure).
1030 LRESULT WINAPI
ButtonWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1032 if (!IsWindow(hWnd
)) return 0;
1033 return ButtonWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
1036 /***********************************************************************
1039 LRESULT WINAPI
ButtonWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1041 if (!IsWindow(hWnd
)) return 0;
1042 return ButtonWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
1045 #endif /* __REACTOS__ */
1047 /**********************************************************************
1048 * Convert button styles to flags used by DrawText.
1050 static UINT
BUTTON_BStoDT( DWORD style
, DWORD ex_style
)
1052 UINT dtStyle
= DT_NOCLIP
; /* We use SelectClipRgn to limit output */
1054 /* "Convert" pushlike buttons to pushbuttons */
1055 if (style
& BS_PUSHLIKE
)
1056 style
&= ~BS_TYPEMASK
;
1058 if (!(style
& BS_MULTILINE
))
1059 dtStyle
|= DT_SINGLELINE
;
1061 dtStyle
|= DT_WORDBREAK
;
1063 switch (style
& BS_CENTER
)
1065 case BS_LEFT
: /* DT_LEFT is 0 */ break;
1066 case BS_RIGHT
: dtStyle
|= DT_RIGHT
; break;
1067 case BS_CENTER
: dtStyle
|= DT_CENTER
; break;
1069 /* Pushbutton's text is centered by default */
1070 if (get_button_type(style
) <= BS_DEFPUSHBUTTON
) dtStyle
|= DT_CENTER
;
1071 /* all other flavours have left aligned text */
1074 if (ex_style
& WS_EX_RIGHT
) dtStyle
= DT_RIGHT
| (dtStyle
& ~(DT_LEFT
| DT_CENTER
));
1076 /* DrawText ignores vertical alignment for multiline text,
1077 * but we use these flags to align label manually.
1079 if (get_button_type(style
) != BS_GROUPBOX
)
1081 switch (style
& BS_VCENTER
)
1083 case BS_TOP
: /* DT_TOP is 0 */ break;
1084 case BS_BOTTOM
: dtStyle
|= DT_BOTTOM
; break;
1085 case BS_VCENTER
: /* fall through */
1086 default: dtStyle
|= DT_VCENTER
; break;
1090 /* GroupBox's text is always single line and is top aligned. */
1091 dtStyle
|= DT_SINGLELINE
;
1096 /**********************************************************************
1097 * BUTTON_CalcLabelRect
1099 * Calculates label's rectangle depending on button style.
1101 * Returns flags to be passed to DrawText.
1102 * Calculated rectangle doesn't take into account button state
1103 * (pushed, etc.). If there is nothing to draw (no text/image) output
1104 * rectangle is empty, and return value is (UINT)-1.
1106 static UINT
BUTTON_CalcLabelRect(HWND hwnd
, HDC hdc
, RECT
*rc
)
1108 LONG style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
1109 LONG ex_style
= GetWindowLongPtrW( hwnd
, GWL_EXSTYLE
);
1113 UINT dtStyle
= BUTTON_BStoDT( style
, ex_style
);
1117 /* Calculate label rectangle according to label type */
1118 switch (style
& (BS_ICON
|BS_BITMAP
))
1122 HFONT hFont
, hPrevFont
= 0;
1124 if (!(text
= get_button_text( hwnd
))) goto empty_rect
;
1127 HeapFree( GetProcessHeap(), 0, text
);
1131 if ((hFont
= get_button_font( hwnd
))) hPrevFont
= SelectObject( hdc
, hFont
);
1132 DrawTextW(hdc
, text
, -1, &r
, dtStyle
| DT_CALCRECT
);
1133 if (hPrevFont
) SelectObject( hdc
, hPrevFont
);
1134 HeapFree( GetProcessHeap(), 0, text
);
1136 if (get_ui_state(hwnd
) & UISF_HIDEACCEL
)
1137 dtStyle
|= DT_HIDEPREFIX
;
1144 if (!GetIconInfo((HICON
)GetWindowLongPtrW( hwnd
, HIMAGE_GWL_OFFSET
), &iconInfo
))
1146 if (!GetIconInfo((HICON
)get_button_image(hwnd
), &iconInfo
))
1150 GetObjectW (iconInfo
.hbmColor
, sizeof(BITMAP
), &bm
);
1152 r
.right
= r
.left
+ bm
.bmWidth
;
1153 r
.bottom
= r
.top
+ bm
.bmHeight
;
1155 DeleteObject(iconInfo
.hbmColor
);
1156 DeleteObject(iconInfo
.hbmMask
);
1161 if (!GetObjectW( (HANDLE
)GetWindowLongPtrW( hwnd
, HIMAGE_GWL_OFFSET
), sizeof(BITMAP
), &bm
))
1163 if (!GetObjectW( (HANDLE
)get_button_image(hwnd
), sizeof(BITMAP
), &bm
))
1167 r
.right
= r
.left
+ bm
.bmWidth
;
1168 r
.bottom
= r
.top
+ bm
.bmHeight
;
1178 /* Position label inside bounding rectangle according to
1179 * alignment flags. (calculated rect is always left-top aligned).
1180 * If label is aligned to any side - shift label in opposite
1181 * direction to leave extra space for focus rectangle.
1183 switch (dtStyle
& (DT_CENTER
|DT_RIGHT
))
1185 case DT_LEFT
: r
.left
++; r
.right
++; break;
1186 case DT_CENTER
: n
= r
.right
- r
.left
;
1187 r
.left
= rc
->left
+ ((rc
->right
- rc
->left
) - n
) / 2;
1188 r
.right
= r
.left
+ n
; break;
1189 case DT_RIGHT
: n
= r
.right
- r
.left
;
1190 r
.right
= rc
->right
- 1;
1191 r
.left
= r
.right
- n
;
1195 switch (dtStyle
& (DT_VCENTER
|DT_BOTTOM
))
1197 case DT_TOP
: r
.top
++; r
.bottom
++; break;
1198 case DT_VCENTER
: n
= r
.bottom
- r
.top
;
1199 r
.top
= rc
->top
+ ((rc
->bottom
- rc
->top
) - n
) / 2;
1200 r
.bottom
= r
.top
+ n
; break;
1201 case DT_BOTTOM
: n
= r
.bottom
- r
.top
;
1202 r
.bottom
= rc
->bottom
- 1;
1203 r
.top
= r
.bottom
- n
;
1212 /**********************************************************************
1213 * BUTTON_DrawTextCallback
1215 * Callback function used by DrawStateW function.
1217 static BOOL CALLBACK
BUTTON_DrawTextCallback(HDC hdc
, LPARAM lp
, WPARAM wp
, int cx
, int cy
)
1222 SetRect(&rc
, 0, 0, cx
, cy
);
1223 DrawTextW(hdc
, (LPCWSTR
)lp
, -1, &rc
, (UINT
)wp
);
1226 HWND hwnd
= (HWND
)lp
;
1228 PBUTTON_DATA pdata
= _GetButtonData(hwnd
);
1232 if (!(text
= get_button_text( hwnd
))) return TRUE
;
1234 SetRect(&rc
, 0, 0, cx
, cy
);
1236 if (pdata
->imlData
.himl
&& ImageList_GetIconSize(pdata
->imlData
.himl
, &ImageSize
.cx
, &ImageSize
.cy
))
1238 int left
= pdata
->imlData
.margin
.left
;
1239 int top
= (cy
- ImageSize
.cy
) / 2;
1240 rc
.left
+= pdata
->imlData
.margin
.left
+ pdata
->imlData
.margin
.right
+ ImageSize
.cy
;
1241 ImageList_Draw(pdata
->imlData
.himl
, 0, hdc
, left
, top
, 0);
1244 DrawTextW(hdc
, text
, -1, &rc
, (UINT
)wp
);
1250 /**********************************************************************
1253 * Common function for drawing button label.
1255 static void BUTTON_DrawLabel(HWND hwnd
, HDC hdc
, UINT dtFlags
, const RECT
*rc
)
1257 DRAWSTATEPROC lpOutputProc
= NULL
;
1261 UINT flags
= IsWindowEnabled(hwnd
) ? DSS_NORMAL
: DSS_DISABLED
;
1262 LONG state
= get_button_state( hwnd
);
1263 LONG style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
1266 /* FIXME: To draw disabled label in Win31 look-and-feel, we probably
1267 * must use DSS_MONO flag and COLOR_GRAYTEXT brush (or maybe DSS_UNION).
1268 * I don't have Win31 on hand to verify that, so I leave it as is.
1271 if ((style
& BS_PUSHLIKE
) && (state
& BST_INDETERMINATE
))
1273 hbr
= GetSysColorBrush(COLOR_GRAYTEXT
);
1277 switch (style
& (BS_ICON
|BS_BITMAP
))
1280 /* DST_COMPLEX -- is 0 */
1281 lpOutputProc
= BUTTON_DrawTextCallback
;
1283 if (!(text
= get_button_text( hwnd
))) return;
1289 wp
= (WPARAM
)dtFlags
;
1292 if (dtFlags
& DT_HIDEPREFIX
)
1293 flags
|= DSS_HIDEPREFIX
;
1300 lp
= GetWindowLongPtrW( hwnd
, HIMAGE_GWL_OFFSET
);
1302 lp
= get_button_image(hwnd
);
1307 flags
|= DST_BITMAP
;
1309 lp
= GetWindowLongPtrW( hwnd
, HIMAGE_GWL_OFFSET
);
1311 lp
= get_button_image(hwnd
);
1319 DrawStateW(hdc
, hbr
, lpOutputProc
, lp
, wp
, rc
->left
, rc
->top
,
1320 rc
->right
- rc
->left
, rc
->bottom
- rc
->top
, flags
);
1321 HeapFree( GetProcessHeap(), 0, text
);
1324 /**********************************************************************
1325 * Push Button Functions
1327 static void PB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1330 UINT dtFlags
, uState
;
1334 COLORREF oldTxtColor
;
1336 LONG state
= get_button_state( hwnd
);
1337 LONG style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
1338 BOOL pushedState
= (state
& BST_PUSHED
);
1342 GetClientRect( hwnd
, &rc
);
1344 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
1345 if ((hFont
= get_button_font( hwnd
))) SelectObject( hDC
, hFont
);
1346 parent
= GetParent(hwnd
);
1347 if (!parent
) parent
= hwnd
;
1348 #if defined(__REACTOS__) && defined(_USER32_)
1349 GetControlColor( parent
, hwnd
, hDC
, WM_CTLCOLORBTN
);
1351 SendMessageW( parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)hwnd
);
1354 hrgn
= set_control_clipping( hDC
, &rc
);
1356 hOldPen
= SelectObject(hDC
, GetStockObject(DC_PEN
));
1357 SetDCPenColor(hDC
, GetSysColor(COLOR_WINDOWFRAME
));
1359 hOldPen
= SelectObject(hDC
, SYSCOLOR_GetPen(COLOR_WINDOWFRAME
));
1361 hOldBrush
= SelectObject(hDC
,GetSysColorBrush(COLOR_BTNFACE
));
1362 oldBkMode
= SetBkMode(hDC
, TRANSPARENT
);
1364 if (get_button_type(style
) == BS_DEFPUSHBUTTON
)
1366 if (action
!= ODA_FOCUS
)
1367 Rectangle(hDC
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1368 InflateRect( &rc
, -1, -1 );
1371 /* completely skip the drawing if only focus has changed */
1372 if (action
== ODA_FOCUS
) goto draw_focus
;
1374 uState
= DFCS_BUTTONPUSH
;
1376 if (style
& BS_FLAT
)
1377 uState
|= DFCS_MONO
;
1378 else if (pushedState
)
1380 if (get_button_type(style
) == BS_DEFPUSHBUTTON
)
1381 uState
|= DFCS_FLAT
;
1383 uState
|= DFCS_PUSHED
;
1386 if (state
& (BST_CHECKED
| BST_INDETERMINATE
))
1387 uState
|= DFCS_CHECKED
;
1389 DrawFrameControl( hDC
, &rc
, DFC_BUTTON
, uState
);
1391 /* draw button label */
1393 dtFlags
= BUTTON_CalcLabelRect(hwnd
, hDC
, &r
);
1395 if (dtFlags
== (UINT
)-1L)
1399 OffsetRect(&r
, 1, 1);
1401 oldTxtColor
= SetTextColor( hDC
, GetSysColor(COLOR_BTNTEXT
) );
1403 BUTTON_DrawLabel(hwnd
, hDC
, dtFlags
, &r
);
1405 SetTextColor( hDC
, oldTxtColor
);
1408 if (action
== ODA_FOCUS
|| (state
& BST_FOCUS
))
1411 if (!(get_ui_state(hwnd
) & UISF_HIDEFOCUS
))
1414 InflateRect( &rc
, -2, -2 );
1415 DrawFocusRect( hDC
, &rc
);
1422 SelectObject( hDC
, hOldPen
);
1423 SelectObject( hDC
, hOldBrush
);
1424 SetBkMode(hDC
, oldBkMode
);
1425 SelectClipRgn( hDC
, hrgn
);
1426 if (hrgn
) DeleteObject( hrgn
);
1429 /**********************************************************************
1430 * Check Box & Radio Button Functions
1433 static void CB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1435 RECT rbox
, rtext
, client
;
1437 int delta
, text_offset
, checkBoxWidth
, checkBoxHeight
;
1440 LONG state
= get_button_state( hwnd
);
1441 LONG style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
1442 LONG ex_style
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
1446 if (style
& BS_PUSHLIKE
)
1448 PB_Paint( hwnd
, hDC
, action
);
1452 GetClientRect(hwnd
, &client
);
1453 rbox
= rtext
= client
;
1455 checkBoxWidth
= 12 * GetDeviceCaps( hDC
, LOGPIXELSX
) / 96 + 1;
1456 checkBoxHeight
= 12 * GetDeviceCaps( hDC
, LOGPIXELSY
) / 96 + 1;
1458 if ((hFont
= get_button_font( hwnd
))) SelectObject( hDC
, hFont
);
1459 GetCharWidthW( hDC
, '0', '0', &text_offset
);
1462 parent
= GetParent(hwnd
);
1463 if (!parent
) parent
= hwnd
;
1464 #if defined(__REACTOS__) && defined(_USER32_)
1465 hBrush
= GetControlColor(parent
, hwnd
, hDC
, WM_CTLCOLORSTATIC
);
1467 hBrush
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORSTATIC
,
1468 (WPARAM
)hDC
, (LPARAM
)hwnd
);
1469 if (!hBrush
) /* did the app forget to call defwindowproc ? */
1470 hBrush
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORSTATIC
,
1471 (WPARAM
)hDC
, (LPARAM
)hwnd
);
1473 hrgn
= set_control_clipping( hDC
, &client
);
1475 if (style
& BS_LEFTTEXT
|| ex_style
& WS_EX_RIGHT
)
1477 /* magic +4 is what CTL3D expects */
1479 rtext
.right
-= checkBoxWidth
+ text_offset
;;
1480 rbox
.left
= rbox
.right
- checkBoxWidth
;
1484 rtext
.left
+= checkBoxWidth
+ text_offset
;;
1485 rbox
.right
= checkBoxWidth
;
1488 /* Since WM_ERASEBKGND does nothing, first prepare background */
1489 if (action
== ODA_SELECT
) FillRect( hDC
, &rbox
, hBrush
);
1490 if (action
== ODA_DRAWENTIRE
) FillRect( hDC
, &client
, hBrush
);
1494 dtFlags
= BUTTON_CalcLabelRect(hwnd
, hDC
, &rtext
);
1496 /* Only adjust rbox when rtext is valid */
1497 if (dtFlags
!= (UINT
)-1L)
1499 rbox
.top
= rtext
.top
;
1500 rbox
.bottom
= rtext
.bottom
;
1503 /* Draw the check-box bitmap */
1504 if (action
== ODA_DRAWENTIRE
|| action
== ODA_SELECT
)
1508 if ((get_button_type(style
) == BS_RADIOBUTTON
) ||
1509 (get_button_type(style
) == BS_AUTORADIOBUTTON
)) flags
= DFCS_BUTTONRADIO
;
1510 else if (state
& BST_INDETERMINATE
) flags
= DFCS_BUTTON3STATE
;
1511 else flags
= DFCS_BUTTONCHECK
;
1513 if (state
& (BST_CHECKED
| BST_INDETERMINATE
)) flags
|= DFCS_CHECKED
;
1514 if (state
& BST_PUSHED
) flags
|= DFCS_PUSHED
;
1516 if (style
& WS_DISABLED
) flags
|= DFCS_INACTIVE
;
1518 /* rbox must have the correct height */
1519 delta
= rbox
.bottom
- rbox
.top
- checkBoxHeight
;
1521 if (style
& BS_TOP
) {
1523 rbox
.bottom
= rbox
.top
+ checkBoxHeight
;
1525 rbox
.top
-= -delta
/2 + 1;
1526 rbox
.bottom
= rbox
.top
+ checkBoxHeight
;
1528 } else if (style
& BS_BOTTOM
) {
1530 rbox
.top
= rbox
.bottom
- checkBoxHeight
;
1532 rbox
.bottom
+= -delta
/2 + 1;
1533 rbox
.top
= rbox
.bottom
- checkBoxHeight
;
1535 } else { /* Default */
1537 int ofs
= (delta
/ 2);
1538 rbox
.bottom
-= ofs
+ 1;
1539 rbox
.top
= rbox
.bottom
- checkBoxHeight
;
1540 } else if (delta
< 0) {
1541 int ofs
= (-delta
/ 2);
1542 rbox
.top
-= ofs
+ 1;
1543 rbox
.bottom
= rbox
.top
+ checkBoxHeight
;
1547 DrawFrameControl( hDC
, &rbox
, DFC_BUTTON
, flags
);
1550 if (dtFlags
== (UINT
)-1L) /* Noting to draw */
1553 if (action
== ODA_DRAWENTIRE
)
1554 BUTTON_DrawLabel(hwnd
, hDC
, dtFlags
, &rtext
);
1557 if (action
== ODA_FOCUS
|| (state
& BST_FOCUS
))
1560 if (!(get_ui_state(hwnd
) & UISF_HIDEFOCUS
))
1565 IntersectRect(&rtext
, &rtext
, &client
);
1566 DrawFocusRect( hDC
, &rtext
);
1571 SelectClipRgn( hDC
, hrgn
);
1572 if (hrgn
) DeleteObject( hrgn
);
1576 /**********************************************************************
1577 * BUTTON_CheckAutoRadioButton
1579 * hwnd is checked, uncheck every other auto radio button in group
1581 static void BUTTON_CheckAutoRadioButton( HWND hwnd
)
1583 HWND parent
, sibling
, start
;
1585 parent
= GetParent(hwnd
);
1586 /* make sure that starting control is not disabled or invisible */
1587 start
= sibling
= GetNextDlgGroupItem( parent
, hwnd
, TRUE
);
1590 if (!sibling
) break;
1591 if ((hwnd
!= sibling
) &&
1592 ((GetWindowLongPtrW( sibling
, GWL_STYLE
) & BS_TYPEMASK
) == BS_AUTORADIOBUTTON
))
1593 SendMessageW( sibling
, BM_SETCHECK
, BST_UNCHECKED
, 0 );
1594 sibling
= GetNextDlgGroupItem( parent
, sibling
, FALSE
);
1595 } while (sibling
!= start
);
1599 /**********************************************************************
1600 * Group Box Functions
1603 static void GB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1610 LONG style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
1614 if ((hFont
= get_button_font( hwnd
))) SelectObject( hDC
, hFont
);
1615 /* GroupBox acts like static control, so it sends CTLCOLORSTATIC */
1616 parent
= GetParent(hwnd
);
1617 if (!parent
) parent
= hwnd
;
1618 #if defined(__REACTOS__) && defined(_USER32_)
1619 hbr
= GetControlColor(parent
, hwnd
, hDC
, WM_CTLCOLORSTATIC
);
1621 hbr
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORSTATIC
, (WPARAM
)hDC
, (LPARAM
)hwnd
);
1622 if (!hbr
) /* did the app forget to call defwindowproc ? */
1623 hbr
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORSTATIC
,
1624 (WPARAM
)hDC
, (LPARAM
)hwnd
);
1626 GetClientRect( hwnd
, &rc
);
1628 hrgn
= set_control_clipping( hDC
, &rc
);
1630 GetTextMetricsW (hDC
, &tm
);
1631 rcFrame
.top
+= (tm
.tmHeight
/ 2) - 1;
1632 DrawEdge (hDC
, &rcFrame
, EDGE_ETCHED
, BF_RECT
| ((style
& BS_FLAT
) ? BF_FLAT
: 0));
1634 InflateRect(&rc
, -7, 1);
1635 dtFlags
= BUTTON_CalcLabelRect(hwnd
, hDC
, &rc
);
1637 if (dtFlags
!= (UINT
)-1L)
1639 /* Because buttons have CS_PARENTDC class style, there is a chance
1640 * that label will be drawn out of client rect.
1641 * But Windows doesn't clip label's rect, so do I.
1644 /* There is 1-pixel margin at the left, right, and bottom */
1645 rc
.left
--; rc
.right
++; rc
.bottom
++;
1646 FillRect(hDC
, &rc
, hbr
);
1647 rc
.left
++; rc
.right
--; rc
.bottom
--;
1649 BUTTON_DrawLabel(hwnd
, hDC
, dtFlags
, &rc
);
1651 SelectClipRgn( hDC
, hrgn
);
1652 if (hrgn
) DeleteObject( hrgn
);
1656 /**********************************************************************
1657 * User Button Functions
1660 static void UB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1665 LONG state
= get_button_state( hwnd
);
1668 GetClientRect( hwnd
, &rc
);
1670 if ((hFont
= get_button_font( hwnd
))) SelectObject( hDC
, hFont
);
1672 parent
= GetParent(hwnd
);
1673 if (!parent
) parent
= hwnd
;
1674 #if defined(__REACTOS__) && defined(_USER32_)
1675 hBrush
= GetControlColor( parent
, hwnd
, hDC
, WM_CTLCOLORBTN
);
1677 hBrush
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)hwnd
);
1678 if (!hBrush
) /* did the app forget to call defwindowproc ? */
1679 hBrush
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORBTN
,
1680 (WPARAM
)hDC
, (LPARAM
)hwnd
);
1683 FillRect( hDC
, &rc
, hBrush
);
1684 if (action
== ODA_FOCUS
|| (state
& BST_FOCUS
))
1687 if (!(get_ui_state(hwnd
) & UISF_HIDEFOCUS
))
1689 DrawFocusRect( hDC
, &rc
);
1697 BUTTON_NOTIFY_PARENT( hwnd
, (state
& BST_FOCUS
) ? BN_SETFOCUS
: BN_KILLFOCUS
);
1701 BUTTON_NOTIFY_PARENT( hwnd
, (state
& BST_PUSHED
) ? BN_HILITE
: BN_UNHILITE
);
1705 BUTTON_NOTIFY_PARENT( hwnd
, BN_PAINT
);
1711 /**********************************************************************
1712 * Ownerdrawn Button Functions
1715 static void OB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1717 LONG state
= get_button_state( hwnd
);
1719 LONG_PTR id
= GetWindowLongPtrW( hwnd
, GWLP_ID
);
1721 HFONT hFont
, hPrevFont
= 0;
1724 dis
.CtlType
= ODT_BUTTON
;
1727 dis
.itemAction
= action
;
1728 dis
.itemState
= ((state
& BST_FOCUS
) ? ODS_FOCUS
: 0) |
1729 ((state
& BST_PUSHED
) ? ODS_SELECTED
: 0) |
1730 (IsWindowEnabled(hwnd
) ? 0: ODS_DISABLED
);
1731 dis
.hwndItem
= hwnd
;
1734 GetClientRect( hwnd
, &dis
.rcItem
);
1736 if ((hFont
= get_button_font( hwnd
))) hPrevFont
= SelectObject( hDC
, hFont
);
1737 parent
= GetParent(hwnd
);
1738 if (!parent
) parent
= hwnd
;
1739 #if defined(__REACTOS__) && defined(_USER32_)
1740 GetControlColor( parent
, hwnd
, hDC
, WM_CTLCOLORBTN
);
1742 SendMessageW( parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)hwnd
);
1745 hrgn
= set_control_clipping( hDC
, &dis
.rcItem
);
1747 SendMessageW( GetParent(hwnd
), WM_DRAWITEM
, id
, (LPARAM
)&dis
);
1748 if (hPrevFont
) SelectObject(hDC
, hPrevFont
);
1749 SelectClipRgn( hDC
, hrgn
);
1750 if (hrgn
) DeleteObject( hrgn
);
1754 void BUTTON_Register()
1758 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
1759 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_VREDRAW
| CS_HREDRAW
| CS_PARENTDC
;
1760 wndClass
.lpfnWndProc
= ButtonWndProcW
;
1761 wndClass
.cbClsExtra
= 0;
1762 wndClass
.cbWndExtra
= sizeof(PBUTTON_DATA
);
1763 wndClass
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
1764 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
1765 wndClass
.lpszClassName
= WC_BUTTONW
;
1767 RegisterClassW(&wndClass
);
1770 void BUTTON_Unregister()
1772 UnregisterClassW(WC_BUTTONW
, NULL
);