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
14 #include "wine/winuser16.h"
17 static void PaintGrayOnGray( HDC hDC
,HFONT hFont
,RECT
*rc
,
18 char *text
, UINT format
);
20 static void PB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
);
21 static void CB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
);
22 static void GB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
);
23 static void UB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
);
24 static void OB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
);
25 static void BUTTON_CheckAutoRadioButton( WND
*wndPtr
);
26 static void BUTTON_DrawPushButton( WND
*wndPtr
, HDC hDC
, WORD action
, BOOL pushedState
);
28 #define MAX_BTN_TYPE 12
30 static const WORD maxCheckState
[MAX_BTN_TYPE
] =
32 BUTTON_UNCHECKED
, /* BS_PUSHBUTTON */
33 BUTTON_UNCHECKED
, /* BS_DEFPUSHBUTTON */
34 BUTTON_CHECKED
, /* BS_CHECKBOX */
35 BUTTON_CHECKED
, /* BS_AUTOCHECKBOX */
36 BUTTON_CHECKED
, /* BS_RADIOBUTTON */
37 BUTTON_3STATE
, /* BS_3STATE */
38 BUTTON_3STATE
, /* BS_AUTO3STATE */
39 BUTTON_UNCHECKED
, /* BS_GROUPBOX */
40 BUTTON_UNCHECKED
, /* BS_USERBUTTON */
41 BUTTON_CHECKED
, /* BS_AUTORADIOBUTTON */
42 BUTTON_UNCHECKED
, /* Not defined */
43 BUTTON_UNCHECKED
/* BS_OWNERDRAW */
46 typedef void (*pfPaint
)( WND
*wndPtr
, HDC hdc
, WORD action
);
48 static const pfPaint btnPaintFunc
[MAX_BTN_TYPE
] =
50 PB_Paint
, /* BS_PUSHBUTTON */
51 PB_Paint
, /* BS_DEFPUSHBUTTON */
52 CB_Paint
, /* BS_CHECKBOX */
53 CB_Paint
, /* BS_AUTOCHECKBOX */
54 CB_Paint
, /* BS_RADIOBUTTON */
55 CB_Paint
, /* BS_3STATE */
56 CB_Paint
, /* BS_AUTO3STATE */
57 GB_Paint
, /* BS_GROUPBOX */
58 UB_Paint
, /* BS_USERBUTTON */
59 CB_Paint
, /* BS_AUTORADIOBUTTON */
60 NULL
, /* Not defined */
61 OB_Paint
/* BS_OWNERDRAW */
64 #define PAINT_BUTTON(wndPtr,style,action) \
65 if (btnPaintFunc[style]) { \
66 HDC hdc = GetDC( (wndPtr)->hwndSelf ); \
67 (btnPaintFunc[style])(wndPtr,hdc,action); \
68 ReleaseDC( (wndPtr)->hwndSelf, hdc ); }
70 #define BUTTON_SEND_CTLCOLOR(wndPtr,hdc) \
71 SendMessageA( GetParent((wndPtr)->hwndSelf), WM_CTLCOLORBTN, \
72 (hdc), (wndPtr)->hwndSelf )
74 static HBITMAP hbitmapCheckBoxes
= 0;
75 static WORD checkBoxWidth
= 0, checkBoxHeight
= 0;
78 /***********************************************************************
79 * ButtonWndProc_locked
81 * Called with window lock held.
83 static inline LRESULT WINAPI
ButtonWndProc_locked(WND
* wndPtr
, UINT uMsg
,
84 WPARAM wParam
, LPARAM lParam
)
87 HWND hWnd
= wndPtr
->hwndSelf
;
89 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
90 LONG style
= wndPtr
->dwStyle
& 0x0f;
93 pt
.x
= LOWORD(lParam
);
94 pt
.y
= HIWORD(lParam
);
101 case BS_PUSHBUTTON
: return DLGC_BUTTON
| DLGC_UNDEFPUSHBUTTON
;
102 case BS_DEFPUSHBUTTON
: return DLGC_BUTTON
| DLGC_DEFPUSHBUTTON
;
104 case BS_AUTORADIOBUTTON
: return DLGC_BUTTON
| DLGC_RADIOBUTTON
;
105 default: return DLGC_BUTTON
;
109 PAINT_BUTTON( wndPtr
, style
, ODA_DRAWENTIRE
);
113 if (!hbitmapCheckBoxes
)
116 hbitmapCheckBoxes
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_CHECKBOXES
));
117 GetObjectA( hbitmapCheckBoxes
, sizeof(bmp
), &bmp
);
118 checkBoxWidth
= bmp
.bmWidth
/ 4;
119 checkBoxHeight
= bmp
.bmHeight
/ 3;
121 if (style
< 0L || style
>= MAX_BTN_TYPE
)
122 return -1; /* abort */
123 infoPtr
->state
= BUTTON_UNCHECKED
;
132 if (btnPaintFunc
[style
])
135 HDC hdc
= wParam
? (HDC
)wParam
: BeginPaint( hWnd
, &ps
);
136 SetBkMode( hdc
, OPAQUE
);
137 (btnPaintFunc
[style
])( wndPtr
, hdc
, ODA_DRAWENTIRE
);
138 if( !wParam
) EndPaint( hWnd
, &ps
);
143 if (wParam
== VK_SPACE
)
145 SendMessageA( hWnd
, BM_SETSTATE
, TRUE
, 0 );
146 infoPtr
->state
|= BUTTON_BTNPRESSED
;
150 case WM_LBUTTONDBLCLK
:
151 if(wndPtr
->dwStyle
& BS_NOTIFY
||
152 style
==BS_RADIOBUTTON
||
153 style
==BS_USERBUTTON
||
154 style
==BS_OWNERDRAW
) {
155 SendMessageA( GetParent(hWnd
), WM_COMMAND
,
156 MAKEWPARAM( wndPtr
->wIDmenu
, BN_DOUBLECLICKED
), hWnd
);
163 SendMessageA( hWnd
, BM_SETSTATE
, TRUE
, 0 );
164 infoPtr
->state
|= BUTTON_BTNPRESSED
;
168 if (wParam
!= VK_SPACE
)
172 if (!(infoPtr
->state
& BUTTON_BTNPRESSED
)) break;
173 infoPtr
->state
&= BUTTON_NSTATES
;
174 if (!(infoPtr
->state
& BUTTON_HIGHLIGHTED
)) {
178 SendMessageA( hWnd
, BM_SETSTATE
, FALSE
, 0 );
180 GetClientRect( hWnd
, &rect
);
181 if (uMsg
== WM_KEYUP
|| PtInRect( &rect
, pt
))
185 case BS_AUTOCHECKBOX
:
186 SendMessageA( hWnd
, BM_SETCHECK
,
187 !(infoPtr
->state
& BUTTON_CHECKED
), 0 );
189 case BS_AUTORADIOBUTTON
:
190 SendMessageA( hWnd
, BM_SETCHECK
, TRUE
, 0 );
193 SendMessageA( hWnd
, BM_SETCHECK
,
194 (infoPtr
->state
& BUTTON_3STATE
) ? 0 :
195 ((infoPtr
->state
& 3) + 1), 0 );
198 SendMessageA( GetParent(hWnd
), WM_COMMAND
,
199 MAKEWPARAM( wndPtr
->wIDmenu
, BN_CLICKED
), hWnd
);
203 case WM_CAPTURECHANGED
:
204 if (infoPtr
->state
& BUTTON_BTNPRESSED
) {
205 infoPtr
->state
&= BUTTON_NSTATES
;
206 if (infoPtr
->state
& BUTTON_HIGHLIGHTED
)
207 SendMessageA( hWnd
, BM_SETSTATE
, FALSE
, 0 );
212 if (GetCapture() == hWnd
)
214 GetClientRect( hWnd
, &rect
);
215 SendMessageA( hWnd
, BM_SETSTATE
, PtInRect(&rect
, pt
), 0 );
220 if(style
== BS_GROUPBOX
) return HTTRANSPARENT
;
221 return DefWindowProcA( hWnd
, uMsg
, wParam
, lParam
);
224 DEFWND_SetText( wndPtr
, (LPCSTR
)lParam
);
225 if( wndPtr
->dwStyle
& WS_VISIBLE
)
226 PAINT_BUTTON( wndPtr
, style
, ODA_DRAWENTIRE
);
230 infoPtr
->hFont
= (HFONT16
)wParam
;
231 if (lParam
&& (wndPtr
->dwStyle
& WS_VISIBLE
))
232 PAINT_BUTTON( wndPtr
, style
, ODA_DRAWENTIRE
);
236 return infoPtr
->hFont
;
239 if ((style
== BS_AUTORADIOBUTTON
) && (GetCapture() != hWnd
) &&
240 !(SendMessageA(hWnd
, BM_GETCHECK
, 0, 0) & BST_CHECKED
))
242 /* The notification is sent when the button (BS_AUTORADIOBUTTON)
243 is unckecked and the focus was not given by a mouse click. */
244 SendMessageA( hWnd
, BM_SETCHECK
, TRUE
, 0 );
245 SendMessageA( GetParent(hWnd
), WM_COMMAND
,
246 MAKEWPARAM( wndPtr
->wIDmenu
, BN_CLICKED
), hWnd
);
248 infoPtr
->state
|= BUTTON_HASFOCUS
;
249 PAINT_BUTTON( wndPtr
, style
, ODA_FOCUS
);
253 infoPtr
->state
&= ~BUTTON_HASFOCUS
;
254 PAINT_BUTTON( wndPtr
, style
, ODA_FOCUS
);
255 InvalidateRect( hWnd
, NULL
, TRUE
);
258 case WM_SYSCOLORCHANGE
:
259 InvalidateRect( hWnd
, NULL
, FALSE
);
264 if ((wParam
& 0x0f) >= MAX_BTN_TYPE
) break;
265 wndPtr
->dwStyle
= (wndPtr
->dwStyle
& 0xfffffff0)
266 | (wParam
& 0x0000000f);
267 style
= wndPtr
->dwStyle
& 0x0000000f;
268 PAINT_BUTTON( wndPtr
, style
, ODA_DRAWENTIRE
);
272 SendMessageA( hWnd
, WM_LBUTTONDOWN
, 0, 0 );
273 SendMessageA( hWnd
, WM_LBUTTONUP
, 0, 0 );
277 oldHbitmap
= infoPtr
->hImage
;
278 if ((wndPtr
->dwStyle
& BS_BITMAP
) || (wndPtr
->dwStyle
& BS_ICON
))
280 infoPtr
->hImage
= (HANDLE
) lParam
;
281 InvalidateRect( hWnd
, NULL
, FALSE
);
286 if (wParam
== IMAGE_BITMAP
)
287 return (HBITMAP
)infoPtr
->hImage
;
288 else if (wParam
== IMAGE_ICON
)
289 return (HICON
)infoPtr
->hImage
;
295 return infoPtr
->state
& 3;
299 if (wParam
> maxCheckState
[style
]) wParam
= maxCheckState
[style
];
300 if ((infoPtr
->state
& 3) != wParam
)
302 if ((style
== BS_RADIOBUTTON
) || (style
== BS_AUTORADIOBUTTON
))
305 wndPtr
->dwStyle
|= WS_TABSTOP
;
307 wndPtr
->dwStyle
&= ~WS_TABSTOP
;
309 infoPtr
->state
= (infoPtr
->state
& ~3) | wParam
;
310 PAINT_BUTTON( wndPtr
, style
, ODA_SELECT
);
312 if ((style
== BS_AUTORADIOBUTTON
) && (wParam
== BUTTON_CHECKED
))
313 BUTTON_CheckAutoRadioButton( wndPtr
);
318 return infoPtr
->state
;
324 if (infoPtr
->state
& BUTTON_HIGHLIGHTED
) break;
325 infoPtr
->state
|= BUTTON_HIGHLIGHTED
;
329 if (!(infoPtr
->state
& BUTTON_HIGHLIGHTED
)) break;
330 infoPtr
->state
&= ~BUTTON_HIGHLIGHTED
;
332 PAINT_BUTTON( wndPtr
, style
, ODA_SELECT
);
336 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
341 /***********************************************************************
343 * The button window procedure. This is just a wrapper which locks
344 * the passed HWND and calls the real window procedure (with a WND*
345 * pointer pointing to the locked windowstructure).
347 LRESULT WINAPI
ButtonWndProc( HWND hWnd
, UINT uMsg
,
348 WPARAM wParam
, LPARAM lParam
)
351 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
353 res
= ButtonWndProc_locked(wndPtr
,uMsg
,wParam
,lParam
);
355 WIN_ReleaseWndPtr(wndPtr
);
359 /**********************************************************************
360 * Push Button Functions
362 static void PB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
364 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
365 BOOL bHighLighted
= (infoPtr
->state
& BUTTON_HIGHLIGHTED
);
368 * Delegate this to the more generic pushbutton painting
371 BUTTON_DrawPushButton(wndPtr
,
377 /**********************************************************************
378 * This method will actually do the drawing of the pushbutton
379 * depending on it's state and the pushedState parameter.
381 static void BUTTON_DrawPushButton(
390 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
391 int xBorderOffset
, yBorderOffset
;
392 xBorderOffset
= yBorderOffset
= 0;
394 GetClientRect( wndPtr
->hwndSelf
, &rc
);
396 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
397 if (infoPtr
->hFont
) SelectObject( hDC
, infoPtr
->hFont
);
398 BUTTON_SEND_CTLCOLOR( wndPtr
, hDC
);
399 hOldPen
= (HPEN
)SelectObject(hDC
, GetSysColorPen(COLOR_WINDOWFRAME
));
400 hOldBrush
=(HBRUSH
)SelectObject(hDC
,GetSysColorBrush(COLOR_BTNFACE
));
401 SetBkMode(hDC
, TRANSPARENT
);
403 if ( TWEAK_WineLook
== WIN31_LOOK
)
405 Rectangle(hDC
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
407 SetPixel( hDC
, rc
.left
, rc
.top
, GetSysColor(COLOR_WINDOW
) );
408 SetPixel( hDC
, rc
.left
, rc
.bottom
-1, GetSysColor(COLOR_WINDOW
) );
409 SetPixel( hDC
, rc
.right
-1, rc
.top
, GetSysColor(COLOR_WINDOW
) );
410 SetPixel( hDC
, rc
.right
-1, rc
.bottom
-1, GetSysColor(COLOR_WINDOW
));
411 InflateRect( &rc
, -1, -1 );
414 if ((wndPtr
->dwStyle
& 0x000f) == BS_DEFPUSHBUTTON
)
416 Rectangle(hDC
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
417 InflateRect( &rc
, -1, -1 );
420 if (TWEAK_WineLook
== WIN31_LOOK
)
424 /* draw button shadow: */
425 SelectObject(hDC
, GetSysColorBrush(COLOR_BTNSHADOW
));
426 PatBlt(hDC
, rc
.left
, rc
.top
, 1, rc
.bottom
-rc
.top
, PATCOPY
);
427 PatBlt(hDC
, rc
.left
, rc
.top
, rc
.right
-rc
.left
, 1, PATCOPY
);
428 rc
.left
+= 2; /* To position the text down and right */
431 rc
.right
++, rc
.bottom
++;
432 DrawEdge( hDC
, &rc
, EDGE_RAISED
, BF_RECT
);
434 /* To place de bitmap correctly */
435 xBorderOffset
+= GetSystemMetrics(SM_CXEDGE
);
436 yBorderOffset
+= GetSystemMetrics(SM_CYEDGE
);
438 rc
.right
--, rc
.bottom
--;
443 UINT uState
= DFCS_BUTTONPUSH
;
447 if ( (wndPtr
->dwStyle
& 0x000f) == BS_DEFPUSHBUTTON
)
450 uState
|= DFCS_PUSHED
;
453 DrawFrameControl( hDC
, &rc
, DFC_BUTTON
, uState
);
454 InflateRect( &rc
, -2, -2 );
460 rc
.left
+= 2; /* To position the text down and right */
465 /* draw button label, if any:
467 * In win9x we don't show text if there is a bitmap or icon.
468 * I don't know about win31 so I leave it as it was for win31.
469 * Dennis Björklund 12 Jul, 99
471 if ( wndPtr
->text
&& wndPtr
->text
[0]
472 && (TWEAK_WineLook
== WIN31_LOOK
|| !(wndPtr
->dwStyle
& (BS_ICON
|BS_BITMAP
))) )
475 GetObjectA( GetSysColorBrush(COLOR_BTNFACE
), sizeof(lb
), &lb
);
476 if (wndPtr
->dwStyle
& WS_DISABLED
&&
477 GetSysColor(COLOR_GRAYTEXT
)==lb
.lbColor
)
478 /* don't write gray text on gray background */
479 PaintGrayOnGray( hDC
,infoPtr
->hFont
,&rc
,wndPtr
->text
,
480 DT_CENTER
| DT_VCENTER
);
483 SetTextColor( hDC
, (wndPtr
->dwStyle
& WS_DISABLED
) ?
484 GetSysColor(COLOR_GRAYTEXT
) :
485 GetSysColor(COLOR_BTNTEXT
) );
486 DrawTextA( hDC
, wndPtr
->text
, -1, &rc
,
487 DT_SINGLELINE
| DT_CENTER
| DT_VCENTER
);
488 /* do we have the focus?
489 * Win9x draws focus last with a size prop. to the button
491 if (TWEAK_WineLook
== WIN31_LOOK
492 && infoPtr
->state
& BUTTON_HASFOCUS
)
494 RECT r
= { 0, 0, 0, 0 };
497 DrawTextA( hDC
, wndPtr
->text
, -1, &r
,
498 DT_SINGLELINE
| DT_CALCRECT
);
499 xdelta
= ((rc
.right
- rc
.left
) - (r
.right
- r
.left
) - 1) / 2;
500 ydelta
= ((rc
.bottom
- rc
.top
) - (r
.bottom
- r
.top
) - 1) / 2;
501 if (xdelta
< 0) xdelta
= 0;
502 if (ydelta
< 0) ydelta
= 0;
503 InflateRect( &rc
, -xdelta
, -ydelta
);
504 DrawFocusRect( hDC
, &rc
);
508 if ( ((wndPtr
->dwStyle
& BS_ICON
) || (wndPtr
->dwStyle
& BS_BITMAP
) ) &&
509 (infoPtr
->hImage
!= 0) )
511 int yOffset
, xOffset
;
512 int imageWidth
, imageHeight
;
515 * We extract the size of the image from the handle.
517 if (wndPtr
->dwStyle
& BS_ICON
)
522 GetIconInfo((HICON
)infoPtr
->hImage
, &iconInfo
);
523 GetObjectA (iconInfo
.hbmColor
, sizeof(BITMAP
), &bm
);
525 imageWidth
= bm
.bmWidth
;
526 imageHeight
= bm
.bmHeight
;
528 DeleteObject(iconInfo
.hbmColor
);
529 DeleteObject(iconInfo
.hbmMask
);
536 GetObjectA (infoPtr
->hImage
, sizeof(BITMAP
), &bm
);
538 imageWidth
= bm
.bmWidth
;
539 imageHeight
= bm
.bmHeight
;
542 /* Center the bitmap */
543 xOffset
= (((rc
.right
- rc
.left
) - 2*xBorderOffset
) - imageWidth
) / 2;
544 yOffset
= (((rc
.bottom
- rc
.top
) - 2*yBorderOffset
) - imageHeight
) / 2;
546 /* If the image is too big for the button then create a region*/
547 if(xOffset
< 0 || yOffset
< 0)
550 hBitmapRgn
= CreateRectRgn(
551 rc
.left
+ xBorderOffset
, rc
.top
+yBorderOffset
,
552 rc
.right
- xBorderOffset
, rc
.bottom
- yBorderOffset
);
553 SelectClipRgn(hDC
, hBitmapRgn
);
554 DeleteObject(hBitmapRgn
);
557 /* Let minimum 1 space from border */
558 xOffset
++, yOffset
++;
561 * Draw the image now.
563 if (wndPtr
->dwStyle
& BS_ICON
)
566 rc
.left
+ xOffset
, rc
.top
+ yOffset
,
567 (HICON
)infoPtr
->hImage
);
573 hdcMem
= CreateCompatibleDC (hDC
);
574 SelectObject (hdcMem
, (HBITMAP
)infoPtr
->hImage
);
578 imageWidth
, imageHeight
,
579 hdcMem
, 0, 0, SRCCOPY
);
584 if(xOffset
< 0 || yOffset
< 0)
586 SelectClipRgn(hDC
, 0);
590 if (TWEAK_WineLook
!= WIN31_LOOK
591 && infoPtr
->state
& BUTTON_HASFOCUS
)
593 InflateRect( &focus_rect
, -1, -1 );
594 DrawFocusRect( hDC
, &focus_rect
);
598 SelectObject( hDC
, hOldPen
);
599 SelectObject( hDC
, hOldBrush
);
603 /**********************************************************************
604 * PB_Paint & CB_Paint sub function [internal]
605 * Paint text using a raster brush to avoid gray text on gray
606 * background. 'format' can be a combination of DT_CENTER and
607 * DT_VCENTER to use this function in both PB_PAINT and
608 * CB_PAINT. - Dirk Thierbach
610 * FIXME: This and TEXT_GrayString should be eventually combined,
611 * so calling one common function from PB_Paint, CB_Paint and
612 * TEXT_GrayString will be enough. Also note that this
613 * function ignores the CACHE_GetPattern funcs.
616 void PaintGrayOnGray(HDC hDC
,HFONT hFont
,RECT
*rc
,char *text
,
619 /* This is the standard gray on gray pattern:
620 static const WORD Pattern[] = {0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55};
622 /* This pattern gives better readability with X Fonts.
623 FIXME: Maybe the user should be allowed to decide which he wants. */
624 static const WORD Pattern
[] = {0x55,0xFF,0xAA,0xFF,0x55,0xFF,0xAA,0xFF};
626 HBITMAP hbm
= CreateBitmap( 8, 8, 1, 1, Pattern
);
627 HDC hdcMem
= CreateCompatibleDC(hDC
);
633 DrawTextA( hDC
, text
, -1, &rect
, DT_SINGLELINE
| DT_CALCRECT
);
634 /* now text width and height are in rect.right and rect.bottom */
636 rect
.left
= rect
.top
= 0; /* drawing pos in hdcMem */
637 if (format
& DT_CENTER
) rect
.left
=(rc
->right
-rect
.right
)/2;
638 if (format
& DT_VCENTER
) rect
.top
=(rc
->bottom
-rect
.bottom
)/2;
639 hbmMem
= CreateCompatibleBitmap( hDC
,rect
.right
,rect
.bottom
);
640 SelectObject( hdcMem
, hbmMem
);
641 PatBlt( hdcMem
,0,0,rect
.right
,rect
.bottom
,WHITENESS
);
642 /* will be overwritten by DrawText, but just in case */
643 if (hFont
) SelectObject( hdcMem
, hFont
);
644 DrawTextA( hdcMem
, text
, -1, &rc2
, DT_SINGLELINE
);
645 /* After draw: foreground = 0 bits, background = 1 bits */
646 hBr
= SelectObject( hdcMem
, CreatePatternBrush(hbm
) );
648 PatBlt( hdcMem
,0,0,rect
.right
,rect
.bottom
,0xAF0229);
649 /* only keep the foreground bits where pattern is 1 */
650 DeleteObject( SelectObject( hdcMem
,hBr
) );
651 BitBlt(hDC
,rect
.left
,rect
.top
,rect
.right
,rect
.bottom
,hdcMem
,0,0,SRCAND
);
652 /* keep the background of the dest */
654 DeleteObject( hbmMem
);
658 /**********************************************************************
659 * Check Box & Radio Button Functions
662 static void CB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
664 RECT rbox
, rtext
, client
;
667 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
670 * if the button has a bitmap/icon, draw a normal pushbutton
671 * instead of a radion button.
673 if (infoPtr
->hImage
!= 0)
675 BOOL bHighLighted
= ((infoPtr
->state
& BUTTON_HIGHLIGHTED
) ||
676 (infoPtr
->state
& BUTTON_CHECKED
));
678 BUTTON_DrawPushButton(wndPtr
,
686 GetClientRect(wndPtr
->hwndSelf
, &client
);
687 rbox
= rtext
= client
;
689 if (infoPtr
->hFont
) SelectObject( hDC
, infoPtr
->hFont
);
691 /* Something is still not right, checkboxes (and edit controls)
692 * in wsping32 have white backgrounds instead of dark grey.
693 * BUTTON_SEND_CTLCOLOR() is even worse since it returns 0 in this
694 * particular case and the background is not painted at all.
697 hBrush
= GetControlBrush16( wndPtr
->hwndSelf
, hDC
, CTLCOLOR_BTN
);
699 if (wndPtr
->dwStyle
& BS_LEFTTEXT
)
701 /* magic +4 is what CTL3D expects */
703 rtext
.right
-= checkBoxWidth
+ 4;
704 rbox
.left
= rbox
.right
- checkBoxWidth
;
708 rtext
.left
+= checkBoxWidth
+ 4;
709 rbox
.right
= checkBoxWidth
;
712 /* Draw the check-box bitmap */
714 if (wndPtr
->text
) textlen
= strlen( wndPtr
->text
);
715 if (action
== ODA_DRAWENTIRE
|| action
== ODA_SELECT
)
717 if( TWEAK_WineLook
== WIN31_LOOK
)
719 HDC hMemDC
= CreateCompatibleDC( hDC
);
721 delta
= (rbox
.bottom
- rbox
.top
- checkBoxHeight
) / 2;
723 /* Check in case the client area is smaller than the checkbox bitmap */
724 if (delta
< 0) delta
= 0;
726 if (action
== ODA_SELECT
) FillRect( hDC
, &rbox
, hBrush
);
727 else FillRect( hDC
, &client
, hBrush
);
729 if (infoPtr
->state
& BUTTON_HIGHLIGHTED
) x
+= 2 * checkBoxWidth
;
730 if (infoPtr
->state
& (BUTTON_CHECKED
| BUTTON_3STATE
)) x
+= checkBoxWidth
;
731 if (((wndPtr
->dwStyle
& 0x0f) == BS_RADIOBUTTON
) ||
732 ((wndPtr
->dwStyle
& 0x0f) == BS_AUTORADIOBUTTON
)) y
+= checkBoxHeight
;
733 else if (infoPtr
->state
& BUTTON_3STATE
) y
+= 2 * checkBoxHeight
;
735 /* The bitmap for the radio button is not aligned with the
736 * left of the window, it is 1 pixel off. */
737 if (((wndPtr
->dwStyle
& 0x0f) == BS_RADIOBUTTON
) ||
738 ((wndPtr
->dwStyle
& 0x0f) == BS_AUTORADIOBUTTON
))
741 SelectObject( hMemDC
, hbitmapCheckBoxes
);
742 BitBlt( hDC
, rbox
.left
, rbox
.top
+ delta
, checkBoxWidth
,
743 checkBoxHeight
, hMemDC
, x
, y
, SRCCOPY
);
750 if (((wndPtr
->dwStyle
& 0x0f) == BS_RADIOBUTTON
) ||
751 ((wndPtr
->dwStyle
& 0x0f) == BS_AUTORADIOBUTTON
)) state
= DFCS_BUTTONRADIO
;
752 else if (infoPtr
->state
& BUTTON_3STATE
) state
= DFCS_BUTTON3STATE
;
753 else state
= DFCS_BUTTONCHECK
;
755 if (infoPtr
->state
& (BUTTON_CHECKED
| BUTTON_3STATE
)) state
|= DFCS_CHECKED
;
757 if (infoPtr
->state
& BUTTON_HIGHLIGHTED
) state
|= DFCS_PUSHED
;
759 if (wndPtr
->dwStyle
& WS_DISABLED
) state
|= DFCS_INACTIVE
;
761 DrawFrameControl( hDC
, &rbox
, DFC_BUTTON
, state
);
765 if( textlen
&& action
!= ODA_SELECT
)
767 if (wndPtr
->dwStyle
& WS_DISABLED
&&
768 GetSysColor(COLOR_GRAYTEXT
)==GetBkColor(hDC
)) {
769 /* don't write gray text on gray background */
770 PaintGrayOnGray( hDC
, infoPtr
->hFont
, &rtext
, wndPtr
->text
,
773 if (wndPtr
->dwStyle
& WS_DISABLED
)
774 SetTextColor( hDC
, GetSysColor(COLOR_GRAYTEXT
) );
775 DrawTextA( hDC
, wndPtr
->text
, textlen
, &rtext
,
776 DT_SINGLELINE
| DT_VCENTER
);
781 if ((action
== ODA_FOCUS
) ||
782 ((action
== ODA_DRAWENTIRE
) && (infoPtr
->state
& BUTTON_HASFOCUS
)))
784 /* again, this is what CTL3D expects */
788 DrawTextA( hDC
, wndPtr
->text
, textlen
, &rbox
,
789 DT_SINGLELINE
| DT_CALCRECT
);
790 textlen
= rbox
.bottom
- rbox
.top
;
791 delta
= ((rtext
.bottom
- rtext
.top
) - textlen
)/2;
792 rbox
.bottom
= (rbox
.top
= rtext
.top
+ delta
- 1) + textlen
+ 2;
793 textlen
= rbox
.right
- rbox
.left
;
794 rbox
.right
= (rbox
.left
+= --rtext
.left
) + textlen
+ 2;
795 IntersectRect(&rbox
, &rbox
, &rtext
);
796 DrawFocusRect( hDC
, &rbox
);
801 /**********************************************************************
802 * BUTTON_CheckAutoRadioButton
804 * wndPtr is checked, uncheck every other auto radio button in group
806 static void BUTTON_CheckAutoRadioButton( WND
*wndPtr
)
808 HWND parent
, sibling
, start
;
809 if (!(wndPtr
->dwStyle
& WS_CHILD
)) return;
810 parent
= wndPtr
->parent
->hwndSelf
;
811 /* assure that starting control is not disabled or invisible */
812 start
= sibling
= GetNextDlgGroupItem( parent
, wndPtr
->hwndSelf
, TRUE
);
817 tmpWnd
= WIN_FindWndPtr(sibling
);
818 if ((wndPtr
->hwndSelf
!= sibling
) &&
819 ((tmpWnd
->dwStyle
& 0x0f) == BS_AUTORADIOBUTTON
))
820 SendMessageA( sibling
, BM_SETCHECK
, BUTTON_UNCHECKED
, 0 );
821 sibling
= GetNextDlgGroupItem( parent
, sibling
, FALSE
);
822 WIN_ReleaseWndPtr(tmpWnd
);
823 } while (sibling
!= start
);
827 /**********************************************************************
828 * Group Box Functions
831 static void GB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
834 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
836 if (action
!= ODA_DRAWENTIRE
) return;
838 BUTTON_SEND_CTLCOLOR( wndPtr
, hDC
);
840 GetClientRect( wndPtr
->hwndSelf
, &rc
);
841 if (TWEAK_WineLook
== WIN31_LOOK
) {
842 HPEN hPrevPen
= SelectObject( hDC
,
843 GetSysColorPen(COLOR_WINDOWFRAME
));
844 HBRUSH hPrevBrush
= SelectObject( hDC
,
845 GetStockObject(NULL_BRUSH
) );
847 Rectangle( hDC
, rc
.left
, rc
.top
+ 2, rc
.right
- 1, rc
.bottom
- 1 );
848 SelectObject( hDC
, hPrevBrush
);
849 SelectObject( hDC
, hPrevPen
);
855 SelectObject (hDC
, infoPtr
->hFont
);
856 GetTextMetricsA (hDC
, &tm
);
857 rcFrame
.top
+= (tm
.tmHeight
/ 2) - 1;
858 DrawEdge (hDC
, &rcFrame
, EDGE_ETCHED
, BF_RECT
);
863 if (infoPtr
->hFont
) SelectObject( hDC
, infoPtr
->hFont
);
864 if (wndPtr
->dwStyle
& WS_DISABLED
)
865 SetTextColor( hDC
, GetSysColor(COLOR_GRAYTEXT
) );
867 DrawTextA( hDC
, wndPtr
->text
, -1, &rc
, DT_SINGLELINE
| DT_NOCLIP
);
872 /**********************************************************************
873 * User Button Functions
876 static void UB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
880 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
882 if (action
== ODA_SELECT
) return;
884 GetClientRect( wndPtr
->hwndSelf
, &rc
);
886 if (infoPtr
->hFont
) SelectObject( hDC
, infoPtr
->hFont
);
887 hBrush
= GetControlBrush16( wndPtr
->hwndSelf
, hDC
, CTLCOLOR_BTN
);
889 FillRect( hDC
, &rc
, hBrush
);
890 if ((action
== ODA_FOCUS
) ||
891 ((action
== ODA_DRAWENTIRE
) && (infoPtr
->state
& BUTTON_HASFOCUS
)))
892 DrawFocusRect( hDC
, &rc
);
896 /**********************************************************************
897 * Ownerdrawn Button Functions
900 static void OB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
902 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
905 dis
.CtlType
= ODT_BUTTON
;
906 dis
.CtlID
= wndPtr
->wIDmenu
;
908 dis
.itemAction
= action
;
909 dis
.itemState
= ((infoPtr
->state
& BUTTON_HASFOCUS
) ? ODS_FOCUS
: 0) |
910 ((infoPtr
->state
& BUTTON_HIGHLIGHTED
) ? ODS_SELECTED
: 0) |
911 ((wndPtr
->dwStyle
& WS_DISABLED
) ? ODS_DISABLED
: 0);
912 dis
.hwndItem
= wndPtr
->hwndSelf
;
915 GetClientRect( wndPtr
->hwndSelf
, &dis
.rcItem
);
917 SetBkColor( hDC
, GetSysColor( COLOR_BTNFACE
) );
919 SendMessageA( GetParent(wndPtr
->hwndSelf
), WM_DRAWITEM
,
920 wndPtr
->wIDmenu
, (LPARAM
)&dis
);