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 */
161 static inline LONG
get_button_state( HWND hwnd
)
163 return GetWindowLongPtrW( hwnd
, STATE_GWL_OFFSET
);
166 static inline void set_button_state( HWND hwnd
, LONG state
)
168 SetWindowLongPtrW( hwnd
, STATE_GWL_OFFSET
, state
);
173 static __inline
void set_ui_state( HWND hwnd
, LONG flags
)
175 SetWindowLongPtrW( hwnd
, UISTATE_GWL_OFFSET
, flags
);
178 static __inline LONG
get_ui_state( HWND hwnd
)
180 return GetWindowLongPtrW( hwnd
, UISTATE_GWL_OFFSET
);
183 #endif /* __REACTOS__ */
186 #define NtUserAlterWindowStyle SetWindowLongPtrW
188 HRGN
set_control_clipping( HDC hdc
, const RECT
*rect
)
191 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
193 if (GetClipRgn( hdc
, hrgn
) != 1)
195 DeleteObject( hrgn
);
198 DPtoLP( hdc
, (POINT
*)&rc
, 2 );
199 if (GetLayout( hdc
) & LAYOUT_RTL
) /* compensate for the shifting done by IntersectClipRect */
204 IntersectClipRect( hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
208 BOOL
BUTTON_PaintWithTheme(HTHEME theme
, HWND hwnd
, HDC hParamDC
);
212 static inline HFONT
get_button_font( HWND hwnd
)
214 return (HFONT
)GetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
);
217 static inline void set_button_font( HWND hwnd
, HFONT font
)
219 SetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
, (LONG_PTR
)font
);
222 static inline UINT
get_button_type( LONG window_style
)
224 return (window_style
& BS_TYPEMASK
);
227 /* paint a button of any type */
228 static inline void paint_button( HWND hwnd
, LONG style
, UINT action
)
231 HTHEME theme
= GetWindowTheme(hwnd
);
233 HDC hdc
= GetDC( hwnd
);
234 /* GetDC appears to give a dc with a clip rect that includes the whoe parent, not sure if it is correct or not. */
235 GetClientRect(hwnd
, &rc
);
236 IntersectClipRect (hdc
, rc
.left
, rc
. top
, rc
.right
, rc
.bottom
);
237 if (theme
&& BUTTON_PaintWithTheme(theme
, hwnd
, hdc
))
239 ReleaseDC( hwnd
, hdc
);
242 if (btnPaintFunc
[style
] && IsWindowVisible(hwnd
))
244 btnPaintFunc
[style
]( hwnd
, hdc
, action
);
246 ReleaseDC( hwnd
, hdc
);
248 if (btnPaintFunc
[style
] && IsWindowVisible(hwnd
))
250 HDC hdc
= GetDC( hwnd
);
251 btnPaintFunc
[style
]( hwnd
, hdc
, action
);
252 ReleaseDC( hwnd
, hdc
);
257 /* retrieve the button text; returned buffer must be freed by caller */
258 static inline WCHAR
*get_button_text( HWND hwnd
)
261 WCHAR
*buffer
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) );
262 if (buffer
) InternalGetWindowText( hwnd
, buffer
, len
+ 1 );
267 /* Retrieve the UI state for the control */
268 static BOOL
button_update_uistate(HWND hwnd
, BOOL unicode
)
270 LONG flags
, prevflags
;
273 flags
= DefWindowProcW(hwnd
, WM_QUERYUISTATE
, 0, 0);
275 flags
= DefWindowProcA(hwnd
, WM_QUERYUISTATE
, 0, 0);
277 prevflags
= get_ui_state(hwnd
);
279 if (prevflags
!= flags
)
281 set_ui_state(hwnd
, flags
);
289 /***********************************************************************
290 * ButtonWndProc_common
292 LRESULT WINAPI
ButtonWndProc_common(HWND hWnd
, UINT uMsg
,
293 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
297 LONG style
= GetWindowLongPtrW( hWnd
, GWL_STYLE
);
298 UINT btn_type
= get_button_type( style
);
301 #if defined(__REACTOS__) && defined(_USER32_)
304 pWnd
= ValidateHwnd(hWnd
);
309 NtUserSetWindowFNID(hWnd
, FNID_BUTTON
);
313 if (pWnd
->fnid
!= FNID_BUTTON
)
315 ERR("Wrong window class for Button! fnId 0x%x\n",pWnd
->fnid
);
323 if (!IsWindow( hWnd
)) return 0;
326 pt
.x
= (short)LOWORD(lParam
);
327 pt
.y
= (short)HIWORD(lParam
);
335 case BS_PUSHBUTTON
: return DLGC_BUTTON
| DLGC_UNDEFPUSHBUTTON
;
336 case BS_DEFPUSHBUTTON
: return DLGC_BUTTON
| DLGC_DEFPUSHBUTTON
;
338 case BS_AUTORADIOBUTTON
: return DLGC_BUTTON
| DLGC_RADIOBUTTON
;
339 case BS_GROUPBOX
: return DLGC_STATIC
;
340 default: return DLGC_BUTTON
;
344 paint_button( hWnd
, btn_type
, ODA_DRAWENTIRE
);
348 if (btn_type
>= MAX_BTN_TYPE
)
349 return -1; /* abort */
351 /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
352 if (btn_type
== BS_USERBUTTON
)
354 style
= (style
& ~BS_TYPEMASK
) | BS_PUSHBUTTON
;
356 NtUserAlterWindowStyle(hWnd
, GWL_STYLE
, style
);
358 WIN_SetStyle( hWnd
, style
, BS_TYPEMASK
& ~style
);
361 set_button_state( hWnd
, BST_UNCHECKED
);
363 button_update_uistate( hWnd
, unicode
);
366 OpenThemeData(hWnd
, WC_BUTTONW
);
370 #if defined(__REACTOS__) && defined(_USER32_)
372 NtUserSetWindowFNID(hWnd
, FNID_DESTROY
);
378 CloseThemeData (GetWindowTheme(hWnd
));
380 case WM_THEMECHANGED
:
381 CloseThemeData (GetWindowTheme(hWnd
));
382 OpenThemeData(hWnd
, WC_BUTTONW
);
387 int state
= (int)SendMessageW(hWnd
, BM_GETSTATE
, 0, 0);
388 SetWindowLongW(hWnd
, 0, state
|BST_HOT
);
389 InvalidateRect(hWnd
, NULL
, FALSE
);
395 int state
= (int)SendMessageW(hWnd
, BM_GETSTATE
, 0, 0);
396 SetWindowLongW(hWnd
, 0, state
&(~BST_HOT
));
397 InvalidateRect(hWnd
, NULL
, FALSE
);
402 if (btn_type
== BS_OWNERDRAW
)
404 HDC hdc
= (HDC
)wParam
;
407 HWND parent
= GetParent(hWnd
);
408 if (!parent
) parent
= hWnd
;
409 #if defined(__REACTOS__) && defined(_USER32_)
410 hBrush
= GetControlColor( parent
, hWnd
, hdc
, WM_CTLCOLORBTN
);
412 hBrush
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORBTN
, (WPARAM
)hdc
, (LPARAM
)hWnd
);
413 if (!hBrush
) /* did the app forget to call defwindowproc ? */
414 hBrush
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORBTN
,
415 (WPARAM
)hdc
, (LPARAM
)hWnd
);
417 GetClientRect(hWnd
, &rc
);
418 FillRect(hdc
, &rc
, hBrush
);
426 HDC hdc
= wParam
? (HDC
)wParam
: BeginPaint( hWnd
, &ps
);
428 HTHEME theme
= GetWindowTheme(hWnd
);
429 if (theme
&& BUTTON_PaintWithTheme(theme
, hWnd
, hdc
))
431 if ( !wParam
) EndPaint( hWnd
, &ps
);
435 if (btnPaintFunc
[btn_type
])
437 int nOldMode
= SetBkMode( hdc
, OPAQUE
);
438 (btnPaintFunc
[btn_type
])( hWnd
, hdc
, ODA_DRAWENTIRE
);
439 SetBkMode(hdc
, nOldMode
); /* reset painting mode */
441 if ( !wParam
) EndPaint( hWnd
, &ps
);
446 if (wParam
== VK_SPACE
)
448 SendMessageW( hWnd
, BM_SETSTATE
, TRUE
, 0 );
449 set_button_state( hWnd
, get_button_state( hWnd
) | BUTTON_BTNPRESSED
);
454 case WM_LBUTTONDBLCLK
:
455 if(style
& BS_NOTIFY
||
456 btn_type
== BS_RADIOBUTTON
||
457 btn_type
== BS_USERBUTTON
||
458 btn_type
== BS_OWNERDRAW
)
460 BUTTON_NOTIFY_PARENT(hWnd
, BN_DOUBLECLICKED
);
467 set_button_state( hWnd
, get_button_state( hWnd
) | BUTTON_BTNPRESSED
);
468 SendMessageW( hWnd
, BM_SETSTATE
, TRUE
, 0 );
472 if (wParam
!= VK_SPACE
)
477 BOOL TellParent
= FALSE
; //// ReactOS see note below.
479 state
= get_button_state( hWnd
);
480 if (!(state
& BUTTON_BTNPRESSED
)) break;
481 state
&= BUTTON_NSTATES
;
482 set_button_state( hWnd
, state
);
483 if (!(state
& BST_PUSHED
))
488 SendMessageW( hWnd
, BM_SETSTATE
, FALSE
, 0 );
489 GetClientRect( hWnd
, &rect
);
490 if (uMsg
== WM_KEYUP
|| PtInRect( &rect
, pt
))
492 state
= get_button_state( hWnd
);
495 case BS_AUTOCHECKBOX
:
496 SendMessageW( hWnd
, BM_SETCHECK
, !(state
& BST_CHECKED
), 0 );
498 case BS_AUTORADIOBUTTON
:
499 SendMessageW( hWnd
, BM_SETCHECK
, TRUE
, 0 );
502 SendMessageW( hWnd
, BM_SETCHECK
,
503 (state
& BST_INDETERMINATE
) ? 0 : ((state
& 3) + 1), 0 );
507 TellParent
= TRUE
; // <---- Fix CORE-10194, Notify parent after capture is released.
510 BUTTON_NOTIFY_PARENT(hWnd
, BN_CLICKED
);
515 if (TellParent
) BUTTON_NOTIFY_PARENT(hWnd
, BN_CLICKED
);
524 case WM_CAPTURECHANGED
:
525 TRACE("WM_CAPTURECHANGED %p\n", hWnd
);
526 if (hWnd
== (HWND
)lParam
) break;
527 state
= get_button_state( hWnd
);
528 if (state
& BUTTON_BTNPRESSED
)
530 state
&= BUTTON_NSTATES
;
531 set_button_state( hWnd
, state
);
532 if (state
& BST_PUSHED
) SendMessageW( hWnd
, BM_SETSTATE
, FALSE
, 0 );
539 TRACKMOUSEEVENT mouse_event
;
540 mouse_event
.cbSize
= sizeof(TRACKMOUSEEVENT
);
541 mouse_event
.dwFlags
= TME_QUERY
;
542 if(!TrackMouseEvent(&mouse_event
) || !(mouse_event
.dwFlags
&(TME_HOVER
|TME_LEAVE
)))
544 mouse_event
.dwFlags
= TME_HOVER
|TME_LEAVE
;
545 mouse_event
.hwndTrack
= hWnd
;
546 mouse_event
.dwHoverTime
= 1;
547 TrackMouseEvent(&mouse_event
);
552 if ((wParam
& MK_LBUTTON
) && GetCapture() == hWnd
)
554 GetClientRect( hWnd
, &rect
);
555 SendMessageW( hWnd
, BM_SETSTATE
, PtInRect(&rect
, pt
), 0 );
561 /* Clear an old text here as Windows does */
564 // wine Bug: http://bugs.winehq.org/show_bug.cgi?id=25790
565 // Patch: http://source.winehq.org/patches/data/70889
566 // By: Alexander LAW, Replicate Windows behavior of WM_SETTEXT handler regarding WM_CTLCOLOR*
569 if (style
& WS_VISIBLE
)
571 if (IsWindowVisible(hWnd
))
574 HDC hdc
= GetDC(hWnd
);
577 HWND parent
= GetParent(hWnd
);
578 UINT message
= (btn_type
== BS_PUSHBUTTON
||
579 btn_type
== BS_DEFPUSHBUTTON
||
580 btn_type
== BS_PUSHLIKE
||
581 btn_type
== BS_USERBUTTON
||
582 btn_type
== BS_OWNERDRAW
) ?
583 WM_CTLCOLORBTN
: WM_CTLCOLORSTATIC
;
585 if (!parent
) parent
= hWnd
;
586 #if defined(__REACTOS__) && defined(_USER32_)
587 hbrush
= GetControlColor(parent
, hWnd
, hdc
, message
);
589 hbrush
= (HBRUSH
)SendMessageW(parent
, message
,
590 (WPARAM
)hdc
, (LPARAM
)hWnd
);
591 if (!hbrush
) /* did the app forget to call DefWindowProc ? */
592 hbrush
= (HBRUSH
)DefWindowProcW(parent
, message
,
593 (WPARAM
)hdc
, (LPARAM
)hWnd
);
596 GetClientRect(hWnd
, &client
);
598 /* FIXME: check other BS_* handlers */
599 if (btn_type
== BS_GROUPBOX
)
600 InflateRect(&rc
, -7, 1); /* GB_Paint does this */
601 BUTTON_CalcLabelRect(hWnd
, hdc
, &rc
);
602 /* Clip by client rect bounds */
603 if (rc
.right
> client
.right
) rc
.right
= client
.right
;
604 if (rc
.bottom
> client
.bottom
) rc
.bottom
= client
.bottom
;
605 FillRect(hdc
, &rc
, hbrush
);
606 ReleaseDC(hWnd
, hdc
);
609 if (unicode
) DefWindowProcW( hWnd
, WM_SETTEXT
, wParam
, lParam
);
610 else DefWindowProcA( hWnd
, WM_SETTEXT
, wParam
, lParam
);
611 if (btn_type
== BS_GROUPBOX
) /* Yes, only for BS_GROUPBOX */
612 InvalidateRect( hWnd
, NULL
, TRUE
);
614 paint_button( hWnd
, btn_type
, ODA_DRAWENTIRE
);
615 return 1; /* success. FIXME: check text length */
619 set_button_font( hWnd
, (HFONT
)wParam
);
620 if (lParam
) InvalidateRect(hWnd
, NULL
, TRUE
);
624 return (LRESULT
)get_button_font( hWnd
);
627 TRACE("WM_SETFOCUS %p\n",hWnd
);
628 set_button_state( hWnd
, get_button_state(hWnd
) | BST_FOCUS
);
629 paint_button( hWnd
, btn_type
, ODA_FOCUS
);
630 if (style
& BS_NOTIFY
)
631 BUTTON_NOTIFY_PARENT(hWnd
, BN_SETFOCUS
);
635 TRACE("WM_KILLFOCUS %p\n",hWnd
);
636 state
= get_button_state( hWnd
);
637 set_button_state( hWnd
, state
& ~BST_FOCUS
);
638 paint_button( hWnd
, btn_type
, ODA_FOCUS
);
640 if ((state
& BUTTON_BTNPRESSED
) && GetCapture() == hWnd
)
642 if (style
& BS_NOTIFY
)
643 BUTTON_NOTIFY_PARENT(hWnd
, BN_KILLFOCUS
);
645 InvalidateRect( hWnd
, NULL
, FALSE
);
648 case WM_SYSCOLORCHANGE
:
649 InvalidateRect( hWnd
, NULL
, FALSE
);
653 btn_type
= wParam
& BS_TYPEMASK
;
654 style
= (style
& ~BS_TYPEMASK
) | btn_type
;
656 NtUserAlterWindowStyle(hWnd
, GWL_STYLE
, style
);
658 WIN_SetStyle( hWnd
, style
, BS_TYPEMASK
& ~style
);
661 /* Only redraw if lParam flag is set.*/
663 InvalidateRect( hWnd
, NULL
, TRUE
);
669 state
= get_button_state(hWnd
);
670 if (state
& BUTTON_BMCLICK
)
672 set_button_state(hWnd
, state
| BUTTON_BMCLICK
); // Tracked in STATE_GWL_OFFSET.
674 SendMessageW( hWnd
, WM_LBUTTONDOWN
, 0, 0 );
675 SendMessageW( hWnd
, WM_LBUTTONUP
, 0, 0 );
677 state
= get_button_state(hWnd
);
678 if (!(state
& BUTTON_BMCLICK
)) break;
679 state
&= ~BUTTON_BMCLICK
;
680 set_button_state(hWnd
, state
);
685 /* Check that image format matches button style */
686 switch (style
& (BS_BITMAP
|BS_ICON
))
689 if (wParam
!= IMAGE_BITMAP
) return 0;
692 if (wParam
!= IMAGE_ICON
) return 0;
697 oldHbitmap
= (HBITMAP
)SetWindowLongPtrW( hWnd
, HIMAGE_GWL_OFFSET
, lParam
);
698 InvalidateRect( hWnd
, NULL
, FALSE
);
699 return (LRESULT
)oldHbitmap
;
702 return GetWindowLongPtrW( hWnd
, HIMAGE_GWL_OFFSET
);
705 return get_button_state( hWnd
) & 3;
708 if (wParam
> maxCheckState
[btn_type
]) wParam
= maxCheckState
[btn_type
];
709 state
= get_button_state( hWnd
);
710 if ((btn_type
== BS_RADIOBUTTON
) || (btn_type
== BS_AUTORADIOBUTTON
))
713 if (wParam
) style
|= WS_TABSTOP
;
714 else style
&= ~WS_TABSTOP
;
715 NtUserAlterWindowStyle(hWnd
, GWL_STYLE
, style
);
717 if (wParam
) WIN_SetStyle( hWnd
, WS_TABSTOP
, 0 );
718 else WIN_SetStyle( hWnd
, 0, WS_TABSTOP
);
721 if ((state
& 3) != wParam
)
723 set_button_state( hWnd
, (state
& ~3) | wParam
);
724 paint_button( hWnd
, btn_type
, ODA_SELECT
);
726 if ((btn_type
== BS_AUTORADIOBUTTON
) && (wParam
== BST_CHECKED
) && (style
& WS_CHILD
))
727 BUTTON_CheckAutoRadioButton( hWnd
);
731 return get_button_state( hWnd
);
734 state
= get_button_state( hWnd
);
736 set_button_state( hWnd
, state
| BST_PUSHED
);
738 set_button_state( hWnd
, state
& ~BST_PUSHED
);
740 paint_button( hWnd
, btn_type
, ODA_SELECT
);
744 case WM_UPDATEUISTATE
:
746 DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
748 DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
750 if (button_update_uistate(hWnd
, unicode
))
751 paint_button( hWnd
, btn_type
, ODA_DRAWENTIRE
);
756 if(btn_type
== BS_GROUPBOX
) return HTTRANSPARENT
;
759 return unicode
? DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
) :
760 DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
767 /***********************************************************************
769 * The button window procedure. This is just a wrapper which locks
770 * the passed HWND and calls the real window procedure (with a WND*
771 * pointer pointing to the locked windowstructure).
773 LRESULT WINAPI
ButtonWndProcW(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
775 if (!IsWindow(hWnd
)) return 0;
776 return ButtonWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
779 /***********************************************************************
782 LRESULT WINAPI
ButtonWndProcA(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
784 if (!IsWindow(hWnd
)) return 0;
785 return ButtonWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
788 #endif /* __REACTOS__ */
790 /**********************************************************************
791 * Convert button styles to flags used by DrawText.
793 static UINT
BUTTON_BStoDT( DWORD style
, DWORD ex_style
)
795 UINT dtStyle
= DT_NOCLIP
; /* We use SelectClipRgn to limit output */
797 /* "Convert" pushlike buttons to pushbuttons */
798 if (style
& BS_PUSHLIKE
)
799 style
&= ~BS_TYPEMASK
;
801 if (!(style
& BS_MULTILINE
))
802 dtStyle
|= DT_SINGLELINE
;
804 dtStyle
|= DT_WORDBREAK
;
806 switch (style
& BS_CENTER
)
808 case BS_LEFT
: /* DT_LEFT is 0 */ break;
809 case BS_RIGHT
: dtStyle
|= DT_RIGHT
; break;
810 case BS_CENTER
: dtStyle
|= DT_CENTER
; break;
812 /* Pushbutton's text is centered by default */
813 if (get_button_type(style
) <= BS_DEFPUSHBUTTON
) dtStyle
|= DT_CENTER
;
814 /* all other flavours have left aligned text */
817 if (ex_style
& WS_EX_RIGHT
) dtStyle
= DT_RIGHT
| (dtStyle
& ~(DT_LEFT
| DT_CENTER
));
819 /* DrawText ignores vertical alignment for multiline text,
820 * but we use these flags to align label manually.
822 if (get_button_type(style
) != BS_GROUPBOX
)
824 switch (style
& BS_VCENTER
)
826 case BS_TOP
: /* DT_TOP is 0 */ break;
827 case BS_BOTTOM
: dtStyle
|= DT_BOTTOM
; break;
828 case BS_VCENTER
: /* fall through */
829 default: dtStyle
|= DT_VCENTER
; break;
833 /* GroupBox's text is always single line and is top aligned. */
834 dtStyle
|= DT_SINGLELINE
;
839 /**********************************************************************
840 * BUTTON_CalcLabelRect
842 * Calculates label's rectangle depending on button style.
844 * Returns flags to be passed to DrawText.
845 * Calculated rectangle doesn't take into account button state
846 * (pushed, etc.). If there is nothing to draw (no text/image) output
847 * rectangle is empty, and return value is (UINT)-1.
849 static UINT
BUTTON_CalcLabelRect(HWND hwnd
, HDC hdc
, RECT
*rc
)
851 LONG style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
852 LONG ex_style
= GetWindowLongPtrW( hwnd
, GWL_EXSTYLE
);
856 UINT dtStyle
= BUTTON_BStoDT( style
, ex_style
);
860 /* Calculate label rectangle according to label type */
861 switch (style
& (BS_ICON
|BS_BITMAP
))
865 HFONT hFont
, hPrevFont
= 0;
867 if (!(text
= get_button_text( hwnd
))) goto empty_rect
;
870 HeapFree( GetProcessHeap(), 0, text
);
874 if ((hFont
= get_button_font( hwnd
))) hPrevFont
= SelectObject( hdc
, hFont
);
875 DrawTextW(hdc
, text
, -1, &r
, dtStyle
| DT_CALCRECT
);
876 if (hPrevFont
) SelectObject( hdc
, hPrevFont
);
877 HeapFree( GetProcessHeap(), 0, text
);
879 if (get_ui_state(hwnd
) & UISF_HIDEACCEL
)
880 dtStyle
|= DT_HIDEPREFIX
;
886 if (!GetIconInfo((HICON
)GetWindowLongPtrW( hwnd
, HIMAGE_GWL_OFFSET
), &iconInfo
))
889 GetObjectW (iconInfo
.hbmColor
, sizeof(BITMAP
), &bm
);
891 r
.right
= r
.left
+ bm
.bmWidth
;
892 r
.bottom
= r
.top
+ bm
.bmHeight
;
894 DeleteObject(iconInfo
.hbmColor
);
895 DeleteObject(iconInfo
.hbmMask
);
899 if (!GetObjectW( (HANDLE
)GetWindowLongPtrW( hwnd
, HIMAGE_GWL_OFFSET
), sizeof(BITMAP
), &bm
))
902 r
.right
= r
.left
+ bm
.bmWidth
;
903 r
.bottom
= r
.top
+ bm
.bmHeight
;
913 /* Position label inside bounding rectangle according to
914 * alignment flags. (calculated rect is always left-top aligned).
915 * If label is aligned to any side - shift label in opposite
916 * direction to leave extra space for focus rectangle.
918 switch (dtStyle
& (DT_CENTER
|DT_RIGHT
))
920 case DT_LEFT
: r
.left
++; r
.right
++; break;
921 case DT_CENTER
: n
= r
.right
- r
.left
;
922 r
.left
= rc
->left
+ ((rc
->right
- rc
->left
) - n
) / 2;
923 r
.right
= r
.left
+ n
; break;
924 case DT_RIGHT
: n
= r
.right
- r
.left
;
925 r
.right
= rc
->right
- 1;
926 r
.left
= r
.right
- n
;
930 switch (dtStyle
& (DT_VCENTER
|DT_BOTTOM
))
932 case DT_TOP
: r
.top
++; r
.bottom
++; break;
933 case DT_VCENTER
: n
= r
.bottom
- r
.top
;
934 r
.top
= rc
->top
+ ((rc
->bottom
- rc
->top
) - n
) / 2;
935 r
.bottom
= r
.top
+ n
; break;
936 case DT_BOTTOM
: n
= r
.bottom
- r
.top
;
937 r
.bottom
= rc
->bottom
- 1;
938 r
.top
= r
.bottom
- n
;
947 /**********************************************************************
948 * BUTTON_DrawTextCallback
950 * Callback function used by DrawStateW function.
952 static BOOL CALLBACK
BUTTON_DrawTextCallback(HDC hdc
, LPARAM lp
, WPARAM wp
, int cx
, int cy
)
956 SetRect(&rc
, 0, 0, cx
, cy
);
957 DrawTextW(hdc
, (LPCWSTR
)lp
, -1, &rc
, (UINT
)wp
);
962 /**********************************************************************
965 * Common function for drawing button label.
967 static void BUTTON_DrawLabel(HWND hwnd
, HDC hdc
, UINT dtFlags
, const RECT
*rc
)
969 DRAWSTATEPROC lpOutputProc
= NULL
;
973 UINT flags
= IsWindowEnabled(hwnd
) ? DSS_NORMAL
: DSS_DISABLED
;
974 LONG state
= get_button_state( hwnd
);
975 LONG style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
978 /* FIXME: To draw disabled label in Win31 look-and-feel, we probably
979 * must use DSS_MONO flag and COLOR_GRAYTEXT brush (or maybe DSS_UNION).
980 * I don't have Win31 on hand to verify that, so I leave it as is.
983 if ((style
& BS_PUSHLIKE
) && (state
& BST_INDETERMINATE
))
985 hbr
= GetSysColorBrush(COLOR_GRAYTEXT
);
989 switch (style
& (BS_ICON
|BS_BITMAP
))
992 /* DST_COMPLEX -- is 0 */
993 lpOutputProc
= BUTTON_DrawTextCallback
;
994 if (!(text
= get_button_text( hwnd
))) return;
996 wp
= (WPARAM
)dtFlags
;
999 if (dtFlags
& DT_HIDEPREFIX
)
1000 flags
|= DSS_HIDEPREFIX
;
1006 lp
= GetWindowLongPtrW( hwnd
, HIMAGE_GWL_OFFSET
);
1010 flags
|= DST_BITMAP
;
1011 lp
= GetWindowLongPtrW( hwnd
, HIMAGE_GWL_OFFSET
);
1018 DrawStateW(hdc
, hbr
, lpOutputProc
, lp
, wp
, rc
->left
, rc
->top
,
1019 rc
->right
- rc
->left
, rc
->bottom
- rc
->top
, flags
);
1020 HeapFree( GetProcessHeap(), 0, text
);
1023 /**********************************************************************
1024 * Push Button Functions
1026 static void PB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1029 UINT dtFlags
, uState
;
1033 COLORREF oldTxtColor
;
1035 LONG state
= get_button_state( hwnd
);
1036 LONG style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
1037 BOOL pushedState
= (state
& BST_PUSHED
);
1041 GetClientRect( hwnd
, &rc
);
1043 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
1044 if ((hFont
= get_button_font( hwnd
))) SelectObject( hDC
, hFont
);
1045 parent
= GetParent(hwnd
);
1046 if (!parent
) parent
= hwnd
;
1047 #if defined(__REACTOS__) && defined(_USER32_)
1048 GetControlColor( parent
, hwnd
, hDC
, WM_CTLCOLORBTN
);
1050 SendMessageW( parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)hwnd
);
1053 hrgn
= set_control_clipping( hDC
, &rc
);
1055 hOldPen
= SelectObject(hDC
, GetStockObject(DC_PEN
));
1056 SetDCPenColor(hDC
, GetSysColor(COLOR_WINDOWFRAME
));
1058 hOldPen
= SelectObject(hDC
, SYSCOLOR_GetPen(COLOR_WINDOWFRAME
));
1060 hOldBrush
= SelectObject(hDC
,GetSysColorBrush(COLOR_BTNFACE
));
1061 oldBkMode
= SetBkMode(hDC
, TRANSPARENT
);
1063 if (get_button_type(style
) == BS_DEFPUSHBUTTON
)
1065 if (action
!= ODA_FOCUS
)
1066 Rectangle(hDC
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1067 InflateRect( &rc
, -1, -1 );
1070 /* completely skip the drawing if only focus has changed */
1071 if (action
== ODA_FOCUS
) goto draw_focus
;
1073 uState
= DFCS_BUTTONPUSH
;
1075 if (style
& BS_FLAT
)
1076 uState
|= DFCS_MONO
;
1077 else if (pushedState
)
1079 if (get_button_type(style
) == BS_DEFPUSHBUTTON
)
1080 uState
|= DFCS_FLAT
;
1082 uState
|= DFCS_PUSHED
;
1085 if (state
& (BST_CHECKED
| BST_INDETERMINATE
))
1086 uState
|= DFCS_CHECKED
;
1088 DrawFrameControl( hDC
, &rc
, DFC_BUTTON
, uState
);
1090 /* draw button label */
1092 dtFlags
= BUTTON_CalcLabelRect(hwnd
, hDC
, &r
);
1094 if (dtFlags
== (UINT
)-1L)
1098 OffsetRect(&r
, 1, 1);
1100 oldTxtColor
= SetTextColor( hDC
, GetSysColor(COLOR_BTNTEXT
) );
1102 BUTTON_DrawLabel(hwnd
, hDC
, dtFlags
, &r
);
1104 SetTextColor( hDC
, oldTxtColor
);
1107 if (action
== ODA_FOCUS
|| (state
& BST_FOCUS
))
1110 if (!(get_ui_state(hwnd
) & UISF_HIDEFOCUS
))
1113 InflateRect( &rc
, -2, -2 );
1114 DrawFocusRect( hDC
, &rc
);
1121 SelectObject( hDC
, hOldPen
);
1122 SelectObject( hDC
, hOldBrush
);
1123 SetBkMode(hDC
, oldBkMode
);
1124 SelectClipRgn( hDC
, hrgn
);
1125 if (hrgn
) DeleteObject( hrgn
);
1128 /**********************************************************************
1129 * Check Box & Radio Button Functions
1132 static void CB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1134 RECT rbox
, rtext
, client
;
1136 int delta
, text_offset
, checkBoxWidth
, checkBoxHeight
;
1139 LONG state
= get_button_state( hwnd
);
1140 LONG style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
1141 LONG ex_style
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
1145 if (style
& BS_PUSHLIKE
)
1147 PB_Paint( hwnd
, hDC
, action
);
1151 GetClientRect(hwnd
, &client
);
1152 rbox
= rtext
= client
;
1154 checkBoxWidth
= 12 * GetDeviceCaps( hDC
, LOGPIXELSX
) / 96 + 1;
1155 checkBoxHeight
= 12 * GetDeviceCaps( hDC
, LOGPIXELSY
) / 96 + 1;
1157 if ((hFont
= get_button_font( hwnd
))) SelectObject( hDC
, hFont
);
1158 GetCharWidthW( hDC
, '0', '0', &text_offset
);
1161 parent
= GetParent(hwnd
);
1162 if (!parent
) parent
= hwnd
;
1163 #if defined(__REACTOS__) && defined(_USER32_)
1164 hBrush
= GetControlColor(parent
, hwnd
, hDC
, WM_CTLCOLORSTATIC
);
1166 hBrush
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORSTATIC
,
1167 (WPARAM
)hDC
, (LPARAM
)hwnd
);
1168 if (!hBrush
) /* did the app forget to call defwindowproc ? */
1169 hBrush
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORSTATIC
,
1170 (WPARAM
)hDC
, (LPARAM
)hwnd
);
1172 hrgn
= set_control_clipping( hDC
, &client
);
1174 if (style
& BS_LEFTTEXT
|| ex_style
& WS_EX_RIGHT
)
1176 /* magic +4 is what CTL3D expects */
1178 rtext
.right
-= checkBoxWidth
+ text_offset
;;
1179 rbox
.left
= rbox
.right
- checkBoxWidth
;
1183 rtext
.left
+= checkBoxWidth
+ text_offset
;;
1184 rbox
.right
= checkBoxWidth
;
1187 /* Since WM_ERASEBKGND does nothing, first prepare background */
1188 if (action
== ODA_SELECT
) FillRect( hDC
, &rbox
, hBrush
);
1189 if (action
== ODA_DRAWENTIRE
) FillRect( hDC
, &client
, hBrush
);
1193 dtFlags
= BUTTON_CalcLabelRect(hwnd
, hDC
, &rtext
);
1195 /* Only adjust rbox when rtext is valid */
1196 if (dtFlags
!= (UINT
)-1L)
1198 rbox
.top
= rtext
.top
;
1199 rbox
.bottom
= rtext
.bottom
;
1202 /* Draw the check-box bitmap */
1203 if (action
== ODA_DRAWENTIRE
|| action
== ODA_SELECT
)
1207 if ((get_button_type(style
) == BS_RADIOBUTTON
) ||
1208 (get_button_type(style
) == BS_AUTORADIOBUTTON
)) flags
= DFCS_BUTTONRADIO
;
1209 else if (state
& BST_INDETERMINATE
) flags
= DFCS_BUTTON3STATE
;
1210 else flags
= DFCS_BUTTONCHECK
;
1212 if (state
& (BST_CHECKED
| BST_INDETERMINATE
)) flags
|= DFCS_CHECKED
;
1213 if (state
& BST_PUSHED
) flags
|= DFCS_PUSHED
;
1215 if (style
& WS_DISABLED
) flags
|= DFCS_INACTIVE
;
1217 /* rbox must have the correct height */
1218 delta
= rbox
.bottom
- rbox
.top
- checkBoxHeight
;
1220 if (style
& BS_TOP
) {
1222 rbox
.bottom
= rbox
.top
+ checkBoxHeight
;
1224 rbox
.top
-= -delta
/2 + 1;
1225 rbox
.bottom
= rbox
.top
+ checkBoxHeight
;
1227 } else if (style
& BS_BOTTOM
) {
1229 rbox
.top
= rbox
.bottom
- checkBoxHeight
;
1231 rbox
.bottom
+= -delta
/2 + 1;
1232 rbox
.top
= rbox
.bottom
- checkBoxHeight
;
1234 } else { /* Default */
1236 int ofs
= (delta
/ 2);
1237 rbox
.bottom
-= ofs
+ 1;
1238 rbox
.top
= rbox
.bottom
- checkBoxHeight
;
1239 } else if (delta
< 0) {
1240 int ofs
= (-delta
/ 2);
1241 rbox
.top
-= ofs
+ 1;
1242 rbox
.bottom
= rbox
.top
+ checkBoxHeight
;
1246 DrawFrameControl( hDC
, &rbox
, DFC_BUTTON
, flags
);
1249 if (dtFlags
== (UINT
)-1L) /* Noting to draw */
1252 if (action
== ODA_DRAWENTIRE
)
1253 BUTTON_DrawLabel(hwnd
, hDC
, dtFlags
, &rtext
);
1256 if (action
== ODA_FOCUS
|| (state
& BST_FOCUS
))
1259 if (!(get_ui_state(hwnd
) & UISF_HIDEFOCUS
))
1264 IntersectRect(&rtext
, &rtext
, &client
);
1265 DrawFocusRect( hDC
, &rtext
);
1270 SelectClipRgn( hDC
, hrgn
);
1271 if (hrgn
) DeleteObject( hrgn
);
1275 /**********************************************************************
1276 * BUTTON_CheckAutoRadioButton
1278 * hwnd is checked, uncheck every other auto radio button in group
1280 static void BUTTON_CheckAutoRadioButton( HWND hwnd
)
1282 HWND parent
, sibling
, start
;
1284 parent
= GetParent(hwnd
);
1285 /* make sure that starting control is not disabled or invisible */
1286 start
= sibling
= GetNextDlgGroupItem( parent
, hwnd
, TRUE
);
1289 if (!sibling
) break;
1290 if ((hwnd
!= sibling
) &&
1291 ((GetWindowLongPtrW( sibling
, GWL_STYLE
) & BS_TYPEMASK
) == BS_AUTORADIOBUTTON
))
1292 SendMessageW( sibling
, BM_SETCHECK
, BST_UNCHECKED
, 0 );
1293 sibling
= GetNextDlgGroupItem( parent
, sibling
, FALSE
);
1294 } while (sibling
!= start
);
1298 /**********************************************************************
1299 * Group Box Functions
1302 static void GB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1309 LONG style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
1313 if ((hFont
= get_button_font( hwnd
))) SelectObject( hDC
, hFont
);
1314 /* GroupBox acts like static control, so it sends CTLCOLORSTATIC */
1315 parent
= GetParent(hwnd
);
1316 if (!parent
) parent
= hwnd
;
1317 #if defined(__REACTOS__) && defined(_USER32_)
1318 hbr
= GetControlColor(parent
, hwnd
, hDC
, WM_CTLCOLORSTATIC
);
1320 hbr
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORSTATIC
, (WPARAM
)hDC
, (LPARAM
)hwnd
);
1321 if (!hbr
) /* did the app forget to call defwindowproc ? */
1322 hbr
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORSTATIC
,
1323 (WPARAM
)hDC
, (LPARAM
)hwnd
);
1325 GetClientRect( hwnd
, &rc
);
1327 hrgn
= set_control_clipping( hDC
, &rc
);
1329 GetTextMetricsW (hDC
, &tm
);
1330 rcFrame
.top
+= (tm
.tmHeight
/ 2) - 1;
1331 DrawEdge (hDC
, &rcFrame
, EDGE_ETCHED
, BF_RECT
| ((style
& BS_FLAT
) ? BF_FLAT
: 0));
1333 InflateRect(&rc
, -7, 1);
1334 dtFlags
= BUTTON_CalcLabelRect(hwnd
, hDC
, &rc
);
1336 if (dtFlags
!= (UINT
)-1L)
1338 /* Because buttons have CS_PARENTDC class style, there is a chance
1339 * that label will be drawn out of client rect.
1340 * But Windows doesn't clip label's rect, so do I.
1343 /* There is 1-pixel margin at the left, right, and bottom */
1344 rc
.left
--; rc
.right
++; rc
.bottom
++;
1345 FillRect(hDC
, &rc
, hbr
);
1346 rc
.left
++; rc
.right
--; rc
.bottom
--;
1348 BUTTON_DrawLabel(hwnd
, hDC
, dtFlags
, &rc
);
1350 SelectClipRgn( hDC
, hrgn
);
1351 if (hrgn
) DeleteObject( hrgn
);
1355 /**********************************************************************
1356 * User Button Functions
1359 static void UB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1364 LONG state
= get_button_state( hwnd
);
1367 GetClientRect( hwnd
, &rc
);
1369 if ((hFont
= get_button_font( hwnd
))) SelectObject( hDC
, hFont
);
1371 parent
= GetParent(hwnd
);
1372 if (!parent
) parent
= hwnd
;
1373 #if defined(__REACTOS__) && defined(_USER32_)
1374 hBrush
= GetControlColor( parent
, hwnd
, hDC
, WM_CTLCOLORBTN
);
1376 hBrush
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)hwnd
);
1377 if (!hBrush
) /* did the app forget to call defwindowproc ? */
1378 hBrush
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORBTN
,
1379 (WPARAM
)hDC
, (LPARAM
)hwnd
);
1382 FillRect( hDC
, &rc
, hBrush
);
1383 if (action
== ODA_FOCUS
|| (state
& BST_FOCUS
))
1386 if (!(get_ui_state(hwnd
) & UISF_HIDEFOCUS
))
1388 DrawFocusRect( hDC
, &rc
);
1396 BUTTON_NOTIFY_PARENT( hwnd
, (state
& BST_FOCUS
) ? BN_SETFOCUS
: BN_KILLFOCUS
);
1400 BUTTON_NOTIFY_PARENT( hwnd
, (state
& BST_PUSHED
) ? BN_HILITE
: BN_UNHILITE
);
1404 BUTTON_NOTIFY_PARENT( hwnd
, BN_PAINT
);
1410 /**********************************************************************
1411 * Ownerdrawn Button Functions
1414 static void OB_Paint( HWND hwnd
, HDC hDC
, UINT action
)
1416 LONG state
= get_button_state( hwnd
);
1418 LONG_PTR id
= GetWindowLongPtrW( hwnd
, GWLP_ID
);
1420 HFONT hFont
, hPrevFont
= 0;
1423 dis
.CtlType
= ODT_BUTTON
;
1426 dis
.itemAction
= action
;
1427 dis
.itemState
= ((state
& BST_FOCUS
) ? ODS_FOCUS
: 0) |
1428 ((state
& BST_PUSHED
) ? ODS_SELECTED
: 0) |
1429 (IsWindowEnabled(hwnd
) ? 0: ODS_DISABLED
);
1430 dis
.hwndItem
= hwnd
;
1433 GetClientRect( hwnd
, &dis
.rcItem
);
1435 if ((hFont
= get_button_font( hwnd
))) hPrevFont
= SelectObject( hDC
, hFont
);
1436 parent
= GetParent(hwnd
);
1437 if (!parent
) parent
= hwnd
;
1438 #if defined(__REACTOS__) && defined(_USER32_)
1439 GetControlColor( parent
, hwnd
, hDC
, WM_CTLCOLORBTN
);
1441 SendMessageW( parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)hwnd
);
1444 hrgn
= set_control_clipping( hDC
, &dis
.rcItem
);
1446 SendMessageW( GetParent(hwnd
), WM_DRAWITEM
, id
, (LPARAM
)&dis
);
1447 if (hPrevFont
) SelectObject(hDC
, hPrevFont
);
1448 SelectClipRgn( hDC
, hrgn
);
1449 if (hrgn
) DeleteObject( hrgn
);
1453 void BUTTON_Register()
1457 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
1458 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_VREDRAW
| CS_HREDRAW
| CS_PARENTDC
;
1459 wndClass
.lpfnWndProc
= ButtonWndProcW
;
1460 wndClass
.cbClsExtra
= 0;
1461 wndClass
.cbWndExtra
= NB_EXTRA_BYTES
;
1462 wndClass
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
1463 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
1464 wndClass
.lpszClassName
= WC_BUTTONW
;
1466 RegisterClassW(&wndClass
);
1469 void BUTTON_Unregister()
1471 UnregisterClassW(WC_BUTTONW
, NULL
);