Bugfix: free loaded library not before exit.
[wine/hacks.git] / controls / button.c
blobb8f6726681e16f65b4502b301e285b8d6a1c811b
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 "winuser.h"
12 #include "wine/winuser16.h"
13 #include "tweak.h"
15 static void PaintGrayOnGray( HDC hDC,HFONT hFont,RECT *rc,
16 char *text, UINT format );
18 static void PB_Paint( WND *wndPtr, HDC hDC, WORD action );
19 static void CB_Paint( WND *wndPtr, HDC hDC, WORD action );
20 static void GB_Paint( WND *wndPtr, HDC hDC, WORD action );
21 static void UB_Paint( WND *wndPtr, HDC hDC, WORD action );
22 static void OB_Paint( WND *wndPtr, HDC hDC, WORD action );
23 static void BUTTON_CheckAutoRadioButton( WND *wndPtr );
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
78 LRESULT WINAPI ButtonWndProc( HWND hWnd, UINT uMsg,
79 WPARAM wParam, LPARAM lParam )
81 RECT rect;
82 LRESULT retvalue;
83 POINT pt = { LOWORD(lParam), HIWORD(lParam) };
84 WND *wndPtr = WIN_FindWndPtr(hWnd);
85 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
86 LONG style = wndPtr->dwStyle & 0x0f;
87 HANDLE oldHbitmap;
89 switch (uMsg)
91 case WM_GETDLGCODE:
92 WIN_ReleaseWndPtr(wndPtr);
93 switch(style)
95 case BS_PUSHBUTTON: return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON;
96 case BS_DEFPUSHBUTTON: return DLGC_BUTTON | DLGC_DEFPUSHBUTTON;
97 case BS_RADIOBUTTON:
98 case BS_AUTORADIOBUTTON: return DLGC_BUTTON | DLGC_RADIOBUTTON;
99 default: return DLGC_BUTTON;
102 case WM_ENABLE:
103 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
104 break;
106 case WM_CREATE:
107 if (!hbitmapCheckBoxes)
109 BITMAP bmp;
110 hbitmapCheckBoxes = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_CHECKBOXES));
111 GetObjectA( hbitmapCheckBoxes, sizeof(bmp), &bmp );
112 checkBoxWidth = bmp.bmWidth / 4;
113 checkBoxHeight = bmp.bmHeight / 3;
115 if (style < 0L || style >= MAX_BTN_TYPE)
117 WIN_ReleaseWndPtr(wndPtr);
118 return -1; /* abort */
120 infoPtr->state = BUTTON_UNCHECKED;
121 infoPtr->hFont = 0;
122 infoPtr->hImage = NULL;
123 WIN_ReleaseWndPtr(wndPtr);
124 return 0;
126 case WM_ERASEBKGND:
127 WIN_ReleaseWndPtr(wndPtr);
128 return 1;
130 case WM_PAINT:
131 if (btnPaintFunc[style])
133 PAINTSTRUCT ps;
134 HDC hdc = wParam ? (HDC)wParam : BeginPaint( hWnd, &ps );
135 SetBkMode( hdc, OPAQUE );
136 (btnPaintFunc[style])( wndPtr, hdc, ODA_DRAWENTIRE );
137 if( !wParam ) EndPaint( hWnd, &ps );
139 break;
141 case WM_LBUTTONDOWN:
142 case WM_LBUTTONDBLCLK:
143 SendMessageA( hWnd, BM_SETSTATE, TRUE, 0 );
144 SetFocus( hWnd );
145 SetCapture( hWnd );
146 break;
148 case WM_LBUTTONUP:
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 WIN_ReleaseWndPtr(wndPtr);
185 if(style == BS_GROUPBOX) return HTTRANSPARENT;
186 return DefWindowProcA( hWnd, uMsg, wParam, lParam );
188 case WM_SETTEXT:
189 DEFWND_SetText( wndPtr, (LPCSTR)lParam );
190 if( wndPtr->dwStyle & WS_VISIBLE )
191 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
192 WIN_ReleaseWndPtr(wndPtr);
193 return 0;
195 case WM_SETFONT:
196 infoPtr->hFont = (HFONT16)wParam;
197 if (lParam && (wndPtr->dwStyle & WS_VISIBLE))
198 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
199 break;
201 case WM_GETFONT:
202 retvalue = infoPtr->hFont;
203 WIN_ReleaseWndPtr(wndPtr);
204 return retvalue;
206 case WM_SETFOCUS:
207 infoPtr->state |= BUTTON_HASFOCUS;
208 if (style == BS_AUTORADIOBUTTON)
210 SendMessageA( hWnd, BM_SETCHECK, 1, 0 );
212 PAINT_BUTTON( wndPtr, style, ODA_FOCUS );
213 break;
215 case WM_KILLFOCUS:
216 infoPtr->state &= ~BUTTON_HASFOCUS;
217 PAINT_BUTTON( wndPtr, style, ODA_FOCUS );
218 InvalidateRect( hWnd, NULL, TRUE );
219 break;
221 case WM_SYSCOLORCHANGE:
222 InvalidateRect( hWnd, NULL, FALSE );
223 break;
225 case BM_SETSTYLE16:
226 case BM_SETSTYLE:
227 if ((wParam & 0x0f) >= MAX_BTN_TYPE) break;
228 wndPtr->dwStyle = (wndPtr->dwStyle & 0xfffffff0)
229 | (wParam & 0x0000000f);
230 style = wndPtr->dwStyle & 0x0000000f;
231 PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE );
232 break;
234 case BM_SETIMAGE:
235 oldHbitmap = infoPtr->hImage;
236 if(wndPtr->dwStyle & BS_BITMAP)
237 infoPtr->hImage = (HANDLE) lParam;
238 WIN_ReleaseWndPtr(wndPtr);
239 return oldHbitmap;
241 case BM_GETIMAGE:
242 WIN_ReleaseWndPtr(wndPtr);
243 return infoPtr->hImage;
245 case BM_GETCHECK16:
246 case BM_GETCHECK:
247 retvalue = infoPtr->state & 3;
248 WIN_ReleaseWndPtr(wndPtr);
249 return retvalue;
251 case BM_SETCHECK16:
252 case BM_SETCHECK:
253 if (wParam > maxCheckState[style]) wParam = maxCheckState[style];
254 if ((infoPtr->state & 3) != wParam)
256 if ((style == BS_RADIOBUTTON) || (style == BS_AUTORADIOBUTTON))
258 if (wParam)
259 wndPtr->dwStyle |= WS_TABSTOP;
260 else
261 wndPtr->dwStyle &= ~WS_TABSTOP;
263 infoPtr->state = (infoPtr->state & ~3) | wParam;
264 PAINT_BUTTON( wndPtr, style, ODA_SELECT );
266 if ((style == BS_AUTORADIOBUTTON) && (wParam == BUTTON_CHECKED))
267 BUTTON_CheckAutoRadioButton( wndPtr );
268 break;
270 case BM_GETSTATE16:
271 case BM_GETSTATE:
272 retvalue = infoPtr->state;
273 WIN_ReleaseWndPtr(wndPtr);
274 return retvalue;
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 WIN_ReleaseWndPtr(wndPtr);
293 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
295 WIN_ReleaseWndPtr(wndPtr);
296 return 0;
300 /**********************************************************************
301 * Push Button Functions
304 static void PB_Paint( WND *wndPtr, HDC hDC, WORD action )
306 RECT rc;
307 HPEN hOldPen;
308 HBRUSH hOldBrush;
309 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
310 int xBorderOffset, yBorderOffset;
311 xBorderOffset = yBorderOffset = 0;
313 GetClientRect( wndPtr->hwndSelf, &rc );
315 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
316 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
317 BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
318 hOldPen = (HPEN)SelectObject(hDC, GetSysColorPen(COLOR_WINDOWFRAME));
319 hOldBrush =(HBRUSH)SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE));
320 SetBkMode(hDC, TRANSPARENT);
321 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
322 /* if (action == ODA_DRAWENTIRE)*/
324 SetPixel( hDC, rc.left, rc.top, GetSysColor(COLOR_WINDOW) );
325 SetPixel( hDC, rc.left, rc.bottom-1, GetSysColor(COLOR_WINDOW) );
326 SetPixel( hDC, rc.right-1, rc.top, GetSysColor(COLOR_WINDOW) );
327 SetPixel( hDC, rc.right-1, rc.bottom-1, GetSysColor(COLOR_WINDOW));
329 InflateRect( &rc, -1, -1 );
331 if ((wndPtr->dwStyle & 0x000f) == BS_DEFPUSHBUTTON)
333 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
334 InflateRect( &rc, -1, -1 );
337 if (infoPtr->state & BUTTON_HIGHLIGHTED)
339 /* draw button shadow: */
340 SelectObject(hDC, GetSysColorBrush(COLOR_BTNSHADOW));
341 PatBlt(hDC, rc.left, rc.top, 1, rc.bottom-rc.top, PATCOPY );
342 PatBlt(hDC, rc.left, rc.top, rc.right-rc.left, 1, PATCOPY );
343 rc.left += 2; /* To position the text down and right */
344 rc.top += 2;
345 } else {
346 rc.right++, rc.bottom++;
347 DrawEdge( hDC, &rc, EDGE_RAISED, BF_RECT );
349 /* To place de bitmap correctly */
350 xBorderOffset += GetSystemMetrics(SM_CXEDGE);
351 yBorderOffset += GetSystemMetrics(SM_CYEDGE);
353 rc.right--, rc.bottom--;
356 /* draw button label, if any: */
357 if (wndPtr->text && wndPtr->text[0])
359 LOGBRUSH lb;
360 GetObjectA( GetSysColorBrush(COLOR_BTNFACE), sizeof(lb), &lb );
361 if (wndPtr->dwStyle & WS_DISABLED &&
362 GetSysColor(COLOR_GRAYTEXT)==lb.lbColor)
363 /* don't write gray text on gray background */
364 PaintGrayOnGray( hDC,infoPtr->hFont,&rc,wndPtr->text,
365 DT_CENTER | DT_VCENTER );
366 else
368 SetTextColor( hDC, (wndPtr->dwStyle & WS_DISABLED) ?
369 GetSysColor(COLOR_GRAYTEXT) :
370 GetSysColor(COLOR_BTNTEXT) );
371 DrawTextA( hDC, wndPtr->text, -1, &rc,
372 DT_SINGLELINE | DT_CENTER | DT_VCENTER );
373 /* do we have the focus? */
374 if (infoPtr->state & BUTTON_HASFOCUS)
376 RECT r = { 0, 0, 0, 0 };
377 INT xdelta, ydelta;
379 DrawTextA( hDC, wndPtr->text, -1, &r,
380 DT_SINGLELINE | DT_CALCRECT );
381 xdelta = ((rc.right - rc.left) - (r.right - r.left) - 1) / 2;
382 ydelta = ((rc.bottom - rc.top) - (r.bottom - r.top) - 1) / 2;
383 if (xdelta < 0) xdelta = 0;
384 if (ydelta < 0) ydelta = 0;
385 InflateRect( &rc, -xdelta, -ydelta );
386 DrawFocusRect( hDC, &rc );
391 if((wndPtr->dwStyle & BS_BITMAP) && (infoPtr->hImage != NULL))
393 BITMAP bm;
394 HDC hdcMem;
395 int yOffset, xOffset, imageWidth, imageHeight;
397 GetObjectA (infoPtr->hImage, sizeof(BITMAP), &bm);
399 /* Center the bitmap */
400 xOffset = (((rc.right - rc.left) - 2*xBorderOffset) - bm.bmWidth ) / 2;
401 yOffset = (((rc.bottom - rc.top) - 2*yBorderOffset) - bm.bmHeight ) / 2;
403 imageWidth = bm.bmWidth;
404 imageHeight = bm.bmHeight;
406 /* If the image is to big for the button */
407 if (xOffset < 0)
409 imageWidth = rc.right - rc.left - 2*xBorderOffset -1;
410 xOffset = xBorderOffset;
413 if (yOffset < 0)
415 imageHeight = rc.bottom - rc.top - 2*yBorderOffset -1;
416 yOffset = yBorderOffset;
419 /* Let minimum 1 space from border */
420 xOffset++, yOffset++;
422 hdcMem = CreateCompatibleDC (hDC);
423 SelectObject (hdcMem, (HBITMAP)infoPtr->hImage);
424 BitBlt(hDC, rc.left + xOffset,
425 rc.top + yOffset,
426 imageWidth, imageHeight,
427 hdcMem, 0, 0, SRCCOPY);
429 DeleteDC (hdcMem);
432 SelectObject( hDC, hOldPen );
433 SelectObject( hDC, hOldBrush );
437 /**********************************************************************
438 * PB_Paint & CB_Paint sub function [internal]
439 * Paint text using a raster brush to avoid gray text on gray
440 * background. 'format' can be a combination of DT_CENTER and
441 * DT_VCENTER to use this function in both PB_PAINT and
442 * CB_PAINT. - Dirk Thierbach
444 * FIXME: This and TEXT_GrayString should be eventually combined,
445 * so calling one common function from PB_Paint, CB_Paint and
446 * TEXT_GrayString will be enough. Also note that this
447 * function ignores the CACHE_GetPattern funcs.
450 void PaintGrayOnGray(HDC hDC,HFONT hFont,RECT *rc,char *text,
451 UINT format)
453 /* This is the standard gray on gray pattern:
454 static const WORD Pattern[] = {0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55};
456 /* This pattern gives better readability with X Fonts.
457 FIXME: Maybe the user should be allowed to decide which he wants. */
458 static const WORD Pattern[] = {0x55,0xFF,0xAA,0xFF,0x55,0xFF,0xAA,0xFF};
460 HBITMAP hbm = CreateBitmap( 8, 8, 1, 1, Pattern );
461 HDC hdcMem = CreateCompatibleDC(hDC);
462 HBITMAP hbmMem;
463 HBRUSH hBr;
464 RECT rect,rc2;
466 rect=*rc;
467 DrawTextA( hDC, text, -1, &rect, DT_SINGLELINE | DT_CALCRECT);
468 /* now text width and height are in rect.right and rect.bottom */
469 rc2=rect;
470 rect.left = rect.top = 0; /* drawing pos in hdcMem */
471 if (format & DT_CENTER) rect.left=(rc->right-rect.right)/2;
472 if (format & DT_VCENTER) rect.top=(rc->bottom-rect.bottom)/2;
473 hbmMem = CreateCompatibleBitmap( hDC,rect.right,rect.bottom );
474 SelectObject( hdcMem, hbmMem);
475 PatBlt( hdcMem,0,0,rect.right,rect.bottom,WHITENESS);
476 /* will be overwritten by DrawText, but just in case */
477 if (hFont) SelectObject( hdcMem, hFont);
478 DrawTextA( hdcMem, text, -1, &rc2, DT_SINGLELINE);
479 /* After draw: foreground = 0 bits, background = 1 bits */
480 hBr = SelectObject( hdcMem, CreatePatternBrush(hbm) );
481 DeleteObject( hbm );
482 PatBlt( hdcMem,0,0,rect.right,rect.bottom,0xAF0229);
483 /* only keep the foreground bits where pattern is 1 */
484 DeleteObject( SelectObject( hdcMem,hBr) );
485 BitBlt(hDC,rect.left,rect.top,rect.right,rect.bottom,hdcMem,0,0,SRCAND);
486 /* keep the background of the dest */
487 DeleteDC( hdcMem);
488 DeleteObject( hbmMem );
492 /**********************************************************************
493 * Check Box & Radio Button Functions
496 static void CB_Paint( WND *wndPtr, HDC hDC, WORD action )
498 RECT rbox, rtext, client;
499 HBRUSH hBrush;
500 int textlen, delta;
501 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
503 textlen = 0;
504 GetClientRect(wndPtr->hwndSelf, &client);
505 rbox = rtext = client;
507 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
509 /* Something is still not right, checkboxes (and edit controls)
510 * in wsping32 have white backgrounds instead of dark grey.
511 * BUTTON_SEND_CTLCOLOR() is even worse since it returns 0 in this
512 * particular case and the background is not painted at all.
515 hBrush = GetControlBrush16( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
517 if (wndPtr->dwStyle & BS_LEFTTEXT)
519 /* magic +4 is what CTL3D expects */
521 rtext.right -= checkBoxWidth + 4;
522 rbox.left = rbox.right - checkBoxWidth;
524 else
526 rtext.left += checkBoxWidth + 4;
527 rbox.right = checkBoxWidth;
530 /* Draw the check-box bitmap */
532 if (wndPtr->text) textlen = strlen( wndPtr->text );
533 if (action == ODA_DRAWENTIRE || action == ODA_SELECT)
535 HDC hMemDC = CreateCompatibleDC( hDC );
536 int x = 0, y = 0;
537 delta = (rbox.bottom - rbox.top - checkBoxHeight) >> 1;
539 if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush );
540 else FillRect( hDC, &client, hBrush );
542 if (infoPtr->state & BUTTON_HIGHLIGHTED) x += 2 * checkBoxWidth;
543 if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE)) x += checkBoxWidth;
544 if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) ||
545 ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) y += checkBoxHeight;
546 else if (infoPtr->state & BUTTON_3STATE) y += 2 * checkBoxHeight;
548 SelectObject( hMemDC, hbitmapCheckBoxes );
549 BitBlt( hDC, rbox.left, rbox.top + delta, checkBoxWidth,
550 checkBoxHeight, hMemDC, x, y, SRCCOPY );
551 DeleteDC( hMemDC );
553 if( textlen && action != ODA_SELECT )
555 if (wndPtr->dwStyle & WS_DISABLED &&
556 GetSysColor(COLOR_GRAYTEXT)==GetBkColor(hDC)) {
557 /* don't write gray text on gray background */
558 PaintGrayOnGray( hDC, infoPtr->hFont, &rtext, wndPtr->text,
559 DT_VCENTER);
560 } else {
561 if (wndPtr->dwStyle & WS_DISABLED)
562 SetTextColor( hDC, GetSysColor(COLOR_GRAYTEXT) );
563 DrawTextA( hDC, wndPtr->text, textlen, &rtext,
564 DT_SINGLELINE | DT_VCENTER );
565 textlen = 0; /* skip DrawText() below */
570 if ((action == ODA_FOCUS) ||
571 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
573 /* again, this is what CTL3D expects */
575 SetRectEmpty(&rbox);
576 if( textlen )
577 DrawTextA( hDC, wndPtr->text, textlen, &rbox,
578 DT_SINGLELINE | DT_CALCRECT );
579 textlen = rbox.bottom - rbox.top;
580 delta = ((rtext.bottom - rtext.top) - textlen)/2;
581 rbox.bottom = (rbox.top = rtext.top + delta - 1) + textlen + 2;
582 textlen = rbox.right - rbox.left;
583 rbox.right = (rbox.left += --rtext.left) + textlen + 2;
584 IntersectRect(&rbox, &rbox, &rtext);
585 DrawFocusRect( hDC, &rbox );
590 /**********************************************************************
591 * BUTTON_CheckAutoRadioButton
593 * wndPtr is checked, uncheck every other auto radio button in group
595 static void BUTTON_CheckAutoRadioButton( WND *wndPtr )
597 HWND parent, sibling, start;
598 if (!(wndPtr->dwStyle & WS_CHILD)) return;
599 parent = wndPtr->parent->hwndSelf;
600 /* assure that starting control is not disabled or invisible */
601 start = sibling = GetNextDlgGroupItem( parent, wndPtr->hwndSelf, TRUE );
604 WND *tmpWnd;
605 if (!sibling) break;
606 tmpWnd = WIN_FindWndPtr(sibling);
607 if ((wndPtr->hwndSelf != sibling) &&
608 ((tmpWnd->dwStyle & 0x0f) == BS_AUTORADIOBUTTON))
609 SendMessageA( sibling, BM_SETCHECK, BUTTON_UNCHECKED, 0 );
610 sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
611 WIN_ReleaseWndPtr(tmpWnd);
612 } while (sibling != start);
616 /**********************************************************************
617 * Group Box Functions
620 static void GB_Paint( WND *wndPtr, HDC hDC, WORD action )
622 RECT rc, rcFrame;
623 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
625 if (action != ODA_DRAWENTIRE) return;
627 BUTTON_SEND_CTLCOLOR( wndPtr, hDC );
629 GetClientRect( wndPtr->hwndSelf, &rc);
630 if (TWEAK_WineLook == WIN31_LOOK) {
631 HPEN hPrevPen = SelectObject( hDC,
632 GetSysColorPen(COLOR_WINDOWFRAME));
633 HBRUSH hPrevBrush = SelectObject( hDC,
634 GetStockObject(NULL_BRUSH) );
636 Rectangle( hDC, rc.left, rc.top + 2, rc.right - 1, rc.bottom - 1 );
637 SelectObject( hDC, hPrevBrush );
638 SelectObject( hDC, hPrevPen );
639 } else {
640 TEXTMETRICA tm;
641 rcFrame = rc;
643 if (infoPtr->hFont)
644 SelectObject (hDC, infoPtr->hFont);
645 GetTextMetricsA (hDC, &tm);
646 rcFrame.top += (tm.tmHeight / 2) - 1;
647 DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT);
650 if (wndPtr->text)
652 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
653 if (wndPtr->dwStyle & WS_DISABLED)
654 SetTextColor( hDC, GetSysColor(COLOR_GRAYTEXT) );
655 rc.left += 10;
656 DrawTextA( hDC, wndPtr->text, -1, &rc, DT_SINGLELINE | DT_NOCLIP );
661 /**********************************************************************
662 * User Button Functions
665 static void UB_Paint( WND *wndPtr, HDC hDC, WORD action )
667 RECT rc;
668 HBRUSH hBrush;
669 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
671 if (action == ODA_SELECT) return;
673 GetClientRect( wndPtr->hwndSelf, &rc);
675 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
676 hBrush = GetControlBrush16( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN );
678 FillRect( hDC, &rc, hBrush );
679 if ((action == ODA_FOCUS) ||
680 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS)))
681 DrawFocusRect( hDC, &rc );
685 /**********************************************************************
686 * Ownerdrawn Button Functions
689 static void OB_Paint( WND *wndPtr, HDC hDC, WORD action )
691 BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra;
692 DRAWITEMSTRUCT dis;
694 dis.CtlType = ODT_BUTTON;
695 dis.CtlID = wndPtr->wIDmenu;
696 dis.itemID = 0;
697 dis.itemAction = action;
698 dis.itemState = ((infoPtr->state & BUTTON_HASFOCUS) ? ODS_FOCUS : 0) |
699 ((infoPtr->state & BUTTON_HIGHLIGHTED) ? ODS_SELECTED : 0) |
700 ((wndPtr->dwStyle & WS_DISABLED) ? ODS_DISABLED : 0);
701 dis.hwndItem = wndPtr->hwndSelf;
702 dis.hDC = hDC;
703 dis.itemData = 0;
704 GetClientRect( wndPtr->hwndSelf, &dis.rcItem );
705 SendMessageA( GetParent(wndPtr->hwndSelf), WM_DRAWITEM,
706 wndPtr->wIDmenu, (LPARAM)&dis );