1 /* File: button.c -- Button type widgets
3 * Copyright (C) 1993 Johannes Ruscheinski
4 * Copyright (C) 1993 David Metcalfe
5 * Copyright (C) 1994 Alexandre Julliard
11 #include "wine/winuser16.h"
14 static void PaintGrayOnGray( HDC hDC
,HFONT hFont
,RECT
*rc
,
15 char *text
, UINT format
);
17 static void PB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
);
18 static void CB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
);
19 static void GB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
);
20 static void UB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
);
21 static void OB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
);
22 static void BUTTON_CheckAutoRadioButton( WND
*wndPtr
);
23 static void BUTTON_DrawPushButton( WND
*wndPtr
, HDC hDC
, WORD action
, BOOL pushedState
);
25 #define MAX_BTN_TYPE 12
27 static const WORD maxCheckState
[MAX_BTN_TYPE
] =
29 BUTTON_UNCHECKED
, /* BS_PUSHBUTTON */
30 BUTTON_UNCHECKED
, /* BS_DEFPUSHBUTTON */
31 BUTTON_CHECKED
, /* BS_CHECKBOX */
32 BUTTON_CHECKED
, /* BS_AUTOCHECKBOX */
33 BUTTON_CHECKED
, /* BS_RADIOBUTTON */
34 BUTTON_3STATE
, /* BS_3STATE */
35 BUTTON_3STATE
, /* BS_AUTO3STATE */
36 BUTTON_UNCHECKED
, /* BS_GROUPBOX */
37 BUTTON_UNCHECKED
, /* BS_USERBUTTON */
38 BUTTON_CHECKED
, /* BS_AUTORADIOBUTTON */
39 BUTTON_UNCHECKED
, /* Not defined */
40 BUTTON_UNCHECKED
/* BS_OWNERDRAW */
43 typedef void (*pfPaint
)( WND
*wndPtr
, HDC hdc
, WORD action
);
45 static const pfPaint btnPaintFunc
[MAX_BTN_TYPE
] =
47 PB_Paint
, /* BS_PUSHBUTTON */
48 PB_Paint
, /* BS_DEFPUSHBUTTON */
49 CB_Paint
, /* BS_CHECKBOX */
50 CB_Paint
, /* BS_AUTOCHECKBOX */
51 CB_Paint
, /* BS_RADIOBUTTON */
52 CB_Paint
, /* BS_3STATE */
53 CB_Paint
, /* BS_AUTO3STATE */
54 GB_Paint
, /* BS_GROUPBOX */
55 UB_Paint
, /* BS_USERBUTTON */
56 CB_Paint
, /* BS_AUTORADIOBUTTON */
57 NULL
, /* Not defined */
58 OB_Paint
/* BS_OWNERDRAW */
61 #define PAINT_BUTTON(wndPtr,style,action) \
62 if (btnPaintFunc[style]) { \
63 HDC hdc = GetDC( (wndPtr)->hwndSelf ); \
64 (btnPaintFunc[style])(wndPtr,hdc,action); \
65 ReleaseDC( (wndPtr)->hwndSelf, hdc ); }
67 #define BUTTON_SEND_CTLCOLOR(wndPtr,hdc) \
68 SendMessageA( GetParent((wndPtr)->hwndSelf), WM_CTLCOLORBTN, \
69 (hdc), (wndPtr)->hwndSelf )
71 static HBITMAP hbitmapCheckBoxes
= 0;
72 static WORD checkBoxWidth
= 0, checkBoxHeight
= 0;
75 /***********************************************************************
76 * ButtonWndProc_locked
78 * Called with window lock held.
80 static inline LRESULT WINAPI
ButtonWndProc_locked(WND
* wndPtr
, UINT uMsg
,
81 WPARAM wParam
, LPARAM lParam
)
84 HWND hWnd
= wndPtr
->hwndSelf
;
86 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
87 LONG style
= wndPtr
->dwStyle
& 0x0f;
90 pt
.x
= LOWORD(lParam
);
91 pt
.y
= HIWORD(lParam
);
98 case BS_PUSHBUTTON
: return DLGC_BUTTON
| DLGC_UNDEFPUSHBUTTON
;
99 case BS_DEFPUSHBUTTON
: return DLGC_BUTTON
| DLGC_DEFPUSHBUTTON
;
101 case BS_AUTORADIOBUTTON
: return DLGC_BUTTON
| DLGC_RADIOBUTTON
;
102 default: return DLGC_BUTTON
;
106 PAINT_BUTTON( wndPtr
, style
, ODA_DRAWENTIRE
);
110 if (!hbitmapCheckBoxes
)
113 hbitmapCheckBoxes
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_CHECKBOXES
));
114 GetObjectA( hbitmapCheckBoxes
, sizeof(bmp
), &bmp
);
115 checkBoxWidth
= bmp
.bmWidth
/ 4;
116 checkBoxHeight
= bmp
.bmHeight
/ 3;
118 if (style
< 0L || style
>= MAX_BTN_TYPE
)
119 return -1; /* abort */
120 infoPtr
->state
= BUTTON_UNCHECKED
;
129 if (btnPaintFunc
[style
])
132 HDC hdc
= wParam
? (HDC
)wParam
: BeginPaint( hWnd
, &ps
);
133 SetBkMode( hdc
, OPAQUE
);
134 (btnPaintFunc
[style
])( wndPtr
, hdc
, ODA_DRAWENTIRE
);
135 if( !wParam
) EndPaint( hWnd
, &ps
);
140 if (wParam
== VK_SPACE
)
142 SendMessageA( hWnd
, BM_SETSTATE
, TRUE
, 0 );
143 infoPtr
->state
|= BUTTON_BTNPRESSED
;
147 case WM_LBUTTONDBLCLK
:
148 if(wndPtr
->dwStyle
& BS_NOTIFY
||
149 style
==BS_RADIOBUTTON
||
150 style
==BS_USERBUTTON
||
151 style
==BS_OWNERDRAW
) {
152 SendMessageA( GetParent(hWnd
), WM_COMMAND
,
153 MAKEWPARAM( wndPtr
->wIDmenu
, BN_DOUBLECLICKED
), hWnd
);
160 SendMessageA( hWnd
, BM_SETSTATE
, TRUE
, 0 );
161 infoPtr
->state
|= BUTTON_BTNPRESSED
;
165 if (wParam
!= VK_SPACE
)
169 if (!(infoPtr
->state
& BUTTON_BTNPRESSED
)) break;
170 infoPtr
->state
&= BUTTON_NSTATES
;
171 if (!(infoPtr
->state
& BUTTON_HIGHLIGHTED
)) {
175 SendMessageA( hWnd
, BM_SETSTATE
, FALSE
, 0 );
177 GetClientRect( hWnd
, &rect
);
178 if (uMsg
== WM_KEYUP
|| PtInRect( &rect
, pt
))
182 case BS_AUTOCHECKBOX
:
183 SendMessageA( hWnd
, BM_SETCHECK
,
184 !(infoPtr
->state
& BUTTON_CHECKED
), 0 );
186 case BS_AUTORADIOBUTTON
:
187 SendMessageA( hWnd
, BM_SETCHECK
, TRUE
, 0 );
190 SendMessageA( hWnd
, BM_SETCHECK
,
191 (infoPtr
->state
& BUTTON_3STATE
) ? 0 :
192 ((infoPtr
->state
& 3) + 1), 0 );
195 SendMessageA( GetParent(hWnd
), WM_COMMAND
,
196 MAKEWPARAM( wndPtr
->wIDmenu
, BN_CLICKED
), hWnd
);
200 case WM_CAPTURECHANGED
:
201 if (infoPtr
->state
& BUTTON_BTNPRESSED
) {
202 infoPtr
->state
&= BUTTON_NSTATES
;
203 if (infoPtr
->state
& BUTTON_HIGHLIGHTED
)
204 SendMessageA( hWnd
, BM_SETSTATE
, FALSE
, 0 );
209 if (GetCapture() == hWnd
)
211 GetClientRect( hWnd
, &rect
);
212 SendMessageA( hWnd
, BM_SETSTATE
, PtInRect(&rect
, pt
), 0 );
217 if(style
== BS_GROUPBOX
) return HTTRANSPARENT
;
218 return DefWindowProcA( hWnd
, uMsg
, wParam
, lParam
);
221 DEFWND_SetText( wndPtr
, (LPCSTR
)lParam
);
222 if( wndPtr
->dwStyle
& WS_VISIBLE
)
223 PAINT_BUTTON( wndPtr
, style
, ODA_DRAWENTIRE
);
227 infoPtr
->hFont
= (HFONT16
)wParam
;
228 if (lParam
&& (wndPtr
->dwStyle
& WS_VISIBLE
))
229 PAINT_BUTTON( wndPtr
, style
, ODA_DRAWENTIRE
);
233 return infoPtr
->hFont
;
236 if ((style
== BS_AUTORADIOBUTTON
) && (GetCapture() != hWnd
) &&
237 !(SendMessageA(hWnd
, BM_GETCHECK
, 0, 0) & BST_CHECKED
))
239 /* The notification is sent when the button (BS_AUTORADIOBUTTON)
240 is unckecked and the focus was not given by a mouse click. */
241 SendMessageA( hWnd
, BM_SETCHECK
, TRUE
, 0 );
242 SendMessageA( GetParent(hWnd
), WM_COMMAND
,
243 MAKEWPARAM( wndPtr
->wIDmenu
, BN_CLICKED
), hWnd
);
245 infoPtr
->state
|= BUTTON_HASFOCUS
;
246 PAINT_BUTTON( wndPtr
, style
, ODA_FOCUS
);
250 infoPtr
->state
&= ~BUTTON_HASFOCUS
;
251 PAINT_BUTTON( wndPtr
, style
, ODA_FOCUS
);
252 InvalidateRect( hWnd
, NULL
, TRUE
);
255 case WM_SYSCOLORCHANGE
:
256 InvalidateRect( hWnd
, NULL
, FALSE
);
261 if ((wParam
& 0x0f) >= MAX_BTN_TYPE
) break;
262 wndPtr
->dwStyle
= (wndPtr
->dwStyle
& 0xfffffff0)
263 | (wParam
& 0x0000000f);
264 style
= wndPtr
->dwStyle
& 0x0000000f;
265 PAINT_BUTTON( wndPtr
, style
, ODA_DRAWENTIRE
);
269 oldHbitmap
= infoPtr
->hImage
;
270 if ((wndPtr
->dwStyle
& BS_BITMAP
) || (wndPtr
->dwStyle
& BS_ICON
))
271 infoPtr
->hImage
= (HANDLE
) lParam
;
275 if (wParam
== IMAGE_BITMAP
)
276 return (HBITMAP
)infoPtr
->hImage
;
277 else if (wParam
== IMAGE_ICON
)
278 return (HICON
)infoPtr
->hImage
;
284 return infoPtr
->state
& 3;
288 if (wParam
> maxCheckState
[style
]) wParam
= maxCheckState
[style
];
289 if ((infoPtr
->state
& 3) != wParam
)
291 if ((style
== BS_RADIOBUTTON
) || (style
== BS_AUTORADIOBUTTON
))
294 wndPtr
->dwStyle
|= WS_TABSTOP
;
296 wndPtr
->dwStyle
&= ~WS_TABSTOP
;
298 infoPtr
->state
= (infoPtr
->state
& ~3) | wParam
;
299 PAINT_BUTTON( wndPtr
, style
, ODA_SELECT
);
301 if ((style
== BS_AUTORADIOBUTTON
) && (wParam
== BUTTON_CHECKED
))
302 BUTTON_CheckAutoRadioButton( wndPtr
);
307 return infoPtr
->state
;
313 if (infoPtr
->state
& BUTTON_HIGHLIGHTED
) break;
314 infoPtr
->state
|= BUTTON_HIGHLIGHTED
;
318 if (!(infoPtr
->state
& BUTTON_HIGHLIGHTED
)) break;
319 infoPtr
->state
&= ~BUTTON_HIGHLIGHTED
;
321 PAINT_BUTTON( wndPtr
, style
, ODA_SELECT
);
325 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
330 /***********************************************************************
332 * The button window procedure. This is just a wrapper which locks
333 * the passed HWND and calls the real window procedure (with a WND*
334 * pointer pointing to the locked windowstructure).
336 LRESULT WINAPI
ButtonWndProc( HWND hWnd
, UINT uMsg
,
337 WPARAM wParam
, LPARAM lParam
)
340 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
342 res
= ButtonWndProc_locked(wndPtr
,uMsg
,wParam
,lParam
);
344 WIN_ReleaseWndPtr(wndPtr
);
348 /**********************************************************************
349 * Push Button Functions
351 static void PB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
353 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
354 BOOL bHighLighted
= (infoPtr
->state
& BUTTON_HIGHLIGHTED
);
357 * Delegate this to the more generic pushbutton painting
360 BUTTON_DrawPushButton(wndPtr
,
366 /**********************************************************************
367 * This method will actually do the drawing of the pushbutton
368 * depending on it's state and the pushedState parameter.
370 static void BUTTON_DrawPushButton(
379 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
380 int xBorderOffset
, yBorderOffset
;
381 xBorderOffset
= yBorderOffset
= 0;
383 GetClientRect( wndPtr
->hwndSelf
, &rc
);
385 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
386 if (infoPtr
->hFont
) SelectObject( hDC
, infoPtr
->hFont
);
387 BUTTON_SEND_CTLCOLOR( wndPtr
, hDC
);
388 hOldPen
= (HPEN
)SelectObject(hDC
, GetSysColorPen(COLOR_WINDOWFRAME
));
389 hOldBrush
=(HBRUSH
)SelectObject(hDC
,GetSysColorBrush(COLOR_BTNFACE
));
390 SetBkMode(hDC
, TRANSPARENT
);
392 if ( TWEAK_WineLook
== WIN31_LOOK
)
394 Rectangle(hDC
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
396 SetPixel( hDC
, rc
.left
, rc
.top
, GetSysColor(COLOR_WINDOW
) );
397 SetPixel( hDC
, rc
.left
, rc
.bottom
-1, GetSysColor(COLOR_WINDOW
) );
398 SetPixel( hDC
, rc
.right
-1, rc
.top
, GetSysColor(COLOR_WINDOW
) );
399 SetPixel( hDC
, rc
.right
-1, rc
.bottom
-1, GetSysColor(COLOR_WINDOW
));
400 InflateRect( &rc
, -1, -1 );
403 if ((wndPtr
->dwStyle
& 0x000f) == BS_DEFPUSHBUTTON
)
405 Rectangle(hDC
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
406 InflateRect( &rc
, -1, -1 );
409 if (TWEAK_WineLook
== WIN31_LOOK
)
413 /* draw button shadow: */
414 SelectObject(hDC
, GetSysColorBrush(COLOR_BTNSHADOW
));
415 PatBlt(hDC
, rc
.left
, rc
.top
, 1, rc
.bottom
-rc
.top
, PATCOPY
);
416 PatBlt(hDC
, rc
.left
, rc
.top
, rc
.right
-rc
.left
, 1, PATCOPY
);
417 rc
.left
+= 2; /* To position the text down and right */
420 rc
.right
++, rc
.bottom
++;
421 DrawEdge( hDC
, &rc
, EDGE_RAISED
, BF_RECT
);
423 /* To place de bitmap correctly */
424 xBorderOffset
+= GetSystemMetrics(SM_CXEDGE
);
425 yBorderOffset
+= GetSystemMetrics(SM_CYEDGE
);
427 rc
.right
--, rc
.bottom
--;
432 UINT uState
= DFCS_BUTTONPUSH
;
436 if ( (wndPtr
->dwStyle
& 0x000f) == BS_DEFPUSHBUTTON
)
439 uState
|= DFCS_PUSHED
;
442 DrawFrameControl( hDC
, &rc
, DFC_BUTTON
, uState
);
443 InflateRect( &rc
, -2, -2 );
449 rc
.left
+= 2; /* To position the text down and right */
454 /* draw button label, if any:
456 * In win9x we don't show text if there is a bitmap or icon.
457 * I don't know about win31 so I leave it as it was for win31.
458 * Dennis Björklund 12 Jul, 99
460 if ( wndPtr
->text
&& wndPtr
->text
[0]
461 && (TWEAK_WineLook
== WIN31_LOOK
|| !(wndPtr
->dwStyle
& (BS_ICON
|BS_BITMAP
))) )
464 GetObjectA( GetSysColorBrush(COLOR_BTNFACE
), sizeof(lb
), &lb
);
465 if (wndPtr
->dwStyle
& WS_DISABLED
&&
466 GetSysColor(COLOR_GRAYTEXT
)==lb
.lbColor
)
467 /* don't write gray text on gray background */
468 PaintGrayOnGray( hDC
,infoPtr
->hFont
,&rc
,wndPtr
->text
,
469 DT_CENTER
| DT_VCENTER
);
472 SetTextColor( hDC
, (wndPtr
->dwStyle
& WS_DISABLED
) ?
473 GetSysColor(COLOR_GRAYTEXT
) :
474 GetSysColor(COLOR_BTNTEXT
) );
475 DrawTextA( hDC
, wndPtr
->text
, -1, &rc
,
476 DT_SINGLELINE
| DT_CENTER
| DT_VCENTER
);
477 /* do we have the focus?
478 * Win9x draws focus last with a size prop. to the button
480 if (TWEAK_WineLook
== WIN31_LOOK
481 && infoPtr
->state
& BUTTON_HASFOCUS
)
483 RECT r
= { 0, 0, 0, 0 };
486 DrawTextA( hDC
, wndPtr
->text
, -1, &r
,
487 DT_SINGLELINE
| DT_CALCRECT
);
488 xdelta
= ((rc
.right
- rc
.left
) - (r
.right
- r
.left
) - 1) / 2;
489 ydelta
= ((rc
.bottom
- rc
.top
) - (r
.bottom
- r
.top
) - 1) / 2;
490 if (xdelta
< 0) xdelta
= 0;
491 if (ydelta
< 0) ydelta
= 0;
492 InflateRect( &rc
, -xdelta
, -ydelta
);
493 DrawFocusRect( hDC
, &rc
);
497 if ( ((wndPtr
->dwStyle
& BS_ICON
) || (wndPtr
->dwStyle
& BS_BITMAP
) ) &&
498 (infoPtr
->hImage
!= 0) )
500 int yOffset
, xOffset
;
501 int imageWidth
, imageHeight
;
504 * We extract the size of the image from the handle.
506 if (wndPtr
->dwStyle
& BS_ICON
)
511 GetIconInfo((HICON
)infoPtr
->hImage
, &iconInfo
);
512 GetObjectA (iconInfo
.hbmColor
, sizeof(BITMAP
), &bm
);
514 imageWidth
= bm
.bmWidth
;
515 imageHeight
= bm
.bmHeight
;
517 DeleteObject(iconInfo
.hbmColor
);
518 DeleteObject(iconInfo
.hbmMask
);
525 GetObjectA (infoPtr
->hImage
, sizeof(BITMAP
), &bm
);
527 imageWidth
= bm
.bmWidth
;
528 imageHeight
= bm
.bmHeight
;
531 /* Center the bitmap */
532 xOffset
= (((rc
.right
- rc
.left
) - 2*xBorderOffset
) - imageWidth
) / 2;
533 yOffset
= (((rc
.bottom
- rc
.top
) - 2*yBorderOffset
) - imageHeight
) / 2;
535 /* If the image is too big for the button then create a region*/
536 if(xOffset
< 0 || yOffset
< 0)
539 hBitmapRgn
= CreateRectRgn(
540 rc
.left
+ xBorderOffset
, rc
.top
+yBorderOffset
,
541 rc
.right
- xBorderOffset
, rc
.bottom
- yBorderOffset
);
542 SelectClipRgn(hDC
, hBitmapRgn
);
543 DeleteObject(hBitmapRgn
);
546 /* Let minimum 1 space from border */
547 xOffset
++, yOffset
++;
550 * Draw the image now.
552 if (wndPtr
->dwStyle
& BS_ICON
)
555 rc
.left
+ xOffset
, rc
.top
+ yOffset
,
556 (HICON
)infoPtr
->hImage
);
562 hdcMem
= CreateCompatibleDC (hDC
);
563 SelectObject (hdcMem
, (HBITMAP
)infoPtr
->hImage
);
567 imageWidth
, imageHeight
,
568 hdcMem
, 0, 0, SRCCOPY
);
573 if(xOffset
< 0 || yOffset
< 0)
575 SelectClipRgn(hDC
, 0);
579 if (TWEAK_WineLook
!= WIN31_LOOK
580 && infoPtr
->state
& BUTTON_HASFOCUS
)
582 InflateRect( &focus_rect
, -1, -1 );
583 DrawFocusRect( hDC
, &focus_rect
);
587 SelectObject( hDC
, hOldPen
);
588 SelectObject( hDC
, hOldBrush
);
592 /**********************************************************************
593 * PB_Paint & CB_Paint sub function [internal]
594 * Paint text using a raster brush to avoid gray text on gray
595 * background. 'format' can be a combination of DT_CENTER and
596 * DT_VCENTER to use this function in both PB_PAINT and
597 * CB_PAINT. - Dirk Thierbach
599 * FIXME: This and TEXT_GrayString should be eventually combined,
600 * so calling one common function from PB_Paint, CB_Paint and
601 * TEXT_GrayString will be enough. Also note that this
602 * function ignores the CACHE_GetPattern funcs.
605 void PaintGrayOnGray(HDC hDC
,HFONT hFont
,RECT
*rc
,char *text
,
608 /* This is the standard gray on gray pattern:
609 static const WORD Pattern[] = {0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55};
611 /* This pattern gives better readability with X Fonts.
612 FIXME: Maybe the user should be allowed to decide which he wants. */
613 static const WORD Pattern
[] = {0x55,0xFF,0xAA,0xFF,0x55,0xFF,0xAA,0xFF};
615 HBITMAP hbm
= CreateBitmap( 8, 8, 1, 1, Pattern
);
616 HDC hdcMem
= CreateCompatibleDC(hDC
);
622 DrawTextA( hDC
, text
, -1, &rect
, DT_SINGLELINE
| DT_CALCRECT
);
623 /* now text width and height are in rect.right and rect.bottom */
625 rect
.left
= rect
.top
= 0; /* drawing pos in hdcMem */
626 if (format
& DT_CENTER
) rect
.left
=(rc
->right
-rect
.right
)/2;
627 if (format
& DT_VCENTER
) rect
.top
=(rc
->bottom
-rect
.bottom
)/2;
628 hbmMem
= CreateCompatibleBitmap( hDC
,rect
.right
,rect
.bottom
);
629 SelectObject( hdcMem
, hbmMem
);
630 PatBlt( hdcMem
,0,0,rect
.right
,rect
.bottom
,WHITENESS
);
631 /* will be overwritten by DrawText, but just in case */
632 if (hFont
) SelectObject( hdcMem
, hFont
);
633 DrawTextA( hdcMem
, text
, -1, &rc2
, DT_SINGLELINE
);
634 /* After draw: foreground = 0 bits, background = 1 bits */
635 hBr
= SelectObject( hdcMem
, CreatePatternBrush(hbm
) );
637 PatBlt( hdcMem
,0,0,rect
.right
,rect
.bottom
,0xAF0229);
638 /* only keep the foreground bits where pattern is 1 */
639 DeleteObject( SelectObject( hdcMem
,hBr
) );
640 BitBlt(hDC
,rect
.left
,rect
.top
,rect
.right
,rect
.bottom
,hdcMem
,0,0,SRCAND
);
641 /* keep the background of the dest */
643 DeleteObject( hbmMem
);
647 /**********************************************************************
648 * Check Box & Radio Button Functions
651 static void CB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
653 RECT rbox
, rtext
, client
;
656 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
659 * if the button has a bitmap/icon, draw a normal pushbutton
660 * instead of a radion button.
662 if (infoPtr
->hImage
!= 0)
664 BOOL bHighLighted
= ((infoPtr
->state
& BUTTON_HIGHLIGHTED
) ||
665 (infoPtr
->state
& BUTTON_CHECKED
));
667 BUTTON_DrawPushButton(wndPtr
,
675 GetClientRect(wndPtr
->hwndSelf
, &client
);
676 rbox
= rtext
= client
;
678 if (infoPtr
->hFont
) SelectObject( hDC
, infoPtr
->hFont
);
680 /* Something is still not right, checkboxes (and edit controls)
681 * in wsping32 have white backgrounds instead of dark grey.
682 * BUTTON_SEND_CTLCOLOR() is even worse since it returns 0 in this
683 * particular case and the background is not painted at all.
686 hBrush
= GetControlBrush16( wndPtr
->hwndSelf
, hDC
, CTLCOLOR_BTN
);
688 if (wndPtr
->dwStyle
& BS_LEFTTEXT
)
690 /* magic +4 is what CTL3D expects */
692 rtext
.right
-= checkBoxWidth
+ 4;
693 rbox
.left
= rbox
.right
- checkBoxWidth
;
697 rtext
.left
+= checkBoxWidth
+ 4;
698 rbox
.right
= checkBoxWidth
;
701 /* Draw the check-box bitmap */
703 if (wndPtr
->text
) textlen
= strlen( wndPtr
->text
);
704 if (action
== ODA_DRAWENTIRE
|| action
== ODA_SELECT
)
706 if( TWEAK_WineLook
== WIN31_LOOK
)
708 HDC hMemDC
= CreateCompatibleDC( hDC
);
710 delta
= (rbox
.bottom
- rbox
.top
- checkBoxHeight
) / 2;
712 /* Check in case the client area is smaller than the checkbox bitmap */
713 if (delta
< 0) delta
= 0;
715 if (action
== ODA_SELECT
) FillRect( hDC
, &rbox
, hBrush
);
716 else FillRect( hDC
, &client
, hBrush
);
718 if (infoPtr
->state
& BUTTON_HIGHLIGHTED
) x
+= 2 * checkBoxWidth
;
719 if (infoPtr
->state
& (BUTTON_CHECKED
| BUTTON_3STATE
)) x
+= checkBoxWidth
;
720 if (((wndPtr
->dwStyle
& 0x0f) == BS_RADIOBUTTON
) ||
721 ((wndPtr
->dwStyle
& 0x0f) == BS_AUTORADIOBUTTON
)) y
+= checkBoxHeight
;
722 else if (infoPtr
->state
& BUTTON_3STATE
) y
+= 2 * checkBoxHeight
;
724 /* The bitmap for the radio button is not aligned with the
725 * left of the window, it is 1 pixel off. */
726 if (((wndPtr
->dwStyle
& 0x0f) == BS_RADIOBUTTON
) ||
727 ((wndPtr
->dwStyle
& 0x0f) == BS_AUTORADIOBUTTON
))
730 SelectObject( hMemDC
, hbitmapCheckBoxes
);
731 BitBlt( hDC
, rbox
.left
, rbox
.top
+ delta
, checkBoxWidth
,
732 checkBoxHeight
, hMemDC
, x
, y
, SRCCOPY
);
739 if (((wndPtr
->dwStyle
& 0x0f) == BS_RADIOBUTTON
) ||
740 ((wndPtr
->dwStyle
& 0x0f) == BS_AUTORADIOBUTTON
)) state
= DFCS_BUTTONRADIO
;
741 else if (infoPtr
->state
& BUTTON_3STATE
) state
= DFCS_BUTTON3STATE
;
742 else state
= DFCS_BUTTONCHECK
;
744 if (infoPtr
->state
& (BUTTON_CHECKED
| BUTTON_3STATE
)) state
|= DFCS_CHECKED
;
746 if (infoPtr
->state
& BUTTON_HIGHLIGHTED
) state
|= DFCS_PUSHED
;
748 if (wndPtr
->dwStyle
& WS_DISABLED
) state
|= DFCS_INACTIVE
;
750 DrawFrameControl( hDC
, &rbox
, DFC_BUTTON
, state
);
754 if( textlen
&& action
!= ODA_SELECT
)
756 if (wndPtr
->dwStyle
& WS_DISABLED
&&
757 GetSysColor(COLOR_GRAYTEXT
)==GetBkColor(hDC
)) {
758 /* don't write gray text on gray background */
759 PaintGrayOnGray( hDC
, infoPtr
->hFont
, &rtext
, wndPtr
->text
,
762 if (wndPtr
->dwStyle
& WS_DISABLED
)
763 SetTextColor( hDC
, GetSysColor(COLOR_GRAYTEXT
) );
764 DrawTextA( hDC
, wndPtr
->text
, textlen
, &rtext
,
765 DT_SINGLELINE
| DT_VCENTER
);
770 if ((action
== ODA_FOCUS
) ||
771 ((action
== ODA_DRAWENTIRE
) && (infoPtr
->state
& BUTTON_HASFOCUS
)))
773 /* again, this is what CTL3D expects */
777 DrawTextA( hDC
, wndPtr
->text
, textlen
, &rbox
,
778 DT_SINGLELINE
| DT_CALCRECT
);
779 textlen
= rbox
.bottom
- rbox
.top
;
780 delta
= ((rtext
.bottom
- rtext
.top
) - textlen
)/2;
781 rbox
.bottom
= (rbox
.top
= rtext
.top
+ delta
- 1) + textlen
+ 2;
782 textlen
= rbox
.right
- rbox
.left
;
783 rbox
.right
= (rbox
.left
+= --rtext
.left
) + textlen
+ 2;
784 IntersectRect(&rbox
, &rbox
, &rtext
);
785 DrawFocusRect( hDC
, &rbox
);
790 /**********************************************************************
791 * BUTTON_CheckAutoRadioButton
793 * wndPtr is checked, uncheck every other auto radio button in group
795 static void BUTTON_CheckAutoRadioButton( WND
*wndPtr
)
797 HWND parent
, sibling
, start
;
798 if (!(wndPtr
->dwStyle
& WS_CHILD
)) return;
799 parent
= wndPtr
->parent
->hwndSelf
;
800 /* assure that starting control is not disabled or invisible */
801 start
= sibling
= GetNextDlgGroupItem( parent
, wndPtr
->hwndSelf
, TRUE
);
806 tmpWnd
= WIN_FindWndPtr(sibling
);
807 if ((wndPtr
->hwndSelf
!= sibling
) &&
808 ((tmpWnd
->dwStyle
& 0x0f) == BS_AUTORADIOBUTTON
))
809 SendMessageA( sibling
, BM_SETCHECK
, BUTTON_UNCHECKED
, 0 );
810 sibling
= GetNextDlgGroupItem( parent
, sibling
, FALSE
);
811 WIN_ReleaseWndPtr(tmpWnd
);
812 } while (sibling
!= start
);
816 /**********************************************************************
817 * Group Box Functions
820 static void GB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
823 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
825 if (action
!= ODA_DRAWENTIRE
) return;
827 BUTTON_SEND_CTLCOLOR( wndPtr
, hDC
);
829 GetClientRect( wndPtr
->hwndSelf
, &rc
);
830 if (TWEAK_WineLook
== WIN31_LOOK
) {
831 HPEN hPrevPen
= SelectObject( hDC
,
832 GetSysColorPen(COLOR_WINDOWFRAME
));
833 HBRUSH hPrevBrush
= SelectObject( hDC
,
834 GetStockObject(NULL_BRUSH
) );
836 Rectangle( hDC
, rc
.left
, rc
.top
+ 2, rc
.right
- 1, rc
.bottom
- 1 );
837 SelectObject( hDC
, hPrevBrush
);
838 SelectObject( hDC
, hPrevPen
);
844 SelectObject (hDC
, infoPtr
->hFont
);
845 GetTextMetricsA (hDC
, &tm
);
846 rcFrame
.top
+= (tm
.tmHeight
/ 2) - 1;
847 DrawEdge (hDC
, &rcFrame
, EDGE_ETCHED
, BF_RECT
);
852 if (infoPtr
->hFont
) SelectObject( hDC
, infoPtr
->hFont
);
853 if (wndPtr
->dwStyle
& WS_DISABLED
)
854 SetTextColor( hDC
, GetSysColor(COLOR_GRAYTEXT
) );
856 DrawTextA( hDC
, wndPtr
->text
, -1, &rc
, DT_SINGLELINE
| DT_NOCLIP
);
861 /**********************************************************************
862 * User Button Functions
865 static void UB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
869 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
871 if (action
== ODA_SELECT
) return;
873 GetClientRect( wndPtr
->hwndSelf
, &rc
);
875 if (infoPtr
->hFont
) SelectObject( hDC
, infoPtr
->hFont
);
876 hBrush
= GetControlBrush16( wndPtr
->hwndSelf
, hDC
, CTLCOLOR_BTN
);
878 FillRect( hDC
, &rc
, hBrush
);
879 if ((action
== ODA_FOCUS
) ||
880 ((action
== ODA_DRAWENTIRE
) && (infoPtr
->state
& BUTTON_HASFOCUS
)))
881 DrawFocusRect( hDC
, &rc
);
885 /**********************************************************************
886 * Ownerdrawn Button Functions
889 static void OB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
891 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
894 dis
.CtlType
= ODT_BUTTON
;
895 dis
.CtlID
= wndPtr
->wIDmenu
;
897 dis
.itemAction
= action
;
898 dis
.itemState
= ((infoPtr
->state
& BUTTON_HASFOCUS
) ? ODS_FOCUS
: 0) |
899 ((infoPtr
->state
& BUTTON_HIGHLIGHTED
) ? ODS_SELECTED
: 0) |
900 ((wndPtr
->dwStyle
& WS_DISABLED
) ? ODS_DISABLED
: 0);
901 dis
.hwndItem
= wndPtr
->hwndSelf
;
904 GetClientRect( wndPtr
->hwndSelf
, &dis
.rcItem
);
906 SetBkColor( hDC
, GetSysColor( COLOR_BTNFACE
) );
908 SendMessageA( GetParent(wndPtr
->hwndSelf
), WM_DRAWITEM
,
909 wndPtr
->wIDmenu
, (LPARAM
)&dis
);