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
9 #include <stdlib.h> /* for abs() */
15 #include "wine/winuser16.h"
18 static void PB_Paint( WND *wndPtr, HDC hDC, WORD action );
19 static void CB_Paint( WND *wndPtr, HDC hDC, WORD action );
20 static void GB_Paint( WND *wndPtr, HDC hDC, WORD action );
21 static void UB_Paint( WND *wndPtr, HDC hDC, WORD action );
22 static void OB_Paint( WND *wndPtr, HDC hDC, WORD action );
23 static void BUTTON_CheckAutoRadioButton( WND *wndPtr );
24 static void BUTTON_DrawPushButton( WND *wndPtr, HDC hDC, WORD action, BOOL pushedState);
26 #define MAX_BTN_TYPE 12
28 static const WORD maxCheckState[MAX_BTN_TYPE] =
30 BUTTON_UNCHECKED, /* BS_PUSHBUTTON */
31 BUTTON_UNCHECKED, /* BS_DEFPUSHBUTTON */
32 BUTTON_CHECKED, /* BS_CHECKBOX */
33 BUTTON_CHECKED, /* BS_AUTOCHECKBOX */
34 BUTTON_CHECKED, /* BS_RADIOBUTTON */
35 BUTTON_3STATE, /* BS_3STATE */
36 BUTTON_3STATE, /* BS_AUTO3STATE */
37 BUTTON_UNCHECKED, /* BS_GROUPBOX */
38 BUTTON_UNCHECKED, /* BS_USERBUTTON */
39 BUTTON_CHECKED, /* BS_AUTORADIOBUTTON */
40 BUTTON_UNCHECKED, /* Not defined */
41 BUTTON_UNCHECKED /* BS_OWNERDRAW */
44 typedef void (*pfPaint)( WND *wndPtr, HDC hdc, WORD action );
46 static const pfPaint btnPaintFunc[MAX_BTN_TYPE] =
48 PB_Paint, /* BS_PUSHBUTTON */
49 PB_Paint, /* BS_DEFPUSHBUTTON */
50 CB_Paint, /* BS_CHECKBOX */
51 CB_Paint, /* BS_AUTOCHECKBOX */
52 CB_Paint, /* BS_RADIOBUTTON */
53 CB_Paint, /* BS_3STATE */
54 CB_Paint, /* BS_AUTO3STATE */
55 GB_Paint, /* BS_GROUPBOX */
56 UB_Paint, /* BS_USERBUTTON */
57 CB_Paint, /* BS_AUTORADIOBUTTON */
58 NULL, /* Not defined */
59 OB_Paint /* BS_OWNERDRAW */
62 #define PAINT_BUTTON(wndPtr,style,action) \
63 if (btnPaintFunc[style]) { \
64 HDC hdc = GetDC( (wndPtr)->hwndSelf ); \
65 (btnPaintFunc[style])(wndPtr,hdc,action); \
66 ReleaseDC( (wndPtr)->hwndSelf, hdc ); }
68 #define BUTTON_SEND_CTLCOLOR(wndPtr,hdc) \
69 SendMessageA( GetParent((wndPtr)->hwndSelf), WM_CTLCOLORBTN, \
70 (hdc), (wndPtr)->hwndSelf )
72 static HBITMAP hbitmapCheckBoxes = 0;
73 static WORD checkBoxWidth = 0, checkBoxHeight = 0;
76 /***********************************************************************
77 * ButtonWndProc_locked
79 * Called with window lock held.
81 static inline LRESULT WINAPI ButtonWndProc_locked(WND* wndPtr, UINT uMsg,
82 WPARAM wParam, LPARAM lParam )
85 HWND hWnd = wndPtr->hwndSelf;
87 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
88 LONG style = wndPtr->dwStyle & 0x0f;
91 pt.x = LOWORD(lParam);
92 pt.y = HIWORD(lParam);
99 case BS_PUSHBUTTON: return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON;
100 case BS_DEFPUSHBUTTON: return DLGC_BUTTON | DLGC_DEFPUSHBUTTON;
102 case BS_AUTORADIOBUTTON: return DLGC_BUTTON | DLGC_RADIOBUTTON;
103 default: return DLGC_BUTTON;
107 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
111 if (!hbitmapCheckBoxes)
114 hbitmapCheckBoxes = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_CHECKBOXES));
115 GetObjectA( hbitmapCheckBoxes, sizeof(bmp), &bmp );
116 checkBoxWidth = bmp.bmWidth / 4;
117 checkBoxHeight = bmp.bmHeight / 3;
119 if (style < 0L || style >= MAX_BTN_TYPE)
120 return -1; /* abort */
121 infoPtr->state = BUTTON_UNCHECKED;
130 if (btnPaintFunc[style])
133 HDC hdc = wParam ? (HDC)wParam : BeginPaint( hWnd, &ps );
134 int nOldMode = SetBkMode( hdc, OPAQUE );
135 (btnPaintFunc[style])( wndPtr, hdc, ODA_DRAWENTIRE );
136 SetBkMode(hdc, nOldMode); /* reset painting mode */
137 if( !wParam ) EndPaint( hWnd, &ps );
142 if (wParam == VK_SPACE)
144 SendMessageA( hWnd, BM_SETSTATE, TRUE, 0 );
145 infoPtr->state |= BUTTON_BTNPRESSED;
149 case WM_LBUTTONDBLCLK:
150 if(wndPtr->dwStyle & BS_NOTIFY ||
151 style==BS_RADIOBUTTON ||
152 style==BS_USERBUTTON ||
153 style==BS_OWNERDRAW) {
154 SendMessageA( GetParent(hWnd), WM_COMMAND,
155 MAKEWPARAM( wndPtr->wIDmenu, BN_DOUBLECLICKED ), hWnd);
162 SendMessageA( hWnd, BM_SETSTATE, TRUE, 0 );
163 infoPtr->state |= BUTTON_BTNPRESSED;
167 if (wParam != VK_SPACE)
171 if (!(infoPtr->state & BUTTON_BTNPRESSED)) break;
172 infoPtr->state &= BUTTON_NSTATES;
173 if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) {
177 SendMessageA( hWnd, BM_SETSTATE, FALSE, 0 );
179 GetClientRect( hWnd, &rect );
180 if (uMsg == WM_KEYUP || PtInRect( &rect, pt ))
184 case BS_AUTOCHECKBOX:
185 SendMessageA( hWnd, BM_SETCHECK,
186 !(infoPtr->state & BUTTON_CHECKED), 0 );
188 case BS_AUTORADIOBUTTON:
189 SendMessageA( hWnd, BM_SETCHECK, TRUE, 0 );
192 SendMessageA( hWnd, BM_SETCHECK,
193 (infoPtr->state & BUTTON_3STATE) ? 0 :
194 ((infoPtr->state & 3) + 1), 0 );
197 SendMessageA( GetParent(hWnd), WM_COMMAND,
198 MAKEWPARAM( wndPtr->wIDmenu, BN_CLICKED ), hWnd);
202 case WM_CAPTURECHANGED:
203 if (infoPtr->state & BUTTON_BTNPRESSED) {
204 infoPtr->state &= BUTTON_NSTATES;
205 if (infoPtr->state & BUTTON_HIGHLIGHTED)
206 SendMessageA( hWnd, BM_SETSTATE, FALSE, 0 );
211 if (GetCapture() == hWnd)
213 GetClientRect( hWnd, &rect );
214 SendMessageA( hWnd, BM_SETSTATE, PtInRect(&rect, pt), 0 );
219 if(style == BS_GROUPBOX) return HTTRANSPARENT;
220 return DefWindowProcA( hWnd, uMsg, wParam, lParam );
223 DEFWND_SetTextA( wndPtr, (LPCSTR)lParam );
224 if( wndPtr->dwStyle & WS_VISIBLE )
225 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
229 infoPtr->hFont = (HFONT16)wParam;
230 if (lParam && (wndPtr->dwStyle & WS_VISIBLE))
231 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
235 return infoPtr->hFont;
238 if ((style == BS_RADIOBUTTON || style == BS_AUTORADIOBUTTON) && (GetCapture() != hWnd) &&
239 !(SendMessageA(hWnd, BM_GETCHECK, 0, 0) & BST_CHECKED))
241 /* The notification is sent when the button (BS_AUTORADIOBUTTON)
242 is unchecked and the focus was not given by a mouse click. */
243 if (style == BS_AUTORADIOBUTTON)
244 SendMessageA( hWnd, BM_SETCHECK, BUTTON_CHECKED, 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;
269 /* Only redraw if lParam flag is set.*/
271 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
276 SendMessageA( hWnd, WM_LBUTTONDOWN, 0, 0 );
277 SendMessageA( hWnd, WM_LBUTTONUP, 0, 0 );
281 /* Check that image format confirm button style */
282 if ((wndPtr->dwStyle & (BS_BITMAP|BS_ICON)) == BS_BITMAP)
284 if (wParam != (WPARAM) IMAGE_BITMAP)
287 else if ((wndPtr->dwStyle & (BS_BITMAP|BS_ICON)) == BS_ICON)
289 if (wParam != (WPARAM) IMAGE_ICON)
294 oldHbitmap = infoPtr->hImage;
295 infoPtr->hImage = (HANDLE) lParam;
296 InvalidateRect( hWnd, NULL, FALSE );
300 if ((wndPtr->dwStyle & (BS_BITMAP|BS_ICON)) == BS_BITMAP)
302 if (wParam != (WPARAM) IMAGE_BITMAP)
305 else if ((wndPtr->dwStyle & (BS_BITMAP|BS_ICON)) == BS_ICON)
307 if (wParam != (WPARAM) IMAGE_ICON)
311 return infoPtr->hImage;
315 return infoPtr->state & 3;
319 if (wParam > maxCheckState[style]) wParam = maxCheckState[style];
320 if ((infoPtr->state & 3) != wParam)
322 if ((style == BS_RADIOBUTTON) || (style == BS_AUTORADIOBUTTON))
325 wndPtr->dwStyle |= WS_TABSTOP;
327 wndPtr->dwStyle &= ~WS_TABSTOP;
329 infoPtr->state = (infoPtr->state & ~3) | wParam;
330 PAINT_BUTTON( wndPtr, style, ODA_SELECT );
332 if ((style == BS_AUTORADIOBUTTON) && (wParam == BUTTON_CHECKED))
333 BUTTON_CheckAutoRadioButton( wndPtr );
338 return infoPtr->state;
344 if (infoPtr->state & BUTTON_HIGHLIGHTED) break;
345 infoPtr->state |= BUTTON_HIGHLIGHTED;
349 if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) break;
350 infoPtr->state &= ~BUTTON_HIGHLIGHTED;
352 PAINT_BUTTON( wndPtr, style, ODA_SELECT );
356 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
361 /***********************************************************************
363 * The button window procedure. This is just a wrapper which locks
364 * the passed HWND and calls the real window procedure (with a WND*
365 * pointer pointing to the locked windowstructure).
367 LRESULT WINAPI ButtonWndProc( HWND hWnd, UINT uMsg,
368 WPARAM wParam, LPARAM lParam )
371 WND *wndPtr = WIN_FindWndPtr(hWnd);
373 res = ButtonWndProc_locked(wndPtr,uMsg,wParam,lParam);
375 WIN_ReleaseWndPtr(wndPtr);
379 /**********************************************************************
380 * Push Button Functions
382 static void PB_Paint( WND *wndPtr, HDC hDC, WORD action )
384 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
385 BOOL bHighLighted = (infoPtr->state & BUTTON_HIGHLIGHTED);
388 * Delegate this to the more generic pushbutton painting
391 BUTTON_DrawPushButton(wndPtr,
397 /**********************************************************************
398 * Convert button styles to flags used by DrawText.
399 * TODO: handle WS_EX_RIGHT extended style.
401 static UINT BUTTON_BStoDT(DWORD style)
403 UINT dtStyle = DT_NOCLIP; /* We use SelectClipRgn to limit output */
405 /* "Convert" pushlike buttons to pushbuttons */
406 if (style & BS_PUSHLIKE)
409 if (!(style & BS_MULTILINE))
410 dtStyle |= DT_SINGLELINE;
412 dtStyle |= DT_WORDBREAK;
414 switch (style & BS_CENTER)
416 case BS_LEFT: /* DT_LEFT is 0 */ break;
417 case BS_RIGHT: dtStyle |= DT_RIGHT; break;
418 case BS_CENTER: dtStyle |= DT_CENTER; break;
420 /* Pushbutton's text is centered by default */
421 if ((style & 0x0F) <= BS_DEFPUSHBUTTON)
422 dtStyle |= DT_CENTER;
423 /* all other flavours have left aligned text */
426 /* DrawText ignores vertical alignment for multiline text,
427 * but we use these flags to align label manualy.
429 if ((style & 0x0F) != BS_GROUPBOX)
431 switch (style & BS_VCENTER)
433 case BS_TOP: /* DT_TOP is 0 */ break;
434 case BS_BOTTOM: dtStyle |= DT_BOTTOM; break;
435 case BS_VCENTER: /* fall through */
436 default: dtStyle |= DT_VCENTER; break;
440 /* GroupBox's text is always single line and is top aligned. */
441 dtStyle |= DT_SINGLELINE;
446 /**********************************************************************
447 * BUTTON_CalcLabelRect
449 * Calculates label's rectangle depending on button style.
451 * Returns flags to be passed to DrawText.
452 * Calculated rectangle doesn't take into account button state
453 * (pushed, etc.). If there is nothing to draw (no text/image) output
454 * rectangle is empty, and return value is (UINT)-1.
456 static UINT BUTTON_CalcLabelRect(WND *wndPtr, HDC hdc, RECT *rc)
458 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
461 UINT dtStyle = BUTTON_BStoDT(wndPtr->dwStyle);
465 /* Calculate label rectangle according to label type */
466 switch (wndPtr->dwStyle & (BS_ICON|BS_BITMAP))
469 if (wndPtr->text && wndPtr->text[0])
470 DrawTextW(hdc, wndPtr->text, -1, &r, dtStyle | DT_CALCRECT);
476 if (!GetIconInfo((HICON)infoPtr->hImage, &iconInfo))
479 GetObjectA (iconInfo.hbmColor, sizeof(BITMAP), &bm);
481 r.right = r.left + bm.bmWidth;
482 r.bottom = r.top + bm.bmHeight;
484 DeleteObject(iconInfo.hbmColor);
485 DeleteObject(iconInfo.hbmMask);
489 if (!GetObjectA (infoPtr->hImage, sizeof(BITMAP), &bm))
492 r.right = r.left + bm.bmWidth;
493 r.bottom = r.top + bm.bmHeight;
500 return (UINT)(LONG)-1;
503 /* Position label inside bounding rectangle according to
504 * alignment flags. (calculated rect is always left-top aligned).
505 * If label is aligned to any side - shift label in opposite
506 * direction to leave extra space for focus rectangle.
508 switch (dtStyle & (DT_CENTER|DT_RIGHT))
510 case DT_LEFT: r.left++; r.right++; break;
511 case DT_CENTER: n = r.right - r.left;
512 r.left = rc->left + ((rc->right - rc->left) - n) / 2;
513 r.right = r.left + n; break;
514 case DT_RIGHT: n = r.right - r.left;
515 r.right = rc->right - 1;
516 r.left = r.right - n;
520 switch (dtStyle & (DT_VCENTER|DT_BOTTOM))
522 case DT_TOP: r.top++; r.bottom++; break;
523 case DT_VCENTER: n = r.bottom - r.top;
524 r.top = rc->top + ((rc->bottom - rc->top) - n) / 2;
525 r.bottom = r.top + n; break;
526 case DT_BOTTOM: n = r.bottom - r.top;
527 r.bottom = rc->bottom - 1;
528 r.top = r.bottom - n;
537 /**********************************************************************
538 * BUTTON_DrawTextCallback
540 * Callback function used be DrawStateA function.
542 static BOOL CALLBACK BUTTON_DrawTextCallback(HDC hdc, LPARAM lp, WPARAM wp, int cx, int cy)
550 DrawTextW(hdc, (LPCWSTR)lp, -1, &rc, (UINT)wp);
555 /**********************************************************************
558 * Common function for drawing button label.
560 static void BUTTON_DrawLabel(WND *wndPtr, HDC hdc, UINT dtFlags,
563 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
564 DRAWSTATEPROC lpOutputProc = NULL;
568 UINT flags = IsWindowEnabled(wndPtr->hwndSelf) ? DSS_NORMAL : DSS_DISABLED;
570 /* Fixme: To draw disabled label in Win31 look-and-feel, we probably
571 * must use DSS_MONO flag and COLOR_GRAYTEXT brush (or maybe DSS_UNION).
572 * I don't have Win31 on hand to verify that, so I leave it as is.
575 if ((wndPtr->dwStyle & BS_PUSHLIKE) && (infoPtr->state & BUTTON_3STATE))
577 hbr = GetSysColorBrush(COLOR_GRAYTEXT);
581 switch (wndPtr->dwStyle & (BS_ICON|BS_BITMAP))
584 /* DST_COMPLEX -- is 0 */
585 lpOutputProc = BUTTON_DrawTextCallback;
586 lp = (LPARAM)wndPtr->text;
587 wp = (WPARAM)dtFlags;
592 lp = (LPARAM)infoPtr->hImage;
597 lp = (LPARAM)infoPtr->hImage;
604 DrawStateW(hdc, hbr, lpOutputProc, lp, wp, rc->left, rc->top,
605 rc->right - rc->left, rc->bottom - rc->top, flags);
608 /**********************************************************************
609 * This method will actually do the drawing of the pushbutton
610 * depending on it's state and the pushedState parameter.
612 static void BUTTON_DrawPushButton(
618 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
619 RECT rc, focus_rect, r;
625 COLORREF oldTxtColor;
627 GetClientRect( wndPtr->hwndSelf, &rc );
629 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
630 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
631 BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
632 hOldPen = (HPEN)SelectObject(hDC, GetSysColorPen(COLOR_WINDOWFRAME));
633 hOldBrush =(HBRUSH)SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE));
634 oldBkMode = SetBkMode(hDC, TRANSPARENT);
636 if ( TWEAK_WineLook == WIN31_LOOK)
638 COLORREF clr_wnd = GetSysColor(COLOR_WINDOW);
639 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
641 SetPixel( hDC, rc.left, rc.top, clr_wnd);
642 SetPixel( hDC, rc.left, rc.bottom-1, clr_wnd);
643 SetPixel( hDC, rc.right-1, rc.top, clr_wnd);
644 SetPixel( hDC, rc.right-1, rc.bottom-1, clr_wnd);
645 InflateRect( &rc, -1, -1 );
648 if ((wndPtr->dwStyle & 0x000f) == BS_DEFPUSHBUTTON)
650 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
651 InflateRect( &rc, -1, -1 );
654 if (TWEAK_WineLook == WIN31_LOOK)
658 /* draw button shadow: */
659 SelectObject(hDC, GetSysColorBrush(COLOR_BTNSHADOW));
660 PatBlt(hDC, rc.left, rc.top, 1, rc.bottom-rc.top, PATCOPY );
661 PatBlt(hDC, rc.left, rc.top, rc.right-rc.left, 1, PATCOPY );
663 rc.right++, rc.bottom++;
664 DrawEdge( hDC, &rc, EDGE_RAISED, BF_RECT );
665 rc.right--, rc.bottom--;
670 UINT uState = DFCS_BUTTONPUSH | DFCS_ADJUSTRECT;
672 if (wndPtr->dwStyle & BS_FLAT)
674 else if (pushedState)
676 if ( (wndPtr->dwStyle & 0x000f) == BS_DEFPUSHBUTTON )
679 uState |= DFCS_PUSHED;
682 if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE))
683 uState |= DFCS_CHECKED;
685 DrawFrameControl( hDC, &rc, DFC_BUTTON, uState );
690 /* draw button label */
692 dtFlags = BUTTON_CalcLabelRect(wndPtr, hDC, &r);
694 if (dtFlags == (UINT)-1L)
698 OffsetRect(&r, 1, 1);
700 if(TWEAK_WineLook == WIN31_LOOK)
703 InflateRect(&focus_rect, 2, 0);
706 hRgn = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
707 SelectClipRgn(hDC, hRgn);
709 oldTxtColor = SetTextColor( hDC, GetSysColor(COLOR_BTNTEXT) );
711 BUTTON_DrawLabel(wndPtr, hDC, dtFlags, &r);
713 SetTextColor( hDC, oldTxtColor );
714 SelectClipRgn(hDC, 0);
717 if (infoPtr->state & BUTTON_HASFOCUS)
719 InflateRect( &focus_rect, -1, -1 );
720 IntersectRect(&focus_rect, &focus_rect, &rc);
721 DrawFocusRect( hDC, &focus_rect );
725 SelectObject( hDC, hOldPen );
726 SelectObject( hDC, hOldBrush );
727 SetBkMode(hDC, oldBkMode);
730 /**********************************************************************
731 * Check Box & Radio Button Functions
734 static void CB_Paint( WND *wndPtr, HDC hDC, WORD action )
736 RECT rbox, rtext, client;
739 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
743 if (wndPtr->dwStyle & BS_PUSHLIKE)
745 BOOL bHighLighted = (infoPtr->state & BUTTON_HIGHLIGHTED);
747 BUTTON_DrawPushButton(wndPtr,
754 GetClientRect(wndPtr->hwndSelf, &client);
755 rbox = rtext = client;
757 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
759 /* GetControlBrush16 sends WM_CTLCOLORBTN, plus it returns default brush
760 * if parent didn't return valid one. So we kill two hares at once
762 hBrush = GetControlBrush16( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
764 if (wndPtr->dwStyle & BS_LEFTTEXT)
766 /* magic +4 is what CTL3D expects */
768 rtext.right -= checkBoxWidth + 4;
769 rbox.left = rbox.right - checkBoxWidth;
773 rtext.left += checkBoxWidth + 4;
774 rbox.right = checkBoxWidth;
777 /* Draw the check-box bitmap */
778 if (action == ODA_DRAWENTIRE || action == ODA_SELECT)
780 if( TWEAK_WineLook == WIN31_LOOK )
782 HDC hMemDC = CreateCompatibleDC( hDC );
784 delta = (rbox.bottom - rbox.top - checkBoxHeight) / 2;
786 /* Check in case the client area is smaller than the checkbox bitmap */
787 if (delta < 0) delta = 0;
789 if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush );
790 else FillRect( hDC, &client, hBrush );
792 if (infoPtr->state & BUTTON_HIGHLIGHTED) x += 2 * checkBoxWidth;
793 if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE)) x += checkBoxWidth;
794 if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) ||
795 ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) y += checkBoxHeight;
796 else if (infoPtr->state & BUTTON_3STATE) y += 2 * checkBoxHeight;
798 /* The bitmap for the radio button is not aligned with the
799 * left of the window, it is 1 pixel off. */
800 if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) ||
801 ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON))
804 SelectObject( hMemDC, hbitmapCheckBoxes );
805 BitBlt( hDC, rbox.left, rbox.top + delta, checkBoxWidth,
806 checkBoxHeight, hMemDC, x, y, SRCCOPY );
813 if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) ||
814 ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) state = DFCS_BUTTONRADIO;
815 else if (infoPtr->state & BUTTON_3STATE) state = DFCS_BUTTON3STATE;
816 else state = DFCS_BUTTONCHECK;
818 if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE)) state |= DFCS_CHECKED;
820 if (infoPtr->state & BUTTON_HIGHLIGHTED) state |= DFCS_PUSHED;
822 if (wndPtr->dwStyle & WS_DISABLED) state |= DFCS_INACTIVE;
824 /* rbox must have the correct height */
825 delta = rbox.bottom - rbox.top - checkBoxHeight;
828 int ofs = (abs(delta) / 2);
829 rbox.bottom -= ofs + 1;
830 rbox.top = rbox.bottom - checkBoxHeight;
834 int ofs = (abs(delta) / 2);
836 rbox.bottom = rbox.top + checkBoxHeight;
839 DrawFrameControl( hDC, &rbox, DFC_BUTTON, state );
845 dtFlags = BUTTON_CalcLabelRect(wndPtr, hDC, &rtext);
847 if (dtFlags == (UINT)-1L) /* Noting to draw */
849 hRgn = CreateRectRgn(client.left, client.top, client.right, client.bottom);
850 SelectClipRgn(hDC, hRgn);
853 if (action == ODA_DRAWENTIRE)
854 BUTTON_DrawLabel(wndPtr, hDC, dtFlags, &rtext);
857 if ((action == ODA_FOCUS) ||
858 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
862 IntersectRect(&rtext, &rtext, &client);
863 DrawFocusRect( hDC, &rtext );
865 SelectClipRgn(hDC, 0);
869 /**********************************************************************
870 * BUTTON_CheckAutoRadioButton
872 * wndPtr is checked, uncheck every other auto radio button in group
874 static void BUTTON_CheckAutoRadioButton( WND *wndPtr )
876 HWND parent, sibling, start;
877 if (!(wndPtr->dwStyle & WS_CHILD)) return;
878 parent = wndPtr->parent->hwndSelf;
879 /* assure that starting control is not disabled or invisible */
880 start = sibling = GetNextDlgGroupItem( parent, wndPtr->hwndSelf, TRUE );
885 tmpWnd = WIN_FindWndPtr(sibling);
886 if ((wndPtr->hwndSelf != sibling) &&
887 ((tmpWnd->dwStyle & 0x0f) == BS_AUTORADIOBUTTON))
888 SendMessageA( sibling, BM_SETCHECK, BUTTON_UNCHECKED, 0 );
889 sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
890 WIN_ReleaseWndPtr(tmpWnd);
891 } while (sibling != start);
895 /**********************************************************************
896 * Group Box Functions
899 static void GB_Paint( WND *wndPtr, HDC hDC, WORD action )
902 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
906 if (action != ODA_DRAWENTIRE) return;
909 SelectObject (hDC, infoPtr->hFont);
910 /* GroupBox acts like static control, so it sends CTLCOLORSTATIC */
911 hbr = GetControlBrush16( wndPtr->hwndSelf, hDC, CTLCOLOR_STATIC );
914 GetClientRect( wndPtr->hwndSelf, &rc);
915 if (TWEAK_WineLook == WIN31_LOOK) {
916 HPEN hPrevPen = SelectObject( hDC,
917 GetSysColorPen(COLOR_WINDOWFRAME));
918 HBRUSH hPrevBrush = SelectObject( hDC,
919 GetStockObject(NULL_BRUSH) );
921 Rectangle( hDC, rc.left, rc.top + 2, rc.right - 1, rc.bottom - 1 );
922 SelectObject( hDC, hPrevBrush );
923 SelectObject( hDC, hPrevPen );
928 GetTextMetricsA (hDC, &tm);
929 rcFrame.top += (tm.tmHeight / 2) - 1;
930 DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT |
931 ((wndPtr->dwStyle & BS_FLAT) ? BF_FLAT : 0));
934 InflateRect(&rc, -7, 1);
935 dtFlags = BUTTON_CalcLabelRect(wndPtr, hDC, &rc);
937 if (dtFlags == (UINT)-1L)
940 /* Because buttons have CS_PARENTDC class style, there is a chance
941 * that label will be drawn out of client rect.
942 * But Windows doesn't clip label's rect, so do I.
945 /* There is 1-pixel marging at the left, right, and bottom */
946 rc.left--; rc.right++; rc.bottom++;
947 FillRect(hDC, &rc, hbr);
948 rc.left++; rc.right--; rc.bottom--;
950 BUTTON_DrawLabel(wndPtr, hDC, dtFlags, &rc);
954 /**********************************************************************
955 * User Button Functions
958 static void UB_Paint( WND *wndPtr, HDC hDC, WORD action )
962 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
964 if (action == ODA_SELECT) return;
966 GetClientRect( wndPtr->hwndSelf, &rc);
968 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
969 hBrush = GetControlBrush16( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
971 FillRect( hDC, &rc, hBrush );
972 if ((action == ODA_FOCUS) ||
973 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
974 DrawFocusRect( hDC, &rc );
978 /**********************************************************************
979 * Ownerdrawn Button Functions
982 static void OB_Paint( WND *wndPtr, HDC hDC, WORD action )
984 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
989 dis.CtlType = ODT_BUTTON;
990 dis.CtlID = wndPtr->wIDmenu;
992 dis.itemAction = action;
993 dis.itemState = ((infoPtr->state & BUTTON_HASFOCUS) ? ODS_FOCUS : 0) |
994 ((infoPtr->state & BUTTON_HIGHLIGHTED) ? ODS_SELECTED : 0) |
995 (IsWindowEnabled(wndPtr->hwndSelf) ? 0: ODS_DISABLED);
996 dis.hwndItem = wndPtr->hwndSelf;
999 GetClientRect( wndPtr->hwndSelf, &dis.rcItem );
1001 clipRegion = CreateRectRgnIndirect(&dis.rcItem);
1002 if (GetClipRgn(hDC, clipRegion) != 1)
1004 DeleteObject(clipRegion);
1005 clipRegion=(HRGN)NULL;
1007 clipRect = dis.rcItem;
1008 DPtoLP(hDC, (LPPOINT) &clipRect, 2);
1009 IntersectClipRect(hDC, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
1011 SetBkColor( hDC, GetSysColor( COLOR_BTNFACE ) );
1013 SendMessageA( GetParent(wndPtr->hwndSelf), WM_DRAWITEM,
1014 wndPtr->wIDmenu, (LPARAM)&dis );
1016 SelectClipRgn(hDC, clipRegion);