Real implementation of SHRestricted(), clarified SHInitRestricted()'s
[wine/wine64.git] / controls / button.c
blob50e816007f9cd926863ad2dcb49e587b773b793d
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_LBUTTONDBLCLK:
140 if(wndPtr->dwStyle & BS_NOTIFY ||
141 style==BS_RADIOBUTTON ||
142 style==BS_USERBUTTON ||
143 style==BS_OWNERDRAW) {
144 SendMessageA( GetParent(hWnd), WM_COMMAND,
145 MAKEWPARAM( wndPtr->wIDmenu, BN_DOUBLECLICKED ), hWnd);
146 break;
148 /* fall through */
149 case WM_LBUTTONDOWN:
150 SetCapture( hWnd );
151 SetFocus( hWnd );
152 SendMessageA( hWnd, BM_SETSTATE, TRUE, 0 );
153 infoPtr->state |= BUTTON_BTNPRESSED;
154 break;
156 case WM_LBUTTONUP:
157 if (!(infoPtr->state & BUTTON_BTNPRESSED)) break;
158 infoPtr->state &= BUTTON_NSTATES;
159 if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) {
160 ReleaseCapture();
161 break;
163 SendMessageA( hWnd, BM_SETSTATE, FALSE, 0 );
164 ReleaseCapture();
165 GetClientRect( hWnd, &rect );
166 if (PtInRect( &rect, pt ))
168 switch(style)
170 case BS_AUTOCHECKBOX:
171 SendMessageA( hWnd, BM_SETCHECK,
172 !(infoPtr->state & BUTTON_CHECKED), 0 );
173 break;
174 case BS_AUTORADIOBUTTON:
175 SendMessageA( hWnd, BM_SETCHECK, TRUE, 0 );
176 break;
177 case BS_AUTO3STATE:
178 SendMessageA( hWnd, BM_SETCHECK,
179 (infoPtr->state & BUTTON_3STATE) ? 0 :
180 ((infoPtr->state & 3) + 1), 0 );
181 break;
183 SendMessageA( GetParent(hWnd), WM_COMMAND,
184 MAKEWPARAM( wndPtr->wIDmenu, BN_CLICKED ), hWnd);
186 break;
188 case WM_CAPTURECHANGED:
189 if (infoPtr->state & BUTTON_BTNPRESSED) {
190 infoPtr->state &= BUTTON_NSTATES;
191 if (infoPtr->state & BUTTON_HIGHLIGHTED)
192 SendMessageA( hWnd, BM_SETSTATE, FALSE, 0 );
194 break;
196 case WM_MOUSEMOVE:
197 if (GetCapture() == hWnd)
199 GetClientRect( hWnd, &rect );
200 SendMessageA( hWnd, BM_SETSTATE, PtInRect(&rect, pt), 0 );
202 break;
204 case WM_NCHITTEST:
205 if(style == BS_GROUPBOX) return HTTRANSPARENT;
206 return DefWindowProcA( hWnd, uMsg, wParam, lParam );
208 case WM_SETTEXT:
209 DEFWND_SetText( wndPtr, (LPCSTR)lParam );
210 if( wndPtr->dwStyle & WS_VISIBLE )
211 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
212 return 0;
214 case WM_SETFONT:
215 infoPtr->hFont = (HFONT16)wParam;
216 if (lParam && (wndPtr->dwStyle & WS_VISIBLE))
217 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
218 break;
220 case WM_GETFONT:
221 return infoPtr->hFont;
223 case WM_SETFOCUS:
224 if ((style == BS_AUTORADIOBUTTON) && (GetCapture() != hWnd) &&
225 !(SendMessageA(hWnd, BM_GETCHECK, 0, 0) & BST_CHECKED))
227 /* The notification is sent when the button (BS_AUTORADIOBUTTON)
228 is unckecked and the focus was not given by a mouse click. */
229 SendMessageA( hWnd, BM_SETCHECK, TRUE, 0 );
230 SendMessageA( GetParent(hWnd), WM_COMMAND,
231 MAKEWPARAM( wndPtr->wIDmenu, BN_CLICKED ), hWnd);
233 infoPtr->state |= BUTTON_HASFOCUS;
234 PAINT_BUTTON( wndPtr, style, ODA_FOCUS );
235 break;
237 case WM_KILLFOCUS:
238 infoPtr->state &= ~BUTTON_HASFOCUS;
239 PAINT_BUTTON( wndPtr, style, ODA_FOCUS );
240 InvalidateRect( hWnd, NULL, TRUE );
241 break;
243 case WM_SYSCOLORCHANGE:
244 InvalidateRect( hWnd, NULL, FALSE );
245 break;
247 case BM_SETSTYLE16:
248 case BM_SETSTYLE:
249 if ((wParam & 0x0f) >= MAX_BTN_TYPE) break;
250 wndPtr->dwStyle = (wndPtr->dwStyle & 0xfffffff0)
251 | (wParam & 0x0000000f);
252 style = wndPtr->dwStyle & 0x0000000f;
253 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
254 break;
256 case BM_SETIMAGE:
257 oldHbitmap = infoPtr->hImage;
258 if ((wndPtr->dwStyle & BS_BITMAP) || (wndPtr->dwStyle & BS_ICON))
259 infoPtr->hImage = (HANDLE) lParam;
260 return oldHbitmap;
262 case BM_GETIMAGE:
263 if (wParam == IMAGE_BITMAP)
264 return (HBITMAP)infoPtr->hImage;
265 else if (wParam == IMAGE_ICON)
266 return (HICON)infoPtr->hImage;
267 else
268 return NULL;
270 case BM_GETCHECK16:
271 case BM_GETCHECK:
272 return infoPtr->state & 3;
274 case BM_SETCHECK16:
275 case BM_SETCHECK:
276 if (wParam > maxCheckState[style]) wParam = maxCheckState[style];
277 if ((infoPtr->state & 3) != wParam)
279 if ((style == BS_RADIOBUTTON) || (style == BS_AUTORADIOBUTTON))
281 if (wParam)
282 wndPtr->dwStyle |= WS_TABSTOP;
283 else
284 wndPtr->dwStyle &= ~WS_TABSTOP;
286 infoPtr->state = (infoPtr->state & ~3) | wParam;
287 PAINT_BUTTON( wndPtr, style, ODA_SELECT );
289 if ((style == BS_AUTORADIOBUTTON) && (wParam == BUTTON_CHECKED))
290 BUTTON_CheckAutoRadioButton( wndPtr );
291 break;
293 case BM_GETSTATE16:
294 case BM_GETSTATE:
295 return infoPtr->state;
297 case BM_SETSTATE16:
298 case BM_SETSTATE:
299 if (wParam)
301 if (infoPtr->state & BUTTON_HIGHLIGHTED) break;
302 infoPtr->state |= BUTTON_HIGHLIGHTED;
304 else
306 if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) break;
307 infoPtr->state &= ~BUTTON_HIGHLIGHTED;
309 PAINT_BUTTON( wndPtr, style, ODA_SELECT );
310 break;
312 default:
313 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
315 return 0;
318 /***********************************************************************
319 * ButtonWndProc
320 * The button window procedure. This is just a wrapper which locks
321 * the passed HWND and calls the real window procedure (with a WND*
322 * pointer pointing to the locked windowstructure).
324 LRESULT WINAPI ButtonWndProc( HWND hWnd, UINT uMsg,
325 WPARAM wParam, LPARAM lParam )
327 LRESULT res;
328 WND *wndPtr = WIN_FindWndPtr(hWnd);
330 res = ButtonWndProc_locked(wndPtr,uMsg,wParam,lParam);
332 WIN_ReleaseWndPtr(wndPtr);
333 return res;
336 /**********************************************************************
337 * Push Button Functions
339 static void PB_Paint( WND *wndPtr, HDC hDC, WORD action )
341 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
342 BOOL bHighLighted = (infoPtr->state & BUTTON_HIGHLIGHTED);
345 * Delegate this to the more generic pushbutton painting
346 * method.
348 BUTTON_DrawPushButton(wndPtr,
349 hDC,
350 action,
351 bHighLighted);
354 /**********************************************************************
355 * This method will actually do the drawing of the pushbutton
356 * depending on it's state and the pushedState parameter.
358 static void BUTTON_DrawPushButton(
359 WND* wndPtr,
360 HDC hDC,
361 WORD action,
362 BOOL pushedState )
364 RECT rc, focus_rect;
365 HPEN hOldPen;
366 HBRUSH hOldBrush;
367 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
368 int xBorderOffset, yBorderOffset;
369 xBorderOffset = yBorderOffset = 0;
371 GetClientRect( wndPtr->hwndSelf, &rc );
373 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
374 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
375 BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
376 hOldPen = (HPEN)SelectObject(hDC, GetSysColorPen(COLOR_WINDOWFRAME));
377 hOldBrush =(HBRUSH)SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE));
378 SetBkMode(hDC, TRANSPARENT);
380 if ( TWEAK_WineLook == WIN31_LOOK)
382 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
384 SetPixel( hDC, rc.left, rc.top, GetSysColor(COLOR_WINDOW) );
385 SetPixel( hDC, rc.left, rc.bottom-1, GetSysColor(COLOR_WINDOW) );
386 SetPixel( hDC, rc.right-1, rc.top, GetSysColor(COLOR_WINDOW) );
387 SetPixel( hDC, rc.right-1, rc.bottom-1, GetSysColor(COLOR_WINDOW));
388 InflateRect( &rc, -1, -1 );
391 if ((wndPtr->dwStyle & 0x000f) == BS_DEFPUSHBUTTON)
393 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
394 InflateRect( &rc, -1, -1 );
397 if (TWEAK_WineLook == WIN31_LOOK)
399 if (pushedState)
401 /* draw button shadow: */
402 SelectObject(hDC, GetSysColorBrush(COLOR_BTNSHADOW));
403 PatBlt(hDC, rc.left, rc.top, 1, rc.bottom-rc.top, PATCOPY );
404 PatBlt(hDC, rc.left, rc.top, rc.right-rc.left, 1, PATCOPY );
405 rc.left += 2; /* To position the text down and right */
406 rc.top += 2;
407 } else {
408 rc.right++, rc.bottom++;
409 DrawEdge( hDC, &rc, EDGE_RAISED, BF_RECT );
411 /* To place de bitmap correctly */
412 xBorderOffset += GetSystemMetrics(SM_CXEDGE);
413 yBorderOffset += GetSystemMetrics(SM_CYEDGE);
415 rc.right--, rc.bottom--;
418 else
420 UINT uState = DFCS_BUTTONPUSH;
422 if (pushedState)
424 if ( (wndPtr->dwStyle & 0x000f) == BS_DEFPUSHBUTTON )
425 uState |= DFCS_FLAT;
426 else
427 uState |= DFCS_PUSHED;
430 DrawFrameControl( hDC, &rc, DFC_BUTTON, uState );
431 InflateRect( &rc, -2, -2 );
433 focus_rect = rc;
435 if (pushedState)
437 rc.left += 2; /* To position the text down and right */
438 rc.top += 2;
442 /* draw button label, if any:
444 * In win9x we don't show text if there is a bitmap or icon.
445 * I don't know about win31 so I leave it as it was for win31.
446 * Dennis Björklund 12 Jul, 99
448 if ( wndPtr->text && wndPtr->text[0]
449 && (TWEAK_WineLook == WIN31_LOOK || !(wndPtr->dwStyle & (BS_ICON|BS_BITMAP))) )
451 LOGBRUSH lb;
452 GetObjectA( GetSysColorBrush(COLOR_BTNFACE), sizeof(lb), &lb );
453 if (wndPtr->dwStyle & WS_DISABLED &&
454 GetSysColor(COLOR_GRAYTEXT)==lb.lbColor)
455 /* don't write gray text on gray background */
456 PaintGrayOnGray( hDC,infoPtr->hFont,&rc,wndPtr->text,
457 DT_CENTER | DT_VCENTER );
458 else
460 SetTextColor( hDC, (wndPtr->dwStyle & WS_DISABLED) ?
461 GetSysColor(COLOR_GRAYTEXT) :
462 GetSysColor(COLOR_BTNTEXT) );
463 DrawTextA( hDC, wndPtr->text, -1, &rc,
464 DT_SINGLELINE | DT_CENTER | DT_VCENTER );
465 /* do we have the focus?
466 * Win9x draws focus last with a size prop. to the button
468 if (TWEAK_WineLook == WIN31_LOOK
469 && infoPtr->state & BUTTON_HASFOCUS)
471 RECT r = { 0, 0, 0, 0 };
472 INT xdelta, ydelta;
474 DrawTextA( hDC, wndPtr->text, -1, &r,
475 DT_SINGLELINE | DT_CALCRECT );
476 xdelta = ((rc.right - rc.left) - (r.right - r.left) - 1) / 2;
477 ydelta = ((rc.bottom - rc.top) - (r.bottom - r.top) - 1) / 2;
478 if (xdelta < 0) xdelta = 0;
479 if (ydelta < 0) ydelta = 0;
480 InflateRect( &rc, -xdelta, -ydelta );
481 DrawFocusRect( hDC, &rc );
485 if ( ((wndPtr->dwStyle & BS_ICON) || (wndPtr->dwStyle & BS_BITMAP) ) &&
486 (infoPtr->hImage != NULL) )
488 int yOffset, xOffset;
489 int imageWidth, imageHeight;
492 * We extract the size of the image from the handle.
494 if (wndPtr->dwStyle & BS_ICON)
496 ICONINFO iconInfo;
497 BITMAP bm;
499 GetIconInfo((HICON)infoPtr->hImage, &iconInfo);
500 GetObjectA (iconInfo.hbmColor, sizeof(BITMAP), &bm);
502 imageWidth = bm.bmWidth;
503 imageHeight = bm.bmHeight;
505 DeleteObject(iconInfo.hbmColor);
506 DeleteObject(iconInfo.hbmMask);
509 else
511 BITMAP bm;
513 GetObjectA (infoPtr->hImage, sizeof(BITMAP), &bm);
515 imageWidth = bm.bmWidth;
516 imageHeight = bm.bmHeight;
519 /* Center the bitmap */
520 xOffset = (((rc.right - rc.left) - 2*xBorderOffset) - imageWidth ) / 2;
521 yOffset = (((rc.bottom - rc.top) - 2*yBorderOffset) - imageHeight) / 2;
523 /* If the image is too big for the button then create a region*/
524 if(xOffset < 0 || yOffset < 0)
526 HRGN hBitmapRgn = NULL;
527 hBitmapRgn = CreateRectRgn(
528 rc.left + xBorderOffset, rc.top +yBorderOffset,
529 rc.right - xBorderOffset, rc.bottom - yBorderOffset);
530 SelectClipRgn(hDC, hBitmapRgn);
531 DeleteObject(hBitmapRgn);
534 /* Let minimum 1 space from border */
535 xOffset++, yOffset++;
538 * Draw the image now.
540 if (wndPtr->dwStyle & BS_ICON)
542 DrawIcon(hDC,
543 rc.left + xOffset, rc.top + yOffset,
544 (HICON)infoPtr->hImage);
546 else
548 HDC hdcMem;
550 hdcMem = CreateCompatibleDC (hDC);
551 SelectObject (hdcMem, (HBITMAP)infoPtr->hImage);
552 BitBlt(hDC,
553 rc.left + xOffset,
554 rc.top + yOffset,
555 imageWidth, imageHeight,
556 hdcMem, 0, 0, SRCCOPY);
558 DeleteDC (hdcMem);
561 if(xOffset < 0 || yOffset < 0)
563 SelectClipRgn(hDC, NULL);
567 if (TWEAK_WineLook != WIN31_LOOK
568 && infoPtr->state & BUTTON_HASFOCUS)
570 InflateRect( &focus_rect, -1, -1 );
571 DrawFocusRect( hDC, &focus_rect );
575 SelectObject( hDC, hOldPen );
576 SelectObject( hDC, hOldBrush );
580 /**********************************************************************
581 * PB_Paint & CB_Paint sub function [internal]
582 * Paint text using a raster brush to avoid gray text on gray
583 * background. 'format' can be a combination of DT_CENTER and
584 * DT_VCENTER to use this function in both PB_PAINT and
585 * CB_PAINT. - Dirk Thierbach
587 * FIXME: This and TEXT_GrayString should be eventually combined,
588 * so calling one common function from PB_Paint, CB_Paint and
589 * TEXT_GrayString will be enough. Also note that this
590 * function ignores the CACHE_GetPattern funcs.
593 void PaintGrayOnGray(HDC hDC,HFONT hFont,RECT *rc,char *text,
594 UINT format)
596 /* This is the standard gray on gray pattern:
597 static const WORD Pattern[] = {0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55};
599 /* This pattern gives better readability with X Fonts.
600 FIXME: Maybe the user should be allowed to decide which he wants. */
601 static const WORD Pattern[] = {0x55,0xFF,0xAA,0xFF,0x55,0xFF,0xAA,0xFF};
603 HBITMAP hbm = CreateBitmap( 8, 8, 1, 1, Pattern );
604 HDC hdcMem = CreateCompatibleDC(hDC);
605 HBITMAP hbmMem;
606 HBRUSH hBr;
607 RECT rect,rc2;
609 rect=*rc;
610 DrawTextA( hDC, text, -1, &rect, DT_SINGLELINE | DT_CALCRECT);
611 /* now text width and height are in rect.right and rect.bottom */
612 rc2=rect;
613 rect.left = rect.top = 0; /* drawing pos in hdcMem */
614 if (format & DT_CENTER) rect.left=(rc->right-rect.right)/2;
615 if (format & DT_VCENTER) rect.top=(rc->bottom-rect.bottom)/2;
616 hbmMem = CreateCompatibleBitmap( hDC,rect.right,rect.bottom );
617 SelectObject( hdcMem, hbmMem);
618 PatBlt( hdcMem,0,0,rect.right,rect.bottom,WHITENESS);
619 /* will be overwritten by DrawText, but just in case */
620 if (hFont) SelectObject( hdcMem, hFont);
621 DrawTextA( hdcMem, text, -1, &rc2, DT_SINGLELINE);
622 /* After draw: foreground = 0 bits, background = 1 bits */
623 hBr = SelectObject( hdcMem, CreatePatternBrush(hbm) );
624 DeleteObject( hbm );
625 PatBlt( hdcMem,0,0,rect.right,rect.bottom,0xAF0229);
626 /* only keep the foreground bits where pattern is 1 */
627 DeleteObject( SelectObject( hdcMem,hBr) );
628 BitBlt(hDC,rect.left,rect.top,rect.right,rect.bottom,hdcMem,0,0,SRCAND);
629 /* keep the background of the dest */
630 DeleteDC( hdcMem);
631 DeleteObject( hbmMem );
635 /**********************************************************************
636 * Check Box & Radio Button Functions
639 static void CB_Paint( WND *wndPtr, HDC hDC, WORD action )
641 RECT rbox, rtext, client;
642 HBRUSH hBrush;
643 int textlen, delta;
644 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
647 * if the button has a bitmap/icon, draw a normal pushbutton
648 * instead of a radion button.
650 if (infoPtr->hImage!=NULL)
652 BOOL bHighLighted = ((infoPtr->state & BUTTON_HIGHLIGHTED) ||
653 (infoPtr->state & BUTTON_CHECKED));
655 BUTTON_DrawPushButton(wndPtr,
656 hDC,
657 action,
658 bHighLighted);
659 return;
662 textlen = 0;
663 GetClientRect(wndPtr->hwndSelf, &client);
664 rbox = rtext = client;
666 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
668 /* Something is still not right, checkboxes (and edit controls)
669 * in wsping32 have white backgrounds instead of dark grey.
670 * BUTTON_SEND_CTLCOLOR() is even worse since it returns 0 in this
671 * particular case and the background is not painted at all.
674 hBrush = GetControlBrush16( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
676 if (wndPtr->dwStyle & BS_LEFTTEXT)
678 /* magic +4 is what CTL3D expects */
680 rtext.right -= checkBoxWidth + 4;
681 rbox.left = rbox.right - checkBoxWidth;
683 else
685 rtext.left += checkBoxWidth + 4;
686 rbox.right = checkBoxWidth;
689 /* Draw the check-box bitmap */
691 if (wndPtr->text) textlen = strlen( wndPtr->text );
692 if (action == ODA_DRAWENTIRE || action == ODA_SELECT)
694 if( TWEAK_WineLook == WIN31_LOOK )
696 HDC hMemDC = CreateCompatibleDC( hDC );
697 int x = 0, y = 0;
698 delta = (rbox.bottom - rbox.top - checkBoxHeight) / 2;
700 /* Check in case the client area is smaller than the checkbox bitmap */
701 if (delta < 0) delta = 0;
703 if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush );
704 else FillRect( hDC, &client, hBrush );
706 if (infoPtr->state & BUTTON_HIGHLIGHTED) x += 2 * checkBoxWidth;
707 if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE)) x += checkBoxWidth;
708 if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) ||
709 ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) y += checkBoxHeight;
710 else if (infoPtr->state & BUTTON_3STATE) y += 2 * checkBoxHeight;
712 /* The bitmap for the radio button is not aligned with the
713 * left of the window, it is 1 pixel off. */
714 if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) ||
715 ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON))
716 rbox.left += 1;
718 SelectObject( hMemDC, hbitmapCheckBoxes );
719 BitBlt( hDC, rbox.left, rbox.top + delta, checkBoxWidth,
720 checkBoxHeight, hMemDC, x, y, SRCCOPY );
721 DeleteDC( hMemDC );
723 else
725 UINT state;
727 if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) ||
728 ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) state = DFCS_BUTTONRADIO;
729 else if (infoPtr->state & BUTTON_3STATE) state = DFCS_BUTTON3STATE;
730 else state = DFCS_BUTTONCHECK;
732 if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE)) state |= DFCS_CHECKED;
734 if (infoPtr->state & BUTTON_HIGHLIGHTED) state |= DFCS_PUSHED;
736 if (wndPtr->dwStyle & WS_DISABLED) state |= DFCS_INACTIVE;
738 DrawFrameControl( hDC, &rbox, DFC_BUTTON, state );
742 if( textlen && action != ODA_SELECT )
744 if (wndPtr->dwStyle & WS_DISABLED &&
745 GetSysColor(COLOR_GRAYTEXT)==GetBkColor(hDC)) {
746 /* don't write gray text on gray background */
747 PaintGrayOnGray( hDC, infoPtr->hFont, &rtext, wndPtr->text,
748 DT_VCENTER);
749 } else {
750 if (wndPtr->dwStyle & WS_DISABLED)
751 SetTextColor( hDC, GetSysColor(COLOR_GRAYTEXT) );
752 DrawTextA( hDC, wndPtr->text, textlen, &rtext,
753 DT_SINGLELINE | DT_VCENTER );
758 if ((action == ODA_FOCUS) ||
759 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
761 /* again, this is what CTL3D expects */
763 SetRectEmpty(&rbox);
764 if( textlen )
765 DrawTextA( hDC, wndPtr->text, textlen, &rbox,
766 DT_SINGLELINE | DT_CALCRECT );
767 textlen = rbox.bottom - rbox.top;
768 delta = ((rtext.bottom - rtext.top) - textlen)/2;
769 rbox.bottom = (rbox.top = rtext.top + delta - 1) + textlen + 2;
770 textlen = rbox.right - rbox.left;
771 rbox.right = (rbox.left += --rtext.left) + textlen + 2;
772 IntersectRect(&rbox, &rbox, &rtext);
773 DrawFocusRect( hDC, &rbox );
778 /**********************************************************************
779 * BUTTON_CheckAutoRadioButton
781 * wndPtr is checked, uncheck every other auto radio button in group
783 static void BUTTON_CheckAutoRadioButton( WND *wndPtr )
785 HWND parent, sibling, start;
786 if (!(wndPtr->dwStyle & WS_CHILD)) return;
787 parent = wndPtr->parent->hwndSelf;
788 /* assure that starting control is not disabled or invisible */
789 start = sibling = GetNextDlgGroupItem( parent, wndPtr->hwndSelf, TRUE );
792 WND *tmpWnd;
793 if (!sibling) break;
794 tmpWnd = WIN_FindWndPtr(sibling);
795 if ((wndPtr->hwndSelf != sibling) &&
796 ((tmpWnd->dwStyle & 0x0f) == BS_AUTORADIOBUTTON))
797 SendMessageA( sibling, BM_SETCHECK, BUTTON_UNCHECKED, 0 );
798 sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
799 WIN_ReleaseWndPtr(tmpWnd);
800 } while (sibling != start);
804 /**********************************************************************
805 * Group Box Functions
808 static void GB_Paint( WND *wndPtr, HDC hDC, WORD action )
810 RECT rc, rcFrame;
811 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
813 if (action != ODA_DRAWENTIRE) return;
815 BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
817 GetClientRect( wndPtr->hwndSelf, &rc);
818 if (TWEAK_WineLook == WIN31_LOOK) {
819 HPEN hPrevPen = SelectObject( hDC,
820 GetSysColorPen(COLOR_WINDOWFRAME));
821 HBRUSH hPrevBrush = SelectObject( hDC,
822 GetStockObject(NULL_BRUSH) );
824 Rectangle( hDC, rc.left, rc.top + 2, rc.right - 1, rc.bottom - 1 );
825 SelectObject( hDC, hPrevBrush );
826 SelectObject( hDC, hPrevPen );
827 } else {
828 TEXTMETRICA tm;
829 rcFrame = rc;
831 if (infoPtr->hFont)
832 SelectObject (hDC, infoPtr->hFont);
833 GetTextMetricsA (hDC, &tm);
834 rcFrame.top += (tm.tmHeight / 2) - 1;
835 DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT);
838 if (wndPtr->text)
840 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
841 if (wndPtr->dwStyle & WS_DISABLED)
842 SetTextColor( hDC, GetSysColor(COLOR_GRAYTEXT) );
843 rc.left += 10;
844 DrawTextA( hDC, wndPtr->text, -1, &rc, DT_SINGLELINE | DT_NOCLIP );
849 /**********************************************************************
850 * User Button Functions
853 static void UB_Paint( WND *wndPtr, HDC hDC, WORD action )
855 RECT rc;
856 HBRUSH hBrush;
857 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
859 if (action == ODA_SELECT) return;
861 GetClientRect( wndPtr->hwndSelf, &rc);
863 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
864 hBrush = GetControlBrush16( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
866 FillRect( hDC, &rc, hBrush );
867 if ((action == ODA_FOCUS) ||
868 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
869 DrawFocusRect( hDC, &rc );
873 /**********************************************************************
874 * Ownerdrawn Button Functions
877 static void OB_Paint( WND *wndPtr, HDC hDC, WORD action )
879 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
880 DRAWITEMSTRUCT dis;
882 dis.CtlType = ODT_BUTTON;
883 dis.CtlID = wndPtr->wIDmenu;
884 dis.itemID = 0;
885 dis.itemAction = action;
886 dis.itemState = ((infoPtr->state & BUTTON_HASFOCUS) ? ODS_FOCUS : 0) |
887 ((infoPtr->state & BUTTON_HIGHLIGHTED) ? ODS_SELECTED : 0) |
888 ((wndPtr->dwStyle & WS_DISABLED) ? ODS_DISABLED : 0);
889 dis.hwndItem = wndPtr->hwndSelf;
890 dis.hDC = hDC;
891 dis.itemData = 0;
892 GetClientRect( wndPtr->hwndSelf, &dis.rcItem );
894 SetBkColor( hDC, GetSysColor( COLOR_BTNFACE ) );
896 SendMessageA( GetParent(wndPtr->hwndSelf), WM_DRAWITEM,
897 wndPtr->wIDmenu, (LPARAM)&dis );