Actually return the number of events in Mouse_GetDeviceData (fixes
[wine/testsucceed.git] / controls / button.c
blob9210f7e5c99a8ae050a1d8bc531079d93657dfbf
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
6 */
8 #include <string.h>
9 #include "win.h"
10 #include "button.h"
11 #include "wine/winuser16.h"
12 #include "tweak.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 )
83 RECT rect;
84 HWND hWnd = wndPtr->hwndSelf;
85 POINT pt;
86 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
87 LONG style = wndPtr->dwStyle & 0x0f;
88 HANDLE oldHbitmap;
90 pt.x = LOWORD(lParam);
91 pt.y = HIWORD(lParam);
93 switch (uMsg)
95 case WM_GETDLGCODE:
96 switch(style)
98 case BS_PUSHBUTTON: return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON;
99 case BS_DEFPUSHBUTTON: return DLGC_BUTTON | DLGC_DEFPUSHBUTTON;
100 case BS_RADIOBUTTON:
101 case BS_AUTORADIOBUTTON: return DLGC_BUTTON | DLGC_RADIOBUTTON;
102 default: return DLGC_BUTTON;
105 case WM_ENABLE:
106 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
107 break;
109 case WM_CREATE:
110 if (!hbitmapCheckBoxes)
112 BITMAP bmp;
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;
121 infoPtr->hFont = 0;
122 infoPtr->hImage = NULL;
123 return 0;
125 case WM_ERASEBKGND:
126 return 1;
128 case WM_PAINT:
129 if (btnPaintFunc[style])
131 PAINTSTRUCT ps;
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 );
137 break;
139 case WM_LBUTTONDOWN:
140 case WM_LBUTTONDBLCLK:
141 SendMessageA( hWnd, BM_SETSTATE, TRUE, 0 );
142 SetCapture( hWnd );
143 SetFocus( hWnd );
144 break;
146 case WM_LBUTTONUP:
147 /* FIXME: real windows uses extra flags in the status for this */
148 if (GetCapture() != hWnd) break;
149 ReleaseCapture();
150 if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) break;
151 SendMessageA( hWnd, BM_SETSTATE, FALSE, 0 );
152 GetClientRect( hWnd, &rect );
153 if (PtInRect( &rect, pt ))
155 switch(style)
157 case BS_AUTOCHECKBOX:
158 SendMessageA( hWnd, BM_SETCHECK,
159 !(infoPtr->state & BUTTON_CHECKED), 0 );
160 break;
161 case BS_AUTORADIOBUTTON:
162 SendMessageA( hWnd, BM_SETCHECK, TRUE, 0 );
163 break;
164 case BS_AUTO3STATE:
165 SendMessageA( hWnd, BM_SETCHECK,
166 (infoPtr->state & BUTTON_3STATE) ? 0 :
167 ((infoPtr->state & 3) + 1), 0 );
168 break;
170 SendMessageA( GetParent(hWnd), WM_COMMAND,
171 MAKEWPARAM( wndPtr->wIDmenu, BN_CLICKED ), hWnd);
173 break;
175 case WM_MOUSEMOVE:
176 if (GetCapture() == hWnd)
178 GetClientRect( hWnd, &rect );
179 SendMessageA( hWnd, BM_SETSTATE, PtInRect(&rect, pt), 0 );
181 break;
183 case WM_NCHITTEST:
184 if(style == BS_GROUPBOX) return HTTRANSPARENT;
185 return DefWindowProcA( hWnd, uMsg, wParam, lParam );
187 case WM_SETTEXT:
188 DEFWND_SetText( wndPtr, (LPCSTR)lParam );
189 if( wndPtr->dwStyle & WS_VISIBLE )
190 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
191 return 0;
193 case WM_SETFONT:
194 infoPtr->hFont = (HFONT16)wParam;
195 if (lParam && (wndPtr->dwStyle & WS_VISIBLE))
196 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
197 break;
199 case WM_GETFONT:
200 return infoPtr->hFont;
202 case WM_SETFOCUS:
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 );
214 break;
216 case WM_KILLFOCUS:
217 infoPtr->state &= ~BUTTON_HASFOCUS;
218 PAINT_BUTTON( wndPtr, style, ODA_FOCUS );
219 InvalidateRect( hWnd, NULL, TRUE );
220 break;
222 case WM_SYSCOLORCHANGE:
223 InvalidateRect( hWnd, NULL, FALSE );
224 break;
226 case BM_SETSTYLE16:
227 case BM_SETSTYLE:
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 );
233 break;
235 case BM_SETIMAGE:
236 oldHbitmap = infoPtr->hImage;
237 if ((wndPtr->dwStyle & BS_BITMAP) || (wndPtr->dwStyle & BS_ICON))
238 infoPtr->hImage = (HANDLE) lParam;
239 return oldHbitmap;
241 case BM_GETIMAGE:
242 if (wParam == IMAGE_BITMAP)
243 return (HBITMAP)infoPtr->hImage;
244 else if (wParam == IMAGE_ICON)
245 return (HICON)infoPtr->hImage;
246 else
247 return NULL;
249 case BM_GETCHECK16:
250 case BM_GETCHECK:
251 return infoPtr->state & 3;
253 case BM_SETCHECK16:
254 case BM_SETCHECK:
255 if (wParam > maxCheckState[style]) wParam = maxCheckState[style];
256 if ((infoPtr->state & 3) != wParam)
258 if ((style == BS_RADIOBUTTON) || (style == BS_AUTORADIOBUTTON))
260 if (wParam)
261 wndPtr->dwStyle |= WS_TABSTOP;
262 else
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 );
270 break;
272 case BM_GETSTATE16:
273 case BM_GETSTATE:
274 return infoPtr->state;
276 case BM_SETSTATE16:
277 case BM_SETSTATE:
278 if (wParam)
280 if (infoPtr->state & BUTTON_HIGHLIGHTED) break;
281 infoPtr->state |= BUTTON_HIGHLIGHTED;
283 else
285 if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) break;
286 infoPtr->state &= ~BUTTON_HIGHLIGHTED;
288 PAINT_BUTTON( wndPtr, style, ODA_SELECT );
289 break;
291 default:
292 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
294 return 0;
297 /***********************************************************************
298 * ButtonWndProc
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 )
306 LRESULT res;
307 WND *wndPtr = WIN_FindWndPtr(hWnd);
309 res = ButtonWndProc_locked(wndPtr,uMsg,wParam,lParam);
311 WIN_ReleaseWndPtr(wndPtr);
312 return res;
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
325 * method.
327 return BUTTON_DrawPushButton(wndPtr,
328 hDC,
329 action,
330 bHighLighted);
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(
338 WND* wndPtr,
339 HDC hDC,
340 WORD action,
341 BOOL pushedState )
343 RECT rc, focus_rect;
344 HPEN hOldPen;
345 HBRUSH hOldBrush;
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)
378 if (pushedState)
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 */
385 rc.top += 2;
386 } else {
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--;
397 else
399 UINT uState = DFCS_BUTTONPUSH;
401 if (pushedState)
403 if ( (wndPtr->dwStyle & 0x000f) == BS_DEFPUSHBUTTON )
404 uState |= DFCS_FLAT;
405 else
406 uState |= DFCS_PUSHED;
409 DrawFrameControl( hDC, &rc, DFC_BUTTON, uState );
410 InflateRect( &rc, -2, -2 );
412 focus_rect = rc;
414 if (pushedState)
416 rc.left += 2; /* To position the text down and right */
417 rc.top += 2;
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))) )
430 LOGBRUSH lb;
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 );
437 else
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 };
451 INT xdelta, ydelta;
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)
475 ICONINFO iconInfo;
476 BITMAP bm;
478 GetIconInfo((HICON)infoPtr->hImage, &iconInfo);
479 GetObjectA (iconInfo.hbmColor, sizeof(BITMAP), &bm);
481 imageWidth = bm.bmWidth;
482 imageHeight = bm.bmHeight;
484 else
486 BITMAP bm;
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 */
499 if (xOffset < 0)
501 imageWidth = rc.right - rc.left - 2*xBorderOffset -1;
502 xOffset = xBorderOffset;
505 if (yOffset < 0)
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)
519 DrawIcon(hDC,
520 rc.left + xOffset,
521 rc.top + yOffset,
522 (HICON)infoPtr->hImage);
524 else
526 HDC hdcMem;
528 hdcMem = CreateCompatibleDC (hDC);
529 SelectObject (hdcMem, (HBITMAP)infoPtr->hImage);
530 BitBlt(hDC,
531 rc.left + xOffset,
532 rc.top + yOffset,
533 imageWidth, imageHeight,
534 hdcMem, 0, 0, SRCCOPY);
536 DeleteDC (hdcMem);
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,
567 UINT format)
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);
578 HBITMAP hbmMem;
579 HBRUSH hBr;
580 RECT rect,rc2;
582 rect=*rc;
583 DrawTextA( hDC, text, -1, &rect, DT_SINGLELINE | DT_CALCRECT);
584 /* now text width and height are in rect.right and rect.bottom */
585 rc2=rect;
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) );
597 DeleteObject( 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 */
603 DeleteDC( hdcMem);
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;
615 HBRUSH hBrush;
616 int textlen, delta;
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,
629 hDC,
630 action,
631 bHighLighted);
634 textlen = 0;
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;
655 else
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 );
667 int x = 0, y = 0;
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 );
682 DeleteDC( hMemDC );
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,
690 DT_VCENTER);
691 } else {
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 */
706 SetRectEmpty(&rbox);
707 if( textlen )
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 );
735 WND *tmpWnd;
736 if (!sibling) break;
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 )
753 RECT rc, rcFrame;
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 );
770 } else {
771 TEXTMETRICA tm;
772 rcFrame = rc;
774 if (infoPtr->hFont)
775 SelectObject (hDC, infoPtr->hFont);
776 GetTextMetricsA (hDC, &tm);
777 rcFrame.top += (tm.tmHeight / 2) - 1;
778 DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT);
781 if (wndPtr->text)
783 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
784 if (wndPtr->dwStyle & WS_DISABLED)
785 SetTextColor( hDC, GetSysColor(COLOR_GRAYTEXT) );
786 rc.left += 10;
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 )
798 RECT rc;
799 HBRUSH hBrush;
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;
823 DRAWITEMSTRUCT dis;
825 dis.CtlType = ODT_BUTTON;
826 dis.CtlID = wndPtr->wIDmenu;
827 dis.itemID = 0;
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;
833 dis.hDC = hDC;
834 dis.itemData = 0;
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 );