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;
122 infoPtr->hImage = NULL;
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 case WM_LBUTTONDBLCLK:
141 SendMessageA( hWnd, BM_SETSTATE, TRUE, 0 );
147 /* FIXME: real windows uses extra flags in the status for this */
148 if (GetCapture() != hWnd) break;
150 if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) break;
151 SendMessageA( hWnd, BM_SETSTATE, FALSE, 0 );
152 GetClientRect( hWnd, &rect );
153 if (PtInRect( &rect, pt ))
157 case BS_AUTOCHECKBOX:
158 SendMessageA( hWnd, BM_SETCHECK,
159 !(infoPtr->state & BUTTON_CHECKED), 0 );
161 case BS_AUTORADIOBUTTON:
162 SendMessageA( hWnd, BM_SETCHECK, TRUE, 0 );
165 SendMessageA( hWnd, BM_SETCHECK,
166 (infoPtr->state & BUTTON_3STATE) ? 0 :
167 ((infoPtr->state & 3) + 1), 0 );
170 SendMessageA( GetParent(hWnd), WM_COMMAND,
171 MAKEWPARAM( wndPtr->wIDmenu, BN_CLICKED ), hWnd);
176 if (GetCapture() == hWnd)
178 GetClientRect( hWnd, &rect );
179 SendMessageA( hWnd, BM_SETSTATE, PtInRect(&rect, pt), 0 );
184 if(style == BS_GROUPBOX) return HTTRANSPARENT;
185 return DefWindowProcA( hWnd, uMsg, wParam, lParam );
188 DEFWND_SetText( wndPtr, (LPCSTR)lParam );
189 if( wndPtr->dwStyle & WS_VISIBLE )
190 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
194 infoPtr->hFont = (HFONT16)wParam;
195 if (lParam && (wndPtr->dwStyle & WS_VISIBLE))
196 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
200 return infoPtr->hFont;
203 if ((style == BS_AUTORADIOBUTTON) && (GetCapture() != hWnd) &&
204 !(SendMessageA(hWnd, BM_GETCHECK, 0, 0) & BST_CHECKED))
206 /* The notification is sent when the button (BS_AUTORADIOBUTTON)
207 is unckecked and the focus was not given by a mouse click. */
208 SendMessageA( hWnd, BM_SETCHECK, TRUE, 0 );
209 SendMessageA( GetParent(hWnd), WM_COMMAND,
210 MAKEWPARAM( wndPtr->wIDmenu, BN_CLICKED ), hWnd);
212 infoPtr->state |= BUTTON_HASFOCUS;
213 PAINT_BUTTON( wndPtr, style, ODA_FOCUS );
217 infoPtr->state &= ~BUTTON_HASFOCUS;
218 PAINT_BUTTON( wndPtr, style, ODA_FOCUS );
219 InvalidateRect( hWnd, NULL, TRUE );
222 case WM_SYSCOLORCHANGE:
223 InvalidateRect( hWnd, NULL, FALSE );
228 if ((wParam & 0x0f) >= MAX_BTN_TYPE) break;
229 wndPtr->dwStyle = (wndPtr->dwStyle & 0xfffffff0)
230 | (wParam & 0x0000000f);
231 style = wndPtr->dwStyle & 0x0000000f;
232 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
236 oldHbitmap = infoPtr->hImage;
237 if ((wndPtr->dwStyle & BS_BITMAP) || (wndPtr->dwStyle & BS_ICON))
238 infoPtr->hImage = (HANDLE) lParam;
242 if (wParam == IMAGE_BITMAP)
243 return (HBITMAP)infoPtr->hImage;
244 else if (wParam == IMAGE_ICON)
245 return (HICON)infoPtr->hImage;
251 return infoPtr->state & 3;
255 if (wParam > maxCheckState[style]) wParam = maxCheckState[style];
256 if ((infoPtr->state & 3) != wParam)
258 if ((style == BS_RADIOBUTTON) || (style == BS_AUTORADIOBUTTON))
261 wndPtr->dwStyle |= WS_TABSTOP;
263 wndPtr->dwStyle &= ~WS_TABSTOP;
265 infoPtr->state = (infoPtr->state & ~3) | wParam;
266 PAINT_BUTTON( wndPtr, style, ODA_SELECT );
268 if ((style == BS_AUTORADIOBUTTON) && (wParam == BUTTON_CHECKED))
269 BUTTON_CheckAutoRadioButton( wndPtr );
274 return infoPtr->state;
280 if (infoPtr->state & BUTTON_HIGHLIGHTED) break;
281 infoPtr->state |= BUTTON_HIGHLIGHTED;
285 if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) break;
286 infoPtr->state &= ~BUTTON_HIGHLIGHTED;
288 PAINT_BUTTON( wndPtr, style, ODA_SELECT );
292 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
297 /***********************************************************************
299 * The button window procedure. This is just a wrapper which locks
300 * the passed HWND and calls the real window procedure (with a WND*
301 * pointer pointing to the locked windowstructure).
303 LRESULT WINAPI ButtonWndProc( HWND hWnd, UINT uMsg,
304 WPARAM wParam, LPARAM lParam )
307 WND *wndPtr = WIN_FindWndPtr(hWnd);
309 res = ButtonWndProc_locked(wndPtr,uMsg,wParam,lParam);
311 WIN_ReleaseWndPtr(wndPtr);
315 /**********************************************************************
316 * Push Button Functions
318 static void PB_Paint( WND *wndPtr, HDC hDC, WORD action )
320 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
321 BOOL bHighLighted = (infoPtr->state & BUTTON_HIGHLIGHTED);
324 * Delegate this to the more generic pushbutton painting
327 return BUTTON_DrawPushButton(wndPtr,
333 /**********************************************************************
334 * This method will actually do the drawing of the pushbutton
335 * depending on it's state and the pushedState parameter.
337 static void BUTTON_DrawPushButton(
346 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
347 int xBorderOffset, yBorderOffset;
348 xBorderOffset = yBorderOffset = 0;
350 GetClientRect( wndPtr->hwndSelf, &rc );
352 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
353 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
354 BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
355 hOldPen = (HPEN)SelectObject(hDC, GetSysColorPen(COLOR_WINDOWFRAME));
356 hOldBrush =(HBRUSH)SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE));
357 SetBkMode(hDC, TRANSPARENT);
359 if ( TWEAK_WineLook == WIN31_LOOK)
361 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
363 SetPixel( hDC, rc.left, rc.top, GetSysColor(COLOR_WINDOW) );
364 SetPixel( hDC, rc.left, rc.bottom-1, GetSysColor(COLOR_WINDOW) );
365 SetPixel( hDC, rc.right-1, rc.top, GetSysColor(COLOR_WINDOW) );
366 SetPixel( hDC, rc.right-1, rc.bottom-1, GetSysColor(COLOR_WINDOW));
367 InflateRect( &rc, -1, -1 );
370 if ((wndPtr->dwStyle & 0x000f) == BS_DEFPUSHBUTTON)
372 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
373 InflateRect( &rc, -1, -1 );
376 if (TWEAK_WineLook == WIN31_LOOK)
380 /* draw button shadow: */
381 SelectObject(hDC, GetSysColorBrush(COLOR_BTNSHADOW));
382 PatBlt(hDC, rc.left, rc.top, 1, rc.bottom-rc.top, PATCOPY );
383 PatBlt(hDC, rc.left, rc.top, rc.right-rc.left, 1, PATCOPY );
384 rc.left += 2; /* To position the text down and right */
387 rc.right++, rc.bottom++;
388 DrawEdge( hDC, &rc, EDGE_RAISED, BF_RECT );
390 /* To place de bitmap correctly */
391 xBorderOffset += GetSystemMetrics(SM_CXEDGE);
392 yBorderOffset += GetSystemMetrics(SM_CYEDGE);
394 rc.right--, rc.bottom--;
399 UINT uState = DFCS_BUTTONPUSH;
403 if ( (wndPtr->dwStyle & 0x000f) == BS_DEFPUSHBUTTON )
406 uState |= DFCS_PUSHED;
409 DrawFrameControl( hDC, &rc, DFC_BUTTON, uState );
410 InflateRect( &rc, -2, -2 );
416 rc.left += 2; /* To position the text down and right */
421 /* draw button label, if any:
423 * In win9x we don't show text if there is a bitmap or icon.
424 * I don't know about win31 so I leave it as it was for win31.
425 * Dennis Björklund 12 Jul, 99
427 if ( wndPtr->text && wndPtr->text[0]
428 && (TWEAK_WineLook == WIN31_LOOK || !(wndPtr->dwStyle & (BS_ICON|BS_BITMAP))) )
431 GetObjectA( GetSysColorBrush(COLOR_BTNFACE), sizeof(lb), &lb );
432 if (wndPtr->dwStyle & WS_DISABLED &&
433 GetSysColor(COLOR_GRAYTEXT)==lb.lbColor)
434 /* don't write gray text on gray background */
435 PaintGrayOnGray( hDC,infoPtr->hFont,&rc,wndPtr->text,
436 DT_CENTER | DT_VCENTER );
439 SetTextColor( hDC, (wndPtr->dwStyle & WS_DISABLED) ?
440 GetSysColor(COLOR_GRAYTEXT) :
441 GetSysColor(COLOR_BTNTEXT) );
442 DrawTextA( hDC, wndPtr->text, -1, &rc,
443 DT_SINGLELINE | DT_CENTER | DT_VCENTER );
444 /* do we have the focus?
445 * Win9x draws focus last with a size prop. to the button
447 if (TWEAK_WineLook == WIN31_LOOK
448 && infoPtr->state & BUTTON_HASFOCUS)
450 RECT r = { 0, 0, 0, 0 };
453 DrawTextA( hDC, wndPtr->text, -1, &r,
454 DT_SINGLELINE | DT_CALCRECT );
455 xdelta = ((rc.right - rc.left) - (r.right - r.left) - 1) / 2;
456 ydelta = ((rc.bottom - rc.top) - (r.bottom - r.top) - 1) / 2;
457 if (xdelta < 0) xdelta = 0;
458 if (ydelta < 0) ydelta = 0;
459 InflateRect( &rc, -xdelta, -ydelta );
460 DrawFocusRect( hDC, &rc );
464 if ( ((wndPtr->dwStyle & BS_ICON) || (wndPtr->dwStyle & BS_BITMAP) ) &&
465 (infoPtr->hImage != NULL) )
467 int yOffset, xOffset;
468 int imageWidth, imageHeight;
471 * We extract the size of the image from the handle.
473 if (wndPtr->dwStyle & BS_ICON)
478 GetIconInfo((HICON)infoPtr->hImage, &iconInfo);
479 GetObjectA (iconInfo.hbmColor, sizeof(BITMAP), &bm);
481 imageWidth = bm.bmWidth;
482 imageHeight = bm.bmHeight;
488 GetObjectA (infoPtr->hImage, sizeof(BITMAP), &bm);
490 imageWidth = bm.bmWidth;
491 imageHeight = bm.bmHeight;
494 /* Center the bitmap */
495 xOffset = (((rc.right - rc.left) - 2*xBorderOffset) - imageWidth ) / 2;
496 yOffset = (((rc.bottom - rc.top) - 2*yBorderOffset) - imageHeight) / 2;
498 /* If the image is to big for the button */
501 imageWidth = rc.right - rc.left - 2*xBorderOffset -1;
502 xOffset = xBorderOffset;
507 imageHeight = rc.bottom - rc.top - 2*yBorderOffset -1;
508 yOffset = yBorderOffset;
511 /* Let minimum 1 space from border */
512 xOffset++, yOffset++;
515 * Draw the image now.
517 if (wndPtr->dwStyle & BS_ICON)
522 (HICON)infoPtr->hImage);
528 hdcMem = CreateCompatibleDC (hDC);
529 SelectObject (hdcMem, (HBITMAP)infoPtr->hImage);
533 imageWidth, imageHeight,
534 hdcMem, 0, 0, SRCCOPY);
540 if (TWEAK_WineLook != WIN31_LOOK
541 && infoPtr->state & BUTTON_HASFOCUS)
543 InflateRect( &focus_rect, -1, -1 );
544 DrawFocusRect( hDC, &focus_rect );
548 SelectObject( hDC, hOldPen );
549 SelectObject( hDC, hOldBrush );
553 /**********************************************************************
554 * PB_Paint & CB_Paint sub function [internal]
555 * Paint text using a raster brush to avoid gray text on gray
556 * background. 'format' can be a combination of DT_CENTER and
557 * DT_VCENTER to use this function in both PB_PAINT and
558 * CB_PAINT. - Dirk Thierbach
560 * FIXME: This and TEXT_GrayString should be eventually combined,
561 * so calling one common function from PB_Paint, CB_Paint and
562 * TEXT_GrayString will be enough. Also note that this
563 * function ignores the CACHE_GetPattern funcs.
566 void PaintGrayOnGray(HDC hDC,HFONT hFont,RECT *rc,char *text,
569 /* This is the standard gray on gray pattern:
570 static const WORD Pattern[] = {0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55};
572 /* This pattern gives better readability with X Fonts.
573 FIXME: Maybe the user should be allowed to decide which he wants. */
574 static const WORD Pattern[] = {0x55,0xFF,0xAA,0xFF,0x55,0xFF,0xAA,0xFF};
576 HBITMAP hbm = CreateBitmap( 8, 8, 1, 1, Pattern );
577 HDC hdcMem = CreateCompatibleDC(hDC);
583 DrawTextA( hDC, text, -1, &rect, DT_SINGLELINE | DT_CALCRECT);
584 /* now text width and height are in rect.right and rect.bottom */
586 rect.left = rect.top = 0; /* drawing pos in hdcMem */
587 if (format & DT_CENTER) rect.left=(rc->right-rect.right)/2;
588 if (format & DT_VCENTER) rect.top=(rc->bottom-rect.bottom)/2;
589 hbmMem = CreateCompatibleBitmap( hDC,rect.right,rect.bottom );
590 SelectObject( hdcMem, hbmMem);
591 PatBlt( hdcMem,0,0,rect.right,rect.bottom,WHITENESS);
592 /* will be overwritten by DrawText, but just in case */
593 if (hFont) SelectObject( hdcMem, hFont);
594 DrawTextA( hdcMem, text, -1, &rc2, DT_SINGLELINE);
595 /* After draw: foreground = 0 bits, background = 1 bits */
596 hBr = SelectObject( hdcMem, CreatePatternBrush(hbm) );
598 PatBlt( hdcMem,0,0,rect.right,rect.bottom,0xAF0229);
599 /* only keep the foreground bits where pattern is 1 */
600 DeleteObject( SelectObject( hdcMem,hBr) );
601 BitBlt(hDC,rect.left,rect.top,rect.right,rect.bottom,hdcMem,0,0,SRCAND);
602 /* keep the background of the dest */
604 DeleteObject( hbmMem );
608 /**********************************************************************
609 * Check Box & Radio Button Functions
612 static void CB_Paint( WND *wndPtr, HDC hDC, WORD action )
614 RECT rbox, rtext, client;
617 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
620 * if the button has a bitmap/icon, draw a normal pushbutton
621 * instead of a radion button.
623 if (infoPtr->hImage!=NULL)
625 BOOL bHighLighted = ((infoPtr->state & BUTTON_HIGHLIGHTED) ||
626 (infoPtr->state & BUTTON_CHECKED));
628 return BUTTON_DrawPushButton(wndPtr,
635 GetClientRect(wndPtr->hwndSelf, &client);
636 rbox = rtext = client;
638 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
640 /* Something is still not right, checkboxes (and edit controls)
641 * in wsping32 have white backgrounds instead of dark grey.
642 * BUTTON_SEND_CTLCOLOR() is even worse since it returns 0 in this
643 * particular case and the background is not painted at all.
646 hBrush = GetControlBrush16( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
648 if (wndPtr->dwStyle & BS_LEFTTEXT)
650 /* magic +4 is what CTL3D expects */
652 rtext.right -= checkBoxWidth + 4;
653 rbox.left = rbox.right - checkBoxWidth;
657 rtext.left += checkBoxWidth + 4;
658 rbox.right = checkBoxWidth;
661 /* Draw the check-box bitmap */
663 if (wndPtr->text) textlen = strlen( wndPtr->text );
664 if (action == ODA_DRAWENTIRE || action == ODA_SELECT)
666 HDC hMemDC = CreateCompatibleDC( hDC );
668 delta = (rbox.bottom - rbox.top - checkBoxHeight) >> 1;
670 if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush );
671 else FillRect( hDC, &client, hBrush );
673 if (infoPtr->state & BUTTON_HIGHLIGHTED) x += 2 * checkBoxWidth;
674 if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE)) x += checkBoxWidth;
675 if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) ||
676 ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) y += checkBoxHeight;
677 else if (infoPtr->state & BUTTON_3STATE) y += 2 * checkBoxHeight;
679 SelectObject( hMemDC, hbitmapCheckBoxes );
680 BitBlt( hDC, rbox.left, rbox.top + delta, checkBoxWidth,
681 checkBoxHeight, hMemDC, x, y, SRCCOPY );
684 if( textlen && action != ODA_SELECT )
686 if (wndPtr->dwStyle & WS_DISABLED &&
687 GetSysColor(COLOR_GRAYTEXT)==GetBkColor(hDC)) {
688 /* don't write gray text on gray background */
689 PaintGrayOnGray( hDC, infoPtr->hFont, &rtext, wndPtr->text,
692 if (wndPtr->dwStyle & WS_DISABLED)
693 SetTextColor( hDC, GetSysColor(COLOR_GRAYTEXT) );
694 DrawTextA( hDC, wndPtr->text, textlen, &rtext,
695 DT_SINGLELINE | DT_VCENTER );
696 textlen = 0; /* skip DrawText() below */
701 if ((action == ODA_FOCUS) ||
702 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
704 /* again, this is what CTL3D expects */
708 DrawTextA( hDC, wndPtr->text, textlen, &rbox,
709 DT_SINGLELINE | DT_CALCRECT );
710 textlen = rbox.bottom - rbox.top;
711 delta = ((rtext.bottom - rtext.top) - textlen)/2;
712 rbox.bottom = (rbox.top = rtext.top + delta - 1) + textlen + 2;
713 textlen = rbox.right - rbox.left;
714 rbox.right = (rbox.left += --rtext.left) + textlen + 2;
715 IntersectRect(&rbox, &rbox, &rtext);
716 DrawFocusRect( hDC, &rbox );
721 /**********************************************************************
722 * BUTTON_CheckAutoRadioButton
724 * wndPtr is checked, uncheck every other auto radio button in group
726 static void BUTTON_CheckAutoRadioButton( WND *wndPtr )
728 HWND parent, sibling, start;
729 if (!(wndPtr->dwStyle & WS_CHILD)) return;
730 parent = wndPtr->parent->hwndSelf;
731 /* assure that starting control is not disabled or invisible */
732 start = sibling = GetNextDlgGroupItem( parent, wndPtr->hwndSelf, TRUE );
737 tmpWnd = WIN_FindWndPtr(sibling);
738 if ((wndPtr->hwndSelf != sibling) &&
739 ((tmpWnd->dwStyle & 0x0f) == BS_AUTORADIOBUTTON))
740 SendMessageA( sibling, BM_SETCHECK, BUTTON_UNCHECKED, 0 );
741 sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
742 WIN_ReleaseWndPtr(tmpWnd);
743 } while (sibling != start);
747 /**********************************************************************
748 * Group Box Functions
751 static void GB_Paint( WND *wndPtr, HDC hDC, WORD action )
754 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
756 if (action != ODA_DRAWENTIRE) return;
758 BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
760 GetClientRect( wndPtr->hwndSelf, &rc);
761 if (TWEAK_WineLook == WIN31_LOOK) {
762 HPEN hPrevPen = SelectObject( hDC,
763 GetSysColorPen(COLOR_WINDOWFRAME));
764 HBRUSH hPrevBrush = SelectObject( hDC,
765 GetStockObject(NULL_BRUSH) );
767 Rectangle( hDC, rc.left, rc.top + 2, rc.right - 1, rc.bottom - 1 );
768 SelectObject( hDC, hPrevBrush );
769 SelectObject( hDC, hPrevPen );
775 SelectObject (hDC, infoPtr->hFont);
776 GetTextMetricsA (hDC, &tm);
777 rcFrame.top += (tm.tmHeight / 2) - 1;
778 DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT);
783 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
784 if (wndPtr->dwStyle & WS_DISABLED)
785 SetTextColor( hDC, GetSysColor(COLOR_GRAYTEXT) );
787 DrawTextA( hDC, wndPtr->text, -1, &rc, DT_SINGLELINE | DT_NOCLIP );
792 /**********************************************************************
793 * User Button Functions
796 static void UB_Paint( WND *wndPtr, HDC hDC, WORD action )
800 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
802 if (action == ODA_SELECT) return;
804 GetClientRect( wndPtr->hwndSelf, &rc);
806 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
807 hBrush = GetControlBrush16( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
809 FillRect( hDC, &rc, hBrush );
810 if ((action == ODA_FOCUS) ||
811 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
812 DrawFocusRect( hDC, &rc );
816 /**********************************************************************
817 * Ownerdrawn Button Functions
820 static void OB_Paint( WND *wndPtr, HDC hDC, WORD action )
822 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
825 dis.CtlType = ODT_BUTTON;
826 dis.CtlID = wndPtr->wIDmenu;
828 dis.itemAction = action;
829 dis.itemState = ((infoPtr->state & BUTTON_HASFOCUS) ? ODS_FOCUS : 0) |
830 ((infoPtr->state & BUTTON_HIGHLIGHTED) ? ODS_SELECTED : 0) |
831 ((wndPtr->dwStyle & WS_DISABLED) ? ODS_DISABLED : 0);
832 dis.hwndItem = wndPtr->hwndSelf;
835 GetClientRect( wndPtr->hwndSelf, &dis.rcItem );
837 SetBkColor( hDC, GetSysColor( COLOR_BTNFACE ) );
838 FillRect( hDC, &dis.rcItem, GetSysColorBrush( COLOR_BTNFACE ) );
840 SendMessageA( GetParent(wndPtr->hwndSelf), WM_DRAWITEM,
841 wndPtr->wIDmenu, (LPARAM)&dis );