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 SendMessageA( hWnd
, WM_LBUTTONDOWN
, 0, 0 );
270 SendMessageA( hWnd
, WM_LBUTTONUP
, 0, 0 );
274 oldHbitmap
= infoPtr
->hImage
;
275 if ((wndPtr
->dwStyle
& BS_BITMAP
) || (wndPtr
->dwStyle
& BS_ICON
))
276 infoPtr
->hImage
= (HANDLE
) lParam
;
280 if (wParam
== IMAGE_BITMAP
)
281 return (HBITMAP
)infoPtr
->hImage
;
282 else if (wParam
== IMAGE_ICON
)
283 return (HICON
)infoPtr
->hImage
;
289 return infoPtr
->state
& 3;
293 if (wParam
> maxCheckState
[style
]) wParam
= maxCheckState
[style
];
294 if ((infoPtr
->state
& 3) != wParam
)
296 if ((style
== BS_RADIOBUTTON
) || (style
== BS_AUTORADIOBUTTON
))
299 wndPtr
->dwStyle
|= WS_TABSTOP
;
301 wndPtr
->dwStyle
&= ~WS_TABSTOP
;
303 infoPtr
->state
= (infoPtr
->state
& ~3) | wParam
;
304 PAINT_BUTTON( wndPtr
, style
, ODA_SELECT
);
306 if ((style
== BS_AUTORADIOBUTTON
) && (wParam
== BUTTON_CHECKED
))
307 BUTTON_CheckAutoRadioButton( wndPtr
);
312 return infoPtr
->state
;
318 if (infoPtr
->state
& BUTTON_HIGHLIGHTED
) break;
319 infoPtr
->state
|= BUTTON_HIGHLIGHTED
;
323 if (!(infoPtr
->state
& BUTTON_HIGHLIGHTED
)) break;
324 infoPtr
->state
&= ~BUTTON_HIGHLIGHTED
;
326 PAINT_BUTTON( wndPtr
, style
, ODA_SELECT
);
330 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
335 /***********************************************************************
337 * The button window procedure. This is just a wrapper which locks
338 * the passed HWND and calls the real window procedure (with a WND*
339 * pointer pointing to the locked windowstructure).
341 LRESULT WINAPI
ButtonWndProc( HWND hWnd
, UINT uMsg
,
342 WPARAM wParam
, LPARAM lParam
)
345 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
347 res
= ButtonWndProc_locked(wndPtr
,uMsg
,wParam
,lParam
);
349 WIN_ReleaseWndPtr(wndPtr
);
353 /**********************************************************************
354 * Push Button Functions
356 static void PB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
358 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
359 BOOL bHighLighted
= (infoPtr
->state
& BUTTON_HIGHLIGHTED
);
362 * Delegate this to the more generic pushbutton painting
365 BUTTON_DrawPushButton(wndPtr
,
371 /**********************************************************************
372 * This method will actually do the drawing of the pushbutton
373 * depending on it's state and the pushedState parameter.
375 static void BUTTON_DrawPushButton(
384 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
385 int xBorderOffset
, yBorderOffset
;
386 xBorderOffset
= yBorderOffset
= 0;
388 GetClientRect( wndPtr
->hwndSelf
, &rc
);
390 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
391 if (infoPtr
->hFont
) SelectObject( hDC
, infoPtr
->hFont
);
392 BUTTON_SEND_CTLCOLOR( wndPtr
, hDC
);
393 hOldPen
= (HPEN
)SelectObject(hDC
, GetSysColorPen(COLOR_WINDOWFRAME
));
394 hOldBrush
=(HBRUSH
)SelectObject(hDC
,GetSysColorBrush(COLOR_BTNFACE
));
395 SetBkMode(hDC
, TRANSPARENT
);
397 if ( TWEAK_WineLook
== WIN31_LOOK
)
399 Rectangle(hDC
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
401 SetPixel( hDC
, rc
.left
, rc
.top
, GetSysColor(COLOR_WINDOW
) );
402 SetPixel( hDC
, rc
.left
, rc
.bottom
-1, GetSysColor(COLOR_WINDOW
) );
403 SetPixel( hDC
, rc
.right
-1, rc
.top
, GetSysColor(COLOR_WINDOW
) );
404 SetPixel( hDC
, rc
.right
-1, rc
.bottom
-1, GetSysColor(COLOR_WINDOW
));
405 InflateRect( &rc
, -1, -1 );
408 if ((wndPtr
->dwStyle
& 0x000f) == BS_DEFPUSHBUTTON
)
410 Rectangle(hDC
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
411 InflateRect( &rc
, -1, -1 );
414 if (TWEAK_WineLook
== WIN31_LOOK
)
418 /* draw button shadow: */
419 SelectObject(hDC
, GetSysColorBrush(COLOR_BTNSHADOW
));
420 PatBlt(hDC
, rc
.left
, rc
.top
, 1, rc
.bottom
-rc
.top
, PATCOPY
);
421 PatBlt(hDC
, rc
.left
, rc
.top
, rc
.right
-rc
.left
, 1, PATCOPY
);
422 rc
.left
+= 2; /* To position the text down and right */
425 rc
.right
++, rc
.bottom
++;
426 DrawEdge( hDC
, &rc
, EDGE_RAISED
, BF_RECT
);
428 /* To place de bitmap correctly */
429 xBorderOffset
+= GetSystemMetrics(SM_CXEDGE
);
430 yBorderOffset
+= GetSystemMetrics(SM_CYEDGE
);
432 rc
.right
--, rc
.bottom
--;
437 UINT uState
= DFCS_BUTTONPUSH
;
441 if ( (wndPtr
->dwStyle
& 0x000f) == BS_DEFPUSHBUTTON
)
444 uState
|= DFCS_PUSHED
;
447 DrawFrameControl( hDC
, &rc
, DFC_BUTTON
, uState
);
448 InflateRect( &rc
, -2, -2 );
454 rc
.left
+= 2; /* To position the text down and right */
459 /* draw button label, if any:
461 * In win9x we don't show text if there is a bitmap or icon.
462 * I don't know about win31 so I leave it as it was for win31.
463 * Dennis Björklund 12 Jul, 99
465 if ( wndPtr
->text
&& wndPtr
->text
[0]
466 && (TWEAK_WineLook
== WIN31_LOOK
|| !(wndPtr
->dwStyle
& (BS_ICON
|BS_BITMAP
))) )
469 GetObjectA( GetSysColorBrush(COLOR_BTNFACE
), sizeof(lb
), &lb
);
470 if (wndPtr
->dwStyle
& WS_DISABLED
&&
471 GetSysColor(COLOR_GRAYTEXT
)==lb
.lbColor
)
472 /* don't write gray text on gray background */
473 PaintGrayOnGray( hDC
,infoPtr
->hFont
,&rc
,wndPtr
->text
,
474 DT_CENTER
| DT_VCENTER
);
477 SetTextColor( hDC
, (wndPtr
->dwStyle
& WS_DISABLED
) ?
478 GetSysColor(COLOR_GRAYTEXT
) :
479 GetSysColor(COLOR_BTNTEXT
) );
480 DrawTextA( hDC
, wndPtr
->text
, -1, &rc
,
481 DT_SINGLELINE
| DT_CENTER
| DT_VCENTER
);
482 /* do we have the focus?
483 * Win9x draws focus last with a size prop. to the button
485 if (TWEAK_WineLook
== WIN31_LOOK
486 && infoPtr
->state
& BUTTON_HASFOCUS
)
488 RECT r
= { 0, 0, 0, 0 };
491 DrawTextA( hDC
, wndPtr
->text
, -1, &r
,
492 DT_SINGLELINE
| DT_CALCRECT
);
493 xdelta
= ((rc
.right
- rc
.left
) - (r
.right
- r
.left
) - 1) / 2;
494 ydelta
= ((rc
.bottom
- rc
.top
) - (r
.bottom
- r
.top
) - 1) / 2;
495 if (xdelta
< 0) xdelta
= 0;
496 if (ydelta
< 0) ydelta
= 0;
497 InflateRect( &rc
, -xdelta
, -ydelta
);
498 DrawFocusRect( hDC
, &rc
);
502 if ( ((wndPtr
->dwStyle
& BS_ICON
) || (wndPtr
->dwStyle
& BS_BITMAP
) ) &&
503 (infoPtr
->hImage
!= 0) )
505 int yOffset
, xOffset
;
506 int imageWidth
, imageHeight
;
509 * We extract the size of the image from the handle.
511 if (wndPtr
->dwStyle
& BS_ICON
)
516 GetIconInfo((HICON
)infoPtr
->hImage
, &iconInfo
);
517 GetObjectA (iconInfo
.hbmColor
, sizeof(BITMAP
), &bm
);
519 imageWidth
= bm
.bmWidth
;
520 imageHeight
= bm
.bmHeight
;
522 DeleteObject(iconInfo
.hbmColor
);
523 DeleteObject(iconInfo
.hbmMask
);
530 GetObjectA (infoPtr
->hImage
, sizeof(BITMAP
), &bm
);
532 imageWidth
= bm
.bmWidth
;
533 imageHeight
= bm
.bmHeight
;
536 /* Center the bitmap */
537 xOffset
= (((rc
.right
- rc
.left
) - 2*xBorderOffset
) - imageWidth
) / 2;
538 yOffset
= (((rc
.bottom
- rc
.top
) - 2*yBorderOffset
) - imageHeight
) / 2;
540 /* If the image is too big for the button then create a region*/
541 if(xOffset
< 0 || yOffset
< 0)
544 hBitmapRgn
= CreateRectRgn(
545 rc
.left
+ xBorderOffset
, rc
.top
+yBorderOffset
,
546 rc
.right
- xBorderOffset
, rc
.bottom
- yBorderOffset
);
547 SelectClipRgn(hDC
, hBitmapRgn
);
548 DeleteObject(hBitmapRgn
);
551 /* Let minimum 1 space from border */
552 xOffset
++, yOffset
++;
555 * Draw the image now.
557 if (wndPtr
->dwStyle
& BS_ICON
)
560 rc
.left
+ xOffset
, rc
.top
+ yOffset
,
561 (HICON
)infoPtr
->hImage
);
567 hdcMem
= CreateCompatibleDC (hDC
);
568 SelectObject (hdcMem
, (HBITMAP
)infoPtr
->hImage
);
572 imageWidth
, imageHeight
,
573 hdcMem
, 0, 0, SRCCOPY
);
578 if(xOffset
< 0 || yOffset
< 0)
580 SelectClipRgn(hDC
, 0);
584 if (TWEAK_WineLook
!= WIN31_LOOK
585 && infoPtr
->state
& BUTTON_HASFOCUS
)
587 InflateRect( &focus_rect
, -1, -1 );
588 DrawFocusRect( hDC
, &focus_rect
);
592 SelectObject( hDC
, hOldPen
);
593 SelectObject( hDC
, hOldBrush
);
597 /**********************************************************************
598 * PB_Paint & CB_Paint sub function [internal]
599 * Paint text using a raster brush to avoid gray text on gray
600 * background. 'format' can be a combination of DT_CENTER and
601 * DT_VCENTER to use this function in both PB_PAINT and
602 * CB_PAINT. - Dirk Thierbach
604 * FIXME: This and TEXT_GrayString should be eventually combined,
605 * so calling one common function from PB_Paint, CB_Paint and
606 * TEXT_GrayString will be enough. Also note that this
607 * function ignores the CACHE_GetPattern funcs.
610 void PaintGrayOnGray(HDC hDC
,HFONT hFont
,RECT
*rc
,char *text
,
613 /* This is the standard gray on gray pattern:
614 static const WORD Pattern[] = {0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55};
616 /* This pattern gives better readability with X Fonts.
617 FIXME: Maybe the user should be allowed to decide which he wants. */
618 static const WORD Pattern
[] = {0x55,0xFF,0xAA,0xFF,0x55,0xFF,0xAA,0xFF};
620 HBITMAP hbm
= CreateBitmap( 8, 8, 1, 1, Pattern
);
621 HDC hdcMem
= CreateCompatibleDC(hDC
);
627 DrawTextA( hDC
, text
, -1, &rect
, DT_SINGLELINE
| DT_CALCRECT
);
628 /* now text width and height are in rect.right and rect.bottom */
630 rect
.left
= rect
.top
= 0; /* drawing pos in hdcMem */
631 if (format
& DT_CENTER
) rect
.left
=(rc
->right
-rect
.right
)/2;
632 if (format
& DT_VCENTER
) rect
.top
=(rc
->bottom
-rect
.bottom
)/2;
633 hbmMem
= CreateCompatibleBitmap( hDC
,rect
.right
,rect
.bottom
);
634 SelectObject( hdcMem
, hbmMem
);
635 PatBlt( hdcMem
,0,0,rect
.right
,rect
.bottom
,WHITENESS
);
636 /* will be overwritten by DrawText, but just in case */
637 if (hFont
) SelectObject( hdcMem
, hFont
);
638 DrawTextA( hdcMem
, text
, -1, &rc2
, DT_SINGLELINE
);
639 /* After draw: foreground = 0 bits, background = 1 bits */
640 hBr
= SelectObject( hdcMem
, CreatePatternBrush(hbm
) );
642 PatBlt( hdcMem
,0,0,rect
.right
,rect
.bottom
,0xAF0229);
643 /* only keep the foreground bits where pattern is 1 */
644 DeleteObject( SelectObject( hdcMem
,hBr
) );
645 BitBlt(hDC
,rect
.left
,rect
.top
,rect
.right
,rect
.bottom
,hdcMem
,0,0,SRCAND
);
646 /* keep the background of the dest */
648 DeleteObject( hbmMem
);
652 /**********************************************************************
653 * Check Box & Radio Button Functions
656 static void CB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
658 RECT rbox
, rtext
, client
;
661 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
664 * if the button has a bitmap/icon, draw a normal pushbutton
665 * instead of a radion button.
667 if (infoPtr
->hImage
!= 0)
669 BOOL bHighLighted
= ((infoPtr
->state
& BUTTON_HIGHLIGHTED
) ||
670 (infoPtr
->state
& BUTTON_CHECKED
));
672 BUTTON_DrawPushButton(wndPtr
,
680 GetClientRect(wndPtr
->hwndSelf
, &client
);
681 rbox
= rtext
= client
;
683 if (infoPtr
->hFont
) SelectObject( hDC
, infoPtr
->hFont
);
685 /* Something is still not right, checkboxes (and edit controls)
686 * in wsping32 have white backgrounds instead of dark grey.
687 * BUTTON_SEND_CTLCOLOR() is even worse since it returns 0 in this
688 * particular case and the background is not painted at all.
691 hBrush
= GetControlBrush16( wndPtr
->hwndSelf
, hDC
, CTLCOLOR_BTN
);
693 if (wndPtr
->dwStyle
& BS_LEFTTEXT
)
695 /* magic +4 is what CTL3D expects */
697 rtext
.right
-= checkBoxWidth
+ 4;
698 rbox
.left
= rbox
.right
- checkBoxWidth
;
702 rtext
.left
+= checkBoxWidth
+ 4;
703 rbox
.right
= checkBoxWidth
;
706 /* Draw the check-box bitmap */
708 if (wndPtr
->text
) textlen
= strlen( wndPtr
->text
);
709 if (action
== ODA_DRAWENTIRE
|| action
== ODA_SELECT
)
711 if( TWEAK_WineLook
== WIN31_LOOK
)
713 HDC hMemDC
= CreateCompatibleDC( hDC
);
715 delta
= (rbox
.bottom
- rbox
.top
- checkBoxHeight
) / 2;
717 /* Check in case the client area is smaller than the checkbox bitmap */
718 if (delta
< 0) delta
= 0;
720 if (action
== ODA_SELECT
) FillRect( hDC
, &rbox
, hBrush
);
721 else FillRect( hDC
, &client
, hBrush
);
723 if (infoPtr
->state
& BUTTON_HIGHLIGHTED
) x
+= 2 * checkBoxWidth
;
724 if (infoPtr
->state
& (BUTTON_CHECKED
| BUTTON_3STATE
)) x
+= checkBoxWidth
;
725 if (((wndPtr
->dwStyle
& 0x0f) == BS_RADIOBUTTON
) ||
726 ((wndPtr
->dwStyle
& 0x0f) == BS_AUTORADIOBUTTON
)) y
+= checkBoxHeight
;
727 else if (infoPtr
->state
& BUTTON_3STATE
) y
+= 2 * checkBoxHeight
;
729 /* The bitmap for the radio button is not aligned with the
730 * left of the window, it is 1 pixel off. */
731 if (((wndPtr
->dwStyle
& 0x0f) == BS_RADIOBUTTON
) ||
732 ((wndPtr
->dwStyle
& 0x0f) == BS_AUTORADIOBUTTON
))
735 SelectObject( hMemDC
, hbitmapCheckBoxes
);
736 BitBlt( hDC
, rbox
.left
, rbox
.top
+ delta
, checkBoxWidth
,
737 checkBoxHeight
, hMemDC
, x
, y
, SRCCOPY
);
744 if (((wndPtr
->dwStyle
& 0x0f) == BS_RADIOBUTTON
) ||
745 ((wndPtr
->dwStyle
& 0x0f) == BS_AUTORADIOBUTTON
)) state
= DFCS_BUTTONRADIO
;
746 else if (infoPtr
->state
& BUTTON_3STATE
) state
= DFCS_BUTTON3STATE
;
747 else state
= DFCS_BUTTONCHECK
;
749 if (infoPtr
->state
& (BUTTON_CHECKED
| BUTTON_3STATE
)) state
|= DFCS_CHECKED
;
751 if (infoPtr
->state
& BUTTON_HIGHLIGHTED
) state
|= DFCS_PUSHED
;
753 if (wndPtr
->dwStyle
& WS_DISABLED
) state
|= DFCS_INACTIVE
;
755 DrawFrameControl( hDC
, &rbox
, DFC_BUTTON
, state
);
759 if( textlen
&& action
!= ODA_SELECT
)
761 if (wndPtr
->dwStyle
& WS_DISABLED
&&
762 GetSysColor(COLOR_GRAYTEXT
)==GetBkColor(hDC
)) {
763 /* don't write gray text on gray background */
764 PaintGrayOnGray( hDC
, infoPtr
->hFont
, &rtext
, wndPtr
->text
,
767 if (wndPtr
->dwStyle
& WS_DISABLED
)
768 SetTextColor( hDC
, GetSysColor(COLOR_GRAYTEXT
) );
769 DrawTextA( hDC
, wndPtr
->text
, textlen
, &rtext
,
770 DT_SINGLELINE
| DT_VCENTER
);
775 if ((action
== ODA_FOCUS
) ||
776 ((action
== ODA_DRAWENTIRE
) && (infoPtr
->state
& BUTTON_HASFOCUS
)))
778 /* again, this is what CTL3D expects */
782 DrawTextA( hDC
, wndPtr
->text
, textlen
, &rbox
,
783 DT_SINGLELINE
| DT_CALCRECT
);
784 textlen
= rbox
.bottom
- rbox
.top
;
785 delta
= ((rtext
.bottom
- rtext
.top
) - textlen
)/2;
786 rbox
.bottom
= (rbox
.top
= rtext
.top
+ delta
- 1) + textlen
+ 2;
787 textlen
= rbox
.right
- rbox
.left
;
788 rbox
.right
= (rbox
.left
+= --rtext
.left
) + textlen
+ 2;
789 IntersectRect(&rbox
, &rbox
, &rtext
);
790 DrawFocusRect( hDC
, &rbox
);
795 /**********************************************************************
796 * BUTTON_CheckAutoRadioButton
798 * wndPtr is checked, uncheck every other auto radio button in group
800 static void BUTTON_CheckAutoRadioButton( WND
*wndPtr
)
802 HWND parent
, sibling
, start
;
803 if (!(wndPtr
->dwStyle
& WS_CHILD
)) return;
804 parent
= wndPtr
->parent
->hwndSelf
;
805 /* assure that starting control is not disabled or invisible */
806 start
= sibling
= GetNextDlgGroupItem( parent
, wndPtr
->hwndSelf
, TRUE
);
811 tmpWnd
= WIN_FindWndPtr(sibling
);
812 if ((wndPtr
->hwndSelf
!= sibling
) &&
813 ((tmpWnd
->dwStyle
& 0x0f) == BS_AUTORADIOBUTTON
))
814 SendMessageA( sibling
, BM_SETCHECK
, BUTTON_UNCHECKED
, 0 );
815 sibling
= GetNextDlgGroupItem( parent
, sibling
, FALSE
);
816 WIN_ReleaseWndPtr(tmpWnd
);
817 } while (sibling
!= start
);
821 /**********************************************************************
822 * Group Box Functions
825 static void GB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
828 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
830 if (action
!= ODA_DRAWENTIRE
) return;
832 BUTTON_SEND_CTLCOLOR( wndPtr
, hDC
);
834 GetClientRect( wndPtr
->hwndSelf
, &rc
);
835 if (TWEAK_WineLook
== WIN31_LOOK
) {
836 HPEN hPrevPen
= SelectObject( hDC
,
837 GetSysColorPen(COLOR_WINDOWFRAME
));
838 HBRUSH hPrevBrush
= SelectObject( hDC
,
839 GetStockObject(NULL_BRUSH
) );
841 Rectangle( hDC
, rc
.left
, rc
.top
+ 2, rc
.right
- 1, rc
.bottom
- 1 );
842 SelectObject( hDC
, hPrevBrush
);
843 SelectObject( hDC
, hPrevPen
);
849 SelectObject (hDC
, infoPtr
->hFont
);
850 GetTextMetricsA (hDC
, &tm
);
851 rcFrame
.top
+= (tm
.tmHeight
/ 2) - 1;
852 DrawEdge (hDC
, &rcFrame
, EDGE_ETCHED
, BF_RECT
);
857 if (infoPtr
->hFont
) SelectObject( hDC
, infoPtr
->hFont
);
858 if (wndPtr
->dwStyle
& WS_DISABLED
)
859 SetTextColor( hDC
, GetSysColor(COLOR_GRAYTEXT
) );
861 DrawTextA( hDC
, wndPtr
->text
, -1, &rc
, DT_SINGLELINE
| DT_NOCLIP
);
866 /**********************************************************************
867 * User Button Functions
870 static void UB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
874 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
876 if (action
== ODA_SELECT
) return;
878 GetClientRect( wndPtr
->hwndSelf
, &rc
);
880 if (infoPtr
->hFont
) SelectObject( hDC
, infoPtr
->hFont
);
881 hBrush
= GetControlBrush16( wndPtr
->hwndSelf
, hDC
, CTLCOLOR_BTN
);
883 FillRect( hDC
, &rc
, hBrush
);
884 if ((action
== ODA_FOCUS
) ||
885 ((action
== ODA_DRAWENTIRE
) && (infoPtr
->state
& BUTTON_HASFOCUS
)))
886 DrawFocusRect( hDC
, &rc
);
890 /**********************************************************************
891 * Ownerdrawn Button Functions
894 static void OB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
896 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
899 dis
.CtlType
= ODT_BUTTON
;
900 dis
.CtlID
= wndPtr
->wIDmenu
;
902 dis
.itemAction
= action
;
903 dis
.itemState
= ((infoPtr
->state
& BUTTON_HASFOCUS
) ? ODS_FOCUS
: 0) |
904 ((infoPtr
->state
& BUTTON_HIGHLIGHTED
) ? ODS_SELECTED
: 0) |
905 ((wndPtr
->dwStyle
& WS_DISABLED
) ? ODS_DISABLED
: 0);
906 dis
.hwndItem
= wndPtr
->hwndSelf
;
909 GetClientRect( wndPtr
->hwndSelf
, &dis
.rcItem
);
911 SetBkColor( hDC
, GetSysColor( COLOR_BTNFACE
) );
913 SendMessageA( GetParent(wndPtr
->hwndSelf
), WM_DRAWITEM
,
914 wndPtr
->wIDmenu
, (LPARAM
)&dis
);