Removed resource.h.
[wine.git] / controls / button.c
blobfb958e567963fc2009bdf62590ba90741d21db45
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 = 0;
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_KEYDOWN:
140 if (wParam == VK_SPACE)
142 SendMessageA( hWnd, BM_SETSTATE, TRUE, 0 );
143 infoPtr->state |= BUTTON_BTNPRESSED;
145 break;
147 case WM_LBUTTONDBLCLK:
148 if(wndPtr->dwStyle & BS_NOTIFY ||
149 style==BS_RADIOBUTTON ||
150 style==BS_USERBUTTON ||
151 style==BS_OWNERDRAW) {
152 SendMessageA( GetParent(hWnd), WM_COMMAND,
153 MAKEWPARAM( wndPtr->wIDmenu, BN_DOUBLECLICKED ), hWnd);
154 break;
156 /* fall through */
157 case WM_LBUTTONDOWN:
158 SetCapture( hWnd );
159 SetFocus( hWnd );
160 SendMessageA( hWnd, BM_SETSTATE, TRUE, 0 );
161 infoPtr->state |= BUTTON_BTNPRESSED;
162 break;
164 case WM_KEYUP:
165 if (wParam != VK_SPACE)
166 break;
167 /* fall through */
168 case WM_LBUTTONUP:
169 if (!(infoPtr->state & BUTTON_BTNPRESSED)) break;
170 infoPtr->state &= BUTTON_NSTATES;
171 if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) {
172 ReleaseCapture();
173 break;
175 SendMessageA( hWnd, BM_SETSTATE, FALSE, 0 );
176 ReleaseCapture();
177 GetClientRect( hWnd, &rect );
178 if (uMsg == WM_KEYUP || PtInRect( &rect, pt ))
180 switch(style)
182 case BS_AUTOCHECKBOX:
183 SendMessageA( hWnd, BM_SETCHECK,
184 !(infoPtr->state & BUTTON_CHECKED), 0 );
185 break;
186 case BS_AUTORADIOBUTTON:
187 SendMessageA( hWnd, BM_SETCHECK, TRUE, 0 );
188 break;
189 case BS_AUTO3STATE:
190 SendMessageA( hWnd, BM_SETCHECK,
191 (infoPtr->state & BUTTON_3STATE) ? 0 :
192 ((infoPtr->state & 3) + 1), 0 );
193 break;
195 SendMessageA( GetParent(hWnd), WM_COMMAND,
196 MAKEWPARAM( wndPtr->wIDmenu, BN_CLICKED ), hWnd);
198 break;
200 case WM_CAPTURECHANGED:
201 if (infoPtr->state & BUTTON_BTNPRESSED) {
202 infoPtr->state &= BUTTON_NSTATES;
203 if (infoPtr->state & BUTTON_HIGHLIGHTED)
204 SendMessageA( hWnd, BM_SETSTATE, FALSE, 0 );
206 break;
208 case WM_MOUSEMOVE:
209 if (GetCapture() == hWnd)
211 GetClientRect( hWnd, &rect );
212 SendMessageA( hWnd, BM_SETSTATE, PtInRect(&rect, pt), 0 );
214 break;
216 case WM_NCHITTEST:
217 if(style == BS_GROUPBOX) return HTTRANSPARENT;
218 return DefWindowProcA( hWnd, uMsg, wParam, lParam );
220 case WM_SETTEXT:
221 DEFWND_SetText( wndPtr, (LPCSTR)lParam );
222 if( wndPtr->dwStyle & WS_VISIBLE )
223 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
224 return 0;
226 case WM_SETFONT:
227 infoPtr->hFont = (HFONT16)wParam;
228 if (lParam && (wndPtr->dwStyle & WS_VISIBLE))
229 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
230 break;
232 case WM_GETFONT:
233 return infoPtr->hFont;
235 case WM_SETFOCUS:
236 if ((style == BS_AUTORADIOBUTTON) && (GetCapture() != hWnd) &&
237 !(SendMessageA(hWnd, BM_GETCHECK, 0, 0) & BST_CHECKED))
239 /* The notification is sent when the button (BS_AUTORADIOBUTTON)
240 is unckecked and the focus was not given by a mouse click. */
241 SendMessageA( hWnd, BM_SETCHECK, TRUE, 0 );
242 SendMessageA( GetParent(hWnd), WM_COMMAND,
243 MAKEWPARAM( wndPtr->wIDmenu, BN_CLICKED ), hWnd);
245 infoPtr->state |= BUTTON_HASFOCUS;
246 PAINT_BUTTON( wndPtr, style, ODA_FOCUS );
247 break;
249 case WM_KILLFOCUS:
250 infoPtr->state &= ~BUTTON_HASFOCUS;
251 PAINT_BUTTON( wndPtr, style, ODA_FOCUS );
252 InvalidateRect( hWnd, NULL, TRUE );
253 break;
255 case WM_SYSCOLORCHANGE:
256 InvalidateRect( hWnd, NULL, FALSE );
257 break;
259 case BM_SETSTYLE16:
260 case BM_SETSTYLE:
261 if ((wParam & 0x0f) >= MAX_BTN_TYPE) break;
262 wndPtr->dwStyle = (wndPtr->dwStyle & 0xfffffff0)
263 | (wParam & 0x0000000f);
264 style = wndPtr->dwStyle & 0x0000000f;
265 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
266 break;
268 case BM_CLICK:
269 SendMessageA( hWnd, WM_LBUTTONDOWN, 0, 0 );
270 SendMessageA( hWnd, WM_LBUTTONUP, 0, 0 );
271 break;
273 case BM_SETIMAGE:
274 oldHbitmap = infoPtr->hImage;
275 if ((wndPtr->dwStyle & BS_BITMAP) || (wndPtr->dwStyle & BS_ICON))
276 infoPtr->hImage = (HANDLE) lParam;
277 return oldHbitmap;
279 case BM_GETIMAGE:
280 if (wParam == IMAGE_BITMAP)
281 return (HBITMAP)infoPtr->hImage;
282 else if (wParam == IMAGE_ICON)
283 return (HICON)infoPtr->hImage;
284 else
285 return (HICON)0;
287 case BM_GETCHECK16:
288 case BM_GETCHECK:
289 return infoPtr->state & 3;
291 case BM_SETCHECK16:
292 case BM_SETCHECK:
293 if (wParam > maxCheckState[style]) wParam = maxCheckState[style];
294 if ((infoPtr->state & 3) != wParam)
296 if ((style == BS_RADIOBUTTON) || (style == BS_AUTORADIOBUTTON))
298 if (wParam)
299 wndPtr->dwStyle |= WS_TABSTOP;
300 else
301 wndPtr->dwStyle &= ~WS_TABSTOP;
303 infoPtr->state = (infoPtr->state & ~3) | wParam;
304 PAINT_BUTTON( wndPtr, style, ODA_SELECT );
306 if ((style == BS_AUTORADIOBUTTON) && (wParam == BUTTON_CHECKED))
307 BUTTON_CheckAutoRadioButton( wndPtr );
308 break;
310 case BM_GETSTATE16:
311 case BM_GETSTATE:
312 return infoPtr->state;
314 case BM_SETSTATE16:
315 case BM_SETSTATE:
316 if (wParam)
318 if (infoPtr->state & BUTTON_HIGHLIGHTED) break;
319 infoPtr->state |= BUTTON_HIGHLIGHTED;
321 else
323 if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) break;
324 infoPtr->state &= ~BUTTON_HIGHLIGHTED;
326 PAINT_BUTTON( wndPtr, style, ODA_SELECT );
327 break;
329 default:
330 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
332 return 0;
335 /***********************************************************************
336 * ButtonWndProc
337 * The button window procedure. This is just a wrapper which locks
338 * the passed HWND and calls the real window procedure (with a WND*
339 * pointer pointing to the locked windowstructure).
341 LRESULT WINAPI ButtonWndProc( HWND hWnd, UINT uMsg,
342 WPARAM wParam, LPARAM lParam )
344 LRESULT res;
345 WND *wndPtr = WIN_FindWndPtr(hWnd);
347 res = ButtonWndProc_locked(wndPtr,uMsg,wParam,lParam);
349 WIN_ReleaseWndPtr(wndPtr);
350 return res;
353 /**********************************************************************
354 * Push Button Functions
356 static void PB_Paint( WND *wndPtr, HDC hDC, WORD action )
358 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
359 BOOL bHighLighted = (infoPtr->state & BUTTON_HIGHLIGHTED);
362 * Delegate this to the more generic pushbutton painting
363 * method.
365 BUTTON_DrawPushButton(wndPtr,
366 hDC,
367 action,
368 bHighLighted);
371 /**********************************************************************
372 * This method will actually do the drawing of the pushbutton
373 * depending on it's state and the pushedState parameter.
375 static void BUTTON_DrawPushButton(
376 WND* wndPtr,
377 HDC hDC,
378 WORD action,
379 BOOL pushedState )
381 RECT rc, focus_rect;
382 HPEN hOldPen;
383 HBRUSH hOldBrush;
384 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
385 int xBorderOffset, yBorderOffset;
386 xBorderOffset = yBorderOffset = 0;
388 GetClientRect( wndPtr->hwndSelf, &rc );
390 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
391 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
392 BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
393 hOldPen = (HPEN)SelectObject(hDC, GetSysColorPen(COLOR_WINDOWFRAME));
394 hOldBrush =(HBRUSH)SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE));
395 SetBkMode(hDC, TRANSPARENT);
397 if ( TWEAK_WineLook == WIN31_LOOK)
399 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
401 SetPixel( hDC, rc.left, rc.top, GetSysColor(COLOR_WINDOW) );
402 SetPixel( hDC, rc.left, rc.bottom-1, GetSysColor(COLOR_WINDOW) );
403 SetPixel( hDC, rc.right-1, rc.top, GetSysColor(COLOR_WINDOW) );
404 SetPixel( hDC, rc.right-1, rc.bottom-1, GetSysColor(COLOR_WINDOW));
405 InflateRect( &rc, -1, -1 );
408 if ((wndPtr->dwStyle & 0x000f) == BS_DEFPUSHBUTTON)
410 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
411 InflateRect( &rc, -1, -1 );
414 if (TWEAK_WineLook == WIN31_LOOK)
416 if (pushedState)
418 /* draw button shadow: */
419 SelectObject(hDC, GetSysColorBrush(COLOR_BTNSHADOW));
420 PatBlt(hDC, rc.left, rc.top, 1, rc.bottom-rc.top, PATCOPY );
421 PatBlt(hDC, rc.left, rc.top, rc.right-rc.left, 1, PATCOPY );
422 rc.left += 2; /* To position the text down and right */
423 rc.top += 2;
424 } else {
425 rc.right++, rc.bottom++;
426 DrawEdge( hDC, &rc, EDGE_RAISED, BF_RECT );
428 /* To place de bitmap correctly */
429 xBorderOffset += GetSystemMetrics(SM_CXEDGE);
430 yBorderOffset += GetSystemMetrics(SM_CYEDGE);
432 rc.right--, rc.bottom--;
435 else
437 UINT uState = DFCS_BUTTONPUSH;
439 if (pushedState)
441 if ( (wndPtr->dwStyle & 0x000f) == BS_DEFPUSHBUTTON )
442 uState |= DFCS_FLAT;
443 else
444 uState |= DFCS_PUSHED;
447 DrawFrameControl( hDC, &rc, DFC_BUTTON, uState );
448 InflateRect( &rc, -2, -2 );
450 focus_rect = rc;
452 if (pushedState)
454 rc.left += 2; /* To position the text down and right */
455 rc.top += 2;
459 /* draw button label, if any:
461 * In win9x we don't show text if there is a bitmap or icon.
462 * I don't know about win31 so I leave it as it was for win31.
463 * Dennis Björklund 12 Jul, 99
465 if ( wndPtr->text && wndPtr->text[0]
466 && (TWEAK_WineLook == WIN31_LOOK || !(wndPtr->dwStyle & (BS_ICON|BS_BITMAP))) )
468 LOGBRUSH lb;
469 GetObjectA( GetSysColorBrush(COLOR_BTNFACE), sizeof(lb), &lb );
470 if (wndPtr->dwStyle & WS_DISABLED &&
471 GetSysColor(COLOR_GRAYTEXT)==lb.lbColor)
472 /* don't write gray text on gray background */
473 PaintGrayOnGray( hDC,infoPtr->hFont,&rc,wndPtr->text,
474 DT_CENTER | DT_VCENTER );
475 else
477 SetTextColor( hDC, (wndPtr->dwStyle & WS_DISABLED) ?
478 GetSysColor(COLOR_GRAYTEXT) :
479 GetSysColor(COLOR_BTNTEXT) );
480 DrawTextA( hDC, wndPtr->text, -1, &rc,
481 DT_SINGLELINE | DT_CENTER | DT_VCENTER );
482 /* do we have the focus?
483 * Win9x draws focus last with a size prop. to the button
485 if (TWEAK_WineLook == WIN31_LOOK
486 && infoPtr->state & BUTTON_HASFOCUS)
488 RECT r = { 0, 0, 0, 0 };
489 INT xdelta, ydelta;
491 DrawTextA( hDC, wndPtr->text, -1, &r,
492 DT_SINGLELINE | DT_CALCRECT );
493 xdelta = ((rc.right - rc.left) - (r.right - r.left) - 1) / 2;
494 ydelta = ((rc.bottom - rc.top) - (r.bottom - r.top) - 1) / 2;
495 if (xdelta < 0) xdelta = 0;
496 if (ydelta < 0) ydelta = 0;
497 InflateRect( &rc, -xdelta, -ydelta );
498 DrawFocusRect( hDC, &rc );
502 if ( ((wndPtr->dwStyle & BS_ICON) || (wndPtr->dwStyle & BS_BITMAP) ) &&
503 (infoPtr->hImage != 0) )
505 int yOffset, xOffset;
506 int imageWidth, imageHeight;
509 * We extract the size of the image from the handle.
511 if (wndPtr->dwStyle & BS_ICON)
513 ICONINFO iconInfo;
514 BITMAP bm;
516 GetIconInfo((HICON)infoPtr->hImage, &iconInfo);
517 GetObjectA (iconInfo.hbmColor, sizeof(BITMAP), &bm);
519 imageWidth = bm.bmWidth;
520 imageHeight = bm.bmHeight;
522 DeleteObject(iconInfo.hbmColor);
523 DeleteObject(iconInfo.hbmMask);
526 else
528 BITMAP bm;
530 GetObjectA (infoPtr->hImage, sizeof(BITMAP), &bm);
532 imageWidth = bm.bmWidth;
533 imageHeight = bm.bmHeight;
536 /* Center the bitmap */
537 xOffset = (((rc.right - rc.left) - 2*xBorderOffset) - imageWidth ) / 2;
538 yOffset = (((rc.bottom - rc.top) - 2*yBorderOffset) - imageHeight) / 2;
540 /* If the image is too big for the button then create a region*/
541 if(xOffset < 0 || yOffset < 0)
543 HRGN hBitmapRgn = 0;
544 hBitmapRgn = CreateRectRgn(
545 rc.left + xBorderOffset, rc.top +yBorderOffset,
546 rc.right - xBorderOffset, rc.bottom - yBorderOffset);
547 SelectClipRgn(hDC, hBitmapRgn);
548 DeleteObject(hBitmapRgn);
551 /* Let minimum 1 space from border */
552 xOffset++, yOffset++;
555 * Draw the image now.
557 if (wndPtr->dwStyle & BS_ICON)
559 DrawIcon(hDC,
560 rc.left + xOffset, rc.top + yOffset,
561 (HICON)infoPtr->hImage);
563 else
565 HDC hdcMem;
567 hdcMem = CreateCompatibleDC (hDC);
568 SelectObject (hdcMem, (HBITMAP)infoPtr->hImage);
569 BitBlt(hDC,
570 rc.left + xOffset,
571 rc.top + yOffset,
572 imageWidth, imageHeight,
573 hdcMem, 0, 0, SRCCOPY);
575 DeleteDC (hdcMem);
578 if(xOffset < 0 || yOffset < 0)
580 SelectClipRgn(hDC, 0);
584 if (TWEAK_WineLook != WIN31_LOOK
585 && infoPtr->state & BUTTON_HASFOCUS)
587 InflateRect( &focus_rect, -1, -1 );
588 DrawFocusRect( hDC, &focus_rect );
592 SelectObject( hDC, hOldPen );
593 SelectObject( hDC, hOldBrush );
597 /**********************************************************************
598 * PB_Paint & CB_Paint sub function [internal]
599 * Paint text using a raster brush to avoid gray text on gray
600 * background. 'format' can be a combination of DT_CENTER and
601 * DT_VCENTER to use this function in both PB_PAINT and
602 * CB_PAINT. - Dirk Thierbach
604 * FIXME: This and TEXT_GrayString should be eventually combined,
605 * so calling one common function from PB_Paint, CB_Paint and
606 * TEXT_GrayString will be enough. Also note that this
607 * function ignores the CACHE_GetPattern funcs.
610 void PaintGrayOnGray(HDC hDC,HFONT hFont,RECT *rc,char *text,
611 UINT format)
613 /* This is the standard gray on gray pattern:
614 static const WORD Pattern[] = {0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55};
616 /* This pattern gives better readability with X Fonts.
617 FIXME: Maybe the user should be allowed to decide which he wants. */
618 static const WORD Pattern[] = {0x55,0xFF,0xAA,0xFF,0x55,0xFF,0xAA,0xFF};
620 HBITMAP hbm = CreateBitmap( 8, 8, 1, 1, Pattern );
621 HDC hdcMem = CreateCompatibleDC(hDC);
622 HBITMAP hbmMem;
623 HBRUSH hBr;
624 RECT rect,rc2;
626 rect=*rc;
627 DrawTextA( hDC, text, -1, &rect, DT_SINGLELINE | DT_CALCRECT);
628 /* now text width and height are in rect.right and rect.bottom */
629 rc2=rect;
630 rect.left = rect.top = 0; /* drawing pos in hdcMem */
631 if (format & DT_CENTER) rect.left=(rc->right-rect.right)/2;
632 if (format & DT_VCENTER) rect.top=(rc->bottom-rect.bottom)/2;
633 hbmMem = CreateCompatibleBitmap( hDC,rect.right,rect.bottom );
634 SelectObject( hdcMem, hbmMem);
635 PatBlt( hdcMem,0,0,rect.right,rect.bottom,WHITENESS);
636 /* will be overwritten by DrawText, but just in case */
637 if (hFont) SelectObject( hdcMem, hFont);
638 DrawTextA( hdcMem, text, -1, &rc2, DT_SINGLELINE);
639 /* After draw: foreground = 0 bits, background = 1 bits */
640 hBr = SelectObject( hdcMem, CreatePatternBrush(hbm) );
641 DeleteObject( hbm );
642 PatBlt( hdcMem,0,0,rect.right,rect.bottom,0xAF0229);
643 /* only keep the foreground bits where pattern is 1 */
644 DeleteObject( SelectObject( hdcMem,hBr) );
645 BitBlt(hDC,rect.left,rect.top,rect.right,rect.bottom,hdcMem,0,0,SRCAND);
646 /* keep the background of the dest */
647 DeleteDC( hdcMem);
648 DeleteObject( hbmMem );
652 /**********************************************************************
653 * Check Box & Radio Button Functions
656 static void CB_Paint( WND *wndPtr, HDC hDC, WORD action )
658 RECT rbox, rtext, client;
659 HBRUSH hBrush;
660 int textlen, delta;
661 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
664 * if the button has a bitmap/icon, draw a normal pushbutton
665 * instead of a radion button.
667 if (infoPtr->hImage != 0)
669 BOOL bHighLighted = ((infoPtr->state & BUTTON_HIGHLIGHTED) ||
670 (infoPtr->state & BUTTON_CHECKED));
672 BUTTON_DrawPushButton(wndPtr,
673 hDC,
674 action,
675 bHighLighted);
676 return;
679 textlen = 0;
680 GetClientRect(wndPtr->hwndSelf, &client);
681 rbox = rtext = client;
683 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
685 /* Something is still not right, checkboxes (and edit controls)
686 * in wsping32 have white backgrounds instead of dark grey.
687 * BUTTON_SEND_CTLCOLOR() is even worse since it returns 0 in this
688 * particular case and the background is not painted at all.
691 hBrush = GetControlBrush16( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
693 if (wndPtr->dwStyle & BS_LEFTTEXT)
695 /* magic +4 is what CTL3D expects */
697 rtext.right -= checkBoxWidth + 4;
698 rbox.left = rbox.right - checkBoxWidth;
700 else
702 rtext.left += checkBoxWidth + 4;
703 rbox.right = checkBoxWidth;
706 /* Draw the check-box bitmap */
708 if (wndPtr->text) textlen = strlen( wndPtr->text );
709 if (action == ODA_DRAWENTIRE || action == ODA_SELECT)
711 if( TWEAK_WineLook == WIN31_LOOK )
713 HDC hMemDC = CreateCompatibleDC( hDC );
714 int x = 0, y = 0;
715 delta = (rbox.bottom - rbox.top - checkBoxHeight) / 2;
717 /* Check in case the client area is smaller than the checkbox bitmap */
718 if (delta < 0) delta = 0;
720 if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush );
721 else FillRect( hDC, &client, hBrush );
723 if (infoPtr->state & BUTTON_HIGHLIGHTED) x += 2 * checkBoxWidth;
724 if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE)) x += checkBoxWidth;
725 if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) ||
726 ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) y += checkBoxHeight;
727 else if (infoPtr->state & BUTTON_3STATE) y += 2 * checkBoxHeight;
729 /* The bitmap for the radio button is not aligned with the
730 * left of the window, it is 1 pixel off. */
731 if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) ||
732 ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON))
733 rbox.left += 1;
735 SelectObject( hMemDC, hbitmapCheckBoxes );
736 BitBlt( hDC, rbox.left, rbox.top + delta, checkBoxWidth,
737 checkBoxHeight, hMemDC, x, y, SRCCOPY );
738 DeleteDC( hMemDC );
740 else
742 UINT state;
744 if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) ||
745 ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) state = DFCS_BUTTONRADIO;
746 else if (infoPtr->state & BUTTON_3STATE) state = DFCS_BUTTON3STATE;
747 else state = DFCS_BUTTONCHECK;
749 if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE)) state |= DFCS_CHECKED;
751 if (infoPtr->state & BUTTON_HIGHLIGHTED) state |= DFCS_PUSHED;
753 if (wndPtr->dwStyle & WS_DISABLED) state |= DFCS_INACTIVE;
755 DrawFrameControl( hDC, &rbox, DFC_BUTTON, state );
759 if( textlen && action != ODA_SELECT )
761 if (wndPtr->dwStyle & WS_DISABLED &&
762 GetSysColor(COLOR_GRAYTEXT)==GetBkColor(hDC)) {
763 /* don't write gray text on gray background */
764 PaintGrayOnGray( hDC, infoPtr->hFont, &rtext, wndPtr->text,
765 DT_VCENTER);
766 } else {
767 if (wndPtr->dwStyle & WS_DISABLED)
768 SetTextColor( hDC, GetSysColor(COLOR_GRAYTEXT) );
769 DrawTextA( hDC, wndPtr->text, textlen, &rtext,
770 DT_SINGLELINE | DT_VCENTER );
775 if ((action == ODA_FOCUS) ||
776 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
778 /* again, this is what CTL3D expects */
780 SetRectEmpty(&rbox);
781 if( textlen )
782 DrawTextA( hDC, wndPtr->text, textlen, &rbox,
783 DT_SINGLELINE | DT_CALCRECT );
784 textlen = rbox.bottom - rbox.top;
785 delta = ((rtext.bottom - rtext.top) - textlen)/2;
786 rbox.bottom = (rbox.top = rtext.top + delta - 1) + textlen + 2;
787 textlen = rbox.right - rbox.left;
788 rbox.right = (rbox.left += --rtext.left) + textlen + 2;
789 IntersectRect(&rbox, &rbox, &rtext);
790 DrawFocusRect( hDC, &rbox );
795 /**********************************************************************
796 * BUTTON_CheckAutoRadioButton
798 * wndPtr is checked, uncheck every other auto radio button in group
800 static void BUTTON_CheckAutoRadioButton( WND *wndPtr )
802 HWND parent, sibling, start;
803 if (!(wndPtr->dwStyle & WS_CHILD)) return;
804 parent = wndPtr->parent->hwndSelf;
805 /* assure that starting control is not disabled or invisible */
806 start = sibling = GetNextDlgGroupItem( parent, wndPtr->hwndSelf, TRUE );
809 WND *tmpWnd;
810 if (!sibling) break;
811 tmpWnd = WIN_FindWndPtr(sibling);
812 if ((wndPtr->hwndSelf != sibling) &&
813 ((tmpWnd->dwStyle & 0x0f) == BS_AUTORADIOBUTTON))
814 SendMessageA( sibling, BM_SETCHECK, BUTTON_UNCHECKED, 0 );
815 sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
816 WIN_ReleaseWndPtr(tmpWnd);
817 } while (sibling != start);
821 /**********************************************************************
822 * Group Box Functions
825 static void GB_Paint( WND *wndPtr, HDC hDC, WORD action )
827 RECT rc, rcFrame;
828 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
830 if (action != ODA_DRAWENTIRE) return;
832 BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
834 GetClientRect( wndPtr->hwndSelf, &rc);
835 if (TWEAK_WineLook == WIN31_LOOK) {
836 HPEN hPrevPen = SelectObject( hDC,
837 GetSysColorPen(COLOR_WINDOWFRAME));
838 HBRUSH hPrevBrush = SelectObject( hDC,
839 GetStockObject(NULL_BRUSH) );
841 Rectangle( hDC, rc.left, rc.top + 2, rc.right - 1, rc.bottom - 1 );
842 SelectObject( hDC, hPrevBrush );
843 SelectObject( hDC, hPrevPen );
844 } else {
845 TEXTMETRICA tm;
846 rcFrame = rc;
848 if (infoPtr->hFont)
849 SelectObject (hDC, infoPtr->hFont);
850 GetTextMetricsA (hDC, &tm);
851 rcFrame.top += (tm.tmHeight / 2) - 1;
852 DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT);
855 if (wndPtr->text)
857 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
858 if (wndPtr->dwStyle & WS_DISABLED)
859 SetTextColor( hDC, GetSysColor(COLOR_GRAYTEXT) );
860 rc.left += 10;
861 DrawTextA( hDC, wndPtr->text, -1, &rc, DT_SINGLELINE | DT_NOCLIP );
866 /**********************************************************************
867 * User Button Functions
870 static void UB_Paint( WND *wndPtr, HDC hDC, WORD action )
872 RECT rc;
873 HBRUSH hBrush;
874 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
876 if (action == ODA_SELECT) return;
878 GetClientRect( wndPtr->hwndSelf, &rc);
880 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
881 hBrush = GetControlBrush16( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
883 FillRect( hDC, &rc, hBrush );
884 if ((action == ODA_FOCUS) ||
885 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
886 DrawFocusRect( hDC, &rc );
890 /**********************************************************************
891 * Ownerdrawn Button Functions
894 static void OB_Paint( WND *wndPtr, HDC hDC, WORD action )
896 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
897 DRAWITEMSTRUCT dis;
899 dis.CtlType = ODT_BUTTON;
900 dis.CtlID = wndPtr->wIDmenu;
901 dis.itemID = 0;
902 dis.itemAction = action;
903 dis.itemState = ((infoPtr->state & BUTTON_HASFOCUS) ? ODS_FOCUS : 0) |
904 ((infoPtr->state & BUTTON_HIGHLIGHTED) ? ODS_SELECTED : 0) |
905 ((wndPtr->dwStyle & WS_DISABLED) ? ODS_DISABLED : 0);
906 dis.hwndItem = wndPtr->hwndSelf;
907 dis.hDC = hDC;
908 dis.itemData = 0;
909 GetClientRect( wndPtr->hwndSelf, &dis.rcItem );
911 SetBkColor( hDC, GetSysColor( COLOR_BTNFACE ) );
913 SendMessageA( GetParent(wndPtr->hwndSelf), WM_DRAWITEM,
914 wndPtr->wIDmenu, (LPARAM)&dis );