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_RADIOBUTTON
|| 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 if (style
== BS_AUTORADIOBUTTON
)
245 SendMessageA( hWnd
, BM_SETCHECK
, BUTTON_CHECKED
, 0 );
246 SendMessageA( GetParent(hWnd
), WM_COMMAND
,
247 MAKEWPARAM( wndPtr
->wIDmenu
, BN_CLICKED
), hWnd
);
249 infoPtr
->state
|= BUTTON_HASFOCUS
;
250 PAINT_BUTTON( wndPtr
, style
, ODA_FOCUS
);
254 infoPtr
->state
&= ~BUTTON_HASFOCUS
;
255 PAINT_BUTTON( wndPtr
, style
, ODA_FOCUS
);
256 InvalidateRect( hWnd
, NULL
, TRUE
);
259 case WM_SYSCOLORCHANGE
:
260 InvalidateRect( hWnd
, NULL
, FALSE
);
265 if ((wParam
& 0x0f) >= MAX_BTN_TYPE
) break;
266 wndPtr
->dwStyle
= (wndPtr
->dwStyle
& 0xfffffff0)
267 | (wParam
& 0x0000000f);
268 style
= wndPtr
->dwStyle
& 0x0000000f;
269 PAINT_BUTTON( wndPtr
, style
, ODA_DRAWENTIRE
);
273 SendMessageA( hWnd
, WM_LBUTTONDOWN
, 0, 0 );
274 SendMessageA( hWnd
, WM_LBUTTONUP
, 0, 0 );
278 oldHbitmap
= infoPtr
->hImage
;
279 if ((wndPtr
->dwStyle
& BS_BITMAP
) || (wndPtr
->dwStyle
& BS_ICON
))
281 infoPtr
->hImage
= (HANDLE
) lParam
;
282 InvalidateRect( hWnd
, NULL
, FALSE
);
287 if (wParam
== IMAGE_BITMAP
)
288 return (HBITMAP
)infoPtr
->hImage
;
289 else if (wParam
== IMAGE_ICON
)
290 return (HICON
)infoPtr
->hImage
;
296 return infoPtr
->state
& 3;
300 if (wParam
> maxCheckState
[style
]) wParam
= maxCheckState
[style
];
301 if ((infoPtr
->state
& 3) != wParam
)
303 if ((style
== BS_RADIOBUTTON
) || (style
== BS_AUTORADIOBUTTON
))
306 wndPtr
->dwStyle
|= WS_TABSTOP
;
308 wndPtr
->dwStyle
&= ~WS_TABSTOP
;
310 infoPtr
->state
= (infoPtr
->state
& ~3) | wParam
;
311 PAINT_BUTTON( wndPtr
, style
, ODA_SELECT
);
313 if ((style
== BS_AUTORADIOBUTTON
) && (wParam
== BUTTON_CHECKED
))
314 BUTTON_CheckAutoRadioButton( wndPtr
);
319 return infoPtr
->state
;
325 if (infoPtr
->state
& BUTTON_HIGHLIGHTED
) break;
326 infoPtr
->state
|= BUTTON_HIGHLIGHTED
;
330 if (!(infoPtr
->state
& BUTTON_HIGHLIGHTED
)) break;
331 infoPtr
->state
&= ~BUTTON_HIGHLIGHTED
;
333 PAINT_BUTTON( wndPtr
, style
, ODA_SELECT
);
337 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
342 /***********************************************************************
344 * The button window procedure. This is just a wrapper which locks
345 * the passed HWND and calls the real window procedure (with a WND*
346 * pointer pointing to the locked windowstructure).
348 LRESULT WINAPI
ButtonWndProc( HWND hWnd
, UINT uMsg
,
349 WPARAM wParam
, LPARAM lParam
)
352 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
354 res
= ButtonWndProc_locked(wndPtr
,uMsg
,wParam
,lParam
);
356 WIN_ReleaseWndPtr(wndPtr
);
360 /**********************************************************************
361 * Push Button Functions
363 static void PB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
365 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
366 BOOL bHighLighted
= (infoPtr
->state
& BUTTON_HIGHLIGHTED
);
369 * Delegate this to the more generic pushbutton painting
372 BUTTON_DrawPushButton(wndPtr
,
378 /**********************************************************************
379 * This method will actually do the drawing of the pushbutton
380 * depending on it's state and the pushedState parameter.
382 static void BUTTON_DrawPushButton(
391 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
392 int xBorderOffset
, yBorderOffset
;
393 xBorderOffset
= yBorderOffset
= 0;
395 GetClientRect( wndPtr
->hwndSelf
, &rc
);
397 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
398 if (infoPtr
->hFont
) SelectObject( hDC
, infoPtr
->hFont
);
399 BUTTON_SEND_CTLCOLOR( wndPtr
, hDC
);
400 hOldPen
= (HPEN
)SelectObject(hDC
, GetSysColorPen(COLOR_WINDOWFRAME
));
401 hOldBrush
=(HBRUSH
)SelectObject(hDC
,GetSysColorBrush(COLOR_BTNFACE
));
402 SetBkMode(hDC
, TRANSPARENT
);
404 if ( TWEAK_WineLook
== WIN31_LOOK
)
406 Rectangle(hDC
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
408 SetPixel( hDC
, rc
.left
, rc
.top
, GetSysColor(COLOR_WINDOW
) );
409 SetPixel( hDC
, rc
.left
, rc
.bottom
-1, GetSysColor(COLOR_WINDOW
) );
410 SetPixel( hDC
, rc
.right
-1, rc
.top
, GetSysColor(COLOR_WINDOW
) );
411 SetPixel( hDC
, rc
.right
-1, rc
.bottom
-1, GetSysColor(COLOR_WINDOW
));
412 InflateRect( &rc
, -1, -1 );
415 if ((wndPtr
->dwStyle
& 0x000f) == BS_DEFPUSHBUTTON
)
417 Rectangle(hDC
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
418 InflateRect( &rc
, -1, -1 );
421 if (TWEAK_WineLook
== WIN31_LOOK
)
425 /* draw button shadow: */
426 SelectObject(hDC
, GetSysColorBrush(COLOR_BTNSHADOW
));
427 PatBlt(hDC
, rc
.left
, rc
.top
, 1, rc
.bottom
-rc
.top
, PATCOPY
);
428 PatBlt(hDC
, rc
.left
, rc
.top
, rc
.right
-rc
.left
, 1, PATCOPY
);
429 rc
.left
+= 2; /* To position the text down and right */
432 rc
.right
++, rc
.bottom
++;
433 DrawEdge( hDC
, &rc
, EDGE_RAISED
, BF_RECT
);
435 /* To place de bitmap correctly */
436 xBorderOffset
+= GetSystemMetrics(SM_CXEDGE
);
437 yBorderOffset
+= GetSystemMetrics(SM_CYEDGE
);
439 rc
.right
--, rc
.bottom
--;
444 UINT uState
= DFCS_BUTTONPUSH
;
448 if ( (wndPtr
->dwStyle
& 0x000f) == BS_DEFPUSHBUTTON
)
451 uState
|= DFCS_PUSHED
;
454 DrawFrameControl( hDC
, &rc
, DFC_BUTTON
, uState
);
455 InflateRect( &rc
, -2, -2 );
461 rc
.left
+= 2; /* To position the text down and right */
466 /* draw button label, if any:
468 * In win9x we don't show text if there is a bitmap or icon.
469 * I don't know about win31 so I leave it as it was for win31.
470 * Dennis Björklund 12 Jul, 99
472 if ( wndPtr
->text
&& wndPtr
->text
[0]
473 && (TWEAK_WineLook
== WIN31_LOOK
|| !(wndPtr
->dwStyle
& (BS_ICON
|BS_BITMAP
))) )
476 GetObjectA( GetSysColorBrush(COLOR_BTNFACE
), sizeof(lb
), &lb
);
477 if (wndPtr
->dwStyle
& WS_DISABLED
&&
478 GetSysColor(COLOR_GRAYTEXT
)==lb
.lbColor
)
479 /* don't write gray text on gray background */
480 PaintGrayOnGray( hDC
,infoPtr
->hFont
,&rc
,wndPtr
->text
,
481 DT_CENTER
| DT_VCENTER
);
484 SetTextColor( hDC
, (wndPtr
->dwStyle
& WS_DISABLED
) ?
485 GetSysColor(COLOR_GRAYTEXT
) :
486 GetSysColor(COLOR_BTNTEXT
) );
487 DrawTextA( hDC
, wndPtr
->text
, -1, &rc
,
488 DT_SINGLELINE
| DT_CENTER
| DT_VCENTER
);
489 /* do we have the focus?
490 * Win9x draws focus last with a size prop. to the button
492 if (TWEAK_WineLook
== WIN31_LOOK
493 && infoPtr
->state
& BUTTON_HASFOCUS
)
495 RECT r
= { 0, 0, 0, 0 };
498 DrawTextA( hDC
, wndPtr
->text
, -1, &r
,
499 DT_SINGLELINE
| DT_CALCRECT
);
500 xdelta
= ((rc
.right
- rc
.left
) - (r
.right
- r
.left
) - 1) / 2;
501 ydelta
= ((rc
.bottom
- rc
.top
) - (r
.bottom
- r
.top
) - 1) / 2;
502 if (xdelta
< 0) xdelta
= 0;
503 if (ydelta
< 0) ydelta
= 0;
504 InflateRect( &rc
, -xdelta
, -ydelta
);
505 DrawFocusRect( hDC
, &rc
);
509 if ( ((wndPtr
->dwStyle
& BS_ICON
) || (wndPtr
->dwStyle
& BS_BITMAP
) ) &&
510 (infoPtr
->hImage
!= 0) )
512 int yOffset
, xOffset
;
513 int imageWidth
, imageHeight
;
516 * We extract the size of the image from the handle.
518 if (wndPtr
->dwStyle
& BS_ICON
)
523 GetIconInfo((HICON
)infoPtr
->hImage
, &iconInfo
);
524 GetObjectA (iconInfo
.hbmColor
, sizeof(BITMAP
), &bm
);
526 imageWidth
= bm
.bmWidth
;
527 imageHeight
= bm
.bmHeight
;
529 DeleteObject(iconInfo
.hbmColor
);
530 DeleteObject(iconInfo
.hbmMask
);
537 GetObjectA (infoPtr
->hImage
, sizeof(BITMAP
), &bm
);
539 imageWidth
= bm
.bmWidth
;
540 imageHeight
= bm
.bmHeight
;
543 /* Center the bitmap */
544 xOffset
= (((rc
.right
- rc
.left
) - 2*xBorderOffset
) - imageWidth
) / 2;
545 yOffset
= (((rc
.bottom
- rc
.top
) - 2*yBorderOffset
) - imageHeight
) / 2;
547 /* If the image is too big for the button then create a region*/
548 if(xOffset
< 0 || yOffset
< 0)
551 hBitmapRgn
= CreateRectRgn(
552 rc
.left
+ xBorderOffset
, rc
.top
+yBorderOffset
,
553 rc
.right
- xBorderOffset
, rc
.bottom
- yBorderOffset
);
554 SelectClipRgn(hDC
, hBitmapRgn
);
555 DeleteObject(hBitmapRgn
);
558 /* Let minimum 1 space from border */
559 xOffset
++, yOffset
++;
562 * Draw the image now.
564 if (wndPtr
->dwStyle
& BS_ICON
)
567 rc
.left
+ xOffset
, rc
.top
+ yOffset
,
568 (HICON
)infoPtr
->hImage
);
574 hdcMem
= CreateCompatibleDC (hDC
);
575 SelectObject (hdcMem
, (HBITMAP
)infoPtr
->hImage
);
579 imageWidth
, imageHeight
,
580 hdcMem
, 0, 0, SRCCOPY
);
585 if(xOffset
< 0 || yOffset
< 0)
587 SelectClipRgn(hDC
, 0);
591 if (TWEAK_WineLook
!= WIN31_LOOK
592 && infoPtr
->state
& BUTTON_HASFOCUS
)
594 InflateRect( &focus_rect
, -1, -1 );
595 DrawFocusRect( hDC
, &focus_rect
);
599 SelectObject( hDC
, hOldPen
);
600 SelectObject( hDC
, hOldBrush
);
604 /**********************************************************************
605 * PB_Paint & CB_Paint sub function [internal]
606 * Paint text using a raster brush to avoid gray text on gray
607 * background. 'format' can be a combination of DT_CENTER and
608 * DT_VCENTER to use this function in both PB_PAINT and
609 * CB_PAINT. - Dirk Thierbach
611 * FIXME: This and TEXT_GrayString should be eventually combined,
612 * so calling one common function from PB_Paint, CB_Paint and
613 * TEXT_GrayString will be enough. Also note that this
614 * function ignores the CACHE_GetPattern funcs.
617 void PaintGrayOnGray(HDC hDC
,HFONT hFont
,RECT
*rc
,char *text
,
620 /* This is the standard gray on gray pattern:
621 static const WORD Pattern[] = {0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55};
623 /* This pattern gives better readability with X Fonts.
624 FIXME: Maybe the user should be allowed to decide which he wants. */
625 static const WORD Pattern
[] = {0x55,0xFF,0xAA,0xFF,0x55,0xFF,0xAA,0xFF};
627 HBITMAP hbm
= CreateBitmap( 8, 8, 1, 1, Pattern
);
628 HDC hdcMem
= CreateCompatibleDC(hDC
);
634 DrawTextA( hDC
, text
, -1, &rect
, DT_SINGLELINE
| DT_CALCRECT
);
635 /* now text width and height are in rect.right and rect.bottom */
637 rect
.left
= rect
.top
= 0; /* drawing pos in hdcMem */
638 if (format
& DT_CENTER
) rect
.left
=(rc
->right
-rect
.right
)/2;
639 if (format
& DT_VCENTER
) rect
.top
=(rc
->bottom
-rect
.bottom
)/2;
640 hbmMem
= CreateCompatibleBitmap( hDC
,rect
.right
,rect
.bottom
);
641 SelectObject( hdcMem
, hbmMem
);
642 PatBlt( hdcMem
,0,0,rect
.right
,rect
.bottom
,WHITENESS
);
643 /* will be overwritten by DrawText, but just in case */
644 if (hFont
) SelectObject( hdcMem
, hFont
);
645 DrawTextA( hdcMem
, text
, -1, &rc2
, DT_SINGLELINE
);
646 /* After draw: foreground = 0 bits, background = 1 bits */
647 hBr
= SelectObject( hdcMem
, CreatePatternBrush(hbm
) );
649 PatBlt( hdcMem
,0,0,rect
.right
,rect
.bottom
,0xAF0229);
650 /* only keep the foreground bits where pattern is 1 */
651 DeleteObject( SelectObject( hdcMem
,hBr
) );
652 BitBlt(hDC
,rect
.left
,rect
.top
,rect
.right
,rect
.bottom
,hdcMem
,0,0,SRCAND
);
653 /* keep the background of the dest */
655 DeleteObject( hbmMem
);
659 /**********************************************************************
660 * Check Box & Radio Button Functions
663 static void CB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
665 RECT rbox
, rtext
, client
;
668 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
671 * if the button has a bitmap/icon, draw a normal pushbutton
672 * instead of a radion button.
674 if (infoPtr
->hImage
!= 0)
676 BOOL bHighLighted
= ((infoPtr
->state
& BUTTON_HIGHLIGHTED
) ||
677 (infoPtr
->state
& BUTTON_CHECKED
));
679 BUTTON_DrawPushButton(wndPtr
,
687 GetClientRect(wndPtr
->hwndSelf
, &client
);
688 rbox
= rtext
= client
;
690 if (infoPtr
->hFont
) SelectObject( hDC
, infoPtr
->hFont
);
692 /* Something is still not right, checkboxes (and edit controls)
693 * in wsping32 have white backgrounds instead of dark grey.
694 * BUTTON_SEND_CTLCOLOR() is even worse since it returns 0 in this
695 * particular case and the background is not painted at all.
698 hBrush
= GetControlBrush16( wndPtr
->hwndSelf
, hDC
, CTLCOLOR_BTN
);
700 if (wndPtr
->dwStyle
& BS_LEFTTEXT
)
702 /* magic +4 is what CTL3D expects */
704 rtext
.right
-= checkBoxWidth
+ 4;
705 rbox
.left
= rbox
.right
- checkBoxWidth
;
709 rtext
.left
+= checkBoxWidth
+ 4;
710 rbox
.right
= checkBoxWidth
;
713 /* Draw the check-box bitmap */
715 if (wndPtr
->text
) textlen
= strlen( wndPtr
->text
);
716 if (action
== ODA_DRAWENTIRE
|| action
== ODA_SELECT
)
718 if( TWEAK_WineLook
== WIN31_LOOK
)
720 HDC hMemDC
= CreateCompatibleDC( hDC
);
722 delta
= (rbox
.bottom
- rbox
.top
- checkBoxHeight
) / 2;
724 /* Check in case the client area is smaller than the checkbox bitmap */
725 if (delta
< 0) delta
= 0;
727 if (action
== ODA_SELECT
) FillRect( hDC
, &rbox
, hBrush
);
728 else FillRect( hDC
, &client
, hBrush
);
730 if (infoPtr
->state
& BUTTON_HIGHLIGHTED
) x
+= 2 * checkBoxWidth
;
731 if (infoPtr
->state
& (BUTTON_CHECKED
| BUTTON_3STATE
)) x
+= checkBoxWidth
;
732 if (((wndPtr
->dwStyle
& 0x0f) == BS_RADIOBUTTON
) ||
733 ((wndPtr
->dwStyle
& 0x0f) == BS_AUTORADIOBUTTON
)) y
+= checkBoxHeight
;
734 else if (infoPtr
->state
& BUTTON_3STATE
) y
+= 2 * checkBoxHeight
;
736 /* The bitmap for the radio button is not aligned with the
737 * left of the window, it is 1 pixel off. */
738 if (((wndPtr
->dwStyle
& 0x0f) == BS_RADIOBUTTON
) ||
739 ((wndPtr
->dwStyle
& 0x0f) == BS_AUTORADIOBUTTON
))
742 SelectObject( hMemDC
, hbitmapCheckBoxes
);
743 BitBlt( hDC
, rbox
.left
, rbox
.top
+ delta
, checkBoxWidth
,
744 checkBoxHeight
, hMemDC
, x
, y
, SRCCOPY
);
751 if (((wndPtr
->dwStyle
& 0x0f) == BS_RADIOBUTTON
) ||
752 ((wndPtr
->dwStyle
& 0x0f) == BS_AUTORADIOBUTTON
)) state
= DFCS_BUTTONRADIO
;
753 else if (infoPtr
->state
& BUTTON_3STATE
) state
= DFCS_BUTTON3STATE
;
754 else state
= DFCS_BUTTONCHECK
;
756 if (infoPtr
->state
& (BUTTON_CHECKED
| BUTTON_3STATE
)) state
|= DFCS_CHECKED
;
758 if (infoPtr
->state
& BUTTON_HIGHLIGHTED
) state
|= DFCS_PUSHED
;
760 if (wndPtr
->dwStyle
& WS_DISABLED
) state
|= DFCS_INACTIVE
;
762 /* rbox must have the correct height */
763 delta
= rbox
.bottom
- rbox
.top
- checkBoxHeight
;
766 int ofs
= (abs(delta
) / 2);
767 rbox
.bottom
-= ofs
+ 1;
768 rbox
.top
= rbox
.bottom
- checkBoxHeight
;
772 int ofs
= (abs(delta
) / 2);
774 rbox
.bottom
= rbox
.top
+ checkBoxHeight
;
777 DrawFrameControl( hDC
, &rbox
, DFC_BUTTON
, state
);
780 if( textlen
&& action
!= ODA_SELECT
)
782 if (wndPtr
->dwStyle
& WS_DISABLED
&&
783 GetSysColor(COLOR_GRAYTEXT
)==GetBkColor(hDC
)) {
784 /* don't write gray text on gray background */
785 PaintGrayOnGray( hDC
, infoPtr
->hFont
, &rtext
, wndPtr
->text
,
788 if (wndPtr
->dwStyle
& WS_DISABLED
)
789 SetTextColor( hDC
, GetSysColor(COLOR_GRAYTEXT
) );
790 DrawTextA( hDC
, wndPtr
->text
, textlen
, &rtext
,
791 DT_SINGLELINE
| DT_VCENTER
);
796 if ((action
== ODA_FOCUS
) ||
797 ((action
== ODA_DRAWENTIRE
) && (infoPtr
->state
& BUTTON_HASFOCUS
)))
799 /* again, this is what CTL3D expects */
803 DrawTextA( hDC
, wndPtr
->text
, textlen
, &rbox
,
804 DT_SINGLELINE
| DT_CALCRECT
);
805 textlen
= rbox
.bottom
- rbox
.top
;
806 delta
= ((rtext
.bottom
- rtext
.top
) - textlen
)/2;
807 rbox
.bottom
= (rbox
.top
= rtext
.top
+ delta
- 1) + textlen
+ 2;
808 textlen
= rbox
.right
- rbox
.left
;
809 rbox
.right
= (rbox
.left
+= --rtext
.left
) + textlen
+ 2;
810 IntersectRect(&rbox
, &rbox
, &rtext
);
811 DrawFocusRect( hDC
, &rbox
);
816 /**********************************************************************
817 * BUTTON_CheckAutoRadioButton
819 * wndPtr is checked, uncheck every other auto radio button in group
821 static void BUTTON_CheckAutoRadioButton( WND
*wndPtr
)
823 HWND parent
, sibling
, start
;
824 if (!(wndPtr
->dwStyle
& WS_CHILD
)) return;
825 parent
= wndPtr
->parent
->hwndSelf
;
826 /* assure that starting control is not disabled or invisible */
827 start
= sibling
= GetNextDlgGroupItem( parent
, wndPtr
->hwndSelf
, TRUE
);
832 tmpWnd
= WIN_FindWndPtr(sibling
);
833 if ((wndPtr
->hwndSelf
!= sibling
) &&
834 ((tmpWnd
->dwStyle
& 0x0f) == BS_AUTORADIOBUTTON
))
835 SendMessageA( sibling
, BM_SETCHECK
, BUTTON_UNCHECKED
, 0 );
836 sibling
= GetNextDlgGroupItem( parent
, sibling
, FALSE
);
837 WIN_ReleaseWndPtr(tmpWnd
);
838 } while (sibling
!= start
);
842 /**********************************************************************
843 * Group Box Functions
846 static void GB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
849 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
851 if (action
!= ODA_DRAWENTIRE
) return;
853 BUTTON_SEND_CTLCOLOR( wndPtr
, hDC
);
855 GetClientRect( wndPtr
->hwndSelf
, &rc
);
856 if (TWEAK_WineLook
== WIN31_LOOK
) {
857 HPEN hPrevPen
= SelectObject( hDC
,
858 GetSysColorPen(COLOR_WINDOWFRAME
));
859 HBRUSH hPrevBrush
= SelectObject( hDC
,
860 GetStockObject(NULL_BRUSH
) );
862 Rectangle( hDC
, rc
.left
, rc
.top
+ 2, rc
.right
- 1, rc
.bottom
- 1 );
863 SelectObject( hDC
, hPrevBrush
);
864 SelectObject( hDC
, hPrevPen
);
870 SelectObject (hDC
, infoPtr
->hFont
);
871 GetTextMetricsA (hDC
, &tm
);
872 rcFrame
.top
+= (tm
.tmHeight
/ 2) - 1;
873 DrawEdge (hDC
, &rcFrame
, EDGE_ETCHED
, BF_RECT
);
878 if (infoPtr
->hFont
) SelectObject( hDC
, infoPtr
->hFont
);
879 if (wndPtr
->dwStyle
& WS_DISABLED
)
880 SetTextColor( hDC
, GetSysColor(COLOR_GRAYTEXT
) );
882 DrawTextA( hDC
, wndPtr
->text
, -1, &rc
, DT_SINGLELINE
| DT_NOCLIP
);
887 /**********************************************************************
888 * User Button Functions
891 static void UB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
895 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
897 if (action
== ODA_SELECT
) return;
899 GetClientRect( wndPtr
->hwndSelf
, &rc
);
901 if (infoPtr
->hFont
) SelectObject( hDC
, infoPtr
->hFont
);
902 hBrush
= GetControlBrush16( wndPtr
->hwndSelf
, hDC
, CTLCOLOR_BTN
);
904 FillRect( hDC
, &rc
, hBrush
);
905 if ((action
== ODA_FOCUS
) ||
906 ((action
== ODA_DRAWENTIRE
) && (infoPtr
->state
& BUTTON_HASFOCUS
)))
907 DrawFocusRect( hDC
, &rc
);
911 /**********************************************************************
912 * Ownerdrawn Button Functions
915 static void OB_Paint( WND
*wndPtr
, HDC hDC
, WORD action
)
917 BUTTONINFO
*infoPtr
= (BUTTONINFO
*)wndPtr
->wExtra
;
920 dis
.CtlType
= ODT_BUTTON
;
921 dis
.CtlID
= wndPtr
->wIDmenu
;
923 dis
.itemAction
= action
;
924 dis
.itemState
= ((infoPtr
->state
& BUTTON_HASFOCUS
) ? ODS_FOCUS
: 0) |
925 ((infoPtr
->state
& BUTTON_HIGHLIGHTED
) ? ODS_SELECTED
: 0) |
926 ((wndPtr
->dwStyle
& WS_DISABLED
) ? ODS_DISABLED
: 0);
927 dis
.hwndItem
= wndPtr
->hwndSelf
;
930 GetClientRect( wndPtr
->hwndSelf
, &dis
.rcItem
);
932 SetBkColor( hDC
, GetSysColor( COLOR_BTNFACE
) );
934 SendMessageA( GetParent(wndPtr
->hwndSelf
), WM_DRAWITEM
,
935 wndPtr
->wIDmenu
, (LPARAM
)&dis
);