2 * Copyright (C) 1993 Johannes Ruscheinski
3 * Copyright (C) 1993 David Metcalfe
4 * Copyright (C) 1994 Alexandre Julliard
5 * Copyright (C) 2008 by Reece H. Dunn
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 * - BS_NOTIFY: is it complete?
24 * - BS_RIGHTBUTTON: same as BS_LEFTTEXT
27 * - WM_CHAR: Checks a (manual or automatic) check box on '+' or '=', clears it on '-' key.
28 * - WM_SETFOCUS: For (manual or automatic) radio buttons, send the parent window BN_CLICKED
29 * - WM_NCCREATE: Turns any BS_OWNERDRAW button into a BS_PUSHBUTTON button.
40 * - BN_PUSHED/BN_HILITE
41 * + BN_KILLFOCUS: is it OK?
43 * + BN_SETFOCUS: is it OK?
44 * - BN_UNPUSHED/BN_UNHILITE
47 * Structures/Macros/Definitions
50 * - Button_GetIdealSize
51 * - Button_GetImageList
52 * - Button_GetTextMargin
53 * - Button_SetImageList
54 * - Button_SetTextMargin
69 #include "wine/debug.h"
70 #include "wine/heap.h"
74 WINE_DEFAULT_DEBUG_CHANNEL(button
);
76 /* undocumented flags */
77 #define BUTTON_NSTATES 0x0F
78 #define BUTTON_BTNPRESSED 0x40
79 #define BUTTON_UNKNOWN2 0x20
80 #define BUTTON_UNKNOWN3 0x10
82 #define BUTTON_NOTIFY_PARENT(hWnd, code) \
83 do { /* Notify parent which has created this button control */ \
84 TRACE("notification " #code " sent to hwnd=%p\n", GetParent(hWnd)); \
85 SendMessageW(GetParent(hWnd), WM_COMMAND, \
86 MAKEWPARAM(GetWindowLongPtrW((hWnd),GWLP_ID), (code)), \
90 typedef struct _BUTTON_INFO
103 static UINT
BUTTON_CalcLabelRect( const BUTTON_INFO
*infoPtr
, HDC hdc
, RECT
*rc
);
104 static void PB_Paint( const BUTTON_INFO
*infoPtr
, HDC hDC
, UINT action
);
105 static void CB_Paint( const BUTTON_INFO
*infoPtr
, HDC hDC
, UINT action
);
106 static void GB_Paint( const BUTTON_INFO
*infoPtr
, HDC hDC
, UINT action
);
107 static void UB_Paint( const BUTTON_INFO
*infoPtr
, HDC hDC
, UINT action
);
108 static void OB_Paint( const BUTTON_INFO
*infoPtr
, HDC hDC
, UINT action
);
109 static void BUTTON_CheckAutoRadioButton( HWND hwnd
);
111 #define MAX_BTN_TYPE 16
113 static const WORD maxCheckState
[MAX_BTN_TYPE
] =
115 BST_UNCHECKED
, /* BS_PUSHBUTTON */
116 BST_UNCHECKED
, /* BS_DEFPUSHBUTTON */
117 BST_CHECKED
, /* BS_CHECKBOX */
118 BST_CHECKED
, /* BS_AUTOCHECKBOX */
119 BST_CHECKED
, /* BS_RADIOBUTTON */
120 BST_INDETERMINATE
, /* BS_3STATE */
121 BST_INDETERMINATE
, /* BS_AUTO3STATE */
122 BST_UNCHECKED
, /* BS_GROUPBOX */
123 BST_UNCHECKED
, /* BS_USERBUTTON */
124 BST_CHECKED
, /* BS_AUTORADIOBUTTON */
125 BST_UNCHECKED
, /* BS_PUSHBOX */
126 BST_UNCHECKED
, /* BS_OWNERDRAW */
127 BST_UNCHECKED
, /* BS_SPLITBUTTON */
128 BST_UNCHECKED
, /* BS_DEFSPLITBUTTON */
129 BST_UNCHECKED
, /* BS_COMMANDLINK */
130 BST_UNCHECKED
/* BS_DEFCOMMANDLINK */
133 /* These are indices into a states array to determine the theme state for a given theme part. */
143 typedef void (*pfPaint
)( const BUTTON_INFO
*infoPtr
, HDC hdc
, UINT action
);
145 static const pfPaint btnPaintFunc
[MAX_BTN_TYPE
] =
147 PB_Paint
, /* BS_PUSHBUTTON */
148 PB_Paint
, /* BS_DEFPUSHBUTTON */
149 CB_Paint
, /* BS_CHECKBOX */
150 CB_Paint
, /* BS_AUTOCHECKBOX */
151 CB_Paint
, /* BS_RADIOBUTTON */
152 CB_Paint
, /* BS_3STATE */
153 CB_Paint
, /* BS_AUTO3STATE */
154 GB_Paint
, /* BS_GROUPBOX */
155 UB_Paint
, /* BS_USERBUTTON */
156 CB_Paint
, /* BS_AUTORADIOBUTTON */
157 NULL
, /* BS_PUSHBOX */
158 OB_Paint
, /* BS_OWNERDRAW */
159 PB_Paint
, /* BS_SPLITBUTTON */
160 PB_Paint
, /* BS_DEFSPLITBUTTON */
161 PB_Paint
, /* BS_COMMANDLINK */
162 PB_Paint
/* BS_DEFCOMMANDLINK */
165 typedef void (*pfThemedPaint
)( HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hdc
, ButtonState drawState
, UINT dtflags
, BOOL focused
);
167 static void PB_ThemedPaint( HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hdc
, ButtonState drawState
, UINT dtflags
, BOOL focused
);
168 static void CB_ThemedPaint( HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hdc
, ButtonState drawState
, UINT dtflags
, BOOL focused
);
169 static void GB_ThemedPaint( HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hdc
, ButtonState drawState
, UINT dtflags
, BOOL focused
);
171 static const pfThemedPaint btnThemedPaintFunc
[MAX_BTN_TYPE
] =
173 PB_ThemedPaint
, /* BS_PUSHBUTTON */
174 PB_ThemedPaint
, /* BS_DEFPUSHBUTTON */
175 CB_ThemedPaint
, /* BS_CHECKBOX */
176 CB_ThemedPaint
, /* BS_AUTOCHECKBOX */
177 CB_ThemedPaint
, /* BS_RADIOBUTTON */
178 CB_ThemedPaint
, /* BS_3STATE */
179 CB_ThemedPaint
, /* BS_AUTO3STATE */
180 GB_ThemedPaint
, /* BS_GROUPBOX */
181 NULL
, /* BS_USERBUTTON */
182 CB_ThemedPaint
, /* BS_AUTORADIOBUTTON */
183 NULL
, /* BS_PUSHBOX */
184 NULL
, /* BS_OWNERDRAW */
185 NULL
, /* BS_SPLITBUTTON */
186 NULL
, /* BS_DEFSPLITBUTTON */
187 NULL
, /* BS_COMMANDLINK */
188 NULL
, /* BS_DEFCOMMANDLINK */
191 static inline UINT
get_button_type( LONG window_style
)
193 return (window_style
& BS_TYPEMASK
);
196 /* paint a button of any type */
197 static inline void paint_button( BUTTON_INFO
*infoPtr
, LONG style
, UINT action
)
199 if (btnPaintFunc
[style
] && IsWindowVisible(infoPtr
->hwnd
))
201 HDC hdc
= GetDC( infoPtr
->hwnd
);
202 btnPaintFunc
[style
]( infoPtr
, hdc
, action
);
203 ReleaseDC( infoPtr
->hwnd
, hdc
);
207 /* retrieve the button text; returned buffer must be freed by caller */
208 static inline WCHAR
*get_button_text( const BUTTON_INFO
*infoPtr
)
210 INT len
= GetWindowTextLengthW( infoPtr
->hwnd
);
211 WCHAR
*buffer
= heap_alloc( (len
+ 1) * sizeof(WCHAR
) );
213 GetWindowTextW( infoPtr
->hwnd
, buffer
, len
+ 1 );
217 HRGN
set_control_clipping( HDC hdc
, const RECT
*rect
)
220 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
222 if (GetClipRgn( hdc
, hrgn
) != 1)
224 DeleteObject( hrgn
);
227 DPtoLP( hdc
, (POINT
*)&rc
, 2 );
228 if (GetLayout( hdc
) & LAYOUT_RTL
) /* compensate for the shifting done by IntersectClipRect */
233 IntersectClipRect( hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
237 /**********************************************************************
238 * Convert button styles to flags used by DrawText.
240 static UINT
BUTTON_BStoDT( DWORD style
, DWORD ex_style
)
242 UINT dtStyle
= DT_NOCLIP
; /* We use SelectClipRgn to limit output */
244 /* "Convert" pushlike buttons to pushbuttons */
245 if (style
& BS_PUSHLIKE
)
246 style
&= ~BS_TYPEMASK
;
248 if (!(style
& BS_MULTILINE
))
249 dtStyle
|= DT_SINGLELINE
;
251 dtStyle
|= DT_WORDBREAK
;
253 switch (style
& BS_CENTER
)
255 case BS_LEFT
: /* DT_LEFT is 0 */ break;
256 case BS_RIGHT
: dtStyle
|= DT_RIGHT
; break;
257 case BS_CENTER
: dtStyle
|= DT_CENTER
; break;
259 /* Pushbutton's text is centered by default */
260 if (get_button_type(style
) <= BS_DEFPUSHBUTTON
) dtStyle
|= DT_CENTER
;
261 /* all other flavours have left aligned text */
264 if (ex_style
& WS_EX_RIGHT
) dtStyle
= DT_RIGHT
| (dtStyle
& ~(DT_LEFT
| DT_CENTER
));
266 /* DrawText ignores vertical alignment for multiline text,
267 * but we use these flags to align label manually.
269 if (get_button_type(style
) != BS_GROUPBOX
)
271 switch (style
& BS_VCENTER
)
273 case BS_TOP
: /* DT_TOP is 0 */ break;
274 case BS_BOTTOM
: dtStyle
|= DT_BOTTOM
; break;
275 case BS_VCENTER
: /* fall through */
276 default: dtStyle
|= DT_VCENTER
; break;
280 /* GroupBox's text is always single line and is top aligned. */
281 dtStyle
|= DT_SINGLELINE
;
286 static LRESULT CALLBACK
BUTTON_WindowProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
288 BUTTON_INFO
*infoPtr
= (BUTTON_INFO
*)GetWindowLongPtrW(hWnd
, 0);
291 LONG style
= GetWindowLongW( hWnd
, GWL_STYLE
);
292 UINT btn_type
= get_button_type( style
);
293 LONG state
, new_state
;
297 if (!IsWindow( hWnd
)) return 0;
299 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
300 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
302 pt
.x
= (short)LOWORD(lParam
);
303 pt
.y
= (short)HIWORD(lParam
);
312 case BS_PUSHBUTTON
: return DLGC_BUTTON
| DLGC_UNDEFPUSHBUTTON
;
313 case BS_DEFCOMMANDLINK
:
314 case BS_DEFPUSHBUTTON
: return DLGC_BUTTON
| DLGC_DEFPUSHBUTTON
;
316 case BS_AUTORADIOBUTTON
: return DLGC_BUTTON
| DLGC_RADIOBUTTON
;
317 case BS_GROUPBOX
: return DLGC_STATIC
;
318 case BS_SPLITBUTTON
: return DLGC_BUTTON
| DLGC_UNDEFPUSHBUTTON
| DLGC_WANTARROWS
;
319 case BS_DEFSPLITBUTTON
: return DLGC_BUTTON
| DLGC_DEFPUSHBUTTON
| DLGC_WANTARROWS
;
320 default: return DLGC_BUTTON
;
324 theme
= GetWindowTheme( hWnd
);
326 RedrawWindow( hWnd
, NULL
, NULL
, RDW_FRAME
| RDW_INVALIDATE
| RDW_UPDATENOW
);
328 paint_button( infoPtr
, btn_type
, ODA_DRAWENTIRE
);
332 infoPtr
= heap_alloc_zero( sizeof(*infoPtr
) );
333 SetWindowLongPtrW( hWnd
, 0, (LONG_PTR
)infoPtr
);
334 infoPtr
->hwnd
= hWnd
;
335 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
338 SetWindowLongPtrW( hWnd
, 0, 0 );
343 if (btn_type
>= MAX_BTN_TYPE
)
344 return -1; /* abort */
346 /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
347 if (btn_type
== BS_USERBUTTON
)
349 style
= (style
& ~BS_TYPEMASK
) | BS_PUSHBUTTON
;
350 SetWindowLongW( hWnd
, GWL_STYLE
, style
);
352 infoPtr
->state
= BST_UNCHECKED
;
353 OpenThemeData( hWnd
, WC_BUTTONW
);
357 theme
= GetWindowTheme( hWnd
);
358 CloseThemeData( theme
);
361 case WM_THEMECHANGED
:
362 theme
= GetWindowTheme( hWnd
);
363 CloseThemeData( theme
);
364 OpenThemeData( hWnd
, WC_BUTTONW
);
368 if (btn_type
== BS_OWNERDRAW
)
370 HDC hdc
= (HDC
)wParam
;
373 HWND parent
= GetParent(hWnd
);
374 if (!parent
) parent
= hWnd
;
375 hBrush
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORBTN
, (WPARAM
)hdc
, (LPARAM
)hWnd
);
376 if (!hBrush
) /* did the app forget to call defwindowproc ? */
377 hBrush
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORBTN
,
378 (WPARAM
)hdc
, (LPARAM
)hWnd
);
379 GetClientRect(hWnd
, &rc
);
380 FillRect(hdc
, &rc
, hBrush
);
390 theme
= GetWindowTheme( hWnd
);
391 hdc
= wParam
? (HDC
)wParam
: BeginPaint( hWnd
, &ps
);
393 if (theme
&& btnThemedPaintFunc
[btn_type
])
395 ButtonState drawState
;
398 if (IsWindowEnabled( hWnd
))
400 if (infoPtr
->state
& BST_PUSHED
) drawState
= STATE_PRESSED
;
401 else if (infoPtr
->state
& BST_HOT
) drawState
= STATE_HOT
;
402 else if (infoPtr
->state
& BST_FOCUS
) drawState
= STATE_DEFAULTED
;
403 else drawState
= STATE_NORMAL
;
406 drawState
= STATE_DISABLED
;
408 dtflags
= BUTTON_BStoDT(style
, GetWindowLongW(hWnd
, GWL_EXSTYLE
));
409 btnThemedPaintFunc
[btn_type
](theme
, infoPtr
, hdc
, drawState
, dtflags
, infoPtr
->state
& BST_FOCUS
);
411 else if (btnPaintFunc
[btn_type
])
413 int nOldMode
= SetBkMode( hdc
, OPAQUE
);
414 btnPaintFunc
[btn_type
]( infoPtr
, hdc
, ODA_DRAWENTIRE
);
415 SetBkMode(hdc
, nOldMode
); /* reset painting mode */
418 if ( !wParam
) EndPaint( hWnd
, &ps
);
423 if (wParam
== VK_SPACE
)
425 SendMessageW( hWnd
, BM_SETSTATE
, TRUE
, 0 );
426 infoPtr
->state
|= BUTTON_BTNPRESSED
;
431 case WM_LBUTTONDBLCLK
:
432 if(style
& BS_NOTIFY
||
433 btn_type
== BS_RADIOBUTTON
||
434 btn_type
== BS_USERBUTTON
||
435 btn_type
== BS_OWNERDRAW
)
437 BUTTON_NOTIFY_PARENT(hWnd
, BN_DOUBLECLICKED
);
444 infoPtr
->state
|= BUTTON_BTNPRESSED
;
445 SendMessageW( hWnd
, BM_SETSTATE
, TRUE
, 0 );
449 if (wParam
!= VK_SPACE
)
453 state
= infoPtr
->state
;
454 if (!(state
& BUTTON_BTNPRESSED
)) break;
455 infoPtr
->state
&= BUTTON_NSTATES
;
456 if (!(state
& BST_PUSHED
))
461 SendMessageW( hWnd
, BM_SETSTATE
, FALSE
, 0 );
462 GetClientRect( hWnd
, &rect
);
463 if (uMsg
== WM_KEYUP
|| PtInRect( &rect
, pt
))
467 case BS_AUTOCHECKBOX
:
468 SendMessageW( hWnd
, BM_SETCHECK
, !(infoPtr
->state
& BST_CHECKED
), 0 );
470 case BS_AUTORADIOBUTTON
:
471 SendMessageW( hWnd
, BM_SETCHECK
, TRUE
, 0 );
474 SendMessageW( hWnd
, BM_SETCHECK
, (infoPtr
->state
& BST_INDETERMINATE
) ? 0 :
475 ((infoPtr
->state
& 3) + 1), 0 );
479 BUTTON_NOTIFY_PARENT(hWnd
, BN_CLICKED
);
487 case WM_CAPTURECHANGED
:
488 TRACE("WM_CAPTURECHANGED %p\n", hWnd
);
489 if (hWnd
== (HWND
)lParam
) break;
490 if (infoPtr
->state
& BUTTON_BTNPRESSED
)
492 infoPtr
->state
&= BUTTON_NSTATES
;
493 if (infoPtr
->state
& BST_PUSHED
)
494 SendMessageW( hWnd
, BM_SETSTATE
, FALSE
, 0 );
500 TRACKMOUSEEVENT mouse_event
;
502 mouse_event
.cbSize
= sizeof(TRACKMOUSEEVENT
);
503 mouse_event
.dwFlags
= TME_QUERY
;
504 if (!TrackMouseEvent(&mouse_event
) || !(mouse_event
.dwFlags
& (TME_HOVER
| TME_LEAVE
)))
506 mouse_event
.dwFlags
= TME_HOVER
| TME_LEAVE
;
507 mouse_event
.hwndTrack
= hWnd
;
508 mouse_event
.dwHoverTime
= 1;
509 TrackMouseEvent(&mouse_event
);
512 if ((wParam
& MK_LBUTTON
) && GetCapture() == hWnd
)
514 GetClientRect( hWnd
, &rect
);
515 SendMessageW( hWnd
, BM_SETSTATE
, PtInRect(&rect
, pt
), 0 );
522 infoPtr
->state
|= BST_HOT
;
523 InvalidateRect( hWnd
, NULL
, FALSE
);
529 infoPtr
->state
&= ~BST_HOT
;
530 InvalidateRect( hWnd
, NULL
, FALSE
);
536 /* Clear an old text here as Windows does */
537 if (IsWindowVisible(hWnd
))
539 HDC hdc
= GetDC(hWnd
);
542 HWND parent
= GetParent(hWnd
);
543 UINT message
= (btn_type
== BS_PUSHBUTTON
||
544 btn_type
== BS_DEFPUSHBUTTON
||
545 btn_type
== BS_USERBUTTON
||
546 btn_type
== BS_OWNERDRAW
) ?
547 WM_CTLCOLORBTN
: WM_CTLCOLORSTATIC
;
549 if (!parent
) parent
= hWnd
;
550 hbrush
= (HBRUSH
)SendMessageW(parent
, message
,
551 (WPARAM
)hdc
, (LPARAM
)hWnd
);
552 if (!hbrush
) /* did the app forget to call DefWindowProc ? */
553 hbrush
= (HBRUSH
)DefWindowProcW(parent
, message
,
554 (WPARAM
)hdc
, (LPARAM
)hWnd
);
556 GetClientRect(hWnd
, &client
);
558 /* FIXME: check other BS_* handlers */
559 if (btn_type
== BS_GROUPBOX
)
560 InflateRect(&rc
, -7, 1); /* GB_Paint does this */
561 BUTTON_CalcLabelRect(infoPtr
, hdc
, &rc
);
562 /* Clip by client rect bounds */
563 if (rc
.right
> client
.right
) rc
.right
= client
.right
;
564 if (rc
.bottom
> client
.bottom
) rc
.bottom
= client
.bottom
;
565 FillRect(hdc
, &rc
, hbrush
);
566 ReleaseDC(hWnd
, hdc
);
569 DefWindowProcW( hWnd
, WM_SETTEXT
, wParam
, lParam
);
570 if (btn_type
== BS_GROUPBOX
) /* Yes, only for BS_GROUPBOX */
571 InvalidateRect( hWnd
, NULL
, TRUE
);
573 paint_button( infoPtr
, btn_type
, ODA_DRAWENTIRE
);
574 return 1; /* success. FIXME: check text length */
578 infoPtr
->font
= (HFONT
)wParam
;
579 if (lParam
) InvalidateRect(hWnd
, NULL
, TRUE
);
583 return (LRESULT
)infoPtr
->font
;
586 TRACE("WM_SETFOCUS %p\n",hWnd
);
587 infoPtr
->state
|= BST_FOCUS
;
588 paint_button( infoPtr
, btn_type
, ODA_FOCUS
);
589 if (style
& BS_NOTIFY
)
590 BUTTON_NOTIFY_PARENT(hWnd
, BN_SETFOCUS
);
594 TRACE("WM_KILLFOCUS %p\n",hWnd
);
595 infoPtr
->state
&= ~BST_FOCUS
;
596 paint_button( infoPtr
, btn_type
, ODA_FOCUS
);
598 if ((infoPtr
->state
& BUTTON_BTNPRESSED
) && GetCapture() == hWnd
)
600 if (style
& BS_NOTIFY
)
601 BUTTON_NOTIFY_PARENT(hWnd
, BN_KILLFOCUS
);
603 InvalidateRect( hWnd
, NULL
, FALSE
);
606 case WM_SYSCOLORCHANGE
:
607 InvalidateRect( hWnd
, NULL
, FALSE
);
611 btn_type
= wParam
& BS_TYPEMASK
;
612 style
= (style
& ~BS_TYPEMASK
) | btn_type
;
613 SetWindowLongW( hWnd
, GWL_STYLE
, style
);
615 /* Only redraw if lParam flag is set.*/
617 InvalidateRect( hWnd
, NULL
, TRUE
);
622 SendMessageW( hWnd
, WM_LBUTTONDOWN
, 0, 0 );
623 SendMessageW( hWnd
, WM_LBUTTONUP
, 0, 0 );
627 /* Check that image format matches button style */
628 switch (style
& (BS_BITMAP
|BS_ICON
))
631 if (wParam
!= IMAGE_BITMAP
) return 0;
634 if (wParam
!= IMAGE_ICON
) return 0;
639 oldHbitmap
= infoPtr
->u
.image
;
640 infoPtr
->u
.image
= (HANDLE
)lParam
;
641 InvalidateRect( hWnd
, NULL
, FALSE
);
642 return (LRESULT
)oldHbitmap
;
645 return (LRESULT
)infoPtr
->u
.image
;
648 return infoPtr
->state
& 3;
651 if (wParam
> maxCheckState
[btn_type
]) wParam
= maxCheckState
[btn_type
];
652 if ((btn_type
== BS_RADIOBUTTON
) || (btn_type
== BS_AUTORADIOBUTTON
))
654 style
= wParam
? style
| WS_TABSTOP
: style
& ~WS_TABSTOP
;
655 SetWindowLongW( hWnd
, GWL_STYLE
, style
);
657 if ((infoPtr
->state
& 3) != wParam
)
659 infoPtr
->state
= (infoPtr
->state
& ~3) | wParam
;
660 InvalidateRect( hWnd
, NULL
, FALSE
);
662 if ((btn_type
== BS_AUTORADIOBUTTON
) && (wParam
== BST_CHECKED
) && (style
& WS_CHILD
))
663 BUTTON_CheckAutoRadioButton( hWnd
);
667 return infoPtr
->state
;
670 state
= infoPtr
->state
;
671 new_state
= wParam
? BST_PUSHED
: 0;
673 if ((state
^ new_state
) & BST_PUSHED
)
678 state
&= ~BST_PUSHED
;
680 if (btn_type
== BS_USERBUTTON
)
681 BUTTON_NOTIFY_PARENT( hWnd
, (state
& BST_PUSHED
) ? BN_HILITE
: BN_UNHILITE
);
682 infoPtr
->state
= state
;
684 InvalidateRect( hWnd
, NULL
, FALSE
);
689 if(btn_type
== BS_GROUPBOX
) return HTTRANSPARENT
;
692 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
697 /**********************************************************************
698 * BUTTON_CalcLabelRect
700 * Calculates label's rectangle depending on button style.
702 * Returns flags to be passed to DrawText.
703 * Calculated rectangle doesn't take into account button state
704 * (pushed, etc.). If there is nothing to draw (no text/image) output
705 * rectangle is empty, and return value is (UINT)-1.
707 static UINT
BUTTON_CalcLabelRect(const BUTTON_INFO
*infoPtr
, HDC hdc
, RECT
*rc
)
709 LONG style
= GetWindowLongW( infoPtr
->hwnd
, GWL_STYLE
);
710 LONG ex_style
= GetWindowLongW( infoPtr
->hwnd
, GWL_EXSTYLE
);
714 UINT dtStyle
= BUTTON_BStoDT( style
, ex_style
);
718 /* Calculate label rectangle according to label type */
719 switch (style
& (BS_ICON
|BS_BITMAP
))
723 HFONT hFont
, hPrevFont
= 0;
725 if (!(text
= get_button_text( infoPtr
))) goto empty_rect
;
732 if ((hFont
= infoPtr
->font
)) hPrevFont
= SelectObject( hdc
, hFont
);
733 DrawTextW(hdc
, text
, -1, &r
, dtStyle
| DT_CALCRECT
);
734 if (hPrevFont
) SelectObject( hdc
, hPrevFont
);
740 if (!GetIconInfo(infoPtr
->u
.icon
, &iconInfo
))
743 GetObjectW (iconInfo
.hbmColor
, sizeof(BITMAP
), &bm
);
745 r
.right
= r
.left
+ bm
.bmWidth
;
746 r
.bottom
= r
.top
+ bm
.bmHeight
;
748 DeleteObject(iconInfo
.hbmColor
);
749 DeleteObject(iconInfo
.hbmMask
);
753 if (!GetObjectW( infoPtr
->u
.bitmap
, sizeof(BITMAP
), &bm
))
756 r
.right
= r
.left
+ bm
.bmWidth
;
757 r
.bottom
= r
.top
+ bm
.bmHeight
;
767 /* Position label inside bounding rectangle according to
768 * alignment flags. (calculated rect is always left-top aligned).
769 * If label is aligned to any side - shift label in opposite
770 * direction to leave extra space for focus rectangle.
772 switch (dtStyle
& (DT_CENTER
|DT_RIGHT
))
774 case DT_LEFT
: r
.left
++; r
.right
++; break;
775 case DT_CENTER
: n
= r
.right
- r
.left
;
776 r
.left
= rc
->left
+ ((rc
->right
- rc
->left
) - n
) / 2;
777 r
.right
= r
.left
+ n
; break;
778 case DT_RIGHT
: n
= r
.right
- r
.left
;
779 r
.right
= rc
->right
- 1;
780 r
.left
= r
.right
- n
;
784 switch (dtStyle
& (DT_VCENTER
|DT_BOTTOM
))
786 case DT_TOP
: r
.top
++; r
.bottom
++; break;
787 case DT_VCENTER
: n
= r
.bottom
- r
.top
;
788 r
.top
= rc
->top
+ ((rc
->bottom
- rc
->top
) - n
) / 2;
789 r
.bottom
= r
.top
+ n
; break;
790 case DT_BOTTOM
: n
= r
.bottom
- r
.top
;
791 r
.bottom
= rc
->bottom
- 1;
792 r
.top
= r
.bottom
- n
;
801 /**********************************************************************
802 * BUTTON_DrawTextCallback
804 * Callback function used by DrawStateW function.
806 static BOOL CALLBACK
BUTTON_DrawTextCallback(HDC hdc
, LPARAM lp
, WPARAM wp
, int cx
, int cy
)
810 SetRect(&rc
, 0, 0, cx
, cy
);
811 DrawTextW(hdc
, (LPCWSTR
)lp
, -1, &rc
, (UINT
)wp
);
816 /**********************************************************************
819 * Common function for drawing button label.
821 static void BUTTON_DrawLabel(const BUTTON_INFO
*infoPtr
, HDC hdc
, UINT dtFlags
, const RECT
*rc
)
823 DRAWSTATEPROC lpOutputProc
= NULL
;
827 UINT flags
= IsWindowEnabled(infoPtr
->hwnd
) ? DSS_NORMAL
: DSS_DISABLED
;
828 LONG state
= infoPtr
->state
;
829 LONG style
= GetWindowLongW( infoPtr
->hwnd
, GWL_STYLE
);
832 /* FIXME: To draw disabled label in Win31 look-and-feel, we probably
833 * must use DSS_MONO flag and COLOR_GRAYTEXT brush (or maybe DSS_UNION).
834 * I don't have Win31 on hand to verify that, so I leave it as is.
837 if ((style
& BS_PUSHLIKE
) && (state
& BST_INDETERMINATE
))
839 hbr
= GetSysColorBrush(COLOR_GRAYTEXT
);
843 switch (style
& (BS_ICON
|BS_BITMAP
))
846 /* DST_COMPLEX -- is 0 */
847 lpOutputProc
= BUTTON_DrawTextCallback
;
848 if (!(text
= get_button_text( infoPtr
))) return;
855 lp
= (LPARAM
)infoPtr
->u
.icon
;
860 lp
= (LPARAM
)infoPtr
->u
.bitmap
;
867 DrawStateW(hdc
, hbr
, lpOutputProc
, lp
, wp
, rc
->left
, rc
->top
,
868 rc
->right
- rc
->left
, rc
->bottom
- rc
->top
, flags
);
872 /**********************************************************************
873 * Push Button Functions
875 static void PB_Paint( const BUTTON_INFO
*infoPtr
, HDC hDC
, UINT action
)
878 UINT dtFlags
, uState
;
882 COLORREF oldTxtColor
;
884 LONG state
= infoPtr
->state
;
885 LONG style
= GetWindowLongW( infoPtr
->hwnd
, GWL_STYLE
);
886 BOOL pushedState
= (state
& BST_PUSHED
);
890 GetClientRect( infoPtr
->hwnd
, &rc
);
892 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
893 if ((hFont
= infoPtr
->font
)) SelectObject( hDC
, hFont
);
894 parent
= GetParent(infoPtr
->hwnd
);
895 if (!parent
) parent
= infoPtr
->hwnd
;
896 SendMessageW( parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
898 hrgn
= set_control_clipping( hDC
, &rc
);
900 hpen
= CreatePen( PS_SOLID
, 1, GetSysColor(COLOR_WINDOWFRAME
));
901 hOldPen
= SelectObject(hDC
, hpen
);
902 hOldBrush
= SelectObject(hDC
,GetSysColorBrush(COLOR_BTNFACE
));
903 oldBkMode
= SetBkMode(hDC
, TRANSPARENT
);
905 if (get_button_type(style
) == BS_DEFPUSHBUTTON
)
907 if (action
!= ODA_FOCUS
)
908 Rectangle(hDC
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
909 InflateRect( &rc
, -1, -1 );
912 /* completely skip the drawing if only focus has changed */
913 if (action
== ODA_FOCUS
) goto draw_focus
;
915 uState
= DFCS_BUTTONPUSH
;
919 else if (pushedState
)
921 if (get_button_type(style
) == BS_DEFPUSHBUTTON
)
924 uState
|= DFCS_PUSHED
;
927 if (state
& (BST_CHECKED
| BST_INDETERMINATE
))
928 uState
|= DFCS_CHECKED
;
930 DrawFrameControl( hDC
, &rc
, DFC_BUTTON
, uState
);
932 /* draw button label */
934 dtFlags
= BUTTON_CalcLabelRect(infoPtr
, hDC
, &r
);
936 if (dtFlags
== (UINT
)-1L)
940 OffsetRect(&r
, 1, 1);
942 oldTxtColor
= SetTextColor( hDC
, GetSysColor(COLOR_BTNTEXT
) );
944 BUTTON_DrawLabel(infoPtr
, hDC
, dtFlags
, &r
);
946 SetTextColor( hDC
, oldTxtColor
);
949 if (action
== ODA_FOCUS
|| (state
& BST_FOCUS
))
951 InflateRect( &rc
, -2, -2 );
952 DrawFocusRect( hDC
, &rc
);
956 SelectObject( hDC
, hOldPen
);
957 SelectObject( hDC
, hOldBrush
);
958 SetBkMode(hDC
, oldBkMode
);
959 SelectClipRgn( hDC
, hrgn
);
960 if (hrgn
) DeleteObject( hrgn
);
961 DeleteObject( hpen
);
964 /**********************************************************************
965 * Check Box & Radio Button Functions
968 static void CB_Paint( const BUTTON_INFO
*infoPtr
, HDC hDC
, UINT action
)
970 RECT rbox
, rtext
, client
;
972 int delta
, text_offset
, checkBoxWidth
, checkBoxHeight
;
975 LONG state
= infoPtr
->state
;
976 LONG style
= GetWindowLongW( infoPtr
->hwnd
, GWL_STYLE
);
977 LONG ex_style
= GetWindowLongW( infoPtr
->hwnd
, GWL_EXSTYLE
);
981 if (style
& BS_PUSHLIKE
)
983 PB_Paint( infoPtr
, hDC
, action
);
987 GetClientRect(infoPtr
->hwnd
, &client
);
988 rbox
= rtext
= client
;
990 checkBoxWidth
= 12 * GetDeviceCaps( hDC
, LOGPIXELSX
) / 96 + 1;
991 checkBoxHeight
= 12 * GetDeviceCaps( hDC
, LOGPIXELSY
) / 96 + 1;
993 if ((hFont
= infoPtr
->font
)) SelectObject( hDC
, hFont
);
994 GetCharWidthW( hDC
, '0', '0', &text_offset
);
997 parent
= GetParent(infoPtr
->hwnd
);
998 if (!parent
) parent
= infoPtr
->hwnd
;
999 hBrush
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORSTATIC
, (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
1000 if (!hBrush
) /* did the app forget to call defwindowproc ? */
1001 hBrush
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORSTATIC
, (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
1002 hrgn
= set_control_clipping( hDC
, &client
);
1004 if (style
& BS_LEFTTEXT
|| ex_style
& WS_EX_RIGHT
)
1006 rtext
.right
-= checkBoxWidth
+ text_offset
;
1007 rbox
.left
= rbox
.right
- checkBoxWidth
;
1011 rtext
.left
+= checkBoxWidth
+ text_offset
;
1012 rbox
.right
= checkBoxWidth
;
1015 /* Since WM_ERASEBKGND does nothing, first prepare background */
1016 if (action
== ODA_SELECT
) FillRect( hDC
, &rbox
, hBrush
);
1017 if (action
== ODA_DRAWENTIRE
) FillRect( hDC
, &client
, hBrush
);
1021 dtFlags
= BUTTON_CalcLabelRect(infoPtr
, hDC
, &rtext
);
1023 /* Only adjust rbox when rtext is valid */
1024 if (dtFlags
!= (UINT
)-1L)
1026 rbox
.top
= rtext
.top
;
1027 rbox
.bottom
= rtext
.bottom
;
1030 /* Draw the check-box bitmap */
1031 if (action
== ODA_DRAWENTIRE
|| action
== ODA_SELECT
)
1035 if ((get_button_type(style
) == BS_RADIOBUTTON
) ||
1036 (get_button_type(style
) == BS_AUTORADIOBUTTON
)) flags
= DFCS_BUTTONRADIO
;
1037 else if (state
& BST_INDETERMINATE
) flags
= DFCS_BUTTON3STATE
;
1038 else flags
= DFCS_BUTTONCHECK
;
1040 if (state
& (BST_CHECKED
| BST_INDETERMINATE
)) flags
|= DFCS_CHECKED
;
1041 if (state
& BST_PUSHED
) flags
|= DFCS_PUSHED
;
1043 if (style
& WS_DISABLED
) flags
|= DFCS_INACTIVE
;
1045 /* rbox must have the correct height */
1046 delta
= rbox
.bottom
- rbox
.top
- checkBoxHeight
;
1048 if (style
& BS_TOP
) {
1050 rbox
.bottom
= rbox
.top
+ checkBoxHeight
;
1052 rbox
.top
-= -delta
/2 + 1;
1053 rbox
.bottom
= rbox
.top
+ checkBoxHeight
;
1055 } else if (style
& BS_BOTTOM
) {
1057 rbox
.top
= rbox
.bottom
- checkBoxHeight
;
1059 rbox
.bottom
+= -delta
/2 + 1;
1060 rbox
.top
= rbox
.bottom
- checkBoxHeight
;
1062 } else { /* Default */
1064 int ofs
= (delta
/ 2);
1065 rbox
.bottom
-= ofs
+ 1;
1066 rbox
.top
= rbox
.bottom
- checkBoxHeight
;
1067 } else if (delta
< 0) {
1068 int ofs
= (-delta
/ 2);
1069 rbox
.top
-= ofs
+ 1;
1070 rbox
.bottom
= rbox
.top
+ checkBoxHeight
;
1074 DrawFrameControl( hDC
, &rbox
, DFC_BUTTON
, flags
);
1077 if (dtFlags
== (UINT
)-1L) /* Noting to draw */
1080 if (action
== ODA_DRAWENTIRE
)
1081 BUTTON_DrawLabel(infoPtr
, hDC
, dtFlags
, &rtext
);
1084 if (action
== ODA_FOCUS
|| (state
& BST_FOCUS
))
1088 IntersectRect(&rtext
, &rtext
, &client
);
1089 DrawFocusRect( hDC
, &rtext
);
1091 SelectClipRgn( hDC
, hrgn
);
1092 if (hrgn
) DeleteObject( hrgn
);
1096 /**********************************************************************
1097 * BUTTON_CheckAutoRadioButton
1099 * hwnd is checked, uncheck every other auto radio button in group
1101 static void BUTTON_CheckAutoRadioButton( HWND hwnd
)
1103 HWND parent
, sibling
, start
;
1105 parent
= GetParent(hwnd
);
1106 /* make sure that starting control is not disabled or invisible */
1107 start
= sibling
= GetNextDlgGroupItem( parent
, hwnd
, TRUE
);
1110 if (!sibling
) break;
1111 if ((hwnd
!= sibling
) &&
1112 ((GetWindowLongW( sibling
, GWL_STYLE
) & BS_TYPEMASK
) == BS_AUTORADIOBUTTON
))
1113 SendMessageW( sibling
, BM_SETCHECK
, BST_UNCHECKED
, 0 );
1114 sibling
= GetNextDlgGroupItem( parent
, sibling
, FALSE
);
1115 } while (sibling
!= start
);
1119 /**********************************************************************
1120 * Group Box Functions
1123 static void GB_Paint( const BUTTON_INFO
*infoPtr
, HDC hDC
, UINT action
)
1130 LONG style
= GetWindowLongW( infoPtr
->hwnd
, GWL_STYLE
);
1134 if ((hFont
= infoPtr
->font
)) SelectObject( hDC
, hFont
);
1135 /* GroupBox acts like static control, so it sends CTLCOLORSTATIC */
1136 parent
= GetParent(infoPtr
->hwnd
);
1137 if (!parent
) parent
= infoPtr
->hwnd
;
1138 hbr
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORSTATIC
, (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
1139 if (!hbr
) /* did the app forget to call defwindowproc ? */
1140 hbr
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORSTATIC
, (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
1141 GetClientRect( infoPtr
->hwnd
, &rc
);
1143 hrgn
= set_control_clipping( hDC
, &rc
);
1145 GetTextMetricsW (hDC
, &tm
);
1146 rcFrame
.top
+= (tm
.tmHeight
/ 2) - 1;
1147 DrawEdge (hDC
, &rcFrame
, EDGE_ETCHED
, BF_RECT
| ((style
& BS_FLAT
) ? BF_FLAT
: 0));
1149 InflateRect(&rc
, -7, 1);
1150 dtFlags
= BUTTON_CalcLabelRect(infoPtr
, hDC
, &rc
);
1152 if (dtFlags
!= (UINT
)-1)
1154 /* Because buttons have CS_PARENTDC class style, there is a chance
1155 * that label will be drawn out of client rect.
1156 * But Windows doesn't clip label's rect, so do I.
1159 /* There is 1-pixel margin at the left, right, and bottom */
1160 rc
.left
--; rc
.right
++; rc
.bottom
++;
1161 FillRect(hDC
, &rc
, hbr
);
1162 rc
.left
++; rc
.right
--; rc
.bottom
--;
1164 BUTTON_DrawLabel(infoPtr
, hDC
, dtFlags
, &rc
);
1166 SelectClipRgn( hDC
, hrgn
);
1167 if (hrgn
) DeleteObject( hrgn
);
1171 /**********************************************************************
1172 * User Button Functions
1175 static void UB_Paint( const BUTTON_INFO
*infoPtr
, HDC hDC
, UINT action
)
1180 LONG state
= infoPtr
->state
;
1183 GetClientRect( infoPtr
->hwnd
, &rc
);
1185 if ((hFont
= infoPtr
->font
)) SelectObject( hDC
, hFont
);
1187 parent
= GetParent(infoPtr
->hwnd
);
1188 if (!parent
) parent
= infoPtr
->hwnd
;
1189 hBrush
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
1190 if (!hBrush
) /* did the app forget to call defwindowproc ? */
1191 hBrush
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
1193 FillRect( hDC
, &rc
, hBrush
);
1194 if (action
== ODA_FOCUS
|| (state
& BST_FOCUS
))
1195 DrawFocusRect( hDC
, &rc
);
1200 BUTTON_NOTIFY_PARENT( infoPtr
->hwnd
, (state
& BST_FOCUS
) ? BN_SETFOCUS
: BN_KILLFOCUS
);
1204 BUTTON_NOTIFY_PARENT( infoPtr
->hwnd
, (state
& BST_PUSHED
) ? BN_HILITE
: BN_UNHILITE
);
1213 /**********************************************************************
1214 * Ownerdrawn Button Functions
1217 static void OB_Paint( const BUTTON_INFO
*infoPtr
, HDC hDC
, UINT action
)
1219 LONG state
= infoPtr
->state
;
1221 LONG_PTR id
= GetWindowLongPtrW( infoPtr
->hwnd
, GWLP_ID
);
1226 dis
.CtlType
= ODT_BUTTON
;
1229 dis
.itemAction
= action
;
1230 dis
.itemState
= ((state
& BST_FOCUS
) ? ODS_FOCUS
: 0) |
1231 ((state
& BST_PUSHED
) ? ODS_SELECTED
: 0) |
1232 (IsWindowEnabled(infoPtr
->hwnd
) ? 0: ODS_DISABLED
);
1233 dis
.hwndItem
= infoPtr
->hwnd
;
1236 GetClientRect( infoPtr
->hwnd
, &dis
.rcItem
);
1238 if ((hFont
= infoPtr
->font
)) SelectObject( hDC
, hFont
);
1239 parent
= GetParent(infoPtr
->hwnd
);
1240 if (!parent
) parent
= infoPtr
->hwnd
;
1241 SendMessageW( parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
1243 hrgn
= set_control_clipping( hDC
, &dis
.rcItem
);
1245 SendMessageW( GetParent(infoPtr
->hwnd
), WM_DRAWITEM
, id
, (LPARAM
)&dis
);
1246 SelectClipRgn( hDC
, hrgn
);
1247 if (hrgn
) DeleteObject( hrgn
);
1250 static void PB_ThemedPaint(HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hDC
, ButtonState drawState
, UINT dtFlags
, BOOL focused
)
1252 static const int states
[] = { PBS_NORMAL
, PBS_DISABLED
, PBS_HOT
, PBS_PRESSED
, PBS_DEFAULTED
};
1254 RECT bgRect
, textRect
;
1255 HFONT font
= infoPtr
->font
;
1256 HFONT hPrevFont
= font
? SelectObject(hDC
, font
) : NULL
;
1257 int state
= states
[ drawState
];
1258 WCHAR
*text
= get_button_text(infoPtr
);
1260 GetClientRect(infoPtr
->hwnd
, &bgRect
);
1261 GetThemeBackgroundContentRect(theme
, hDC
, BP_PUSHBUTTON
, state
, &bgRect
, &textRect
);
1263 if (IsThemeBackgroundPartiallyTransparent(theme
, BP_PUSHBUTTON
, state
))
1264 DrawThemeParentBackground(infoPtr
->hwnd
, hDC
, NULL
);
1265 DrawThemeBackground(theme
, hDC
, BP_PUSHBUTTON
, state
, &bgRect
, NULL
);
1268 DrawThemeText(theme
, hDC
, BP_PUSHBUTTON
, state
, text
, lstrlenW(text
), dtFlags
, 0, &textRect
);
1275 RECT focusRect
= bgRect
;
1277 GetThemeMargins(theme
, hDC
, BP_PUSHBUTTON
, state
, TMT_CONTENTMARGINS
, NULL
, &margins
);
1279 focusRect
.left
+= margins
.cxLeftWidth
;
1280 focusRect
.top
+= margins
.cyTopHeight
;
1281 focusRect
.right
-= margins
.cxRightWidth
;
1282 focusRect
.bottom
-= margins
.cyBottomHeight
;
1284 DrawFocusRect( hDC
, &focusRect
);
1287 if (hPrevFont
) SelectObject(hDC
, hPrevFont
);
1290 static void CB_ThemedPaint(HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hDC
, ButtonState drawState
, UINT dtFlags
, BOOL focused
)
1292 static const int cb_states
[3][5] =
1294 { CBS_UNCHECKEDNORMAL
, CBS_UNCHECKEDDISABLED
, CBS_UNCHECKEDHOT
, CBS_UNCHECKEDPRESSED
, CBS_UNCHECKEDNORMAL
},
1295 { CBS_CHECKEDNORMAL
, CBS_CHECKEDDISABLED
, CBS_CHECKEDHOT
, CBS_CHECKEDPRESSED
, CBS_CHECKEDNORMAL
},
1296 { CBS_MIXEDNORMAL
, CBS_MIXEDDISABLED
, CBS_MIXEDHOT
, CBS_MIXEDPRESSED
, CBS_MIXEDNORMAL
}
1299 static const int rb_states
[2][5] =
1301 { RBS_UNCHECKEDNORMAL
, RBS_UNCHECKEDDISABLED
, RBS_UNCHECKEDHOT
, RBS_UNCHECKEDPRESSED
, RBS_UNCHECKEDNORMAL
},
1302 { RBS_CHECKEDNORMAL
, RBS_CHECKEDDISABLED
, RBS_CHECKEDHOT
, RBS_CHECKEDPRESSED
, RBS_CHECKEDNORMAL
}
1306 RECT bgRect
, textRect
;
1307 HFONT font
, hPrevFont
= NULL
;
1308 int checkState
= infoPtr
->state
& 3;
1309 DWORD dwStyle
= GetWindowLongW(infoPtr
->hwnd
, GWL_STYLE
);
1310 UINT btn_type
= get_button_type( dwStyle
);
1311 int part
= (btn_type
== BS_RADIOBUTTON
) || (btn_type
== BS_AUTORADIOBUTTON
) ? BP_RADIOBUTTON
: BP_CHECKBOX
;
1312 int state
= (part
== BP_CHECKBOX
)
1313 ? cb_states
[ checkState
][ drawState
]
1314 : rb_states
[ checkState
][ drawState
];
1315 WCHAR
*text
= get_button_text(infoPtr
);
1317 BOOL created_font
= FALSE
;
1319 HRESULT hr
= GetThemeFont(theme
, hDC
, part
, state
, TMT_FONT
, &lf
);
1320 if (SUCCEEDED(hr
)) {
1321 font
= CreateFontIndirectW(&lf
);
1323 TRACE("Failed to create font\n");
1325 TRACE("font = %s\n", debugstr_w(lf
.lfFaceName
));
1326 hPrevFont
= SelectObject(hDC
, font
);
1327 created_font
= TRUE
;
1330 font
= (HFONT
)SendMessageW(infoPtr
->hwnd
, WM_GETFONT
, 0, 0);
1331 hPrevFont
= SelectObject(hDC
, font
);
1334 if (FAILED(GetThemePartSize(theme
, hDC
, part
, state
, NULL
, TS_DRAW
, &sz
)))
1337 GetClientRect(infoPtr
->hwnd
, &bgRect
);
1338 GetThemeBackgroundContentRect(theme
, hDC
, part
, state
, &bgRect
, &textRect
);
1340 if (dtFlags
& DT_SINGLELINE
) /* Center the checkbox / radio button to the text. */
1341 bgRect
.top
= bgRect
.top
+ (textRect
.bottom
- textRect
.top
- sz
.cy
) / 2;
1343 /* adjust for the check/radio marker */
1344 bgRect
.bottom
= bgRect
.top
+ sz
.cy
;
1345 bgRect
.right
= bgRect
.left
+ sz
.cx
;
1346 textRect
.left
= bgRect
.right
+ 6;
1348 DrawThemeParentBackground(infoPtr
->hwnd
, hDC
, NULL
);
1350 DrawThemeBackground(theme
, hDC
, part
, state
, &bgRect
, NULL
);
1353 DrawThemeText(theme
, hDC
, part
, state
, text
, lstrlenW(text
), dtFlags
, 0, &textRect
);
1359 focusRect
= textRect
;
1361 DrawTextW(hDC
, text
, lstrlenW(text
), &focusRect
, dtFlags
| DT_CALCRECT
);
1363 if (focusRect
.right
< textRect
.right
) focusRect
.right
++;
1364 focusRect
.bottom
= textRect
.bottom
;
1366 DrawFocusRect( hDC
, &focusRect
);
1372 if (created_font
) DeleteObject(font
);
1373 if (hPrevFont
) SelectObject(hDC
, hPrevFont
);
1376 static void GB_ThemedPaint(HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hDC
, ButtonState drawState
, UINT dtFlags
, BOOL focused
)
1378 static const int states
[] = { GBS_NORMAL
, GBS_DISABLED
, GBS_NORMAL
, GBS_NORMAL
, GBS_NORMAL
};
1380 RECT bgRect
, textRect
, contentRect
;
1381 int state
= states
[ drawState
];
1382 WCHAR
*text
= get_button_text(infoPtr
);
1384 HFONT font
, hPrevFont
= NULL
;
1385 BOOL created_font
= FALSE
;
1387 HRESULT hr
= GetThemeFont(theme
, hDC
, BP_GROUPBOX
, state
, TMT_FONT
, &lf
);
1388 if (SUCCEEDED(hr
)) {
1389 font
= CreateFontIndirectW(&lf
);
1391 TRACE("Failed to create font\n");
1393 hPrevFont
= SelectObject(hDC
, font
);
1394 created_font
= TRUE
;
1397 font
= (HFONT
)SendMessageW(infoPtr
->hwnd
, WM_GETFONT
, 0, 0);
1398 hPrevFont
= SelectObject(hDC
, font
);
1401 GetClientRect(infoPtr
->hwnd
, &bgRect
);
1407 GetTextExtentPoint32W(hDC
, text
, lstrlenW(text
), &textExtent
);
1408 bgRect
.top
+= (textExtent
.cy
/ 2);
1409 textRect
.left
+= 10;
1410 textRect
.bottom
= textRect
.top
+ textExtent
.cy
;
1411 textRect
.right
= textRect
.left
+ textExtent
.cx
+ 4;
1413 ExcludeClipRect(hDC
, textRect
.left
, textRect
.top
, textRect
.right
, textRect
.bottom
);
1416 GetThemeBackgroundContentRect(theme
, hDC
, BP_GROUPBOX
, state
, &bgRect
, &contentRect
);
1417 ExcludeClipRect(hDC
, contentRect
.left
, contentRect
.top
, contentRect
.right
, contentRect
.bottom
);
1419 if (IsThemeBackgroundPartiallyTransparent(theme
, BP_GROUPBOX
, state
))
1420 DrawThemeParentBackground(infoPtr
->hwnd
, hDC
, NULL
);
1421 DrawThemeBackground(theme
, hDC
, BP_GROUPBOX
, state
, &bgRect
, NULL
);
1423 SelectClipRgn(hDC
, NULL
);
1427 InflateRect(&textRect
, -2, 0);
1428 DrawThemeText(theme
, hDC
, BP_GROUPBOX
, state
, text
, lstrlenW(text
), 0, 0, &textRect
);
1432 if (created_font
) DeleteObject(font
);
1433 if (hPrevFont
) SelectObject(hDC
, hPrevFont
);
1436 void BUTTON_Register(void)
1440 memset(&wndClass
, 0, sizeof(wndClass
));
1441 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_VREDRAW
| CS_HREDRAW
| CS_PARENTDC
;
1442 wndClass
.lpfnWndProc
= BUTTON_WindowProc
;
1443 wndClass
.cbClsExtra
= 0;
1444 wndClass
.cbWndExtra
= sizeof(BUTTON_INFO
*);
1445 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
1446 wndClass
.hbrBackground
= NULL
;
1447 wndClass
.lpszClassName
= WC_BUTTONW
;
1448 RegisterClassW(&wndClass
);