Implemented _TrackMouseEvent for the TME_LEAVE flag.
[wine/multimedia.git] / controls / button.c
blob7d9097b778a216037bd635b7bed0b099746c276d
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_SETIMAGE:
269 oldHbitmap = infoPtr->hImage;
270 if ((wndPtr->dwStyle & BS_BITMAP) || (wndPtr->dwStyle & BS_ICON))
271 infoPtr->hImage = (HANDLE) lParam;
272 return oldHbitmap;
274 case BM_GETIMAGE:
275 if (wParam == IMAGE_BITMAP)
276 return (HBITMAP)infoPtr->hImage;
277 else if (wParam == IMAGE_ICON)
278 return (HICON)infoPtr->hImage;
279 else
280 return (HICON)0;
282 case BM_GETCHECK16:
283 case BM_GETCHECK:
284 return infoPtr->state & 3;
286 case BM_SETCHECK16:
287 case BM_SETCHECK:
288 if (wParam > maxCheckState[style]) wParam = maxCheckState[style];
289 if ((infoPtr->state & 3) != wParam)
291 if ((style == BS_RADIOBUTTON) || (style == BS_AUTORADIOBUTTON))
293 if (wParam)
294 wndPtr->dwStyle |= WS_TABSTOP;
295 else
296 wndPtr->dwStyle &= ~WS_TABSTOP;
298 infoPtr->state = (infoPtr->state & ~3) | wParam;
299 PAINT_BUTTON( wndPtr, style, ODA_SELECT );
301 if ((style == BS_AUTORADIOBUTTON) && (wParam == BUTTON_CHECKED))
302 BUTTON_CheckAutoRadioButton( wndPtr );
303 break;
305 case BM_GETSTATE16:
306 case BM_GETSTATE:
307 return infoPtr->state;
309 case BM_SETSTATE16:
310 case BM_SETSTATE:
311 if (wParam)
313 if (infoPtr->state & BUTTON_HIGHLIGHTED) break;
314 infoPtr->state |= BUTTON_HIGHLIGHTED;
316 else
318 if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) break;
319 infoPtr->state &= ~BUTTON_HIGHLIGHTED;
321 PAINT_BUTTON( wndPtr, style, ODA_SELECT );
322 break;
324 default:
325 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
327 return 0;
330 /***********************************************************************
331 * ButtonWndProc
332 * The button window procedure. This is just a wrapper which locks
333 * the passed HWND and calls the real window procedure (with a WND*
334 * pointer pointing to the locked windowstructure).
336 LRESULT WINAPI ButtonWndProc( HWND hWnd, UINT uMsg,
337 WPARAM wParam, LPARAM lParam )
339 LRESULT res;
340 WND *wndPtr = WIN_FindWndPtr(hWnd);
342 res = ButtonWndProc_locked(wndPtr,uMsg,wParam,lParam);
344 WIN_ReleaseWndPtr(wndPtr);
345 return res;
348 /**********************************************************************
349 * Push Button Functions
351 static void PB_Paint( WND *wndPtr, HDC hDC, WORD action )
353 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
354 BOOL bHighLighted = (infoPtr->state & BUTTON_HIGHLIGHTED);
357 * Delegate this to the more generic pushbutton painting
358 * method.
360 BUTTON_DrawPushButton(wndPtr,
361 hDC,
362 action,
363 bHighLighted);
366 /**********************************************************************
367 * This method will actually do the drawing of the pushbutton
368 * depending on it's state and the pushedState parameter.
370 static void BUTTON_DrawPushButton(
371 WND* wndPtr,
372 HDC hDC,
373 WORD action,
374 BOOL pushedState )
376 RECT rc, focus_rect;
377 HPEN hOldPen;
378 HBRUSH hOldBrush;
379 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
380 int xBorderOffset, yBorderOffset;
381 xBorderOffset = yBorderOffset = 0;
383 GetClientRect( wndPtr->hwndSelf, &rc );
385 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
386 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
387 BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
388 hOldPen = (HPEN)SelectObject(hDC, GetSysColorPen(COLOR_WINDOWFRAME));
389 hOldBrush =(HBRUSH)SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE));
390 SetBkMode(hDC, TRANSPARENT);
392 if ( TWEAK_WineLook == WIN31_LOOK)
394 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
396 SetPixel( hDC, rc.left, rc.top, GetSysColor(COLOR_WINDOW) );
397 SetPixel( hDC, rc.left, rc.bottom-1, GetSysColor(COLOR_WINDOW) );
398 SetPixel( hDC, rc.right-1, rc.top, GetSysColor(COLOR_WINDOW) );
399 SetPixel( hDC, rc.right-1, rc.bottom-1, GetSysColor(COLOR_WINDOW));
400 InflateRect( &rc, -1, -1 );
403 if ((wndPtr->dwStyle & 0x000f) == BS_DEFPUSHBUTTON)
405 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
406 InflateRect( &rc, -1, -1 );
409 if (TWEAK_WineLook == WIN31_LOOK)
411 if (pushedState)
413 /* draw button shadow: */
414 SelectObject(hDC, GetSysColorBrush(COLOR_BTNSHADOW));
415 PatBlt(hDC, rc.left, rc.top, 1, rc.bottom-rc.top, PATCOPY );
416 PatBlt(hDC, rc.left, rc.top, rc.right-rc.left, 1, PATCOPY );
417 rc.left += 2; /* To position the text down and right */
418 rc.top += 2;
419 } else {
420 rc.right++, rc.bottom++;
421 DrawEdge( hDC, &rc, EDGE_RAISED, BF_RECT );
423 /* To place de bitmap correctly */
424 xBorderOffset += GetSystemMetrics(SM_CXEDGE);
425 yBorderOffset += GetSystemMetrics(SM_CYEDGE);
427 rc.right--, rc.bottom--;
430 else
432 UINT uState = DFCS_BUTTONPUSH;
434 if (pushedState)
436 if ( (wndPtr->dwStyle & 0x000f) == BS_DEFPUSHBUTTON )
437 uState |= DFCS_FLAT;
438 else
439 uState |= DFCS_PUSHED;
442 DrawFrameControl( hDC, &rc, DFC_BUTTON, uState );
443 InflateRect( &rc, -2, -2 );
445 focus_rect = rc;
447 if (pushedState)
449 rc.left += 2; /* To position the text down and right */
450 rc.top += 2;
454 /* draw button label, if any:
456 * In win9x we don't show text if there is a bitmap or icon.
457 * I don't know about win31 so I leave it as it was for win31.
458 * Dennis Björklund 12 Jul, 99
460 if ( wndPtr->text && wndPtr->text[0]
461 && (TWEAK_WineLook == WIN31_LOOK || !(wndPtr->dwStyle & (BS_ICON|BS_BITMAP))) )
463 LOGBRUSH lb;
464 GetObjectA( GetSysColorBrush(COLOR_BTNFACE), sizeof(lb), &lb );
465 if (wndPtr->dwStyle & WS_DISABLED &&
466 GetSysColor(COLOR_GRAYTEXT)==lb.lbColor)
467 /* don't write gray text on gray background */
468 PaintGrayOnGray( hDC,infoPtr->hFont,&rc,wndPtr->text,
469 DT_CENTER | DT_VCENTER );
470 else
472 SetTextColor( hDC, (wndPtr->dwStyle & WS_DISABLED) ?
473 GetSysColor(COLOR_GRAYTEXT) :
474 GetSysColor(COLOR_BTNTEXT) );
475 DrawTextA( hDC, wndPtr->text, -1, &rc,
476 DT_SINGLELINE | DT_CENTER | DT_VCENTER );
477 /* do we have the focus?
478 * Win9x draws focus last with a size prop. to the button
480 if (TWEAK_WineLook == WIN31_LOOK
481 && infoPtr->state & BUTTON_HASFOCUS)
483 RECT r = { 0, 0, 0, 0 };
484 INT xdelta, ydelta;
486 DrawTextA( hDC, wndPtr->text, -1, &r,
487 DT_SINGLELINE | DT_CALCRECT );
488 xdelta = ((rc.right - rc.left) - (r.right - r.left) - 1) / 2;
489 ydelta = ((rc.bottom - rc.top) - (r.bottom - r.top) - 1) / 2;
490 if (xdelta < 0) xdelta = 0;
491 if (ydelta < 0) ydelta = 0;
492 InflateRect( &rc, -xdelta, -ydelta );
493 DrawFocusRect( hDC, &rc );
497 if ( ((wndPtr->dwStyle & BS_ICON) || (wndPtr->dwStyle & BS_BITMAP) ) &&
498 (infoPtr->hImage != 0) )
500 int yOffset, xOffset;
501 int imageWidth, imageHeight;
504 * We extract the size of the image from the handle.
506 if (wndPtr->dwStyle & BS_ICON)
508 ICONINFO iconInfo;
509 BITMAP bm;
511 GetIconInfo((HICON)infoPtr->hImage, &iconInfo);
512 GetObjectA (iconInfo.hbmColor, sizeof(BITMAP), &bm);
514 imageWidth = bm.bmWidth;
515 imageHeight = bm.bmHeight;
517 DeleteObject(iconInfo.hbmColor);
518 DeleteObject(iconInfo.hbmMask);
521 else
523 BITMAP bm;
525 GetObjectA (infoPtr->hImage, sizeof(BITMAP), &bm);
527 imageWidth = bm.bmWidth;
528 imageHeight = bm.bmHeight;
531 /* Center the bitmap */
532 xOffset = (((rc.right - rc.left) - 2*xBorderOffset) - imageWidth ) / 2;
533 yOffset = (((rc.bottom - rc.top) - 2*yBorderOffset) - imageHeight) / 2;
535 /* If the image is too big for the button then create a region*/
536 if(xOffset < 0 || yOffset < 0)
538 HRGN hBitmapRgn = 0;
539 hBitmapRgn = CreateRectRgn(
540 rc.left + xBorderOffset, rc.top +yBorderOffset,
541 rc.right - xBorderOffset, rc.bottom - yBorderOffset);
542 SelectClipRgn(hDC, hBitmapRgn);
543 DeleteObject(hBitmapRgn);
546 /* Let minimum 1 space from border */
547 xOffset++, yOffset++;
550 * Draw the image now.
552 if (wndPtr->dwStyle & BS_ICON)
554 DrawIcon(hDC,
555 rc.left + xOffset, rc.top + yOffset,
556 (HICON)infoPtr->hImage);
558 else
560 HDC hdcMem;
562 hdcMem = CreateCompatibleDC (hDC);
563 SelectObject (hdcMem, (HBITMAP)infoPtr->hImage);
564 BitBlt(hDC,
565 rc.left + xOffset,
566 rc.top + yOffset,
567 imageWidth, imageHeight,
568 hdcMem, 0, 0, SRCCOPY);
570 DeleteDC (hdcMem);
573 if(xOffset < 0 || yOffset < 0)
575 SelectClipRgn(hDC, 0);
579 if (TWEAK_WineLook != WIN31_LOOK
580 && infoPtr->state & BUTTON_HASFOCUS)
582 InflateRect( &focus_rect, -1, -1 );
583 DrawFocusRect( hDC, &focus_rect );
587 SelectObject( hDC, hOldPen );
588 SelectObject( hDC, hOldBrush );
592 /**********************************************************************
593 * PB_Paint & CB_Paint sub function [internal]
594 * Paint text using a raster brush to avoid gray text on gray
595 * background. 'format' can be a combination of DT_CENTER and
596 * DT_VCENTER to use this function in both PB_PAINT and
597 * CB_PAINT. - Dirk Thierbach
599 * FIXME: This and TEXT_GrayString should be eventually combined,
600 * so calling one common function from PB_Paint, CB_Paint and
601 * TEXT_GrayString will be enough. Also note that this
602 * function ignores the CACHE_GetPattern funcs.
605 void PaintGrayOnGray(HDC hDC,HFONT hFont,RECT *rc,char *text,
606 UINT format)
608 /* This is the standard gray on gray pattern:
609 static const WORD Pattern[] = {0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55};
611 /* This pattern gives better readability with X Fonts.
612 FIXME: Maybe the user should be allowed to decide which he wants. */
613 static const WORD Pattern[] = {0x55,0xFF,0xAA,0xFF,0x55,0xFF,0xAA,0xFF};
615 HBITMAP hbm = CreateBitmap( 8, 8, 1, 1, Pattern );
616 HDC hdcMem = CreateCompatibleDC(hDC);
617 HBITMAP hbmMem;
618 HBRUSH hBr;
619 RECT rect,rc2;
621 rect=*rc;
622 DrawTextA( hDC, text, -1, &rect, DT_SINGLELINE | DT_CALCRECT);
623 /* now text width and height are in rect.right and rect.bottom */
624 rc2=rect;
625 rect.left = rect.top = 0; /* drawing pos in hdcMem */
626 if (format & DT_CENTER) rect.left=(rc->right-rect.right)/2;
627 if (format & DT_VCENTER) rect.top=(rc->bottom-rect.bottom)/2;
628 hbmMem = CreateCompatibleBitmap( hDC,rect.right,rect.bottom );
629 SelectObject( hdcMem, hbmMem);
630 PatBlt( hdcMem,0,0,rect.right,rect.bottom,WHITENESS);
631 /* will be overwritten by DrawText, but just in case */
632 if (hFont) SelectObject( hdcMem, hFont);
633 DrawTextA( hdcMem, text, -1, &rc2, DT_SINGLELINE);
634 /* After draw: foreground = 0 bits, background = 1 bits */
635 hBr = SelectObject( hdcMem, CreatePatternBrush(hbm) );
636 DeleteObject( hbm );
637 PatBlt( hdcMem,0,0,rect.right,rect.bottom,0xAF0229);
638 /* only keep the foreground bits where pattern is 1 */
639 DeleteObject( SelectObject( hdcMem,hBr) );
640 BitBlt(hDC,rect.left,rect.top,rect.right,rect.bottom,hdcMem,0,0,SRCAND);
641 /* keep the background of the dest */
642 DeleteDC( hdcMem);
643 DeleteObject( hbmMem );
647 /**********************************************************************
648 * Check Box & Radio Button Functions
651 static void CB_Paint( WND *wndPtr, HDC hDC, WORD action )
653 RECT rbox, rtext, client;
654 HBRUSH hBrush;
655 int textlen, delta;
656 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
659 * if the button has a bitmap/icon, draw a normal pushbutton
660 * instead of a radion button.
662 if (infoPtr->hImage != 0)
664 BOOL bHighLighted = ((infoPtr->state & BUTTON_HIGHLIGHTED) ||
665 (infoPtr->state & BUTTON_CHECKED));
667 BUTTON_DrawPushButton(wndPtr,
668 hDC,
669 action,
670 bHighLighted);
671 return;
674 textlen = 0;
675 GetClientRect(wndPtr->hwndSelf, &client);
676 rbox = rtext = client;
678 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
680 /* Something is still not right, checkboxes (and edit controls)
681 * in wsping32 have white backgrounds instead of dark grey.
682 * BUTTON_SEND_CTLCOLOR() is even worse since it returns 0 in this
683 * particular case and the background is not painted at all.
686 hBrush = GetControlBrush16( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
688 if (wndPtr->dwStyle & BS_LEFTTEXT)
690 /* magic +4 is what CTL3D expects */
692 rtext.right -= checkBoxWidth + 4;
693 rbox.left = rbox.right - checkBoxWidth;
695 else
697 rtext.left += checkBoxWidth + 4;
698 rbox.right = checkBoxWidth;
701 /* Draw the check-box bitmap */
703 if (wndPtr->text) textlen = strlen( wndPtr->text );
704 if (action == ODA_DRAWENTIRE || action == ODA_SELECT)
706 if( TWEAK_WineLook == WIN31_LOOK )
708 HDC hMemDC = CreateCompatibleDC( hDC );
709 int x = 0, y = 0;
710 delta = (rbox.bottom - rbox.top - checkBoxHeight) / 2;
712 /* Check in case the client area is smaller than the checkbox bitmap */
713 if (delta < 0) delta = 0;
715 if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush );
716 else FillRect( hDC, &client, hBrush );
718 if (infoPtr->state & BUTTON_HIGHLIGHTED) x += 2 * checkBoxWidth;
719 if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE)) x += checkBoxWidth;
720 if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) ||
721 ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) y += checkBoxHeight;
722 else if (infoPtr->state & BUTTON_3STATE) y += 2 * checkBoxHeight;
724 /* The bitmap for the radio button is not aligned with the
725 * left of the window, it is 1 pixel off. */
726 if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) ||
727 ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON))
728 rbox.left += 1;
730 SelectObject( hMemDC, hbitmapCheckBoxes );
731 BitBlt( hDC, rbox.left, rbox.top + delta, checkBoxWidth,
732 checkBoxHeight, hMemDC, x, y, SRCCOPY );
733 DeleteDC( hMemDC );
735 else
737 UINT state;
739 if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) ||
740 ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) state = DFCS_BUTTONRADIO;
741 else if (infoPtr->state & BUTTON_3STATE) state = DFCS_BUTTON3STATE;
742 else state = DFCS_BUTTONCHECK;
744 if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE)) state |= DFCS_CHECKED;
746 if (infoPtr->state & BUTTON_HIGHLIGHTED) state |= DFCS_PUSHED;
748 if (wndPtr->dwStyle & WS_DISABLED) state |= DFCS_INACTIVE;
750 DrawFrameControl( hDC, &rbox, DFC_BUTTON, state );
754 if( textlen && action != ODA_SELECT )
756 if (wndPtr->dwStyle & WS_DISABLED &&
757 GetSysColor(COLOR_GRAYTEXT)==GetBkColor(hDC)) {
758 /* don't write gray text on gray background */
759 PaintGrayOnGray( hDC, infoPtr->hFont, &rtext, wndPtr->text,
760 DT_VCENTER);
761 } else {
762 if (wndPtr->dwStyle & WS_DISABLED)
763 SetTextColor( hDC, GetSysColor(COLOR_GRAYTEXT) );
764 DrawTextA( hDC, wndPtr->text, textlen, &rtext,
765 DT_SINGLELINE | DT_VCENTER );
770 if ((action == ODA_FOCUS) ||
771 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
773 /* again, this is what CTL3D expects */
775 SetRectEmpty(&rbox);
776 if( textlen )
777 DrawTextA( hDC, wndPtr->text, textlen, &rbox,
778 DT_SINGLELINE | DT_CALCRECT );
779 textlen = rbox.bottom - rbox.top;
780 delta = ((rtext.bottom - rtext.top) - textlen)/2;
781 rbox.bottom = (rbox.top = rtext.top + delta - 1) + textlen + 2;
782 textlen = rbox.right - rbox.left;
783 rbox.right = (rbox.left += --rtext.left) + textlen + 2;
784 IntersectRect(&rbox, &rbox, &rtext);
785 DrawFocusRect( hDC, &rbox );
790 /**********************************************************************
791 * BUTTON_CheckAutoRadioButton
793 * wndPtr is checked, uncheck every other auto radio button in group
795 static void BUTTON_CheckAutoRadioButton( WND *wndPtr )
797 HWND parent, sibling, start;
798 if (!(wndPtr->dwStyle & WS_CHILD)) return;
799 parent = wndPtr->parent->hwndSelf;
800 /* assure that starting control is not disabled or invisible */
801 start = sibling = GetNextDlgGroupItem( parent, wndPtr->hwndSelf, TRUE );
804 WND *tmpWnd;
805 if (!sibling) break;
806 tmpWnd = WIN_FindWndPtr(sibling);
807 if ((wndPtr->hwndSelf != sibling) &&
808 ((tmpWnd->dwStyle & 0x0f) == BS_AUTORADIOBUTTON))
809 SendMessageA( sibling, BM_SETCHECK, BUTTON_UNCHECKED, 0 );
810 sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
811 WIN_ReleaseWndPtr(tmpWnd);
812 } while (sibling != start);
816 /**********************************************************************
817 * Group Box Functions
820 static void GB_Paint( WND *wndPtr, HDC hDC, WORD action )
822 RECT rc, rcFrame;
823 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
825 if (action != ODA_DRAWENTIRE) return;
827 BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
829 GetClientRect( wndPtr->hwndSelf, &rc);
830 if (TWEAK_WineLook == WIN31_LOOK) {
831 HPEN hPrevPen = SelectObject( hDC,
832 GetSysColorPen(COLOR_WINDOWFRAME));
833 HBRUSH hPrevBrush = SelectObject( hDC,
834 GetStockObject(NULL_BRUSH) );
836 Rectangle( hDC, rc.left, rc.top + 2, rc.right - 1, rc.bottom - 1 );
837 SelectObject( hDC, hPrevBrush );
838 SelectObject( hDC, hPrevPen );
839 } else {
840 TEXTMETRICA tm;
841 rcFrame = rc;
843 if (infoPtr->hFont)
844 SelectObject (hDC, infoPtr->hFont);
845 GetTextMetricsA (hDC, &tm);
846 rcFrame.top += (tm.tmHeight / 2) - 1;
847 DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT);
850 if (wndPtr->text)
852 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
853 if (wndPtr->dwStyle & WS_DISABLED)
854 SetTextColor( hDC, GetSysColor(COLOR_GRAYTEXT) );
855 rc.left += 10;
856 DrawTextA( hDC, wndPtr->text, -1, &rc, DT_SINGLELINE | DT_NOCLIP );
861 /**********************************************************************
862 * User Button Functions
865 static void UB_Paint( WND *wndPtr, HDC hDC, WORD action )
867 RECT rc;
868 HBRUSH hBrush;
869 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
871 if (action == ODA_SELECT) return;
873 GetClientRect( wndPtr->hwndSelf, &rc);
875 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
876 hBrush = GetControlBrush16( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
878 FillRect( hDC, &rc, hBrush );
879 if ((action == ODA_FOCUS) ||
880 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
881 DrawFocusRect( hDC, &rc );
885 /**********************************************************************
886 * Ownerdrawn Button Functions
889 static void OB_Paint( WND *wndPtr, HDC hDC, WORD action )
891 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
892 DRAWITEMSTRUCT dis;
894 dis.CtlType = ODT_BUTTON;
895 dis.CtlID = wndPtr->wIDmenu;
896 dis.itemID = 0;
897 dis.itemAction = action;
898 dis.itemState = ((infoPtr->state & BUTTON_HASFOCUS) ? ODS_FOCUS : 0) |
899 ((infoPtr->state & BUTTON_HIGHLIGHTED) ? ODS_SELECTED : 0) |
900 ((wndPtr->dwStyle & WS_DISABLED) ? ODS_DISABLED : 0);
901 dis.hwndItem = wndPtr->hwndSelf;
902 dis.hDC = hDC;
903 dis.itemData = 0;
904 GetClientRect( wndPtr->hwndSelf, &dis.rcItem );
906 SetBkColor( hDC, GetSysColor( COLOR_BTNFACE ) );
908 SendMessageA( GetParent(wndPtr->hwndSelf), WM_DRAWITEM,
909 wndPtr->wIDmenu, (LPARAM)&dis );