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_BMCLICK 0x100 // ReactOS Need to up to wine!
85 #define BUTTON_NOTIFY_PARENT(hWnd, code) \
86 do { /* Notify parent which has created this button control */ \
87 TRACE("notification " #code " sent to hwnd=%p\n", GetParent(hWnd)); \
88 SendMessageW(GetParent(hWnd), WM_COMMAND, \
89 MAKEWPARAM(GetWindowLongPtrW((hWnd),GWLP_ID), (code)), \
93 typedef struct _BUTTON_INFO
108 BUTTON_IMAGELIST imlData
;
112 static UINT
BUTTON_CalcLabelRect( const BUTTON_INFO
*infoPtr
, HDC hdc
, RECT
*rc
);
113 static void PB_Paint( const BUTTON_INFO
*infoPtr
, HDC hDC
, UINT action
);
114 static void CB_Paint( const BUTTON_INFO
*infoPtr
, HDC hDC
, UINT action
);
115 static void GB_Paint( const BUTTON_INFO
*infoPtr
, HDC hDC
, UINT action
);
116 static void UB_Paint( const BUTTON_INFO
*infoPtr
, HDC hDC
, UINT action
);
117 static void OB_Paint( const BUTTON_INFO
*infoPtr
, HDC hDC
, UINT action
);
118 static void BUTTON_CheckAutoRadioButton( HWND hwnd
);
120 #define MAX_BTN_TYPE 16
122 static const WORD maxCheckState
[MAX_BTN_TYPE
] =
124 BST_UNCHECKED
, /* BS_PUSHBUTTON */
125 BST_UNCHECKED
, /* BS_DEFPUSHBUTTON */
126 BST_CHECKED
, /* BS_CHECKBOX */
127 BST_CHECKED
, /* BS_AUTOCHECKBOX */
128 BST_CHECKED
, /* BS_RADIOBUTTON */
129 BST_INDETERMINATE
, /* BS_3STATE */
130 BST_INDETERMINATE
, /* BS_AUTO3STATE */
131 BST_UNCHECKED
, /* BS_GROUPBOX */
132 BST_UNCHECKED
, /* BS_USERBUTTON */
133 BST_CHECKED
, /* BS_AUTORADIOBUTTON */
134 BST_UNCHECKED
, /* BS_PUSHBOX */
135 BST_UNCHECKED
, /* BS_OWNERDRAW */
136 BST_UNCHECKED
, /* BS_SPLITBUTTON */
137 BST_UNCHECKED
, /* BS_DEFSPLITBUTTON */
138 BST_UNCHECKED
, /* BS_COMMANDLINK */
139 BST_UNCHECKED
/* BS_DEFCOMMANDLINK */
142 /* These are indices into a states array to determine the theme state for a given theme part. */
152 typedef void (*pfPaint
)( const BUTTON_INFO
*infoPtr
, HDC hdc
, UINT action
);
154 static const pfPaint btnPaintFunc
[MAX_BTN_TYPE
] =
156 PB_Paint
, /* BS_PUSHBUTTON */
157 PB_Paint
, /* BS_DEFPUSHBUTTON */
158 CB_Paint
, /* BS_CHECKBOX */
159 CB_Paint
, /* BS_AUTOCHECKBOX */
160 CB_Paint
, /* BS_RADIOBUTTON */
161 CB_Paint
, /* BS_3STATE */
162 CB_Paint
, /* BS_AUTO3STATE */
163 GB_Paint
, /* BS_GROUPBOX */
164 UB_Paint
, /* BS_USERBUTTON */
165 CB_Paint
, /* BS_AUTORADIOBUTTON */
166 NULL
, /* BS_PUSHBOX */
167 OB_Paint
, /* BS_OWNERDRAW */
168 PB_Paint
, /* BS_SPLITBUTTON */
169 PB_Paint
, /* BS_DEFSPLITBUTTON */
170 PB_Paint
, /* BS_COMMANDLINK */
171 PB_Paint
/* BS_DEFCOMMANDLINK */
175 #ifdef __REACTOS__ /* r73885 */
176 typedef void (*pfThemedPaint
)( HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hdc
, ButtonState drawState
, UINT dtflags
, BOOL focused
, LPARAM prfFlag
);
178 static void PB_ThemedPaint( HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hdc
, ButtonState drawState
, UINT dtflags
, BOOL focused
, LPARAM prfFlag
);
179 static void CB_ThemedPaint( HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hdc
, ButtonState drawState
, UINT dtflags
, BOOL focused
, LPARAM prfFlag
);
180 static void GB_ThemedPaint( HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hdc
, ButtonState drawState
, UINT dtflags
, BOOL focused
, LPARAM prfFlag
);
183 typedef void (*pfThemedPaint
)( HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hdc
, ButtonState drawState
, UINT dtflags
, BOOL focused
);
185 static void PB_ThemedPaint( HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hdc
, ButtonState drawState
, UINT dtflags
, BOOL focused
);
186 static void CB_ThemedPaint( HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hdc
, ButtonState drawState
, UINT dtflags
, BOOL focused
);
187 static void GB_ThemedPaint( HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hdc
, ButtonState drawState
, UINT dtflags
, BOOL focused
);
191 static const pfThemedPaint btnThemedPaintFunc
[MAX_BTN_TYPE
] =
193 PB_ThemedPaint
, /* BS_PUSHBUTTON */
194 PB_ThemedPaint
, /* BS_DEFPUSHBUTTON */
195 CB_ThemedPaint
, /* BS_CHECKBOX */
196 CB_ThemedPaint
, /* BS_AUTOCHECKBOX */
197 CB_ThemedPaint
, /* BS_RADIOBUTTON */
198 CB_ThemedPaint
, /* BS_3STATE */
199 CB_ThemedPaint
, /* BS_AUTO3STATE */
200 GB_ThemedPaint
, /* BS_GROUPBOX */
201 NULL
, /* BS_USERBUTTON */
202 CB_ThemedPaint
, /* BS_AUTORADIOBUTTON */
203 NULL
, /* BS_PUSHBOX */
204 NULL
, /* BS_OWNERDRAW */
205 NULL
, /* BS_SPLITBUTTON */
206 NULL
, /* BS_DEFSPLITBUTTON */
207 NULL
, /* BS_COMMANDLINK */
208 NULL
, /* BS_DEFCOMMANDLINK */
211 static inline UINT
get_button_type( LONG window_style
)
213 return (window_style
& BS_TYPEMASK
);
217 /* paint a button of any type */
218 static inline void paint_button( BUTTON_INFO
*infoPtr
, LONG style
, UINT action
)
220 if (btnPaintFunc
[style
] && IsWindowVisible(infoPtr
->hwnd
))
222 HDC hdc
= GetDC( infoPtr
->hwnd
);
223 btnPaintFunc
[style
]( infoPtr
, hdc
, action
);
224 ReleaseDC( infoPtr
->hwnd
, hdc
);
229 /* retrieve the button text; returned buffer must be freed by caller */
230 static inline WCHAR
*get_button_text( const BUTTON_INFO
*infoPtr
)
232 INT len
= GetWindowTextLengthW( infoPtr
->hwnd
);
233 WCHAR
*buffer
= heap_alloc( (len
+ 1) * sizeof(WCHAR
) );
235 GetWindowTextW( infoPtr
->hwnd
, buffer
, len
+ 1 );
239 HRGN
set_control_clipping( HDC hdc
, const RECT
*rect
)
242 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
244 if (GetClipRgn( hdc
, hrgn
) != 1)
246 DeleteObject( hrgn
);
249 DPtoLP( hdc
, (POINT
*)&rc
, 2 );
250 if (GetLayout( hdc
) & LAYOUT_RTL
) /* compensate for the shifting done by IntersectClipRect */
255 IntersectClipRect( hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
259 /**********************************************************************
260 * Convert button styles to flags used by DrawText.
262 static UINT
BUTTON_BStoDT( DWORD style
, DWORD ex_style
)
264 UINT dtStyle
= DT_NOCLIP
; /* We use SelectClipRgn to limit output */
266 /* "Convert" pushlike buttons to pushbuttons */
267 if (style
& BS_PUSHLIKE
)
268 style
&= ~BS_TYPEMASK
;
270 if (!(style
& BS_MULTILINE
))
271 dtStyle
|= DT_SINGLELINE
;
273 dtStyle
|= DT_WORDBREAK
;
275 switch (style
& BS_CENTER
)
277 case BS_LEFT
: /* DT_LEFT is 0 */ break;
278 case BS_RIGHT
: dtStyle
|= DT_RIGHT
; break;
279 case BS_CENTER
: dtStyle
|= DT_CENTER
; break;
281 /* Pushbutton's text is centered by default */
282 if (get_button_type(style
) <= BS_DEFPUSHBUTTON
) dtStyle
|= DT_CENTER
;
283 /* all other flavours have left aligned text */
286 if (ex_style
& WS_EX_RIGHT
) dtStyle
= DT_RIGHT
| (dtStyle
& ~(DT_LEFT
| DT_CENTER
));
288 /* DrawText ignores vertical alignment for multiline text,
289 * but we use these flags to align label manually.
291 if (get_button_type(style
) != BS_GROUPBOX
)
293 switch (style
& BS_VCENTER
)
295 case BS_TOP
: /* DT_TOP is 0 */ break;
296 case BS_BOTTOM
: dtStyle
|= DT_BOTTOM
; break;
297 case BS_VCENTER
: /* fall through */
298 default: dtStyle
|= DT_VCENTER
; break;
302 /* GroupBox's text is always single line and is top aligned. */
303 dtStyle
|= DT_SINGLELINE
;
310 BOOL
BUTTON_PaintWithTheme(HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hParamDC
, LPARAM prfFlag
)
316 ButtonState drawState
;
319 /* Don't draw with themes on a button with BS_ICON or BS_BITMAP */
320 if (infoPtr
->u
.image
!= 0)
323 dwStyle
= GetWindowLongW(infoPtr
->hwnd
, GWL_STYLE
);
324 type
= get_button_type(dwStyle
);
326 if (type
!= BS_PUSHBUTTON
&& type
!= BS_DEFPUSHBUTTON
&& (dwStyle
& BS_PUSHLIKE
))
327 type
= BS_PUSHBUTTON
;
329 paint
= btnThemedPaintFunc
[type
];
333 dwStyleEx
= GetWindowLongW(infoPtr
->hwnd
, GWL_EXSTYLE
);
334 dtFlags
= BUTTON_BStoDT(dwStyle
, dwStyleEx
);
336 if(dwStyle
& WS_DISABLED
)
337 drawState
= STATE_DISABLED
;
338 else if(infoPtr
->state
& BST_PUSHED
)
339 drawState
= STATE_PRESSED
;
340 else if ((dwStyle
& BS_PUSHLIKE
) && (infoPtr
->state
& (BST_CHECKED
|BST_INDETERMINATE
)))
341 drawState
= STATE_PRESSED
;
342 else if(infoPtr
->state
& BST_HOT
)
343 drawState
= STATE_HOT
;
344 else if((infoPtr
->state
& BST_FOCUS
) || (dwStyle
& BS_DEFPUSHBUTTON
))
345 drawState
= STATE_DEFAULTED
;
347 drawState
= STATE_NORMAL
;
349 if (paint
== PB_ThemedPaint
|| paint
== CB_ThemedPaint
)
355 GetClientRect(infoPtr
->hwnd
, &rc
);
356 hdc
= CreateCompatibleDC(hParamDC
);
357 hbmp
= CreateCompatibleBitmap(hParamDC
, rc
.right
, rc
.bottom
);
360 SelectObject(hdc
, hbmp
);
362 paint(theme
, infoPtr
, hdc
, drawState
, dtFlags
, infoPtr
->state
& BST_FOCUS
, prfFlag
);
364 BitBlt(hParamDC
, 0, 0, rc
.right
, rc
.bottom
, hdc
, 0, 0, SRCCOPY
);
371 ERR("Failed to create DC and bitmap for double buffering\n");
379 paint(theme
, infoPtr
, hParamDC
, drawState
, dtFlags
, infoPtr
->state
& BST_FOCUS
, prfFlag
);
383 /* paint a button of any type */
384 static inline void paint_button( BUTTON_INFO
*infoPtr
, LONG style
, UINT action
)
386 HTHEME theme
= GetWindowTheme(infoPtr
->hwnd
);
388 HDC hdc
= GetDC( infoPtr
->hwnd
);
389 /* GetDC appears to give a dc with a clip rect that includes the whoe parent, not sure if it is correct or not. */
390 GetClientRect(infoPtr
->hwnd
, &rc
);
391 IntersectClipRect (hdc
, rc
.left
, rc
. top
, rc
.right
, rc
.bottom
);
392 if (theme
&& BUTTON_PaintWithTheme(theme
, infoPtr
, hdc
, 0))
394 ReleaseDC( infoPtr
->hwnd
, hdc
);
397 if (btnPaintFunc
[style
] && IsWindowVisible(infoPtr
->hwnd
))
399 btnPaintFunc
[style
]( infoPtr
, hdc
, action
);
401 ReleaseDC( infoPtr
->hwnd
, hdc
);
404 BOOL
BUTTON_GetIdealSize(BUTTON_INFO
*infoPtr
, HTHEME theme
, SIZE
* psize
)
408 HFONT hFont
= 0, hPrevFont
= 0;
409 SIZE TextSize
, ImageSize
, ButtonSize
;
411 LOGFONTW logfont
= {0};
413 text
= get_button_text(infoPtr
);
414 hdc
= GetDC(infoPtr
->hwnd
);
415 if (!text
|| !hdc
|| !text
[0])
418 /* FIXME : Should use GetThemeTextExtent but unfortunately uses DrawTextW which is broken */
421 HRESULT hr
= GetThemeFont(theme
, hdc
, BP_PUSHBUTTON
, PBS_NORMAL
, TMT_FONT
, &logfont
);
424 hFont
= CreateFontIndirectW(&logfont
);
426 hPrevFont
= SelectObject( hdc
, hFont
);
432 hPrevFont
= SelectObject( hdc
, infoPtr
->font
);
435 GetTextExtentPoint32W(hdc
, text
, wcslen(text
), &TextSize
);
437 if (logfont
.lfHeight
== -1 && logfont
.lfWidth
== 0 && wcscmp(logfont
.lfFaceName
, L
"Arial") == 0 && wcsicmp(text
, L
"Start") == 0)
444 SelectObject( hdc
, hPrevFont
);
446 TextSize
.cy
+= infoPtr
->rcTextMargin
.top
+ infoPtr
->rcTextMargin
.bottom
;
447 TextSize
.cx
+= infoPtr
->rcTextMargin
.left
+ infoPtr
->rcTextMargin
.right
;
449 if (infoPtr
->imlData
.himl
&& ImageList_GetIconSize(infoPtr
->imlData
.himl
, &ImageSize
.cx
, &ImageSize
.cy
))
451 ImageSize
.cx
+= infoPtr
->imlData
.margin
.left
+ infoPtr
->imlData
.margin
.right
;
452 ImageSize
.cy
+= infoPtr
->imlData
.margin
.top
+ infoPtr
->imlData
.margin
.bottom
;
456 ImageSize
.cx
= ImageSize
.cy
= 0;
461 RECT rcContents
= {0};
462 RECT rcButtonExtent
= {0};
463 rcContents
.right
= ImageSize
.cx
+ TextSize
.cx
;
464 rcContents
.bottom
= max(ImageSize
.cy
, TextSize
.cy
);
465 GetThemeBackgroundExtent(theme
, hdc
, BP_PUSHBUTTON
, PBS_NORMAL
, &rcContents
, &rcButtonExtent
);
466 ButtonSize
.cx
= rcButtonExtent
.right
- rcButtonExtent
.left
;
467 ButtonSize
.cy
= rcButtonExtent
.bottom
- rcButtonExtent
.top
;
471 ButtonSize
.cx
= ImageSize
.cx
+ TextSize
.cx
+ 5;
472 ButtonSize
.cy
= max(ImageSize
.cy
, TextSize
.cy
+ 7);
482 HeapFree( GetProcessHeap(), 0, text
);
484 ReleaseDC(infoPtr
->hwnd
, hdc
);
489 BOOL
BUTTON_DrawIml(HDC hDC
, const BUTTON_IMAGELIST
*pimlData
, RECT
*prc
, BOOL bOnlyCalc
, int index
)
492 int left
, top
, count
;
497 if (!ImageList_GetIconSize(pimlData
->himl
, &ImageSize
.cx
, &ImageSize
.cy
))
500 if (pimlData
->uAlign
== BUTTON_IMAGELIST_ALIGN_LEFT
)
502 left
= prc
->left
+ pimlData
->margin
.left
;
503 top
= prc
->top
+ (prc
->bottom
- prc
->top
- ImageSize
.cy
) / 2;
504 prc
->left
= left
+ pimlData
->margin
.right
+ ImageSize
.cx
;
506 else if (pimlData
->uAlign
== BUTTON_IMAGELIST_ALIGN_RIGHT
)
508 left
= prc
->right
- pimlData
->margin
.right
- ImageSize
.cx
;
509 top
= prc
->top
+ (prc
->bottom
- prc
->top
- ImageSize
.cy
) / 2;
510 prc
->right
= left
- pimlData
->margin
.left
;
512 else if (pimlData
->uAlign
== BUTTON_IMAGELIST_ALIGN_TOP
)
514 left
= prc
->left
+ (prc
->right
- prc
->left
- ImageSize
.cx
) / 2;
515 top
= prc
->top
+ pimlData
->margin
.top
;
516 prc
->top
= top
+ ImageSize
.cy
+ pimlData
->margin
.bottom
;
518 else if (pimlData
->uAlign
== BUTTON_IMAGELIST_ALIGN_BOTTOM
)
520 left
= prc
->left
+ (prc
->right
- prc
->left
- ImageSize
.cx
) / 2;
521 top
= prc
->bottom
- pimlData
->margin
.bottom
- ImageSize
.cy
;
522 prc
->bottom
= top
- pimlData
->margin
.top
;
524 else if (pimlData
->uAlign
== BUTTON_IMAGELIST_ALIGN_CENTER
)
526 left
= prc
->left
+ (prc
->right
- prc
->left
- ImageSize
.cx
) / 2;
527 top
= prc
->top
+ (prc
->bottom
- prc
->top
- ImageSize
.cy
) / 2;
533 count
= ImageList_GetImageCount(pimlData
->himl
);
537 else if (index
>= count
)
540 ImageList_Draw(pimlData
->himl
, index
, hDC
, left
, top
, 0);
545 DWORD
BUTTON_SendCustomDraw(const BUTTON_INFO
*infoPtr
, HDC hDC
, DWORD dwDrawStage
, RECT
* prc
)
549 nmcs
.hdr
.hwndFrom
= infoPtr
->hwnd
;
550 nmcs
.hdr
.idFrom
= GetWindowLongPtrW (infoPtr
->hwnd
, GWLP_ID
);
551 nmcs
.hdr
.code
= NM_CUSTOMDRAW
;
552 nmcs
.dwDrawStage
= dwDrawStage
;
557 nmcs
.lItemlParam
= 0;
558 if(!IsWindowEnabled(infoPtr
->hwnd
))
559 nmcs
.uItemState
|= CDIS_DISABLED
;
560 if (infoPtr
->state
& (BST_CHECKED
| BST_INDETERMINATE
))
561 nmcs
.uItemState
|= CDIS_CHECKED
;
562 if (infoPtr
->state
& BST_FOCUS
)
563 nmcs
.uItemState
|= CDIS_FOCUS
;
564 if (infoPtr
->state
& BST_PUSHED
)
565 nmcs
.uItemState
|= CDIS_SELECTED
;
566 if (!(infoPtr
->ui_state
& UISF_HIDEACCEL
))
567 nmcs
.uItemState
|= CDIS_SHOWKEYBOARDCUES
;
569 return SendMessageW(GetParent(infoPtr
->hwnd
), WM_NOTIFY
, nmcs
.hdr
.idFrom
, (LPARAM
)&nmcs
);
572 /* Retrieve the UI state for the control */
573 static BOOL
button_update_uistate(BUTTON_INFO
*infoPtr
)
575 LONG flags
= DefWindowProcW(infoPtr
->hwnd
, WM_QUERYUISTATE
, 0, 0);
577 if (infoPtr
->ui_state
!= flags
)
579 infoPtr
->ui_state
= flags
;
587 static LRESULT CALLBACK
BUTTON_WindowProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
589 BUTTON_INFO
*infoPtr
= (BUTTON_INFO
*)GetWindowLongPtrW(hWnd
, 0);
592 LONG style
= GetWindowLongW( hWnd
, GWL_STYLE
);
593 UINT btn_type
= get_button_type( style
);
594 LONG state
, new_state
;
598 if (!IsWindow( hWnd
)) return 0;
600 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
601 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
603 pt
.x
= (short)LOWORD(lParam
);
604 pt
.y
= (short)HIWORD(lParam
);
613 case BS_PUSHBUTTON
: return DLGC_BUTTON
| DLGC_UNDEFPUSHBUTTON
;
614 case BS_DEFCOMMANDLINK
:
615 case BS_DEFPUSHBUTTON
: return DLGC_BUTTON
| DLGC_DEFPUSHBUTTON
;
617 case BS_AUTORADIOBUTTON
: return DLGC_BUTTON
| DLGC_RADIOBUTTON
;
618 case BS_GROUPBOX
: return DLGC_STATIC
;
619 case BS_SPLITBUTTON
: return DLGC_BUTTON
| DLGC_UNDEFPUSHBUTTON
| DLGC_WANTARROWS
;
620 case BS_DEFSPLITBUTTON
: return DLGC_BUTTON
| DLGC_DEFPUSHBUTTON
| DLGC_WANTARROWS
;
621 default: return DLGC_BUTTON
;
626 theme
= GetWindowTheme( hWnd
);
628 RedrawWindow( hWnd
, NULL
, NULL
, RDW_FRAME
| RDW_INVALIDATE
| RDW_UPDATENOW
);
631 paint_button( infoPtr
, btn_type
, ODA_DRAWENTIRE
);
635 infoPtr
= heap_alloc_zero( sizeof(*infoPtr
) );
636 SetWindowLongPtrW( hWnd
, 0, (LONG_PTR
)infoPtr
);
637 infoPtr
->hwnd
= hWnd
;
639 SetRect(&infoPtr
->rcTextMargin
, 1,1,1,1);
641 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
644 SetWindowLongPtrW( hWnd
, 0, 0 );
649 if (btn_type
>= MAX_BTN_TYPE
)
650 return -1; /* abort */
652 /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
653 if (btn_type
== BS_USERBUTTON
)
655 style
= (style
& ~BS_TYPEMASK
) | BS_PUSHBUTTON
;
656 SetWindowLongW( hWnd
, GWL_STYLE
, style
);
658 infoPtr
->state
= BST_UNCHECKED
;
659 OpenThemeData( hWnd
, WC_BUTTONW
);
663 theme
= GetWindowTheme( hWnd
);
664 CloseThemeData( theme
);
667 case WM_THEMECHANGED
:
668 theme
= GetWindowTheme( hWnd
);
669 CloseThemeData( theme
);
670 OpenThemeData( hWnd
, WC_BUTTONW
);
672 InvalidateRect(hWnd
, NULL
, TRUE
);
677 if (btn_type
== BS_OWNERDRAW
)
679 HDC hdc
= (HDC
)wParam
;
682 HWND parent
= GetParent(hWnd
);
683 if (!parent
) parent
= hWnd
;
684 hBrush
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORBTN
, (WPARAM
)hdc
, (LPARAM
)hWnd
);
685 if (!hBrush
) /* did the app forget to call defwindowproc ? */
686 hBrush
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORBTN
,
687 (WPARAM
)hdc
, (LPARAM
)hWnd
);
688 GetClientRect(hWnd
, &rc
);
689 FillRect(hdc
, &rc
, hBrush
);
699 theme
= GetWindowTheme( hWnd
);
700 hdc
= wParam
? (HDC
)wParam
: BeginPaint( hWnd
, &ps
);
703 if (theme
&& BUTTON_PaintWithTheme(theme
, infoPtr
, hdc
, uMsg
== WM_PRINTCLIENT
? lParam
: 0))
705 if ( !wParam
) EndPaint( hWnd
, &ps
);
709 if (theme
&& btnThemedPaintFunc
[btn_type
])
711 ButtonState drawState
;
714 if (IsWindowEnabled( hWnd
))
716 if (infoPtr
->state
& BST_PUSHED
) drawState
= STATE_PRESSED
;
717 else if (infoPtr
->state
& BST_HOT
) drawState
= STATE_HOT
;
718 else if (infoPtr
->state
& BST_FOCUS
) drawState
= STATE_DEFAULTED
;
719 else drawState
= STATE_NORMAL
;
722 drawState
= STATE_DISABLED
;
724 dtflags
= BUTTON_BStoDT(style
, GetWindowLongW(hWnd
, GWL_EXSTYLE
));
725 btnThemedPaintFunc
[btn_type
](theme
, infoPtr
, hdc
, drawState
, dtflags
, infoPtr
->state
& BST_FOCUS
);
728 else if (btnPaintFunc
[btn_type
])
730 int nOldMode
= SetBkMode( hdc
, OPAQUE
);
731 btnPaintFunc
[btn_type
]( infoPtr
, hdc
, ODA_DRAWENTIRE
);
732 SetBkMode(hdc
, nOldMode
); /* reset painting mode */
735 if ( !wParam
) EndPaint( hWnd
, &ps
);
740 if (wParam
== VK_SPACE
)
742 SendMessageW( hWnd
, BM_SETSTATE
, TRUE
, 0 );
743 infoPtr
->state
|= BUTTON_BTNPRESSED
;
748 case WM_LBUTTONDBLCLK
:
749 if(style
& BS_NOTIFY
||
750 btn_type
== BS_RADIOBUTTON
||
751 btn_type
== BS_USERBUTTON
||
752 btn_type
== BS_OWNERDRAW
)
754 BUTTON_NOTIFY_PARENT(hWnd
, BN_DOUBLECLICKED
);
761 infoPtr
->state
|= BUTTON_BTNPRESSED
;
762 SendMessageW( hWnd
, BM_SETSTATE
, TRUE
, 0 );
766 if (wParam
!= VK_SPACE
)
770 state
= infoPtr
->state
;
771 if (!(state
& BUTTON_BTNPRESSED
)) break;
772 infoPtr
->state
&= BUTTON_NSTATES
;
773 if (!(state
& BST_PUSHED
))
778 SendMessageW( hWnd
, BM_SETSTATE
, FALSE
, 0 );
779 GetClientRect( hWnd
, &rect
);
780 if (uMsg
== WM_KEYUP
|| PtInRect( &rect
, pt
))
784 case BS_AUTOCHECKBOX
:
785 SendMessageW( hWnd
, BM_SETCHECK
, !(infoPtr
->state
& BST_CHECKED
), 0 );
787 case BS_AUTORADIOBUTTON
:
788 SendMessageW( hWnd
, BM_SETCHECK
, TRUE
, 0 );
791 SendMessageW( hWnd
, BM_SETCHECK
, (infoPtr
->state
& BST_INDETERMINATE
) ? 0 :
792 ((infoPtr
->state
& 3) + 1), 0 );
796 // Fix CORE-10194, Notify parent after capture is released.
798 BUTTON_NOTIFY_PARENT(hWnd
, BN_CLICKED
);
800 BUTTON_NOTIFY_PARENT(hWnd
, BN_CLICKED
);
811 case WM_CAPTURECHANGED
:
812 TRACE("WM_CAPTURECHANGED %p\n", hWnd
);
813 if (hWnd
== (HWND
)lParam
) break;
814 if (infoPtr
->state
& BUTTON_BTNPRESSED
)
816 infoPtr
->state
&= BUTTON_NSTATES
;
817 if (infoPtr
->state
& BST_PUSHED
)
818 SendMessageW( hWnd
, BM_SETSTATE
, FALSE
, 0 );
824 TRACKMOUSEEVENT mouse_event
;
825 mouse_event
.cbSize
= sizeof(TRACKMOUSEEVENT
);
826 mouse_event
.dwFlags
= TME_QUERY
;
829 if ((infoPtr
->state
& BST_HOT
) == 0)
831 NMBCHOTITEM nmhotitem
;
833 infoPtr
->state
|= BST_HOT
;
835 nmhotitem
.hdr
.hwndFrom
= hWnd
;
836 nmhotitem
.hdr
.idFrom
= GetWindowLongPtrW (hWnd
, GWLP_ID
);
837 nmhotitem
.hdr
.code
= BCN_HOTITEMCHANGE
;
838 nmhotitem
.dwFlags
= HICF_ENTERING
;
839 SendMessageW(GetParent(hWnd
), WM_NOTIFY
, nmhotitem
.hdr
.idFrom
, (LPARAM
)&nmhotitem
);
841 InvalidateRect(hWnd
, NULL
, TRUE
);
844 if(!TrackMouseEvent(&mouse_event
) || !(mouse_event
.dwFlags
&TME_LEAVE
))
846 mouse_event
.dwFlags
= TME_LEAVE
;
847 mouse_event
.hwndTrack
= hWnd
;
848 mouse_event
.dwHoverTime
= 1;
849 TrackMouseEvent(&mouse_event
);
854 if (!TrackMouseEvent(&mouse_event
) || !(mouse_event
.dwFlags
& (TME_HOVER
| TME_LEAVE
)))
856 mouse_event
.dwFlags
= TME_HOVER
| TME_LEAVE
;
857 mouse_event
.hwndTrack
= hWnd
;
858 mouse_event
.dwHoverTime
= 1;
859 TrackMouseEvent(&mouse_event
);
862 if ((wParam
& MK_LBUTTON
) && GetCapture() == hWnd
)
864 GetClientRect( hWnd
, &rect
);
865 SendMessageW( hWnd
, BM_SETSTATE
, PtInRect(&rect
, pt
), 0 );
874 infoPtr
->state
|= BST_HOT
;
875 InvalidateRect( hWnd
, NULL
, FALSE
);
883 if (infoPtr
->state
& BST_HOT
)
885 NMBCHOTITEM nmhotitem
;
887 infoPtr
->state
&= ~BST_HOT
;
889 nmhotitem
.hdr
.hwndFrom
= hWnd
;
890 nmhotitem
.hdr
.idFrom
= GetWindowLongPtrW (hWnd
, GWLP_ID
);
891 nmhotitem
.hdr
.code
= BCN_HOTITEMCHANGE
;
892 nmhotitem
.dwFlags
= HICF_LEAVING
;
893 SendMessageW(GetParent(hWnd
), WM_NOTIFY
, nmhotitem
.hdr
.idFrom
, (LPARAM
)&nmhotitem
);
895 InvalidateRect(hWnd
, NULL
, TRUE
);
899 infoPtr
->state
&= ~BST_HOT
;
900 InvalidateRect( hWnd
, NULL
, FALSE
);
906 case BCM_GETTEXTMARGIN
:
908 RECT
* prc
= (RECT
*)lParam
;
911 *prc
= infoPtr
->rcTextMargin
;
914 case BCM_SETTEXTMARGIN
:
916 RECT
* prc
= (RECT
*)lParam
;
919 infoPtr
->rcTextMargin
= *prc
;
922 case BCM_SETIMAGELIST
:
924 BUTTON_IMAGELIST
* pimldata
= (BUTTON_IMAGELIST
*)lParam
;
925 if (!pimldata
|| !pimldata
->himl
)
927 infoPtr
->imlData
= *pimldata
;
930 case BCM_GETIMAGELIST
:
932 BUTTON_IMAGELIST
* pimldata
= (BUTTON_IMAGELIST
*)lParam
;
935 *pimldata
= infoPtr
->imlData
;
938 case BCM_GETIDEALSIZE
:
940 HTHEME theme
= GetWindowTheme(hWnd
);
942 SIZE
* pSize
= (SIZE
*)lParam
;
949 if (btn_type
== BS_PUSHBUTTON
||
950 btn_type
== BS_DEFPUSHBUTTON
||
951 btn_type
== BS_USERBUTTON
)
953 ret
= BUTTON_GetIdealSize(infoPtr
, theme
, pSize
);
958 GetClientRect(hWnd
, &rect
);
959 pSize
->cx
= rect
.right
;
960 pSize
->cy
= rect
.bottom
;
969 /* Clear an old text here as Windows does */
973 // wine Bug: http://bugs.winehq.org/show_bug.cgi?id=25790
974 // Patch: http://source.winehq.org/patches/data/70889
975 // By: Alexander LAW, Replicate Windows behavior of WM_SETTEXT handler regarding WM_CTLCOLOR*
977 if (style
& WS_VISIBLE
)
979 if (IsWindowVisible(hWnd
))
982 HDC hdc
= GetDC(hWnd
);
985 HWND parent
= GetParent(hWnd
);
986 UINT message
= (btn_type
== BS_PUSHBUTTON
||
987 btn_type
== BS_DEFPUSHBUTTON
||
988 btn_type
== BS_USERBUTTON
||
989 btn_type
== BS_OWNERDRAW
) ?
990 WM_CTLCOLORBTN
: WM_CTLCOLORSTATIC
;
992 if (!parent
) parent
= hWnd
;
993 hbrush
= (HBRUSH
)SendMessageW(parent
, message
,
994 (WPARAM
)hdc
, (LPARAM
)hWnd
);
995 if (!hbrush
) /* did the app forget to call DefWindowProc ? */
996 hbrush
= (HBRUSH
)DefWindowProcW(parent
, message
,
997 (WPARAM
)hdc
, (LPARAM
)hWnd
);
999 GetClientRect(hWnd
, &client
);
1001 /* FIXME: check other BS_* handlers */
1002 if (btn_type
== BS_GROUPBOX
)
1003 InflateRect(&rc
, -7, 1); /* GB_Paint does this */
1004 BUTTON_CalcLabelRect(infoPtr
, hdc
, &rc
);
1005 /* Clip by client rect bounds */
1006 if (rc
.right
> client
.right
) rc
.right
= client
.right
;
1007 if (rc
.bottom
> client
.bottom
) rc
.bottom
= client
.bottom
;
1008 FillRect(hdc
, &rc
, hbrush
);
1009 ReleaseDC(hWnd
, hdc
);
1012 DefWindowProcW( hWnd
, WM_SETTEXT
, wParam
, lParam
);
1013 if (btn_type
== BS_GROUPBOX
) /* Yes, only for BS_GROUPBOX */
1014 InvalidateRect( hWnd
, NULL
, TRUE
);
1016 paint_button( infoPtr
, btn_type
, ODA_DRAWENTIRE
);
1017 return 1; /* success. FIXME: check text length */
1021 infoPtr
->font
= (HFONT
)wParam
;
1022 if (lParam
) InvalidateRect(hWnd
, NULL
, TRUE
);
1026 return (LRESULT
)infoPtr
->font
;
1029 TRACE("WM_SETFOCUS %p\n",hWnd
);
1030 infoPtr
->state
|= BST_FOCUS
;
1032 if (btn_type
!= BS_OWNERDRAW
)
1033 InvalidateRect(hWnd
, NULL
, FALSE
);
1036 paint_button( infoPtr
, btn_type
, ODA_FOCUS
);
1037 if (style
& BS_NOTIFY
)
1038 BUTTON_NOTIFY_PARENT(hWnd
, BN_SETFOCUS
);
1042 TRACE("WM_KILLFOCUS %p\n",hWnd
);
1043 infoPtr
->state
&= ~BST_FOCUS
;
1045 paint_button( infoPtr
, btn_type
, ODA_FOCUS
);
1048 if ((infoPtr
->state
& BUTTON_BTNPRESSED
) && GetCapture() == hWnd
)
1050 if (style
& BS_NOTIFY
)
1051 BUTTON_NOTIFY_PARENT(hWnd
, BN_KILLFOCUS
);
1053 InvalidateRect( hWnd
, NULL
, FALSE
);
1056 case WM_SYSCOLORCHANGE
:
1057 InvalidateRect( hWnd
, NULL
, FALSE
);
1061 btn_type
= wParam
& BS_TYPEMASK
;
1062 style
= (style
& ~BS_TYPEMASK
) | btn_type
;
1063 SetWindowLongW( hWnd
, GWL_STYLE
, style
);
1065 /* Only redraw if lParam flag is set.*/
1067 InvalidateRect( hWnd
, NULL
, TRUE
);
1073 /* Fix for core CORE-6024 */
1074 if (infoPtr
->state
& BUTTON_BMCLICK
)
1076 infoPtr
->state
|= BUTTON_BMCLICK
;
1078 SendMessageW( hWnd
, WM_LBUTTONDOWN
, 0, 0 );
1079 SendMessageW( hWnd
, WM_LBUTTONUP
, 0, 0 );
1081 infoPtr
->state
&= ~BUTTON_BMCLICK
;
1086 /* Check that image format matches button style */
1087 switch (style
& (BS_BITMAP
|BS_ICON
))
1090 if (wParam
!= IMAGE_BITMAP
) return 0;
1093 if (wParam
!= IMAGE_ICON
) return 0;
1098 oldHbitmap
= infoPtr
->u
.image
;
1099 infoPtr
->u
.image
= (HANDLE
)lParam
;
1100 InvalidateRect( hWnd
, NULL
, FALSE
);
1101 return (LRESULT
)oldHbitmap
;
1104 return (LRESULT
)infoPtr
->u
.image
;
1107 return infoPtr
->state
& 3;
1110 if (wParam
> maxCheckState
[btn_type
]) wParam
= maxCheckState
[btn_type
];
1111 if ((btn_type
== BS_RADIOBUTTON
) || (btn_type
== BS_AUTORADIOBUTTON
))
1113 style
= wParam
? style
| WS_TABSTOP
: style
& ~WS_TABSTOP
;
1114 SetWindowLongW( hWnd
, GWL_STYLE
, style
);
1116 if ((infoPtr
->state
& 3) != wParam
)
1118 infoPtr
->state
= (infoPtr
->state
& ~3) | wParam
;
1119 InvalidateRect( hWnd
, NULL
, FALSE
);
1121 if ((btn_type
== BS_AUTORADIOBUTTON
) && (wParam
== BST_CHECKED
) && (style
& WS_CHILD
))
1122 BUTTON_CheckAutoRadioButton( hWnd
);
1126 return infoPtr
->state
;
1129 state
= infoPtr
->state
;
1130 new_state
= wParam
? BST_PUSHED
: 0;
1132 if ((state
^ new_state
) & BST_PUSHED
)
1135 state
|= BST_PUSHED
;
1137 state
&= ~BST_PUSHED
;
1139 if (btn_type
== BS_USERBUTTON
)
1140 BUTTON_NOTIFY_PARENT( hWnd
, (state
& BST_PUSHED
) ? BN_HILITE
: BN_UNHILITE
);
1141 infoPtr
->state
= state
;
1143 InvalidateRect( hWnd
, NULL
, FALSE
);
1148 case WM_UPDATEUISTATE
:
1149 DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
1151 if (button_update_uistate(infoPtr
))
1152 paint_button( infoPtr
, btn_type
, ODA_DRAWENTIRE
);
1157 if(btn_type
== BS_GROUPBOX
) return HTTRANSPARENT
;
1160 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
1165 /**********************************************************************
1166 * BUTTON_CalcLabelRect
1168 * Calculates label's rectangle depending on button style.
1170 * Returns flags to be passed to DrawText.
1171 * Calculated rectangle doesn't take into account button state
1172 * (pushed, etc.). If there is nothing to draw (no text/image) output
1173 * rectangle is empty, and return value is (UINT)-1.
1175 static UINT
BUTTON_CalcLabelRect(const BUTTON_INFO
*infoPtr
, HDC hdc
, RECT
*rc
)
1177 LONG style
= GetWindowLongW( infoPtr
->hwnd
, GWL_STYLE
);
1178 LONG ex_style
= GetWindowLongW( infoPtr
->hwnd
, GWL_EXSTYLE
);
1182 UINT dtStyle
= BUTTON_BStoDT( style
, ex_style
);
1186 BOOL bHasIml
= BUTTON_DrawIml(hdc
, &infoPtr
->imlData
, &r
, TRUE
, 0);
1189 /* Calculate label rectangle according to label type */
1190 switch (style
& (BS_ICON
|BS_BITMAP
))
1194 HFONT hFont
, hPrevFont
= 0;
1196 if (!(text
= get_button_text( infoPtr
))) goto empty_rect
;
1203 if ((hFont
= infoPtr
->font
)) hPrevFont
= SelectObject( hdc
, hFont
);
1204 DrawTextW(hdc
, text
, -1, &r
, dtStyle
| DT_CALCRECT
);
1205 if (hPrevFont
) SelectObject( hdc
, hPrevFont
);
1208 if (infoPtr
->ui_state
& UISF_HIDEACCEL
)
1209 dtStyle
|= DT_HIDEPREFIX
;
1215 if (!GetIconInfo(infoPtr
->u
.icon
, &iconInfo
))
1218 GetObjectW (iconInfo
.hbmColor
, sizeof(BITMAP
), &bm
);
1220 r
.right
= r
.left
+ bm
.bmWidth
;
1221 r
.bottom
= r
.top
+ bm
.bmHeight
;
1223 DeleteObject(iconInfo
.hbmColor
);
1224 DeleteObject(iconInfo
.hbmMask
);
1228 if (!GetObjectW( infoPtr
->u
.bitmap
, sizeof(BITMAP
), &bm
))
1231 r
.right
= r
.left
+ bm
.bmWidth
;
1232 r
.bottom
= r
.top
+ bm
.bmHeight
;
1249 if (infoPtr
->imlData
.uAlign
== BUTTON_IMAGELIST_ALIGN_LEFT
)
1250 r
.left
= infoPtr
->imlData
.margin
.left
;
1251 else if (infoPtr
->imlData
.uAlign
== BUTTON_IMAGELIST_ALIGN_RIGHT
)
1252 r
.right
= infoPtr
->imlData
.margin
.right
;
1253 else if (infoPtr
->imlData
.uAlign
== BUTTON_IMAGELIST_ALIGN_TOP
)
1254 r
.top
= infoPtr
->imlData
.margin
.top
;
1255 else if (infoPtr
->imlData
.uAlign
== BUTTON_IMAGELIST_ALIGN_BOTTOM
)
1256 r
.bottom
= infoPtr
->imlData
.margin
.bottom
;
1260 /* Position label inside bounding rectangle according to
1261 * alignment flags. (calculated rect is always left-top aligned).
1262 * If label is aligned to any side - shift label in opposite
1263 * direction to leave extra space for focus rectangle.
1265 switch (dtStyle
& (DT_CENTER
|DT_RIGHT
))
1267 case DT_LEFT
: r
.left
++; r
.right
++; break;
1268 case DT_CENTER
: n
= r
.right
- r
.left
;
1269 r
.left
= rc
->left
+ ((rc
->right
- rc
->left
) - n
) / 2;
1270 r
.right
= r
.left
+ n
; break;
1271 case DT_RIGHT
: n
= r
.right
- r
.left
;
1272 r
.right
= rc
->right
- 1;
1273 r
.left
= r
.right
- n
;
1277 switch (dtStyle
& (DT_VCENTER
|DT_BOTTOM
))
1279 case DT_TOP
: r
.top
++; r
.bottom
++; break;
1280 case DT_VCENTER
: n
= r
.bottom
- r
.top
;
1282 r
.top
= rc
->top
+ ((rc
->bottom
- 1 - rc
->top
) - n
) / 2;
1284 r
.top
= rc
->top
+ ((rc
->bottom
- rc
->top
) - n
) / 2;
1286 r
.bottom
= r
.top
+ n
; break;
1287 case DT_BOTTOM
: n
= r
.bottom
- r
.top
;
1288 r
.bottom
= rc
->bottom
- 1;
1289 r
.top
= r
.bottom
- n
;
1298 /**********************************************************************
1299 * BUTTON_DrawTextCallback
1301 * Callback function used by DrawStateW function.
1303 static BOOL CALLBACK
BUTTON_DrawTextCallback(HDC hdc
, LPARAM lp
, WPARAM wp
, int cx
, int cy
)
1307 SetRect(&rc
, 0, 0, cx
, cy
);
1308 DrawTextW(hdc
, (LPCWSTR
)lp
, -1, &rc
, (UINT
)wp
);
1313 /**********************************************************************
1316 * Common function for drawing button label.
1318 static void BUTTON_DrawLabel(const BUTTON_INFO
*infoPtr
, HDC hdc
, UINT dtFlags
, const RECT
*rc
)
1320 DRAWSTATEPROC lpOutputProc
= NULL
;
1324 UINT flags
= IsWindowEnabled(infoPtr
->hwnd
) ? DSS_NORMAL
: DSS_DISABLED
;
1325 LONG state
= infoPtr
->state
;
1326 LONG style
= GetWindowLongW( infoPtr
->hwnd
, GWL_STYLE
);
1329 /* FIXME: To draw disabled label in Win31 look-and-feel, we probably
1330 * must use DSS_MONO flag and COLOR_GRAYTEXT brush (or maybe DSS_UNION).
1331 * I don't have Win31 on hand to verify that, so I leave it as is.
1336 BUTTON_DrawIml(hdc
, &infoPtr
->imlData
, &rcText
, FALSE
, 0);
1339 if ((style
& BS_PUSHLIKE
) && (state
& BST_INDETERMINATE
))
1341 hbr
= GetSysColorBrush(COLOR_GRAYTEXT
);
1345 switch (style
& (BS_ICON
|BS_BITMAP
))
1348 /* DST_COMPLEX -- is 0 */
1349 lpOutputProc
= BUTTON_DrawTextCallback
;
1350 if (!(text
= get_button_text( infoPtr
))) return;
1354 if (dtFlags
& DT_HIDEPREFIX
)
1355 flags
|= DSS_HIDEPREFIX
;
1361 lp
= (LPARAM
)infoPtr
->u
.icon
;
1365 flags
|= DST_BITMAP
;
1366 lp
= (LPARAM
)infoPtr
->u
.bitmap
;
1374 DrawStateW(hdc
, hbr
, lpOutputProc
, lp
, wp
, rcText
.left
, rcText
.top
,
1375 rcText
.right
- rcText
.left
, rcText
.bottom
- rcText
.top
, flags
);
1377 DrawStateW(hdc
, hbr
, lpOutputProc
, lp
, wp
, rc
->left
, rc
->top
,
1378 rc
->right
- rc
->left
, rc
->bottom
- rc
->top
, flags
);
1383 /**********************************************************************
1384 * Push Button Functions
1386 static void PB_Paint( const BUTTON_INFO
*infoPtr
, HDC hDC
, UINT action
)
1389 UINT dtFlags
, uState
;
1393 COLORREF oldTxtColor
;
1395 LONG state
= infoPtr
->state
;
1396 LONG style
= GetWindowLongW( infoPtr
->hwnd
, GWL_STYLE
);
1397 BOOL pushedState
= (state
& BST_PUSHED
);
1404 GetClientRect( infoPtr
->hwnd
, &rc
);
1406 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
1407 if ((hFont
= infoPtr
->font
)) SelectObject( hDC
, hFont
);
1408 parent
= GetParent(infoPtr
->hwnd
);
1409 if (!parent
) parent
= infoPtr
->hwnd
;
1410 SendMessageW( parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
1412 hrgn
= set_control_clipping( hDC
, &rc
);
1414 hpen
= CreatePen( PS_SOLID
, 1, GetSysColor(COLOR_WINDOWFRAME
));
1415 hOldPen
= SelectObject(hDC
, hpen
);
1416 hOldBrush
= SelectObject(hDC
,GetSysColorBrush(COLOR_BTNFACE
));
1417 oldBkMode
= SetBkMode(hDC
, TRANSPARENT
);
1420 cdrf
= BUTTON_SendCustomDraw(infoPtr
, hDC
, CDDS_PREERASE
, &rc
);
1421 if (cdrf
== CDRF_SKIPDEFAULT
)
1425 if (get_button_type(style
) == BS_DEFPUSHBUTTON
)
1427 if (action
!= ODA_FOCUS
)
1428 Rectangle(hDC
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1429 InflateRect( &rc
, -1, -1 );
1432 /* completely skip the drawing if only focus has changed */
1433 if (action
== ODA_FOCUS
) goto draw_focus
;
1435 uState
= DFCS_BUTTONPUSH
;
1437 if (style
& BS_FLAT
)
1438 uState
|= DFCS_MONO
;
1439 else if (pushedState
)
1441 if (get_button_type(style
) == BS_DEFPUSHBUTTON
)
1442 uState
|= DFCS_FLAT
;
1444 uState
|= DFCS_PUSHED
;
1447 if (state
& (BST_CHECKED
| BST_INDETERMINATE
))
1448 uState
|= DFCS_CHECKED
;
1450 DrawFrameControl( hDC
, &rc
, DFC_BUTTON
, uState
);
1453 if (cdrf
== CDRF_NOTIFYPOSTERASE
)
1454 BUTTON_SendCustomDraw(infoPtr
, hDC
, CDDS_POSTERASE
, &rc
);
1456 cdrf
= BUTTON_SendCustomDraw(infoPtr
, hDC
, CDDS_PREPAINT
, &rc
);
1457 if (cdrf
== CDRF_SKIPDEFAULT
)
1461 /* draw button label */
1463 dtFlags
= BUTTON_CalcLabelRect(infoPtr
, hDC
, &r
);
1465 if (dtFlags
== (UINT
)-1L)
1469 OffsetRect(&r
, 1, 1);
1471 oldTxtColor
= SetTextColor( hDC
, GetSysColor(COLOR_BTNTEXT
) );
1473 BUTTON_DrawLabel(infoPtr
, hDC
, dtFlags
, &r
);
1475 SetTextColor( hDC
, oldTxtColor
);
1478 if (cdrf
== CDRF_NOTIFYPOSTPAINT
)
1479 BUTTON_SendCustomDraw(infoPtr
, hDC
, CDDS_POSTPAINT
, &rc
);
1483 if (action
== ODA_FOCUS
|| (state
& BST_FOCUS
))
1486 if (!(infoPtr
->ui_state
& UISF_HIDEFOCUS
))
1489 InflateRect( &rc
, -2, -2 );
1490 DrawFocusRect( hDC
, &rc
);
1497 SelectObject( hDC
, hOldPen
);
1498 SelectObject( hDC
, hOldBrush
);
1499 SetBkMode(hDC
, oldBkMode
);
1500 SelectClipRgn( hDC
, hrgn
);
1501 if (hrgn
) DeleteObject( hrgn
);
1502 DeleteObject( hpen
);
1505 /**********************************************************************
1506 * Check Box & Radio Button Functions
1509 static void CB_Paint( const BUTTON_INFO
*infoPtr
, HDC hDC
, UINT action
)
1511 RECT rbox
, rtext
, client
;
1513 int delta
, text_offset
, checkBoxWidth
, checkBoxHeight
;
1516 LONG state
= infoPtr
->state
;
1517 LONG style
= GetWindowLongW( infoPtr
->hwnd
, GWL_STYLE
);
1518 LONG ex_style
= GetWindowLongW( infoPtr
->hwnd
, GWL_EXSTYLE
);
1522 if (style
& BS_PUSHLIKE
)
1524 PB_Paint( infoPtr
, hDC
, action
);
1528 GetClientRect(infoPtr
->hwnd
, &client
);
1529 rbox
= rtext
= client
;
1531 checkBoxWidth
= 12 * GetDeviceCaps( hDC
, LOGPIXELSX
) / 96 + 1;
1532 checkBoxHeight
= 12 * GetDeviceCaps( hDC
, LOGPIXELSY
) / 96 + 1;
1534 if ((hFont
= infoPtr
->font
)) SelectObject( hDC
, hFont
);
1535 GetCharWidthW( hDC
, '0', '0', &text_offset
);
1538 parent
= GetParent(infoPtr
->hwnd
);
1539 if (!parent
) parent
= infoPtr
->hwnd
;
1540 hBrush
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORSTATIC
, (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
1541 if (!hBrush
) /* did the app forget to call defwindowproc ? */
1542 hBrush
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORSTATIC
, (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
1543 hrgn
= set_control_clipping( hDC
, &client
);
1545 if (style
& BS_LEFTTEXT
|| ex_style
& WS_EX_RIGHT
)
1547 rtext
.right
-= checkBoxWidth
+ text_offset
;
1548 rbox
.left
= rbox
.right
- checkBoxWidth
;
1552 rtext
.left
+= checkBoxWidth
+ text_offset
;
1553 rbox
.right
= checkBoxWidth
;
1556 /* Since WM_ERASEBKGND does nothing, first prepare background */
1557 if (action
== ODA_SELECT
) FillRect( hDC
, &rbox
, hBrush
);
1558 if (action
== ODA_DRAWENTIRE
) FillRect( hDC
, &client
, hBrush
);
1562 dtFlags
= BUTTON_CalcLabelRect(infoPtr
, hDC
, &rtext
);
1564 /* Only adjust rbox when rtext is valid */
1565 if (dtFlags
!= (UINT
)-1L)
1567 rbox
.top
= rtext
.top
;
1568 rbox
.bottom
= rtext
.bottom
;
1571 /* Draw the check-box bitmap */
1572 if (action
== ODA_DRAWENTIRE
|| action
== ODA_SELECT
)
1576 if ((get_button_type(style
) == BS_RADIOBUTTON
) ||
1577 (get_button_type(style
) == BS_AUTORADIOBUTTON
)) flags
= DFCS_BUTTONRADIO
;
1578 else if (state
& BST_INDETERMINATE
) flags
= DFCS_BUTTON3STATE
;
1579 else flags
= DFCS_BUTTONCHECK
;
1581 if (state
& (BST_CHECKED
| BST_INDETERMINATE
)) flags
|= DFCS_CHECKED
;
1582 if (state
& BST_PUSHED
) flags
|= DFCS_PUSHED
;
1584 if (style
& WS_DISABLED
) flags
|= DFCS_INACTIVE
;
1586 /* rbox must have the correct height */
1587 delta
= rbox
.bottom
- rbox
.top
- checkBoxHeight
;
1589 if (style
& BS_TOP
) {
1591 rbox
.bottom
= rbox
.top
+ checkBoxHeight
;
1593 rbox
.top
-= -delta
/2 + 1;
1594 rbox
.bottom
= rbox
.top
+ checkBoxHeight
;
1596 } else if (style
& BS_BOTTOM
) {
1598 rbox
.top
= rbox
.bottom
- checkBoxHeight
;
1600 rbox
.bottom
+= -delta
/2 + 1;
1601 rbox
.top
= rbox
.bottom
- checkBoxHeight
;
1603 } else { /* Default */
1605 int ofs
= (delta
/ 2);
1606 rbox
.bottom
-= ofs
+ 1;
1607 rbox
.top
= rbox
.bottom
- checkBoxHeight
;
1608 } else if (delta
< 0) {
1609 int ofs
= (-delta
/ 2);
1610 rbox
.top
-= ofs
+ 1;
1611 rbox
.bottom
= rbox
.top
+ checkBoxHeight
;
1615 DrawFrameControl( hDC
, &rbox
, DFC_BUTTON
, flags
);
1618 if (dtFlags
== (UINT
)-1L) /* Noting to draw */
1621 if (action
== ODA_DRAWENTIRE
)
1622 BUTTON_DrawLabel(infoPtr
, hDC
, dtFlags
, &rtext
);
1625 if (action
== ODA_FOCUS
|| (state
& BST_FOCUS
))
1629 IntersectRect(&rtext
, &rtext
, &client
);
1630 DrawFocusRect( hDC
, &rtext
);
1632 SelectClipRgn( hDC
, hrgn
);
1633 if (hrgn
) DeleteObject( hrgn
);
1637 /**********************************************************************
1638 * BUTTON_CheckAutoRadioButton
1640 * hwnd is checked, uncheck every other auto radio button in group
1642 static void BUTTON_CheckAutoRadioButton( HWND hwnd
)
1644 HWND parent
, sibling
, start
;
1646 parent
= GetParent(hwnd
);
1647 /* make sure that starting control is not disabled or invisible */
1648 start
= sibling
= GetNextDlgGroupItem( parent
, hwnd
, TRUE
);
1651 if (!sibling
) break;
1652 if ((hwnd
!= sibling
) &&
1653 ((GetWindowLongW( sibling
, GWL_STYLE
) & BS_TYPEMASK
) == BS_AUTORADIOBUTTON
))
1654 SendMessageW( sibling
, BM_SETCHECK
, BST_UNCHECKED
, 0 );
1655 sibling
= GetNextDlgGroupItem( parent
, sibling
, FALSE
);
1656 } while (sibling
!= start
);
1660 /**********************************************************************
1661 * Group Box Functions
1664 static void GB_Paint( const BUTTON_INFO
*infoPtr
, HDC hDC
, UINT action
)
1671 LONG style
= GetWindowLongW( infoPtr
->hwnd
, GWL_STYLE
);
1675 if ((hFont
= infoPtr
->font
)) SelectObject( hDC
, hFont
);
1676 /* GroupBox acts like static control, so it sends CTLCOLORSTATIC */
1677 parent
= GetParent(infoPtr
->hwnd
);
1678 if (!parent
) parent
= infoPtr
->hwnd
;
1679 hbr
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORSTATIC
, (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
1680 if (!hbr
) /* did the app forget to call defwindowproc ? */
1681 hbr
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORSTATIC
, (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
1682 GetClientRect( infoPtr
->hwnd
, &rc
);
1684 hrgn
= set_control_clipping( hDC
, &rc
);
1686 GetTextMetricsW (hDC
, &tm
);
1687 rcFrame
.top
+= (tm
.tmHeight
/ 2) - 1;
1688 DrawEdge (hDC
, &rcFrame
, EDGE_ETCHED
, BF_RECT
| ((style
& BS_FLAT
) ? BF_FLAT
: 0));
1690 InflateRect(&rc
, -7, 1);
1691 dtFlags
= BUTTON_CalcLabelRect(infoPtr
, hDC
, &rc
);
1693 if (dtFlags
!= (UINT
)-1)
1695 /* Because buttons have CS_PARENTDC class style, there is a chance
1696 * that label will be drawn out of client rect.
1697 * But Windows doesn't clip label's rect, so do I.
1700 /* There is 1-pixel margin at the left, right, and bottom */
1701 rc
.left
--; rc
.right
++; rc
.bottom
++;
1702 FillRect(hDC
, &rc
, hbr
);
1703 rc
.left
++; rc
.right
--; rc
.bottom
--;
1705 BUTTON_DrawLabel(infoPtr
, hDC
, dtFlags
, &rc
);
1707 SelectClipRgn( hDC
, hrgn
);
1708 if (hrgn
) DeleteObject( hrgn
);
1712 /**********************************************************************
1713 * User Button Functions
1716 static void UB_Paint( const BUTTON_INFO
*infoPtr
, HDC hDC
, UINT action
)
1721 LONG state
= infoPtr
->state
;
1724 GetClientRect( infoPtr
->hwnd
, &rc
);
1726 if ((hFont
= infoPtr
->font
)) SelectObject( hDC
, hFont
);
1728 parent
= GetParent(infoPtr
->hwnd
);
1729 if (!parent
) parent
= infoPtr
->hwnd
;
1730 hBrush
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
1731 if (!hBrush
) /* did the app forget to call defwindowproc ? */
1732 hBrush
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
1734 FillRect( hDC
, &rc
, hBrush
);
1735 if (action
== ODA_FOCUS
|| (state
& BST_FOCUS
))
1736 DrawFocusRect( hDC
, &rc
);
1741 BUTTON_NOTIFY_PARENT( infoPtr
->hwnd
, (state
& BST_FOCUS
) ? BN_SETFOCUS
: BN_KILLFOCUS
);
1745 BUTTON_NOTIFY_PARENT( infoPtr
->hwnd
, (state
& BST_PUSHED
) ? BN_HILITE
: BN_UNHILITE
);
1754 /**********************************************************************
1755 * Ownerdrawn Button Functions
1758 static void OB_Paint( const BUTTON_INFO
*infoPtr
, HDC hDC
, UINT action
)
1760 LONG state
= infoPtr
->state
;
1762 LONG_PTR id
= GetWindowLongPtrW( infoPtr
->hwnd
, GWLP_ID
);
1767 dis
.CtlType
= ODT_BUTTON
;
1770 dis
.itemAction
= action
;
1771 dis
.itemState
= ((state
& BST_FOCUS
) ? ODS_FOCUS
: 0) |
1772 ((state
& BST_PUSHED
) ? ODS_SELECTED
: 0) |
1773 (IsWindowEnabled(infoPtr
->hwnd
) ? 0: ODS_DISABLED
);
1774 dis
.hwndItem
= infoPtr
->hwnd
;
1777 GetClientRect( infoPtr
->hwnd
, &dis
.rcItem
);
1779 if ((hFont
= infoPtr
->font
)) SelectObject( hDC
, hFont
);
1780 parent
= GetParent(infoPtr
->hwnd
);
1781 if (!parent
) parent
= infoPtr
->hwnd
;
1782 SendMessageW( parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
1784 hrgn
= set_control_clipping( hDC
, &dis
.rcItem
);
1786 SendMessageW( GetParent(infoPtr
->hwnd
), WM_DRAWITEM
, id
, (LPARAM
)&dis
);
1787 SelectClipRgn( hDC
, hrgn
);
1788 if (hrgn
) DeleteObject( hrgn
);
1791 #ifdef __REACTOS__ /* r73885 */
1792 static void PB_ThemedPaint( HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hDC
, ButtonState drawState
, UINT dtFlags
, BOOL focused
, LPARAM prfFlag
)
1794 static void PB_ThemedPaint(HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hDC
, ButtonState drawState
, UINT dtFlags
, BOOL focused
)
1797 static const int states
[] = { PBS_NORMAL
, PBS_DISABLED
, PBS_HOT
, PBS_PRESSED
, PBS_DEFAULTED
};
1799 RECT bgRect
, textRect
;
1800 HFONT font
= infoPtr
->font
;
1801 HFONT hPrevFont
= font
? SelectObject(hDC
, font
) : NULL
;
1802 int state
= states
[ drawState
];
1803 WCHAR
*text
= get_button_text(infoPtr
);
1808 GetClientRect(infoPtr
->hwnd
, &bgRect
);
1809 GetThemeBackgroundContentRect(theme
, hDC
, BP_PUSHBUTTON
, state
, &bgRect
, &textRect
);
1813 if (IsThemeBackgroundPartiallyTransparent(theme
, BP_PUSHBUTTON
, state
))
1814 DrawThemeParentBackground(infoPtr
->hwnd
, hDC
, NULL
);
1817 parent
= GetParent(infoPtr
->hwnd
);
1818 if (!parent
) parent
= infoPtr
->hwnd
;
1819 SendMessageW( parent
, WM_CTLCOLORBTN
, (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
1821 cdrf
= BUTTON_SendCustomDraw(infoPtr
, hDC
, CDDS_PREERASE
, &bgRect
);
1822 if (cdrf
== CDRF_SKIPDEFAULT
)
1825 DrawThemeBackground(theme
, hDC
, BP_PUSHBUTTON
, state
, &bgRect
, NULL
);
1827 if (cdrf
== CDRF_NOTIFYPOSTERASE
)
1828 BUTTON_SendCustomDraw(infoPtr
, hDC
, CDDS_POSTERASE
, &bgRect
);
1830 cdrf
= BUTTON_SendCustomDraw(infoPtr
, hDC
, CDDS_PREPAINT
, &bgRect
);
1831 if (cdrf
== CDRF_SKIPDEFAULT
)
1834 BUTTON_DrawIml(hDC
, &infoPtr
->imlData
, &textRect
, FALSE
, drawState
);
1836 GetClientRect(infoPtr
->hwnd
, &bgRect
);
1837 GetThemeBackgroundContentRect(theme
, hDC
, BP_PUSHBUTTON
, state
, &bgRect
, &textRect
);
1839 if (IsThemeBackgroundPartiallyTransparent(theme
, BP_PUSHBUTTON
, state
))
1840 DrawThemeParentBackground(infoPtr
->hwnd
, hDC
, NULL
);
1842 DrawThemeBackground(theme
, hDC
, BP_PUSHBUTTON
, state
, &bgRect
, NULL
);
1847 DrawThemeText(theme
, hDC
, BP_PUSHBUTTON
, state
, text
, lstrlenW(text
), dtFlags
, 0, &textRect
);
1857 RECT focusRect
= bgRect
;
1859 GetThemeMargins(theme
, hDC
, BP_PUSHBUTTON
, state
, TMT_CONTENTMARGINS
, NULL
, &margins
);
1861 focusRect
.left
+= margins
.cxLeftWidth
;
1862 focusRect
.top
+= margins
.cyTopHeight
;
1863 focusRect
.right
-= margins
.cxRightWidth
;
1864 focusRect
.bottom
-= margins
.cyBottomHeight
;
1866 DrawFocusRect( hDC
, &focusRect
);
1870 if (cdrf
== CDRF_NOTIFYPOSTPAINT
)
1871 BUTTON_SendCustomDraw(infoPtr
, hDC
, CDDS_POSTPAINT
, &bgRect
);
1873 if (text
) heap_free(text
);
1875 if (hPrevFont
) SelectObject(hDC
, hPrevFont
);
1878 #ifdef __REACTOS__ /* r73885 */
1879 static void CB_ThemedPaint(HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hDC
, ButtonState drawState
, UINT dtFlags
, BOOL focused
, LPARAM prfFlag
)
1881 static void CB_ThemedPaint(HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hDC
, ButtonState drawState
, UINT dtFlags
, BOOL focused
)
1884 static const int cb_states
[3][5] =
1886 { CBS_UNCHECKEDNORMAL
, CBS_UNCHECKEDHOT
, CBS_UNCHECKEDPRESSED
, CBS_UNCHECKEDDISABLED
, CBS_UNCHECKEDNORMAL
},
1887 { CBS_CHECKEDNORMAL
, CBS_CHECKEDHOT
, CBS_CHECKEDPRESSED
, CBS_CHECKEDDISABLED
, CBS_CHECKEDNORMAL
},
1888 { CBS_MIXEDNORMAL
, CBS_MIXEDHOT
, CBS_MIXEDPRESSED
, CBS_MIXEDDISABLED
, CBS_MIXEDNORMAL
}
1891 static const int rb_states
[2][5] =
1893 { RBS_UNCHECKEDNORMAL
, RBS_UNCHECKEDHOT
, RBS_UNCHECKEDPRESSED
, RBS_UNCHECKEDDISABLED
, RBS_UNCHECKEDNORMAL
},
1894 { RBS_CHECKEDNORMAL
, RBS_CHECKEDHOT
, RBS_CHECKEDPRESSED
, RBS_CHECKEDDISABLED
, RBS_CHECKEDNORMAL
}
1898 RECT bgRect
, textRect
;
1899 HFONT font
, hPrevFont
= NULL
;
1900 int checkState
= infoPtr
->state
& 3;
1901 DWORD dwStyle
= GetWindowLongW(infoPtr
->hwnd
, GWL_STYLE
);
1902 UINT btn_type
= get_button_type( dwStyle
);
1903 int part
= (btn_type
== BS_RADIOBUTTON
) || (btn_type
== BS_AUTORADIOBUTTON
) ? BP_RADIOBUTTON
: BP_CHECKBOX
;
1904 int state
= (part
== BP_CHECKBOX
)
1905 ? cb_states
[ checkState
][ drawState
]
1906 : rb_states
[ checkState
][ drawState
];
1907 WCHAR
*text
= get_button_text(infoPtr
);
1909 BOOL created_font
= FALSE
;
1916 HRESULT hr
= GetThemeFont(theme
, hDC
, part
, state
, TMT_FONT
, &lf
);
1917 if (SUCCEEDED(hr
)) {
1918 font
= CreateFontIndirectW(&lf
);
1920 TRACE("Failed to create font\n");
1922 TRACE("font = %s\n", debugstr_w(lf
.lfFaceName
));
1923 hPrevFont
= SelectObject(hDC
, font
);
1924 created_font
= TRUE
;
1927 #ifdef __REACTOS__ /* r73885 */
1928 font
= infoPtr
->font
;
1930 font
= (HFONT
)SendMessageW(infoPtr
->hwnd
, WM_GETFONT
, 0, 0);
1932 hPrevFont
= SelectObject(hDC
, font
);
1935 if (FAILED(GetThemePartSize(theme
, hDC
, part
, state
, NULL
, TS_DRAW
, &sz
)))
1938 GetClientRect(infoPtr
->hwnd
, &bgRect
);
1943 DrawThemeParentBackground(infoPtr
->hwnd
, hDC
, NULL
);
1946 parent
= GetParent(infoPtr
->hwnd
);
1947 if (!parent
) parent
= infoPtr
->hwnd
;
1948 hBrush
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORSTATIC
,
1949 (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
1950 if (!hBrush
) /* did the app forget to call defwindowproc ? */
1951 hBrush
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORSTATIC
,
1952 (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
1953 FillRect( hDC
, &bgRect
, hBrush
);
1955 cdrf
= BUTTON_SendCustomDraw(infoPtr
, hDC
, CDDS_PREERASE
, &bgRect
);
1956 if (cdrf
== CDRF_SKIPDEFAULT
)
1960 GetThemeBackgroundContentRect(theme
, hDC
, part
, state
, &bgRect
, &textRect
);
1962 if (dtFlags
& DT_SINGLELINE
) /* Center the checkbox / radio button to the text. */
1963 bgRect
.top
= bgRect
.top
+ (textRect
.bottom
- textRect
.top
- sz
.cy
) / 2;
1965 /* adjust for the check/radio marker */
1966 bgRect
.bottom
= bgRect
.top
+ sz
.cy
;
1967 bgRect
.right
= bgRect
.left
+ sz
.cx
;
1968 textRect
.left
= bgRect
.right
+ 6;
1971 DrawThemeBackground(theme
, hDC
, part
, state
, &bgRect
, NULL
);
1973 if (cdrf
== CDRF_NOTIFYPOSTERASE
)
1974 BUTTON_SendCustomDraw(infoPtr
, hDC
, CDDS_POSTERASE
, &bgRect
);
1976 cdrf
= BUTTON_SendCustomDraw(infoPtr
, hDC
, CDDS_PREPAINT
, &bgRect
);
1977 if (cdrf
== CDRF_SKIPDEFAULT
)
1981 DrawThemeParentBackground(infoPtr
->hwnd
, hDC
, NULL
);
1982 DrawThemeBackground(theme
, hDC
, part
, state
, &bgRect
, NULL
);
1986 DrawThemeText(theme
, hDC
, part
, state
, text
, lstrlenW(text
), dtFlags
, 0, &textRect
);
1992 focusRect
= textRect
;
1994 DrawTextW(hDC
, text
, lstrlenW(text
), &focusRect
, dtFlags
| DT_CALCRECT
);
1996 if (focusRect
.right
< textRect
.right
) focusRect
.right
++;
1997 focusRect
.bottom
= textRect
.bottom
;
1999 DrawFocusRect( hDC
, &focusRect
);
2009 if (cdrf
== CDRF_NOTIFYPOSTPAINT
)
2010 BUTTON_SendCustomDraw(infoPtr
, hDC
, CDDS_POSTPAINT
, &bgRect
);
2012 if (text
) heap_free(text
);
2014 if (created_font
) DeleteObject(font
);
2015 if (hPrevFont
) SelectObject(hDC
, hPrevFont
);
2018 #ifdef __REACTOS__ /* r73885 */
2019 static void GB_ThemedPaint(HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hDC
, ButtonState drawState
, UINT dtFlags
, BOOL focused
, LPARAM prfFlag
)
2021 static void GB_ThemedPaint(HTHEME theme
, const BUTTON_INFO
*infoPtr
, HDC hDC
, ButtonState drawState
, UINT dtFlags
, BOOL focused
)
2024 static const int states
[] = { GBS_NORMAL
, GBS_DISABLED
, GBS_NORMAL
, GBS_NORMAL
, GBS_NORMAL
};
2026 RECT bgRect
, textRect
, contentRect
;
2027 int state
= states
[ drawState
];
2028 WCHAR
*text
= get_button_text(infoPtr
);
2030 HFONT font
, hPrevFont
= NULL
;
2031 BOOL created_font
= FALSE
;
2032 #ifdef __REACTOS__ /* r74406 */
2038 HRESULT hr
= GetThemeFont(theme
, hDC
, BP_GROUPBOX
, state
, TMT_FONT
, &lf
);
2039 if (SUCCEEDED(hr
)) {
2040 font
= CreateFontIndirectW(&lf
);
2042 TRACE("Failed to create font\n");
2044 hPrevFont
= SelectObject(hDC
, font
);
2045 created_font
= TRUE
;
2048 #ifdef __REACTOS__ /* r73885 */
2049 font
= infoPtr
->font
;
2051 font
= (HFONT
)SendMessageW(infoPtr
->hwnd
, WM_GETFONT
, 0, 0);
2053 hPrevFont
= SelectObject(hDC
, font
);
2056 GetClientRect(infoPtr
->hwnd
, &bgRect
);
2062 GetTextExtentPoint32W(hDC
, text
, lstrlenW(text
), &textExtent
);
2063 bgRect
.top
+= (textExtent
.cy
/ 2);
2064 textRect
.left
+= 10;
2065 textRect
.bottom
= textRect
.top
+ textExtent
.cy
;
2066 textRect
.right
= textRect
.left
+ textExtent
.cx
+ 4;
2068 ExcludeClipRect(hDC
, textRect
.left
, textRect
.top
, textRect
.right
, textRect
.bottom
);
2071 GetThemeBackgroundContentRect(theme
, hDC
, BP_GROUPBOX
, state
, &bgRect
, &contentRect
);
2072 ExcludeClipRect(hDC
, contentRect
.left
, contentRect
.top
, contentRect
.right
, contentRect
.bottom
);
2074 #ifdef __REACTOS__ /* r73885 & r74149 */
2077 if (IsThemeBackgroundPartiallyTransparent(theme
, BP_GROUPBOX
, state
))
2078 DrawThemeParentBackground(infoPtr
->hwnd
, hDC
, NULL
);
2080 #ifdef __REACTOS__ /* r74406 */
2081 parent
= GetParent(infoPtr
->hwnd
);
2082 if (!parent
) parent
= infoPtr
->hwnd
;
2083 hBrush
= (HBRUSH
)SendMessageW(parent
, WM_CTLCOLORSTATIC
,
2084 (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
2085 if (!hBrush
) /* did the app forget to call defwindowproc ? */
2086 hBrush
= (HBRUSH
)DefWindowProcW(parent
, WM_CTLCOLORSTATIC
,
2087 (WPARAM
)hDC
, (LPARAM
)infoPtr
->hwnd
);
2088 GetClientRect(infoPtr
->hwnd
, &clientRect
);
2089 FillRect( hDC
, &clientRect
, hBrush
);
2092 DrawThemeBackground(theme
, hDC
, BP_GROUPBOX
, state
, &bgRect
, NULL
);
2094 SelectClipRgn(hDC
, NULL
);
2098 InflateRect(&textRect
, -2, 0);
2099 DrawThemeText(theme
, hDC
, BP_GROUPBOX
, state
, text
, lstrlenW(text
), 0, 0, &textRect
);
2103 if (created_font
) DeleteObject(font
);
2104 if (hPrevFont
) SelectObject(hDC
, hPrevFont
);
2107 void BUTTON_Register(void)
2111 memset(&wndClass
, 0, sizeof(wndClass
));
2112 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
| CS_VREDRAW
| CS_HREDRAW
| CS_PARENTDC
;
2113 wndClass
.lpfnWndProc
= BUTTON_WindowProc
;
2114 wndClass
.cbClsExtra
= 0;
2115 wndClass
.cbWndExtra
= sizeof(BUTTON_INFO
*);
2116 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
2117 wndClass
.hbrBackground
= NULL
;
2118 wndClass
.lpszClassName
= WC_BUTTONW
;
2119 RegisterClassW(&wndClass
);
2124 void BUTTON_Unregister(void)
2126 UnregisterClassW(WC_BUTTONW
, NULL
);